KVM: arm64: Ratelimit error log during guest debug exception
PATCH 1/1 KVM: arm64: Ratelimit error log during guest debug exception
Potentially, the guests could trigger a debug exception that's outside the exception class range. This could lead to an excessive syslog flooding. Hence, ratelimit the error message.
--- arch/arm64/kvm/handle_exit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/handle_exit.c +1 -1
@@ -134,7 +134,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)case ESR_ELx_EC_BRK64:break ;default : -kvm_err ("%s: un-handled case esr: %#08x\n" , +kvm_pr_unimpl ("%s: un-handled case esr: %#08x\n" , __func__, (unsigned int ) esr); ret =-1 ;break ;
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog
Marc Zyngier
maintainerQuoted 3 lines · Raghavendra Rao Ananta
Potentially, the guests could trigger a debug exception that's outside the exception class range.
How? All the exception classes that lead to this functions are already handled in the switch/case statement.
Quoted 13 lines
This could lead to an excessive syslog flooding. Hence, ratelimit the error message.
Signed-off-by Raghavendra Rao Ananta <[email protected]>--- arch/arm64/kvm/handle_exit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/handle_exit.c +0
-0
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu) · line 140
Quoted 8 lines
arch/arm64/kvm/handle_exit.c +1
-1@@ -134,7 +134,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)case ESR_ELx_EC_BRK64:break ;default : -kvm_err ("%s: un-handled case esr: %#08x\n" , +kvm_pr_unimpl ("%s: un-handled case esr: %#08x\n" , __func__, (unsigned int ) esr); ret =-1 ;break ;
My take on this is that this code isn't reachable, and that it could be better rewritten as:
arch/arm64/kvm/handle_exit.c +2 -16
@@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run;u32 esr =kvm_vcpu_get_esr (vcpu); -int ret =0 ; run->exit_reason =KVM_EXIT_DEBUG ; run->debug.arch.hsr = esr; -switch (ESR_ELx_EC (esr)) { -case ESR_ELx_EC_WATCHPT_LOW: +if (ESR_ELx_EC (esr) == ESR_ELx_EC_WATCHPT_LOW) run->debug.arch.far = vcpu->arch.fault.far_el2; - fallthrough; -case ESR_ELx_EC_SOFTSTP_LOW: -case ESR_ELx_EC_BREAKPT_LOW: -case ESR_ELx_EC_BKPT32: -case ESR_ELx_EC_BRK64: -break ; -default : -kvm_err ("%s: un-handled case esr: %#08x\n" , - __func__, (unsigned int ) esr); - ret =-1 ; -break ; - } -return ret; +return 0 ; }static int kvm_handle_unknown_ec (struct kvm_vcpu *vcpu)
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 10 lines · Marc Zyngier
Quoted 3 lines · Raghavendra Rao Ananta
Potentially, the guests could trigger a debug exception that's outside the exception class range.
How? All the exception classes that lead to this functions are already handled in the switch/case statement.
I guess I didn't think this through. Landing into kvm_handle_guest_debug() itself is not possible :)
Quoted 8 lines
Quoted 8 lines
This could lead to an excessive syslog flooding. Hence, ratelimit the error message.
Signed-off-by Raghavendra Rao Ananta <[email protected]>--- arch/arm64/kvm/handle_exit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu
Quoted 5 lines
arch/arm64/kvm/handle_exit.c +0
-0@@ -134,7 +134,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu
*vcpu)
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu
Quoted 17 lines
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu · line 140
Quoted 8 lines
arch/arm64/kvm/handle_exit.c +1
-1case ESR_ELx_EC_BRK64:break ;default : -kvm_err ("%s: un-handled case esr: %#08x\n" , +kvm_pr_unimpl ("%s: un-handled case esr: %#08x\n" , __func__, (unsigned int ) esr); ret =-1 ;break ;My take on this is that this code isn't reachable, and that it could be better rewritten as:
arch/arm64/kvm/handle_exit.c +0
-0@@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu
*vcpu)
Quoted 19 lines
arch/arm64/kvm/handle_exit.c +1
-10{struct kvm_run *run = vcpu->run;u32 esr =kvm_vcpu_get_esr (vcpu); -int ret =0 ; run->exit_reason =KVM_EXIT_DEBUG ; run->debug.arch.hsr = esr; -switch (ESR_ELx_EC (esr)) { -case ESR_ELx_EC_WATCHPT_LOW: +if (ESR_ELx_EC (esr) == ESR_ELx_EC_WATCHPT_LOW) run->debug.arch.far = vcpu->arch.fault.far_el2; - fallthrough; -case ESR_ELx_EC_SOFTSTP_LOW: -case ESR_ELx_EC_BREAKPT_LOW: -case ESR_ELx_EC_BKPT32: -case ESR_ELx_EC_BRK64: -break ; -default :
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu) · line 131
Quoted 10 lines
arch/arm64/kvm/handle_exit.c +1
-6-kvm_err ("%s: un-handled case esr: %#08x\n" , - __func__, (unsigned int ) esr); - ret =-1 ; -break ; - } -return ret; +return 0 ; }
This looks better, but do you think we would be compromising on readability?
Regards,
Raghavendra
Quoted 8 lines
arch/arm64/kvm/handle_exit.c +0
-0static int kvm_handle_unknown_ec (struct kvm_vcpu *vcpu)Thanks,
M.--
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerQuoted 7 lines · Raghavendra Rao Ananta
[1 <text/plain; UTF-8 (7bit)>]
Quoted 4 lines · Marc Zyngier
Quoted 1 line · Raghavendra Rao Ananta
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Potentially, the guests could trigger a debug exception that's outside the exception class range.
How? All the exception classes that lead to this functions are already handled in the switch/case statement.
I guess I didn't think this through. Landing into
kvm_handle_guest_debug()itself is not possible :)
Exactly.
Quoted 34 lines
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu
Quoted 8 lines
My take on this is that this code isn't reachable, and that it could be better rewritten as:
arch/arm64/kvm/handle_exit.c +0
-0@@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu*vcpu)
Quoted 25 lines
arch/arm64/kvm/handle_exit.c +1
-15{struct kvm_run *run = vcpu->run;u32 esr =kvm_vcpu_get_esr (vcpu); -int ret =0 ; run->exit_reason =KVM_EXIT_DEBUG ; run->debug.arch.hsr = esr; -switch (ESR_ELx_EC (esr)) { -case ESR_ELx_EC_WATCHPT_LOW: +if (ESR_ELx_EC (esr) == ESR_ELx_EC_WATCHPT_LOW) run->debug.arch.far = vcpu->arch.fault.far_el2; - fallthrough; -case ESR_ELx_EC_SOFTSTP_LOW: -case ESR_ELx_EC_BREAKPT_LOW: -case ESR_ELx_EC_BKPT32: -case ESR_ELx_EC_BRK64: -break ; -default : -kvm_err ("%s: un-handled case esr: %#08x\n" , - __func__, (unsigned int ) esr); - ret =-1 ; -break ; - }
Quoted 5 lines
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu) · line 131
Quoted 4 lines
arch/arm64/kvm/handle_exit.c +1
-1-return ret; +return 0 ; }This looks better, but do you think we would be compromising on readability?
I don't think so. The exit handler table is, on its own, pretty explicit about what we route to this handler, and the comment above the function clearly states that we exit to userspace for all the debug ECs.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 59 lines · Marc Zyngier
Quoted 7 lines · Raghavendra Rao Ananta
[1 <text/plain; UTF-8 (7bit)>]
Quoted 4 lines · Marc Zyngier
Quoted 1 line · Raghavendra Rao Ananta
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Potentially, the guests could trigger a debug exception that's outside the exception class range.
How? All the exception classes that lead to this functions are already handled in the switch/case statement.
I guess I didn't think this through. Landing into
kvm_handle_guest_debug()itself is not possible :)Exactly.
Quoted 38 lines
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu
Quoted 8 lines
My take on this is that this code isn't reachable, and that it could be better rewritten as:
arch/arm64/kvm/handle_exit.c +0
-0@@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu*vcpu)
Quoted 29 lines
arch/arm64/kvm/handle_exit.c +2
-16{struct kvm_run *run = vcpu->run;u32 esr =kvm_vcpu_get_esr (vcpu); -int ret =0 ; run->exit_reason =KVM_EXIT_DEBUG ; run->debug.arch.hsr = esr; -switch (ESR_ELx_EC (esr)) { -case ESR_ELx_EC_WATCHPT_LOW: +if (ESR_ELx_EC (esr) == ESR_ELx_EC_WATCHPT_LOW) run->debug.arch.far = vcpu->arch.fault.far_el2; - fallthrough; -case ESR_ELx_EC_SOFTSTP_LOW: -case ESR_ELx_EC_BREAKPT_LOW: -case ESR_ELx_EC_BKPT32: -case ESR_ELx_EC_BRK64: -break ; -default : -kvm_err ("%s: un-handled case esr: %#08x\n" , - __func__, (unsigned int ) esr); - ret =-1 ; -break ; - } -return ret; +return 0 ; }
Quoted 6 lines
Quoted 1 line
This looks better, but do you think we would be compromising on readability?
I don't think so. The exit handler table is, on its own, pretty explicit about what we route to this handler, and the comment above the function clearly states that we exit to userspace for all the debug ECs.
Sounds great. I'm happy to send out a patch with you as 'Suggested-by' , if you are okay with it.
Regards,
Raghavendra
Quoted 5 lines
M.--
Without deviation from the norm, progress is not possible.
Marc Zyngier
maintainerQuoted 62 lines · Raghavendra Rao Ananta
Quoted 61 lines · Marc Zyngier
Quoted 7 lines · Raghavendra Rao Ananta
[1 <text/plain; UTF-8 (7bit)>]
Quoted 4 lines · Marc Zyngier
Quoted 1 line · Raghavendra Rao Ananta
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Potentially, the guests could trigger a debug exception that's outside the exception class range.
How? All the exception classes that lead to this functions are already handled in the switch/case statement.
I guess I didn't think this through. Landing into
kvm_handle_guest_debug()itself is not possible :)Exactly.
Quoted 39 lines
arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu
Quoted 8 lines
My take on this is that this code isn't reachable, and that it could be better rewritten as:
arch/arm64/kvm/handle_exit.c +0
-0@@ -119,28 +119,14 @@ static int kvm_handle_guest_debug(struct kvm_vcpu*vcpu)
Quoted 19 lines
arch/arm64/kvm/handle_exit.c +1
-10{struct kvm_run *run = vcpu->run;u32 esr =kvm_vcpu_get_esr (vcpu); -int ret =0 ; run->exit_reason =KVM_EXIT_DEBUG ; run->debug.arch.hsr = esr; -switch (ESR_ELx_EC (esr)) { -case ESR_ELx_EC_WATCHPT_LOW: +if (ESR_ELx_EC (esr) == ESR_ELx_EC_WATCHPT_LOW) run->debug.arch.far = vcpu->arch.fault.far_el2; - fallthrough; -case ESR_ELx_EC_SOFTSTP_LOW: -case ESR_ELx_EC_BREAKPT_LOW: -case ESR_ELx_EC_BKPT32: -case ESR_ELx_EC_BRK64: -break ; -default :arch/arm64/kvm/handle_exit.c static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu) · line 131
Quoted 10 lines
arch/arm64/kvm/handle_exit.c +1
-6-kvm_err ("%s: un-handled case esr: %#08x\n" , - __func__, (unsigned int ) esr); - ret =-1 ; -break ; - } -return ret; +return 0 ; }This looks better, but do you think we would be compromising on readability?
Quoted 7 lines
Quoted 4 lines
I don't think so. The exit handler table is, on its own, pretty explicit about what we route to this handler, and the comment above the function clearly states that we exit to userspace for all the debug ECs.
Sounds great. I'm happy to send out a patch with you as 'Suggested-by' , if you are okay with it.
Fire away!
M.
Signature · 1 line
Jazz is not dead. It just smells funny...