[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 1/7] xen/arm: Improve readability of check for registered devices


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 6 Jun 2023 23:02:14 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IR23MxhVQUAbCp/F/DH8joMby5YUmz7+v0X+yjQZ5Cw=; b=kuoGyO3tcw21UfhiSctHkgd4FEEsCYNVSLhgP/066BJ+AiyPbOYWshwbmiEsiRrQpPxpxejmwrNN7VfROqEpTeKg9HcL6q6WkgiYBeSI8OUwml7+XjwTG+5R0kxbOtFcdsfqvR62Nl1/uAbWKaw7txW6gFtJtVwqMCwrijjesTAKCaO8uz2TA51YjUq7Pz1vF4tlAVyx84LOs/n28bW75NzuHLvujwuNkDp3+5Dt9dMCkx4et+uuHLIHFkP75J7b0ZAatytcVpesp55YDOYHuWLIIDpAN0snN0OKdUL/2MvbLUEIJMj0aApuCPvKdqW7M5lEEbnbBGIbkOu6De1iMA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A31Zozbf4U0MlcxvxzzzVvE4IGw2EC3S72yZrehb3FaYhv4gPWixfRk56tPS8bry9AXH9wCagNWUoAZB/NqZDomr/0Z7B7Y8444YhVgtBTPC3EyIH/IPu8jUlkvwaUYW6rjJlMaiInqXDhPlf90g7ocGV5hxUQzMT2zSA25oL0uX+njVNNGVrtx+4L1nCtZQPKxKvHDh9mow7W9vMiZalrF+Btp4sD+AzIgKFwP6wyYyP5+WXxWEvZWS32FvkIZ23vS196JrCXFpOI3lUlUeOBKWKtqvMkzFKjmtaleKtyAe54qDttwGyWdMId8Kgr0bKQfJYlrMk5DuE+5/qSOZmg==
  • Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, "Stewart Hildebrand" <stewart.hildebrand@xxxxxxx>
  • Delivery-date: Wed, 07 Jun 2023 03:05:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>

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@xxxxxxxx>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
---
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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.