@@ -1002,3 +1002,124 @@ index 73bde4ba0e..6f0f8f4488 100644
1002
1002
- -
1003
1003
2.41.0
1004
1004
1005
+ From 7c60f74fafee1658625d98f198ca14b9c71456c9 Mon Sep 17 00:00:00 2001
1006
+ From: Joelle van Dyne <
[email protected] >
1007
+ Date: Sun, 22 Dec 2024 19:49:20 -0800
1008
+ Subject: [PATCH] hvf: arm: disable unavailable features on older macOS
1009
+
1010
+ IPA size queries were introduced in macOS 13. When QEMU is built targeting
1011
+ a lower version, the compile will fail. If targeting a higher version and
1012
+ the binary is executed on an older version, QEMU will crash. This will
1013
+ restore the behaviour before IPA max size querying was added which means
1014
+ VMs with 64+ GB of RAM will not work if running on < macOS 13.
1015
+
1016
+ Signed-off-by: Joelle van Dyne <
[email protected] >
1017
+ ---
1018
+ target/arm/hvf/hvf.c | 59 ++++++++++++++++++++++++++++----------------
1019
+ 1 file changed, 38 insertions(+), 21 deletions(-)
1020
+
1021
+ diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
1022
+ index a63a7763a0..141fd35300 100644
1023
+ --- a/target/arm/hvf/hvf.c
1024
+ +++ b/target/arm/hvf/hvf.c
1025
+ @@ -907,7 +907,9 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
1026
+ r |= hv_vcpu_destroy(fd);
1027
+
1028
+ #if !defined(CONFIG_HVF_PRIVATE)
1029
+ - clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar.id_aa64mmfr0);
1030
+ + if (__builtin_available(macOS 13.0, *)) {
1031
+ + clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar.id_aa64mmfr0);
1032
+ + }
1033
+ #endif
1034
+
1035
+ /*
1036
+ @@ -967,26 +969,34 @@ static hv_return_t hvf_vcpu_set_actlr(hv_vcpu_t vcpu, uint64_t value)
1037
+
1038
+ uint32_t hvf_arm_get_default_ipa_bit_size(void)
1039
+ {
1040
+ - uint32_t default_ipa_size;
1041
+ - hv_return_t ret = hv_vm_config_get_default_ipa_size(&default_ipa_size);
1042
+ - assert_hvf_ok(ret);
1043
+ + if (__builtin_available(macOS 13.0, *)) {
1044
+ + uint32_t default_ipa_size;
1045
+ + hv_return_t ret = hv_vm_config_get_default_ipa_size(&default_ipa_size);
1046
+ + assert_hvf_ok(ret);
1047
+
1048
+ - return default_ipa_size;
1049
+ + return default_ipa_size;
1050
+ + } else {
1051
+ + return 0;
1052
+ + }
1053
+ }
1054
+
1055
+ uint32_t hvf_arm_get_max_ipa_bit_size(void)
1056
+ {
1057
+ - uint32_t max_ipa_size;
1058
+ - hv_return_t ret = hv_vm_config_get_max_ipa_size(&max_ipa_size);
1059
+ - assert_hvf_ok(ret);
1060
+ + if (__builtin_available(macOS 13.0, *)) {
1061
+ + uint32_t max_ipa_size;
1062
+ + hv_return_t ret = hv_vm_config_get_max_ipa_size(&max_ipa_size);
1063
+ + assert_hvf_ok(ret);
1064
+
1065
+ - /*
1066
+ - * We clamp any IPA size we want to back the VM with to a valid PARange
1067
+ - * value so the guest doesn't try and map memory outside of the valid range.
1068
+ - * This logic just clamps the passed in IPA bit size to the first valid
1069
+ - * PARange value <= to it.
1070
+ - */
1071
+ - return round_down_to_parange_bit_size(max_ipa_size);
1072
+ + /*
1073
+ + * We clamp any IPA size we want to back the VM with to a valid PARange
1074
+ + * value so the guest doesn't try and map memory outside of the valid
1075
+ + * range. This logic just clamps the passed in IPA bit size to the first
1076
+ + * valid PARange value <= to it.
1077
+ + */
1078
+ + return round_down_to_parange_bit_size(max_ipa_size);
1079
+ + } else {
1080
+ + return 0;
1081
+ + }
1082
+ }
1083
+
1084
+ #endif
1085
+ @@ -1019,24 +1029,31 @@ void hvf_arch_vcpu_destroy(CPUState *cpu)
1086
+ hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range)
1087
+ {
1088
+ hv_return_t ret;
1089
+ - hv_vm_config_t config = hv_vm_config_create();
1090
+ + hv_vm_config_t config = NULL;
1091
+
1092
+ #if defined(CONFIG_HVF_PRIVATE)
1093
+ if (hvf_tso_mode) {
1094
+ + config = hv_vm_config_create();
1095
+ _hv_vm_config_set_isa(config, HV_VM_CONFIG_ISA_PRIVATE);
1096
+ }
1097
+ #else
1098
+ - ret = hv_vm_config_set_ipa_size(config, pa_range);
1099
+ - if (ret != HV_SUCCESS) {
1100
+ - goto cleanup;
1101
+ + if (__builtin_available(macOS 13.0, *)) {
1102
+ + config = hv_vm_config_create();
1103
+ + ret = hv_vm_config_set_ipa_size(config, pa_range);
1104
+ + if (ret != HV_SUCCESS) {
1105
+ + goto cleanup;
1106
+ + }
1107
+ + chosen_ipa_bit_size = pa_range;
1108
+ }
1109
+ - chosen_ipa_bit_size = pa_range;
1110
+ #endif
1111
+
1112
+ ret = hv_vm_create(config);
1113
+
1114
+ cleanup:
1115
+ - os_release(config);
1116
+ + if (config) {
1117
+ + os_release(config);
1118
+ + }
1119
+ +
1120
+ return ret;
1121
+ }
1122
+
1123
+ - -
1124
+ 2.41.0
1125
+
0 commit comments