From patchwork Thu Sep 22 08:53:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 608312 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 3F453C6FA82 for ; Thu, 22 Sep 2022 08:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230422AbiIVIyH (ORCPT ); Thu, 22 Sep 2022 04:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbiIVIyG (ORCPT ); Thu, 22 Sep 2022 04:54:06 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2041.outbound.protection.outlook.com [40.107.237.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58D15B4EB2; Thu, 22 Sep 2022 01:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HfKyjr5sG4m9Gv3jznGU5qchcO2hqfpiH6IQiVvXx+2gJjIGV/LaXTJH/2N4gPQX3t2ri+75wZWC4jwHMS8/lwQQ+mcDrcvsillQ/ifyuEr2RujpyoaCwwskakbGQ3N/FBzcw3sgqmjYm+9Bqyhm9RirO0VuTlEYPbYhTPkILzM21myVgZ71ZcrwRzbAq+wUQPeBPQR0T4ODVZPQ//mEx7J5bPZeDBqZF4sD+29GlPU6oAcw/f3v7OOR9wDTd2qlMrlrZyA6Ha99TqKXs0hUloObFqOeyprCO0Rv45GoloEq2993+DSzxAYOgC6gxIBjYnHL3fh1tiCF7iQ+eEushA== 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=qLwkC/P7zQ6hAE0ocHswVqwiO2oH27WCZXrbECT9knU=; b=f+xk4Dgq4AqZJASBMgL58GWwpnqzcmStgQ6OIYNssb3kjZYVQSHkCxM8yNcaxB3peGxdCEp2PzpQTNyToVNpHzGi/gmRCaeTgoKZeymuJ2hSDxUe/S6BiAfkdwQtGvGbGGP+5ajvqq1O9405Pw4svO7PXmsrGxsWZ2IlTbcp6FnTR8K5O5enbecTClJ709nJdmevNRQCRxLMd5jRtCQj9mPho3ZWYpnq/4F4I6cZ++3LZ45VEdjA8hvljRqNUJW3sFD5BKAKuiKXR7v9B+sgNc7NKo/D+cs/0jYKge+xF8gv57UZITtnep7kyTMgyxKnnbQcd8zdakUs1BdcMy2+CQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=qLwkC/P7zQ6hAE0ocHswVqwiO2oH27WCZXrbECT9knU=; b=U+Fnq4rnEq6otGGIX3zzG6Qk11gri+enKOpl945Sz2bsiYz2nAwX2SWS6PKyZT1HELWMhXV5Oc6ktc33BMsGYRIVDorOAtVRH7YS381442Jh+VSx6kYKK/UaD48lBtzlbTLFXx2nKTqRMSX3cqA5Kr4vy17lkazO+efT8iZwshA8+HyhcQErFrAwA+By9XMPHw2W5OO/8sV40D30/DGPRq763bfxtkN5s2eCtg0gKbaOO1/ruBC7gV1/WAk7SC+wnvLYElkeNm11FIjdKUB/VL6FPB0tyJOM1hbg10MjWKBn2SQMRPbBm/9gZZ1IlpYEJcbxGvyMfMnqygFM6khGaA== Received: from DS7PR05CA0084.namprd05.prod.outlook.com (2603:10b6:8:57::25) by DS0PR12MB6629.namprd12.prod.outlook.com (2603:10b6:8:d3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.23; Thu, 22 Sep 2022 08:54:02 +0000 Received: from DS1PEPF0000B077.namprd05.prod.outlook.com (2603:10b6:8:57:cafe::30) 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.5676.7 via Frontend Transport; Thu, 22 Sep 2022 08:54:02 +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 DS1PEPF0000B077.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.11 via Frontend Transport; Thu, 22 Sep 2022 08:54:02 +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, 22 Sep 2022 01:53:47 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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, 22 Sep 2022 01:53:47 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 22 Sep 2022 01:53:46 -0700 From: Nicolin Chen To: , , , , , , CC: , , , , Subject: [PATCH v5 1/6] iommu/msm: Fix error-out routine in msm_iommu_attach_dev() Date: Thu, 22 Sep 2022 01:53:44 -0700 Message-ID: <23e009bba72c3e46320c59acefbbdd976111cc8a.1663836372.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: DS1PEPF0000B077:EE_|DS0PR12MB6629:EE_ X-MS-Office365-Filtering-Correlation-Id: f75ce6fe-c8c9-47f3-0d26-08da9c77ff50 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EY6cz5HKMfW8EMqcvxy+tYXZTFM4fk1/fIRyeQa34wiN7ZjZ69Q6DCE0m0NzVMqjUa2IEMBGqqjaV4uvSbJzUTfEDspR5RuTSTBJCTcpSu4xkoS7Kl9gKfvDbZtRl064ommOsAaYY7lAeqLOfbKhG90AQpFoqh98ojNGRHEv5EOzQGlW7Iq12/AXsCR+uWkfTbgH1dV6/Pff5z+KAYxKy/MjEbGUbriOSSy65iCgDw2xet8jzsrzclvd3aAb1Y7Swzz4DCmgBJQtrdrk45LkhWGKSZfK8q04hd37uWOi4Jl784Az8F3/hPYrKGF3sEzIChV82tOdzjcUS3PRVf3+dAkFB6WwVv6g3naDZAZ8OfOK1GoUBuBoeDDp3kpBMmbTN+kjO/lj3GsFQ2Wo5zPWx6Nnfa5agUfBsc+c4Cv60bHF9hWo1X7HmvOgSBvsySDc0ivjsOokZDKa7UkPxXD2h2b5HtZn3RrK8bUqDuW7JFLNpBcU93aTjShoNozhBQ71FuW0cqqsABM0ars4h6XBN8MVOmV8jBdVPTmwmmAVBKQAc909c/rPaZWg7gXRhsnOjPL17jqheGg31ipDwgMytIX4gBlB2E2hbmWHDzzyuOsrh0bALeTNJH5ETk0QW4bfu3p6F5NcBuauN/1AXGYrwzZ4h0evXf2/vz9ZApVOCWvCHs6pMA/OOIYS0cZFBQFi2996G1SsIagXAfQTmdyFEqyginOlJxGtP4ZSiaSQaIBc/bD4AA5XzzLWA4h/1SUJFdvmbbsRxFSlToVrGaNHNg== 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)(39860400002)(376002)(136003)(396003)(346002)(451199015)(40470700004)(36840700001)(46966006)(2616005)(5660300002)(336012)(41300700001)(426003)(36756003)(7416002)(83380400001)(2906002)(8936002)(7636003)(7696005)(186003)(82740400003)(40460700003)(47076005)(356005)(36860700001)(40480700001)(316002)(4326008)(110136005)(82310400005)(26005)(70206006)(54906003)(86362001)(70586007)(478600001)(8676002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2022 08:54:02.3261 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f75ce6fe-c8c9-47f3-0d26-08da9c77ff50 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: DS1PEPF0000B077.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6629 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The error-out routine is missing all the reverting pieces for the iop and attached-ctx allocations. And clock enable/disable is unbalanced too. Fix it by adding __disable_clocks() and calling msm_iommu_detach_dev() at the end of the msm_iommu_attach_dev() if "ret" is non-zero. Also set the master->num to 0 in the detach_dev() since attach_dev() would check it. Fixes: 109bd48ea2e1 ("iommu/msm: Add DT adaptation") Cc: stable@vger.kernel.org Cc: Sricharan R Cc: Andy Gross Cc: Bjorn Andersson Cc: Konrad Dybcio Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- drivers/iommu/msm_iommu.c | 59 +++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 6a24aa804ea3..14df722f0060 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -394,6 +394,34 @@ static struct iommu_device *msm_iommu_probe_device(struct device *dev) return &iommu->iommu; } +static void msm_iommu_detach_dev(struct iommu_domain *domain, + struct device *dev) +{ + struct msm_priv *priv = to_msm_priv(domain); + unsigned long flags; + struct msm_iommu_dev *iommu; + struct msm_iommu_ctx_dev *master; + int ret; + + free_io_pgtable_ops(priv->iop); + + spin_lock_irqsave(&msm_iommu_lock, flags); + list_for_each_entry(iommu, &priv->list_attached, dom_node) { + ret = __enable_clocks(iommu); + if (ret) + goto fail; + + list_for_each_entry(master, &iommu->ctx_list, list) { + msm_iommu_free_ctx(iommu->context_map, master->num); + __reset_context(iommu->base, master->num); + master->num = 0; + } + __disable_clocks(iommu); + } +fail: + spin_unlock_irqrestore(&msm_iommu_lock, flags); +} + static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; @@ -418,6 +446,7 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, 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 = -EEXIST; goto fail; } @@ -425,6 +454,7 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) msm_iommu_alloc_ctx(iommu->context_map, 0, iommu->ncb); if (IS_ERR_VALUE(master->num)) { + __disable_clocks(iommu); ret = -ENODEV; goto fail; } @@ -439,37 +469,12 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) fail: spin_unlock_irqrestore(&msm_iommu_lock, flags); + if (ret) + msm_iommu_detach_dev(domain, dev); return ret; } -static void msm_iommu_detach_dev(struct iommu_domain *domain, - struct device *dev) -{ - struct msm_priv *priv = to_msm_priv(domain); - unsigned long flags; - struct msm_iommu_dev *iommu; - struct msm_iommu_ctx_dev *master; - int ret; - - free_io_pgtable_ops(priv->iop); - - spin_lock_irqsave(&msm_iommu_lock, flags); - list_for_each_entry(iommu, &priv->list_attached, dom_node) { - ret = __enable_clocks(iommu); - if (ret) - goto fail; - - list_for_each_entry(master, &iommu->ctx_list, list) { - msm_iommu_free_ctx(iommu->context_map, master->num); - __reset_context(iommu->base, master->num); - } - __disable_clocks(iommu); - } -fail: - spin_unlock_irqrestore(&msm_iommu_lock, flags); -} - static int msm_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t pa, size_t len, int prot, gfp_t gfp) { From patchwork Thu Sep 22 08:54:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 608311 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 3F626C6FA82 for ; Thu, 22 Sep 2022 08:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbiIVIzM (ORCPT ); Thu, 22 Sep 2022 04:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbiIVIzE (ORCPT ); Thu, 22 Sep 2022 04:55:04 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C266538459; Thu, 22 Sep 2022 01:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BYahsBS+EovGIEJjNIIzV6MORykMpVwEYk9crzmWK9J60qBZvaO6HWxXcRnDfpJux2MU3EFyO73Ve7qzlJeLRpZYR41q3+VYe+fYdEfQibfeBSgj+hDCkowxiALqBJfGLTRfau4S6ngMXIJkskTvLEHD7K79lOHjnGfG+xDHARvELOgYIRTqhDS/pec1jE8TsQHQfNPNrmej3TC+EYa5PQ6EKaUOCPKYQmUlrLgiy/grFFgNAdU7yOPAc0nhgIGcw+CI/dShjSQn8nGWEQRmVknncbsqu6hRXEsuiIL8uCPOlUztBPssgQxSjNyDAscLnjqV9sSc5PjtrEBndrSiWQ== 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=R6RDcSdVHjHbpLbVw3O506y8KAleFfHcA4+qqblUE+U=; b=BwqeAr9S3lgePEOgylS5n8pBg0Cl9J9VLfpctfyorsq3IZN3Cor/08J/8NiN08Ewns4u+7b0vuO6+WoHpdkar7LCOf7xmQldBXnpgI6xWTk4svq/4eRC5qVOWNLXcV24QuHvNCilGeNN0o1L+/5oZ6EoYnKgwE2okWFwXFyBu+FUDlYLY9xtQBFlTtFEolsx8h5t09kwi1zcb+ckYtEDFecuX00yiYKgkfOnHfbYk8uGbiOBnYkArIstzqpqT468ocn8YQBaGQMZXw13hmYgc4hjxdNsaS/FGoWsC3v50f32pAZjroUvoXz1R+NSuciJANBYUY9Qp/Ncn0/h43Xjlg== 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=R6RDcSdVHjHbpLbVw3O506y8KAleFfHcA4+qqblUE+U=; b=hUAHXsqA84yZUoD0bXSYuEA2lQ8cT/yIJ5VDqm87mb5pUpUC3gnN/NLZWe1syL/M8r6WBjQ9jNk8s1q+ZhYTinpN7Nk71V4PUEEclcdKpzgw63DNEFYcbjiCWSZDX1aXUsNdW+7Te3SReABnHj0TcJWk4MUGL82TmUEW+2T57iU9xnfDCHFpSfkTus+ZYJmbBGs2IAMDs+D4cCjcZTTTaDNWp2Hx8sOpq9G0aGjsbKJmfRN9u+W0kuJm/uLNdKaWZJPc77VynXxjN3uSckOuH/rwbG7FzMI0jjw96dYL3PU81V/2nsqGIPsiETqY4CKxSk07itRB5xlkqHVV0i43YA== Received: from BN9PR03CA0952.namprd03.prod.outlook.com (2603:10b6:408:108::27) by CH0PR12MB5107.namprd12.prod.outlook.com (2603:10b6:610:be::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.18; Thu, 22 Sep 2022 08:54:53 +0000 Received: from BN8NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:408:108:cafe::4f) by BN9PR03CA0952.outlook.office365.com (2603:10b6:408:108::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.19 via Frontend Transport; Thu, 22 Sep 2022 08:54:53 +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 BN8NAM11FT024.mail.protection.outlook.com (10.13.177.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Thu, 22 Sep 2022 08:54:52 +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; Thu, 22 Sep 2022 01:54:37 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) 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; Thu, 22 Sep 2022 01:54:37 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) 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, 22 Sep 2022 01:54:37 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 22 Sep 2022 01:54:35 -0700 From: Nicolin Chen To: , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 5/6] iommu: Use EINVAL for incompatible device/domain in ->attach_dev Date: Thu, 22 Sep 2022 01:54:34 -0700 Message-ID: <9cfa41b3aceba02cacba33d86849277f5d1c3684.1663836372.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: BN8NAM11FT024:EE_|CH0PR12MB5107:EE_ X-MS-Office365-Filtering-Correlation-Id: 28b8cdb0-c53d-4d80-90ef-08da9c781d83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QjbgruD7s/B5fkNiPFa7U2d3l+gYO/g290ye3LNzZtGgIyThRInu4by6CZkELHQL0vUnFlmIDnCKe7MtbIbmK1vjQpqIP1UsDTXMLtpscGtuaLxa/RI+fUSautItFcp7LLd8ln8dLJJX0s96jsF8rjprKxQogvgkJdSqz/kJ7spTMJKBvfjqxhZ/1Qj1gQqb8HMiKbDUjFw98JVdhlqvN6zMyt/0PB8ABbN3TBvzMUxuhAuf3lY9Mf8q5mCmMmQDV1w4n7nmZc+OFiKWfnfiUGCeK3gTf4wUy9WOPrjoLqXsj6slzfN0bowMaWEaxzK7unra9GUYmmIbCEX59vWYMJv2Wyt59XJxQuoYx1T0GsRYIxQKru0GelDD7Fi9IUqpg11v55GarI44StUWM5rB8GSsVKoWHX+WwEkciKb6Tm23i/T9vrXHklRvyFwMloLtADe7V3/cxNeQtPu5Eo28SzgeTa8mvhNfu3hENx1dpsHH8AXqUfDBORQys+vKtEhmvgehBYSgvGSBo91lr9DyiJUAW0pIT2KkcvmFjl9DsWDZGTNVbOD5Akfa9zZRmXtEB9GjZ28KwPexsWcg4BC6N+s7JmcnJkFCXjmv+kjW4n9Qlv1evzubP0j3kHjg/W2HC1XzalJdrlm605jTtrQ2ri5Ayow6SH5C2HV/Z9ctfeJ3YG8tvtRN0Ag1HW4yP7f6gr8FbZcCU3ejWcTfkMP7mLrQBvgamL1aPl1O6OaSUd/9bDs1cOp4TovxsPFPYqNSa3ZDS0e8WnmXX/2uN00t+4mpjtFI7FAXmp5d1ZkWkGn56zRzyEtD6EL9gbqeWVco8fSgnlupLlr0wykucrILGh4eVBYe3qxZZTqzPnE39e0= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(346002)(136003)(396003)(39860400002)(376002)(451199015)(36840700001)(46966006)(40470700004)(186003)(47076005)(426003)(336012)(7636003)(82310400005)(356005)(8936002)(26005)(921005)(70586007)(70206006)(7696005)(8676002)(4326008)(41300700001)(86362001)(40480700001)(82740400003)(36756003)(40460700003)(36860700001)(2616005)(7416002)(7406005)(2906002)(83380400001)(478600001)(5660300002)(54906003)(316002)(110136005)(2101003)(83996005)(473944003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2022 08:54:52.9485 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28b8cdb0-c53d-4d80-90ef-08da9c781d83 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: BN8NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5107 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Following the new rules in include/linux/iommu.h kdocs, update all drivers ->attach_dev callback functions to return EINVAL in the failure paths that are related to domain incompatibility. Also, drop adjacent error prints to prevent a kernel log spam. Reviewed-by: Jean-Philippe Brucker Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 +---------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 3 --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 7 +------ drivers/iommu/intel/iommu.c | 10 +++------- drivers/iommu/ipmmu-vmsa.c | 2 -- drivers/iommu/omap-iommu.c | 2 +- drivers/iommu/sprd-iommu.c | 4 +--- drivers/iommu/tegra-gart.c | 2 +- drivers/iommu/virtio-iommu.c | 3 +-- 9 files changed, 9 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index d32b02336411..f96f8aad8280 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2429,23 +2429,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) goto out_unlock; } } else if (smmu_domain->smmu != smmu) { - dev_err(dev, - "cannot attach to SMMU %s (upstream of %s)\n", - dev_name(smmu_domain->smmu->dev), - dev_name(smmu->dev)); - ret = -ENXIO; + ret = -EINVAL; goto out_unlock; } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 && master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) { - dev_err(dev, - "cannot attach to incompatible domain (%u SSID bits != %u)\n", - smmu_domain->s1_cfg.s1cdmax, master->ssid_bits); ret = -EINVAL; goto out_unlock; } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 && smmu_domain->stall_enabled != master->stall_enabled) { - dev_err(dev, "cannot attach to stall-%s domain\n", - smmu_domain->stall_enabled ? "enabled" : "disabled"); ret = -EINVAL; goto out_unlock; } diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index dfa82df00342..dbd12da31707 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1167,9 +1167,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) * different SMMUs. */ if (smmu_domain->smmu != smmu) { - dev_err(dev, - "cannot attach to SMMU %s whilst already attached to domain on SMMU %s\n", - dev_name(smmu_domain->smmu->dev), dev_name(smmu->dev)); ret = -EINVAL; goto rpm_put; } diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 17235116d3bb..37c5ddc212c1 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -381,13 +381,8 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev * Sanity check the domain. We don't support domains across * different IOMMUs. */ - if (qcom_domain->iommu != qcom_iommu) { - dev_err(dev, "cannot attach to IOMMU %s while already " - "attached to domain on IOMMU %s\n", - dev_name(qcom_domain->iommu->dev), - dev_name(qcom_iommu->dev)); + if (qcom_domain->iommu != qcom_iommu) return -EINVAL; - } return 0; } diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 31bc50e538a3..b1788b3d3b2d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4181,19 +4181,15 @@ static int prepare_domain_attach_device(struct iommu_domain *domain, return -ENODEV; if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) - return -EOPNOTSUPP; + return -EINVAL; /* check if this iommu agaw is sufficient for max mapped address */ addr_width = agaw_to_width(iommu->agaw); if (addr_width > cap_mgaw(iommu->cap)) addr_width = cap_mgaw(iommu->cap); - if (dmar_domain->max_addr > (1LL << addr_width)) { - dev_err(dev, "%s: iommu width (%d) is not " - "sufficient for the mapped address (%llx)\n", - __func__, addr_width, dmar_domain->max_addr); - return -EFAULT; - } + if (dmar_domain->max_addr > (1LL << addr_width)) + return -EINVAL; dmar_domain->gaw = addr_width; /* diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 1d42084d0276..f5217a4cb9b3 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -628,8 +628,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, * Something is wrong, we can't attach two devices using * different IOMMUs to the same domain. */ - dev_err(dev, "Can't attach IPMMU %s to domain on IPMMU %s\n", - dev_name(mmu->dev), dev_name(domain->mmu->dev)); ret = -EINVAL; } else dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 447e40d55918..be12f49140c7 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1472,7 +1472,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) /* only a single client device can be attached to a domain */ if (omap_domain->dev) { dev_err(dev, "iommu domain is already attached\n"); - ret = -EBUSY; + ret = -EINVAL; goto out; } diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 511959c8a14d..945576039c9e 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -237,10 +237,8 @@ static int sprd_iommu_attach_device(struct iommu_domain *domain, struct sprd_iommu_domain *dom = to_sprd_domain(domain); size_t pgt_size = sprd_iommu_pgt_size(domain); - if (dom->sdev) { - pr_err("There's already a device attached to this domain.\n"); + if (dom->sdev) return -EINVAL; - } dom->pgt_va = dma_alloc_coherent(sdev->dev, pgt_size, &dom->pgt_pa, GFP_KERNEL); if (!dom->pgt_va) diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index e5ca3cf1a949..ed53279d1106 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -112,7 +112,7 @@ static int gart_iommu_attach_dev(struct iommu_domain *domain, spin_lock(&gart->dom_lock); if (gart->active_domain && gart->active_domain != domain) { - ret = -EBUSY; + ret = -EINVAL; } else if (dev_iommu_priv_get(dev) != domain) { dev_iommu_priv_set(dev, domain); gart->active_domain = domain; diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 4c652773fd6c..87128266b6e3 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -733,8 +733,7 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) */ ret = viommu_domain_finalise(vdev, domain); } else if (vdomain->viommu != vdev->viommu) { - dev_err(dev, "cannot attach to foreign vIOMMU\n"); - ret = -EXDEV; + ret = -EINVAL; } mutex_unlock(&vdomain->mutex);