From nobody Thu Nov 14 08:29:21 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90EC1C4332F for ; Mon, 17 Oct 2022 23:02:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbiJQXCd (ORCPT ); Mon, 17 Oct 2022 19:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbiJQXBj (ORCPT ); Mon, 17 Oct 2022 19:01:39 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2054.outbound.protection.outlook.com [40.107.243.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F07978306A for ; Mon, 17 Oct 2022 16:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bKPQ7UeYM60ohN+JTCQD3V5C0NAa6BhY4x+LLIIEQEu1QUhclWKftlTZaniYk4rHzFINwwumZs5/7XF3to2kMcJjQKWEcIMpSzhXeOTd1L9UYgSyS4yaw05aWP5oSYk6CBXpJH0vczwy0XEVwOAtafiutFpCfLjA1rwMD31VW/7acG77uiqmM3d16f6lWUcxynoxtpUFdyLFt2Ox7oX6hVQ+a8mI8baxu63PAX29n5B4e4FjZ5aU6DUZvvqiRbDU0Dc28szos2RqCOMs4gK42Wa8f8I9yGTaBEiHUWDfGeG7k2r1PSiGVQGyI8Pqsf2DXzDgxGetQSRG90UU2Be0Ug== 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=MT0lY3mbgmiFSnOeSMckMtE9MFTGdyP0vg2ZAYNExvM=; b=TDbTgL5UBsmGmIKGQKnaj+tMdsa7JlcfUz9EFDzRgp/dLBwaMzxsNU+W6+BKvIonFnZHj1o37aA014Yrdal5mI4RxtA92U8VBCjzSTuINzIrFxpGgBlPT54Gx6HzwYKgGX24zaVsM9SfKE5LZbSTgt+Y9GVuzRUre3j9bH7YTgSadsEh87Crw6HRV6Bu86XN9PrdMAbneFRvemJ/k0zVr6ny3/ADwR8Mez1cFpCqKOIyFz1d+QPuZXRa0SuoC8AYGTpZsVr+15aV1agLHYil6yCUFEku+/m/1CwRnQWbTmxkWAo5Pib1K0HJGdHxcoorG2dQu4yrKgzIDUAAIcFeKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=8bytes.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=MT0lY3mbgmiFSnOeSMckMtE9MFTGdyP0vg2ZAYNExvM=; b=THjdEk0obZh1hgE67JTJeQcAXS1+aDwkHwPxbNJsdohK+dt8LyuL+JbxTJGJlgJEkbb9NMosCrRlYS0l7lj+9SOROnKETbJVd9yne8iLF3p+Y7NDoN6w+ajDMD2jQ7zxKLQlK8eBj0bF+KnE6w06YMwR5At+F6QBA51nYIKTQH716JXaTO9WK1kKwplHhOgfo6nrCMiANdMKR3N9jM2P5GcnoUMEENawVxQQByvSlquSwE/lNfDzuVSVygWKlnWQrs/SBfjvMENvdd75aC0HGg+TSwlvnAu4DHk66xSutfAOYrH9+o3IsMvRyTwhxL1vUnP3tu83dfxShfq+TV4y9w== Received: from MW4PR04CA0105.namprd04.prod.outlook.com (2603:10b6:303:83::20) by BL1PR12MB5320.namprd12.prod.outlook.com (2603:10b6:208:314::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Mon, 17 Oct 2022 23:01:03 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:83:cafe::e8) by MW4PR04CA0105.outlook.office365.com (2603:10b6:303:83::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32 via Frontend Transport; Mon, 17 Oct 2022 23:01:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Mon, 17 Oct 2022 23:01:01 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Mon, 17 Oct 2022 16:00:48 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Mon, 17 Oct 2022 16:00:48 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Mon, 17 Oct 2022 16:00:47 -0700 From: Nicolin Chen To: , , CC: , , , , Subject: [PATCH v7 1/5] iommu/amd: Drop unnecessary checks in amd_iommu_attach_device() Date: Mon, 17 Oct 2022 16:00:45 -0700 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT013:EE_|BL1PR12MB5320:EE_ X-MS-Office365-Filtering-Correlation-Id: be357109-64db-4c7c-37ce-08dab09375f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o+6g8VUjorM8f9Ep4W6pB7a8pWxhoIzVWCqzZQdtbF9IzafTzF/ofcX9G0oSfVs8V+ibJ/cWG6DW97ePUnS/7rla7py/qaUIpvFcwyb46FQ/083kWqOJeKJrQ/frpehP/3V3qbPp45bPeeyuJU16RLnNZ4QeFQft+52mb/KSY1ximO8N/ip8WVX9JgDpq55bwI9xHe9enC4F8v0vYYfcQVDR5S+NLennNVeUjgO91vAfoUaBEgZL42N0ijinsBAjfihuvTM3JqTpQge9wonKFsOf0Svz2mGwmg2V1WgppIZBUvy1MzZYAvksc17zmXvk/8ivlSxwlJP6qpm8C7hUUeb/hK4DYnxPnFum6mZOFbTteWtMlvZur5720RhigEGICv9aPnZG+xYKynEgZ2OguXVYJ9MTaF7JYxC+sN6J/H0KEfRETdWDP+gbYIv/wAkmaUXrdHCXCM6PxXaYe+sW5crcypGuvA7UmE3r9bj2Wn6dGDu77pEW+RH6XRI/84YyW5z1gF5X/xFrnm6IHZK3MvKxm25ePisd/X1EDRdHZC8lcA3c9vsM/e68PQdQQ6zfN+MZ/h/Nn9aupn42KkccFA1odxbWnrPBl+dgyTZfjTAjPTzbOeeFN7xl0E9HcrmtAZ+TjmqhJX/4/FU1UHCC/OYcQavanvHLah9es8E3v8mWnWrT2SZ0BwHe7aQcJeWcIP5/JNanflnGHsDzO57OawA2eoyP4mVFlYx1x8SaeofzLm51Yxc0pJ4U/CqbAC+EbRJuudb8Oe2s/r9s0heNrA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199015)(46966006)(36840700001)(40470700004)(83380400001)(2906002)(2616005)(336012)(186003)(426003)(40460700003)(8676002)(7696005)(26005)(4326008)(82740400003)(47076005)(40480700001)(86362001)(82310400005)(356005)(7636003)(36756003)(316002)(54906003)(41300700001)(5660300002)(8936002)(36860700001)(70206006)(110136005)(70586007)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 23:01:01.1226 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be357109-64db-4c7c-37ce-08dab09375f7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5320 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The same checks are done in amd_iommu_probe_device(). If any of them fails there, then the device won't get a group, so there's no way for it to even reach amd_iommu_attach_device anymore. Suggested-by: Robin Murphy Cc: Joerg Roedel Cc: Suravee Suthikulpanit Reviewed-by: Vasant Hegde Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/amd/iommu.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 65856e401949..fbb2d1be76a0 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2155,21 +2155,13 @@ static void amd_iommu_detach_device(struct iommu_do= main *dom, static int amd_iommu_attach_device(struct iommu_domain *dom, struct device *dev) { + struct iommu_dev_data *dev_data =3D dev_iommu_priv_get(dev); struct protection_domain *domain =3D to_pdomain(dom); - struct iommu_dev_data *dev_data; - struct amd_iommu *iommu; + struct amd_iommu *iommu =3D rlookup_amd_iommu(dev); int ret; =20 - if (!check_device(dev)) - return -EINVAL; - - dev_data =3D dev_iommu_priv_get(dev); dev_data->defer_attach =3D false; =20 - iommu =3D rlookup_amd_iommu(dev); - if (!iommu) - return -EINVAL; - if (dev_data->domain) detach_device(dev); =20 --=20 2.17.1 From nobody Thu Nov 14 08:29:21 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3585C433FE for ; Mon, 17 Oct 2022 23:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbiJQXGH (ORCPT ); Mon, 17 Oct 2022 19:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbiJQXF2 (ORCPT ); Mon, 17 Oct 2022 19:05:28 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F053284E58; Mon, 17 Oct 2022 16:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WnbwoAAvaARGuQ9T2LiI5cLgBO1mWmDpf2Tpo3IDbOBmYloTxPo0D8FbDuuTdAUr4ayZCApOs1bmT4vIdjKWPv7kAaoW0RFnrMh/XAfKb9n9Czc9qs1hfyGzdwDLdp8kf96R4nGmAVqwbDIQ+a4kinxCcjPn2zHkzJzE5diwcVmoPQKqnvjQwbvagmCUaV2Sif/TCRyNoaJpB/qREjla6NJznzu60t40b5ydv6yeeYns2cuioVY5WaKA1Lv2OwkDX2TKxoW4NYllXUQS5d8fxI3MPU2r6pLWfTYteN1cUU90gA3iRC70zfTUhBAMQZ+/6Hl7hteA/v4B7Wn+JuWv8w== 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=83OZRIvitM222fOcogL3i3tPVuHaJXb1DWqJ2DZfAsw=; b=kHhyAapHGYj1lE0WzFS0yj91d5XJJOILDszz0HMCO+Riyi1wGTaX63LV0DrViA1BwStJxYGuLygtBPWkocH01mclVP8EwSvRimJObVn1fl9f5LLhkuha4tTutHLujPR+LK9bIoWXRPfg70J5SauQoQpBYbEHWiPop/qo2a8ErT4yxzA6YhmRf+wpyD2Hl0Z/3IssU2+bcg6HRFkBFSFYW3bKOXVOKtKc2pdSCS9JKg+sWNb0vfvSXu9+cL1nWjuuNI4i8/YThhwqp1RzyzHFjClLKNycV3cbSxSfcs0b5oY1KVW3u1wxHv0cYqaHdbvJNU3uq03/K8atDY7CqSBIXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=8bytes.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=83OZRIvitM222fOcogL3i3tPVuHaJXb1DWqJ2DZfAsw=; b=I3R2CkZDeDJt1oCmEoSVBIoRG8XL1BDqXLV97Pynarpjz5F2OOMLEOq8NZVLY2qwLCCEbGNYO4t3COdm5eF7niuqzcX9E2s1ZD8ezQh7yssC93dKY0/yUqzJbVVP0vGOE6iAewB2IipI3mD1sgyolpIqhLeQaGQFIbQ+PuJpJBbA9v5UO5QCoJS39gY+AbrIKR+mwZyMkk76k2n6B1t++VI9G/mfvVTHA6HsncnQcOnSdobBQhEnxKYAagS1q/xi9lA/dNx+lqA/qYxI+ljUB1FTqR0pBr2P2OK7sCqYQ75BWaJbzWmlsIPXCrSaxlAFe1GtiCZ69KTSGf3MwtD3zg== Received: from BN0PR04CA0153.namprd04.prod.outlook.com (2603:10b6:408:eb::8) by BL1PR12MB5285.namprd12.prod.outlook.com (2603:10b6:208:31f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 23:02:11 +0000 Received: from BN8NAM11FT086.eop-nam11.prod.protection.outlook.com (2603:10b6:408:eb:cafe::24) by BN0PR04CA0153.outlook.office365.com (2603:10b6:408:eb::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32 via Frontend Transport; Mon, 17 Oct 2022 23:02:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT086.mail.protection.outlook.com (10.13.176.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Mon, 17 Oct 2022 23:02:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Mon, 17 Oct 2022 16:01:56 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Mon, 17 Oct 2022 16:01:56 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Mon, 17 Oct 2022 16:01:54 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v7 2/5] iommu: Add return value rules to attach_dev op and APIs Date: Mon, 17 Oct 2022 16:01:22 -0700 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT086:EE_|BL1PR12MB5285:EE_ X-MS-Office365-Filtering-Correlation-Id: 5508daa0-38ff-4d5b-6877-08dab0939ff8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YGTb2JPrXNXA64F6YZ4Z053hknGT4ed1UZwnUvroI9tXZTsxsmB0drJBjUybOjRxOlZ2uWgpc4NZExU994iw8yBMjks5vHaxsSeLdB/iwSLlVO1Xs+6u67GF/f1+jpkwkK/kpWZVilFPTZAwt00T7bkxPAN4uYxd3oOWgL1P6WJ+jxiutBLS3QESyAqTH2Z4a/J1DK6vxMNOYdzFEsWzM2aAykd9UYOda9S+nQToRhzQLrElP6WmwlK95lFoMRhqCWER4HOHj+bTM36DaxYYG9lrS68na9i5VBD2juxadCm78J6rlb2uCmwhiPTs4zsKzBngxSjQXomnWgfTj1R0Rm0INvIoaA2tdRmBjJ2SgebMWSI7BTRekQi/hcM2eIbgehl5BcEUFrghLLQ7M7YmWSotabqOZll1UdjjxJPjrlKaJ72dvZIhOnEe0Ujfe+hdVu+vhvKqzrMb/CiBEQ4msBHeXsEdNV4lEEnp9Zr6W8WI/mQdv2GM4cgUcFqemTVN0+oDBzl9U9lApn8235zRQjS+SwOYs0yosyglGJtJOHHvL3YZSZv1nuZDyQ5ZCPJVsNwvJWbYwUm7k4RohJywgn/dx5QMPtJBbAByErKKpg29dyrTjOGVFNuhJaqVddQJaIN1XbR1lkwupWmGy/Cyeibgu0fbusEJfQEHMkhTFLg8rf7QLZLo1TSecJJnyOFQ0V5Us6jDAMbVG+hxUcLt+91vouvKUeMGSpaWaRc+yFCrLaMCZVLO/GlqV1hk4sENxPs5HJUHQqzK+u6vwgGEJg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199015)(36840700001)(46966006)(40470700004)(36860700001)(82310400005)(82740400003)(478600001)(356005)(7636003)(110136005)(4326008)(2616005)(36756003)(7696005)(40460700003)(54906003)(316002)(186003)(70586007)(70206006)(47076005)(426003)(336012)(6666004)(8676002)(40480700001)(83380400001)(5660300002)(2906002)(26005)(8936002)(86362001)(7416002)(7406005)(41300700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 23:02:11.4541 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5508daa0-38ff-4d5b-6877-08dab0939ff8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT086.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5285 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved by using a different domain. Provide a dedicated errno EINVAL from the IOMMU driver during attach that the reason why the attach failed is because of domain incompatibility. VFIO can use this to know that the attach is a soft failure and it should continue searching. Otherwise, the attach will be a hard failure and VFIO will return the code to userspace. Update kdocs to add rules of return value to the attach_dev op and APIs. Suggested-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu --- drivers/iommu/iommu.c | 24 ++++++++++++++++++++++++ include/linux/iommu.h | 12 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4893c2429ca5..3c0c5d64bb50 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1949,6 +1949,18 @@ static int __iommu_attach_device(struct iommu_domain= *domain, return ret; } =20 +/** + * iommu_attach_device - Attach an IOMMU domain to a device + * @domain: IOMMU domain to attach + * @dev: Device that will be attached + * + * Returns 0 on success and error code on failure + * + * Note that EINVAL can be treated as a soft failure, indicating + * that certain configuration of the domain is incompatible with + * the device. In this case attaching a different domain to the + * device may succeed. + */ int iommu_attach_device(struct iommu_domain *domain, struct device *dev) { struct iommu_group *group; @@ -2075,6 +2087,18 @@ static int __iommu_attach_group(struct iommu_domain = *domain, return ret; } =20 +/** + * iommu_attach_group - Attach an IOMMU domain to an IOMMU group + * @domain: IOMMU domain to attach + * @group: IOMMU group that will be attached + * + * Returns 0 on success and error code on failure + * + * Note that EINVAL can be treated as a soft failure, indicating + * that certain configuration of the domain is incompatible with + * the group. In this case attaching a different domain to the + * group may succeed. + */ int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *gr= oup) { int ret; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a325532aeab5..6f3569340e8a 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -266,6 +266,18 @@ struct iommu_ops { /** * struct iommu_domain_ops - domain specific operations * @attach_dev: attach an iommu domain to a device + * Return: + * * 0 - success + * * EINVAL - can indicate that device and domain are incompatible due to + * some previous configuration of the domain, in which case the + * driver shouldn't log an error, since it is legitimate for a + * caller to test reuse of existing domains. Otherwise, it may + * still represent some other fundamental problem + * * ENOMEM - out of memory + * * ENOSPC - non-ENOMEM type of resource allocation failures + * * EBUSY - device is attached to a domain and cannot be changed + * * ENODEV - device specific errors, not able to be attached + * * - treated as ENODEV by the caller. Use is discouraged * @detach_dev: detach an iommu domain from a device * @map: map a physically contiguous memory region to an iommu domain * @map_pages: map a physically contiguous set of pages of the same size to --=20 2.17.1 From nobody Thu Nov 14 08:29:21 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31B7DC43217 for ; Mon, 17 Oct 2022 23:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbiJQXMO (ORCPT ); Mon, 17 Oct 2022 19:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbiJQXL6 (ORCPT ); Mon, 17 Oct 2022 19:11:58 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::600]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB5B785AA7 for ; Mon, 17 Oct 2022 16:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eY+NWR3+apZvhwmzqF5AZQeOrsL6Ko2J86y98O70ykDEr+UDpl1UmRq6ff3cSiJU8+jl+Ri5Cavc7bGxiZTo5kf/hinBl+24JF0UiuI0zbGFTQDyRbhldHxHqhp6lN85IokN9P4LUsQUP86efnW37EMk+ck8X0oSG518F9YHpZyhRDbCnEqAp+qELk6Uyh1tj2yPuzevR79qjhk0AfkItw7HjkXaWSxEc0AOAQTOgi8j8vPEi566jMSlceorBxPWkd2tQb/wdblUDLUCQM9KZpIP6n7wO5BxNWyzhyVJevqlw0HhL7JzX2Y8CIv/4RMGZuUEniDVsKyaBiTGgA5aSA== 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=md+2EX1dSQkKHGoKCzmI58GHG+0xMrjwQG+DK8rY6Wg=; b=Olu+dyEYCICqZ+cOUTJiIlVGMLN+YeZaisVrmwh1KF+8xUpp/+dndg+gstPe3JlIZhgMQ/phPK59uCGpeDtJkCTv5+b1eOYYMXnRralW7vet6S4ozvpcS/Me2MdEHgSA2XRSCQDhpGA75yqyB4X2rSo7/Mwb7EP8BhqUv/2BecKN4KiYX4xUT22UzKhEBOFVa2/85aHIiLrdNfUpoOtImt4vxIrXYz0ifojM8M32qY+Y0yEFJFnsKYeiWc5CpB8SZcnrI47U1YaGkeKZEkSk6/xn1LrZqu8bg+zOpZiVg+u9szQ/woMcihPyUhIpv184vYCBrJoctqDpisjtUtS7dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=8bytes.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=md+2EX1dSQkKHGoKCzmI58GHG+0xMrjwQG+DK8rY6Wg=; b=hDDDKKmUUpA1y1Tcf/Q18HzDWjPQFmSuUgFM9+X3ykj0w5l7+uqrdRlPyk8SCQrC/56d/mFcaQTT4RNjopE4qfaSa9+KdA1SeuWIkRuIRS1rjZzYvsrHCtGEoVV4U2rVkmCT8dxHC5FJsBIHly/srXsZhQYFDLKphKZ6bHj9B51ERmd3G9pUe/5jUoNXfZiL1DtG7n+xBJJjkX3KkOzLoZLJ7ResllXZ5VuToxKxLoKA8FCl9mQPKlVNjL9wgdkZ7ls+RehQIoP4o/DYSA9wgqKSL3/CuMk5kXK41oGP/IrPNYK1ezpOAw51VxIHvopDdN15TXhUnrzf82LCtBRVvA== Received: from MW4PR04CA0239.namprd04.prod.outlook.com (2603:10b6:303:87::34) by MW4PR12MB7032.namprd12.prod.outlook.com (2603:10b6:303:20a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 23:02:21 +0000 Received: from CO1NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:303:87:cafe::81) by MW4PR04CA0239.outlook.office365.com (2603:10b6:303:87::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32 via Frontend Transport; Mon, 17 Oct 2022 23:02:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CO1NAM11FT045.mail.protection.outlook.com (10.13.175.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Mon, 17 Oct 2022 23:02:21 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Mon, 17 Oct 2022 16:02:16 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Mon, 17 Oct 2022 16:02:16 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Mon, 17 Oct 2022 16:02:15 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , Subject: [PATCH v7 3/5] iommu: Regulate EINVAL in ->attach_dev callback functions Date: Mon, 17 Oct 2022 16:02:13 -0700 Message-ID: <5924c03bea637f05feb2a20d624bae086b555ec5.1666042872.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT045:EE_|MW4PR12MB7032:EE_ X-MS-Office365-Filtering-Correlation-Id: c8ad0e01-35c4-42fe-691c-08dab093a5da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: alLEcC7RG1asN5GjKte4DPx/QnrXOpncwp6ZAaWaZjKNr8Y7wmjWfzkUrYfzIw7l5CxBEjKHVH59DGIjM1ajdBBOQDwsIFlSlL8OeC9hxoBwpH83edFGMoO3zdy+nITYwyeNdedaSYUVrcU/J+tUULSvoXsorl6XlbZOGWnYoSjbkjRsEo/nWQLKyXO2PDQQNHNCezeSNkIxxxitaw5blM3bnVWSTzK9WvdwvEy3dU7Z+87z42Lv8RcRSjhZnC0Ku0I4Ll6hPI2ZMt92r+z5zuz9h9n3I5/DV3I+OEvVembCxFThHDMLkVYIAV7VfvevuburCufNNdl3N1kST2cMKKs/mTkvU+HF7ePqDm/Jb7rO8dYiDLFtQ8riJ+Y86uh1suCuqBAIlOfBMeBMCQEj6yOw98yBVWrxlx/ouB9ZaGxyMhrvGauJQspY15mZ3szJjY3G/0rXk82LdbjQDfC9AtQvpqohoA9fxmNVqYl1w3IJiHX8f36A4ZmEzWu1pt9aTaKCXx/CuHJIVGfbmDIwVLytcieEYWfrCWh7MTGs7oiN6dMDeDdMSVUgE04sH3Z/6T2zhpAhM/4ufb7tiLPM8fQcxua9gWfJwiZfUsHBf6gM35S/zyrTJQPIcIs34sBtJhL3aZ+2big+qnNB7tl+3ayep4SNi8Kr8VQR5+1ujAyL/afdFgjhyBcUfgvsFd8GE6HnkIdsLYx3BfL0sq+sNLqw+ZooATb8qNEKfNZkrCwfU++254653/jhLNZ2C7MuxT/o7QhhCznrGy+QPRnqmQ== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(346002)(39860400002)(136003)(451199015)(46966006)(40470700004)(36840700001)(54906003)(47076005)(186003)(2616005)(426003)(7636003)(83380400001)(356005)(86362001)(36860700001)(336012)(5660300002)(7416002)(82740400003)(2906002)(4326008)(82310400005)(40480700001)(8676002)(40460700003)(41300700001)(478600001)(8936002)(7696005)(316002)(70586007)(110136005)(70206006)(26005)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 23:02:21.4488 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8ad0e01-35c4-42fe-691c-08dab093a5da X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7032 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following the new rules in include/linux/iommu.h kdocs, EINVAL now can be used to indicate that domain and device are incompatible by a caller that treats it as a soft failure and tries attaching to another domain. On the other hand, there are ->attach_dev callback functions returning it for obvious device-specific errors. They will result in some inefficiency in the caller handling routine. Update these places to corresponding errnos following the new rules. Reviewed-by: Jean-Philippe Brucker Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/fsl_pamu.c | 2 +- drivers/iommu/fsl_pamu_domain.c | 4 ++-- drivers/iommu/intel/pasid.c | 6 ++++-- drivers/iommu/mtk_iommu.c | 2 +- drivers/iommu/omap-iommu.c | 4 ++-- drivers/iommu/virtio-iommu.c | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c index 0d03f837a5d4..2eb3211c8167 100644 --- a/drivers/iommu/fsl_pamu.c +++ b/drivers/iommu/fsl_pamu.c @@ -211,7 +211,7 @@ int pamu_config_ppaace(int liodn, u32 omi, u32 stashid,= int prot) ppaace->op_encode.index_ot.omi =3D omi; } else if (~omi !=3D 0) { pr_debug("bad operation mapping index: %d\n", omi); - return -EINVAL; + return -ENODEV; } =20 /* configure stash id */ diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domai= n.c index fa20f4b03e12..4408ac3c49b6 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -258,7 +258,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *= domain, liodn =3D of_get_property(dev->of_node, "fsl,liodn", &len); if (!liodn) { pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node); - return -EINVAL; + return -ENODEV; } =20 spin_lock_irqsave(&dma_domain->domain_lock, flags); @@ -267,7 +267,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *= domain, if (liodn[i] >=3D PAACE_NUMBER_ENTRIES) { pr_debug("Invalid liodn %d, attach device failed for %pOF\n", liodn[i], dev->of_node); - ret =3D -EINVAL; + ret =3D -ENODEV; break; } =20 diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index c30ddac40ee5..95d73f19ab61 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -101,8 +101,10 @@ int intel_pasid_alloc_table(struct device *dev) =20 might_sleep(); info =3D dev_iommu_priv_get(dev); - if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table)) - return -EINVAL; + if (WARN_ON(!info || !dev_is_pci(dev))) + return -ENODEV; + if (WARN_ON(info->pasid_table)) + return -EEXIST; =20 pasid_table =3D kzalloc(sizeof(*pasid_table), GFP_KERNEL); if (!pasid_table) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 5a4e00e4bbbc..f3dc2aba188e 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -609,7 +609,7 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_d= omain *dom, dom->iop =3D alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data); if (!dom->iop) { dev_err(data->dev, "Failed to alloc io pgtable\n"); - return -EINVAL; + return -ENOMEM; } =20 /* Update our support page sizes bitmap */ diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 07ee2600113c..3f153f9e0ac5 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1414,7 +1414,7 @@ static int omap_iommu_attach_init(struct device *dev, =20 odomain->num_iommus =3D omap_iommu_count(dev); if (!odomain->num_iommus) - return -EINVAL; + return -ENODEV; =20 odomain->iommus =3D kcalloc(odomain->num_iommus, sizeof(*iommu), GFP_ATOMIC); @@ -1464,7 +1464,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, st= ruct device *dev) =20 if (!arch_data || !arch_data->iommu_dev) { dev_err(dev, "device doesn't have an associated iommu\n"); - return -EINVAL; + return -ENODEV; } =20 spin_lock(&omap_domain->lock); diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index b7c22802f57c..f0caf9a4f6f8 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -668,7 +668,7 @@ static int viommu_domain_finalise(struct viommu_endpoin= t *vdev, dev_err(vdev->dev, "granule 0x%lx larger than system page size 0x%lx\n", viommu_page_size, PAGE_SIZE); - return -EINVAL; + return -ENODEV; } =20 ret =3D ida_alloc_range(&viommu->domain_ids, viommu->first_domain, --=20 2.17.1 From nobody Thu Nov 14 08:29:21 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4337CC433FE for ; Mon, 17 Oct 2022 23:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbiJQXKG (ORCPT ); Mon, 17 Oct 2022 19:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbiJQXIp (ORCPT ); Mon, 17 Oct 2022 19:08:45 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::601]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8469085585; Mon, 17 Oct 2022 16:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cQoEi9v4CaMciPrveoQ4hOMhEdj9XfnsKFB0zmIEdppbs1bjPvx61rPfX35arIuq2hCj85v/3GicHk+nhSe5DfmPerqjQeqGD105DIGfMsWjP6igIWnzW8yY5u+UlQRTm0LwhKUjONddKFOCSVGvUUfJvM5l/bo1bwIHLDzw9ciZzAd8v1GNH9dFjMddcTqQb/UHs4BchBmmNjKjWh+Yk+7LsTTRaEq5jab65o/kTkqpoBArobbnzoykQ6qpQGSnacMm0bIbyxWDoolVmfLG6+hEykpW3y5q2IpOpadr/u8XUCINwNw6cNf3SMcfCy7sSGC7+Tdpq0ur2xrQkGrcQA== 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=scc7vrirRVcL8XzNKnuTWYRhUwokIrL6E4cMmUCt3Sg=; b=CsBZpCpKI+ZFcxEZoe4xauLZ4X0UUxwjqxNB9ZyY3UK26vyUEYuhS0pGlE0StQfLOa8DBPeSK6Mj659SHQzRAOiRwGEFb97SdrTq6MkQnkfhpXyFWbI9KeJEfjh0jQEPsvCFhwakfw4ZimzHoEhsd0MRnR08ECjx1EPOKNCVbTsqc7DUuWkfbbT7xnz3Kt4+XPEN5/hfN2Jxc7NFCvh1H3PkuMCK7n++QnOlGoxXpg0MLLhXsUD+nJPfR1jz8RwsYbk52sl4LGz4AJW8EyiF9gKMttQM6jpJ4Y5NOKMR7SpFbXv2WsEaD9rWuK9e7/LxHZPxzdLFdeMFCQP7Tp5RuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=8bytes.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=scc7vrirRVcL8XzNKnuTWYRhUwokIrL6E4cMmUCt3Sg=; b=CM7fWgdP2gVwOaRl9AYKVwR1VgDshwBzsiE6UrWC7Omd3MceUobMNq0HUxyKw5MKCPGTsdfaTvNv6hpwxiXRvLTBdSoW8NVqgjmiwViSh+uiisDzIA3G0G1rnv0SjvaA+9QXJIt90hx6yj9Q3a+Gx0wOiCEeIXSlCqwF8sL6qa+NTxoyRdiKdq1/H2Cvpc6Exz4nShQBsLKoDXXCkCldT5mQB2IgAxqkxiJapgN2SnDcCBLolMvS3aIPCkLZFnCDaodXtJk3jKDotG97r1rnWZI1Q8tTxjc6ffXS3CEpYj7r3cfonS/AGqCoIDAwfmJ4O7dRSfcrYWdTzQqRX8hl8w== Received: from BN0PR04CA0096.namprd04.prod.outlook.com (2603:10b6:408:ec::11) by CH0PR12MB5107.namprd12.prod.outlook.com (2603:10b6:610:be::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Mon, 17 Oct 2022 23:02:39 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ec:cafe::aa) by BN0PR04CA0096.outlook.office365.com (2603:10b6:408:ec::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30 via Frontend Transport; Mon, 17 Oct 2022 23:02:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Mon, 17 Oct 2022 23:02:38 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Mon, 17 Oct 2022 16:02:27 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Mon, 17 Oct 2022 16:02:26 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Mon, 17 Oct 2022 16:02:24 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v7 4/5] iommu: Use EINVAL for incompatible device/domain in ->attach_dev Date: Mon, 17 Oct 2022 16:02:21 -0700 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|CH0PR12MB5107:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f853e77-116a-454c-3126-08dab093b041 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0dAtlg/n/MAltIN+Tor6ovwTMDtdDddGciZfIcuzEJ0WP5UTqRmsN/tUs0yE4qWVi/OSstzsSyVDl64EzCgKZdGXz72U1nwMSw3SPCdnFDYn9RSlOvnduZcRQrVu0ldQdCovatjfBijZbEAou2aywrRZFh2PirkDjYRpmWko3XqUGFl5UEyGdjVFsdJKe//G4LWsKGdYNQ9K9GLdgIl3ZbUr8v15cJ6UrJEqY/+/nf+zHO1UA6z/mGCl9p6oJQ1LOtGv4ZNj4vkrFSFkop+zxBcCSjhotkr0x/k+8MCOzMWamemyHfe5+qD4bPnracuP4X/8W2Q5U3AuuIHj+9YdAFPgJSToM1PKRkg/WaybrYfFGinzuFgj9qlmLmzhI9cFeqvQHlVu58ljQ0vcw7uJcONlEOcqlU/PKrbymX6VEqqYwkAgsbBrwB8VE/Ry+WL/3ElMO7ze44GTjgbPChD8mqItiZlaeVg42MaAYNrRo1qQ+hOmDPgj2VjvxKI7qqmfY7rweYrW3izVhmu13C6agFNw05vlVas/VaN6cycgMNBAVh65kz6zzxy+fR8sqfhNTH2+JDnc+3bC+g+NEOga7T0FNEasraYHiae7iTS6pQcdx8LBtgi6Fdyexdlxm2T9p7VRdNOJGr/nXUJrDIMlf6t7nTy2WDdxeMjrPWh0zZtP/JnQBX/oWiJIYTtIQawt8sZTQEQtsDJ/s8Hb3vhIYx+z2cVg438oEx++z7QwMzlgj21XBpnu3G1+H8m7aT+4uuZxhTXsmCkgWsckLV+eddpLx8WW9KkG1FclyZXJJ5E= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199015)(36840700001)(40470700004)(46966006)(36756003)(36860700001)(86362001)(7416002)(7406005)(2906002)(5660300002)(82740400003)(336012)(47076005)(2616005)(186003)(426003)(7636003)(356005)(83380400001)(316002)(7696005)(478600001)(26005)(110136005)(54906003)(70586007)(70206006)(82310400005)(40480700001)(41300700001)(4326008)(8936002)(6666004)(40460700003)(8676002)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 23:02:38.7433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4f853e77-116a-454c-3126-08dab093b041 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5107 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following the new rules in include/linux/iommu.h kdocs, update all drivers ->attach_dev callback functions to return EINVAL in the failure paths that are related to domain incompatibility. Also, drop adjacent error prints to prevent a kernel log spam. Reviewed-by: Jean-Philippe Brucker Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen Acked-by: Will Deacon --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 +---------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 3 --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 7 +------ drivers/iommu/intel/iommu.c | 10 +++------- drivers/iommu/ipmmu-vmsa.c | 2 -- drivers/iommu/omap-iommu.c | 2 +- drivers/iommu/sprd-iommu.c | 4 +--- drivers/iommu/tegra-gart.c | 2 +- drivers/iommu/virtio-iommu.c | 3 +-- 9 files changed, 9 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index ba47c73f5b8c..01fd7df16cb9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2430,23 +2430,14 @@ static int arm_smmu_attach_dev(struct iommu_domain = *domain, struct device *dev) goto out_unlock; } } else if (smmu_domain->smmu !=3D smmu) { - dev_err(dev, - "cannot attach to SMMU %s (upstream of %s)\n", - dev_name(smmu_domain->smmu->dev), - dev_name(smmu->dev)); - ret =3D -ENXIO; + ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && master->ssid_bits !=3D smmu_domain->s1_cfg.s1cdmax) { - dev_err(dev, - "cannot attach to incompatible domain (%u SSID bits !=3D %u)\n", - smmu_domain->s1_cfg.s1cdmax, master->ssid_bits); ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && smmu_domain->stall_enabled !=3D master->stall_enabled) { - dev_err(dev, "cannot attach to stall-%s domain\n", - smmu_domain->stall_enabled ? "enabled" : "disabled"); ret =3D -EINVAL; goto out_unlock; } diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-= smmu/arm-smmu.c index 6c1114a4d6cc..3bca3cc1ceae 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1150,9 +1150,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *d= omain, struct device *dev) * different SMMUs. */ if (smmu_domain->smmu !=3D smmu) { - dev_err(dev, - "cannot attach to SMMU %s whilst already attached to domain on SMMU %s\= n", - dev_name(smmu_domain->smmu->dev), dev_name(smmu->dev)); ret =3D -EINVAL; goto rpm_put; } diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/ar= m-smmu/qcom_iommu.c index 3869c3ecda8c..bfd7b51eb5db 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -381,13 +381,8 @@ static int qcom_iommu_attach_dev(struct iommu_domain *= domain, struct device *dev * Sanity check the domain. We don't support domains across * different IOMMUs. */ - if (qcom_domain->iommu !=3D qcom_iommu) { - dev_err(dev, "cannot attach to IOMMU %s while already " - "attached to domain on IOMMU %s\n", - dev_name(qcom_domain->iommu->dev), - dev_name(qcom_iommu->dev)); + if (qcom_domain->iommu !=3D qcom_iommu) return -EINVAL; - } =20 return 0; } diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a8b36c3fddf1..1ac94f7fc8be 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4189,19 +4189,15 @@ static int prepare_domain_attach_device(struct iomm= u_domain *domain, return -ENODEV; =20 if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) - return -EOPNOTSUPP; + return -EINVAL; =20 /* check if this iommu agaw is sufficient for max mapped address */ addr_width =3D agaw_to_width(iommu->agaw); if (addr_width > cap_mgaw(iommu->cap)) addr_width =3D cap_mgaw(iommu->cap); =20 - if (dmar_domain->max_addr > (1LL << addr_width)) { - dev_err(dev, "%s: iommu width (%d) is not " - "sufficient for the mapped address (%llx)\n", - __func__, addr_width, dmar_domain->max_addr); - return -EFAULT; - } + if (dmar_domain->max_addr > (1LL << addr_width)) + return -EINVAL; dmar_domain->gaw =3D addr_width; =20 /* diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 3b30c0752274..22230cc15dcd 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -628,8 +628,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_= domain, * Something is wrong, we can't attach two devices using * different IOMMUs to the same domain. */ - dev_err(dev, "Can't attach IPMMU %s to domain on IPMMU %s\n", - dev_name(mmu->dev), dev_name(domain->mmu->dev)); ret =3D -EINVAL; } else dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 3f153f9e0ac5..2fd7702c6709 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1472,7 +1472,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, st= ruct device *dev) /* only a single client device can be attached to a domain */ if (omap_domain->dev) { dev_err(dev, "iommu domain is already attached\n"); - ret =3D -EBUSY; + ret =3D -EINVAL; goto out; } =20 diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index fadd2c907222..e02793375598 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -237,10 +237,8 @@ static int sprd_iommu_attach_device(struct iommu_domai= n *domain, struct sprd_iommu_domain *dom =3D to_sprd_domain(domain); size_t pgt_size =3D sprd_iommu_pgt_size(domain); =20 - if (dom->sdev) { - pr_err("There's already a device attached to this domain.\n"); + if (dom->sdev) return -EINVAL; - } =20 dom->pgt_va =3D dma_alloc_coherent(sdev->dev, pgt_size, &dom->pgt_pa, GFP= _KERNEL); if (!dom->pgt_va) diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index e5ca3cf1a949..ed53279d1106 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -112,7 +112,7 @@ static int gart_iommu_attach_dev(struct iommu_domain *d= omain, spin_lock(&gart->dom_lock); =20 if (gart->active_domain && gart->active_domain !=3D domain) { - ret =3D -EBUSY; + ret =3D -EINVAL; } else if (dev_iommu_priv_get(dev) !=3D domain) { dev_iommu_priv_set(dev, domain); gart->active_domain =3D domain; diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index f0caf9a4f6f8..9e0ca757fa42 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -732,8 +732,7 @@ static int viommu_attach_dev(struct iommu_domain *domai= n, struct device *dev) */ ret =3D viommu_domain_finalise(vdev, domain); } else if (vdomain->viommu !=3D vdev->viommu) { - dev_err(dev, "cannot attach to foreign vIOMMU\n"); - ret =3D -EXDEV; + ret =3D -EINVAL; } mutex_unlock(&vdomain->mutex); =20 --=20 2.17.1 From nobody Thu Nov 14 08:29:22 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3250C4332F for ; Mon, 17 Oct 2022 23:07:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230199AbiJQXHP (ORCPT ); Mon, 17 Oct 2022 19:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231444AbiJQXGu (ORCPT ); Mon, 17 Oct 2022 19:06:50 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20626.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5a::626]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E10DB84E5A for ; Mon, 17 Oct 2022 16:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ajhyn/NnBBjR5jNcM50fI90VkbEEN2NdCwBivyqRqVGIdrGhkTFhVcCwqXoR4s3f1hpLigPQY36A5q7HRTvua5RikMCcJIehTzcKsNuw3Oj2lPcuewd5Uorq95aGtgt+mW7gLUp12tX4Eix4clLZyJ5HR37lqpnoJI4k7i9H77zKvO86T/Fs4hTstDLT79C3+V54+o5/pHKYIdI7MKNCqVvj/Z+ILTQ5OqqZzcLWmfAQCXcsRAk7oSFJWhY1Lle2o8N1J4SmFhGzRcGbdWfCp4fCosNBsoSvyqpOFXCvxAwWU/5is3aYpxaxrmWxvpaUOiireQEVKI0UiWxun2QKpA== 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=bkfNKy7kBz07Xahm5eQ7Vb3aISDZT2P21keDziNvtKk=; b=IpbK7Ycpr3ZLhAKSLsw0IMzOrgbvbEsYeyuRsZ0/JJeHpJha1hVLdM2hYGzEy45+WhdR1sREokKl1BNEdsDo3+WlT9hrPv/IEXwM/8PmcE9cX5bZJ6wWoCK6C6DygQTkldKZre2R61BC4XLBj+mP6Olj3ziwBRlqgka0M7jPhvpbrVLFGHSNsW7JGCr8GJeSiP8o/NEIsgIcP0Mm83WSSSOGwAfkJU23vwh4HDFFTnHeNdsISIvBz9Y7sIBkdAsrUETNF4KjFhhOwOLfdtDFDq3ltN7wMo2Q5SwUEhEo3ntGdTdX3SBgCyOOCZMpemLaF0jWLFPqc3Y4uNg/Z2xnjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=8bytes.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=bkfNKy7kBz07Xahm5eQ7Vb3aISDZT2P21keDziNvtKk=; b=WYCkB/WEGSoFA9etL9jfO3gYDY2zfodmuSajFlo3JlT6lVPzppTjr78pUnMfu/cm4ScHPVYYVBa3j9bR46rYeEyQo8ZUlsYytqN5fkHCnUGd1dQ2s5SO5FYvt2ti869uHTH4EIvnjQSrvbaBVH7Df7eC3+lMK+FFEV+e2S/RHUDtLYILi7Ps8joiCGz0V7sOpb538WrC2Um0Icm1y3DoUEjHIsEqrvrMgQiduVkhPB8Qj/mvlfYKseK4XgBQ1xxiHYSQFASzIDvoD1dS6gxH7ctdj8HxQnOonkHYng4XvlemYc61BDHoAuaH7YorBigkj3vsSBXD5fiT9/cmH6cvcQ== Received: from MW4PR04CA0068.namprd04.prod.outlook.com (2603:10b6:303:6b::13) by PH7PR12MB6659.namprd12.prod.outlook.com (2603:10b6:510:210::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32; Mon, 17 Oct 2022 23:02:46 +0000 Received: from CO1NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::87) by MW4PR04CA0068.outlook.office365.com (2603:10b6:303:6b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32 via Frontend Transport; Mon, 17 Oct 2022 23:02:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1NAM11FT029.mail.protection.outlook.com (10.13.174.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Mon, 17 Oct 2022 23:02:46 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Mon, 17 Oct 2022 16:02:39 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Mon, 17 Oct 2022 16:02:38 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Mon, 17 Oct 2022 16:02:37 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v7 5/5] iommu: Propagate return value in ->attach_dev callback functions Date: Mon, 17 Oct 2022 16:02:36 -0700 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT029:EE_|PH7PR12MB6659:EE_ X-MS-Office365-Filtering-Correlation-Id: 92a8ffc0-564a-4070-4368-08dab093b488 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vregawATSCx03eZMk9lgOypWNxewB8KbG0coHOMXIAqWbztO3WEz5xYv2Bo329LOVq9hA0P8t0LYzYRSEIAni81n8TLQtffl75RuLtu5q7dozsAgO1Nyv8pudGBhtmVGDb7Bf75b3jDoEny+aNOMrOIEHsZStMTBfOQRABgf4Gu7XrbUxReMwFYlAVBgeTl+EXJJ8d5JFPIFh1IxY94GjAb9dPUQni9sLGrTUpEFfP7fipIbO777HspG+d/451zBTXIFIdPTpY+YcW9GB2gf9pmddmKKngZzpd4kxb8OxDlL9OFG4dlRWXFxVgMCnZlx+txQjoBTgy1ynWAjjZBlF8wyqxwaelPVASKp08kivDwGOZ1oaTIkJOPfhg+oZ04t6Kdakzgmes6zt0GoIKfwYDWYRf7KpXoqsd7/ocBOq6TRUg3Rp0cBiM5T7xREWEZghuc/PmT+Dx6XcrVLGKADU6wKpZvBfkm6FhWfGVBY52ADEZUjU+D4h71btXHqsOA2G/4qSPRqKwkC391hM3NM5dnVeOe6LI9Cpb/DJ9oH/81gpv1yvCocmZyFt6WWceu+HbcCWzgiKrxgvgctLDaj0skjEqTuk4atmn9u/wDOmHWyc9byWAUd47SypFmVLOJWffR+rivBgMkqDk4xr4knMUbwv2wfnWc+ZJ3b/eIMlQ1/YkT4LLEGPNiRRYTaiOmTx+NU51xKVQmC4JnbYIONOUJOYVvulYE6fILg3nJ453zdRb+S6VWVUky37Pm77kYGWveQWf5FW503W8ayPMKFhQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(136003)(346002)(396003)(451199015)(40470700004)(46966006)(36840700001)(36756003)(82740400003)(40460700003)(356005)(7636003)(8936002)(83380400001)(5660300002)(7416002)(41300700001)(2906002)(70206006)(70586007)(4326008)(8676002)(86362001)(36860700001)(316002)(110136005)(40480700001)(336012)(54906003)(82310400005)(47076005)(426003)(186003)(7696005)(2616005)(26005)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 23:02:46.0919 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92a8ffc0-564a-4070-4368-08dab093b488 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6659 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The mtk_iommu and virtio drivers have places in the ->attach_dev callback functions that return hardcode errnos instead of the returned values, but callers of these ->attach_dv callback functions may care. Propagate them directly without the extra conversions. Reviewed-by: Kevin Tian Reviewed-by: Jean-Philippe Brucker Reviewed-by: Jason Gunthorpe Reviewed-by: Yong Wu Signed-off-by: Nicolin Chen --- drivers/iommu/mtk_iommu.c | 2 +- drivers/iommu/virtio-iommu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index f3dc2aba188e..660c5296f338 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -668,7 +668,7 @@ static int mtk_iommu_attach_device(struct iommu_domain = *domain, ret =3D mtk_iommu_domain_finalise(dom, frstdata, region_id); if (ret) { mutex_unlock(&dom->mutex); - return -ENODEV; + return ret; } dom->bank =3D &data->bank[bankid]; } diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 9e0ca757fa42..a204942f28fe 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -695,7 +695,7 @@ static int viommu_domain_finalise(struct viommu_endpoin= t *vdev, if (ret) { ida_free(&viommu->domain_ids, vdomain->id); vdomain->viommu =3D NULL; - return -EOPNOTSUPP; + return ret; } } =20 --=20 2.17.1