Skip to content

Commit c783631

Browse files
Janis Schoetterl-Glauschfrankjaa
authored andcommitted
KVM: s390: Don't indicate suppression on dirtying, failing memop
If user space uses a memop to emulate an instruction and that memop fails, the execution of the instruction ends. Instruction execution can end in different ways, one of which is suppression, which requires that the instruction execute like a no-op. A writing memop that spans multiple pages and fails due to key protection may have modified guest memory, as a result, the likely correct ending is termination. Therefore, do not indicate a suppressing instruction ending in this case. Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Link: https://lore.kernel.org/r/20220512131019.2594948-2-scgl@linux.ibm.com Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
1 parent cbac924 commit c783631

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

Documentation/virt/kvm/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,12 +3754,18 @@ in case of KVM_S390_MEMOP_F_CHECK_ONLY), the ioctl returns a positive
37543754
error number indicating the type of exception. This exception is also
37553755
raised directly at the corresponding VCPU if the flag
37563756
KVM_S390_MEMOP_F_INJECT_EXCEPTION is set.
3757+
On protection exceptions, unless specified otherwise, the injected
3758+
translation-exception identifier (TEID) indicates suppression.
37573759

37583760
If the KVM_S390_MEMOP_F_SKEY_PROTECTION flag is set, storage key
37593761
protection is also in effect and may cause exceptions if accesses are
37603762
prohibited given the access key designated by "key"; the valid range is 0..15.
37613763
KVM_S390_MEMOP_F_SKEY_PROTECTION is available if KVM_CAP_S390_MEM_OP_EXTENSION
37623764
is > 0.
3765+
Since the accessed memory may span multiple pages and those pages might have
3766+
different storage keys, it is possible that a protection exception occurs
3767+
after memory has been modified. In this case, if the exception is injected,
3768+
the TEID does not indicate suppression.
37633769

37643770
Absolute read/write:
37653771
^^^^^^^^^^^^^^^^^^^^

arch/s390/kvm/gaccess.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ enum prot_type {
491491
PROT_TYPE_IEP = 4,
492492
};
493493

494-
static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,
495-
u8 ar, enum gacc_mode mode, enum prot_type prot)
494+
static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
495+
enum gacc_mode mode, enum prot_type prot, bool terminate)
496496
{
497497
struct kvm_s390_pgm_info *pgm = &vcpu->arch.pgm;
498498
struct trans_exc_code_bits *tec;
@@ -520,6 +520,11 @@ static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,
520520
tec->b61 = 1;
521521
break;
522522
}
523+
if (terminate) {
524+
tec->b56 = 0;
525+
tec->b60 = 0;
526+
tec->b61 = 0;
527+
}
523528
fallthrough;
524529
case PGM_ASCE_TYPE:
525530
case PGM_PAGE_TRANSLATION:
@@ -552,6 +557,12 @@ static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva,
552557
return code;
553558
}
554559

560+
static int trans_exc(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
561+
enum gacc_mode mode, enum prot_type prot)
562+
{
563+
return trans_exc_ending(vcpu, code, gva, ar, mode, prot, false);
564+
}
565+
555566
static int get_vcpu_asce(struct kvm_vcpu *vcpu, union asce *asce,
556567
unsigned long ga, u8 ar, enum gacc_mode mode)
557568
{
@@ -1109,8 +1120,11 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
11091120
data += fragment_len;
11101121
ga = kvm_s390_logical_to_effective(vcpu, ga + fragment_len);
11111122
}
1112-
if (rc > 0)
1113-
rc = trans_exc(vcpu, rc, ga, ar, mode, prot);
1123+
if (rc > 0) {
1124+
bool terminate = (mode == GACC_STORE) && (idx > 0);
1125+
1126+
rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
1127+
}
11141128
out_unlock:
11151129
if (need_ipte_lock)
11161130
ipte_unlock(vcpu);

0 commit comments

Comments
 (0)