[PATCH] x86/msi: Switch msi_info to using pci_sbdf_t

Andrew Cooper posted 1 patch 1 year, 8 months ago
Test gitlab-ci failed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20220811163740.31494-1-andrew.cooper3@citrix.com
xen/arch/x86/hvm/vmsi.c        |  4 +---
xen/arch/x86/include/asm/msi.h |  4 +---
xen/arch/x86/irq.c             |  2 +-
xen/arch/x86/msi.c             |  4 ++--
xen/arch/x86/physdev.c         | 10 +++++-----
xen/drivers/char/ns16550.c     |  4 ++--
xen/xsm/flask/hooks.c          |  2 +-
7 files changed, 13 insertions(+), 17 deletions(-)
[PATCH] x86/msi: Switch msi_info to using pci_sbdf_t
Posted by Andrew Cooper 1 year, 8 months ago
This reorders the fields in msi_info, but removes all the under-the-hood
parameter shuffling required to call pci_get_pdev().

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>
---
 xen/arch/x86/hvm/vmsi.c        |  4 +---
 xen/arch/x86/include/asm/msi.h |  4 +---
 xen/arch/x86/irq.c             |  2 +-
 xen/arch/x86/msi.c             |  4 ++--
 xen/arch/x86/physdev.c         | 10 +++++-----
 xen/drivers/char/ns16550.c     |  4 ++--
 xen/xsm/flask/hooks.c          |  2 +-
 7 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c
index 198fbd67084b..75f92885dc5e 100644
--- a/xen/arch/x86/hvm/vmsi.c
+++ b/xen/arch/x86/hvm/vmsi.c
@@ -750,9 +750,7 @@ static int vpci_msi_enable(const struct pci_dev *pdev, unsigned int nr,
                            paddr_t table_base)
 {
     struct msi_info msi_info = {
-        .seg = pdev->seg,
-        .bus = pdev->bus,
-        .devfn = pdev->devfn,
+        .sbdf = pdev->sbdf,
         .table_base = table_base,
         .entry_nr = nr,
     };
diff --git a/xen/arch/x86/include/asm/msi.h b/xen/arch/x86/include/asm/msi.h
index 117379318f2c..fe670895eed2 100644
--- a/xen/arch/x86/include/asm/msi.h
+++ b/xen/arch/x86/include/asm/msi.h
@@ -59,9 +59,7 @@
 #define FIX_MSIX_MAX_PAGES              512
 
 struct msi_info {
-    u16 seg;
-    u8 bus;
-    u8 devfn;
+    pci_sbdf_t sbdf;
     int irq;
     int entry_nr;
     uint64_t table_base;
diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index bf8b52d1114e..cd0c8a30a864 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -2162,7 +2162,7 @@ int map_domain_pirq(
         if ( !cpu_has_apic )
             goto done;
 
-        pdev = pci_get_pdev(d, PCI_SBDF(msi->seg, msi->bus, msi->devfn));
+        pdev = pci_get_pdev(d, msi->sbdf);
         if ( !pdev )
             goto done;
 
diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
index 62c4fbcfbe55..d0bf63df1def 100644
--- a/xen/arch/x86/msi.c
+++ b/xen/arch/x86/msi.c
@@ -1001,7 +1001,7 @@ static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc)
     struct msi_desc *old_desc;
 
     ASSERT(pcidevs_locked());
-    pdev = pci_get_pdev(NULL, PCI_SBDF(msi->seg, msi->bus, msi->devfn));
+    pdev = pci_get_pdev(NULL, msi->sbdf);
     if ( !pdev )
         return -ENODEV;
 
@@ -1056,7 +1056,7 @@ static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc)
     struct msi_desc *old_desc;
 
     ASSERT(pcidevs_locked());
-    pdev = pci_get_pdev(NULL, PCI_SBDF(msi->seg, msi->bus, msi->devfn));
+    pdev = pci_get_pdev(NULL, msi->sbdf);
     if ( !pdev || !pdev->msix )
         return -ENODEV;
 
diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c
index 3a50d9d0c969..2f1d955a96bd 100644
--- a/xen/arch/x86/physdev.c
+++ b/xen/arch/x86/physdev.c
@@ -312,21 +312,21 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         {
         case MAP_PIRQ_TYPE_MSI_SEG:
             map.type = MAP_PIRQ_TYPE_MSI;
-            msi.seg = map.bus >> 16;
+            msi.sbdf.seg = map.bus >> 16;
             break;
 
         case MAP_PIRQ_TYPE_MULTI_MSI:
             if ( map.table_base )
                 return -EINVAL;
-            msi.seg = map.bus >> 16;
+            msi.sbdf.seg = map.bus >> 16;
             break;
 
         default:
-            msi.seg = 0;
+            msi.sbdf.seg = 0;
             break;
         }
-        msi.bus = map.bus;
-        msi.devfn = map.devfn;
+        msi.sbdf.bus = map.bus;
+        msi.sbdf.devfn = map.devfn;
         msi.entry_nr = map.entry_nr;
         msi.table_base = map.table_base;
         ret = physdev_map_pirq(map.domid, map.type, &map.index, &map.pirq,
diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index cd3573e43df3..01a05c9aa859 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -435,8 +435,8 @@ static void __init cf_check ns16550_init_postirq(struct serial_port *port)
         if ( uart->msi )
         {
             struct msi_info msi = {
-                .bus = uart->ps_bdf[0],
-                .devfn = PCI_DEVFN(uart->ps_bdf[1], uart->ps_bdf[2]),
+                .sbdf = PCI_SBDF(0, uart->ps_bdf[0], uart->ps_bdf[1],
+                                 uart->ps_bdf[2]),
                 .irq = rc = uart->irq,
                 .entry_nr = 1
             };
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index 8c9cd0f2972d..8bd56644efe4 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -918,7 +918,7 @@ static int flask_map_domain_msi (
 {
 #ifdef CONFIG_HAS_PCI_MSI
     const struct msi_info *msi = data;
-    uint32_t machine_bdf = (msi->seg << 16) | (msi->bus << 8) | msi->devfn;
+    uint32_t machine_bdf = msi->sbdf.sbdf;
 
     AVC_AUDIT_DATA_INIT(ad, DEV);
     ad->device = machine_bdf;
-- 
2.11.0


Re: [PATCH] x86/msi: Switch msi_info to using pci_sbdf_t
Posted by Jan Beulich 1 year, 8 months ago
On 11.08.2022 18:37, Andrew Cooper wrote:
> This reorders the fields in msi_info, but removes all the under-the-hood
> parameter shuffling required to call pci_get_pdev().
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Oh, you've made the requested change yourself - thanks!

Reviewed-by: Jan Beulich <jbeulich@suse.com>

While not the primary goal as per the description, I'm particularly happy
to see ...

> --- a/xen/xsm/flask/hooks.c
> +++ b/xen/xsm/flask/hooks.c
> @@ -918,7 +918,7 @@ static int flask_map_domain_msi (
>  {
>  #ifdef CONFIG_HAS_PCI_MSI
>      const struct msi_info *msi = data;
> -    uint32_t machine_bdf = (msi->seg << 16) | (msi->bus << 8) | msi->devfn;
> +    uint32_t machine_bdf = msi->sbdf.sbdf;

... this open-coding go away.

Jan
Re: [PATCH] x86/msi: Switch msi_info to using pci_sbdf_t
Posted by Andrew Cooper 1 year, 8 months ago
On 12/08/2022 07:45, Jan Beulich wrote:
> On 11.08.2022 18:37, Andrew Cooper wrote:
>> This reorders the fields in msi_info, but removes all the under-the-hood
>> parameter shuffling required to call pci_get_pdev().
>>
>> No functional change.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Oh, you've made the requested change yourself - thanks!

I looked at the code and decided it was simple enough.

While doing it, it became clear that uart->ps_bdf[0..2] is in desperate
need too, but that was more complicated than I had time for.

> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Thanks.