From nobody Thu Nov 14 08:36:43 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89E77ECAAD3 for ; Thu, 15 Sep 2022 07:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230130AbiIOH4g (ORCPT ); Thu, 15 Sep 2022 03:56:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiIOH4b (ORCPT ); Thu, 15 Sep 2022 03:56:31 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2063.outbound.protection.outlook.com [40.107.94.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E163D97509; Thu, 15 Sep 2022 00:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=At37551KHQmkLTeKmsASpqND/+tLqP2VgQtR4ayf2MPoB0AT6GnWZJOIv3mG++Oo6owVjKwkwAwpTmKxa2ahP4iuOrB+eXZY+73fWoDt/ojybCeHveetBfz3NmS98KSvzB4rzMqODGL+v/Y9spE4GKV+UKNhepN21Tb8yXspbQVgNbYZhZKZLs5+XWYK8bo10xu0F2Ua6lFaALh7WOVK0/h9jH4nLux+c6RFDdMKaoZ9W7NXls2yGckcN4KV+a4m6n/O67Uco6FGZDuCkbSHaHm9/gsdT8qXPW61VLp6Tjoa/jUqEd07DnUIjX4WtwhnzDS1w22bEERBKtt/HmCPIA== 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=unWC6su4TYXmqDEOlDuaRyUpogsCCTes7oHL6iBr7Os=; b=GWg7hdPMQguMPxR2kxYIzibJVGKA7hVNxLyGpKcSW5Ro/9rWO+s1fGvVn1PbVhTx367zG+8ZkyPjCUU5768f8SKhp+efRy5EWNYbJlIljOaNR4p8nAqHBX8H8S+cSU3g+ba62udCOUOtbRiT5hsdK2SQ9aN/Wxt42msU3mDWgLLFxL20T+6bAq5dVc3omIFhwyPSWmznLUzckvcBdzPurjI+J/v5IyR1GyzzbHUB0vyzLfYybIvGnKpcKiFW9rQA+8LvDFYrHAN/kjOpowA+Haw0GsEFDBoZGFS65zWva1cRjojUtWrUN3xYEZ8qQRIoSQ7MbowfYNm4U8Z451H2rg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.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=unWC6su4TYXmqDEOlDuaRyUpogsCCTes7oHL6iBr7Os=; b=GnmFA2mSznbjKYM85BUNOMIiZId9XG+Y+jF7dXu0UKhG8nyUlBVjjTXt7AnNeNn2JuDEpM5NOYzU6vqkXVup2g32cpjS+Nhd2wqv2ElyfIeb327V3fusZMyatsc4Q1Q1BLlOPFpIIX8kRuNU2pC0YRC4LlXqjJn3r7TGXbVRavIx1xmDuUVNj/PGkrbkbVVgAO1hA1IzPRNvf/ykXm68pCcp21FMvxosRk9SgDltyla7NQp/XnHK8QcRsNUJ4oN535NFUAA4toAI4r8iKDiCB3GqqquXHY5pTm7jZsXgJQPgaDhOWA7Enf51d4KgpwzPVPQC7P001+pNYXcCjR8bdg== Received: from DM6PR10CA0020.namprd10.prod.outlook.com (2603:10b6:5:60::33) by SA0PR12MB4527.namprd12.prod.outlook.com (2603:10b6:806:73::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.14; Thu, 15 Sep 2022 07:56:22 +0000 Received: from DM6NAM11FT062.eop-nam11.prod.protection.outlook.com (2603:10b6:5:60:cafe::1d) by DM6PR10CA0020.outlook.office365.com (2603:10b6:5:60::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.15 via Frontend Transport; Thu, 15 Sep 2022 07:56:22 +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 DM6NAM11FT062.mail.protection.outlook.com (10.13.173.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Thu, 15 Sep 2022 07:56:22 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Thu, 15 Sep 2022 00:56:15 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 15 Sep 2022 00:56:15 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 15 Sep 2022 00:56:14 -0700 From: Nicolin Chen To: , , , , , , CC: , , , , Subject: [PATCH v3 1/6] iommu/msm: Add missing __disable_clocks calls Date: Thu, 15 Sep 2022 00:56:08 -0700 Message-ID: <031c4ec032025a299d72665118d58dd48aa936ac.1663227492.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: DM6NAM11FT062:EE_|SA0PR12MB4527:EE_ X-MS-Office365-Filtering-Correlation-Id: fc126afe-969f-4e97-b831-08da96efc848 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fa00DKS/Oj6/RioFyY8K171XJoFv6l42ykQhyi0Lxu2qmAdWEGgWwALZJM8RYRlRlidSmKqL6GqZKr6+FdrPDTos7SaGCAqTlB0W+/XgT49F3xDXMDBe5omB22dUUJzczVcT9jqIdS9RMPFgd0OeyhcpigizVDO1/gDbjTIB31gUB6KlJEzQ7BfGF51oz4ISxx5fFrZz2Tc50fMPxVkd0EnVa3OS9g27MwRyndlLkf/aEpHbsay+UGephBt4XPhidybuGsc2LHrZvowuP2BvtCFbdheYwPcPhQ84PcmtfNQ/vxfy+BY0OlKAZKb3thOtCTrQyWDwIXJ4YMgE+LwSIPAzo5cQARVsqmtomUNDB/6lQn9tmFUcE/KstEJqscr8qCQ/+cGQIauVnqo1geSWrCfeKYX3Ns72f65dByJiEZ5PKLkxvzlupBH/EM/HHne6ZB9PkZGdhgAFHRPdertAgt/dGCCqCLI2KzsWiUr6253I+mj/sSf3hwUUwFrS1HCUx6FtsdXsmTafucInN9AXBcA0rjBvA0+Y1XJXElSUCFrxe3dotd0fDwpM5uJHTnYgKynIzgkxvBFQR/KgXLDAS3XHnxN46CDZQQdfS9TGC0fi5HhE+5p13qzrdGaAFdSAaRGPh+Gs04RtbAmUBmo4D1RvKEIJH+ooRR04/2bbkEW615ICfOqdek7KMoTUH58j2VfoiC3wjYbFGCpG0YH2sqFiCGPjNGe7ekpRVP6cR0JBi294YRR52WUtO68k0tstSTM4c8+1uGiUh6WLjpvdpw== 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)(396003)(136003)(39860400002)(346002)(451199015)(40470700004)(46966006)(36840700001)(6666004)(47076005)(41300700001)(478600001)(2616005)(426003)(186003)(336012)(83380400001)(26005)(7696005)(2906002)(7416002)(40460700003)(70586007)(316002)(70206006)(40480700001)(82310400005)(4326008)(5660300002)(110136005)(54906003)(8936002)(8676002)(86362001)(7636003)(356005)(36860700001)(82740400003)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 07:56:22.6499 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc126afe-969f-4e97-b831-08da96efc848 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: DM6NAM11FT062.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4527 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clock is not symmetrically disabled in the error-out routines. Fixes: 109bd48ea2e1 ("iommu/msm: Add DT adaptation") Cc: stable@vger.kernel.org Cc: Sricharan R Cc: Andy Gross Cc: Bjorn Andersson Cc: Konrad Dybcio Signed-off-by: Nicolin Chen --- drivers/iommu/msm_iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 6a24aa804ea3..a7d41ba4a47b 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -418,6 +418,7 @@ static int msm_iommu_attach_dev(struct iommu_domain *do= main, struct device *dev) list_for_each_entry(master, &iommu->ctx_list, list) { if (master->num) { dev_err(dev, "domain already attached"); + __disable_clocks(iommu); ret =3D -EEXIST; goto fail; } @@ -425,6 +426,7 @@ static int msm_iommu_attach_dev(struct iommu_domain *do= main, struct device *dev) msm_iommu_alloc_ctx(iommu->context_map, 0, iommu->ncb); if (IS_ERR_VALUE(master->num)) { + __disable_clocks(iommu); ret =3D -ENODEV; goto fail; } --=20 2.17.1 From nobody Thu Nov 14 08:36:43 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83C97ECAAD3 for ; Thu, 15 Sep 2022 07:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230125AbiIOH6r (ORCPT ); Thu, 15 Sep 2022 03:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbiIOH6i (ORCPT ); Thu, 15 Sep 2022 03:58:38 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2074.outbound.protection.outlook.com [40.107.93.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 028AC97504 for ; Thu, 15 Sep 2022 00:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KRXLEGJWAicn5NUQOyu8ag3HmQgir2PqHZBTXkol2fIS1HkoPdg6dZhSoGAiFq8q7Q7AHs4ugLExE8qMVAxa63smZlPGwF57J9xUW9J7PG/QbWBoxgkKp363TwLjI9tP4VUqTWmm3PDnHR7xe/Z77sRlU6ylw+7dBZf/8bzQqnhu8wdyTg/A3W7GgsxPbqkgGEgOCPh16fWyTQckMsbb9DG4W9KnDW7GMC3MLz/X6D625lXdrIpn9B00Q823BNgMaT+uCoxBy0mBr0qZeLIIpzVo2AqP6sgLYHlKSwovdJhul+4RZRaPN1G8bzSstRFDWdosKFSJlsrY1kW6uleJfg== 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=tGcXU9A3YFr5tH9FN/uC9AtJ8o+Ku4JaXjKDFv27XyA=; b=EJwQmmC27LEFQ8FrAX405C+uOLnW+QsDvI4CQkFWSm4niaAM77f7UHaA0QuIIOCskegeAZ50gVlDK0+Ggz3eKh/nFqmdN+dePVl2kq+rWkU1k5jvuxNs+FKL9Tc/bWu7g7hCdk/zZSViujkMF50bhDgz2D1w3NdxYo0QyIKIbeAi9QdCOv0ZE7UYq9xcr3YhY6QzNymXkfFMMIlvounaQt9fepbWIF7FDn8R1hL2OgiDdgj2flH7PJFGqOxtgPtqBtuTkMAvzpy784Yx44gCQW1PCKm/3oGuR1IbCR21/CxcDO/gjEUfPbX7TlgcBltnrHFs2OvPASQlOmVgrrfRVA== 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=tGcXU9A3YFr5tH9FN/uC9AtJ8o+Ku4JaXjKDFv27XyA=; b=hGQj2JJImKkXC8us5BRW9SvH3OyHedqBHQ2UbVE4cInjO5NetwNHoG/GpUNJJ03NzB2aYesbYRNHptTqfPGdd3iXdUcpriLD2oewJGr0HODVNHuCvNLgZiSpRNml1SgnHxohkw3/CMe4wMrw8vm55HkuIf6cCLHtgw6XR96dyiV+8mJkvdYP8YbuTOkX87wQwF4fbMtCvmDHQTdaTXOUQo839XkZfmjmDOuShjt3GPY0TfM9sbPEROSpLzW7Vbv9ER6sCtGMHi5ixs7YRpiW/5UbqGtgELbRbAE9tyMPiPiljA9JC+ZKUenub3y/8KiV3AETSMcVU7Z09W0vwCx3wg== Received: from BN9PR03CA0335.namprd03.prod.outlook.com (2603:10b6:408:f6::10) by CY5PR12MB6552.namprd12.prod.outlook.com (2603:10b6:930:40::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.15; Thu, 15 Sep 2022 07:58:35 +0000 Received: from BN8NAM11FT078.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::e4) by BN9PR03CA0335.outlook.office365.com (2603:10b6:408:f6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.15 via Frontend Transport; Thu, 15 Sep 2022 07:58:35 +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 BN8NAM11FT078.mail.protection.outlook.com (10.13.176.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Thu, 15 Sep 2022 07:58:35 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Thu, 15 Sep 2022 00:58:22 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Thu, 15 Sep 2022 00:58:21 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 15 Sep 2022 00:58:21 -0700 From: Nicolin Chen To: , , CC: , , , , Subject: [PATCH v3 2/6] iommu/amd: Drop unnecessary checks in amd_iommu_attach_device() Date: Thu, 15 Sep 2022 00:58:18 -0700 Message-ID: <1080ad9a761272a370b04ae65767447f715ba325.1663227492.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: BN8NAM11FT078:EE_|CY5PR12MB6552:EE_ X-MS-Office365-Filtering-Correlation-Id: a0c16506-598d-4b21-7bef-08da96f0175f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LOdeJM7ZWPRa3+WWH02ELm/l7TTcKEPbk42Y+dyVvPJh1t74AOawAoG2F3jKbeq0FceOhPra6xqRQBZik5hJbJOryFtO5MFjUbQPaoKbe9YNt0wJ/m8IyJqH9zE0z45tgUbsEitRB0BZoxyq7BrztU/2xn6tZ4st5IRE/xQAwH1rANRos7tQDBZcgmjNaFscEAfcaglCPBCWxnIG/2UmlmZXqMVHio7gAZ65WvuRvz1lSbiFI4F2S0lejB04I79USeKO6oDiAlQ/NqlHk4S7HamVUgbIxD+BsU8qGRpAwqOVCOA3u2ImznGaIzwQkS+NQA8ui6wLmaYfSrMuHCESBmtPpdppSqpsB/U0JCVXtaoAPDAWN3uJ+RRDipxyFMtilP7HzLbGhxod+2zduNp+3Nk5i4eB3MAwJo6FZIcP9xpcuF5WdpAq8h1kT22VYxCG7FSsnJo69LV0T7vQcIv3tNcZ8xu063DBwS7cyRAsviIcZVtRCixDskkt/EOeFt2PwJxsTp9MSqiDa9HKxyqzKgw7cvlpZ8xMpmHDKXBsKJp9u+J7xjggD0FL6fURU7XHZlfOQTeKBmicgHUnQboZMMH6Ife7fwFibblE9oeH0lWoz56fIwBlEsuS1F7c6PeRMsFn+vMF0OFZb3FsDabQU/0EFdt1MMIKMiHVyIXkO+CErdWQLscnA9h0SQxIrOSC+0CN7xzLwBRbl3W6ohTBkK0B9xrlqhWgpp13fqdh9SQLtnEnNyOaec3rPUFf3CpSvFwW8gtdvK4cFFnutOXu6g== 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)(396003)(376002)(39860400002)(346002)(136003)(451199015)(40470700004)(36840700001)(46966006)(2906002)(26005)(36756003)(40480700001)(110136005)(36860700001)(4326008)(54906003)(316002)(41300700001)(82310400005)(70586007)(70206006)(86362001)(5660300002)(478600001)(8936002)(8676002)(7696005)(336012)(2616005)(83380400001)(426003)(47076005)(7636003)(356005)(186003)(6666004)(82740400003)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 07:58:35.2610 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0c16506-598d-4b21-7bef-08da96f0175f 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: BN8NAM11FT078.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6552 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The same checks are done in amd_iommu_probe_device(). If any of them fails there, then the device won't get a group, so there's no way for it to even reach amd_iommu_attach_device anymore. Suggested-by: Robin Murphy Cc: Joerg Roedel Cc: Suravee Suthikulpanit Reviewed-by: Vasant Hegde Signed-off-by: Nicolin Chen --- drivers/iommu/amd/iommu.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 828672a46a3d..930d9946b9f7 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2135,21 +2135,13 @@ static void amd_iommu_detach_device(struct iommu_do= main *dom, static int amd_iommu_attach_device(struct iommu_domain *dom, struct device *dev) { + struct iommu_dev_data *dev_data =3D dev_iommu_priv_get(dev); struct protection_domain *domain =3D to_pdomain(dom); - struct iommu_dev_data *dev_data; - struct amd_iommu *iommu; + struct amd_iommu *iommu =3D rlookup_amd_iommu(dev); int ret; =20 - if (!check_device(dev)) - return -EINVAL; - - dev_data =3D dev_iommu_priv_get(dev); dev_data->defer_attach =3D false; =20 - iommu =3D rlookup_amd_iommu(dev); - if (!iommu) - return -EINVAL; - if (dev_data->domain) detach_device(dev); =20 --=20 2.17.1 From nobody Thu Nov 14 08:36:43 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C877ECAAA1 for ; Thu, 15 Sep 2022 07:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbiIOHyV (ORCPT ); Thu, 15 Sep 2022 03:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbiIOHyK (ORCPT ); Thu, 15 Sep 2022 03:54:10 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FCFF58DC3; Thu, 15 Sep 2022 00:54:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SbKu0aSPTAyeursEZ8a8xW6AYwty4TURGwYrPSGJzvxHSv23hr+Sx0GV04SXdXhP49GsX0V0BbgmUKWXyG8MIRpx7mO4JYrx0S3ArET9mG4pmeksVOM4lwwfiaheGaAvr1edUeb2fBXcHqeFja+eU3n3EibFeTcafAsQQQGmSQXZV/pVEFiIzvzj2SUn8A1w5yhTU7GhbFFYedXoHVDW1XtbsaAy3Ea9eKn+NRkLiKM/IPH/nYcXtzUP9BzINGtRGrYpL/T0UtDsD3HgY2QBsBWNIlO/rTtl5xdc/S0LMtOWX/FZUJWUGroWWYPLmBXAP/Mm45wGnummbJLnu7mm3Q== 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=W4++iVSopDD7PZ9pvc6GGvWnim/xl1FguP/v4ZG2nL8=; b=K936KmBMXxG3XMy4vzECdu/66FM0ZFbfsUiqHzfswQjNB8HKy7OgHzzvhBfQ7xnDXPI0GL/OI1XqOjmWCWpMCEyN/ZeFD4G+QytQcgukPi7HDKmBoi7bMxCJPzko7hy6sggLiE5HAQzgfmkXZNxynBbLYVECIJbBsdU/BMo4914wvd3t13Ni/CjJd8lx43HDMRRTO2WN2I3G2seZKRbfeVfyJImquNg5T4PLaJ8Ki3g+9uRDmKkutdvpV+ixu4hB9rlgBGwdNLdrVYtsxF8d6F1/vOBjWQ/Hat+ZrK8fhyEDtDcjlhdE/yUUrQU7XiPRW7fVKDiUfGS+wh/ImhiYWg== 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=W4++iVSopDD7PZ9pvc6GGvWnim/xl1FguP/v4ZG2nL8=; b=AOwzrKoHutfUT73BOYSwcef4PRmGA9ZOo3JK7oNj8kAQw93afheposn9m969VV9d9YbJo+I5HWzA+wPZwP/IhmZN0PnHGH5yY8mrDMoAA9kaBxLxgwKartRWoR56I4el5/4fvPRoGLLmeYfUEDevCXvFGOR8U2F/kQjQRqldDaJqBtf/nwUSc1t+OSVVA9hQ49SjoqcMLRr7vfhu5Gk2kq0kc2GOzhG+kFrSUfwv6c4d5zZdH+e1qsE74nvCWd1Vdum+0vQ8qE2vZsTn5CtVfIfCrOxjsEyVbHPlUmT8tNqegNNfakt51Q86eGUjWRdU9h2ruybjNL8cFutsNt9aYw== Received: from MW4PR04CA0185.namprd04.prod.outlook.com (2603:10b6:303:86::10) by SJ0PR12MB6832.namprd12.prod.outlook.com (2603:10b6:a03:47e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.20; Thu, 15 Sep 2022 07:54:07 +0000 Received: from CO1NAM11FT021.eop-nam11.prod.protection.outlook.com (2603:10b6:303:86:cafe::26) by MW4PR04CA0185.outlook.office365.com (2603:10b6:303:86::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.15 via Frontend Transport; Thu, 15 Sep 2022 07:54:07 +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 CO1NAM11FT021.mail.protection.outlook.com (10.13.175.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Thu, 15 Sep 2022 07:54:06 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Thu, 15 Sep 2022 00:53:54 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 15 Sep 2022 00:53:53 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) 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; Thu, 15 Sep 2022 00:53:53 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 15 Sep 2022 00:53:51 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 3/6] iommu: Add return value rules to attach_dev op and APIs Date: Thu, 15 Sep 2022 00:53:36 -0700 Message-ID: <822a983febf7e259aa2aca70dddd382810b96117.1663227492.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: CO1NAM11FT021:EE_|SJ0PR12MB6832:EE_ X-MS-Office365-Filtering-Correlation-Id: 831f3a5c-281f-4224-4878-08da96ef776d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +0ijxw3EtCKf8jruw/BHqXP8sW20J7Pcx1ATV6p8OMn6Ladu95lNgrRFWSAuLKuM4EV7XAZnfkxYO1RIRnBJG+nHUO4IjQQFADX8WIxSmnli/1YPHC6f4rQcGbE0BoMOpG2gUTnyzNDdxVbzrRwkW+CCnmLoGGlTebE6myCZ0bYPPslTQ8DyKinT5fLLa9g5nexUakRDvLn5pHUuew96T17oAgsbadYQVjmC+c7AP5IvXxxuEHj17kmTUYp0cO0VbP3CVI4lxdaKnuL6+rPTtj/vKRkAl4MpmwPLud+QWWGWNchtjQaG3yyKisw40EaJVIFDTGL9edIenxpfrA6Gspbyp9jkkxKHHKOxXvVzOiuNinseWyDGRrAWmoxMkjClBrLXQ1IoA9XvGkbUyDRpkSCrh3WxIZ05Zx+bWLMHkghPPs4WEmNw3SKEHEpzoUQTqZ6BtJBCqXeMsn/p2BWtRfE1eDtWUJZTz1ZsIiGkTmhPhhYF05uPdLFqCVC343x9WDLuGn+Bi/OY4LYnVstZAkN8iFrk2jRPlw/HXmY3BfEOlgjnCaLt3xaJaEam2+qxESlmWHuSeGEi8KtBBRFj6Ox0+lqXzWOw6GDJ75ji/ka+WjBMX+3yMPHzUgfX/VgWOoTrYWYes1wopYdP4Ei1khteCuttwvo1i99nWHHcmruVdAyUVucyRil1a/IO1I9f9B4imNve6/2Snj3y2R3ZprL5ORAoFZYCdB+UhRIUZt4zvZFA4y2iClmSpjrtSif6LZ5wpu/RhIac/laIU7Tgg7zxEIyzaJmhU8xMQB6gvkWZ15f2tGDlBbTPl4XnPHUfuj6VLy1quOaPMaR60GEuYg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(39860400002)(396003)(346002)(451199015)(36840700001)(40470700004)(46966006)(26005)(8936002)(6666004)(36756003)(356005)(86362001)(2906002)(82310400005)(7406005)(7636003)(316002)(478600001)(426003)(82740400003)(4326008)(54906003)(47076005)(83380400001)(336012)(40460700003)(7696005)(36860700001)(8676002)(921005)(186003)(5660300002)(7416002)(41300700001)(70206006)(40480700001)(110136005)(2616005)(70586007)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 07:54:06.9784 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 831f3a5c-281f-4224-4878-08da96ef776d 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: CO1NAM11FT021.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6832 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved by using a different domain. Provide a dedicated errno EINVAL from the IOMMU driver during attach that the reason why the attach failed is because of domain incompatibility. VFIO can use this to know that the attach is a soft failure and it should continue searching. Otherwise, the attach will be a hard failure and VFIO will return the code to userspace. Update kdocs to add rules of return value to the attach_dev op and APIs. Suggested-by: Jason Gunthorpe 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..e4d2ee99a264 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; } =20 +/** + * 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 de= vice + * are incompatible: if the domain has already been used or configured in = some + * way, attaching the same device to a different domain may succeed. Other= wise, + * it may still represent some fundamental problem. + */ 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; } =20 +/** + * 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 gr= oup + * are incompatible: if the domain has already been used or configured in = some + * way, attaching the same group to a different domain may succeed. Otherw= ise, + * it may still represent some fundamental problem. + */ int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *gr= oup) { int ret; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ea30f00dc145..90960fa8cd91 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 - the device and domain are incompatible. If this is due to so= me + * previous configuration of the domain, drivers shouldn't log an + * error, since it is legitimate for a caller to test reuse of an + * existing domain. Otherwise, it may still represent some other + * fundamental problem + * * ENOMEM - out of memory + * * ENOSPC - non-ENOMEM type of resource allocation failures + * * EBUSY - device is attached to a domain and cannot be changed + * * ENODEV - device specific errors, not able to be attached + * * - treated as ENODEV by the caller. Use is discouraged * @detach_dev: detach an iommu domain from a device * @map: map a physically contiguous memory region to an iommu domain * @map_pages: map a physically contiguous set of pages of the same size to --=20 2.17.1 From nobody Thu Nov 14 08:36:43 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08827ECAAA1 for ; Thu, 15 Sep 2022 07:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbiIOH6n (ORCPT ); Thu, 15 Sep 2022 03:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbiIOH6h (ORCPT ); Thu, 15 Sep 2022 03:58:37 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2059.outbound.protection.outlook.com [40.107.243.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16DEB97500 for ; Thu, 15 Sep 2022 00:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CFQlOQTUTrR81Zw3GprDQtkNlilBZx6MoVoYHQW794bCOx0b6eBEccHOq2kG7VWxcn3S2a6x2FqkPHKk1fZcTjhEahbzx/lPN82P5Ionblnld7bV2oDBjsJIvhQ0p4ozJdz80KKBRXzXRJ74PmZTXgoYySbmoc227Af4V1oVBvqUu5AV64rsDwmprz+gNghCD3surMRbh6VJ+KjHPL7Nj6mItYSzQVoxwVEeiOoq1/Gqi4RBRMOHOGTN6595gFyoXh6fw7nV8w+fjwQWgdZlNRDBn2+Z0LEIEp3P69RJoDkD4b1lVvKynXgbmbnsBDvmZ2SnWolONBSistCpsYVxzw== 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=fJfH8Poz1xtRvTXzuGTECwbGRWb45/l3U0wob21yavM=; b=jeRFJtMX6e/wQnPH15mCZwIgN01phSNHxvzVAXpaDL8D2i2bchYDxft2fC+mml39CyQoBwoM4ST03NidbZYBiVk7uM2YDXyLCdwPwFoEFVDIqi1zH5HisvpLzGE8HDzvmgyGspjZOzu5zzFm8jxkjMUgCz5Apnzr/e05CbBhBQxjwqL5p6W3iMqx9iBbR9Hly26v7lIMeriiq7GT2VSVqGQaqbWWZYOkMJ5QFrCG5Ey27zUXSYT2k5F2uGOKzTtH9EZsij506skWgYNg3sYpUhkI68qEjHy8tYabWdmWcbrlDa5MfNS7cbivJsGzA2r9R72q2SZ/zQTrTvmZ2Rb6hQ== 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=fJfH8Poz1xtRvTXzuGTECwbGRWb45/l3U0wob21yavM=; b=s1B/JCBsqk+U0NCUL7vUHbcUv/WZuE7q2RtoehUsh0FuYoNf8OLmcMN4GGTzt/8pc2m7bW8z8MM0kJOYpHZCkk0/6JPL0NxeCjyff72d3D7adM04T4QRYtTVXFMV2IR29uf33Ic6q3nGbn8/SJ8GDEXudoabk0YXdZUhmBRulA7i+mybM6XlvbdQ7Xs3SuH7oyiE/7kntLyhu+09RepVjE1ZkjRdTHogBE3PeGhDYrqjc2VmMTAWOGa7xugJLkCHQ8qsmffneHac3L8XIpcUqWPlwjkBLgwKjXpMQ4bamUXm2QaMFJXyHsLNhYgx9ccaVpg01sYrpJTiuhl9I5BJUA== Received: from DS7PR05CA0084.namprd05.prod.outlook.com (2603:10b6:8:57::25) by MN2PR12MB4454.namprd12.prod.outlook.com (2603:10b6:208:26c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.19; Thu, 15 Sep 2022 07:58:35 +0000 Received: from DM6NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:8:57:cafe::73) by DS7PR05CA0084.outlook.office365.com (2603:10b6:8:57::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.5 via Frontend Transport; Thu, 15 Sep 2022 07:58:35 +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 DM6NAM11FT051.mail.protection.outlook.com (10.13.172.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Thu, 15 Sep 2022 07:58:35 +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; Thu, 15 Sep 2022 00:58:33 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Thu, 15 Sep 2022 00:58:33 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 15 Sep 2022 00:58:32 -0700 From: Nicolin Chen To: , , , , , , CC: , , , , , Subject: [PATCH v3 4/6] iommu: Regulate EINVAL in ->attach_dev callback functions Date: Thu, 15 Sep 2022 00:58:30 -0700 Message-ID: <253f8098664f78f5b5a8a7deb816af8ad7d37122.1663227492.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: DM6NAM11FT051:EE_|MN2PR12MB4454:EE_ X-MS-Office365-Filtering-Correlation-Id: b77d1d42-8eb2-445b-92fb-08da96f01730 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SocX25x3lEs0ANA1D6LG8TP80pT/632jY9XCgd19NMhnwZNcGJFvrXugJfdM8Oqzm/37uXhofz/ZJTsY4DLjwPcfnsEf/UascJIsEzMO5WGbK3/RABLKm2ZxkG/kh8V6LiJu/YH9hjDkPg8U4ZgUerc8tU7/g9z73Ag97LjYT+4A08/KltXHnv0dO30Yib/ohN7Ac5YZOLa8ziPIN5ukZ3CGP71xs3ZtyL4cuqW+q65M0go33+9B5ujKaFtqXnFmHFGQvr7t3jjxEjR+neMxguVJu+AEtNPoKNeWBc1z8s9fHyIVFefAPio8qOYgR+oANVrSJBKHMmG1lt2FvBzW2SZbC2Xw3PI86qme9c14q9PXVgCbmX9X7jLMTr5Cug+SlIPXPZm5U2cexX1iC+bn5TZW5ZoGr/+S6qh1yzwe64qdlzAkeYCgmmDcoVWhjnB/QDPQO0HWI1xKdfDYkS0hbAPZEtQJp1B/G8anqUZ8ZB1lWqsTCM+MxLvc6TULx3K6+my5vekAAHKtlNzulMGu09zeTlYjP7IfapgDxWkKpdOSk7ayqAWRfqYwQj4jmz68uiBSQZ0K0hl291gBz5DUskhmZMsxnUBRfn7YoX4OjoXI2p435Su4LrsX/k52r3mUbjeG5QEiyiNgIFrSmba2AaAZK+eX8Y8avIK4MBAubWTEcKATd4Jn/5LbBpwNCZNRhjArjMe0ox4s5Y2IJ4hhDIQ409pLzGZy4Yg6deN9TyJTVu7AnkC7716tT9SUhpYx1akdS+f2e/dEIAH1G3DJkQ== 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)(396003)(376002)(346002)(39860400002)(136003)(451199015)(40470700004)(36840700001)(46966006)(316002)(7696005)(186003)(41300700001)(336012)(2616005)(82740400003)(26005)(36756003)(54906003)(110136005)(83380400001)(426003)(478600001)(40460700003)(47076005)(82310400005)(40480700001)(36860700001)(86362001)(8936002)(356005)(4326008)(70206006)(8676002)(70586007)(7636003)(2906002)(7416002)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 07:58:35.0317 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b77d1d42-8eb2-445b-92fb-08da96f01730 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: DM6NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4454 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following the new rules in include/linux/iommu.h kdocs, EINVAL now can be used to indicate that domain and device are incompatible by a caller that treats it as a soft failure and tries attaching to another domain. On the other hand, there are ->attach_dev callback functions returning it for obvious device-specific errors. They will result in some inefficiency in the caller handling routine. Update these places to corresponding errnos following the new rules. 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 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c index 0d03f837a5d4..2eb3211c8167 100644 --- a/drivers/iommu/fsl_pamu.c +++ b/drivers/iommu/fsl_pamu.c @@ -211,7 +211,7 @@ int pamu_config_ppaace(int liodn, u32 omi, u32 stashid,= int prot) ppaace->op_encode.index_ot.omi =3D omi; } else if (~omi !=3D 0) { pr_debug("bad operation mapping index: %d\n", omi); - return -EINVAL; + return -ENODEV; } =20 /* configure stash id */ diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domai= n.c index 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 =3D of_get_property(dev->of_node, "fsl,liodn", &len); if (!liodn) { pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node); - return -EINVAL; + return -ENODEV; } =20 spin_lock_irqsave(&dma_domain->domain_lock, flags); @@ -267,7 +267,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *= domain, if (liodn[i] >=3D PAACE_NUMBER_ENTRIES) { pr_debug("Invalid liodn %d, attach device failed for %pOF\n", liodn[i], dev->of_node); - ret =3D -EINVAL; + ret =3D -ENODEV; break; } =20 diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index c5e7e8b020a5..4cadbd744b7f 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -101,8 +101,10 @@ int intel_pasid_alloc_table(struct device *dev) =20 might_sleep(); info =3D dev_iommu_priv_get(dev); - if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table)) - return -EINVAL; + if (WARN_ON(!info || !dev_is_pci(dev))) + return -ENODEV; + if (WARN_ON(info->pasid_table)) + return -EBUSY; =20 pasid_table =3D kzalloc(sizeof(*pasid_table), GFP_KERNEL); if (!pasid_table) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 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_d= omain *dom, dom->iop =3D alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data); if (!dom->iop) { dev_err(data->dev, "Failed to alloc io pgtable\n"); - return -EINVAL; + return -ENOMEM; } =20 /* Update our support page sizes bitmap */ diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 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, =20 odomain->num_iommus =3D omap_iommu_count(dev); if (!odomain->num_iommus) - return -EINVAL; + return -ENODEV; =20 odomain->iommus =3D kcalloc(odomain->num_iommus, sizeof(*iommu), GFP_ATOMIC); @@ -1464,7 +1464,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, st= ruct device *dev) =20 if (!arch_data || !arch_data->iommu_dev) { dev_err(dev, "device doesn't have an associated iommu\n"); - return -EINVAL; + return -ENODEV; } =20 spin_lock(&omap_domain->lock); --=20 2.17.1 From nobody Thu Nov 14 08:36:43 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F831C6FA8B for ; Thu, 15 Sep 2022 07:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbiIOHyK (ORCPT ); Thu, 15 Sep 2022 03:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbiIOHyG (ORCPT ); Thu, 15 Sep 2022 03:54:06 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2084.outbound.protection.outlook.com [40.107.94.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0537B58DC3; Thu, 15 Sep 2022 00:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jkQdXUs3i7t4+VmwSyAodEqPW1U3/1fSQrDuBy68f/IP/hf5hdRIYeVlsbpy/QRTsHVxycYkR2NxZ5PjZuIjG8wTJQSg7dECxiZgVdGByw7q8tC1Bp/LNo6w2K5E216eamXAooVOTqOpz349g3FaWSLphN2CRhjAdj6f5MH4sAE6CHvaqECFaw02ZJilXoqvS3sGJq8zuNK62FI8T2VE29zOzzv+pKx2FGMGW3NU0R3YDM9XMO+nkfd9mss/fXikoViglYOqgQXNHslC1BhM8N7SHz0IIl6PiDrYgTVGcc7BGKFnvuEQRftgI4GkPo4b6m603e3LsducjDwYue7t8A== 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=DfLOdCiOUyUBZ957iIROO5B67gyhmf+1I/2Md8hgqjI=; b=FGMc4i9k3k/ywkl0AwnG/1UOogN/aApdOz+Z05g22OHs4GGdrxaZmmM2pbeMtzt09dF29cxG/8qP6MgS4+xnRtKTtfY+UugUrRFuBiDH94EgwJgoELJj5wOrCYOiSyRp45/HdM/8JZYyLBWgn2pxhKrTrfQVg9vbbfa16v10nvp5XleI63U+ikIg0XqwxPghXyTcln+r0Zpf7bt79haC2gcFchLaH4wOotmwM8zuoRFCMqkxrBwqdJfHuL1qrGzCm8a/bbOGO/0ridYxmHrB+NZ6BAnIENH3Sp21Gk0OOLT9GYzVKljYOWlF48C0nDziMLQXsf5SVOFcDIuvLxCEXw== 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=DfLOdCiOUyUBZ957iIROO5B67gyhmf+1I/2Md8hgqjI=; b=LQQbxIWMr3zTIU815Y0VKeV49h5mdLUllAuvhFche9rVni05j9lVXaqmFwHGKHaiLyWbw5yOJUdL5XKbLm2vyn/g9PjxYXQgiLhylSXeVXHlAafE7U7zQGoT3AFyLakPqvuvx3zTjGWEZxsJ2w558gN1L5n0QMjgcwnPNPHUuSjp4GEkQksKEv/ESY5JmmHDTfU5rCTLV/QQdZ4D37CuHB17/Oevp7T1T+H8JZuuCItp2E906wl76GUzpEBvcbrTrTLIpJ3DRO4glJH5SZJWetKBLHe63r15HTtOQm97ayN9lIBiDkdoimvAzVs4/VPQYffZgbXN4EG6U6U30f83wQ== Received: from DM6PR02CA0088.namprd02.prod.outlook.com (2603:10b6:5:1f4::29) by BY5PR12MB4035.namprd12.prod.outlook.com (2603:10b6:a03:206::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.16; Thu, 15 Sep 2022 07:54:03 +0000 Received: from DM6NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1f4:cafe::da) by DM6PR02CA0088.outlook.office365.com (2603:10b6:5:1f4::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.15 via Frontend Transport; Thu, 15 Sep 2022 07:54:02 +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 DM6NAM11FT005.mail.protection.outlook.com (10.13.172.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Thu, 15 Sep 2022 07:54:02 +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; Thu, 15 Sep 2022 00:53:55 -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; Thu, 15 Sep 2022 00:53:55 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) 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; Thu, 15 Sep 2022 00:53:54 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 15 Sep 2022 00:53:53 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 5/6] iommu: Use EINVAL for incompatible device/domain in ->attach_dev Date: Thu, 15 Sep 2022 00:53:37 -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: DM6NAM11FT005:EE_|BY5PR12MB4035:EE_ X-MS-Office365-Filtering-Correlation-Id: 485ac931-ce33-4c59-c191-08da96ef74e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8i9CRjkDyzT89tBtc5/y5MNpA6xRPblz1erXpUfigA/fN3kcQYzrXlem2lEj+5UPygdVAUr+laHc8mp+vVILpAgcbX91Fzh3SbF4W0+bg4Cv3S9ui9twQKB+5ghFxRW6iMq3LD1OHcdV9155lC5Ij6JFoTAYcSN9kNsQgki/Y7rzkQn7KOY2MBl3J+hlYkH9kQGIJsUHuxPp708khq8GE/qIZMlG689OJvU/40pM48nxAZc6noCeZhTNdymtp1hoU9fB7xG62PL2O4U7n3rM6qobz7uTMWfbzUTVnwma66SXgxvNIjJLKxDYh4NvV73lXR0arAt5/FKl6exFIBbmqGLsZr+C7Z2sVKH6j3790N1sUm0G83iY5xRJjMPRRZ+0D2j7WCFcBhtpFhSpxyXg9UdbaSidNC7LCf/P+57215KCB1gJgTdWPEI6vKV8xbHlNHMmeeQk4hMKZkuQZZy+QKqO7KBkCRRzlBj4vSMIFL27s/LPzj4qYSPWDs8MzrRPLZqzVUxdak5jW6BY097BE/Hrs6oOJn+NXu6iMzOy6KWCTo/0sV/QC9BjP0pQmN5VUrq5zpARSxjX0fcUQK69MPjfqnSeoDlkpGSJHmrw8yseBwXkabZrotc/CPpRWweU+FRVF2XZMcCSPLBg6D0V8OnDMYvXrToyxVDfXvf0OALALLUPFKfHW2ugS2uQCBPTwRcqZd1oieTXyhUF6kDWmLaEgl1lZtLKTG52YKgUMTqLa2kEzCpK6mEojNjVOfA4siOzy5dI5TgF8v4eelj0/1c17Pg36adJCNfiYE+GzPadKjnY6H/4v0OC8C308+qiZHvFrq8gEwtqoYpk5Yhl6yD2odzE0M2sGIx/5iRCgVg= 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)(396003)(376002)(346002)(136003)(451199015)(36840700001)(40470700004)(46966006)(7636003)(2616005)(7416002)(82740400003)(921005)(8676002)(40480700001)(36756003)(356005)(2906002)(40460700003)(82310400005)(54906003)(47076005)(186003)(83380400001)(86362001)(336012)(110136005)(7696005)(5660300002)(7406005)(426003)(6666004)(36860700001)(8936002)(70586007)(316002)(70206006)(26005)(41300700001)(478600001)(4326008)(83996005)(2101003)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 07:54:02.7283 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 485ac931-ce33-4c59-c191-08da96ef74e4 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: DM6NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4035 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following the new rules in include/linux/iommu.h kdocs, update all drivers ->attach_dev callback functions to return EINVAL in the failure paths that are related to domain incompatibility. Also, drop adjacent error prints to prevent a kernel log spam. 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/ar= m/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 !=3D smmu) { - dev_err(dev, - "cannot attach to SMMU %s (upstream of %s)\n", - dev_name(smmu_domain->smmu->dev), - dev_name(smmu->dev)); - ret =3D -ENXIO; + ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && master->ssid_bits !=3D smmu_domain->s1_cfg.s1cdmax) { - dev_err(dev, - "cannot attach to incompatible domain (%u SSID bits !=3D %u)\n", - smmu_domain->s1_cfg.s1cdmax, master->ssid_bits); ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && smmu_domain->stall_enabled !=3D master->stall_enabled) { - dev_err(dev, "cannot attach to stall-%s domain\n", - smmu_domain->stall_enabled ? "enabled" : "disabled"); ret =3D -EINVAL; goto out_unlock; } diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-= smmu/arm-smmu.c index 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 *d= omain, struct device *dev) * different SMMUs. */ if (smmu_domain->smmu !=3D smmu) { - dev_err(dev, - "cannot attach to SMMU %s whilst already attached to domain on SMMU %s\= n", - dev_name(smmu_domain->smmu->dev), dev_name(smmu->dev)); ret =3D -EINVAL; goto rpm_put; } diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/ar= m-smmu/qcom_iommu.c index 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 !=3D qcom_iommu) { - dev_err(dev, "cannot attach to IOMMU %s while already " - "attached to domain on IOMMU %s\n", - dev_name(qcom_domain->iommu->dev), - dev_name(qcom_iommu->dev)); + if (qcom_domain->iommu !=3D qcom_iommu) return -EINVAL; - } =20 return 0; } diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 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 iomm= u_domain *domain, return -ENODEV; =20 if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) - return -EOPNOTSUPP; + return -EINVAL; =20 /* check if this iommu agaw is sufficient for max mapped address */ addr_width =3D agaw_to_width(iommu->agaw); if (addr_width > cap_mgaw(iommu->cap)) addr_width =3D cap_mgaw(iommu->cap); =20 - if (dmar_domain->max_addr > (1LL << addr_width)) { - dev_err(dev, "%s: iommu width (%d) is not " - "sufficient for the mapped address (%llx)\n", - __func__, addr_width, dmar_domain->max_addr); - return -EFAULT; - } + if (dmar_domain->max_addr > (1LL << addr_width)) + return -EINVAL; dmar_domain->gaw =3D addr_width; =20 /* diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 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 =3D -EINVAL; } else dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 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, st= ruct device *dev) /* only a single client device can be attached to a domain */ if (omap_domain->dev) { dev_err(dev, "iommu domain is already attached\n"); - ret =3D -EBUSY; + ret =3D -EINVAL; goto out; } =20 diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 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_domai= n *domain, struct sprd_iommu_domain *dom =3D to_sprd_domain(domain); size_t pgt_size =3D sprd_iommu_pgt_size(domain); =20 - if (dom->sdev) { - pr_err("There's already a device attached to this domain.\n"); + if (dom->sdev) return -EINVAL; - } =20 dom->pgt_va =3D dma_alloc_coherent(sdev->dev, pgt_size, &dom->pgt_pa, GFP= _KERNEL); if (!dom->pgt_va) diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index e5ca3cf1a949..ed53279d1106 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -112,7 +112,7 @@ static int gart_iommu_attach_dev(struct iommu_domain *d= omain, spin_lock(&gart->dom_lock); =20 if (gart->active_domain && gart->active_domain !=3D domain) { - ret =3D -EBUSY; + ret =3D -EINVAL; } else if (dev_iommu_priv_get(dev) !=3D domain) { dev_iommu_priv_set(dev, domain); gart->active_domain =3D domain; diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 80151176ba12..caca0a638c4d 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 *domai= n, struct device *dev) */ ret =3D viommu_domain_finalise(vdev, domain); } else if (vdomain->viommu !=3D vdev->viommu) { - dev_err(dev, "cannot attach to foreign vIOMMU\n"); - ret =3D -EXDEV; + ret =3D -EINVAL; } mutex_unlock(&vdomain->mutex); =20 --=20 2.17.1 From nobody Thu Nov 14 08:36:43 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C55EECAAD3 for ; Thu, 15 Sep 2022 07:59:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbiIOH7g (ORCPT ); Thu, 15 Sep 2022 03:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbiIOH7P (ORCPT ); Thu, 15 Sep 2022 03:59:15 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2079.outbound.protection.outlook.com [40.107.96.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4611F9751F for ; Thu, 15 Sep 2022 00:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hL5sbpJKtwwaKGqA9Vm1TiBanQPxX3FCfS0bdeAWmiXVINa1XTx80MWaDHPg1EtWoqsRSzO3JEXLdgtAAKUgWAs498RCHvkJjLtUlz4Okm65sW8LskxFbrcFmYXRnQwfBGlkaHqpFdIb298GxXKDkq2CRD+YTD4NCipWmvibueX2C9DqSLdE9XnAUETzYpxmx8589lAssau9ku2RTYmvY9IyVmmaIl1mBRzlcfZ4awBb96Da3xEobTvxKikptQ/tGcYLXaodl2/BpxUsGxpe/Gnb/dHAJTUKqR9i5s4EuYrlSuTqGbIC+PwDvpVstRjMnaH/T2Wyb4MmOB1lvlBNmw== 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=lfQaMqK1friW6Q1YOcu8fec3/nE/LM+iYWmCLgxzogs=; b=Nj9c4QbURjBWZtDiihJxlF+NjOhxXnHY5fJjGdhCp3+On766gkCSZVqvUa+K59Y/tAxsr3bcLVH3Wd3LMJB9lzfLVW7YTLeSmFluQmrAfdG9FqPBMBjxRYNtZ7ArWNeHPXx2CBHbD3puPXMwUxwq/Qtr21zJLstVEsD12DqBNXcT+5Ir2Xmhgc8nsERD0FutKtASsZYmHFu6wn3jbGlrFj5VJbep06rOsQtOCAYFX9w0hOoMYSStd9mmQI66zmo9nlFODNkmUI+gy5McfDotS3OWt+eitsEZDcGZd0sbcPL7xsMzbtp8UcoqOjJ2z3if2DnZCKm71v8YO/Ssys1RJw== 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=lfQaMqK1friW6Q1YOcu8fec3/nE/LM+iYWmCLgxzogs=; b=C0HcDFW8Ak4DFJ2pbo0/9jO8deSBx+q55I8o+cyG1cMGyiA3LQ5xGwFIBsRa3USDY/bXM1a1UAxSYPO2jqBSFazM9Je2Wqt3wmq423RxuHvZLF018TWU1lGLDRMdgWpT5yADNyRKvBFCIiYGz7DaHlbgldowsciqczbuOwRSXvbfebcZVWgCR/2hhQxH3kraf2xcaVb3hzBxBwrsPdhBICHyQJJ3f+LGrjhKMbClqSyF20WEoV95jIsP1JlvGMtMJO0ldiukKOh5lcoVgoVEpEgJBzWj6ItH6IwJbo5tgQT5hHfWuox61Rz6OyrSrdV9+EEW6XgtkcYlNoAmAuh+0Q== Received: from BN9PR03CA0635.namprd03.prod.outlook.com (2603:10b6:408:13b::10) by BN9PR12MB5148.namprd12.prod.outlook.com (2603:10b6:408:119::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.23; Thu, 15 Sep 2022 07:59:09 +0000 Received: from BN8NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::8a) by BN9PR03CA0635.outlook.office365.com (2603:10b6:408:13b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.15 via Frontend Transport; Thu, 15 Sep 2022 07:59:08 +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 BN8NAM11FT022.mail.protection.outlook.com (10.13.176.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Thu, 15 Sep 2022 07:59:07 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Thu, 15 Sep 2022 00:58:56 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 15 Sep 2022 00:58:56 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 15 Sep 2022 00:58:55 -0700 From: Nicolin Chen To: , , , , , CC: , , , , , , Subject: [PATCH v3 6/6] iommu: Propagate ret for a potential soft failure EINVAL Date: Thu, 15 Sep 2022 00:58:45 -0700 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT022:EE_|BN9PR12MB5148:EE_ X-MS-Office365-Filtering-Correlation-Id: fceb390a-b0d5-42cc-51b4-08da96f02aca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lt6HvkJJ3oRO8UoW0Q9Yrmv2nc106Fm2Z+xnYwT8r4PLcO/7OqS47AP3aGF0bsqIcmf//xYzNSxEr94hY1jq+fvke6uu4HZIOWfg1a+9e95J52ZSz15l4p9lvcD82M9HS5EUkhj5SLM20ykP9SFWSnb4LLxPs0jSGDQJS12tw5kTF1hV2vYW4zRO/xhmbqekPs9OJNsntWelEPQ4Vxnfl6KoibAchNHNoGLbKcGFmC5J15oSIPGEcT018FyR/CUcqHeBdH3rZqvf+t6pOInuyL47QMYpNCwF7hMTQWOn6XNAaBj7KWSIMPXpLjNiFBan73rfnnowMa8aGkqJ3LNJHJ792PhX4s1LKXYQh6SJ9WjvDXFkBh+cZ/gb0hpSOpKSxwjJSTxQ8DuukrjhnRElAGxaUf7v6VvcTC03aAfTELZe10rzBGk4gbIXGLw4BPt7Dvqu1c1gcVTBBNwkPKOLsJ7/5MgSihRRDwWvUBkRTZb2nRsM+ngwjUt0l9DHPkdH+kIHYIdryR/wR+wyyEEAoxsr6NAj5VjAAsVOY78SXUwj3QUkljDeJUpIvxkxmXjuz28uW9yL8iMxxIMVUpXK/jC/nxIkYL1YtnwUMT1x/hSARPPKlWPIt5VHVUI5/voPN7vYU0bv+UtKw5/dJ+TRpYGEr20DS2yle1ykTJyGDKqzCBTB+MasIojKkfrmxiYfMjxiCC+17rOhzO5drS9V6QPMVvLQ0UlUtQAjaSdINPy1O/wgjGAHGWrE6x+znb7t/sMkua5X7sxc3YHnPboY8w== 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)(376002)(136003)(396003)(39860400002)(451199015)(40470700004)(46966006)(36840700001)(41300700001)(336012)(2616005)(186003)(6666004)(7416002)(4326008)(8676002)(40460700003)(26005)(5660300002)(70586007)(70206006)(8936002)(82740400003)(36756003)(36860700001)(356005)(86362001)(40480700001)(82310400005)(7636003)(47076005)(426003)(83380400001)(2906002)(478600001)(54906003)(7696005)(316002)(110136005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2022 07:59:07.8378 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fceb390a-b0d5-42cc-51b4-08da96f02aca 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: BN8NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5148 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following the new rules in include/linux/iommu.h kdocs, EINVAL now can be used to indicate that domain and device are incompatible by a caller that treats it as a soft failure and tries attaching to another domain. Either mtk_iommu or virtio driver has a place that returns a hard failure instead of the return value from the function call, where an incompatible errno EINVAL could potentially occur. Propagate the real return value to not miss a potential soft failure. Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian --- 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 =3D mtk_iommu_domain_finalise(dom, frstdata, region_id); if (ret) { mutex_unlock(&dom->mutex); - return -ENODEV; + return ret; } dom->bank =3D &data->bank[bankid]; } diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index caca0a638c4d..f1ecc5589626 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -696,7 +696,7 @@ static int viommu_domain_finalise(struct viommu_endpoin= t *vdev, if (ret) { ida_free(&viommu->domain_ids, vdomain->id); vdomain->viommu =3D NULL; - return -EOPNOTSUPP; + return ret; } } =20 --=20 2.17.1