From nobody Mon May 08 08:25:29 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QFDr93Gtkz49ZQb; Mon, 8 May 2023 08:25:29 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QFDr92Jvfz3l6B; Mon, 8 May 2023 08:25:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683534329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rs3M5HeUzN3y8599aOllIivoDuqgZAPAZ8bEYwcmU2g=; b=AIHH/sQjAEknrl/r6g9wBVF+6gDrTo7HessqA2pFVDRzl/lxJYeYmiX0CBjoz3PwbJRyV8 yBeioI3N6PnLDUsrerjFbCTm/99MCdJzPQTCH537uYvBbVb9bWM0o6b5z2mGM/WYNvPuRR cpsnqkT0kcMKowM5s3Pfgnv22vA7pQLfWkIbnF96Z1Q3KDczWCvm4HY/9ruL2FLMtz8yPI sNXF1jdRu9LBOnqWFMty6gxz6XIIsqWdQDvGvHGmK7cwPz73IGvJ4BlYpXbGaqMrkC/OGC xkgO15H2wBvnOEepM8R5aE6KMEVhUbMDvyr+uM5w7TuGzWbdgxc4I5OJ4WBt8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683534329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rs3M5HeUzN3y8599aOllIivoDuqgZAPAZ8bEYwcmU2g=; b=Y7nclbK8zt99LM8vbPmUJEeDGrKlkzl6S5SDzmGkQb7PUmDjoEx0og0QGwr/Mn+qVsJOPR iqHvqJdXv71am6U13nRYIwCirRV5V1nn1Q2VjqT3p3oXvL9RZs6SxeSWUDJSh/qCMh6GBw LQ5zz/3cXmofVyKUZoRNfJ2moI1S7vB8VGMUjJZ3ZAvQp4vT3pv8NoOUVOgdDufsZEgkxj ivd+BTr4wfYo5f0w4LfdFKFOMChpmMd3Y2FizJ48zCGzOH7YcLFVfT0OHwPO/w0UMTuhKh soU3bJCO9rMQKnYPYqfqt/t+ndmY0AG17aTp6Dngbj6dJEOVk1lSm9TR+hMH8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683534329; a=rsa-sha256; cv=none; b=eA8F+lcFOqqrnyWMp/ypN8X4vt/f5iIB2rVlpLX0kONH3djlb7Jy3y0OoOey+jMAexKiVZ +M2eQEGdnuOuqs8hBy/KXzE59Gh72HfhCF8/ZLiy3l+r9Wu5cMqpEtpepYOCQniIs/ltwT m6U7xAvEAYhc5BhKBgugD+Gfcd5IxdUmHUsfjBOfDqqbF4SQ6HeLS0uVkYmtOIpksgkTsw QolezLp8pvN6CHr43W44Ck9avBBIbl9rbaumR+KuvZI9VlMFdvbr5HiYyyuDRDNKgsEt50 aSB0FztNBtmqUYe6ltMqszZk4AOyyaGxEXkF+xLJz73mlf3nsCdGKhXXxmtVOw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QFDr91PwFzt6T; Mon, 8 May 2023 08:25:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 3488PTvh050382; Mon, 8 May 2023 08:25:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3488PTJK050381; Mon, 8 May 2023 08:25:29 GMT (envelope-from git) Date: Mon, 8 May 2023 08:25:29 GMT Message-Id: <202305080825.3488PTJK050381@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 951ca31bf66b - stable/13 - bhyve: add common memory holes to E820 table List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 951ca31bf66bdc3eea8cf1a8d4262a9d5db61904 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=951ca31bf66bdc3eea8cf1a8d4262a9d5db61904 commit 951ca31bf66bdc3eea8cf1a8d4262a9d5db61904 Author: Corvin Köhne AuthorDate: 2021-09-09 09:37:03 +0000 Commit: Corvin Köhne CommitDate: 2023-05-08 08:21:31 +0000 bhyve: add common memory holes to E820 table The VGA and the ROM memory ranges can't be used as system memory. For that reason, remove them from the E820 table. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D39546 (cherry picked from commit 059af92a300f76653048c042559f7d7d8fd8f99c) --- usr.sbin/bhyve/e820.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/usr.sbin/bhyve/e820.c b/usr.sbin/bhyve/e820.c index 746d34d6521c..95b83c056b9b 100644 --- a/usr.sbin/bhyve/e820.c +++ b/usr.sbin/bhyve/e820.c @@ -26,6 +26,16 @@ #define MB (1024 * KB) #define GB (1024 * MB) +/* + * Fix E820 memory holes: + * [ A0000, C0000) VGA + * [ C0000, 100000) ROM + */ +#define E820_VGA_MEM_BASE 0xA0000 +#define E820_VGA_MEM_END 0xC0000 +#define E820_ROM_MEM_BASE 0xC0000 +#define E820_ROM_MEM_END 0x100000 + struct e820_element { TAILQ_ENTRY(e820_element) chain; uint64_t base; @@ -204,6 +214,74 @@ e820_add_entry(const uint64_t base, const uint64_t end, return (0); } +static int +e820_add_memory_hole(const uint64_t base, const uint64_t end) +{ + struct e820_element *element; + struct e820_element *ram_element; + + assert(end >= base); + + /* + * E820 table should be always sorted in ascending order. Therefore, + * search for an element which end is larger than the base parameter. + */ + TAILQ_FOREACH(element, &e820_table, chain) { + if (element->end > base) { + break; + } + } + + if (element == NULL || end <= element->base) { + /* Nothing to do. Hole already exists */ + return (0); + } + + /* Memory holes are only allowed in system memory */ + assert(element->type == E820_TYPE_MEMORY); + + if (base == element->base) { + /* + * New hole at system memory base boundary. + * + * Old table: + * [ 0x1000, 0x4000] RAM + * New table: + * [ 0x2000, 0x4000] RAM + */ + element->base = end; + } else if (end == element->end) { + /* + * New hole at system memory end boundary. + * + * Old table: + * [ 0x1000, 0x4000] RAM + * New table: + * [ 0x1000, 0x3000] RAM + */ + element->end = base; + } else { + /* + * New hole inside system memory entry. Split the system memory. + * + * Old table: + * [ 0x1000, 0x4000] RAM <-- element + * New table: + * [ 0x1000, 0x2000] RAM + * [ 0x3000, 0x4000] RAM <-- element + */ + ram_element = e820_element_alloc(element->base, base, + E820_TYPE_MEMORY); + if (ram_element == NULL) { + return (ENOMEM); + } + TAILQ_INSERT_BEFORE(element, ram_element, chain); + element->base = end; + } + + return (0); +} + int e820_init(struct vmctx *const ctx) { @@ -229,5 +307,17 @@ e820_init(struct vmctx *const ctx) } } + error = e820_add_memory_hole(E820_VGA_MEM_BASE, E820_VGA_MEM_END); + if (error) { + warnx("%s: Could not add VGA memory", __func__); + return (error); + } + + error = e820_add_memory_hole(E820_ROM_MEM_BASE, E820_ROM_MEM_END); + if (error) { + warnx("%s: Could not add ROM area", __func__); + return (error); + } + return (0); }