KVM: s390: fix cc for successful PQAP
PATCH 1/1 KVM: s390: fix cc for successful PQAP
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
--- arch/s390/kvm/priv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/s390/kvm/priv.c +6 -2
@@ -676,8 +676,12 @@ static int handle_pqap(struct kvm_vcpu *vcpu)if (vcpu->kvm->arch.crypto.pqap_hook) { pqap_hook = *vcpu->kvm->arch.crypto.pqap_hook; ret =pqap_hook (vcpu); -if (!ret && vcpu->run->s.regs.gprs[1 ] &0x00ff0000 ) -kvm_s390_set_psw_cc (vcpu,3 ); +if (!ret) { +if (vcpu->run->s.regs.gprs[1 ] &0x00ff0000 ) +kvm_s390_set_psw_cc (vcpu,3 ); +else +kvm_s390_set_psw_cc (vcpu,0 ); + }up_read (&vcpu->kvm->arch.crypto.pqap_hook_rwsem);return ret; }
Signature · 1 line
2.40.1
Quoted 11 lines · On Fri, 1 Dec 2023 19:16:57 +0100 Eric Farman <[email protected]> wrote:
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Fixes e5282de93105 ("s390: ap: kvm: add PQAP interception for AQIC")Signed-off-by Eric Farman <[email protected]>
Quoted 9 lines
--- arch/s390/kvm/priv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)arch/s390/kvm/priv.c +0
-0
arch/s390/kvm/priv.c static int handle_pqap(struct kvm_vcpu *vcpu) · line 680
Quoted 5 lines
arch/s390/kvm/priv.c +0
-2@@ -676,8 +676,12 @@ static int handle_pqap(struct kvm_vcpu *vcpu)if (vcpu->kvm->arch.crypto.pqap_hook) { pqap_hook = *vcpu->kvm->arch.crypto.pqap_hook; ret =pqap_hook (vcpu); -if (!ret && vcpu->run->s.regs.gprs[1 ] &0x00ff0000 ) -kvm_s390_set_psw_cc (vcpu,3 );
Maybe a comment that tells pqap_hook() returns 0 or -EOPNOTSUPP that singnals this should be handled by QEMU. But that can certainly be done on top, and it is not a part of a minimal fix.
Quoted 9 lines
arch/s390/kvm/priv.c +6
-0+if (!ret) { +if (vcpu->run->s.regs.gprs[1 ] &0x00ff0000 ) +kvm_s390_set_psw_cc (vcpu,3 ); +else +kvm_s390_set_psw_cc (vcpu,0 ); + }up_read (&vcpu->kvm->arch.crypto.pqap_hook_rwsem);return ret; }
Quoted 21 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Fixes e5282de93105 ("s390: ap: kvm: add PQAP interception for AQIC")Signed-off-by Eric Farman <[email protected]>--- arch/s390/kvm/priv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)arch/s390/kvm/priv.c +0
-0@@ -676,8 +676,12 @@ static int handle_pqap(struct kvm_vcpu *vcpu)if (vcpu->kvm->arch.crypto.pqap_hook) {
arch/s390/kvm/priv.c static int handle_pqap(struct kvm_vcpu *vcpu) · line 684
Quoted 10 lines
arch/s390/kvm/priv.c +6
-2pqap_hook = *vcpu->kvm->arch.crypto.pqap_hook; ret =pqap_hook (vcpu); -if (!ret && vcpu->run->s.regs.gprs[1 ] &0x00ff0000 ) -kvm_s390_set_psw_cc (vcpu,3 ); +if (!ret) { +if (vcpu->run->s.regs.gprs[1 ] &0x00ff0000 ) +kvm_s390_set_psw_cc (vcpu,3 ); +else +kvm_s390_set_psw_cc (vcpu,0 ); + }
The cc is not set if pqap_hook returns a non-zero rc; however, this point may be moot given the only non-zero rc is -EOPNOTSUPP. I'm a bit foggy on what happens when non-zero return codes are passed up the stack.
Quoted 3 lines
arch/s390/kvm/priv.c +0
-0up_read (&vcpu->kvm->arch.crypto.pqap_hook_rwsem);return ret; }
Quoted 33 lines · Anthony Krowiak
Quoted 31 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Fixes e5282de93105 ("s390: ap: kvm: add PQAP interception forAQIC")
Signed-off-by Eric Farman <[email protected]>---
arch/s390/kvm/priv.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)arch/s390/kvm/priv.c +5
-2@@ -676,8 +676,12 @@ static int handle_pqap(struct kvm_vcpu *vcpu) if (vcpu->kvm->arch.crypto.pqap_hook) { pqap_hook = *vcpu->kvm->arch.crypto.pqap_hook; ret = pqap_hook(vcpu); - if (!ret && vcpu->run->s.regs.gprs[1] & 0x00ff0000) - kvm_s390_set_psw_cc(vcpu, 3); + if (!ret) { + if (vcpu->run->s.regs.gprs[1] & 0x00ff0000) + kvm_s390_set_psw_cc(vcpu, 3); + else + kvm_s390_set_psw_cc(vcpu, 0);
Quoted 8 lines
arch/s390/kvm/priv.c static int handle_pqap(struct kvm_vcpu *vcpu) · line 684
Quoted 1 line
arch/s390/kvm/priv.c +1
-0+ }The cc is not set if
pqap_hookreturns a non-zero rc; however, this point may be moot given the only non-zero rc is-EOPNOTSUPP. I'm a bit
foggy on what happens when non-zero return codes are passed up the stack.
Right, a non-zero RC will get reflected to the interception handlers, where EOPNOTSUPP instructs control to be given to userspace. So not setting a condition code is correct here, as userspace will be expected to do that.
Quoted 5 lines
Quoted 5 lines
arch/s390/kvm/priv.c +0
-0up_read(&vcpu->kvm->arch.crypto.pqap_hook_rwsem); return ret; }
Anthony Krowiak
Reviewed-byQuoted 40 lines · Eric Farman
Quoted 31 lines · Anthony Krowiak
Quoted 30 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Fixes e5282de93105 ("s390: ap: kvm: add PQAP interception forAQIC")
Signed-off-by Eric Farman <[email protected]>--- arch/s390/kvm/priv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)arch/s390/kvm/priv.c +4
-2@@ -676,8 +676,12 @@ static int handle_pqap(struct kvm_vcpu *vcpu) if (vcpu->kvm->arch.crypto.pqap_hook) { pqap_hook = *vcpu->kvm->arch.crypto.pqap_hook; ret = pqap_hook(vcpu); - if (!ret && vcpu->run->s.regs.gprs[1] & 0x00ff0000) - kvm_s390_set_psw_cc(vcpu, 3); + if (!ret) { + if (vcpu->run->s.regs.gprs[1] & 0x00ff0000) + kvm_s390_set_psw_cc(vcpu, 3); + elseQuoted 8 lines
arch/s390/kvm/priv.c static int handle_pqap(struct kvm_vcpu *vcpu) · line 684
Quoted 2 lines
arch/s390/kvm/priv.c +2
-0+ kvm_s390_set_psw_cc(vcpu, 0); + }The cc is not set if
pqap_hookreturns a non-zero rc; however, this point may be moot given the only non-zero rc is-EOPNOTSUPP. I'm a bit
foggy on what happens when non-zero return codes are passed up the stack.
Quoted 4 lines
Right, a non-zero RC will get reflected to the interception handlers, where EOPNOTSUPP instructs control to be given to userspace. So not setting a condition code is correct here, as userspace will be expected to do that.
Thanks for confirming that. With that said:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
arch/s390/kvm/priv.c +0
-0up_read(&vcpu->kvm->arch.crypto.pqap_hook_rwsem); return ret; }
Janosch Frank
maintainerQuoted 9 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Hey Eric, I have yet to see this produce a fail in my AP KVM unit tests.
If you find some spare time I'd like to discuss how I can extend my test so that I can see the fail before it's fixed.
Quoted 11 lines · Janosch Frank
Quoted 9 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Quoted 6 lines
Hey Eric, I have yet to see this produce a fail in my AP KVM unit tests.
If you find some spare time I'd like to discuss how I can extend my test
so that I can see the fail before it's fixed.
Hi Janosch, absolutely. I had poked around kvm-unit-tests before I sent this up to see if I could adapt something to show this scenario, but came up empty and didn't want to go too far down that rabbit hole creating something from scratch. I'll ping you offline to find a time to talk.
Eric
Quoted 17 lines · Eric Farman
Quoted 7 lines · Janosch Frank
Quoted 6 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Quoted 9 lines
Quoted 3 lines
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Hey Eric, I have yet to see this produce a fail in my AP KVM unit tests.
If you find some spare time I'd like to discuss how I can extend my test
so that I can see the fail before it's fixed.
Quoted 5 lines
Hi Janosch, absolutely. I had poked around kvm-unit-tests before I sent this up to see if I could adapt something to show this scenario, but came up empty and didn't want to go too far down that rabbit hole creating something from scratch. I'll ping you offline to find a time to talk.
If this is recreateable, I'd like to know how. I don't see any code path that would cause this result.
Quoted 3 lines
Eric
Quoted 30 lines · Anthony Krowiak
Quoted 18 lines · Eric Farman
Quoted 10 lines · Janosch Frank
Quoted 9 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
Quoted 7 lines
Hey Eric, I have yet to see this produce a fail in my AP KVM unit tests.
If you find some spare time I'd like to discuss how I can extend my
test
so that I can see the fail before it's fixed.Quoted 8 lines
Hi Janosch, absolutely. I had poked around kvm-unit-tests before I sent
this up to see if I could adapt something to show this scenario, but
came up empty and didn't want to go too far down that rabbit hole creating something from scratch. I'll ping you offline to find a time
to talk.
Quoted 3 lines
If this is recreateable, I'd like to know how. I don't see any code path
that would cause this result.
Janosch and I spoke offline... He was using a proposed series of kvm- unit-tests [1] as a base, but the condition code of the PSW was zero at the time of the PQAP, meaning everything seemed fine. By dirtying the CC before the PQAP, this problem pops up quite easily, and this patch gets things back in line.
[1]
https://lore.kernel.org/kvm/[email protected]/
Quoted 6 lines
Quoted 5 lines
Eric
Janosch Frank
maintainerQuoted 9 lines · Eric Farman
The various errors that are possible when processing a PQAP instruction (the absence of a driver hook, an error FROM that hook), all correctly set the PSW condition code to 3. But if that processing works successfully, CC0 needs to be set to convey that everything was fine.
Fix the check so that the guest can examine the condition code to determine whether GPR1 has meaningful data.
I've needed some time to remember this patch set, thanks for the ping. The patch has been pushed to devel for some CI coverage.