From patchwork Mon Mar 4 23:43:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13581361 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 E9D3DC48BF6 for ; Mon, 4 Mar 2024 23:45:22 +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=IjLd73UQigfEcdRntOmRBIdms11ASePIfSyXg17HJj4=; b=Q0kOzTAV1SgeKZ 5Nkz1YyGCEGl5ECgwyeKSjenMQkY2HOrGcKg7cis7Epwq1/do6SqEl+xGPE4i7DAjsZWDk1pcZcwB GHWBjGpmBCGNmHDsvQDiHrGJ17Wdq5t0l2gEZ+vkN+0PphZkXxpuKswavqyc3qKVCNuvvyDjWSsEu 2ZjdiHiafYNVIjZRmFODi82byDeRd0DZGSYLaKSqOpJ8T06X1gr3cLteHSN75LBp5X4BE+92BI0h3 607Nk7aQCX8F8g/YJCNb2g+wPrhDIz7erz4Jf55eh2IDuqvreKzcuvcw50qd63gx7cgdAGF9yPPrH bHqXeuP/wxvQlF7gFCLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhHzY-0000000B7ii-20PF; Mon, 04 Mar 2024 23:45:08 +0000 Received: from mail-mw2nam10on20601.outbound.protection.outlook.com ([2a01:111:f403:2412::601] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhHyx-0000000B7EH-27iZ for linux-arm-kernel@lists.infradead.org; Mon, 04 Mar 2024 23:44:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J+/1iSoZ+Raz8nNcJ9MMejIhljBKWXFIBVXOAzIYmgLsRoI78swJYpWIa22tiWYimm13p4nAj74oy57SUrd1jMNdw/Wu8W3BofV8pIqXYC1KiJE+vVJtI1IwjyQNNqsbZAFENjBWczxVHDjmwdJg+ftQXYRA4BpAN3efOwYlrMwZNvulw98r1l9cyYCbs7hmzqVBOZS2/ZsI1xfFSS1MTwlTUACkqGo6P6bx76IFDXbtomGj2jI8zBbOuS/NkZEPVIY/eukR63MIGnEqiO1mBs1jHM5N4MsrlLkwktcOFTpkOBTx93UA7gdqFm+pUb5Qy0Bxc3eD7j9zaMiy5/wulg== 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=cJgwdoDaW47suk5Q2w2veOLO9v8O8xdVOnj4yobDwx0=; b=DWRLsJOoLlXiersZSdZ/AZqyOBGh7DZZaT6kzgqEH663etDeCMKeoVR92nXUXfxPC51mkGsYFzacpsy1K3I1qXn6F1eTbo7ODzNsPn0QRQyODFXyMweOpLXufE1aqXJF0CqEwv86BQqRVCgFkP84tU3LcXwMosnLhzN9zeyMy3r3OtBI6OpoJWkb39GW2Y8CHvNIWMnZAtNC3PnU+Em1/g4eyYM86IVHwjp/Ilhl4M9hi8/BCspUX4Iyuf3EmBhYwtor6JP7jo1VzrJyXcgaVpHyuZsDnO3Nml39RvT3p9OQPMj3Mm537+auFuZA7G6COtY257LrK/S864eXk4wq1Q== 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=cJgwdoDaW47suk5Q2w2veOLO9v8O8xdVOnj4yobDwx0=; b=WI9JSSy/p99RNF+dLZhG+QdAGRDIKC/R/EcB3QcogzYQd5XMP4k5rbYY+lts/SN36r+fOAbO9fGb2vOPWKlGh54EY71dK40TqlnxHV0KFMwhgeHq3vRWFyieUoAn6lRBn5F4jKYoy1oVMHWKRgaACeMu9CjpMrdyFLUwBPPBatWER5QM0z/ooyG9ErR90bBfnoObMfCMENh0pUkvIaFsS2LDFzeeHqlDqZi+JcZ56FXtr8WXsxpiS2DgCqvkQE1GgzrdtS3e3lNoostBHHWN/hRdgBQmKdEIiogbIdxZ3h38H9MUwooT6ZYrBt1y18MotNEEOstW78gFMZ+M4P1oDw== 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 MW6PR12MB8949.namprd12.prod.outlook.com (2603:10b6:303:248::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 23:44:17 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c33c:18db:c570:33b3]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c33c:18db:c570:33b3%5]) with mapi id 15.20.7339.035; Mon, 4 Mar 2024 23:44:17 +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 v5 11/27] iommu/arm-smmu-v3: Build the whole CD in arm_smmu_make_s1_cd() Date: Mon, 4 Mar 2024 19:43:59 -0400 Message-ID: <11-v5-9a37e0c884ce+31e3-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v5-9a37e0c884ce+31e3-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0043.namprd20.prod.outlook.com (2603:10b6:208:235::12) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|MW6PR12MB8949:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a7b9749-2d42-4e99-1371-08dc3ca500c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9WV+yIsApOPQf5KOaQf7HWfhoct315s159Ybk7RfN1hlIyrL3NQ+IoBLRk7Vj1yonkWWCSenDEfd01LjZUJKXwVyDIuObhPZJeMOdx7Vrc0krzcN5HCv1jGj0uKBRd9PYF3dHfuoHLFsZ9o5X1zY5qdV3lzQcPGHnWwHSu5hep2ZADfBZZB/rDAuAjjuY2yyWbklLgQus4EP9we3BPbly0vKufotgihXEbDMuqoQhdIUwESBtz6BSyAxUKs2nBPITbfIbxhosiyXT8UlVYvt2WsZoidz89erGdNkRb/hufg4AG/vGy1tYvoelu8p/vTiQjrDVgDOPesHwjef/EO2yCmjOF/3eHszX0+Ojf+x1mWa6n4r94dvgejhR7g5fcH5WsEew7km6VuteCoRibBZcBSUvfNgZUSB89BqTqjbcz9Q125GziSXets61sF4pVpH3PNJ4QKD9eKhwcn8rn7QySIXB2lES1fdzZQ+1TW8rRfgvQYqGN5dlHEEqRR98xNBMoEgL885sVQF9VVsBQM6A/GFCFvtjImZZ+yJ6mJuju6UOPRWYu1OUuuLEep8SuKgl0az/tY8sYHpomZmE8tqiFrXktY6oj63uTojJLiaTo17bwUaJ6k7nmtcAyqaMmYHqwceXGKi0Cl+CrgOcvh6pJqf3JGgfWpzxM+Fc0YC/jg= 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)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r/k/ODh9SKaRwX2PrHg/DRq+P8jyS7mmxT3R7pTdUWLp7FA1M7Q/2xNYWxu4ibYISDGyDcgHmmoC42k0df2MhfC17LxIH1YzajskVjbXJNGAP8f8Xp87ryFBOR7+Y7S9rO1bfuVk6GW8KeIztpQpzHlDdR3j8h+yj/qSBhQrR7eyeSUjmXQ5be9EKVwxgPpo5bHWxZyHNhvDaVAAX/2gE26DtIvdyWIQvggtfuLrYLg3TyssyP0D/4s5xu4n43ShHQJ6KjpMSgnC6B5+ZrjoLv46X7AfaK7056pi8A8e/2jhP3gsZJ+gl5o2J+Pb9Y56F/JIJT3gOKqsz5IcT9XhHmXEQMWkQQPrpI5+eur3/4PxhCXoPBSsMv3id+Q2MZwdBEU4BCWtjYxywoCDyi0INdkpMKDr2zcDxc/8YbuFsvx1+33KlraCy38Sy8iSvODdv4V8wGDHpUjvSB8F8xfo7MNXQYdKClddwa7C2O7TSGbX2u5Wt4maylvD/WhM8BzF0fzSUwNc8AXloZBY+uoPZYbG7jAKYAyMBXVGXhMLsqY4n1yy8+lDLoX0CpjJPVT+EhciHx5AUDumPOXOIMLUre1DiBAYLP391r+u3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rossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 23:44:16.1328 (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: l+vlukmtIcPeOzrYEhnFDzwHKRkAFpNEEXHXKu2yxBz01FpFM789+D18+TDD4zkD X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8949 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240304_154431_618599_623A5F5F X-CRM114-Status: GOOD ( 13.95 ) 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_s1(), just move it here and take the values directly from the pgtbl_ops instead of storing copies. Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Michael Shavit Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 47 ++++++++------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 -- 2 files changed, 18 insertions(+), 32 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 50d17e3ce0a956..dfdd48cf217c4e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1301,15 +1301,25 @@ void arm_smmu_make_s1_cd(struct arm_smmu_cd *target, struct arm_smmu_domain *smmu_domain) { struct arm_smmu_ctx_desc *cd = &smmu_domain->cd; + const struct io_pgtable_cfg *pgtbl_cfg = + &io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops)->cfg; + typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = + &pgtbl_cfg->arm_lpae_s1_cfg.tcr; memset(target, 0, sizeof(*target)); target->data[0] = cpu_to_le64( - cd->tcr | + FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) | + FIELD_PREP(CTXDESC_CD_0_TCR_TG0, tcr->tg) | + FIELD_PREP(CTXDESC_CD_0_TCR_IRGN0, tcr->irgn) | + FIELD_PREP(CTXDESC_CD_0_TCR_ORGN0, tcr->orgn) | + FIELD_PREP(CTXDESC_CD_0_TCR_SH0, tcr->sh) | + CTXDESC_CD_0_TCR_EPD1 | #ifdef __BIG_ENDIAN CTXDESC_CD_0_ENDI | #endif CTXDESC_CD_0_V | + FIELD_PREP(CTXDESC_CD_0_TCR_IPS, tcr->ips) | CTXDESC_CD_0_AA64 | (master->stall_enabled ? CTXDESC_CD_0_S : 0) | CTXDESC_CD_0_R | @@ -1317,9 +1327,9 @@ void arm_smmu_make_s1_cd(struct arm_smmu_cd *target, CTXDESC_CD_0_ASET | FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid) ); - - target->data[1] = cpu_to_le64(cd->ttbr & CTXDESC_CD_1_TTB0_MASK); - target->data[3] = cpu_to_le64(cd->mair); + target->data[1] = cpu_to_le64(pgtbl_cfg->arm_lpae_s1_cfg.ttbr & + CTXDESC_CD_1_TTB0_MASK); + target->data[3] = cpu_to_le64(pgtbl_cfg->arm_lpae_s1_cfg.mair); } void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) @@ -2305,13 +2315,11 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) } static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu, - struct arm_smmu_domain *smmu_domain, - struct io_pgtable_cfg *pgtbl_cfg) + struct arm_smmu_domain *smmu_domain) { int ret; u32 asid; struct arm_smmu_ctx_desc *cd = &smmu_domain->cd; - typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr; refcount_set(&cd->refs, 1); @@ -2319,31 +2327,13 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu, mutex_lock(&arm_smmu_asid_lock); ret = xa_alloc(&arm_smmu_asid_xa, &asid, cd, XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); - if (ret) - goto out_unlock; - cd->asid = (u16)asid; - cd->ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr; - cd->tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) | - FIELD_PREP(CTXDESC_CD_0_TCR_TG0, tcr->tg) | - FIELD_PREP(CTXDESC_CD_0_TCR_IRGN0, tcr->irgn) | - FIELD_PREP(CTXDESC_CD_0_TCR_ORGN0, tcr->orgn) | - FIELD_PREP(CTXDESC_CD_0_TCR_SH0, tcr->sh) | - FIELD_PREP(CTXDESC_CD_0_TCR_IPS, tcr->ips) | - CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64; - cd->mair = pgtbl_cfg->arm_lpae_s1_cfg.mair; - - mutex_unlock(&arm_smmu_asid_lock); - return 0; - -out_unlock: mutex_unlock(&arm_smmu_asid_lock); return ret; } static int arm_smmu_domain_finalise_s2(struct arm_smmu_device *smmu, - struct arm_smmu_domain *smmu_domain, - struct io_pgtable_cfg *pgtbl_cfg) + struct arm_smmu_domain *smmu_domain) { int vmid; struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; @@ -2367,8 +2357,7 @@ static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, struct io_pgtable_cfg pgtbl_cfg; struct io_pgtable_ops *pgtbl_ops; int (*finalise_stage_fn)(struct arm_smmu_device *smmu, - struct arm_smmu_domain *smmu_domain, - struct io_pgtable_cfg *pgtbl_cfg); + struct arm_smmu_domain *smmu_domain); /* Restrict the stage to what we can actually support */ if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) @@ -2411,7 +2400,7 @@ static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, smmu_domain->domain.geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; smmu_domain->domain.geometry.force_aperture = true; - ret = finalise_stage_fn(smmu, smmu_domain, &pgtbl_cfg); + ret = finalise_stage_fn(smmu, smmu_domain); if (ret < 0) { free_io_pgtable_ops(pgtbl_ops); return ret; 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 8eabcccb9420ba..468cd33b80ac35 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -587,9 +587,6 @@ struct arm_smmu_strtab_l1_desc { struct arm_smmu_ctx_desc { u16 asid; - u64 ttbr; - u64 tcr; - u64 mair; refcount_t refs; struct mm_struct *mm;