All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stewart Hildebrand <stewart.hildebrand@amd.com>
To: <xen-devel@lists.xenproject.org>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>, Rahul Singh <rahul.singh@arm.com>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	"Stewart Hildebrand" <stewart.hildebrand@amd.com>
Subject: [PATCH v4 1/7] xen/arm: Improve readability of check for registered devices
Date: Tue, 6 Jun 2023 23:02:14 -0400	[thread overview]
Message-ID: <20230607030220.22698-2-stewart.hildebrand@amd.com> (raw)
In-Reply-To: <20230607030220.22698-1-stewart.hildebrand@amd.com>

From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

Improve readability of check for devices already registered with the SMMU with
legacy mmu-masters DT bindings by using is_protected.

There are 2 device tree bindings for registering a device with the SMMU:
* mmu-masters (legacy, SMMUv1/2 only)
* iommus

A device tree may include both mmu-masters and iommus properties (although it is
unnecessary to do so). When a device appears in the mmu-masters list,
np->is_protected and dev->iommu_fwspec both get set by the SMMUv1/2 driver. The
function iommu_add_dt_device() is subsequently invoked for devices that have an
iommus specification.

The check as it was before this patch:

  if ( dev_iommu_fwspec_get(dev) )
      return 0;

and the new check:

  if ( dt_device_is_protected(np) )
      return 0;

are guarding against the same corner case: when a device has both mmu-masters
and iommus specifications in the device tree. The is_protected naming is more
descriptive.

If np->is_protected is not set (i.e. false), but dev->iommu_fwspec is set, it is
an error condition, so return an error in this case.

Expand the comment to further clarify the corner case.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
v3->v4:
* new patch: this change was split from ("xen/arm: Move is_protected flag to struct device")
---
 xen/drivers/passthrough/device_tree.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c
index 1c32d7b50cce..d9b63da7260a 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -141,12 +141,17 @@ int iommu_add_dt_device(struct dt_device_node *np)
         return -EINVAL;
 
     /*
-     * The device may already have been registered. As there is no harm in
-     * it just return success early.
+     * Devices that appear in the legacy mmu-masters list may have already been
+     * registered with the SMMU. In case a device has both a mmu-masters entry
+     * and iommus property, there is no need to register it again. In this case
+     * simply return success early.
      */
-    if ( dev_iommu_fwspec_get(dev) )
+    if ( dt_device_is_protected(np) )
         return 0;
 
+    if ( dev_iommu_fwspec_get(dev) )
+        return -EEXIST;
+
     /*
      * According to the Documentation/devicetree/bindings/iommu/iommu.txt
      * from Linux.
-- 
2.40.1



  reply	other threads:[~2023-06-07  3:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07  3:02 [PATCH v4 0/7] SMMU handling for PCIe Passthrough on ARM Stewart Hildebrand
2023-06-07  3:02 ` Stewart Hildebrand [this message]
2023-06-07  7:27   ` [PATCH v4 1/7] xen/arm: Improve readability of check for registered devices Julien Grall
2023-06-07 13:41     ` Stewart Hildebrand
2023-06-29 21:47       ` Julien Grall
2023-07-07  2:17         ` Stewart Hildebrand
2023-06-07  3:02 ` [PATCH v4 2/7] xen/arm: Move is_protected flag to struct device Stewart Hildebrand
2023-06-29 22:22   ` Julien Grall
2023-09-29 14:45     ` Stewart Hildebrand
2023-06-07  3:02 ` [PATCH v4 3/7] iommu/arm: Add iommu_dt_xlate() Stewart Hildebrand
2023-06-29 22:29   ` Julien Grall
2023-09-29 16:31     ` Stewart Hildebrand
2023-06-07  3:02 ` [PATCH v4 4/7] iommu/arm: Introduce iommu_add_dt_pci_sideband_ids API Stewart Hildebrand
2023-06-07  7:59   ` Jan Beulich
2023-06-07 12:45     ` Stewart Hildebrand
2023-06-07 13:41       ` Jan Beulich
2023-06-29 22:37   ` Julien Grall
2023-07-04  9:35   ` Julien Grall
2023-09-29 21:03     ` Stewart Hildebrand
2023-06-07  3:02 ` [PATCH v4 5/7] iommu/arm: iommu_add_dt_pci_sideband_ids phantom handling Stewart Hildebrand
2023-06-07  3:02 ` [PATCH v4 6/7] xen/arm: smmuv2: Add PCI devices support for SMMUv2 Stewart Hildebrand
2023-06-07  3:02 ` [PATCH v4 7/7] xen/arm: smmuv3: Add PCI devices support for SMMUv3 Stewart Hildebrand
2023-06-07  7:19 ` [PATCH v4 0/7] SMMU handling for PCIe Passthrough on ARM Julien Grall
2023-06-15 21:05   ` Stewart Hildebrand
2023-06-25 12:56     ` Julien Grall
2023-06-25 14:28       ` Rahul Singh
2023-06-28  8:14         ` Julien Grall

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=20230607030220.22698-2-stewart.hildebrand@amd.com \
    --to=stewart.hildebrand@amd.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=rahul.singh@arm.com \
    --cc=sstabellini@kernel.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.