mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Stefano Stabellini <sstabellini@kernel.org>,
	"Chen, Jiqian" <Jiqian.Chen@amd.com>
Cc: "Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Oleksandr Tyshchenko" <oleksandr_tyshchenko@epam.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Boris Ostrovsky" <boris.ostrovsky@oracle.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Len Brown" <lenb@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"Stabellini, Stefano" <stefano.stabellini@amd.com>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Koenig, Christian" <Christian.Koenig@amd.com>,
	"Hildebrand, Stewart" <Stewart.Hildebrand@amd.com>,
	"Ragiadakou, Xenia" <Xenia.Ragiadakou@amd.com>,
	"Huang, Honglei1" <Honglei1.Huang@amd.com>,
	"Zhang, Julia" <Julia.Zhang@amd.com>,
	"Huang, Ray" <Ray.Huang@amd.com>
Subject: Re: [RFC KERNEL PATCH v2 2/3] xen/pvh: Unmask irq for passthrough device in PVH dom0
Date: Thu, 7 Dec 2023 07:43:48 +0100	[thread overview]
Message-ID: <ed0729b6-8896-41cb-87fc-9111afc68151@suse.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2312061818030.1265976@ubuntu-linux-20-04-desktop>


[-- Attachment #1.1.1: Type: text/plain, Size: 7560 bytes --]

On 07.12.23 03:18, Stefano Stabellini wrote:
> On Tue, 5 Dec 2023, Chen, Jiqian wrote:
>> When PVH dom0 enable a device, it will get trigger and polarity from ACPI (see acpi_pci_irq_enable)
>> I have a version of patch which tried that way, see below:
> 
> This approach looks much better. I think this patch is OKish. Juergen,
> what do you think?

The approach seems to be fine.


Juergen

> 
> 
>> diff --git a/arch/x86/xen/enlighten_pvh.c b/arch/x86/xen/enlighten_pvh.c
>> index ada3868c02c2..43e1bda9f946 100644
>> --- a/arch/x86/xen/enlighten_pvh.c
>> +++ b/arch/x86/xen/enlighten_pvh.c
>> @@ -1,6 +1,7 @@
>>   // SPDX-License-Identifier: GPL-2.0
>>   #include <linux/acpi.h>
>>   #include <linux/export.h>
>> +#include <linux/pci.h>
>>
>>   #include <xen/hvc-console.h>
>>
>> @@ -25,6 +26,127 @@
>>   bool __ro_after_init xen_pvh;
>>   EXPORT_SYMBOL_GPL(xen_pvh);
>>
>> +typedef struct gsi_info {
>> +       int gsi;
>> +       int trigger;
>> +       int polarity;
>> +       int pirq;
>> +} gsi_info_t;
>> +
>> +struct acpi_prt_entry {
>> +       struct acpi_pci_id      id;
>> +       u8                      pin;
>> +       acpi_handle             link;
>> +       u32                     index;          /* GSI, or link _CRS index */
>> +};
>> +
>> +static int xen_pvh_get_gsi_info(struct pci_dev *dev,
>> +                                                               gsi_info_t *gsi_info)
>> +{
>> +       int gsi;
>> +       u8 pin = 0;
>> +       struct acpi_prt_entry *entry;
>> +       int trigger = ACPI_LEVEL_SENSITIVE;
>> +       int polarity = acpi_irq_model == ACPI_IRQ_MODEL_GIC ?
>> +                                     ACPI_ACTIVE_HIGH : ACPI_ACTIVE_LOW;
>> +
>> +       if (dev)
>> +               pin = dev->pin;
>> +       if (!pin) {
>> +               xen_raw_printk("No interrupt pin configured\n");
>> +               return -EINVAL;
>> +       }
>> +
>> +       entry = acpi_pci_irq_lookup(dev, pin);
>> +       if (entry) {
>> +               if (entry->link)
>> +                       gsi = acpi_pci_link_allocate_irq(entry->link,
>> +                                                        entry->index,
>> +                                                        &trigger, &polarity,
>> +                                                        NULL);
>> +               else
>> +                       gsi = entry->index;
>> +       } else
>> +               return -EINVAL;
>> +
>> +       gsi_info->gsi = gsi;
>> +       gsi_info->trigger = trigger;
>> +       gsi_info->polarity = polarity;
>> +
>> +       return 0;
>> +}
>> +
>> +static int xen_pvh_map_pirq(gsi_info_t *gsi_info)
>> +{
>> +       struct physdev_map_pirq map_irq;
>> +       int ret;
>> +
>> +       map_irq.domid = DOMID_SELF;
>> +       map_irq.type = MAP_PIRQ_TYPE_GSI;
>> +       map_irq.index = gsi_info->gsi;
>> +       map_irq.pirq = gsi_info->gsi;
>> +
>> +       ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
>> +       gsi_info->pirq = map_irq.pirq;
>> +
>> +       return ret;
>> +}
>> +
>> +static int xen_pvh_unmap_pirq(gsi_info_t *gsi_info)
>> +{
>> +       struct physdev_unmap_pirq unmap_irq;
>> +
>> +       unmap_irq.domid = DOMID_SELF;
>> +       unmap_irq.pirq = gsi_info->pirq;
>> +
>> +       return HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
>> +}
>> +
>> +static int xen_pvh_setup_gsi(gsi_info_t *gsi_info)
>> +{
>> +       struct physdev_setup_gsi setup_gsi;
>> +
>> +       setup_gsi.gsi = gsi_info->gsi;
>> +       setup_gsi.triggering = (gsi_info->trigger == ACPI_EDGE_SENSITIVE ? 0 : 1);
>> +       setup_gsi.polarity = (gsi_info->polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
>> +
>> +       return HYPERVISOR_physdev_op(PHYSDEVOP_setup_gsi, &setup_gsi);
>> +}
>> +
>> +int xen_pvh_passthrough_gsi(struct pci_dev *dev)
>> +{
>> +       int ret;
>> +       gsi_info_t gsi_info;
>> +
>> +       if (!dev) {
>> +               return -EINVAL;
>> +       }
>> +
>> +       ret = xen_pvh_get_gsi_info(dev, &gsi_info);
>> +       if (ret) {
>> +               xen_raw_printk("Fail to get gsi info!\n");
>> +               return ret;
>> +       }
>> +
>> +       ret = xen_pvh_map_pirq(&gsi_info);
>> +       if (ret) {
>> +               xen_raw_printk("Fail to map pirq for gsi (%d)!\n", gsi_info.gsi);
>> +               return ret;
>> +       }
>> +
>> +       ret = xen_pvh_setup_gsi(&gsi_info);
>> +       if (ret == -EEXIST) {
>> +               ret = 0;
>> +               xen_raw_printk("Already setup the GSI :%u\n", gsi_info.gsi);
>> +       } else if (ret) {
>> +               xen_raw_printk("Fail to setup gsi (%d)!\n", gsi_info.gsi);
>> +               xen_pvh_unmap_pirq(&gsi_info);
>> +       }
>> +
>> +       return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(xen_pvh_passthrough_gsi);
>> +
>>   void __init xen_pvh_init(struct boot_params *boot_params)
>>   {
>>          u32 msr;
>> diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
>> index ff30ceca2203..630fe0a34bc6 100644
>> --- a/drivers/acpi/pci_irq.c
>> +++ b/drivers/acpi/pci_irq.c
>> @@ -288,7 +288,7 @@ static int acpi_reroute_boot_interrupt(struct pci_dev *dev,
>>   }
>>   #endif /* CONFIG_X86_IO_APIC */
>>
>> -static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
>> +struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
>>   {
>>          struct acpi_prt_entry *entry = NULL;
>>          struct pci_dev *bridge;
>> diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
>> index e34b623e4b41..1abd4dad6f40 100644
>> --- a/drivers/xen/xen-pciback/pci_stub.c
>> +++ b/drivers/xen/xen-pciback/pci_stub.c
>> @@ -20,6 +20,7 @@
>>   #include <linux/atomic.h>
>>   #include <xen/events.h>
>>   #include <xen/pci.h>
>> +#include <xen/acpi.h>
>>   #include <xen/xen.h>
>>   #include <asm/xen/hypervisor.h>
>>   #include <xen/interface/physdev.h>
>> @@ -399,6 +400,12 @@ static int pcistub_init_device(struct pci_dev *dev)
>>          if (err)
>>                  goto config_release;
>>
>> +       if (xen_initial_domain() && xen_pvh_domain()) {
>> +               err = xen_pvh_passthrough_gsi(dev);
>> +               if (err)
>> +                       goto config_release;
>> +       }
>> +
>>          if (dev->msix_cap) {
>>                  struct physdev_pci_device ppdev = {
>>                          .seg = pci_domain_nr(dev->bus),
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>> index 641dc4843987..368d56ba2c5e 100644
>> --- a/include/linux/acpi.h
>> +++ b/include/linux/acpi.h
>> @@ -375,6 +375,7 @@ void acpi_unregister_gsi (u32 gsi);
>>
>>   struct pci_dev;
>>
>> +struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin);
>>   int acpi_pci_irq_enable (struct pci_dev *dev);
>>   void acpi_penalize_isa_irq(int irq, int active);
>>   bool acpi_isa_irq_available(int irq);
>> diff --git a/include/xen/acpi.h b/include/xen/acpi.h
>> index b1e11863144d..ce7f5554f88e 100644
>> --- a/include/xen/acpi.h
>> +++ b/include/xen/acpi.h
>> @@ -67,6 +67,7 @@ static inline void xen_acpi_sleep_register(void)
>>                  acpi_suspend_lowlevel = xen_acpi_suspend_lowlevel;
>>          }
>>   }
>> +int xen_pvh_passthrough_gsi(struct pci_dev *dev);
>>   #else
>>   static inline void xen_acpi_sleep_register(void)
>>   {
>>
>>>
>>> Jan
>>
>> -- 
>> Best regards,
>> Jiqian Chen.
>>


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  parent reply	other threads:[~2023-12-07  6:43 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24 10:31 [RFC KERNEL PATCH v2 0/3] Support device passthrough when dom0 is PVH on Xen Jiqian Chen
2023-11-24 10:31 ` [RFC KERNEL PATCH v2 1/3] xen/pci: Add xen_reset_device_state function Jiqian Chen
2023-11-30  3:46   ` Stefano Stabellini
2023-11-30  7:03     ` Chen, Jiqian
2023-11-30 15:03       ` Stewart Hildebrand
2023-12-04  3:25         ` Chen, Jiqian
2023-12-04  3:45           ` Stewart Hildebrand
2023-12-04  7:58   ` Thomas Gleixner
2023-12-04  8:49     ` Chen, Jiqian
2023-12-04 21:31       ` Stefano Stabellini
2023-12-05  6:50         ` Chen, Jiqian
2023-12-05 17:02         ` Thomas Gleixner
2023-12-06  6:37           ` Chen, Jiqian
2023-11-24 10:31 ` [RFC KERNEL PATCH v2 2/3] xen/pvh: Unmask irq for passthrough device in PVH dom0 Jiqian Chen
2023-11-30  3:53   ` Stefano Stabellini
2023-11-30 16:02     ` Roger Pau Monné
2023-12-01  3:15       ` Stefano Stabellini
2023-12-01  8:58         ` Roger Pau Monné
2023-12-02  3:37           ` Stefano Stabellini
2023-12-04 10:28             ` Roger Pau Monné
2023-12-04 22:19               ` Stefano Stabellini
2023-12-05  9:19                 ` Roger Pau Monné
2023-12-05  9:39                   ` Chen, Jiqian
2023-12-05 10:32                   ` Jan Beulich
2023-12-06  6:07                     ` Chen, Jiqian
2023-12-07  2:18                       ` Stefano Stabellini
2023-12-07  3:38                         ` Chen, Jiqian
2023-12-07  6:43                         ` Juergen Gross [this message]
2023-12-08  5:53                           ` Chen, Jiqian
2023-12-11 15:45                       ` Roger Pau Monné
2023-12-12  6:16                         ` Chen, Jiqian
2023-12-12  8:49                           ` Roger Pau Monné
2023-12-12  9:38                             ` Jan Beulich
2023-12-12 11:18                               ` Roger Pau Monné
2023-12-12 11:19                                 ` Jan Beulich
2023-12-12 11:39                                   ` Roger Pau Monné
2023-12-13  7:14                                     ` Chen, Jiqian
2023-12-13  7:41                                       ` Jan Beulich
2023-12-05  6:46               ` Chen, Jiqian
2023-12-04  8:13   ` Thomas Gleixner
2023-12-05  7:03     ` Chen, Jiqian
2023-11-24 10:31 ` [RFC KERNEL PATCH v2 3/3] xen/privcmd: Add new syscall to get gsi from irq Jiqian Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed0729b6-8896-41cb-87fc-9111afc68151@suse.com \
    --to=jgross@suse.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Honglei1.Huang@amd.com \
    --cc=Jiqian.Chen@amd.com \
    --cc=Julia.Zhang@amd.com \
    --cc=Ray.Huang@amd.com \
    --cc=Stewart.Hildebrand@amd.com \
    --cc=Xenia.Ragiadakou@amd.com \
    --cc=bhelgaas@google.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jbeulich@suse.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=rafael@kernel.org \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=stefano.stabellini@amd.com \
    --cc=tglx@linutronix.de \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®