Skip to contentSkip to conversation

s390/kvm: VSIE: fix prefixing and MSO for MVPG

PATCH Superseded Claudio Imbrenda 5 participants 10 messages Mar 19, 2021 – Mar 22, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Claudio Imbrenda

author maintainer
#0 lore raw

cover s390/kvm: VSIE: fix prefixing and MSO for MVPG

The guest real address needs to pass through prefixing in order to yield the absolute address.

The absolute address needs to be offset by the MSO in order to get the host virtual address.

Claudio Imbrenda (2):
s390/kvm: split kvm_s390_real_to_abs
s390/kvm: VSIE: fix MVPG handling for prefixing and MSO

 arch/s390/kvm/gaccess.h | 23 +++++++++++++++++------
 arch/s390/kvm/vsie.c    | 10 +++++++---
 2 files changed, 24 insertions(+), 9 deletions(-)
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH 1/2 s390/kvm: split kvm_s390_real_to_abs

A new function _kvm_s390_real_to_abs will apply prefixing to a real address with a given prefix value.

The old kvm_s390_real_to_abs becomes now a wrapper around the new function.

This is needed to avoid code duplication in vSIE.

---
 arch/s390/kvm/gaccess.h | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
arch/s390/kvm/gaccess.h +17 -6
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
 
 /**
  * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu
+ * @prefix - guest prefix
  * @gra - guest real address
  *
  * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
  */
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)
 {
-	unsigned long prefix  = kvm_s390_get_prefix(vcpu);
-
 	if (gra < 2 * PAGE_SIZE)
 		gra += prefix;
 	else if (gra >= prefix && gra < prefix + 2 * PAGE_SIZE)
@@ -36,6 +33,20 @@ static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
 	return gra;
 }
 
+/**
+ * kvm_s390_real_to_abs - convert guest real address to guest absolute address
+ * @vcpu - guest virtual cpu
+ * @gra - guest real address
+ *
+ * Returns the guest absolute address that corresponds to the passed guest real
+ * address @gra of a virtual guest cpu by applying its prefix.
+ */
+static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
+						 unsigned long gra)
+{
+	return _kvm_s390_real_to_abs(kvm_s390_get_prefix(vcpu), gra);
+}
+
 /**
  * _kvm_s390_logical_to_effective - convert guest logical to effective address
  * @psw: psw of the guest
Signature · 1 line
2.26.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] s390/kvm: split kvm_s390_real_to_abs

Quoted 22 lines · Claudio Imbrenda

A new function _kvm_s390_real_to_abs will apply prefixing to a real address with a given prefix value.

The old kvm_s390_real_to_abs becomes now a wrapper around the new function.

This is needed to avoid code duplication in vSIE.

---
  arch/s390/kvm/gaccess.h | 23 +++++++++++++++++------
  1 file changed, 17 insertions(+), 6 deletions(-)
arch/s390/kvm/gaccess.h +0 -1
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
 
  /**
   * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu

arch/s390/kvm/gaccess.h line 27

Quoted 10 lines
arch/s390/kvm/gaccess.h +3 -3
+ * @prefix - guest prefix
   * @gra - guest real address
   *
   * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
   */
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)

<bikeshedding>
Just a matter of taste, but maybe this could be named differently? kvm_s390_real2abs_prefix() ? kvm_s390_prefix_real_to_abs()? </bikeshedding>

Anyway:

Reviewed-by
#3 lore raw

Re: [PATCH v1 1/2] s390/kvm: split kvm_s390_real_to_abs

Quoted 30 lines · Thomas Huth
Quoted 29 lines · Claudio Imbrenda

A new function _kvm_s390_real_to_abs will apply prefixing to a real address with a given prefix value.

The old kvm_s390_real_to_abs becomes now a wrapper around the new function.

This is needed to avoid code duplication in vSIE.

---
   arch/s390/kvm/gaccess.h | 23 +++++++++++++++++------
   1 file changed, 17 insertions(+), 6 deletions(-)
arch/s390/kvm/gaccess.h +2 -2
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
 
   /**
    * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu
+ * @prefix - guest prefix
    * @gra - guest real address
    *
    * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
    */
Quoted 8 lines

arch/s390/kvm/gaccess.h line 27

Quoted 3 lines
arch/s390/kvm/gaccess.h +1 -2
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)

<bikeshedding>
Just a matter of taste, but maybe this could be named differently? kvm_s390_real2abs_prefix() ? kvm_s390_prefix_real_to_abs()? </bikeshedding>

+1, I also dislike these "_.*" style functions here.

Quoted 4 lines

Anyway:

Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#4 lore raw

Re: [PATCH v1 1/2] s390/kvm: split kvm_s390_real_to_abs

Quoted 24 lines · David Hildenbrand
Quoted 15 lines
Quoted 15 lines
arch/s390/kvm/gaccess.h +2 -2
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
   /**
    * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu
+ * @prefix - guest prefix
    * @gra - guest real address
    *
    * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
    */
Quoted 8 lines

arch/s390/kvm/gaccess.h line 27

Quoted 3 lines
arch/s390/kvm/gaccess.h +1 -2
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)

<bikeshedding>
Just a matter of taste, but maybe this could be named differently? kvm_s390_real2abs_prefix() ? kvm_s390_prefix_real_to_abs()? </bikeshedding>

Quoted 1 line

+1, I also dislike these "_.*" style functions here.

Yes, let's bikeshed then :)

Could you then please try to rename page_to* and everything that looks similar to page2* please? I'm wondering what the response will be..

#5 lore raw

Re: [PATCH v1 1/2] s390/kvm: split kvm_s390_real_to_abs

Quoted 25 lines · Heiko Carstens
Quoted 24 lines · David Hildenbrand
Quoted 23 lines
Quoted 8 lines
arch/s390/kvm/gaccess.h +0 -1
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
    /**
     * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu

arch/s390/kvm/gaccess.h line 26

Quoted 10 lines
arch/s390/kvm/gaccess.h +3 -3
+ * @prefix - guest prefix
     * @gra - guest real address
     *
     * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
     */
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)

<bikeshedding>
Just a matter of taste, but maybe this could be named differently? kvm_s390_real2abs_prefix() ? kvm_s390_prefix_real_to_abs()? </bikeshedding>

Quoted 6 lines
Quoted 1 line

+1, I also dislike these "_.*" style functions here.

Yes, let's bikeshed then :)

Could you then please try to rename page_to* and everything that looks similar to page2* please? I'm wondering what the response will be..

Oh, we're bikeshedding about anything now? Cool.

Signature · 3 lines
Thanks,

David / dhildenb
#6 lore raw

Re: [PATCH v1 1/2] s390/kvm: split kvm_s390_real_to_abs

Quoted 26 lines · David Hildenbrand
Quoted 25 lines · Heiko Carstens
Quoted 24 lines · David Hildenbrand
Quoted 23 lines
Quoted 8 lines
arch/s390/kvm/gaccess.h +0 -1
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
     /**
      * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu

arch/s390/kvm/gaccess.h line 26

Quoted 10 lines
arch/s390/kvm/gaccess.h +3 -3
+ * @prefix - guest prefix
      * @gra - guest real address
      *
      * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
      */
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)

<bikeshedding>
Just a matter of taste, but maybe this could be named differently? kvm_s390_real2abs_prefix() ? kvm_s390_prefix_real_to_abs()? </bikeshedding>

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

+1, I also dislike these "_.*" style functions here.

Yes, let's bikeshed then :)

Could you then please try to rename page_to* and everything that looks similar to page2* please? I'm wondering what the response will be..

Oh, we're bikeshedding about anything now? Cool.

(I agree that real2abs is not such a good idea ;) )

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH v1 1/2] s390/kvm: split kvm_s390_real_to_abs

In reply to Heiko Carstens
Quoted 25 lines · Heiko Carstens
Quoted 24 lines · David Hildenbrand
Quoted 23 lines
Quoted 8 lines
arch/s390/kvm/gaccess.h +0 -1
index daba10f76936..7c72a5e3449f 100644
@@ -18,17 +18,14 @@
    /**
     * kvm_s390_real_to_abs - convert guest real address to guest absolute address
- * @vcpu - guest virtual cpu

arch/s390/kvm/gaccess.h line 26

Quoted 10 lines
arch/s390/kvm/gaccess.h +3 -3
+ * @prefix - guest prefix
     * @gra - guest real address
     *
     * Returns the guest absolute address that corresponds to the passed guest real
- * address @gra of a virtual guest cpu by applying its prefix.
+ * address @gra of by applying the given prefix.
     */
-static inline unsigned long kvm_s390_real_to_abs(struct kvm_vcpu *vcpu,
-						 unsigned long gra)
+static inline unsigned long _kvm_s390_real_to_abs(u32 prefix, unsigned long gra)

<bikeshedding>
Just a matter of taste, but maybe this could be named differently? kvm_s390_real2abs_prefix() ? kvm_s390_prefix_real_to_abs()? </bikeshedding>

Quoted 6 lines
Quoted 1 line

+1, I also dislike these "_.*" style functions here.

Yes, let's bikeshed then :)

Could you then please try to rename page_to* and everything that looks similar to page2* please? I'm wondering what the response will be..

Given that this is stable material (due to patch 2), can we try to minimize the bikeshedding to everything that his touched by this patch?

Claudio, can you respin the series addressing the comments?
I will then either add this to next or fold that into the existing next patches. Not sure yet.

author maintainer
#8 lore raw

PATCH 2/2 s390/kvm: VSIE: fix MVPG handling for prefixing and MSO

In reply to Claudio Imbrenda

Prefixing needs to be applied to the guest real address to translate it into a guest absolute address.

The value of MSO needs to be added to a guest-absolute address in order to obtain the host-virtual.

Fixes 223ea46de9e79 ("s390/kvm: VSIE: correctly handle MVPG when in VSIE")
---
 arch/s390/kvm/vsie.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
arch/s390/kvm/vsie.c +7 -3
index 48aab6290a77..92864f9b3d84 100644
@@ -1002,7 +1002,7 @@ static u64 vsie_get_register(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
 static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 {
 	struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
-	unsigned long pei_dest, pei_src, src, dest, mask;
+	unsigned long pei_dest, pei_src, r1, r2, src, dest, mask, mso, prefix;
 	u64 *pei_block = &vsie_page->scb_o->mcic;
 	int edat, rc_dest, rc_src;
 	union ctlreg0 cr0;
@@ -1010,9 +1010,13 @@ static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	cr0.val = vcpu->arch.sie_block->gcr[0];
 	edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
 	mask = _kvm_s390_logical_to_effective(&scb_s->gpsw, PAGE_MASK);
+	mso = READ_ONCE(vsie_page->scb_o->mso) & ~(1UL << 20);
+	prefix = scb_s->prefix << GUEST_PREFIX_SHIFT;
 
-	dest = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16) & mask;
-	src = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20) & mask;
+	r1 = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16);
+	r2 = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20);
+	dest = _kvm_s390_real_to_abs(prefix, r1 & mask) + mso;
+	src = _kvm_s390_real_to_abs(prefix, r2 & mask) + mso;
 
 	rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest);
 	rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src);
Signature · 1 line
2.26.2
#9 lore raw

Re: [PATCH v1 2/2] s390/kvm: VSIE: fix MVPG handling for prefixing and MSO

Quoted 27 lines · Claudio Imbrenda

Prefixing needs to be applied to the guest real address to translate it into a guest absolute address.

The value of MSO needs to be added to a guest-absolute address in order to obtain the host-virtual.

Fixes 223ea46de9e79 ("s390/kvm: VSIE: correctly handle MVPG when in VSIE")
---
  arch/s390/kvm/vsie.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
arch/s390/kvm/vsie.c +1 -1
index 48aab6290a77..92864f9b3d84 100644
@@ -1002,7 +1002,7 @@ static u64 vsie_get_register(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
  static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  {
  	struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
-	unsigned long pei_dest, pei_src, src, dest, mask;
+	unsigned long pei_dest, pei_src, r1, r2, src, dest, mask, mso, prefix;
  	u64 *pei_block = &vsie_page->scb_o->mcic;
  	int edat, rc_dest, rc_src;
  	union ctlreg0 cr0;

arch/s390/kvm/vsie.c static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 1013

Quoted 4 lines
arch/s390/kvm/vsie.c +1 -0
@@ -1010,9 +1010,13 @@ static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	cr0.val = vcpu->arch.sie_block->gcr[0];
  	edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
  	mask = _kvm_s390_logical_to_effective(&scb_s->gpsw, PAGE_MASK);
+	mso = READ_ONCE(vsie_page->scb_o->mso) & ~(1UL << 20);

I think we should use the one stored in the shadow page - this is what the SIE saw and will see when retrying.

arch/s390/kvm/vsie.c static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 1017

Quoted 6 lines
arch/s390/kvm/vsie.c +3 -2
+	prefix = scb_s->prefix << GUEST_PREFIX_SHIFT;
 
-	dest = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16) & mask;
-	src = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20) & mask;
+	r1 = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16);
+	r2 = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20);

Just reuse dest and src here?

arch/s390/kvm/vsie.c static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 1022

Quoted 6 lines
arch/s390/kvm/vsie.c +2 -0
+	dest = _kvm_s390_real_to_abs(prefix, r1 & mask) + mso;
+	src = _kvm_s390_real_to_abs(prefix, r2 & mask) + mso;
 
  	rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest);
  	rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src);

Apart from that, looks good to me.

Signature · 3 lines
Thanks,

David / dhildenb