From: Eric Auger <eric.auger@redhat.com>
To: "Duan, Zhenzhong" <zhenzhong.duan@intel.com>,
"Cédric Le Goater" <clg@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"peterx@redhat.com" <peterx@redhat.com>,
"jasowang@redhat.com" <jasowang@redhat.com>,
"mst@redhat.com" <mst@redhat.com>,
"jgg@nvidia.com" <jgg@nvidia.com>,
"nicolinc@nvidia.com" <nicolinc@nvidia.com>,
"joao.m.martins@oracle.com" <joao.m.martins@oracle.com>,
"Tian, Kevin" <kevin.tian@intel.com>,
"Liu, Yi L" <yi.l.liu@intel.com>,
"Sun, Yi Y" <yi.y.sun@intel.com>,
"Peng, Chao P" <chao.p.peng@intel.com>,
Yi Sun <yi.y.sun@linux.intel.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Subject: Re: [PATCH rfcv1 2/6] hw/pci: introduce pci_device_set/unset_iommu_device()
Date: Tue, 23 Jan 2024 11:18:40 +0100 [thread overview]
Message-ID: <39a50e45-73e8-4f17-871b-336dc2fdc35f@redhat.com> (raw)
In-Reply-To: <SJ0PR11MB6744254204FF8E9D3E1169C892742@SJ0PR11MB6744.namprd11.prod.outlook.com>
On 1/23/24 10:25, Duan, Zhenzhong wrote:
>
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: Re: [PATCH rfcv1 2/6] hw/pci: introduce
>> pci_device_set/unset_iommu_device()
>>
>> On 1/23/24 07:37, Duan, Zhenzhong wrote:
>>>
>>>> -----Original Message-----
>>>> From: Cédric Le Goater <clg@redhat.com>
>>>> Subject: Re: [PATCH rfcv1 2/6] hw/pci: introduce
>>>> pci_device_set/unset_iommu_device()
>>>>
>>>> On 1/15/24 11:13, Zhenzhong Duan wrote:
>>>>> From: Yi Liu <yi.l.liu@intel.com>
>>>>>
>>>>> This adds pci_device_set/unset_iommu_device() to set/unset
>>>>> IOMMUFDDevice for a given PCIe device. Caller of set
>>>>> should fail if set operation fails.
>>>>>
>>>>> Extract out pci_device_get_iommu_bus_devfn() to facilitate
>>>>> implementation of pci_device_set/unset_iommu_device().
>>>>>
>>>>> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
>>>>> Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
>>>>> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
>>>>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>>>>> ---
>>>>> include/hw/pci/pci.h | 39
>> ++++++++++++++++++++++++++++++++++-
>>>>> hw/pci/pci.c | 49
>>>> +++++++++++++++++++++++++++++++++++++++++++-
>>>>> 2 files changed, 86 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
>>>>> index fa6313aabc..a810c0ec74 100644
>>>>> --- a/include/hw/pci/pci.h
>>>>> +++ b/include/hw/pci/pci.h
>>>>> @@ -7,6 +7,8 @@
>>>>> /* PCI includes legacy ISA access. */
>>>>> #include "hw/isa/isa.h"
>>>>>
>>>>> +#include "sysemu/iommufd_device.h"
>>>>> +
>>>>> extern bool pci_available;
>>>>>
>>>>> /* PCI bus */
>>>>> @@ -384,10 +386,45 @@ typedef struct PCIIOMMUOps {
>>>>> *
>>>>> * @devfn: device and function number
>>>>> */
>>>>> - AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int
>>>> devfn);
>>>>> + AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque,
>> int
>>>> devfn);
>>>>> + /**
>>>>> + * @set_iommu_device: set iommufd device for a PCI device to
>>>> vIOMMU
>>>>> + *
>>>>> + * Optional callback, if not implemented in vIOMMU, then vIOMMU
>>>> can't
>>>>> + * utilize iommufd specific features.
>>>>> + *
>>>>> + * Return true if iommufd device is accepted, or else return false with
>>>>> + * errp set.
>>>>> + *
>>>>> + * @bus: the #PCIBus of the PCI device.
>>>>> + *
>>>>> + * @opaque: the data passed to pci_setup_iommu().
>>>>> + *
>>>>> + * @devfn: device and function number of the PCI device.
>>>>> + *
>>>>> + * @idev: the data structure representing iommufd device.
>>>>> + *
>>>>> + */
>>>>> + int (*set_iommu_device)(PCIBus *bus, void *opaque, int32_t devfn,
>>>>> + IOMMUFDDevice *idev, Error **errp);
>>>>> + /**
>>>>> + * @unset_iommu_device: unset iommufd device for a PCI device
>> from
>>>> vIOMMU
>>>>> + *
>>>>> + * Optional callback.
>>>>> + *
>>>>> + * @bus: the #PCIBus of the PCI device.
>>>>> + *
>>>>> + * @opaque: the data passed to pci_setup_iommu().
>>>>> + *
>>>>> + * @devfn: device and function number of the PCI device.
>>>>> + */
>>>>> + void (*unset_iommu_device)(PCIBus *bus, void *opaque, int32_t
>>>> devfn);
>>>>> } PCIIOMMUOps;
>>>>>
>>>>> AddressSpace *pci_device_iommu_address_space(PCIDevice *dev);
>>>>> +int pci_device_set_iommu_device(PCIDevice *dev, IOMMUFDDevice
>>>> *idev,
>>>>> + Error **errp);
>>>>> +void pci_device_unset_iommu_device(PCIDevice *dev);
>>>>>
>>>>> /**
>>>>> * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus
>>>>> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
>>>>> index 76080af580..3848662f95 100644
>>>>> --- a/hw/pci/pci.c
>>>>> +++ b/hw/pci/pci.c
>>>>> @@ -2672,7 +2672,10 @@ static void
>>>> pci_device_class_base_init(ObjectClass *klass, void *data)
>>>>> }
>>>>> }
>>>>>
>>>>> -AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
>>>>> +static void pci_device_get_iommu_bus_devfn(PCIDevice *dev,
>>>>> + PCIBus **aliased_pbus,
>>>>> + PCIBus **piommu_bus,
>>>>> + uint8_t *aliased_pdevfn)
>>>>> {
>>>>> PCIBus *bus = pci_get_bus(dev);
>>>>> PCIBus *iommu_bus = bus;
>>>>> @@ -2717,6 +2720,18 @@ AddressSpace
>>>> *pci_device_iommu_address_space(PCIDevice *dev)
>>>>> iommu_bus = parent_bus;
>>>>> }
>>>>> + *aliased_pbus = bus;
>>>>> + *piommu_bus = iommu_bus;
>>>>> + *aliased_pdevfn = devfn;
>>>>> +}
>>>>> +
>>>>> +AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
>>>>> +{
>>>>> + PCIBus *bus;
>>>>> + PCIBus *iommu_bus;
>>>>> + uint8_t devfn;
>>>>> +
>>>>> + pci_device_get_iommu_bus_devfn(dev, &bus, &iommu_bus,
>> &devfn);
>>>>> if (!pci_bus_bypass_iommu(bus) && iommu_bus->iommu_ops) {
>>>>> return iommu_bus->iommu_ops->get_address_space(bus,
>>>>> iommu_bus->iommu_opaque, devfn);
>>>>> @@ -2724,6 +2739,38 @@ AddressSpace
>>>> *pci_device_iommu_address_space(PCIDevice *dev)
>>>>> return &address_space_memory;
>>>>> }
>>>>>
>>>>> +int pci_device_set_iommu_device(PCIDevice *dev, IOMMUFDDevice
>>>> *idev,
>>>>> + Error **errp)
>>>>> +{
>>>>> + PCIBus *bus;
>>>>> + PCIBus *iommu_bus;
>>>>> + uint8_t devfn;
>>>>> +
>>>>> + pci_device_get_iommu_bus_devfn(dev, &bus, &iommu_bus,
>> &devfn);
>>>>> + if (!pci_bus_bypass_iommu(bus) && iommu_bus &&
>>>> Why do we test iommu_bus in pci_device_un/set_iommu_device
>> routines
>>>> and
>>>> not in pci_device_iommu_address_space() ?
>>> iommu_bus check in pci_device_iommu_address_space() is dropped in
>>> below commit, I didn't find related discussion in mail history, maybe
>>> by accident? I can add it back if it's not intentional.
>> Can iommu_bus be NULL or should we add an assert ?
> I dig into the history changes of pci_device_iommu_address_space() and
> below commit added iommu_bus check.
>
> 5af2ae230514 pci: Fix pci_device_iommu_address_space() bus propagation
>
> In theory, !iommu_bus->parent_dev take precedency over !iommu_bus,
> So we never see iommu_bus NULL, assert may be better.
I think we had such a discussion in
https://www.mail-archive.com/qemu-devel@nongnu.org/msg994766.html
But maybe this was related to a different call place. I remember I
challenged the check at some point
Eric
>
> Thanks
> Zhenzhong
>
next prev parent reply other threads:[~2024-01-23 10:19 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 10:13 [PATCH rfcv1 0/6] Check and sync host IOMMU cap/ecap with vIOMMU Zhenzhong Duan
2024-01-15 10:13 ` [PATCH rfcv1 1/6] backends/iommufd_device: introduce IOMMUFDDevice Zhenzhong Duan
2024-01-17 14:11 ` Eric Auger
2024-01-18 2:58 ` Duan, Zhenzhong
2024-01-18 12:42 ` Eric Auger
2024-01-19 7:31 ` Duan, Zhenzhong
2024-01-22 16:25 ` Cédric Le Goater
2024-01-23 5:51 ` Duan, Zhenzhong
2024-01-23 10:10 ` Eric Auger
2024-01-15 10:13 ` [PATCH rfcv1 2/6] hw/pci: introduce pci_device_set/unset_iommu_device() Zhenzhong Duan
2024-01-17 14:11 ` Eric Auger
2024-01-18 7:58 ` Duan, Zhenzhong
2024-01-22 16:55 ` Cédric Le Goater
2024-01-23 6:37 ` Duan, Zhenzhong
2024-01-23 7:40 ` Cédric Le Goater
2024-01-23 9:25 ` Duan, Zhenzhong
2024-01-23 10:18 ` Eric Auger [this message]
2024-01-24 9:23 ` Duan, Zhenzhong
2024-01-15 10:13 ` [PATCH rfcv1 3/6] intel_iommu: add set/unset_iommu_device callback Zhenzhong Duan
2024-01-17 15:44 ` Eric Auger
2024-01-18 8:43 ` Duan, Zhenzhong
2024-01-18 12:34 ` Eric Auger
2024-01-19 7:27 ` Duan, Zhenzhong
2024-01-22 17:09 ` Cédric Le Goater
2024-01-23 9:46 ` Duan, Zhenzhong
2024-01-15 10:13 ` [PATCH rfcv1 4/6] vfio: initialize IOMMUFDDevice and pass to vIOMMU Zhenzhong Duan
2024-01-17 15:37 ` Joao Martins
2024-01-18 8:17 ` Duan, Zhenzhong
2024-01-18 10:17 ` Yi Liu
2024-01-18 10:20 ` Joao Martins
2024-01-17 17:30 ` Eric Auger
2024-01-18 9:23 ` Duan, Zhenzhong
2024-01-22 17:15 ` Cédric Le Goater
2024-01-23 9:46 ` Duan, Zhenzhong
2024-01-23 12:54 ` Cédric Le Goater
2024-01-24 9:26 ` Duan, Zhenzhong
2024-01-15 10:13 ` [PATCH rfcv1 5/6] intel_iommu: extract out vtd_cap_init to initialize cap/ecap Zhenzhong Duan
2024-01-17 17:36 ` Eric Auger
2024-01-15 10:13 ` [PATCH rfcv1 6/6] intel_iommu: add a framework to check and sync host IOMMU cap/ecap Zhenzhong Duan
2024-01-17 17:56 ` Eric Auger
2024-01-18 9:30 ` Duan, Zhenzhong
2024-01-18 12:40 ` Eric Auger
2024-01-19 11:55 ` Duan, Zhenzhong
2024-01-23 13:10 ` Eric Auger
2024-01-23 8:39 ` Cédric Le Goater
2024-01-23 10:01 ` Duan, Zhenzhong
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=39a50e45-73e8-4f17-871b-336dc2fdc35f@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=chao.p.peng@intel.com \
--cc=clg@redhat.com \
--cc=jasowang@redhat.com \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=kevin.tian@intel.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=nicolinc@nvidia.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@intel.com \
--cc=yi.y.sun@linux.intel.com \
--cc=zhenzhong.duan@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).