Skip to contentSkip to conversation

xen/arm: fix SBDF calculation for vPCI MMIO handlers

PATCH In review Oleksandr Andrushchenko 4 participants 5 messages Nov 2, 2021 – Nov 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/arm: fix SBDF calculation for vPCI MMIO handlers

From: Oleksandr Andrushchenko <[email protected]>

While in vPCI MMIO trap handlers for the guest PCI host bridge it is not enough for SBDF translation to simply call VPCI_ECAM_BDF(info->gpa) as the base address may not be aligned in the way that the translation always work. If not adjusted with respect to the base address it may not be able to properly convert SBDF.
Fix this by adjusting the gpa with respect to the host bridge base address in a way as it is done for x86.

Please note, that this change is not strictly required given the current value of GUEST_VPCI_ECAM_BASE which has bits 0 to 27 clear, but could cause issues if such value is changed, or when handlers for dom0 ECAM regions are added as those will be mapped over existing hardware regions that could use non-aligned base addresses.

Fixes d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support for ARM")

---
Since v1:
- updated commit message (Roger)

This patch aims for 4.16 release.
Benefits:
Fix potential bug and clear the way for further PCI passthrough development.
Risks:
None as the change doesn't change the behaviour of the current code, but brings clarity into SBDF calculation.

---
 xen/arch/arm/vpci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/vpci.c +2 -2
index 8f40a0dec6d2..23f45386f4b3 100644
@@ -24,7 +24,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
     unsigned long data;
 
     /* We ignore segment part and always handle segment 0 */
-    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE);
 
     if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
                         1U << info->dabt.size, &data) )
@@ -44,7 +44,7 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
     pci_sbdf_t sbdf;
 
     /* We ignore segment part and always handle segment 0 */
-    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE);
 
     return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa),
                            1U << info->dabt.size, r);
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#1 lore raw
Quoted 16 lines · Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

While in vPCI MMIO trap handlers for the guest PCI host bridge it is not enough for SBDF translation to simply call VPCI_ECAM_BDF(info->gpa) as the base address may not be aligned in the way that the translation always work. If not adjusted with respect to the base address it may not be able to properly convert SBDF.
Fix this by adjusting the gpa with respect to the host bridge base address in a way as it is done for x86.

Please note, that this change is not strictly required given the current value of GUEST_VPCI_ECAM_BASE which has bits 0 to 27 clear, but could cause issues if such value is changed, or when handlers for dom0 ECAM regions are added as those will be mapped over existing hardware regions that could use non-aligned base addresses.

Quoted 3 lines
Fixes d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support for ARM")

Also, Ian already gave his release-ack.

Quoted 40 lines

---
Since v1:
- updated commit message (Roger)

This patch aims for 4.16 release.
Benefits:
Fix potential bug and clear the way for further PCI passthrough development.
Risks:
None as the change doesn't change the behaviour of the current code, but brings clarity into SBDF calculation.

---
 xen/arch/arm/vpci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/vpci.c +2 -2
index 8f40a0dec6d2..23f45386f4b3 100644
@@ -24,7 +24,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
     unsigned long data;
 
     /* We ignore segment part and always handle segment 0 */
-    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE);
 
     if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
                         1U << info->dabt.size, &data) )
@@ -44,7 +44,7 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
     pci_sbdf_t sbdf;
 
     /* We ignore segment part and always handle segment 0 */
-    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE);
 
     return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa),
                            1U << info->dabt.size, r);
Signature · 1 line
2.25.1
#2 lore raw
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

While in vPCI MMIO trap handlers for the guest PCI host bridge it is not enough for SBDF translation to simply call VPCI_ECAM_BDF(info->gpa) as the base address may not be aligned in the way that the translation always work. If not adjusted with respect to the base address it may not be able to properly convert SBDF.
Fix this by adjusting the gpa with respect to the host bridge base address in a way as it is done for x86.

Please note, that this change is not strictly required given the current value of GUEST_VPCI_ECAM_BASE which has bits 0 to 27 clear, but could cause issues if such value is changed, or when handlers for dom0 ECAM regions are added as those will be mapped over existing hardware regions that could use non-aligned base addresses.

Quoted 6 lines
Quoted 3 lines
Fixes d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support for ARM")

Also, Ian already gave his release-ack.

Thank you,
Do I need to resend the patch with Acks? Or hopefully those can be applied on commit?

Quoted 42 lines
Quoted 42 lines

---
Since v1:
- updated commit message (Roger)

This patch aims for 4.16 release.
Benefits:
Fix potential bug and clear the way for further PCI passthrough development.
Risks:
None as the change doesn't change the behaviour of the current code, but brings clarity into SBDF calculation.

---
  xen/arch/arm/vpci.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/vpci.c +2 -2
index 8f40a0dec6d2..23f45386f4b3 100644
@@ -24,7 +24,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info,
      unsigned long data;
 
      /* We ignore segment part and always handle segment 0 */
-    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE);
 
      if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa),
                          1U << info->dabt.size, &data) )
@@ -44,7 +44,7 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info,
      pci_sbdf_t sbdf;
 
      /* We ignore segment part and always handle segment 0 */
-    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa);
+    sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE);
 
      return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa),
                             1U << info->dabt.size, r);
Signature · 1 line
2.25.1
#3 lore raw

Hi Oleksandr,

Quoted 22 lines · Oleksandr Andrushchenko
Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

While in vPCI MMIO trap handlers for the guest PCI host bridge it is not enough for SBDF translation to simply call VPCI_ECAM_BDF(info->gpa) as the base address may not be aligned in the way that the translation always work. If not adjusted with respect to the base address it may not be able to properly convert SBDF.
Fix this by adjusting the gpa with respect to the host bridge base address in a way as it is done for x86.

Please note, that this change is not strictly required given the current value of GUEST_VPCI_ECAM_BASE which has bits 0 to 27 clear, but could cause issues if such value is changed, or when handlers for dom0 ECAM regions are added as those will be mapped over existing hardware regions that could use non-aligned base addresses.

Fixes d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support for ARM")
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Also, Ian already gave his release-ack.

Thank you,
Do I need to resend the patch with Acks? Or hopefully those can be applied on commit?

I have committed with the two tags applied.

Next time, please remember to carry Release-acked-by tag.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Hi, Julien!

Quoted 26 lines · Julien Grall

Hi Oleksandr,

Quoted 23 lines · Oleksandr Andrushchenko
Quoted 20 lines · Stefano Stabellini
Quoted 19 lines · Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

While in vPCI MMIO trap handlers for the guest PCI host bridge it is not enough for SBDF translation to simply call VPCI_ECAM_BDF(info->gpa) as the base address may not be aligned in the way that the translation always work. If not adjusted with respect to the base address it may not be able to properly convert SBDF.
Fix this by adjusting the gpa with respect to the host bridge base address in a way as it is done for x86.

Please note, that this change is not strictly required given the current value of GUEST_VPCI_ECAM_BASE which has bits 0 to 27 clear, but could cause issues if such value is changed, or when handlers for dom0 ECAM regions are added as those will be mapped over existing hardware regions that could use non-aligned base addresses.

Fixes d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support for ARM")
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Also, Ian already gave his release-ack.

Thank you,
Do I need to resend the patch with Acks? Or hopefully those can be applied on commit?

I have committed with the two tags applied.

Thank you

Quoted 2 lines

Next time, please remember to carry Release-acked-by tag.

The Release-acked-by tag was sent by Ian *after* I've sent v2 of the patch (this one) and it was in v1 mail thread....

Quoted 3 lines

Cheers,