Re: [PATCH RFC 04/15] drivers/base: Add support for a new IMS irq domain

From: Jason Gunthorpe
Date: Sun May 03 2020 - 18:47:04 EST


On Sun, May 03, 2020 at 03:40:44PM -0700, Dey, Megha wrote:
> On 5/3/2020 3:25 PM, Jason Gunthorpe wrote:
> > On Fri, May 01, 2020 at 03:30:02PM -0700, Dey, Megha wrote:
> > > Hi Jason,
> > >
> > > On 4/23/2020 1:11 PM, Jason Gunthorpe wrote:
> > > > On Tue, Apr 21, 2020 at 04:34:11PM -0700, Dave Jiang wrote:
> > > > > diff --git a/drivers/base/ims-msi.c b/drivers/base/ims-msi.c
> > > > > new file mode 100644
> > > > > index 000000000000..738f6d153155
> > > > > +++ b/drivers/base/ims-msi.c
> > > > > @@ -0,0 +1,100 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0-only
> > > > > +/*
> > > > > + * Support for Device Specific IMS interrupts.
> > > > > + *
> > > > > + * Copyright  2019 Intel Corporation.
> > > > > + *
> > > > > + * Author: Megha Dey <megha.dey@xxxxxxxxx>
> > > > > + */
> > > > > +
> > > > > +#include <linux/dmar.h>
> > > > > +#include <linux/irq.h>
> > > > > +#include <linux/mdev.h>
> > > > > +#include <linux/pci.h>
> > > > > +
> > > > > +/*
> > > > > + * Determine if a dev is mdev or not. Return NULL if not mdev device.
> > > > > + * Return mdev's parent dev if success.
> > > > > + */
> > > > > +static inline struct device *mdev_to_parent(struct device *dev)
> > > > > +{
> > > > > + struct device *ret = NULL;
> > > > > + struct device *(*fn)(struct device *dev);
> > > > > + struct bus_type *bus = symbol_get(mdev_bus_type);
> > > > > +
> > > > > + if (bus && dev->bus == bus) {
> > > > > + fn = symbol_get(mdev_dev_to_parent_dev);
> > > > > + ret = fn(dev);
> > > > > + symbol_put(mdev_dev_to_parent_dev);
> > > > > + symbol_put(mdev_bus_type);
> > > >
> > > > No, things like this are not OK in the drivers/base
> > > >
> > > > Whatever this is doing needs to be properly architected in some
> > > > generic way.
> > >
> > > Basically what I am trying to do here is to determine if the device is an
> > > mdev device or not.
> >
> > Why? mdev devices are virtual they don't have HW elements.
>
> Hmm yeah exactly, since they are virtual, they do not have an associated IRQ
> domain right? So they use the irq domain of the parent device..
>
> >
> > The caller should use the concrete pci_device to allocate
> > platform_msi? What is preventing this?
>
> hmmm do you mean to say all platform-msi adhere to the rules of a PCI
> device?

I mean where a platform-msi can work should be defined by the arch,
and probably is related to things like having an irq_domain attached

So, like pci, drivers must only try to do platfor_msi stuff on
particular devices. eg on pci_device and platform_device types.

Even so it may not even work, but I can't think of any reason why it
should be made to work on a virtual device like mdev.

> The use case if when we have a device assigned to a guest and we
> want to allocate IMS(platform-msi) interrupts for that
> guest-assigned device. Currently, this is abstracted through a mdev
> interface.

And the mdev has the pci_device internally, so it should simply pass
that pci_device to the platform_msi machinery.

This is no different from something like pci_iomap() which must be
used with the pci_device.

Jason