git: f281bda11a1a - stable/13 - bhyve: use a fixed 32 bit BAR base address

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 14 Jan 2022 14:20:41 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=f281bda11a1a01abd911053325407205cffcf808

commit f281bda11a1a01abd911053325407205cffcf808
Author:     Corvin Köhne <CorvinK@beckhoff.com>
AuthorDate: 2021-11-22 15:24:47 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-14 14:18:03 +0000

    bhyve: use a fixed 32 bit BAR base address
    
    OVMF always uses 0xC0000000 as base address for 32 bit PCI MMIO space.
    For that reason, we should use that address too.
    
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D31051
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    
    (cherry picked from commit 5cf21e48ccf114928da9c6564c7e5dec7d6119c5)
    
    bhyve: Fix compile
    
    We need err.h
    
    Fixes:  5cf21e48ccf11 ("bhyve: use a fixed 32 bit BAR base address")
    Sponsored by:   Bechoff Automation GmbH & Co. KG
    
    (cherry picked from commit fc7207c87795da4533dc7f97287638f6da85b3b0)
---
 usr.sbin/bhyve/pci_emul.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
index cbcd8154b2b1..0b46bcc6200e 100644
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/linker_set.h>
 
 #include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <pthread.h>
 #include <stdio.h>
@@ -43,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include <strings.h>
 #include <assert.h>
 #include <stdbool.h>
+#include <sysexits.h>
 
 #include <machine/vmm.h>
 #include <machine/vmm_snapshot.h>
@@ -110,6 +112,11 @@ static uint64_t pci_emul_memlim64;
 #define	PCI_EMUL_ECFG_SIZE	(MAXBUSES * 1024 * 1024)    /* 1MB per bus */
 SYSRES_MEM(PCI_EMUL_ECFG_BASE, PCI_EMUL_ECFG_SIZE);
 
+/*
+ * OVMF always uses 0xC0000000 as base address for 32 bit PCI MMIO. Don't
+ * change this address without changing it in OVMF.
+ */
+#define PCI_EMUL_MEMBASE32 0xC0000000
 #define	PCI_EMUL_MEMLIMIT32	PCI_EMUL_ECFG_BASE
 #define PCI_EMUL_MEMSIZE64	(32*GB)
 
@@ -1156,8 +1163,11 @@ init_pci(struct vmctx *ctx)
 	int bus, slot, func;
 	int error;
 
+	if (vm_get_lowmem_limit(ctx) > PCI_EMUL_MEMBASE32)
+		errx(EX_OSERR, "Invalid lowmem limit");
+
 	pci_emul_iobase = PCI_EMUL_IOBASE;
-	pci_emul_membase32 = vm_get_lowmem_limit(ctx);
+	pci_emul_membase32 = PCI_EMUL_MEMBASE32;
 
 	pci_emul_membase64 = 4*GB + vm_get_highmem_size(ctx);
 	pci_emul_membase64 = roundup2(pci_emul_membase64, PCI_EMUL_MEMSIZE64);
@@ -1262,8 +1272,8 @@ init_pci(struct vmctx *ctx)
 	/*
 	 * The guest physical memory map looks like the following:
 	 * [0,		    lowmem)		guest system memory
-	 * [lowmem,	    lowmem_limit)	memory hole (may be absent)
-	 * [lowmem_limit,   0xE0000000)		PCI hole (32-bit BAR allocation)
+	 * [lowmem,	    0xC0000000)		memory hole (may be absent)
+	 * [0xC0000000,     0xE0000000)		PCI hole (32-bit BAR allocation)
 	 * [0xE0000000,	    0xF0000000)		PCI extended config window
 	 * [0xF0000000,	    4GB)		LAPIC, IOAPIC, HPET, firmware
 	 * [4GB,	    4GB + highmem)