From nobody Wed Apr 26 07:59:34 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 4Q5rqp67Vfz47PMW; Wed, 26 Apr 2023 07:59:34 +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 4Q5rqp3qqYz4bVv; Wed, 26 Apr 2023 07:59:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682495974; 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=oqpF2ZfJ9OC1RLBzOJ/6T8D/hULL1Ti0eN0C42jC+cw=; b=kjH11KQRwU3MRcgmjtJiD6cW6PvChWFCWM3Of28852U6pvkJ1yG6mETPFWBS3+Ypot+w1F 76ZmPzfwjaHnHe8vT9BPN7bAGXIuAREZFHRYCR9whaYlpucEJNEwgqGYK7oHXgkBmQGB1B 4hF5GOMIWgo8cRX/NN9L0aTwrigR5iR4/MOQQoj+rNaSt+rE6rYGF9Gfa+d88a3wv623eB K7SkudCY6uDMBcGnIlFkZe/xp17QfPgL+whF3tUadMZURoEVYiiQCpOJl+w3/cuU2LVrlr /BvZG2lOjICVCN0oCTjyF3IQYFkfBri6/n+RcFtw1J1x0K9gNcq3WSJ4zgEeWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682495974; 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=oqpF2ZfJ9OC1RLBzOJ/6T8D/hULL1Ti0eN0C42jC+cw=; b=lKWHYCR54MvhFoxxGNIjJCpM+QZAURkVGAzX4mdTByOgCpVWcV+eYqLVelYwypJLJZwgcx GITAOeHL4um37RSPOE9D9OR6RQPlLr+IesKgIYbY0V2ksu2SEXcAuwSiJhZWYWF5TGT2zb nEmLhHko8wcvB2G9wwOhdjYxuddIyM+Gd4N+GOpsRphS27odWKsrh+8s4ZcpTDQtnjnCB5 ow6pGXw1iFkarstxz7PC1J3Gv5uZ0UCe41QKGgCtw4rLqxS3/xnpBNjFbgOq8hYhKzUolv p58wknGADyNovNWTjc7Kv8374hl5NP6Z5GE2Jpgo/FJGzE7bIpLwPrQSabPgVw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682495974; a=rsa-sha256; cv=none; b=gRzQjwuX5fYzIKtt2K3K9rDSEH0WC8EVd+P/KgarIDl02E/EQ/mXbyDm+W/InPImjOcHcM EIiHk/WJdg+SzCX3pyNhTS4zeiueD4E47JzJSzOMhWzAqjFXdyjg5VTGUILzPEIOfgFDHA 0VKGQfEIp72HETfRxD2QSNqu/bgOVY2W2eKfITHU0mb+nr+nEPdugjPyGXYUKqYboPxhC5 WtPZ99q+wdYPtIkHNSvSQZvBhxFo27VBQuez0ycEo4RCCFgZymnBBVm9JsQDSea/EnHt7X 0Y5XXp0+kmiDe+OJzBrx08yFH/DfEcZyWoNz1MfRVhG3XlaUZ99msW3EM2HstQ== 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 4Q5rqp2m2wzRXF; Wed, 26 Apr 2023 07:59:34 +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 33Q7xYx4059706; Wed, 26 Apr 2023 07:59:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33Q7xYZV059705; Wed, 26 Apr 2023 07:59:34 GMT (envelope-from git) Date: Wed, 26 Apr 2023 07:59:34 GMT Message-Id: <202304260759.33Q7xYZV059705@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 059af92a300f - main - 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/main X-Git-Reftype: branch X-Git-Commit: 059af92a300f76653048c042559f7d7d8fd8f99c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=059af92a300f76653048c042559f7d7d8fd8f99c commit 059af92a300f76653048c042559f7d7d8fd8f99c Author: Corvin Köhne AuthorDate: 2021-09-09 09:37:03 +0000 Commit: Corvin Köhne CommitDate: 2023-04-26 07:58: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 --- 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); }