Skip to contentSkip to conversation

s390/vfio-ap: GISA: sort out physical vs virtual pointers usage

PATCH Superseded Nico Boehr 4 participants 5 messages Nov 8, 2022 – Nov 17, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

PATCH 1/1 s390/vfio-ap: GISA: sort out physical vs virtual pointers usage

Fix virtual vs physical address confusion (which currently are the same) for the GISA when enabling the IRQ.

---
 drivers/s390/crypto/vfio_ap_ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_ops.c +1 -1
index 0b4cc8c597ae..20859cabbced 100644
@@ -429,7 +429,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
 
 	aqic_gisa.isc = nisc;
 	aqic_gisa.ir = 1;
-	aqic_gisa.gisa = (uint64_t)gisa >> 4;
+	aqic_gisa.gisa = (uint64_t)virt_to_phys(gisa) >> 4;
 
 	status = ap_aqic(q->apqn, aqic_gisa, h_nib);
 	switch (status.response_code) {
Signature · 1 line
2.37.3
#1 lore raw
Quoted 13 lines · Nico Boehr

Fix virtual vs physical address confusion (which currently are the same) for the GISA when enabling the IRQ.

---
  drivers/s390/crypto/vfio_ap_ops.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_ops.c +0 -0
index 0b4cc8c597ae..20859cabbced 100644

drivers/s390/crypto/vfio_ap_ops.c static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, · line 432

Quoted 5 lines
drivers/s390/crypto/vfio_ap_ops.c +1 -1
@@ -429,7 +429,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
 
  	aqic_gisa.isc = nisc;
  	aqic_gisa.ir = 1;
-	aqic_gisa.gisa = (uint64_t)gisa >> 4;
+	aqic_gisa.gisa = (uint64_t)virt_to_phys(gisa) >> 4;

I'd suggest doing s/uint64_t/u64/ or s/uint64_t/unsigned long/ but I'm wondering if (u32)(u64) would be more appropriate anyway.

@halil @christian ?

Quoted 3 lines
drivers/s390/crypto/vfio_ap_ops.c +0 -0
  	status = ap_aqic(q->apqn, aqic_gisa, h_nib);
  	switch (status.response_code) {
author
#2 lore raw

Quoting Janosch Frank (2022-11-15 09:56:52)

Quoted 15 lines · Nico Boehr
Quoted 14 lines

Fix virtual vs physical address confusion (which currently are the same) for the GISA when enabling the IRQ.

---
  drivers/s390/crypto/vfio_ap_ops.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_ops.c +0 -0
index 0b4cc8c597ae..20859cabbced 100644
@@ -429,7 +429,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
 
Quoted 7 lines

drivers/s390/crypto/vfio_ap_ops.c static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, · line 432

Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +1 -1
      aqic_gisa.isc = nisc;
      aqic_gisa.ir = 1;
-     aqic_gisa.gisa = (uint64_t)gisa >> 4;
+     aqic_gisa.gisa = (uint64_t)virt_to_phys(gisa) >> 4;

I'd suggest doing s/uint64_t/u64/ or s/uint64_t/unsigned long/ but I'm wondering if (u32)(u64) would be more appropriate anyway.

The gisa origin is a unsigned int, hence you are right, uint64_t is odd. But since virt_to_phys() returns unsigned long, the cast to uint64_t is now useless.

My suggestion is to remove the cast alltogether.

#3 lore raw
Quoted 24 lines · On Thu, 17 Nov 2022 09:50:14 +0100 Nico Boehr <[email protected]> wrote:

Quoting Janosch Frank (2022-11-15 09:56:52)

Quoted 15 lines · Nico Boehr
Quoted 14 lines

Fix virtual vs physical address confusion (which currently are the same) for the GISA when enabling the IRQ.

---
  drivers/s390/crypto/vfio_ap_ops.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_ops.c +0 -0
index 0b4cc8c597ae..20859cabbced 100644
@@ -429,7 +429,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
 
Quoted 7 lines

drivers/s390/crypto/vfio_ap_ops.c static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, · line 432

Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +1 -1
      aqic_gisa.isc = nisc;
      aqic_gisa.ir = 1;
-     aqic_gisa.gisa = (uint64_t)gisa >> 4;
+     aqic_gisa.gisa = (uint64_t)virt_to_phys(gisa) >> 4;  

I'd suggest doing s/uint64_t/u64/ or s/uint64_t/unsigned long/ but I'm wondering if (u32)(u64) would be more appropriate anyway.

Quoted 3 lines

The gisa origin is a unsigned int, hence you are right, uint64_t is odd. But since virt_to_phys() returns unsigned long, the cast to uint64_t is now useless.

My suggestion is to remove the cast alltogether.

I agree to remove it

maintainer Reviewed-by
#4 lore raw
Quoted 27 lines · On Thu, 17 Nov 2022 11:01:43 +0100 Claudio Imbrenda <[email protected]>…
Quoted 24 lines · On Thu, 17 Nov 2022 09:50:14 +0100 Nico Boehr <[email protected]> wrote:

Quoting Janosch Frank (2022-11-15 09:56:52)

Quoted 22 lines · Nico Boehr
Quoted 13 lines

Fix virtual vs physical address confusion (which currently are the same) for the GISA when enabling the IRQ.

---
  drivers/s390/crypto/vfio_ap_ops.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_ops.c +0 -0
index 0b4cc8c597ae..20859cabbced 100644

drivers/s390/crypto/vfio_ap_ops.c static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, · line 432

Quoted 5 lines
drivers/s390/crypto/vfio_ap_ops.c +1 -1
@@ -429,7 +429,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
 
      aqic_gisa.isc = nisc;
      aqic_gisa.ir = 1;
-     aqic_gisa.gisa = (uint64_t)gisa >> 4;
+     aqic_gisa.gisa = (uint64_t)virt_to_phys(gisa) >> 4;    

I'd suggest doing s/uint64_t/u64/ or s/uint64_t/unsigned long/ but I'm wondering if (u32)(u64) would be more appropriate anyway.

Quoted 1 line
Quoted 1 line

The gisa origin is a unsigned int, hence you are right, uint64_t is odd.

The reason for the cast was that gisa is a pointer, but we needed to do integer arithmetic on the address of the object pointed to by the pointer. It happens so that the pointer must point to a piece of memory that is 31 bit addressable in host real address space, but for getting the address from a pointer, casting to the unsigned integral type with-wise corresponds to the pointer is IMHO sensible regardless of that information.

Quoted 6 lines

But since virt_to_phys() returns unsigned long, the cast to uint64_t is now useless.

Quoted 2 lines

My suggestion is to remove the cast alltogether.

I agree to remove it

Right: that cast makes no sense any more. And with that change: