Skip to contentSkip to conversation

KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA

PATCH Superseded Nico Boehr 3 participants 5 messages Feb 23, 2023 – Mar 8, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

PATCH 1/1 KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA

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.

---
 arch/s390/kvm/interrupt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/interrupt.c +2 -2
index ab26aa53ee37..20743c5b000a 100644
@@ -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)
@@ -3167,7 +3167,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);
 }
 
Signature · 1 line
2.39.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Nico Boehr

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.

I'd replace that with something like:

The gisa next alert address is defined as a host absolute address so let's use virt_to_phys() to make sure we always write an absolute address to this hardware structure.

This is not a bug since we're currently still running as a virtual == physical kernel but plan to move away from that.

Quoted 2 lines

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

Quoted 28 lines
---
  arch/s390/kvm/interrupt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/interrupt.c +2 -2
index ab26aa53ee37..20743c5b000a 100644
@@ -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)
@@ -3167,7 +3167,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 lore raw
In reply to Nico Boehr
Quoted 27 lines · Nico Boehr

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.

---
  arch/s390/kvm/interrupt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/interrupt.c +1 -1
index ab26aa53ee37..20743c5b000a 100644
@@ -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)

arch/s390/kvm/interrupt.c void kvm_s390_gisa_init(struct kvm *kvm) · line 3173

Quoted 8 lines
arch/s390/kvm/interrupt.c +1 -1
@@ -3167,7 +3167,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);
  }
 

Here is my

I ran hades tests as well. Thanks.

maintainer
#3 lore raw
Quoted 41 lines · Michael Mueller
Quoted 27 lines · Nico Boehr

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.

---
   arch/s390/kvm/interrupt.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/interrupt.c +1 -1
index ab26aa53ee37..20743c5b000a 100644
@@ -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)

arch/s390/kvm/interrupt.c void kvm_s390_gisa_init(struct kvm *kvm) · line 3173

Quoted 8 lines
arch/s390/kvm/interrupt.c +1 -1
@@ -3167,7 +3167,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);
   }
 

Here is my

Quoted 1 line

After a consultation with Michael I'm now a 100% sure this is a rev-by and not a s-o-b. I've picked the patch with his rev-by.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Nico Boehr
Quoted 27 lines · Nico Boehr

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.

---
  arch/s390/kvm/interrupt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/interrupt.c +1 -1
index ab26aa53ee37..20743c5b000a 100644
@@ -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)

arch/s390/kvm/interrupt.c void kvm_s390_gisa_init(struct kvm *kvm) · line 3173

Quoted 8 lines
arch/s390/kvm/interrupt.c +1 -1
@@ -3167,7 +3167,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);
  }
 

I ran hades tests as well. Thanks.

Here is my