On 9/4/26 5:36 AM, Mathieu Poirier wrote:
From: Jean-Philippe Brucker <[email protected]>

When RME is enabled, the upper GPA bit is used to distinguish protected
from unprotected addresses. Reserve it when setting up the guest memory
map.

Signed-off-by: Jean-Philippe Brucker <[email protected]>
Signed-off-by: Mathieu Poirier <[email protected]>
---
  hw/arm/virt.c | 20 +++++++++++++++-----
  1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 61751aa31e0d..cf3a9320dc3a 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -4054,17 +4054,27 @@ static int virt_kvm_type(MachineState *ms, const char 
*type_str)
  {
      VirtMachineState *vms = VIRT_MACHINE(ms);
      int max_vm_pa_size, requested_pa_size;
+    int rme_reserve_bit = 0;
      bool fixed_ipa;
      int vm_type;
- max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa);
-
      vm_type = (ms->cgs ? KVM_VM_TYPE_ARM_REALM : KVM_VM_TYPE_ARM_NORMAL);
+ if (vm_type) {
+        /*
+         * With RME, the upper GPA bit differentiates Realm from NS memory.
+         * Reserve the upper bit to ensure that highmem devices will fit.
+         */
+        rme_reserve_bit = 1;
+    }

"if (vm_type)" are mapped to any VM types other than KVM_VM_TYPE_ARM_NORMAL, 
meaning
it can be PKVM in theory. So this would be:

       if (vm_type == KVM_VM_TYPE_ARM_REALM) {
           ...
       }

+
+    max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa) -
+                     rme_reserve_bit;
+
      /* we freeze the memory map to compute the highest gpa */
      virt_set_memmap(vms, max_vm_pa_size);
- requested_pa_size = 64 - clz64(vms->highest_gpa);
+    requested_pa_size = 64 - clz64(vms->highest_gpa) + rme_reserve_bit;
/*
       * KVM requires the IPA size to be at least 32 bits.
@@ -4073,11 +4083,11 @@ static int virt_kvm_type(MachineState *ms, const char 
*type_str)
          requested_pa_size = 32;
      }
- if (requested_pa_size > max_vm_pa_size) {
+    if (requested_pa_size > max_vm_pa_size + rme_reserve_bit) {
          error_report("-m and ,maxmem option values "
                       "require an IPA range (%d bits) larger than "
                       "the one supported by the host (%d bits)",
-                     requested_pa_size, max_vm_pa_size);
+                     requested_pa_size, max_vm_pa_size + rme_reserve_bit);
          return -1;
      }
      /*

Thanks,
Gavin


Reply via email to