From owner-svn-src-head@freebsd.org Tue Mar 31 02:36:50 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 555A2273046; Tue, 31 Mar 2020 02:36:50 +0000 (UTC) (envelope-from bcran@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48rtkn1k4mz4294; Tue, 31 Mar 2020 02:36:49 +0000 (UTC) (envelope-from bcran@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B8ED210C4; Tue, 31 Mar 2020 02:36:40 +0000 (UTC) (envelope-from bcran@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 02V2aecX009084; Tue, 31 Mar 2020 02:36:40 GMT (envelope-from bcran@FreeBSD.org) Received: (from bcran@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 02V2aeEN009083; Tue, 31 Mar 2020 02:36:40 GMT (envelope-from bcran@FreeBSD.org) Message-Id: <202003310236.02V2aeEN009083@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bcran set sender to bcran@FreeBSD.org using -f From: Rebecca Cran Date: Tue, 31 Mar 2020 02:36:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r359478 - head/usr.sbin/bhyve X-SVN-Group: head X-SVN-Commit-Author: bcran X-SVN-Commit-Paths: head/usr.sbin/bhyve X-SVN-Commit-Revision: 359478 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Tue, 31 Mar 2020 02:36:50 -0000 Author: bcran Date: Tue Mar 31 02:36:39 2020 New Revision: 359478 URL: https://svnweb.freebsd.org/changeset/base/359478 Log: Bhyve: fix SMBIOS Type 17 table generation According to the SMBIOS specification (revision 2.7 or newer), the extended module size field should only be used for sizes that can't fit in the older size field. Reviewed by: rgrimes, grehan, jhb Differential Revision: https://reviews.freebsd.org/D24107 Modified: head/usr.sbin/bhyve/smbiostbl.c Modified: head/usr.sbin/bhyve/smbiostbl.c ============================================================================== --- head/usr.sbin/bhyve/smbiostbl.c Tue Mar 31 02:25:53 2020 (r359477) +++ head/usr.sbin/bhyve/smbiostbl.c Tue Mar 31 02:36:39 2020 (r359478) @@ -255,7 +255,7 @@ struct smbios_table_type17 { uint16_t errhand; /* handle of mem error data */ uint16_t twidth; /* total width in bits */ uint16_t dwidth; /* data width in bits */ - uint16_t size; /* size in bytes */ + uint16_t size; /* size in kb or mb */ uint8_t form; /* form factor */ uint8_t set; /* set */ uint8_t dloc; /* device locator string */ @@ -268,7 +268,7 @@ struct smbios_table_type17 { uint8_t asset; /* asset tag string */ uint8_t part; /* part number string */ uint8_t attributes; /* attributes */ - uint32_t xsize; /* extended size in mbs */ + uint32_t xsize; /* extended size in mb */ uint16_t curspeed; /* current speed in mhz */ uint16_t minvoltage; /* minimum voltage */ uint16_t maxvoltage; /* maximum voltage */ @@ -444,7 +444,7 @@ struct smbios_table_type17 smbios_type17_template = { -1, /* handle of memory error data */ 64, /* total width in bits including ecc */ 64, /* data width in bits */ - 0x7fff, /* size in bytes (0x7fff=use extended)*/ + 0, /* size in kb or mb (0x7fff=use extended)*/ SMBIOS_MDFF_UNKNOWN, 0, /* set (0x00=none, 0xff=unknown) */ 1, /* device locator string */ @@ -695,20 +695,39 @@ smbios_type17_initializer(struct smbios_structure *tem uint16_t *n, uint16_t *size) { struct smbios_table_type17 *type17; + uint64_t memsize, size_KB, size_MB; smbios_generic_initializer(template_entry, template_strings, curaddr, endaddr, n, size); type17 = (struct smbios_table_type17 *)curaddr; type17->arrayhand = type16_handle; - type17->xsize = guest_lomem; - if (guest_himem > 0) { - curaddr = *endaddr; - smbios_generic_initializer(template_entry, template_strings, - curaddr, endaddr, n, size); - type17 = (struct smbios_table_type17 *)curaddr; - type17->arrayhand = type16_handle; - type17->xsize = guest_himem; + memsize = guest_lomem + guest_himem; + size_KB = memsize / 1024; + size_MB = memsize / MB; + + /* A single Type 17 entry can't represent more than ~2PB RAM */ + if (size_MB > 0x7FFFFFFF) { + printf("Warning: guest memory too big for SMBIOS Type 17 table: " + "%luMB greater than max supported 2147483647MB\n", size_MB); + + size_MB = 0x7FFFFFFF; + } + + /* See SMBIOS 2.7.0 section 7.18 - Memory Device (Type 17) */ + if (size_KB <= 0x7FFF) { + /* Can represent up to 32767KB with the top bit set */ + type17->size = size_KB | (1 << 15); + } else if (size_MB < 0x7FFF) { + /* Can represent up to 32766MB with the top bit unset */ + type17->size = size_MB & 0x7FFF; + } else { + type17->size = 0x7FFF; + /* + * Can represent up to 2147483647MB (~2PB) + * The top bit is reserved + */ + type17->xsize = size_MB & 0x7FFFFFFF; } return (0);