From patchwork Tue Jun 25 12:37:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13711070 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 71E36C2BBCA for ; Tue, 25 Jun 2024 12:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=RiQNhmMdDikOXGESry1EWwFazvSFA/KajKnQo4+YLMU=; b=STKQLgic5WnnwbqWb/iPRvohrw sNMU26osDHVG1vsaJjWQx18Y7JpVNvvgROpHBto5XooWyjFyvu5izl7ZLFQ0Grs/lMviay1hUmyja cSuBn++a2J5JAs8wwFG1HbxhTFd/yeJ6YbvHdKnNrQJ4UGZQStYjo55NlICiWUn5Vnn/ZpRwUJSvn h+7RiewdFI/ICoppvDG26e30TpfaBKR5NkfgHhU56UG5wPHeU/WX5kyALkUrsHDtCZywMxOW1SxEe hWi3vyUCc5SUvzHMijqZBDsInIdKNlys+3Gbu8EUmSp4GOMVWTjIwkdKjpTnqRrxKnh9wYJOGSA6S gZu9y1qQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5R7-00000002nsy-2tKq; Tue, 25 Jun 2024 12:38:13 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM5Qo-00000002nfA-3D2C for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 12:37:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JfFtcVUAzGz81NjgKN2ZyiySEdTUbfzuvFDMaUkRydQKGLrV1oAsN79GnOQ5e2wYuMhgDI1X9kACyU6VaVnSv+pT5ZrLCYe/9VsXFUOQ2Yp+44LsZNB7Ry/IE3ysfDtXz91SsPk6nAC28Qv5wu2hmn3Ek6Gyvv+xZRSBdGYALJwuQ+Bs+MhzJnezt0FhdQUVUCxG62DfONZ2Y0/m+JDuL9PobOea0rSdMfDRLuQ3jkHuzhG+lpgv/8qpTTKBtTgRKtJAU/IdQG3HayuMlTFP9bcSTMwvYI5An4MCA35h3s/Tzu7c/F+vs/YA9r54oQ6TgGvZU2Laz8OTW90KiIBr+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RiQNhmMdDikOXGESry1EWwFazvSFA/KajKnQo4+YLMU=; b=P0aw/fsa6K13UkdKd//jH5Tr05xieHtpcFwHujCuM3Wc5j0JCVNY1AZ1N897xnbIwXByRDnuS9yw5ZVFt5/DVIYv3XEiRBV+jovMrBLlcQkvX+qpdkonGZ7BANJSXjlKXVh+Qy04IIDCtnCrzGWr4r5juPkNeQSsCFOhyTRXaZuw8/Ryp5hfVnSbbRGFLDk5UnV403qfKKYKggRoi/NbSkkZa6hiT5gGtRhBdT6zSZNFkeEIB5CVTGkBKiQjWB6MHayBAPWXLtq/BtAr+hVJ5sUxpmarEHLDR6bRsHMLu7SOVfC8DMfU5BJ6v84yAdCNIR3b7pyfLJs9s3//8d1+7A== 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=RiQNhmMdDikOXGESry1EWwFazvSFA/KajKnQo4+YLMU=; b=kZou4tYvuoHTBofQLcLVYjMpPdHFTCcuq3DttunY9MxpTl24DQgJQcM0JRuUtaJUzr9KVsDlv31b0vDGF5mwlHUoQ8mMkRK3lkZZWwc+6E59b4iUGxtB8m03SO9bAjGGLR4hKje6bgdGPapofVtcDeBr/C6mUN4Ro00lF+RVyvcLbzdd/e7s6220h78+j9r4To7dXPPz+ySJKMKtMYPnl6i6Fz1J1SlL3IQj3LTlo82u8AXQYmqucQatzX79CvQMAkgAwvu+1NGhoeuUnznneIw6U9dDikMnjqT1JrxI/DrGELoE4YzS+d3eHUrWCPodTxMQ4rehlPIDDctduPqicg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by SA1PR12MB8946.namprd12.prod.outlook.com (2603:10b6:806:375::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.26; Tue, 25 Jun 2024 12:37:47 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%6]) with mapi id 15.20.7698.025; Tue, 25 Jun 2024 12:37:47 +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 , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v9 02/14] iommu/arm-smmu-v3: Start building a generic PASID layer Date: Tue, 25 Jun 2024 09:37:33 -0300 Message-ID: <2-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v9-5cd718286059+79186-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0022.namprd08.prod.outlook.com (2603:10b6:208:239::27) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SA1PR12MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: ed97b583-3157-4631-6aaa-08dc95139d95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|366013|1800799021|376011; X-Microsoft-Antispam-Message-Info: 8WLJbyrueB7Nl45DjwZo79OLbZ2nFt50KfAfrhoYv0vvd65rLiGZS2F56UbJYJ+Qv93Tgo93Oa25d3E/gGH8Uxdeto6yaK1O0fAw2IpAHcGEViIYGB61hXdLA+H9KK62XODQzo9GzmnEh+qIygHNKPZim+JJogFFAuhpAM/X62WMVPeQyKQ8qR+BmmKzkyLrdlw324XA6wxMY+WX3iEpprZOr86loPPbzZfv15aj+ObXSAb+a8/iKgJEcIGXlko5mpR/6QPCs4GhNG6w/Kw/ckbLV461b+0VJ9UWLeFmVO/Hgt4kbkmlZwzrLvWbpTq+V+ddAtbCWuWmJ94+p+hNP4Rhm+aawzhw5Pp/hA7sXEuIp/1dAx4/HDGVDGumZBWsCLzGuF4Or2QAPOHxw4p7f1Ew9alQ0znoNYyRFRY9bJmyGaP6H87qJfmwSqQlRQC9akbEZXuNewXLCD/vh8h+kYjcTFHlA5z5dfOhUOGCjVzH2LlPfQO98O2VDLI3EzZqVOGvg1RCxEtzL4oaszz23RrHMdzw3s+KLMs1L6YSZx/R9VyzKtwJVp3HZ5wc49hCstgT3xNhOXkeQkZB1kfqAQAd2+81DAhcmUGc8wLxJ1uHo4HZXGqrnf9NEb5OHIrXBTG8+GgvAc8MuP43n4iSsfBuDZo6aVgefxJ4EkGY5iy+OEUTH+xlO/pMbHlYhxQFkw07D9odP5ucdzVkrnO8G8d2HZPsok0J/mpWW9Ty792NFhjE9z/GuXecnwLgowHsDIDBYy4MD8N5FACUZbwSlGIWp3tB9MhPR2wAOoxKVnoB348vlC/7SqkTJS6Vv0rn3m6vLsD2rhD8AF7drtq8VPDS62ujpYzIYbttf3r69dhGFFrm2RneehK5gc29pkDue3x8KsmT/98AoWuYrgoYisr5Gaf9NAJeMrovY907piC28Q4YF6HyqL4wEFpA3fxrTfLHLi5fCW4j6O4a13pPnBg0PsQCvVHQTjvSVv9KW1MIWYGcbXW7MtB4h/N8+anR/Xke4ZXzID/h6r2PyFksAJpioMZ+pZO9PNWJTU5A0anQ8UAY7ZGJpgcrGHRS+3sTgKw0n7cBW6KuppVGNEaxszMaiPhmqsyJhU2sRlcD2BYadTN2BBEtF6WsOCP5+w/Up7NspygI+Ko3nEqLfLeMOemwZqbArSBE/0hdTikQMAnJbgrVTNThUwjc5JTAzSFODFXiiiMoGCC41e6P5jEV7LSr+OZKkjI11kydvWbv+AvwiEv1Mv97Vunrs5cd8UT7pbq92Yn8AFI7F2xBNjuUcfsXgrP4wcsttS6fmTKuLYc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(7416011)(366013)(1800799021)(376011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4lPuljBv07SiLFSrqZXfYedVPj87IWZkHqzAz91+Y07FsyQQLogXF1Bn0ro2wwbSaO9vTf8zmR1O9WKuhSLLSFfXD2RmuHcOPy90RtLhAg67CYpMliLCkeJSJ+xTem3YCNoSDITSWGR1sNiFIpKd5huGzHU6UyIQD/X8fiO/CkTTUEc9qLR5TqrPJEqig6fxhrDxXQhMdNFOhqzfu2uF7kkRBHIDJBQGzLkuThY5ZqGOKdpCHwp+gYQbK7+bwM/eOgWxgWYnsLJebBRe99LrLO+kERJlDQh6yf+7wp/oaH7BPBE8iiFOKPw051vq7sgb26GjSvYSWJYqsZUxZwMf84mBWKA2KN+osA12svxY2Z7vKN1ml7L6onV7wYNvTc5MeU7893K7MqELM1qELLQRuumX068OsuOETVm3cjWYzptgz5Q8i0cmBBsmHUW3PJqY7uAOpEND6ikfKVZ8Xvhd91L1D3DWQeuw24mPNoXRtlgLvgTpZDxnP5vMWelVSshTPfP/PT+WWmqVjHX1NURJuQiGOSm8hFAueJQicQ/wgk/YyseEoSSUm9bWK4qyOE72CRYNDkqmPBIi7DHfcgf8ER3s5FOx8zNrPMEHRomIB0iXw726ldPY6kfQciio5Lr6aJSJ18FysW3pjp2l3EfVfRVcokJr0AcAHDMBjEcDXuqv8Yl/w6sdWPwabksrQN5TjMjU39lmV9Iu+F0qvoSYUsh4m0boz6MllqcL4Q+fTIO7kPSQtGKo8QRu/kU2yr7s1mMjzi9vDgAYjAiCJPQRnMCcSuPCl4TJcEHXNh4ExGyj8z6RydQd0OESs15vD8dIV6oUV0neHKfPn2DitrW3qRg5yVAI+kv2FUxFCA6xRPqW17f1PQnVA77LNpgdoX3KsL6i3lwnk3LvXh3CHeaoKTh1J2Caie8EJX/3MFGz7u+IvZ6LtsXwIXmqARQ7lUlFxRZQTNW95zYuT8SUvujhsoN/Tiv3CeZ2rgRoOLRiD/6a6rqTtaENnrIQgU98Li4XOuDZZF/Nr1GeLBmlNMqRejcE04bExE2KCWCb2lrXWRVFnHDb8rOHUSLcsmkD+YR/fA+XKnYrLiiFnHRra/5eQ1tGsepFM7OTJgqSGXzQ7Dcvo7jw/RBbLYlxTikuKUTUtwyXevXGRhtv1YakQIeFR2UN66iXzWzlF1rabU7m90kJQGVjyis7qfnPfDGBJ/Uv8nfh9YQlfBTPSl5Y67dDTts0m1ZoOgwZrASvVrlxP+m/WXYobfGRpkmGq33BG+2IgeXVGnk0PCUFvRX5cZqQh4PTYgJVEslmXrOTGn32Jmjwpb94Tu/mP/1PICFKqJNTudXrgXOrTuLCs1twQVNpW2vbC3DEH+Pjxl/lzTbVjkSGAUfhH0ty2DhwPjB8TN1cIn8xPbEGFNJpDmDBw5gaq7gAVq9lozbjeawXU4hw82NYBvZuz8K/JsXp+6WIytxMCLgYv9lLhdaAiZvPx8Timw0wFIaQKc9v0BPCqBjBGPJ70f37WeyRz8MTC9G8hBVFZhgFwINGtGYB/dzneHT9tHGK5ZlnO8qVgAYWL/hmGpXVG2YteSKyB0a8wWeHJ0D4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed97b583-3157-4631-6aaa-08dc95139d95 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2024 12:37:46.2611 (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: L5NFu0OPLXLhdOKxPjJfyTqGccFBW5d2QrplGiQo0N/KgK+BoSt2ln8LWs9iwaWi X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8946 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_053754_994541_678AB494 X-CRM114-Status: GOOD ( 18.88 ) 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 Add arm_smmu_set_pasid()/arm_smmu_remove_pasid() which are to be used by callers that already constructed the arm_smmu_cd they wish to program. These functions will encapsulate the shared logic to setup a CD entry that will be shared by SVA and S1 domain cases. Prior fixes had already moved most of this logic up into __arm_smmu_sva_bind(), move it to it's final home. Following patches will relieve some of the remaining SVA restrictions: - The RID domain is a S1 domain and has already setup the STE to point to the CD table - The programmed PASID is the mm_get_enqcmd_pasid() - Nothing changes while SVA is running (sva_enable) SVA invalidation will still iterate over the S1 domain's master list, later patches will resolve that. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Nicolin Chen Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 57 ++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 32 ++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 ++- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 28f8bf4327f69a..71ca87c2c5c3b6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -417,29 +417,27 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) arm_smmu_free_shared_cd(cd); } -static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, - struct mm_struct *mm) +static struct arm_smmu_bond *__arm_smmu_sva_bind(struct device *dev, + struct mm_struct *mm) { int ret; - struct arm_smmu_cd target; - struct arm_smmu_cd *cdptr; struct arm_smmu_bond *bond; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct arm_smmu_domain *smmu_domain; if (!(domain->type & __IOMMU_DOMAIN_PAGING)) - return -ENODEV; + return ERR_PTR(-ENODEV); smmu_domain = to_smmu_domain(domain); if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) - return -ENODEV; + return ERR_PTR(-ENODEV); if (!master || !master->sva_enabled) - return -ENODEV; + return ERR_PTR(-ENODEV); bond = kzalloc(sizeof(*bond), GFP_KERNEL); if (!bond) - return -ENOMEM; + return ERR_PTR(-ENOMEM); bond->mm = mm; @@ -449,22 +447,12 @@ static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, goto err_free_bond; } - cdptr = arm_smmu_alloc_cd_ptr(master, mm_get_enqcmd_pasid(mm)); - if (!cdptr) { - ret = -ENOMEM; - goto err_put_notifier; - } - arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - arm_smmu_write_cd_entry(master, pasid, cdptr, &target); - list_add(&bond->list, &master->bonds); - return 0; + return bond; -err_put_notifier: - arm_smmu_mmu_notifier_put(bond->smmu_mn); err_free_bond: kfree(bond); - return ret; + return ERR_PTR(ret); } bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) @@ -611,10 +599,9 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct arm_smmu_bond *bond = NULL, *t; struct arm_smmu_master *master = dev_iommu_priv_get(dev); + arm_smmu_remove_pasid(master, to_smmu_domain(domain), id); + mutex_lock(&sva_lock); - - arm_smmu_clear_cd(master, id); - list_for_each_entry(t, &master->bonds, list) { if (t->mm == mm) { bond = t; @@ -633,17 +620,33 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id) { - int ret = 0; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct mm_struct *mm = domain->mm; + struct arm_smmu_bond *bond; + struct arm_smmu_cd target; + int ret; if (mm_get_enqcmd_pasid(mm) != id) return -EINVAL; mutex_lock(&sva_lock); - ret = __arm_smmu_sva_bind(dev, id, mm); - mutex_unlock(&sva_lock); + bond = __arm_smmu_sva_bind(dev, mm); + if (IS_ERR(bond)) { + mutex_unlock(&sva_lock); + return PTR_ERR(bond); + } - return ret; + arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); + ret = arm_smmu_set_pasid(master, NULL, id, &target); + if (ret) { + list_del(&bond->list); + arm_smmu_mmu_notifier_put(bond->smmu_mn); + kfree(bond); + mutex_unlock(&sva_lock); + return ret; + } + mutex_unlock(&sva_lock); + return 0; } static void arm_smmu_sva_domain_free(struct iommu_domain *domain) 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 bd79422f7b6f50..3f19436fe86a37 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1211,8 +1211,8 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; } -struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, - u32 ssid) +static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, + u32 ssid) { struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; struct arm_smmu_device *smmu = master->smmu; @@ -2412,6 +2412,10 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, int i, j; struct arm_smmu_device *smmu = master->smmu; + master->cd_table.in_ste = + FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) == + STRTAB_STE_0_CFG_S1_TRANS; + for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; struct arm_smmu_ste *step = @@ -2632,6 +2636,30 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return 0; } +int arm_smmu_set_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid, + const struct arm_smmu_cd *cd) +{ + struct arm_smmu_cd *cdptr; + + /* The core code validates pasid */ + + if (!master->cd_table.in_ste) + return -ENODEV; + + cdptr = arm_smmu_alloc_cd_ptr(master, pasid); + if (!cdptr) + return -ENOMEM; + arm_smmu_write_cd_entry(master, pasid, cdptr, cd); + return 0; +} + +void arm_smmu_remove_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid) +{ + arm_smmu_clear_cd(master, pasid); +} + static int arm_smmu_attach_dev_ste(struct device *dev, struct arm_smmu_ste *ste) { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index b10712d3de66a9..6a74d3d884fe8d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -602,6 +602,7 @@ struct arm_smmu_ctx_desc_cfg { dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; + u8 in_ste; u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; @@ -777,8 +778,6 @@ extern struct mutex arm_smmu_asid_lock; void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid); -struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, - u32 ssid); void arm_smmu_make_s1_cd(struct arm_smmu_cd *target, struct arm_smmu_master *master, struct arm_smmu_domain *smmu_domain); @@ -786,6 +785,12 @@ void arm_smmu_write_cd_entry(struct arm_smmu_master *master, int ssid, struct arm_smmu_cd *cdptr, const struct arm_smmu_cd *target); +int arm_smmu_set_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid, + const struct arm_smmu_cd *cd); +void arm_smmu_remove_pasid(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain, ioasid_t pasid); + void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, size_t granule, bool leaf,