Skip to content

Commit 0c02cc5

Browse files
committed
KVM: s390: fix sthyi error handling
Commit 9fb6c9b ("s390/sthyi: add cache to store hypervisor info") added cache handling for store hypervisor info. This also changed the possible return code for sthyi_fill(). Instead of only returning a condition code like the sthyi instruction would do, it can now also return a negative error value (-ENOMEM). handle_styhi() was not changed accordingly. In case of an error, the negative error value would incorrectly injected into the guest PSW. Add proper error handling to prevent this, and update the comment which describes the possible return values of sthyi_fill(). Fixes: 9fb6c9b ("s390/sthyi: add cache to store hypervisor info") Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Link: https://lore.kernel.org/r/20230727182939.2050744-1-hca@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 2608766 commit 0c02cc5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

arch/s390/kernel/sthyi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ static int sthyi_update_cache(u64 *rc)
459459
*
460460
* Fills the destination with system information returned by the STHYI
461461
* instruction. The data is generated by emulation or execution of STHYI,
462-
* if available. The return value is the condition code that would be
463-
* returned, the rc parameter is the return code which is passed in
464-
* register R2 + 1.
462+
* if available. The return value is either a negative error value or
463+
* the condition code that would be returned, the rc parameter is the
464+
* return code which is passed in register R2 + 1.
465465
*/
466466
int sthyi_fill(void *dst, u64 *rc)
467467
{

arch/s390/kvm/intercept.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ static int handle_partial_execution(struct kvm_vcpu *vcpu)
389389
*/
390390
int handle_sthyi(struct kvm_vcpu *vcpu)
391391
{
392-
int reg1, reg2, r = 0;
393-
u64 code, addr, cc = 0, rc = 0;
392+
int reg1, reg2, cc = 0, r = 0;
393+
u64 code, addr, rc = 0;
394394
struct sthyi_sctns *sctns = NULL;
395395

396396
if (!test_kvm_facility(vcpu->kvm, 74))
@@ -421,7 +421,10 @@ int handle_sthyi(struct kvm_vcpu *vcpu)
421421
return -ENOMEM;
422422

423423
cc = sthyi_fill(sctns, &rc);
424-
424+
if (cc < 0) {
425+
free_page((unsigned long)sctns);
426+
return cc;
427+
}
425428
out:
426429
if (!cc) {
427430
if (kvm_s390_pv_cpu_is_protected(vcpu)) {

0 commit comments

Comments
 (0)