From nobody Mon Nov 21 08:31:45 2022 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 4NG0wx5l48z4j4B7; Mon, 21 Nov 2022 08:31: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NG0wx512rz3Mfc; Mon, 21 Nov 2022 08:31:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669019505; 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=KYOdPMw9ou0zi9X5i0pf3Cb4YrVb+97lUY26rjaEZ+U=; b=XcqKzLQCOuwpor4WAK64KMHeLt0Y6FpqWz5BdJwozuU1dXPsYKDf/b3iQjbIuzgnqCI0jO C0it5U0qugFTHPAM88Wl3Q73tvnSoKwzEjEdQQUnw3qBeS09mm+gJ2Kwbd+BrG7Ruqf/Is JV0kWUXtE+R1L3nuf49splSfNtBU3jmaK4+ZFqhDFg0bWIitnCGphog7rrSNalkHc+T5b/ HJ+WBnJu2ZahftvsPCzL0t67yz7rWm//z4s1BMStkfJ8I9yJ3A7zM5OIhGPX8GZcTgjK+g 4NNsVW9bbvdeswFkMFdWKT1oBox43pPRExZt7xPZne5y2LMUsT+v7VOykiXq6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669019505; 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=KYOdPMw9ou0zi9X5i0pf3Cb4YrVb+97lUY26rjaEZ+U=; b=yDZbpAoLfyvRNuhTRj0Of/UMp7880joXo0XJBCyOZWSDsVMVW94MeWJ7lR/uO2PDoeuHlH eHpoNOc10eiaYVQnUuje0zpGW+8Kc0pI3NazkoaB14k1I6ec8ROLxCxFaMe1NTTknS3Wum ypEuib5zEEHweqjXqTNDT9rB0rzBvlPZ4FyhI+rixHykcGhQtvaB6a/O6zSeM7tmnUi4uG 3Fv83FdtLHnHCpYv7yrvLe9a1z/uTmSDwGX3eb0tK3luwNobHCrLL81k2E16u1Az4GaYr2 zvwmPOuv8nsSbZqL5QbHWhqeVyMIzXwUigQgNDs6E55++H2/wDm6dYi+II3xMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669019505; a=rsa-sha256; cv=none; b=CSK5/jxv2H4cP6pRogsa/S5HMgGPJHjvrV0Af7tFc9+Zkw9Djd2Ok3TERKsA0ShJVxTL4+ XxAwtR1EwFfzai1vrkrntPjtsho5GulAF0CVGNpPlQrsghpZ3+KFKMFjgz73s0Uh5rcdPf DJNBx3X71R55aJ8bagEGRYaeb359LYLLgMYD36SsWyPu8k9O2F3gdYOXU8c0/HY6XstESj 5Iab0SPYBu4jLkEPO3nnN8GYjs4RGrPRAp3kkGGBoM8eGM843ockd14udmL9nTaxgy+ZW+ M2siUmySg3kIk0Ex6JIUeGc7OJCpU8aumdiVpAnBsm8jd5z4JIV3cwL17CnBWg== 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 4NG0wx43dmzwkn; Mon, 21 Nov 2022 08:31:45 +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 2AL8VjfR028425; Mon, 21 Nov 2022 08:31:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AL8VjRq028412; Mon, 21 Nov 2022 08:31:45 GMT (envelope-from git) Date: Mon, 21 Nov 2022 08:31:45 GMT Message-Id: <202211210831.2AL8VjRq028412@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: 67654ffd4424 - main - bhyve: use dynamic ACPI table offsets 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: 67654ffd4424a55ab04091f0ccdf472516c140d8 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=67654ffd4424a55ab04091f0ccdf472516c140d8 commit 67654ffd4424a55ab04091f0ccdf472516c140d8 Author: Corvin Köhne AuthorDate: 2022-04-06 09:10:44 +0000 Commit: Corvin Köhne CommitDate: 2022-11-21 08:28:01 +0000 bhyve: use dynamic ACPI table offsets Now that all ACPI tables are build by basl, basl can dynamically calculate the offset for each table. Reviewed by: jhb, markj (older version) Approved by: manu (mentor) MFC after: 2 weeks Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D37002 --- usr.sbin/bhyve/acpi.c | 71 +++++++++++---------------------------------------- usr.sbin/bhyve/basl.c | 17 ++++++++---- usr.sbin/bhyve/basl.h | 2 +- 3 files changed, 28 insertions(+), 62 deletions(-) diff --git a/usr.sbin/bhyve/acpi.c b/usr.sbin/bhyve/acpi.c index 4f48986fd936..d8d021f4bb81 100644 --- a/usr.sbin/bhyve/acpi.c +++ b/usr.sbin/bhyve/acpi.c @@ -36,20 +36,6 @@ * * The tables are placed in the guest's ROM area just below 1MB physical, * above the MPTable. - * - * Layout (No longer correct at FADT and beyond due to properly - * calculating the size of the MADT to allow for changes to - * VM_MAXCPU above 21 which overflows this layout.) - * ------ - * RSDP -> 0xf2400 (36 bytes fixed) - * RSDT -> 0xf2440 (36 bytes + 4*7 table addrs, 4 used) - * XSDT -> 0xf2480 (36 bytes + 8*7 table addrs, 4 used) - * MADT -> 0xf2500 (depends on #CPUs) - * FADT -> 0xf2600 (268 bytes) - * HPET -> 0xf2740 (56 bytes) - * MCFG -> 0xf2780 (60 bytes) - * FACS -> 0xf27C0 (64 bytes) - * DSDT -> 0xf2800 (variable - can go up to 0x100000) */ #include @@ -78,32 +64,6 @@ __FBSDID("$FreeBSD$"); #include "pci_emul.h" #include "vmgenc.h" -/* - * Define the base address of the ACPI tables, the sizes of some tables, - * and the offsets to the individual tables, - */ -#define RSDT_OFFSET 0x040 -#define XSDT_OFFSET 0x080 -#define MADT_OFFSET 0x100 -/* - * The MADT consists of: - * 44 Fixed Header - * 8 * maxcpu Processor Local APIC entries - * 12 I/O APIC entry - * 2 * 10 Interrupt Source Override entries - * 6 Local APIC NMI entry - */ -#define MADT_SIZE roundup2((44 + basl_ncpu*8 + 12 + 2*10 + 6), 0x100) -#define FADT_OFFSET (MADT_OFFSET + MADT_SIZE) -#define FADT_SIZE 0x140 -#define HPET_OFFSET (FADT_OFFSET + FADT_SIZE) -#define HPET_SIZE 0x40 -#define MCFG_OFFSET (HPET_OFFSET + HPET_SIZE) -#define MCFG_SIZE 0x40 -#define FACS_OFFSET (MCFG_OFFSET + MCFG_SIZE) -#define FACS_SIZE 0x40 -#define DSDT_OFFSET (FACS_OFFSET + FACS_SIZE) - #define BHYVE_ASL_TEMPLATE "bhyve.XXXXXXX" #define BHYVE_ASL_SUFFIX ".aml" #define BHYVE_ASL_COMPILER "/usr/sbin/iasl" @@ -334,7 +294,7 @@ basl_end(struct basl_fio *in, struct basl_fio *out) } static int -basl_load(struct vmctx *ctx, int fd, uint64_t off) +basl_load(struct vmctx *ctx, int fd) { struct stat sb; void *addr; @@ -353,15 +313,14 @@ basl_load(struct vmctx *ctx, int fd, uint64_t off) uint8_t name[ACPI_NAMESEG_SIZE + 1] = { 0 }; memcpy(name, addr, sizeof(name) - 1 /* last char is '\0' */); - BASL_EXEC( - basl_table_create(&table, ctx, name, BASL_TABLE_ALIGNMENT, off)); + BASL_EXEC(basl_table_create(&table, ctx, name, BASL_TABLE_ALIGNMENT)); BASL_EXEC(basl_table_append_bytes(table, addr, sb.st_size)); return (0); } static int -basl_compile(struct vmctx *ctx, int (*fwrite_section)(FILE *), uint64_t offset) +basl_compile(struct vmctx *ctx, int (*fwrite_section)(FILE *)) { struct basl_fio io[2]; static char iaslbuf[3*MAXPATHLEN + 10]; @@ -395,7 +354,7 @@ basl_compile(struct vmctx *ctx, int (*fwrite_section)(FILE *), uint64_t offset) * Copy the aml output file into guest * memory at the specified location */ - err = basl_load(ctx, io[1].fd, offset); + err = basl_load(ctx, io[1].fd); } } basl_end(&io[0], &io[1]); @@ -453,7 +412,7 @@ basl_make_templates(void) static int build_dsdt(struct vmctx *const ctx) { - BASL_EXEC(basl_compile(ctx, basl_fwrite_dsdt, DSDT_OFFSET)); + BASL_EXEC(basl_compile(ctx, basl_fwrite_dsdt)); return (0); } @@ -465,7 +424,7 @@ build_facs(struct vmctx *const ctx) struct basl_table *table; BASL_EXEC(basl_table_create(&table, ctx, ACPI_SIG_FACS, - BASL_TABLE_ALIGNMENT_FACS, FACS_OFFSET)); + BASL_TABLE_ALIGNMENT_FACS)); memset(&facs, 0, sizeof(facs)); memcpy(facs.Signature, ACPI_SIG_FACS, ACPI_NAMESEG_SIZE); @@ -483,7 +442,7 @@ build_fadt(struct vmctx *const ctx) struct basl_table *table; BASL_EXEC(basl_table_create(&table, ctx, ACPI_SIG_FADT, - BASL_TABLE_ALIGNMENT, FADT_OFFSET)); + BASL_TABLE_ALIGNMENT)); memset(&fadt, 0, sizeof(fadt)); BASL_EXEC(basl_table_append_header(table, ACPI_SIG_FADT, 5, 1)); @@ -559,7 +518,7 @@ build_hpet(struct vmctx *const ctx) struct basl_table *table; BASL_EXEC(basl_table_create(&table, ctx, ACPI_SIG_HPET, - BASL_TABLE_ALIGNMENT, HPET_OFFSET)); + BASL_TABLE_ALIGNMENT)); memset(&hpet, 0, sizeof(hpet)); BASL_EXEC(basl_table_append_header(table, ACPI_SIG_HPET, 1, 1)); @@ -588,7 +547,7 @@ build_madt(struct vmctx *const ctx) struct basl_table *table; BASL_EXEC(basl_table_create(&table, ctx, ACPI_SIG_MADT, - BASL_TABLE_ALIGNMENT, MADT_OFFSET)); + BASL_TABLE_ALIGNMENT)); memset(&madt, 0, sizeof(madt)); BASL_EXEC(basl_table_append_header(table, ACPI_SIG_MADT, 1, 1)); @@ -663,7 +622,7 @@ build_mcfg(struct vmctx *const ctx) struct basl_table *table; BASL_EXEC(basl_table_create(&table, ctx, ACPI_SIG_MCFG, - BASL_TABLE_ALIGNMENT, MCFG_OFFSET)); + BASL_TABLE_ALIGNMENT)); memset(&mcfg, 0, sizeof(mcfg)); BASL_EXEC(basl_table_append_header(table, ACPI_SIG_MCFG, 1, 1)); @@ -690,7 +649,7 @@ build_rsdp(struct vmctx *const ctx) struct basl_table *table; BASL_EXEC(basl_table_create(&table, ctx, ACPI_RSDP_NAME, - BASL_TABLE_ALIGNMENT, 0)); + BASL_TABLE_ALIGNMENT)); memset(&rsdp, 0, sizeof(rsdp)); memcpy(rsdp.Signature, ACPI_SIG_RSDP, 8); @@ -723,8 +682,8 @@ build_rsdp(struct vmctx *const ctx) static int build_rsdt(struct vmctx *const ctx) { - BASL_EXEC(basl_table_create(&rsdt, ctx, ACPI_SIG_RSDT, - BASL_TABLE_ALIGNMENT, RSDT_OFFSET)); + BASL_EXEC( + basl_table_create(&rsdt, ctx, ACPI_SIG_RSDT, BASL_TABLE_ALIGNMENT)); /* Header */ BASL_EXEC(basl_table_append_header(rsdt, ACPI_SIG_RSDT, 1, 1)); @@ -736,8 +695,8 @@ build_rsdt(struct vmctx *const ctx) static int build_xsdt(struct vmctx *const ctx) { - BASL_EXEC(basl_table_create(&xsdt, ctx, ACPI_SIG_XSDT, - BASL_TABLE_ALIGNMENT, XSDT_OFFSET)); + BASL_EXEC( + basl_table_create(&xsdt, ctx, ACPI_SIG_XSDT, BASL_TABLE_ALIGNMENT)); /* Header */ BASL_EXEC(basl_table_append_header(xsdt, ACPI_SIG_XSDT, 1, 1)); diff --git a/usr.sbin/bhyve/basl.c b/usr.sbin/bhyve/basl.c index 3333ecbc870c..e002c3724ef0 100644 --- a/usr.sbin/bhyve/basl.c +++ b/usr.sbin/bhyve/basl.c @@ -136,10 +136,18 @@ basl_fill_gas(ACPI_GENERIC_ADDRESS *const gas, const uint8_t space_id, } static int -basl_finish_install_guest_tables(struct basl_table *const table) +basl_finish_install_guest_tables(struct basl_table *const table, uint32_t *const off) { void *gva; + table->off = roundup2(*off, table->alignment); + *off = table->off + table->len; + if (*off <= table->off) { + warnx("%s: invalid table length 0x%8x @ offset 0x%8x", __func__, + table->len, table->off); + return (EFAULT); + } + /* * Install ACPI tables directly in guest memory for use by guests which * do not boot via EFI. EFI ROMs provide a pointer to the firmware @@ -303,6 +311,7 @@ int basl_finish(void) { struct basl_table *table; + uint32_t off = 0; if (STAILQ_EMPTY(&basl_tables)) { warnx("%s: no ACPI tables found", __func__); @@ -316,7 +325,7 @@ basl_finish(void) */ STAILQ_FOREACH(table, &basl_tables, chain) { BASL_EXEC(basl_finish_set_length(table)); - BASL_EXEC(basl_finish_install_guest_tables(table)); + BASL_EXEC(basl_finish_install_guest_tables(table, &off)); } STAILQ_FOREACH(table, &basl_tables, chain) { BASL_EXEC(basl_finish_patch_pointers(table)); @@ -553,8 +562,7 @@ basl_table_append_pointer(struct basl_table *const table, int basl_table_create(struct basl_table **const table, struct vmctx *ctx, - const uint8_t *const name, const uint32_t alignment, - const uint32_t off) + const uint8_t *const name, const uint32_t alignment) { struct basl_table *new_table; @@ -572,7 +580,6 @@ basl_table_create(struct basl_table **const table, struct vmctx *ctx, "etc/acpi/%s", name); new_table->alignment = alignment; - new_table->off = off; STAILQ_INIT(&new_table->checksums); STAILQ_INIT(&new_table->lengths); diff --git a/usr.sbin/bhyve/basl.h b/usr.sbin/bhyve/basl.h index 9c7ba0c84229..71b3e6dc07fc 100644 --- a/usr.sbin/bhyve/basl.h +++ b/usr.sbin/bhyve/basl.h @@ -70,4 +70,4 @@ int basl_table_append_length(struct basl_table *table, uint8_t size); int basl_table_append_pointer(struct basl_table *table, const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size); int basl_table_create(struct basl_table **table, struct vmctx *ctx, - const uint8_t *name, uint32_t alignment, uint32_t off); + const uint8_t *name, uint32_t alignment);