From patchwork Fri Sep 23 07:17:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12986236 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2EFD2ECAAD8 for ; Fri, 23 Sep 2022 07:18:59 +0000 (UTC) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=p2G9Jk0ij+Uq711yIkTjagbOUqcf69rG49l/peI7nnI=; b=uPpVgLJBaXMe1T 1lK8vNRhWJvp+1ApVv7sASY0soE9sRRvrmrR1sMZXrpIrt7IHG2Kh8Wd2g0POZhBIWAqJ9JKYHy3n kNTOrRG0ctgc7VAGDR/Qq8hSJobk+yOHLh9RkZIEMzfxH2c5fmzvMZPtcMPJgF7ghh8GOi0ZL2oVS 0k/ebP/v0IW543IiddTEgrAg7DFa8Czw9Ugh73NCjqOiFKae04gvjJ/vMlOjaxlIB9X+kHmoHARSZ jJE/HFNhAgL2zbLPi5cvdJFk9LgB1uoLPJG1ukfcgvPr/aHtZ3EOtnbNJHG7f6JTVnYD5Dzv0O12D Z8biL85Rr8l7HG0vK9eA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcwM-002eff-Sy; Fri, 23 Sep 2022 07:17:39 +0000 Received: from mail-bn7nam10on2083.outbound.protection.outlook.com ([40.107.92.83] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcwJ-002edU-Es; Fri, 23 Sep 2022 07:17:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KOC3FMu8JYPZElD67s0rSTFLweOIqhmRGFFD5LgJx8X/1KEsH5p/jBatf3y/Le8pvHfSV3UW9L2/jQJd8Lc/BRJ/ml0vUjQytnn89JQ/nGmeIaja9KUovhnvD31AurWZGOmHRTPIUJ5lu0v0pfk9Lef02+WnQmWBoy/wxFE+HR28d6VkHtf7+Mx8HIfRYe0uCFJLNI91vBTX9Dfb34z4e98x08P+2JCNXloPRFRABd42fv9YkFC3vWT5OMygNaxtRVEDRuUP/HUeSmdFys5jwSAB8GFhQnZev+n32AsTxMIeLCL9d1NXn3tNn3DlCKDu0TNHnQJ0cuozK5jrmmRF9g== 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=nYMKpkpS9ba8j+RZsvMkycIUdHSqGCVNAQ4fLXx8euU=; b=AYjPZIIhBgh6vsgXD6dzTsZ35DCceXYXC2E29ch64a5Vt0ymttX5+44i3ZUgADdo29pWQOI91uCM8cpeX7L3tDKthKf1w3CjrF7ENwfHaASrvcNGPCSpp6pgfqCm77TzbY0t6jEo+jKcu2Gb4STU/pJPbb2pvrFIp2G9aMjOa9mEf1qxW27yyCd+7WQePM8y2vB55cXTvgEgRaQFfly9EFg8IhiFyadHM+TqNWlk6dVoyNYRnZc/weYdUlZ7fMIUd78RnV5kp8cENVowbxFcZhEXn686x6BssAFfG2LMXGOhkTTHJLaAYeCoEwFZ+8mn2oPeVvQwBTcWG7+WE6/lug== 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=nYMKpkpS9ba8j+RZsvMkycIUdHSqGCVNAQ4fLXx8euU=; b=JneMjicmwYEtRW+K794LYXAogzeyZ7Y7JtMCQHo75Q3LFpJh3mNRxId9teuEMUtGdrBfqdcMse6gcKEIdtUrDieKulrO/PNrbTQs8pvKvlmZxtnsKh76t+IAAQfIqBBbU0iCTt9VzF33/bogB/8jPpnvEcHq7dnpjCv1/aq+j8GhlKW7nEb24+V7gaXdrQyKxmuhkoLskhTYWq9C6McA8wxjPhGfmQcp2Dqh7h+dCbILRD1W0Wzg7Ok3VBFY+q5Fn/JB/zA0UiH3JwjU+L8OOCej77KbF3MayZHA0AqpxmEiT1YQzUy+IjDFNtrJzo1IlFFYgG7umQFraHVlVXgbZQ== Received: from DM5PR07CA0075.namprd07.prod.outlook.com (2603:10b6:4:ad::40) by DM4PR12MB5248.namprd12.prod.outlook.com (2603:10b6:5:39c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.20; Fri, 23 Sep 2022 07:17:31 +0000 Received: from DM6NAM11FT053.eop-nam11.prod.protection.outlook.com (2603:10b6:4:ad:cafe::35) by DM5PR07CA0075.outlook.office365.com (2603:10b6:4:ad::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.20 via Frontend Transport; Fri, 23 Sep 2022 07:17:31 +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 DM6NAM11FT053.mail.protection.outlook.com (10.13.173.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Fri, 23 Sep 2022 07:17:30 +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; Fri, 23 Sep 2022 00:17:22 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) 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; Fri, 23 Sep 2022 00:17:22 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Fri, 23 Sep 2022 00:17:20 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Fri, 23 Sep 2022 00:17:19 -0700 From: Nicolin Chen To: , , Subject: [PATCH v6 2/5] iommu: Add return value rules to attach_dev op and APIs Date: Fri, 23 Sep 2022 00:17:17 -0700 Message-ID: <3dcbf9eca9da17cec4b89d60a1691618b2236fe8.1663899032.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: DM6NAM11FT053:EE_|DM4PR12MB5248:EE_ X-MS-Office365-Filtering-Correlation-Id: 3791989c-2e35-4a12-3da0-08da9d33ada6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +YRhpJrLHF4NW2yPkjDSR++g8ybAloE659fV1doQhrNXb0Tpu+T2iNeIpBvKObx4EZlW/PrLNJ1lk+JCoBYHD5yS6GDaGbLfx7/qfb7/BPQZ5IqvyQ6RFPPpwrRuyvIOfDMeTH1YVm0h0JWuU1oRQwsO6SddP9toWMPhiLcw6uiwh0qGbXyYDGMB3yH/hM4DR9qc63UiBYdl75nbCLPSudKCMm9Il/vof3/bXKBSX0SYbs3ijzg7Itwu7jkRvmh5weVmpqGQ+A/Z6F7lp+hv8DByu+YXpKlueCa56VvF9KqWpzEA+PNfyPbHFV/ZILkJkWOdgBSh14TI+pfGKyivqthEgxwbBYDVh/K9pdoNibBFXw665KQy7SPuecDvYIKOm1GGe8Ao6lQm6xnlyvRs8dRGIlORZnRis46KDr14pXsDRnapf+bOhWoCs0Xz9rdMSSb7ZENmE0HzA+WyS0VOdSU4wWSDK6UIuR6zoBMr1kJHWUsLOQkvuh99jSygBINmXo9vBA2eIELaDYjg8YLnpTKOL4pWH1cNOFexkDRY5ygdvEeGwzcSAkIUxtNH0XVCqxkJaBzzBv0jGjhiEFS2NnuUXYJo0z/V+rXPMClmMs/UFd1f34YxnKXaj3kM94ZyYH+EuOPjUDxXKxcxVEiDDHkgq3SOo6bI/rWV5gH/WfbPbbzqvsxKRSnTOsgdap28YcoOGc+NhxvJXR38KVH9ttVk2S966AjGcpAkfCiKGOk/3YM1uWPBSHXz75euljnWSV77f9ZwzrworSWnyD4rDA== 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)(136003)(346002)(396003)(451199015)(40470700004)(36840700001)(46966006)(2906002)(7406005)(7416002)(5660300002)(54906003)(8936002)(110136005)(36756003)(8676002)(40460700003)(316002)(41300700001)(82310400005)(356005)(4326008)(70206006)(70586007)(478600001)(26005)(7696005)(83380400001)(47076005)(86362001)(7636003)(186003)(40480700001)(336012)(426003)(2616005)(36860700001)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2022 07:17:30.7186 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3791989c-2e35-4a12-3da0-08da9d33ada6 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: DM6NAM11FT053.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220923_001735_522615_5DE0A9FB X-CRM114-Status: GOOD ( 19.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quic_saipraka@quicinc.com, virtualization@lists.linux-foundation.org, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jean-philippe@linaro.org, zhang.lyra@gmail.com, jon@solid-run.com, jonathanh@nvidia.com, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jgg@nvidia.com, yangyingliang@huawei.com, orsonzhai@gmail.com, kevin.tian@intel.com, linux-arm-msm@vger.kernel.org, christophe.jaillet@wanadoo.fr, baolin.wang@linux.alibaba.com, thunder.leizhen@huawei.com, matthias.bgg@gmail.com, tglx@linutronix.de, yong.wu@mediatek.com, dwmw2@infradead.org, linux-kernel@vger.kernel.org, shameerali.kolothum.thodi@huawei.com, robdclark@gmail.com, suravee.suthikulpanit@amd.com, linux-mediatek@lists.infradead.org, quic_jjohnson@quicinc.com, baolu.lu@linux.intel.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 3a808146b50f..5f7f9605db48 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1975,6 +1975,18 @@ static int __iommu_attach_device(struct iommu_domain *domain, return ret; } +/** + * 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; @@ -2101,6 +2113,18 @@ static int __iommu_attach_group(struct iommu_domain *domain, return ret; } +/** + * 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 *group) { int ret; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ea30f00dc145..13a33b04e867 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 From patchwork Fri Sep 23 07:17:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12986237 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41071C6FA82 for ; Fri, 23 Sep 2022 07:19:40 +0000 (UTC) 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=3sfTAxx5gtOsMrm3qDWxD42J9j908QzZyYszAGxxXBU=; b=rGozLYSSjHqlLQ jMiPEVszNwahLrzZLFBLGrKxSLGm61PVj4UeR6BLVKe1avi+isg75mBp8W5oIPL9ZkyapvP3iHRx/ HRCXfcDIF3b0Ozupcl9I+gyzXcFb5n9gmuzyNMX8ZY4AW7XYj8IQ7khIGO3uJrz7gzcUpPjc01eoX GKD1I9Zj9f74oOr1iZSMvNq0e8ez8N7hsTFODsXYr9/l0GotAYJmQxdiaXSg3rVpe3fkIaALVLJQo 7tAwH/qgJq5DoN1zY7kpIqz9fKISp0srWoqYVNwPn5JPDU6N6yuYmmUnxiZ/ZOkggXAdhjx+71NXv 89sqBjc5jI4z8VK/jVaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcwn-002erQ-4c; Fri, 23 Sep 2022 07:18:05 +0000 Received: from mail-bn8nam11on2041.outbound.protection.outlook.com ([40.107.236.41] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcwe-002elR-LY; Fri, 23 Sep 2022 07:17:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GUYq5CHDmrU7fmrGGV7gfKgEA3dF/DVJSns94QCdv/tcwOd2TE50LyAqWojYipxYxc8ojQMiV6E/aDI/9ZNH+1I5/Y+tjNhtjiqPH9yIkwfveazPtTiQZTsf3zgHoDf2UjHHfhI52tmbYsY3O2zHVJy8krdFYE5lCy5q7SJhnbrh86tRBOxtXxiYu0atMa1+2F+Gd4Wvvnc7ZNrYp+/qjnHB10q0HTta/JYBe37Xyoa7TTc78nwDKVjKzwSq+aNz51c/F2cwaKg+oDWpiBEN1QsH0vEXGqHo8JWbat+wGgPkqbe7g6rgR/yvntnGVaP/lsA2bzy23oJtz777Brl+7g== 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=QB80d3+zufLsFYg0tOQC+fyM3vmYoMYu61U0bFKxbp8=; b=mKv28YLtZ9alPTT+xYnpdcaUEAlT1puBF1qtXVTQ929YtwSGFGhCrtkIgGjAeDitI5xRxc2V5N18FABY2+IwGgymGsqD2hMEdzfQunOpKZbTV26cnpUxgXf9GTegKpPOeXrFOva9AZLr9h26u5pntzJB1au/ERYgwC/6wCbNDYGnCAIn7m24ctTqSTkHywXMsSB2zV6oM48HlHA0hbqp4PdZy6rp5o4Vfoq3vVyWepRXwRcb9psMiIGxgolCI38MBsxaufqW9iueFIIR1ST8h+eEEt/FrOA2H/N97huur8819M3lCIXvtj6UhqINX5o592nEl8R2BxiYx+qDe//2kQ== 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=QB80d3+zufLsFYg0tOQC+fyM3vmYoMYu61U0bFKxbp8=; b=cMDu1/K5Wmymh0JbJQeVePLF6hA6hk/iGDKoErb0/CVBCTp7v8nnInPWqKTHkO83EnCYqRI9kDR0n2mKB5a/LkZDwWqKse45jZrguApdHQ+j3wjRBZZ8tbwmgQ9RI+2yZZjRSn1F22NwzrtLBXQjm6PcsgH9eAZdX92u4ciPwhwVIyt043Xf0uwA2izsrWSVYqnYYdj2YRBHlF57NW00tvkZdXCEHt4CiVJ/1vp5KisKhL0LRez3L90W2rgVpf98L9rw+9RVP2hPyWjGojOa/tS8lMQDA7G9y3SgLCF2CNBuUy4qxN6ynv/MaauBc2YRCqkm8nNivnfxW+EWY+caDw== Received: from DS7PR05CA0042.namprd05.prod.outlook.com (2603:10b6:8:2f::29) by IA0PR12MB7601.namprd12.prod.outlook.com (2603:10b6:208:43b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.15; Fri, 23 Sep 2022 07:17:50 +0000 Received: from DM6NAM11FT087.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2f:cafe::44) by DS7PR05CA0042.outlook.office365.com (2603:10b6:8:2f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.7 via Frontend Transport; Fri, 23 Sep 2022 07:17:50 +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 DM6NAM11FT087.mail.protection.outlook.com (10.13.172.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Fri, 23 Sep 2022 07:17:50 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Fri, 23 Sep 2022 00:17:44 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Fri, 23 Sep 2022 00:17:43 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Fri, 23 Sep 2022 00:17:42 -0700 From: Nicolin Chen To: , , , , , , CC: , , , , , Subject: [PATCH v6 3/5] iommu: Regulate EINVAL in ->attach_dev callback functions Date: Fri, 23 Sep 2022 00:17:41 -0700 Message-ID: <03bbdfd598344f2b28674cb9a739e29049fb3cec.1663899032.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: DM6NAM11FT087:EE_|IA0PR12MB7601:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ce0af2d-ab9b-400a-340a-08da9d33b93f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9MpLkg/dqQ0pJPE5JFeTg/ISuPgY2S0fWOzthrYR6MwBFLjfwAWgUZUKiuyu8YsFi4JTCmumA5La2X16l9zpaxE/4FKe5WSge8ANJIkSMqZpEFnEmU2NnPX7PAJYkQUqUOVDVMGOHafMWjLoUuMZN2is6DLYEAOIDrtz9yS3hM3+Y924KDO3F539FgoQdEGcvoJaOBDLrtrGvxvg3zxO1hvujaeVG7B4S3RNnpD8OabaTF7ZIdfO4u81mHYEnPB5kHZFCdm0oWiQzAS+saJyjUiHKOiB6kLiTbOtss1FcdwOeU36LxC23w+Qe/vwjEQc9QRkFScsWSXMwJMsBs9/AZQKKHVkmViBqus+1n0/30OJtJOFhl34jMJHmLdgN7vAwDOz9iJMmsWS+UIoHgJetm22Nq7LywKfvSu85tVrfJpcYGF8rhU7BDBX4pS8+3BK2FogZIQbeVMfaCAzuENClKTFsCGaLuYZGuxK1//GUSTchuuPbovcKbdcLg9BwCSIQScnHH+TGw9VDA5PfqlpCL1LKbLHUQfpBKMeEB64JqWOkcboT8YGIO4rmv7V1KqkeAGDIAf3Mat8agtq7MS5FUPz3GJtcRoyTtCnFn9zjlFMV1LAilSMkyuhncCw/vOSkEc1zFIJ3Lik4tVjDwNLfoSLkis4E2ra+Bu1kQ6Swnc2C2sNsQY8PeF7l5sWxtAs6zYQP7a7C3qZqUx4Uwicqrhglkt+YuSAuGxUv7f42pCCNJp3jYlUX53llI/mIRImvIiBbdm5BuOCwRJSHUJAzg== 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)(136003)(396003)(376002)(346002)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(110136005)(70206006)(4326008)(316002)(82740400003)(70586007)(356005)(7636003)(8676002)(47076005)(54906003)(426003)(2616005)(186003)(82310400005)(5660300002)(478600001)(36860700001)(7696005)(336012)(36756003)(86362001)(83380400001)(40480700001)(26005)(2906002)(41300700001)(7416002)(8936002)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2022 07:17:50.1760 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4ce0af2d-ab9b-400a-340a-08da9d33b93f 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: DM6NAM11FT087.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7601 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220923_001756_781718_3F341353 X-CRM114-Status: GOOD ( 15.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = omi; } else if (~omi != 0) { pr_debug("bad operation mapping index: %d\n", omi); - return -EINVAL; + return -ENODEV; } /* configure stash id */ diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c index 011f9ab7f743..b4a1c0f79c3e 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 = 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; } 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] >= PAACE_NUMBER_ENTRIES) { pr_debug("Invalid liodn %d, attach device failed for %pOF\n", liodn[i], dev->of_node); - ret = -EINVAL; + ret = -ENODEV; break; } diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index c5e7e8b020a5..aff1a9caa496 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) might_sleep(); info = 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; pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL); if (!pasid_table) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 7e363b1f24df..be1a7d1cc630 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -607,7 +607,7 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, dom->iop = 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; } /* Update our support page sizes bitmap */ diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index d9cf2820c02e..447e40d55918 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, odomain->num_iommus = omap_iommu_count(dev); if (!odomain->num_iommus) - return -EINVAL; + return -ENODEV; odomain->iommus = kcalloc(odomain->num_iommus, sizeof(*iommu), GFP_ATOMIC); @@ -1464,7 +1464,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) if (!arch_data || !arch_data->iommu_dev) { dev_err(dev, "device doesn't have an associated iommu\n"); - return -EINVAL; + return -ENODEV; } spin_lock(&omap_domain->lock); diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 80151176ba12..4c652773fd6c 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -669,7 +669,7 @@ static int viommu_domain_finalise(struct viommu_endpoint *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; } ret = ida_alloc_range(&viommu->domain_ids, viommu->first_domain, From patchwork Fri Sep 23 07:18:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12986238 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D90BEECAAD8 for ; Fri, 23 Sep 2022 07:20:06 +0000 (UTC) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HLhYZQWFYnqZuqO8i5FrVdwF7wf7xAFbGU32S8YoUeo=; b=EmGDTXECKtpzSj O/B6XYU3tWEf5wAiBzc/dh31vu3pH+up1WL5fbtM3enPCZXW0Udx7Ao2WHL3vT7DD/Ly7b5uSUFLL R7xHoemWMCRoHMIhbXi2se2RRXSFj/rCBGGmB/srFO/rcIqy5x7V0nleCdGSjzG+5y6eWpPOETrZ1 SZEHu3+9FExXCExoHBSc7oegWgETVOl6M2QNJps9FTqe1DFT/iw9SfAnRHy6KUGNrD30FQtUA8C6d uBQ/H4q+GEQwTAB5n9zrnSX7PGBMnLvZQH9q2BIdRvF538Mm6p2J/fwDJui1/aWrR6JB0qfia6d6v BnNu76rpEUdIbdfoEqtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcxK-002f9C-4x; Fri, 23 Sep 2022 07:18:39 +0000 Received: from mail-dm6nam12on2058.outbound.protection.outlook.com ([40.107.243.58] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcxA-002f3R-GO; Fri, 23 Sep 2022 07:18:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SJHxjxjKBKoRELTVeMFT8rz6fyMxeg0I9A+Tq6+hRGH0dT3OYzVwoGa/Rrkq+Um/Wk+aTH3pZy2QgDmhgANNIkDUFM3qov/zj3kpL3iLLh5Von/3piABQxo9NmVD9eD+NDVh+30M5jXaC9+WrYFEnfh0Xebxqi5QPlEsUaceG/c5Y4lLmrfhqRJr3aQBqe2f9bwfyi2u/TuuD+HiWZ8wSMPmDd2dO4NAWmpavib5YnGnw69GL19rEPZ+lhe9jDbNUwR6ZtmVD39Pim7e6F3Pl5IYgx4kdpK0w0zuWmll2cfQYrUuJynwdj0qEdRDrBzPzsMc7sXg8y0wBaCxzxDuLg== 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=jRiBvP68Uab8yBr834AJHBWnp7688abiJFpvB0PALhE=; b=eh+BtQ9mdg+CefVCZTg8a1Gw1e8vbNGHm7W1fLE6RCVx5G1cQ+k0pZ9ZbU+NUdUiR7+/5IClab9IJ/04t4RyDrXCRdv3zSQhB7eSlJPl6zN6W+ZWnlWGEBVmN9iBs36kGnQAC/EmtOuAaJzHRSiQ2mCSNxkEsFNu1vHGE3wBRLu7hk27ZkVQ+pH5Q0fjORcr4gmzaKcbI4hkI6zOPWLK8AyU/KfmnoZUquLsvu5MaJGaKUz72WU4xyMUI9TwXbIn1+WyoITyUVinnQRXigm1rMUkO9SMtPw+O7kfU1X3jwabLvdXdagU8dV9R3bdqwlyrVirF8LJKPuHEcSE11cADg== 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=jRiBvP68Uab8yBr834AJHBWnp7688abiJFpvB0PALhE=; b=ddced6HLVUfSinVqiO40HgCkEB9kviLcq0PDzTga0wEkWpsiwIISwqBrvzLPDpokpAsNfasXa3Pt/wlVHCVA0a14rPfhDljCNPVADk0UgRmM/cU5dn1QxuWgnR91VbC+k5PbhpWjiNrqvf23X6CbG88K8d3cAmbm4DhbeAX0VADRT6KibTaz5avRdMkA+To8CwCC5lD+J3NPiZjkSlLsEVqmX/U1Kr8ViTvb4+McUHUVsF8U8c+z0SlwuBHiQu31JbyjYd4emPFXLne2A0G9wBkeQySF0YZKvrVAJen6CV480zj7C0g7QYJVDBBtObr/wU9VsSkRKLsT9txTvm9cIw== Received: from DM6PR11CA0001.namprd11.prod.outlook.com (2603:10b6:5:190::14) by SA1PR12MB6679.namprd12.prod.outlook.com (2603:10b6:806:252::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.20; Fri, 23 Sep 2022 07:18:24 +0000 Received: from DM6NAM11FT020.eop-nam11.prod.protection.outlook.com (2603:10b6:5:190:cafe::90) by DM6PR11CA0001.outlook.office365.com (2603:10b6:5:190::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.20 via Frontend Transport; Fri, 23 Sep 2022 07:18:24 +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 DM6NAM11FT020.mail.protection.outlook.com (10.13.172.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Fri, 23 Sep 2022 07:18:24 +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; Fri, 23 Sep 2022 00:18:14 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) 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; Fri, 23 Sep 2022 00:18:14 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Fri, 23 Sep 2022 00:18:13 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Fri, 23 Sep 2022 00:18:12 -0700 From: Nicolin Chen To: , , Subject: [PATCH v6 4/5] iommu: Use EINVAL for incompatible device/domain in ->attach_dev Date: Fri, 23 Sep 2022 00:18:10 -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: DM6NAM11FT020:EE_|SA1PR12MB6679:EE_ X-MS-Office365-Filtering-Correlation-Id: f07b0c43-4fed-4490-567b-08da9d33cd78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TFv8VhofpgAza50wADAwEemhUCLV3G7Ual01bikEGRRo4mexO6/bsHdl3QUSdr5eblt6zY+UD5zcn5g8VKvSuSK1Xa7RnZLPo54cQKFqdbzE3O0JavpAzjQkj5paOFZtfDlLxr/aNXADfls+zEmofwuThR7mh8tE5BeMLJp0X/sO0ePQ9+Gj4gyWCRP0+j1mpdjfuUPUDbMAkhE0mohVgvKDgtrqEdW4f8IBIu5no3MvK05JsWhQJsWrlKdQDICkEOM3SVQSnwvYjuVlzw+6epIM5iYhD8yxeP/cKBB+WKy5ZJzK0eDXFgLdB1Ycgyivwpk+dAVeO8IbcZ1oAMr8E7jYJ08mVEiRfo2bTaL44xw0HnXraxPA+8rFK3kpNBiqut9trUfUiwUIj7J7YbFQQSr7ORArp8dglWUodyblwTwPcHHXo+PVJCwVlg+CN87RWYwLQlTDyHV41N7465NklaLK0313LkNoANAxMpi6BoH7K8NnRn//zL4m4xtow059soixUWzYlNjSidKXhmMsa3HF5J83uQTB3IHKqDwXaWMEeWVmzeZ05Wg8IymPUWscD2hv29RGozGBXJa30+ZZZUKkMBBKAZfEpM59tzxp9VTNjrW72kyDX021FbFhVb3mKPE7I7rzyciE4yY616X7FmCfaHVN/Ui+4OfPOYRPivnndrFBOTGOWBwSJQPPL2GdxkGqhWl0yfm35tCGzxmP588wy+5buvGIUoQhbYxNeVWefsWVmTs/im4SFTXz99Z+K2mpgIS86vdAkkuwzkrGP9EFMiE2RA/XU+/reU/gZxg= 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)(346002)(376002)(396003)(136003)(39860400002)(451199015)(46966006)(36840700001)(40470700004)(356005)(7636003)(110136005)(316002)(54906003)(82740400003)(70586007)(70206006)(186003)(2906002)(2616005)(478600001)(47076005)(4326008)(41300700001)(8676002)(26005)(40480700001)(82310400005)(7416002)(5660300002)(86362001)(36860700001)(336012)(426003)(36756003)(7696005)(83380400001)(40460700003)(8936002)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2022 07:18:24.1049 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f07b0c43-4fed-4490-567b-08da9d33cd78 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: DM6NAM11FT020.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6679 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220923_001828_655232_0ED9A6E9 X-CRM114-Status: GOOD ( 17.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: quic_saipraka@quicinc.com, virtualization@lists.linux-foundation.org, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jean-philippe@linaro.org, zhang.lyra@gmail.com, jon@solid-run.com, jonathanh@nvidia.com, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jgg@nvidia.com, yangyingliang@huawei.com, orsonzhai@gmail.com, kevin.tian@intel.com, linux-arm-msm@vger.kernel.org, christophe.jaillet@wanadoo.fr, baolin.wang@linux.alibaba.com, thunder.leizhen@huawei.com, matthias.bgg@gmail.com, tglx@linutronix.de, yong.wu@mediatek.com, linux-kernel@vger.kernel.org, shameerali.kolothum.thodi@huawei.com, robdclark@gmail.com, suravee.suthikulpanit@amd.com, linux-mediatek@lists.infradead.org, dwmw2@infradead.org, baolu.lu@linux.intel.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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/arm/arm-smmu-v3/arm-smmu-v3.c index d32b02336411..f96f8aad8280 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2429,23 +2429,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) goto out_unlock; } } else if (smmu_domain->smmu != smmu) { - dev_err(dev, - "cannot attach to SMMU %s (upstream of %s)\n", - dev_name(smmu_domain->smmu->dev), - dev_name(smmu->dev)); - ret = -ENXIO; + ret = -EINVAL; goto out_unlock; } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 && master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) { - dev_err(dev, - "cannot attach to incompatible domain (%u SSID bits != %u)\n", - smmu_domain->s1_cfg.s1cdmax, master->ssid_bits); ret = -EINVAL; goto out_unlock; } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 && smmu_domain->stall_enabled != master->stall_enabled) { - dev_err(dev, "cannot attach to stall-%s domain\n", - smmu_domain->stall_enabled ? "enabled" : "disabled"); ret = -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 dfa82df00342..dbd12da31707 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1167,9 +1167,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) * different SMMUs. */ if (smmu_domain->smmu != 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 = -EINVAL; goto rpm_put; } diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 17235116d3bb..37c5ddc212c1 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 != 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 != qcom_iommu) return -EINVAL; - } return 0; } diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 31bc50e538a3..b1788b3d3b2d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4181,19 +4181,15 @@ static int prepare_domain_attach_device(struct iommu_domain *domain, return -ENODEV; if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) - return -EOPNOTSUPP; + return -EINVAL; /* check if this iommu agaw is sufficient for max mapped address */ addr_width = agaw_to_width(iommu->agaw); if (addr_width > cap_mgaw(iommu->cap)) addr_width = cap_mgaw(iommu->cap); - 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 = addr_width; /* diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 1d42084d0276..f5217a4cb9b3 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 = -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 447e40d55918..be12f49140c7 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, struct 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 = -EBUSY; + ret = -EINVAL; goto out; } diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 511959c8a14d..945576039c9e 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_domain *domain, struct sprd_iommu_domain *dom = to_sprd_domain(domain); size_t pgt_size = sprd_iommu_pgt_size(domain); - if (dom->sdev) { - pr_err("There's already a device attached to this domain.\n"); + if (dom->sdev) return -EINVAL; - } dom->pgt_va = 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 *domain, spin_lock(&gart->dom_lock); if (gart->active_domain && gart->active_domain != domain) { - ret = -EBUSY; + ret = -EINVAL; } else if (dev_iommu_priv_get(dev) != domain) { dev_iommu_priv_set(dev, domain); gart->active_domain = domain; diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 4c652773fd6c..87128266b6e3 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -733,8 +733,7 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) */ ret = viommu_domain_finalise(vdev, domain); } else if (vdomain->viommu != vdev->viommu) { - dev_err(dev, "cannot attach to foreign vIOMMU\n"); - ret = -EXDEV; + ret = -EINVAL; } mutex_unlock(&vdomain->mutex); From patchwork Fri Sep 23 07:18:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12986239 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB439ECAAD8 for ; Fri, 23 Sep 2022 07:21:09 +0000 (UTC) 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=00NnLbcfu/ARN93ugmfdyntQ9G5JNj1QZoee8NQZeDQ=; b=KoECP14I2qzK3y NwxlHLsKJeUxuXmmpxQybS580qIGH7Dc0ZxH1vxIB3sGumMLikeHWnxva1Bk4Z5fKQkLs5sV1nU8O rIG72iCL43hjyY+lfmy3wsv6Oose+IgxKUnOsud1avNscNlskhUYHtIiuD2D+qdJ4pt2OawBWOXAX YC1FasK8HcsI98rTmA5U+0bjX+5mMBbHe1i7OfADiClah0qoq4KF4E1zqplBRvw9EBuURcyQe7727 IQCjebY/x5sHd+ZfLXir7M2CNXLn+uewqlqmgR99yqkaFWojTitwVk/q6wxG2Re0WUtq0MIR13JT1 FHpzruoGXb9OEe5conzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcyK-002fei-BR; Fri, 23 Sep 2022 07:19:41 +0000 Received: from mail-dm6nam11on2046.outbound.protection.outlook.com ([40.107.223.46] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1obcxd-002fHs-DX; Fri, 23 Sep 2022 07:18:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bGXNqFGhOknuEPMYgKZZXbyaVgtUxmZWafkMktFCke7GVZ8VsRzHv0bOYyG/42LTWNAp+TXSqtG+mOE5wjuQbFWrZj7SAHMOwKFp27w2qGGPIH14uMPSNQoYKeVDN+NiHsC/LDh6eT3bSc8olprs03GCmF1iCUXxNPZ4MlnrNVrIfm2yNhYsnVPpIxc5mcYtsyo0k0fGAgQwVDmAo3JShoE8cnTsSr4u2xmix/MYEeZ8RAIeXoaxwYNhEko8LSr5gOy+eoGb4Txb3lNe6FBj6g58gytfGlfE7ti8hkyEYmNUF7X9ueaS9VGiv8iRlI6xUNmdyl4lAlZlPfV0dtQBqQ== 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=KbfMwAYwJ3pKjs2uyFVOf7om7FtU8aOpQYMWbXrhj4w=; b=IElEDt8NTAO5PQPDg0zHFocjyr2eD6KQmabKMKbW18yLfazqE91A2NC9vugnifktVDTqEtnN7zL/XEiKSnaDsNGSwYeO8jDE3VnptXhGQGcvrc7WtfkJHRxY6d2QbO9fGbmln3t6CZa9sTR1+vYMlNRnYNy+z4mj7NwZ93HiCl7Ap/5BXEdKsVaB2WkArse4n498fZjPeL+zNXVTN5PWyaJ16G1uyC6LX7VU/AsM4bkXf+PFzRdQnvblhgAD/c7IpDYvmd0c0SYYxiiUb02yy3fbqbFdj7tarsyWuLmiNzyLek94nwNCUhQgOemQHjCOnteJ1EeGLcjJPJv3fgGZpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=mediatek.com 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=KbfMwAYwJ3pKjs2uyFVOf7om7FtU8aOpQYMWbXrhj4w=; b=tCR+kIa8CMMHmUOLeF+K4mcCoAScEPHbbLrjhUB+40XGFwFNySXIXXHjwYc5zxjDwmbqPZgN0Kd70YqUkpNfQC2P8P+EYTRw9pjup5b8482awAUBEUSiKCfH4AkhD66MIsZm7A0F3hUOJZKFvAp0HgyzzmMt4C1+dSMmmGXAwwHEmzVWZf69TZxeF3GcqerK49UBGhdnNaoAwAXzoXPfOSR1lPo6J54sj+tjxreWbky7kpV7tpNuqDwjR2uBxE5ECArHfLJRg1d7VOcN8vp/Rsoab0Qz0F52/4bXM0aTc1bf4BsuquozqLt1ABnO9slUMvVXQ2GRmnsi/IL/S3Nyrg== Received: from DS7PR03CA0304.namprd03.prod.outlook.com (2603:10b6:8:2b::16) by CH0PR12MB5170.namprd12.prod.outlook.com (2603:10b6:610:b9::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.20; Fri, 23 Sep 2022 07:18:49 +0000 Received: from DM6NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2b:cafe::c2) by DS7PR03CA0304.outlook.office365.com (2603:10b6:8:2b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Fri, 23 Sep 2022 07:18:48 +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 DM6NAM11FT073.mail.protection.outlook.com (10.13.173.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Fri, 23 Sep 2022 07:18:48 +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; Fri, 23 Sep 2022 00:18:30 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Fri, 23 Sep 2022 00:18:30 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Fri, 23 Sep 2022 00:18:29 -0700 From: Nicolin Chen To: , , , , , CC: , , , , , , Subject: [PATCH v6 5/5] iommu: Propagate return value in ->attach_dev callback functions Date: Fri, 23 Sep 2022 00:18:27 -0700 Message-ID: <3b5b29b735dc5e5f4a047262f91636dbee4af981.1663899032.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: DM6NAM11FT073:EE_|CH0PR12MB5170:EE_ X-MS-Office365-Filtering-Correlation-Id: e4c66298-5b29-4967-334e-08da9d33dbde X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u0o94C4QJWK1wE/DNwRbXQQk9FZ0B+3yBD1MxZ/1y436hxssO2xLRBMgF90byYJ1uqaMdxnpbp38n8WLDQ0KdQRmkXDRonwm/v4iHS0U4EP0UYwnjxFRO3dX0NJlZJpQuE7D4M16TJSN73h/Dnf5M6eN+rbY7Y03VMVikAYxkACfOiFZR0qCtRFEzkM8vDGo2jLqsCAd8WzBd93ulzcbjSPBhvrGSD6ElyuZaOrSEYTJOouJiN1vjlg1xL4bwUpqWxRPt1tQtSABhohdaRZ8uh/7oe6o2GDMw6IG832ltDYjoP2IFIEokVwIt3k1wwPa47Jii6Voj5NviBgBc+Lx8Hkwul7wrRLsE8GreSZSPlKIzyNMgj+BEMGpChivPPYtlDiWksHbOCcFl377W/HMUK2Pt5EsWj6VpsKt1taUVAfMFplYB8vww0e/5340yK99aANrKMjXohHzxvZhuopE14rkzAaRIUcqGY5/aL7ZdxW1GI9zCu8f+9finVLrIN+oCDGGQnsR4woS63fVqolhJTOY6kHIb4/l45QDUZtVzGw2MbMs/j7Z+xQLOud3lYIQI2TVvXY8Px2faIrEBn83wPHEk3qJmTH1skG7KPfsJ4XVnzP+2VI/klDZe7PcMG4DzsGqgMGb4v6zDIREGT8AdDGCKDAMBODIla0id6D3dsactLM5nWqIwNXVwcbsCMkObGiG/1ONag75TaeoYaufyCfUeYrCCgWUrAu2ppICOvtKOebLQEHJEYWkVL7nbxai0CDYk0V1lLuwXI02QIlAEg== 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)(346002)(39860400002)(396003)(376002)(136003)(451199015)(40470700004)(36840700001)(46966006)(110136005)(426003)(47076005)(2616005)(40480700001)(336012)(186003)(86362001)(316002)(54906003)(83380400001)(5660300002)(7416002)(4326008)(40460700003)(8676002)(7696005)(8936002)(26005)(82740400003)(41300700001)(36756003)(70586007)(70206006)(2906002)(36860700001)(356005)(82310400005)(7636003)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2022 07:18:48.2449 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e4c66298-5b29-4967-334e-08da9d33dbde 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: DM6NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5170 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220923_001857_489176_F3708EB4 X-CRM114-Status: GOOD ( 11.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 be1a7d1cc630..c30dc8f81778 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -666,7 +666,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, ret = mtk_iommu_domain_finalise(dom, frstdata, region_id); if (ret) { mutex_unlock(&dom->mutex); - return -ENODEV; + return ret; } dom->bank = &data->bank[bankid]; } diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 87128266b6e3..35de7b433b17 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -696,7 +696,7 @@ static int viommu_domain_finalise(struct viommu_endpoint *vdev, if (ret) { ida_free(&viommu->domain_ids, vdomain->id); vdomain->viommu = NULL; - return -EOPNOTSUPP; + return ret; } }