git: e497fe865703 - main - bhyve: Use vm_get_highmem_base() instead of hard-coding the value

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 10 Apr 2024 15:19:01 UTC
The branch main has been updated by markj:

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

commit e497fe8657031bf52a27d28943e6517922e330ba
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-04-03 16:51:37 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-04-10 15:17:55 +0000

    bhyve: Use vm_get_highmem_base() instead of hard-coding the value
    
    This reduces the coupling between libvmmapi (which creates the highmem
    segment) and bhyve, in preparation for the arm64 port.
    
    No functional change intended.
    
    Reviewed by:    corvink, jhb
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D40992
---
 usr.sbin/bhyve/bootrom.c   | 7 +++++--
 usr.sbin/bhyve/pci_emul.c  | 3 ++-
 usr.sbin/bhyve/smbiostbl.c | 7 ++++---
 usr.sbin/bhyve/snapshot.c  | 4 ++--
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/usr.sbin/bhyve/bootrom.c b/usr.sbin/bhyve/bootrom.c
index 64f1921f901e..1d461ba76597 100644
--- a/usr.sbin/bhyve/bootrom.c
+++ b/usr.sbin/bhyve/bootrom.c
@@ -118,12 +118,15 @@ bootrom_var_mem_handler(struct vcpu *vcpu __unused, int dir, uint64_t addr,
 void
 init_bootrom(struct vmctx *ctx)
 {
+	vm_paddr_t highmem;
+
 	romptr = vm_create_devmem(ctx, VM_BOOTROM, "bootrom", BOOTROM_SIZE);
 	if (romptr == MAP_FAILED)
 		err(4, "%s: vm_create_devmem", __func__);
-	gpa_base = (1ULL << 32) - BOOTROM_SIZE;
+	highmem = vm_get_highmem_base(ctx);
+	gpa_base = highmem - BOOTROM_SIZE;
 	gpa_allocbot = gpa_base;
-	gpa_alloctop = (1ULL << 32) - 1;
+	gpa_alloctop = highmem - 1;
 }
 
 int
diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
index 3d6797c7168e..e5e9e56cc3c3 100644
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -1509,7 +1509,8 @@ init_pci(struct vmctx *ctx)
 	pci_emul_iobase = PCI_EMUL_IOBASE;
 	pci_emul_membase32 = PCI_EMUL_MEMBASE32;
 
-	pci_emul_membase64 = 4*GB + vm_get_highmem_size(ctx);
+	pci_emul_membase64 = vm_get_highmem_base(ctx) +
+	    vm_get_highmem_size(ctx);
 	pci_emul_membase64 = roundup2(pci_emul_membase64, PCI_EMUL_MEMSIZE64);
 	pci_emul_memlim64 = pci_emul_membase64 + PCI_EMUL_MEMSIZE64;
 
diff --git a/usr.sbin/bhyve/smbiostbl.c b/usr.sbin/bhyve/smbiostbl.c
index 4a98278d5e61..e09fbc95fc9e 100644
--- a/usr.sbin/bhyve/smbiostbl.c
+++ b/usr.sbin/bhyve/smbiostbl.c
@@ -600,7 +600,7 @@ static struct smbios_template_entry smbios_template[] = {
 	{ NULL,NULL, NULL }
 };
 
-static uint64_t guest_lomem, guest_himem;
+static uint64_t guest_lomem, guest_himem, guest_himem_base;
 static uint16_t type16_handle;
 
 static int
@@ -831,8 +831,8 @@ smbios_type19_initializer(const struct smbios_structure *template_entry,
 		    curaddr, endaddr, n);
 		type19 = (struct smbios_table_type19 *)curaddr;
 		type19->arrayhand = type16_handle;
-		type19->xsaddr = 4*GB;
-		type19->xeaddr = type19->xsaddr + guest_himem;
+		type19->xsaddr = guest_himem_base;
+		type19->xeaddr = guest_himem_base + guest_himem;
 	}
 
 	return (0);
@@ -891,6 +891,7 @@ smbios_build(struct vmctx *ctx)
 
 	guest_lomem = vm_get_lowmem_size(ctx);
 	guest_himem = vm_get_highmem_size(ctx);
+	guest_himem_base = vm_get_highmem_base(ctx);
 
 	startaddr = paddr_guest2host(ctx, SMBIOS_BASE, SMBIOS_MAX_LENGTH);
 	if (startaddr == NULL) {
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index 9bb7873f1d25..997faa254284 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -758,8 +758,8 @@ vm_snapshot_mem(struct vmctx *ctx, int snapfd, size_t memsz, const bool op_wr)
 	if (highmem == 0)
 		goto done;
 
-	ret = vm_snapshot_mem_part(snapfd, lowmem, baseaddr + 4*GB,
-		highmem, totalmem, op_wr);
+	ret = vm_snapshot_mem_part(snapfd, lowmem,
+	    baseaddr + vm_get_highmem_base(ctx), highmem, totalmem, op_wr);
 	if (ret) {
 		fprintf(stderr, "%s: Could not %s highmem\r\n",
 		        __func__, op_wr ? "write" : "read");