From patchwork Mon Feb 26 17:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572522 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 57B5BC54E4A for ; Mon, 26 Feb 2024 17:08:51 +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=+Vf6vRjn3KzxVbFTHlzEV6l4ZuRVfDLkhMICJy0Mpg0=; b=USfCG0Ie41q8yV Lr9GRResACy5bKJWEZw56FBvNnqdbidm00zWmSUd+4nShFT+rQFllA2kbRSasICVEgThX6etKAU3x XErp9hEhnxIFKVeb4nqIqLT0/ySKEI1M1ak0sg2BIRd3j+8P42IzpysCa03A7DYVJuEVyjRykndaX hEUCpGRvUnmcKuUIx5cn6y6aahvOQhNMm99fLAe7Af/MuF3XzwgptQ7WRiG2207SHEeIMoBWZLFcT GBCZlBtKgJKGEqnS54tmG5/i7d5LUx9RnRHbV58N2v29IFnWzr1nGWxLeGq0EHNYOEnQoG+rfgMb9 aYRQFj6dXYPFIQnvg2MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSz-00000001qDK-0soB; Mon, 26 Feb 2024 17:08:37 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS9-00000001ph5-1iBG for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BC/pqbE2MQ8pc5oAxDl7qZo1Zecx/EZVV/Gn47iSaxcLT8H3ELGM2AKLz2eg30EkL7u0XtYYK5izF3JWKwsZQ4klo1NWim3UjbXaVMkdz3jI9/y5yiQfqSR0lL21SbGfu3zbb14u5iwfA4v/nA1AWV/Z991P5nTQp8rAN49E7pp7dGVzdOrbtw20swpg1R07d3nGHXhVlsSGsH2S/E5rIKlQTjqt5cPTLjcz3/6CLtPD3mn6hLSyEuo2w7AMbvRPAghKRIxpKhz+eXVxggFsIP9kTbuy1s+GGqcjUmQuctF/Jxp/Jv1ciFnHicnx0W0xwhSnZpdMS8QfROF0AT0AJg== 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=StRJq5aimsZUjZHxbJehWYgdwTVyadidAX6VEVeAfao=; b=IsyyDK45cJUFLyFmGLH+bpyV5NK7qCkpNsMkjB+bVNfAnYJWi7gV1DJ0G55R/BGpxly+G70eGMgWR5n3Wm8ovVc2TIuPYErGJrmNaiyTSwBQNrqJ2lC/mE1J/iOAeN+D/STvK8M2wb93YFfTCiMrgUjgLQCm1/KcorsYUXpIYMtK9er39uyZHj/h/e+US78rkygjQVWd/uPwcWrnNZN8uN3inWv/SWF5O/nJEAw8Jul/AjKe8olXQlDgvSxqt6On8ucRLpfmngJPdVGua55wwlgm6dgShHGo3xMJKbDuvUCH54aumdS2MCApJnG7y/j7cl/5517g/XBEk2hr61nEDw== 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=StRJq5aimsZUjZHxbJehWYgdwTVyadidAX6VEVeAfao=; b=DNRjIswpbIM87pTDezxJvKCCjXmXe7RhSzRxxRTUXVEY+Ui+Cxlmy+PA7c/05cZFDzy19ulDtEcPnmPOslnRdY8H6X2woM0toaw01wiWesBvk/+rv/k6PUTTOXUMtX80sl6cZCsg4XCZYaUhlrLXyDegBDFi/GVRkjangDoBgIts9vdmYv42951NzBmyLPD2PLLpe1dzSZ3VNEJWQxZLgaf2swcis2f9cM+IAOs5AgYXp1jtlriZ+/4+WtB+ZJRkr++MwQCB8JRQKsLr7btW+4S5X7XAikXBXHTOQSt0rndLV+hu5VBkvbxxiHa1T+Q8MvlqGAocZk+xTT1QQdII8A== 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 PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:32 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 06/16] iommu/arm-smmu-v3: Compute the STE only once for each master Date: Mon, 26 Feb 2024 13:07:17 -0400 Message-ID: <6-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0006.namprd15.prod.outlook.com (2603:10b6:208:1b4::19) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: aee38f8e-a26f-4675-fa1e-08dc36ed6a4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pMmJm9tz+TWped58ZFI8DNsTvU9YPF6DXO45eGCvTGfp4RhB/uWrUIa1myw46jbsCrmGqpO4dMx4/kh21rddm9BwKjhtMGnOwhTvnag6D0YpxsrUUsHk4wXeA3epMEGChEFolPLS5KllcE7jxcEw7GNlnIwvgWVenjpA9xSGsLCsDg02J1o1++QiicGiXicyHjpR0V1yOVRKhew+KW5ClsHbbPqJqj1+FBdxyenMtYCQFNX2wExzVxnm1lVSlupER/FU6weWaTnmEK+yFMJeERUEmRC4Q3R1/cw5CR9+CN9X1zGtGYDXfYLXFV+S5DmsGTnCahXSclCcQvHY05+FERdHUqq29S3vrlv6pQOhkaUzmmmZSVS/WmVVNtA8dH9PBuLKtZ3nHLxtXlDSH0KQYgb8cD4+lXRKyGR5P98tXMVjbOfHPd7QPOw43DUhMSDXL2ykODEFrhQjBR3zaHXA+aLI+HOqqlUnFkap+wSRdMc2+6pGKr6Rtgfr3bDmuATz5DsLd9tSIXKPpISh4SDqGzsSxNLJgmEeQaedyXo/LaLk5VjaTJj8oSyknaAkGBXJoH14n6F74rJMs82Kg4Ykr0KJY98Qr6kPu6Fqi5NRq2pjaMsACXrSBAxoMQHJTSG2qGIwQOwNw6Qf8ScpOn0e3w== 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:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bbYS0FiUgVA49IeMRppCBw5RyzJr6HUVJ4mLJIzVJiBPNkDEkEhOYBsDStWheoDsRjVcqwgBbh18VyQuQR4qC13GLXFbW0Cqd7V4PmB9b3Vex19oS4Fd8/U2RGAAmkOGzyfoqEUg9248q+BvmYI8kIv/KWv9IWG65qqG+U+2QmdVjW5O++88Ll1bBpk46YnFl8GWHIxRliRrXKYyD7tYG2hn1myWV72aX7HeYz6m4j4mEVtbVFh3u1YaS7UuslVbUp9VQhqLzZkFWG3N5ezHdIsLkoS/MhkpS2a/MQZ0IsQt3ozCVNW/WrL69OSG35PJrT8tktYnXEHesuA47xkWReLKxfO4/vWiLUUbcD7hFZSrGjHkUq51HoT1UiyQiNyN2GRoIWNOUTEV6L/hNfUf3Zm8o6RzoPhojrfY+zNRvjWn7h35tRXtrqmt/wT02BGtda+91h52PTef4ysbf0fUVZMahXOoLhwNxPDZvdB33cKeT7IR1ktyFZc37uUTzBfAIQ9SZvoRpCKWvKDAE+MbaQJcxokeM2fN9AkxaGbyILG2RPaqmnvaCgpEyXIbTBJbH5ULsZa9gv3tKlT7Xc/wOCWozbDcHGILQhPckYbDO+qc2Tx2rCS0pKJy3yXyNLhDW5LHcASljFdULJ0AQtqJKNh8upqwmITAeQ/Ek/k3T03UTdj9M6n7DcXCDYxlrEGtdf8OF2GttoOlbFoUje8tjIP8gY4M0ankB2BzyOuetkk1ebMDeNPxbgbhhYPrbn4+Bc3Gr/XGqw15HL76BIXb4ix9pb2V1pd5aZd2b+rWzn5yZhq2IzP+H4IPM36ri5yhFIY6T4zc8upOtfgumJcyWC5IoN0trNvM4KDherRjpvqz9T8+9sbjmbzlG9o45GWWmG50UY7Y3A+QDVsJAwp5trbfzqilXWCgHLVdZd+jzwLCvFBLVHRjLO5uaW57x5kL/xqaj/Wrefbd7EY40Gf5AlP30foG8zNrRtrjCLeHpRav+4JFSG9QiWQ9YMu05inO0anT1hUIXt5MrC7fW67SWSLa514z674Nb0hVu9qAar+f5Fpl23PJaLgpL6nWDIoMk2TA3JfwkKBUX7KrSJwby7OI9goDnDO3Ucw3AyCPi+7KLuxWjFY7jF+hULWiYriv9UE13Id3jro4q3N9Bp2c4T9oP/mx9l85Uo/6K0A1o6n2TYUzT150SoAfGOV1Jxi5lbZiIvcOIj5zSFX/jdCiNCnncwMPvQXiyXYKRyInJfEAeGnjrusTKfbpKV6FjkD+nOT3lXQTnnexZNV2YxMPJh1ajtsQ4HE+26MsQxRn+OcMUUFHbKAEtaruPWzrX4RP2Hr0mZgRQy5l6TPIlUAzPITBJ0QTXEDio5MafgGgt24T03rU6vh6E2JBKovPKYRJivLnWw4Z7zfcw85NyZaozhrsC844DynAg9F1vWumEu0Zdebfo3h2ktG3rZh0WnK8/ECjLuzliQuTfQZdmYAp1CJ2D1HmB+jfbAP6wCsMoxbCJgzTXQhgGhwbcpcshGVZDFdkr51AMFDnjiuGguRH0hOPTfSp8ywJE/miK0g9s2wkU51hCRQypKYXR5OFWwTH X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: aee38f8e-a26f-4675-fa1e-08dc36ed6a4e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.9342 (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: o7rjbnR2cBPyLW/ys0SQrb2WWX4EEETr7t11lIIBdmMMtdtR7KmyQa2b70q5ya5y X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090745_577832_008A563F X-CRM114-Status: GOOD ( 16.26 ) 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 Currently arm_smmu_install_ste_for_dev() iterates over every SID and computes from scratch an identical STE. Every SID should have the same STE contents. Turn this inside out so that the STE is supplied by the caller and arm_smmu_install_ste_for_dev() simply installs it to every SID. This is possible now that the STE generation does not inform what sequence should be used to program it. This allows splitting the STE calculation up according to the call site, which following patches will make use of, and removes the confusing NULL domain special case that only supported arm_smmu_detach_dev(). Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 57 ++++++++------------- 1 file changed, 22 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 d2fc609fab60ab..6cdf075e9a7ee7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1558,35 +1558,6 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, STRTAB_STE_3_S2TTB_MASK); } -static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, - struct arm_smmu_ste *dst) -{ - struct arm_smmu_domain *smmu_domain = master->domain; - struct arm_smmu_ste target = {}; - - if (!smmu_domain) { - if (disable_bypass) - arm_smmu_make_abort_ste(&target); - else - arm_smmu_make_bypass_ste(&target); - arm_smmu_write_ste(master, sid, dst, &target); - return; - } - - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - arm_smmu_make_cdtable_ste(&target, master); - break; - case ARM_SMMU_DOMAIN_S2: - arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); - break; - case ARM_SMMU_DOMAIN_BYPASS: - arm_smmu_make_bypass_ste(&target); - break; - } - arm_smmu_write_ste(master, sid, dst, &target); -} - /* * This can safely directly manipulate the STE memory without a sync sequence * because the STE table has not been installed in the SMMU yet. @@ -2413,7 +2384,8 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) } } -static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) +static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, + const struct arm_smmu_ste *target) { int i, j; struct arm_smmu_device *smmu = master->smmu; @@ -2430,7 +2402,7 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) if (j < i) continue; - arm_smmu_write_strtab_ent(master, sid, step); + arm_smmu_write_ste(master, sid, step, target); } } @@ -2537,6 +2509,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static void arm_smmu_detach_dev(struct arm_smmu_master *master) { unsigned long flags; + struct arm_smmu_ste target; struct arm_smmu_domain *smmu_domain = master->domain; if (!smmu_domain) @@ -2550,7 +2523,11 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) master->domain = NULL; master->ats_enabled = false; - arm_smmu_install_ste_for_dev(master); + if (disable_bypass) + arm_smmu_make_abort_ste(&target); + else + arm_smmu_make_bypass_ste(&target); + arm_smmu_install_ste_for_dev(master, &target); /* * Clearing the CD entry isn't strictly required to detach the domain * since the table is uninstalled anyway, but it helps avoid confusion @@ -2565,6 +2542,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; unsigned long flags; + struct arm_smmu_ste target; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); @@ -2626,7 +2604,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) list_add(&master->domain_head, &smmu_domain->devices); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + switch (smmu_domain->stage) { + case ARM_SMMU_DOMAIN_S1: if (!master->cd_table.cdtab) { ret = arm_smmu_alloc_cd_tables(master); if (ret) { @@ -2640,9 +2619,17 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = NULL; goto out_list_del; } - } - arm_smmu_install_ste_for_dev(master); + arm_smmu_make_cdtable_ste(&target, master); + break; + case ARM_SMMU_DOMAIN_S2: + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); + break; + case ARM_SMMU_DOMAIN_BYPASS: + arm_smmu_make_bypass_ste(&target); + break; + } + arm_smmu_install_ste_for_dev(master, &target); arm_smmu_enable_ats(master); goto out_unlock;