All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@vates.tech>
To: Jiqian Chen <Jiqian.Chen@amd.com>
Cc: xen-devel@lists.xenproject.org, "Jan Beulich" <jbeulich@suse.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Julien Grall" <julien@xen.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Anthony PERARD" <anthony@xenproject.org>,
	"Juergen Gross" <jgross@suse.com>,
	"Daniel P . Smith" <dpsmith@apertussolutions.com>,
	"Stewart Hildebrand" <Stewart.Hildebrand@amd.com>,
	"Huang Rui" <Ray.Huang@amd.com>
Subject: Re: [XEN PATCH v10 4/5] tools: Add new function to get gsi from dev
Date: Thu, 20 Jun 2024 14:38:58 +0000	[thread overview]
Message-ID: <ZnQ+/y/AGyasDGHY@l14> (raw)
In-Reply-To: <20240617090035.839640-5-Jiqian.Chen@amd.com>

On Mon, Jun 17, 2024 at 05:00:34PM +0800, Jiqian Chen wrote:
> diff --git a/tools/include/xencall.h b/tools/include/xencall.h
> index fc95ed0fe58e..750aab070323 100644
> --- a/tools/include/xencall.h
> +++ b/tools/include/xencall.h
> @@ -113,6 +113,8 @@ int xencall5(xencall_handle *xcall, unsigned int op,
>               uint64_t arg1, uint64_t arg2, uint64_t arg3,
>               uint64_t arg4, uint64_t arg5);
>  
> +int xen_oscall_gsi_from_dev(xencall_handle *xcall, unsigned int sbdf);

I don't think that an appropriate library for this new feature.
libxencall is a generic lib to make hypercall.

>  /* Variant(s) of the above, as needed, returning "long" instead of "int". */
>  long xencall2L(xencall_handle *xcall, unsigned int op,
>                 uint64_t arg1, uint64_t arg2);
> diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
> index 9ceca0cffc2f..a0381f74d24b 100644
> --- a/tools/include/xenctrl.h
> +++ b/tools/include/xenctrl.h
> @@ -1641,6 +1641,8 @@ int xc_physdev_unmap_pirq(xc_interface *xch,
>                            uint32_t domid,
>                            int pirq);
>  
> +int xc_physdev_gsi_from_dev(xc_interface *xch, uint32_t sbdf);
> +
>  /*
>   *  LOGGING AND ERROR REPORTING
>   */
> diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c
> index 02c4f8e1aefa..6dae50c9a6ba 100644
> --- a/tools/libs/call/core.c
> +++ b/tools/libs/call/core.c
> @@ -173,6 +173,11 @@ int xencall5(xencall_handle *xcall, unsigned int op,
>      return osdep_hypercall(xcall, &call);
>  }
>  
> +int xen_oscall_gsi_from_dev(xencall_handle *xcall, unsigned int sbdf)
> +{
> +    return osdep_oscall(xcall, sbdf);
> +}
> +
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/tools/libs/call/libxencall.map b/tools/libs/call/libxencall.map
> index d18a3174e9dc..b92a0b5dc12c 100644
> --- a/tools/libs/call/libxencall.map
> +++ b/tools/libs/call/libxencall.map
> @@ -10,6 +10,8 @@ VERS_1.0 {
>  		xencall4;
>  		xencall5;
>  
> +		xen_oscall_gsi_from_dev;

FYI, never change already released version of a library, this would add
a new function to libxencall.1.0. Instead, when adding a new function
to a library that is supposed to be stable (they have a *.map file in
xen case), add it to a new section, that woud be VERS_1.4 in this case.
But libxencall isn't approriate for this new function, so just for
future reference.

>  		xencall_alloc_buffer;
>  		xencall_free_buffer;
>  		xencall_alloc_buffer_pages;
> diff --git a/tools/libs/call/linux.c b/tools/libs/call/linux.c
> index 6d588e6bea8f..92c740e176f2 100644
> --- a/tools/libs/call/linux.c
> +++ b/tools/libs/call/linux.c
> @@ -85,6 +85,21 @@ long osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall)
>      return ioctl(xcall->fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
>  }
>  
> +int osdep_oscall(xencall_handle *xcall, unsigned int sbdf)
> +{
> +    privcmd_gsi_from_dev_t dev_gsi = {
> +        .sbdf = sbdf,
> +        .gsi = -1,
> +    };
> +
> +    if (ioctl(xcall->fd, IOCTL_PRIVCMD_GSI_FROM_DEV, &dev_gsi)) {

Looks like libxencall is only for hypercall, and so I don't think
it's the right place to introducing another ioctl() call.

> +        PERROR("failed to get gsi from dev");
> +        return -1;
> +    }
> +
> +    return dev_gsi.gsi;
> +}
> +
>  static void *alloc_pages_bufdev(xencall_handle *xcall, size_t npages)
>  {
>      void *p;
> diff --git a/tools/libs/call/private.h b/tools/libs/call/private.h
> index 9c3aa432efe2..cd6eb5a3e66f 100644
> --- a/tools/libs/call/private.h
> +++ b/tools/libs/call/private.h
> @@ -57,6 +57,15 @@ int osdep_xencall_close(xencall_handle *xcall);
>  
>  long osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall);
>  
> +#if defined(__linux__)
> +int osdep_oscall(xencall_handle *xcall, unsigned int sbdf);
> +#else
> +static inline int osdep_oscall(xencall_handle *xcall, unsigned int sbdf)
> +{
> +    return -1;
> +}
> +#endif
> +
>  void *osdep_alloc_pages(xencall_handle *xcall, size_t nr_pages);
>  void osdep_free_pages(xencall_handle *xcall, void *p, size_t nr_pages);
>  
> diff --git a/tools/libs/ctrl/xc_physdev.c b/tools/libs/ctrl/xc_physdev.c
> index 460a8e779ce8..c1458f3a38b5 100644
> --- a/tools/libs/ctrl/xc_physdev.c
> +++ b/tools/libs/ctrl/xc_physdev.c
> @@ -111,3 +111,7 @@ int xc_physdev_unmap_pirq(xc_interface *xch,
>      return rc;
>  }
>  
> +int xc_physdev_gsi_from_dev(xc_interface *xch, uint32_t sbdf)
> +{

I'm not sure if this is the best place for this new function, but I
can't find another one, so that will do.

> +    return xen_oscall_gsi_from_dev(xch->xcall, sbdf);
> +}
> diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
> index 37e4d1670986..6b616d5ee9b6 100644
> --- a/tools/libs/light/Makefile
> +++ b/tools/libs/light/Makefile
> @@ -40,7 +40,7 @@ OBJS-$(CONFIG_X86) += $(ACPI_OBJS)
>  
>  CFLAGS += -Wno-format-zero-length -Wmissing-declarations -Wformat-nonliteral
>  
> -CFLAGS-$(CONFIG_X86) += -DCONFIG_PCI_SUPP_LEGACY_IRQ
> +CFLAGS-$(CONFIG_X86) += -DCONFIG_PCI_SUPP_LEGACY_IRQ -DCONFIG_X86
>  
>  OBJS-$(CONFIG_X86) += libxl_cpuid.o
>  OBJS-$(CONFIG_X86) += libxl_x86.o
> diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
> index 96cb4da0794e..376f91759ac6 100644
> --- a/tools/libs/light/libxl_pci.c
> +++ b/tools/libs/light/libxl_pci.c
> @@ -1406,6 +1406,12 @@ static bool pci_supp_legacy_irq(void)
>  #endif
>  }
>  
> +#define PCI_DEVID(bus, devfn)\
> +            ((((uint16_t)(bus)) << 8) | ((devfn) & 0xff))
> +
> +#define PCI_SBDF(seg, bus, devfn) \
> +            ((((uint32_t)(seg)) << 16) | (PCI_DEVID(bus, devfn)))
> +
>  static void pci_add_dm_done(libxl__egc *egc,
>                              pci_add_state *pas,
>                              int rc)
> @@ -1418,6 +1424,10 @@ static void pci_add_dm_done(libxl__egc *egc,
>      unsigned long long start, end, flags, size;
>      int irq, i;
>      int r;
> +#ifdef CONFIG_X86
> +    int gsi;
> +    uint32_t sbdf;
> +#endif
>      uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED;
>      uint32_t domainid = domid;
>      bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid);
> @@ -1486,6 +1496,18 @@ static void pci_add_dm_done(libxl__egc *egc,
>          goto out_no_irq;
>      }
>      if ((fscanf(f, "%u", &irq) == 1) && irq) {
> +#ifdef CONFIG_X86

Could you avoid these #ifdef, and move the new arch specific code (and
maybe existing code) into libxl_x86.c ? There's already examples of arch
specific code.

> +        sbdf = PCI_SBDF(pci->domain, pci->bus,
> +                        (PCI_DEVFN(pci->dev, pci->func)));
> +        gsi = xc_physdev_gsi_from_dev(ctx->xch, sbdf);
> +        /*
> +         * Old kernel version may not support this function,
> +         * so if fail, keep using irq; if success, use gsi
> +         */
> +        if (gsi > 0) {
> +            irq = gsi;
> +        }
> +#endif
>          r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq);
>          if (r < 0) {
>              LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)",
> @@ -2172,6 +2194,10 @@ static void pci_remove_detached(libxl__egc *egc,
>      int  irq = 0, i, stubdomid = 0;
>      const char *sysfs_path;
>      FILE *f;
> +#ifdef CONFIG_X86
> +    int gsi;
> +    uint32_t sbdf;
> +#endif
>      uint32_t domainid = prs->domid;
>      bool isstubdom;
>  
> @@ -2239,6 +2265,18 @@ skip_bar:
>      }
>  
>      if ((fscanf(f, "%u", &irq) == 1) && irq) {
> +#ifdef CONFIG_X86
> +        sbdf = PCI_SBDF(pci->domain, pci->bus,
> +                        (PCI_DEVFN(pci->dev, pci->func)));
> +        gsi = xc_physdev_gsi_from_dev(ctx->xch, sbdf);
> +        /*
> +         * Old kernel version may not support this function,
> +         * so if fail, keep using irq; if success, use gsi
> +         */
> +        if (gsi > 0) {
> +            irq = gsi;
> +        }
> +#endif
>          rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
>          if (rc < 0) {
>              /*

Thanks,

-- 


Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech


  parent reply	other threads:[~2024-06-20 14:39 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17  9:00 [XEN PATCH v10 0/5] Support device passthrough when dom0 is PVH on Xen Jiqian Chen
2024-06-17  9:00 ` [XEN PATCH v10 1/5] xen/vpci: Clear all vpci status of device Jiqian Chen
2024-06-17 14:17   ` Jan Beulich
2024-06-18  6:25     ` Chen, Jiqian
2024-06-18  8:33       ` Jan Beulich
2024-06-19  3:39         ` Chen, Jiqian
2024-06-19  7:02           ` Jan Beulich
2024-06-17  9:00 ` [XEN PATCH v10 2/5] x86/pvh: Allow (un)map_pirq when dom0 is PVH Jiqian Chen
2024-06-17 14:45   ` Jan Beulich
2024-06-18  6:49     ` Chen, Jiqian
2024-06-18  8:38       ` Jan Beulich
2024-06-19  5:35         ` Chen, Jiqian
2024-06-17  9:00 ` [XEN PATCH v10 3/5] x86/pvh: Add PHYSDEVOP_setup_gsi for PVH dom0 Jiqian Chen
2024-06-17 14:52   ` Jan Beulich
2024-06-18  6:57     ` Chen, Jiqian
2024-06-18  8:55       ` Jan Beulich
2024-06-19  7:53         ` Chen, Jiqian
2024-06-19  8:06           ` Jan Beulich
2024-06-19  8:51             ` Chen, Jiqian
2024-06-19  9:49               ` Jan Beulich
2024-06-19 10:10                 ` Chen, Jiqian
2024-06-17  9:00 ` [XEN PATCH v10 4/5] tools: Add new function to get gsi from dev Jiqian Chen
2024-06-17 15:10   ` Jan Beulich
2024-06-18  8:10     ` Chen, Jiqian
2024-06-18  9:13       ` Jan Beulich
2024-06-20  7:03         ` Chen, Jiqian
2024-06-20  7:43           ` Jan Beulich
2024-06-20 10:23             ` Chen, Jiqian
2024-06-20 10:37               ` Jan Beulich
2024-06-21  8:15                 ` Chen, Jiqian
2024-06-24  8:13                   ` Jan Beulich
2024-06-25  7:38                     ` Chen, Jiqian
2024-06-20 14:38   ` Anthony PERARD [this message]
2024-06-21  8:34     ` Chen, Jiqian
2024-06-24 12:08       ` Anthony PERARD
2024-06-17  9:00 ` [XEN PATCH v10 5/5] domctl: Add XEN_DOMCTL_gsi_permission to grant gsi Jiqian Chen
2024-06-17  9:15   ` Chen, Jiqian
2024-06-17 15:32   ` Jan Beulich
2024-06-18  8:23     ` Chen, Jiqian
2024-06-18  9:23       ` Jan Beulich
2024-06-20  9:40         ` Chen, Jiqian
2024-06-20 10:42           ` Jan Beulich
2024-06-21  8:20             ` Chen, Jiqian
2024-06-24  8:17               ` Jan Beulich
2024-06-25  7:44                 ` Chen, Jiqian
2024-06-25  7:48                   ` Jan Beulich
2024-06-24 12:33               ` Anthony PERARD
2024-06-25  7:46                 ` Chen, Jiqian

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=ZnQ+/y/AGyasDGHY@l14 \
    --to=anthony.perard@vates.tech \
    --cc=Jiqian.Chen@amd.com \
    --cc=Ray.Huang@amd.com \
    --cc=Stewart.Hildebrand@amd.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony@xenproject.org \
    --cc=dpsmith@apertussolutions.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=julien@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.