stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: borntraeger@de.ibm.com, frankja@linux.ibm.com, david@redhat.com,
	kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH v1 3/4] s390/kvm: add kvm_s390_vsie_mvpg_check needed for VSIE MVPG
Date: Fri, 18 Dec 2020 15:18:10 +0100	[thread overview]
Message-ID: <20201218141811.310267-4-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20201218141811.310267-1-imbrenda@linux.ibm.com>

Add kvm_s390_vsie_mvpg_check to perform the necessary checks in case an
MVPG instruction intercepts in a VSIE guest.

Cc: stable@vger.kernel.org
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 arch/s390/kvm/gaccess.c | 55 +++++++++++++++++++++++++++++++++++++++++
 arch/s390/kvm/gaccess.h |  3 +++
 2 files changed, 58 insertions(+)

diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 8e256a233583..90e9baff6eac 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -1228,3 +1228,58 @@ int kvm_s390_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *sg,
 	mmap_read_unlock(sg->mm);
 	return rc;
 }
+
+static int kvm_s390_mvpg_check_one(struct kvm_vcpu *vcpu, unsigned long *addr,
+			     const int edat, const union asce asce,
+			     const enum gacc_mode mode, unsigned long *pteptr)
+{
+	enum prot_type prot;
+	int rc;
+
+	rc = guest_translate(vcpu, *addr, addr, asce, mode, &prot, pteptr);
+	if (rc <= 0)
+		return rc;
+
+	switch (rc) {
+	case PGM_REGION_FIRST_TRANS:
+	case PGM_REGION_SECOND_TRANS:
+	case PGM_REGION_THIRD_TRANS:
+	case PGM_SEGMENT_TRANSLATION:
+		if (!edat)
+			return trans_exc(vcpu, rc, *addr, 0, mode, prot);
+		*pteptr |= 4;
+		fallthrough;
+	case PGM_PAGE_TRANSLATION:
+		return -ENOENT;
+	default:
+		return rc;
+	}
+}
+
+int kvm_s390_vsie_mvpg_check(struct kvm_vcpu *vcpu, unsigned long r1,
+			     unsigned long r2, void *gpei)
+{
+	unsigned long pei[2] = {0};
+	union ctlreg0 cr0;
+	union asce cr1;
+	int edat, rc1, rc2;
+
+	cr0.val = vcpu->arch.sie_block->gcr[0];
+	cr1.val = vcpu->arch.sie_block->gcr[1];
+	edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
+
+	rc1 = kvm_s390_mvpg_check_one(vcpu, &r1, edat, cr1, GACC_FETCH, pei);
+	rc2 = kvm_s390_mvpg_check_one(vcpu, &r2, edat, cr1, GACC_STORE, pei + 1);
+
+	if (rc1 == -ENOENT || rc2 == -ENOENT) {
+		memcpy(gpei, pei, sizeof(pei));
+		return -ENOENT;
+	}
+
+	if (rc2 < 0)
+		return rc2;
+	if (rc1 < 0)
+		return rc1;
+
+	return 0;
+}
diff --git a/arch/s390/kvm/gaccess.h b/arch/s390/kvm/gaccess.h
index f4c51756c462..2c53cee3b29f 100644
--- a/arch/s390/kvm/gaccess.h
+++ b/arch/s390/kvm/gaccess.h
@@ -166,6 +166,9 @@ int check_gva_range(struct kvm_vcpu *vcpu, unsigned long gva, u8 ar,
 int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
 		 unsigned long len, enum gacc_mode mode);
 
+int kvm_s390_vsie_mvpg_check(struct kvm_vcpu *vcpu, unsigned long r1,
+			     unsigned long r2, void *gpei);
+
 int access_guest_real(struct kvm_vcpu *vcpu, unsigned long gra,
 		      void *data, unsigned long len, enum gacc_mode mode);
 
-- 
2.26.2


  parent reply	other threads:[~2020-12-18 14:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20201218141811.310267-1-imbrenda@linux.ibm.com>
2020-12-18 14:18 ` [PATCH v1 1/4] s390/kvm: VSIE: stop leaking host addresses Claudio Imbrenda
2020-12-20  9:44   ` David Hildenbrand
2021-01-04 13:58     ` Claudio Imbrenda
2021-01-04 15:36       ` David Hildenbrand
2021-01-19 14:23   ` Janosch Frank
2020-12-18 14:18 ` [PATCH v1 2/4] s390/kvm: extend guest_translate for MVPG interpretation Claudio Imbrenda
2021-01-19 14:59   ` Janosch Frank
2020-12-18 14:18 ` Claudio Imbrenda [this message]
2021-01-05 10:31   ` [PATCH v1 3/4] s390/kvm: add kvm_s390_vsie_mvpg_check needed for VSIE MVPG David Hildenbrand
2020-12-18 14:18 ` [PATCH v1 4/4] s390/kvm: VSIE: correctly handle MVPG when in VSIE Claudio Imbrenda
2020-12-20 10:13   ` David Hildenbrand
2021-01-04 15:22     ` Claudio Imbrenda
2021-01-04 16:08       ` David Hildenbrand
2021-01-04 16:36         ` Claudio Imbrenda
2021-01-05 10:17           ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201218141811.310267-4-imbrenda@linux.ibm.com \
    --to=imbrenda@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).