From patchwork Wed Oct 11 00:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416481 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 AEAE1CD98D9 for ; Wed, 11 Oct 2023 00:34:44 +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=Jsvou9RDE4PC+5GpijtOX0FxL6/BjLludSOPVDsbR4o=; b=RSYczizNLGWIA+ VBquQ13zcOeidexup08ePwgbDqF+prHkk2okRwCELKV/8c5BMl/zt/B2pTrYKIQRs5K77kb/VEr+u YhK2ixXjjIg7k7uQORkMsFBGcz7CFJvfDX/AQk4BICYDxhN4XBwDEKzjNE4igwha5dxYOvpvfhf1i 8s5NC4v9AnB9InNqoICTZbL8DQG+Z9uQ1z7oUEJZonrgMuAWR1i5Dg1pnMUGOkqRVP+IK2AwZ6eLa +3y08gyouMV2T+R86CxWZfelAVWQfpPlYAnWC3HtL8rlIfsfNuOtkxcWUITA3yLazTal+rnrJb9XB YATLPz399Rt6meP4tYKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAu-00ERO3-0l; Wed, 11 Oct 2023 00:34:08 +0000 Received: from mail-dm6nam04on20624.outbound.protection.outlook.com ([2a01:111:f400:7e8b::624] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAd-00ER5U-0r for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYxcq1zUTgGDV5t1Na+z4Zuwcq+OuXtx/oQtRKdeMjKq12Himtc7reJz9mNihdRjTk9EKgxnCNxsof0Kczkg6xQuNP6Iz1gr67APWc2Li7M9IVSwyeNkfGHzNNZkZtobBh+cG1cn/CY4ObQU5zLkvM+LWv46sLIc4PFF4NdEE1vrq0/x+l4ghiimbPLLDOREjvdv6bRdzEknIpwe8iwxaBtYItoR5wStOJ4lr+mMfUU3oyetuXFHYf91SoTDwYetHQKrBKi5tkiyWTSPbS8ZAoRmMShMz+/0gJVOwCt+L9yRvwIVrImqb/9podkrQ96CkIa1F6cTMbA0id5PCiiQqg== 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=BveVXCPio5cejeu+gnNGMe2uG4zPA/l1WnMj0/qt1J8=; b=DgGg52yG5C1wrNUTo+z4H43wrCo5ojHtO/VxRN6jvFHkh3MjS1oOUzjyglp9OKwO+UGQBMAcH/7v4LZue68g+jYOP/giOWbQxeLNEAPTc/V5cCK12c/EfExJAyNAYRRacOyXVpXJWoB1nFsbV6YC/LoVqEEMllsQlgrGoAJ5jd+LLSLzJUjeCmJM5cQEQXLfqfoIGEFS9L+blXcv0mfOxFO4BG0nPNL9TLbE2M6mID0lY6pa3lIAEmsGu4LP7NsGVDhjiKYw+Hwu9OcfYC2Q7JfCeYRi8IC464BpLPZpyte8y1W5LXAq/4uZ1qe4M0V9tbTUZQnzUEhXWLF5zCs7lA== 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=BveVXCPio5cejeu+gnNGMe2uG4zPA/l1WnMj0/qt1J8=; b=QuxEBVqqpPk6CrOhgJwfe6c0LAuV7qN5CGlaivbFR3ruMiKzToZ09cBNzmGycwLl9Q0eRjBCQJwurlTP1fqhgbQWNBgDSJVy3AdRaS/qaxUWDLKLS0Lgm5fj0buFCPOjOBB7vYM6qCcqUMm6S0OXp9AAdPb0k73f2A7EO5TCqOtL0B5u0lldIfB/2w1OBJp1NGkA19YVWWgaBojKgHAK4xGPo+/4hWcpfKh9lpRQF6+ZZIj/G1oWp+bby/ciyCykniwotflrkoVEu1KA2mFUXkXzZZCSRAlYucfwYIY128gWQL0X/49kUUqI8aLl/boeo3FxmVhrvhKJ8qiWAQKKvA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 01/19] iommu/arm-smmu-v3: Add a type for the STE Date: Tue, 10 Oct 2023 21:33:07 -0300 Message-ID: <1-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0418.namprd13.prod.outlook.com (2603:10b6:208:2c2::33) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ccfdc91-2ce0-4a9a-192e-08dbc9f1af9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZpwTutF5y1jsjZ8jnWXPtfIyc+T0T1D8fPQSj3Fa2jk/7vF+2o7igRD/H6mZIfADe0pPjE+7MYjYDNzlSnDMBkYStfTsSZyWpQX6Y3zWbI9rXOQWSHAWtXsw/GenCIKpKDqXNs3RhywdlTREeDtL0iu18kQjQFlhiLbg5nvcnGG4dNSH6aQU3msYBlh/diyOWut3i4b9+JK0bblbkZDKnYBsvw1zh3Sms4Ef9fziXj4xj9QzWRASasb8HCIbcv1d4ARa6uZ7kjAa8K8gijdMdRnrKXrlFukJTIIf/H+xQGF+8IdRyRoDX3N0jAYMNYdBkRCXc3Ei70CuLcCG4v6c8yVhnHbNveM/YiuiuD/gQhWIWTUWbluAhKiXHeOyqoZxHbMhOdzfH2x3xPzW70KsmW9Mbr4bcmY+CzQ2pbjlFMk/ZohVTKXlZY12kRAin84EDl5JUtEjtKXTFpm6xzw7S3uEIPyZxXPWRt4nnLL7yLZgAEvp8LJtlriUDjR8T+QH/Hkrh+WoICWaSF/EFySS8Qfg6E6cvjeFVsyq3xku8uArMWo0RMKkh9u5izi4fLcHLnK04B1uiq3tL0CVordruIsvI97toQxobs7Ljqrf3ko= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rguaZJpEn86lbiYwHc9eiVF2SwUgk71n+00xrWGaKJqx0o6kD8bJnUShvtJLlgsHyz/PzDczNyWGObtDl1sVQcs3Uelc9zQdK4OukXOuJl69k7ioKstFiuavL4kikqiilrGYwJvzEelhef/XpruVCAC0trRAJRSLCKIrnXkKL/askT1ZWkNwjk37epi9RgAg/3zJYHCWX/st3AneE7ema4/pYnNPWjB1cpBZFIMwp5weAy1dDCv1/YhLVAL7l4ndEoY+sd45SMUyFfdGA5Fwknio4UDNY+dYsWL3y8zFcfdP3WgZS+LyBrHuWA5Z4QKIAnhFR/bzhBO2wLOAT7PEVfRT++LnWCcyGs+oWPwvdoxXji12tzTeAmPG0D1VqfpBCcD7T61nPnZrsCmSeyC6Mzz0jA6wczIGaepjCVwI+QBKQ0HloASbzpEPNEvLxZB5JWmpkpHLxcokXnwwzcTn5nJMCGh4cdgFrI0UCNRe8JK6KDnAWSLKCtQgP2XlwFUVUq4zmJQSLOQxrBehR67lqA0qKiccd4toabpgKjjcnyh3ssdSIyYl0V6Hl5IhuVSRh4gXK8S63S7hTj0UfVRykcamRqD4r5dMdZ2w4ZNWyVCdVw5DNx+pyLpA+twCQBBqyb4eUon6crXiwxhtUbCcNThGQiScJBT7S1N8O0vqg3J3cdNB4vewdTgRdS3NZmFPArB4aXzyWkw1cbPk7B4hlY9vycoP2zjDPqRUWfk1HRoN8m1phtWxK1PqZzSkfKUnRjcyRJn5h2YRTU5MVidUSijycsh7wSg/pr6Fkb3yp9jzvPs+SgR6sPVasdRh14z0QVkhT/tCtimzvO34C2+YXMrpJZKVTIB4CyPSjtznu2rQ/mwqDomDAOrWGsioBhuwlQo+F3V4bBuhLZ0IGwexkkuwpA5I6cD8GZ3brlCjRMTkjfuuwgwGq0VGqApKyQ2fCqZf9LzjXxlFMtPNvz7F7t6fW+Uedun8bxNXHH9zH06Pvz1m4r8myaTS4434+W+AJXkuJFi80cbSiJ/xkbCjjJ8BFDwQmZnLa+4O99syUW8Gumq0Cm57D+oM8mrXV+Og//hl4NxJmbce0k23zqSZdl9xxyR1fHNtYYMjhFiL1bmew0tOhZmVl98c3dgNS184lm8iXN2Qt807jFOFb6WR+3jbtaGn0GqI1BsE1ROTsYAxd+4eFE6R7VUqT/FY/w4dhRhyDjoO1wsA5xcO5e2dIA/BXT80+iWXkN57wryIzHyThZa77u2zYoy1I1n3G1FeU9UHXIk1vVI/C3RxnnpjwIWvmgM9KswyAu7UQOu5OHQNqDwu7ESUb/JLwEMoFGBJ1MavkDmk1fm+pdrqvTZuTvCBmtk+YOm8Po6uApqzL2oeXGaZNI3o4MHYRwtlIKL5mMf0VYA4gXq+SIIelurBaNqCRoof9nyvwG0uBxeX4+ojclf1nkVeWiSh4/pKTYVJmAHGeX88BPrmGg658eLs/dkNCbuFoMdQiF0O3/+cuHyidcJFfuxkc4cxTZjGf2AMJNe3bRL267CYgxtaphGDcNqzMx5Ys0ejsG4w8FUVEvlnO0yY68as0TxR1H8i8xmj X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ccfdc91-2ce0-4a9a-192e-08dbc9f1af9e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.5109 (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: +oiWL+VOaCDLrVw4DZ+QQRhu3R7Cv5QcQVuJlGXYFvNR5YFAcff1u6R1+lg+K4DJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173351_336098_C365CBC7 X-CRM114-Status: GOOD ( 17.75 ) 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 Instead of passing a naked __le16 * around to represent a STE wrap it in a "struct arm_smmu_ste" with an array of the correct size. This makes it much clearer which functions will comprise the "STE API". Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 54 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 ++- 2 files changed, 32 insertions(+), 29 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 7445454c2af244..519749d15fbda0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1249,7 +1249,7 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) } static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, - __le64 *dst) + struct arm_smmu_ste *dst) { /* * This is hideously complicated, but we only really care about @@ -1267,7 +1267,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, * 2. Write everything apart from dword 0, sync, write dword 0, sync * 3. Update Config, sync */ - u64 val = le64_to_cpu(dst[0]); + u64 val = le64_to_cpu(dst->data[0]); bool ste_live = false; struct arm_smmu_device *smmu = NULL; struct arm_smmu_ctx_desc_cfg *cd_table = NULL; @@ -1325,10 +1325,10 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, else val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); - dst[0] = cpu_to_le64(val); - dst[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, + dst->data[0] = cpu_to_le64(val); + dst->data[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); - dst[2] = 0; /* Nuke the VMID */ + dst->data[2] = 0; /* Nuke the VMID */ /* * The SMMU can perform negative caching, so we must sync * the STE regardless of whether the old value was live. @@ -1343,7 +1343,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; BUG_ON(ste_live); - dst[1] = cpu_to_le64( + dst->data[1] = cpu_to_le64( FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | @@ -1352,7 +1352,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, if (smmu->features & ARM_SMMU_FEAT_STALLS && !master->stall_enabled) - dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); + dst->data[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); val |= (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | @@ -1362,7 +1362,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, if (s2_cfg) { BUG_ON(ste_live); - dst[2] = cpu_to_le64( + dst->data[2] = cpu_to_le64( FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | #ifdef __BIG_ENDIAN @@ -1371,18 +1371,18 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2R); - dst[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); + dst->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); } if (master->ats_enabled) - dst[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, + dst->data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, STRTAB_STE_1_EATS_TRANS)); arm_smmu_sync_ste_for_sid(smmu, sid); /* See comment in arm_smmu_write_ctx_desc() */ - WRITE_ONCE(dst[0], cpu_to_le64(val)); + WRITE_ONCE(dst->data[0], cpu_to_le64(val)); arm_smmu_sync_ste_for_sid(smmu, sid); /* It's likely that we'll want to use the new STE soon */ @@ -1390,7 +1390,8 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); } -static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent, bool force) +static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, + unsigned int nent, bool force) { unsigned int i; u64 val = STRTAB_STE_0_V; @@ -1401,11 +1402,11 @@ static void arm_smmu_init_bypass_stes(__le64 *strtab, unsigned int nent, bool fo val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); for (i = 0; i < nent; ++i) { - strtab[0] = cpu_to_le64(val); - strtab[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, - STRTAB_STE_1_SHCFG_INCOMING)); - strtab[2] = 0; - strtab += STRTAB_STE_DWORDS; + strtab->data[0] = cpu_to_le64(val); + strtab->data[1] = cpu_to_le64(FIELD_PREP( + STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); + strtab->data[2] = 0; + strtab++; } } @@ -2209,26 +2210,22 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) return 0; } -static __le64 *arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) +static struct arm_smmu_ste * +arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) { - __le64 *step; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { - struct arm_smmu_strtab_l1_desc *l1_desc; int idx; /* Two-level walk */ idx = (sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS; - l1_desc = &cfg->l1_desc[idx]; - idx = (sid & ((1 << STRTAB_SPLIT) - 1)) * STRTAB_STE_DWORDS; - step = &l1_desc->l2ptr[idx]; + return &cfg->l1_desc[idx].l2ptr[sid & ((1 << STRTAB_SPLIT) - 1)]; } else { /* Simple linear lookup */ - step = &cfg->strtab[sid * STRTAB_STE_DWORDS]; + return (struct arm_smmu_ste *)&cfg + ->strtab[sid * STRTAB_STE_DWORDS]; } - - return step; } static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) @@ -2238,7 +2235,8 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) for (i = 0; i < master->num_streams; ++i) { u32 sid = master->streams[i].id; - __le64 *step = arm_smmu_get_step_for_sid(smmu, sid); + struct arm_smmu_ste *step = + arm_smmu_get_step_for_sid(smmu, sid); /* Bridged PCI devices may end up with duplicated IDs */ for (j = 0; j < i; j++) @@ -3769,7 +3767,7 @@ static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) iort_get_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); list_for_each_entry(e, &rmr_list, list) { - __le64 *step; + struct arm_smmu_ste *step; struct iommu_iort_rmr_data *rmr; int ret, i; 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 961205ba86d25d..03f9e526cbd92f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -206,6 +206,11 @@ #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) #define STRTAB_STE_DWORDS 8 + +struct arm_smmu_ste { + __le64 data[STRTAB_STE_DWORDS]; +}; + #define STRTAB_STE_0_V (1UL << 0) #define STRTAB_STE_0_CFG GENMASK_ULL(3, 1) #define STRTAB_STE_0_CFG_ABORT 0 @@ -571,7 +576,7 @@ struct arm_smmu_priq { struct arm_smmu_strtab_l1_desc { u8 span; - __le64 *l2ptr; + struct arm_smmu_ste *l2ptr; dma_addr_t l2ptr_dma; }; From patchwork Wed Oct 11 00:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416480 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 E4DDECD98E0 for ; Wed, 11 Oct 2023 00:34:44 +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=QeeyylnDrlEj9CYD5PET7RkdiPtgHeJmm0Ohw31TBnM=; b=kcKbB+tUnneofr q+YrYPjc+J+mZLvMfgNiMQISkPSivN+QxbzgH1qeu7y6D1+B0TdX77D2ekOLds5q+7Hs0dDKKeEAU /tKINYnVQ7ZJqzZPzEPZknK4ejb4oc0OXLKoBQS1vhddkoxEluWJLKc8Cf9IKuooPtNA/4DaFBjYb pLhri4wcUwJy8wEmt6y2nySyBmtxlXpO9zN21E3YFMlCEqCGNjWrow1Ksrz1mjJ458SS/nWFoXwWC tov/mxaFYlWsLK8tEOiM5Y1UWIMGnmvT5X3azflZMVVV/aFdN9eWqlGUVi1obPVXYgjW+tf/iLfPi LNfgRvMyE5DZD2aEbXyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAw-00ERQT-0l; Wed, 11 Oct 2023 00:34:10 +0000 Received: from mail-dm6nam04on20624.outbound.protection.outlook.com ([2a01:111:f400:7e8b::624] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAi-00ER5U-2Y for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OCK8fNQUiR0wCTQZUpqsEY/bYwhzKSHv3B9rGfcgncmkDFCJYQblBH380jHWkx/gKSNjTuB+o0PItQSrMOcNMymxzguMgje5aOtIl2i8VjKu8Ys2mFg4z1UVLCB4V7eTJxT8itzZEw5gRUonipZXfQY9Sx40+bkyEtt6Co8yJ62GnjPE8Mlqxf/ynvJzKzp/ex3gSTlGQxxxdUPz0Plp4xGPE2Baz+pMiJNLmqaxjmv23phnqhRoxBzbTIOTphLan/yOhydmMobSEol49MbAbpYm7Ika21NlPbwEWN5MPjSju5O2/ydxvSs+knmbQMgdPrxSh/Wk14XdqZq0hwwXGw== 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=LU1VnFcORe3Garadx4FemnCc/4o+ni1i3OYVQDm5PI4=; b=JIKJVe6oVraLWi4QhdHGIksx+tMsRP1ZG1V3VF79oxz94BTRDlO0Tqq4jbLmg2EUqDaZ4d8vLm4C6X8TOmkrMdng2s1JaF7BMvXvhaoKk9dJBDpEFd+CdH040pNCu0VHy8CbTdPlDEDc1trEbjc5T478I8JeYNH6Nm5eMID8wZr4dXLTddX+xG2q9PIhsxPL1w/z00getsh0ER80YfIZRngvE8B8jXfsBKowXYTlO0PhCvjg+Tp5eMMu1pOk3qI7Uy5SPnv5GzacDGGxlNgKEN8gzUwXHRhVuGJjTMOsxvObCom2coUW+jcNjZHqMHJAikpxyxbC2d29aE24VQ0NxA== 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=LU1VnFcORe3Garadx4FemnCc/4o+ni1i3OYVQDm5PI4=; b=ivviCDxssAYAe33rFP6o/pdJvtsriCCMdrzCsFaDIOr80uFoAkKY4bBsftcxcOQJq9vTEIsuGcQ/UIBWIEEZheh+++qenUMu1tL9Orno4qY8Ul5zjpKKJY7vig2iSGX2XUg4x80K/wZpEhhiZObxmrORONIeD2QDxJFcbO+4BU7hVcSpASgA3bfB74OTz/LTjgq39+eWoHmArUj9wdGWAakmtwKHyeH7CzH5l0eqHbk6yKO+LA+onrddMrsgr5eJHHp1/qVHqaGBEYSgTuiqVkZ4SlCPkVM9N5SDBDdzhcc/SlzblackC6fzfn9F5SHYc9qX2+553yFE0IbWeSK+6w== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:30 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 02/19] iommu/arm-smmu-v3: Master cannot be NULL in arm_smmu_write_strtab_ent() Date: Tue, 10 Oct 2023 21:33:08 -0300 Message-ID: <2-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0020.namprd18.prod.outlook.com (2603:10b6:208:23c::25) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 58051e5a-ada5-4f2d-25b9-08dbc9f1af41 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UkUUg8ft1g744IrmRa8aBFrE2LKVgFutGAQIXsztjc4Gub707FvY6vOH8/pqoM0iOXvTvYe6NpNo/6ylgY11xMhCjQSJjCSoSGwjFeZMSpZTaXhzQeFdfuyVElw7bqtKQLcuG41b2Y6LdeQ0v68wQ9kudYfGsCY51+vj+UXHbWBNXqW1ERPxjtw+XcB19oNZULpKWJSDT7WgkurI0rnPq1bSyd+GC9t9ZhDUVthZ4YVxSZ9ROUS5tSBmArR+ipLuksGtXsWPcKtpSKEm9RrAMLWXcVJikTXQldWcfFwF+Xp7wWDIz7en7W34G3PGvvD7WDAHk6T5KoC478/DvmFxUglZFxojORaqZ3iTbLMUqOTQKmz2L5pyeiS4Dip4d9R9OEnjPqNUruCpcvDeN73QrT5LhGq1+DSAX2VY4hQtpoZb1HytW4yqZGySdI7B5ww0GwRTRyeVcWPQqA24MOfx9OohBcE5+QY3bVvgqbfYQMRrH+SO6YHBbykbw0sPWbPxcCtiL79h7ZNJ1GxvUhfiHdc32mfXA2KXkBFlxdovt/e7wdRTN+q0gdWXfKh8BVOwlaD44vDVumUheOc3xOZnqz+7nW6UTTcjr//Laz/2dVo= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PKMU/cBYUEX0iOAbGngjTDC2phEj00y4yiWjXeGrzbqWztW62xv6k+kd5un3rY2LfgGsElLWHujpaWcopdzDllLLMlB9Snl1LglcF8Jjm7bbrm/6k1LKKKxyZqdWRBosF/U4K/AqMiHExtK9E9E6KZjPx3UNC18eyeanIwkN/ZKvzFMIBagSaDT9qEJHrRkVBDYgDAfnqTgf3WlJwNQ1sNNWDq3gPGkeMT1+hj1x1Y4bGwLAjj5n4tAobj4UEq7COxjTzppJltOxwT+ZfKAte7JKzd726rFcOWG0Rd5ISQaQeugobV/WPhCOH49gLLPb6iIpeYTJhXzHFo0gKR1W+FOLFtQhuWotvbR5L7ole7qX2w6z/pfeap6OvlDWB81DXq49a/ZDk+hY2EcsoiYd4e5A9HUx+UjfAe3A9eIHep53hAEp5OCVvWWoMd/fVIlT1NjcV6LbhzxdWqfmL91wgIX5ND2+6yzRZuxe0F/f7MBvC+cFlpd6MLf58gQCuaDFwONfGNXGHuktAliFS9epNtJW4LKc++OvzGlP2kdIYJaji+NWr3XQPyuOUTar4GKzhUhVmpIA7OMdE3ahhkWOTxs2amxrgRIaXvAJ9JR0hAhebjdrfEriwvbsh44QJEFete5szf4mCl+YEPsXiWJ5e1fqRvUnSbxqXs0ap2tPj4bfIbIMPEkeK7IanXIc+7FTbVCCObMfWxC5BcTy62IcOp9LjhaDUXJHPtxkQToP15bCaUMR1ReqyQInpfDDC2Qk61FyGHFVF/diT9IXcEHNcA9dB182ZXWJ46AfJtn8tCc6kwQ0QJabyUa+/nJ1y1/B3lOBccKYAzF9DJzb7h9vrvhy/OoW/JdeQUOecsitsNz85n/M4i7IEnkFYE0LvR/reunHe2K7jxDJt47TiCLnf+fFEJMtvOrPb0ql88RcqXXocy5qs/WQKrWU3+sFbHlc086lDYT+WWdZF6Uuv1sSaajLlyG0hVWW990TM3ASP2BIl2OtwdWBFS1ygHKSXrJGFNHtNFMu1tk7fUciNgQQjssnlOlZStoW90DjW/M2O0yqOdaJ7WnnXHjlYjTm609m5TJcKp8Sli4fcRavNgJQjY6MVrh1xODqZMrSqVx4pmB6bXbd/G7tCTLNs0NXl8qLjcD1WHaxImxOzGwbfiIZRltdCivE6Nnto7p7Kh945cBfQ1CLAyIEGF7g6+3/MQugsZDBv+GzVqOcxrj/DWjZUqz5U5c/qcdc5ABHaDpZQEaYBgcCNazxBeC2TU+MtpwdiXeV5XpyfkgZ/Iu3RuoEqEMx9RWSSLWw/ryDB+P+c7/sIcJbZ6Ydu3yQ1AoYQF4WMzZac5JpZUt+ajW4w2uPU4G13FjIx/tTd2lwKAg4Loa/nNfTypDaGCXyurAJPrMhWSA9fsGWU0//b5pmrWaL15Z30nhxve1sOiSn+ZMIHJu++ArXmGhN7HdDXHnMYi+8jhWuHQ8xyBWIKVlaAz58ataRATJbnhJgE976KnESD2+QNeiYS2le+hbXj+6Pf+5//pv9uv7fSHAva5sFLoayilcDeMHnEMSitK9J6wiu4kAriRKGXFTGmNfzuZgnA8Ez X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58051e5a-ada5-4f2d-25b9-08dbc9f1af41 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.8573 (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: 4bj4yFVsDFBMe82iDA9eHbsHK/Ob9XcZYbttpQLU081FWcib+h/x4mGid4bfmsPG X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173356_849646_35761AA0 X-CRM114-Status: UNSURE ( 9.24 ) X-CRM114-Notice: Please train this message. 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 The only caller is arm_smmu_install_ste_for_dev() which never has a NULL master. Remove the confusing if. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++------- 1 file changed, 2 insertions(+), 7 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 519749d15fbda0..9117e769a965e1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1269,10 +1269,10 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, */ u64 val = le64_to_cpu(dst->data[0]); bool ste_live = false; - struct arm_smmu_device *smmu = NULL; + struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = NULL; struct arm_smmu_s2_cfg *s2_cfg = NULL; - struct arm_smmu_domain *smmu_domain = NULL; + struct arm_smmu_domain *smmu_domain = master->domain; struct arm_smmu_cmdq_ent prefetch_cmd = { .opcode = CMDQ_OP_PREFETCH_CFG, .prefetch = { @@ -1280,11 +1280,6 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, }, }; - if (master) { - smmu_domain = master->domain; - smmu = master->smmu; - } - if (smmu_domain) { switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: From patchwork Wed Oct 11 00:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416486 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 7937CCD98D9 for ; Wed, 11 Oct 2023 00:34:54 +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=dsiph/aJeq6USTyXuU4Ks1Lbwr4UdNsi55uVT4RMZbc=; b=KPL1eoBZ+m0p4L uMo9qNEb8ljCYMTAhkbiorfj/QNr9dxU9QIfd1qerGBL+dnq/5JLuvsjn8LdVz+hD+lmLoOXdB69j 4B9F5obkZY0VblZnU/P2FIsrxavnuH6axA8EBPuPyGqeghnY/4evCEwmGECz/bkVSI5PF3JyzEH8n +mgDYCXv7yBsOiMG+Qg1L+JUjolPhg5Y/+mdpfUfgxPo4YwsBk+1BvyUR+hLSPQ1GRIsux0fvetVZ 8x64kRFqZkWQLoaNVt15JObQfMpjldQlkgVF8y27qxKQZuog/heoIcOS7uANnNEIXeU/UGre1f+69 o1iWniqd2rDeQ7z8mM2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNB4-00ERUR-0A; Wed, 11 Oct 2023 00:34:18 +0000 Received: from mail-dm6nam04on20617.outbound.protection.outlook.com ([2a01:111:f400:7e8b::617] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAi-00ER8o-2S for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=islR07DKAc8dfe7nG/WwDm6H6EGPMgJUGzrOdDM3WeFV8ME0KuIc4iyzFWeUE4u6+h0EnFZOa8ZKKBE1xCcsm8b84KwicA+UN157LGjwFhylN2qUdEB8Joz3y/49571gN/uG8qzopGVcbb5wptABtf49qKLtCMyQtLnpDcwOWiaxw+15UWPUK7v2K9szln0bxWZRGGOFzLfr9w+0bflUWoHcPYRerTwwijEt1EHe+OmX94zTl499/XqgJhG21PUoUAh8JbZ5H2hd8pflGvNm3vYZAbLSwEAWjsvtGf/Fgy6dIUbIIRIHFIzHANRklNnTVJOih1ML5pfq6Kl8e6uvOQ== 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=+jfjLgiQddbkGMxPnFEHgFgTjad/UVbGA26QDxIp3W8=; b=eMg8JC/Fs19RdcU7Z0sagrcY+gyw4F38kduzejc7hOQ1HKTOFfr+ubW1HEgDHamFa1YbqIUmDoG+3QQHjyDszNoOkk68iEnVrjMI0UFvDzIKZog+mcA0obRY/QkvFzPJFs9TAoz/6/oBIuZoik76U5arZ/JHneX98579LxLFO/5B/1o2nEgsMHffxfnjF9Rg4JQZx6H39NcSV1gUP5bLbsK06NLVduaEfywRbu1FkviKGBTDlDJ/S1S2dP1AUz8J0KXlcsjkXc46SZ0w/XLl1los+UY3/TdhEpJFtBt2ODoFs1qeSTXmiaPkYcaLK4o3sKR0pKXsEwHp2H0wLOT4xQ== 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=+jfjLgiQddbkGMxPnFEHgFgTjad/UVbGA26QDxIp3W8=; b=Zc5FiWesiejL9kLhvFESDarX2gGee+wSN7UWISSQQ8SzPqANkajWWqxWgY4R1Ge6R1UZ3bwzstZBhXPqx/0pgquK/LN6s1ddsAILhX8FVglhyXwcjqRSEJ3SbLEAhgWNGe6Ny/Z2m/XE91iOzOSHgqHPIGUyYxXtONnB2bZPpAGoRaFOBdfaUe24i3yBXJYr7zsZCds8JY3Ia15fx9XNn9rUwcaWXpOLyZ5aa+6OKAxYOVvGahRLYi4RC97vfiCrMJBeQXKUCfzJxMABhUYa9h4Zc1dJRnQMOWOrZzplvTkDV2usWcDq/0ULqRFqUILsysSDy/L6ExICZehg70i8xA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:32 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 03/19] iommu/arm-smmu-v3: Remove ARM_SMMU_DOMAIN_NESTED Date: Tue, 10 Oct 2023 21:33:09 -0300 Message-ID: <3-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0413.namprd13.prod.outlook.com (2603:10b6:208:2c2::28) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: e1226df5-241c-4010-d1f4-08dbc9f1b01e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L/rxMpah8KWY8ME6+G66r3TZxtJlyGxGVJLmsA1x/akuhqOe/MA76VwR8bhv8TXyT8MDV9I/D9EeNeKiu1hvNVMU/xQG3O9v3kwCCu3CMMaRqkJVVRGJuHoPBhuY01/2PP8p6BuzkDc6BV+MpFucIBWkz20XZtu4zwj+pBLp8bqAUFn4oJ2uUG6HDqrzzu56f8lrcOvgPZscWrBr3b0r9KJJMCNKqGxSeTwtN1CmmxWfME0pVhLyPTnRXfpNaLa+KJ5FTqi06Jv8sR9AUNlvfZ3MOvGWljNQyTvu+2H0SkBplrOmYg9N4rWV+HU4LnbDPP5+Wk2WyXpX/pKVRNdmhtKBV/TI06PAnjUZxtafGkeu8dkqG1ojijKfwep++o6DTSVEX3jYs8cKDK2+AEQhKdO46Dubik2oxsE+f3HbQqrMeXl63uOcdT4hxK01SVk985NfA8AVjL74Q+2VRY3yohuCUCjBjwKps86S1/G1vejmvv8UX0hjXGEJZAm8AVeKroOd4jgyas2lPvh+UPi0HNp4VusbBOKwuVC18jGuxgmk8lLD5Sf8RMfpkGdKJLVV8yXeDEoao/CgyqpN5WtL+zHjrzrAybFx4lUE8va0v8k= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KYkowyP/KLGQJxLM3i78dxk4VMe2lQWVAUvnIp6PyjaYU6jPj7g0Cwz/BDUl0wqWfuRBUr3aXLnu+ryVD0YnP7jQ8z1bV0t5jhm6FC+3JszoXx5csTCe81rvJGVK84u7j+HxOmtclDmd8DGi15jJudBNu17UNM7vCML2mFCYLiOoRpJnvmrBc8/4lPdNVA5Qa3qobXoXPJEs7xJdzeVP7fehKpQ4jYqHK3rEUfE3qVvhsy5JSbOnpBoGrOo6ICpVvQoByNWhQjeYFEJPdpyGGteC81aPyrJguxe57Xu4brbxQYhro3FTkx8cRiBjGP0Bxp+Iwle3iIW1SoS1s4weKxtTLmFE25Nvql/j0ixkSnqaBzkXvZsG6rE/OIkiSSVOW4q0Sf0A3hwchkPhtZgVJQcjsIcnsH18ZVMkyE92G9EYQnHJWAij4PxMkZ/7YwqLVZ45nAlkXnehRr2t3voEC4qKTyd3BZrWsQ16tmBc+AhFlx4ripK78Dtd9gaobXNRtKAMTqCcBtAW8yujFBmM/2jnOx/QFLYGUc25bUh+gKdexKulV1bxyWH8k7wVUhduOVC4WrT3dfrK97UbKwJuPapwgXPWTQqpU9+Cc/gwjhZ8T5pDqwH/PQF13dqV+QefIEMKh6QvFiCKltIz9jxwf9EloeIKAAa8HFTGkdHHEvR2a7rlQJs1iddTcDFYg67wEznuF8byD68yrxIEH3xJNXnv19G4i3je7M/s4+Pg/V+2UKg53cmyYLLGu4KXYgLqGmNIt7wgPHFBSYRpoBJInDCeoVYZ4WzQS3xXCma/2YZSTpixft3YiT1qeldPrCg2SdbL1cchS9ju7pJHE5f5nVIhKVY1oj8HrX5FNDIBPE5fVI9BNs8fR9wwtXuBx9alDZCuQBN84RkNCF6Q4e8+U0ceFBj6CooCJwG7d6UzbRTSV3ahyh5qSdA+rVT4vxArOE66N+1GrKFY5VZ1hOAs2zBiSUWE92Yu0MQJr8o9WGcrtUtVWJ2rmW2KchYsL2nzEMVSGKesTQ7IDHH9oqGHs8HFDOhRyKEmTFF7isnzLLh8CUPNJefHOxVtCCNVQhbC+noW6ZviBCngG7mWEcrpA+zX8sbECbVhnbWpjWZFPpvamMrXa12g5cqkkkYoMap+51UzjHKKbSXITuZic9M+cOCVrMOiiWrUt33GIuhC3KIfOmQYoIh+ZoRWuWXERZO9PH1icPY1S5q2KT+xk0fDT/IuC9eoF9QS+kvD0US4QiIBSWnCkcxOJ8tGd8OWAPlQulewYj0z45/Uk+ECOzHEZz39vUts2qggb54fa5MwjVVSanaydmrn/WIWxbcQvNKaUjcQ73Z4sA8LHDrrVg9kvecgnvceWsqTNvckxYP7SGTLNIaDJ9dlWgLskMCZ8Opy8EkpCxomkU9TlurqowzBwMZifkx67tQraySDCi0sXwyEjLM74DkAtFWWmfK9qxCPMPxx39vQFyKzQVwaoBR+0Y0azOXdElJZinjf/owEMuUvEHiUlMl/lksoV9hK6Vl0tg18zVKolJvXgSgwJ0rEPvuZXKDtGmr8MkiNXWH64VQImnNRIZBy++52b9+pP4Xr X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1226df5-241c-4010-d1f4-08dbc9f1b01e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:28.3068 (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: l2VF3seq/G7td0PT2sYN5NkD0rmNisY8TLFD/rXPwbtHGZcBDl4g+0yxxc8Dmt2n X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173356_826112_74CEB64D X-CRM114-Status: GOOD ( 10.77 ) 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 this is exactly the same as ARM_SMMU_DOMAIN_S2, so just remove it. The ongoing work to add nesting support through iommufd will do something a little different. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 +--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 1 insertion(+), 4 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 9117e769a965e1..bf7218adbc2822 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1286,7 +1286,6 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, cd_table = &master->cd_table; break; case ARM_SMMU_DOMAIN_S2: - case ARM_SMMU_DOMAIN_NESTED: s2_cfg = &smmu_domain->s2_cfg; break; default: @@ -2167,7 +2166,6 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) fmt = ARM_64_LPAE_S1; finalise_stage_fn = arm_smmu_domain_finalise_s1; break; - case ARM_SMMU_DOMAIN_NESTED: case ARM_SMMU_DOMAIN_S2: ias = smmu->ias; oas = smmu->oas; @@ -2735,7 +2733,7 @@ static int arm_smmu_enable_nesting(struct iommu_domain *domain) if (smmu_domain->smmu) ret = -EPERM; else - smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED; + smmu_domain->stage = ARM_SMMU_DOMAIN_S2; mutex_unlock(&smmu_domain->init_mutex); 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 03f9e526cbd92f..27ddf1acd12cea 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -715,7 +715,6 @@ struct arm_smmu_master { enum arm_smmu_domain_stage { ARM_SMMU_DOMAIN_S1 = 0, ARM_SMMU_DOMAIN_S2, - ARM_SMMU_DOMAIN_NESTED, ARM_SMMU_DOMAIN_BYPASS, }; From patchwork Wed Oct 11 00:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416458 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 DD3EBCD98E3 for ; Wed, 11 Oct 2023 00:34:19 +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=hw1Rs1Ni5ev1C6uefIWwEWMIUIijaTfhnTMn9LD2PTs=; b=BvId+Y7CJ9ZLc3 9cdd61Ye3ckUKrlgaIWDs+swcTJCmkPXVbm4eicdxwysRREuy3H4zRL9HRQ64JBR3RfcvqR+HlQCE qhvBkkyYjXm0zl3EBLlm5umV+czggRPUtxVt3EMadnBPBheFJnZ3a0LmIQkkHniiO/85VNbU2JS8i etvuvomDnMoZe8CE+7nVwB19UYrAjZLN3oK0fJMpUelr7/78M0uTskIBAVZ9n0h13aw1r8ZDWW+nN TnvaIvhjtnwmLVis1/iIg2boMt9BF71Wo0ZW/FzyPK/fS+1NcAuqIO1pZXOk7c87S4GRNtuheDzxI iCjkmn5YWvuAkXpaYE7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAY-00ER5D-1e; Wed, 11 Oct 2023 00:33:46 +0000 Received: from mail-dm6nam11on20605.outbound.protection.outlook.com ([2a01:111:f400:7eaa::605] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAQ-00EQyC-0H for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GwaQThzob69r7JYkM4jAOydpcXNLgJpJaccv/gpsiYfJg7KndFlSaosucYF2n9vdvB9ZHpwtLfYWrb2W+SNU31BpP0rFAIqWKMCY+fVRg+xEVfiMA2yw0jglxQE9aoYq+8odhzhf8FhT+OaVXmjJfAHESPhaLgSdw4ZBT65MiGb1e0HcGh5ylJO44oaaakmWBJL9abD4O5aEPMUSEweJV4CmW0barzz5sQbpG/Hx6yTLb00ODMu2GVsbK8ePyidhkrzzvw4TuuwEK6QUvm1LwW3Tb/TC7UiYlCViQnfxghRUbSl1sVQXAespy9SRRlLuem41fofdFuBoDKsrhVYoTA== 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=D6dWbNrR/nEF6btEMTVv1f+7dExpUXjbUUby1CvnHKw=; b=Jm5+K5koVDJvxdkjSse0YmFa9OeNbTElgO1r+N1DP9ncWWbATS8RFiXRcOUb0mwRL2EI+ay060VfWnE6JOj5dmPpAWhU12j5DGTKbO7Hrk9AcOshznz+7OmJPC0lJyEiqigLd5bM5DESK+Y1swMBJsKb0bRgDBVCIzgUIjFnQbGQWLpJdDdzCMfmyOej1Lhey5KfXLozGK16hjN4ektVA0j/1OEmYKvyTmevmA8qv9Qf5HZvMLCCImpOFNVwHbphGsfQCKH31fp2mMhS5flfDrQ3LnRpV67JIhlFoum48+hr3z95szW+JbdCKTPDAJAjdY9XDQ+npqO/iw/FfMw78g== 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=D6dWbNrR/nEF6btEMTVv1f+7dExpUXjbUUby1CvnHKw=; b=C5IWl+ztR+h/E6adGi1u7KhJaFlC3LT9FYPQmLFUJa2tni/cHaAOCZZRA8hlgiykKh9Ej/SrWWJRqmWOzlLO7bTssEoS56+2FbOBY8jCEtWoGb3BUvCxe8M1JZTDsEWi8TJPP5jpqX0x/93wqJA9SETyXiA9nsuVFmE9mrtWHtrVqJT0CdYTgLtTd1h1RgiNPnJt/c68jl4QEEjUTdS/ajPsbpthOsLuOrdr4dHsnQQk+TVmkLtfF/eVofqHzFqyh9KpQ7vywHV3Ojwgaj9xfmNdKwnsxpQ1Fud7ck/3OKeHS99WMeLkQM1Rqa09wdH6vJEZx25NujI1pEISdy++7A== 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 CH3PR12MB8658.namprd12.prod.outlook.com (2603:10b6:610:175::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Wed, 11 Oct 2023 00:33:26 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:26 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 04/19] iommu/arm-smmu-v3: Make STE programming independent of the callers Date: Tue, 10 Oct 2023 21:33:10 -0300 Message-ID: <4-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR04CA0012.namprd04.prod.outlook.com (2603:10b6:208:d4::25) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH3PR12MB8658:EE_ X-MS-Office365-Filtering-Correlation-Id: 3bc42a3f-0333-4e07-695c-08dbc9f1aec0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6ctZZL98KwECPB0qgWEjRu2kbMboiLP+D/aOQJn2qs4jqmz6D+sOs6IgBRPa/TSOGfxbB680TuBHNqhAN9PL1AldqMEaC97FzNn38oY6cYGXLy6HbhU2lkLSRD497Lnc9c1DL1bdb89VCG79yhXBKBo/+DM5FPlqrVqrq8IwunaAEyQMJ38r1NrS2+dcLXl9bezepIbHChwzISZX1kKe2Y7LeaL3wimW7xm3VaczTPvx3e98cj2tX/yKPs8tRL6NjAJ7yRa/xttgEUw4oCNkXaSkEeXYD7YY7oQR+eRQbSc6M2Q0XMx4IZzia2phj9kXIB0dQnLK5xq/7wYquZhyHy3oUoN2VY6sErxLogTzMdlA3DUE4CuklUgghE8EMFm+DnYVLy/Csypxifp0/dt0CZnP4Cpk9rP4nQK+yHvGUXNjin7OM/7oJzdB1tKfe1DcqrQiY5PBeq0w1lU3fUWoBtNKvsW1iXC2dNrOQyGxQThzDtWa2rJavLY1FBKWGNMfrnQror+29e0kJ5rLK5qLIFNpvw0tDcNu6uI6IWsZGv++kM62zb4f8bcdCV5PZDRe4hdGXx5CB+sudQN0EPA/5qtvqgSyG5fcGM+NDfR67Mo= 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)(136003)(346002)(366004)(39860400002)(396003)(376002)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(107886003)(2616005)(478600001)(26005)(6486002)(38100700002)(316002)(66556008)(66946007)(66476007)(6512007)(110136005)(6506007)(54906003)(5660300002)(83380400001)(41300700001)(8936002)(8676002)(4326008)(6666004)(36756003)(86362001)(2906002)(30864003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UKyGu54CmcvhlBK3GugdcK2odVEQbnxGePxPMYrrHfmRwY+h7STcdOB+Ei8hCFy7H1t/9iqGtOgI6xZliUPs/ZyC3l7JoanNclDLFoAP5B3FNyFuwZk2ShjVNEjdw68W5w9ke4OCfVHYdUo/GxL0FOqGxABHiVssGHoPewuysBPKtm/CmxGxj3NcRq0DROovc2wfWndwvA5EHFnhOOOEBXBiR1VANaAC/xGjJyL2onGH3nDtETTvDcWfKeTDLnf3/+uz8/Kze1h86i4qkKDBNPjdhakcZNJRSsLgke9sEaNp0+wi9YPmhG22locWDwcm/tC22fZy28MFOqehIPGNIPI+/jqC8v2N2bkwqlXxnY0p7Wzt7tsLSLyiK8suyLhwddOH/sNV5BUiB97G3MgZsff7mygXJnATqly8kS09ysmEm1XjRRHm/gQ8KMIyDVtJ8aheJkcSF3KSiHmaHPniZ0zMCx1vsU4C0rVAcqaB+fJfuvnjWTVbS/1GcB98zhDkCO7jONza4oZcS8H8L6mZP37OurTfS8EXkLXq5lIxVOG363G4bK2LCSE/4Vtjjpwarxp6dEW7uZLqpl3E6TuCGBEmzA2iZANV7FwDwQulkPC17GsAD2JdOKVH7+GnLCxgTiZ6wCAVRVWXyWP35EcuX7uEyMtuOQ5mjbbkLDlPMt6nO2DWwoFLAaMB5Cd5ux0joCxuUxw2sdVRua3BK074JADAMw9q4EhVU3rRkfZ/ENPyflhR64VvIsKBT3VWBM7KT2spHAst1ONABZWhlHrl85upXZ7PXkEnANdEl3C2xEbJwYoKPNb2dR6KMqDsABVCQl5WC3s6hik2hD1MdsSx972pX2NqLQAHtvNIyxMElhrVOEfjPeB04DFtyCbwO5mwaGE6flTh206NH96YJ437alrLdP/cVe/pMarvIe0GDZGTj9uHQh4FgOJTaSNx30XsXB4ItJ+te36OxQ5+sPEHH1n1AcP+z65kn1GOa3WPHowGjxevzlVi9ToO/nkhGKwqOKCBYii67k14Wv3LW/6gXz69xA8ZcBHwQo9Blr30iFYMlfJ6JxcMef3SX2cetguXZCRvcW1+BggHmEYxtQ94jf3avvGFyzrTrFN9Ek2JK92LzaQh+oPZ9aqY+5/v/1Ym7EtXd35B64EPW+GYNfrdtCZiJStOWzyDufSxhttUJhmOdgn+3D6a+H5SpTKWeyuohdZVouADoEcNhHdfN/omIQF7TBQz+kXB3OpTBvuS00nuBesSh6o+yr4BCmEcI3C/yYRLkAcvSD5krf/44/4l3EmyV2hBl+G1qZA2zk7MmsXvVcJ/GOsFvNmNbW2u/tRv2ilboR77EmSf/JBqdktOslnU+seiYZS2sxYMu1qXOHmyvg2SWT0jtjNQ8q3o4COkW9TgNXLdpl9F0O4YVxkyAfynAjyiJseEBeCszdRakK7tI0rEeVABXHeWjQXeZp9Do+vBhjsoGJypLIESaLL8e17jh5wvGuJLhNg8Hk2JSQVG5HrTXNDZVBZQNmxoMzh1gXZ9nfwKvBHluOoMnwVGZm7Umt0zeYe0SwG2ZndciIFOjTw0Jl0pAt8q+RGCh2G1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3bc42a3f-0333-4e07-695c-08dbc9f1aec0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.0590 (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: Mdi9MjvYDU4xYLrHY1FH5pt245/QBplhfxl1frBsbDPggUX/x7FYz9wb1dIu1wGL X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8658 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173338_215258_372E63E6 X-CRM114-Status: GOOD ( 33.16 ) 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 As the comment in arm_smmu_write_strtab_ent() explains, this routine has been limited to only work correctly in certain scenarios that the caller must ensure. Generally the caller must put the STE into ABORT or BYPASS before attempting to program it to something else. The next patches/series are going to start removing some of this logic from the callers, and add more complex state combinations than currently. Thus, consolidate all the complexity here. Callers do not have to care about what STE transition they are doing, this function will handle everything optimally. Revise arm_smmu_write_strtab_ent() so it algorithmically computes the required programming sequence to avoid creating an incoherent 'torn' STE in the HW caches. The update algorithm follows the same design that the driver already uses: it is safe to change bits that HW doesn't currently use and then do a single 64 bit update, with sync's in between. The basic idea is to express in a bitmask what bits the HW is actually using based on the V and CFG bits. Based on that mask we know what STE changes are safe and which are disruptive. We can count how many 64 bit QWORDS need a disruptive update and know if a step with V=0 is required. This gives two basic flows through the algorithm. If only a single 64 bit quantity needs disruptive replacement: - Write the target value into all currently unused bits - Write the single 64 bit quantity - Zero the remaining different bits If multiple 64 bit quantities need disruptive replacement then do: - Write V=0 to QWORD 0 - Write the entire STE except QWORD 0 - Write QWORD 0 With HW flushes at each step, that can be skipped if the STE didn't change in that step. At this point it generates the same sequence of updates as the current code, except that zeroing the VMID on entry to BYPASS/ABORT will do an extra sync (this seems to be an existing bug). Going forward this will use a V=0 transition instead of cycling through ABORT if a hitfull change is required. This seems more appropriate as ABORT will fail DMAs without any logging, but dropping a DMA due to transient V=0 is probably signaling a bug, so the C_BAD_STE is valuable. Signed-off-by: Jason Gunthorpe Signed-off-by: Michael Shavit --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 247 +++++++++++++++----- 1 file changed, 183 insertions(+), 64 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 bf7218adbc2822..6e6b1ebb5ac0ef 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -971,6 +971,69 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } +/* + * Do one step along the coherent update algorithm. Each step either changes + * only bits that the HW isn't using or entirely changes 1 qword. It may take + * several iterations of this routine to make the full change. + */ +static bool arm_smmu_write_entry_step(__le64 *cur, const __le64 *cur_used, + const __le64 *target, + const __le64 *target_used, __le64 *step, + __le64 v_bit, + unsigned int len) +{ + u8 step_used_diff = 0; + u8 step_change = 0; + unsigned int i; + + /* + * Compute a step that has all the bits currently unused by HW set to + * their target values. + */ + for (i = 0; i != len; i++) { + step[i] = (cur[i] & cur_used[i]) | (target[i] & ~cur_used[i]); + if (cur[i] != step[i]) + step_change |= 1 << i; + /* + * Each bit indicates if the step is incorrect compared to the + * target, considering only the used bits in the target + */ + if ((step[i] & target_used[i]) != (target[i] & target_used[i])) + step_used_diff |= 1 << i; + } + + if (hweight8(step_used_diff) > 1) { + /* + * More than 1 qword is mismatched, this cannot be done without + * a break. Clear the V bit and go again. + */ + step[0] &= ~v_bit; + } else if (!step_change && step_used_diff) { + /* + * Have exactly one critical qword, all the other qwords are set + * correctly, so we can set this qword now. + */ + i = ffs(step_used_diff) - 1; + step[i] = target[i]; + } else if (!step_change) { + /* cur == target, so all done */ + if (memcmp(cur, target, sizeof(*cur)) == 0) + return true; + + /* + * All the used HW bits match, but unused bits are different. + * Set them as well. Technically this isn't necessary but it + * brings the entry to the full target state, so if there are + * bugs in the mask calculation this will obscure them. + */ + memcpy(step, target, len * sizeof(*step)); + } + + for (i = 0; i != len; i++) + WRITE_ONCE(cur[i], step[i]); + return false; +} + static void arm_smmu_sync_cd(struct arm_smmu_master *master, int ssid, bool leaf) { @@ -1248,37 +1311,122 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } +/* + * Based on the value of ent report which bits of the STE the HW will access. It + * would be nice if this was complete according to the spec, but minimally it + * has to capture the bits this driver uses. + */ +static void arm_smmu_get_ste_used(const struct arm_smmu_ste *ent, + struct arm_smmu_ste *used_bits) +{ + memset(used_bits, 0, sizeof(*used_bits)); + + used_bits->data[0] = cpu_to_le64(STRTAB_STE_0_V); + if (!(ent->data[0] & cpu_to_le64(STRTAB_STE_0_V))) + return; + + used_bits->data[0] |= cpu_to_le64(STRTAB_STE_0_CFG); + switch (FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(ent->data[0]))) { + case STRTAB_STE_0_CFG_ABORT: + break; + case STRTAB_STE_0_CFG_BYPASS: + used_bits->data[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); + break; + case STRTAB_STE_0_CFG_S1_TRANS: + used_bits->data[0] |= cpu_to_le64(STRTAB_STE_0_S1FMT | + STRTAB_STE_0_S1CTXPTR_MASK | + STRTAB_STE_0_S1CDMAX); + used_bits->data[1] |= + cpu_to_le64(STRTAB_STE_1_S1DSS | STRTAB_STE_1_S1CIR | + STRTAB_STE_1_S1COR | STRTAB_STE_1_S1CSH | + STRTAB_STE_1_S1STALLD | STRTAB_STE_1_STRW); + used_bits->data[1] |= cpu_to_le64(STRTAB_STE_1_EATS); + + if (FIELD_GET(STRTAB_STE_1_S1DSS, le64_to_cpu(ent->data[1])) == + STRTAB_STE_1_S1DSS_BYPASS) + used_bits->data[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); + break; + case STRTAB_STE_0_CFG_S2_TRANS: + used_bits->data[1] |= cpu_to_le64(STRTAB_STE_1_EATS); + used_bits->data[2] |= + cpu_to_le64(STRTAB_STE_2_S2VMID | STRTAB_STE_2_VTCR | + STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2ENDI | + STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2R); + used_bits->data[3] |= cpu_to_le64(STRTAB_STE_3_S2TTB_MASK); + break; + + default: + memset(used_bits, 0xFF, sizeof(*used_bits)); + } +} + +static bool arm_smmu_write_ste_step(struct arm_smmu_ste *cur, + const struct arm_smmu_ste *target, + const struct arm_smmu_ste *target_used) +{ + struct arm_smmu_ste cur_used; + struct arm_smmu_ste step; + + arm_smmu_get_ste_used(cur, &cur_used); + return arm_smmu_write_entry_step(cur->data, cur_used.data, target->data, + target_used->data, step.data, + cpu_to_le64(STRTAB_STE_0_V), + ARRAY_SIZE(cur->data)); +} + +/* + * This algorithm updates any STE to any value without creating a situation + * where the HW can percieve a corrupted STE. HW is only required to have a 64 + * bit atomicity with stores. + * + * In the most general case we can make any update by disrupting the STE (making + * it abort, or clearing the V bit) using a single qword store. Then all the + * other qwords can be written safely, and finally the full STE written. + * + * However this disrupts the HW while it is happening. There are several + * interesting cases where a STE can be updated without disturbing the HW + * because only a small number of bits are changing (S1DSS, CONFIG, etc) or + * because the used bits don't intersect. + */ +static void arm_smmu_write_ste(struct arm_smmu_device *smmu, u32 sid, + struct arm_smmu_ste *ste, + const struct arm_smmu_ste *target) +{ + struct arm_smmu_ste target_used; + int i; + + arm_smmu_get_ste_used(target, &target_used); + /* Masks in arm_smmu_get_ste_used() are up to date */ + for (i = 0; i != ARRAY_SIZE(target->data); i++) + WARN_ON_ONCE(target->data[i] & ~target_used.data[i]); + + while (true) { + if (arm_smmu_write_ste_step(ste, target, &target_used)) + break; + arm_smmu_sync_ste_for_sid(smmu, sid); + } + + /* It's likely that we'll want to use the new STE soon */ + if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH)) { + struct arm_smmu_cmdq_ent + prefetch_cmd = { .opcode = CMDQ_OP_PREFETCH_CFG, + .prefetch = { + .sid = sid, + } }; + + arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); + } +} + static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_ste *dst) { - /* - * This is hideously complicated, but we only really care about - * three cases at the moment: - * - * 1. Invalid (all zero) -> bypass/fault (init) - * 2. Bypass/fault -> translation/bypass (attach) - * 3. Translation/bypass -> bypass/fault (detach) - * - * Given that we can't update the STE atomically and the SMMU - * doesn't read the thing in a defined order, that leaves us - * with the following maintenance requirements: - * - * 1. Update Config, return (init time STEs aren't live) - * 2. Write everything apart from dword 0, sync, write dword 0, sync - * 3. Update Config, sync - */ - u64 val = le64_to_cpu(dst->data[0]); - bool ste_live = false; + u64 val; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = NULL; struct arm_smmu_s2_cfg *s2_cfg = NULL; struct arm_smmu_domain *smmu_domain = master->domain; - struct arm_smmu_cmdq_ent prefetch_cmd = { - .opcode = CMDQ_OP_PREFETCH_CFG, - .prefetch = { - .sid = sid, - }, - }; + struct arm_smmu_ste target = {}; if (smmu_domain) { switch (smmu_domain->stage) { @@ -1293,22 +1441,6 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, } } - if (val & STRTAB_STE_0_V) { - switch (FIELD_GET(STRTAB_STE_0_CFG, val)) { - case STRTAB_STE_0_CFG_BYPASS: - break; - case STRTAB_STE_0_CFG_S1_TRANS: - case STRTAB_STE_0_CFG_S2_TRANS: - ste_live = true; - break; - case STRTAB_STE_0_CFG_ABORT: - BUG_ON(!disable_bypass); - break; - default: - BUG(); /* STE corruption */ - } - } - /* Nuke the existing STE_0 value, as we're going to rewrite it */ val = STRTAB_STE_0_V; @@ -1319,16 +1451,11 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, else val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); - dst->data[0] = cpu_to_le64(val); - dst->data[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, + target.data[0] = cpu_to_le64(val); + target.data[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); - dst->data[2] = 0; /* Nuke the VMID */ - /* - * The SMMU can perform negative caching, so we must sync - * the STE regardless of whether the old value was live. - */ - if (smmu) - arm_smmu_sync_ste_for_sid(smmu, sid); + target.data[2] = 0; /* Nuke the VMID */ + arm_smmu_write_ste(smmu, sid, dst, &target); return; } @@ -1336,8 +1463,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ? STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; - BUG_ON(ste_live); - dst->data[1] = cpu_to_le64( + target.data[1] = cpu_to_le64( FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | @@ -1346,7 +1472,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, if (smmu->features & ARM_SMMU_FEAT_STALLS && !master->stall_enabled) - dst->data[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); + target.data[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); val |= (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | @@ -1355,8 +1481,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, } if (s2_cfg) { - BUG_ON(ste_live); - dst->data[2] = cpu_to_le64( + target.data[2] = cpu_to_le64( FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | #ifdef __BIG_ENDIAN @@ -1365,23 +1490,17 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2R); - dst->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); + target.data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); } if (master->ats_enabled) - dst->data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, + target.data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, STRTAB_STE_1_EATS_TRANS)); - arm_smmu_sync_ste_for_sid(smmu, sid); - /* See comment in arm_smmu_write_ctx_desc() */ - WRITE_ONCE(dst->data[0], cpu_to_le64(val)); - arm_smmu_sync_ste_for_sid(smmu, sid); - - /* It's likely that we'll want to use the new STE soon */ - if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH)) - arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); + target.data[0] = cpu_to_le64(val); + arm_smmu_write_ste(smmu, sid, dst, &target); } static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, From patchwork Wed Oct 11 00:33:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416473 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 5BA20CD98E0 for ; Wed, 11 Oct 2023 00:34:34 +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=bxOvJLJCzqG/d1Gr81VFiXlwx7I3i3Ak8dozmHr//HU=; b=Bl7d5hUDdyf+6d 8uCBPmxGM8stSAWeK8yxQpzrwQbYlP9XAuJHqzgHDugeGNzRtbNXJirlnmhNXKyz89RyTTObnWDj1 Hm/2TzvabnTxdlL3BlWr+5Z3IeEKaR8KStVjRVdAyh5Rn3iR2iC+AFJnZRktxrTlnyzstmkocGCoG fUKI5v89XH3r4Eb8oGncvztBebx+bVjS9NJAZ7ga779Hag+vtGa204DugjhI89G0iwa9ks538d4VZ Ghf1igzgK84UmRySH+b7xscK2WDmztrA0diIxHjOG0wIaD6RdKBg9JQCXPYeJYjaKKEt1DMhr1Rmb RIR0Uaxoa4UGzwJq8QpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAl-00ERGH-31; Wed, 11 Oct 2023 00:33:59 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAV-00EQyX-2B for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PwiIXMstnKkEXaJanzOGlPafnuVpBRqBGXz+VUiEWpUAS/bK4kz5Q0hQRyri7Lh//s20Cgfcm3fxB2rUwHsNjpEsIMDi17U56b5eoGkyUg0r2RnJOA0oHDNHo8n26txwmBQGwlVQSvbc2PSTVK+SmeevOgKFPXk5NPE//zri4WuZEn6UCLk35htMJKkg2p4lTT99RJUkvDNuyecAFtU/4x93XGB9M7k0wzwV4VEaoYbjpDKd+LBWCMAQ0iTt4Vtp2TetxGgfQzfCEOempJjKYnx9hvKUtjV3qafgg2R7yaRCJtW1IQRfULLINcNNFmRnLvt6hQQxHmNeSS+h85PCow== 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=4dEqUIHbAzS54hxbxdiuDBUkKGk0WiGQK2I1e0sSWgA=; b=XdjNA8BpkqTx80KWWM3SKA9sSAYcLfBwd1EndNOlSdmjvIcXsjBF1R/1fLXLeDen4hF5K/gINwBSJSvuOL8mJgIHt3L+fSM0+cTc/3XVni2AR0cYwH2AAJDblr0PQHVaek2NXDINpcZ9v7VCBSuFQTQbqcfwnY/AIo8cwP3a6UzoJsXXYBxgNdNRRgPlCjrEAPJaJQXZD42Y06uxdbybIE/z5r3y+nsZwcD+mjbkbrTrPcfEkcYZ08/LC4tm274eP5m2gpuS8o/kX2hds1y9bDqa10Nu0ycg/KEHgTX8t+fNQDEj+owZJ/XbdBHgKKB5dYPBdOOqDI10wMDOlgFKGA== 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=4dEqUIHbAzS54hxbxdiuDBUkKGk0WiGQK2I1e0sSWgA=; b=JwR1NS+5LGT5mTYgYimmJmg99Bjx7M/zPADnMfakpLhS5tk6fvynWk8GAg5Hr3YfCqauoNg7hBxrSppQ2MoqCxWSRfvA/o3DMgwhdCyIxnyFfm2fA587/OMtw3cJcGvE3Sd0IabVcqxsKK1Z+trnF4hH4p9o6l88z4dsMkmsrPAdjBisWTdiPQl1Rm9d2VTbIN9zyW6FvqSxwIDRPTu5yqrVdaCVwU+xvPqcUd2zu0LqFDBw3r+UyQq0Q0wJEv3l2VRbUPp5+rGP5KNj90L+kTwJAB3wCu0UXKUhvtTaGBJXUmTBrKOQKnOyT4sYShvmKGUXqALV8Ru9g7rkJzTEKA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:29 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 05/19] iommu/arm-smmu-v3: Consolidate the STE generation for abort/bypass Date: Tue, 10 Oct 2023 21:33:11 -0300 Message-ID: <5-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0024.namprd18.prod.outlook.com (2603:10b6:208:23c::29) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 8fbc2dce-0aa1-44ba-155a-08dbc9f1af0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +I3e0yf2FsTfa9LvXpHTeMIJVU7EvKiR7Px/vQXaIFSXpyeCW9GnB7envJD2EzYDJBlE20DUMfDoAv0xyMcCTW05rKJIY+zzQujFD5Nrz7bw7F6jSj6ckiGiJl0RlvDtvx8ehaJHj5sM3f4a7XDHryrLzS9mGnpaZBYkaAU+WDbBi6nvXwrz8S5dvnnqFy1z/1kNqklCr5IieDbO1Teeo00E+OfgRsrI1Gjflele8RT/BW+wOGQSticGaqrNQ+DRKhQo6Q43ydnZzykKXvVslDaTkLsrfvz0b0Qj7zGnGT8CjX8AZt0LRud0CNB2QtZFr328JSwz0NcqqOCzDvqDnsXOzceKomjrbf4jHUh+FXO04DhMye45i8z9WL22hT2ctZ2M0aSfmPmwgEf1JQeAnpx1lz/cJu6iuAIqSjdJz9rDEW7deLLSopMIhQ2YLDHkq0yeWuHqvpZTTJwJ4ry4nJS3zu0FoUMHu3X0ZvRtIXc/yN95vCbaF+pj+DLQArJs8i8Ot1HXzqfnFwO9yl/aT/344cCUoIqYFCwZhyTDjkzNt+wbL/3P1gN2pN57zcLP6cnOE/Ga6rrO+CymYcXzb8heXsBdUyG6t6sYZsnJ1w8= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RkIyp0iUzdtQT9esp02ZCwfPEzByPO5OwK1Cz/t8wTaTk4UbulO4/vmIfauo5wkGdl6C8fEJYskA9cQAq0FF//xKqPSN/mk123FUAcjDCKAdJVvE1KPsKSzK0eCX+peJyd704NAkTI7tlxJh38RO1KdyTpX6S0I7KXgfh4aVFVzUCqjgfn0uaRFwHbdSwSrNUg0YdmB3UxWNeZ6gP8uYfVSUP9qLLOV4olLFn0pWk2x5l12gaYpuW9APOpUOjSlt7TNJ1+Esc3AC/MPcANgJGD81DEZor0Y2BlDozCHZ5U8yUxXb6BEOpR51sFV2rWbN0ZIX5HTdri/PNgbUjbrIP/8JIp1nbj1tEDPO/5KlzuvEf58DGnU/yy45CXDwN9HdxD+CPHncK4RpA81H0min225gaGRMovkQzfJqsHb6oNbtBJa/NTLLAA/+yv0tKyJvbPFzdKVUNnWQ8+6vIP/d5e/7BGnYYrtVUnUn2dzzBIe1tGK/U8zvC0Fs2F/6VWgbKwLCJa5K4RO41WwMUGQpqcmFYD7XrEXlHIR4fyKl6zJWkM7PO7oKTnPgWPSdjlC8p2oNnEl5HiSmzNcOlXipelHSKgBcHSP+pAAVFZB08zpJn3SXyJH8dyB2qRCi60c60jKNqyp1mjG3dsrzBGR6vAqgS/OEPxNEaLh4Nq1zn5GXChhSVGbCKMieOkp4v9V0VmqleZdKkkHjWoKwRflPM+1+2G2keaaS2Y9L3W2A51Wu7zfLGVDbcF//6YpCt/0aTiH0UhXhIU3DzjsBvmnxlIT/nue0qimgcxE433Hy8ZAVF4LDP1/yIdqu0ek1OjySodziUOtMk1a6DShlJK6C5PG0EHSH4c+Kmt7FciR4Lj8OxiWBdUvVlTQPzQmSkoibROZmw2XJK2CpEw18lhlp2b+sH3K+ok5w8bER5GRWd2tNnjVpRFd9XnWLbPU2l66Z6REHo3YvBQfCX4H4LZlFeWnv1aIYlLlfmqWg0rjALZbR0FltV7wcpcPGOgl7XqWa8xutXuNewWMROSpWLTJRvtIBfwjlraKL9eJ/fUi80ehIyAVwikW7q27cuoTkSOZ54Rfod5D6/+n3d1No/tiOk8ilezAOWCnHge8hQgzDs5mo1geW32EE8P25S1RQupi5jGLvbkB+L4DqwLdF9q96pTpvRqySGnjVJdJ5nEGBSEnCS48/t5/nl/yUBKQdkyxzFRMnAaeW/oGtB6CwCJrQlPk7lwf3DhlSmdhrB1LceZXqP2r8vEnasyasGOhOzXK3jU13xLDTotM+cm4cqA7Qh3Lv4WquQxzLd5idqnmTsT1/V1cdWzv4Y9i5ce7Tj+ecBv3IMgN34L7UrOLMEJcBTg8utshLgMT7jK0pSSyPOwqfHRfjXHqKCZlHfeVX88/un4nc9ZqlKi5ZCozkXVi5Dc4IsyzmIdIczDseqDvvyiOJsj4aDN6OO+c5twyNBFNCsbI5tTA4jsmOF07YFj8LWJvCX74hJTr+WM56+JSWIHBTimN8itrCuy0QCo3GGDCxSpDKrmlAnQSvK2sBConjCrSRlm/Y1Dl5+YjHguni+9yW3EsJpddnLJbF/rsRmkDy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fbc2dce-0aa1-44ba-155a-08dbc9f1af0f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.5240 (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: vCJ6+tQOtmA+7m2FxPs+M/TFAynDdPNmjCpSkKnIrLUdprVzeXKw566ksLvC3fj9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173343_737014_4EF958F4 X-CRM114-Status: GOOD ( 14.90 ) 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 This allows writing the flow of arm_smmu_write_strtab_ent() around abort and bypass domains more naturally. Note that the core code no longer supplies NULL domains, though there is still a flow in the driver that end up in arm_smmu_write_strtab_ent() with NULL. A later patch will remove it. Remove the duplicate calculation of the STE in arm_smmu_init_bypass_stes() and remove the force parameter. arm_smmu_rmr_install_bypass_ste() can now simply invoke arm_smmu_make_bypass_ste() directly. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 89 +++++++++++---------- 1 file changed, 47 insertions(+), 42 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 6e6b1ebb5ac0ef..91e2bd1d8ed40b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1418,6 +1418,24 @@ static void arm_smmu_write_ste(struct arm_smmu_device *smmu, u32 sid, } } +static void arm_smmu_make_abort_ste(struct arm_smmu_ste *target) +{ + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT)); +} + +static void arm_smmu_make_bypass_ste(struct arm_smmu_ste *target) +{ + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS)); + target->data[1] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); +} + static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_ste *dst) { @@ -1428,37 +1446,31 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_domain *smmu_domain = master->domain; struct arm_smmu_ste target = {}; - if (smmu_domain) { - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - cd_table = &master->cd_table; - break; - case ARM_SMMU_DOMAIN_S2: - s2_cfg = &smmu_domain->s2_cfg; - break; - default: - break; - } + if (!smmu_domain) { + if (disable_bypass) + arm_smmu_make_abort_ste(&target); + else + arm_smmu_make_bypass_ste(&target); + arm_smmu_write_ste(smmu, sid, dst, &target); + return; + } + + switch (smmu_domain->stage) { + case ARM_SMMU_DOMAIN_S1: + cd_table = &master->cd_table; + break; + case ARM_SMMU_DOMAIN_S2: + s2_cfg = &smmu_domain->s2_cfg; + break; + case ARM_SMMU_DOMAIN_BYPASS: + arm_smmu_make_bypass_ste(&target); + arm_smmu_write_ste(smmu, sid, dst, &target); + return; } /* Nuke the existing STE_0 value, as we're going to rewrite it */ val = STRTAB_STE_0_V; - /* Bypass/fault */ - if (!smmu_domain || !(cd_table || s2_cfg)) { - if (!smmu_domain && disable_bypass) - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); - else - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); - - target.data[0] = cpu_to_le64(val); - target.data[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, - STRTAB_STE_1_SHCFG_INCOMING)); - target.data[2] = 0; /* Nuke the VMID */ - arm_smmu_write_ste(smmu, sid, dst, &target); - return; - } - if (cd_table) { u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ? STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; @@ -1504,21 +1516,15 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, } static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, - unsigned int nent, bool force) + unsigned int nent) { unsigned int i; - u64 val = STRTAB_STE_0_V; - - if (disable_bypass && !force) - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); - else - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); for (i = 0; i < nent; ++i) { - strtab->data[0] = cpu_to_le64(val); - strtab->data[1] = cpu_to_le64(FIELD_PREP( - STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); - strtab->data[2] = 0; + if (disable_bypass) + arm_smmu_make_abort_ste(strtab); + else + arm_smmu_make_bypass_ste(strtab); strtab++; } } @@ -1546,7 +1552,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT, false); + arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT); arm_smmu_write_strtab_l1_desc(strtab, desc); return 0; } @@ -3168,7 +3174,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); cfg->strtab_base_cfg = reg; - arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents, false); + arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); return 0; } @@ -3879,7 +3885,6 @@ static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) iort_get_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); list_for_each_entry(e, &rmr_list, list) { - struct arm_smmu_ste *step; struct iommu_iort_rmr_data *rmr; int ret, i; @@ -3892,8 +3897,8 @@ static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) continue; } - step = arm_smmu_get_step_for_sid(smmu, rmr->sids[i]); - arm_smmu_init_bypass_stes(step, 1, true); + arm_smmu_make_bypass_ste( + arm_smmu_get_step_for_sid(smmu, rmr->sids[i])); } } From patchwork Wed Oct 11 00:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416455 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 62632CD98D9 for ; Wed, 11 Oct 2023 00:34:16 +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=WRLhZIj5gJ6CBDvRxnl8IifyKRpmcuNg6+GHLrAYzyM=; b=yAhN8RPBWtkbj1 ysDi9/p1kWlthLICAEnwaNe6UC/hysve0P4KacJ0lq/RD6m2PTxfHULfMOVDBnsl+fa8p+GcKJp1e JgT1TOaUBVkVkHFhI4pOjUyi/oTCY9yOL/mpHikcevoYe0YD+luw74dAVEeg1RPwaZIqTzOq/kvBW DgULea4+8a/SeYHGMjgeto/SPF917UUIliRqoYTwxs/ncQ2LTIzCuVBCQpp16K/HQhsBEWdPnR7lV 8UymbuZu9oWOa3O2b+1UeHkqffsUeThlsRYUUeZKTQSwbOo9el+tSzMzMEg1NUuaI9F2FrA1psdTS qEI8+2dPdhlB3huQ87mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAZ-00ER5V-0O; Wed, 11 Oct 2023 00:33:47 +0000 Received: from mail-mw2nam12on20617.outbound.protection.outlook.com ([2a01:111:f400:fe5a::617] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAT-00ER0E-1K for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtZcAst/NjOrCyBRhd0/wf7L8WmO2/4xWEYvqenR32BtX6Gjwvqg6yoQF9FZSfe3ee1tB9/u1yNiTmt4pNGwxuah/lk4nqrYImvSBitP5pWNRm/nERrZBGcBO3GKQS5p4TLukl3Igrs5A42K02dz8D23LTnyB6GAPcdvC8Up5KlKGf+yBWWmXQZdDbhe7P58oG9LVnzAStK3nw0v+Q1W+17V8gJ8q+czwgV18NVck2bCuV15gu2Y3cM5K/NobuWBlL7uczS12p93twLnC+YTiM4bklWfjMoB4S8uciGavU5PU01mIexXpPkJ5wyHgPbQosDBUy8t0c6q3scdv1p3yg== 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=fU5KZ8JSkzVJmqI9EXc2PiFFDbrPyxmFTsOT8OudYAM=; b=DK0T0A147hUn7xyKSha5xL9KHrxSGSFAgEyseQaVQn1LqxQp8Bybiulq390kRgYE7jmDuMVBo7bm8a4u85eP3GWuVQ+eynMoeKfT6G3dtVQwaQ270AQPVpYU9nQWYhq7iMVi36lVMFLQJcXT7R6bLRB33ffnpjUn9wVl4q9Vft7YzJYbJeFzg//iHWo2xzCG7BvHedkUNT/7aH1G+LIuivVNeunL9mGkJxl6I8KVDPOUzxOJvSuxlUvuq7KrQ7X8GA7TUNAFZrGwgKzmr+4kMEnpqLCKYGylRSaK2loV72zdIxvCap7fjEADZYrh+lNm7JLVEMqJ144PS5gSJBGuag== 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=fU5KZ8JSkzVJmqI9EXc2PiFFDbrPyxmFTsOT8OudYAM=; b=n47onOJi0PuDYRli/A8Z2SAcg0Vvl2ok7g5gpbXcJirKMiTIKkDclVw5G1wZMFhe661CuCuvK27/mm7KFnR6YO0B+qyD/XuSr48JVswqLEPVyr3CQVBymqkqvhFDZin8f1Skyp5Yhl5dzwL1WYivli+Pi1+dCJhOnYZCc9zMUsrQV6e0Ehu9Ghrmto4d0E/pHBF3aIZV17g6Jf9F6W9RZ7lUQyA6KE6mkOkfV9JHqcTT9t6UQYpm94dDExc5sfZPm/w0ZXdq1Qvm//nx26pUWWl+q6Tr2Xfs6AAn6xDieM5SXdaPptaM896FWmUhnt2gGR+y0NwHktlZ0JQ9+jm/bA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:27 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:27 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 06/19] iommu/arm-smmu-v3: Move arm_smmu_rmr_install_bypass_ste() Date: Tue, 10 Oct 2023 21:33:12 -0300 Message-ID: <6-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR04CA0034.namprd04.prod.outlook.com (2603:10b6:208:d4::47) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: b248d581-80a1-4ab7-b6c8-08dbc9f1aece X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DjhNSh5rVS86dTrw4ipwiFgxeCzOQthDYR75hrzRWoGphchMnxNP8sMoWFrkpC/96FnoZ+Gr4v61W3bJ8ZR53bpxWP8MVm1xWOhYKAxh1HcSzNOvRQAgZZDJE407EgN4wJ7NcL0T9/VMdYY374WdFXSzofw16fEwTfXqPq8EmXJiKksdCLZA8K0+0+XnLcZuR0lAoPuGP/0jzzaj0v80HwsbTcbdg/lOa35nqOr0YE5E/XraglUpH45habpDyqcDhDxx3OysQWPFXC4Dl25jl/jfte8YL0Gpa7FxYZlcfyoN+IIgN67FgCbD00TQFBH+krBZWa5Ox+1nBt3lb/z+Lq/KxxXsS/ZBwLOZjr9qh5SWmq8POr/PDEQJqCpP/Zvzzc3fMAHgUMxRK05H2KWYIfS/arsgyMLrG5ZGfcZKef+lE8Fm8ZMvC7B2gYny5k4FENuK8FFwC3y4TkmrXVuuqNQUE/1MJ93U5re0mKo4nhsPIrp1Q9aoqNGBTO96gf+bf3ldjZolgR/tVGjCVk2ARZe841HDATWxB/9h9GxVPSERO4C1j4BGnD3enrf5ICYoVpc4YmY1Srtl460pFWDEVtfG9oC+Z1evmXaZafANEfY= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +NhPWTr8cH648gLr21FQVYeQka/SVwdi2BFEgdY9erYhOraX8ki8hhOz2qrnI/B8btS8FX0Yw71Ig9yIM/D3B+npagbkiWKcLcASJEyOhLYec1z8SVpXN4EOcS2LGRjxKKLbOFwqo92l0agFwDP8JkeYO0D1MWGoS0xUoxbOPZHH4mrvnXZjBcYerJ0qc3AUgZ7Fr4MqPloi/xDfhOi0H0cyCUxwE23UFHll5OyXF+IwhG6l92++zkLkSTlJUF/z1FJv39Iv1DX4EjVq+Q0cpieAkiYNK6DBdYZ8pMwNJdt/lXWkbE3pcIxagm5EGPqgPOhrUR3uC0XL5DiSAptDoTPUYUfwbniqm64stpYtdOuG2j4+bS7aNlB7111A2+rsUufv9Mhsuzz7D4FQzNyd2JFoSaEhGBed0jayjvWaMOyKj3iXk/I/nDKq7CBjBjlzN1layhB63JBfq59VooqSBgMtCswN2UmBKuVnX4IwqjRSy+P1sHhHLSAeFQHkYgpN5yFZTJkYK+lHR+EZZxmvCU2qPVuJbUqWrJEoJUs7K1sSP85BE9Ru6cJnaq3an/jRnQp8FXgLvYFQqMDiRqalL2u2Ej3yT8is+gCmCKYzolnGK1W31YHkHDeJRhflRSPIXemETUDbSRtYnuu2HzdJql/UcRMpZqpVF5vz8F9yR/m3tm/RYj2YE2kmAOsa6C5j9kuseEl3clMJ41qwUyZYTY6qOVNCIKDML1jcs7jTcXU+Xhn7ZETacyOLpGZJ3jAAaogfrVlzT0MKaZIblWZ7NnxitdIWA0pe3UrOqP1wvyoYZBUtezMsLinodDwDTuX5p0ChngZI1ytiPi0IKVTB15HlXZZmUeMgEDQKptqTS6oSxWdK5LqLTp0UqOSzltwDeo7FtgFj164aDg5ht0av/JK0VzFe2/eYfyyUdBlgEeqjPjHlc4zVFRmfJgyjwRml59y6slkp+k7pp8fxnvyt+GveqDu9PFPonovQATg/tyjU8bgKQzd/5fKFd24OwjhCc+muG3w5aNB1jtDlbzyvJ19BNVtPB+v4lgrMLKg+cyWKsuTO+SNAi7KFhmimbsIwdm3FEdxRRb67RvV1aKJvPklnr3SqG0Us8zE9Jm4Yq8ewWLcALBIn9wduLHlPV4knK399r4oUknX8G7rJFvCMd2AO9j+CoqEetSlenevVp9mojZwy2Yt8g9mCJTOcDApjDrGbjJbZ/vQ2ifvbohLsCO6t6EpEOCLrDudBZn3xV5z8yFCJvCzCFMUnPdw4OOy3wBuVtVjkBzbfiMsffGnfDlLjFOQuSuyDZTh8Hp+Aj8wGg6dg/w1wCkTXVy69nJn6l/k4rAo0jlFCFKakSkGP6+IJ9QYRRpx+e4qgT9aJZ+L+2F88WgGLcEQuBVU3is1ZQ2K8bI06jtTQxsW/M7qdIl4yBYF54cOZi7BmaHzJ8hw1o6fRqE7ijG7aCqdT2zg8Gz+aO5xGiy+1xJihxO8ZhcokH0c5TZF7Mxa54Gdwg4SiITvkIH7vT8U87G/e6v0W7dxmWCeT47CyfeKqpIFNz0pLbqV4fHaDPQFSwA7233lnnF8eZMARqYNqbNFOdhpg X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b248d581-80a1-4ab7-b6c8-08dbc9f1aece X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.1372 (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: hSFd8t/0uxlsuGffNG62gAj2ba4xFWuQUvPRnrPSWkWDHmmv4wpHuGcGZ5NFDuSS X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173341_452666_461F78B5 X-CRM114-Status: GOOD ( 12.22 ) 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 Logically arm_smmu_init_strtab_linear() is the function that allocates and populates the stream table with the initial value of the STEs. After this function returns the stream table should be fully ready. arm_smmu_rmr_install_bypass_ste() adjusts the initial stream table to force any SIDs that the FW says have IOMMU_RESV_DIRECT to use bypass. This ensures there is no disruption to the identity mapping during boot. Put arm_smmu_rmr_install_bypass_ste() into arm_smmu_init_strtab_linear(), it already executes immediately after arm_smmu_init_strtab_linear(). No functional change intended. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 91e2bd1d8ed40b..27eac8d4d86f03 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -86,6 +86,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { { 0, NULL}, }; +static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu); + static void parse_driver_options(struct arm_smmu_device *smmu) { int i = 0; @@ -3175,6 +3177,9 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) cfg->strtab_base_cfg = reg; arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); + + /* Check for RMRs and install bypass STEs if any */ + arm_smmu_rmr_install_bypass_ste(smmu); return 0; } @@ -3988,9 +3993,6 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Record our private device structure */ platform_set_drvdata(pdev, smmu); - /* Check for RMRs and install bypass STEs if any */ - arm_smmu_rmr_install_bypass_ste(smmu); - /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); if (ret) From patchwork Wed Oct 11 00:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416484 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 376BBCD98E0 for ; Wed, 11 Oct 2023 00:34: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=jCxjc/52CH14l/T+1Aql2PKLs4k6JefpJ68nifD0kNk=; b=ob566FQz82tjZ4 CpklTlElPmMTdCwpgtCF+p2Mlo0n8paqqRQ1ueZhOBBG/GTFtdp0q4pt1rYrxFF+owBeT40+bPKWK LhBLhhaRf63SUOaSjC3KfE/+b7dlayc8H6yWDf1SHH9RyRkofpJh3GAFToWBFQ87OiyByadsHIf1M 2u6qERS1K40XYmnGwOmYcaAWqyZybVgeCH+UUpdYj0Ll/YBxCmmVcbcq8VVXNq3/u4Nob34SW27xX voRGxQv5CBpO6FOmxP8hyLDT0jngKEnrURjn4He3BBDfE+5Pbs2bR48GM3CaEVFWHX4q/fhTlDWE3 bMqHCIueEXmyyTBupNpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAt-00ERNB-23; Wed, 11 Oct 2023 00:34:07 +0000 Received: from mail-dm6nam04on20617.outbound.protection.outlook.com ([2a01:111:f400:7e8b::617] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAf-00ER8o-0i for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lRVG7IGboRQ1ePbMRhuD6c3kP7VJ9nsUwh/h78oTRZXckY7RWxRCbYO4LinfChC1S/QfTVynVjkYm1RhCNG+qFsPWlBiQ8ucWhPj3Ecn82cHpCNqgK1IYBWHeZz32ARV3EOJ3+EfkK2PlEejPAoWW7fdtZD5PFH4da2osChqb/vh3Y+2I/IeimE4xevK7J8EvBFKCH3K1cxq0MgorDvA5e1cca+baew7y6Iw23JgUwAX3iZ15CWZbWtrJFXLkf8uZaiIws0DhGU210WHvsGcEfhjDx3t8jro+8CmxWmK6pZj38usXtv8LIZ9FjFYGjE+pXCLXY+uQZIRwaTpEyq0PQ== 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=bIcDGSlI4UTjJMnl6oNbEniLy3SV8fMl6Ixj6SIksq8=; b=jJrFHqZlCAQMrzB/A9JyFh2X14l1JsU/a2UP4ktNAGAdKTUxWw6uvWpByiHksKIZzg7AoxzcD/SPT2zBF01c6y5CaR3nDNl7/MVElDp7+QzXPrAqSLLXZhceJXwh7yaYNEEjuLJoLL5UrDCPe/SI6ygZqdj+uk4YOprxrf7rludk63oPAfQC5m3VBma1Q5XcvPN0S61PXsXlztiY6RFcWweXNeZLGbD74TA8zD/98WoE6mDSPrl4ACsojX5I+AOHoBUfHT81jgS8i2rRlEGe3gdq2U4QyqEHLn7nnPDMZR3dBy8x1FYBPECaHP2ANsBE/mfcFZ+s+FC0HUzgUtU1ig== 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=bIcDGSlI4UTjJMnl6oNbEniLy3SV8fMl6Ixj6SIksq8=; b=DzFJ18r7Zljx/RrWesRkB0zxiS6RzUYho61rVXai872rUj7ozxbOcBO9HsSAU8+nezEtnJVcA3iHGLkFy3b0pVJY6CJ9pZ2AHMFtIkzX7w6dV2ZtO8nRV3pJjWQvEqsiuusvxeXxaZZ3rPY4NpzXob5i4F4BYtMkRi6j4BpR34E/SrkwXW/1ak9K1jYBeLPM/hjG+m86OuquNO7W+hqH2JHLEcFfKD1dHbDsRohhSX+5HdKP5kUBpR4sQmF9xm7PjHvuem6v2rkV3fW+/vRG20qkbILYxuwC/pK5VroWElq3KWK7BFaG52hiPUm9JwDL9TcUI7fomUmHD/XOe8shJg== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:32 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 07/19] iommu/arm-smmu-v3: Move the STE generation for S1 and S2 domains into functions Date: Tue, 10 Oct 2023 21:33:13 -0300 Message-ID: <7-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR04CA0008.namprd04.prod.outlook.com (2603:10b6:208:d4::21) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f482254-771f-4177-1351-08dbc9f1afdc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N8bVZWXs+Rd5+5c9uRHlJ0zUsXjjz2qpsJoenstzjXk+xOeFtfp3LxAY1IzhhXv6EfpTjzWR2cURPUE1oS1RMDGvH1Rw5+3YpNTTzQR/IZ9nu1WAx5ZHKvSIrC1hlJPeHmPkwSgsOhaPcyoM4OxB0KyDq6t7uosUtrWzumPcrmpWI1ynE+Xl2Uchyi45WtpSV9M/uEBaz5UC0rdFBOdsha9RyYmeeHiELn7jYGyZ84yPsSkzorWJk79icZkE5MoyLTY/aC7Jw+Bd2exvTC/EQX6QpbJtuopyylakZC9z83iY1heHYbINHz0Dlz1exMYb/JEzNU6WnM8LrPckrevLo8kiEx/z4MnbKUM18DZnkjT0H6dyJb4g3/n/f66Ao8iycfpfRppdHX9a8vDzqJUMyeNWrEyTLSQYCbSqmYe3eBUrSb4Qtpqc1X3HFDc0MsfvdSWyMU1XrPrTX9ZVTdYTQ2Go/fuNVlXL5jNENVWRwcWXOMGTpq2w93u5pTwPUUA7QRMDKkKnth+iXdCsGsRO9LAR7DQuEOvHxk80UBSqeaXGl8/0kYU06kLn0ViwOquvYvdhYmHmn8ilH1P2ca9F/fAdG2n4xza4HDKH88wtJLU8zvehx1WY0kxgvmyruAMjfG0fqwm2fqVIFJgZ9NkONA== 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8kl6eqyVLmy43F/QPZNSQ/ZLJYoYqnA7W5qhELiHw8thEDL8ziEobpR2ZQVtsPm5VlwmN4oOz9o9f9tX+0bPy2HQGua/+FdPzeDWcaiUNyxJ0C0yIx4wLVHkObxEJkjKRMQiPcWSLF1vUNfGxLK1Tcm2m60VZSH8580qWd3wbyNyIueA+2zD+uhDgfmI/CHW+IMY5xU76h/kiQWKg6AoWHtnL3495vymnl6OGqU0KjYqRb9ljQex8hnqWP2hlN74aESPgIv2ICK0+3xSuFI50GPrR+/eWZoY7V+rENDlNS5OKW45pCKKC/JwG1WcaSHms1pj01WcE2QRdTOi6pBx8C5kCehqiv178isDC/XFW2eQqi8GGfp5mdi5mvZH3MH/vs55/THlsmrjNoVltazKpaKop3hxMSFqWZFr1kPWWMOGZ+sVPBIDIL2SoftIWwRTmBSutove3kDmKB0E0T5r9sHra9fzk1DPWk2K9z4VmYL7dCYBRhL8FDEIBknZPY0WCGMd+ZsHitRE2h4bozGrQUr8aVRxVgRcQclCVjWVFxMs9AHSiZ3lxocGaXDpAYfxN/i7SYLqEm0mD2hEtXYN+MlyhA+hUyrSmcASKB/E7o1ict9BWFhVQ+n4KUcHyGlWIHUeyVTY9UJQZRcYN6FJrkw0+bBG643ncP6PvPDghxnJ73wGsKdqloNi7fk9Rva26J4+qOxXm719o/zUzzASuNz1ZTFMcWEAajDdT2Ejg5m6Egf2ZnTxVhB30wJ3FQ80vrUkCDGcvbGFm+iXm1eEG+a6CpME+bbe/ZztZrz3vOOtZMwLnv4TTsnr0R5kCu9n11RPOv58MAkntpyCZmPQ2O44c2qvY3NJoDIkt+r/ZTWnxUjWVBoII1Ul6v0MR4Hv7T+rtOocduKxbsjleTqIfqMbdF+37Iab9LDOIOoWwAG12w8O6xW7GK81RdOI1k34yYfTG4eeT4LGB5c6w2tfCEsnS2UPaue4idTkLRRnVkAhGFItlhAUIwe8+kEWJsZ+otvrASmQc3jFkhLuLj0sjdaveizmNSy59W82G6bJM7npMfUKkUiN/Uuia5izp9iZGn1jinKXBC+V5vBxactBemeKGTwWn7JBsr7ScgT2oTMEB15V5RKlz+9nUEpaZByasWf+TmbxGo4A57s7ur8NJJpR9Lp7OHNq+EprQRcLw3rBtAc1kapkF1v3OHdh9p/CQ2C1mj7Rn8kAR4JATyEIxzRGbv2k+vjkYJF+BTRUYDjPp9yuzrbWC0Wsom4+GPxDaMjlnXP94q3711drbno/iWE9P6xbpgyJLbrY9DFx7/0MTjHgzOjRosmHa3xYAkJ+ee5pi2dwqPr8qMOJ6Mm5l0MJgDLogxMw1HUaJGtjfPHtIm0LO8cTTqbnhANY+eJ7pHMw4PO3hoiA+kUs5rYb0Mc4V+YmVSOoTJY9xwe+NiereOY06M3A8qijOtmO+T2vu/qA2DrGycKmWKrY8cq4giwCHigJBF4NlxkEeiSUYnCv3wGjUu8lqvR2iW7HalwDtALdm+jx2EO1G7JoYnPm39oVVDZemVY1zhn7N3ac0yKpeUmNi3tots7IzcdCqTI5 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f482254-771f-4177-1351-08dbc9f1afdc X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.8721 (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: nYMzRQKWsXY+Hrx5gx4P/mUDrdS1gQjFokvVo5WOkPkx5tkpbIWE23ikPP1CmP+F X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173353_293650_E5713CEF X-CRM114-Status: GOOD ( 11.52 ) 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 This is preperation to move the STE calculation higher up in to the call chain and remove arm_smmu_write_strtab_ent(). These new functions will be called directly from attach_dev. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 115 +++++++++++--------- 1 file changed, 63 insertions(+), 52 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 27eac8d4d86f03..00d960756823e3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1438,13 +1438,70 @@ static void arm_smmu_make_bypass_ste(struct arm_smmu_ste *target) FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); } +static void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, + struct arm_smmu_master *master, + struct arm_smmu_ctx_desc_cfg *cd_table) +{ + struct arm_smmu_device *smmu = master->smmu; + + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | + FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt) | + (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | + FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax)); + + target->data[1] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | + FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | + FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | + FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | + ((smmu->features & ARM_SMMU_FEAT_STALLS && + !master->stall_enabled) ? + STRTAB_STE_1_S1STALLD : + 0) | + FIELD_PREP(STRTAB_STE_1_EATS, + master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0) | + FIELD_PREP(STRTAB_STE_1_STRW, + (smmu->features & ARM_SMMU_FEAT_E2H) ? + STRTAB_STE_1_STRW_EL2 : + STRTAB_STE_1_STRW_NSEL1)); +} + +static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, + struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain) +{ + struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; + + memset(target, 0, sizeof(*target)); + + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS)); + + target->data[1] |= cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_EATS, + master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + + target->data[2] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | + FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | + STRTAB_STE_2_S2AA64 | +#ifdef __BIG_ENDIAN + STRTAB_STE_2_S2ENDI | +#endif + STRTAB_STE_2_S2PTW | + STRTAB_STE_2_S2R); + + target->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); +} + static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_ste *dst) { - u64 val; struct arm_smmu_device *smmu = master->smmu; - struct arm_smmu_ctx_desc_cfg *cd_table = NULL; - struct arm_smmu_s2_cfg *s2_cfg = NULL; struct arm_smmu_domain *smmu_domain = master->domain; struct arm_smmu_ste target = {}; @@ -1459,61 +1516,15 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: - cd_table = &master->cd_table; + arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); break; case ARM_SMMU_DOMAIN_S2: - s2_cfg = &smmu_domain->s2_cfg; + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); break; case ARM_SMMU_DOMAIN_BYPASS: arm_smmu_make_bypass_ste(&target); - arm_smmu_write_ste(smmu, sid, dst, &target); - return; + break; } - - /* Nuke the existing STE_0 value, as we're going to rewrite it */ - val = STRTAB_STE_0_V; - - if (cd_table) { - u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ? - STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; - - target.data[1] = cpu_to_le64( - FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | - FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | - FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | - FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | - FIELD_PREP(STRTAB_STE_1_STRW, strw)); - - if (smmu->features & ARM_SMMU_FEAT_STALLS && - !master->stall_enabled) - target.data[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); - - val |= (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | - FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | - FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax) | - FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt); - } - - if (s2_cfg) { - target.data[2] = cpu_to_le64( - FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | - FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | -#ifdef __BIG_ENDIAN - STRTAB_STE_2_S2ENDI | -#endif - STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 | - STRTAB_STE_2_S2R); - - target.data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); - - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); - } - - if (master->ats_enabled) - target.data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, - STRTAB_STE_1_EATS_TRANS)); - - target.data[0] = cpu_to_le64(val); arm_smmu_write_ste(smmu, sid, dst, &target); } From patchwork Wed Oct 11 00:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416457 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 72D40CD98E0 for ; Wed, 11 Oct 2023 00:34:19 +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=dfP3R5mlNoXmVH7612ptZc+0taXP7dLIypYbS5J7Csk=; b=v7fre9Olsxe7PT nWtbWUTPKdt4sr+BEh73DFvcrhZLCLFFnHC5YXHwa8c1L8H5qWXWtSVpJZ4m9PRNkZYmCh+Q5VFkQ t830iEKdxhEtECtgLFgGoDqY4JqUAsX/+qeHtOzEBhwFhnvken94ZQZQSWZYlCC15QbACKsetUfhs gNXCnoEAi+YhJq7HF5XHIflqrAufusZ0fn8dJUjwMp3GvXuAA6EOAuUWW6zjeyaXcFpJW2bwShSsg vBxepUnW9MM9iotliyPIdVMQjIEc8XO6G2whi6H5/VaESvYv1MhX0GCREtcavIus0FITbK1YfyVtE fpY+Hvo02Pu9xYcz5CBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAZ-00ER6Q-2o; Wed, 11 Oct 2023 00:33:47 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAT-00EQyX-2i for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n6M0ZCm4hmAN7PSvX4MBWOoU4cbKNBykhZ4sE70jdBZQyRmOwK60ItRxT6Y2enYzniy6hl3ZADckH4gaiPcFOiTPnjeoO4aUpleYLmtuZo4c7bHnfT6uLowvgfrx27FAgdpt0aRWWARInVRIdtk0rAI+5BGcYmpsQnjVCsL/9YqXGgF4bl62/DioSexQhxM4Foh22TJjdcWmfCcEh8Ue1/F9HUDNzwuuPjNlhJh5bmJRxvHVRcX/ENj56flniIUprMNTmREvIbeTqui/gmb07iSzALI+JDpCggn9NWB90xQ/AuxLqF4m/V54UHaykWGFnIPWtoU1G4221XiZgt9QaA== 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=XaknFvtt8XwLhwGa7F01IzPrR2SMierLH8q9M1ejBkQ=; b=VG2hXsCDZLoZqlZ8lOU187CdcZ0lRonWKAMndlbgYGvi+XNZZDgKwdnfkWLFHCxh3nnlJ4VckdAgnMkYMBlQo/jb5+No3Ul7MCGgPXhYGMq9fgwEhpxW9qZFwvvIRHKpNps8VkJ+w6Fg5XpkuVSl51tWfPFbNqq9d1Saz8LOD246BfhM0iifafGoTtpbyfJEugWmWRDK/qkiyvV9/O4t/+6V4psV8c4yDpoRJMqNgvIWgJ+YW2G9J1IqhCHJ/Oa6JaqTY+1IZq6COYFTHmhbzPMNEsiaHMNuH5Z3PEly8XUqr2EgiC9yr7y8liJQRqYxS11ix37mesKRp5EsVl9Gkg== 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=XaknFvtt8XwLhwGa7F01IzPrR2SMierLH8q9M1ejBkQ=; b=TAXNDQ1U1bCa4tbvlu0GfhARss48j448CfBLWra+W+/ny0q37s4jsK15SC0ZEoGCA/3DRHLd+YO4s6Txjcw6i2Xe/6cl8OKvbVJCxt+qNM4I7K5D+bBzcUYR1h7q7EW00VGcfKEexgpGSvh0SXrkXJ6ZeCyTpA+t+LMT0TMtavbwJ20YIsLTH7fynQnh596PIYMn7hv9wb5KiXwoWHoIc9IWvZ8GSoKOmKeSkHVXrhEQ3svO8ruK2JHt9diRk6ivp+zrS1qny8O/ud0yRj13g3BppYnD9zv+X3TAmIqETif0KJLvtQ1W9c0E7sQNYKThIpxk3qG4i/mmk8vv1T29aQ== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:27 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:27 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 08/19] iommu/arm-smmu-v3: Build the whole STE in arm_smmu_make_s2_domain_ste() Date: Tue, 10 Oct 2023 21:33:14 -0300 Message-ID: <8-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0011.namprd18.prod.outlook.com (2603:10b6:208:23c::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 4aa64959-131f-4dab-784a-08dbc9f1aef2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cww+ax7lnu1ms9XMbXXgAXtAWo4vSv0/Bu8D4dUVRjCabxqz1rthZ2q3Vm/OYrYTbWeXQBoG1DP93kWEcH19dz4m0FH+vvDJDxr8jxF0Ev1zOnmOtravdMgUfA63V+X6WzqQy6j+1SAPfPyWUcjroctjoS9eLQf7F1B8Z4X87UOtvYZebBEd8dB0rnufDlsQfPYBQk06xT5SHoG3oVEc+hoLPQM0Cw1hUz3Xz67V84EMTCin3CSFeW2/XO+RWr8EZGLgMFCKDbfXCH5eEld0uqZvJT8HzFMxDdAXjrfLJ8/cYhpCk3eKfgNTAgWoBs1jb0Z+oe/2CecIOdBRpopBPArEqfke7ZVdP1e8jhKH/XMC/SHa+hUiiDHEiJmI2SCs4GbFVWwsoAowoqdB4+fzmuMhmKdaMkKm+T8cCibncet4xjcmJWmOdcPn1QB+50hsGWDUnKebpQ9T6hrh2rBAuGLBg3oPICtjsE+1MGgrmUnphwCno4kuv4YgmWQntxk1JMV8S7aBaUkUt/43S4YfvctiM6Bt/REf9McZJFcjjnpticQGul//GKXRuB2VRSpd2WnUnipcll6vXt9KDEHysZkPRumBP/bLaP7AqKPR3PE= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HAxnO/wBCESij3u70euWK/lb3V2kPH0yw+4KPEyvzLSIIP/ZNMZtY+rvj/oMJoAzbZWA5CLyLADW4SySpbXPhHp36IwNad1Y41JNqu7tsXiHGOpgIwFgIUnz99r6u+ekjK2/qMHvwS2IHVyNBphrd4Ev65X13w84FfGmn4F3jhOYgRZaXnkPSI/80Gj5shDzthycBqZbz9oZpIn+O9oNqo1Wj/NMdsfRpgtjgJMIzdTihUrN6uChMNXW+y4xUYeCIOvQVTndsRBDKqUPg1sipiPc6ELdqhxql+nn3x0V6v5oSm4btvBYVgip0pY+qXgJkMF0684bOB616ckX9dnnpUqXg9vl/c4TmIFTGZE/2IIqclwAou9kIZwVas+f8SDNAdUJIsu43/xGyKri2HhyTwF1FFz0PvBK/eqS1VQpBtduh1OMaf0EJy2qIZj/c644dPAcvlCpOk4gHQxwdG93JsClKtZtamfj2tfKFYRuo6LlANBeZ1WbP218c9I9RyxZFea2xW5Vvz0sBNt9KiQA77Z04isGGOhCR+lMAjnUWHNrES/oBit/ox/Uo7Vbh8CfsfwW//n4+sln7M0aBUePdt4LDio5pcK+FbVGhBa/VqAAXnv8ybV2lZOJIrZjinxNlPa0cSxXDDnlH0oNduKfv2quzhtZeKR6Wowr80iqwkPqvjqBFRZHqLFkH9smJEJhpe5chF1Ps6q3ZyrUmwycU/bLqL5hsv6JEAxwpeB5VNtsXYrrThcCAlORvL3bsmsVcrMdYrMT7fcGpFjdEkAezvCvbP/86/ugnoUInIv7BC55R1C0ek1+6p1wamrMCsfUe/5MX7J5bu/03qCfn3VGhuOeLs5k9H5BridCtlUDBt/gKOrYW4WlZEAK7gDFhUyYhFY4WRcXNKpo/xUQWhIiGYzujSr/BW36WNnxX84pWg5A/uTJp7X7MSziHqxVhmVE5T+DMKT+DmGGxEclHzU5o8K8cZcMaiFyb5WM3+BSXACK/T53uBrzArlQTWjaGQvqola6o6PSVvhP1SqWZOd5mVlT5MZ8fF4MHw119RLu51RsKmqaBrPWJgAA/OATnHEbpWnoB27J3OLzWIdgQDGxV15lXor/t/yzGj7ULjX2NDImeQv2Ipo+4R5riaaf1DBcMI43p6vXSvnt4avdXlj1XK/KU9IdeIOEOprh4/OhbKHNlaeVSWAfFKcvPZhVUyxBMBtAIlE3ZEULai2y/PlsU+jF+IXMsIfLxwmdvXL6Z8ZC5Ips4INNy9AaUJ8v8wDQqPq0fOiqAjHkqJfbuZUhe86OXPVYRYlaXxV3HAYzAobpbm1As+lL+G+UX1MmMCO0ygMCaP25MlKmqRs9LQVqOZg+YSDCd6atJF5Y105fNuc6eILNQxYIswtnuL+WcalVR/5rrvASvb+R+DIOMLJGTxsoBGkI2dkefjEFvHw1UbPvut5YjMWrkBJhAZc7hWEmtnalWcROAO02ECsKOKXrrttgHESp9rtHghVC/12M5oZ9VfGAt9vprcgKrrTSEbag8NZPKwvynvoVTB+o2pX24KbPKSZvNtVQmct9rq1fxZrAfEgGj5AI9iT8iPMkH+fe X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4aa64959-131f-4dab-784a-08dbc9f1aef2 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.3490 (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: 0pt9QuI6Iu1cD3CnlKnZMnNaroUy/Ju0JVrJc0qcYUyQZhV/AdXAjFkuRvC7EkvO X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173341_899847_52BE1C86 X-CRM114-Status: GOOD ( 10.98 ) 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. 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 00d960756823e3..2c06d3e3abe2b1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1474,6 +1474,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)); @@ -1485,9 +1490,16 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_EATS, master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + 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 | @@ -1495,7 +1507,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, @@ -2252,7 +2265,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, @@ -2260,16 +2272,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 27ddf1acd12cea..1be0c1151c50c3 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 { From patchwork Wed Oct 11 00:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416478 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 0D097CD98E3 for ; Wed, 11 Oct 2023 00:34:41 +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=rqoZ3LrJObDeMExmCyVBQzbKltQ3T3HozIHQb5rjfMs=; b=EXru3njOYk+g/r sFUdM0dBnJDO1B9Wb3+p1wSqPnBGJm1VamOsByzz3BW03qhoCjoU36PH31hchISiqRVmYZFl/QdjP OQ+QZ9bakEhocqDZVgsW2ZGYyW1ytxVWgPsMOsZ/44X5oaZpGGtw33JOf6e420gaNxx90y0Tqsowd JLTZfwnaca8rX/namyskvnxeu8U3y+GvOv0a/DiIlrydxaEFKqFR6gzlNU5TkjOGOlcl6SKMgmVYV NMtMR1+pWy1Kt8Lbvsq9GBg+nXqdd5wKn15p3UdW7yShIvlehxwlJmpIHtBTIf1voMQ2y1460eJg+ k30+6InrYzM2AeEoUcNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAo-00ERI8-0t; Wed, 11 Oct 2023 00:34:02 +0000 Received: from mail-dm6nam04on20624.outbound.protection.outlook.com ([2a01:111:f400:7e8b::624] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAZ-00ER5U-2v for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fg1wj//O5p/tRcadGl/wFyp/r/Jjt4pI45waHnkH1ruKxA+36h54TWpmU0QCz4XXP/VbOeYH7eXq4tBbSBcV1d34KvKTCQVUIit+31kua9FYQf3RINCg7js86Dbu/1ieJ0BRaLsoGthEqGv4r6p0jLA3qWgU4cI8TZbPcXA9fGqHRwSniaR0dTJUaFr4T9jXvnfP1HC5aISnnvabkwAi7UCQ3vHRtINlBYHK8iplycjRbs0GX0fDIrucNiDFEyIxCwEdhXTwvZELBIWO6KRh98AAwcb0pZD4lZZhz7qbcNRke22dLjBg7RZGcTENPhj7E7V7/bGo45BeGJQ/XBK6/w== 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=Lhdu3XauMHONZgY5iEOc6vQJyDzADOO357lRw+1A3qQ=; b=VEtqMX9xMuPTgmZIE8IVgVZR3rEj3+4g0XmdsLnpfSILQ38qXrZfA4hgjiV4ScMEGpt5b5Upnqvv2AAYJHPUOQnbMI5zE5930kzfSlEyUpxVy1mPd6R8OuNugXkMLaJewc6caT5TrtyZd/Of42RrlOR+5IKQtbFELfk0R+HfwBhVoVx2EMAaQFmK1T+O/+j9gFM4h/mQEg9te2XK8rtRc0T2IjzQYowB9aYB7huSQth44TPP6fmnSwv1hKgBWRMWdBK3TunWk6/qDvOsD8nwipWtjjeM9fPJiwuh1feGHNU12V3/ylYaRahlG6Fs28RRwnsNdCZ8nvZTnbw0ubnsrw== 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=Lhdu3XauMHONZgY5iEOc6vQJyDzADOO357lRw+1A3qQ=; b=Rw0Nq3kU9gZhqVreyCa2bVlB61P9r8iy0GCOl+C0sm9gV//yvQ/kAell2DrUpN+bNRJrP70bkpP9Lvi9cWix7HlZNgUMPPQDbO21zR4rSP6+MrECMoru7gR5Y4OhUO7aTHwGcIk1rWmZqWdt3MpPDfxEMzT+g/K0cbIlQEDkqFWj1zZcVXIEDU3Bnvp89I+8cDQVLxYASZjzhti4GUQsHIk3sik3zre7z135GquqsetglrKPyEjtflPjgnyuILgn0j0mszOeHY1YevxoC5WZwdbKJ8vOxE0P62AcnRtbzrXZj0/XPi+uK1BauktR4tdddq3zlN/t/HRcrs1m2K4A/g== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:27 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:27 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 09/19] iommu/arm-smmu-v3: Hold arm_smmu_asid_lock during all of attach_dev Date: Tue, 10 Oct 2023 21:33:15 -0300 Message-ID: <9-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0015.namprd18.prod.outlook.com (2603:10b6:208:23c::20) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 1129a94f-3aec-4b37-b403-08dbc9f1aeed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TyyAI+7o6UV2D+wutQ2v2SD8qL4zqYavvG15XnLvhpr8ZX/NtdAeSncct8uNoD7tgFRqfU4g0KWjLaI60TOFH8AXjy1rnEL8Btt8tNeO4b7FB7TOsLStSPb67t5BaOyPlIrtMatUAmUESLfdX9mMOj6WSqgV4/Ygf5q7hkX1iigSnL9ZUbqOPtvlIuxeQQVEPL2Vy5woStvHH7qpH/WE0P5KjaISBT3d6juKs6JQl/efvU2/PGGBFjdPbmivKf83RNEMJ4QeJAFaYnTCF6wQjaKOO5rKF79zgnVb3w7OLa1JE38Z2auM8W4SWf69MI4k+GSDZpQQR7ROH0EKjcFExgoT0hXkSiqbsGXviJNbXpmTgKfLRBVVYl4+xbVyJd3M0YIrJN1J2ajA+8BAw9LSP/xdDbEnvOr+RkoVnuo4eY/qkuC2lLF5Wy7Sq/0ULgV6ZGNWTRQUx/W80EZSXkchVu4xjzKjm4ooSzfKC6BSZ/Rotl9h74dXsnmxIRdex8LM37BE6KCZERa98OhHQbi3GnvW5dCyL232CCAUSoRKgfCoHdKY4sg13qSFC5F56c8L0BRrULOs/eEuUnw5/D+pEKyN9uIfKoYt4wDCaBUyHJ4= 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OXGLeXd7IMpjibBea52sFa6pgumqSQye0s1TOA0gEhqxqitbl/vIYnsNZAVexALi7mhS5DOHzXEH7eM1+WlKoEQz1VobXb0TRH8bF6BsQq5m9M81+1O9crSJIyXiUWX3md7W4ouF0RW8JJMGTzzGbLhESaGNinfRs7m7TyLUY84BYZfAKoN1rx++MYCUf8wpbe42x7MZgYnKYos/WYO59CIRPJkW6DFib2Cz2Sl7g85+gfLfVNzA3hgHa92FVCtyUI+MOc2dPN8PUnmQ/Y637qkFneE3zAt/XWe0yLTHD6Gd9VBTEh7C63GSGXWKa/sm6pIG2x4AeVi+YZ+xj+aLDPtg1ZxJtnqhz8Qy9yU41/0w8X+S4AjFZJHPkohMFv6fmZkVJ1qO2F1ve7SfDK0EUT+kK1hwEGvjQx1lnY85C04pMTDGUgxhA1kvs2JSKw/miHsrPfhHBU7iPoSpohY//0h32XhcCGTUToHoxKftRVADsub+oaiSmQ1IxTrE1SdQAwOEdv7WBXxZoqwkc9BsHnV8S8QpxbEP8ehe4nWRfnDOnW40Sv7k/b499ZMVAxeZXnXDmCo7/S/ecJvUg02UPereVVyS60h6QbCLyc6JpMBqqBEV17Ri/oUlEDliRerzeFHp1QIe+qJvChZS1L74y5ZjW51YJmvo/RahFnzpgLRe/nArchynonHAVfDMHhX9Ux/IG9+uFFIuVRfb1aDXTw7WWGlwenlG1nIhj2paTLYjB0FGH+/Xg53mNrWnckTbX75rQzVAVIxyaBzUvSJVoYMX5x9qDBSrTY4iDx2e2lw986IuDkoFGlKgwBAn7mXpInWoGfnrybrMJ0npC3fNuM647WximHKL5trsyZNegRfaCxQ8kdUrFiFiLKfUL0YB42xa2w/fa0uu4QVYEACqy20VFqGm4Zj6VDngW+FGgm21RBG9pbDznqy7Kv89sKCU0J++8W0ZWQcA8mDAid1Nlgu6p3FYUlOVkNopT0us7Q19OFZXhzei7rXTCjCSWL/SCktn2WRo22oN1hJ/8RjEl11z0xM37I4RW/tI7aLST8W6Cm54GaemBid7nmA6Na2RlpS+LkOt3Y+U6WsTtLhOzLuPQX68Iatb/jjf927Ht4vkSWf9Qeg2oxmfzMiGT9KdtV0ccYvr+roM/NPkKTWNh41mBoJmtjjNjkPHFvXg2r3L/4LHYg6YjcaBDVb8cudAkkoZuZxFJ1cQJm+k/p4doxbiVaygDli8wWz96TPpRXMkW0YIYKum1H7RLFu5qpDWGoJohh0XEqoFp5xsJKFqQ2xgDnWWskcjQ7vXXsJXkKz4B91FpNip++OoR9Qjmch1+xkjIaw8/c7ZrggXM4gYIVM7BTf2/9HiShchXfbOpsZyptHvulu7ItAPzurk2jc+PMcNkoELRDVHH1wkIh1FOzHi1wfDPFnKLqYIgFfFPyLyyKu2oTNZyvWBirX4Zl3GnLPeDQiApKgFaD1+WmtxLqRn7FWOlhsAZfBC3Ar8vEJ8cqQPwL3mJRSL01zCdy9twzpOizS4CkYzzHqB/rYDDnwErg6dDIO13bXy+QW+S+FdDfVXdRS2wgUlZ3fAIfag X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1129a94f-3aec-4b37-b403-08dbc9f1aeed X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.3074 (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: tIeXq5tZnmlkyvyMiqeXhJkXvw/LpXIOgpLlSxoHkV4NJ+xGgzuXCZ1DIPyw5XO9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173347_980586_0CBB7939 X-CRM114-Status: GOOD ( 18.48 ) 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 The BTM support wants to be able to change the ASID of any smmu_domain. When it goes to do this it holds the arm_smmu_asid_lock and iterates over the target domain's devices list. During attach of a S1 domain we must ensure that the devices list and CD are in sync, otherwise we could miss CD updates or a parallel CD update could push an out of date CD. This is pretty complicated, and works today because arm_smmu_detach_dev() remove the CD table from the STE before working on the CD entries. The next patch will allow the CD table to remain in the STE so solve this racy by holding the lock for a longer period. The lock covers both of the changes to the device list and the CD table entries. Move arm_smmu_detach_dev() till after we have initialized the domain so the lock can be held for less time. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 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 2c06d3e3abe2b1..a29421f133a3c0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2535,8 +2535,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return -EBUSY; } - arm_smmu_detach_dev(master); - mutex_lock(&smmu_domain->init_mutex); if (!smmu_domain->smmu) { @@ -2549,7 +2547,17 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) mutex_unlock(&smmu_domain->init_mutex); if (ret) - return ret; + goto out_unlock; + + /* + * Prevent arm_smmu_share_asid() from trying to change the ASID + * of either the old or new domain while we are working on it. + * This allows the STE and the smmu_domain->devices list to + * be inconsistent during this routine. + */ + mutex_lock(&arm_smmu_asid_lock); + + arm_smmu_detach_dev(master); master->domain = smmu_domain; @@ -2576,13 +2584,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) } } - /* - * Prevent SVA from concurrently modifying the CD or writing to - * the CD entry - */ - mutex_lock(&arm_smmu_asid_lock); ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, &smmu_domain->cd); - mutex_unlock(&arm_smmu_asid_lock); if (ret) { master->domain = NULL; goto out_list_del; @@ -2592,13 +2594,15 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_install_ste_for_dev(master); arm_smmu_enable_ats(master); - return 0; + goto out_unlock; out_list_del: spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_del(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); +out_unlock: + mutex_unlock(&arm_smmu_asid_lock); return ret; } From patchwork Wed Oct 11 00:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416487 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 31D34CD98E3 for ; Wed, 11 Oct 2023 00:34:55 +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=p3ZfjhAtrIunbD50D+NeL2l4lMg9eBKR1Uiloz8JRu4=; b=oIe4VA2l8dlu+2 7MTGu4M8RSw43h/siISR+UHg69ljrNtcz5Ek6WlbYrhU3KrZdNMauv43eDBNAhN7x7sHissKQy0+c hLZT2sJ9zbxmHRzxWzKNJKAHCaVixgCUkq9Pp1/mR3Z7PLYrqsRwATCeglLQfq7hv5P2vpoYKzT3q 73tgGinSfVMe4qzFBWgKoifkxR8EMFkRWKvrroIkRG8yRWGxBBBdY4UGCOLwOe/qqnNREBngY+E1p rZEA8eqnjAJ7xJErGyNuoWXoiSpIXq2pDdn6mqeZm1n4OVUdT4+YQGsgvtq2bpRa81z/a/N8y8O7j wN3HlxkzRscXuVNjgPBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAv-00ERPN-0j; Wed, 11 Oct 2023 00:34:09 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAf-00EQyX-2n for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TuF4GSGiDtwthcnW611/18laojpQRcAOVP/ALizYnroJToQA5fjJJQusRB7HO819+p4d6PZqI1d3zyH+u1iqUIfXNlkRM3aTK3hg8Asv9rwexXZoNcji2eNVjbEIhRLj8/xLvbAvnSytyY1VB9VkXoqOlGSqVzXukOineLcF7D4jsIef2qyWuFi2yyjIvIfI2h2eqE4tepNpJmQMdSdPsZjaDYJsb8z8UVktAY0V6xqjsoFdj0/Y6qdUD/Dnec5nm7fiPNruwdMuL653i1W8nLVHq+YlfVSJZ/c5ZlgjLMT4Xk88oyHJf/UvM1qctz2hSbLY9ggTP7bXHlTNoyjbag== 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=VFDzciuVVSdzDW6j9Dub0CZ4WR/DCHJnuYqzfd5iYjI=; b=fwVkPUvTmoRNqJHmfP+UpkviDjMbBo8urdVEx3A5F/zxqtVpvtmsWqqHBou6nrahexuly1uYRL5bvu8wRCsFIQbjdCKvTRlhq/voM1AgSpGq3LnWSl13DVpEv+huoQ6OmRCSfdGYpqMvQ6VhnFUXl1DrXQwjfdNaYQ2SM8fPI8aLH7xkJkh/gb5JILYFmNfoJBPgI+ZR46W1zul8ZHWyGWcHQiAQ7Uvt9e/uHbTVBJvTPMYYxm4CYJTsrVgyFiSjMgrmUfxsTV7/1CvnmTODNg5tESgIDjRBhlhF4oBwCoUe8PvFYmn8IGBuD1pgAgTYtBQCARewoJd2lIZuOga56Q== 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=VFDzciuVVSdzDW6j9Dub0CZ4WR/DCHJnuYqzfd5iYjI=; b=tSUS0wqJRiup18jQ3N2mtqx44lbo0nKdgo4VJC5CL3hhZhEBcU0S7PH3VOlWoAkJE54ZklKBzBu+KkN1pGLJwNp4OGDzjOv2b/NI8A29OSxokKJGTn4Yv/LDUz7/mIcW9iqsTfpI6dFmwHi4ywl9m8x7jilOMjzvv5jxEXUtiG4b2bytJpAhs4hBo259xErp3AXUNvVVP0bdxefStFHQIEx37i6/+E0xAxzlfMZN1sy39EMO1ho2EeU3P0qcS5ao8H68RvgFmUPPfLi1Qw74Z8lZBJ8PrKr+AqZpwUCh9/8YXNqSoNQ5MMY5VinP3ohkFHNIDC3k33gVKt9zuw6kKQ== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:32 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 10/19] iommu/arm-smmu-v3: Compute the STE only once for each master Date: Tue, 10 Oct 2023 21:33:16 -0300 Message-ID: <10-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0017.namprd18.prod.outlook.com (2603:10b6:208:23c::22) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f55f0f2-fcab-4c94-fb8e-08dbc9f1b006 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Blm9hxWmYLI9Ne2qEaJmY8maJLMsYL8WgQvGPzp+veLf4ZKAaR5ooOAPvXxvcn1ltypkWQ+xxd+CrfaP/zG6EGMV7pLlVhhGjLXM4QYp2xk8AsRTKZ22GJTmtoGzJhJmU2r+yG/RVECyovgPvqEyLSpQWfta4dmODsOAt2+0FcExQTKRfm83WR4hL6LcRtnmbnPfLvet/cCh9iiBxSSO1nkxEtPC8iLUJqkbUryTTTd5f8Ai7+4LYmM5GHqdMJIb6e8FzEXyxovDG9URqa1XvfopzecGQ19T3XTLbF52gs8t0ix08IDrfEGDnreXEIB2bHNaJUODjxToYjsdTd9/4EwmiwMimou9LVHz3XWmmtLPsdnwdA8IdEljqKAp5ow3FBnqhfOg2nFph/Ofg6JZQNmuSop5MDGRQVmhzyytU3to2FN2DoVLoaDocDo36/+qszrRomybFrouRQNoPOs/7eWSBesyXJJkV4hzAa35XBNSTnl/aFsyMHNFkyvxz1SNq9qP5y8l9yV3Fs06vt5XhDReiR/2LdRrzYKieucS4ulK/CJCIU8t9AC4+o97WUU/ 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nDoYbj4iZXtGQTp03CSZfP9u0zx8ds+p6lFyBzrxdhTrK9wirmb2X4jA8kL6VWWmDiSWKBHOVgeX6VfcNnyZiBc4r5ZQ5J2+TDYYXvX/SLJZdQvcuwmEI4XEOkBiJVGIjxTA+wTBS6nZviFZpb4wh2wgU/JnzHo9BSrixbyli5FHWj5qHwgN/8npyj503XgnlrYKc1iO5LdXbr3oqnO7DON3Q4JJ3jcWkBp7QPXYv7Y2vs5Xs3SVkV93OLmiof2vwng6qaTQxOMhmUUd/AhSZMgph7EyoXesTcZuSzh7SnNqHpvJAwd2+yPIgL+Vpy/QRksYQKM2Rss4FzIjj2c9NUYnn42baLjofBgkZ2nqEPO+t1+7vLeUwSr7HAQ9hcen7JHyxXjxY7wgCNYNhNE6GkrR0jW+E8NWgN5aIznLmQ2jJzeVdkJiOFsrNpy7nSruL1svY30B+EBW9XnGWP/5f8rW7qK0soaIcZ0xGKRMutzre6sKBG+uzfFOAmj3GqCno839vpcYktGQJ4OXi6ikkmAsTG/LlOKAuX/bCC7sglP+O50hnED8wsRIB1zGklMUDWwkXEqruF6BvGZ3z6VWUzPg8aNJQs7eLB8BlPhKzALS8Uw0EcxvpvDsINkDS9dImKqfYNyHMs15/7WBBZThxdxlU+qLM/yZLeHRJF3jqSusWLAbazPsAvdtZYxHPfgzJ0UxvxkkSzXcUYa+s4sjgowD22jfoWv9OSHR2Sep2qUlDg+i3LGYCPTKUD439ujNTkKuG1ZXJRt53cMhqQiVq6DRY5RjrOkh4RqCxpidIMVd++2jlQBKgaBlZgErSHN5/MLAdBH7IfcT56cTZCV8fjK5Lxv4Dtqf5iyMEA+mm9J6oO17Stu6lfbsCdhR+jwWcX9GKPdivA5JB+lJVZJ3TvsWE1JfYDXKEZf/FyySZZ7UAd+/ED7q9Py3Rxs6o7E6ZdeIGagk0r61M/lGIolN8v8hQVqIK2FSX3ZR2PhtitjbWRrHc9QBDJ+Eb+j/o52HSsKRvdb9SGxKX/NDHOfoDOB+jSJnsH1fUUWUQp/5rPgZaKQfqZECbCNvqyNy8zXX16ZIwDqc+2fQng6OqjiaooeSBl1Ij/+X2kAEnDWVycI5cYu/Bo7BRxmf1s1WLQyC6GQKX4AyPk5gNmG5aN45BVddTnz5e4SsGBfkFjWo3RADaX9zCFlSUE1hqTT+3LqKVoIEv7rm4AyCBbMEkcWmK4QGfjydDJPWa+XYhVrx76c8IM6aTBI3pFV+ZLWnB+MwOnuel6ezv1Zp6R5M6LRZ9WJXo8mRhgjWQNQSOVMw6P79rRjLix7t0VbY3rQkiQddVMRt5uAtGhi0VWdBKtdMr6vG0A8aTnlKRI53gdKN8cnKLyNxr4X/R6cbCpivOPzj1FGr0zzZkp5o7NLNfaBI6Dtp/+u19ql3RcFr3gowQtAPAm9RB3ZC1j4dadGjC9St/KmF296v9Zo1VrGVptRmeGLy7p3gv/qPlm6WxyJpKe5KNITwMs+ZRC57NO7usc4j4ng0JFn0e3/iSW3SVIsHeAOSxbXOlVD7hKSg5sSMwpoekQYw5SDFqASaGCdmRBjz X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f55f0f2-fcab-4c94-fb8e-08dbc9f1b006 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:28.1574 (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: 0eK638ieLxIJWG5eOlTOmFReVS18/sOEoVYfTlRnHarsCC5I02qZi7ZDYtdHw7pQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173353_948655_3AD718E2 X-CRM114-Status: GOOD ( 16.44 ) 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(). Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 58 ++++++++------------- 1 file changed, 22 insertions(+), 36 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 a29421f133a3c0..ce1bbdba66c48a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1511,36 +1511,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_device *smmu = master->smmu; - 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(smmu, sid, dst, &target); - return; - } - - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); - 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(smmu, sid, dst, &target); -} - static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, unsigned int nent) { @@ -2362,7 +2332,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; @@ -2379,7 +2350,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(smmu,sid, step, target); } } @@ -2486,6 +2457,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) @@ -2499,7 +2471,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 @@ -2514,6 +2490,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); @@ -2575,7 +2552,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) { @@ -2589,9 +2567,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, &master->cd_table); + 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; From patchwork Wed Oct 11 00:33:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416477 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 76439CD98E4 for ; Wed, 11 Oct 2023 00:34:38 +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=ADWu+nXieLEaNIQN5AP1QnlQk4M9n8ZiEA9I/1eFZCU=; b=OFQMAjev3VIyEE QOavZxW442ItGTztNb40OTqrqBcIKtacupq45Y7loS5CwcoDA5v9N48w5HgLXa9Pr7XSasfS4Bo+I peom7U/u6RbFnTeHz2jeU8182Ax8L+1PoxIivb+D4lwHM5JO0vtEgHMlPiloek3WUPWRi02x6L1+0 KbPZOLMe5pssrHnDNZXS0OcgTAhfeRVbCKO1CqMNFBwT6Z/efj8ygrofoFWZNtcILyB1rL+qaHvRj vPMN/dxs5imD9DLJIV7Fa+Ol+HvFw196rxDYi5nemdZOR3E/aaWHlKUYSuDyAAjT0ztvDPCucjRAR YOfV1Og8NHqGCvVY5Azg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAq-00ERKE-2r; Wed, 11 Oct 2023 00:34:04 +0000 Received: from mail-dm6nam04on20617.outbound.protection.outlook.com ([2a01:111:f400:7e8b::617] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAc-00ER8o-2q for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQuMuNaO3xBWQEptgZ212VH26M4TmRkkvLH1WtrC0YaM2mTjcf7zk+wHm5EOF/zw19v1u1mBCLHDMyKxEP17qMgbBtphKdOglU6ovzf1v3JLbr29QSMkeLaqKO6pUgToJs50XPRV8dipBButBFrQ3eBT0BK2s2Wng+goKTmpHr0zw01upXmjoCUk/MYsBl2TaQkIOXVcX3hV6RrVo56kjXwqh9P6XMm0IQsxLS9nfygbrAQl7lbeVbdgfvZngYdd9ANPqurjLBM0YwlP07hCy5twQI18I984FNx8hdEbb2aotOxxhBfHZ1NJbAnlZ9+5ibYthy3556xNW5GBY64TCg== 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=W61Se46VPgMQr56svmSHw5sOJgbPbT3Rcwo3Na9yTTs=; b=eugoxmzgq256rcpVV9TAUcYo4QZgAh9CZ4OArEMt47Tu0tUCz5l/JEuKtCDtdW4R0z0vFw5j9zw2kA/KqQoPwR174na43HfnsEZlCbHbqvVfeUc37JrVtBseXkylmC/kLb571K5hG+/BNDWVOnZHbW0gxNNc1Ye7ILCvOnTDoTG1/HIg8Z9g7WwS4zo+PHP0GIIIfCHx3C1Y2y0Vib7fphlhR9FJ/Q/KFabKEDuPLDlqZKFm1w/014blGe1erz1piBd2QA65BtK7TAqtWjgSouEt3C1fQRG1gU8g4F5K/2HBkz+IUAWifTRtDZF5BfH/9ORiqF7Ii1tQnXfLRhdLlw== 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=W61Se46VPgMQr56svmSHw5sOJgbPbT3Rcwo3Na9yTTs=; b=qVpy2GNaWk/42gJWvxFphnptT30pOndAcazdDZREcYclHWLgfocrATERtMEd1i6R0CFe8WOTUDXx6BSN4E0zq+Uu0ulVbs9YDl/1AyFK+EUgwhKNnhcEm7x3YepwpFTyrQnFVeQi07euayfoRkIb7RnVxJqXusKsU766/qSCWphG2SPHt5fzsNAOwmpvH/Kmjg/sRdLLJMjjUXB8KC277P5GiQBxnCPMwzmgY4zKgqYh4mTG6bNJzDwV2+ubgXuN6Y/qnc3Fd4rswlZpGntFF04t1hcyLa733DRy0hKIoJa05LUJPZz/82jVRWRB/GaUnNwJZrWTbs4QFkxBll7iTA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:30 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 11/19] iommu/arm-smmu-v3: Do not change the STE twice during arm_smmu_attach_dev() Date: Tue, 10 Oct 2023 21:33:17 -0300 Message-ID: <11-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0392.namprd13.prod.outlook.com (2603:10b6:208:2c2::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f604675-4c39-437b-e3a6-08dbc9f1af64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rEFJ21gLvZeJmLoFfaY6Pz4E9zUIEtxcBgEliZuCzvA9xLP/Qwtk0vu0EZpE6XNkVFlGoNB9g3d6lY2pBsEZnxy3qHiKcDCfFbF15vScYIbLN3vW15VgHv02ulIO9Ty11LmtLZ8WPVavYrzjZngJeRASLczYEWGK8HmMEsOpw33Ub8PeD8473ngBJE2ls6Rs6eyv94fg++Siq5DoxMn77CT4bf9aTP3LuESKdhVOCZoJ+5pvPv/rVlwTMzU1iOe2Ncl/rvFWsPFyEZUjX/oaezcIl8a6VYckH8Tan+OjNw2FgPEkSJgBKdYbRAnbry6hF3cFmhHjqCK5tNk22zxDE9ui9ONOYA0ZER/+HpYRh1tSY8g0O4unQ1KZowm5/FpZAU6/9Grt42MSzMgZVVYL+wIibBoCYa+7SRMdb2WJRjk4EBafwc1uiu8T75Kvo/iwNeC5z9SmlJ5zDfLWrJ3PjTHmTs/jLXYyPPKrYHQvZHNgS5j5IFyqPUd1xwZUguX/9UtyrD4CUaoy0SNO+cdtrLTU64U887mRtdM0cdiTxUy8nb4iiekiecobs2/6RI2f 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sKemnwa5qMDGsd88hpEsNQPozQRiquxkZsLLusyfgBkGQ2LNtb5jZ4Zaj9DbTcu3leke9VuIqium+M3d/K7PwNjSbEDS71dq7ey7T+0wlbwcHNE3iHLH5H+3hdRnZx9NNswvXSztt3ymcxn//XVeqRo3x/qcLBl6y/wtqhwcVaeiQ9FuovBBoFFjMDWKVNtrJrA6yuZ+Nj5UXS0utfvJcmQ9/PqgOkt92kQ0aPLQwatkJKeG/fgpJkr2Q7fBCKPZP8eZQNQcEt+xp8yog2/MVY4O2JydE6do+/joRJ+eyIuynTdnmM2sFQ/GMPxH549vyq4WrFLskcM3dO5gFV0zkGgD8VnVILJ16I2W+02O5flKg36mzKE0YtjHH9peNyXWzOOroPWFJc18g4koTbqNqFMNvsnQadS3VtYH9LE3polOqh5hy4e1MBTcvQyQdMPf442wt+W/mOZ6m5QQaDCHxKR85yU1YKfnG6ffElKfeEfoKm6M0MOu9NgPiA4vlyAbsaagQXf6QqvpYSlcvmVkbljhrVe1ijbwayLlZZf6TxTgDm6bCn9O1EiIw8E5WeRIB3OkK7Xk5xj+GgGBWKPHa7hRGxJNKY6vgR29qadvSH49a9jbSOkNlXNtA3XI+NYJB3u0E77zlBjR1dDLrUq05YHlM771/y/vCl9dvbrm+IgykJwNH53SYj2lX3mOMYOeV8LY/Q/yL+fep6OFvjWYnoXd0Hp2CZ7gjf257IR+pqEwG2nfVgpf/bx7XpOd4iDoSAIb9kQKB2NsIdsGU3GAuxqoDqpUVVeK5YYkvkhhWp71pS/BGIEXKj8ioKWxYpZcyZQpV7HxCjEidhvzZOWZ/SXsP/pVvNFscM/p7NEm9cSHQajzCPg94Y19esErkWN1PmS68Cges7BmHNpig1IBor16m3wnolj8YXTkuYo3bSVDZcYISiUO+3GkNIqTY/WxL9p88c6NOaw9uQzuvjXGvb1czsiiiZXBvEvvbz2co2kNWiOwC91uNRyspf5kT/7jCvahqrh7yDMiIjoCSGNMi0/3gjNH2eyR6byE5C0AvoJ68b2ZiG3vi/jTx/bbigodOTuuZ8YnGytPq+8uKrDF+LZFybEBeZXU63lZocl9IFghdaszWiQIF/mUxi4ZoiTRC1dpXtBUcerXRQPldt0ugzU7X8ntlUgLECzYi33CHgZyMHTtZmI8/vJFcbLYgfJNzdrTHlvakcg7bj21+FncneElE3jczJ19kt2jRee21k8rG0NsYZ5XEz/ot2q48xTwgFI6BlL/lO+ECQ4lTz8lbi0uSAT4dVq7zGJ27pDfn8taBtjCFu06ZLiUHy3DvhXxztbIr+rzjTRCRbjQQg6gLx0xL8MEyxG4fxcq1fF5m9IlhZduxSTNpOVL8w5f5IRgOnZ0wMbn1JHGVf80YY4QQNoJ4qbaY6sBo4Dv9ZQzX64yhjQ/NHRBr9evRxFZGHIieRqIaKCQm0ucAaMBBN5hwj+F3kbvVYsUthH3sVyk/QRYf5LU7us+xrmXde+bJDktWEUqfaLAlSXKgbkHDIWEssA4lM2zHXaemhjATSlSXJ7zyS51elRSSoVRwGTf+RpN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f604675-4c39-437b-e3a6-08dbc9f1af64 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.0937 (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: N4C+HiY1gsVUjsqSQ1eCpRLLNX64vQtcOydhqOId9Or24E7ToZQe60Og7GfiXcHT X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173350_954996_9491CE25 X-CRM114-Status: GOOD ( 16.38 ) 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 This was needed because the STE code required the STE to be in ABORT/BYPASS inorder to program a cdtable or S2 STE. Now that the STE code can automatically handle all transitions we can remove this step from the attach_dev flow. A few small bugs exist because of this: 1) If the core code does BLOCKED -> UNMANAGED with disable_bypass=false then there will be a moment where the STE points at BYPASS. Since this can be done by VFIO/IOMMUFD it is a small security race. 2) If the core code does IDENTITY -> DMA then any IOMMU_RESV_DIRECT regions will temporarily become BLOCKED. We'd like drivers to work in a way that allows IOMMU_RESV_DIRECT to be continuously functional during these transitions. Make arm_smmu_release_device() put the STE back to the correct ABORT/BYPASS setting. Fix a bug where a IOMMU_RESV_DIRECT was ignored on this path. Notice this subtly depends on the prior arm_smmu_asid_lock change as the STE must be put to non-paging before removing the device for the linked list to avoid races with arm_smmu_share_asid(). Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 ce1bbdba66c48a..b84cd91dc5e596 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2457,7 +2457,6 @@ 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) @@ -2471,11 +2470,6 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) master->domain = NULL; master->ats_enabled = false; - 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 @@ -2827,9 +2821,18 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) static void arm_smmu_release_device(struct device *dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_ste target; if (WARN_ON(arm_smmu_master_sva_enabled(master))) iopf_queue_remove_device(master->smmu->evtq.iopf, dev); + + /* Put the STE back to what arm_smmu_init_strtab() sets */ + if (disable_bypass && !dev->iommu->require_direct) + arm_smmu_make_abort_ste(&target); + else + arm_smmu_make_bypass_ste(&target); + arm_smmu_install_ste_for_dev(master, &target); + arm_smmu_detach_dev(master); arm_smmu_disable_pasid(master); arm_smmu_remove_master(master); From patchwork Wed Oct 11 00:33:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416483 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 084ADCD98E3 for ; Wed, 11 Oct 2023 00:34: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=7RP21VbDWijP2woCzs/NPoMaS8wCzlXNLKIog0zhnYc=; b=SOWpwYFCIwZ9ST TPh8EkRVFbrreuhfVcxqUCqkAgc2JFLb6x8owJKbbMuByxtHq5ExTLUX8/pomqbDwsnSsONxT5r23 uuVFV98pRxXgUcVKKiBIbtLIzKwUb4U/AN7npkioCIUUWm4nxyHzl1YPgQnqaRc2VyY4tpQ0j3n6m tTkKMghUZMGLr/v9kVExuFg27f0nZNbgGyPp+MBlZg+fg1nT/yXguFwFeV5fv3NLWTob/YcVdim41 8JmrjcCYcFSTAVYludXMIcSC8waqSXLB33l1ELKgxbiwhIPVR59rspiM1MsJauw2I38zQHVyAm1os TaXO0d4NvXG7dqZ4Va6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAn-00ERH7-03; Wed, 11 Oct 2023 00:34:01 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAX-00EQyX-1z for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jRtMK8t8XfpaMwdc8uVLuVcULYOH1Pg/8Q4kcAhTg/9L4lsPK8fmBlIcfpidjbDToO97/ZeSYgfN+mbfBI9QThb375AzgYkkg0rLO5pCe4uLjdUjBi2GU5cet3BvBhzQD7GKaOJOGMyx/TD6BuUikQ9qL1KXRlfd3bHeQONtZf7bckFtP8SQZq+EbUO9ZNjg14jxsYpWmzk2coxznRrDkvEeIpjVdBqOU9pr6Xz1JmlqVx0a0yahA8bP4BdLRQrTZpxYltzOryx7pSa8G7y+gQQnlT5Hib9GLYReaU8lcqGCak9cKjku6VZUkLnql2WaUORG/wL2J07uczHsVb/J+Q== 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=pJEnKe35tbWpzXhz/4/6PxYmS6R8IirgNIvg5EWAmQA=; b=U894Pof9lDu8ohu1Xt8U8H3F9UgFpDLje+xP59LImETWy2TJP8IZbZoGqb+cHFcfaq9DJO0qg+s8A1OUSOMsNqL0U7mDHv1I1fJv3sJPG6ZaXYlgalNudk++rzXyKPP6YvpdFQHqpi6cevHCcseLEKGDSMWWdrCd5crMe5ldSXsbHbVrP7+nqOFmmlfMURVFU1xxhcoR0fl8k+w5TQG/3Maolq+RbnxCoV1GP6vYS8dL9DEfyDAw3Z7qo2F+OrA+P9010C+pk4EysPYBVGQrUCryOa/49fdwHameJVLW4a6+f230zA1tHWIMgrdOJGIttHhyrnG18IDG+pUyPUqo5A== 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=pJEnKe35tbWpzXhz/4/6PxYmS6R8IirgNIvg5EWAmQA=; b=MyCeV9/B069RO2i/4u/iSJ16+bEG+aum3GPjGD34bmHA8IEd1LduRJEkY03EtEgJpGo83RBjT3NGAOyM1kDkZ5+SXqs8X7uysz6KlSwgVE8d5kwJ935x0k5TCVzvjz1VfNdmbZMRmoeMtNsp85Zmw22AAcKAxoCeACSR6Gqo1zA5lQc1KPPJDihOZf4apJS+MWAYIi0+wrThoQNcgvf0HmX2ChDPJbb80fO7vepz1hK+kNP4UMvUdvBDQ+4T29zfi8Zs3vatLS7pXLXPlm9Q8E1Eg8neA8scnUdk+FTYVbJd6RfLSzdA54U3r/yqTKfYUFx5yR6N544H7SOTe5iimQ== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:29 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 12/19] iommu/arm-smmu-v3: Put writing the context descriptor in the right order Date: Tue, 10 Oct 2023 21:33:18 -0300 Message-ID: <12-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0058.namprd16.prod.outlook.com (2603:10b6:208:234::27) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 227a7608-1f02-4c45-8741-08dbc9f1af24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pMGm+AVeb2uhpstDnRSPVathqK962dhP3O2U+ZQ+VwoBFYzrx0akHD8CQSztGQco3eZVjyofRUky3hOdkkpCroaUbzBzJ64qSxb9WhqKwWzMSqI/fU8foiCRl5S3V5OLNgzCcsJhwy9X7/JJhm6uCzMt1EU+S09xImGc2Dv0xpr2P8g8uJ7n3KDBPyZesI2nLtFLt46xEHDnNnDUB1O7zB8VF1ecPU3Rv9c1NnvNVoDb7ne/ciCroax6ZkKagGCIXwJduc7nSZRYoERQLcgJ3aM2XounloP5Oqsnhl2CB+5JE2pTQvETuBNiNgVjYIqMaBj9d5me0fktcY+fO7Xrd7nQzCojqk8t5S1pxMULhuqr8sYXOju0nxkSQpMSeavAmd0S4/JNHmfSFzrbjBpgip7TDDym9Rt0PcK6646KSwibWNKkSJn+SZSSy/8NAlTquU88erzxY3hwTw6nyZph7LGuxANsuZVTGRVF2fklLrxhaFjxNjoacHLCXhvJWgws6DID4k/8vzAzkhZQDXK654EInkEjHhT5idJHCD+YI31MwAmagTZJqj0aLGMb6iBd 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(66899024)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 052nL4YJA3qcdlPIAqiMJr92XFfOccimhqfK+dmGz39ExcWmTiYb10/jQexd7kx6vn3pzwMM3zAdUrYtXCMcpBhwpIA5n3N6MbdImpt2Spt/NN1CxHfoSdR1//h2y300lF0gsb+VchKHeCXuy0pspOvH9oelLvXc5jGn+N7yoEfiu1WJbZNEvL+TESA/ZfOxAbPOZNV0pBlc5c7/k/3pGj6gV1ZXt2VL4hzypZA4mEyAjEKCBBKh6wUisklS+xuLjdZWUYAiTIiSwxJj7YrluS1UNonCS2fzyIJ5R8aKEUvN/8L2uBPl4TEfGWfg5wqesMtxFkQWxBa0B4VzfRtu6qoGMazzl4YUuMuiV6dpXpdbfg08Y8bG67cckRaoRDARUmu7lBnk2jRjvi+zAl6WcWG/Y1FlGpXt6GRlQ7ySAldI4aqP6P32PufYmCqj2NMZACUsUEOU205yBXdvqnobjdFJXI6YoolQqPilF9z2gYY85NeAcy5v9PvfOjgL1tkEI8XJ9YTgUSppPoEBK3ADZ8ETejocFo40DN7v6QmpgQdZVEyrR6klIuoka5r4lkYbodRdmLBINl4kawSTkTEEfy7aEOELOuhDQcueqDrT+k7987RJ/hIwIITPFWiPA/DWRFZMEvuzAWaOAls3+7gUw3+JrJjaLIRCQBuEkpDvuL+ml8i2BqIiFSHEcwmsoPOS3F+L8vMJz9aHA3tzQJXbxKT07X1g9YZ1gkG3OczVGpkDMhNzX59n/aKVQXUxgI0PZQJyM6son3kfTauQmkHa6ddtM8hOuYqNsTYL6DeUY1POhrEF/Yl0GHa8HriLJFrBMbq6BXdCwvVMXqGFjareecGYV4bQ1NaOO0inNXoh/nGDN/06XlSUcuFtfzBy1WQFps5WqknFXJgu7u0uk3iutfuFHw6DtnnHh+ywAl6TDBHJ8s18AarAbIVC4mVo9O+Nkn7Amp/ufq2Mav1J4UQlHPz/RjRSePVl5rgKQYSxDAx5AkvQwBvAJZJj76Dr/KUcugIFC9P2P9a+PuqvcvLnl6dSHjjcaVApWdxmuC9QvQJVasHAPjnNNKKCyHg8d0e1GRLo5k1uAunsUP1jkmFF81UUD0sH8Y74PZRelO+VT8yRNjEzCQ8L0QKcjFKdGbcRW3qGlc35Z2enCGKA/wHUoe/cQxi2agt8QcDiPJO0bo9gq6zBKaFiMn1YmfJSCvR4K3M/mAU/vieei+BmmCdap9MRkTEFzYAvaTBl0MCLROvyzPHY6bB8isljlV+S4yc8ZsLpD8FnVTyYTdDBFzm9p+ciOKN/PvT33LsjbgYjV3U4osjVu0EcWmFqt9B+NqfDNiQ7q3crjisIhShf54HgCXJaaKtDKY5mJdGM1NGkQ9uae2t4Q3cc9K5XpG9Lh8XH6RNe12oNSIelOEidmvmSa28m1HooNIhc3fLxhVM/B9HcPEGWlPXxIYTNjQ1GYdtG9bN0ysPE+84LYgdPOXSkNGWDa1Ez7pVqhkvRp/q0SGZR3I1YkNywEQbWFS77gfj/I2lPzTK08THp5T4Xu1tbuGQQHnrlIM8k/nb2nFEyK/a0kUH3deV6G7Z7xsjQe/TV X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 227a7608-1f02-4c45-8741-08dbc9f1af24 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.6989 (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: iq3F9it+PY/mEYB8v/oXwgfQg6+ps3Egu2LulBqgF6xHLHscblSFL81PicxjUFiC X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173345_684437_81233AB7 X-CRM114-Status: GOOD ( 20.23 ) 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 Get closer to the IOMMU API ideal that changes between domains can be hitless. The ordering for the CD table entry is not entirely clean from this perspective. When switching away from a STE with a CD table programmed in it we should write the new STE first, then clear any old data in the CD entry. If we are programming a CD table for the first time to a STE then the CD entry should be programmed before the STE is loaded. If we are replacing a CD table entry when the STE already points at the CD entry then we just need to do the make/break sequence. Lift this code out of arm_smmu_detach_dev() so it can all be sequenced properly. The only other caller is arm_smmu_release_device() and it is going to free the cdtable anyhow, so it doesn't matter what is in it. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 29 ++++++++++++++------- 1 file changed, 20 insertions(+), 9 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 b84cd91dc5e596..540f38bb44873e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2470,14 +2470,6 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) master->domain = NULL; master->ats_enabled = false; - /* - * Clearing the CD entry isn't strictly required to detach the domain - * since the table is uninstalled anyway, but it helps avoid confusion - * in the call to arm_smmu_write_ctx_desc on the next attach (which - * expects the entry to be empty). - */ - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 && master->cd_table.cdtab) - arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL); } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) @@ -2554,6 +2546,17 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = NULL; goto out_list_del; } + } else { + /* + * arm_smmu_write_ctx_desc() relies on the entry being + * invalid to work, clear any existing entry. + */ + ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, + NULL); + if (ret) { + master->domain = NULL; + goto out_list_del; + } } ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, &smmu_domain->cd); @@ -2563,15 +2566,23 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) } arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); + arm_smmu_install_ste_for_dev(master, &target); break; case ARM_SMMU_DOMAIN_S2: arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); + arm_smmu_install_ste_for_dev(master, &target); + if (master->cd_table.cdtab) + arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, + NULL); break; case ARM_SMMU_DOMAIN_BYPASS: arm_smmu_make_bypass_ste(&target); + arm_smmu_install_ste_for_dev(master, &target); + if (master->cd_table.cdtab) + arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, + NULL); break; } - arm_smmu_install_ste_for_dev(master, &target); arm_smmu_enable_ats(master); goto out_unlock; From patchwork Wed Oct 11 00:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416479 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 5F7EACD98E4 for ; Wed, 11 Oct 2023 00:34:42 +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=gVPknwvrvCTBCoO68X245n2vIHDaOFdsPz7oRbuok88=; b=gm5byqwX/QhtKK PSJivvnuNW2ifuTVVF/S1TjB2SbNHd6HMvQmdwAmBDqZxq17lZZtSLtCdNCCKLx0bsHONWDuu/k6K CnYN25KZbgUuNpHiKfcZhB8bMYjJf8NxR+iJbJtC57xT6iOGocoBkj+5A6vucbFMBpmFur3QJBeg4 LPJmNrLxtCBFT3tViFkPkF9LZR2CU3ZCmEFN/+22BYh15MlwG1Xv0nV5TiuhmFVBV4U0Qv3Oje13p aADog4Bmkw3nKijrXzkypZnjZM4pNPWGiy1E+d46B8a4VXEEraeL2LVCzFtNlGxrNVszMpupSCgRF q8FNcJ+//mzruJWdLaoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAp-00ERIj-0X; Wed, 11 Oct 2023 00:34:03 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAb-00EQyX-1c for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WCn7+0jBN63hsa1TMTLy6U+g4v4QqUe/uqP+ep8z1k+ZNlzNbocCeeoKH9iXMtFOBlf0owsECUS2QrJT9a02H6HvDsa1uct90iuLyfpJNnbxWtO5+JRg0QQgsDQSCFhTEGj4QvWY2JQQ3ouyTs8l8I+lMCeowdK88qoZ4KnhP6Qnvx2Gn7rRMf0dzIDgrbq7Vb2EuMMLMv2Pcpfgi5w2PCSEcjE8HoWyloOZxkHyjHJf47EjwrhSdd/ovf+3ENlk6XJfzVJ9d0R79+fk+MPO8IkQ2QN+/yHBmWFvraRLOEf0BJtUa6vZOJqD6rRP9ok77TTzcETaH7Z1NisFYh4w+g== 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=jZd7R7J2PzBAsBBgvft5UKof3LboQwE45ppu9LD7xx8=; b=P/7n7BdEKIOBXbaqgQEk5mmSVdj7X4Ll9h+kHqtbSvg49lPm/QPY2BlQXQUvW50Xq7C82utRJjatF/h1wpMt40xN3pDka8sQgAorxzNxmnPINrFSy5CslSVAlMoCqun2ic5QDYG0ekXdCgtixxks/GjOLQfzv/QElB1wF92l9k2ovXBqp89y9FV0sKLZZB7V82Y2zNiOCzqhhP23V4FKLhfksbVlOQ5y2F3Ygw7Q6U7kCFVqbhBxN44HTYaTyIYgjHSl3T/p9OnRYCf6fTr7sCZY75vkcivNihYI4Csu977aeMS3v0OO3Emh6n1jnOAXsGP9+iMf+3Avdy39GxWaKw== 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=jZd7R7J2PzBAsBBgvft5UKof3LboQwE45ppu9LD7xx8=; b=rvkjAa64KiRSXu+0eFVq+IXRe4rjwqWeKeJTIySmHzBZ6yUBrERw9qQDx68wfHGrgfW7Q35heb+RKHImwbavZIWozHHDRq+2twxQ50BAONA6tVN5pbI5l7E6wfeRCazcYDnl2cwadevNw5uLUT1//c3e586pft7p5Fso6JEY21ix2JQ6lwQthn6KK61yoP6SildHW2GMSILEHVKFNMnwzHQdh1hRgimfwDAsjbreaWCGO04gXRnOy/sFtq68t9CM4rCwcXkK0k4q7KPBHeb3EUf9gerzSECMTWarzU6VdyMC1/UOn2D7+9F2udfOLJhsI3AS8nmrhdVW6RrGLGa+ag== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 13/19] iommu/arm-smmu-v3: Pass smmu_domain to arm_enable/disable_ats() Date: Tue, 10 Oct 2023 21:33:19 -0300 Message-ID: <13-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0023.namprd18.prod.outlook.com (2603:10b6:208:23c::28) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: af7bda9e-f432-42ea-0a63-08dbc9f1af6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AZo1fjaRDWWOeXlUocvHoPmSw941xPCs6G7oif+VhVSIQKRsT8FbxyN04Q+Hah+6Cj5/bmUufAYTeWRVz05+ljWY+s4EtkcWjbsRZiiezwQOEwlL3GhrJJMVWtnveI7Fao7M34jC/zoS8ZWgfqVLT3SoCkoA9cosfxYc7l3PMLAJ6pNMcMout5jBEbv65iq7jyZBZZrB59gFJR6RGa89/zoHCj2OYc8xd0I34Tc/i3Rap9x9VEwzY0SWFllniUzSIwsoGTbLCqJQsk3EU9p6lufTVPy7MpdfDjfM5YI35AfIMEREc54X3jdMWu4z+rAUr9OF4ltNYLHMx7+Ne15UBD+DkZnVXuwNKNBzwfO6+QTAp9h5agyJiHvNLpeTTYhbsRTyXFjv42OB6k1wMH9dIFulYH9Y8BVy7mZJ/RToYFFoGyJdGGG4CbEEZ3OSj3isxH6mazuuVh+JW0E3UqzwaLHJnh52txkbB7vEdaY756qGarSpc/iYrtguTJVdR55CV8DR3tG37SKFUDNXn/sXNlDe05Qg3C8j6phblPd3IlFeWsuHSwF6r5EK7OBQZOyy 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HcC807ZwXtDwXU0lsxz/ogCLSdMTBPB0vNBum4EZDXf7yPZtKNiwVRoN82jkwv9+Jvxfem/jbmr1XFyWJTeoHK7XgYENDRrSMjxsceOeovFoEArPfnsDz9UxxjvVst5hjt0LuW36t0MbCdxkDMhnO+rlvNXHRjO9o9VvVRsMc0QrIBz7iJt/o5HqkJ1qxua2C0gjPX0XgkclQoMGh7axFbJSpXxjaNv2zQv82to0ouLanIUqc4eLORBuhbCOywEILE+i7amoQ5EIhCd78wC6bZ6wFAy2wZIvsY2IbZUmp6cyd0tJ7MwJRCyYCHNOBjiFGtt7ZGuMdYYmp08F3HuQYBc08fX5GMQEMe7yaqTYo1lF+S89YDgqBpHiHxkAFPj2Ay0rJaYLk0xOxBjQRW/P/V9XsPOfIHGvUp77dDbRwSZqHVO1560DooeRy31a12EIPwUaX+NXQYBvnzMLQb4iOOve62YH6jneZ+A0IFqc9L/bBBfez62goQWSWrmItp1ZUagGAABxMhqTWdtkua3fOHPadjnDlqMpHdgNFet+F5RGrrzLd4bM+u0QXWD7u5ZkCMHlUnRS14ijPdvtWpSJw4nudAg5KR+Y86VivTRWQCvs94sy5uqM9E4Ql6NQ5n01wxJRKSkOy1FUcdEJ+7iXNUjackChlDn8u5lxe9UFdXtR5kK8Pm1wf9nFchfy4B2bGyZyQXQgyi2Bz1KWcPW74YXxV+SCSpsNwsVDkQk0fsMlB55OX1U351SDQoqBga3nPGkSQ32CCBcsjwXhuSJFp9XvasxbOrdSoggozHONFmbqe2pki+M0iLxtI0IEmHlxYiN7mIl+ZYE4ZIWYQSI//eWgCxktNH4WVls5Feq3dgJ5J9k2Cz4Qcinlie8c2qY1gdO9+vgvmgU0FAGp5UP6mp8V9xqZy/ZYAB+EG6OVyuixYKVx3EUdqUwIokRI3Q4q65YKpat7V7IitdDKepbqotTHr1YGRRKYLVeP9uyFu1QAuy4oWGfrBq6dRRi6BK9/4zz6NdyapRMAjIKauYwzd+58YbS/DtNBd5qAjQVk7O0cY+XFflZb46b+rVeghiXOCh2mNEVHbOJsG7Wa4digIpkmp2cYPpG9/Iq0CIG7/ijO6uPeCzrz5njK4NtChhg4/bCX1uOKcfaaIw2iOVeZ2I2lJ5hTkH8xaoWLfNFzd1cEQD1WY2Q1h0E0IVXAUv/Znvp/X8cG6cXIV5qrE2dOm8pkbkVPzBqhmN/9zZqbIMbBT/LfPwBxxMNVgAEwGz5LRo5aL0Q8/5KY0UHqpsxAaSBezkij1ecV3sA8sg9yA5NPYiJgLW280Wsl3aC5Lm96aWi1w61fkXL29tYZt4GgeN3JMgI1U2u3BX+nkJbRbXhNB0SWP8g3DNSboGUftirmjSJkd1YjAPfaYlSvWxaGAl3HaeJ8KFNMZcB7Cc2Xk20OQp8Z48JqlkUjlnxF5KuSKa1pRP4m0O8Vc8wReheNL9z8P7hq3qqfKj9pDaawgr8/hcueUgHvsitvk+bxvqiIZJN8GE2Iy7gjIY80JPnXP7MYFGeo3ny1/iJy3euGVvhHkcyGy1gpRMwT3WXxsjPm X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: af7bda9e-f432-42ea-0a63-08dbc9f1af6c X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.1913 (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: HdtRaUDczXEZwCj9unT2w60w6WxjtpaLOS8OdSLWgdNmeUJ8Zi40EmpyZ7JVYsOI X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173349_548305_EBB27239 X-CRM114-Status: GOOD ( 10.03 ) 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 The caller already has the domain, just pass it in. A following patch will remove master->domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 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 540f38bb44873e..34893801d05c73 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2369,12 +2369,12 @@ static bool arm_smmu_ats_supported(struct arm_smmu_master *master) return dev_is_pci(dev) && pci_ats_supported(to_pci_dev(dev)); } -static void arm_smmu_enable_ats(struct arm_smmu_master *master) +static void arm_smmu_enable_ats(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain) { size_t stu; struct pci_dev *pdev; struct arm_smmu_device *smmu = master->smmu; - struct arm_smmu_domain *smmu_domain = master->domain; /* Don't enable ATS at the endpoint if it's not enabled in the STE */ if (!master->ats_enabled) @@ -2390,10 +2390,9 @@ static void arm_smmu_enable_ats(struct arm_smmu_master *master) dev_err(master->dev, "Failed to enable ATS (STU %zu)\n", stu); } -static void arm_smmu_disable_ats(struct arm_smmu_master *master) +static void arm_smmu_disable_ats(struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain) { - struct arm_smmu_domain *smmu_domain = master->domain; - if (!master->ats_enabled) return; @@ -2462,7 +2461,7 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) if (!smmu_domain) return; - arm_smmu_disable_ats(master); + arm_smmu_disable_ats(master, smmu_domain); spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_del(&master->domain_head); @@ -2584,7 +2583,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) break; } - arm_smmu_enable_ats(master); + arm_smmu_enable_ats(master, smmu_domain); goto out_unlock; out_list_del: From patchwork Wed Oct 11 00:33:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416476 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 339DECD98E0 for ; Wed, 11 Oct 2023 00:34:38 +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=VetgMQK7R9cvKi2EhSqHL/pCmfiKw1wb9ZYjswqveqY=; b=rJdIa9YnmTpQyq 8gWIQMhrygpAudCIeOJ7CMf+Q+QTN8td2wk06l+sUgEU+VtRX26WSNm3Ve1xOqGnKAwKS0l7H3+4Z 2J5YLKWwKwAbEgwYTGSgWy81Pk/R8AwRhbrMb38Elgn4ITetAnze2ZQihxP5dkF0Sg6KMrBoZHZE0 l4D4TPaZOjz2aX7oYZ2sm/jGvc8TDzfkPRKmLrXZdqhhP4OLn3bXuUzDrkbNlp9oGVO8lD7+iwct7 g8gqmWrK4NmJTAzMLTcoxSng2jBnoSb/gX42k2EUAxSZXk/4AYa8ZuZdupkQ2Rdo4SoVVgO8hrkjj lbc5OMVqjodmofPeA2iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAn-00ERHW-1u; Wed, 11 Oct 2023 00:34:01 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAZ-00EQyX-24 for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lKXvG+zJQIbBtLoPpSyzurKqiBhMU4knmkLBYaGhRRELp2umFAZhV3oAeVAov3bDQ1rTvBWRsRILVUXwDMl/Qzvg+P9oJlK9r+FCYpV5dluKCIkXVG/08qFFF6bPmbpSh9RCt2sl7ncU7q0CSPGRyZNqi7pyLwo1y383SUJMzimZUMzQyGS7Ympy1sWxqhGvnXTMXwq3+6zEHCU2gYCFNATEgtUHaR6Zcz1XVg6TWeCcVaKlzlV9DP9zSIUdTyYqqyFiz7DOARqZFqPtR5QvBi3g10s1TRHmMtw8xQ7MiTScUQdxXolQPXxCFzs1XAzLaRa2WfNckEiEkLqQIQZ5Mg== 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=OzBBVX8IHARBG8hBgQt1hEfFdqAZcBYE3S0tB2lOj/o=; b=nj7SObyWIH0t1AsAo7ReSYe9etlrlf1vph4SZCcKTQdpLqQEKwE0UCoqYSWeHgSTvQU5yvXFmekCRiHHHwKczKgFt1OhPm/urZkP7Ltpl5cvMeN88aOgyWaMY7a+PGfdecfV9Mblun7K3LLm7aYYRbmhIbvM/1Slogwj/WSIhRv9ThBuP/EOYiU1BVrwjCt6m06YZoMrH8ABRy3YtpWP4Et93EMs3uySkfasxyBjKAaBgeSNmHpv4E72MJZYcgKf0e1Lojycg1wlixd/yHLJ5cs/n033ob30ZhVxa20dxIZWbSUA4yd8buscAEH6hSBEq7Neo3FCZuE3d5SnhfTTkQ== 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=OzBBVX8IHARBG8hBgQt1hEfFdqAZcBYE3S0tB2lOj/o=; b=OPiP5vU2I0De/8rE39aZoQPbw7AoVB/LN6WxQST/HHP6Es2jMVJjKfOVKz27kx/GZGdrpzGRwMYImwg56ke0GtYrVPGxwg4xo1RcoY46BcWDWDf/e9wgHYX20oVSdqSY0Pom5hvdWK+qZxNEGfhTFk2qvhVwOnPK4kQp3vEcjGRwGunWG0YPeNmP7d0cTXxtYKX1A7lstqOt+R7EOB7ibf3X+iFsxJpVapmtrqE3MfPmejQBE/6H9/rA3arcvv3jnkVzdeND/+lMSipLjU49UeWC6MRlO6b34h+YcAyA8sDNPLF131U84Dxg22JivVYhPk6YqUzSIJ1zBZZ84dW4XA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:30 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 14/19] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Tue, 10 Oct 2023 21:33:20 -0300 Message-ID: <14-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0401.namprd13.prod.outlook.com (2603:10b6:208:2c2::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: c07fc13a-a795-437c-e3a6-08dbc9f1af64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cJ65mWdneSl1nCJ3EEhZDuxsvkkNkBGscScvitjyT2NQuvz0gMiUtTeq8nKoNKLDBDO33Ml10L+aaIh+MGCv9+ptLoi2VBqRCcxpZbJSMwOboFJxUo2YteAIsKsF/pHL5Y3cLjy28Wp/n7T+3Sbq2HryCmN/EPgCW14Se8eXtQi1U9frMRmbKGLDMxdf6SpbVxNdJAJ3n6nGHJFhhbMvTE/Sv8NdZMwx0a8LbvN3gt2QPiJ+KmdsxMSA7EybvK+oQXfk1NCLhUi9SYgWtZn0hShg1Wug8hQ+Y6pWshbME2nyFEBy/VlhAkp7pWbCJCejFu1+Aj3iPglUfRZmKb7V3mhKAdBxgNJbc94yYHKfGWrXM/L/FM/0nmok+LDnuC0K5YLOyZCsnrUud9GgeNRBXrrV1UgGLC/pf04Hmm4rUd5ov5dnJmYXyCqhAQU7UAKF5NnWSgWuA7BlQ/wXGqhCJS26mrWpyT7ppNzk1WbVzcKmBRzoxs9ZcBj9gOssxkEolpqOGaZIHnWmBMMDi+SHp98cJ4BbFQ99Rd7wtjj5eb7GSbK/r7HCOAYi1pylzpNw 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y0jw59FIuEd0cLuQJ30GK1bJBcqJpFURpYtmh/metOsmQyph49dqbZLCOW33Ssn5JnaWYClGBXKzElhYUz3gMTkAaePDyxENCrk33MZXpPI9hZuM5i81wWkDo4SmHxpYOkDCVhvG6bgn43ZntM5nvu6XOP7ALd/Gtki3lkdczonrJ437mfQkGMZix0DW+PW3xc2IRM+aHXLn/y2Fwg767AndSnE6s6ou8rVMKWrSCZ6VYBdVjyqrz56mKRj5x7THnjUmB8S0mB6YEPefy88pM/F06k95Iw0tHnPbXvmQOKh70d1TRO30ZQQ5ZR35Flg2udU39XXCD5Byhp9eNize6v0hvkAgVaaBH8EtcnQRKBU2h1W/IccalCFEEPeVL/PQ6iUG2PCpp2KKnj8NlGwWXNfmgZKiPnexW2vvaA2kRoPU/Ma2KRYGJtEzRtHjy1F7sfTKVAy7bGAYSYPk+qKxWHFGhWSDdbncyhqR1EyBBcnh4BBpr7jzXlXmH2oSChk6bWbyyTBbiHDDuK5k0XANYkZC6ru6XGLd+6hXuUSnGBFl3+wT359awva74UqiLncXHrmZCJ94q6uGrpweIlBocXInT0m8unnM9k/iFi5P3Y5OLfpBKId206ibBRVn6NZ0tiIxj7Ocxp8mvjKYmqWj//afuRwJwggaMvT4Fnj2AlwlBPvKHY0/H1aCb/jz2Ka8bHLBH9dqJ/Umh2fHVz/Ktr177+Z3fqjaqdXF87fN/6LbvL35PAHiihZnFyGVUxYflPC6Qvidgz657oD8VBV5VNjXoS1oC1YzA4Jw2/TJg2AObMxn6ZBuQEIi54PRJQAsm3X7BPMABjL8Or22evQB/sGr+si4n9Oj1kridjsbNKcJk7BV1MB0KBWAru3K6Lz8JC0quRHYTePjaiMNpF3WFBwSw2mJ9/f4N+CC0IFe+Lf8OS++VXJpvGTsKFSYu4rvr1B0nAKaFpzCAkQkrBC5/9LCgTI/bKsBMuL6NvuoPiCNdGCOfbT6V6D9NmnVAdr3mXse4HQ4I0G+wL2HGSfSWdUHPS5NcSOCW8ZVe9QEy2Ww2Z1uZsoLBmmz7QuBXxEKm1yI7o2rw63/kI9ok1TW5D8k2zgrKdNYjkv9FQNdt8GDK/PbNtBLpzog/zk0tLpIYA9v7O95I6iyR3nHzQwM+Xjl0Wzndtsz+GoeaPgklzeXJqbpXmBo8gqiCxC+xmmcXeP8OlHmTCjBzMqhEUpFR/X722fB1TxICIkLvH5pbXMb+ZLGRJaPQgT7/iUORmn1L4s+xeXiw8AaaX8jfq6AOz9OmRMuIeIMrzQrWjrBLpD2h/B725zwUwQRTwZ9kw7KQ3FVQ04hxsKX/YBx6RLF0Vz9246I8bhZPZYhEZmMyXeEj9mrrXyPczrIwNeykfCm8H1MoRvR+bQAwGxgaxLY+I07/DsWElAet9Pj3ufmOcGavelgD/JmTfXmS4M6kmO63epjxw+zolwkL0fyPkkz7gDwIMjjYqmm3F4vOA3zrFYbTdGpVfCsHMF8RnNvEVV6PJTGs2HmFxtaDUD3u3k2k6EbcDcs65B3zeTZUsfRAfoufqpeQEECnsc78uRFdmvF X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c07fc13a-a795-437c-e3a6-08dbc9f1af64 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.1268 (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: sQWRqxbAgfclp9ThALx17r7OEKBIckodBdQsr1g7gROwe4FmRAxMiFfrMPA0crXy X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173347_695252_93B0218F X-CRM114-Status: GOOD ( 16.14 ) 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 Introducing global statics which are of type struct iommu_domain, not struct arm_smmu_domain makes it difficult to retain arm_smmu_master->domain, as it can no longer point to an IDENTITY or BLOCKED domain. The only place that uses the value is arm_smmu_detach_dev(). Change things to work like other drivers and call iommu_get_domain_for_dev() to obtain the current domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 21 +++++++-------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 7 insertions(+), 15 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 34893801d05c73..26d3200c127450 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2455,19 +2455,20 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static void arm_smmu_detach_dev(struct arm_smmu_master *master) { + struct iommu_domain *domain = iommu_get_domain_for_dev(master->dev); + struct arm_smmu_domain *smmu_domain; unsigned long flags; - struct arm_smmu_domain *smmu_domain = master->domain; - if (!smmu_domain) + if (!domain) return; + smmu_domain = to_smmu_domain(domain); arm_smmu_disable_ats(master, smmu_domain); spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_del(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - master->domain = NULL; master->ats_enabled = false; } @@ -2521,8 +2522,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_detach_dev(master); - master->domain = smmu_domain; - /* * The SMMU does not support enabling ATS with bypass. When the STE is * in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests and @@ -2541,10 +2540,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) case ARM_SMMU_DOMAIN_S1: if (!master->cd_table.cdtab) { ret = arm_smmu_alloc_cd_tables(master); - if (ret) { - master->domain = NULL; + if (ret) goto out_list_del; - } } else { /* * arm_smmu_write_ctx_desc() relies on the entry being @@ -2552,17 +2549,13 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) */ ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL); - if (ret) { - master->domain = NULL; + if (ret) goto out_list_del; - } } ret = arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, &smmu_domain->cd); - if (ret) { - master->domain = NULL; + if (ret) goto out_list_del; - } arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); arm_smmu_install_ste_for_dev(master, &target); 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 1be0c1151c50c3..21f2f73501019a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -695,7 +695,6 @@ struct arm_smmu_stream { struct arm_smmu_master { struct arm_smmu_device *smmu; struct device *dev; - struct arm_smmu_domain *domain; struct list_head domain_head; struct arm_smmu_stream *streams; /* Locked by the iommu core using the group mutex */ From patchwork Wed Oct 11 00:33:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416454 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 A3DC7CD98E4 for ; Wed, 11 Oct 2023 00:34:08 +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=anp7a6MOfYo97YAfler6YVx3zvBaxqv0OFiH6qFIKgs=; b=EGtTBys5CBnC0X la7UU2OwvYPo3LEGMOmMMzHNHzQ0fOzv+lMYy0ffAhhUdY8xirlWa5cfls/+nVBTQl2ZM0+BJV27h RfIyvHOa8Gemgnm+k6ITU+QYKYUZDXRZV6MlwNaKkvlkOEJ4ySkNI59blTBP6FbfTBmZH2JFzQcj6 dF6wX8jHe+d8ToZKrY5V8uB0yS3R0oMz3gL0m75iDze31ifqzUrN5B+F6g4chlLez/aN2JppO3qh3 RVx0aRJIKttrgDicZSe+cu8LCSkUGmT43y+GPjO0kWBbT5+Yy4zaU4uuGTtCD73ne6RVZmpJORC61 cgKULWWZVD0Y/pzDl3Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAT-00ER0Q-0I; Wed, 11 Oct 2023 00:33:41 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAQ-00EQyX-07 for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ioPWRoXC4yO7RGZqzwjcSxpp44xsFpgrWgngQX/sef07XRAgRPmNwZPz0/6h5qJUuPjMo2RTjhhW7B8NGl6q/QuWWrCiDLtIanfLt8cAx6TbQsn2lAgHCMULc6TAXAVg37DDXjEA5E4GE2U6p7QpjDPNpOqVdkSxzOoghcp1NAx0NjNZOcRlB++OGq0sYZzRzsQJnvjsgb2UhBgNTO5KcJqyqCCtJ4nFyNSm3CWmPoyIuZqpuTkRjuKnyxEUWOmqOuK3cn5YBllkrYqPaMFzOcsGXQl+MthqpfEC5st9VTqQrvEkiRW4SQL9FtjE+5lEKNA7u6VeuW0NZp4Sr20UwQ== 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=AheY92vkUiJ5a678ypXiBZGqbwjhyDCguTy7iwI+hJA=; b=g6ABIkrivdetq0v8QqbhuFxtg1lJN3ZCWCWBtJUzT1ps8o/WCZRMbgHSEhCCFZVrybRta5WyJ5mR/aJexzIZAmZOIC0wbV5+UtJAHpMIzoVTAZ4svv2YM5SYVdWOCke6qZdYqpeNpMHAm369HM5aJCldm54WmGT62PuWzNRztI9KRUWHpS16ve2jUI+BO/Te6VcdG82GIwA6mvIzGM69RYbCUM9XxX5nF8dV6sSoj06GLR8dLVrz/joCeE4nNq5HPy/Y9a6R1BgN9xmOR3jPkNKpgLsgRxkLDxI7EZEHCDh6eVexhu+aDp7LBdsWoDywv1vptzNnDSrn7RXej2KZlw== 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=AheY92vkUiJ5a678ypXiBZGqbwjhyDCguTy7iwI+hJA=; b=dzQk+veHk3bUOoiWCyVwjHDCWpnx4r9H82Uy2aQAqs4ipikqL3MysjardFeTNGPVjKXuJtLJgTgg/zWVptw4/4EauD/XsyCgGKQyVwTyHRPqM5woIv9vhIEHDg67lXD4bT17m5L7IWNKc5v6Co/hLoFUN41EjuStP4zwGieBTl/iQcr0yTN1jujG3RzpuLUee+fDhIen880JZf9nUj9pvEks7zxk7FTCU44gQ3h0hfrT/UJ1ZVsaZEAt9xnFd10iJWntXUaHoaUQe9LpjOyV/p2ETSSSL8BTVSNocM4nVIywm3oMD3I4esU0G2V+cIZL/REzeVaFc3YL1XUwYgxUBA== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:26 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:26 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 15/19] iommu/arm-smmu-v3: Add a global static IDENTITY domain Date: Tue, 10 Oct 2023 21:33:21 -0300 Message-ID: <15-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR04CA0032.namprd04.prod.outlook.com (2603:10b6:208:d4::45) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 376bc3c4-3f42-415d-2dd5-08dbc9f1aec5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q549P3zmABXWpfrld+k7/TvAjRVxy40HBuVzIumFf2J3ItKdn/YzEtYqVihUC3gx9nlE6w79F36nbSDJA7M8O2x3jiPCzPjnJiEs4cjV69TOyk/21ai5BoSSKIoXuqleuy3S79ziDyij4BByBv45ZB47BVgtTZIwq2cLRoTWye21iqH+/nwCMLJeFr8W2CDKFB3RueH8ZyVHvT9TmS6+kDuw4lj6GkVq1uoLboh0X4UFC+JMHTJgXZWQ7h0dZPIcv0MISXe+ZU6AcPFpZSabfvKmIZwlvNt1GvRSab1RhU6hGqwe2C1D+Ke7yrRFQZJd4Es7rI+o/20n2Qrw56ocWwX72ZFNwyoWJEzEtaFBofCLz0xL2WmHLF14LY5pGJ78pP7O/WxyANRus7wTdlEFxdENkKmwIpitNmrGnZWKpddijYAGiDtcZj2wuUymW421l02zIQMkel3zALAtVmvkrcd+FIv63jhTj9oEgOuotNdDaAFf/GaI8fCnEgIehGETjak1gKipGps2E4iO+wGuhEWr/xESz2NYRGSBrWKweI6K+zARxVUDTaF88CzuywSx 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7DLxJ5/m7gSCLs1tMNjL8qBRN1btD11947qZN1k0Kdnj70KYygpFryCvPPTtOcrXt47mJYtdWRSulALegMir1uBIvYBX7SlpxH5nFe9dbkD9lwf/qRbfgcBe5C08XbY2Pf9d8kHWl86IdfqKfuuG3/S94hM2vjsKPs7sdWJjUg0VNXiEyDEtvgLWozbBkofRqOR4p551Rlv/OXbdut+NsckDnb+2nEQscL5/pwx73gjWDSeAjOnnLexXAtL04RR3/oK2N5Mq7EnROGMR5MMobf+a347cn5Lgac9c+4h8XehimKXX10U7Ezis6x3EizzKcx5osrbQN0ArxU8MEa+BR+3GPzXI7/vI84nZfmwqxEQrHsgtNH7Kp8xi/rJ3MbXiXgHiXMtQvHmOeRUkApXGv9PfmSeotsXkuHLMZPVAM/v3+8iJmOrV4DfSwVoNFgYtFiwdS2IZSZjKSSdtkTsUK5FSIyMW0coasruwYQq1xTVFNJ810oarGKtmcb43QoDvHIq6S5W0PWWOTik5SRSDvCspotOnCXnO2ALZRIWG10vcWeH9Jdih2241bfnGOBX+21IpZ6AcLarwoDHsdUcciV43l0XhNWspdafLiRVeZoN9bz6dB8cceNGfMReAJzX1aQZHX03MgCQQToFVuu/3HvIHDeQ1894JoXWytfxlk8LE4Pe7Y4HDaGWKaATxETLLD9U08wl68vYwR9hd9loxpJ0b7ApN0qw6pq7E8ws4uaDarr3Ql+pwXxEdBBfAnSADqzi8VYjIwbisVlNukQ0TchW/G+QRo9WyXrIkhbZfdhvVJJc1EyNpAriR2NPalkADrHYRoZLoE3s0C2jPJFecqSITeiDT1esV5HLu3ef26gPUDhmR2i2BvCWhTdAck978Om29ckLQ2Ru2r9VmJ8TE4rKvt6x4zkxm95maHDGFHN8MtrZRUzNUeydWiOZ7lmptYSD7S6dX7Zo1gv89GHAszTbEj8vNfYfGavVoSgYQ6DTKIHy9z88sjd3ylY7tsJn9/wNQqi2VqKICwOd+M/aJ8iShx9tIwAnNw7v5PJaHxFWw1FlWvKnaqqPAG8VFfuJF3HCRyZm5cK3jfE4KGzH2KIARi8CAhnTF5/aVHTVLdHbQycOxH5UBPAWtJQwGOiLBCOq6+cc4/vMhlI1iQKL1FBqakasJYYsD0SgwcmqGLjmCuLnmNztu9oBW42CvHUdjUbe/rWFlcmYj0ZW8YXNkeoxj0UAgf8ckessQiB6kJLHmFvAD7hwAFjUBYAUMCCTZm6EDrLSiQgwvBtkrvom6+MEmBRTFNtytdUVasN4sHRorw3XOetMXboOJvv02o590oQFAV55SsX6INiNHgOX1eCMxjo4H4XeBvwlI/EN3CSzxlPPFmK0ZrX3K65MWn9ASvZM4PJKbfV7khVTbdSmHeFfMe8yaaQ37xAFIg2tuHTviyHxwa4LVvG9JLB+Dw4kzzmdP5jVOU9RIeAEIuYaGI7sFpCIRYe6lYXljTsDjk/xo5BruafrqtaeJJu0CPCsuo7ymrN50AOeSDbwxF3Azznom7yl3GjiDb+JLRhH5F6heDKAwqnVQnca2HENzX6Ic X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 376bc3c4-3f42-415d-2dd5-08dbc9f1aec5 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.0782 (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: OKtDrkw3BkJOz0KhwmA5PMpXRa4NWMEMV6aUIZFBwS//HCzrZl8huCDp/H4261G1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173338_076903_735BB7BA X-CRM114-Status: GOOD ( 20.54 ) 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 Move to the new static global for identity domains. Move all the logic out of arm_smmu_attach_dev into an identity only function. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 82 +++++++++++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 58 insertions(+), 25 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 26d3200c127450..1e03bdedfabad1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2149,8 +2149,7 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) return arm_smmu_sva_domain_alloc(); if (type != IOMMU_DOMAIN_UNMANAGED && - type != IOMMU_DOMAIN_DMA && - type != IOMMU_DOMAIN_IDENTITY) + type != IOMMU_DOMAIN_DMA) return NULL; /* @@ -2258,11 +2257,6 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; - if (domain->type == IOMMU_DOMAIN_IDENTITY) { - smmu_domain->stage = ARM_SMMU_DOMAIN_BYPASS; - return 0; - } - /* Restrict the stage to what we can actually support */ if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) smmu_domain->stage = ARM_SMMU_DOMAIN_S2; @@ -2459,7 +2453,7 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) struct arm_smmu_domain *smmu_domain; unsigned long flags; - if (!domain) + if (!domain || !(domain->type & __IOMMU_DOMAIN_PAGING)) return; smmu_domain = to_smmu_domain(domain); @@ -2522,15 +2516,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_detach_dev(master); - /* - * The SMMU does not support enabling ATS with bypass. When the STE is - * in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests and - * Translated transactions are denied as though ATS is disabled for the - * stream (STE.EATS == 0b00), causing F_BAD_ATS_TREQ and - * F_TRANSL_FORBIDDEN events (IHI0070Ea 5.2 Stream Table Entry). - */ - if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS) - master->ats_enabled = arm_smmu_ats_supported(master); + master->ats_enabled = arm_smmu_ats_supported(master); spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_add(&master->domain_head, &smmu_domain->devices); @@ -2567,13 +2553,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL); break; - case ARM_SMMU_DOMAIN_BYPASS: - arm_smmu_make_bypass_ste(&target); - arm_smmu_install_ste_for_dev(master, &target); - if (master->cd_table.cdtab) - arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, - NULL); - break; } arm_smmu_enable_ats(master, smmu_domain); @@ -2589,6 +2568,60 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return ret; } +static int arm_smmu_attach_dev_ste(struct device *dev, + struct arm_smmu_ste *ste) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + + if (arm_smmu_master_sva_enabled(master)) + return -EBUSY; + + /* + * Do not allow any ASID to be changed while are working on the STE, + * otherwise we could miss invalidations. + */ + mutex_lock(&arm_smmu_asid_lock); + + /* + * The SMMU does not support enabling ATS with bypass/abort. When the + * STE is in bypass (STE.Config[2:0] == 0b100), ATS Translation Requests + * and Translated transactions are denied as though ATS is disabled for + * the stream (STE.EATS == 0b00), causing F_BAD_ATS_TREQ and + * F_TRANSL_FORBIDDEN events (IHI0070Ea 5.2 Stream Table Entry). + */ + arm_smmu_detach_dev(master); + + arm_smmu_install_ste_for_dev(master, ste); + mutex_unlock(&arm_smmu_asid_lock); + + /* + * This has to be done after removing the master from the + * arm_smmu_domain->devices to avoid races updating the same context + * descriptor from arm_smmu_share_asid(). + */ + if (master->cd_table.cdtab) + arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL); + return 0; +} + +static int arm_smmu_attach_dev_identity(struct iommu_domain *domain, + struct device *dev) +{ + struct arm_smmu_ste ste; + + arm_smmu_make_bypass_ste(&ste); + return arm_smmu_attach_dev_ste(dev, &ste); +} + +static const struct iommu_domain_ops arm_smmu_identity_ops = { + .attach_dev = arm_smmu_attach_dev_identity, +}; + +static struct iommu_domain arm_smmu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &arm_smmu_identity_ops, +}; + static int arm_smmu_map_pages(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -2981,6 +3014,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) } static struct iommu_ops arm_smmu_ops = { + .identity_domain = &arm_smmu_identity_domain, .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc, .probe_device = arm_smmu_probe_device, 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 21f2f73501019a..154808f96718df 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -712,7 +712,6 @@ struct arm_smmu_master { enum arm_smmu_domain_stage { ARM_SMMU_DOMAIN_S1 = 0, ARM_SMMU_DOMAIN_S2, - ARM_SMMU_DOMAIN_BYPASS, }; struct arm_smmu_domain { From patchwork Wed Oct 11 00:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416475 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 36395CD98E3 for ; Wed, 11 Oct 2023 00:34:36 +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=5TP5BrLuVpHP0h80NSs2rbJpbHuZ03CKR30vISeG/zM=; b=i8bNgldQX/Bhoi Og0phv7NuSyLn7AWkUZ/emE6jzVqY2nYvHMgs0+mtR0bJ9zy/EhgYPngE8Lwr8wcYRBqn23Y3YvF8 Msrnk7cqQKvALLMir0ph044n8Hleai5AZuIY9nNNCUUFThve0ufGul4c8qL7+MkOf1gyMuJIojdkD vJ4IYVEdvrJk1zZ8PXY/7K36nLRSFm2AFpMRVD88tW1I/ggPMFJpabLhW/RkB4UF9G+y6x67+RDX4 aM1hqeGC6gIvArXKpPrlLZz2mM6O4TDZIw2rPbrbzXpo8HiVcwpca6SIk7rQW7iJVRiq4dbYCZq9H 7eC0qEJvEuvYWhG4wX9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAm-00ERGc-1V; Wed, 11 Oct 2023 00:34:00 +0000 Received: from mail-mw2nam12on20617.outbound.protection.outlook.com ([2a01:111:f400:fe5a::617] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAX-00ER0E-1E for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hQakWVh24CRHpuf1A2Ery0McuUxnWlthosvfXv9mENOK4hUP5SvuffyNXXJlVjq1wDl+Fe0zE7dJ0LaSAWMMEUKQbRsghVVTCFNYbewBc08GCWYspQ+IhN0Wlb5o4S2capLc/LTQX8hW10zRgRywWMzUlgg6zG/OqvNf5vfaXyylZ0ZjucEq8y8fWrIg1+dWeSfQmIrG0qieCWboO/5iX4X5FJ1mrJADtsOUDSdbd7wuHzsO0pQMs/8LtO3s+LW0YCU7ao09LK+wJTEEqlycwQ51M5wGftm03AwYmzx8MDdbVz5cH+IcXNF20pP8kEYjgZG0ht4F2fGYJCINQPQCqg== 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=72o3XBxKUaRgMD+8q+wJGvaPfgY/xZUTxdrbN9ncAhg=; b=AGCjRTLW1sk8o073RU/1tOV/qWHyG+xPCUL/uyJTqDYqJnn5zXo4JBxgBzuI18XE+l4YmDnOeNYGPmw+9SwIlewpN2QRG6jvKWp7vbp4K+Aasq19kiHCc4Q5a5BnHMP4kc/7/VOkesWdwRaeRuSQE6/2gMqDDXZuul4mNf/lfpd6Df175ggRuO8syzgGyiDJevF1zjgH9auNV9RuMDtD/rkk9d98KwMINHQdnKDbl9I6/ZzFH2nhOi/m54ELEEyhYfrZxC3/t6O56VJz/HMqBm6heuRln/Hh1mvpTMWU2pGK8L7BGx4OYTx+2nuIGzRAMLF/xy0SHQLwSVXyJDCF5w== 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=72o3XBxKUaRgMD+8q+wJGvaPfgY/xZUTxdrbN9ncAhg=; b=H0AwupG7PNAgIMEKKsClbDWiCu6PcpwpB30efnvkXL4zXuzJozFaRRGdReYDPbH6VfXLEwSWq/j+CBB2AQmfO1aNt5ewqu7Ug3M4G33P6CaFFZshaGc6RzHVa7msgS11htZhiuMI+g8ITKr8VGDP/pjB8oUH9uGZU8iqoBkCXV5W+XZ8EKckOXfOIJGp42pEfZudtRUNGEhO8xzaVE3St14T/DalODKq72aMjSeoYs4XwAb37nhRXw+lNcb7ANjWCWOZ+Fdn7dR/S3rFcCNMoEYMHoSanm8NWK7YsUguSg/M1eqckF3d5xcAXtG+wn2Hy/aExE/kmYRjwogQNxjSsw== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:29 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 16/19] iommu/arm-smmu-v3: Add a global static BLOCKED domain Date: Tue, 10 Oct 2023 21:33:22 -0300 Message-ID: <16-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0397.namprd13.prod.outlook.com (2603:10b6:208:2c2::12) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: f4457024-743f-42af-d7a1-08dbc9f1af13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Tx1Gbl7SflGCtUYSwkA8UiqB+++DYqyhkKKYBxSdU14S7SkR9+en12QYvzzAqAITmIEkExi04yqj0jlxlEuiUkE74qeTbNYHgoVZzF56EU8EqjqQHucAv/KXMBolsjiDVdzgJRldm1b3JfyYdUjE5scvexIh/y3CaBKronYHgB7clyOXVSbJzfcs2fmS2V6pMRMwV5R/f+NKRv4s3g6R9DLCvNLFpx/S4+NOuY7S2lupamd5QDmUY0gSO18Aka7bsp9d2xq1363uHIaBWamRbX0hrGP2p7QnuH3QoBQHZMn4pH0AXQu+2Y6Yqx/qiYW7ehe1z5rgSgmrSbsveP4RB+WWvUAWkmm68D0jjv8oAB9PvUuW0lTuRi7ApRHcx5Y3JJx5Hlq9+dJ+I02tfjSgnf5/lXNM3cchAdUx/rn6RAvN+tgKr4qKFwrxZJZz/ncpP0Sm+/JqKnrkPC+10nHlbKRuz1tnmEhMBbtl/cwBQOxrxY6P7GNIZ+MtDxcNLw16dCktFfpJWZ61SyciCZ7Rz86S64WZKG8ujw86den0hDnHYNBefe7nuiQv0z9m02/ 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(15650500001)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xgEw+0zcLCVA7LAvpTXPWyP1HZCgNf5GR5aPIe4YmO0vKiR7CsgN/ytFAlIgl67EdSYG3Asx+JOmKjciGeEbDVvCTCEdQ5pe6aO3nAt3L2OvOeQCiPq1CATGEh6pRIe4+N1G8dz4JQIBOghnOgpgPhqtxOc6M0VJIlYLZ5diOgHdXvX5DV5Mdom9ylAE9yUyWV1WBUPatoBsfn0mBEfotyoV5LIyvxSdUCAhiBRJrNxLWUH5OSd1m7V5Mpup1s4K/62f2V5GQWxOC5DDtewoBm/CdJBIr3rgjG3ZXpKHspor+bY28guENdWQruTG0x8PbODaosjA62etg0qDP5CNKz1a48MtznCl/QVQS/iASeNgXon6rlMZ56zHK8roLorC98/CNUY5OOk1DCcEj0Q8ZYtYfbcr3UUXYVDBO21K7E7s+Fou12AwhLyEUSPPRXv0HrGq3g2iX0T0kLj5Tl9uW+jChD/DbmjzmcDJjXVC0biHvsv3GI0fdJCI+5K1ANEnKNUNXM8FTYimw7PPlM89wChp2CWBxiae95GNEh/fmq3V7o2oWQ7/IeNJDkPn49KmbXFxAsRSXK49UqKt8D+n5f5yVVKEszkYnPdX99qy8lKSXeLsJD31z3RjhPnbfEpFaLGBdnRdNdOLzuvQNJCoKenLkUePAqTObYTum2HuSxBPyLx9Iqa2zdbE9Ov+9m+XBrzmoLM3eEIOQnJe9XMqhyyWuzspSyKtNjqjA6AhDIl9zbpg+z4w6mUb11IYKeMXICWV9g9zRFYCxfWp0l9v98Ja3RxXa29FU2XhYE7Yw11AgFjbOZX2FC4Uvl5XU+ua92ur6xCdCvJbp8Ta9lXHssO5vbgdWn93mIvY4iGEh4CQUWcdakUwbX+xEyFboXYzm4H04UHSNdp2+n7Bdzz0oe1eg3/m42XnK5LeNwryj1QHdTP+Zd39pc96Z4yVdkYvPHqHLC1Dim7VbxtiZ5+u5Oq7JYZve3FAYLRGokQi0GwPPzVkzkn4AZGe3vICYeK34F6qC5zNpvmFACvLb6Ap1DHh9ItzW9UDu1t4aj03gLoT53ml8mH6z9t8GQ+2o1OyhmIimy5FDuNfaJ8Qem4VnYnz690RtkVLKZhSV93/LQa5n0SFS90PNyniwU9iMllshwYk02dAlJOk/Uk/gJ9Ys354rseFRQuBehA6pTozqTm8sMBFLfp0h9SYbnrXPgbtw7QJX5T8C7eNuTxlxRTVu4TzneFx0PDQM3NJVvdk686anTUuHB2HGKSvxfnOBtgVIP/EalcCYawx3YdTEDlAoWO9Pf9I0se3pN8MET/WdyK2IHW7RZIGeWbSqDd0TfswhZpPvGyb2pvhmJtKioI2criIUyJjdCJysJFBcxvAlBsn4A1RB11TU7+nqeCvUgInM57bJoIB5zMADMYcUhSHIwsDCuHxPaRTubSOsW4nZAc3ADXEeY9ptwltDYY7x1HNT66l3P+f53M2XIBA1dVQVwDvN8mxBgAO+8M8nOSgq3LYl8IKCTEdWa5AgKnTW2qH9oEh7iElnEjTmcn7RiQ0qyuwlSTp+GL50JJk60grKTHY6xafbQGGsCfmQ1msQEHh X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4457024-743f-42af-d7a1-08dbc9f1af13 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.5762 (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: aPd/c1FhoqpDM1QJnunohPX2jDtJtJtNHAKtUXh7q7ZwCz4z6Zn7Ul+kXFmEOgIZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173345_438083_88D2197C X-CRM114-Status: UNSURE ( 9.25 ) X-CRM114-Notice: Please train this message. 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 Using the same design as the IDENTITY domain install an STRTAB_STE_0_CFG_ABORT STE. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 1e03bdedfabad1..d42d5d0c03f812 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2622,6 +2622,24 @@ static struct iommu_domain arm_smmu_identity_domain = { .ops = &arm_smmu_identity_ops, }; +static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain, + struct device *dev) +{ + struct arm_smmu_ste ste; + + arm_smmu_make_abort_ste(&ste); + return arm_smmu_attach_dev_ste(dev, &ste); +} + +static const struct iommu_domain_ops arm_smmu_blocked_ops = { + .attach_dev = arm_smmu_attach_dev_blocked, +}; + +static struct iommu_domain arm_smmu_blocked_domain = { + .type = IOMMU_DOMAIN_BLOCKED, + .ops = &arm_smmu_blocked_ops, +}; + static int arm_smmu_map_pages(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -3015,6 +3033,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, + .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc, .probe_device = arm_smmu_probe_device, From patchwork Wed Oct 11 00:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416482 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 A619BCD98D9 for ; Wed, 11 Oct 2023 00:34:48 +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=xZ3xmvVhotcpoz+Sh15c+E9XSLhdGiwpSYDfXiZQa4k=; b=HTVpTS5trgpov+ hefYyfbpo50l23HnOv8y22zr3/brNOk9rz1SWk64UWAWjD6wFf03W5s/6lGHulRFI1ygVIGgVR2AO r8APE+BEcgO4D4qn075iT9xu7wdL5LUqvqytu3qay1tI/L43Cz6dadbKAYomDj02krsPLfCF6wwkQ eS4JuEuA79vuI+E/zScsQ8dcTfToFGgPmOABuwmLvtHH7lK5VSGnMIZIX9Gv/ILCSjVQIqy6zMNec odK2DbU7nmbsFWpWLwoTCviaTOaucn7ppoOP5hEPY7/zb2oIfv6j85pOaidgDm78J3ceHq2Lkq7Wo NM5vLddaZufOtVWCDXTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAp-00ERJV-32; Wed, 11 Oct 2023 00:34:03 +0000 Received: from mail-dm6nam04on20624.outbound.protection.outlook.com ([2a01:111:f400:7e8b::624] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAb-00ER5U-27 for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TzZICpDKDO+n6rw/T/qXnADFEuUoQZDC2I96mJSDgbA30S0w4ivMBjImnVR++VHMBtKHp8SHJEj2jAFU5+a4PfCNZr9DwTxQIUBuTTxCzS2gr5THewdr8z44aAxIH3/tDjdUdFMYeNE3wqKXJ7YwGTdpjOtcEjvN1lS09Wg8cdIey10p94HB2tpqleyqTpfO/UgBw5hezjjQ+VnjwZbkdKWPKEiQkjq6XPp79sLY2kAGs0DN0o56SGDLPwZ6FN0D/9tvwXYvNlF27t0VLUQ1yS1jC0as1E5zFC/sS1xyOz6C9lvu+eARuFWDQRPrG7og8wXp98I6SPEHmzCJUMj4gw== 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=czc5qz9bl8H0GQ6OSswFtZ82ieR3jreREUCQivMJWR0=; b=fUt48iaOzDvg4LvbXeiWKshYbP73lki+lILnE/X1/aROv4HBM4hNHPB6IcD0RJaz05alicKTWk5Nplv4+qk44bFjkEXUNMoRlUkjDHYMJGwdzM6GGC2K7SX5jkINAL/Q2a1rH1V3K8aEIQrOdeBr/bca/E5U2do6QTk3gPUD/V0dKmxYsQZcorMIhkUJy+G6LbnhP77Qs6QTm3xOA+o6CI3cXVx9m9fDybx2baVkxmLrzDA5cPBmFvOEJrHYUFzrP3md3Xz0gG4vr8vphz9QL0Tid6JbSDn6Rt0vXEVUsY68kCKNtFuG2QeD3mtQlCYLalrP7vDUjE/GystWILy3KQ== 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=czc5qz9bl8H0GQ6OSswFtZ82ieR3jreREUCQivMJWR0=; b=ne1CJO+lJTBji7GI1nqacDExvB3hfuTpsuukW56WzJgvVsQ2bPMP3DhHBB+4UltNfqlJQxTtuhASY5y1uAWRIdtCsYiqeZ/rJe4gAAeFamhSDRgyk5d3+163xH7bTFtCe7itZklxBqkBNWJMewtG+J/rTQLjoLSm0Bhu+KCnV3+0kfSjAu96QsWi64BfO7JRS2tAszxWVhu3XfwcKHOuvnrRmwb2HNQbJ3zDYkBjHIk1PtT3VEsYVvzvQuk7AI5lPvWKxshB7MPqO8MxXRgtnFE/YZ/5RWudmaRCEfRfrv1t8E/9W1M78FSedmdnMR/HHZtTwdTFtxqDoNomoxtGzw== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 17/19] iommu/arm-smmu-v3: Use the identity/blocked domain during release Date: Tue, 10 Oct 2023 21:33:23 -0300 Message-ID: <17-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0048.namprd16.prod.outlook.com (2603:10b6:208:234::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 559e6b05-b100-4c27-e0aa-08dbc9f1af83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BQvF0NAbXXL/eFn56C5mFyYRfW4L1IU+CyUhov43Ei6yXN9DAOX366QA0MoG6t0MTxzGkMmvXlCPYBkVcM1LafqUkvK5vKIeLZcBPkEXVOjJEcyGwp8vZxB9Rq1R42vq2k7w1qsRynW+Wdr2YiFnLJKBr87iGzCYQGquJOYolIys/m92XKCxD39pPEJWQFWMzB5+IB9Fj6BsUAUJa/qb8rSsmQrStt5RiMO/6B6KdetuaC5SFhbRdkQ6OypSGBNNHX+qIwMmdd7QmlexmuYybjSCj3ykMfRahviAeHmvaej2DofOVEnxKwcFvNg4saFx/gcNVujzyr2T0dTJVIHY6MPZemJebdTbiLDuGYpm1ihWWpMDSpYtjtwCEXRy/TUrxazTcZAtHlypftPnij14C7CYqoB6042AzFiM4W9KNT152W6yQmqM2nrre+0BIqcO6GYGzpmCv+5ejeGf+Gc1lSaVZf6w8em4Zk4PLwu3UDPOvgy+k2v3bMVjvJokyG5f8RF7f0HIrb9KhyzBaFd1WTvdz1/SoWEZeYK9ikC6vo5bRQqyeRvozzHdtvpQcDRz 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(15650500001)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dR5YWavcNrBFV5hUp3X1gL2zkrWyclAMJI0s46QzMqsdyv9MnLxQuVnXAEzJ51Bp2mIMnCkvs/vOwkp3RS1i2iP/p2HASR9OC4DgC0zUEK52jD1zYhirinS2l9MKwiTUIg0zLbEEomB4DEtVp2ziBCGWVXAAAymoMu7+UF9Iy/QDlpgAFlsML6+hCPGvYfJrFDKRX6r6RfxnoO1w2m2nslPdtC9EGvwOfLyirj9ve6KepQ9VxuM4IkXhosjlGKa3nPd9TKKxpJSctsHZx4a0oan0bfvPfhf/zoAW/c8ie6Sk2GB0SS5eVZENK5v2vl553G6zQdym2LkPyGV8CJpc7HPsacxe61zuUwYGEVxXvBymPpy3toD43T7BPJvhc9cnWFfFoo+w23fD8wMevr5jAq9tySCqEd/zT+APdzFH3WgNBxvBUDmfmh/WVXfX5AGcexZt/7aDMfsgF8LZD0OpzCjQcib5TkylkRZMN0QdadXedRPvtufwlP96NRTBsQ+OiVbvnM+EEKZVgsjkigNBgzUB+b03r3LCMpVTJyLqew6ccv2gRrGCpkQuMoEMEO+EpNv86iLyVimWzXX4W1IonZBZItdRUZIHN89sjmli8G4AAjTcrM3rwOjZJjli9styL8SlP5KnsNX+JkGA+7DMZdje5g7G1MFFSI2lizbOTni/gbuzmjPeVNOUgoBt8O4P+3kvLbetFpbveK12qNA9yNu+ce/Ao/8y321tG10YBi1lmgCIdSMlN4kOOMvEz88sueQIJjn3BeVzHLD7AGkWKU07xs8KKnhZcFWO65kUHk5tnvBxGPaRqGDGzZ3QBg5ccF+h9lIxN/cIXz00aIhx/pS4RmKnbh1ogviODmDhFHuUhf50XB2tBjiEVe2U9e171Fx294byFUd3h1PVYak2WBgjwB59UCj03PvZivnCPP+p2DeXXV5vWzE40t4EnvarIFTCO5TboPGiZglNXXZLswywqOE5AMoPMtUYhm8voSdhpMYnMV5bYLoyB6HfwDHHf6li16u+6BlfWKsG9ye5yN8TJxXYSWsb7+Oe8toYJrkz6z5AdmRWpSXtr3EqChCVqYLVuIw6NEet+ZWU8z8ZiuNugRBW+oQmhlDanngCdvbGTyS0LIsdFsRkQiz4Z2OCGEkwit3v4Cax6xhuqBDwQNn9qwb6os1SF6ZDi87OCwP5r3TmQyJ5RJB5yAaIoBO8nTVcAEQbnWcmP+JDnFmA2jNuP/I/PCXJAbAQrorRS4M0MpS4RY5c1QaZvA1gJwNXnnKV1GGC+cBxSbsPtKBcp/+LllW7D1S1zODtorvc559zTqJYV3aM90MliBk+2w0md+EpJg7OBX4Objpa/hkZOt/yr05KMtvSflE+cnHqUvA9/ueOaG4iAsTLV/592772Zvc47o/DrIZU8ioqk73Xz2LStJdQlfYpZzvXHabXDFZSXlgJLVEsmOc2Wj1y9iIIREJOym2byTtKi34wnd7ISgagq9rN8rYH85JzS+oY33hObWxikT0dk/0Eh57kSUrk1o22Xmj7bfXUVjmNoKk+E3zTBmUqHDLCBDNFYDRoFEkY6WUTyD6vm85LHgNZSeSb X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 559e6b05-b100-4c27-e0aa-08dbc9f1af83 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.2962 (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: bYg3gVrxCBxBmSBP3ZQW41L8V/uPMUfh5zEuypMywoOa1E5G0jTkCWJn8UYl43fN X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173349_722376_9B458879 X-CRM114-Status: UNSURE ( 9.29 ) X-CRM114-Notice: Please train this message. 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 Consolidate some more core by having release call arm_smmu_attach_dev_identity/blocked() instead of open coding this. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++----- 1 file changed, 2 insertions(+), 5 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 d42d5d0c03f812..95bb6cbe2fdb08 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2875,19 +2875,16 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) static void arm_smmu_release_device(struct device *dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); - struct arm_smmu_ste target; if (WARN_ON(arm_smmu_master_sva_enabled(master))) iopf_queue_remove_device(master->smmu->evtq.iopf, dev); /* Put the STE back to what arm_smmu_init_strtab() sets */ if (disable_bypass && !dev->iommu->require_direct) - arm_smmu_make_abort_ste(&target); + arm_smmu_attach_dev_blocked(&arm_smmu_blocked_domain, dev); else - arm_smmu_make_bypass_ste(&target); - arm_smmu_install_ste_for_dev(master, &target); + arm_smmu_attach_dev_identity(&arm_smmu_identity_domain, dev); - arm_smmu_detach_dev(master); arm_smmu_disable_pasid(master); arm_smmu_remove_master(master); if (master->cd_table.cdtab) From patchwork Wed Oct 11 00:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416474 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 0206BCD98D9 for ; Wed, 11 Oct 2023 00:34:34 +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=erJEL9hP8eEKuJoQCTgan/iZdBLsijH33BDnRycEe78=; b=sEqEVe5VRW+1d1 Y6qECYe+hrHjfmuHfuXvdCvIA6i6jcz2pnq/UKieVqV0AFJ/pzdYqn20pYBTaszriF9tmETnVPrBT XU+3JqjmsOoqF1hwHGsAPWooBkIcdwmAMpZeJPWWyQ0ivXlkZkDNDyks5He7hA7W8xjrJUVSvklxz 03fqgkf6q0AL/nt0tqs99gJGxBSaJMY5VQLg91KppQZKhdF8mMFdOcUWOLvMMb/XCMKL5bxy1t219 ZwRXNcznNJ2/DbFbj75ElWJd5ucKQ7NTJ4zVt0hDmGDVFoytnjwOEbH2V5VGzP1lI93hNYux3oa8h bj5AYHsHI+1IZt6LcGRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAl-00ERFw-1J; Wed, 11 Oct 2023 00:33:59 +0000 Received: from mail-mw2nam12on20617.outbound.protection.outlook.com ([2a01:111:f400:fe5a::617] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAV-00ER0E-1R for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QhrhNGCwALHuc2562n+Ffk5JJEm4ZqkO/rT8bYu6TC737NTLAKa5igmtJYMY8mvO4v0oTbBrcTQWgdHpZJk17GCJPP37wbmYrNiZ/zz06btXgn0YjOrudUt0AsQ4nFzxto4r5dTbMSDTQ2xaGEpbH0xSLvvlDBkjjnObff7xWgn0lkDNy/X4iVn9Juu6ThlpZJ+nqlw5Ayk7dLbnDb1crvDHvd8hzgNqlJwASlLdeO3yb9FXXLzKwri5BjfEYqfeV4dmmkMpH/bm4J6vlIpi0o4RS+udRKfxBSF+uEm5MJcouOoCKSKk0PEopRSo8IpI9lfm1eNdiHpBGXZzXYkeDw== 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=QqXG+k7WyZkYXBzLYd1S77ABlEvO92CIdnjTsgUweg8=; b=Z8k06RaDyUwyzDbcNZQxZqHh+EpJzYP9AlLClNRrDBac83PynOwKyznWsik2+IOU3yMOouO7GxauJtTIdXzbHYnA/pSiouVNjA/dda332XNdgh69z6uEdOYpbxObUS3Ux7/oJ7zd/jLpyFzzyJH+YZRRSP/4fVol5yyLN5YfTyaMV/60he8zAnvCdhx165JkmZ8blgYh/tn9L1cRQF/4/Md6rFfPYCYpq4OB4DvFXdS/nCtE+E01NkIFdo6fVWVU6OjThnPLksFZM9/KQJwzvtSoBoL0gvEknSbkMkHbwGmjItvPZUqHNRoQXiEhvdAG6LW2cOXFRhQdtHHmSg0Uuw== 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=QqXG+k7WyZkYXBzLYd1S77ABlEvO92CIdnjTsgUweg8=; b=YaVQq8mV8cAJ2sMx67uTnHGYWzaDRdy/mEwUNN056i+reHRN/5IkrYuBdVL0wpgl7jeFrSXL5lxf5as1B/35f/obDlPiuZtj1jQYXvhihvIRm3oPMN4gmVJHzSRaxWvz/9PJVkTcsYqcCZ5Nx7YgCGX0zspj4cVUqgfx+eHpOWlJjCmgKhXTvm91wPVCRRISe6sTc/Cceyt0zEFL/CTd5E6cf9AaAiSfVgA2aE2qmRP0W6Pqhq66cLI92y59DTQWqR9I4gN7cTDEDHDnB7y+c2TbXff6lrWQLfcmRlaLBKA4xVqrKPS5M3lQpKO0ZDjD1KQdBPirg4uBOd95M4hMQw== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:28 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:28 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 18/19] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Tue, 10 Oct 2023 21:33:24 -0300 Message-ID: <18-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0420.namprd13.prod.outlook.com (2603:10b6:208:2c2::35) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 8567ba54-60cc-462a-27f5-08dbc9f1af03 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OjDQQoyEiYhXBoODiRiNhBmc+O4M+gfnhe+74asP9/TozZTEdTQp0CB4GFMrlxHoTZLumfF+ogRYyov1azAJrnjfOclPZ8h9vxkxl/WGOqs7TsEETwPLx4Z9oaujNLaD6udaZwsBNzMTDZmBipqlC2zRG/zTsdT7ws5HvBb5pNbNATs8HkYU09vzHVfpPwRGu1yZamADluD90tTXuQnn9oqlsq8pK5MtZKSlEE5zUWS75pAF01XmMVueDBX6FNjtsoM4aknn0gCTCfAeRwnVlBA1MKGQZLMzO2ghEwH0rrRU0uiadc/2fLhXPTGSWPo1Rs9V6OhWnUHVab3MS0lQ32OKNZ65ajYUsV8nFOxDXYielAFzmscc2EHFsIZf8dY/OXARLO92xp380tWaBkOC15Jz2q8sTEZE2AtidjyxeI5Hfq++tCOQlnDjfabyj47LawJC+LQ83wC0ibz5mfoZyFhxbVBIx2mqZSfdCjavBekeD8Lm7fWeBP9N8hI8o+YBrP6qwWuY1t/VtQPlbWjHVUEf+V7fK4ct7PdnC32FMPfLreMPQvWsP+YMny5Z39EV 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3FyheEhuuxuSWbib6xP7Y09Mtag8zcnM46MtpAocEHdU3BwbqsKJZcDQsVe0f9rOR+KS8aDshs7kYChXkjVZp8kGJIEtiQSHJE9c7U+icdEQhBvNaJI7lad7os8m3VnOwg1eis8+GOG2JRXfNwaSYZiMFxVXR4OBx2SOzBD6DreIMeeeVOwzOXqvK+TotsYoU96otNe04UYGGM/QG0gUSr9F9nIBedcOnywoX+az+djObSl2w7U3NrD6uLcGHB/B5i6y/oLtBePv8FYjpQboKPyld+d66asuojmhvFEibo0bMT4tsVbPG/ve6lTS+BSZVGtnzHqQmlwK5m8VEwsukZ86OkahKe/gLA1ksusEQ1S9dP9DVFVS8PzPxpfvjAm1FweH6DiaQwN5Cf2FYWAm7oAtHN6+KOoDg67COySErJUmfwm7P2Ws+VA3LIR2BU8ODzSIJF6mo+v4hJvruUPbQkICCY8jNLJ/Bm3G6d7HscarpjHu9MjHTLBZP4A17UPLWy8EnSvl4ubRe7vLk8+8zdXl9hyJzWh4NEYpxyc+Nq7ulDH2laTjo27b+s6HdtVzU741mYSqhZwsoGbaym2UBK+szpUDTw5nCXB4+yPUW65wBpGjwIQ933YMwvCnpGPhGMfYLBhcXnZDcIJdfdEH6yJpg7M5DWXC/xjp7PmwzztOEmEPa1DXwJ2apIjxiKytT79In6RYp3IcBo+a41/R2E3Nq0OWWJmd2qHIrIPJpae9ob68ewt/gS86ziSiZkdG7JTmjWHqJ+qTq0uIz5o61GHkoeCtyp7Vi9ZtVKzK4zFRUe3ny+C9euui8X29sEycxUMVZXWgQtORROo/toYqRFDqssoJYiztAdN7SycPoqn+8cH2uRiHlPvrLpPsjApZkEBj6Aa94y9i6i9KRlaaWg0lSBES3SkR6PuZEO9HTD2Kb3BsmrYSN/IN98FvRjqnYgYQtzF3qlLIbTnQfuN7ilsqkqm+TQF16hZ0pl/6rz2PPZKkh+SA5z2Z7Y/LbNtTfm/KkOEEtIFMeXeG7l37JhftDLIGfEbmp+hyaYzLxJ8Zl2csWAaY4qKDkOwy38n6PiFqqTZkLtIWPjVS3SCPP4/VivNHJggMzStRVvuyHk2JRaSeTme/aKcEPaGgrAk7TXlT835hNOXIMgGynVm54kXwR9gjWfYUKyFFoRkitXA47xNmt0fiJQEm8Kq9XC9d9JrCTLAc476q/73GVEqjjt/bwJyWrkskVyBGd4ThRlzzIP2kJ5jvF1MrXRDOKjg3tf0RaAhoPJSZmIPto0TgCql8aXVUR5R/M3pnPngmpncISMLhww6OIG7+QhmebGip7R6x/vRB4vwrPUr20OFseVbV16oiBDYoWLLMidGS5qSomXuJLktLaMpszk/nLwWdoGm9truot+DieKOUA1+D9O3dcK7c0wiE1BWa1O3VRHsq9AOe+td0U5CYeZCAk0aNPcL3bHG41pPz0T804iTo1aUFtAQtVJmAhT80QQjFnktm9LBH6BtTxkqe2ghklYEZm3E+/WV6QV0eog6T1fJJxxDNutkNh+Bu7fhHEok2QdzP4InWb9K1NVRcZAxbNJ30 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8567ba54-60cc-462a-27f5-08dbc9f1af03 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:26.4481 (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: /UBnSgGkORPufh/iFrpMeerRXY3lpSe3+Xb746rJkRnCrXMrTBstIeNCVnuYHLFd X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173343_535368_000B7027 X-CRM114-Status: GOOD ( 15.01 ) 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 Instead of putting container_of() casts in the internals, use the proper type in this call chain. This makes it easier to check that the two global static domains are not leaking into call chains they should not. Passing the smmu avoids the only caller from having to set it and unset it in the error path. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 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 95bb6cbe2fdb08..6a4b6d23590e8f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -87,6 +87,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { }; static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu); +static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_device *smmu); static void parse_driver_options(struct arm_smmu_device *smmu) { @@ -2191,12 +2193,12 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) kfree(smmu_domain); } -static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_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) { int ret; u32 asid; - struct arm_smmu_device *smmu = smmu_domain->smmu; 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; @@ -2228,11 +2230,11 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, return ret; } -static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, +static int arm_smmu_domain_finalise_s2(struct arm_smmu_device *smmu, + struct arm_smmu_domain *smmu_domain, struct io_pgtable_cfg *pgtbl_cfg) { int vmid; - struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; /* Reserve VMID 0 for stage-2 bypass STEs */ @@ -2245,17 +2247,17 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, return 0; } -static int arm_smmu_domain_finalise(struct iommu_domain *domain) +static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_device *smmu) { int ret; unsigned long ias, oas; enum io_pgtable_fmt fmt; struct io_pgtable_cfg pgtbl_cfg; struct io_pgtable_ops *pgtbl_ops; - int (*finalise_stage_fn)(struct arm_smmu_domain *, + int (*finalise_stage_fn)(struct arm_smmu_device *smmu, + struct arm_smmu_domain *, struct io_pgtable_cfg *); - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct arm_smmu_device *smmu = smmu_domain->smmu; /* Restrict the stage to what we can actually support */ if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) @@ -2294,17 +2296,18 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) if (!pgtbl_ops) return -ENOMEM; - domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; - domain->geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; - domain->geometry.force_aperture = true; + smmu_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; + smmu_domain->domain.geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; + smmu_domain->domain.geometry.force_aperture = true; - ret = finalise_stage_fn(smmu_domain, &pgtbl_cfg); + ret = finalise_stage_fn(smmu, smmu_domain, &pgtbl_cfg); if (ret < 0) { free_io_pgtable_ops(pgtbl_ops); return ret; } smmu_domain->pgtbl_ops = pgtbl_ops; + smmu_domain->smmu = smmu; return 0; } @@ -2495,10 +2498,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) mutex_lock(&smmu_domain->init_mutex); if (!smmu_domain->smmu) { - smmu_domain->smmu = smmu; - ret = arm_smmu_domain_finalise(domain); - if (ret) - smmu_domain->smmu = NULL; + ret = arm_smmu_domain_finalise(smmu_domain, smmu); } else if (smmu_domain->smmu != smmu) ret = -EINVAL; From patchwork Wed Oct 11 00:33:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13416485 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 31510CD98E0 for ; Wed, 11 Oct 2023 00:34:54 +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=KVTaLbRisKuegNDvDgZJPIfL9Iu8AjHzB7Q7/cpJeSA=; b=yUfPhlrtE0J4E+ cJjwmXkr9+zWlGv2I5L8dZoIUvHjX6HOK+FmpPkofVic1O+m411SDKtsKv7M8R9enDk40tKeMw+V1 DUXVnp9dye0Z/77FPtLMeazEJyLUHl37KE8/GwwznOd8pNh1sJRRHBYoJUV6w4fNLfggzdrtUFijT pYnno0/5SyFo2JNYm+m+Q3MBn6a4PPGO/pFsmD+Qvsz6OVTBEeIHDYLSX7K6OtYnJWU3ysaOs6WDc sdThorbKaUfKSizMefJsvaPFi1p7Viz5mk+tA4KMUkOvhEM3TS/XfwZcHYBw1MU6VMFaSPO8qmbb5 KawdJQd4JVbRQ0t8YaWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAs-00ERLX-06; Wed, 11 Oct 2023 00:34:06 +0000 Received: from mail-mw2nam12on20610.outbound.protection.outlook.com ([2a01:111:f400:fe5a::610] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqNAd-00EQyX-0w for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 00:33:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=geSvKlWoOC/boGhXoXJl5OxESpNz77ArStQVuRrDp4Bc3mlFBBugoOduX+0wM396DlEq9QXFvb+DcFcHkoiwFyB2uGqeIyf6eK/0k7lFQSRhR9sWH9PCjJi4ZDPAtVDArNTTxKeJn++GH9rYqOJink6ndSGWn9XD5f8GzhBNwZSQ6LTmUB/7ODCT0uhbDXlyfWu7iekdLQ1um+lbijXRHHp3vo3kACz9RNtBbysU4Ymp9tQXTSd/xyS82h2a5XGY5ESBzAdYDok90hdZM7RyO7GZu1tKSIK0qZp3/9lNgpPmYhSZB44WS4VNRxpWj3MZEX6ddgHVmUrKmxz+UZzpDw== 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=eN5pXfHl1wjjBYDfP8PKaLCqsrVUbnIEedeq1lfBfMc=; b=Vm3N9C2+2K9I1/oQvW7tqKH4omNmwomyJ2c6lc9PSM30KLt8nTVo1tLOVXJ4Gxujr6Se28VcRpt6ANtbht4ocO77fVkwGzgjGtBu6JEMf5+MBADrZ1h0SKGThk0hv3vtvfkiZ8qchBu5qd+u0cYmE+ciVgo2F9u/S+uYO4y3SwcQyXDvCaTxp+Qo0XWR3d2TeITZLRusZ97adQmatFmFxMxsKjVLWL1oCOeXNS2rRPTOV0zoEy8nJyu4x7r4j+aLnnPky8uGFT+s6EJ9KPScPhwI1mD1eihOS9FeR6OsHFx7g72PnKRp06mS53NoqRIENQ3HUq2yqcB9KjSrHxJA9g== 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=eN5pXfHl1wjjBYDfP8PKaLCqsrVUbnIEedeq1lfBfMc=; b=HDYCoJvHGoJA9+qQXtmCWlom9L/Bnh0XHX+0v07HN9efs9kIxU1/UmuJ5UndAbfda2CkR6eCHMfdpowqBKpiTPX9YKCjo8NbX2p8tfTiutOH4+ha9EijD76VTRjup18aJjPjHzCMQuiongUNQ9NeUGmqN/MI6p6664wru2hdLJ7cNYh3hoanBFk3rxp5zMWDsd58zCfKCDZ5+PIwE2LV9M/QzPy5Yamrddmzh3o2gc2j1EpWo5eATfdvR+xH0HX5sf5h/3mqpXxOwUEvVzyGtKjJIsOS/al8JK8wkq5mP1hvwujOIyXJd6pNt2VHVtUjBb66IEk5FhzdUxd2Mv8bmQ== 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 IA1PR12MB6625.namprd12.prod.outlook.com (2603:10b6:208:3a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.42; Wed, 11 Oct 2023 00:33:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 00:33:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen Subject: [PATCH 19/19] iommu/arm-smmu-v3: Convert to domain_alloc_paging() Date: Tue, 10 Oct 2023 21:33:25 -0300 Message-ID: <19-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v1-e289ca9121be+2be-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0062.namprd16.prod.outlook.com (2603:10b6:208:234::31) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: ee5cf119-9772-4706-e0aa-08dbc9f1af83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v+7vxvO/cvRXlVxHp7oS6ZijXymKCVcuvrj7o4QLl0Og/i0SExjnZIB/lcZam8eIVsixDEC7gz7YAP4ONQ3HimG13TGhTzWHp0ZwCp3PQFpe5w7UHonEO0j7QsyX+NHB7d1ux/tRABBDYQ1Cp4AhLgSxFek8NI7lWuTwSlDWVBeE0rMOrpoS4+ELcR15NUnGjNCjx64yqFRMi4RPgaxmBSdQWzhh3+AORIPewHDkPzN7dv7zKLc2VfSU/YfvMKp1dEZM3EtvqATnn/CDt3ZBVmxSBqSlo9ruCOnrrm7UGsV89wxwJyxQavDpmXy2PbUxg14kvIexzRtodze3eEUtL3mJvtDHe1Ik/mCQ+xv3XSG28Y4NJHm7WjXBPtMnRfqJ0vHdiRj6Sx34U/lpgaToBzoRUqTbB+rI3Dqd+ehYK3z8uR3Q4n6+qOo25DaUzliJLKV2f9BWMKyRP98L/4tRoy4lUsRP3IYEDB2qYYzapIEUDQjwB6bfH2HiKt4H25KjRvKufgkJxTn/3LZCx3tMn1NC5Hnh7IbsOJXLTjKOlZzlyYHXKKg0CA0cNJ2RHRaB 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)(396003)(366004)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(107886003)(6512007)(36756003)(38100700002)(86362001)(26005)(83380400001)(2906002)(6666004)(2616005)(6506007)(478600001)(6486002)(8936002)(8676002)(4326008)(316002)(41300700001)(110136005)(66946007)(66556008)(66476007)(54906003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d/1shM3gQiwgovdILfixt5wEA9QhRS4Vz3YVYdYVmB16A/BZLq5DF/8P4SGYR9oqH8w3noKCFuKv571PuB7YGfuPIFWgspZyS0kvZfPVysxJurL6DY3mIh+xIL9bf/vJzC/2H6IX3j2uwqJukjV+it2EbIqJibDmX0auwr+t+dxLq/OYc3gbH6rqug5Ao2VgS0xYejr9gXxkfEhT8eRqYqAvZlZM/QAspLH/zPZ5IEsMWKwHEIxl69qUazOgVKasjSGVlOkunURJQGfNcCYwJSQKH9APHzoiWdkr4yIQz0WMHkhUA6avFROxAagnnR5/U/rX03ww/XwecoRuTdpohV1mlm3Q0OKlzyH9ZnI+xPO8vAfEgkFSujPQickI3KrJeso63n7pCtaun/vTfkqBFHHdfSJZ1aNluiaIELnf+HMh+GkBWs5vU/IthlLCbz9PrZdbBtj3kdkMEsFLgg7sihcKJs/NQ+OM+Hf0lOreaeXoGoBPST/eM7WGWq8Cg1HrVYbeTfvCT1iR86EO/EF5eebAjDz4g0OvPyXtslSDFaqc4rLFt6o5AoctLMpwJuhr2jvPptoT9kLna6GK0ARYrBuhShhDPLXU7G943Dwo4AfN14K//5tcAw99gi/9gxLfFAwEsXOo/wfhQUxilirHxdQgF7NKmd6UDEVVGCQW/SgQudW0Pz6UUD712IFRJYxO9atWANMTrLKDbCKlG36erPzYu0yzeRgWw7AYB4jEEpiyOI63HZ+PNRJCynj7HB4m488Q9Obb0uMqH2mvUJA0FwzJufMX2lzH2uPJaZ0QCKLp9kTbc9x95bLSIFrsN4WEf4+JKjT63FqdTg4j4kMAKX2rbixrSVSGsfNdPf/es0SyY8FQZZKjB0AGkyoEiopraJ49PtEtajUUveoFUktWEnhqvlqvt7Z8q2aKM6Z1S+zlrR4GDq4O7BgT9kHh/8JNBVPdwHy/EeRxuhn5fdXMqQYdkBc8jkBEjMW31z1gl9aFDpF5DPpSW+2rCIGCJ2SBCvIc2BqQbZkGAPhKQ2V9t2BfKcc/beAhjbp5NFiQdTmk6kf40eVXyRWkz42RkHNkMCn9O5PGNkMqZYxVS2WaeK93rq40lGPbe55SVXeXQzKg9zAz5L4ZkWJq3XY+W6iiCGlMAcHPENAqIe8JiOGXC+kgHHXC/IxiIjhJxJ/4hpkbu2WYhrAeY6AihxTkhk4Bhx+4uEadny121iXuYUjJH80BH3VpXXUBwLgfAYba+2B7R6NCes17yTNkBKmNGbT0UfJtlLgMS5Ke4KMzs14loKxfBnhKQPJZygWFkpYrDfM2mveLyJleC/6pDYS6PXtNre28NWMQpAIGKsoGJx8+u/CAt0XOLbZJGtXWf82BGlOtZGvA97olkYrypVKmBzAcHrB3OEoU9NVkwhKPNFvzaeiVgisE4dIkksRTLThxwIeFxRP0i570ug4R5p9jCyPZOU2NvP4OzzmcegwAa0a8FUL9GP/p2h86diYCTkKpx9tjfLbZ5Ap4bEYiSZLHCPPh5BZWcAPkB8rwI+8/oyXaRpzKSr20II90woCDTX66kvCfdAuJQT9FrxzU77X5gGfV X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee5cf119-9772-4706-e0aa-08dbc9f1af83 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 00:33:27.3330 (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: +0E2aBYQrweHkf0YiMBmmAKowCnN53Q235WY4xguc+tKe+7KZlDOyG6UlKqIx7ny X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6625 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231010_173351_369538_419A1580 X-CRM114-Status: GOOD ( 12.55 ) 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 Now that the BLOCKED and IDENTITY behaviors are managed with their own domains change to the domain_alloc_paging() op. For now SVA remains using the old interface, eventually it will get its own op that can pass in the device and mm_struct which will let us have a sane lifetime for the mmu_notifier. Call arm_smmu_domain_finalise() early if dev is available. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 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 6a4b6d23590e8f..7c1dc96aa75d92 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2145,14 +2145,15 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) { - struct arm_smmu_domain *smmu_domain; if (type == IOMMU_DOMAIN_SVA) return arm_smmu_sva_domain_alloc(); + return NULL; +} - if (type != IOMMU_DOMAIN_UNMANAGED && - type != IOMMU_DOMAIN_DMA) - return NULL; +static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) +{ + struct arm_smmu_domain *smmu_domain; /* * Allocate the domain and initialise some of its data structures. @@ -2168,6 +2169,14 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) spin_lock_init(&smmu_domain->devices_lock); INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + if (dev) { + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + + if (arm_smmu_domain_finalise(smmu_domain, master->smmu)) { + kfree(smmu_domain); + return NULL; + } + } return &smmu_domain->domain; } @@ -3033,6 +3042,7 @@ static struct iommu_ops arm_smmu_ops = { .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc, + .domain_alloc_paging = arm_smmu_domain_alloc_paging, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, .device_group = arm_smmu_device_group,