From patchwork Wed Nov 1 23:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13443154 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 DB028C4167D for ; Wed, 1 Nov 2023 23:38:11 +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=1EaNgm+HJMFmOwitw55k7cpeXO5BB6PO8IPi5TOp+/0=; b=TO6VXHdAAWNx+r PSPHInjwxgES4S1gq6rU5NdZQc/wuOGV0eY3DoPg42pYhf04Cv8GllAGYNx+239FTK0ENvKClbu1Z yTmai32Dj31sQ89yiLlmfJ8Wy7PDjarqQXZ28E6+hZRSPeOvBx8YZ/dNv1n4ZjqeiZW/NZwP8m39F RN+/VQMa5D4qbVTtI1id2b+L0tKBAuvYD7vjgDc0+U+qWdt9xtU6sNoh1jJcPYuU2XDt+kxJQkEdC D63FcodVi1/jMvkLXY1IVJXDegRZTPE08dOmzD1pB6S3d5v5b4z95Vozk4Vc59N4Rbtze/hf3BIe+ ZQgjOV1cOU+596crRFsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qyKmF-008KBV-0s; Wed, 01 Nov 2023 23:37:35 +0000 Received: from mail-bn8nam04on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e8d::62d] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qyKm3-008JUF-2S for linux-arm-kernel@lists.infradead.org; Wed, 01 Nov 2023 23:37:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mC5CmygunVBFighq6MKv2Td71CcbN2p1bud5rQhAuJWo+48ZP3H0HmWkM6tQKUWdhszOsL7ZrPTUrdB0rjDaztWsxcrzDIghOjCV6TOy0tqTfLKw7UVoSepjsm3/ncaDhjKy/5hsaJsV5SpIoLc+5zHhrWavDWeWojwYdIKYFGtWDlVDLdPPE3/1Mr0NW1ImK8+Bnqs3aJr1lgHy7Vn/kzhDlS0HPVPbcWOi0UbBkC1IAuMXA4bA1d1pkcLf/e8ysHet/++yEBGZMHc4Dv0997OIF85mvVF39RYNDkxLSb88WMKyp2gI8b7dbDXZitiCQjoLjhGtXAZfWtZ0tkHwCw== 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=DAROnw1Ms6tjK3l/yhCdIeSefffCoQAZEexrXSu4jWE=; b=mqNmJGyHce7yd5eY1o2974sNoNRpWVnh2il1goPyMoeAp7bEvyo0td6bonBE0qLfv+Mr5Naf6n00MN/OGfCLxwI/wFFEiYK5XYovNX00TyinzaiyT1YIKiU7nzUzKesv5gfbNUHJ1NGVqOX2dqi3130/R7HUQZu47VTIuJHHU03KoUYqwxWsninCtiLLSr640DEm49cnm90lSfae228F54GvFKKAoptA9q81uUD/O8Om/Z2ZojNJbtQKO5HGT6gwsHpmaE5B5vt3SBSLNDRyjK8SlU8mflSrCGXqzO+QOjGqDZrEqPKwRZ4J/zWQJdQZDYFEaETkh/GCHgJcLCoA1A== 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=DAROnw1Ms6tjK3l/yhCdIeSefffCoQAZEexrXSu4jWE=; b=qJ62Bwos4fzaFP65LvyI6C/rwUqMD68PbYeq4DHo1Eyy9nd5WUcufizCD0L9IWqYW7gEuEAJsni1JIVljhPLvVQUDi/3lfTgqPK05nD+w+Wg9aHFn1amwLBWR8LAQeCpCFx6/4HMQetOxU/eTHn1N6qVtJmAm4RTB/58bDE1uXuQJDiCEHY/8by75fq4YKoNKStRZ3XpRKWpV2JPOhOL5RtXXXtTmFkgzBIKnq+XTXIByx6h60eFEODwFVKjofUvA+gKjl5KBPcJy9+mRwkiG23Bgod/xnHFuyuBFa8cftzSh4Vv60ZCTifDLWxeiZ/ytTPK1W3m620CLqoKLfVMrg== 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 BN9PR12MB5338.namprd12.prod.outlook.com (2603:10b6:408:103::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21; Wed, 1 Nov 2023 23:36:51 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::b53a:1092:9be2:cfb9]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::b53a:1092:9be2:cfb9%4]) with mapi id 15.20.6933.027; Wed, 1 Nov 2023 23:36:51 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Jean-Philippe Brucker , Michael Shavit , Nicolin Chen Subject: [PATCH v2 17/27] iommu/arm-smmu-v3: Thread SSID through the arm_smmu_attach_*() interface Date: Wed, 1 Nov 2023 20:36:35 -0300 Message-ID: <17-v2-16665a652079+5947-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v2-16665a652079+5947-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0265.namprd13.prod.outlook.com (2603:10b6:208:2ba::30) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|BN9PR12MB5338:EE_ X-MS-Office365-Filtering-Correlation-Id: 98031a4e-52ea-442e-036b-08dbdb336a32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gmS18KKdjALN61WHISRfmoF2PHNJl/1mh/1NgJaYWH/IxOTQ9qLUCFjilqq6dbSDQdsFFYrp6Ymyjo5niG4RD0pgaa6oTH0BvBP4SegEFxWUHk4HW1tSEkdG/BXZkEldTP33mqzMj3UoTBJQrUirQyPQLq0Xekwowh6VOkNsSok3hTHGgJx3P8DGQDulWIKYPZw4bu7MlmQAaHYVOhoGrTjTyW66L9hdpdaKLAVFZ1vQBpv64GcNUQjLGx3UzYzg2iPK9IIIuQ3p2bnXnCMrr9781J6kI7PUXO0MNSBs/Gy2iuK3jlGLshNxMV+lFM8E8v8ltk/Ac3BEKdyuwwEQlm7XjgkZT//6/H6C+ZA3SASsjAAxKEkliElOGxbvQ3Hsj7/MsPRW0DZqfufEc6LUZzuiNo1rmr8MHEsONtuHT6GaAL0fWBKBNlUo3zSeSH8a4z8cpiZnDNEL2kYgnc6x7TWVV3+omU8gudCLGzjR1iSsvV0CMIjnW6HLykP7KiCcBnl34eKISFMejI22nj6LQAmJ9MzIrAavFrFYwnr5PGLQnroWo7EqsxQmhL8hgEjM 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)(396003)(39860400002)(136003)(346002)(376002)(230922051799003)(451199024)(1800799009)(186009)(64100799003)(6486002)(2906002)(478600001)(36756003)(54906003)(66476007)(86362001)(110136005)(66556008)(66946007)(5660300002)(41300700001)(26005)(107886003)(2616005)(38100700002)(83380400001)(8936002)(8676002)(4326008)(6506007)(316002)(6666004)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DRie91kSlrUiLtPgwwnw48wO4FP4a3O+yMA4/O85Sr7LzdxZgq0PH0xsRCHXXolPFCV2XaGeWa8znGVPpZ+tz4DxA7plnBY4ld8xMrZ2BxpsVbGf5k4sRs/cFmuKt/FiXLALkHfCOEO/KovjcFyFJZi1TjyfUXCHp/qDUv+lHSqgJOThFB7hknZy03CQZsVJCmj5i2GN4B1SuHdnuYgnYkJS8E1thfdvvJCRKeDLDpYI1PkZFmGzqhgtK2oKiRNGoyLzFH6GKjKrSmaGmT/ZwCBAEwgolTAYgvAgBVA4OiSX4s406ilERJVYpVk98BIWhRI2OJgIxkjRQ+dfigvbDBBhMHj+gnNI2Id2qFtU+ZX7EW1yhsBfFdRZyk5kiULBeNzLHgSSo9btb/cbeWqj9e9GzEv8To/Ynv+Z1b49YXnWeEmrxsAjI9RVAfcHLJTMUbyjJdZGdVgf8IBEDio/tv5NwQCI7OZejalGCAOvcIkDDLCAJMYv3n2jaXQd+mj6eWZwU+ivnH5G3XDI7z+OzYDMUlqhj3etFtWyqnRLtz56dN6TUNPeQ67X632WPWTb2CH2gLgYsP1UMBzfIUjS201WmSqtK5YOGIKPQARw+/eCyvA5Dz28p05GPW/W9bdtAqX4dF85WLdrv/hBOyd2WK3R2hrWJax5rHTFXSNPmqVqijg4BVaQNUi0lyvhEHJqw/Eg+JmtYTvRIbK5+Niqpuj4EuX4vbG2k1poGNxG2idEAswkXxNJaV5rT/OqO3IjvQnoXzBCDE1r2LUIwt8NJGOZ6W3f6Tm282FAUHHBMW86xFABtU8rpL4QS3aknfdejlr4HZvDm9rG9k1UlIMdsMuj5eqTkKPx5DE0VNYUIpxnBZAqgnnK1av7i4iHh4b/esfWUYBBUThUDz+ow9cnWsWKGyjc7Vpnetbe0adTXIvGqJAb1PoogM+CcMzEQcnSkExwfpFmo6letw/Bx55P0NUPK350uwntZftMa6J1iiawS+sB6JGwoW4BHDOZu6XgNO96bIM9HCC+0g5oXUFIixpyuTvzdVoYsVREjLwQTTnhEEubfFpFlW5LnVJjPj09ZVZXo0S1uKy7aIulQEAI63r9HqrjAqnRGuj0U04NxvawrFNG50FjRaO6NwddQGD/vemHuICCmXitVXkjePgR1+cceH0mjExdDdv3xDlbLyAewUoar3KAl0nwQLhQZDUviDD0zCaYlfefBZpu9Hk6uemhZJq6uE3cN/pHjQFJnr4cufvufBqeqxvwnP5Su0mwppEkDnMSlmvPMySyQ4DhzGS+pC5W9rK6L+vqsAuc3bIEb74HEDnQe68igfJ8sAoaCBlZSkinw5qRrSvC6eyKx05+80uoRk1TK6STCYMnCK+G0NiSMCzA+4O6MJNkd4qdt6FFpqpnCwAj5y0cmx6i+O+j3VnGFGRk62esw2Dr2F+J1c7D3upK0ja29AUCbYMrjbJM6FqMSme5nYCrEeC0QV50T7kzNrdO7RGPJEVIB0O4/qoia5KIotE9uue1whoFhUW+CXdXn6nVu0guX/pa43H3gF+qI1ycDZ/r7BVViousKLEXloCFWKxVoRVPcop8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98031a4e-52ea-442e-036b-08dbdb336a32 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2023 23:36:47.5478 (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: zmGM++Al5/rYpwKfxG3JsCvJXWYRcOI+p5ywYU8Ij2pSXgAGXrLID3xSSpqcBate X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5338 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231101_163723_810519_FBA24F63 X-CRM114-Status: GOOD ( 14.49 ) 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 877bb8d69c0902..d9174d609659d2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1962,13 +1962,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;