public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL 0/3] KVM: s390: Changes for 6.4
@ 2023-04-26 12:51 Janosch Frank
  2023-04-26 12:51 ` [GIT PULL 1/3] KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA Janosch Frank
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Janosch Frank @ 2023-04-26 12:51 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda

Hi Paolo,

nothing major for today, two patches that continue our phys_to_virt()
conversion efforts and a patch that increases readability.

Please pull,
Janosch

The following changes since commit eeac8ede17557680855031c6f305ece2378af326:

  Linux 6.3-rc2 (2023-03-12 16:36:44 -0700)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.4-1

for you to fetch changes up to 8a46df7cd135fe576c18efa418cd1549e51f2732:

  KVM: s390: pci: fix virtual-physical confusion on module unload/load (2023-04-20 16:30:35 +0200)

----------------------------------------------------------------
Minor cleanup:
 - phys_to_virt conversion
 - Improvement of VSIE AP management

----------------------------------------------------------------
Nico Boehr (2):
      KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA
      KVM: s390: pci: fix virtual-physical confusion on module unload/load

Pierre Morel (1):
      KVM: s390: vsie: clarifications on setting the APCB

 arch/s390/kvm/interrupt.c |  4 ++--
 arch/s390/kvm/pci.c       |  2 +-
 arch/s390/kvm/vsie.c      | 50 +++++++++++++++++++++++++++--------------------
 3 files changed, 32 insertions(+), 24 deletions(-)


Nico Boehr (2):
  KVM: s390: interrupt: fix virtual-physical confusion for next alert
    GISA
  KVM: s390: pci: fix virtual-physical confusion on module unload/load

Pierre Morel (1):
  KVM: s390: vsie: clarifications on setting the APCB

 arch/s390/kvm/interrupt.c |  4 ++--
 arch/s390/kvm/pci.c       |  2 +-
 arch/s390/kvm/vsie.c      | 50 +++++++++++++++++++++++----------------
 3 files changed, 32 insertions(+), 24 deletions(-)

-- 
2.40.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [GIT PULL 1/3] KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA
  2023-04-26 12:51 [GIT PULL 0/3] KVM: s390: Changes for 6.4 Janosch Frank
@ 2023-04-26 12:51 ` Janosch Frank
  2023-04-26 12:51 ` [GIT PULL 2/3] KVM: s390: vsie: clarifications on setting the APCB Janosch Frank
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2023-04-26 12:51 UTC (permalink / raw)
  To: pbonzini
  Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda,
	Nico Boehr, Michael Mueller

From: Nico Boehr <nrb@linux.ibm.com>

We sometimes put a virtual address in next_alert, which should always be
a physical address, since it is shared with hardware.

This currently works, because virtual and physical addresses are
the same.

Add phys_to_virt() to resolve the virtual-physical confusion.

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Michael Mueller <mimu@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20230223162236.51569-1-nrb@linux.ibm.com
Message-Id: <20230223162236.51569-1-nrb@linux.ibm.com>
---
 arch/s390/kvm/interrupt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 9250fde1f97d..da6dac36e959 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -305,7 +305,7 @@ static inline u8 gisa_get_ipm_or_restore_iam(struct kvm_s390_gisa_interrupt *gi)
 
 static inline int gisa_in_alert_list(struct kvm_s390_gisa *gisa)
 {
-	return READ_ONCE(gisa->next_alert) != (u32)(u64)gisa;
+	return READ_ONCE(gisa->next_alert) != (u32)virt_to_phys(gisa);
 }
 
 static inline void gisa_set_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
@@ -3168,7 +3168,7 @@ void kvm_s390_gisa_init(struct kvm *kvm)
 	hrtimer_init(&gi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	gi->timer.function = gisa_vcpu_kicker;
 	memset(gi->origin, 0, sizeof(struct kvm_s390_gisa));
-	gi->origin->next_alert = (u32)(u64)gi->origin;
+	gi->origin->next_alert = (u32)virt_to_phys(gi->origin);
 	VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin);
 }
 
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [GIT PULL 2/3] KVM: s390: vsie: clarifications on setting the APCB
  2023-04-26 12:51 [GIT PULL 0/3] KVM: s390: Changes for 6.4 Janosch Frank
  2023-04-26 12:51 ` [GIT PULL 1/3] KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA Janosch Frank
@ 2023-04-26 12:51 ` Janosch Frank
  2023-04-26 12:51 ` [GIT PULL 3/3] KVM: s390: pci: fix virtual-physical confusion on module unload/load Janosch Frank
  2023-04-26 19:43 ` [GIT PULL 0/3] KVM: s390: Changes for 6.4 Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2023-04-26 12:51 UTC (permalink / raw)
  To: pbonzini
  Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda,
	Pierre Morel

From: Pierre Morel <pmorel@linux.ibm.com>

The APCB is part of the CRYCB.
The calculation of the APCB origin can be done by adding
the APCB offset to the CRYCB origin.

Current code makes confusing transformations, converting
the CRYCB origin to a pointer to calculate the APCB origin.

Let's make things simpler and keep the CRYCB origin to make
these calculations.

Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20230214122841.13066-2-pmorel@linux.ibm.com
Message-Id: <20230214122841.13066-2-pmorel@linux.ibm.com>
---
 arch/s390/kvm/vsie.c | 50 +++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index b6a0219e470a..8d6b765abf29 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -138,11 +138,15 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 }
 /* Copy to APCB FORMAT1 from APCB FORMAT0 */
 static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s,
-			unsigned long apcb_o, struct kvm_s390_apcb1 *apcb_h)
+			unsigned long crycb_gpa, struct kvm_s390_apcb1 *apcb_h)
 {
 	struct kvm_s390_apcb0 tmp;
+	unsigned long apcb_gpa;
 
-	if (read_guest_real(vcpu, apcb_o, &tmp, sizeof(struct kvm_s390_apcb0)))
+	apcb_gpa = crycb_gpa + offsetof(struct kvm_s390_crypto_cb, apcb0);
+
+	if (read_guest_real(vcpu, apcb_gpa, &tmp,
+			    sizeof(struct kvm_s390_apcb0)))
 		return -EFAULT;
 
 	apcb_s->apm[0] = apcb_h->apm[0] & tmp.apm[0];
@@ -157,15 +161,19 @@ static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s,
  * setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0
  * @vcpu: pointer to the virtual CPU
  * @apcb_s: pointer to start of apcb in the shadow crycb
- * @apcb_o: pointer to start of original apcb in the guest2
+ * @crycb_gpa: guest physical address to start of original guest crycb
  * @apcb_h: pointer to start of apcb in the guest1
  *
  * Returns 0 and -EFAULT on error reading guest apcb
  */
 static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
-			unsigned long apcb_o, unsigned long *apcb_h)
+			unsigned long crycb_gpa, unsigned long *apcb_h)
 {
-	if (read_guest_real(vcpu, apcb_o, apcb_s,
+	unsigned long apcb_gpa;
+
+	apcb_gpa = crycb_gpa + offsetof(struct kvm_s390_crypto_cb, apcb0);
+
+	if (read_guest_real(vcpu, apcb_gpa, apcb_s,
 			    sizeof(struct kvm_s390_apcb0)))
 		return -EFAULT;
 
@@ -178,16 +186,20 @@ static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
  * setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB
  * @vcpu: pointer to the virtual CPU
  * @apcb_s: pointer to start of apcb in the shadow crycb
- * @apcb_o: pointer to start of original guest apcb
+ * @crycb_gpa: guest physical address to start of original guest crycb
  * @apcb_h: pointer to start of apcb in the host
  *
  * Returns 0 and -EFAULT on error reading guest apcb
  */
 static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
-			unsigned long apcb_o,
+			unsigned long crycb_gpa,
 			unsigned long *apcb_h)
 {
-	if (read_guest_real(vcpu, apcb_o, apcb_s,
+	unsigned long apcb_gpa;
+
+	apcb_gpa = crycb_gpa + offsetof(struct kvm_s390_crypto_cb, apcb1);
+
+	if (read_guest_real(vcpu, apcb_gpa, apcb_s,
 			    sizeof(struct kvm_s390_apcb1)))
 		return -EFAULT;
 
@@ -200,7 +212,7 @@ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
  * setup_apcb - Create a shadow copy of the apcb.
  * @vcpu: pointer to the virtual CPU
  * @crycb_s: pointer to shadow crycb
- * @crycb_o: pointer to original guest crycb
+ * @crycb_gpa: guest physical address of original guest crycb
  * @crycb_h: pointer to the host crycb
  * @fmt_o: format of the original guest crycb.
  * @fmt_h: format of the host crycb.
@@ -211,50 +223,46 @@ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s,
  * Return 0 or an error number if the guest and host crycb are incompatible.
  */
 static int setup_apcb(struct kvm_vcpu *vcpu, struct kvm_s390_crypto_cb *crycb_s,
-	       const u32 crycb_o,
+	       const u32 crycb_gpa,
 	       struct kvm_s390_crypto_cb *crycb_h,
 	       int fmt_o, int fmt_h)
 {
-	struct kvm_s390_crypto_cb *crycb;
-
-	crycb = (struct kvm_s390_crypto_cb *) (unsigned long)crycb_o;
-
 	switch (fmt_o) {
 	case CRYCB_FORMAT2:
-		if ((crycb_o & PAGE_MASK) != ((crycb_o + 256) & PAGE_MASK))
+		if ((crycb_gpa & PAGE_MASK) != ((crycb_gpa + 256) & PAGE_MASK))
 			return -EACCES;
 		if (fmt_h != CRYCB_FORMAT2)
 			return -EINVAL;
 		return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1,
-				    (unsigned long) &crycb->apcb1,
+				    crycb_gpa,
 				    (unsigned long *)&crycb_h->apcb1);
 	case CRYCB_FORMAT1:
 		switch (fmt_h) {
 		case CRYCB_FORMAT2:
 			return setup_apcb10(vcpu, &crycb_s->apcb1,
-					    (unsigned long) &crycb->apcb0,
+					    crycb_gpa,
 					    &crycb_h->apcb1);
 		case CRYCB_FORMAT1:
 			return setup_apcb00(vcpu,
 					    (unsigned long *) &crycb_s->apcb0,
-					    (unsigned long) &crycb->apcb0,
+					    crycb_gpa,
 					    (unsigned long *) &crycb_h->apcb0);
 		}
 		break;
 	case CRYCB_FORMAT0:
-		if ((crycb_o & PAGE_MASK) != ((crycb_o + 32) & PAGE_MASK))
+		if ((crycb_gpa & PAGE_MASK) != ((crycb_gpa + 32) & PAGE_MASK))
 			return -EACCES;
 
 		switch (fmt_h) {
 		case CRYCB_FORMAT2:
 			return setup_apcb10(vcpu, &crycb_s->apcb1,
-					    (unsigned long) &crycb->apcb0,
+					    crycb_gpa,
 					    &crycb_h->apcb1);
 		case CRYCB_FORMAT1:
 		case CRYCB_FORMAT0:
 			return setup_apcb00(vcpu,
 					    (unsigned long *) &crycb_s->apcb0,
-					    (unsigned long) &crycb->apcb0,
+					    crycb_gpa,
 					    (unsigned long *) &crycb_h->apcb0);
 		}
 	}
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [GIT PULL 3/3] KVM: s390: pci: fix virtual-physical confusion on module unload/load
  2023-04-26 12:51 [GIT PULL 0/3] KVM: s390: Changes for 6.4 Janosch Frank
  2023-04-26 12:51 ` [GIT PULL 1/3] KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA Janosch Frank
  2023-04-26 12:51 ` [GIT PULL 2/3] KVM: s390: vsie: clarifications on setting the APCB Janosch Frank
@ 2023-04-26 12:51 ` Janosch Frank
  2023-04-26 19:43 ` [GIT PULL 0/3] KVM: s390: Changes for 6.4 Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2023-04-26 12:51 UTC (permalink / raw)
  To: pbonzini
  Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda,
	Nico Boehr, Matthew Rosato

From: Nico Boehr <nrb@linux.ibm.com>

When the kvm module is unloaded, zpci_setup_aipb() perists some data in the
zpci_aipb structure in s390 pci code. Note that this struct is also passed
to firmware in the zpci_set_irq_ctrl() call and thus the GAIT must be a
physical address.

On module re-insertion, the GAIT is restored from this structure in
zpci_reset_aipb(). But it is a physical address, hence this may cause
issues when the kvm module is unloaded and loaded again.

Fix virtual vs physical address confusion (which currently are the same) by
adding the necessary physical-to-virtual-conversion in zpci_reset_aipb().

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Link: https://lore.kernel.org/r/20230222155503.43399-1-nrb@linux.ibm.com
Message-Id: <20230222155503.43399-1-nrb@linux.ibm.com>
---
 arch/s390/kvm/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index b124d586db55..7dab00f1e833 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -112,7 +112,7 @@ static int zpci_reset_aipb(u8 nisc)
 		return -EINVAL;
 
 	aift->sbv = zpci_aif_sbv;
-	aift->gait = (struct zpci_gaite *)zpci_aipb->aipb.gait;
+	aift->gait = phys_to_virt(zpci_aipb->aipb.gait);
 
 	return 0;
 }
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [GIT PULL 0/3] KVM: s390: Changes for 6.4
  2023-04-26 12:51 [GIT PULL 0/3] KVM: s390: Changes for 6.4 Janosch Frank
                   ` (2 preceding siblings ...)
  2023-04-26 12:51 ` [GIT PULL 3/3] KVM: s390: pci: fix virtual-physical confusion on module unload/load Janosch Frank
@ 2023-04-26 19:43 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2023-04-26 19:43 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, david, borntraeger, cohuck, linux-s390, imbrenda

On Wed, Apr 26, 2023 at 2:52 PM Janosch Frank <frankja@linux.ibm.com> wrote:
>
> Hi Paolo,
>
> nothing major for today, two patches that continue our phys_to_virt()
> conversion efforts and a patch that increases readability.
>
> Please pull,
> Janosch

Queued, thanks.

Paolo

> The following changes since commit eeac8ede17557680855031c6f305ece2378af326:
>
>   Linux 6.3-rc2 (2023-03-12 16:36:44 -0700)
>
> are available in the Git repository at:
>
>   https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.4-1
>
> for you to fetch changes up to 8a46df7cd135fe576c18efa418cd1549e51f2732:
>
>   KVM: s390: pci: fix virtual-physical confusion on module unload/load (2023-04-20 16:30:35 +0200)
>
> ----------------------------------------------------------------
> Minor cleanup:
>  - phys_to_virt conversion
>  - Improvement of VSIE AP management
>
> ----------------------------------------------------------------
> Nico Boehr (2):
>       KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA
>       KVM: s390: pci: fix virtual-physical confusion on module unload/load
>
> Pierre Morel (1):
>       KVM: s390: vsie: clarifications on setting the APCB
>
>  arch/s390/kvm/interrupt.c |  4 ++--
>  arch/s390/kvm/pci.c       |  2 +-
>  arch/s390/kvm/vsie.c      | 50 +++++++++++++++++++++++++++--------------------
>  3 files changed, 32 insertions(+), 24 deletions(-)
>
>
> Nico Boehr (2):
>   KVM: s390: interrupt: fix virtual-physical confusion for next alert
>     GISA
>   KVM: s390: pci: fix virtual-physical confusion on module unload/load
>
> Pierre Morel (1):
>   KVM: s390: vsie: clarifications on setting the APCB
>
>  arch/s390/kvm/interrupt.c |  4 ++--
>  arch/s390/kvm/pci.c       |  2 +-
>  arch/s390/kvm/vsie.c      | 50 +++++++++++++++++++++++----------------
>  3 files changed, 32 insertions(+), 24 deletions(-)
>
> --
> 2.40.0
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-26 19:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-26 12:51 [GIT PULL 0/3] KVM: s390: Changes for 6.4 Janosch Frank
2023-04-26 12:51 ` [GIT PULL 1/3] KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA Janosch Frank
2023-04-26 12:51 ` [GIT PULL 2/3] KVM: s390: vsie: clarifications on setting the APCB Janosch Frank
2023-04-26 12:51 ` [GIT PULL 3/3] KVM: s390: pci: fix virtual-physical confusion on module unload/load Janosch Frank
2023-04-26 19:43 ` [GIT PULL 0/3] KVM: s390: Changes for 6.4 Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox