Skip to contentSkip to conversation

hvf: allow slot size to increase

PATCH In review Joelle van Dyne 2 participants 4 messages Dec 3, 2025 – Jan 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hvf: allow slot size to increase

Instead of having a fixed limit of 32 slots, we allow the number of slots to expand. Currently there does not seem to be a need to add a limit, but if the allocation fails, we will abort. The KVM backend was used for inspiration here.

---
 include/system/hvf_int.h | 12 ++++++-
 accel/hvf/hvf-all.c      | 78 ++++++++++++++++++++++++++++++----------
 2 files changed, 71 insertions(+), 19 deletions(-)
include/system/hvf_int.h +11 -1
index 3d2be4092e..1d2616595c 100644
@@ -27,6 +27,7 @@ typedef hv_vcpuid_t hvf_vcpuid;
 /* hvf_slot flags */
 #define HVF_SLOT_LOG (1 << 0)
 
+/* Represent memory logically mapped by QEMU */
 typedef struct hvf_slot {
     uint64_t start;
     uint64_t size;
@@ -36,6 +37,14 @@ typedef struct hvf_slot {
     MemoryRegion *region;
 } hvf_slot;
 
+/* Represent memory currently mapped in HVF */
+typedef struct hvf_mac_slot {
+    int present;
+    uint64_t size;
+    uint64_t gpa_start;
+    uint64_t gva;
+} hvf_mac_slot;
+
 typedef struct hvf_vcpu_caps {
     uint64_t vmx_cap_pinbased;
     uint64_t vmx_cap_procbased;
@@ -48,7 +57,8 @@ typedef struct hvf_vcpu_caps {
 struct HVFState {
     AccelState parent_obj;
 
-    hvf_slot slots[32];
+    hvf_slot *slots;
+    hvf_mac_slot *mac_slots;
     int num_slots;
 
     hvf_vcpu_caps *hvf_caps;
accel/hvf/hvf-all.c +60 -18

116 lines not on this page · raw message

Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/1 hvf: warn when attempting to add unaligned page size

Instead of silently failing, we should print a warning so it is clear why a future guest access to that location might cause an exception.

---
 accel/hvf/hvf-all.c | 8 ++++++++
 1 file changed, 8 insertions(+)
accel/hvf/hvf-all.c +8 -0
index 0a4b498e83..7823d8416c 100644
@@ -112,6 +112,14 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
 
     if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) ||
         !QEMU_IS_ALIGNED(section->offset_within_address_space, page_size)) {
+        if (add) {
+            warn_report("Cannot add 0x%016llX:0x%016llX because it is not "
+                        "aligned to page size (0x%X)",
+                        section->offset_within_address_space,
+                        section->offset_within_address_space +
+                        int128_get64(section->size),
+                        (uint32_t)page_size);
+        }
         /* Not page aligned, so we can not map as RAM */
         add = false;
     }
Signature · 1 line
2.41.0
#2 lore raw
In reply to Joelle van Dyne

Hi Joelle,

Quoted 10 lines · Joelle van Dyne

Instead of having a fixed limit of 32 slots, we allow the number of slots to expand. Currently there does not seem to be a need to add a limit, but if the allocation fails, we will abort. The KVM backend was used for inspiration here.

---
  include/system/hvf_int.h | 12 ++++++-
  accel/hvf/hvf-all.c      | 78 ++++++++++++++++++++++++++++++----------
  2 files changed, 71 insertions(+), 19 deletions(-)

See first 12 patches of:
https://lore.kernel.org/qemu-devel/[email protected]/

#3 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé

Hi Joelle,

Quoted 5 lines · Joelle van Dyne

Instead of having a fixed limit of 32 slots, we allow the number of slots to expand. Currently there does not seem to be a need to add a limit, but if the allocation fails, we will abort. The KVM backend was used for inspiration here.

Quoted 8 lines
Quoted 5 lines

---
  include/system/hvf_int.h | 12 ++++++-
  accel/hvf/hvf-all.c      | 78 ++++++++++++++++++++++++++++++----------

  2 files changed, 71 insertions(+), 19 deletions(-)

See first 12 patches of:
https://lore.kernel.org/qemu-devel/[email protected]/

Maybe you could add yourself as reviewer (R:) on 'HVF' and 'Apple Silicon HVF CPUs' MAINTAINERS sections to be Cc'ed on patches in this area.