public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: Yi Liu <yi.l.liu@intel.com>
Cc: <jgg@nvidia.com>, <kevin.tian@intel.com>, <will@kernel.org>,
	<joro@8bytes.org>, <suravee.suthikulpanit@amd.com>,
	<robin.murphy@arm.com>, <dwmw2@infradead.org>,
	<baolu.lu@linux.intel.com>, <shuah@kernel.org>,
	<linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kselftest@vger.kernel.org>, <eric.auger@redhat.com>,
	<jean-philippe@linaro.org>, <mdf@kernel.org>,
	<mshavit@google.com>, <shameerali.kolothum.thodi@huawei.com>,
	<smostafa@google.com>, Jason Wang <jasowang@redhat.com>
Subject: Re: [PATCH v2 04/19] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC
Date: Fri, 27 Sep 2024 13:29:00 -0700	[thread overview]
Message-ID: <ZvcVjNHykF1BJLUt@Asurada-Nvidia> (raw)
In-Reply-To: <899c781b-c2bc-4012-b0a1-794fc64eb478@intel.com>

On Fri, Sep 27, 2024 at 08:12:40PM +0800, Yi Liu wrote:
> External email: Use caution opening links or attachments
> 
> 
> On 2024/9/27 14:02, Nicolin Chen wrote:
> > On Fri, Sep 27, 2024 at 01:38:08PM +0800, Yi Liu wrote:
> > > > > Does it mean each vIOMMU of VM can only have
> > > > > one s2 HWPT?
> > > > 
> > > > Giving some examples here:
> > > >    - If a VM has 1 vIOMMU, there will be 1 vIOMMU object in the
> > > >      kernel holding one S2 HWPT.
> > > >    - If a VM has 2 vIOMMUs, there will be 2 vIOMMU objects in the
> > > >      kernel that can hold two different S2 HWPTs, or share one S2
> > > >      HWPT (saving memory).
> > > 
> > > So if you have two devices assigned to a VM, then you may have two
> > > vIOMMUs or one vIOMMU exposed to guest. This depends on whether the two
> > > devices are behind the same physical IOMMU. If it's two vIOMMUs, the two
> > > can share the s2 hwpt if their physical IOMMU is compatible. is it?
> > 
> > Yes.
> > 
> > > To achieve the above, you need to know if the physical IOMMUs of the
> > > assigned devices, hence be able to tell if physical IOMMUs are the
> > > same and if they are compatible. How would userspace know such infos?
> > 
> > My draft implementation with QEMU does something like this:
> >   - List all viommu-matched iommu nodes under /sys/class/iommu: LINKs
> >   - Get PCI device's /sys/bus/pci/devices/0000:00:00.0/iommu: LINK0
> >   - Compare the LINK0 against the LINKs
> > 
> > We so far don't have an ID for physical IOMMU instance, which can
> > be an alternative to return via the hw_info call, otherwise.
> 
> intel platform has a kind of ID for the physical IOMMUs.
> 
> ls /sys/class/iommu/
> dmar0  dmar1  dmar10  dmar11  dmar12  dmar13  dmar14  dmar15  dmar16
> dmar17  dmar18  dmar19  dmar2  dmar3  dmar4  dmar5  dmar6  dmar7  dmar8
> dmar9  iommufd_selftest_iommu.0

Wow, that's a lot of IOMMU devices. I somehow had an impression
that Intel uses one physical IOMMU..

Yea, we need something in the core. I had one patch previously:
https://github.com/nicolinc/iommufd/commit/b7520901184fd9fa127abb88c1f0be16b9967cff

> > QEMU then does the routing to assign PCI buses and IORT (or DT).
> > This part is suggested now to move to libvirt though. So, I think
> > at the end of the day, libvirt would run the sys check and assign
> > a device to the corresponding pci bus backed by the correct IOMMU.
> 
> and also give the correct viommu for the device.

In this design, a pxb bus is exclusively created for a viommu
instance, meaning so long as device is assigned to the correct
bus number, it'll be linked to the correct viommu.

> > This gives an example showing two devices behind iommu0 and third
> > device behind iommu1 are assigned to a VM:
> >    -device pxb-pcie.id=pcie.viommu0,bus=pcie.0.... \   # bus for viommu0
> >    -device pxb-pcie.id=pcie.viommu1,bus=pcie.0.... \   # bus for viommu1
> >    -device pcie-root-port,id=pcie.viommu0p0,bus=pcie.viommu0... \
> >    -device pcie-root-port,id=pcie.viommu0p1,bus=pcie.viommu0... \
> >    -device pcie-root-port,id=pcie.viommu1p0,bus=pcie.viommu1... \
> >    -device vfio-pci,bus=pcie.viommu0p0... \  # connect to bus for viommu0
> >    -device vfio-pci,bus=pcie.viommu0p1... \  # connect to bus for viommu0
> >    -device vfio-pci,bus=pcie.viommu1p0...    # connect to bus for viommu1
> 
> is the viommu# an "-object" or just hints to describe the relationship
> between device and viommu and build the IORT?

Yes. Eric actually suggested something better for the relationship
between pxb-pcie with viommu:

-device
pxb-pcie,bus_nr=100,id=pci.12,numa_node=0,bus=pcie.0,addr=0x3,iommu=<id>
from:
https://lore.kernel.org/qemu-devel/9c3e95c2-1035-4a55-89a3-97165ef32f18@redhat.com/

This would likely help the IORT or Device Tree building.

Currently, ARM VIRT machine doesn't create a vSMMU via a "-device"
string, i.e. not a plugable module yet. I recall Intel does. So,
you guys are one step ahead.

> I'm considering how it would look like if the QEMU Intel vIOMMU is going
> to use the viommu obj. Currently, we only support one virtual VT-d due to
> some considerations like hot-plug. Per your conversation with Kevin, it
> seems to be supported. So there is no strict connection between vIOMMU
> and vIOMMU obj. But the vIOMMU obj can only be connected with one pIOMMU.
> right?

Yes. Most of my earlier vSMMU versions did something similar, e.g.
one shared vSMMU instance in the QEMU holding a list of S2 hwpts.
With this new iommufd viommu object, it would be a list of viommu
objs. Eric suggested that HostIOMMUDevice could store any pIOMMU
info. So, compatibility check can be done with that (or the old
fashioned way of trying an device attach).

The invalidation on the other hand needs to identify each trapped
invalidation request to distribute it to the correct viommu. This
is also one of the cons of this shared viommu model: invalidation
inefficiency -- there can be some cases where we fail to identify
which viommu to distribute so we have to broadcast to all viommus.
With a multi-viommu-instance model, invalidations are distributed
naturally by the guest kernel.

Thanks
Nicolin


  reply	other threads:[~2024-09-27 20:30 UTC|newest]

Thread overview: 149+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27 16:59 [PATCH v2 00/19] iommufd: Add VIOMMU infrastructure (Part-1) Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 01/19] iommufd: Reorder struct forward declarations Nicolin Chen
2024-09-05 15:44   ` Jason Gunthorpe
2024-08-27 16:59 ` [PATCH v2 02/19] iommufd/viommu: Add IOMMUFD_OBJ_VIOMMU and IOMMU_VIOMMU_ALLOC ioctl Nicolin Chen
2024-09-01  2:39   ` Baolu Lu
2024-09-02  5:27     ` Nicolin Chen
2024-09-04 16:26       ` Jason Gunthorpe
2024-09-04 17:29         ` Nicolin Chen
2024-09-04 23:37           ` Jason Gunthorpe
2024-09-05  3:07             ` Nicolin Chen
2024-09-12  3:39             ` Nicolin Chen
2024-09-15 21:10               ` Jason Gunthorpe
2024-09-05 15:53   ` Jason Gunthorpe
2024-09-05 17:10     ` Nicolin Chen
2024-09-05 17:41       ` Jason Gunthorpe
2024-09-05 18:04         ` Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 03/19] iommu: Pass in a viommu pointer to domain_alloc_user op Nicolin Chen
2024-09-05 15:54   ` Jason Gunthorpe
2024-09-05 17:19     ` Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 04/19] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC Nicolin Chen
2024-09-05 15:56   ` Jason Gunthorpe
2024-09-26  8:50   ` Yi Liu
2024-09-26 20:10     ` Nicolin Chen
2024-09-27  0:43       ` Tian, Kevin
2024-09-27  1:25         ` Nicolin Chen
2024-09-27  2:23           ` Tian, Kevin
2024-09-27  2:57             ` Nicolin Chen
2024-09-27  5:38       ` Yi Liu
2024-09-27  6:02         ` Nicolin Chen
2024-09-27 11:59           ` Jason Gunthorpe
2024-09-27 19:52             ` Nicolin Chen
2024-09-27 12:12           ` Yi Liu
2024-09-27 20:29             ` Nicolin Chen [this message]
2024-08-27 16:59 ` [PATCH v2 05/19] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test coverage Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 06/19] iommufd/viommu: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctl Nicolin Chen
2024-09-05 16:03   ` Jason Gunthorpe
2024-09-05 17:37     ` Nicolin Chen
2024-09-05 17:43       ` Jason Gunthorpe
2024-09-05 20:14         ` Nicolin Chen
2024-09-11  6:19           ` Tian, Kevin
2024-09-11  7:11             ` Nicolin Chen
2024-09-11  7:18               ` Tian, Kevin
2024-09-11  7:47                 ` Nicolin Chen
2024-10-01  8:54       ` Nicolin Chen
2024-10-01 13:46         ` Jason Gunthorpe
2024-10-01 18:45           ` Nicolin Chen
2024-09-27 13:50   ` Mostafa Saleh
2024-09-27 14:01     ` Jason Gunthorpe
2024-09-27 14:22       ` Mostafa Saleh
2024-09-27 14:58         ` Jason Gunthorpe
2024-09-27 15:59           ` Mostafa Saleh
2024-10-04  4:32   ` Alexey Kardashevskiy
2024-10-04  5:33     ` Nicolin Chen
2024-10-04 11:41     ` Jason Gunthorpe
2024-10-04 18:13       ` Nicolin Chen
2024-10-04 18:50         ` Jason Gunthorpe
2024-10-04 19:25           ` Nicolin Chen
2024-10-04 20:17             ` Jason Gunthorpe
2024-10-04 20:33               ` Nicolin Chen
2024-10-07 17:18                 ` Jason Gunthorpe
2025-04-30  7:54       ` Alexey Kardashevskiy
2025-04-30  7:58         ` Nicolin Chen
2025-05-05 17:08           ` Jason Gunthorpe
2025-05-06  2:53             ` Nicolin Chen
2025-05-06  4:35               ` Alexey Kardashevskiy
2025-05-06  4:46               ` Tian, Kevin
2025-05-06 12:58               ` Jason Gunthorpe
2025-05-06 19:55                 ` Nicolin Chen
2025-05-07 12:28                   ` Jason Gunthorpe
2025-05-07 11:18                 ` Alexey Kardashevskiy
2025-05-07 12:24                   ` Jason Gunthorpe
2025-05-09  2:57                     ` Alexey Kardashevskiy
2025-05-09 22:07                       ` Jason Gunthorpe
2025-05-10 12:51                         ` Alexey Kardashevskiy
2025-05-12 15:31                           ` Jason Gunthorpe
2024-08-27 16:59 ` [PATCH v2 07/19] iommufd/selftest: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID test coverage Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 08/19] iommufd/viommu: Add cache_invalidate for IOMMU_VIOMMU_TYPE_DEFAULT Nicolin Chen
2024-09-05 16:05   ` Jason Gunthorpe
2024-08-27 16:59 ` [PATCH v2 09/19] iommufd: Allow hwpt_id to carry viommu_id for IOMMU_HWPT_INVALIDATE Nicolin Chen
2024-09-05 16:10   ` Jason Gunthorpe
2024-08-27 16:59 ` [PATCH v2 10/19] iommufd/viommu: Add vdev_id helpers for IOMMU drivers Nicolin Chen
2024-09-05 16:14   ` Jason Gunthorpe
2024-09-05 17:53     ` Nicolin Chen
2024-09-11 23:11       ` Jason Gunthorpe
2024-09-12  3:17         ` Nicolin Chen
2024-10-05  5:19           ` Nicolin Chen
2024-10-07 15:38             ` Jason Gunthorpe
2024-10-07 16:36               ` Nicolin Chen
2024-10-07 17:11                 ` Jason Gunthorpe
2024-10-07 17:25                   ` Nicolin Chen
2024-10-07 18:28                     ` Jason Gunthorpe
2024-10-07 19:56                       ` Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 11/19] iommu: Add iommu_copy_struct_from_full_user_array helper Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 12/19] iommufd/selftest: Add mock_viommu_invalidate_user op Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 13/19] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 14/19] iommufd/selftest: Add VIOMMU coverage for IOMMU_HWPT_INVALIDATE ioctl Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 15/19] iommufd/viommu: Add iommufd_viommu_to_parent_domain helper Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 16/19] iommu/arm-smmu-v3: Add arm_smmu_cache_invalidate_user Nicolin Chen
2024-09-05 16:23   ` Jason Gunthorpe
2024-09-05 17:56     ` Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 17/19] iommu/arm-smmu-v3: Add arm_smmu_viommu_cache_invalidate Nicolin Chen
2024-09-05 16:20   ` Jason Gunthorpe
2024-09-05 18:00     ` Nicolin Chen
2024-09-05 18:21       ` Jason Gunthorpe
2024-09-11  6:25         ` Tian, Kevin
2024-09-11  7:20           ` Nicolin Chen
2024-09-11  7:50             ` Baolu Lu
2024-09-11  8:17               ` Tian, Kevin
2024-09-11  8:19                 ` Baolu Lu
2024-09-11 21:08                 ` Nicolin Chen
2024-09-12  4:45                   ` Baolu Lu
2024-09-11  8:13             ` Tian, Kevin
2024-09-11 20:53               ` Nicolin Chen
2024-09-11 23:07               ` Jason Gunthorpe
2024-09-13  2:33                 ` Tian, Kevin
2024-09-14 14:50                   ` Jason Gunthorpe
2024-09-18  8:10                     ` Tian, Kevin
2024-09-23 18:34                       ` Jason Gunthorpe
2024-09-11 23:00           ` Jason Gunthorpe
2024-08-27 16:59 ` [PATCH v2 18/19] iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED Nicolin Chen
2024-08-27 16:59 ` [PATCH v2 19/19] iommu/arm-smmu-v3: Update comments about ATS and bypass Nicolin Chen
2024-09-11  6:12 ` [PATCH v2 00/19] iommufd: Add VIOMMU infrastructure (Part-1) Tian, Kevin
2024-09-11  7:08   ` Nicolin Chen
2024-09-11  7:18     ` Tian, Kevin
2024-09-11  7:40       ` Nicolin Chen
2024-09-11  8:08         ` Tian, Kevin
2024-09-11 20:21           ` Nicolin Chen
2024-10-01  1:55     ` Alexey Kardashevskiy
2024-10-01  3:36       ` Nicolin Chen
2024-10-01  5:06         ` Alexey Kardashevskiy
2024-10-01 13:44           ` Jason Gunthorpe
2024-09-25 10:30 ` Yi Liu
2024-09-25 18:55   ` Nicolin Chen
2024-09-26  8:47     ` Yi Liu
2024-09-26 20:03       ` Nicolin Chen
2024-09-27  2:05         ` Baolu Lu
2024-09-27  6:14           ` Yi Liu
2024-09-27  5:54         ` Yi Liu
2024-09-27  6:32           ` Nicolin Chen
2024-09-27 12:12             ` Yi Liu
2024-09-27 12:20               ` Jason Gunthorpe
2024-09-29  7:19                 ` Yi Liu
2024-10-01 13:48                   ` Jason Gunthorpe
2024-10-01 18:40                     ` Nicolin Chen
2024-09-27 20:44               ` Nicolin Chen
2024-09-29  7:16                 ` Yi Liu
2024-09-30 21:59                   ` Nicolin Chen
2024-10-09  7:20                     ` Yi Liu
2024-10-09 12:31                       ` Jason Gunthorpe

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=ZvcVjNHykF1BJLUt@Asurada-Nvidia \
    --to=nicolinc@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jasowang@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=mshavit@google.com \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shuah@kernel.org \
    --cc=smostafa@google.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=will@kernel.org \
    --cc=yi.l.liu@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