diff mbox series

[v5,07/10] libxl: Only map legacy PCI IRQs if they are supported

Message ID 20211008055535.337436-8-andr2000@gmail.com (mailing list archive)
State Superseded
Headers show
Series PCI devices passthrough on Arm, part 2 | expand

Commit Message

Oleksandr Andrushchenko Oct. 8, 2021, 5:55 a.m. UTC
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Arm's PCI passthrough implementation doesn't support legacy interrupts,
but MSI/MSI-X. This can be the case for other platforms too.
For that reason introduce a new CONFIG_PCI_SUPP_LEGACY_IRQ and add
it to the CFLAGS and compile the relevant code in the toolstack only if
applicable.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Rahul Singh <rahul.singh@arm.com>
Tested-by: Rahul Singh <rahul.singh@arm.com>
---
Cc: Ian Jackson <iwj@xenproject.org>
Cc: Juergen Gross <jgross@suse.com>

Since v1:
 - Minimized #idefery by introducing pci_supp_legacy_irq function
   for relevant checks
---
 tools/libs/light/Makefile    |  4 ++++
 tools/libs/light/libxl_pci.c | 13 +++++++++++++
 2 files changed, 17 insertions(+)

Comments

Anthony PERARD Oct. 11, 2021, 4:37 p.m. UTC | #1
On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> 
> Arm's PCI passthrough implementation doesn't support legacy interrupts,
> but MSI/MSI-X. This can be the case for other platforms too.
> For that reason introduce a new CONFIG_PCI_SUPP_LEGACY_IRQ and add
> it to the CFLAGS and compile the relevant code in the toolstack only if
> applicable.

I don't think that's true anymore since v2 ;-). The compiler may
choose to avoid compiling code that wouldn't be executed, but I think
that would just be optimisation.

> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> Reviewed-by: Rahul Singh <rahul.singh@arm.com>
> Tested-by: Rahul Singh <rahul.singh@arm.com>
> ---
> diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
> index 7d8c51d49242..bd3f6be2a183 100644
> --- a/tools/libs/light/Makefile
> +++ b/tools/libs/light/Makefile
> @@ -46,6 +46,10 @@ CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
>  	-Wno-declaration-after-statement -Wformat-nonliteral
>  CFLAGS += -I.
>  
> +ifeq ($(CONFIG_X86),y)
> +CFLAGS += -DCONFIG_PCI_SUPP_LEGACY_IRQ
> +endif
> +

Could you write this instead:
  CFLAGS-$(CONFIG_X86) += -DCONFIG_PCI_SUPP_LEGACY_IRQ

In any case,
Acked-by: Anthony PERARD <anthony.perard@citrix.com>

Thanks,
Stefano Stabellini Oct. 12, 2021, 1:32 a.m. UTC | #2
On Mon, 11 Oct 2021, Anthony PERARD wrote:
> On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
> > From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> > 
> > Arm's PCI passthrough implementation doesn't support legacy interrupts,
> > but MSI/MSI-X. This can be the case for other platforms too.
> > For that reason introduce a new CONFIG_PCI_SUPP_LEGACY_IRQ and add
> > it to the CFLAGS and compile the relevant code in the toolstack only if
> > applicable.
> 
> I don't think that's true anymore since v2 ;-). The compiler may
> choose to avoid compiling code that wouldn't be executed, but I think
> that would just be optimisation.
> 
> > Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> > Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> > Reviewed-by: Rahul Singh <rahul.singh@arm.com>
> > Tested-by: Rahul Singh <rahul.singh@arm.com>
> > ---
> > diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
> > index 7d8c51d49242..bd3f6be2a183 100644
> > --- a/tools/libs/light/Makefile
> > +++ b/tools/libs/light/Makefile
> > @@ -46,6 +46,10 @@ CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
> >  	-Wno-declaration-after-statement -Wformat-nonliteral
> >  CFLAGS += -I.
> >  
> > +ifeq ($(CONFIG_X86),y)
> > +CFLAGS += -DCONFIG_PCI_SUPP_LEGACY_IRQ
> > +endif
> > +
> 
> Could you write this instead:
>   CFLAGS-$(CONFIG_X86) += -DCONFIG_PCI_SUPP_LEGACY_IRQ
> 
> In any case,
> Acked-by: Anthony PERARD <anthony.perard@citrix.com>

Thanks Anthony! I made this change on commit and committed both this
patch and the previous one.
Roger Pau Monné Oct. 25, 2021, 1:22 p.m. UTC | #3
On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> 
> Arm's PCI passthrough implementation doesn't support legacy interrupts,
> but MSI/MSI-X. This can be the case for other platforms too.
> For that reason introduce a new CONFIG_PCI_SUPP_LEGACY_IRQ and add
> it to the CFLAGS and compile the relevant code in the toolstack only if
> applicable.
> 
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> Reviewed-by: Rahul Singh <rahul.singh@arm.com>
> Tested-by: Rahul Singh <rahul.singh@arm.com>
> ---
> Cc: Ian Jackson <iwj@xenproject.org>
> Cc: Juergen Gross <jgross@suse.com>
> 
> Since v1:
>  - Minimized #idefery by introducing pci_supp_legacy_irq function
>    for relevant checks
> ---
>  tools/libs/light/Makefile    |  4 ++++
>  tools/libs/light/libxl_pci.c | 13 +++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
> index 7d8c51d49242..bd3f6be2a183 100644
> --- a/tools/libs/light/Makefile
> +++ b/tools/libs/light/Makefile
> @@ -46,6 +46,10 @@ CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
>  	-Wno-declaration-after-statement -Wformat-nonliteral
>  CFLAGS += -I.
>  
> +ifeq ($(CONFIG_X86),y)
> +CFLAGS += -DCONFIG_PCI_SUPP_LEGACY_IRQ
> +endif

TBH, since CONFIG_PCI_SUPP_LEGACY_IRQ is used in a single place in the
source I would consider just using CONFIG_X86, as I think it would be
clear enough that some arches support legacy interrupt while others
don't. Not sure it's worth going through the obfuscation of defining a
separate one.

> +
>  SRCS-$(CONFIG_X86) += libxl_cpuid.c
>  SRCS-$(CONFIG_X86) += libxl_x86.c
>  SRCS-$(CONFIG_X86) += libxl_psr.c
> diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
> index 59f3686fc85e..4c2d7aeefbb2 100644
> --- a/tools/libs/light/libxl_pci.c
> +++ b/tools/libs/light/libxl_pci.c
> @@ -1364,6 +1364,15 @@ static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev,
>      pci_add_dm_done(egc, pas, rc);
>  }
>  
> +static bool pci_supp_legacy_irq(void)

A naming more inline with the PCI specification (since we insisted on
using ECAM instead of MCFG) would be intx, ie: pci_supports_intx.

Thanks, Roger.
Oleksandr Andrushchenko Oct. 25, 2021, 1:38 p.m. UTC | #4
Hi, Roger!

On 25.10.21 16:22, Roger Pau Monné wrote:
> On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>
>> Arm's PCI passthrough implementation doesn't support legacy interrupts,
>> but MSI/MSI-X. This can be the case for other platforms too.
>> For that reason introduce a new CONFIG_PCI_SUPP_LEGACY_IRQ and add
>> it to the CFLAGS and compile the relevant code in the toolstack only if
>> applicable.
>>
>> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
>> Reviewed-by: Rahul Singh <rahul.singh@arm.com>
>> Tested-by: Rahul Singh <rahul.singh@arm.com>
>> ---
>> Cc: Ian Jackson <iwj@xenproject.org>
>> Cc: Juergen Gross <jgross@suse.com>
>>
>> Since v1:
>>   - Minimized #idefery by introducing pci_supp_legacy_irq function
>>     for relevant checks
>> ---
>>   tools/libs/light/Makefile    |  4 ++++
>>   tools/libs/light/libxl_pci.c | 13 +++++++++++++
>>   2 files changed, 17 insertions(+)
>>
>> diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
>> index 7d8c51d49242..bd3f6be2a183 100644
>> --- a/tools/libs/light/Makefile
>> +++ b/tools/libs/light/Makefile
>> @@ -46,6 +46,10 @@ CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
>>   	-Wno-declaration-after-statement -Wformat-nonliteral
>>   CFLAGS += -I.
>>   
>> +ifeq ($(CONFIG_X86),y)
>> +CFLAGS += -DCONFIG_PCI_SUPP_LEGACY_IRQ
>> +endif
> TBH, since CONFIG_PCI_SUPP_LEGACY_IRQ is used in a single place in the
> source I would consider just using CONFIG_X86, as I think it would be
> clear enough that some arches support legacy interrupt while others
> don't. Not sure it's worth going through the obfuscation of defining a
> separate one.
The idea behind not using CONFIG_X86 is to be arch agnostic,
so CONFIG_PCI_SUPP_LEGACY_IRQ makes more sense with this
respect
>> +
>>   SRCS-$(CONFIG_X86) += libxl_cpuid.c
>>   SRCS-$(CONFIG_X86) += libxl_x86.c
>>   SRCS-$(CONFIG_X86) += libxl_psr.c
>> diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
>> index 59f3686fc85e..4c2d7aeefbb2 100644
>> --- a/tools/libs/light/libxl_pci.c
>> +++ b/tools/libs/light/libxl_pci.c
>> @@ -1364,6 +1364,15 @@ static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev,
>>       pci_add_dm_done(egc, pas, rc);
>>   }
>>   
>> +static bool pci_supp_legacy_irq(void)
> A naming more inline with the PCI specification (since we insisted on
> using ECAM instead of MCFG) would be intx, ie: pci_supports_intx.
This will require a follow up patch if we all agree this change is needed.
@Jan, are you ok with the rename?
>
> Thanks, Roger.
Thank you,
Oleksandr
Roger Pau Monné Oct. 25, 2021, 1:46 p.m. UTC | #5
On Mon, Oct 25, 2021 at 01:38:19PM +0000, Oleksandr Andrushchenko wrote:
> Hi, Roger!
> 
> On 25.10.21 16:22, Roger Pau Monné wrote:
> > On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
> >> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> >>
> >> Arm's PCI passthrough implementation doesn't support legacy interrupts,
> >> but MSI/MSI-X. This can be the case for other platforms too.
> >> For that reason introduce a new CONFIG_PCI_SUPP_LEGACY_IRQ and add
> >> it to the CFLAGS and compile the relevant code in the toolstack only if
> >> applicable.
> >>
> >> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> >> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> >> Reviewed-by: Rahul Singh <rahul.singh@arm.com>
> >> Tested-by: Rahul Singh <rahul.singh@arm.com>
> >> ---
> >> Cc: Ian Jackson <iwj@xenproject.org>
> >> Cc: Juergen Gross <jgross@suse.com>
> >>
> >> Since v1:
> >>   - Minimized #idefery by introducing pci_supp_legacy_irq function
> >>     for relevant checks
> >> ---
> >>   tools/libs/light/Makefile    |  4 ++++
> >>   tools/libs/light/libxl_pci.c | 13 +++++++++++++
> >>   2 files changed, 17 insertions(+)
> >>
> >> diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
> >> index 7d8c51d49242..bd3f6be2a183 100644
> >> --- a/tools/libs/light/Makefile
> >> +++ b/tools/libs/light/Makefile
> >> @@ -46,6 +46,10 @@ CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
> >>   	-Wno-declaration-after-statement -Wformat-nonliteral
> >>   CFLAGS += -I.
> >>   
> >> +ifeq ($(CONFIG_X86),y)
> >> +CFLAGS += -DCONFIG_PCI_SUPP_LEGACY_IRQ
> >> +endif
> > TBH, since CONFIG_PCI_SUPP_LEGACY_IRQ is used in a single place in the
> > source I would consider just using CONFIG_X86, as I think it would be
> > clear enough that some arches support legacy interrupt while others
> > don't. Not sure it's worth going through the obfuscation of defining a
> > separate one.
> The idea behind not using CONFIG_X86 is to be arch agnostic,
> so CONFIG_PCI_SUPP_LEGACY_IRQ makes more sense with this
> respect

I'm not going to insist, but you could have avoided modifying the
Makefile at all by just using:

static bool pci_supp_legacy_irq(void)
{
#ifdef CONFIG_X86
    return true;
#else
    return false;
#endif
}

Which IMO is clearer than the current approach since it's a single
place where CONFIG_PCI_SUPP_LEGACY_IRQ gets used.

> >> +
> >>   SRCS-$(CONFIG_X86) += libxl_cpuid.c
> >>   SRCS-$(CONFIG_X86) += libxl_x86.c
> >>   SRCS-$(CONFIG_X86) += libxl_psr.c
> >> diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
> >> index 59f3686fc85e..4c2d7aeefbb2 100644
> >> --- a/tools/libs/light/libxl_pci.c
> >> +++ b/tools/libs/light/libxl_pci.c
> >> @@ -1364,6 +1364,15 @@ static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev,
> >>       pci_add_dm_done(egc, pas, rc);
> >>   }
> >>   
> >> +static bool pci_supp_legacy_irq(void)
> > A naming more inline with the PCI specification (since we insisted on
> > using ECAM instead of MCFG) would be intx, ie: pci_supports_intx.
> This will require a follow up patch if we all agree this change is needed.
> @Jan, are you ok with the rename?

Didn't realize it was already committed, in which case I guess we could
leave it as-is.

Thanks, Roger.
Jan Beulich Nov. 2, 2021, 11:32 a.m. UTC | #6
On 25.10.2021 15:38, Oleksandr Andrushchenko wrote:
> On 25.10.21 16:22, Roger Pau Monné wrote:
>> On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
>>> --- a/tools/libs/light/libxl_pci.c
>>> +++ b/tools/libs/light/libxl_pci.c
>>> @@ -1364,6 +1364,15 @@ static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev,
>>>       pci_add_dm_done(egc, pas, rc);
>>>   }
>>>   
>>> +static bool pci_supp_legacy_irq(void)
>> A naming more inline with the PCI specification (since we insisted on
>> using ECAM instead of MCFG) would be intx, ie: pci_supports_intx.
> This will require a follow up patch if we all agree this change is needed.
> @Jan, are you ok with the rename?

Sure, but my view doesn't matter all this much anyway for libxl code.

Jan
Oleksandr Andrushchenko Nov. 2, 2021, 11:37 a.m. UTC | #7
On 02.11.21 13:32, Jan Beulich wrote:
> On 25.10.2021 15:38, Oleksandr Andrushchenko wrote:
>> On 25.10.21 16:22, Roger Pau Monné wrote:
>>> On Fri, Oct 08, 2021 at 08:55:32AM +0300, Oleksandr Andrushchenko wrote:
>>>> --- a/tools/libs/light/libxl_pci.c
>>>> +++ b/tools/libs/light/libxl_pci.c
>>>> @@ -1364,6 +1364,15 @@ static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev,
>>>>        pci_add_dm_done(egc, pas, rc);
>>>>    }
>>>>    
>>>> +static bool pci_supp_legacy_irq(void)
>>> A naming more inline with the PCI specification (since we insisted on
>>> using ECAM instead of MCFG) would be intx, ie: pci_supports_intx.
>> This will require a follow up patch if we all agree this change is needed.
>> @Jan, are you ok with the rename?
> Sure, but my view doesn't matter all this much anyway for libxl code.
Do you want a follow-up patch for this as the original change has been merged?
>
> Jan
>
Thanks,
Oleksandr
diff mbox series

Patch

diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
index 7d8c51d49242..bd3f6be2a183 100644
--- a/tools/libs/light/Makefile
+++ b/tools/libs/light/Makefile
@@ -46,6 +46,10 @@  CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
 	-Wno-declaration-after-statement -Wformat-nonliteral
 CFLAGS += -I.
 
+ifeq ($(CONFIG_X86),y)
+CFLAGS += -DCONFIG_PCI_SUPP_LEGACY_IRQ
+endif
+
 SRCS-$(CONFIG_X86) += libxl_cpuid.c
 SRCS-$(CONFIG_X86) += libxl_x86.c
 SRCS-$(CONFIG_X86) += libxl_psr.c
diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
index 59f3686fc85e..4c2d7aeefbb2 100644
--- a/tools/libs/light/libxl_pci.c
+++ b/tools/libs/light/libxl_pci.c
@@ -1364,6 +1364,15 @@  static void pci_add_timeout(libxl__egc *egc, libxl__ev_time *ev,
     pci_add_dm_done(egc, pas, rc);
 }
 
+static bool pci_supp_legacy_irq(void)
+{
+#ifdef CONFIG_PCI_SUPP_LEGACY_IRQ
+    return true;
+#else
+    return false;
+#endif
+}
+
 static void pci_add_dm_done(libxl__egc *egc,
                             pci_add_state *pas,
                             int rc)
@@ -1434,6 +1443,8 @@  static void pci_add_dm_done(libxl__egc *egc,
         }
     }
     fclose(f);
+    if (!pci_supp_legacy_irq())
+        goto out_no_irq;
     sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain,
                                 pci->bus, pci->dev, pci->func);
     f = fopen(sysfs_path, "r");
@@ -1983,6 +1994,8 @@  static void do_pci_remove(libxl__egc *egc, pci_remove_state *prs)
         }
         fclose(f);
 skip1:
+        if (!pci_supp_legacy_irq())
+            goto skip_irq;
         sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain,
                                pci->bus, pci->dev, pci->func);
         f = fopen(sysfs_path, "r");