From patchwork Wed Sep 21 08:23:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12983368 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 812F4C32771 for ; Wed, 21 Sep 2022 08:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZUuZ+Zjpj5ybs1qjjUFFijxxk0TQIcq4LwJzlyUIp4g=; b=jM511fcIsOs4g/8EWgqVtL7rdO o5QKQFxeSWOBbcrHQrMwM36nWAGX5e04Phw4tDMfO3KW8XHjM7dljvnT6j/wUiD0lfPjyXgfyC/DU 4z15xKf0zABYg+n0vrRFk9nFMCAeZGCpGKFaL58Zp8i1vqzz9PqsjdlJIlvzYLJrVt53aBlwpMHCf 5l3i5X8GxnJ4Jfpvad9vA51nseFpxol1ADrUBJKjnn9plaC87TI3DpIwA1fwnrPvMOuZr47YH9dX8 7vRz6lonqBKDYlZa1Q5Pou5Y2yVAR2N23hfD2rO48LP2nIHMQt5gXbqoDi/VBS1Pl8YHk1XMu22hb rXag0cJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oavAa-009zYj-QW; Wed, 21 Sep 2022 08:33:24 +0000 Received: from mail-bn8nam12on2071.outbound.protection.outlook.com ([40.107.237.71] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oav19-009vHD-Lf; Wed, 21 Sep 2022 08:23:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V6K2oTMt5OZPr5xUZOfWGl819xgS0AESm9Kz+IeC96CBgsnvJkgAyx5UKU3ZFNfpG8FNDgJgyD73V3xiaTbb86zANLqYncJpThaxCEOmtd18oiTouvxAWJE3rZGCShwDgac25ZUTRHiZBMw+jQyDFHWzgtsrF+duGALkVSo5FtP40qog5i2qkOPB0B9BXAhMdfZdTCLkhWz0WdpY0GEVxqkWHhapQZ8IMuQhnKsNFyERPc68VdZjUROnALNRsx56LYgcQiKOtRe6NinOEyx4uwLRgfOOIJ/HXpNfEPzs190CBfVtCNRA8Bo5LkSK5+FD+0sJrS54iRI3mZvLPD8z/A== 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=ZUuZ+Zjpj5ybs1qjjUFFijxxk0TQIcq4LwJzlyUIp4g=; b=Un2/d8KBs+lxo5yycHGWsKHVI2BHgV8pkt87O4okfME6PHoFF4yGLPAaNp0N0WACv/IsEC3t9v8vbUPW49rEu2/rKzy9mYuWSQAP5olwYjn/0w3lV306Fl5bhrcu0Nkq8+JcUjtqKw9fmle9R5LLeixxuG9oGm+e45CBICGpKiYCBjJHZ1B/acGnlblLCoKSdRGArYtVhfCTjtJCDYioidDo+TChfEC1wkDF0wK2s097YuFXKWajWUDBKfYumTNs7TGLN3qeekw48HQFMEp+KpaUG2IG/xWzLLZGrtMr7/AI+O+ScMV9nSfJ2AGRY41JBm8CcA1oeR3BIY2VdeWRIQ== 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=ZUuZ+Zjpj5ybs1qjjUFFijxxk0TQIcq4LwJzlyUIp4g=; b=FXqUDEd10koWHazMUSx+uCMF+YL74FCOOJVNiQRoZ0C09w4UsCijoKPuRnXX3JVnzeO24CPC0Q1sGBzq0GtplNdwHfcnLuz7/MesaiL5q/LUtTqzCNkqB6/zEQ6JInnmGwKFEX5VsrFXHcib6Yc+GzjkQ2CUzMK5Re8l9JTNS6Qwqal0kcc0JvE1yZVv04KRYN+/w0iDr0n6Qm69A71dQljoMA55mx8MlK+IBCRxKXwyKLEVq7Lcf6XXKMt2yWtRTLWIi0jK74Aw0fasq7K5QZHcMZHo8dY0YRWgp6Lxpsv3abVea3y1xFVhDPAwnihTiYszf4KWo0bUYOlsBd9sBw== Received: from DM5PR07CA0062.namprd07.prod.outlook.com (2603:10b6:4:ad::27) by MN0PR12MB5883.namprd12.prod.outlook.com (2603:10b6:208:37b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.18; Wed, 21 Sep 2022 08:23:36 +0000 Received: from DS1PEPF0000B076.namprd05.prod.outlook.com (2603:10b6:4:ad:cafe::4) by DM5PR07CA0062.outlook.office365.com (2603:10b6:4:ad::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.16 via Frontend Transport; Wed, 21 Sep 2022 08:23:36 +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 DS1PEPF0000B076.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.11 via Frontend Transport; Wed, 21 Sep 2022 08:23:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Wed, 21 Sep 2022 01:23:21 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 21 Sep 2022 01:23:21 -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; Wed, 21 Sep 2022 01:23:19 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 3/6] iommu: Add return value rules to attach_dev op and APIs Date: Wed, 21 Sep 2022 01:23:16 -0700 Message-ID: <8c3dbf153b63a3002a46bab6e707c63fd8635bb8.1663744983.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: DS1PEPF0000B076:EE_|MN0PR12MB5883:EE_ X-MS-Office365-Filtering-Correlation-Id: 6dfc07d9-8227-4586-7575-08da9baa9480 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FWxKC9JyW260RPU5WFEiQ68d3Ok5wDXiJ7dFoRBsy8ug2yu6L6a2GQIuWGZU5qd/vbbsQS3HCtH5BBVHHqgw2l60z3SzoiD6/H5QH4/8yEYvNhA8Xq+MiUERYYNR6uHjIx8q1VjQc/wOYmlCD738oCIZnXBx6DayUBiIoEfA8+wjwAey5Fc1M0RWi43aMYIfijvJ506/5zQ7S0T9HF/YhyBIPi5VzjV5cOmxY+nAW/bEWibJkIpbDGB9NNUOa9WpaCLNkcFhkn6vOHUQ+zMKMGtIzyBqO2ktp/XwXaBjIg5pGGpBl28Ap/eXP+dFvGEOudZ5vROXz0Z2b/oZ8GS7glitMA2dTyk/bTAgqBt7CmSKpqH3sajpoFSoCv2/yMaMrcLGeqZWQSnpN9u6c2oADLjLMirOGZFOPfW12kBy+Vyi3WtYHu7dTsXJVmlB5jCOuHLPqh+J5IFYNuiWowx5IlelZZ10hMOT3tmjR5iKL8iOb0ORwd5c+7pP/kZAfGB3jd2juek9IYUA+tcec25vC+SC8IdoHjX2SXKvKnkYySH4QCIOlNLsJsnKE6x2voXuw+g4tTJFZ6FLKGXaYD5tyOuCY/1JtvZW9U1q2pF68jcK1Qtf54CQH9uFrUk2U8CskK2A/fB2QzTKCTl2Nz7p5TeOF9p+7xNe6bzVGa16zKkQsAR47cmOIRghvFY6bq6kdwPpZfIBJAvFgDK6F3dmG47AgtA3tyRND4YpYhYDypfjEkJnb+h65BU1FDgTPNDsCQZIA/EN5LeXhy3qGzAwr8Jp68HPrADRnso7PzIsg1NdKKQ8RFVM7pmoJrznNbbWO2a708BYIAbBlj2OLpEpEQ== 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)(40470700004)(36840700001)(46966006)(478600001)(110136005)(54906003)(316002)(41300700001)(7406005)(5660300002)(47076005)(6666004)(40460700003)(70206006)(8936002)(83380400001)(7416002)(8676002)(82310400005)(86362001)(7636003)(7696005)(4326008)(70586007)(26005)(36756003)(336012)(356005)(186003)(921005)(2906002)(426003)(40480700001)(82740400003)(36860700001)(2616005)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2022 08:23:36.2976 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6dfc07d9-8227-4586-7575-08da9baa9480 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: DS1PEPF0000B076.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5883 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_012339_747079_101E5DCD X-CRM114-Status: GOOD ( 20.87 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 22 ++++++++++++++++++++++ include/linux/iommu.h | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 3a808146b50f..1d1e32aeaae6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1975,6 +1975,17 @@ static int __iommu_attach_device(struct iommu_domain *domain, return ret; } +/** + * iommu_attach_device - Attach a device to an IOMMU domain + * @domain: IOMMU domain to attach + * @dev: Device that will be attached + * + * Returns 0 on success and error code on failure + * + * Note that EINVAL may be returned as a soft failure if the domain and device + * are incompatible due to some previous configuration of the domain, in which + * case attaching the same device to a different domain may succeed. + */ int iommu_attach_device(struct iommu_domain *domain, struct device *dev) { struct iommu_group *group; @@ -2101,6 +2112,17 @@ static int __iommu_attach_group(struct iommu_domain *domain, return ret; } +/** + * iommu_attach_group - Attach an IOMMU group to an IOMMU domain + * @domain: IOMMU domain to attach + * @group: IOMMU group that will be attached + * + * Returns 0 on success and error code on failure + * + * Note that EINVAL may be returned as a soft failure if the domain and group + * are incompatible due to some previous configuration of the domain, in which + * case attaching the same group to a different domain 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 Wed Sep 21 08:23:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12983369 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 EE2E9C32771 for ; Wed, 21 Sep 2022 08:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=s9+qEiTVW/SvsvRS/QghPXFkTHmzCWf++LylwJRai00=; b=UYL6JH4jJO3Z+AdDqv6RFG4vvO UWyOENYLJUVgqrnAoIh5hRpz60KTRBuz5XSS7TZIX72jMwGmbtpjXMkehW94FNlNWi5rkng6m07Mq iLA8xIjNPH1saGjqLAkPEaxEVeahpcXePgCmmOosUO6AFaazxDQB+GlxZs3NRVYNudUAPMLlFaO5p WATNptQY189Tk+gyIYkvk+hIuWrx6kT/pDtefg8GR5oUqTwYIN8vmpFU+ITHf3YHCur+iWnOIGms7 XkaU1Zo0wAYG4o5+lRcgRZfPwVid8MKnz+t0Hp7dJ5lq9vzgQ+GwdRRVzOrIeMltp4GFqS93LD0Nd mU8zDaBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oavAf-009zbH-Nj; Wed, 21 Sep 2022 08:33:29 +0000 Received: from mail-dm6nam11on2061.outbound.protection.outlook.com ([40.107.223.61] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oav1J-009vLB-7V; Wed, 21 Sep 2022 08:23:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BUo8YHzGqCK3BCsEepWc5awnQm50a9CSBva/eijKQs8SBLd/uBTVBx7NTzm7XtCi3po6KePRvbC2ynWs1Km5MPqQM0D7zZ0N0FPb3yk/iQX6XHPw6nV2mgkiMg12q8suDQxjsEWsy6b2qjEet8SY+hSqvIXBXAD2Xf1ysH7nB93y3kSAqHKqPnfQYqCysbEDv5uU1RmjFNtlmVoQmjEwM0pVPGXmbqp465rz3Vjz1BqbLIluqmHCVxZcG35JQRtVpZ6JhCYk/nrED2YRBtLzYUYoxn07bx8aKKnZ/ZngNQUqllN+KyrkwbmoZKxMiptfGIlu5aEx+bT0MBk8ytRl3Q== 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=s9+qEiTVW/SvsvRS/QghPXFkTHmzCWf++LylwJRai00=; b=D+SPYFZcy0olfnmFbUsBq9FfUh2QtV3ozL/IMQyI/i8jduBCJHzVW21JnfgAsKqOOCKr7E+KSySs3jvQDFVUYehXG1D+pYN7Qwi3tOVdEe/NFjD8xaxa4NNgFa9oZp/c7ZbnzmgsqNMms3yOfK5VsyU1RWc9sN2/x+1jP2YaOVzqm7ldB2Q/Ky82y04Sib157QMr3ZiLuMLF1zNOTxH61U4l8C4nrQc2Yl7uuD6KBAA7waFlkyMAe8E9O6u1rXR+204wTkq/CNImlNlJBn/mVjkakNORkQjxTH4eZ16z0RwhswTzbXpTHu0McVhoEGPy3cbcfLkiebb890wE6wFTPQ== 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=s9+qEiTVW/SvsvRS/QghPXFkTHmzCWf++LylwJRai00=; b=Thj3iSawfKBPorUXLCOcuQs6AFdweU6HWKZLD/qqA/Jxvhu8IyXg4QhM0SKya99Hvc+8fD2DbIqMUqHfD+/tKah86RjZtmNLO4Ht6lFt2mhnx3tHDmZBbtz4Vad76FAwihRO9svzWoluJtUPLjXiAH6pVQFQT1Y9inKFnbICuf1+sBaJ0LIkgxI41Ub2sZ72JXagT+NeT2KQeZerItFi661n/Ya9P3tYeE8lsnE5jRsPuqUP4pYO6etKVEeb85cmSXR/0aSAF27s0xd0GYpWUBKNzqkLxvt/DMng8UwexafNvd4SgJSAs9o2Vu9+RTQA7zUNOVJmmvuF8zIi7rOTSg== Received: from MW4PR04CA0317.namprd04.prod.outlook.com (2603:10b6:303:82::22) by SA0PR12MB4542.namprd12.prod.outlook.com (2603:10b6:806:73::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.21; Wed, 21 Sep 2022 08:23:46 +0000 Received: from CO1NAM11FT089.eop-nam11.prod.protection.outlook.com (2603:10b6:303:82:cafe::78) by MW4PR04CA0317.outlook.office365.com (2603:10b6:303:82::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.21 via Frontend Transport; Wed, 21 Sep 2022 08:23:46 +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 CO1NAM11FT089.mail.protection.outlook.com (10.13.175.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Wed, 21 Sep 2022 08:23:46 +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; Wed, 21 Sep 2022 01:23:30 -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; Wed, 21 Sep 2022 01:23:30 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Wed, 21 Sep 2022 01:23:29 -0700 From: Nicolin Chen To: , , , , , , CC: , , , , , Subject: [PATCH v4 4/6] iommu: Regulate EINVAL in ->attach_dev callback functions Date: Wed, 21 Sep 2022 01:23:28 -0700 Message-ID: <6c48822600154314778157ab7f72a7b55f5e2c65.1663744983.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: CO1NAM11FT089:EE_|SA0PR12MB4542:EE_ X-MS-Office365-Filtering-Correlation-Id: 35bd10bb-3d08-49bb-4ba6-08da9baa9a55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +FKap5FC5SM/KoxsWoYq41gcMM59OevgWYbJSmJArYbvFdJtZE2deN9wPW6HRzqPfkg50pMTkZ1XyDjiLrXV8ICWqPFe+TT+IBg11b3gfC6CbcINsEEdN/wDq5Umv6QPy2AIOvmOZVo89J0AMc59Ko8KM6cYNBGdW7GbIhsFGtlxJ/oy1xXHtVeXZorOwzqBpqm4pZUf7nzX0yOSVXjbMRmOO/3oQmSmfVMjVxw1sx7fZlB5tkKI3oEPziW2KJZ9egsXEx9uZsZ4LqCmGrVRHi6xydBarSLKcD0mmhxBAs77ttlLF3RGeMNv52o8eHXVVuOzraWtjYI1q1GzauDSM/7YmTr+YXYWHTbjsvJuJEzSRygWGRLtDK6WOY65Lx5LfOHGl01K7qyLZZJM5aBPOaAowcf4kYJ/bryiwVm7g6npuQSOXcy7K5HTe/WiPDUizmMz4uLnun+3X2Mza/9XQRi8b0jeQBEMfmsFdU/9CwzwZdaaEROimK36OgDOX76U3nmoaJ8S3Pjh8U9/xQlBUnLTCoFEsZOfCsrwoOametaz173S3mCIneiNRLDpXq5A13c9GKN1iZr7KxxN2IuGr/dR+kz7nzsvb2EUmH2wRTsMxVEmL7nfa7x43BM0NpRi21PQnVUz6LXEVTYmr1Hu32PDxjzfmeNBa0k6T32U5C85pdLZ1aVUK9Y0SZ6u4BeYRYqJH0hpkHSLWCrBARnde4ysvz+VU+81IkEGAvKYWQSUTWQHhCw9ioTlimwP6W09nq8/v4cSlwvyMfVP0cAc6A== 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)(346002)(396003)(136003)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(5660300002)(82740400003)(7416002)(36860700001)(83380400001)(47076005)(110136005)(26005)(316002)(40480700001)(54906003)(2906002)(478600001)(40460700003)(82310400005)(426003)(336012)(356005)(7636003)(186003)(2616005)(8936002)(36756003)(86362001)(41300700001)(70206006)(70586007)(8676002)(4326008)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2022 08:23:46.0810 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35bd10bb-3d08-49bb-4ba6-08da9baa9a55 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: CO1NAM11FT089.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4542 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_012349_313256_827E1CDE X-CRM114-Status: GOOD ( 16.64 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- 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 Wed Sep 21 08:23:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12983370 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 16D6CC32771 for ; Wed, 21 Sep 2022 08:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=++uoO3LawFXul3U/9kiNYyLITdupVpuzSrdELGwdTdw=; b=gAIBgpiCg+3W2z3kVXM/csf09K +N+FFpmNEEg6sgtBKn3uAAx6Z1e+qxl8kKDcYhXPkcySF+0OvVezRB1fe/8lqUfqmJxCQLoANzdLO 5aWuiu73uCl5T+oOgJWrScZ0e3nlXmAak+FiY37rj6fZG/XJKluZnczWK2WM7jyswXClBy6p1pszq f6WVW03T8xZGcMl4jdp69XDpyqqfxren1DI9RkY8J3WULS5AgYqMvsN6tbQS4Tl2RZIKDCY0WoJpa /H5B6kLDeV0wQDSOFhVASP9gHugUiuTMJ+j4HO5cvzqxjczfTtMEm8nqrvhP7K8mWGexVRwX1j2eL 6/7+lH6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oavCs-00A0X6-Af; Wed, 21 Sep 2022 08:35:46 +0000 Received: from mail-bn8nam12on2082.outbound.protection.outlook.com ([40.107.237.82] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oav1O-009vN0-Oq; Wed, 21 Sep 2022 08:23:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dpb6mvB1iMGzd8g8dohRZy+NqAiihxMuCS2xBpoWDM42oHfZbJJkxaBIV6ofwRuG2V2Z2o1ltHqIpT/oLyU/I624SVnfFzzCDdOuMMhsHqvbD/zjx3Uyj6Beq73D2TVFGetdj0pm5Pb9bk1i2CREjN6CDbsOpUIxtlgwhe4eCNz01oRbIPtBpdho0qsEeI5Bx7m+J0RCaNwB0Pndy40dNn8s+2JpyfhJ2HRq7BqAQIXCTNMoIsAsdwo1LdKPo36hn+5oLcskkYBnpM/LwC2rnJylnlrHPcJ5ig/mmZqvfnUcKgrGNsu37QyccUijCZScbuv4tIs52dXYO5Ec5wy5IA== 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=++uoO3LawFXul3U/9kiNYyLITdupVpuzSrdELGwdTdw=; b=MkNSaeYeWA79zpjV2JBJm4q4lK30FrHkujnqR9PwRF7FIPFWoFQbSfsia7QzF3zwyGGMU+XJTNo7p8pVZbzaIv0KJGnUvOhRlcqG9hkXxwG/sqIdQMh/iLKyrpJlQzjsEajdrNiEFKNqf/37I4rQRt+LrGRFVRaZAzWnNRPcs9wf1H/gZKPuhs8tsrd3up7pX4FyHQPeIkK0aryH3LO7pcwfH5qTMLNI+tmWvnQSHX3Ny89tx8GXbTuCuvy6cjjOKFFu+PQQnGJ4kXfCWQcHvnvVvaU2YM87Jw5KfNlp7DWDD+wgzftskBao4kxcn3vT2EMe/flsETOB6PsGAYChJQ== 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=++uoO3LawFXul3U/9kiNYyLITdupVpuzSrdELGwdTdw=; b=nf6kJ0ACGRu+PyHKoxvndDnmBh8f+0huwPr9dAHLzs1HflMg6wWlbRDOhQfPsnebfypw38Xh3XygPA8G8GQwvP66dy1MJ232nH+SSa27/y+wGTL1gZESq6hGhhAN9IJrXpMAJpALPz5zArHCDaC7oyd8/Ejyo8t+CnJLdN+VNjg3d4DmxMe+jCXkLjttZrDgtiLpMKvh+zjQx2U2PM1rH0qdIsSXvB1Oaz7tKYDRVYUfK1W5qW4WHbMUd9JYMDsNhgiL3q7ICUK/ca9CcjSy9ZcN8CK+kgF4VujoCJE9+wR51HOSUDr1/Al+3naqOCLUCGa1Zm8OnPmJBCMj5onCAg== Received: from DS7PR05CA0038.namprd05.prod.outlook.com (2603:10b6:8:2f::23) by SN7PR12MB7156.namprd12.prod.outlook.com (2603:10b6:806:2a7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14; Wed, 21 Sep 2022 08:23:51 +0000 Received: from DS1PEPF0000B075.namprd05.prod.outlook.com (2603:10b6:8:2f:cafe::c) by DS7PR05CA0038.outlook.office365.com (2603:10b6:8:2f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.6 via Frontend Transport; Wed, 21 Sep 2022 08:23:51 +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 DS1PEPF0000B075.mail.protection.outlook.com (10.167.17.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.11 via Frontend Transport; Wed, 21 Sep 2022 08:23:51 +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; Wed, 21 Sep 2022 01:23:43 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) 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; Wed, 21 Sep 2022 01:23:43 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Wed, 21 Sep 2022 01:23:42 -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; Wed, 21 Sep 2022 01:23:40 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 5/6] iommu: Use EINVAL for incompatible device/domain in ->attach_dev Date: Wed, 21 Sep 2022 01:23:39 -0700 Message-ID: <4469b88b4460fc230b8c394f806c134e627aa5bd.1663744983.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: DS1PEPF0000B075:EE_|SN7PR12MB7156:EE_ X-MS-Office365-Filtering-Correlation-Id: bf644beb-214b-47f1-829f-08da9baa9d59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8fDJj9PvhhCdGRkkGOg5mZ7ZS1SoiRf5gp19Uz79DMqoOo6k/p7iUK7+PB+K/Dnzn65HqCC6r0Opfiu2Z0FVh/txTIV5cmgTcbXkkJX8wxiag2NQZ/oa2awcw2xdt46WnvgWkfA3DiI/wKc8xHTMUcWWPleHkjCf6uCwroeEKS3OEdCl4vE5Gi1s7v2uwBO5j8WDfaRydi+ClH+S/RV5+QtZerDtTZU0dWCm9DL5jH+4ZN/v/sBpK8yBJHPc1BdPu4DXlyTbGxp1rFWoA+c8DMwISp0Qre9lZCib6v04lNlwPnooFgdAJ77Z1M4ntnMm9jMRCm70sOVXd9BgsoNgI6fAYipNvVlxdJlXWWdmX6vQ2sHs9OemvUeekvizfJcKS2tRxnXp5JTWJ/6QQKf3fKxJ1SOoDPK0Jjg32v3Ykg4wfRYL802uOYIyThDqZsqzwHm1FbhjQ7rMxD9d0VDgrU55OO1Tw6FqYSq+DyRJO+XNBRcomflvNBqdzDiUiEGOoo3sfA+1Fq+NgYe4LhfGZAgNYxePOcoKaF8/tEbgdXcPN2OAQ3QrOnl4vUMVt2eLZlvYc499KmG9j7tHTFX4aziFtvzB+uiNyNa1Y4vvgb+5ZjHKZ/KbFhnAurJSgQ8ZM+oRN9BLSDBS+0ynEWWarKSoZZ5bd+J+7Y4i4TwRlouOUlbX9Y+1XNen+BHQIZ7MRhF7mXRqavqJu6GnC22bLk6N86LjXeqMdFfS93wYk0k4IPT+eUIvKHwOfLUcp3tX6/2+EURC9AzwHSO5Yavsf5E2ylHxqhJW5etS8PA3ADo7upKouCgumCaRvSy+WXDsLiAAlutB9+qI1O39TWiyQAbSPxMxrtI4O9CiSxS4DPg= 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)(136003)(376002)(396003)(346002)(451199015)(40470700004)(46966006)(36840700001)(478600001)(2616005)(426003)(186003)(26005)(336012)(47076005)(7696005)(2906002)(86362001)(54906003)(40460700003)(8936002)(7406005)(7416002)(5660300002)(82310400005)(40480700001)(110136005)(36756003)(70206006)(8676002)(316002)(41300700001)(4326008)(70586007)(82740400003)(356005)(83380400001)(7636003)(921005)(36860700001)(83996005)(2101003)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2022 08:23:51.1418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf644beb-214b-47f1-829f-08da9baa9d59 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: DS1PEPF0000B075.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7156 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_012354_939589_22A563AC X-CRM114-Status: GOOD ( 18.71 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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. Signed-off-by: Nicolin Chen Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- 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 1f2cd43cf9bc..51ef42b1bd4e 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4158,19 +4158,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 Wed Sep 21 08:23:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12983371 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 9904AECAAD8 for ; Wed, 21 Sep 2022 08:36: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6FBAlYTbzpv+ZVa52FA+ghPKRnXlfos8t8xo4q6govk=; b=eCiQCqaIk2eOPwdB+dds2mwQGx aU3LHQTWyqm1Aohm9mnwDI2J7jq9ibmjD/wDER3hB9aLRdxBYnYtJmTgy59BIpf5Uzh2pbkdMR7zf gEFzWret932xXr/oQr7YSUysoSq3c3h5meJbwlEVrTV/tXDtbPmy5ZMS7Lt+CgFi0OvqnBXuMGmet H4TPwsgiiY/ZivI2qQdTU6dsMorRJzjMpzzaenJlCL5h6tq5iMY5JE0iMW7jhKVxPE/LpAlwMAEUf XPMkBFLl8jJoTXXsUhoLDhRa4ykQFoR8slrJd0R0DEiILfolHUhqxwFNMb4f64RIxH8H7wYJNMy2H ihRXrgGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oavD4-00A0bp-23; Wed, 21 Sep 2022 08:35:58 +0000 Received: from mail-mw2nam12on2051.outbound.protection.outlook.com ([40.107.244.51] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oav1a-009vSt-TW; Wed, 21 Sep 2022 08:24:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HC0OFVJtrAgbuZeZhnhxEbaxPauqqEfrQKQdM4ELZpHGnlbPBqT5kp9g0XtUdklsoDJBLKh8Xm4ukffKbtBZYGZGJrDdb6Oq5+c4m4VqcIrQ9W2D/YKMAh23e72jH89LljfMnGWBkJ6NqhEDVwXJquDgugbCbWf+3TyI7zTTx7HoDjnPAK9w4TmwwAotIRc3tx016YSaNu9BxSPxMHB9rALzzJMIY8BukLRo57Kams1oMF05RsDEAwRWuBZ/Uy9SKODNeNTjqcbgMjAHXibO5VNjYyfSo0E2712wakH6wM517wyCRJogTLKIqJOSEpHS3pwHPxdx8yrsiXyg2SdAxw== 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=6FBAlYTbzpv+ZVa52FA+ghPKRnXlfos8t8xo4q6govk=; b=PonVzlQr2l+P6urB0kbPZYLeQmPX1w2Uel2v+/o8EG34pUFGMyUZOAzo4jaMJ33qYZ2P5c68EfXUzQioEO59fPSP/cgXPmul7UmHHYtj6lafPP72G534RrmwFUGVC2AAtyKQDoxVS1kqUODxm8/ro0U7BqgnATUMfHmtA4FBR0+XVF0PDw3gciHnMAUJPpO6w3s6Eeo9aL0JOdug3JnS2jMa7EuxpZLwAjp2NDJBVbYKE35BehRkAe9wkjbAzKLQisrNg5oC8aR7k6TdDzsP7SUY5knPxXf58HKN9gS4462QGlU2hzyUeNGkXP1a3k0Sj39NEnKLX5qTaRSmZEV+/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=6FBAlYTbzpv+ZVa52FA+ghPKRnXlfos8t8xo4q6govk=; b=BG7AHOU5rhMGZlhtVVcLib+ULEZ8/QloYi8GKIbHY8XWflvJy8eXwfmp9LBHkldg1Da6r01sFGnS4xrAUKKAeAeiFL8GSoe2geuqKf4wtxCx9LOQAfYNiz6XNZWXqMyYWj/hwax7hgaTWBClfENvLLctIr33D1m5tqfO5Jm5btWAi98jAhHmggeyp4mBEupCwg1sOPZLcei6JNRfr4mejyrkAfU5cbxmr7EehyyWmU/fFYl5kZV4GlByNgwf5WewoAb+nPLx5CdFYqfyBfY8dTlS3w85CmdkVcPVs/rGYFrEqjpbwpGLuRQYWqC3A/DyMjl8Hf8dXbDfvpbqo7NRUA== Received: from DS7PR05CA0060.namprd05.prod.outlook.com (2603:10b6:8:2f::13) by DM4PR12MB6493.namprd12.prod.outlook.com (2603:10b6:8:b6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.19; Wed, 21 Sep 2022 08:24:03 +0000 Received: from DS1PEPF0000B075.namprd05.prod.outlook.com (2603:10b6:8:2f:cafe::51) by DS7PR05CA0060.outlook.office365.com (2603:10b6:8:2f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.7 via Frontend Transport; Wed, 21 Sep 2022 08:24:03 +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 DS1PEPF0000B075.mail.protection.outlook.com (10.167.17.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.11 via Frontend Transport; Wed, 21 Sep 2022 08:24:03 +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; Wed, 21 Sep 2022 01:23:54 -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; Wed, 21 Sep 2022 01:23:54 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Wed, 21 Sep 2022 01:23:53 -0700 From: Nicolin Chen To: , , , , , CC: , , , , , , Subject: [PATCH v4 6/6] iommu: Propagate return value in ->attach_dev callback functions Date: Wed, 21 Sep 2022 01:23:52 -0700 Message-ID: <821361c6f523555cd33f0982d9fa2e1e9db70bd5.1663744983.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: DS1PEPF0000B075:EE_|DM4PR12MB6493:EE_ X-MS-Office365-Filtering-Correlation-Id: 02397e8e-c7b8-4b57-a5e4-08da9baaa493 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5CijtECgqBsGDdx7DawBoRTpRSPYWLnRJYMX5CRfg5Z5iWNWXjg2FnDG6ZOUSfE2a4g8MLbpF3vwo5ocsXnOFDR1xUULlDeMRw0bNEIjpxjm7tXDwdR/qp0JP69Z8OS0o6wkFApWDum7+QmJdLc3ZNJ9fs1EWkBFWMA0K6ompawas4fpWaV3TTKbyEhM1TWE61FXKFbjNLnftBFraynsYdoV/b1pATGErCQB+hTHOdU9U+/Fu/0yFXom2P/e4moTgk0oiILB+yTWMw7H4Z15t+yhgIMf5G/R/4UYg6eyUiJIzEcfEjHW1IDNmc5WQ3aBxxYDyRFcLO+IRzDVuziioFkyJJZc2kMbMIV0PO4+Zt9SrWSgoNBGUkcbRhmBrDZjnrA7sWg99WONSVahe2c1I/18WOBiAUdns+kCdQdTHw9utDHx/5MJD+/5pkRcDHCAX1IYoSYQ82Z9y8630TjeLL0vNcsa2ne0aYcXvXxD/fQAPs0xnn3t4Ga8g0ame5bGmr6YPFDhmjj1BcPW37a3jeNSAFac5LItfNMnsf8D2ThpogwNoYCVIf53KaCrw0aQ/RqKJgRneU3jkKkXK9zuVzaTzXRF4H84dXG12Pt/q9uVw62y0qEJrUaBEJ2e5bFcTEJG7usq861g3vSVyWxtNY+S424s3DI34ecLwNsHrKHgwtI2udaVrUOMq0hYNcvg+MB5vTrfIwZRGfI2lrCbemFRKp2BdLakz7UTkRNEuZJ5dllb8gQcjuhev1jdJhrXn3EZX2ic6RCb/NN01KG/NA== 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)(36840700001)(40470700004)(82310400005)(40460700003)(86362001)(82740400003)(36756003)(356005)(478600001)(5660300002)(36860700001)(336012)(7416002)(2906002)(186003)(70206006)(4326008)(54906003)(110136005)(8676002)(70586007)(8936002)(316002)(7636003)(83380400001)(426003)(41300700001)(40480700001)(47076005)(2616005)(7696005)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2022 08:24:03.2669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02397e8e-c7b8-4b57-a5e4-08da9baaa493 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: DS1PEPF0000B075.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6493 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_012407_109021_CC0B87A5 X-CRM114-Status: GOOD ( 12.97 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=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 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; } }