From patchwork Mon Nov 13 17:53: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: 13454346 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 B2FB3C4332F for ; Mon, 13 Nov 2023 19:00:53 +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=4cSX7HoKOywuFP bw3u3L5BeI8jUFfHBzs3uWjuA81jb2gVVqbUCvoS4Kqg/oIxuF/PzIxTvoWCfaCIwe1sdTn09DDFe 1tO8XNFvB3wET9VXNzGf2XzVMCIByervNvJM6TyGA/b8GSV2WCjBs877DUSH3iHqnXXeQSDsWkINn 4kQ4Jq4z0J6iVXaKw3EA32AerZE/pTakr0C1k++HveO7spgHgpBcxHs7b6LnqbkBCZKa7LSHcgh4A naWvgGvyM+PtR6hUOrcYNtn7JgIq7nX15gBNPIo43IACPnkuyBmJP/orrleC3kDhDj5QCuu3VpOrw NWYlrBFhSQEGzG6Ex8wQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2cAY-00EWze-2L; Mon, 13 Nov 2023 19:00:22 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8C-00ERTJ-2K for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kzLLx+NwJoYtBKVxx/RGdUEAt0SHP60Lc7N5uhs21sYnnxJpwKwKhNbvMUCnNrf3NNua+LhJvTjcQP5ehGzv8VQtL2Xe2UOkHB04TNcWXSis5roqp6VUMdXjS9T4QhZMq5XzOE+craVlhDO2qJaHN7OAmfEn4IfMym2WK3qWdebCM8r/m23engHdBdVHhwTs3SW5MxtYJROrbLcJrQRMdXuJfE6teLBXIpnD/mEcmalvVdRC49Q6rMQSZkXPKo5QrtL2DRLm+kTv/tvWuOv9b5hA8xPquZFMWq4XkdsX3xQGGHn8AXKaWtiNbDN4CK1+4Jjnt8gm6KPmB1ZfPdqb0g== 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=BRw7chAKTa5o19ocujMzWzMIzndAEfDMQp0un35JE80GJlI/tvl2qLm0+vP0lgG5KlvmXd3dgCFIqolLL0LUTRkNfMt8Sgr/Vgli+Gyhht3e9kg+qQNCDRzIuGqHakwLINb6MndK8E4m+DWOWJE5qZ0TVt6seUABxdoY32xx0DSSvWZ2m4DZjkcCoxN47Gien1xtOsL97YSgAkPhjeYKCuAZ8dGxOsX9T+Gibmnv+Sxzw/b1TMWpQFHT41PLRyawkKBfVFf2iJUGQVt79oRTwTFlH/rcn6M/z3KWuDB82ES08s3IpZSRkbwLXhrnIx97csm/7HZVxncBV5kemB7ewA== 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=OczEAv2sovB4EfT4gaTFDld+HvffcRXEy3xVAQZpM63Z7ALD4KxdIAXpjkGFCfg/m13GAdwj6mdREtF6iWX2dKi/OO8XwNATA9ZOvlhUoHhthFbnn0PiVseZ5jCFVaYA98hayI1Sm3BuR4A3TMGuvfqyB/RiZPFz59aouBaLSHCt9ruAFpPsNuTY/b5R47WG3luoQnvvsqupHsUNbrQYnI5z/EPRmbtP6XsB0W1Hae8ePhurI1Bf9x+3swqVM5is1197/mO8HdRXZXnWT+Wg9AfV5vFuMrIbjPA4MLYr+//Jt9tLk4Hitxs/43Rpv7Z4W3YSTATojhqG5OTnLuK2Jg== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:36 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:36 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 01/19] iommu/arm-smmu-v3: Add a type for the STE Date: Mon, 13 Nov 2023 13:53:08 -0400 Message-ID: <1-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0011.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 85f8d554-26c4-4082-9f94-08dbe47170ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tk0N/tVokYAKc9SVxoVNKZrhUwm55rmlUNPRx+EkMUgjPpbJOmn8m9gnGOYxGB9N9DRfFVmA5pmlN/h19VV/TzT6dHKk4xJXMimiDIOerWrAPbXWd1MlK49lZibN8VNnbpnKb4pV4yNJGW6C1OnqBs86D1qfO9yNpXuOaP2TXvDtF2h6S3TBcvWD9syhVkEmZnq5S31qXxV6NY5XHcoE3LWFGlcI3zhwcpIqNgmc1/TOoR7j4X5ZTuZUsSYbkLTSE6yi5JWLi3p2MCm4gIRd5oqC+2kh5bvMDJkqQzhosrSw3GFPLpUa3WvNWVfY0HTK/+y6P8YDmIztU1b4fBgpRtBxV9+oscpC4FsLZ35hntfZxuM08mj4hesFe9/zcf9ChwnCV5hvJhaGcMsWO0ahNTa5Gb2wvpRozQhtN4UFE3/45Y7uFpR09VMnkl9P/9v9vyJs3WpGuTnYHAkU16x+P2v+69nkAyYwyLsbAcyMtTdyBtp8SAK58briauln97D9XWNOA1jqKHU5jr/mra0wXDDd+ptBTPZYrWaI3CGRzyZgPM/2R5bsx2s+m/FZCIVrxS7ntD3vQVYbk9ckVW/5alN89iBF7VZN6nlYYnIw4FQ= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Cf7zOzrs5hd6gxnYl2AGY9wt7hYbOJFJ9Lt/v1s7ZOmmYQ5lLVn3jPZQWIDrdacATP3HYrmDUhSofuRfhCEmCNBjU5MD9SM8fDaFcUkwpcSN4XPheCWd31RZcwaWJKRVux7flWe+aqRw6KhDzvtF/umDy8KbH3QU9J66ADNLVi+6Ty7RrsWPPS16im7nvCdy0QqbBUjimT5vYezaP5fbX6HE6gRYToEJtm/8aEhDoQQ2PcndXBiztQt6fa+ECny3oCvrqWjiST/LbYPYkqkivR2MKF4zuJlkTucKMsB/FY8ZKM92RO4ZqNU3ppBdK32g0vsOxrJ12MB7EsRGdGYJ3duBePCAbviqIkjPmHLIZLkgIUzQzml9AQVH5CDC5q+Bpy8Z+vhZ8wIQhQGcah1ju2309sNzTew4ekVIRuo3qbcp31wFE6us55lav50ieSGqEXpYghyZqwheX745iKT3bpX1RU76A8o39lu8ZjMlKAf6MefS99Jwx/TNy/NObqBXBlJ9iDz5OqKmR3f/kykZpcOB5r2fSH37UFDZWMQRa0tQ2kBSDru7/pWSErk2rFfTpa5h1Kg7cmmfKtiXu4faaW62rrev0W047rmDQXuu3Hlkli7D/WWPe13gzLmrhkI94/m3bl+Moy9fJLWJ1pra4anVPO60Gwj0lMVql1mdbnvu6wyywZgzP8Du6m6/mOFCXAcUTBr/ieYd9SD5rUcypuF4fqX4mJHETO8yTwKYHmPAzmEKoIhlGpst5W989BNWufWOtUWrx9GMQ28IaCUU4JdGLgagWlxg8EGV3rtQ1PDVFCePZ9E1QFG000+m1AFrhIwr95FHWzp+uLG+xoRb46v3tHbRf7CzXHXtULUuQyEpMnpzRhVMlYmoXecIU0o3EEwdkACS9y7OHgjw+IOjTjmPdrYphoU9/4n0XVHOAl2OWqHsVCsoxZ4dNN4YIKY3Z3YurusOXpldb4xNyenmYnFBAhnkX2LX56qiy0S9mENzKIAgkuMu2BTALoL0ghus4yreieFuiti6Lxznb9BMPYea3Uiw0itcSRsfJhzDtsR2yDQCxkzDop4pjTfBBynXaoKBLOV8Sb16Yr2oP6fy8/AvDecXP1YWTrxb8VkMMAhCX909ETFZjm2nAswUAKfM9zHpmXWCAI1J9qul5qVYP6nGt7uAw23WbWL8am/qBxLNZzTmgEeOoG7NuqV+F0MoEzj2K6X/GvLy2dYspozOxUI2kq9An6n0P9TuzgwOoRjNI2G9dVAKMtAT4qBwE24w6kJa++aBwLMnoxT7XkIBPPOgVNHEu+drq5/J9TlSnl7KXgJMqsqs0OLomW2qGN+C5nQlgiHxhwN0aU6rPQmwJyahXeKoYleRfZGuvLziaZBpOBGvz2PdqQ3I+LRmFgs0vVq5Wyw222aFJUb6fmw4ynsq+pSaD9VLr6lcEPcouePN09xchDAPVOD9F2d3Cq1rB8/kNjVcXiKBXosYuBoG2TX+eHLuWnKsUlo8wI6Rg+scIJHHfhDhbApQ3q6TCKxoBmCDTNXSrWqZlOzH5E/YjjyR79dP4qEp3r8CesHoQP4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85f8d554-26c4-4082-9f94-08dbe47170ab X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.6935 (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: QnstzaAGGQBMlTb22UjuW3qhgmWftYqeJV2UxRjyLlT4GiS0vBMBKvRUTgK+IYGb X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095352_790680_656ADC93 X-CRM114-Status: GOOD ( 17.93 ) 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 Reviewed-by: Moritz Fischer Reviewed-by: Michael Shavit Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen --- 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 Mon Nov 13 17:53: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: 13454294 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 2CD73C4332F for ; Mon, 13 Nov 2023 17:54: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=y7hXU2sJelH3v6 6fdIWs8dnBAEqrqfXgE77UUsWGYFWmIV/HXRtxM9bRe2k/K6aD8AMw5UUtPIItbDzkKRAN9YSez4p sSaohIuvq+QPi3IRO6zhERKqDus7K39M3VbN7jru0X3zWVAqcKB/y9VkxPrCEOD+LPaJjAeIUFAJK 7VokuVOXNNNt3dlm7baghqLFu/672oLDpvc1/3shGyBEFUbgUHAa+XoQPsSfQaEDiJ40pbbPJ6Eii cCz7tcZ204B48TqsgNMNYiQeKpXK4aJlFScPbd97eMNRIa/w3vadBhknw7r6c5W2Y+LUCxG+V7+gY 2vl9OjFLuxCvNixrKVuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8e-00ES3Y-2o; Mon, 13 Nov 2023 17:54:20 +0000 Received: from mail-mw2nam12on2060e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8E-00ERWJ-2W for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fz8FiNz+I6iKG2m63Se/KHGj95sa3M4H6uT+1HBQbEA0nVa4PUF4/CwLjNZdMjg5oK/GSULWCn8TQDVOGS9cEo3TXlpYWYgFDtm5bKg8l7Ss1p1YwW7oTuQLiqLvfomx1PsCfYe1fWv3kqHWa6sEaR3GOlXqnmqPzocZD5Rp50M4aoYa3oIrFP6F79g4aDBk0NmFMQ3Tuhjmm5RvczgARwNq15Spdj9TRfvTsx+xiZyqxOOh+0JRNa0uXLjdpjMoqbWP74XWe/0QeQQNN45YENJrNfd1rQt+Pr+eHiqZe7r2sXndTq3CQrBApVyur+qYD3RHFDlev2MCwlKoVCxecQ== 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=Mj0eVt9k1XA6lvKxS7t+Z0qB/jOtn7R1hyAbj2XxZ486hGWTqjlLCk0h5VeoA0FXwfmvh0D4dHsCJbc0DS9NIIP0vo2F6XwslWtmSwboWdWraowN4OG/InJ+g1qYEUU2+oj0ZeZxM4NN45ELLIe5hh4MsfGozvESTbWxsm0tR/IwoF+/TOOfBHcE9HGjiBdpvqTxA2iaNTw6SGuouT4dcinwBzVsrFZVjIbDtOWOSdqT6qUo+3i+AqcnFeLYJb1SOtou1EALVIbqZalTvKhYowEZ1NHq9hDO2OsWXwD8Rz8OdRxPG0RuhIdyr1jcd5hXHaYyouWFhhLzEYiVTmZ3gA== 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=TvxTesnoy9kxhA47sj5g9z+0nGRDjCrm8vgcGas7klAUqE6ajlC/flP+Rjq8qxWUfiHvNLScZIaUs3A9O/7oE8PlheZB+/cNzESe7ijY2OOnn9T0gUZak3zyMW+h1WxkCT2d72tPZtrLucvnz9+bZrB9gwfhOSZsh4dQMbNLexZeYWMbYdCRBnFeLVV1HV5olNlwKvOKwpf9aSoSXCI4BwqbNaylatmx52wXbOsPJg7VMlRe+mchFl99toAx6/X+mbkkMMQfTk+JGLAIL5lVm3Gv9p7N1rTsJTuzMbY1yiD4mBJxZGTytWq+A6qyAAZlB18iBJCXCNN2ApBgkKMOlg== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:38 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:38 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 02/19] iommu/arm-smmu-v3: Master cannot be NULL in arm_smmu_write_strtab_ent() Date: Mon, 13 Nov 2023 13:53:09 -0400 Message-ID: <2-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0325.namprd13.prod.outlook.com (2603:10b6:208:2c1::30) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f5ad9b9-e308-43a6-d6dc-08dbe4717103 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ivxwOD84DLek5ku5U66Gjc0RT4A6F+/fYbq/5tJVz2H4T5Mx69e5N2x3zqiOeterVMWE/cmLohnCqUWnCzlPPRzfsrYLcMAfE+Pc4ZEhG3bZ6ABI4QIOe37BD61kx65O/JSx0z66JzTJgzBAtBMybUw5Vy3TUV22vGZrHaHBdYYkA8Kt8zLNFxOeakCrXgpF3qUFVcSP7HePCBtlA6LWBgF/hRpUgCW14eZ+GxjSQtFM0/505yv98CwbJfszGhFqS/l3hKC8CMHKIFvmD9cH3f+4o1aPCMXEeuGpG600RrS+MEqlYPlCkHcpBfM6qIJxk2ZiJuxkYfH+Y+7lU7844j3buVuZT2AXpHXOp7A7FUmnlQmaF5m6rHrtfz3EF54WeqP9Wr7oQjfLBywymtjIObaj4k0UdxhUtc3eGHxIXfLue004mItw+m6nwtkabXpd2oT7crk+DlfsrfllXAZX/5zWOYXFN/xgQWF9rAPvANCGyNd/pwxqpU1+BU4wnwO/gw0E6S54CVMpba2myJJnLQHg8eA5q9+2khMBpqgQ5dK5EnO0meDW/w9i+wG5z7f49vdwFG5PSUdROLaQLAUFJGHet8ud3udK+6zhYln0Sd0= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NJraKFXLBxM+OXs2A7vybJKnzSM3MDng4q/PRBWM1DuweS1P05Va1fholsYHpfrvnBMIhp/Iy6dIxOyewunx70kPnrz2ntBkiG4fcfwuxnfsEvnjBccgeJHbj9cHMQPcb2aJ9FI/3QvCG12Vf4j97L+bIbYxB705aVkcCryj6iBHa/JwlMs4r+jJHdj8Blt+01Fc6T6wqUyHV1B45Ri69rPiOcCo9CEO1uSYb8Ui5dGwoDBnCATV10sCuN7A1iVKUx44nSREva6lt4Zc0avDJ3cvG2gCxYEHyZcu6ql7ScZAT9IW7fP0kEu2acyQETuM6Ne8InJdioJ6wYumrogRSj528HLTsLFo6A2pUE7djFB5VdpDJD6KdsehYJ30b82GvcFfO1xkvFtri7wK/XXZrc+BUEWd7UYqZznGbMdfIXCZRpkPGke3JlgKcHym4QxBk/XuUWfX+K2497yo2JMlPBFYDYuaNjMh8pqctU5uCa53RnAsObIOOQLzFcyeEBcxny5e+2zWVvk0hjDjJFC8SwWslarEmv1Zi3UcDgJCkUdztk1osUiwz8Akmjhk/U+FtvXLQPaKxvZ/B+5+N7YFh0sVmxRpQSfrdSOUsET71+pda2R7n27+ji5p5KXXegemySN/OLSCYWc/kB+O58Ivw5WcYNwPt4x1D0y+D3BnZ1gobz4tg40be+5gmi6kEwt6Su8VI/zdoYrDcLrA7sfkQCYzVH8FQSYdk9WtVozksd7QuQbE6Wf8F7jiUHG0ITIet++pDST7raT0Hpa+GY9/KWq6WOUM9f+/YLolRVj1mQOEs9D/wVjnSxVdgoJPozUJATH6ZMvtDBU6jsNJlHpcHyLVdj14vGdiymHMzG5cuAjfVKE6sH8woBTXw3i7H0lwGkux0G+t6OlWOJMZQWeodnMt7kk0m1CYmTqVg+NJWkPqL8w77L67KIbpcySgODMhWq0F0SCFOM7dHiW+ihuSfFArJ5X16TtrlOTLX3Tdk4hIfyrJToFgISpD5tWfCQ7dwwi93oZk7wbmFjVgUItj+bYBOXSZyZBmmbx9yrmWz5FaZYva7yw25hJYUiUMU2ZKUOaiG0qleylmrkp31+ICYLwsr3HUoBDyTcRUlxjGRHW4L8LZArbqVhjqhAV/lDdeXx92R2ehIk82yy94TmlihCve973mEOwdRadH24cRWHTWRXaxEmTC9bWOuobZWhssB94tnB/MC5ymWLW4eDmHP5EdaDxSfe2iRar9SI8+4uRv7xPFBu7rk3WxqVv8u5QZxlZiPCJDgcy5IRXMDd8elfYvZVzcdCVh1r7DKCO9xH/RbS91QMASZDUPjM7ZiSAx8JEeTYyqugIygbccX27P24XlMZEejtWeAmQDyP9bIl16/oEkGNbJkBozJwxZ5jw8tnJU/nPdX4phtrYNo2/ZH6hOsmdOkqzchiVf02XNQKI3JlhD/9ZemM7/lyqbYS5zLIhFuBd1Hce0/7TLTOXbrxJVOEydZWIPwa4qsc7NIjLraulRuALSA14AaxNRe6SX7oot8+fl7kseVyZZB/Pfp65hL4xTO2lhIpWYJlZZgmA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f5ad9b9-e308-43a6-d6dc-08dbe4717103 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:28.2637 (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: ygfHOl/pJgC6OaMWMJDri5v1hWzQLmqJ5AntJNeom685PaNLyLVp06ibi3O0xGQQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095354_850017_95C90796 X-CRM114-Status: UNSURE ( 9.55 ) 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 Reviewed-by: Moritz Fischer Reviewed-by: Michael Shavit Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen --- 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 Mon Nov 13 17:53: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: 13454295 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 AEC4EC4332F for ; Mon, 13 Nov 2023 17:54:50 +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=bb1UIRFjA99wmT lhlBuIsYAnQdW1VvKX2tgPwRSuThIrBczp9+rhXLS42s3Vt0s1HEkR/HFBNxFyPVtuYaMfvDFMl/2 PosDuS8aCTgUMb82HbmYEE8L4FmKvmWcKY3VhCUG7gvJddCEfinAN9Ujjzd/hgVuXztqM+r2B0OMB VgaLyO2edCjzXpZeJqKSzp7iVeeuz9aDKBlZVNVrhseQgPtCoqLfUEfJS62CYYVP81+usxOOwE8Dc RxgoFZFUJvQYQCLgkSLukLOgdSN4OkrdSb+DxOt06sjpLNTkgn7ChZxR16+Fv+KU+VGBTSrK61bCj GN6puKqBpk6f540rQi2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8k-00ES6r-05; Mon, 13 Nov 2023 17:54:26 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8G-00ERSw-0O for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m7w4K4SkZwxSbIhfUxpoe9oXu8isVggre5hmmTV9FWVtANiVDIh/5Qoz+mGSzrYmkoUSbdghn0auFQFl+K8TKGzXkj9h8dpuS8DCG2cjj+2ZS5DT/5jrTjxEF4+qsJnub+jef/ORvQhfVzimxxIUujVxhHpewkqHnx/Qtns/eVLLWWwMIWYKjOy6lD2N+QhPOTlr3HBO51bWd4mSdoDcs1e0hFSMuysG3XH2GB7Fd6Gj3/tuv2IDLJpb5f1hChJBLbXo0Ha+mm4kIVKuo2yoIwfpH0M0+/Rln2W8qB+EPEsV1Fh0lZQvRyJD+9Y8/Klb000lYAxJB3ffk+/sOYFPnw== 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=cagf9zJeboirD5IXT8Oxi5nXcheIlAClQs7qDhyam2foP7kse88MGGhYkihKsadaDToJsmW+bEWfkaCJ7DFTcCzSYIpur+1I1GuE0EQcn4i6/2Me59jbfYAEFyT8pFn86ZdPXUfxgaVOEV19u3el/ef8UUb7uCkvenbs+BBD+4jw/w2jc1FqL46F+6a3AjLFRB6i8zecXpiJSBk0Xx8P5+CIsbkNLR/WTxDNu2ks/0dXERWYqsHqw6X65w0/iX/W/0ytDTDfRGqncSCJgv8wx3bZb9hlYoydi79QyqPHx2W5UnWRrRotvHSSIIpYoru0FIfa4amnP79lSQZXHHU71A== 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=i3i/u5j73p+JWOUbMijylVqDbR8hQ4OSf+bI7d5O1PLAml6suLZfsIWGX5OmNs98jcWOV6YunybhpDlJVf9RgdxH/wxnMrHqhetOJCKiE9d/uW7Bc1CH6gCFpz6iYfCm78i84Pw5OAlVVusWKibHxwPCo8NTBce3W1xtDBZyS7dS1Zo+k3mq81wHA6ppPj2cPrDLWj7HwUd3I6UkJqxEvQjn8wd2xWqv7jeZW5egOGEAmyYyEGDE0vn2Q58Wa5Y+MCkSHS4Az5PtSEAamt+68M8aCTopE0JaiO6B67OIwF8PeTl7n49atgNIuV8MxYG2nfkYwZbLGaw6FxBKgQRS2g== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:40 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:40 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 03/19] iommu/arm-smmu-v3: Remove ARM_SMMU_DOMAIN_NESTED Date: Mon, 13 Nov 2023 13:53:10 -0400 Message-ID: <3-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0025.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::30) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ce20460-1857-42f0-24e9-08dbe4717112 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eG7FxzM5HyF1Ao8AKfJkycvjF463DZwjl4NE3W/DKxhBHQJt+w33SuX5YZ9lcF4NaK0p/H96b2ykV26KxVhCV7GSsnNp/kcJMjq+ZPcmGX6tmYzC+cbTRJ/8b3c52VB4VAd1JbUAMBFyVtKpHXmOUqVm9Dl/2c1yl1A1VIfUDwCnvsxrHctx0o0xFS32M1vtNu3yxJDeT+HqUXhG3XAx7suz2G4RV0wsY3/+BLDSniUGRaWdSkPRsQNDM2MER1QJkILCW3BQWfl+8AL7dWnpfbqL571G3/MKrzT0d8sJpPtZfkwF3e8xAK7lKNbwoc7+dZe7B3714d61kEuAfI6ogra2091mV5wf++N5GR5wVtYTMgPek0T8QOs6qpIsUIA8ladJSjPCUqMYUhEcqLA2C1iHlzvf3cINsb+TMyyg56Jvfwz436/jBd7bPfdLTETL6lQvgEPWssnsndLhacxx6AHlm6hHKLPTiru0W12jyiFGA2qmdIRMSAZYPW03pf/kTg2HQ3/g0QweOEibpn+UukMjnwMlc4/1FoBtV00LQsgoHNbPxT01tQJ3pexOHJIsPypmlfSHaaPjaNqaJqFtMWMal4hFnr2gH7gFmnUDgEQ= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8vawTEXTnPADDqVf2GaL++csuEjHYL5MV2adsCthAHr6s7HzEcdN4BeN4OVEFsc3/oUyy6jglOYAiHnIr9WcN6C5FnzbWzFsIb0CkgGL3jSmDxAh3G+lj3qxMuOmzbykRh8VFNP49Vrg0YL/SMuJW/LRGlw1EfQqjqdHmkXbSEN25rVMAugkHV2CICvJ/VTedGCZp6m0tynOUSMCwpO/1v5ngFI1Vv+NgTNFkDioyob7H1QyBMUjLyazc/itW6iLJ9a6yY70G78JavQzmjYNHsFemBFfu44Pgp8kgP4Sbcr7iX/Vmo6UU3avNQ7B7l6oA18JlVqxW9bLaChKoBo++TmqCEUEXgN6f9ecONceX8uri6w0Pr/UmFKSbpYpoHKmhbPu1pYSBjr/xIAFHHdpE/3LoKV5OSWFjCbr6s3TUkKCIBttWMLbvVpmQ4K05qxVIzbCpfC4VBP1oeihmsR0pZzt7WUYjL1Fy/vD3MKunsGbjqHRhgidvDSwsMLIpEHit7lqjHqWdn2aaChdgarIDvyjRjNAuF/2TeKRTg0QCLn7td3492WxTanVrb2phIOKUmTsge3lsSnVykehv/tZXwAQ7ixwYf0MplZnVaKFkB5YFuxGIqEnrClgWNtpxuJFt+48hBwK5nw7Hg8JcLxAWsSG9FbI3dguU3QEI6ZmZFet2y1ldL5E1tIPYTUF6lGPnlXOYfNAvPGxvCFzRWV2/0cTI9hiCShUtjpBHgYRt7isS5Sxugd6Ta4TMC1U695kS3MvMzNgPyTvyVV0l8Uexx+SSjxDG7ifAtr9DjkiTn0d/JzJzI0SGmcnxO9JbIZKqdHJG4WhtBbVBCpFjGmhEBmcmLJ7DXn7eqDVUJRvejj4mLfKPxjJR9TZaJbdjJWlmBjdGnmgVuWfamXvqtrYHpHCYUkxTmVWtU1xwRqN8htOFCjgSzcfnBJbieKGPq7f88WOtbVEyr4o+3duhGTQ45hjnuUfeRCoNpDoGnozCcvhKIVCZAwfMas4J71jV26Z9ICfK/XAMPNQuPp8IA95XSJ+WGWdGef/6ixz/YxIH+IYExkY+U2c4dlFA0Umc9rx0+2VsvXWySx8EdAqaBYQ1M9K6vrDM8jKDvcwG6gPbbXIciVnmA9OhZO7QCsK1XNQGd7+/Sxoe/KOouLveAQuOLDDfiIk3Yrma7LURSbGgpKR3/4wtHNi1W2cfS9Qv9d2F40IxJy7mR1bkPgp54PTt782JUzqfSLmqdurPedOKOPxgQYcjGnjgp4DIFz/2Ud8PdfHrPSMNKdsT0L49NkWtOnZDTtmpDY8cj9WFyn9YV2Fe1Lc/OE1ayeDZ37GHJrMiof+VwSPBC7hu0pTB3689fY5aIk2YEnTQc/rn0BbIgBLp+NB7GLHp5MIXbXv5pKfEwuHU+ih9xGPIj+JyATili/gLWiiWuzYJ+IVwVKLyLPFbAwO91FtR8aWdlmTclc2c4RVkNFAz/jv5Lq8zhDjpPypscJ6iJlUF3Cpy4SdI8s+2lBkoKRLmvcWxkCX1JSvpaCUVxu5awCD0y++ku0NaRzmn+SLenvFnv3Q6qs59x4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ce20460-1857-42f0-24e9-08dbe4717112 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:28.3733 (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: lnXXt4yKP2eo1P30Mlh8IGMpQhzGbMjkZ5Pd/EXEpaem/Mmjo237uAopdB+3TDtD X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095356_196755_E9D400E9 X-CRM114-Status: GOOD ( 11.05 ) 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 Reviewed-by: Moritz Fischer Reviewed-by: Eric Auger Reviewed-by: Nicolin Chen --- 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 Mon Nov 13 17:53: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: 13454293 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 38185C4332F for ; Mon, 13 Nov 2023 17:54:33 +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=J5ULLXKn0rt7vY9aui+bYLeTevmnGR+RaZGGX65/hPk=; b=swOJn2BW9hxReW SfJ0Hp8eNnjbG5JnPBfsDaMWLFcv3jjD9KW9o3BxMeWKw6DVfIEKy3+jhHs9+oRvzvXnUhYEs1rit c+VdfiGiWlDiGKNPd3lEGmFdcJO8CaUFRxjI3EMbePFusOh0+PQCrQbMRk/hAcuBfxXI+1djf9DvQ d9q9UKonAyqyWOQvH6Qcml/cQxJIkQwGHmnFwrvRhmmUPujon4VaQE9PMkWZKBFh5Py2iF6ghlWGk 755y8T4/+YudnEAnk5Hxexe8NTl9WsY1xkBXAPJDyq93Dt0e0NEea8Xu3fbw1gMvKRuV8C66nUTIi unhNpuomDgVPR8UEgVkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8K-00ERld-37; Mon, 13 Nov 2023 17:54:00 +0000 Received: from mail-mw2nam12on2060e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8A-00ERWJ-1G for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BaVLi4hQ+Y3lN/eH8skJ+ut/jjiLP8a+bNJ04Fx/8DCs17RuOVmhTnXAkcaopZotftDjT0zSzBTJVnR5do59dPgNtlv7U1mH1mKUscecrItQzka3mHmOU8in3yU+aW8vmMldEqLnoi82UjJnjhEF8im4e5Vuv9uigiyYwNU7MzC4Uo1eNP5Hv6FBZdP5aAgGAx9QKu4s0eXjhBOJ+mUxXp0p6HVXRx8U/Ufkim7VivrQINglx72yb2PSvwHky5OjAUoDMy1hePEV60tTBmkixoEx3MtvrwCo5yD6KCggiHISIrSiIwKrz4GmuMqGvv0Muq1EHjSx4D/rNBtTST06kA== 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=NOwAMQ/obnhGFvMT58apBOcxmS6qezpUCxgtrJspcSY=; b=WbRFxDKrmojRUUBQzWCdvyNUNqV1JpOzAAtiGibhc5DY3JTM3OAKqqPSa7qmOvy8WNK1AoKorB+SritWOzZKCdKQyhgNQxW5JAFKIwUsELGbGfrmrcF4qOpKqth5p5w/sXnnjp1d81uc2tpuhbcBPYlWO0JVZkffFEUuldQxHecUhmdDW2CCqf62YtunAJ7DlYCSKm1fdU+klJs4WeekziY/DjEW16q9+z36r075++7mW7bMp+zKSxPeC2d/L+lgI/bSO1LwC5sZjt0dJmKCJYewZC+HV2U4okcgQy5mdfm63nS+v0EhT4njBvBMx4f04jYO8jkAAColFl5BQ+PGQA== 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=NOwAMQ/obnhGFvMT58apBOcxmS6qezpUCxgtrJspcSY=; b=RHiZRAIrnf11sXlWGxO7KTN4BQ6L5NmaXsh6NQ7DPScayiyVKB1g7P/rlIX+EC1ADiEtX+NOuvD3RXDzSNGGEtOq7p5UmtbGBhdDvoUn9/gYSNCH+DgUpE4z4eiQkhhqbrAZ0YWX7oo42yBdE98LoSIvLONU4tJONyzz2CHeK/WNHsLI10UDDaken2N5tGnDWV4kZWICtfeX+ASWPCFwTGeMY/yjIhYb3bni3tpAkHNLqDvBdTXIxQub4jEeeB05AR9ACNu8UQmoiChEpmzQ+9riPV1P7tYS+T88SageJpEx7GpU/nYoBrO5yyEdvQRRmXpQjU/KTiH7gkRHiQ+xVA== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:33 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:33 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 04/19] iommu/arm-smmu-v3: Make STE programming independent of the callers Date: Mon, 13 Nov 2023 13:53:11 -0400 Message-ID: <4-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0039.prod.exchangelabs.com (2603:10b6:208:25::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: a802dc8b-8350-4071-b536-08dbe4717080 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pvk+iQvfR/E228uy0mOPLBAZBwP66TQb5CqhLlf5cVwHLrvzyrkyMtdPQzsLEMJG6n/KA4pi6BpKfxMhMTtNCG5eGfz7ndHLJ6/1bF/K97nMc6Bzxghhm90oqw9NDf0boAkS/B0a9z+Y9MmLluoUrLw9zpPjf1y0efg8ooAqP0qgZMUKhEX9f4nCsg8T1H12VPyF2ZG4U2hztZHXsPfuN9ZqZIundX6nk+P6C8nkBLS3agP+/ZHSCcVNdR7x635NzVTTtZNh8xlyve9LfiJcRQilKVSDGuMMbuBe4kCXefSPiS6B5lOX8QTeImeYgD0/aoyiRofaM4SfVRpeLhLgP3D5wsQ9WoPGml52B/IIrd8xH5vm6VA8TcYrWMIzEc2fEoFPM2pO6+tg98mFSZLx5pjZ5RFNO39xarU4NSIQSWbPTjYxgogd//CzO23fu14qn5aEUVP88I48aFG3+n7u69DzXdJ24cXpweWxoOPnfVpPKbr7uKICjPUpDgKCNdU9zWqSlksTz9vrckiOXpGMmV24bu0Bj/UVlsObOgPXyMpQ2cEfnpE1tKmuDL7+IGIIe1hqrnQEZbG+oqk9X78A1YAdhuBX/ax53nAGOmewoE8= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(30864003)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sjfEK5t0gOlpHjsH5jwAhXy06/qiD27WtyJvLpo6+OzD2FJAr0WBJE31jGaGvZ/WjOwf0cFymF4o55I0FC3kfcxZNtBjYvAR/1Jd6yMLAJiXA7UHyot2alJqPgsUKx9e/13xapuJjSKD1qJMIF4vBDnH382RTKKMfcnoPMEuWFDrySyELDnJvZZ8jhafRjym74trHhZBGnvoR8TBCqhrAAZgLny///ktU5zkDcBgtNuNjwdKYYChwAtdKf2C7kTZXY5Ah/Ee9hl0PdI4ZRbXc36VIkyWv5rPDU57PB9TgCAqgY+9VDjelSHaxK9APAXTgJ4oyl+/LitOA+fCzxtUjGCTjTCm/uDCxktmk6Y448UX07y+6qcEI7Hf7/rz79C6oCUFeUWKfNMAyRhYp8nTQx7aiXPmEGJ4atm03LpRqePu9d9AH3ORYN8Dp3a/eX42pNkO7gAq6jkhRjsCX+ZBS23mkNEW9eQCCt4jWUSqyN0bzxmmhC/6idFJsRc33KtQhQgiihf4c3pBcsJ03s2lNcWsJggVs3lMzqHL60npWRHBeg932xtRF30tpfB9OYz4BnKIvAHy8YhfwuIiq1QFwG3/hYY0ETmt+5tg2TAIPlwonkxZZgUWSOw0FkZ9UDO25OHvQ9vBC/WhlIHCa6wl8ppnveCndG5kqjay7pkG2udEIlTri53YOlDITs6JY9d/1eYBuOtJooJJWWUUTzlol2Nk6BAxA6wPMQzgTgxJjW/eblBakiZdkoPIUbPmHgurkzsVYjf5t7+0B4H/eVNbpRga2hzLxn1vN1TJA0pVv0qrQR0dRH9Okc5WZDDVWdywaPcL/sywJcOvwNiJNJ0+w03wwp4ZO/10k4oXkeaqxJKWncL7xigzLCHN7gSd5JZFZRjQg6KXfTzqSVppI1BhrYPnmEiPn6VOOvzqe2Qq9g2PV1edW/pZJaDzknatylRVM7gmQtv2/D8Wvja4YDffYxZjgWeFeqj6UEost4l+RpefyCkY/DKuqayVkyA/araGp2g1FydNYTLYt7pWlaeCjq/0hdW9c31FaevZxYTuw/eFfBV+YbbcAeprmU4vxtLXivfgONCKUDT86ABWblASnSAHT3G394YTuR97P1ntSTDNH2Vd9mGCvvXZrDShGJLXyIJW6xNBnOmtKGcTT20eGE5rYFXarPSAhMhYWRTpzMp4ISMiC90xEKMT4rzkEI2eJnWpax19dBQsicOe1Ng4DF35yRu8FprgoxkjDAgQv42NvL5/Lpvdlvdw+29tP1MKKzL7CbCqjsF2DpbiPqrhCkXz/SN0xMFG4MUOjaAh30Op11ls2ZWrEDbYY+Fg7omPjs81OVKZZ3uFcM6maHgiJB5FFlei7pBnlohqIsCMocgfmMZHPiZbLT2s5TxLU8q71bW+HAi4A7GT5gYcrBJxUV009NfeddYnLF36d1I4QtN62iJzA9gUCB4zytumcUOC/1cdq4z9bqdZaLCbeow2kDeET19rrWesuIjW/TzUR1xuaHi5w7VD9wkG540zZwNBUGe2ezpZDFbdvfL3/wxaYnvV5QDjKie2g7Q4TrxDXAw= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a802dc8b-8350-4071-b536-08dbe4717080 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.4316 (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: I9u5BcbOmevppoejKWsIdfVZ6aUdFuRKyPEvEs33lncvDO/6u9m9lJuZ75d4qiSx X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095350_433553_67926A20 X-CRM114-Status: GOOD ( 36.92 ) 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 Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 272 +++++++++++++++----- 1 file changed, 208 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..6430a8d89cb471 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,101 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } +/* + * This algorithm updates any STE/CD to any value without creating a situation + * where the HW can percieve a corrupted entry. HW is only required to have a 64 + * bit atomicity with stores from the CPU, while entries are many 64 bit values + * big. + * + * The algorithm works by evolving the entry toward the target in a series of + * steps. Each step synchronizes with the HW so that the HW can not see an entry + * torn across two steps. Upon each call cur/cur_used reflect the current + * synchronized value seen by the HW. + * + * During each step the HW can observe a torn entry that has any combination of + * the step's old/new 64 bit words. The algorithm objective is for the HW + * behavior to always be one of current behavior, V=0, or new behavior, during + * each step, and across all steps. + * + * At each step one of three actions is chosen to evolve cur to target: + * - Update all unused bits with their target values. + * This relies on the IGNORED behavior described in the specification + * - Update a single 64-bit value + * - Update all unused bits and set V=0 + * + * The last two actions will cause cur_used to change, which will then allow the + * first action on the next step. + * + * In the most general case we can make any update in three steps: + * - Disrupting the entry (V=0) + * - Fill now unused bits, all bits except V + * - Make valid (V=1), single 64 bit store + * + * However this disrupts the HW while it is happening. There are several + * interesting cases where a STE/CD 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. We can detect this by calculating how + * many 64 bit values need update after adjusting the unused bits and skip the + * V=0 process. + */ +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, len * 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 +1343,115 @@ 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; + + /* + * If S1 is enabled S1DSS is valid, see 13.5 Summary of + * attribute/permission configuration fields for the SHCFG behavior. + */ + if (FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(ent->data[0])) & 1 && + 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); + + 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); + break; + case STRTAB_STE_0_CFG_S2_TRANS: + used_bits->data[1] |= + cpu_to_le64(STRTAB_STE_1_EATS | STRTAB_STE_1_SHCFG); + 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)); + WARN_ON(true); + } +} + +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)); +} + +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 +1466,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 +1476,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 +1488,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 +1497,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 +1506,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 +1515,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 Mon Nov 13 17:53: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: 13454286 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 686E5C4332F for ; Mon, 13 Nov 2023 17:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yXvPklFVuryreJmIDm4rLkLXZpX3NeJLocV45hj8XTM=; b=lVdzwWF1AYd9wf tVuoxv6ek0cvERLEgtJF0v44Gqy9c64MePuHYTLSuc2KzceTOmxeISbl0pHojqMd9hmb89u6Zcfoe ihxHWIUdt75HQVQjuuwWkBOdpvIV6AJ1UjzzxAoymhnGwFfTk8MefsCtlKDGSdAGCIr5mMO7w2KIg Hs5CTG4qmzrRfJFcd+1eHrCFcWBwnWAhxhtaw67wRd+e7dRxx8+TvjhZyrlGodlBiNEwBxRMuvGde GK+ouVvIJLV6Si0/qvaZxjFtXAWSMD7kE3RTftpQB917SEJeXwilqhjKkl6RH8fWe2dhfaRwVagJa YxjueHLIaeHW8DyGvPzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8E-00EReL-2q; Mon, 13 Nov 2023 17:53:54 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b87-00ERTJ-2a for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YmLLTaaaqOpxcTia5CY92ql0LRMomOGXPNyJLC6hGsNtRifzNt1n2HF6Gvow5/jIXxyF/vLdLI4Y8+5ff4jnA9z+fRjTxKJVNuAKQZ75bllArpTsCFiL1Afx6Hj4SClTPW/wmgxKPUIC3GKb8TghBGHAfb60R/mQfu8llvDFLcEDBuUqqCls2wdPl0fCuS9SWrApbxRJDSmjD0XlsD4AMaM5nALTb2D5k0CNFdHUOGu5XLoqSABWIsFrptbha8Xcm+dn+5plKP5j5b3U7KFpWtYU3+2AZtDAnJ/2EZbjve+lEriJj97i5unW9N49QpC5P0K2qB9jV5QYM6bkOYaZ7Q== 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=ZWejoKw1p6HQH+Ya/3P/IhbDWW+iGk8Eqo6GvGPDlCo=; b=J2ztk/V3ERqqUUVC+g/C5awegrZr+St5wSF2451hVlWj4byv/pU/JJdffBVVOVW1gTtpg3Z+VVQ4N2ja0XwQYc5fdXfpFAvm7bBwKJtmh3aQudbUpCwyQMziySZVzfzzFiB9ogZtyH40H8T4YLUli9ujTDS4N2Dt5FFNOONDrDGSEhtSrK0wLxa4S++hXEycZwxuuasL3ibpK+IoUyjsZ+DugC/b5iO3Aa5qdXxJebdBy/r/2HC/YvrVqPcPhfmDaOssm5E8Zn1vfBw/8HE9hA4JVir2xXCjC7XXHHc/abcN/hnHMfIaOLFsz/bVZEUjbsJ1QvWl2cEbtNnQssG63A== 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=ZWejoKw1p6HQH+Ya/3P/IhbDWW+iGk8Eqo6GvGPDlCo=; b=dRi0QrsZzYJtLgC7arkym6pCoDSWZIaYDIX5OohqlKJw42xpw0BBqAZrFS+4tUlRxG/kXA+cCXKNimzobMtq6tu2Fu+b4/Hkvma1ZfEIKoEyl7o4gf5gFVKeANSGGXCIkyEyE5XCgi5P57z9hu2MoZyG9Tu8K5ZJpOlhJlkeMm0x+kxLkpGPZVGAlw32B7YBghyoRJaLczlJK5Tx9/8DwBL6i9GHflPxSkVJAMUifayxouqFLV4wFc66+qiYgNF7viB/wDr9x43RKr1AaR4DyFrIScMWbmoNh2ViNzCPcvsUCPZsLfzWFp4QTi9INcIwKWyxYrygZWpT+uJlBuwGqA== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:29 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 05/19] iommu/arm-smmu-v3: Consolidate the STE generation for abort/bypass Date: Mon, 13 Nov 2023 13:53:12 -0400 Message-ID: <5-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: e934b737-5682-4d37-060f-08dbe4717051 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bg6Z95qT+a3neEfL1uqs3nlWjbiBQF8u9HptHS4vQlmyPqaRjog+jUiFBwUwg5gLb97ZF4k2mVN2FldKRfxGH/UVaQMa3oDUuXDQV5pF70MK6L+qF7Td1pk9Gz1ORh+Sj9iYMGGx9ROFAGY3QAAcwvtLxGnNFwFdBk2wq9lgBGfLXr75UeYEJI9cLXdYPaDtu+FKoJMeoY75pygObLW2ijRJZm4boSNKvR6cQr1G9btnMcqhbxvHwYo8x0ma5vZs7Hrd/cwS+xHHuf8tOLC2kVQgW482ujQ5sNoU1Ii9IpMqPGRM9Y008n+tsio10A+nYlKcxflWQtpbXI8AI61bHwUcWgrM7MmmRg2uNXwL8U/tfZfdMWNcj1ek54fNzcp+GTQRjuYdFNI+FtNSrEducQ7q26AZ/6j+HXMkhBL8V4npnq8OkQDuBdmZmDCh38dsVy/xt10LKOEw3EZYVI3DazflIE/lW4qavu2751Z9eej05GvlqxEArOB1ezGBHC4drfydt8qIU6ZmCVjPWblHsQ9tbAbxNB2B+sMZDBB4Je3DmJh/tnChJApGquGszwelZzBlX5gwLOYauq+bVCvxvLBN6NGS5tGImflxlaYi/GU= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yiEOw5K/QeKN8Me6aaT37lIzxFbesK+cje4cVM/0mSoHEbH5scMN5zBvF3QXaA03iKah1V/5+COSO2tl75FQPvD7z3nPFI/gyO0O6M3IsY8xIKUtAR2izCM7GptcGYuPExrE/QJ7EhHmtkoHpL7YL0haZfsakd3BRv39MLf4B8xzP3coYZiURNTkNYdT+kttXbi9GV/odX9PX81gBDxr4emR+gF2+Mp4P8AKboZS+5AzHlXohM8fwYRIDAvYsx+US/E0hppDYemBdkaBORBCmrHvQVvJ3rnB2BEmTzSFXYffb3f58Hr6ckqnMTSkOFw9WLKkE3j2lohJ/nJIJvlwYIrfUa1mMPFXUlLoE3afYhoAzsCDyi2vK2MqK4Cab0K1ovNXjAhSPGaWFtcRlNGKO8Lac3YXsM5KiozIyyqc9VaPPhQpgbD76e5siYmykaRW607wTHFKAYT+DL2SGPC7gPLI6xUIW3K+7OEx5bJ0Clq2lvopnol2fQDYMgbZiw1LCBcLMVZ+t4u0yL/WZDGCIunPrSJF93H59AmUW0/B2tgP0An2RU5jpLGgmQLPAJuqgwcD7huEq8IZcYmoh16yk2db+SyObvLBHEbewizoDQhb9Yri0hem1doMGvyTeqp0aXref3AfWmIROvZf0vIXsfStpH35e4iz4uTVTR2gSCVK4P8oJNK50I9qRvtTy7TGC8J9dTQScjwrrH9WqPFNy0ATioiJQHUjjXeGdX5un/2gBNaK16Fb53G3KhAi3z/Sx4twZyAaq8tNUHEx35cySsdHE3btc9+qGvWZv57h4eZu0R+FCKs3SpgFzKR5r42WZbe6l7vVlscc+KzH7CfkrtOZZhFox8b2Ezzlu0k9RnMcnEkdM8fPDrdy91r51niadUSAG6/7r0v7XQyekgod0MmngdbmN8Iivi8TnLMgOQSZBUNdKZ32uJfZZy+m8mlgXkRMeqSQYnd48ydZw8oKFFano7rkhIEvrtJFNPfcVeDdLRbtXuFQJtqYNC49WyCvavgbtqwk4nqCp8W976RpjD2BtQXeg5cYcEvsYAvBBG+3VKt5T4NHmviUpvQYsYZRvXiRyxdwtzxGbeiguQ1i9IVmHP5ciDU+e6X/6w4Z/TkNuuAFbbx3ur1AiQGfJykNuLWDkcq/0Qy8pNZXryNEiXB9Fu/3wrn8DwUq7FElr7Bzt/dxFOhNivg2wGuWtHsjlu4/a4uKM4eT7YGZqMeI33mxpdZs9A542uS5S1nVm4uCvNvPntB5kcMOTOcwGiMlF16AuO0oBfNmWd8g7e8a2+Re3M+7N340y/iTj5VhMsV2J1qdsKQMeYFuvklBLT7HDja8nEpZwgm7peW8xWLDFT+2Bg0dA08dLGVSok8PYSZuOv/EqJehV/q1LDBQPuSWepIiu3t8RcfpaWbIcXdtkEkcQm1AdfNsQO8qbqAueT4KbVM6K+N65p+9JSfub1r8pMjfEAqKP+8cftINGrPHPicHqaj0SJn/keslMVby2OktXW/A6XiLI8vOmDckkkXTqqR+QojxW5QpQehokPwbB7GucDldyDLiEQ2ta9BvZKM= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e934b737-5682-4d37-060f-08dbe4717051 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.1237 (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: OJt5UltZz7MXx85CNvGLaLjopURSo9bgUqz0JGJUGjAG65lmmYSF80NV10eN9hD1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095347_842760_33309DDC X-CRM114-Status: GOOD ( 15.10 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 6430a8d89cb471..13cdb959ec8f58 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1443,6 +1443,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) { @@ -1453,37 +1471,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; @@ -1529,21 +1541,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++; } } @@ -1571,7 +1577,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; } @@ -3193,7 +3199,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; } @@ -3904,7 +3910,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; @@ -3917,8 +3922,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 Mon Nov 13 17:53: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: 13454289 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 488D8C4332F for ; Mon, 13 Nov 2023 17:54:27 +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=M5u7ENrK7GBw6JAv2ODwVRsFr5iPvWgI84zRMgKbF/4=; b=a2gnAUEsgLfOVP MLbeXveIndk5DlKfbKL/8xXHczAMQ92Hm0zS0Nxs20t0yfXeYy+xw2AiqfijtnzthuRdxTxahnPsU L4zWR0yBBmgMn54HtoILHngbDdxF0x2bCzeceJVRuQ8UhW+rCipaMkl397QHZC4v358L2GltziKxF Yw2sbTnfPiWegJV9EcItbWQdNXWNXIOyqUl2jakpoNsJrRcQ32OPdDv+ALcio93y30eFTaeI5NzMx aZS7LzumhAmBtbB4ywGWGutgK8gPxWXPJuR3BfxjktkTu3ZRMgKzgfNR0kneSo6upiVgekYtXLDuC FlgB2gX27IhuG0lg6qFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8J-00ERjo-2K; Mon, 13 Nov 2023 17:53:59 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8B-00ERTJ-0e for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jRh6sUKDiYsx0RMvMkC8egva//HSgnfmK/iMbljasXuqqoE5P2KDD5rLCVlP7ly+U1wWXlcQoDMRlkAB5x5fUD8dXKTbxgtNixjql1uf3xjWFyoVXjlTFYF/CRSE0l1N9gflzCRiUFp4oTOhrDFb+f1dT5hoGM1fTBJlVlscXTh6Mfy5nwEokwgYeFGPnMYnqHGKJSVkabnHeZYm/KF9Io9KXOY3cVpRPiFDvZ7yoNAeuL/l65Hwf7EOFwEpPlPiECFa46EQj7oGqlaxkdu27HSJOJ2y8B3C3m4JxC+ILGs4zZUFvJlvV3c8mJNZkMZ2/bimKjyrynZjqoYkHOxoeQ== 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=prwwyrtPCiGbh1YrTs6eCpDe+5Nx0UTpVHTy4GQOPS4=; b=AoqX1KK/eY0rFOo4oCar8AKzGp3ksfh1Mm9zrnwUnPY9EWIhUyn6ghBcH/ON8311H21mN16sCDxqbhR0ecz/5plMzT4u7vq+O2DdUu/9vIevdir60E0V4UTOhYSgB1BjA+GzhZIgRaHzIH+nmUZ6VCDPEMWjBAmE1WSHduGsiH1IK/FsFXSNKwU8PIiMhUYZZTGgQpehHIHKxr5lNrBHH+oqgaEpZtpcbLNH1lDDRUWUsZAE6osV1YHv/5PHymXH5itvPdR/3zXVD0UjzEf30wD6hyqbRHS9qVRRnSvQaPxl5/Y41kgzfQzrjWIhsS9P2mb6S2GDXPzlTFGRWaTpLQ== 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=prwwyrtPCiGbh1YrTs6eCpDe+5Nx0UTpVHTy4GQOPS4=; b=crK/1hkjsHqgxCneDiFv7sbT5ZEdnnnc9Qa5zy4aZtQ1CCl1jUeUo0G5CZj+EyIvKeP9w/RcvvxEE5fSjVoL4FBw8aYeUulehnZAYbaZGaRyANzwQeSQ1wnSjz5z+yYIEjm7o2SBmc21WX/4PVe2DUoGCt+yh1QKksprMlR2lhNX0snjbKyrui0quubKgsSJhK4oGPt2yVbP5IhKqVOLs5qkFERaLnhRur4j3nYZzohSW7zTKO8XLRZbQ/hHAeIjEIdiKNDsZGI3+QuAlBsR/QvkjTRUC6ZDr5wQ26T4ou056rmoCxEMQD56WlXrtPKa+2L2uedREe7RUt5BGrv2/A== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:34 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:34 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 06/19] iommu/arm-smmu-v3: Move arm_smmu_rmr_install_bypass_ste() Date: Mon, 13 Nov 2023 13:53:13 -0400 Message-ID: <6-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR12CA0026.namprd12.prod.outlook.com (2603:10b6:208:a8::39) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: d4a83163-aec5-490c-a10f-08dbe471708c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XmPorNmPRKrsKGcsWyYtKqBSUmUvGASP9WcyEk7cRYrZfSVt2hFqCDBfxAMGaYnP49aVmxu1b6Y5fuQWNCE+IAW3C0nY4/3D8fidYKBH7/kgHzuDjqn/aBCllc+io6TayztF3k8BFlSSX4ImCYV4Vrb9lSjOkGOvJpbWs1qCMS+Gg8DzVka9BZyzQusMmMdsG/8wVCCy45ZPg2SnbwBN4ZUwGbN0rcL15tiY8DkwVZ9inITrtGbsjtXxYWGY259wnHF6Wg26n/FRcLwTbsjfzQbUf7bFRRPEXckp941BaNQjLOfkV81ikPtUOZ/yGAi/h4Y+FPxHblRphjiqQkOYEOOsK1BnGTVJLRfQ8NgDH1wjWilVlRUn9Xy6RVAXJpx/UAo26NPLg8UGJLzsKHmhKsLit1C5INRiNb/iHJDeSh4nmzKrN7+RvUCIMHQ0VUw1iVtLF0mbXqLHkC+fBn0AkvZoFMKQcVRsnOv5EqrOGjqNlOdX5kiNk8SZpKUukWMCBnOHB8xFdm+nNqM/ykObRBeiFZL57BOxdVb7NpFtzyBk7n488qdojdJE4cufUAAP6hKw7JiCExQnLO69jSDuS8VLzbyb31+S7jYzOGizMTQ= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WaAyYin1Wj6yIT4Vhqfza+siJvUNG8VN3aCsQV992qAisNBlRTyRX6EJjatKvMv2lap4z0vna6iNY+nmm/euYDIASqtgCBTEz8YGH6w//dkmLbIs/gDRUJC3OI5573Xr8Q/+CHsx8dz8IMCEDEOrRwolpoyLijCMjiJKZgCX3KPsYY7R/4wKNqk9TnEkvwdjJE3ibdP+DEAr1710J36+w6jcu0oR1zN4mLXS9Njb09Yu/6kO5EPAfOhQegkohX1Z0dr2KTGYdONT4SwfIT4nTh9z+zjeocLZcF42MGOolVDX0ICDlYUyRk9cIZkY4Djlndnxg8hH2B86k1MHLM1KnJht1ljCNjbFtKwOCOQqlUvW4XHXqEkNHVO03lnihMiPDajE7hUgAo2aaiG3m4Z8ZGcSsqvRn/351EQdHOQJGxcOHYIYlkYQ5z/F6yHdRRl0J5/DjyBz9rSGqbghBRZzznjMxgwau7GkHz07veyQA0lKcsUBu6V/EwWJGY0GgbP3shS47rJSc7q6Qum8qEONIBt+uW6ETyDf6KxB6T/NyfFDVLj8PrZbccn7dtlkJ0ouxEnNBr3MunKb7HOy9z+nmz3Rmqu5u+tedWPGdkhK75ICd/MB5Ofo850B6inErdMK7qPWw9bAzoZoaoG9dZYjYOKXbE6uRfTQeNHBFTQyRt2oZanYAyxW7rY9ipGxGqAn9Ag/ema+5xKYiRq4b18hQSD2KGW0Y5jWSYTM+c+l/kiT5mCAmPyP8slT1lA56NZhr0dDF2nytRD+nw7Ztw0AoKmA3sC0o8ggZiIbuVpe0VmR+xE01oo7Ges/RTzQHMDF+msho1nqY+20Ni2WjPAXHWO2uh+AVKxXY+/NBId1/rQ84GYmQ3JN0qvurwf3Yy14v6PYQCwfyV7FRm7REGw9XSlY9zyM/9umrwi7dpEUbxcLwbdkXyw6GFFIigMZE43H1ElQzXEJeC0tc2P7n730tGjKw//txIsnyO6L9xMOXSDxnXq7PO4l2JIbP8sXCk8w1lRWEpgCOyXw8T9VfRBvf6ZSjz+ZRNzHcAhNWMsdeKQbV9v532RNMJpx3ZPi+SHpuTRVFaRxNsiol4qA0CMlUIvl8AXqX8PqlSSUOME7BHKIDEJT6g9Ds+a53trTTY7jSSWvhv4YCBZe5FAGmyz+ccdOfaA9/W6gx+Q/1E/SJKUoVs+YbItVtKXTEA6wCb+ceaysEa6Q3oN4tExDTQiNaG3HsLykV1qHWaP2AJ0CtJeGQvyzCCcyvpk9q8/uTNGI+4YzwLMaBjtETsMS1btrZmLkqkWnQ/rVbMb7u9vuodJCc2qWVYqWGDwZZWOoOa2dKYvb5fwiFojw/ySzN1U+aJvPL6nCjYRKkjHf9frUos9hknvoKk6x8WwrFS0s162ktgDYRtpudgTTGvNYPXzaoJz4ewFodtNVWIKgmDiOQ4011qaD9tN0A+YxkmiHLO56ka+dOIqHTMEFZY3yXgazDSyx/Rfyv4EKjdmvSi950drT35MkLAzibZduyVWnI22PtdF2vxaBsplu1uirGOFL7A61Hle6A5M6tdLoIVC6FFs= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4a83163-aec5-490c-a10f-08dbe471708c X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.5021 (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: R3K/GOk46r1dVioBIjST9TJVM3i4Hac6rDBBLi4SpbuZ+ivPEcsZW8m2CGbzfwLr X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095351_251908_0B271D7E X-CRM114-Status: GOOD ( 12.43 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 13cdb959ec8f58..3fc8787db2dbc1 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; @@ -3200,6 +3202,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; } @@ -4013,9 +4018,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 Mon Nov 13 17:53: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: 13454345 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 D335FC4167D for ; Mon, 13 Nov 2023 19:00:50 +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=T7e1oi5SeLZee4jX4tjjht48IRiL9NsXBGKaEgxwtfI=; b=TQIDiEMre1i9Pe PFazHUNyhu20Ug9T5lJhE5tzTk39hCalfN7JtBjS0fm0IJJskTa4tE5AzprnJCsIHMPz1rsokF4z7 egrwP8+iM5xCTji03k1csHbi1feuB7JKLf96RyHJ3UNcjof7ZNeDn56nA2aYSldcL4x5EYmg5YzyK daHeGGGidUNlAy/Pj9OI5EV0OteGo7rX8FB5plr17RjfIwDLiqiXx2XwkrleTycjjdhb6xS3FtENG /TbKvIAwLVebXJEStztzQkJ/E9seFpgIjjuYyWgH+qTllvo+Lecv/nhTEC/EdMmst7sNZFGMJsQ+S ty11pLH+4np4h6F2VPWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2cAZ-00EWzz-0m; Mon, 13 Nov 2023 19:00:23 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8D-00ERSw-07 for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vugz7C0DWupwX3zPrMFrNinUuAqWBRsrSbqAKzZnm+p+VGb2lzOdXcNSsXcvEcCcWW3a8xUwMtHNo1B58XA9m0OuOvoyX+xOXT2rYW8LWZVg0eTT+lG8d9yyyT5AoxY9AYcEe6ktuZzrbZw4tubhV0goOrOQKOZEgAnBVr2ANv4AAW8autPy4iAe1R52CZNOUC9fg6X4x8kzlTeSwPd7bK+sGtmLbJLO0AGRMQE0kGK/K5YMFzYTMXTd6E98BlIJdvlsU/fAeB+fqOA2T7InQVCBiINf0yj+i5tUzvfThgDEQCG1yMgTdRjZKHLkm3SQdiJT62RsS4RRjrbnwzAnjQ== 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=BT+4fsyq+r3SxiC10JxAaf4gfCLeb13RDm8agkTquH8=; b=Xel9JSIAyLLbEuv7P9JR5E3QFlmhhkxB8UWDRy/FBG7jxAkDXdXJgg8Gr/vGdNQpCe5xtUDcAMBgBFHEK3O0zxEinl6ohHQVLJ4oopkIqdQgwWoVJOLEwyY9mNaVRCVwRBDpl8Ica85B9QuvInnm4zuB5eYbaqv8PmP5JB4Qezt/rQorsIpHAuEOH7u+5fnqj64jI2vhdsYWHV/uVTBF4cB3FVC43uoYP9HeTQgZkKXJfB4CFa2mmqUJG2vdziTmggfI+MtW/fnEJlAk4BrBhNlS+dzy15T8XE6pyJMN+jvhPxxHntVc8aOhRgrZQqX+25FmeOaor7nmnFf72DK3tw== 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=BT+4fsyq+r3SxiC10JxAaf4gfCLeb13RDm8agkTquH8=; b=Xx3WpqJBBDTZE8iCWaTftssf6nOXWtcswrXFtAB5uXKK1Lm1kOs0S5KGC9ccTN53JYCL7y1OrKbTMGDj+TnSpm/xsOwsuuWksiWtTqaBvK4DB+YeUKtUytmpMJv7DhSoz34tb0MH+bSTd/dU73opt/C3RrFixqSptigTgUgYZ/JdIXNAr7TooYl9flatQAHBk0gQblMK8v31I8jaoGTk5DCO+wN2xu1SM0S+sTjO7CC8/AoDlEn/1pzLVhmlzG2OS8hPeJCt/14UfT2SvBI1RDEVrcEYUrilZ/gtdBzQFIcMcPTokbLJcuJ0xQ6z3h92+GMAeIXvnWGIGPEBqg2uvw== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:37 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:37 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 07/19] iommu/arm-smmu-v3: Move the STE generation for S1 and S2 domains into functions Date: Mon, 13 Nov 2023 13:53:14 -0400 Message-ID: <7-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0026.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fc85848-baf9-47fe-3bce-08dbe47170c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2TE/HdGEYg4DTqKajRFFjpOhyphd5V/d/EYXm7f4EWy++dzBjEg/dHeRUZhyANtMf/Qw+087zucNj2bWbsot4rX9cjAr7xcoIxv8mXQbqVjTWa2dotBzsjuLA6UGgRv88AIWMfY287ulgN2I1asD8owlSCngg4yQCSF9BqY/fiQp+MXYtRVcBk0uyPtEKmEUHysZv0XiCRu9aKNYt3nBdsa3FRpk41HXSmKDslu9dw26rwQK24vZ21JOa9sKzoVjwj6ElVtHeFU9qQVD4QBYQnXfsdr4a56fg+oDLh5lsHO+hmoorc+mwdE9b7/8RAU0DYhrhT3H5n4scH+B29njD+k0K1+wrd+X1109iuuIhJrsldk7aZnSIw5qQJAbi6cpRCRQirYZ8oce6Da0bz0fLds2DEama+/xUKAJqoLG3O2RfXrJr6YVNJLXUvzvHu7AVfHt7IhukasGOhLLYWkcmtTqcOBiRVmYGuGkCsuRMKo58DQQV2fGVzv++9IRj8RDip8CsP1ASJF6/a2lUY0e4mltP0CDdmLFVuqJFSPKRuiJfogYfZX7Gj0vYvadIGnBB//YxMf1G4jdofadob+JYo35YGtpKA1e+Wz4NtbxwTTRD7tV6vXJEtAu0xZSJW/KUen7GohIZ8tDwo2xRYmdyA== 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iNSxWFQMWj+eHOpckW4TuaqweOMegEpbrhZBBtSzu8meJPj/kYI5JKS9bjI3QXdUKjZoZTSQIrm1eBjupu6faeqzb09qUX4CTp66q9b7HZGRNqwjW4EzDMejw6yPCLwd1z4s+ceqJPK/HGp/3z5+r/7KUwV2cOf5aT82DMhlwlG0VZ4rhQ47lvSdMLdTqibgM4oBYMNPeIHVMSljC18aSgqa4byk8oy0YUDrQbvgxYCsUYzebqqY5J1xGSpQu2aqSKPZ599FGUiOio4X+wwGbtkCf2ZNZkh9mK1WJwNCUnt/dL7x0WmgvpZ6C+r1VC68ZP73qTeOncVwqzF48Zu19ny2ucmIBIyi3o03MRJMS++1qgILey/V+TREuAOXtBqwDkfGpFzPYiqlV3pbsG7/YzxOdQzj+MpPhiTB0bdldgUzAGslmoxlkLF+wfjV+qaPuLlMQ8tBN1M6M7cR9BWg15AO1cOuYUYyuMHoM/kJs3CkxD/f0gDUIhdQM2JQkNA2sU7uGT7GECxpUl0Ogx3Xuc3LjNkgqjFLF+CjgFW9atUuRGDx7SrR1Pgx0bo4X4kkKioYav3X1keEVWOt7QnOQd/LzS6pHNHjPpYzw/ScVUmS7hz2F7NfvuUIndd/LH4tPMTfZ1sMuqvboER4txNVwoGy3FGk/zTvgBRCC85ezs4m3q5XdJnRcfuAQuAngPLSMAMfzRCs2G51tbnqDuAmd0oBsnty1I6IQfmp1JK+hYD2ib+HKtAicwJWY1L0Z4o57Kphn4jKdpdc8T8LeKcGP7dJ7RzwvwyTDbNMc82zl77GLeD2nWECwbAZ00+EJOoV7/PZcxoLxTQAlMyAJ5lDpdwCzm703Ep88NsK6Y/7SnmgsBddOCbc1ZUaRLPwuMO2PLxji5PEQJDH0bEdD41GH29RwGnTexLMEwfERJ3qgd1aWldjt7yJjmN0jfEs1EyvPmmeRHZ+EiFlfFZBqL3TIi46Y/D8jNyUqggyViXMeY2tvkp+qMnOjLKxgv7dVfvVuXOJCjPO8kr5HDN052NBs0Dg22VqtMVoQRMIOB82D1b0yTm1Iaj7zYiqasPk0H3jk/AoDRfcb9iE/RwWQSmL1UtyoVqnWR0ywzbqaH672DXr2nbo8eCXUOGCRi8CtJRjkBx5mWOa6teSUAaVWFh6/usU6P6SNsqTJ7lP1+Xl3if3556TPdWyWyQtAqzj0lNe8YGmuRvt9DVQr0NxMtsXGzRjwfCeGdbwUvV8VlPLDhf+wXK8QmcdfSM04qOTZ+CQYd7Ax5n0t3ooAt/WTuUgasV8xQxWCKPJr7HwTuNi7lyxBaqSRWUHJD3xLlEsMsWJmLObX8puKm00lU9Wlmh2XCdQNAagYPH+dN4BHxOSJtPyZB10vap+iR6Os0TeQvMCBD//mVmvOYridqv01qun5xa7Xxuq63CigDdNwLWRq4fFj9AxbWQPEEY23fQ80LpS0KIQRv1AA58A0lzDnWN5nSWmGmY3Tard8If0qYD+hoIL5YdphA0rKNr3hCsfm+g5JNIiu6a76I1KgO0yJXGWRJZ1XWWXV9UV7lHEy0Ym1Gk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fc85848-baf9-47fe-3bce-08dbe47170c8 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.8463 (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: Nuw+LE5D7iRtDqrvQOO2gNY92B+bsLFnSLqgCFpKkR+qpn5jm6DKrkwKMArwhdC7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095353_095895_E70C4D17 X-CRM114-Status: GOOD ( 11.63 ) 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 preparation 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 Reviewed-by: Moritz Fischer Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 3fc8787db2dbc1..1c63fdebbda9d4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1463,13 +1463,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 = {}; @@ -1484,61 +1541,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 Mon Nov 13 17:53: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: 13454285 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 B4E5FC4167D for ; Mon, 13 Nov 2023 17:54:15 +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=/SJFpNsgGsxpKGqnrq/CMLHFW16tJtZOmnlm3XuXMKg=; b=H7AqrkzCxcD+1E YZe1NIuDtQy0d+8d0ABd2Ewu8JxjCUI06ZpZx1aBReeVMfbCgqxJeOCyIE3tVabfZ6qc5GuN/B41Z 0UHrbeYK3JYtJ4mSq4vnZezq2r7AllzxkUZEDGW31XAptLJlS+lTGUa9xldJLCB7gLHSC432Zo7ev Qhxa7nWlKSQFx3C8SdEADbl0K1o121Aiu3TmjQxPxTY2pWUMBPLvV6I3SzZ67kqoMSBTAqVDjQDWv Rl16xq+vLwnQB673r3pQ/OmnQX2RO3KqRy24OBt5XSQfkrvdSvK5qCn68iBVbNwv064JLEURCNLHn +/lzfjbeVEND3Nd7l2Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b87-00ERXe-03; Mon, 13 Nov 2023 17:53:47 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b82-00ERSw-0n for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=apq1fZpyYwyxkbhCV/wPCmEEIsqom7/ly3whRiKiuH8wxDyRpo5jGy6n9rZpxZc5pL0httcsz1fPi0qefD3TEOqMYoAjTlCvSY+CpyCmYx3ZmvMe+ddvMGaazWCHlRfxcgaJapQuwEd0RXm10RwAm2Uo5Di+2eWQo8NncX6O9113jbJ8jk6sbr7jdkDmNAQjgSyZQP0oLl47G6ITmWn9aOFI0JQB3Oi5jLkxZvtCnigVPf4w1fOdyxrE66BXZAzXVmM445faCFyZ8H1uJc+RqqtPlblOM/thPzPiKxz9tg/ZKo8TzTibINuu2fgWkS+eyjMVMkKrk3v8Vjn91enXYA== 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=jGQZ9TMf+mGq1oB43wsmPd91JFOBNphecT2cQecvK6o=; b=Rm77UM8O0GBx8K09nx/s+PRV4TyJo71L27uHkrqXJQKiDRDcQN3EFDDx20BKX8s/KyzixjCopBSAhoQQagJ6BkBCl6y+p7tP5wTfAGFDQf8WkdRk8t4x6A34GDKJmlfdMT9CI7L3zpkHfe57z0QGG9ONJopJYHjwTYS1O0FWbSiYWdsFlEtlGYp+lTsZAUatYL0U8aZiZk8eJYWs+IVtJ84bL2/mZZEYYsxzZgg9JntkEiNSCdR3JW6+fN3oKJ2vnABtMMUqD8zQjY4U15X2rN2zEgTtq0c94VJTpcFrERb/JB2F1f5A9bmSgDbbWKpCdimBHfl23641w/xRa5JIPg== 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=jGQZ9TMf+mGq1oB43wsmPd91JFOBNphecT2cQecvK6o=; b=Pjp4APJl9Gamx8sZso6sIvECku05TIDDzoEw+0rgxCL3xl5qFzzZ2iZ90hoTgjhcnsgi8guObLES76W5VEPtq/7EMfLA2hDSpVLJhXWQuAXzwJk27IMZLJT3wgUTGWYeG3nXKWFaDyCKAg8od61p+bn8B+5mnOMj9niKIdOL54TzQO65g/YqKYOIRZWwRZv+tLI5RNRvu5JE6qJ9XuE8qkAzH8BAVekiYJN4hrd7AKEkBqEo/KqaKsxu1SbWmVh6Abgq+unuqJ1ybD/BH8qoKalbbMPkwtB3nAAd6wER34+gwlSWn+j+U+F4XoX83vQAjUmeQaYD/IyFoPKSJiWhSQ== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:28 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 08/19] iommu/arm-smmu-v3: Build the whole STE in arm_smmu_make_s2_domain_ste() Date: Mon, 13 Nov 2023 13:53:15 -0400 Message-ID: <8-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR12CA0035.namprd12.prod.outlook.com (2603:10b6:208:a8::48) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 449c196a-7f44-44f9-b7dc-08dbe4717042 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ztbxOcYpbjACcoWQnsMbJ2CiIPrEJT+82fTKVrVkiq6mpy35mJRzVJfyWHf1+y/KUNKnanSRxLe8fO7U/yNQxIFVQY3psTovRSg1WKGUIzUgjoJcuzpB6ylJpZd+P4etlqgD9SG1u5WdOb15BnAKyefCxrWZgUMCNwM9rhsUzry2ER7Qyn7ZXTIdiBSY+45HEYLzQ18tlb84xPVdjQVxNrq4TxoCUV0icS+YRHHDpkeVTQKvSSrASyKyX0dPYIMMLK0nPKwrqblvBle1pUg6L6W78ArsyecXWCDOvsUo+LZraHRSQZ57fgMnJiMDnLCtN3UVwfaYnbM/rUlfDE87E1y9JETo8FD267TbJ6h8iwF1RMAKLQ86NFLux+gf+AFlFlN7mYUQ666Of1wvDoE75IH8YIxjFnL+Kbwzbi31D5KsOYFN0E1roNe/CeViJNGYW6McFw1uj1AhE5ZQZPlQPrB+Q4jqN3E2W64guTKnO9N5JxManhA973K5u+FdQaS2M2FEpIIwZXHUTX71Z53A9VKaybmuq8wkU2CIcLAsZquvlEXoEsKZGvPiY4OI0bGW4oCNmAUn1RMg5rWyOSdoHC/1t0dxYsXDmMpAr3Qg0SI= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +rcD/srPhHb+jRTqNLnF342kbZes350hiEfIz6n5TH5T99ic7rlO4BTurmgrtgD/cGgvTm0jiiF6CL8STHYG67ysPGQNRuXpplZY2innOoowIeQSB6+HY/V/Zx+j4D8rmFY/IQ9bMBAbmq3DyEjPnL+jYAtXqu5zNiaZMlo4dh9msILvagzPbK3fh9lJKOkrwzOkzeas07rY1Mv8MxNboV5kO/96ZNSHG9sFoFIDzGnDFgd/iZfS/XetJPTIiMONKyQEPAHD41F8QTc2rsIcHaadwIj1CKpKnwOmsUulp5gWox2aa3sLV54Wo616WbQU8scjBidEn5F/Y+XTkkhgzhEHW64NIoiViDp2fIN4dGxRazXCIipcy0dCcm4xnWVg2zgMBzXGLnMYh3IBvMUFLo2+V8uhG7mMCnx3odjuMkV3qGjanf9tggJkJXDbZD6p95by6CuXBZHJ/4b3ooa7uLhT31WTdaHyCCHPa42Y3Kg/vJ/HwtV0HEroqE+X82I8qly3+rtGoDZYUkmcrj/+hlcIfWr8TBZnTk2qxPk/A4pBJ76wuNMtCNk9j6E8uFw1fQzDJXQzIF+x6EmeqVyDNVJ4D6Tq2E4O6XM26MLUEslpFs+TNW76Vf391l1PBPU5XhDxS0G3uWSo5gLwjmp/iJfEKsrCZlOaK6Wv/BL3pTbfkdn7i3vnJB+h0MxJs8We5QFLdDyzpF3aiE1QExRLNb9uVaaojqsjRglAxIkiyDIjHzMAczOx/YmAwGe6+RBpiwI4Dek175gC+D/k15HHSMOlz4VombO6gVZzpDgMKvLJSxhRSXUtTEGWczGBGlGf6T7RB3yO5GdO+3GceZSmRo4WbgK8artMvulsLHBSV+ADq2dUlY0oYo3E7pZZCkdIb/q+hFLxBdUuShcFdsf32Z6keB9ZcMue96vMGta/OIbpGAopZIV0S41AV3z3OtsyDG9qZfBj4I+2qnxXMLptkZrUTFvkS2qSgxKMBnt7iGwQhnPWP2NtwU7svfQpP7LXsZF8Sqnbqh2kUttIkS+jbdiXeL+sy1plBrwQzBIc4ywGRw23S5AHBKKfG0QUo1axhVoVvdDJlj5k1qIpOumVB45iZYeURDNdY0sr4AtgMDnAbE2qnkrt5msqblEtfG7QcwHFiMRkTgI7DeyDIyJHG/Znhwn5A3Usjr8SvhVI0jCh4pCs7yHP6LKblJK+lYNxNbKrF1GPxDjHZMwtRPwoTqliekcw442mvwrJXMLdzWBhw0jaI1IUSoiC1QlsBXHkxllMEcAZHeJGQPwYGtvi/CtOY9Di8q3ks1gXhpSaR4w2+YikUSwTeVjixuYiPpKqd095jQG/hdWP/MBk57XZVZm7kXz5x/hSpSFVDLxCsq9582Cz7GSDF4T3J+otC8mId7cdPv74TLCvPr7hZgWiXaCzbG7O8OmEaX4PmCLptBsS/GjvR+XP7R2m8cdzanm+FyG4OFR19c86CtthEPw4ZmlBUO7xX3j2BtvL6HBMoP6dtOLVKlJEWLqotY4GyN53zD3OzqFzbPFqzHT0vr9/9XRsW2uetoUXOC7qK9h9mcw= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 449c196a-7f44-44f9-b7dc-08dbe4717042 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:26.9930 (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: WuoxEcAm3LqyJmWNKwJ2oOAFpKHtxEwNwQpUdw0xGQdJ8mZ7tSxsEGUsPOIosx8z X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095342_288508_FD0EDF87 X-CRM114-Status: GOOD ( 11.18 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 1c63fdebbda9d4..e80373885d8b19 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1499,6 +1499,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)); @@ -1510,9 +1515,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 | @@ -1520,7 +1532,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, @@ -2277,7 +2290,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, @@ -2285,16 +2297,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 Mon Nov 13 17:53: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: 13454284 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 8265EC4332F for ; Mon, 13 Nov 2023 17:54:14 +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=9JySAj1LvI4N69SjHpMZaAZYCigoo4tOvmm8xjvWPec=; b=eo8Ii5NWHQzwJX Gc+H5tfUegaIRZlv53LLMQTRqLsmvgia4D8+n7Ah0YaApzXmlcI0y3gmcAliAI+GKrpc3O6xkad13 pHaZBAJk47hAec3frZnuKpVJZ5kLeXCDwfXJTYdNxTXhawFo52oAUXlQ4x2nQpC+Qpp3IlNmPwB3E TpXuJYSHG/xUFRNGtz3jWBPQtD2wSFM7Vlup1uw7ncs2e/ppNxH0YY7iY2uegUE0tqOAkQ6zu/lPs m9PPc4Aqq8EoJkfI0hEH2+v2B/NjlylJDtZM1MKGxn3gk2dmtHyMLdyQCrfdYQ635THjOZPX7lcB/ +hqaOb+Gcg/T3PWnIPew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b85-00ERWg-2C; Mon, 13 Nov 2023 17:53:45 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b80-00ERSw-1u for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=krNi04o5xa8GuMZwFq+QedfATE+E9q+scZrVHJBLGB5N+pDUeYqo+U1SOWqqrpFrqon5xrxhf7RNKMQHlz3WZNXfkUbLYck0KsT8I7kJBCn/i/yLH4jGSnOyeldad3+7zryBWKtLmU5f++PFhUg/l3zB1CcoFYs/NAWf7g67HhuUT53zShYgGyAjtMSX+QsaldTUlcy3Iot5TkB/PY9vJf/jhqqf1YswgjhUtWzkCVQZNAMduM04cbneTHOxrkkkjt+VnzWWZsDruL5EV+4JeJxYOUPuwEv8n7DvF+PIsN0nLrSWSgfmmS6ErZnF2/lAI4NX71Unl3a+73kqf7e9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=msCFeLRLBv5w2Px3ZlSsPPf7JK2Lcc/l/EOrRt7eBwU=; b=PiG6mnb8rGrjf5EVwloF3cEbBhmKH4k91Vb2k9hPF6WPa4MeVX6FHi/lubN71Ri6nc4+0efVukN8Aa1O4wd2XXNUb3Nyeiwc/HOtG8v7EOe4xUKyO3mMyS4yc4J3/vDH8TyLQwM4WujkRtYEmmdg226AEmzMmqHzlZrrs6yGjGXQsQbXWXwbUrNOcKRTT9FS+AwE8cmld5WnDi1bf81k5ZbYLY/mVUaPABhf6FnP9bMXSBLNTgI1UyM0TdNX6Z6g6TdvO/CBbRhQw9EXB2jUHh6Rwg3TdUIXYfhTiX0IHOWr0ZWKtELFDStfr3Bra8dsdK3CM6JBF/K1/sulUKhaSg== 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=msCFeLRLBv5w2Px3ZlSsPPf7JK2Lcc/l/EOrRt7eBwU=; b=q7PZdzXlG7OZsp7kynRO7zaUc2V19aLLiEellbSuV9V9yJPrBe2C7qYqcUTmb9R4nqsMS6WCztXYAVTldemO2NHdpwIvuHlFTd3m5vVcw1t2EJlR+sAPgGv2jZ+X9OPhDoR4yRDWtLiYHI7AXhQcpIwoevFCvkfBwu1wBkBl7XNZY1e49bOEnRo3NOWdxpuri9EHQLcsA+iEnSYRxVzLyy9TcZS3kF7v0VIPlV2USgqGT0oWkfDu+3fXSwRXyhlhZdzYjStMiRMv6zd17vb99PZuFTufpdC9XBURAqIYAyiUa0cYIa17XVi79fXSFlxbOBcWQv8MOC4lVtQ9Loi5KA== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:27 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 09/19] iommu/arm-smmu-v3: Hold arm_smmu_asid_lock during all of attach_dev Date: Mon, 13 Nov 2023 13:53:16 -0400 Message-ID: <9-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0328.namprd13.prod.outlook.com (2603:10b6:208:2c1::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 87216ab0-d498-47ca-a50a-08dbe471702f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7IZ0hfS58eANb2WzYbtsxcVSGB2/TMXMX5c6rjhKIW3wAeSsKsEXv4bncdwTyl5jwRYEIvggPMo0PJ0FMg8vl2XxU4AKeYMRl2zAWD/+OfOlGzwBjcz2Km7bQQycem73/7A2Skrld5JFhSpUMnA7bIKJa7c442A5zlQhNvqIqeVA6EpvANH3g6p7muTRMnLOwRLH4Dr7dwh3DxkZZjB3VPVSqJZ3F6zq/NBnDKJKLjmjNbotKyBsXOK1ZRW7Z/sZCV28iw3NbxSMGLP0YykstSnzdCQBhC1x7UJzybOaoRn1C36gKkjct9SXJ//StDiI1fZFumYHatZ/rQpnYLaFn8EnK6x5+sqcb0A/QhDy7NFOV4bcYzp14ZVM1eAG+7gSCd7FwX6mFRqMzzfkO7xIFLGpiHHm8i1M0p4BF/pR6te8C22wyX0pMtW4d51AcCcatcvW1CRZGcz/TuDnRmonj8OkX7Ukiq/tPSufX9nEI6QWWY2g0Q7XYYHGktHTLl8LH/eZ0Xz0Qc3Aw3axBBWvt8rLMfc2dqoVyevr7SRjRPeChhRADoz7kEKbh8+V5+ImLTiilRfEQXvqdKI6DkDnR0zJuHO8I9qJiTijBPpMbEw= 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Nl0hkPIk+M/wZOwckWAnMwdSk+luwCsf1p9v9fk3It+jIWnv12iz8Zzqta1BcL5I2noDjcNT6ySwrOsorDtHy9CEvHisWpf+PEzuUvHkvPBeyhNZVBw6nrh7YnsN3L8zkobqP9xPVb0l6qpTwZBTNxXP4bzQvw6bqenFrmqf/EAz9YnJoyuBmFsiC96za5AYqjbAu1t5NRUI2Gz7u52Md4SPcGVA+BewsMbKLdE/yuYz6pSl0VRlTHsfkh45fRYu0F7dfPIH6RRIJY0OfipEyLL4aKBOJN3VoIMTG0dkXCs5D6Z9taXLGrwMxgiENoU0RuG6qWfwyBC84fc8hVHfCduJlvDxT93Dc4JXGW7KYH1Y3hePMGCGLvPC3r1wQPoQcs6Ca6YAp7K7aRU0pXOVPhEgNJr1b1y9aS67YmrrX4QM0n0wQ4pVb5tWFnArq+c37f8/NEHp20qNH6CxY+dsJ98puobjpfrZqDflsCbz1E8K6UI0dGvewv/fB1kApey5d/Wbik9kT8LHQNGGctZSNSHknYnxeRghXT94H9AHAT/z3FOwxd2/8jwyffRIP4QJH9RzooahlEVZIUHhZJlW622P2N00etrfdANMXdetboZfgoA22CLPBdvlRYRRXWKMn6roKyjcuHcLxdG9OONKPJXlFhcE9R6Rm0Ncsdmb/7/qDQbvXzcl/YMNmyxq9J7sb0tbGlaq8Dmg1uc7/Z5k41hkXkDjzgz3ES+5OWLxrOBXW/E/+RuFru+oYErOWC7RZx5Kc0zGJ+i/hR7c7paropaRo7RsAbek3ruL/fIWFmzeEHRyHW2ZoDSb33Sfd3Lcpmivgl0IgNTT0ANvjQxG373gwv0Cz+1wOJoSAt2FU0mbSQdTKPz4WQgnW71IuWymoP0ZQwBO9JbO3Bu+JG365i6wPOWpSeVK8/yZKCsAX7K9S4ldTu9l3sT+hvY8fbokA26VNz+EAw92VGEQJXLNTLbVuH5AWuCkq8BFMn60FiaNeF25i3YxaI4ZvKCA4e/PAqGaaMqIR/CpSX31TzSJhimQfTyzPsdLULZmUHasPUyc4cD61sO6En53+P/AWmQ9TQp5KU+M56oabH1klx+lqDA6u1HyOx6LvHG5VYoedxRQFedQodAnEpZwaxQccNI99ZP/+1my2yQpMy0JaEQDnvYCwePAnHeNMgohcVIwi9fgwON1dtT/EBuZ8gGqU5E9WabX0idIgnzrBzg6ig5BaXjYEXpp1203E9RN+ysYbjh31mUxshNOKge6g0kuJol4kxOjJ95/EYbaNbqIYcyUUy/zKsCIu4qA24QF1F5FlPQgsQGocbZCg8XkEVoalprLRjJLwTMnXHUAnXTiE8ITSpBls+XuYkqLjA5MdM2R0EHNzbOlIjP4vgXU0LAJE2QJUOT+cZwJenE8VBK16DBcJ4xxAoWCfaTUAMrxlTIFhkfRThAJ33u8Nmc8w5IN6i+F+MUI0QbXrZZ9dUYl/gTgb3ovmLpEpxiOVBO5d4Amc2FwjmzR05eRbkBi0zZqIKZStXf/14QJQMZx4rqv6iPOQZXaxDiwEc0w2/D2cgdodaU= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87216ab0-d498-47ca-a50a-08dbe471702f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:26.8553 (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: LeLVLKfZxjOUQ+lt2T6+NlRTp5KtI5vIxr5Uie/BnuLrOoY0v7XCtklEb7koXjm8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095340_631853_5E2BDC8E X-CRM114-Status: GOOD ( 19.40 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 ++++++++++++--------- 1 file changed, 13 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 e80373885d8b19..b11dc03ee16880 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2560,8 +2560,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) { @@ -2576,6 +2574,16 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) if (ret) return ret; + /* + * 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; /* @@ -2601,13 +2609,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; @@ -2617,13 +2619,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 Mon Nov 13 17:53: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: 13454298 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 CE871C4167D for ; Mon, 13 Nov 2023 17:54:57 +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=1TihdRxDWU8Vd6/vrGMKxh16UL2q6oJWikwBr6Csrv4=; b=N5PF1t4GRNYvI8 Y+P5wzD0RSdzaOZPd8yR51uXVY8JeC5mV4hjeBf7d/TmUNqKCtZhZJ3UznR/jm9fvmDY1r8Fu7LEI Q8qmx24Ei3MYx7UDPhlH5hA2362kvzGlvDwrpsMUq63cbbnJAZ1q/kyzVwJ+H1t341yZnGfrhqZUR Vu21oEx+BguKPRqG9iGpceZgnh3EG+AIMnspbSYm0n8kzCxJGGeD5CVgYTL7rt4pPoaK45beRfFwr TbeDHYiwexW+kSmr/EmSX0neezAlCFEcdqCBTD/VV7euVQ2+iuLtmA1/uLOa7WtmgoXTRt8ibzNJ7 oypHJtLkGehUfnaCJg6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8p-00ESB0-1s; Mon, 13 Nov 2023 17:54:31 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8G-00ERTJ-2z for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CC3nf9m4u9hvUFNSNmBo5SC+stZS3r8WOM+ljF4/svjkMHiE5WlwTxr4lC6E+KJP8YMdaq63UykwXQlE3z/k83f8YZF6xXWZAOkFKVdDEgvDdgNSEaXNdsnsJaL9Ry8os2OM8YneTeEYFTSOUGsFaLC5L6JCpXIk9IafrcahUL78W06P8nfzmDdAgDJokUkiqtx0MutwGGF77aNOBYfhF8iXhT2J9+JsooTaX+M6CL7B7hPWHVW6T28poHHZ2LLA5cksc+SGtPR3TsNyMzeRhYjfHmDzkCAvEcbgBqdPdMGmPbfDAWIH+TAveZ2IogRCjbZNehCJ7hOVi7FDf4oatA== 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=jXEVyEMnVfxM+DkCSA6TyysfgPKOnBkWVf3smOTXNAE=; b=Yb3PkH35JIWVySGpHfsuh6lji+zmjovj/T5D58ZT/foJpbkef/bmnFeobWBcetSmryGErTg9Lyjr9zQsVfoKETf4EGXy098sW8aAsiBZ6vLNNriwvIi4VB9kM6HPmlCuajce9WMxWBRvzoKueK7eAmTj+6OIuN9B/Rcd/tt98fvUTVb+y1y9vFFsQRUl4GWCMTqNBsf/EbNqN3k2WmG9h94qG86DAUdfJHfSxtDAcNJrbufj0V5guJUXhq/7JNUdvh+K4iDG/IUUv8/kGS8VyrrctrytpNAbNrqrRnoNTdVmuBpp03e0MHj0FLQJ5MPP0UXumB5QjJbmDDLy3oOpEw== 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=jXEVyEMnVfxM+DkCSA6TyysfgPKOnBkWVf3smOTXNAE=; b=biVtUFFmkASj52XHJ8yBKk0gtbsng1HqnJsUmwv3Snvo+Ffp1k1bSKLyaeZ2lNNSlAwEUtp3q3c/6ajm06Vmn8DU2ch/bqtuvzm3DAmgU9J/d6d7jOLerRHpWH1V42YanVzWZiUXGimKu8BJNiOvurDmRPfYbjNsUyJpmlnPzKMUFQvGjqlvSIl0PxFe3f0bl709ahvRDcGn9eenX56NqUiZfUj09OXDVxqKn9cmELt4Er2CL5kdK+sXmpBbMJKucvgxatanHf+x6dp9cYaWhvXKb5/lQdUaFC6o3ugyouUacDrYKcMhJKfNUjLodnd6o4NJvL6htfAK1yYYWLqs2w== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:42 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:41 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 10/19] iommu/arm-smmu-v3: Compute the STE only once for each master Date: Mon, 13 Nov 2023 13:53:17 -0400 Message-ID: <10-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0004.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e7effd7-752d-48c3-5cb5-08dbe471716a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mc29dv/mi7lgIiUGxBNwhXSad4bpOhEH9b5ASdy+mv2b+36D4P8QnM4GCkwSFe5pdNeFOPQ+GBYPTDyaeWxWt0GIkNjDU/IBhUhZxE9o53nHyHouJfU1ZEkmwsoz3QKZW4pKSWunsBc6pTyFPRDmCfkBADdJTWcjtzqdkWjApCnocBMreu5jcEQlx9RhzMGpKx1UyWspGeL0jX7atO8vWzEYpd01woO+A7mUNQ0Ckezya2uYpzX7CPs7dYcl80Sz1uDpc6th9AIGshhDVx+Y7yLUD5fpFx229idko8BbkbKSezyHqxiSXZUnLmk2o7NoiIJt37PQ07f/1P9aTd4mBjpHBI8Hf1bFzxwGz9Z3i7hdo1zYFJWA2prDYVb06ZGlCNKHRsmTXb8u9wD/yRzuzeTXItl3nQiHeL0l1NcawgIy3AsbtNzeHJb1JfMYTlb19/1dmhAHXeYrIuySCtM7AWTCcHVm5oELEaDWMNl6PPLVIqTyCb1vKnfYr8L1L9Oi2tb9bvPr6sikfUUOu9tsErvFaMbABj9Khx/Yg/e+6n3R1oJMeCYfRun8/bl5U3K4 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nnp0hhaTCRn4oWlGkxUzX9FxDGT+thhZABLQ53VR5aI/w0e+sta8uC5sW9Dug0w+4u1p37UYNJMi7E4TUJndHhGqCc1/QD6U3YJN8UySyJK/73QMzmfP8y6DtxDK5XFu6P4ADAVhbyepFeExihAzY14ygjrKWaa/wS2nLRxbO+65uB4erpP0T4yIk+hOcagmzRYqUrdvMYxE7J3fYQLvr6inWUcblqBxwwAvKeIWNIOeki1NoNhh+Hyc7dfEGR32XsHF+uuLd7AKVe2RxOIu/CPypN156DmyHPznnnN/B+nk4k8VYVj1rz9a8IPPoB2PP8ci2B8sU8duumCkD7Ci1O/WqFA29puy9ZHOIDW+a662oaflcv1mWU1MvUJoUBVTgZaVrhnyLhtRaESnb0mOC/noMCv/iSdFHTQOvl7YUJ5unYnrd0BsW3dJyAXqSfYESTMLt0719qpGu70eKBq6aH42iEwjNgRUfXIlpNOPOeFW82HGfYk6rkYsaZySXPbYcKC3OHoyKVFo13P8zSISxxaeotvzUTr9pNMCfhv1RY5CGqDL/jQ0sxHC0JnSB3ojqE1jMPjBRrYcIMWXOGclltYbLBuh2hxUaU30AipMtLm280f6K+bAoMVLjFz7SZ0hznFsbZ0BS+frv/XXe7nhpTrvNvyI+vcqzc46WCM8f3eWOKzXtOKzDRpvij2pBYCxZ/AGt5HC/ZuwGHRlhFsPHDu8dZmM+vq6PvGgz3rrDsK42MxS1/6tbmkOdxTQRtnK05uEYbBRwG0o3rKe//VLH6xTCuAc2QG+XlVp6hGkvHTTcp459rQcZNA5e3wBzrN5HASEUUbQY6C3/B7mgAtsKt8Z7SVXmTyRe0HJv00GzPT4Xhykf3EQ5zFvENOOKX+Dzj4XZpPpd/Rlsu4dcoWEUQVgnRCEfVqU6kN9D56nonL9h4LcsQABNKVFdqorh5L+xCxXQA0hB8zsLhIjRrEK1y4BYgOKJ7QZWyIRlHKcffqWc/TMXwxFvoxPeWPMgBtvxYtBH5n7JOcvBB5gh4rABc5GFl2uKSkjMz486TvPB9wpeipBtKKc2+hLcrrUiMvjZzj4vd9JOhyCspIRgJBHpHxiMgDnJMCmIizGTIcBhVh5RsDDwOiqS3H8SZGU502ef59q8vereumWGbIdV+F+zxpRTg3EBf+bbe/amCfcqr3a3J7zgYZg7BwyheY77D1UfnilhQB77KRwoT5tCGk4kRNCJY6OPgMJBlGcSw+ZVw0vDVjIZ3CKmH67vRi2ogDS0F7U9fHwQk8+W3xOl+zZFvYLCQ5fjW2RzZtcwz3v4ir5i/+glpHTv+fEayfSyybPr321n67ZK9wtw0sqXXz1Sazpb3qqP5lCdiNmfter7qn5igme1BPikWktyb9lEeJmbg/PA48rrHbG9S7WFgYxcDOykv5XgHGOESJ/sbpxgrwfvA3Pg876RJz+0fKIsKOjlPLp1eJVJp47/yWbzEMgizqQIFQ3go2F6dTmigMQInjf/UDPH8WEul0VUWthWGMYcWR/JOpYZeK4LtlqXyYuVjR5SENq9wXft+2OKZsQVIE= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e7effd7-752d-48c3-5cb5-08dbe471716a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:28.9291 (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: c1blB0JoHkFRaW5M9DdZ82N5jr7sTlvjMEcnsc6Q4wzkjW2w891lU+g+5+1OXQqH X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095357_017418_F11901A0 X-CRM114-Status: GOOD ( 16.61 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 b11dc03ee16880..4b157c2ddf9a80 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1536,36 +1536,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) { @@ -2387,7 +2357,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; @@ -2404,7 +2375,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); } } @@ -2511,6 +2482,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) @@ -2524,7 +2496,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 @@ -2539,6 +2515,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); @@ -2600,7 +2577,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) { @@ -2614,9 +2592,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 Mon Nov 13 17:53: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: 13454287 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 5DD33C4167D for ; Mon, 13 Nov 2023 17:54:24 +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=XVFTnRJq9brnQpo2qcm1o472gdjJmZzG/l+/Ic9LmHY=; b=sNvSlvoNYO1apt aKhJL7djJkkGOksYW9gtbsIapYAsNjvtq5aUmWrqbfbgFQQ6nuU0FspAMhL6nYn5Xo8w8hgtxpMAz iM2ApV1BqtpqEZ2Zs4LpA9OMYUrvlSMdfyDVMfRwnKPP33gCqVvsaeGrl6PMFdnwF1QutJ3es83u9 ywthCZL5R73Jv11lOf4sE+0TBfLTOZtsXtqayZ8XDkNLe4Worr8HecOmhQC/yMFIco98p30KlPIKv dURjIHeUo+lQSbFYsByohGAm7D8DrEOtaGNnZrLk6ys2EthorjRnLeEKODmLlyPLQgTox2//rdGnq fjGNjQf6Hk8tfnDlmZQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8E-00ERde-0H; Mon, 13 Nov 2023 17:53:54 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b87-00ERSw-2q for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oo3WwPZbVE84vr1+k8i2CKT9gcRcH9lIJ5JyCwrfgKlcn7VsEv9bvNm/j+MO4EyGsSjHtg3dJTkNKwlBUYg4aD1ZxhJTM+sCqf4NkTwPjw7VAzYeb495Xj3wUhDoYTx+JLlQKMHB7ktxjV5rZbVKt0KIk9dSdwRHddfgF1gEz9lvstegKN1/prStMIO9cJSomIY9293QqRGu2r7PTThuY5qWsRx9R/EtQLJnsTHVLag5xg4QW1Qc1lZW/PRn36Jqutxl85QWu8hpUkx7Qn0YVlV1RsX9lYgq2W7KcNdogPeKdko1IAQg1i6Ap+NHegFeasUtlkveJtavARWQvA6BPA== 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=In/5NjVOIp7IsZ0dOG0i0Y7zCa6RMB+4XqLdi87zf2E=; b=cBkWPkES1oTFR3Zw/aPLn3KI74ksPug4+y6Cm70YVRe/CrcmeEznuNohUMXWU+52sVkJiBwu43Vaz0BIgREGFcD0YBE0TSc9PTzHkbx5ziBOexGpXtaJrYG0TBkLxVSwPceVA4oc9tGbKkzenF+Ggc6Li4bCuGV8b+EXxFL8iL/E5zLcZ7Q5MrM3EaSw+9L79V1byNBn3HECkDhXGE4rX/UxWviNmfAujmmDbRpDXMpVPlwakZzPPEB5rNhEeuUhJLFVTIvXtlsITKypMutlrtZ3Li5VRlNO/ExNB99ly4VK0VeFBi+KySble4R5BYGIdvsFwduuYn8uNqMW7PHHCQ== 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=In/5NjVOIp7IsZ0dOG0i0Y7zCa6RMB+4XqLdi87zf2E=; b=LD+AcO6ExRW+G5sR+DJcgSZ+xGy+3RtgUBxEGTUOeHdIg22Weutjd2IR5+jyYPnxM7UeBE72IGblhd3UlNx8hmzOKH0aMfAmlFUCmopYL8RVc+n05fjXFBNK8ZJKf6zcJgft0QrJeeMgnW9Hkk3BkrI0uij6AW95rYPxfOloIus9deJkFqpPCaCrSRXS7qXqiEV9FI/qq1NQ+SaUXHliL7kpbjqDiL0pCv2Nb2xGxb3GfxdJQfMuAu2iE4PiGme3IoP+7Lf/r9Qz5nCfKLFfkd+neVOgm3dmUAA3QISkCBRPFYV3arZikm1kDCPtvbhk8Aq7x5nK6lo2PB9FldGUdg== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 11/19] iommu/arm-smmu-v3: Do not change the STE twice during arm_smmu_attach_dev() Date: Mon, 13 Nov 2023 13:53:18 -0400 Message-ID: <11-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0309.namprd13.prod.outlook.com (2603:10b6:208:2c1::14) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 75dce906-9076-4cbd-8f9c-08dbe471705a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XBDn/b2BalLWFmQCC9Yw4ZprvAaLu+otuSmDWn3vIIdiKMdJif/N5U5PFbF/whHCZ8goG2aegbC0iiOWKWJ5ZlT5MRg3LFtRCl8SXieTqE79bc6+PYBIQfhxid4HnQJFjhvdcEcu+5W9zbN6cz23Ln9UehoU5elO1m1FnFepJQwX5CfhGsqXJjKr4ASE7N0bBVaei6OrijYXuF2rVAIzP+E59PugSgBOi8Na26/zPpoyrv7V6usC7rP6vjJ0TIn7pdhQTy8IEYMxG6RVDBtefsYR+kD9p4hlpVdWtoS+0A6BOqR2HYQKLFj8OBI/YcMEZve5zGxIbd4hprk2xOU23aJtpMWoSJJbg7/ncG26WEhPkal2Ei78Vo4fdf+5KJu46VtJE3Cy1MmdKmokR6fO92+CSlH9emIZq2uVWDCih+vZMbiasQ/O0tcRe+NQ0gxdyeeE2tOIps2q8nmEic/oQ1pLMCmbRM/TrKaQyu+sChXy5bdorY+WYCc06FLBml9H8J+C29UKAAXnNhTMR2ea7NHXawLdrOEtm9ZP+3njzkleKJxH7dLzIKn8jqdT2ihI 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1ghmGQ6JL1HXWJf3Bk/MeupyetxU6vVESvW/5wn7w2vy1gD8ZDRitfyTEGbQvTt6e0TditAbNjgSZ51xTIDGoVj7+8WG+6Ut+CnQ42o8d0UNkRa/QydjU9NxbXjhLE+Lk4/StOGJ6OzhZFnf5ovhx+4QTMWzXYf5suheLLhuEgFfAteK41PvhEDWEn+aISPZm+Q6+cK78gxn98QxKEGckKNtTjqF7Dg2Sqp/zzUaT22P4zzsUqyXn4q13pDSA2sEnCv1vYzxZRYtVrPyyhlEalV7IwkqkgU71RTCLpqeazjfo1v4YWBIFs0L6O8+0mv16r0OcZ7HFygyWJ+xVOCxvf4nGHIYIvnCSxjIIjmfmQavgeHb6HcbQflWVwa/MjvgjJsQd/fZy8+xWCBp57XKJjQyFOUea5R20fIkwZ11BlT8sKmRlEki7HyjUjy1s+eHtALCaeUkWe2u6/N0rqyizwocmFqBjeedS42vzIcBRwXEARk/p7LkQ5IMUAypWbwr/DbuUwnxB+DzNOm+30sBQohwrk7DGIgRBQVOEtaBHsQcyw7Z/4r0HdoVZyOkOt7WYcNJBYPDw34SvVuz3J+7yZGXAWMJrWkpsZ+fWhM5G29HwiUWZSfyexI15AinUA9M+2+FOPsjHQSC2nsegFUNB8vcHp2AmMywStXlKaVBmoUU4qpAIvHXV78x1enjuph0cW4azUmA6r5yBLHV2s840FTv1ykzKZZQJL4vBSyUz5zMK2N+0Jy26tbtvlHCkdP4DyAFY1K1IcQXFwHl9DZUsOGJlUDP/j2oF5yuCrJ2xT7KrbceRoClMRNBUnqiibVPgVqLwP0HeYdvQp1JcpLVpBOMjVKyBeureCl8e4omMdo9l1v5/7IxO2iGifvR1312ZztzS34U9pTiJXX142/d/IJcDZ0E60bMPWgvemohX33vjYxDkq3WrYGYSq2GW8dQecZjlGs91xyPU2Antx9QGF/ohFChpoLxJuF61ZbPw1Vv6orEJ6ZsCEhsbO6EeE0d+yPwNJXdFhKHIhixd7KO4kYnUIO6H//lXlccxQrp+WwqU8N3Z/aPyHF+gYJdw1nKDUcLe9+a/moCqYKSFeIu10Zg9jQ8lUoebSdsyRlwJzss18Hb6h4JY518A8RpYaPzTQp8sqOlmUqFX29pES398Stq43DtGth8Z0AIwnp0mZCjPNvymhfVsF6ik0DcioD75XOW616vg3L99nXw0mlgDYCfgp/FcMddJjS+EDJQG8Mzjy484/1tb6FQ2hODsTKy3Qk5gAzWI8c6BxAEoTalwu+BBaFuPoJNwV4MkJfJXhLJ/XRMQEKlMrh7IvYZNLaVaH7G2ODtET/Mpu8d4LDCe7oJDwffm30nKDRYDooSTlLtBMKZRw188v0eAEedRqeeZTc6iywEqmcN4tASYKsEHhrfwL4ZDr5ltUIjFuXAG0jwhqKISLEqoTfbv8B+sidC4mpfDLehDoBEmlsSHrdHDsrwIbtXBIPggqHLtBYAf4v2PIRjt1XPZjmtxEGgXfTLhuQgwSMG7sVtIuMQ5J6U5vS6c1BP/fMLPpkVINU8yvs= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75dce906-9076-4cbd-8f9c-08dbe471705a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.1726 (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: ++UOrAGm5c1H1H9ydJNurcayPIwVoMX2A4jqaX2JOojkl5BCCERFZs8wM+PAu7pD X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095347_924662_79AA63CE X-CRM114-Status: GOOD ( 16.69 ) 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 Reviewed-by: Nicolin Chen --- 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 4b157c2ddf9a80..f70862806211de 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2482,7 +2482,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) @@ -2496,11 +2495,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 @@ -2852,9 +2846,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 Mon Nov 13 17:53: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: 13454290 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 08A09C4167D for ; Mon, 13 Nov 2023 17:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: 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=HrVIHSnlz1fZaz7YLGawuNebeoP28trj+SxBi7Kvf5o=; b=VCE0rpZkhuYPD/ dUN+oR0qVA9xelzj/uHfVc3sFetNW+YNuWAFyVXTIFuZoinoo4iNuKdzSBPuV410GqP7P6dZOU+Gn Ufs9izIE7krYWDZ/jYFY1Nfj2JpR9h6YQ//CeHyE6rDAV1w+NAQe2/yA3Nfgf8ususRoFPHH30jiT 8VG14/qQXhh3+6esp0TjhYD+7B2uDJsVn3Vni4NB1bu+opF/MMklX6bvTS0MgWC0gfAJ5P7ti4JgQ FZdP/yX2iEUdJvNPjhEKrDF1quhJLegGhm5cP+hIYhvCU7FlHcW/dBlfkoBEOTL5eHQ3NS8+ntKPJ xhMqiasBptv4t63v/t1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8M-00ERn8-1b; Mon, 13 Nov 2023 17:54:02 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8B-00ERSw-0r for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RtvzN7f49BRsqo5OvHTxHk/CRCHhN4PwNFLSQH0sYE9U/6jmP9rO+Y+CtRcThTT0Dxt1J26pq9Q5o0QmwSovkHx43svsn1wcM0Xc61tzHqlHlX+FAua4pqkqga8RfhBwroBqZEoNjgfv1YEWptolzaq3Pf2NMy3WIWhcDhdAs20KL+VtkpGRketpmnfcFJKouGkalz9feR6p8KEhhy6tVzb1Y+EkaJ2eCtU/MQeuyP/EAeII5hWToZAHBZ7i1k+mci5scdyYh5Ezgr2NUv1V+S80dmt7qT89N0gcjLlo/QGbmPqNzPyv4zmp0S5Ew5VTFnnV1Aom3b+xlk9mpv/sxQ== 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=IXnrxEy7vdF+85YUthoq5173eShwWI/058M3/DeKxZ4=; b=btgLVsnP1yPrgD2EaeLMsMUBUoU5FGi0PTYP9AeEXDY89R+iMKK8gb1lOQevVuoOKIanD1ZOd+3jmIR8J+NUVnJ045zkhoMAdwLOnI9ZYkRCGpknn3wBgHtEFW0gs+UMVhPiWhGWkRJ5Lv7qQFrt7H6nETAB/hccWV077S3mj+gc/R/huFuUceWnlophHAubCLeGqHTrYX6iaJ22JdTA1SDaeagufOaAqWp3m8b3fCTtxqkhMBx13pj8adn3F+OENv8BrDWC06lNBQJ0ISTwuaw7BfA4v6HOfCW7p/Hz55vnA7xdHQHwEKc5BemH7rAnkPoPkkk+kBAndfOSwhuQkA== 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=IXnrxEy7vdF+85YUthoq5173eShwWI/058M3/DeKxZ4=; b=Biggas1Rb7VrLjYvXul1kuEpXU5Z78qdo2MHfhxEAIlpOaMeWicZMMQh84IHP6f5k46wKVLqdETyTDrdVAluAY7ePxTkLB37Pn1g30+CNURLAYH8gY3JUuJkk5cd9I7rILxTuSIOKQF4ikdutQJuHOIv8dgpazoCGzttVR0HEZgoUUpu8frkhtD1Usm8UUHGopTsK/sTkEL0VsXqgHxTPnDLr1PGVMZRrXzRZ4Zi+62kOiHxwOBbEToJSIJo3I7ho15sffuZKFE8Or3jxqyw0XnQ72D/2AFXyqmdzVsVlZ2owLoWFUZrUXdR2Iimt6UaHcDSrZC/CTr8CL9MguJasw== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:35 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:35 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 12/19] iommu/arm-smmu-v3: Put writing the context descriptor in the right order Date: Mon, 13 Nov 2023 13:53:19 -0400 Message-ID: <12-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0314.namprd13.prod.outlook.com (2603:10b6:208:2c1::19) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f79a6bc-ef6c-40c6-9f94-08dbe47170ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 28/84WQYA8cj7ioM+uJ0f40aIqbIbh3oGW4272axXMuobNBlY1vjSNYN5E+FxlQzMHKcC8t/42d6Y2HQoL9KkgDL+m/KuceoihGWT1PezhOnU+ZAMLk9W/qGMJVfc3tSxVeM7m0c0OLI/GybuA/PLaMHYv47cFTmpv9ExuFIaGZlBdFZD9nZUbs/G0AW/tGwfVl/M0QeT65zD3NIsm2EGES69eKXHN6D7hW6R8QZmJBF6NLjS2HUiM4EexcfKid9mH9fSkRGNawpizZaSwiDV73oqaEerOeRjYSt3LpFPpcMRBKHWUWbNMpht8ZnvTZXySdyzTwQiYA/ftfiCMjj8J3oUbZB761/4I/Pgp2OlR9qPSV0tdtG/plmvqVgXyR9V9R3Oqtb6bZ43ARLy0Axvw2SQtTIwsIb8iTrpRHqBv2yxiUWPGfcxc6GjZy+vWyguQJT1ZBpaLaIPqS8CMT13yokoUA6pG//9RlFFnF1igaxxiXQqdksWNIegzslCC/3vX0ryXCOunvVqwDrGqdBYZj2hz+vf9Sp1OXYUdLvmFeBx4hIhZ/W6P5x47P2aZ63 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(66899024)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d5d8E5gfPpwOCDkrDeUG06U/NC2X7pOuzp5wo+jUjIGHoZHXxu7jsfqXhaaf/vZkAvZ5WlgI7htoVjCq2ih4RgAyAumYd8LKgTPVjvoKm0oXh+6AYYzgOsncJem/5wxVjx2TZsdL5durG9ldqrU/2AhgtoIWWLn97nZpC317XtX7Lilx2Lsz+vTfMh/dwgLAKEQK+zBh2JfEUUKq8uRFutPGcX5OzPB37Wm+MXEGbACt9A7L2Umk/TrZrTwBh3X9OAoVkejM7s0SlaM/RZ9XBFmw4/mjsLGlz0aUVylcJ4IKjU99mf/AWrGMJA5kQTYRPYCay7b3rEloaQl6nJhmfhY83v+inQG0KDX6SU9qFM+UmjvPsUA+c72OdInhL3FsB0sRff3lZkZq1Vb98zt9ulGH9J5IEcD9nJh1YQyocddPzGLB6wKsddOrlpA8Q4KEthYavpbC90sXx7FkoCbyKNZVVX1OvyD0ho5misD3RXcQ4HB1K2Q4fD+8blU3oxcheT+fYCdkYtqHvT4XcMpA1XuK7SP7O3rj5TzJCaEzCugc/BuBO+Y1an6kR3tWLOAPrP+TJiHMKV6Kj3RT7FKO9ayteVbaJbF9U0FnOeEvQm4BMSXqU2xsD2jTei7ZJRx6P5dKYZ8B1qmKgObGarAOodzbY+Ddg3OkcIKAfU5hiZSfO1oR6JqtBJrPqTw3VKzyW/dpxI7r1MAGsZhRNJRypXLtxI8j0E+BFxik4LY87jzKAUKk4yn6EKOXN/hPnNUOXnJ3gm0eNTYw0Ka/uxz78JBlN9gMiNsICKACVqx7GxzNh7vMGtf8bEFGC/fzD0q5KG6PGd7FJEJHxTzQebq64s84RbzFkA+ffciKTF3Zltu71uZukLPt6vMYa+jgwHH7BPNKXwCkMFK7wl1s/Q8zy0TK6wRtAzBeXZrEAvFVOa7lbmhhDXcl3lCW1YNsuYe7WA5SMruPINMs6t2mOFkwr0ihQgFMExFWME0oLhrV2PTQU7BZgjN0D4xQcLmyfTYkORRu2E6R9jtYGm82ugz3csk7pGGZ1QzfF/Cqsb+b6ZyHsrl6kwovZP0XIULOxNOM2nASboUStNmfp4RKLuwbmk4IMR78oG7SWU+AY/zvKd/Nz6iqOJjmSWqFwrHlwul+QGGVNG4V8mg8B5w4cYUdnxamDIBAHFZMcTuyO5iPnHUdEr0K5gp2WApBrGvWi8digOCLfAdGr9zHSgSM82mN7uJ5D9A6msSfYxH5RnVBhq/Q0ne5hJeYSt0QZF5jJBITztNC0yMqhwUFlfL2hBAGkX8HdWk2e3xv7tmWSULupda2LoSLO714DgRVzkz1KIfmNBnZ6kEi0hQd6h5S77IiwRqqlIB37KI07lp9q7wNr8r6AUxTZbQsRr5YIwiikeehAMjNVntJ1f7DUO3kcwKF2Ei5+K5cQFNk/x8g2SlHlrIWu8HAyzNnkfLgbRXUoNRymqanPEjiCnJuKxlT0vzZOtjxIq1A++FZ6Wg3k4X1HUPelVH/QCsYGGIHERoJfDnudjD+VhkUX6dcpJrL7yQZ9wAc7FGVEQJdW2HqIum43i8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f79a6bc-ef6c-40c6-9f94-08dbe47170ab X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.6523 (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: /CNBFNr+7p5t7O31a3G3mBWMFhwm8DdlhB3CyssbNNxhCrSqnUKxTDqkTFtM+DV7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095351_309292_6B85BA1B X-CRM114-Status: GOOD ( 20.34 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 f70862806211de..eb5dcd357a42b8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2495,14 +2495,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) @@ -2579,6 +2571,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); @@ -2588,15 +2591,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 Mon Nov 13 17:53: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: 13454283 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 123DAC4332F for ; Mon, 13 Nov 2023 17:54:10 +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=mkT7y1DXDL1oqHYfm3QziLKAJpvaAni3QWskhYtaDSw=; b=mNAKvXCk3nWcT1 H1/34K2S4IYOdVUS/VNoGFhTC79or2mQv3FGCkfm8yXvsXJ6K5aNBGNRzY3bP3eVGf1HeTQk7Euyt 3qfps3F0CfYo5gQu1EVhnBsC4KggCH/pUXto6/oA9j/kNpIAPiHgAgtWp80V0H22kinH4qp+TBDj/ SwevJfhyaMMe2G6pwvhxWpfCmfhS8DekTzUwkWCaMPbIMLwHxh4/kBct4jiY/QV7RH3eFU8FOoFDy 6c+eRkPcnAfAWTd+VAu2Uz+Tgu1I1Z70bgWzguREtXNas0ljIw127xS5JqSUx24B91CpPgAaCnZey ej2MgjKxxypB2hFKLOHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b80-00ERTq-2k; Mon, 13 Nov 2023 17:53:40 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b7y-00ERSw-2b for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MFoTkz7KKbwbMVlXV0Rw3Z1Xn3itrP4+y+aWzEnriSS95VcBuJ7mNTqF2PAazYcG3hbhL25eNJwr1rN3kAY89Vms8OrSk+4qng6dfSGhnkTSYUdAfsjbSdnQ2CA4nd7L1f9rpejsrw1dfAG5Lqmuoi5XXFcHZA6YZADevNtDuwbeOB6sdm6EzDHmN1ZDMJcU7BNTpcQjLmbAuRwn/MsK9wFrkUFPX9ULCYmFiCLRLjVmBrvqT6h9KDrXQtwrzA5WpH7Jp86ljgckaanTSzqv4jN26xq4gxjUC2Im7u5xeGXaFG1zqCwpJw0akcbS5TFKJBF5DgvecvLm+Du2qMsf1Q== 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=6+gCe92q013hxTdsnzbxQuXeRVJ+BFrqzRykqdum77c=; b=cCp3SzuaktynH5+u6Pax75HG4fz2UP2jOEyk40Uj6kGgqMUC5Bgg3/xGuE4o6jQgxL2QPVhnUEWgpzAkHC/AWNRGZfAJIgxnbRN8gyUl8xuqjQ/MPVViiUajGIBf3TqXzoQq31rTFnv0a9RuqlbXYRah3CxUX4j7A9UxiU4gGUzlStXM7Ebw51eVzSVDjRx75RxLXc4Fkx/6lPaqhoDD6io4CTtmA3/oTTZFln1UN+rIX/FvL65+38Y7i/gAY/cCNu8MrCtXv8tTjpSAY88fOcl6Mkvd1BT/TRJEt48M7LzzSO0YRTmpNBcjwmyyGWJnTUSq52z0wSrSjq6OND1Q3g== 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=6+gCe92q013hxTdsnzbxQuXeRVJ+BFrqzRykqdum77c=; b=U11thyv1xjGotM/5oMPrS2hO2gviOBkMznpcvp8mGzCs4xHGZJofvUNfv5rEfpABEypr2A7KqLit03LZofIlFnehVsPg/tHH/fFAxqTiIwjBJ7mmiEnrGaLFclL1bsQLf4TImlAPT3BGsVuPwVyrLiQ5S7JhIhY7NvqVjITsBe0bPUc+CRuszHGBoFlIHM+/+54ht6K2exqIGFO48UAXYYV/o2UFHO/aYKQgNxGA9g5XATfPe47vL0PZPeOW41igV21sIOkGGoOUlxaFKgnxQQURV69X6LVzCN1EKypx5EmmF8sJGfRr9aXIwtE68a47nwoUnDKtquLswqmEBAhlsQ== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:28 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 13/19] iommu/arm-smmu-v3: Pass smmu_domain to arm_enable/disable_ats() Date: Mon, 13 Nov 2023 13:53:20 -0400 Message-ID: <13-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0328.namprd13.prod.outlook.com (2603:10b6:208:2c1::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: fc93690d-3446-4064-42b4-08dbe471702d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uHJJsGOs4xwr74vWESqedlWwSWd/Vt1GDoc4vKM6HKpPkxOVBLBjnnLUb5ABptRdrayq0t2gg0PJnwIPU6MhaGMcd9xKeGup9Gf3NSz/Z55XLaWSjW1ETTPPkQ46fBGt53KidieQLHM9ce2t2dxjXvnfCDH5eIxVnhg2YXk19NuN8GZppNTrhh0w9JCdIiHBhuaO3KBFXEqj65MMz5lKlilDMNApuciJ7A+vJ0HS4U69QKvdR4HglP7HiKWnLFowq1f5vzbQZUTwWbdxDsFoY46sPM6wzdzcFMd8JPF9fiEnCznBWghji4AlyY1P5MClDkENoBi4i2fdM6wUMgLzZ2MxkmoiPJNASUTsnH8rloseBHgwRzhIIyeN7XCmhP845SsSpd3v9BSkmxzM1wY3Fv7GHZyJSPqOOJWJbVRcku0IsZkJ8YYer+JlWGAlBMs92iDE1fptozWoN7euAqbdJCb2kopFhC5md/vh2x1tjXPsMT6vtL8KsLPkKN/tPPJmFd6wbs3fIrYqG5gBXuQTvEynv8fsPOKSAkbvzmY3Cac+67UVOVhZN2I6LS5CavVZ 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6A7XcaJ0lRLsNaimFhS9+QLIpgQ85RjzhLSxBcEPzqpXGKHf8J4G2Ggb+2wvqcK4GX8CPDW7x3IhO34PD5vUI/55VYGX0v9cVrkmYOiC/9p2BsxYHtUK9t1rQeoV/9+V4+9MkySJBb/jrQti6XkSrTo6tyJFTMLHOAlNlCSFw0ZoaboBJkR6wP0yGSLnrVonxFa/fO/wGZosuvZSdkZUc5ASOw6sps7ZE/AV5M5GH8N0ZJXZE756d3dCoqQgRLzQIGtZG71IjwxDzTZGn59Ksg8gVmoV4/um4PWO0gmQ5Rtq9C/ymQHMNEeTtkFYuu06Ft7I42qHNnNDbagNyCvceL2zbbDiStlrurqSQqKGItn0jWs6Lhq2iMIpnY6W2QVhDPDeJhPPOwkOKLU5ozkHKulb8mI2Dlnz85u5MpCFwbK/BDA7R1MCBPVJaE7bDDcbVKqA4kTi4sM1v48expTriPDXlSuQdtQblqeSpjktd/KTQm8ROaupeEDHZQAUVw6tWSWpaj8Wgv3wgXYTe8u1NZeL1PVZcPFsq54UPufdmuTINOV6x3da0H5YUVvy5oLBgLVXZXVikn25WnM0POGrqA1+MIWlSod+uTlGWO6RQHSsvEv+dKYeGxz2GLy40nFk1PSWj7h7SDXvv2hW4Jtlu2y021h901AyZXQavU3c3SN/7APeirYWhcCFjJsS8bIW2U6bkjjiVkfKnqrTwr6dGZF7x76/9EE01FFaju8+OfpXG9pAaHmostZqbNWmGNEk+lS5EnouJY+EOpOCja63471qtLazVTh2ffuzzvjFoTQxm578vYCHgmZEsRKHotLWtAuDnh3Z0WeZC8DpKZWqvvtqtlNwOlUnf+m3uitmfdYSwjQtccIepzN/izbkuuhVS6B6EntmxmH7FcY0CtL//UlKnmAAl9K/XpPrEK2B38Ljf7EbMlZhdBpC2PobFhuuyQEYsgQvv31nCm3ggRRbNbTNzhu1cgihr2y/srCu+nr3VCJFwUvIGGJai3295afiZmKn4ri3LcZ/0VyHQ3oCbktAwbNtaMhHcEtPNFbXGv05kHZsmjxFEwLgCRO1tgrLK+//eefdFX3CXhq/POXzE5yYLrYckB14g6YOi0cLXK14pziwfBp8nfeQfpdF13q7Zm1xHMCl51qJ+56lqRX1S8OjE4wysWMis2QoryXzq3MLbf5dwODlHYIamonK3BO4XjFCjBI+7BhIcJpR51ssWbk+QJ9ttKdH9ueOgTKtjTAx2IVcevSeoQCPEbwfMIicAz3xIqc3XGRRpS4JobvbfE3H0xjoGcSvVx7VlmhtOnx7eej0EiXM062qDsltGQzyht4rFewly+glAPVkjs8acEdAQL5uTU5QqJ0nI07ucfBfPeiQPfCYfhKfZFaFCIkMKpf9uvYIal5KQeg/IUbt4jY/AfrTAJrb3p9HvHDi2+R0n2NxKA0pyPIC2EdC2P1zKH57yb87E39DQA3/VxO2PHmRfkQ3Vj/mybUGARgM+8Nh9P3hUJG2nAQoEb0VxfdCEyztjEHIe9LjplBR6WlVVYgOVRYDUaBr3FGClmbk1eg= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc93690d-3446-4064-42b4-08dbe471702d X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:26.8744 (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: Xcqn81BjF12o9xnL+no+Nl27Ka6tO8Z34r6Ds1DaL27eQA9SLtqBsfmq0+B5zUbC X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095339_042236_A82DCD99 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 Reviewed-by: Nicolin Chen --- 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 eb5dcd357a42b8..7d2dd3ea47ab68 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2394,12 +2394,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) @@ -2415,10 +2415,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; @@ -2487,7 +2486,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); @@ -2609,7 +2608,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 Mon Nov 13 17:53: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: 13454344 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 8D1BFC4332F for ; Mon, 13 Nov 2023 19:00:50 +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=VYGtfhXynsNz2jz8YMq4ixVemt4G+judXrVnvs0nlyE=; b=UpQwzx5qgFHAAx 9iCV7I6cuypGoptWvn4H9vDMkRr0P8zkfU3lGQGeOjMeuDBHlmZozpBsj8E4CmaLnTaf/eHb607S+ AFR0LqADcP4uNcuDzEIGLVmeY21/bbb8ZjSzHa+k8sWnpCkbc6t/nBdGmKs9KAQ0+oOpJo5Kh/6wp QfW5XC0sS6jjjAkW6aKYsnBId2Zc2+akmTpdY2Vr40vEvDWy6+gRl/Bn//2BB9vf9HhZ+YUJkhIym ZWAqt8Od10fMyKTFi79J3dRhLHuyY1XCIKpZJTrE59TPQkCLVeNEZRbjj3RYcOr0uI7VDmQR3xMg2 hDAzpfHu2Mz5NHVySJJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2cAY-00EWzM-0i; Mon, 13 Nov 2023 19:00:22 +0000 Received: from mail-mw2nam12on2060e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8C-00ERWJ-2t for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YaAfPFRVd3pS0lWj9z3xKP3CLOt6ZUBRMbgyd7iLqPW6+AWCg8DFKVR9hsExxR5Td9DbQPvcgT3zFGIyGQDHY3+xx/721ilDB3HuZ923yHOaWICvM0+fYgx2OHjmfaSKbpyMhyQz+2auPOWr6OK+/pqzfsZ8DhD4wo8B6EtEqwTXsoclI2k4Tzk+HoKi5Wi7exPR8d9dPxVkYHpaFXUrPsulIa0iwV/fNSejwhvyvUo4KYTn75QjS1SFdNbqzLdq7jpAnnOMNQlWduYlaJK+dgJaRJFVsLR4IFYzmihZfrmfHP49R3GKztzBYIbbmRM66TNGSZWB1zVaD3fh4q6TgQ== 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=xTuACXyciM4pg2ZdMgnilAeCvfBwrwpgwk/dAoIoopo=; b=ZhyzdJ1Qd5mw+81Tl2cp3FZD3vhyXTgw3zmd3+qKziLV3iWinL1/LmyegOAFckexJdQjai9gni2SSCIAiLao3Rufl7mAmaM5gmxR0QMQu2VXtPLuQSXwpou8IIvoEv0LnKj9pDZHsHzH7e26CLwsMuERJksL1vWwdBw6vyYLQuBPDeHE+vZyJSBJ7DZO0mVl8fYmiCbygd6fWScp1aHUF8u9SJnDyU/rgVisKDRCRmuYeLa2YYXGpYVKGkcc0SPMVtQps3Ell0fE3rvPFzV5s9CoCgcLUAwoJ7zwHLGoE4GszbeHM7F3I2atLaJZViWZ+oM5DHdTxTcUBroXKfVcPg== 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=xTuACXyciM4pg2ZdMgnilAeCvfBwrwpgwk/dAoIoopo=; b=nN2OTSgWbi6W5OiXFvfU2iI8cuxEsG8ScN2TympRd4jcGDmGV5acXFMrsvGvKGt8g8wclcbRktTHaTVLv2rBk0mTSZkUiS00AiCqC7GnVqscWdRacgB64sDzwzBWfJGQByVfjOpwCSDSApuGBgt1LY43ZgyFNZIMixOS76OUYc+iHW78Jmt3S9LJCZt0ZusBzo/RTM6Y0kx0GiN0jmETcRn/15TIrwk4/cxEWpC/AZOzvkJfkP/7i3y4Mo7odxUMaqmtaHXPJ54AdTuJWPi2MzKpITKNG1zFQLpLzs0HXucJfj3T/QBwSFBFuY3baUhV20ZXdUzK7pF0YAhu+cDSQA== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:37 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:37 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 14/19] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Mon, 13 Nov 2023 13:53:21 -0400 Message-ID: <14-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0013.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::18) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b480986-214a-4b80-64b4-08dbe47170b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wXbhcxMgHlxhpLMaTJwSRjx/2irY2Bj0h7DPzjGfdt9+10kMhTSqycwmqpc5nc1JY64nir5GHeL62H51t27zG3sNq1f3YTQsL29WClL1LhE+C3L3CLYIxxhJYMSiBrtgz8nOhbN6x2FqtkBgL9J5zcZAUVuH92CIqZIu5Ndj6alV5F8dxiLdE+SCx1LMKXDEmikHbKZGKE4CU88XAnhuar1yiPbv6EAcJkaftwpYt0unGdoTkGcb+50LHYbW0K13uv4G926tYQ+rlzopeBjPSvoMc3fyhSBG1srQOPpODA8CVuaFvAJg2JomfRr41/H2uesU9lQOP6gM0YIbqMmGsHelwF/SQupYTNv2BtkMDkX7hU5y2VQ90SFtbbVoNX/xnVyDRdlMA6z9tP7ab6A2aUUAkAXbUbkMh4czztNXB7ZBzQxbj5t93XaTEkpEb5rbfIsnLQ1x66FJVpjMA/ojhzIgRyGvVJLaEHvT+33KwW2glhwfCkrwaZ+tcU2yLfubRHu76V83jUZK9Yj9hy2GvQxzkaXh3GzekKVuav3fzmCsdURtVvsAf70+XsSg0MYm 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BJnkieywCmMaBxczj0SBX44bO9WyihDzHheA64wxufq7rjCCXB8fCBWcmRmwIhaVysYBrc23xRqaQktGQn8XlbyNdgmTLMOU6dkPXSwYFSp9PrUGk4YcExzqMUt33T/Fv4lqIvd7prsJlnP2DQQMUiOEdE8BmFP4xjbamG6a6eAdJsKji6PKVd/jax58TqvHkmeXYv4ptaK1E+s2IZjutXxUcfdk9ajOXyXhK91NuZjrsJhGscECN1+AbfjRpT2mksDnf7jljsxcRyGriG1vx/+U5/J4lD48WIgVqXklBvnngFZ7YFMpsuVm8ZMT/RrEEAhBkJVhzZR04plbSAGTBsNaH+S5kQ0Jvb+GNMjvfyGaiYXdHUse99ZAqgEmMfkYpoVtpmTawRwxE9VBzAmJghnGPeEkRwWUBrCI1bMfrGI+YnYMjkIaMwitid+tp9ShgSSuwlamBQPXdybF2Ni14+FKFZvj9dFj1Lzied2qHtQbmdzdbx4OHuwMSz9mX4V4qtoOrrpNPQpQtY8NxUvlnTJA+FvEGhr2ImV2l26ArnUah8tPQnefKzTdCQk1d68PM7oTiq8Bmq9xeUV/UivE+V/h1+HZbIKy9y95XstWtCRajEt7Bo0lEJYkLEf0QPq5wGCGZ2GW0s10whUBIHJ7VSyukWx2m1OgyDbFSEugu31FihJTgyaPobze1WVD6wkfv3m/XsVBI91nrzx2bfpioogIFlHSW40OX5XXu0x2YFcuwf7FQfYoiTcSM+bW5oVaSwWv2XccK2utGU3FUvlFkOLTA07Mgw9KloIVfpiDV7qSFwf78cSVhZ3eLww2DnwyVUtysCP5jiNAXQebO+sYfqO04h1AdFcDSJfpysnaaamyQHHYIHLx1wJwKNy9q1xbjIofwGZ2HB3r/bRZ99gnKz81gMFmBTOWBTkUeOHATena/er8ml3StNfN+lt8cz7aD1u25SfLOz6VJO+TSH1beZHaR928QwfJ9YcS6uyeleQsBfXd7ztGJ86RTluz3SzAxI6LktZbCsvzvh7TDZzYwgKR0pkPUG7UoiOj4BRjyjKF2eUv6uRxT0jA1Pgcap7qu/Hdqizdu5rEykgxmvUx44tgUdYaoXUe6aUHbDYa4ABlE5YYNO+tMY1ZPs2lckD+vBLn/J1jI7KIhQulvTikJ8N/cY6gCaDpVO9pwgWAkA0yLaCPM19SEJ0vua+EFPyHE+Ypj3UNifJO5vHzF6MXUdttI1vo6e4R4fcbdnjAZPt8572r1+DjIQmPxmmiy06p1kA7WEauyUyAOAzmjS7gSfQ/Ke3fCoBc67Lldp5u8fsDJGi8Y7QNL3TLLFoeo2Fi5YI+eI//figjMWxamfJzz6VwU3MS+vYMjulokTvWJRJfEX1RY4o7mf62jWDvRXlguqQ5d8NjIn2DVVqHjouuBEQA2FGsP5d72E1vTaAamPYVfTH7/KiC8hoVIFaKoLCeQvdDAw9MKvkzHd3i2EaV0Gv7RH/QjluHukvIt0v7b4fV8BAkZtXi2bpBhzB977TlRBkGzXEHU9W4wEjEIoNskTmndqZx23UpqAhV36bx6rU= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b480986-214a-4b80-64b4-08dbe47170b0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.7316 (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: QXZczvqD1VYSsSyLscCbw5V8+M/BnOdZE5EbbtxhapRX4xGqSINHthS75GiQ5FXT X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095352_946833_8888685D X-CRM114-Status: GOOD ( 16.42 ) 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 Reviewed-by: Nicolin Chen --- 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 7d2dd3ea47ab68..23dda64722ea17 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2480,19 +2480,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; } @@ -2546,8 +2547,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 @@ -2566,10 +2565,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 @@ -2577,17 +2574,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 Mon Nov 13 17:53: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: 13454297 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 4A5FEC4332F for ; Mon, 13 Nov 2023 17:54: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=gU4IJCkUrK/HTH2Wp9m5swfM09I40h8tAgRIJYQqCKs=; b=RrFLOeliAYsOEO KUG5JnvEh43tHGm+X66evEkf/48ujGKElsh+Gps/jEkXByxnHHyH/oam3woqk77s+JvCQl2yEO2QC yIxT21zsqbVZzBp4/IEgoXkPSKXo0bywyVEhG4r5x7Q6+RdmxxEQS9C1/owPtM3vUZwsyQrz1C4+J aPETVSIhuPOvv2m8773xMrr9cAtJVDAgD7II2+pdvMZb7FB6GlYGSN7SS0LN9ihvqFMT2T/4SbDOk SkV+qqOhwphnnqFDy9Dn2f+oYHBP1Pqh13yCm4vH8nmZrrpQG1picgcMrJddrLBAhsewzLRm/T3+e tW1xbhin1sg8kNRsHFQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8m-00ES8N-0F; Mon, 13 Nov 2023 17:54:28 +0000 Received: from mail-mw2nam12on2060e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8G-00ERWJ-1e for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=arUUPau2QScVYr9Pk6JaVXnGQGPzXU23lh2cIGIRF822GX3QtIMMUl+4xBWNJUaivOMFtA4hFcHhTjAMoopica+r6nIuhdHQNeNzRV9XtJvb3w4fADf5i6qS+nQhyCelJpxGCLVyaYAeP3ui9TAMWJLoWu2CwOlAOCDKWH+RTspxXGH0pvvTUL3kzPbpaasyY8qsPem4oa7m2EXdGFi8srKS2RsLjiLWBZOG7rjRKQHQ83dccJzNGOtqun1jfRFN1sAjV/kX69uS3Pr2GDivyN2l4RabEhVV43/WBfA67fr7eaHiV0yWc5ck2E3igNJnSd/KQRwIIWV7WwASp2xGsg== 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=gafHm90YyaTTunyvL3ecHyFxShSnY+zBl7BLNowIgvE=; b=SGP//AL2ya6t/AG2B+SgK5KF0K7Fs+CF13fALG1A528EiI2C9gXitjz64iRrFFHyQyaEYVtK+Tnowbiy0lekotwA3VQ9K8QeQ5gG0KS48gDPDt2KEBt52c4DpsywBannU+bYh5b6063nBTS+MY7uiqIJ0KczHoz0GAs02evjzcvN8E1YgKrg68msVnSA76D5SE+JtTy8ols3noBpTCFnbY1iJxLRBxjhQ1SpNBvgav/iBMHzED2qO1W2idnyWmtsJSXvbUnOsCAWUwk1ZVfOyhi5qoWenhEJRfrrRsHdg4OHzlZiTgNV+gMXmQTniHzBsaWl6ujsWN1thRLsh1udJQ== 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=gafHm90YyaTTunyvL3ecHyFxShSnY+zBl7BLNowIgvE=; b=oP5jQ5faHSDTEAHPuUhQhRtSoCF7n+F+fJ7XKG0jUaYUJeP9z55OrxqJCW6mdr9fQthQXDlDWkvHfs6nIhlYHaoV5e2WmWQpKyWgen3zg851LtIEt6bhNGzOMBDRej4XUSZ3ZQ2kwiFjfM/eDt3RuqBvQ5B3RqBWIKNGYYG2s7oN45cK5O/6XoXFOhK+JCrakb7FbExHyAc22TygxwlGEF9AtAsuDvy2IL+zfOHVqCWem4wTUW9KAbqdfQcV/q6aeyaLUpK4HuevvXGlGcIKrsFAqfnEHc4/Y0bJalty82g5tqE6ITCdgVsQWvqwFk4Tz8jFmUE6UkznlcyPWLDcyA== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:41 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:41 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 15/19] iommu/arm-smmu-v3: Add a global static IDENTITY domain Date: Mon, 13 Nov 2023 13:53:22 -0400 Message-ID: <15-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR12CA0033.namprd12.prod.outlook.com (2603:10b6:208:a8::46) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 1876ae5b-f9a6-428c-5cb5-08dbe471716a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xeFlZS5flyhxjS13ml+8d3K84uKTQ0Ui2PwSwGiIgTsMm9sNNn/PXWHdXMHK0RATKtLVJdLNv/WdVRb97HmsWwdBlzjAsrBWtLp14sDyiZzG0XEXj2RCfoM/16Au35z5dMUyRxVHQARRoz709dhOZj0yhCtmDiZMOGH2VpyzOxr8ZV7oE7HI9seKqhtS1M/hGmH5aPZKDAw/QQSLL/F3x/52FNsUFU5JIkMkGxjU0eQ3N5pHFfc6lycX/BGIqRq2gSAh9MXSLv5eX/7qdrqAuyp/xEAvqn8B28nS4IUwejBmIufCG5qGq5HAijHhkTja1S1w/N4w9XF6T9InT3tKhloCyw6y0Z/XovTDdMOkqI1NnUGZakkNLJmu+U5LDyTFZzFFacTMj9ZA/woG9Dq1ME2n5Sx8M9v1sET5/I24Bw7pq1aJXB51qMC3miYGfCQTGKMSPMMwwlbfQrQm1Y78MIBNu8GC2CUHf4KV4pkTMCbp1LWKK0uKyF6LYCUTW9l2bsWJonXVFSABnr4m+R7lRPrllFq13nz7xxE4o1YPIMamUlljMP8bF7WgcnRpun/a 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZBeYi0EgrC23iMoQpRGMnBkOo53GFRWElgipV9ZjUrQP1oc/jm9UHCAG1nRg82snVOxfDCxDZFXXb7a8w2cbvoW8KgijY4HT8p1WbdVMxfZ/Aw67VrXBMJek5sHyz1vjLyDtgVnDOSu5LBTHdwRlTxIM0aJvCtD/xeOtiy3tETh09Tp1TKZBLcg56eIWxqJuI/AkPXFMb6U9XztE9LbnQG05RFhLup+hWTUvIQ22zOUTrhWVrx0LFVuzSwxFElS8+s2yX8u2qCS3k4RK/q7Y7+QTf+FGYTXUQwW8TX+2GXQluFQ/ktWKWcpbQAAx57oespIlEzkC0UssVuzeWy/6IqSi4POaJyrFXsX2I7qG+R5VdYKbNJ50NZ3XTeulI5jdOehN7tXLgyrr9MdUhqnO817oIQ6yIJziZlYFmWNsKp1RtIGEsUN9SkFTvFwhXhx77p4zo9f/zB4Bcq/j6WDDm4n0Q4p68LKodMAVlCr3EazGuagiaRBn99fR0mouNpcLwWuf1fknrWpTM0X5vXdl47o8GR5fOBaRF+xIK4k1rqDVonX4AYKiYr1/uH9Cv1oU8DrZllkOwTa/sPStuD61f3C4K4fn9W2mMafOnasiUUB4zO5BuG/EZkIGZ6JnFu2ILCZZgeOpzOpquBu9YldO6P+X3oXuFgc4rZT6b8C0ko67JCpEX/ZwUz00zG3x54uX2h0b8VH655H6c02urMDOz19J6QvP3WPR8iYd7HUGIKfB5NVNV907pGMpkAaej2te72ApyO4jke0OCdocKhtlmaf53NCoiYGDYLakG/LLHpWAtTYQyteaQela1qW+aHZTd5z3UltdIHfAQn7AsaiJ9p0yjA0KMyzn3qzEFP7FXOHC6vPmHXS6reaKf5WnPtsuctntpejD+r/s+vI/j3qK5mQ89M0btZwliYyoWbYydQRTbnRR49RjCazk5TexF+Cq6wVaromBX4W3Tf9JCGUFYkRGR4bFiDJwi2gxgDCYmPjeJofsWvJl82tGOWS5TM6F/VJabaTv0Hn79LQFzqDC682llg79xV9OkkLoPKBmiRdp8U5AX04wQE8HrbYVlA3PIY6gUwVdqQCnQDmfW7BCCfUj1lkU6O0ayNHCL3GTW90ATGXGg0RQlCrCQFejoLdPzhR50D3Xuiz/a8l7JvvrnfW65F4j/DZoB3JKtE/QwHZr+BGKvh/gRqXsuATOsUtRouE3UZ1py1t2tdsGeshkl8lij2o+sEYdTtKp1V6phYVrhi0wO+Sg4hESkKD1wBXm85LpOpdhbOX+oYyFacn1ckS2m/xI1OXvfuQaMoPacURFvtUsYrc7rY+97QihKJAeC6XZA6HhE8OdPvpdRVbcnDNThCaEGLDQPAyFPLdxpc4Z+yQ1q8Vd/ibuPVSP2IIv9Mi9fL6to2PS3lT3wcqxNvw6BoIAdfcjiA6tS4DPSD3NrDTGRXoTvHqyHRTCVmlSCh38u+0EhAm3xkOtvZXfATyJjKIIFOMEui1VPiX8MQrcui2ne+H2PmYimxX1atx8EjtXyvww9UoIsEFO+O7sdfyzMQ2GcMGzsRXVJFCaVXE= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1876ae5b-f9a6-428c-5cb5-08dbe471716a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:28.9221 (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: o/usRftTFkvb4Vx2D9+9V4m3/xdkucfbSChEzy85UWfK+laj0VxYHzHESz9JO3gn X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095356_584022_1A13AB7D X-CRM114-Status: GOOD ( 20.64 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 23dda64722ea17..d6f68a6187d290 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2174,8 +2174,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; /* @@ -2283,11 +2282,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; @@ -2484,7 +2478,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); @@ -2547,15 +2541,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); @@ -2592,13 +2578,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); @@ -2614,6 +2593,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) @@ -3006,6 +3039,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 Mon Nov 13 17:53: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: 13454282 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 1C420C4167B for ; Mon, 13 Nov 2023 17:54:10 +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=RmdAXSQGF+bvJMiy5Wa72Gs1VWIKg3+2l2L5oE6oD7Y=; b=1uAkrneNGPsyFA ilgGRfEy28N9hjtdpk2eFLKfcAwOerZOiHg/IsyKmFohCPWg2tumD4zyJlifRlP1rnYTc8w5D7y2P xrddR+gx5Zzdy0siSBVhogmQ5T4g3B4mO+1NWnUP1WvwuFU+ibRQYj4niyCMMLELpD2ftp/X7KxZI eDTjLCek/ylTEhipOidfxtb82wIJHgrW2+KytMEXXvn1e3urgQq3YE9hW0br4G+lgaG7Y0Jg7JeZF xicHOosmAIv38zMsnCi7nSxN2gjMWw7QQOmvHpvdP/2x082shlxhTYduN87NHb7QdS4UDXrC/nE8u grBshSSJ1IZedDZeHjjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b86-00ERX9-1D; Mon, 13 Nov 2023 17:53:46 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b81-00ERTJ-0B for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CrNEuqbtTMRyTkBzDIMtguVivZt2sHp2NLaGx6g5lk7A2+zYIgsz0v5SOLOsMOA3VPXBUj/COZ7lqBpnL6s1+XjeeSw/31n6CeTtLZyC0Ay87do7pNhsv/8I6VFS9qjeMixMkTfv//T1SNw67N6iqX726qor+zKcSDNZCf9nWXYIKt+gg0iEr6gyv8ZGE5aQYbVtuJarmUpCsbFqU30cNuG/DkWOz8pQDGsQKk/Nio1WwG4WmXgQVA6Y2541WaqB5EOGo/w2uNQEYj8bHul0TFb9VCh2ZN4ndw31PsPgmts2bGhW7YXsfelr0f84NXzDxDNTo+bVlhqFRUuJzghihw== 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=OlTqW+hx4z/JEPgi8ufSSNgBDqkQhsRDOmQ0a6Td5FE=; b=mBPZ4YFNfnLNFNqCo8aKylP3o/1EiBboGfKfBTfcNFKlELgSPrR56z005QDn8bRgBzo6vdjXieiNBa4d0dW35JnDjpbF++Loy8ZNNYZPjneR3QoyCXZ0FNdSlQC00+aBpiB1U/Cc3/XewEFzTKlJfIK/11BT52kzIgvRH1j52qKiq+/+u+dZUYktGb2ts8sNZg0/R9eRCdqjPEV+lLwhOk1z1wUS05EGYqDmc5tkJENKRkBlIXBUj+7AS90LWq4LmZrw63q6ajhOezJlGKtKJSKV75LXiZ6RuhF4noWxOBwf+RPQZVmXyQZ4Mu4TXzw15GHHvkIltLoJGqa03rFSjA== 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=OlTqW+hx4z/JEPgi8ufSSNgBDqkQhsRDOmQ0a6Td5FE=; b=CqVwMNNn++fgoA59P/k5ut58drjcpHVdIZ9RQ/o9+a03P9j8Jw5Qi449ghxgY5x9GfGRn0SulccELC/TznLcyYzkjYolGph+bztaoqeORmu+TRqVymJ4NQD9dEOfkoFG3wCxIGr3QW/aqnx3eHmOpUYQZknAB0/IhALDYQ8PDCT67X7P0ROrdwY0EzF/W+jm8j0bWvNs9Lbp52cRDryO1F9T0oVeYzr7FLe/6ZK3hFG1eA8NkPmLiEUEwPeuRjx2L19YTNdYGbNr+h3A1TIuP7ktn4M1gGtuUgRfwS/ndfDMy8TSeRTC4vf9w/p7gmrDeBi0eQMjc8cvZsbHvRPA0w== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:29 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 16/19] iommu/arm-smmu-v3: Add a global static BLOCKED domain Date: Mon, 13 Nov 2023 13:53:23 -0400 Message-ID: <16-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0039.prod.exchangelabs.com (2603:10b6:208:25::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: f82426df-8b93-4dc7-6862-08dbe4717053 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F8VMBpsNJwE/WPRDlv+/AwQgb3fGXoKI6jl9KRgtg0kAIKlaY8zYqUtjDCIjDyB6kxGCrnHhgDOrZsRMNBiiSEB5D2JgQN9EIWuxtMFG1FzZFrW4IexN++gq926KBonHhDWrXMdq95EK5H5tdUOKL/7lp9DqRSNQeMH+ouc9G/K/2DBg994t9H+nvQULu4cPKrjY5zHDTkdLipz4wPUhTSy9l26JF4ehTbTCow4sO+I9TVyWicyvbYkf5qDgyO7ohmYfiF/H62inkCMk29R7e/QqcXII+MfNrvLJBF3xPrTbAvh5Xp6i2gp5h8pzgqiQat8Z7zm/uSmyjQ14kQMdZPwWpzRuhFbnlu8o9hYHPaXhS5Ulrom/35JFyiQ2mKJ5x1g4JXLXnSSWNVkDspNWd+FG7IQSwySEMvewLyzOkzRMXrJVQ33g5QZnGw8yZCwWXy7TSXtaF4gR2MzBupUYm2yKuY840zPC9TPJxj+NGFi/w6IvwcYLOn5fbP/hMQJBqFBDBP1WHeQ1pW8+HJ4tPvLwuUCeN58ulAbDPEsyaWoE8tYXJ0pQvtL/AfSmSskF 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(15650500001)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FfqDA1/hW3RpUxgLi2M4/VOFMYvhSV1ozS3lk+/CX61SdG+lIuDrjUloe33L9VaHez9Dxac9ynpsCWdHbwWM8YDRZD6nJ0RZb8G+CN/8imBdnq8BVhi4xYKusdnuLkDzhbTlNBjVDnHtGM59usA0KmG7s1AYJjtlbSSxynBIMA1k96ruaFjgiEIHO9JzBWMoI4VSPJXSAeUFyZu7j3QKKT9lW3PEQUW/UvVhG9m0UK2dOZ509IVsngkzVCnmh9/NqPXopZp04tyzARliDbPqvDAllPc0N1BinP0FXWuOz079r2F72n436GO43BIObgSDBjdRB6FpakfYY+x6x8Rc+0khgmPjV6/lxAhPoZKSpBBDrKiAZt0UpyBRM2Z1Mv/okZOoqFgySIGzGWeKx1u7ZLqgSBEsyC/YgUi+of1lCmZZ/KEQDooIVxMljtOhBu3frkmT3eV63lkxnq/I636HpDSDPQ/V8xX/7oJNnBptkgnO46UIw5YUO5Z862g0GQf0FP5Y3DO7b9TeuYaZnLAJaW/8+AG3sHMm86RL+J2Bicj6Xikl8pj50s5AaK5z0gl8DCjtKhkxy+wgnPfutiBaWRvbZhOXo+o8t0HBIeEayA5GXRGfHfT1mP0e1HJuvpWgmFT957jyA100ar86lhfO+wO45QaRdQZg7v0uU7KrVYz6uagfs0cnqjli/1e2A2Y83BXAtnclBPRZSavyWxLermm4ASxa85v01S11p/gTOECH+CoRFiDDhbOZEduGfSplfh+5D+LIj8kwK9gG/S4umolYeernPSV/DufGc2wXql1eA9FWUV0g/jodOLo2Q3IHM1b0h+BB2T0q/m4gRr5XCg28A/5fsPn8m6S2qrLEAPahoQ+CQSJpQqFVFUvaDENHMKQegQh8LIW7bTKa9DSB4jUJQYp/dlL23IASL6lvRW5BISHgNzf/9xozcRK707hDGN/D3CaLUCTUWuyybItEMIetQahyHs/wyeu5Wp3/hPkMPn9cNqSIBfZ3sKYhPolspy0taUCKlVscd+SDkB/ZA6D8E8Gf8GVVELwKqH8mDn2OlTBGyJtTQjl1k9hR7FV3DsiV4nVSQ+ePg7vVDu7vhsO5vINM6vQgECl7CvnuuFcuoA8MQXM8S+Q363JGbG/j85pcjEouYqotSbyLBxC0HXAJ1wqK8tX1IaEShJlamyo3ZZCwbV6S0GcfuBnj2+8fKwEriEqySuthnNNOsSRVAHbFK4hg4E/bUbQm0kRh65CabaozVwVFRxKd2bqiV05jnsJb2un1m+VbjQaP3tUEMUuP1zEF2avgYc2zBJfZQ0NvQ0n5o5EK87fAS05XE0BoRzGwFr+TacGvcorex+yg41funm5UR7qNVpAwlvxc5akbHH+tCeEqLRDKP0GOivw/FH21iNtvARMpfoNQRveiSrHzrgt1aTG9zG0s0YUk0P8wUkCweWERKbfO6q2szHlRmATGps67i/lAYCCdGsc6NG/RoNAYBbJs6C9mZ/ogLpn+XUHuZZ4zG+5UgxVrGZZ43DQn8EDGQT65oFgNszsacX/+Pv9AISCtZWCg+t45EVM= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f82426df-8b93-4dc7-6862-08dbe4717053 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.1101 (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: AlPDZphv1WbR7vbVo5XoIoDabL5I4xrQ99NXw6Df27AynLg6dQ5BQHOWCdC4j8Wm X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095341_114945_6118F404 X-CRM114-Status: UNSURE ( 9.54 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- 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 d6f68a6187d290..48981c2ff7a746 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2647,6 +2647,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) @@ -3040,6 +3058,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 Mon Nov 13 17:53: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: 13454296 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 19D7DC4167D for ; Mon, 13 Nov 2023 17:54: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=QKIFMskw1nYeg7FWuAgxK6x6LWrtT3xfZ7IU9rxwo6E=; b=q/o6F60X9kqCkb bUE4mWWdlq63kFHPRVjJRlaLrBcmr6XoJ762L9+DL0JRE39GElRr7+tIkSpc5tG9gdz4YKmYyAQ8E gzH47+lq1l9vJMBSYUA25iPym/L2TNCSamEqCyJbiA1NHEF/wNvaI+NwpvhvC+81sLww57mn3glGu TkogYGcJIMIoP4h9m4c6AaSc4oWi8cIO5GhBtCLB49G5psRE97NlM1BTh1LKXGcsP07RaIy0HtJl7 7ZmfXdVMVZfzvwUxOoBCUMYlM4k0LOGaEsomF6ddpxrUqtOZzO26K+MPkvIxaXaq+DhyVJk8VMWv6 F2g6gCB/fjDU3NsFV1xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8g-00ES4s-3B; Mon, 13 Nov 2023 17:54:23 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8E-00ERTJ-34 for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c+c69ROHw41QIQgDEhBul1w+O2nimljdOAT1iM3pjaHklZTb1w+911+lbWPIy3D1/GohN0DTzUL1Tj+EywLJdWfsfNoHii7h6ympaP0i26C0BduhHd4MPQqK85eBnczSZ88UrlPfHu8h/gPZQXeLSD7KACwIL0cllb9XmLilsQVLjeGBfcORBJzmUt2NTQdzvGazPqavpNrq07edq2K2RVYDCTywPCaUyS0xZr4hLzMDU8ntCkKi0cfhGwfBcdu2xWUBEFKXf1+ehySRwNzXio4LMnNcG2wOMftKfGLPbCumG4nfTVZR7WcFoxvra4sB/S6SEyjDyjz8qyoHXYtAdw== 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=vmSBMelYoeL8PSeZSGkueUwdtIkXI1yyhlC/bwoJEKY=; b=HvgunloEGOU73R9gcA8WlbGwy2WW52V/C1K+camCWh/Oj3D5YS1nlGVqyc31AaSo6cuj1u9H7FraW0iBRvha0i23wf/OzzkQByGAxrwm8bX6OtQ2ldrIgCyYes/yJLX5moPwkmG5I8Zl4RHSlmzBE/DGHsL+T/82MpZXemxU+9V+LgwrSfcw27uw2BuB6YIKMZTV1t9TsFzayOrOtTOiAaAg1QMQRLTfUZWuLjxq5G05b+0YyZTB4n1y/KJBXTAPF3jPmck7j8C0WPzG74aVCvUCKliSL0U9BmMDbstrjQbb2YA5kmngB9WFz1m3mCBrbEpflppdH2wjtNcAmhGXxw== 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=vmSBMelYoeL8PSeZSGkueUwdtIkXI1yyhlC/bwoJEKY=; b=SqfwTDFullYQqMGBhe/tCogcH/SThTFghXm1b2urtFXDEdBJjure5OyQXLOpSTx/3QSRetjsAGZdvXHNerRwkEwwkk1aGkrJnz52QJfQRLcHWg3FmqryaPIUm1dGqbL1Gr1dUiifm6eYkyGm82GaNepC22U6+NfcfeUESfAfk08rwgUaFfaIac5Ko95+A1xhn0fqGp88oSOkWDQfdK/qVKNpyNhtY7AMbBAMwWTEUPn4l2qhmn7rD0rJHt5xQ04TBZXoW8S/Q8wmqxAx6HAIb6U769+grAihwJdk0Inx7GsjLDMJUPHIKxUFlh4qd+WiVI37sL7nsHGxKFpRf+nTWg== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:39 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 17/19] iommu/arm-smmu-v3: Use the identity/blocked domain during release Date: Mon, 13 Nov 2023 13:53:24 -0400 Message-ID: <17-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR12CA0015.namprd12.prod.outlook.com (2603:10b6:208:a8::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: bbf23e73-c94e-4830-d6dc-08dbe4717103 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fRrlqHmcpPtdbV56AAQF0ixFthAOG9TuIZcF3s/JowhZ0GLG0YdrhMS0KLBOyz2RqA0kFnbHHzqdXTutrdkoS89p8qIr4VeQDU7owPcGGva36XtPnX4orw9PZajUStRT2u+PHnvxtfKyBGgRusmHgUIuM3y6J/oG6cQwUge/9uvry56l6J04w8tlZNLsnugDrdGTpYBw8+6pfNeWrcA9v0m2DGALJMRrddNwnHu+ILMVROE9yF/1SNQLb352VaDr11LAF8BQHMS9xXB7B0izMLtGiee0Or9VRuzMuuVcTRewxegxq5Hgb39ME9SNNCaL7+hHJQj3KokBU8oqPLl74BCufGHRcETMMvVKlvLelYsGnn+Q+1+7fR2uwl8aNxrXhpPow/DRu8JyLylX9uRjcSoZw/ydcumDgj4KDV7Le2L8YMwMcQgXFeZSKsVMKmfmeMV170y7ix33My2VnIvFQfe0feb9tQx6svp/qptpdZClkcxEHqyF36BSgKoL3aIt3GKE7qZ0J5ivqw+sMJmXSWyti0ImlS0W44dzYVPEp1K8CriG4Tgj+bx36OMorvlE 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(15650500001)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YkFXhgJ22DTEEqS+c7LxfDPWsw3AaSbM/YN7id+zgm/sTFu48pTWoP9lsz6TsTUHdWKvdYbh35vfGzrHQI3dlRUdlIRJSfsdMHlbfgwTWNzYT4j7FTWwt9X2okD571qIyCmFJfSbtD7Oja7pBED+MUBwQgftnv/TWeQzk8gRGGYv6zf5MoAQ79pJrvUPD6Li+nDcKNmLdoV1lNuJWMhMhaUxecbo9t7ozWJubB9vvFfy2YozgkuIQjAm10UxYTOq9/Zflgmmwte7hZtQlBtpUlDzgIBM7wfHZmXsPHZrYkP8SDrrKURrOrYxjSOWRDd8fHjF2S9vbV68E+N+MBLL/rRh5a5whlv0E6ChgaP+f8UhPWyKj8OL09JdgzCY0275IMnjhftiz0ccfJySdEzeCHxmOMGdRYCIrcyL+NhWB9cF4Htjc9dk+A9FvsowUH8w7lL7u5zZgWtNnG+2211ba/VRksQulsjtwn4IF77fWmPTOZae8syf2i58fVc+wvbmEJ0n4EJkWuXHDI6yp7glfS6WGiuV2U1RYufL0PHrrHHbpo8qxtMnULHgyz18SCjF9/PMcVHutSt7OTqxl7kVntiptjUfb80SSktvi8sI+4wupJevtIpAz9x0rSsck7rexl/ZjejX+nxYXlq/UaGUKfksQMavSZrgYxJtoyQ5ITz/F4IP62q3jMNPwwrJstjivJ2NI1P0+9zr02ppuMYDXdjW2G2PuwjJpARnD+nNbIchv2QpgZN8Wr39LzwZqvxkAb4wW38cECPKM30qKQ0rfbcbjr/80PutuCYi7prduFy/q4B/7NpD1wG5dM6ba2pPIVsuVqHj+7sGuG6ujIaym/XcIgTiHCLkRNs53hbqRl4qS8GHTw4Dm3lUZ/Jp392PbU2N+cHnYAJjshpVjQjKnztDmWuhVYUymNfDCj6pqeg3fNRJKPU5gS1BCRX4MlM7rUAiJxK7PoQpbpHcF3Tll9F8jb86zgCuyoJNZ9Ey7ymke05eOdMaLHJ5GqLh4YWu8KbQ09xkPESrwPgMms1D2ZXUBY/KZcMt3f7M6pYJxqVZZPabx1VAc0PhTD+c/IjfW6e9KWyTJHjOipAc06xkXf8AkXjDoOMJ7F0gFj2WFl81dnP1bBHvv1LRYobmLUwABegOVa0jdHBVsLPXf4vJpe6iJAd4wNsazSH8BDAaxIiIRWzGOUYpNoGUcADX+annf8Mdp9Drpch3mogNIsvmEx6AIZEkG8I+qlxhtWG9AaGCbZB7/gdCS8oIls1D83haDZRwX9Ywv+WCVHfVNH5F02/cNu6oi2fTaumnIADu0BA+UnC6PNWsB/6jK/oTEzlSTI3RYkNGV8iojyruDo95+TlDUGfIQWl6N1KzuLkVHPKnalCYfkLEO7Fp4NbdjC0PSKc/kZQ//5TVkwbof6k9ouwU7i4H770sxPl9EpoooLoiNjcJkmIOQURKUqZT3ODhgKL/LFmLi5l5tm18I1ZWvhBn+zD97Q1FkYG5f0dyWvm13612Nann/JAfyVNO4fjw/QeSqIq6OQUb+XUYOjtMi5yz8WIesO1eIqV75ckO1YI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbf23e73-c94e-4830-d6dc-08dbe4717103 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:28.2704 (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: VEs76haaxz6nHUBcSvXsK+ApMiWy7jt/Ix3lfIcetqJLjXr3xtZl63fvOff2DwT7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095355_004203_BC52969B X-CRM114-Status: UNSURE ( 9.41 ) 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 Reviewed-by: Nicolin Chen --- 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 48981c2ff7a746..331568e086c70a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2900,19 +2900,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 Mon Nov 13 17:53: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: 13454292 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 671C7C4332F for ; Mon, 13 Nov 2023 17:54:30 +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=lt2N/i6faJvp85YDPTNAr/ZyLrpmg4T8JbJs4NZOO84=; b=wg9jTQTwIbP3Fm 44yVYRp2oSLzLUiadOBiv0dOG2a06ifWekp1rzBbg4Oi4fpaxSeI3L9RCT0onpKT3GdpKl+A1Z/wo 7Ax7/uYZJ9180ZVHVTKDkjzGrb2RNgYJvvIRSxdZcZhnhcM8L9oJgS7esFUjPTllan9ETCc4B75JG VYM6pX96w7mZnM3k825R4QYEkZOuhEOM6HC9H9G7SkJNSadBKjOmymhtxV+hJ1G32z5MtlbeCs8wr miz0CbYdXl2iZteDujHp7RtZlzRkFgofRsvF4pxHnXcMd9ywtd3/GaVkIhbXJKkoPEPrott89H9Qu cUPKQvuQJMu+D1AzD/Og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8I-00ERic-1G; Mon, 13 Nov 2023 17:53:58 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b89-00ERSw-1c for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e/bHiIOXseuJfDAQ7M0sJxFhuD7Z1UN5PSGJNGRuwwTbU7kW8f/R6Qm+tzLwomVP6sJA428BHXPwJhMS2WYJ5hWk3ZWapcT1kbyGVt9uxcPT874zGKcPeuzG+BkoQdPMnESt9Uo6DDOTGuxAMcr1CdCoBvk0CgHyNyLiRczOxMU2a4PGI512563jcyZbfFgQ2f5XZUWOBEK2WudwICdepiEmDnGOxNL4jK0OxQyxQtesRhwI/xO7m+L+DDwymOuLLVml1OrbOpNNirdwFqLMv6/OM4zLhTCDxcpRWzLwSlhaz9l2IKBGDccd2RIH6YzzKvFc+c0H8ETMErb7okU4DQ== 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=vK13GwktKs9VvNVuxxg5EuWjteVKUXDw5vsexCCe5UQ=; b=PAkbZ7RjSIAg5mBUyVq9+c8ghv3YYnq6RoDhHsE2Bl2MxpbIShf1w0st5s/RRtsOPLm0RCdNaf8knPplBKwtsjJKtPMLYOiYC91e2tFGP4Z0zjotQBRub5a6EdiGZJwv2AF55XtuMERzNcdWrqwhbx5SF+9CZGi2nV6GMSSo4o56lYEe2smtb4jZiJndD69OTLHSrwH0/JILl4wOjQexg+HfWxa7KDEVnFUqlB7IaMuGIique9EA/4mJ9fVUtQZLL1n8eXAXA5vZUsHbz5WtCV8ICPWBj2qvp3DXTb28h5U23Pr0dG1/gdTugH6Mmv+/Cf6dG1yWt2mnvdEhtHhByA== 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=vK13GwktKs9VvNVuxxg5EuWjteVKUXDw5vsexCCe5UQ=; b=U1UvmgX6/vMPe3vYpjNenmnB8hAES3+73wvx8YUgzLqPKr2cg26r5PMxlbOL3uariDWBT6jC780UVjqPvIyZ54nHNTxMEfYf8LUBNEfx1Gok18W5e2bOCEpaGMb5B6jsBqXxPamhWjYayHjiAAivU9zYvUWRgB4ycaOWfrQvy16vNfsmu42Lt4jugl4plzXFE2a2pBoHSaqlVln6AQXH4nob6cAy49cGduMsyfrHX1VdcUBPygqrC72iLq5DM5rh4+N+FIC70Ah5T7qBeLs3BtYXyEMep8eU64yahRtIXFUiCXjFKBpdlyfyK/Mrov/m6N2DuwGo3uUbSMVONJpOWA== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:32 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53: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 , Shameerali Kolothum Thodi Subject: [PATCH v2 18/19] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Mon, 13 Nov 2023 13:53:25 -0400 Message-ID: <18-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0050.prod.exchangelabs.com (2603:10b6:208:25::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_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: e1db7a4d-739f-47e5-a265-08dbe471706d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JYvoQiJTDhLyQOtNmnIMP1fpvY24A1aX19V7pYZ/MjWfNENfnRL2o++Q5TtPWSLi3HueQdzFpGPQ0bDBgYwsd69jPo4jGRq7+8FpSYUjKlbiELgoRt2GxmiXrlatA+92oPbUrU3ucCkP/WYk1r0BfQUPtP/wV3EKzTyoKxtgjz9Ywd/+nz4Gy/7f+NmvHY27VjyZzykeck4dsq1fxwzNSbxQaA6L7sw/xYoI+iXsPcj50icEsbNUlV8xgkI1+Gp9mRN6pbNx0e7eSXlPEOBCjHP3zTy3LG4FpIPEy2VDivSmnQqKWyalWzN2q63f9qsdZf4e4G3aJsd8xFB54iuMR8yB6qJg4TKe4YQogTy85PAsn+qKavCFFrudcPqNT2hyYOOaO8Giy8cAotNz8+YAca5Wu4hiueRZU4rCvrDm6F+Ra7j2ejgdhcmBi/YiI5NTQVhSLXhQz6TQ29zbSdidpI9juap2fFUqTsz45umbHPNBKz7jEtY18Zc0MKJl1ZRsngrJ5sLgw9hbdDU7Thk/1fbG5/XXGpauTu9P+QyEWr5BpHsz95juw/BxWsimuGp+ 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +rF2XEv6MjcnK/bvgtKeGuZjiVjE0ZDPd4h3SWYQca8I2OV/l0XmOql2G/oSEt0CXVIf1aPTY7q9Iyaixb3iLcrPWIYBAPiP7PQehDR7E7GLOs0cc6UYYdeffWWq6XPQ6R9qk29M+GykhrgHhKovmy3gn0yOC6teLpJNpjM4IRzS63zHOfxfxNWuiVtS1SjDuT6GN0caFZBynrlHITQ8f0gOTtjsaw06rc4SrekjzwKsD7dIvWJ2H6yVa3lIm40t7YfOPt6KjRCqjdHfjpNqeZVe17YWVIw4QX0S5otA9vR7/Ma1I9+J9dSgLy/ceER3By0iptIfRC48oebnsVmTm60aw1ueAehcmqgAOpcdEP9mMqOrrtflKeBZQbwDiOWXRkRW8GTByH5dy/hbe6Vy+1C3NNM/ykdfgPtuBhJXVapqGeZrPm5dB82fKHX0bqCdoFkYOc2UTE8/CEqKQTMX1IMcJVmz3VCr3SHmIIRktV3AedFFXJLv/Ahc7ox2oWCyztmca9Z/9h6r1iTclEmC31dXXuIQ7gqceyeuE9VkQxVA2gmlo4WQG/3/cPTuHCE8efCe7w+aGzr88yrwqJyJhNn82ThIMJi0pojtWhPOxQxgfHgXswt0YRc6Rep/HIOH8QC14sLDI+ChGLrzFB1bpB26kiiBitv+xB1GCarnUfxzlyrVWlvh2tlcj5LHtf5ZLTxmXDoE1KPzpxEqxz8gi9l8SIzGUZXfrkJLjpgw17twHOhQEn7i/FpO9LqnW4i7JS/3mbZtEkdAoDs0SYkUUf1/clVYqwdmCbhEK/tqAHJhFnPh8heh80JKixcoMX3z6KnNZE7TEpSh6yjvsqPdD9+IhCX1/WZpVKov8mcBIbSnl6vREHPU5pTamstHL5fA7FgrpD9YR7pIaz/I2ZMu7qtQhrdURj2x8ulDo1XU5xOJOeZKTIWiDi0U3gg4tobjgf3mpAp6hq8zOezEKkDkcpmj9h+AM5sqpQxzdtJjKOLzwgLPTuyrF3+ssTeFjsI9aF/I45wWCXq28zuc2ZcLyapOiYrNKTuo2YaqSee+xkxcfZSvS2+QMPJFPjjE6Lq/16lkeX+attPElYlK/YFVZ2dJFFsDguXRzgm6lULnF5Gwf3yUCKfi2aHzKlVONVkZZlJgH1CSLY43r/gFlRzFgMVSSRY3Vta2/mAcS8GFzds0wJVmT54vsVzrsAZGPQM9SP0tPeSh4b0DbjKK3Iesk+NHOTFtqA9nIm+IYi6kiy+z+ox/rA9uP0fNUubDmM6234g7JxCuuwpHVaUwXWMuCnLUPJty3Lp89bJQ5XspgDvMdp9ZiHtP8p0mLZwmbsyYn/K258NpQ4AdLgZzJXWXdBDMeaT+ZKEf7x1wmt3oY27YJBvjfwWHOr/cCmFCFeObJp0YFHHcWf0rN6ZiRTH+mBNPQABcN8qRiIet+LyCBjZteBW2zRBxDDYjFUusUNWY5XtDjYq3afQMLF0xYSO3YqAFtoUo8fCWG3HhbulGDN75hVphZHDkVTLRpZV2Z07shSd0U476zryP2wSryzsJkBJEngMLHhc1OaLszKQOFjQ= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1db7a4d-739f-47e5-a265-08dbe471706d X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.2747 (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: aOB2DYIE+XzNXADd7RMLTBHSmhnL9hDmQyRGdVyIghlBFy7CdoS21cwMuGfisaXr X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095349_547870_7002CC64 X-CRM114-Status: GOOD ( 15.80 ) 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 Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 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 331568e086c70a..50c26792391b56 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) { @@ -2216,12 +2218,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; @@ -2253,11 +2255,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 */ @@ -2270,17 +2272,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 *, - struct io_pgtable_cfg *); - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct arm_smmu_device *smmu = smmu_domain->smmu; + int (*finalise_stage_fn)(struct arm_smmu_device *smmu, + struct arm_smmu_domain *smmu_domain, + struct io_pgtable_cfg *pgtbl_cfg); /* Restrict the stage to what we can actually support */ if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) @@ -2319,17 +2321,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; } @@ -2520,10 +2523,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 Mon Nov 13 17:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13454288 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 DBD69C4167B for ; Mon, 13 Nov 2023 17:54:24 +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=snIyxMNtDHqBV1POKGC+Op66kaZQAD6kqwTcgi0egRE=; b=AOydxh0ZZeUGG2 QAaluVxPE4l0KNzNeZQ90cuDnL/m1K5tanKMyefZywMgNC2jZ+1ICpGGW1paahVM7DyFhcYiFCKBD BnkRw0xxN1Z050pNtA3aU2HIAfIVW423eBCkSRjqkppQD/KptBVJ7iD/WalRZ+5GvRgQS98Gy8sn0 Wc0l/okIseinx69GxqJF45fdFQMJdIPbKh2/P/G4MPKYbhN5EClOpFmdRflu0TntYDMcToaQBI2i8 70/twlpYm8VMo9AqD4+nMqkA00L6sA2ITie7r4Dvnj4OnPbtLmffSG4X+M/vlO4jPqu/01PbTOIG1 8dq4xQtkOiNByAc+pp/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2b8H-00ERhR-1E; Mon, 13 Nov 2023 17:53:57 +0000 Received: from mail-mw2nam12on2061e.outbound.protection.outlook.com ([2a01:111:f400:fe5a::61e] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2b89-00ERTJ-1j for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2023 17:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KudphkosTdywq42qwvQa1ms6iPt9722wt5cC+z+12boVG40idn9Xt3AjGU6mh03KJfkPe5c3NMCJvZH+VXj51F5UVm/Ix0O/lAlwWGosrKPe14J8advwT1f2JVkMqlKRIm9fOEHqQb7pH2HDRYx6i2gYSqP9If8SoZsxpIyOYyP2E6waJFr17cBUNoU4iGtIEkzLRb31tcRHWsdASrJTawnbNo7WP1NPIvL/aueLOhPtHzaUWUGQ3fECwWTw8YsqwnDwTX0Me3E9buqPnw/U/u9DGAL9s6/djsTL3lQbPiqIq05I7JfyJ91aoSZQep25xIB+3d5gFT3u/dssOKHFGg== 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=uk/fdQ9QCHCZ0pmWGlv+J0aGKg3vEDZnOZ6jDXsnwZo=; b=P8WvYGSjatSWnKAI64BP+Ck8/E6+ZD/9jrxAFcAH+QS9SuHaY6TDAZG5N4cUOLUoVwYGuyHs2jUvnh4vL8vER1H04lVpZTUo1aZZVRWLLngdaq5uvz33AYlQ8T3ftFZwkOcQqpuDRiGUGJc4dle9MNCMzCq6ju5b2TziMVvBWgZswP0xOj0YLaA5lyjEHOnz1/IK2PDavD7s5zmuQWDAZua5mX8GFnIjsg0mhM46ZyU0GCOYwOprxBC5jfV2mxvTIze7b3ZM6Va7PYgiw9hrFCRQ0D/iYfL6czk9qdli396apH6PqFBQ1CuJaCs8jEFZGTCxmjh7T3CWYbd2zfyvOw== 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=uk/fdQ9QCHCZ0pmWGlv+J0aGKg3vEDZnOZ6jDXsnwZo=; b=VZatcrcAvvXGgn9AGMvpadnwVXVSoE686NxqsQY3ehShJIXqOSF6FbKKSdOh0vkxvhEAIlgF6NzaQe+zJqKjYgrEqrx+ACbw9o6Pqs0ff2bGKMVgRWfVexSL6E36Izx1eymrqp5Li6p7c8tYp9/LZ/NlBcUSOtY3ztBRzFH33oDs1uDX1y3zvRyHhXZBDNgRKI4JBFYQtV7+ZJOegWtw0NiSlSIIReapzGH6OK6Md0HIziFiPlgTA38Vk6/vnmai/r8a712YhZ2SXEH3n8SKeVcE0Qiq4u1csUBMmW2AVTl6+bGDTkKZFCo/9tBohmVMj1z4VWtM40HsZH4wr1R8zg== 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 DM4PR12MB6038.namprd12.prod.outlook.com (2603:10b6:8:ab::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 17:53:33 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 17:53:33 +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 , Shameerali Kolothum Thodi Subject: [PATCH v2 19/19] iommu/arm-smmu-v3: Convert to domain_alloc_paging() Date: Mon, 13 Nov 2023 13:53:26 -0400 Message-ID: <19-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v2-de8b10590bf5+400-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P223CA0003.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::8) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: 152850a8-6479-4ca3-17a1-08dbe4717083 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4rCpi6ZeXL89c0akgyw21vAAyxpoBt4bXHf1owqzmpQfEc8b9iACpwz5xT/pF1J4k3F57xflAJSIhki6cBHM5iYW2IWPFYB5HANG30em4JHKD3SZj4kLGYXi983KUV34YgY54UylaSGLsngAQ3k5lK1HuVcBeOKxlyseMA9h5+pzgxprtuw+y2EY3LsWhchKV4+xVd0au5JCF7JkeEZHZbi/jYBAVzJB07RaiQm/b3nlObJUoQz48mMzrqPK25CwYm8zzbFliu06kA0+lraxsGfh4xuGeJLSr5644QBQVH1qp8u4l4/pshg2DIK8UwvO82KB70c/6natwEUdThgKNOw9qG4n8WB1mspjGqoMA8RTstUqTmHAmF2jyapmNFWl4ebOXNxLWBnRMDSQG9Lwsvlg6Ed9goxPiR86X11v5wh3z/6JAIgdfh2q78zTOVvRB1iZJfBb0QtAXt1hBD0Wexl6OrNM1SMcWGsdJYjtO0w4bc5sCIco1CNAF0gRue5iOALNOClcsgfkSmbkUjQBtj2cPH9Y7N3JRxsACxSxHEEUZ/WF15Z558bJZiC6iyUh 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)(39860400002)(376002)(396003)(346002)(366004)(136003)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(36756003)(26005)(478600001)(6666004)(6486002)(6506007)(316002)(2616005)(6512007)(66556008)(66946007)(110136005)(38100700002)(66476007)(54906003)(5660300002)(8676002)(8936002)(4326008)(2906002)(83380400001)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KKLcuY2og1UrDp/q7nad3jMG2DWa8n7c8iEKccMnnzDnHXVsnv+A3rG9oPduvq065Ml7BsjU4f3UzSxPJct3BXrRy0n/apTBSz1yPMFk1krT8nsuSOALIOOTkF/o/r9GX64pC9n6WOOWXPRc3xQqhtMMPKWcldMNNY3YIEp3MjHVycPqys/3yWCctQA4hlg4QiGtuFbcWG9PK3hEJYHQUZl/k1DjnmZ+dGBKPTvwZ3sn5qoLAszUY4GHaiWOsuheeUlaTx5PbE6H/WEBeFk3lw1eMRatd77GXnEsGmbCrqNdFDyL2ixMXQnytSxIh9Tbsrf/+rrEz5Z+BEEjJxu6SLqaXZ55Myb1wDjmjcxxgNSlRaAN5UkrKGMMJGz+cEE6cpu7o2GfKcHdq9Y7J7qka+0cj2iystWhfFGqLQLn7INQuef1yrHzvyE1HeyB9BkAszEipFuUWC05haJ8+aVSdUts+MS4WG6EOTKP6OFmPXyeaeIexV8mW6op1TDVGOBHSmAfma4W4EMVU+I9qCRkVcjZIrlZJkdr+uWAhjxUiXsEqbMYMzwYXr2DckJWYJslLFXY0Mq4tTT6tTj+70XIsfSzzJ3Sv2YgqNFEK4mDu3bICo+9CDvIQakQ3dGyzkXdAM0b2zuGINxZSLIIZgRAjaPwYida56V7CLHrQ5HB4/AJx24FviAYOw52Yg7r7imNQm4BRapaPvaanopTk6wxi/q9n1eyU7q0BG7+whbFJEIGkFG3P5Wt0lqQPyqVIv6ynbwsem3Ozj/0X+pPXKJT7dkHqTgnorW2n1L5R1XEZbfvhl+bOxd1Wxrd86MYDRbONrOVs7ramc0v2rEU50/MzrOqPtjUoecGJ78zOhSkoxEra+BV5lFwREYdSM4KpoHEA24qgD7NNmOzH45a35lav2Dsz9rHG9DdHx4R7Mm/7blkNnWW4b9iM14JdyWUaXxhsewH9uvZ94yU9BgAcw+bd4P8Bza7iKJcy/6W5kRYNrAedBOfMv68s/ElQUoWqxiYJCdJOWJKaFLASMNJnM/gxwngLTCdC1CCEwx9AC/MtwIJc3YZP8/e+loID/GpV1D3mCKSW9vJAszHGoHHw+V7hIhFF2+W4omK4EcdP4IqWAEo8Quhues4D/D4rFR8CS4UGbuetu1Bqi2FbFBn3lJj9RcuYxVHOpeMDSjlPsa5toTVjav0t96j60DOHKT7EGnkjATI0Z1xXT3zkCQ5EaWpGdGAdJMt0iwNzlXy7yxXTnH2TLS8z0lRU7VnJ3EXqtKkA6j6rc9wV/tk3WdPoXiOC5OO24lqvPtthcL5pHs5tuBBJIbMkvQgLUlkPduaSqEm/jdIVD9HsVlQBeQNjiXkul3NM3dQXH3BHtwVO/r1N0riuGo3lEKQp/bpAWPq3rsEsZh78dG/PtemLtc+LiK6x7jTBU7hbIXixQwCkBwfVMq5mJhZdom2Lqeujh/LIymn13wd4vQx62bk9NeaGJyQea+chSP5JtyYgoBGUXWwTl6t8R+ZIqe2Un71DtEgReYxAWAva01pvGBXuAmKtQzEjxDr/b+5MU/OapzlW9BQpak= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 152850a8-6479-4ca3-17a1-08dbe4717083 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 17:53:27.4050 (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: hgAq64VlO2UaIP8upFsTGsVbqcsmopno6F7PBSBbXWkAG9XkqXL6MkvF9EOVCM7q X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6038 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231113_095349_577274_C78EF0F7 X-CRM114-Status: GOOD ( 12.56 ) 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 Reviewed-by: Nicolin Chen --- 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 50c26792391b56..5667521bd18091 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2170,14 +2170,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. @@ -2193,6 +2194,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; } @@ -3058,6 +3067,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,