From patchwork Wed Dec 6 17:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13482107 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 63B6CC4167B for ; Wed, 6 Dec 2023 17:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xAnuPweyUXR4T862u9iQk3nXpQNwFYfCKAVh2ux5ZB4=; b=Y3LPrTIPrtRq4m ICO9pfg4l0/kQhAWvVp5IvZ7eoU8xUloKTZDzonONUyXqRkxoPUQEIQKwjf/2uodtvpQJWnQylsjr gm2ill98IwrZfkEeiTMyek5JzRGnBAWyUgR27tO/GUO5NtlZXZ4vsnrLPBYZhHne3VTIv+9q0YD// B+HzSz/Jt6nLmf0rERbEkfkPdL16kv84mNNNh3LMbLkie/oEHiKatDaAxiVHRLOEXRRC3Rr3RAg+n /7DsX4t0Nc9Jltsq+bwIL0pfSbntIcKd2vxJOmssOLqgeJY+9qNsMSvQEFvvzVa+0eKMtefSC72tk vwBzpx/OIYacqa5RHgXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAvi3-00AtqJ-0A; Wed, 06 Dec 2023 17:29:19 +0000 Received: from mail-dm6nam11on2062e.outbound.protection.outlook.com ([2a01:111:f400:7eaa::62e] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAvhc-00AtFn-2F for linux-arm-kernel@lists.infradead.org; Wed, 06 Dec 2023 17:28:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QozAT6tOlwNm57TTQXEGaMTPN/b1uyj1Bn4nZxWyceSNZspXLJY3D257bDcOFaUWXKfmj4JyyqzieijaGb/OxkS+7JVHMsAxt5ClCBdssZmovg7ovkuz3aax8LjrY8t9C9dPbeMidwFnb83kNskGoRHKIGoSuO0OMgalZbJr8cdKgsO3nPWHrSct/A8eOIGGKmVUTTRCquWSC3rPzmSxls7xmku+lPKwDKETYqrCsqLl7cSiwm7pl2bdHBGdqrOA5q7jcgo5KSEfgCQ2YZrdGwOLWma6pNIe2ID8hwFqe7tF+LLC96r2Jp7o3LMWD8cGZnlMRbZmYSrBWHxN3VpKKg== 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=B5kMJb17X3q2OlpYDtvCNFMDA85eXN62Bg/rYC505wY=; b=SmRb/crVntAPpFbSNntnV9BNfxFm1EacuNJNTRquoLFNwQ2XB7YJFbuDK82M5BjpQ6br1LRqg7sTTSXw0X7P3cdXPPomiCP592JXXM/9UbtyozU7bvyQH6Gl+yjPh5Za3WJjh92mkRSfOcV8IFZPmvoNgdD4fDfbJNmn9gXSJ81XxwFlJN194fjzXN9kzZ7HjKF7WTTxRpxLcV6FMr2n1bNu4wRCHaxf/bONMnEVG6XaO6YUOQ7qANG4kqPiJhhauBaWnPfjIL9PHHvoE4Wo48XG7APaL8AqXIZhcmKzFD2K9HZ0Zomic1myr2JsJ0QT9HLyrhnW7b9cAp+2JzWYdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=B5kMJb17X3q2OlpYDtvCNFMDA85eXN62Bg/rYC505wY=; b=mhq0M7n7cvL7NDIhO17WOuOz1GBnF7rto5qb8LNleJ7+Hl4J2T6ZqfM55pr66Ufym/DEI2PZag5Q5NcMnLijSE+uQxBFZMaLP2JcpPHzmRm/MV1lBJJTCYOctw/2rSyr5lAv0OLrVk02h34mYEnL+8mKUrTI0pHIZLHOe0o43bss2TzrXvq2UgnxvCdU+cp5SGkYFvgblPoyPpNag9H03hJXvkvzx0MXb9Eub9xrNPZfcQI6f4Dl0hHuf4R0Qpv0mfbaszUoae4IbcLJC02/yFM1BJ1Ru/Gm8TO2V9D6zq7UAfVtXBv8s4DBDWu3uoXX55/sXxo+79sysP8oN9Ymzw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CY8PR12MB7364.namprd12.prod.outlook.com (2603:10b6:930:50::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.25; Wed, 6 Dec 2023 17:28:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.7046.034; Wed, 6 Dec 2023 17:28:39 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v3 17/27] iommu/arm-smmu-v3: Thread SSID through the arm_smmu_attach_*() interface Date: Wed, 6 Dec 2023 13:28:23 -0400 Message-ID: <17-v3-9083a9368a5c+23fb-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v3-9083a9368a5c+23fb-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0011.namprd22.prod.outlook.com (2603:10b6:208:238::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY8PR12MB7364:EE_ X-MS-Office365-Filtering-Correlation-Id: fb920c62-906a-4634-830d-08dbf680c627 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eflRoCAD1J/+uif1so+VSqd/sq6S+au2Dct0xCkr49IejP2iDG8li9Yzv3TL0y4lLXETbyog4PXeTuIcJVKFTm16v1NtT+u/KEjnfXh1liHwwBGFFyWwlY3lvyHXDwkIA7X/07NI5hoetyD4Zt94YK6jL57NFyt9VlGn9QBr17Tgh31mRkRqOxmNi5gjKKZYjNQdKQyaJYFfuW0liWKvgk61XtFe4D7K8+eo4FUfW5rLWYUOiwQQrmOea2VdrS2DCzAJT1UUgYdBw55EmoYWaQ/YLQB6H7VHMFQpxJm+8UBwdl10pzVGYLoX9ZUAkRnheh97HMXQxKXo+mcyvgQ4q8KmWLvX9Gn0HObLKf4Oj7vlj+1em00xLIH2a8yd8j9uOn/CkiMp5zhjSYM8QDYPNrr/3xl3/l9iFr4tvkqwjchFPgJ8dLs4IyzDzac25Dn06ANxw/49/DuZnH/DL8PJWbDzo2Czy9Im6uIKm2NWkcaljr8kQqFSGZblylBjmNMMJRq8/vkcZNj6s5wMW9cyWkysebM/DROCpZM7FgX+Cj7at+elz023LGbJCs9qsERn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(39860400002)(376002)(136003)(230922051799003)(64100799003)(1800799012)(451199024)(186009)(8936002)(8676002)(4326008)(2906002)(38100700002)(83380400001)(7416002)(41300700001)(36756003)(86362001)(5660300002)(6666004)(26005)(6512007)(66556008)(6486002)(478600001)(2616005)(66946007)(110136005)(54906003)(66476007)(6506007)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oAivjkaDZmZMG6LEOBH/dtV6ZrFcnxvnRrUv3qWqfC2IGIl7aQ+WdC49DNjWQunekGPpSBwImok9N+S2qze+yfWAVRqSdl1DypoE3qE0YJ/318+0hjZ2dRFncKDCwCkuyfVJI9reybPa7Myen4mR+21OMeUszF1KEsqmtHvCPhe0fovVpKc4kbKZfPJZ6rWbbLt96CemeXcqZDX9CaJBPsNXDirXUesYZ9S1vWEcUwH8eGTiyQOb+jJM1Dw+HmKPxlv/xjm/MMc4KclOML5yqAkD3JoUSOsi3PeBsmx0dyoQuMfrLYHgHWbfChi+7+M41MZ3eRu3fGNuBD49SjLJn1qIGGFGhOYrHndwBrFb1P5tE4UAdCcnQi65IZzwm0Z1nFW1bJNPTzhklJwejAvV0+0uFeAuiIM1ZoxwC6n11bkure3ItbdYg25b7te0reAe/2dXX5rT3Gaw9YS/cjhK6urdmAXHedP+5OHOXGXIq0FbBDMWJQaAYI1/DyWkuJUUPr4HVNiV7CG6p2HwGbr5e1JQywKO2C5H7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idia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb920c62-906a-4634-830d-08dbf680c627 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2023 17:28:34.5015 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wevykx50v299wZUQmzOP36QcWrzyChrN010IBVOA6wsZzQ2QIuP/yTkecUhYooyU X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7364 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231206_092852_762444_C3BE17C3 X-CRM114-Status: GOOD ( 13.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allow creating and managing arm_smmu_mater_domain's with a non-zero SSID through the arm_smmu_attach_*() family of functions. This triggers ATC invalidation for the correct SSID in PASID cases and tracks the per-attachment SSID in the struct arm_smmu_master_domain. Generalize arm_smmu_attach_remove() to be able to remove SSID's as well by ensuring the ATC for the PASID is flushed properly. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 33 ++++++++++++--------- 1 file changed, 19 insertions(+), 14 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 5f6ffd816aaee6..a6cd4699ddcc76 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1961,13 +1961,14 @@ arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size, cmd->atc.size = log2_span; } -static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) +static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, + ioasid_t ssid) { int i; struct arm_smmu_cmdq_ent cmd; struct arm_smmu_cmdq_batch cmds; - arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, &cmd); + arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd); cmds.num = 0; for (i = 0; i < master->num_streams; i++) { @@ -2452,7 +2453,7 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master) /* * ATC invalidation of PASID 0 causes the entire ATC to be flushed. */ - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); if (pci_enable_ats(pdev, stu)) dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu); } @@ -2523,7 +2524,8 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, } static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain) + struct arm_smmu_domain *smmu_domain, + ioasid_t ssid) { struct arm_smmu_master_domain *master_domain; unsigned long flags; @@ -2533,8 +2535,7 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, return; spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain = arm_smmu_find_master_domain(smmu_domain, master, - IOMMU_NO_PASID); + master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); @@ -2554,7 +2555,7 @@ struct attach_state { */ static int arm_smmu_attach_prepare(struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain, - struct attach_state *state) + ioasid_t ssid, struct attach_state *state) { struct arm_smmu_master_domain *master_domain; unsigned long flags; @@ -2570,6 +2571,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_master *master, if (!master_domain) return -ENOMEM; master_domain->master = master; + master_domain->ssid = ssid; state->want_ats = arm_smmu_ats_supported(master); @@ -2600,7 +2602,7 @@ static int arm_smmu_attach_prepare(struct arm_smmu_master *master, * smmu_domain->devices list. */ static void arm_smmu_attach_commit(struct arm_smmu_master *master, - struct attach_state *state) + ioasid_t ssid, struct attach_state *state) { lockdep_assert_held(&arm_smmu_asid_lock); @@ -2615,12 +2617,13 @@ static void arm_smmu_attach_commit(struct arm_smmu_master *master, * SMMU is translating for the new domain and both the old&new * domain will issue invalidations. */ - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, ssid); } arm_smmu_remove_master_domain( master, - to_smmu_domain_safe(iommu_get_domain_for_dev(master->dev))); + to_smmu_domain_safe(iommu_get_domain_for_dev(master->dev)), + ssid); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) @@ -2666,7 +2669,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) */ mutex_lock(&arm_smmu_asid_lock); - ret = arm_smmu_attach_prepare(master, smmu_domain, &state); + ret = arm_smmu_attach_prepare(master, smmu_domain, IOMMU_NO_PASID, + &state); if (ret) { mutex_unlock(&arm_smmu_asid_lock); return ret; @@ -2692,7 +2696,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) break; } - arm_smmu_attach_commit(master, &state); + arm_smmu_attach_commit(master, IOMMU_NO_PASID, &state); mutex_unlock(&arm_smmu_asid_lock); return 0; } @@ -2757,8 +2761,9 @@ static int arm_smmu_attach_dev_ste(struct device *dev, if (old_domain) { if (master->ats_enabled) - arm_smmu_atc_inv_master(master); - arm_smmu_remove_master_domain(master, old_domain); + arm_smmu_atc_inv_master(master, IOMMU_NO_PASID); + arm_smmu_remove_master_domain(master, old_domain, + IOMMU_NO_PASID); } master->ats_enabled = false;