From nobody Tue Oct 22 12:18:45 2024 X-Original-To: dev-commits-src-main@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 4XXrnK6pdkz5FF1f; Tue, 22 Oct 2024 12:18:45 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XXrnK4sNXz4ts2; Tue, 22 Oct 2024 12:18:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729599525; 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=cKX+jzOQp8smUNkBnN9de6BB5SJhc0qJdWlGCh+N5qo=; b=qKBIF0i5tuu0BxjYd5zVoZHzwXaXnG68kGrD+5VXfYeAErm8CMLByqgcdtvj82Zu+rMuj4 JVJp5NnX9G4s8MZsMBkHhOvX7nocQR3R04PLzVcSmvwGEPwSqC7sZRu/+YD+PdLZI2qHfB INtFr3DlWn317EWeNiepE9FHnku0/I127vi4LLd39M+lHuDPOTB5RAfUi3KHg1vQ8KVn80 4XYyxJAC27Db+wnSnXz5RwfJlN/t0yTJqvudZuUmTfVjnuM6vIVlnTakIz0piKqJwof94t 3EyeAFi8Gz20VqLY6XDvfviDsDF1UFK410RRjSVxShziu/L8hN5RcHn4GBP8NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729599525; 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=cKX+jzOQp8smUNkBnN9de6BB5SJhc0qJdWlGCh+N5qo=; b=l8zG0Lg1QuQmrt/tX1NadnoxgrWOBcsccX0pV7MiqdddZM48weSAPRrUKPX3EeZoJjBfrn KKHtYXCYDhFMZ8AX9p3TSatL0JjSPMnQ8A7/80gC+5412WOPSiwLNpJOJZz2FFCOglDrs0 e1SejIQjO1q+NHO1oKiO0RgRxVMg+8V6R85iZ+G1XomLoqmAoikE/6Ws/1NnoC+F5UQBzI 3V8ERJXSXBucB6H/diFx2PuSqT8evN6ee+afaIPCKM6q+jOImBs6AR4rhC5ONT6rvTN2bN CxcqrFuGBwl5P5qRMwnKFQmv7P+0CGIzZSAuECYGPAmBVGJgiCxQ22zqVUofYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729599525; a=rsa-sha256; cv=none; b=u/KBt3BaVlpp9bg8EY9ow7IanaIK10dchnJ2etPQkrZV57h+A8hwSQLtwW5BXtRrO2X9dA JL+jXNsDNjewKwWeQB68EDiSuH+5O2Qsw5mNmjvcim0iwXrf9zVUoR44CJORJnmIGXkc9E +zki48hd0YCj9QmGAVC+oqKxhJ7eUaakVtNHhjU7V/jfue6fN4jmhnhpJTRR/5uBaLeDwb luut7D6SrR/+bHlr+ggfutH7rHdDwL2RAI39pw40RdWx2mQObQPUqQrBf6MZt81kDvQBEU boGTa+3FJw5vZN/MvcPDoFI/cmzQjAnjdLp5cbrub2sk6aQE7v0kUUW2BMOnWA== 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 4XXrnK424Bz1Ctm; Tue, 22 Oct 2024 12:18:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49MCIjX7003732; Tue, 22 Oct 2024 12:18:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49MCIjwF003729; Tue, 22 Oct 2024 12:18:45 GMT (envelope-from git) Date: Tue, 22 Oct 2024 12:18:45 GMT Message-Id: <202410221218.49MCIjwF003729@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Corvin =?utf-8?Q?K=C3=B6hne?= Subject: git: 08139140c5f9 - main - bhyve: merge adjacent E820 entries List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 08139140c5f96fd9deb7a8de7a534bccf9a1d0c8 Auto-Submitted: auto-generated The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=08139140c5f96fd9deb7a8de7a534bccf9a1d0c8 commit 08139140c5f96fd9deb7a8de7a534bccf9a1d0c8 Author: Corvin Köhne AuthorDate: 2023-12-19 14:01:45 +0000 Commit: Corvin Köhne CommitDate: 2024-10-22 12:17:02 +0000 bhyve: merge adjacent E820 entries EDKII can allocate adjacent E820 entries only if they are at a page boundary. For some unknown and probably strange reasons, Intel puts it's OpRegion at an offset of 0x18 bytes. If the VBT lays directly behind the OpRegion, we're going to try allocating two adjacent E820 sharing the same page. This causes EDKII to do not properly allocate those entries. A Linux guest then isn't able to map the VBT and those fails to find it. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D45336 --- usr.sbin/bhyve/amd64/e820.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/usr.sbin/bhyve/amd64/e820.c b/usr.sbin/bhyve/amd64/e820.c index 148cae72ca6e..2fad22865ba6 100644 --- a/usr.sbin/bhyve/amd64/e820.c +++ b/usr.sbin/bhyve/amd64/e820.c @@ -156,6 +156,7 @@ e820_add_entry(const uint64_t base, const uint64_t end, { struct e820_element *new_element; struct e820_element *element; + struct e820_element *sib_element; struct e820_element *ram_element; assert(end >= base); @@ -273,6 +274,33 @@ e820_add_entry(const uint64_t base, const uint64_t end, element->base = end; } + /* + * If the previous element has the same type and ends at our base + * boundary, we can merge both entries. + */ + sib_element = TAILQ_PREV(new_element, e820_table, chain); + if (sib_element != NULL && + sib_element->type == new_element->type && + sib_element->end == new_element->base) { + new_element->base = sib_element->base; + TAILQ_REMOVE(&e820_table, sib_element, chain); + free(sib_element); + } + + /* + * If the next element has the same type and starts at our end + * boundary, we can merge both entries. + */ + sib_element = TAILQ_NEXT(new_element, chain); + if (sib_element != NULL && + sib_element->type == new_element->type && + sib_element->base == new_element->end) { + /* Merge new element into subsequent one. */ + new_element->end = sib_element->end; + TAILQ_REMOVE(&e820_table, sib_element, chain); + free(sib_element); + } + return (0); }