From patchwork Mon Feb 26 17:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572527 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 AFB5AC48BF6 for ; Mon, 26 Feb 2024 17:09:05 +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=5cU7+lRkTp3RpPemiuTWWgLVPecYAf1+v/BfvdWh1ZA=; b=T17OI0a3qsFnQi gjNO0ddJuiBSE0Gf26ZeSjepEgaqvD+r0jAnZjphxXIyPPv+LW4EUYxHpp4PUajkVmzDaWQR5ETgg XyHlRmfc16IqVl/tNX3KHGjmMVQMd1O255lREBynJPEbaUq3qBx3LDt59ELef3dJD3i2lLNusiany nOgI40VGcY+Is0DaVoXrlLSf6jUuKNRmgIf1R/twWUePDA3XF5oEali6nRPwwzUjR2pkbMe7dDCFU TeVilxorlKMqxHfuMy16CZFP1pNgli6OStquyKzsp430YnS0oRkqpPwDdtFRMDrPm+SxS0eFdWGWe N40TzV38+qstKTT/tksQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeT7-00000001qIK-1EqX; Mon, 26 Feb 2024 17:08:45 +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 1reeS7-00000001ph5-04SL for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/Ag6Q2/mFaivBdDIPyjVVNf6pHkHEPzVRFuu+hnOnKwACjPBMeeW+IMbJjw/9AXAm+ECaLmKdV9agD/2QgM0THqUnJv5Devbr0vhivzP/YmvZD2bg0SABT07WWLELFd9k07V7kBE7+ibt2UvJLdUF8H0G6om9FPGD1ejBD67d+skj0xJkelGZge56a/8j1J9VTU4E845qisJ70hY7WN8S5cKPpUG7QNZ1MiouxXk0zDPktDfxFWV6F4yQ7CmZf/VgsXnZ/CrfPDDfA1LEx3Ak6wx86Z4ZoTARTs1Pkv9qDFiNscPO/lkCVO5cUavFeBSIvaxOuoTEqvgq3ZKokWMw== 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=C88f9NuSQXK5UjVS+I4LS+ehiwyTVUnej0TZ9JTb3G4=; b=Apg3+AdDDndigK/dMA/xbVVWG6QvFMDXnX+pycThHYn0kw7ADUzYeLSpSlM7faj9/O0qsjf8NiG9MT6wK+qJ79KlZo9NfwElth5fpNQvCkiBlvLnsycdovVQFKddChYxQ3tJaMDNx0CG7V+yOcEqTvkOKDYaU61MOs6R7rgXQt7Te7+OyO5eBKiDaZEXe7gNE1kqbA7LPn9ctVEUnB7nr4X4Zhv4M/RSOGSoIMJJsdmuElE3tOwnWupjLN/0TGmXfAzZ47fk1lcNyIfLx3M5hhtAUdEimh8G4cD90jLs2+J9FeQ81q87X78KdqTHqzqCn43psB5KNOLiG3lbVK03LA== 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=C88f9NuSQXK5UjVS+I4LS+ehiwyTVUnej0TZ9JTb3G4=; b=HkigGeogwXx0579vSZUL1uk3mj2rVwLsEiV65XhbxiWs4GttevpTw+vMiqwS3YWw850GIrHXTapwhTrjf79NLmuX1EEhSGOEI+uPPUNwD9n1qd32EzxSciGasROCCsSU0SixTlD+k6R/Tqgpstp7W4bPsC1N0DymwaMBerFfcLug1XBslE20i3A7wxhPEaiH6bogHjBQVdkeVSfweCR9PdcyfHNWjpi+uO4tD2EFPH53hvcX1QONvKPQkp1QzvIWmBspIa2PN9ZuWvibZ9eVClxk+D8XNkzJfgCuCIwMTE+ztEBdHXz9QDNxobXFOzAhxk4/mXfuasQQ+McpPs1gkA== 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:31 +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:31 +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 04/16] iommu/arm-smmu-v3: Build the whole STE in arm_smmu_make_s2_domain_ste() Date: Mon, 26 Feb 2024 13:07:15 -0400 Message-ID: <4-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: BL0PR1501CA0035.namprd15.prod.outlook.com (2603:10b6:207:17::48) 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: b74601dc-1721-451a-b01e-08dc36ed6a0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s/Gnk3EihsfFpUaKSJL+epbtoFwLkKUV8CE/uTQgDhPxpUOrniZ33jJgvGHIMvS0oqE1I3DySfU4Bp2/x39F/bH2wC+0tzX5iRUtXinPPO0DCzFmpWvMUOOQNCoh2qHB0mGUG6Vx1OEXCSBCplYcFG0jjcGp7QovUrmK7M9MMrDpZeoS+7Hux4reaAkSMf912qOvsKL2dhj8DnGD6O2cyqYptetb1lBHhObeoqFKlV3BncDxAyKlfs4UFEVv9gJ8lENhUu7cMZfumTM93JPNzFYCdhqzqY06Il4MUp676s2oov82dNEfT3bR2zxWpuYO6iztNza1KWxljxgtHYyFsFuM9W/Ozfz/N3t4pbkuA8FrsM1W8FV9vuN5Ylap84BLjlyweawZp/6heJ8hFN3qUAKVBllXtDtnh4mO/GhDi310WLeSt1X3PHrwEjyWhuJ0Nl09dl5V3HF/y+Hjl/Xp9Yg0guAGVAnEVYRuhSMNm4ZC7j1TfCLeNezboQGYiSWcWnx7Zo/BjWyPqKwL7FRsC6kS76f3yfxz0Il4fkog3UeE+xb1vcibcpSKLrlcWUXu3WYdulbitV9+uCByFkOTi8uSx7pyaT7U9o5agvDGb92HzCUHIdQrf/A8PRmzRoOffxHL453ArjXexKZBn1wcRw== 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: HiqiGvPB+e4Wce7aZZroeC8qq+XJihA9nQkahLn+SGFoh7fqH+ki8hdrqR9+U8UuJqY2rnZUb6MXWt7Xvzgxj9lvU1jnSbmJEJf56v/o15RkrW3tdmO4LUuLJVBELw0y2FCoiekofGhMTTPFyFCgPpx7deUfeta6zWjsbIPt3uen8cr32g8FiJwwds+FjGO6YwlSUIsenOHQAwIMBoJmvsuMADNu7tIw0YCWhl/fdwo5IwMlUTr5ociTlrKSgwjyN+PcMSiIfFbK/Si1+g8wUIR2+UZw/lyGUAefOb+ti9hkUkyuCRyt2YuW5mSBM6ggIzX7e1EXkw4+y0xOnTlbzi1yrpD/8pGHCGtwPOF+k3D+vbIbyPVDdFX1tCKg9+ZFVFbSwQcgV1AIohtTF1LtaEo0wpP7ldMjrGBj0kWLBywIUyFTs5iqH7heHSpyC/k1E/K15/Z5wzcvA20IbEuTLopGKILWkBO6yM7DyynbQW/v9KcWc0dDg+s6lECwoCvJNX8oLEchnADwd+Z0BAZGA2vWL5rl0UNmXZMlO+2bQUh6FINZR+WZTGmhQzhUb/JaoucngVbJxSeHgz32lOIyZZ99PxoWiX6/rozVaomv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enant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.5840 (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: NuLqrnW2HUCKcCxMAKfF0DDL4/zbD/Kg6cILiN81II/erGZszxSM15NvhrhRTjRb X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090743_273305_FB767B1A X-CRM114-Status: GOOD ( 10.76 ) 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 Half the code was living in arm_smmu_domain_finalise_s2(), just move it here and take the values directly from the pgtbl_ops instead of storing copies. 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 | 27 ++++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 -- 2 files changed, 15 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 e34c3181966934..b81e621a8e5921 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1520,6 +1520,11 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_domain *smmu_domain) { struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; + const struct io_pgtable_cfg *pgtbl_cfg = + &io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops)->cfg; + typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr = + &pgtbl_cfg->arm_lpae_s2_cfg.vtcr; + u64 vtcr_val; memset(target, 0, sizeof(*target)); target->data[0] = cpu_to_le64( @@ -1532,9 +1537,16 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); + vtcr_val = FIELD_PREP(STRTAB_STE_2_VTCR_S2T0SZ, vtcr->tsz) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2IR0, vtcr->irgn) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2OR0, vtcr->orgn) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2SH0, vtcr->sh) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps); target->data[2] = cpu_to_le64( FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | - FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | + FIELD_PREP(STRTAB_STE_2_VTCR, vtcr_val) | STRTAB_STE_2_S2AA64 | #ifdef __BIG_ENDIAN STRTAB_STE_2_S2ENDI | @@ -1542,7 +1554,8 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2R); - target->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); + target->data[3] = cpu_to_le64(pgtbl_cfg->arm_lpae_s2_cfg.vttbr & + STRTAB_STE_3_S2TTB_MASK); } static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, @@ -2302,7 +2315,6 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, int vmid; struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; - typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr; /* Reserve VMID 0 for stage-2 bypass STEs */ vmid = ida_alloc_range(&smmu->vmid_map, 1, (1 << smmu->vmid_bits) - 1, @@ -2310,16 +2322,7 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, if (vmid < 0) return vmid; - vtcr = &pgtbl_cfg->arm_lpae_s2_cfg.vtcr; cfg->vmid = (u16)vmid; - cfg->vttbr = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; - cfg->vtcr = FIELD_PREP(STRTAB_STE_2_VTCR_S2T0SZ, vtcr->tsz) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2IR0, vtcr->irgn) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2OR0, vtcr->orgn) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2SH0, vtcr->sh) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps); return 0; } 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 65fb388d51734d..eb669121f1954d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -609,8 +609,6 @@ struct arm_smmu_ctx_desc_cfg { struct arm_smmu_s2_cfg { u16 vmid; - u64 vttbr; - u64 vtcr; }; struct arm_smmu_strtab_cfg {