accel/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size()
cover accel/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size()
Have get_physical_address_range() return when HVF is not usable, allowing to try another accelerator if requested with '-accel hvf:tcg', reported here:
https://gitlab.com/qemu-project/qemu/-/issues/2981
Philippe Mathieu-Daudé (3):
accel/hvf: Display executable bit as 'X' accel/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() hw/arm/virt: Warn when HVF doesn't report IPA bit length
target/arm/hvf_arm.h | 11 +++++++++++ accel/hvf/hvf-all.c | 2 +- hw/arm/virt.c | 8 ++++++-- target/arm/hvf/hvf.c | 8 ++------ 4 files changed, 20 insertions(+), 9 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/3 accel/hvf: Display executable bit as 'X'
Developers are custom to read RWX, not RWE.
Replace E -> X.
--- accel/hvf/hvf-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/hvf/hvf-all.c +1 -1
@@ -84,7 +84,7 @@ static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)trace_hvf_vm_map (slot->start, slot->size, slot->mem, flags, flags &HV_MEMORY_READ ?'R' :'-' , flags &HV_MEMORY_WRITE ?'W' :'-' , - flags &HV_MEMORY_EXEC ?'E' :'-' ); + flags &HV_MEMORY_EXEC ?'X' :'-' ); ret =hv_vm_map (slot->mem, slot->start, slot->size, flags);assert_hvf_ok (ret);return 0 ;
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 1/3] accel/hvf: Display executable bit as 'X'
Quoted 5 lines · Philippe Mathieu-Daudé
Developers are custom to read RWX, not RWE.
Replace E -> X.Reported-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH-for-10.1 1/3] accel/hvf: Display executable bit as 'X'
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Developers are custom to read RWX, not RWE. Replace E -> X.
Reported-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
accel/hvf/hvf-all.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH-for-10.1 1/3] accel/hvf: Display executable bit as 'X'
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Developers are custom to read RWX, not RWE.
Replace E -> X.Reported-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
--- accel/hvf/hvf-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/hvf/hvf-all.c +1
-1@@ -84,7 +84,7 @@ static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)trace_hvf_vm_map (slot->start, slot->size, slot->mem, flags, flags &HV_MEMORY_READ ?'R' :'-' , flags &HV_MEMORY_WRITE ?'W' :'-' , - flags &HV_MEMORY_EXEC ?'E' :'-' ); + flags &HV_MEMORY_EXEC ?'X' :'-' ); ret =hv_vm_map (slot->mem, slot->start, slot->size, flags);assert_hvf_ok (ret);return 0 ;
Re: [PATCH-for-10.1 1/3] accel/hvf: Display executable bit as 'X'
Quoted 2 lines · Xiaoyao Li
Quoted 1 line · Philippe Mathieu-Daudé
Developers are custom to read RWX, not RWE.
"accustomed to"
Quoted 28 lines
Quoted 4 lines
Replace E -> X.
Reported-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Xiaoyao Li <[email protected]>Quoted 18 lines
--- accel/hvf/hvf-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/hvf/hvf-all.c +1
-1@@ -84,7 +84,7 @@ static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags) trace_hvf_vm_map(slot->start, slot->size, slot->mem, flags, flags & HV_MEMORY_READ ? 'R' : '-', flags & HV_MEMORY_WRITE ? 'W' : '-', - flags & HV_MEMORY_EXEC ? 'E' : '-'); + flags & HV_MEMORY_EXEC ? 'X' : '-'); ret =hv_vm_map (slot->mem, slot->start, slot->size, flags);assert_hvf_ok (ret);return 0;
PATCH 2/3 accel/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size()
In reply to Philippe Mathieu-DaudéDo not abort in hvf_arm_get_default_ipa_bit_size() and hvf_arm_get_max_ipa_bit_size() when the IPA can not be fetched. Return 0 (and document it).
--- target/arm/hvf_arm.h | 11 +++++++++++ target/arm/hvf/hvf.c | 8 ++------ 2 files changed, 13 insertions(+), 6 deletions(-)
target/arm/hvf_arm.h +11 -0
@@ -22,7 +22,18 @@ void hvf_arm_init_debug(void);void hvf_arm_set_cpu_features_from_host (ARMCPU *cpu); +/** +* hvf_arm_get_default_ipa_bit_size: +* +* Returns the default intermediate physical address bit length or 0 on error. +*/ uint32_t hvf_arm_get_default_ipa_bit_size (void ); + +/** +* hvf_arm_get_max_ipa_bit_size: +* +* Returns the maximum intermediate physical address bit length or 0 on error. +*/ uint32_t hvf_arm_get_max_ipa_bit_size (void );#endif
target/arm/hvf/hvf.c +2 -6
@@ -943,24 +943,20 @@ 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); - -return default_ipa_size; +return ret ==HV_SUCCESS ? default_ipa_size :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); -/* * 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); +return ret ==HV_SUCCESS ?round_down_to_parange_bit_size (max_ipa_size) :0 ; }void hvf_arm_set_cpu_features_from_host (ARMCPU *cpu)
Signature · 1 line
2.49.0
Quoted 7 lines · Philippe Mathieu-Daudé
Do not abort in
hvf_arm_get_default_ipa_bit_size()andhvf_arm_get_max_ipa_bit_size()when the IPA can not be fetched. Return 0 (and document it).
Quoted 5 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf_arm.h| 11 +++++++++++target/arm/hvf/hvf.c| 8 ++------2 files changed, 13 insertions(+), 6 deletions(-)
I looked up the different uses of hvf_arm_get_max_ipa_bit_size. There's an unchecked use in clamp_id_aa64mmfr0_parange_to_ipa_size, but I guess it'll never reach that far, with your changes to virt_hvf_get_physical_address_range.
clamp_id_aa64mmfr0_parange_to_ipa_size is already surrounded by other hv-calls and assert_hvf_ok, so either leave it, or assert ipa_size!=0?
PATCH 3/3 hw/arm/virt: Warn when HVF doesn't report IPA bit length
In reply to Philippe Mathieu-DaudéEmit a warning when HVF doesn't return the IPA bit length and return -1 as "this accelerator is not usable", allowing QEMU to try with the next one (when using '-accel hvf:tcg').
Reported-by: Ivan Krasilnikov
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2981
--- hw/arm/virt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/virt.c +6 -2
@@ -3149,8 +3149,12 @@ static int virt_hvf_get_physical_address_range(MachineState *ms) {VirtMachineState *vms =VIRT_MACHINE (ms); -int default_ipa_size =hvf_arm_get_default_ipa_bit_size (); -int max_ipa_size =hvf_arm_get_max_ipa_bit_size (); +uint32_t default_ipa_size =hvf_arm_get_default_ipa_bit_size (); +uint32_t max_ipa_size =hvf_arm_get_max_ipa_bit_size (); +if (!default_ipa_size || !max_ipa_size) { +warn_report ("HVF didn't report IPA bit length" ); +return -1 ; + }/* We freeze the memory map to compute the highest gpa */ virt_set_memmap (vms, max_ipa_size);
Signature · 1 line
2.49.0
Re: [PATCH-for-10.1 3/3] hw/arm/virt: Warn when HVF doesn't report IPA bit length
Quoted 7 lines · Philippe Mathieu-Daudé
Emit a warning when HVF doesn't return the IPA bit length and return -1 as "this accelerator is not usable", allowing QEMU to try with the next one (when using '-accel hvf:tcg').
Quoted 6 lines
Reported-by: Ivan Krasilnikov
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2981Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/virt.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)
I haven't been able to verify that hv_vm_config_get_max_ipa_size and hv_vm_config_get_default_ipa_size fail if HVF is not available, but assuming so, it looks fine to me.
Re: [PATCH-for-10.1 3/3] hw/arm/virt: Warn when HVF doesn't report IPA bit length
Quoted 14 lines · Mads Ynddal
Quoted 7 lines · Philippe Mathieu-Daudé
Emit a warning when HVF doesn't return the IPA bit length and return -1 as "this accelerator is not usable", allowing QEMU to try with the next one (when using '-accel hvf:tcg').
Quoted 6 lines
Reported-by: Ivan Krasilnikov
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2981Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/virt.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 2 lines
I haven't been able to verify that
hv_vm_config_get_max_ipa_sizeandhv_vm_config_get_default_ipa_sizefail if HVF is not available, but
This happens with nested macOS guest. Maybe we are missing an earlier check whether HVF is usable or not, but we shouldn't brutally abort().
I'll try to update the patch description. Annoyingly the GitLab issue reporter isn't Cc'ed via the mailing list.
Quoted 3 lines
assuming so, it looks fine to me.
Reviewed-by Mads Ynddal <[email protected]>
Re: [PATCH-for-10.1 3/3] hw/arm/virt: Warn when HVF doesn't report IPA bit length
Quoted 2 lines
This happens with nested macOS guest.
I took another look at the stack trace in the issue. Everything should be fine then.
Quoted 2 lines
Maybe we are missing an earlier check whether HVF is usable or not, but we shouldn't brutally
abort().
I agree. I think with this patchset you're doing it practically as early as possible with accel_init_machine.
Re: [PATCH-for-10.1 3/3] hw/arm/virt: Warn when HVF doesn't report IPA bit length
In reply to Philippe Mathieu-DaudéQuoted 18 lines · Philippe Mathieu-Daudé
Emit a warning when HVF doesn't return the IPA bit length and return -1 as "this accelerator is not usable", allowing QEMU to try with the next one (when using '-accel hvf:tcg').
Reported-by: Ivan Krasilnikov
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2981Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/virt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/arm/virt.c +0
-0@@ -3149,8 +3149,12 @@ static int virt_hvf_get_physical_address_range(MachineState *ms) {
hw/arm/virt.c static int virt_hvf_get_physical_address_range(MachineState *ms) · line 3157
Quoted 10 lines
hw/arm/virt.c +6
-2VirtMachineState *vms =VIRT_MACHINE (ms); -int default_ipa_size =hvf_arm_get_default_ipa_bit_size (); -int max_ipa_size =hvf_arm_get_max_ipa_bit_size (); +uint32_t default_ipa_size =hvf_arm_get_default_ipa_bit_size (); +uint32_t max_ipa_size =hvf_arm_get_max_ipa_bit_size (); +if (!default_ipa_size || !max_ipa_size) { +warn_report ("HVF didn't report IPA bit length" ); +return -1 ; + }
Even if we avoid blowing up in this function, won't hvf_accel_init() immediately fail in hvf_arch_vm_create() and either exit(1) or assert() depending on what error code it got back ?
It's unfortunate that there's no convenient way we can check "hvf is basically going to work" in hvf_accel_init() before we get into the machine-specific hook. "HVF didn't report IPA bit length" isn't really a very good message to report for "HVF isn't going to work at all here".
(More generally, I think the hvf code rather overuses assert_hvf_ok(). I don't think the KVM code uses asserts for error checking like this.)
thanks
-- PMM
Peter Maydell
AppliedQuoted 10 lines · Philippe Mathieu-Daudé
Have
get_physical_address_range()return when HVF is not usable, allowing to try another accelerator if requested with '-accel hvf:tcg', reported here:
https://gitlab.com/qemu-project/qemu/-/issues/2981Philippe Mathieu-Daudé (3):
accel/hvf: Display executable bit as 'X' accel/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() hw/arm/virt: Warn when HVF doesn't report IPA bit length
I've applied patch 1 to target-arm.next, since it's not really related to the patch 2 and 3 bugfix.
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Philippe Mathieu-Daudé
Have
get_physical_address_range()return when HVF is not usable, allowing to try another accelerator if requested with '-accel hvf:tcg', reported here:
https://gitlab.com/qemu-project/qemu/-/issues/2981
Quoted 8 lines
Quoted 4 lines
Philippe Mathieu-Daudé (3):
accel/hvf: Display executable bit as 'X' accel/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() hw/arm/virt: Warn when HVF doesn't report IPA bit lengthI've applied patch 1 to target-arm.next, since it's not really related to the patch 2 and 3 bugfix.
Thank you.