iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] Auxiliary IOMMU domains and Arm SMMUv3
@ 2018-10-19 18:11 Jean-Philippe Brucker
       [not found] ` <20181019181158.2395-1-jean-philippe.brucker-5wv7dgnIgG8@public.gmane.org>
  0 siblings, 1 reply; 60+ messages in thread
From: Jean-Philippe Brucker @ 2018-10-19 18:11 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: kevin.tian-ral2JQCrhuEAvxtiuMwx3w, rafael-DgEjT+Ai2ygdnm+yROfE0A,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, will.deacon-5wv7dgnIgG8,
	christian.koenig-5C7GfCeVMHo,
	alex.williamson-H+wXaHxf7aLQT0dZR+AlfA, robin.murphy-5wv7dgnIgG8

This is a first prototype adding auxiliary domain support to Arm SMMUv3,
following Lu Baolu's latest proposal for IOMMU aware mediated devices
[1]. It works, but the attach() API still doesn't feel right. See (2)
below.

Patch 1 adapts iommu.c to the current proposal for auxiliary domains.
Patches 2-4 rework the PASID allocator to make it usable for SVA and
AUXD simultaneously. Patches 5-6 add AUXD support to SMMUv3.


When a device can have multiple address space, for instance with PCI
PASID, an auxiliary domain (AUXD) is the IOMMU representation of one
address space. I distinguish auxiliary from "main" domain, which
represents the non-PASID address space but also (at least for SMMUv3)
the whole device context, PASID tables etc.

Auxiliary domains will be used by VFIO for IOMMU-aware mdev, and by any
other device driver that wants to use PASID for private address spaces
(as opposed to SVA [2]). The following API is available to device
drivers:

(1) Enable AUXD for a device. Enable PASID if necessary and set an AUXD
    flag on the IOMMU data associated to a device.

    For my own convenience I've been using the SVA infrastructure since
    I already had the locking and IOMMU ops in place. The proposed
    interface is also missing min_pasid and max_pasid parameters, which
    could be needed by device drivers to enforce PASID limits.
    iommu_sva_init_device() without arguments already enables PASID, so
    I just added an AUXD flag to SVA features:

      iommu_sva_init_device(dev, IOMMU_SVA_FEAT_AUXD,
                            min_pasid, max_pasid, NULL)
      iommu_sva_shutdown_device(dev)

    Or as proposed in [1]:

      iommu_set_dev_attr(dev, IOMMU_DEV_ATTR_AUXD_ENABLE, NULL)
      iommu_set_dev_attr(dev, IOMMU_DEV_ATTR_AUXD_DISABLE, NULL)

    Finding a compromise for this interface should be easy.

(2) Allocate a domain and attach it to the device.

      dom = iommu_domain_alloc()
      iommu_attach_device(dom, dev)

    I still have concerns about this part, which are highlighted by the
    messy changes of patch 1. I think it would make more sense to
    introduce new attach/detach_dev_aux() functions instead of reusing
    attach/detach_dev()

    Can we reconsider this and avoid unnecessary complications in IOMMU
    core and drivers? Does the VFIO code greatly benefit from using the
    same attach() function? It could as well use a different one for
    devices in AUXD mode, which the mediating driver could tell by
    adding a flag in mdev_set_iommu_device(), for example.

    And I don't think other users of AUXD would benefit from using the
    same attach() function, since they will know whether they want to be
    using main or auxiliary domain when doing attach().

(3) Get the PASID, and program it in the device

      iommu_domain_get_attr(dom, DOMAIN_ATTR_AUXD_ID, &pasid)

(4) Create DMA mappings

      iommu_map(dom, ...)
      iommu_unmap(dom, ...)

    Ultimately it would be nice to add PASID support to the DMA API as
    well. For now drivers allocate IOVAs and pages themselves.


For vfio-mdev, a driver that wants to create mdevs only performs steps (1)
and (3):

* When initializing the parent device, enable AUXD (1)
* In mdev_parent_ops::create(), call mdev_set_iommu_device(mdev_dev(mdev),
  mdev_parent_dev(mdev)).
* In mdev_parent_ops::open(), get the PASID (3) and install it in the
  parent device.
* In mdev_parent_ops::close(), clear the PASID


This code and the many patches it depends on can be found on my
iommu/auxd branch:
	git://linux-arm.org/linux-jpb.git iommu/auxd

[1] [PATCH v3 0/8] vfio/mdev: IOMMU aware mediated device
    https://lwn.net/ml/linux-kernel/20181012051632.26064-1-baolu.lu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org/
[2] [PATCH v3 00/10] Shared Virtual Addressing for the IOMMU
    https://www.spinics.net/lists/iommu/msg30076.html

Jean-Philippe Brucker (6):
  iommu: Adapt attach/detach_dev() for auxiliary domains
  drivers core: Add I/O ASID allocator
  iommu/sva: Use external PASID allocator
  iommu/sva: Support AUXD feature
  iommu/arm-smmu-v3: Implement detach_dev op
  iommu/arm-smmu-v3: Add support for auxiliary domains

 drivers/base/Kconfig        |   7 ++
 drivers/base/Makefile       |   1 +
 drivers/base/ioasid.c       | 140 ++++++++++++++++++++++++++++++
 drivers/iommu/Kconfig       |   1 +
 drivers/iommu/arm-smmu-v3.c | 164 ++++++++++++++++++++++++++++++++++--
 drivers/iommu/iommu-sva.c   | 113 +++++++++++++++++--------
 drivers/iommu/iommu.c       |  58 +++++++++----
 include/linux/ioasid.h      |  45 ++++++++++
 include/linux/iommu.h       |  12 +++
 9 files changed, 479 insertions(+), 62 deletions(-)
 create mode 100644 drivers/base/ioasid.c
 create mode 100644 include/linux/ioasid.h

-- 
2.19.1

^ permalink raw reply	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2018-12-12 10:03 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 18:11 [RFC PATCH 0/6] Auxiliary IOMMU domains and Arm SMMUv3 Jean-Philippe Brucker
     [not found] ` <20181019181158.2395-1-jean-philippe.brucker-5wv7dgnIgG8@public.gmane.org>
2018-10-19 18:11   ` [RFC PATCH 1/6] iommu: Adapt attach/detach_dev() for auxiliary domains Jean-Philippe Brucker
     [not found]     ` <20181019181158.2395-2-jean-philippe.brucker-5wv7dgnIgG8@public.gmane.org>
2018-10-22  2:32       ` Lu Baolu
2018-10-19 18:11   ` [RFC PATCH 2/6] drivers core: Add I/O ASID allocator Jean-Philippe Brucker
     [not found]     ` <20181019181158.2395-3-jean-philippe.brucker-5wv7dgnIgG8@public.gmane.org>
2018-10-22  4:49       ` Lu Baolu
     [not found]         ` <9c6cd6c1-3569-4251-8344-fc9df0e743bc-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-10-22 10:22           ` Raj, Ashok
     [not found]             ` <20181022102254.GA25399-7RUrO8UaCDyr4tA6zuQqW9h3ngVCH38I@public.gmane.org>
2018-10-23  6:56               ` Lu Baolu
     [not found]                 ` <02006e4f-2acf-6ff8-b695-c54c99509b46-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-10-23 22:13                   ` Tian, Kevin
2018-11-07  4:53       ` Lu Baolu
     [not found]         ` <fb2bd5fe-5742-fcd8-b8f0-1885040e8d4f-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-11-08 18:51           ` Jean-Philippe Brucker
2018-11-12 14:40       ` Joerg Roedel
     [not found]         ` <20181112144039.GA25808-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-11-21 11:16           ` Jean-Philippe Brucker
     [not found]             ` <8f17757a-c657-aab9-a6a0-fb0cc9c610a8-5wv7dgnIgG8@public.gmane.org>
2018-11-21 19:10               ` Koenig, Christian
     [not found]                 ` <62f05552-df46-6e12-10ed-820429dfda59-5C7GfCeVMHo@public.gmane.org>
2018-11-22  6:59                   ` Tian, Kevin
2018-11-22  8:38                   ` Joerg Roedel
2018-11-22  8:44               ` Joerg Roedel
     [not found]                 ` <20181122084429.GB1586-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-11-22 11:17                   ` Jean-Philippe Brucker
2018-10-19 18:11   ` [RFC PATCH 3/6] iommu/sva: Use external PASID allocator Jean-Philippe Brucker
2018-10-19 18:11   ` [RFC PATCH 4/6] iommu/sva: Support AUXD feature Jean-Philippe Brucker
2018-10-19 18:11   ` [RFC PATCH 5/6] iommu/arm-smmu-v3: Implement detach_dev op Jean-Philippe Brucker
2018-10-19 18:11   ` [RFC PATCH 6/6] iommu/arm-smmu-v3: Add support for auxiliary domains Jean-Philippe Brucker
2018-10-20  3:36   ` [RFC PATCH 0/6] Auxiliary IOMMU domains and Arm SMMUv3 Xu Zaibo
2018-10-22  6:53   ` Tian, Kevin
     [not found]     ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE0E176-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-10-22 11:50       ` Robin Murphy
     [not found]         ` <11f88122-afd3-a34c-3cd4-db681bf5498b-5wv7dgnIgG8@public.gmane.org>
2018-10-22 15:35           ` Jordan Crouse
2018-10-22 18:01           ` Jean-Philippe Brucker
2018-11-06 16:25           ` joro-zLv9SwRftAIdnm+yROfE0A
     [not found]             ` <20181106162539.4gmkvg57mja3bn7k-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-11-07  3:40               ` Lu Baolu
     [not found]                 ` <e22e3631-2ecb-664d-5666-8e0f865dec83-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-11-07 16:43                   ` joro-zLv9SwRftAIdnm+yROfE0A
     [not found]                     ` <20181107164323.GA19831-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-11-07 17:23                       ` Alex Williamson
2018-11-21  4:40                       ` Lu Baolu
     [not found]                         ` <758bb120-5bc0-1e2d-ccd0-9be0bcc5d8bc-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-11-23 11:21                           ` joro-zLv9SwRftAIdnm+yROfE0A
     [not found]                             ` <20181123112125.GF1586-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-11-25  6:51                               ` Lu Baolu
2018-11-26  3:01                               ` Tian, Kevin
     [not found]                             ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE68777@SHSMSX101.ccr.corp.intel.com>
     [not found]                               ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE68777-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-11-26  7:29                                 ` Tian, Kevin
     [not found]                                   ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE689B8-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-12-07 10:29                                     ` 'joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org'
     [not found]                                       ` <20181207102926.GM16835-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-12-10  2:06                                         ` Tian, Kevin
     [not found]                                           ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE95394-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-12-10  8:57                                             ` 'joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org'
     [not found]                                               ` <20181210085745.GN16835-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-12-11 18:34                                                 ` Jean-Philippe Brucker
     [not found]                                                   ` <4be63d12-fa1c-b180-761b-5e8ceed58545-5wv7dgnIgG8@public.gmane.org>
2018-12-12  9:22                                                     ` 'joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org'
2018-12-12  9:31                                                 ` Tian, Kevin
     [not found]                                                   ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE9D6CA-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-12-12  9:54                                                     ` 'joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org'
     [not found]                                                       ` <20181212095403.GU16835-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-12-12 10:03                                                         ` Tian, Kevin
2018-12-10  2:57                                         ` Lu Baolu
     [not found]                                           ` <bf1ee4a3-6d3f-e0db-a02a-1db819843a60-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-12-10  8:59                                             ` 'joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org'
2018-12-11 13:35                                         ` Jean-Philippe Brucker
     [not found]                                           ` <fc173d9f-57e2-dd87-95d0-1c615f2e14e3-5wv7dgnIgG8@public.gmane.org>
2018-12-12  9:29                                             ` 'joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org'
2018-11-08 18:29               ` Jean-Philippe Brucker
     [not found]                 ` <42949d93-e22c-dd4d-cd49-46efc0b73cdb-5wv7dgnIgG8@public.gmane.org>
2018-11-12 14:55                   ` joro-zLv9SwRftAIdnm+yROfE0A
     [not found]                     ` <20181112145541.GB25808-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2018-11-21 19:05                       ` Jean-Philippe Brucker
     [not found]                         ` <5dcf9238-62b2-8df6-b378-183ee09c5951-5wv7dgnIgG8@public.gmane.org>
2018-11-23 12:50                           ` joro-zLv9SwRftAIdnm+yROfE0A
2018-11-22  8:39                       ` Tian, Kevin
     [not found]                         ` <AADFC41AFE54684AB9EE6CBC0274A5D19BE5A7A7-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-11-23 12:14                           ` joro-zLv9SwRftAIdnm+yROfE0A
2018-10-22 10:07   ` Raj, Ashok
     [not found]     ` <20181021194426.GA11201-7RUrO8UaCDyr4tA6zuQqW9h3ngVCH38I@public.gmane.org>
2018-10-22 16:03       ` Jean-Philippe Brucker
     [not found]         ` <d45c5222-68e9-1d6e-730b-bb8dbc060586-5wv7dgnIgG8@public.gmane.org>
2018-10-23 17:16           ` Raj, Ashok
     [not found]             ` <1540314963.21962.20.camel-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-10-23 22:08               ` Tian, Kevin
2018-10-26  3:00           ` Lu Baolu
2018-10-22 16:48   ` Jordan Crouse
     [not found]     ` <20181022164834.GH26762-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org>
2018-11-02  3:19       ` Lu Baolu

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).