From patchwork Thu Dec 7 18:03:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13483755 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="uHEngP5w" Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2087.outbound.protection.outlook.com [40.107.220.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 526B710F7; Thu, 7 Dec 2023 10:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IfUXgKTejQA4jstSuFLc744GgJhGrxaUe7mP3xop4ipVew4lMwFR/4ilJUAf9MFYJVdSepnJuuKCW1WJtSFS54cvjfQ1fTEslFm4ze6VeFXcyABqOKq4mwzm6YpvMzlqMKnv2sucyrzUVAqqvvegiTf92X0QJ1QXrd2i+Gz1bmBzTiAzAjhZcR7x/6LqOpzI5X7C4zKbjndkhpwMMOFILCu0nLn9LyKbLLW/vchLBCu4/mrG+6d8r0DFemLrIvgOBpPvrbT/xSbK5NUv2P0T9BHaE+D/jkwgg5gpF8b3bUOymg5i1npuxcbsDWEYDW6JU5zhsDTPd8uoHxws1JRWhg== 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=yWIwmEuWImSSTmwf8ViG61yiRK9AiGEml5HPWK2cQs0=; b=Chc+EJHUTTELTAbhADfMsUMD83wFo8IqDtgz+XNuX8NPXzCn40XpM25UeCwh6n9J8dtzoF2IlfQ/Bl2a/MHB1qFN4m3mMxJs90TfnZWDMBn3WW16Ff1gIh6gfB7Fnd8Ho5uolEwfuqelsVAx+f+AyW3OhjJ63SuLXnyWrfde5pPFv5Y0xPZm8Oe9k/lw33+eI5jNsfMQVw2k5DXF/2OB20Vpuyxd2TmRYo3twFOBY3+Aodi77NboIpcQm9eq+zZ8tWtx4pBpbCuViWvEtxPMevgsZFZ5k8CHZxWJcvmlBNzncTuiVxtVkAn+L5SvVcL0fq/XwjODbskHg6tEl5M8cQ== 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=yWIwmEuWImSSTmwf8ViG61yiRK9AiGEml5HPWK2cQs0=; b=uHEngP5w8zYof4h2unuFsqucwK2tsSWdiFdDX3qls4z80PAFFikZNSYd6GR4P/sf1pkWL8Is0bHRGaNmRUQT9sRt6kel7z7N5Vtdi+J+owwBosNHR8o+sBEMUaj+FgIvwDQzErJzdkD4IWQbJ0iBUB9/lXhruNoX9drvrWSDd2ffGSrz2DcH8QItTny3zpzblCHOP8oxrJcAEUdQHtoXP/14QzzWEfdpCmTniZz/RXbVVXrp0+3kXCo+k8aIFOjsgnd9xu1kijpn+L5blTGLAcO4p0orIZkQ+waa0rlprzK/aDe54qaaYtZ81AMG/378M33JYlzPxWk4Qfr7XVsshA== 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 CH3PR12MB7667.namprd12.prod.outlook.com (2603:10b6:610:14f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.25; Thu, 7 Dec 2023 18:03:16 +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.7046.038; Thu, 7 Dec 2023 18:03:16 +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 , 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 , Lyude Paul , Marek Szyprowski , nouveau@lists.freedesktop.org, Palmer Dabbelt , Paul Walmsley , "Rafael J. Wysocki" , Rob Herring , Robin Murphy , 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 , Moritz Fischer , patches@lists.linux.dev, "Rafael J. Wysocki" , Rob Herring , Thierry Reding , Thierry Reding Subject: [PATCH v2 3/7] iommu/of: Use -ENODEV consistently in of_iommu_configure() Date: Thu, 7 Dec 2023 14:03:10 -0400 Message-ID: <3-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com> In-Reply-To: <0-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0054.namprd03.prod.outlook.com (2603:10b6:208:32d::29) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH3PR12MB7667:EE_ X-MS-Office365-Filtering-Correlation-Id: 280d834f-15e4-4df5-fae8-08dbf74ec8c0 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: bsgQUSXxN7dCltll6CjCkPlMZFIgFP7i1IrAkFYOQMVFC7IAU7ROSWiqBU9TBTNZQWUmJ8GJTYiqJilPdokzYIGTy//9L/hV2oNoe8tBth2tYj662qSVgnamip6Wy+4wnmYuRC0lW+8Ut6DdhiXPXVzWky7ikqxjVjTgCCtWKVEcjmDUPQoL/EsAqsrDTD3jJJFGxIjOpWVN94f7q+VgTW44PuyklRxjLGduIyBGZe3oZ78CzU1C2A+edex6zFb+6s3zL5+nGiIOc9f/vA9sNQJANqHgcnPBcfxfVjObprbTLyDyF4uWheNNXh8HLv2zxkLzZ2LMxKme3G6b0MnXbUn2QSQFNThL5KxByBcqY6+mbESFuXp6BfgHtU+HJ3vc059zfwjoLJLG0vvR80uyT8lZxRnsL1Olelfrisa6PMspkDJ5XzmWh7sdcTLdBtx3Up0apHWIR5RFRbjp4zz+POXt2GW7kmeoitagUj4Q72YLuuwQhyYyWVi5dWE654OV+2GEmVSHf2yDEdPf3YQNtYfSGQ83Yn4zzckOnou24PCRQH/vzPznhWhbvVnapkkT8QX93UFO7NUHHye/vCncn1w/RGPH2VmzANHXozZSq8YeCg7VvSTje3lXv3c9ERfD 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)(39860400002)(366004)(376002)(346002)(136003)(396003)(230922051799003)(186009)(1800799012)(451199024)(64100799003)(7366002)(7416002)(2906002)(7406005)(5660300002)(41300700001)(86362001)(8676002)(4326008)(8936002)(36756003)(316002)(66946007)(66556008)(66476007)(54906003)(110136005)(921008)(38100700002)(6486002)(478600001)(107886003)(83380400001)(6666004)(6506007)(26005)(6512007)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vgb+bYitXAtHpG90YCWagwRP5QvBeBpZ01DOmL5P1g23eVNewd2V6mjfmt5g9e6l1t2iZecRN8strjkmEZQztMs7daHHsKlD3dOlJXlk+HhiDv5gghNec7LuRo3bms0Ey87u32Angc2Ephaqe+TqTY9ayu5PkL9s+/cndRXR3e7FpLuXGZIp6bl13anXW2Ffb9mZzyXMPopDZqArIzHMGjh4NX9VIKAwMJGf7+HnbPpDe0/zTwcOsLdKvhZEacQ6Tt5VDk2jZu9or0MO/PrBR3gZpR+n8j4125RgEQcZ5q4Rzh7zK1n3GmEFoEheNWNUd5n8wQkEgreQ/39ULs+aP8AIv8ZHEXRZQv/73Vst22ZoYdKYXRFqEOrUIQ7bCcB1CpqBMaGzyuy6u7YY3PSbLMHbX6cDdclkf7DrP4yl1yufwEfewllkATw2WDtQFslFbD+vDkV9r8XqivGQNqbA+dRWnP90X5oziJiWAKRfiwGIvPeLQcsB8toP/a9i7VzWklscUE5WzTLJnoLQvTg/yyg2Dh5khDISqYkb2vQ4HjXCd/a5nw0rbZp9LowN03buCFoktl5VBXghbUbbB5oZqpSHvphsbFCtw0gyM/x8aKUoEXF+CeBBbtttkt8kIaxDh1/ZX5Fg68047kWdJDE487gSz90aAUjAtnFJxSDQ8NKN757VRIkUWbPh7+UTlZyVO+uNYR9DM68Jj4tzbbo8a3f2WWIWdyZWaUnMc6gPMHTRwJUeUOlEfW2+kxelV8lE87H/Ta36gPyOm/6951DH8yv/K6cvvCa6gQ4ivkTREzG/xbr/0PdYL5WklhoHVJBEI6McGnaqrRyrOFK6rI0NdzD5bVLu+1aO2AcZxzxhGCZf2MThgvwzn6gF3I+0qtX7TtvM894T+T5UKcunPsOW0bUcYyotxIU2+zWiizqoBsKeR0NWLFo2QRV7Z0DA88I8KNQpwmNulSRMysP/oILWcamkPXOFXR7Z4AHOdHJ7r4/UsMdjDOxYMfajAEyoX+SBUNo6rYfUxtfDyp9nq6Jen8T13uPRkqMLSrFzhU0UNdtKYFGygUerK3aSj+mJ/h0Ej/SoH3tZz3PiC/w4gn0LrTc40B7u5ipEtbsPJIqPjfkJW+kXPWfiM66TUNV/LrKEfw3nQWAgFhHTfegRCcY5Zz0gdCsc8PTBHrmivc7yP9PYDqIpdsp+Bf5VDj+DU3Qv28n5wzkeY7DN9DlPPhrAzYDSYnAP2bzGBw/fdBE0E1tK6S9Aot5IUv494NNqW0HHBkX6foNDhKXFvwShb0m3K3bDZMlUmrZNkRuoUJUzb0rFqUddJgsHgbHkAFoxUvtF2fXDtkUvWCdDXOrSd5wrT9F3KcVqCni1+KSG8c+UiiKmZtLKmGpJTE267NGuJxf2cP4NCnDB7K9rPLV/x2A7LgX4vvCCbOQ2QwX/9idxt30rPZkXMX3pON7+qrCKhCAdVTGtNHG1X54IrkhkIE973VhPsN6/P5dup5WuFa6kJL+ffU+l33+CSFgYM1PtUMhiGnTRPAqoMT0Y/cwHNqpXZSt2rIqgR5dPkeZDxPXeYQ/uugmKOXCUWuTE6W0I+rpD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 280d834f-15e4-4df5-fae8-08dbf74ec8c0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2023 18:03:15.2272 (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: umm7RhHZZ7XK2vJf6srTrWIFnDAVscDE7SbqOUMWZws5Px3ErVnmvG8pQpff4vPw X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7667 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 Reviewed-by: Moritz Fischer Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- 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