IPA size queries were introduced in macOS 13. When QEMU is built targeting
a lower version, the compile will fail. If targeting a higher version and
the binary is executed on an older version, QEMU will crash. This will
restore the behaviour before IPA max size querying was added which means
VMs with 64+ GB of RAM will not work if running on < macOS 13.
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
target/arm/hvf/hvf.c | 55 ++++++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 20 deletions(-)
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 0afd96018e..da60476dbc 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -897,7 +897,9 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
r |= hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr);
r |= hv_vcpu_destroy(fd);
- clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar.id_aa64mmfr0);
+ if (__builtin_available(macOS 13.0, *)) {
+ clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar.id_aa64mmfr0);
+ }
ahcf->isar = host_isar;
@@ -923,26 +925,34 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
uint32_t hvf_arm_get_default_ipa_bit_size(void)
{
- uint32_t default_ipa_size;
- hv_return_t ret = hv_vm_config_get_default_ipa_size(&default_ipa_size);
- assert_hvf_ok(ret);
+ if (__builtin_available(macOS 13.0, *)) {
+ uint32_t default_ipa_size;
+ hv_return_t ret = hv_vm_config_get_default_ipa_size(&default_ipa_size);
+ assert_hvf_ok(ret);
- return default_ipa_size;
+ return default_ipa_size;
+ } else {
+ return 0;
+ }
}
uint32_t hvf_arm_get_max_ipa_bit_size(void)
{
- uint32_t max_ipa_size;
- hv_return_t ret = hv_vm_config_get_max_ipa_size(&max_ipa_size);
- assert_hvf_ok(ret);
+ if (__builtin_available(macOS 13.0, *)) {
+ uint32_t max_ipa_size;
+ hv_return_t ret = hv_vm_config_get_max_ipa_size(&max_ipa_size);
+ assert_hvf_ok(ret);
- /*
- * We clamp any IPA size we want to back the VM with to a valid PARange
- * value so the guest doesn't try and map memory outside of the valid range.
- * This logic just clamps the passed in IPA bit size to the first valid
- * PARange value <= to it.
- */
- return round_down_to_parange_bit_size(max_ipa_size);
+ /*
+ * We clamp any IPA size we want to back the VM with to a valid PARange
+ * value so the guest doesn't try and map memory outside of the valid
+ * range. This logic just clamps the passed in IPA bit size to the first
+ * valid PARange value <= to it.
+ */
+ return round_down_to_parange_bit_size(max_ipa_size);
+ } else {
+ return 0;
+ }
}
void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
@@ -973,13 +983,18 @@ void hvf_arch_vcpu_destroy(CPUState *cpu)
hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range)
{
hv_return_t ret;
- hv_vm_config_t config = hv_vm_config_create();
+ hv_vm_config_t config;
- ret = hv_vm_config_set_ipa_size(config, pa_range);
- if (ret != HV_SUCCESS) {
- goto cleanup;
+ if (__builtin_available(macOS 13.0, *)) {
+ config = hv_vm_config_create();
+ ret = hv_vm_config_set_ipa_size(config, pa_range);
+ if (ret != HV_SUCCESS) {
+ goto cleanup;
+ }
+ chosen_ipa_bit_size = pa_range;
+ } else {
+ config = NULL;
}
- chosen_ipa_bit_size = pa_range;
ret = hv_vm_create(config);
--
2.41.0
© 2016 - 2024 Red Hat, Inc.