From patchwork Wed Nov 29 00:47:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 1869540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lE0Zx45E; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=GQjkS6R2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sg10y66znz1ySY for ; Wed, 29 Nov 2023 11:49:06 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e+aFxDRKEtonP/ncyCt7+DQeQmayuylqVH7uiyb4qV4=; b=lE0Zx45ExFrtHC 7KS/ZTVdTIbyGwmjHDGOl0lYzIZIoAFlcBHBh6dQ9IsYsFQx9sl2SYer2DNlW84+/s0fBI2ef42cN KX8PTWXOqnGIqzS6U6dIaeHQw2cmTgQNqA97H80pu2XsXsqTltIZj0DJIq0Y/AMEiWSwzVY0uTizP 1Mwl+8yu+/vQTZCZ4ii864J0H8EGONZt/Wcpxxpr6Msc9+JB40gO557GmnpYTMEL7sABA9qZRSnHe WSW/EXhpgqsSmwm/GhmazuoMdQLqCVbYbXu0HjoHc4gVQQBRnfvGWkfKydhHVOrWW4NkDjGeghfyM R+MpA4m5XwuHEw8qRUxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r88lE-006ier-0V; Wed, 29 Nov 2023 00:49:04 +0000 Received: from mail-bn7nam10on20614.outbound.protection.outlook.com ([2a01:111:f400:7e8a::614] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r88ki-006hsr-2y; Wed, 29 Nov 2023 00:48:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EUXspeAmwG+GJkiEsJtR8ik04zF9P4r3WhBiaRkVhkayJNIm0OBUIml4lXq9tYi5kVn9aU94N7/AEyB9U454Vqs0/WvLW0W0gIC5VOnHXmA6v9me5Vyib0We7rHsG4GdSb20sAJ0pjFAQyfsEXsizOBl69H4gRFF8tWP2xiuDppfJ/9XR3TmeEsx868qJha6p6Gfi/tz5Di9eGRFd5NsxUPUXadBfRCFnWU8NgswlV7wARHAE7VmLawjiIDNKWJFjTO5hB4e0Yr8wNeZCZ4gMPhuM4Gcosi/P9Zr+aEFtR4MBtgv1EJPVpFbTo7SP9B0nmmH0m3qYa6Y5IxmxkNrCg== 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=nCeta3mOG07bQ10PQqHSM5z55NsNDTAU0bAZxyDPqNQ=; b=QAqce+h+L5Qio/2VfIPj3BgcDJ8/oPCDlWbFeGoTBaLRl/LAnADCgzdE+T0KQW16mrKypilHyMpEMwUAbnQQEr/abrbn1/ZoSorBryYcUp/K9CbvB5gX6qtWGvR05GSc29VNMd23SVCc4teSd9eY7B38s0+YC5mhdYTEnaKZWG1klU7oaeOHH301bE9lPl5hAJsrUp/Pf6+xggI3tj1SJZCDbyVp/N4KbTj9Mc9ELbc7TUM+VWJOG9Cutb2ykI7YGlTL6Tmo4mUwr4HrWAhUsaB5Z9uxqcxEdzNR5UCnZCifhBfNu23lChks21QZxgT+RJbV+3B5CPFNELg8fIvQHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nCeta3mOG07bQ10PQqHSM5z55NsNDTAU0bAZxyDPqNQ=; b=GQjkS6R29YN1fRDpTZvZa01JcHOkFKU1t6i9CAa4PiIPvMcUCTOvk4M7dhnPqOJ9VbSzS4erRA3shKDiMmVkSxIknnF3z/KpY5RyvwmZJ4+cQOfKeq3sbw2Gfz8/BnpMJN/BWLvJV9ULu8bhhwtseTyYlHBCmmQVTa3dkZK3OwC3/sHHS14ExNaxN6yK+l1gh67ZZniHJNZFxRx8nEjiJdfSDaDPUcK+v6PSicumrGrUZxOx0DXOVdZzK36vJWG274jVKnV9AKw5cKsqnEDnlmffrgoiFbQQR7rO2o/CevZfAK7GcdxQi8rnxlYNQMkZ8Wn94pmlGEN3flLPvfCb9Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by MW5PR12MB5649.namprd12.prod.outlook.com (2603:10b6:303:19d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Wed, 29 Nov 2023 00:48:14 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.7025.022; Wed, 29 Nov 2023 00:48:14 +0000 From: Jason Gunthorpe To: David Airlie , Alyssa Rosenzweig , Albert Ou , asahi@lists.linux.dev, Catalin Marinas , Danilo Krummrich , Daniel Vetter , Dexuan Cui , devicetree@vger.kernel.org, dmaengine@vger.kernel.org, dri-devel@lists.freedesktop.org, David Woodhouse , Frank Rowand , Hanjun Guo , Haiyang Zhang , iommu@lists.linux.dev, Jon Hunter , Joerg Roedel , Karol Herbst , Krzysztof Kozlowski , "K. Y. Srinivasan" , Laxman Dewangan , Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-snps-arc@lists.infradead.org, linux-tegra@vger.kernel.org, Russell King , Lorenzo Pieralisi , Lyude Paul , Marek Szyprowski , nouveau@lists.freedesktop.org, Palmer Dabbelt , Paul Walmsley , "Rafael J. Wysocki" , Rob Herring , Robin Murphy , Sudeep Holla , Suravee Suthikulpanit , Sven Peter , Thomas Bogendoerfer , Vineet Gupta , Vinod Koul , Wei Liu , Will Deacon Cc: Lu Baolu , Christoph Hellwig , Jerry Snitselaar , Hector Martin , Moritz Fischer , patches@lists.linux.dev, "Rafael J. Wysocki" , Rob Herring , Thierry Reding Subject: [PATCH 03/10] iommu/of: Use -ENODEV consistently in of_iommu_configure() Date: Tue, 28 Nov 2023 20:47:59 -0400 Message-ID: <3-v1-720585788a7d+811b-iommu_fwspec_p1_jgg@nvidia.com> In-Reply-To: <0-v1-720585788a7d+811b-iommu_fwspec_p1_jgg@nvidia.com> References: X-ClientProxiedBy: SN6PR05CA0001.namprd05.prod.outlook.com (2603:10b6:805:de::14) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MW5PR12MB5649:EE_ X-MS-Office365-Filtering-Correlation-Id: 90b77a9e-c96e-4697-a320-08dbf074dbac X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2K4XLcrDu1cIZH421yJ6fSIiXhL8IYHMHSDmOD6Ou+vzPqeHu3ams1b2+aB6CoVXDxMYikC1fAsGCwvqWBdkgy958sSXSwH7yaWpsmLm4i7eeQvuiG3D5mZgcXUnvlAv91StzWSXK+k3OL6OwxOaw7OQuk6FgQAxcYjkNIbyWaLg8vhVS3hu7h/XfZl52iFR857de0MGDAUS4SgBvYX8h803gL6NyXv+xpH1ce6PjMWTZt4J4Uj4itlurfkV+EZhy+26wQHCCqOx7nKMjVEk6y585sPZ8PJsgDrpPDQwws3MwWyzWyO8Ewo6fqtcjbJG4s1g6gARxOThDzgcZEx8LZ0nVNIbmhtPOHm/27RjNGZs6t7XuKwmmrzROAX+b+W+6eWZt7fCGhSfHI2rKfuru0EXfAuuGkn0DX3CoCgplhgDfOlNfcq0oUKyaSwg3EUpLX9EoP0T9+q2E/GSrSFxOOxB93BuKqmne7cvQypHhjoMN6hJa5stbPSgPUZfSRqUsHlPxXmLcVACeE2gitvrPs2MO+aRPVsL+1DUGXMudLYrqIyM7cBcpU6wP4tAVHnJpu5h7B4BYuJ9PSBMFX9mDU4Yw3Y8R4D757lrYMy0aseFGY0d0UFIPGDvA+0hMgNi X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(39860400002)(396003)(366004)(376002)(346002)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(5660300002)(7416002)(7366002)(7406005)(41300700001)(4326008)(8936002)(8676002)(2906002)(110136005)(316002)(66556008)(66476007)(54906003)(66946007)(2616005)(921008)(6486002)(478600001)(36756003)(6512007)(6506007)(26005)(6666004)(83380400001)(86362001)(38100700002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9Ytcw9UcmnZEbrlIm4iU4QqjBGc6/n1yRMw9/PXlSOd4cQb6/UODaE7nFetBL6Dl74KQ5gpmj15zLFfHU4ZpTuhe6qbFpFXKb2VmH67u114Pkbl5eLf48JNxpvXmclXeSA0HLswBbY6pOlhOt68R9wf8BRB5w8EEczIdAAvYBszppluyxFG0aK/XkxcgxjH+7Qyu4VxO+Z987glV88w0pG0vBX3wTV9+suUGMOVE3PABdt3y8wD/1hin+2IsR0H8oSBZp8J9kVlVELzDEzxUKdJaYtM5AAo2HpHtopCXse/xuVEJegaKde6UzE7WIVgQOjY9nCVdA4PptNtGqk3Us7jsvhetauublsqQ8++w4iBCg4grUIxWLaOAjDyTI221rRkXhWVsl5BZ7XGiZhSnl+ux4fKCwNtDtsCFTTGI4H6voKvsmQbycgusQvxdMIdfwE70yOH5aETLQT/cKOKrLxMtG7I4l9jlK8g8Zc8fsOyYYSyD5qUUR4+DcE4t+JDdieuLzylg0qL4NWXife5mmBfYadv5ZRXxK2dyVGqLvs7B3R26yNXykG+q0Mg/hOFdBvY0kmI9zub4dTcCkQJXCqWu54nuSZdLSuyj8SNBF8TmlrEM4JXfjvjh7PbwxL/Ydctu5LUkG66ZQvfkfFG+yd8jEa8HLOpPQe/F9MjR07u4azzOBdfCJoQIugiNWTphF1beeGFCPbv7iG99MAEvG4XoG0OamlTnW+nDtqac0Y8inIN2IEgc8SdMIm22dLqIMzTZOlYOVMKvCtSu6NYsCBIlpxtqnKORjE8q6lS5Ufp3Cxt3ayDu+BXb4jx+QHyel3kW96+yiVTJep3/uQS6rw7XcCGpB70OZPouJd//OiTVPhUHA390p2YkUwx6w8+yIAeKLIkZp5S2/B9GHLyQfk4KyL53Zd/5v7uBU5/Mia1+QqJHjueb6BeAQ1rIekhtr97MfADEub04Ut6cobxJn3qv8cP23lKDn918F7i/TOLJGjtqi+6c+mNc1P8GT0GmGClaB3W000pHlG1vLVPykIe/law3WiDkyEIkRiC1wIWlnU+ulDXWSHsiTerI0gYgfnYofbAeRCvkRQwz6RXICOG0C4Iw44MOGx37iSSQOmbjAJf5qJtEdYtBq6vI1odqXxvPwsQLhjFh/pmflgwo7beydKRZV1ml1f61NaL6EzdgQ7kim5J27MtTrK/TTBT4vuJ+lYn/XjI4nQB/NkRbtMxZHFWFtNWxwNR02/UcFN20DOH95NkZS1wtmiv/fg1syRK8y24XBk4kzi/mxpbnUynlfCw/ZGhnnglDoUwtc0DRwW308Er6korkdMbqknXmLOZikQB+yRop32E9Qk1+k5CLq+c1eeZDi4uAQRm2uYslN4UWJ/JB/aPsIaDrzEuRZBYKufUcy2DrkJpF8KXnnucI9LmgM0IPlfNM9VDBRnZ5xbi7e1Y265c4jN2WdcMT8rOr1W/bpVV7vNSpOKRCbh75uyugvCghwNV2jUIOxoWEchuUo7XBzfGgz2yY2/YBGVbM60E7TLyuEMJXBtXik8JOmmxU0DHy3OXtw8BfpAfmIr9AiJIzQmHrI/bv2yIX X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90b77a9e-c96e-4697-a320-08dbf074dbac X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2023 00:48:09.6808 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qnid2sxxBR52CEopIx4pyN38qx5HD22qIJhJWeAfEBE+iI/VzfaFjjKe3u3ej7nK X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR12MB5649 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231128_164832_996440_480E785D X-CRM114-Status: GOOD ( 21.88 ) X-Spam-Score: 0.6 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Instead of returning 1 and trying to handle positive error codes just stick to the convention of returning -ENODEV. Remove references to ops from of_iommu_configure(), a NULL ops will already generate [...] Content analysis details: (0.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 1.0 FORGED_SPF_HELO No description available. -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Instead of returning 1 and trying to handle positive error codes just stick to the convention of returning -ENODEV. Remove references to ops from of_iommu_configure(), a NULL ops will already generate an error code. There is no reason to check dev->bus, if err=0 at this point then the called configure functions thought there was an iommu and we should try to probe it. Remove it. Reviewed-by: Jerry Snitselaar Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe Reviewed-by: Moritz Fischer --- drivers/iommu/of_iommu.c | 49 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index c6510d7e7b241b..164317bfb8a81f 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -17,8 +17,6 @@ #include #include -#define NO_IOMMU 1 - static int of_iommu_xlate(struct device *dev, struct of_phandle_args *iommu_spec) { @@ -29,7 +27,7 @@ static int of_iommu_xlate(struct device *dev, ops = iommu_ops_from_fwnode(fwnode); if ((ops && !ops->of_xlate) || !of_device_is_available(iommu_spec->np)) - return NO_IOMMU; + return -ENODEV; ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops); if (ret) @@ -61,7 +59,7 @@ static int of_iommu_configure_dev_id(struct device_node *master_np, "iommu-map-mask", &iommu_spec.np, iommu_spec.args); if (err) - return err == -ENODEV ? NO_IOMMU : err; + return err; err = of_iommu_xlate(dev, &iommu_spec); of_node_put(iommu_spec.np); @@ -72,7 +70,7 @@ static int of_iommu_configure_dev(struct device_node *master_np, struct device *dev) { struct of_phandle_args iommu_spec; - int err = NO_IOMMU, idx = 0; + int err = -ENODEV, idx = 0; while (!of_parse_phandle_with_args(master_np, "iommus", "#iommu-cells", @@ -117,9 +115,8 @@ static int of_iommu_configure_device(struct device_node *master_np, int of_iommu_configure(struct device *dev, struct device_node *master_np, const u32 *id) { - const struct iommu_ops *ops = NULL; struct iommu_fwspec *fwspec; - int err = NO_IOMMU; + int err; if (!master_np) return -ENODEV; @@ -153,37 +150,21 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np, } else { err = of_iommu_configure_device(master_np, dev, id); } - - /* - * Two success conditions can be represented by non-negative err here: - * >0 : there is no IOMMU, or one was unavailable for non-fatal reasons - * 0 : we found an IOMMU, and dev->fwspec is initialised appropriately - * <0 : any actual error - */ - if (!err) { - /* The fwspec pointer changed, read it again */ - fwspec = dev_iommu_fwspec_get(dev); - ops = fwspec->ops; - } mutex_unlock(&iommu_probe_device_lock); - /* - * If we have reason to believe the IOMMU driver missed the initial - * probe for dev, replay it to get things in order. - */ - if (!err && dev->bus) - err = iommu_probe_device(dev); - - /* Ignore all other errors apart from EPROBE_DEFER */ - if (err < 0) { - if (err == -EPROBE_DEFER) - return err; - dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err)); + if (err == -ENODEV || err == -EPROBE_DEFER) return err; - } - if (!ops) - return -ENODEV; + if (err) + goto err_log; + + err = iommu_probe_device(dev); + if (err) + goto err_log; return 0; + +err_log: + dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err)); + return err; } static enum iommu_resv_type __maybe_unused