From owner-svn-src-head@freebsd.org Fri Sep 7 16:26:20 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 63552FFF151; Fri, 7 Sep 2018 16:26:20 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E20A98FE73; Fri, 7 Sep 2018 16:26:19 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id w87GQ9Db057171 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 7 Sep 2018 19:26:12 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w87GQ9Db057171 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w87GQ8xt057170; Fri, 7 Sep 2018 19:26:08 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 7 Sep 2018 19:26:08 +0300 From: Konstantin Belousov To: John Baldwin Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r338523 - head/sbin/sysctl Message-ID: <20180907162608.GV3161@kib.kiev.ua> References: <201809071509.w87F9uEO078085@repo.freebsd.org> <8beb57f9-37dc-735c-fa85-78ecb67679ad@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8beb57f9-37dc-735c-fa85-78ecb67679ad@FreeBSD.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Sep 2018 16:26:20 -0000 On Fri, Sep 07, 2018 at 09:00:20AM -0700, John Baldwin wrote: > On 9/7/18 8:09 AM, Konstantin Belousov wrote: > > Author: kib > > Date: Fri Sep 7 15:09:56 2018 > > New Revision: 338523 > > URL: https://svnweb.freebsd.org/changeset/base/338523 > > > > Log: > > Teach sysctl(8) about the Persistent memory type. > > > > Add PersistentMemory to the list of sysctl's known memory types > > when decoding an EFI memory map. > > > > Submitted by: D Scott Phillips > > MFC after: 1 week > > Approved by: re (rgrimes) > > > > Modified: > > head/sbin/sysctl/sysctl.c > > > > Modified: head/sbin/sysctl/sysctl.c > > ============================================================================== > > --- head/sbin/sysctl/sysctl.c Fri Sep 7 14:37:44 2018 (r338522) > > +++ head/sbin/sysctl/sysctl.c Fri Sep 7 15:09:56 2018 (r338523) > > @@ -704,7 +704,8 @@ S_efi_map(size_t l2, void *p) > > "ACPIMemoryNVS", > > "MemoryMappedIO", > > "MemoryMappedIOPortSpace", > > - "PalCode" > > + "PalCode", > > + "PersistentMemory" > > }; > > > > /* > > @@ -733,7 +734,7 @@ S_efi_map(size_t l2, void *p) > > > > for (i = 0; i < ndesc; i++, > > map = efi_next_descriptor(map, efihdr->descriptor_size)) { > > - if (map->md_type <= EFI_MD_TYPE_PALCODE) > > + if (map->md_type <= EFI_MD_TYPE_PERSISTENT) > > Perhaps this should use nitems(types) instead? (And I believe it's my > fault it didn't originally.) For me, it was more an issue that the code assumes contiguous values for the EFI_MD_TYPEs constants. What about the following: diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 427f3e2309b..3a7463ef411 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -691,21 +691,21 @@ S_efi_map(size_t l2, void *p) int ndesc, i; static const char *types[] = { - "Reserved", - "LoaderCode", - "LoaderData", - "BootServicesCode", - "BootServicesData", - "RuntimeServicesCode", - "RuntimeServicesData", - "ConventionalMemory", - "UnusableMemory", - "ACPIReclaimMemory", - "ACPIMemoryNVS", - "MemoryMappedIO", - "MemoryMappedIOPortSpace", - "PalCode", - "PersistentMemory" + [EFI_MD_TYPE_NULL] = "Reserved", + [EFI_MD_TYPE_CODE] = "LoaderCode", + [EFI_MD_TYPE_DATA] = "LoaderData", + [EFI_MD_TYPE_BS_CODE] = "BootServicesCode", + [EFI_MD_TYPE_BS_DATA] = "BootServicesData", + [EFI_MD_TYPE_RT_CODE] = "RuntimeServicesCode", + [EFI_MD_TYPE_RT_DATA] = "RuntimeServicesData", + [EFI_MD_TYPE_FREE] = "ConventionalMemory", + [EFI_MD_TYPE_BAD] = "UnusableMemory", + [EFI_MD_TYPE_RECLAIM] = "ACPIReclaimMemory", + [EFI_MD_TYPE_FIRMWARE] = "ACPIMemoryNVS", + [EFI_MD_TYPE_IOMEM] = "MemoryMappedIO", + [EFI_MD_TYPE_IOPORT] = "MemoryMappedIOPortSpace", + [EFI_MD_TYPE_PALCODE] = "PalCode", + [EFI_MD_TYPE_PERSISTENT] = "PersistentMemory", }; /* @@ -734,9 +734,10 @@ S_efi_map(size_t l2, void *p) for (i = 0; i < ndesc; i++, map = efi_next_descriptor(map, efihdr->descriptor_size)) { - if (map->md_type <= EFI_MD_TYPE_PERSISTENT) + type = NULL; + if (map->md_type < nitems(types)) type = types[map->md_type]; - else + if (type == NULL) type = ""; printf("\n%23s %012jx %12p %08jx ", type, (uintmax_t)map->md_phys, map->md_virt,