From patchwork Mon Feb 26 17:07:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572540 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 D3A79C54E4A for ; Mon, 26 Feb 2024 17:11:49 +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=Q9/jF82G9OQJ6zvj+5xmw1Dk8doDE6n9iEqczdZbu20=; b=ibFqBt8T05i5sp /7ASmruNwJriZfmA9yjLnsdPIFkwGx6EZN04zW/zr296kBMbKYjwixUn/0ULQ3YsklBXWp5cWsYaz kqR4naKldLYTATCs8QiDg1KU2NNjzfwsQoyeWGdc/PnFuyOhhItD3kaXgA/U9F/9SHpOJStOybHqy iSaz0A219cAFKdCzo+pVgYdTaKbF4F/TPhHIVQRdFxWoIwMqqIp9b9zYpatqO3k2b5LvdZPPoxhRn 1YndndSOaW/Z5v8kg+DMSAPkK9bqB9W4lHqKaMu+dPkYdCzHlXZ9kUAdTwf+QDBBymf2KTXJ8gbIl lvPUou126Xx6BiCxOx3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeVm-00000001rVR-3KDA; Mon, 26 Feb 2024 17:11:30 +0000 Received: from mail-sn1nam02on2061d.outbound.protection.outlook.com ([2a01:111:f400:7ea9::61d] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSN-00000001pkC-25Ga for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:08:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O1Z+msfGAnkCwPfAq4+Cm92RkcnzHcO9CfAtHYy7dc6QrxvCrbfiGhfmTjAg3tuE0Iq6yUt3oSVvv2eXPOoi60R2lCtV+o1wFpjk7tW5XJhz6F5fc1exL6hHirOvv5K/Ihde7rYR71WZ1I/xz2iBwnA2iWlnfqzVBoeeG9dnpFrxQ7xD2PcslKtTOnYsx8MHPwzqtvZriJ3LvowhPBrTuPq0XH9k1dpSz8sYdU1zK4Wq0SjuGcFwxG23aLsSdTqefi4M7nF0Vy608V3ORUNaNFOezWUcIfVv/4Bi2ZsL3fHubBreoN268V7KVb5nQIu+S+zSNwlQkvUmxZqR6ZG8Qg== 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=56zE1cCMNvD/FkO8Ni1b2Qx/pMDGtEjDvt+jBWYMAr4=; b=FAcdd8Dy0XvDskZc8H44AedmwGpor7jwgPi7M8fEIUnxcBFzS/vXP5e9evwrn056QinELsr//Q5hB2YykuF/rNe33lGy5O8Lf+rgzGejYARN8BZ4ACiNFO+JjCGO7OP7c4jsTQWO/Fgqatp4OcQB+lUJQshf0dzDvQnF8PxJNywy7pcAXrXZEwAHVLu3UWSdgGroSws7EboLrL7ptQWpGgx+PN2ui+Xiz/VZnESuTGOnwkgGFALuv8V95jfdg5mHyDKe2+vy+mc3x++bPHIh+Clc9pEKtTpjzTKmC1Yge9Mak8eLX+0Gk4h/gg94iyU2oxqroTS1Yg7uQfcKoje66w== 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=56zE1cCMNvD/FkO8Ni1b2Qx/pMDGtEjDvt+jBWYMAr4=; b=cp9timaUHsrVpe5y9jHeQDzfiQrGbPIANPmjkmrMrod7H0VxqycERSBe0UlA4BXJ8dYIy0FydjhN88bCJkB9eDDC+qOCN9zb/0l1M448e2UIm0IwJNNQs54PZM/ChXEqtuc/+AixKuACAyvYFHpZogITsNP4HmWlqvFtXqu/IGWE8F4Ip/EZ8Vy45y5vKMOe5iX29JwaIfq/AXOr+OgyiglNugmOxUx/VCteiIyC2VjQrCASkzvTPaGkNGMNc9/UsW+iTnOB89K1JUw5yHaATTVgrUsmKiPCQtQc7wAHzvDsdCv2zXr0POUPaPqUP1zVy+XemM43esnqXOwArGqW3Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:35 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:35 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 01/16] iommu/arm-smmu-v3: Make STE programming independent of the callers Date: Mon, 26 Feb 2024 13:07:12 -0400 Message-ID: <1-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0009.namprd15.prod.outlook.com (2603:10b6:207:17::22) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 4cccee0a-e3f9-4c5b-cc68-08dc36ed6aa0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3VLjCs3x/C9fPZoq0GrcbQQMrNrHIEfhO3rLQJ7Ss/3r3+BJUUwbYqg4IPFeBj42b8V8PUhn0tpXY2tRyKfg53I0ouAvJ0j4VdS4OvPvNoC5ltDg0/XnL456xUkCc4Mq3QN91C6mhvItK4l4YjPQy5oXjuF6H0RdUUJKE04zogsQyKpSLNT9RLO5n7KI8VWnKF1Ft3xMy2pDBI/6fD9JLXGpPLM7brJXSV2voBuUrr47f0e78Dfz71J9PAIexbBpX+2tgzr8QNcgkB+fMqyY8wMMLSWIQpQF3ptBe/xWTmuRJv6VAmonCJ/wb3bx+AbxUApaU3l4v5hyz5WfWOOZ97yxsrQ6UU4WSv7gU3FuMMy7A495wPloqC2GV58oce+1I2Q7aGSGYnOtLAkusmWms/calfiM6LIlo/H3Nx9SgV9O/BLhGX3+qtFRIZ6tKh8vPYHoJt67lRst2qwh41rWgIC3bDXpG0mBcjk5iEr53oZLzParY+UvB9Fw0zawBI1OZ84UEpfAyvl8krzr4HbjcmvN/pwLwX52nbtMO4oLvkez8m6nblFti4ROIAhmNuar9erkIdztLBwbPtADeOIw2pX/B0C7Gt+Ld/NtKHP7BjRIXZr0jkWBiQ+nlOqPyVIMyszuXywh3VgEWmcKY5zMEw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UYn9QZIgtzvaJhJZcWuaKKNri0XNt4KdOfO3BKF3TNqVYRac1oVmQAmzvz3x6fK319uTyV6STiCZeFuCbPGV+HhFbGBSA2lv+G3pYmZAfQDFzzBEG0aMaR4dGAtjrfihLW2LEUHMK/1P4Tku/M7P0IKvStWaz9FQz0qHraWMoohwrR4HRsZMgGoGaICJwgGB5+9NGn6gXyPFV40ss1Ft4H0mXpu/Ou29IjUYh1bg+nbTV9DqA6UKtOgPSxX6wABFrOb6njeExtgjKThMh95PSqBfTf2aFHY+5QYAZ/qCNUpZvWGxAmHaD2sPix0xAd9wSvZZ24l/xEK43ClJWppXF31nkpjf4NhiiR4LIWcz/UxHUuO/IFP86Jqcgb95I4tnn9UDJMwbdtoLFQRHb7O6l0s3ZvTGqjJBMafHZofs432ml8prWE/N1gRNVOsGPb8iMmpiy53CugJwC27DUD7tCq3cU1Ozx9UcvZuPJjMwBrdcD26L6NuJodUCEllzRBJeqsXPmlXsyzFBkbhmMAjSyQjUloJGKQ0grKPDoGYiWO4XGhQsWvI9Q6syHLi/uLT7dexLs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-cc68-08dc36ed6aa0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.5950 (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: YxACDlowARtQenH5OzDmNBc8ENoK3BA9Qm5i4RaGauYM7bjtHzEVn4alU/tIgZ5Y X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090759_858459_992D5510 X-CRM114-Status: GOOD ( 35.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 iommu core APIs would ideally expect the driver to do a hitless change of iommu_domain in a number of cases: - RESV_DIRECT support wants IDENTITY -> DMA -> IDENTITY to be hitless for the RESV ranges - PASID upgrade has IDENTIY on the RID with no PASID then a PASID paging domain installed. The RID should not be impacted - PASID downgrade has IDENTIY on the RID and all PASID's removed. The RID should not be impacted - RID does PAGING -> BLOCKING with active PASID, PASID's should not be impacted - NESTING -> NESTING for carrying all the above hitless cases in a VM into the hypervisor. To comprehensively emulate the HW in a VM we should assume the VM OS is running logic like this and expecting hitless updates to be relayed to real HW. For CD updates arm_smmu_write_ctx_desc() has a similar comment explaining how limited it is, and the driver does have a need for hitless CD updates: - SMMUv3 BTM S1 ASID re-label - SVA mm release should change the CD to answert not-present to all requests without allowing logging (EPD0) The next patches/series are going to start removing some of this logic from the callers, and add more complex state combinations than currently. At the end everything that can be hitless will be hitless, including all of the above. Introduce arm_smmu_write_ste() which will run through the multi-qword programming sequence to avoid creating an incoherent 'torn' STE in the HW caches. It automatically detects which of two algorithms to use: 1) The disruptive V=0 update described in the spec which disrupts the entry and does three syncs to make the change: - Write V=0 to QWORD 0 - Write the entire STE except QWORD 0 - Write QWORD 0 2) A hitless update algorithm that follows the same rational that the driver already uses. It is safe to change IGNORED bits that HW doesn't use: - Write the target value into all currently unused bits - Write a single QWORD, this makes the new STE live atomically - Ensure now unused bits are 0 The detection of which path to use and the implementation of the hitless update rely on a "used bitmask" describing what bits the HW is actually using based on the V/CFG/etc bits. This flows from the spec language, typically indicated as IGNORED. Knowing which bits the HW is using we can update the bits it does not use and then compute how many QWORDS need to be changed. If only one qword needs to be updated the hitless algorithm is possible. Later patches will include CD updates in this mechanism so make the implementation generic using a struct arm_smmu_entry_writer and struct arm_smmu_entry_writer_ops to abstract the differences between STE and CD to be plugged in. 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. Add STRTAB_STE_1_SHCFG_INCOMING to s2_cfg, this was editing the STE in place and subtly inherited the value of data[1] from abort/bypass. Signed-off-by: Michael Shavit Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 275 +++++++++++++++----- 1 file changed, 211 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 0ffb1cf17e0b2e..9805d989dafd79 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -48,6 +48,9 @@ enum arm_smmu_msi_index { ARM_SMMU_MAX_MSIS, }; +static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, + ioasid_t sid); + static phys_addr_t arm_smmu_msi_cfg[ARM_SMMU_MAX_MSIS][3] = { [EVTQ_MSI_INDEX] = { ARM_SMMU_EVTQ_IRQ_CFG0, @@ -971,6 +974,199 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid) 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) +{ + unsigned int cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(ent->data[0])); + + used_bits->data[0] = cpu_to_le64(STRTAB_STE_0_V); + if (!(ent->data[0] & cpu_to_le64(STRTAB_STE_0_V))) + return; + + used_bits->data[0] |= cpu_to_le64(STRTAB_STE_0_CFG); + + /* S1 translates */ + if (cfg & BIT(0)) { + 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 | + STRTAB_STE_1_EATS); + used_bits->data[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID); + } + + /* S2 translates */ + if (cfg & BIT(1)) { + 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); + } + + if (cfg == STRTAB_STE_0_CFG_BYPASS) + used_bits->data[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); +} + +/* + * Figure out if we can do a hitless update of entry to become target. Returns a + * bit mask where 1 indicates that qword needs to be set disruptively. + * unused_update is an intermediate value of entry that has unused bits set to + * their new values. + */ +static u8 arm_smmu_entry_qword_diff(const struct arm_smmu_ste *entry, + const struct arm_smmu_ste *target, + struct arm_smmu_ste *unused_update) +{ + struct arm_smmu_ste target_used = {}; + struct arm_smmu_ste cur_used = {}; + u8 used_qword_diff = 0; + unsigned int i; + + arm_smmu_get_ste_used(entry, &cur_used); + arm_smmu_get_ste_used(target, &target_used); + + for (i = 0; i != ARRAY_SIZE(target_used.data); i++) { + /* + * Check that masks are up to date, the make functions are not + * allowed to set a bit to 1 if the used function doesn't say it + * is used. + */ + WARN_ON_ONCE(target->data[i] & ~target_used.data[i]); + + /* Bits can change because they are not currently being used */ + unused_update->data[i] = (entry->data[i] & cur_used.data[i]) | + (target->data[i] & ~cur_used.data[i]); + /* + * Each bit indicates that a used bit in a qword needs to be + * changed after unused_update is applied. + */ + if ((unused_update->data[i] & target_used.data[i]) != + target->data[i]) + used_qword_diff |= 1 << i; + } + return used_qword_diff; +} + +static bool entry_set(struct arm_smmu_device *smmu, ioasid_t sid, + struct arm_smmu_ste *entry, + const struct arm_smmu_ste *target, unsigned int start, + unsigned int len) +{ + bool changed = false; + unsigned int i; + + for (i = start; len != 0; len--, i++) { + if (entry->data[i] != target->data[i]) { + WRITE_ONCE(entry->data[i], target->data[i]); + changed = true; + } + } + + if (changed) + arm_smmu_sync_ste_for_sid(smmu, sid); + return changed; +} + +/* + * Update the STE/CD to the target configuration. The transition from the + * current entry to the target entry takes place over multiple steps that + * attempts to make the transition hitless if possible. This function takes care + * not to create a situation where the HW can perceive 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 difference between the current value and the target value is analyzed to + * determine which of three updates are required - disruptive, hitless or no + * change. + * + * In the most general disruptive case we can make any update in three steps: + * - Disrupting the entry (V=0) + * - Fill now unused qwords, execpt qword 0 which contains V + * - Make qword 0 have the final value and valid (V=1) with a 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. This relies on the IGNORED behavior described in the + * specification. + */ +static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, + struct arm_smmu_ste *entry, + const struct arm_smmu_ste *target) +{ + unsigned int num_entry_qwords = ARRAY_SIZE(target->data); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_ste unused_update; + u8 used_qword_diff; + + used_qword_diff = + arm_smmu_entry_qword_diff(entry, target, &unused_update); + if (hweight8(used_qword_diff) == 1) { + /* + * Only one qword needs its used bits to be changed. This is a + * hitless update, update all bits the current STE is ignoring + * to their new values, then update a single "critical qword" to + * change the STE and finally 0 out any bits that are now unused + * in the target configuration. + */ + unsigned int critical_qword_index = ffs(used_qword_diff) - 1; + + /* + * Skip writing unused bits in the critical qword since we'll be + * writing it in the next step anyways. This can save a sync + * when the only change is in that qword. + */ + unused_update.data[critical_qword_index] = + entry->data[critical_qword_index]; + entry_set(smmu, sid, entry, &unused_update, 0, num_entry_qwords); + entry_set(smmu, sid, entry, target, critical_qword_index, 1); + entry_set(smmu, sid, entry, target, 0, num_entry_qwords); + } else if (used_qword_diff) { + /* + * At least two qwords need their inuse bits to be changed. This + * requires a breaking update, zero the V bit, write all qwords + * but 0, then set qword 0 + */ + unused_update.data[0] = entry->data[0] & (~STRTAB_STE_0_V); + entry_set(smmu, sid, entry, &unused_update, 0, 1); + entry_set(smmu, sid, entry, target, 1, num_entry_qwords - 1); + entry_set(smmu, sid, entry, target, 0, 1); + } else { + /* + * No inuse bit changed. Sanity check that all unused bits are 0 + * in the entry. The target was already sanity checked by + * compute_qword_diff(). + */ + WARN_ON_ONCE( + entry_set(smmu, sid, entry, target, 0, num_entry_qwords)); + } + + /* 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_sync_cd(struct arm_smmu_master *master, int ssid, bool leaf) { @@ -1254,34 +1450,12 @@ 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, 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) { @@ -1296,22 +1470,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; @@ -1322,16 +1480,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(master, sid, dst, &target); return; } @@ -1339,8 +1492,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) | @@ -1349,7 +1501,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) | @@ -1358,8 +1510,9 @@ 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[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, + STRTAB_STE_1_SHCFG_INCOMING)); + 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 @@ -1368,23 +1521,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(master, sid, dst, &target); } static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, From patchwork Mon Feb 26 17:07:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572525 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 B019AC5478C for ; Mon, 26 Feb 2024 17:09:00 +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=tWJVJObUCW5UVrQEGuS+WoPbqPM88jin2so2jdpc61s=; b=4V+R09hcPhWAwk jz9SlAMmdXAyal5ZrXcrQXXU8aHd1rsO6YHQGk579H3N8H50J1GuLM16PSDP/YhJ7SEgv99pAVO9d IMYkHx7FbOrbSWq2vP8XMGjMwbJSavMlyWFs+10mjJXa0Hc4cRkbPgCjq+rvTHkmdXdHcnuSrKisJ 5LQXFQl8vhVUzWgXCMx+grKL8TOYvP4iL07vyKtbwzfLSCrbEAACo+zvL95hyAyj0xuGhOvfoVnzX 4ote64F7Xk3UtJ2HZhtG8giHkI2rhXuuotCVSmBCEHe3fQHQI7IMospjoXWS+2jODegTk+FgUxtVr c+2TU7Nn0tuajBBYGGEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeT4-00000001qGX-2xSE; Mon, 26 Feb 2024 17:08:42 +0000 Received: from mail-sn1nam02on2061d.outbound.protection.outlook.com ([2a01:111:f400:7ea9::61d] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSD-00000001pkC-449M for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DV2kHTsbTU5gOBk/DijmRaCHpGfxlJEWBSDgeECulBE6fRLfFFPSEwa40z+zg26jG6jorjIFzD8e4pNz8Xj2WaXlLBP3gZAqwZ9InnPt89qowsyz1B+kW2wLGegPLk74pDUS5e+tUUouxHYU6u74ZynvKgZiZDRcd0aFtMawR19bdodBpNsicDT9LjD0+a6PqucMmVIVKvBDL9Ixh/qwRXnImoYb+o71+Q02ZpMQCMcDc6+A+3Hf2pvTwIL1j92PhgSXG9/Fxb4FYLLzzZr2TFKTXiySyCrFgRkDVaxXWhwDhoW7TbbDoLCe/24emJ1F6qvRhj6RdpLY6KnCjYEgKg== 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=CD0+FHrIzPyJO85Q97dh3teCEo7kSfrLDHD10sjtyxI=; b=RSShp/B3l4mhBXN1/hFKmUwNKMJtO81F1km+pBftT2eDmvPJNQQ14XPlVd31IZW/qrl7AnY9qxU0OfsTyWUm4teSP8vB3gHStNEY7UnJEvq3bYbG59oAN0Q5TerIvefMNZ7juPzNBKhFWCWcG29nVrTePp6RGjUM5Hecor+y611AnkItikYDiAvAfGvxaXgA47apoOa/kuy9UjYyXoErgIpiZejBuvDCubbrNXLoUolctzVk8VyrKi++ZWqMpMsugoH/RefGuJuP0D1ciKKb7wKUTh8KDMCSOQ7PynZhePL3xkJ2UMPrPVAERFJ6y4/5cwLdMYR4cm6ENIa7kreXkQ== 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=CD0+FHrIzPyJO85Q97dh3teCEo7kSfrLDHD10sjtyxI=; b=H+PBDRku3EMgb4mD2jqM/RgYct/2MKIotUys8bOnC/FmRjyxeYktPapLor9zM4XDe0Y7RUU/IF6lg0bi4Ztva2dnZSBsMuEzYWzz23796CVYxnwCCVe6uaDClOW0iL1QBGlU56wbZXuBb17oxWISYVnA8xfgOBeo/Pl6qd5346ioKZAuZb5+hmZYsIS32h7Lq9nxoT+wSaTzpWs8+peT4WWj8Pf5bYRqeqNnYGc+FcXPoVNceS4+oOg5t4AJ9l92AJLujg7AOEHQs3mk+9R032PphRpbE6nq6dwexmBYC03OaN0MH2PwDjuB4ei3PJ1NbLDx/54Ps3OEs/+ne/JWpg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:33 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 02/16] iommu/arm-smmu-v3: Consolidate the STE generation for abort/bypass Date: Mon, 26 Feb 2024 13:07:13 -0400 Message-ID: <2-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR03CA0020.namprd03.prod.outlook.com (2603:10b6:208:23a::25) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 8889dac3-5f55-4258-1997-08dc36ed6a5e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pod089Eo3tsKlOCGtDEshuW3U0RD8KJr6WkK6/4UHuf7eu7xN4R7RTCdAy8rBF2UQdUNEOv0IPbEzEQAGxl1r9y3i6/+Q58EarCKW9DoKnGucHdBVAUEuziGDI46ZP5geno8TJL2zb945jFmGy8YmQTJtZ++ia1YLBZKJdixrIKUPo2zGTxc2YgQ8FbONYOAueR0MhEF2c+NhgdcH5wfleZ6simdDWqMGmvoFOgwjfTzFHZ9T/IFzsD6lFvq/8i6rpospRwrwi9DybTPgPV3C0p4o09cizUrQCGM/JzvQkb668H6Db8YnwpfEmfdYukATyecBLEIquoA7KKvX4oG4APNeT0dlDmrpJgOClt7LrvIKwSARN3dgS8K7e/Zl0qwH/ZbvijTM+wl15TzmU2NXKgWf6xZ5QjdJjblREKqbgpbURgk/POk4YOAB4zxyBhZJ9ZuZ8xhS0gPZVIMee2AT1ZqQ7D0wQJd+m5oI9H1Lxy6QjqUifbdgsFkT4jDRv8hZ9GTGfizyyrkOlR8kjZdbmoD/jpZvyX9mrg7a+vvspUEItm3DzMUH6PjvKcZZtQojPTapJqaG2f791fLwuGFFahPEb87WKgCrYLYkZLv9Z+BDaxFREbUptTB9FXGQzY+ocpAMQNVmnkb949qmrgQ9Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: M1suTowiZ5bMPht+LI0Ks6QKC0cr7faGQhaAkyqtf5exBsUJkmbVfLmLTpuEcttTR9i2WS4s94pRbVZ8qSLiGbnsIEVey5PGWFB/nv02MQA+27nnqqG6wIFNjuSYUo1e1uuTAYncJ4x7eaNcEckgGhM1Vl/c5dvxbK5F6yAiaP1N9kj78265RLxuTz2qWI6+iag8esGD9X9bBWmb5GgMaiHS3r0M5iXixz0PBlxadMd3ItG2+DuOn8wWn94h0y7nYFKxQCz2KXh6pfrA1SxV/nVH2BVtBWfqrfsCZRKvN8PhiJxRsPPhHe8gx7En+OM4/7j3C/2yAbwM1n0TRALojpyrQ4nnmLAZ+2RdFDe6WeT4zGDZNTPdyOAzvzNBPU+AHYdqHytVRjNu0aX8NltUFXi3DEu3Z5kfT1d8pRtXtPfobEharXDs+Eegf0T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Dj7i3zdzNKAQgoniaNJumc4sabKDCKuFmzHrc2xWYT6CRdu6iUOw0rj+KXDkGBnqWpMR7Lh6f3WI6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8889dac3-5f55-4258-1997-08dc36ed6a5e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.1113 (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: Ty3zT2IZ20iHH6UP4pojYL//ob5tIZsj0NyNhEfxT2sTKcq/oJdU2+jCVNq5CiFE X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090750_605317_7A806EA1 X-CRM114-Status: GOOD ( 16.47 ) 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. Rename arm_smmu_init_bypass_stes() to arm_smmu_init_initial_stes() to better reflect its purpose. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 99 ++++++++++++--------- 1 file changed, 56 insertions(+), 43 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 9805d989dafd79..12ba1b97d696c9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1447,6 +1447,24 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } +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) { @@ -1457,37 +1475,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(master, 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(master, 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(master, 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; @@ -1534,22 +1546,20 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, arm_smmu_write_ste(master, sid, dst, &target); } -static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, - unsigned int nent, bool force) +/* + * This can safely directly manipulate the STE memory without a sync sequence + * because the STE table has not been installed in the SMMU yet. + */ +static void arm_smmu_init_initial_stes(struct arm_smmu_ste *strtab, + 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++; } } @@ -1577,7 +1587,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_initial_stes(desc->l2ptr, 1 << STRTAB_SPLIT); arm_smmu_write_strtab_l1_desc(strtab, desc); return 0; } @@ -3196,7 +3206,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_initial_stes(strtab, cfg->num_l1_ents); return 0; } @@ -3907,7 +3917,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; @@ -3920,8 +3929,12 @@ 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); + /* + * STE table is not programmed to HW, see + * arm_smmu_initial_bypass_stes() + */ + arm_smmu_make_bypass_ste( + arm_smmu_get_step_for_sid(smmu, rmr->sids[i])); } } From patchwork Mon Feb 26 17:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572520 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 EE747C5478C for ; Mon, 26 Feb 2024 17:08:01 +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=7NnRo3TAn+wdD+yA9ezO9rzzGTCe7RtUmYNsik4zBZw=; b=cd5Y8qoomxesYF ZdDtDB7aivNMEx2YZnhELl2IXBTLAVVQqf4r0rdhGdqNnfHhkfur6Jhoe1AIeSpXw2yAsHbioXFmV k1OebDanVfo0UWwYVr30n0fjtYS5ZqeoMx7GPDuFoatT2fOePwsLwKWsoZFABCAu/DrGdsboqz0MS 5CXw1s6KSKlUboqLuHT02ZI7lkNQxvVtiCSBEG0GRI7wlMpHi8Ll5HAuyYYym4KM6huPz60aroFUN 2Wrr7TomYGvG3ejUj6JrOGFx4OgEQcjzFq+eBNHOoTAJMq/0b3/8YRsV1ma62qpUqhShLCKyV+/Q9 G2b+YOnA4dQppT6XuX3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS7-00000001pkV-2QnW; Mon, 26 Feb 2024 17:07:44 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS2-00000001ph5-3ITD for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QGEQajO/QDwp8TUxVnRUdE8j/CFaJHU0BMVBl8Ts/vboSQ72bIim0qcSecXVkdXGERFHTheucs6RFmJv7lZAHF5P++s/crnz8i8mPCBQlmPQeWYB5H89ITJGZIVQx+r8oxVpZvmARhvLZYHNt0cm6x4WyJ3HdcH6Fdygl2ZvKZ5bEBvHRroRd4ANn/CMv7yb4ndvLhci8eLMbJPNVXWIdDMnmOMPwppsso4qoEt/3tG5cRdkSrnaKKjjZkpZXHr3njq8gos73HHvB2PebXYNEmIIO6aAG0C7s2A/4WigqhuaK+mmEGJQebjF+NZ9tCI4Wym1blvNHEW/JC33C1OBmw== 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=4YMRf8eUCowtHepCIhiLLHq4UmIUqrl2p80RhAD5JIU=; b=JiOk/wau2+bScju112cGxm7nLpvCaEAVMtDlOG3hQervWHd/4K2SKWJdsW9ccQ2/twKmsCQNS4gvgVpVGq60HHfsyyRsVsoc6KVFtKBZdisFiY10Uv8JOkF+12SZpRq1MoaSHp5RVaSAYNzhgkgSX4nWSsqW8E/T+T/uXwOeeJM/ovg+fIuY/61tFnYHKlcialCRhj9Is1BJj0zBEqX6UqH4iV26IOfLmBbXpZx9AqfHkAjUYkVYig/fNyGK4DZPZTpDsi2c2DNDI7VQdvnlKuA6D5xaiV6d4o8XABV5XMqGP1jkgw+NQZtHahSfJd+r1FHkI6O+q3vl+yh4kmkfyQ== 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=4YMRf8eUCowtHepCIhiLLHq4UmIUqrl2p80RhAD5JIU=; b=gUdTMNY0TuRMpVPuWa2hMm9Wh/6U+PZvb3NFIvifYDY/Nr52lOoWlAy0g0Od27Hazjhw5p2UdeTO2y7Y6lD7/eQlaDt4fgrZp9m1GB/fmNOWMJcQ15qNHilnzHu3b2D8iVZPHCDdsx8iYxPVXtI+O0l124JZ0fdh7QionLcgcPnsTDJBs31caZ6f5ovBIKmMTxx6XIcnXey4JgMKvLQVfXvse6lWezTS51XqeExnrJfnoPrzml3SdytknRz2T9iop2ewsdq1nqg2tdTNE5B0BCdhBzs0dppL4y0JXzD331GSTddEP2Dhz6ikWBpufAULOa76ni5CivmRYttGT7WA3g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:30 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 03/16] iommu/arm-smmu-v3: Move the STE generation for S1 and S2 domains into functions Date: Mon, 26 Feb 2024 13:07:14 -0400 Message-ID: <3-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0002.namprd15.prod.outlook.com (2603:10b6:207:17::15) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e48be36-d683-48e6-5a54-08dc36ed69c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JWYY0usYDwkjyNrni9y8y7G31KzCfLnuHCWCvjiPLYX+Su3qDm1+PEChUcFmMUFlBG8xN4FH1NG1II+qcOQTh6t5jW5Grtq0WH2FAZNkkacy3WjyS/Ew81BZWWas/3FOku3viDD4q12fJchWs8eGFLNhD7uszOQf1YZ2EFrFql1qM8tFKL5OU3K/t6k9/gd1TT9e2Ft5u/75g/Njwm+95mp/31qiMZ63B+YzksnxGkVtmJADNSrnERUg99vvbyqgaxeQNeCBVgx+dBxpvfQ/v/+S0ksFCB2OQJrnYWKzKA6GcvslK62+QszfmvRyElHLzSbt1Jv9//beysn1He2m9fTAR8Qk+oaIsahqLYBFeO60SEQlawoquJCPOW8a1EyYchUtX/55QS+n9PnfTNijShLa+9/6ltVa3/4c8YGkQ+iqtVRhzKy/x/V6gZOJzsKVbUdseyfjakGBXprYwk9pjq9/8vRzHLqMUPjcYOtDMt+62sNLO1YF/Yy89l4bh/bdZB0mIROP8yWwrinnMfa9bt6UYTLONUSa+T9/2KwABW52uo2E+7rC1XMd4KkymQ9a7hXNvWiBBUT0NIVlltIkIMXfyi11Sdm8Eia1ReQ1MtZy5KpTpl1rEeGRN2MpJDLH/j1T5iHUVMenGXVESux0/A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K3GOCZiADwN8pKM5x6rvdfHGrwUKBKTqPGE1XqlswQyMY+RITHp8OIPiFJ/TGgsd009F7KCz7i7BZiqE21auwf92HjPMSDPVFQBMquzOm4RUal8Y2c8Rjgha+AO82XXEgxz6fCApyoKiPOg+BKoeZcPWt/LiH3O+lfg/76NFoJEFvgYIII+Udm6rMIo8f2Lb6oqhLd/SlB60nekMHrmkbButaep2rtRbn/yLTm/6XVuhVV0boB0ytBNZTw6QeoeIwV0GwiDty4yLADIVfWasNFveHmJbm07rSKmyIUpTZ6+Y/e3hnFH/y0J/42QCgWuvdgv5uDWkihztta7jQXW21I8pIhnCshm4schj3Eau+pG4GDnY9B6rvbSYpIklsEpHvA3l1LTnNmwfg9ZgSnv//Mtm92OQXj8QF1P5vEdP1CJcvlFL+t6HB+pcvt5WLWT2GQg+hTDDfBMfjWkwVUaUAa8NvKuiwabnm/lc0pqLAJjS2Hk0KolnQLKh+sPygAnoYNNtrt6rgOah6J6GBzqCtwidfInJxLnVy+SsLidZdlzesUbecjguQcrL9qMQffBaTp7Z1vh7HSc83FY6oEsVSk79He3cuNKOd7biCeRrzdeuDMrzvxZg/4uXZ4lGwRa8Xo6i5/tVanBKp/9Vq2HPDJpVvh1kOITZiXDhqGCClZ458yCRuIEa/zkibOe24h9af1ZX948aIpNoBBmh7B+E1f4Wg2sI4LxDULVqx8yzAgFzDRUeY20Z+X7i7FkqxCCzKHSVn4X5d2TfuX4inA55EzjeM3vu9LQvcpI5eaXLb7Yw0Mty8pmrcilIelO/I/z5lxPFoLSPzKn5ydEUuvqHXapQQqpY1RkFoWBsMs9xf5EijrZQUwG+iDMlLoXIStkB6oc6zV5q8IC8KauwGjDkdbvBC6cgWh73YlzdXsOqikVfVonjv4X6VioU+cSdu4VbOdfDlP/S6CyI1BgrKzGHpNT0LRCpp+L/b2H+f0B7T7WpaiXMDr0vlw0UIDD+SD7lRWtiIAnQ0tRBUq4fwgx/bweDOP6CJHSQ9/4yHnNXZsP14wLmQmcEhZFDjZ2ud6Cza0LUTCmvHd5ZYCU/sXovOVvpdLYfYLH1lymNgKPciTL6Qa2xoVOwGbqF/rzPQ6YWLhGMNc7km3d9Y6oEb/wm51RSRhKyM4jIOgeiqNDFesLIvsUNG61EZmBOnPRVljdu1EB3/joPi9DU13HuqnGVlXRKL1sQSvPWyOvSlehe7g88IXISbjv/BUCsOohQBphMjb5JGKJ0uz/ZV/hlNb6DJgQqpsHlBuzJZHoW5DOCUaatet3T1O/O994vk7wTzOd6G/JgmAF+XPv1JozowmkQlS84+XYatvHvb+Yy4TcNqyhXySB2HJG6kIQVDhzcINSrI9ErOQhxCWdE2VjDuXZAPJBFsSGt0CH5GMD2qYA9YiFvFvknW02VlXoyCUWVulCRkngasIxrOhtWAXu3nSLS0eSGESVLqcTIUKRK/MCFLf7U2bEDa86uQSYUrU9lTEAIRqcbiPBenUYJg5Rl3KkBZ/lIj66FdlpqHTbyUzzfvQg= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e48be36-d683-48e6-5a54-08dc36ed69c8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.2244 (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: hWkxMrzVF8jHvrhBWiAHmUn55WRioPTcBWAOnTPusMcBljduaUCrawX3/BnPGKOV X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090738_969623_A3BA458C X-CRM114-Status: GOOD ( 15.46 ) 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. Reviewed-by: Moritz Fischer Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 138 ++++++++++++-------- 1 file changed, 83 insertions(+), 55 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 12ba1b97d696c9..e34c3181966934 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1465,13 +1465,89 @@ 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 = &master->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)); + + if (smmu->features & ARM_SMMU_FEAT_E2H) { + /* + * To support BTM the streamworld needs to match the + * configuration of the CPU so that the ASID broadcasts are + * properly matched. This means either S/NS-EL2-E2H (hypervisor) + * or NS-EL1 (guest). Since an SVA domain can be installed in a + * PASID this should always use a BTM compatible configuration + * if the HW supports it. + */ + target->data[1] |= cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_EL2)); + } else { + target->data[1] |= cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_NSEL1)); + + /* + * VMID 0 is reserved for stage-2 bypass EL1 STEs, see + * arm_smmu_domain_alloc_id() + */ + target->data[2] = + cpu_to_le64(FIELD_PREP(STRTAB_STE_2_S2VMID, 0)); + } +} + +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) | + FIELD_PREP(STRTAB_STE_1_SHCFG, + STRTAB_STE_1_SHCFG_INCOMING)); + + 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 = {}; @@ -1486,63 +1562,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); 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(master, 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[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, - STRTAB_STE_1_SHCFG_INCOMING)); - 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(master, sid, dst, &target); } From patchwork Mon Feb 26 17:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFB5AC48BF6 for ; Mon, 26 Feb 2024 17:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5cU7+lRkTp3RpPemiuTWWgLVPecYAf1+v/BfvdWh1ZA=; b=T17OI0a3qsFnQi gjNO0ddJuiBSE0Gf26ZeSjepEgaqvD+r0jAnZjphxXIyPPv+LW4EUYxHpp4PUajkVmzDaWQR5ETgg XyHlRmfc16IqVl/tNX3KHGjmMVQMd1O255lREBynJPEbaUq3qBx3LDt59ELef3dJD3i2lLNusiany nOgI40VGcY+Is0DaVoXrlLSf6jUuKNRmgIf1R/twWUePDA3XF5oEali6nRPwwzUjR2pkbMe7dDCFU TeVilxorlKMqxHfuMy16CZFP1pNgli6OStquyKzsp430YnS0oRkqpPwDdtFRMDrPm+SxS0eFdWGWe N40TzV38+qstKTT/tksQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeT7-00000001qIK-1EqX; Mon, 26 Feb 2024 17:08:45 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS7-00000001ph5-04SL for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/Ag6Q2/mFaivBdDIPyjVVNf6pHkHEPzVRFuu+hnOnKwACjPBMeeW+IMbJjw/9AXAm+ECaLmKdV9agD/2QgM0THqUnJv5Devbr0vhivzP/YmvZD2bg0SABT07WWLELFd9k07V7kBE7+ibt2UvJLdUF8H0G6om9FPGD1ejBD67d+skj0xJkelGZge56a/8j1J9VTU4E845qisJ70hY7WN8S5cKPpUG7QNZ1MiouxXk0zDPktDfxFWV6F4yQ7CmZf/VgsXnZ/CrfPDDfA1LEx3Ak6wx86Z4ZoTARTs1Pkv9qDFiNscPO/lkCVO5cUavFeBSIvaxOuoTEqvgq3ZKokWMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C88f9NuSQXK5UjVS+I4LS+ehiwyTVUnej0TZ9JTb3G4=; b=Apg3+AdDDndigK/dMA/xbVVWG6QvFMDXnX+pycThHYn0kw7ADUzYeLSpSlM7faj9/O0qsjf8NiG9MT6wK+qJ79KlZo9NfwElth5fpNQvCkiBlvLnsycdovVQFKddChYxQ3tJaMDNx0CG7V+yOcEqTvkOKDYaU61MOs6R7rgXQt7Te7+OyO5eBKiDaZEXe7gNE1kqbA7LPn9ctVEUnB7nr4X4Zhv4M/RSOGSoIMJJsdmuElE3tOwnWupjLN/0TGmXfAzZ47fk1lcNyIfLx3M5hhtAUdEimh8G4cD90jLs2+J9FeQ81q87X78KdqTHqzqCn43psB5KNOLiG3lbVK03LA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C88f9NuSQXK5UjVS+I4LS+ehiwyTVUnej0TZ9JTb3G4=; b=HkigGeogwXx0579vSZUL1uk3mj2rVwLsEiV65XhbxiWs4GttevpTw+vMiqwS3YWw850GIrHXTapwhTrjf79NLmuX1EEhSGOEI+uPPUNwD9n1qd32EzxSciGasROCCsSU0SixTlD+k6R/Tqgpstp7W4bPsC1N0DymwaMBerFfcLug1XBslE20i3A7wxhPEaiH6bogHjBQVdkeVSfweCR9PdcyfHNWjpi+uO4tD2EFPH53hvcX1QONvKPQkp1QzvIWmBspIa2PN9ZuWvibZ9eVClxk+D8XNkzJfgCuCIwMTE+ztEBdHXz9QDNxobXFOzAhxk4/mXfuasQQ+McpPs1gkA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:31 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 04/16] iommu/arm-smmu-v3: Build the whole STE in arm_smmu_make_s2_domain_ste() Date: Mon, 26 Feb 2024 13:07:15 -0400 Message-ID: <4-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0035.namprd15.prod.outlook.com (2603:10b6:207:17::48) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: b74601dc-1721-451a-b01e-08dc36ed6a0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s/Gnk3EihsfFpUaKSJL+epbtoFwLkKUV8CE/uTQgDhPxpUOrniZ33jJgvGHIMvS0oqE1I3DySfU4Bp2/x39F/bH2wC+0tzX5iRUtXinPPO0DCzFmpWvMUOOQNCoh2qHB0mGUG6Vx1OEXCSBCplYcFG0jjcGp7QovUrmK7M9MMrDpZeoS+7Hux4reaAkSMf912qOvsKL2dhj8DnGD6O2cyqYptetb1lBHhObeoqFKlV3BncDxAyKlfs4UFEVv9gJ8lENhUu7cMZfumTM93JPNzFYCdhqzqY06Il4MUp676s2oov82dNEfT3bR2zxWpuYO6iztNza1KWxljxgtHYyFsFuM9W/Ozfz/N3t4pbkuA8FrsM1W8FV9vuN5Ylap84BLjlyweawZp/6heJ8hFN3qUAKVBllXtDtnh4mO/GhDi310WLeSt1X3PHrwEjyWhuJ0Nl09dl5V3HF/y+Hjl/Xp9Yg0guAGVAnEVYRuhSMNm4ZC7j1TfCLeNezboQGYiSWcWnx7Zo/BjWyPqKwL7FRsC6kS76f3yfxz0Il4fkog3UeE+xb1vcibcpSKLrlcWUXu3WYdulbitV9+uCByFkOTi8uSx7pyaT7U9o5agvDGb92HzCUHIdQrf/A8PRmzRoOffxHL453ArjXexKZBn1wcRw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HiqiGvPB+e4Wce7aZZroeC8qq+XJihA9nQkahLn+SGFoh7fqH+ki8hdrqR9+U8UuJqY2rnZUb6MXWt7Xvzgxj9lvU1jnSbmJEJf56v/o15RkrW3tdmO4LUuLJVBELw0y2FCoiekofGhMTTPFyFCgPpx7deUfeta6zWjsbIPt3uen8cr32g8FiJwwds+FjGO6YwlSUIsenOHQAwIMBoJmvsuMADNu7tIw0YCWhl/fdwo5IwMlUTr5ociTlrKSgwjyN+PcMSiIfFbK/Si1+g8wUIR2+UZw/lyGUAefOb+ti9hkUkyuCRyt2YuW5mSBM6ggIzX7e1EXkw4+y0xOnTlbzi1yrpD/8pGHCGtwPOF+k3D+vbIbyPVDdFX1tCKg9+ZFVFbSwQcgV1AIohtTF1LtaEo0wpP7ldMjrGBj0kWLBywIUyFTs5iqH7heHSpyC/k1E/K15/Z5wzcvA20IbEuTLop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7FZNTzQU6HG0XIGwAMVEsI/ns1ltR60J9RGSMJOIBS3VqurxQvfRy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b74601dc-1721-451a-b01e-08dc36ed6a0d X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.5840 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NuLqrnW2HUCKcCxMAKfF0DDL4/zbD/Kg6cILiN81II/erGZszxSM15NvhrhRTjRb X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090743_273305_FB767B1A X-CRM114-Status: GOOD ( 10.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Half the code was living in arm_smmu_domain_finalise_s2(), just move it here and take the values directly from the pgtbl_ops instead of storing copies. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 27 ++++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 -- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index e34c3181966934..b81e621a8e5921 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1520,6 +1520,11 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_domain *smmu_domain) { struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; + const struct io_pgtable_cfg *pgtbl_cfg = + &io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops)->cfg; + typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr = + &pgtbl_cfg->arm_lpae_s2_cfg.vtcr; + u64 vtcr_val; memset(target, 0, sizeof(*target)); target->data[0] = cpu_to_le64( @@ -1532,9 +1537,16 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); + vtcr_val = FIELD_PREP(STRTAB_STE_2_VTCR_S2T0SZ, vtcr->tsz) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2IR0, vtcr->irgn) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2OR0, vtcr->orgn) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2SH0, vtcr->sh) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) | + FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps); target->data[2] = cpu_to_le64( FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | - FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | + FIELD_PREP(STRTAB_STE_2_VTCR, vtcr_val) | STRTAB_STE_2_S2AA64 | #ifdef __BIG_ENDIAN STRTAB_STE_2_S2ENDI | @@ -1542,7 +1554,8 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2R); - target->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); + target->data[3] = cpu_to_le64(pgtbl_cfg->arm_lpae_s2_cfg.vttbr & + STRTAB_STE_3_S2TTB_MASK); } static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, @@ -2302,7 +2315,6 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, int vmid; struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; - typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr; /* Reserve VMID 0 for stage-2 bypass STEs */ vmid = ida_alloc_range(&smmu->vmid_map, 1, (1 << smmu->vmid_bits) - 1, @@ -2310,16 +2322,7 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, if (vmid < 0) return vmid; - vtcr = &pgtbl_cfg->arm_lpae_s2_cfg.vtcr; cfg->vmid = (u16)vmid; - cfg->vttbr = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; - cfg->vtcr = FIELD_PREP(STRTAB_STE_2_VTCR_S2T0SZ, vtcr->tsz) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2SL0, vtcr->sl) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2IR0, vtcr->irgn) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2OR0, vtcr->orgn) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2SH0, vtcr->sh) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) | - FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps); return 0; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 65fb388d51734d..eb669121f1954d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -609,8 +609,6 @@ struct arm_smmu_ctx_desc_cfg { struct arm_smmu_s2_cfg { u16 vmid; - u64 vttbr; - u64 vtcr; }; struct arm_smmu_strtab_cfg { From patchwork Mon Feb 26 17:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572675 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 A690DC5478C for ; Mon, 26 Feb 2024 18:16:39 +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=za62hY2uA33Ed3UmZQ7/AHnLMee+RHxnQknS64qyF6M=; b=B6BmNUjK39O6N7 DhylqVo2sQOdMBhO/r0ugR4BHvZFUYE7FNjH6X7k1dEaj+80jl86qb5IcqUPG37pgKsYgYKTcz+LZ hkQ0TibJtr07o3sb1s/XsVRerK2fIXqZ+4fvYg+AODW6sja8zjwpk1dE4d7pP0y5G+VROFCTBSHPN vqQmK4cKlHXlQJtOSQlvKGne++np/57nLQhAlZv3M3u3AiMP8BnvMi3WmWkoD2/fxNh19kB4c1Tkt 9suBkDhILJrVb3Ksw7bOKj14StWOUex0mdcS4K5D6EM73T8QEc/ii+g87aKtKFIYFvKJV+UQHmHXm FCX5BkWSiQIs9IpkLBvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1refWg-000000029Cx-1BgB; Mon, 26 Feb 2024 18:16:30 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSC-00000001pm4-2SF4 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zso5XF6AfMqpa1uTE2FUfkYRwggAZD9JvdOAhykIKfq5vYGfaIfgtRW5E0y4sA+VRgRA2XPZOLWWcNkQtNDsuAzu7PB5MHwnmTBHZAY8mTtxGyCpkyWuE9iniv9c9FVxbcdpG1CWioGMHX0h0vJ72s661E5aDjFjswA1UArNLYJNtjsndEppX0hg4Y9Rdcp7whTwDCgJXuM6/inCVnu5sygvD1ter+1D9xw+7Dokhks5v02mlu9csa3UyZ0WoHuDm4zFebB4MN7RsHUyTnkij6GPqWMrYpTZQXL5buGYLXEdatQAlB8/wvN8xmGhHSfI2CDWd26NVLJ6hthMQIqJEQ== 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=v4j2mcTm+Aa/oMQiUnxUzj9IKjIrzKi0EFXG/jhnrW4=; b=UVWehrPpMS88ltc5HC+IVv9PhrRL2rN1Aer/fFNUASyPIeHUOuB0BxQMO+3pY8fxhzvEpSZEJZ8TncVeFyNPMuGk7ObzAfhKao3mJKc1ZzxEbIxRqy8EG9PiLTWjZI3QlPdFKBVTOaMFA5tPEYIa+d+tigggyTC82CGsGCD+GJNpnb1uD9QBI/z6Z/wiyZgTZI0RufkcWQOH4ha0eIUrJUs74YAbhvhkARFBtitp5LGKiTUOiyccRP08Nvyl/3RN81DLh7bHCoHJ+MHr36HxIsfD5xPIRbFe8Hqoj1bmkNSA8JVq4Yv1sqYEJXab905/mhEdupVcgPnbm1XIyodlxA== 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=v4j2mcTm+Aa/oMQiUnxUzj9IKjIrzKi0EFXG/jhnrW4=; b=nUxWZX32zyXOlFfFhiThJrO/zsg2B0oGHGL1+MDZth3HEhVt2iQhNh0ddWNhinY4XKJBc1wZS/4MnAxfYm2Di/zQDRkRFQW7ZVax9qR+HecNfdmGlqtubSGqJX7DtUxEefRwPVFNoUOnHuFBwthFkleeAII++POKwQZb0/Mk1Uv+k2kiymYsxyqwjC7UYgFMYnBlHGaqy95V4JE9YNr/g+G0x3XmzvNoj7i/bJEGnN65H/yqldgAuP1ru8hE4dEN0eVkOho2DFpLN9EoN9PtssXw5k+0BUpjE7CkiaAoAMMJTD6QwLjOpL0DClQX3OERzJF6FaFrAu1FRoxB2PaO4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by SN7PR12MB6768.namprd12.prod.outlook.com (2603:10b6:806:268::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:36 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:36 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 05/16] iommu/arm-smmu-v3: Hold arm_smmu_asid_lock during all of attach_dev Date: Mon, 26 Feb 2024 13:07:16 -0400 Message-ID: <5-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR03CA0013.namprd03.prod.outlook.com (2603:10b6:208:23a::18) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SN7PR12MB6768:EE_ X-MS-Office365-Filtering-Correlation-Id: 71c39cad-15b9-4c55-b630-08dc36ed6b15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FenS+SvTsLBBCCUJKdx3/RILCblm4uYyUytKODQmZ9+7HeUVYM+gptojOigci74NKUwxQEtjKEjGTr9KlLbnEeETz9aR8DBfRPGYiCRoUJpfvG9VWR2dB49AhBk86XRFY9wOAC6HVEhIKBnQKm0E2MiGLwHvfXoRU8ubKWUtGFDPhGoF87UEZuW+DksbnGXFN0fsxiKZU4C/DdA88hX1HT8mcDYb5OC4sPmbxANaaluuRTKKkmMMzuzArHWE2BpBies3fsilDbn0gmuG7Xa5pnQvU3tSeuXSsZD97fApRuMTzDShhZvte6W4wGZlAAnYqXH6tovgpwabO4EMhXA0K1evmNmWcZ8MyaTsYaluaNpXMOxKlVykkcusPDzW3p1Uc36CxEP6kbWk5OwXtYTIvx2M8xrcE7gLnIWBJRUG4VSo2c5Hcg4scNjW9fNOt/8Hz2T8w5RPVa7v0ylUX63ukvxor5r781L5oN/95b8rmak092GZtTKSxJwh+z/VckKkxv2Ld6dk0A0xT8guw6Zb4jYnz80byfuoZMaxGB5YX4Qr+AOWMMKo2MXNtJYRvYQHMKRwmiClOJnKuI7wpcxgwK8Z40umKoWyd6/WFHkMPkmITzM5u8ebA9g+QGrns+ZJHSxPO5uf2iqVHVU/Z/YLJw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m34TLF+KlHgLcsZe4DJLXP1F+bjJzvqoiKeFh7xebMLwpT7Lts0odd70ZrtlurHImxNSBOXNdA2WX5CUrNakFBPeWThDqszRnntoZUAdtD8SD65UrOnUHbGNHiLVEooihIkL+GDX6hTULisoek4hpOcdOSVskfFSfh3xtEpnf3M6AJq8omVbFZDCwjOdAPcpQvtiwNqrX04D/rpzTi41vWdGh8OxEkm8Xnypom906fWFtPj04kJOIWwalyx6l9ekSixU+K1iqUSOeaaKhPYRbEdEaMiiyaGqotTx6Fm56R6CG6j6F8QzLfA1d/69LzYTN97Yz88k9CIYYlgO/MEEzkN//yZdZF64FpBxPDvemu9AR+H6ZtLbCJzta2pODSLrVBzqO9EBsuR/LZVkjuivhtrQTf3tND9edb5cBgKjTHa3N5LH77H3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lL8TB2WV/GSxD5OTBG2fHc3Bd2CMLn0dQY/E1Dn2Zr3vj/ZEZYTpM4hhFJmFn9pFmMYAklBIA+uzGuUvNz X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71c39cad-15b9-4c55-b630-08dc36ed6b15 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:31.2846 (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: DpHvcfaUHBx0fMHVLxq7qI6+1pE8XEGrFs45HDeYBB+ESZkL8q81u9aym6qXcUJz X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090749_967161_81FB85A2 X-CRM114-Status: GOOD ( 20.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 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 almost works today because arm_smmu_detach_dev() removes the master from the linked list before working on the CD entries, preventing parallel update of the CD. However, it does have an issue where the CD can remain programed while the domain appears to be unattached. arm_smmu_share_asid() will then not clear any CD entriess and install its own CD entry with the same ASID concurrently. This creates a small race window where the IOMMU can see two ASIDs pointing to different translations. CPU0 CPU1 arm_smmu_attach_dev() arm_smmu_detach_dev() spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_del(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); arm_smmu_mmu_notifier_get() arm_smmu_alloc_shared_cd() arm_smmu_share_asid(): // Does nothing due to list_del above arm_smmu_update_ctx_desc_devices() arm_smmu_tlb_inv_asid() arm_smmu_write_ctx_desc() ** Now the ASID is in two CDs with different translation arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL); Solve this by wrapping most of the attach flow in the arm_smmu_asid_lock. This locks more than strictly needed to prepare for the next patch which will reorganize the order of the linked list, STE and CD changes. Move arm_smmu_detach_dev() till after we have initialized the domain so the lock can be held for less time. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 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 b81e621a8e5921..d2fc609fab60ab 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2586,8 +2586,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) { @@ -2602,6 +2600,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; /* @@ -2627,13 +2635,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; @@ -2643,13 +2645,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 Feb 26 17:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57B5BC54E4A for ; Mon, 26 Feb 2024 17:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+Vf6vRjn3KzxVbFTHlzEV6l4ZuRVfDLkhMICJy0Mpg0=; b=USfCG0Ie41q8yV Lr9GRResACy5bKJWEZw56FBvNnqdbidm00zWmSUd+4nShFT+rQFllA2kbRSasICVEgThX6etKAU3x XErp9hEhnxIFKVeb4nqIqLT0/ySKEI1M1ak0sg2BIRd3j+8P42IzpysCa03A7DYVJuEVyjRykndaX hEUCpGRvUnmcKuUIx5cn6y6aahvOQhNMm99fLAe7Af/MuF3XzwgptQ7WRiG2207SHEeIMoBWZLFcT GBCZlBtKgJKGEqnS54tmG5/i7d5LUx9RnRHbV58N2v29IFnWzr1nGWxLeGq0EHNYOEnQoG+rfgMb9 aYRQFj6dXYPFIQnvg2MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSz-00000001qDK-0soB; Mon, 26 Feb 2024 17:08:37 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS9-00000001ph5-1iBG for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BC/pqbE2MQ8pc5oAxDl7qZo1Zecx/EZVV/Gn47iSaxcLT8H3ELGM2AKLz2eg30EkL7u0XtYYK5izF3JWKwsZQ4klo1NWim3UjbXaVMkdz3jI9/y5yiQfqSR0lL21SbGfu3zbb14u5iwfA4v/nA1AWV/Z991P5nTQp8rAN49E7pp7dGVzdOrbtw20swpg1R07d3nGHXhVlsSGsH2S/E5rIKlQTjqt5cPTLjcz3/6CLtPD3mn6hLSyEuo2w7AMbvRPAghKRIxpKhz+eXVxggFsIP9kTbuy1s+GGqcjUmQuctF/Jxp/Jv1ciFnHicnx0W0xwhSnZpdMS8QfROF0AT0AJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=StRJq5aimsZUjZHxbJehWYgdwTVyadidAX6VEVeAfao=; b=IsyyDK45cJUFLyFmGLH+bpyV5NK7qCkpNsMkjB+bVNfAnYJWi7gV1DJ0G55R/BGpxly+G70eGMgWR5n3Wm8ovVc2TIuPYErGJrmNaiyTSwBQNrqJ2lC/mE1J/iOAeN+D/STvK8M2wb93YFfTCiMrgUjgLQCm1/KcorsYUXpIYMtK9er39uyZHj/h/e+US78rkygjQVWd/uPwcWrnNZN8uN3inWv/SWF5O/nJEAw8Jul/AjKe8olXQlDgvSxqt6On8ucRLpfmngJPdVGua55wwlgm6dgShHGo3xMJKbDuvUCH54aumdS2MCApJnG7y/j7cl/5517g/XBEk2hr61nEDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=StRJq5aimsZUjZHxbJehWYgdwTVyadidAX6VEVeAfao=; b=DNRjIswpbIM87pTDezxJvKCCjXmXe7RhSzRxxRTUXVEY+Ui+Cxlmy+PA7c/05cZFDzy19ulDtEcPnmPOslnRdY8H6X2woM0toaw01wiWesBvk/+rv/k6PUTTOXUMtX80sl6cZCsg4XCZYaUhlrLXyDegBDFi/GVRkjangDoBgIts9vdmYv42951NzBmyLPD2PLLpe1dzSZ3VNEJWQxZLgaf2swcis2f9cM+IAOs5AgYXp1jtlriZ+/4+WtB+ZJRkr++MwQCB8JRQKsLr7btW+4S5X7XAikXBXHTOQSt0rndLV+hu5VBkvbxxiHa1T+Q8MvlqGAocZk+xTT1QQdII8A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:32 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 06/16] iommu/arm-smmu-v3: Compute the STE only once for each master Date: Mon, 26 Feb 2024 13:07:17 -0400 Message-ID: <6-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0006.namprd15.prod.outlook.com (2603:10b6:208:1b4::19) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: aee38f8e-a26f-4675-fa1e-08dc36ed6a4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pMmJm9tz+TWped58ZFI8DNsTvU9YPF6DXO45eGCvTGfp4RhB/uWrUIa1myw46jbsCrmGqpO4dMx4/kh21rddm9BwKjhtMGnOwhTvnag6D0YpxsrUUsHk4wXeA3epMEGChEFolPLS5KllcE7jxcEw7GNlnIwvgWVenjpA9xSGsLCsDg02J1o1++QiicGiXicyHjpR0V1yOVRKhew+KW5ClsHbbPqJqj1+FBdxyenMtYCQFNX2wExzVxnm1lVSlupER/FU6weWaTnmEK+yFMJeERUEmRC4Q3R1/cw5CR9+CN9X1zGtGYDXfYLXFV+S5DmsGTnCahXSclCcQvHY05+FERdHUqq29S3vrlv6pQOhkaUzmmmZSVS/WmVVNtA8dH9PBuLKtZ3nHLxtXlDSH0KQYgb8cD4+lXRKyGR5P98tXMVjbOfHPd7QPOw43DUhMSDXL2ykODEFrhQjBR3zaHXA+aLI+HOqqlUnFkap+wSRdMc2+6pGKr6Rtgfr3bDmuATz5DsLd9tSIXKPpISh4SDqGzsSxNLJgmEeQaedyXo/LaLk5VjaTJj8oSyknaAkGBXJoH14n6F74rJMs82Kg4Ykr0KJY98Qr6kPu6Fqi5NRq2pjaMsACXrSBAxoMQHJTSG2qGIwQOwNw6Qf8ScpOn0e3w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bbYS0FiUgVA49IeMRppCBw5RyzJr6HUVJ4mLJIzVJiBPNkDEkEhOYBsDStWheoDsRjVcqwgBbh18VyQuQR4qC13GLXFbW0Cqd7V4PmB9b3Vex19oS4Fd8/U2RGAAmkOGzyfoqEUg9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iIvcOIj5zSFX/jdCiNCnncwMPvQXiyXYKRyInJfEAeGnjrusTKfbpKV6FjkD+nOT3lXQTnnexZNV2YxMPJh1ajtsQ4HE+26MsQxRn+OcMUUFHbKAEtaruPWzrX4RP2Hr0mZgRQy5l6TPIlUAzPITBJ0QTXEDio5MafgGgt24T03rU6vh6E2JBKovPKYRJivLnWw4Z7zfcw85NyZaozhrsC844DynAg9F1vWumEu0Zdebfo3h2ktG3rZh0WnK8/ECjLuzliQuTfQZdmYAp1CJ2D1HmB+jfbAP6wCsMoxbCJgzTXQhgGhwbcpcshGVZDFdkr51AMFDnjiuGguRH0hOPTfSp8ywJE/miK0g9s2wkU51hCRQypKYXR5OFWwTH X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: aee38f8e-a26f-4675-fa1e-08dc36ed6a4e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.9342 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o7rjbnR2cBPyLW/ys0SQrb2WWX4EEETr7t11lIIBdmMMtdtR7KmyQa2b70q5ya5y X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090745_577832_008A563F X-CRM114-Status: GOOD ( 16.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently arm_smmu_install_ste_for_dev() iterates over every SID and computes from scratch an identical STE. Every SID should have the same STE contents. Turn this inside out so that the STE is supplied by the caller and arm_smmu_install_ste_for_dev() simply installs it to every SID. This is possible now that the STE generation does not inform what sequence should be used to program it. This allows splitting the STE calculation up according to the call site, which following patches will make use of, and removes the confusing NULL domain special case that only supported arm_smmu_detach_dev(). Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 57 ++++++++------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index d2fc609fab60ab..6cdf075e9a7ee7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1558,35 +1558,6 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, STRTAB_STE_3_S2TTB_MASK); } -static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, - struct arm_smmu_ste *dst) -{ - struct arm_smmu_domain *smmu_domain = master->domain; - struct arm_smmu_ste target = {}; - - if (!smmu_domain) { - if (disable_bypass) - arm_smmu_make_abort_ste(&target); - else - arm_smmu_make_bypass_ste(&target); - arm_smmu_write_ste(master, sid, dst, &target); - return; - } - - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - arm_smmu_make_cdtable_ste(&target, master); - break; - case ARM_SMMU_DOMAIN_S2: - arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); - break; - case ARM_SMMU_DOMAIN_BYPASS: - arm_smmu_make_bypass_ste(&target); - break; - } - arm_smmu_write_ste(master, sid, dst, &target); -} - /* * This can safely directly manipulate the STE memory without a sync sequence * because the STE table has not been installed in the SMMU yet. @@ -2413,7 +2384,8 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) } } -static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) +static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, + const struct arm_smmu_ste *target) { int i, j; struct arm_smmu_device *smmu = master->smmu; @@ -2430,7 +2402,7 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) if (j < i) continue; - arm_smmu_write_strtab_ent(master, sid, step); + arm_smmu_write_ste(master, sid, step, target); } } @@ -2537,6 +2509,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static void arm_smmu_detach_dev(struct arm_smmu_master *master) { unsigned long flags; + struct arm_smmu_ste target; struct arm_smmu_domain *smmu_domain = master->domain; if (!smmu_domain) @@ -2550,7 +2523,11 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) master->domain = NULL; master->ats_enabled = false; - arm_smmu_install_ste_for_dev(master); + if (disable_bypass) + arm_smmu_make_abort_ste(&target); + else + arm_smmu_make_bypass_ste(&target); + arm_smmu_install_ste_for_dev(master, &target); /* * Clearing the CD entry isn't strictly required to detach the domain * since the table is uninstalled anyway, but it helps avoid confusion @@ -2565,6 +2542,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; unsigned long flags; + struct arm_smmu_ste target; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); @@ -2626,7 +2604,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) list_add(&master->domain_head, &smmu_domain->devices); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + switch (smmu_domain->stage) { + case ARM_SMMU_DOMAIN_S1: if (!master->cd_table.cdtab) { ret = arm_smmu_alloc_cd_tables(master); if (ret) { @@ -2640,9 +2619,17 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) master->domain = NULL; goto out_list_del; } - } - arm_smmu_install_ste_for_dev(master); + arm_smmu_make_cdtable_ste(&target, master); + break; + case ARM_SMMU_DOMAIN_S2: + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); + break; + case ARM_SMMU_DOMAIN_BYPASS: + arm_smmu_make_bypass_ste(&target); + break; + } + arm_smmu_install_ste_for_dev(master, &target); arm_smmu_enable_ats(master); goto out_unlock; From patchwork Mon Feb 26 17:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572537 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 3C726C54E4A for ; Mon, 26 Feb 2024 17:11:47 +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=w7FAtGsrcC9FgOVNs4lyD4v7fk+zFilH02AsrGuK5HY=; b=EbkWCXiUDO3Z7m fCgZtFKVysc9V/xdk3vjkGTMUGKvICQZy1y3ha0EII6aDwS4Jr6WNA5DD1spiORtMu6ubb3dRzVZo 1NwBO/WupG4kMqTtnm9eJ/ZCib0FxD/5mTv7MYiwEGa0afW+QwGOl2abWN/tryZefZfoRm8zKHMVQ 0egj4gUcMDifzt/i2wcBW42fOw1FqDKWR6QBdxxw7XdYn25mwIlNxXMTkdYx6fOhqSShMF+jwZ4GQ +s1xKrIGiWnM8yTcT9Ti6MZQQEiByP5JdH3jbXx4ybvXEN7RniCXqv2MLK+cdbVCwlKFS3qzNeDIu ibjBpGf/e/gwyj69fbtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeVl-00000001rUC-03bv; Mon, 26 Feb 2024 17:11:29 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSI-00000001pjD-1gdS for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:08:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHCL2XFQWeBGq8J/Dq4u/9HE0aSAPUJ+SV7Pyh+n/Ln1R1pRqOl9ocrrdkNuu/GCtDa9IEpv17lysu3/GrnvoIjQFj05NLHCdnrHIcm9LyeL/9GQuL5Rtx8wlKAWzHPsC6vPXqyVJgUSvqdyGCbBrpLgfO9lTCXf36UM8nuioo+FdmIaytX5qya1b/gDFSpn0Rbu+r8xJF3H7smRok/RIdkcCgrA1HAaSlKndK9RmM4zZurx173lm2Kv4Hy+BlrQMDxf/thSHOMtlzB3YgsH/MGY7EOCmzKLIDIR4M1k6Kv988LA/L5DZheJNtVcqsIAyNOljqKuSid6mM2byCuZqA== 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=aGGydjNTWbOHl9vFD60RlvhE91QKMCRM8W/0YXBi9wA=; b=brAbFgajFpxelenDAFGyY8wZ6An0tGr0WfiLpRf3o922xVX0fMYHBo6CIWYbcQLNJdhwgGN6nEmjMEb/RkBqM2xOsU3g35trCoejwM8Xu3XCUNu4Lvo9qaQugzZ6vEhqBxcF/CVsBQpK6KS/hFo059NNmmz1AIdIhtCCPg0Q1GusFOFb3kMPg9n7+ClsG00EwQQjhR+lVON+nqttMeRh7wIbd6MsIp6u14EZhmg63HAsXYXBLv4m0lmS6nwvFrb0NLfGdW46wzxrISbL2jJKVQ6gO+J6XNQ0v5tg3hyRvQ9Z474wwrFtLCk7R6T+hy/GQdwaWEkB2viQBloRbfmPbQ== 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=aGGydjNTWbOHl9vFD60RlvhE91QKMCRM8W/0YXBi9wA=; b=sOzp617E3xAEB2RDxlhs/0WSwHD9u0/l+f9BHvmwojMqD72vOBh+IS5UbrdHIIoo4tVWtcGHnnuffvn9IU5t9TZhwdypfAN8o97/pzNheecd+pOl07bjKnwyX2xqJUGg+5gO4atgn8yKtzJcVNNbL/mcLmccUTmnNdTSIfziQAhQPihYgfa7RNw8l+fJfD6CvHLC5WgR3UyvS4YpeF6GhowLWuck4QpCRPD7Byel20cthRJnXwh9clBuwR7x+j7qGOPVub6S6qEvXgKs/X6kPE/zKpbX74xsU3kfTke2W20rt3vq9vYuA7YHEOV8jylEl+yogomx0NLT/6WMg4vMbA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:35 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:35 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 07/16] iommu/arm-smmu-v3: Do not change the STE twice during arm_smmu_attach_dev() Date: Mon, 26 Feb 2024 13:07:18 -0400 Message-ID: <7-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0034.namprd15.prod.outlook.com (2603:10b6:208:1b4::47) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 268f0c36-8564-4561-85bc-08dc36ed6ab8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lTRMldW+qBkq83vhtS4hv3xJfQ9Ui7L1aH1fi1jsJWEBt/jq5SziHIeNjVf7j1LWHiHLiWdwyoahJ14hcfl99hJhloab2v00+4T4788/qOtMrUD8TKPhnksSpJLt8POc1yAVLJcICWCiKSwoaEXMBLSpfuB2nMxAAtdNQ/QgNDB0tWcyNcFNdOBX5zZRtzWnKau0VNCyn8QSqV15GbYFRhY22epe9aBoWIB1c8X0uI/MygL20nSTzH7/GXZjFBiIB15JQ/x5kTSjbhy2qlqQYoDAm4LPb5wZGL+gOqVeNc8YBvbZn1nEaKToTcHOhNkKjWSPmjE2gUp6E2y7OeqKNfiTxpZ08DavU134Du2nI3+svrmlqbJ1VRNMfHWE7EahsZbpq9FCf8BmPAZ83alyInJGg5+G4ZiHOvNFCXCiwNuxKa7dSSK0+2/6rZAlPpNusU9z0DQZUFwAGro0kar5p2iWXj12tyADcqvZ34//8vMm4Hv8QpE3K4ArYcOghHyXpg9nsTm10VbQjCHEzd5d8PTvsoGFrwEBgopaKRPqxJXDHwDpmQkQtmq6uxwpPUqsNl74YQxrKVboU2Wqz8SGQVXoTVkgDI32Baa9eyDWlZQ4If2VfWtRO+KFzhlRZ3I6gipbD+JxKdbflrJODBYLFg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DaMzaiG24BOoIf1aC0l3GNc26GiR4D2+GkTxqVc2Y3gvZoqwx5ds/36zbHO4E0jUB6vrx64ZcD5syxNsFTpWxEJPXD6HtO+xaY0t9zTZgnN9QUZkeFUmXFTLQzNnFNQcRvmVqwEOLwDV4T3uQ/QwQILp7DQfMx0tEGl7aHiVGqDGN90esX8+4DC5zFgPXWYuVNGnYyNWwUs0wIGWZgaVB/PfMGLPqUsxHYdt7/bYyzGnCg7pdDF1s72yXe6o7xPwYZfh/chOp+ASVtq/E5LZjIgBZcf/tInrQMR2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EgTYCWbUUtb6G+zz9gOF4raXc3RF47B+73UCz66iMBeuVt0xc99kB7NQMp7U9ZB/9puo3CA2UXW64oayG3yRHAdHFiBbJzAWYbFElr2g9IZh4YVZJ+Agm8iP7MmwNm2kjlqeDTUU2ysS6b7coyH2I6LpgCfUzER9EUbt1JV21fQ7PaSd9G8HWrqP/HcfP8snfeOUAYeXemudq+XFv78MT1IvL3jbQcXC8CC9egjGJocF X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 268f0c36-8564-4561-85bc-08dc36ed6ab8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.6345 (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: u0AZNWOUACyJak5gZlR2YS5KelVLXejNwa1CoAsgj9Y0CI2Qwk5csCLeMGT1IWjx X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090758_787432_8AF96EE7 X-CRM114-Status: GOOD ( 15.59 ) 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. As noted before the reordering of the linked list/STE/CD changes is OK against concurrent arm_smmu_share_asid() because of the arm_smmu_asid_lock. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 6cdf075e9a7ee7..597a8c5f965899 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2509,7 +2509,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) @@ -2523,11 +2522,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 @@ -2875,9 +2869,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 Feb 26 17:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572539 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 08E8EC54E55 for ; Mon, 26 Feb 2024 17:11:49 +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=f0z3njykMraIUM3MvbnTiq+7bbKe4zoYepKFKicGAdk=; b=xJ3jjP5/s+PJIF LUsNcJb1CIEDdH4w/eYbnAskhQmFUFeJE7GO2thCyNDumfduMPAAeBsJO77vBkRBOQAbuSOVWJ0+s dU7uMhtQP3b0Ir5MUxARQJE8WF5V9fbLJY+mkSU1Ix4Pf9Vn7PToC+7RyAuNZH0lxruyUm8VIFnxu tDVyqA0P2134hbU+lFhMRQ/c54TL9PX4ccyPQGQ/VQH4p5xA2zwe5/67Xof8CHCU6/0gFkTi+lY/0 du/FuRTwzdVzxTUGOdRXhXnjRcs/tIUKP6njJVUzk56x9H/F7ul+IggLwxjC51eZhcewnmLf1giIC 1tLoeeuuaJ2bvpnEYk0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeVl-00000001rUn-3gnZ; Mon, 26 Feb 2024 17:11:29 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSI-00000001pm4-1pa2 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:08:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ii7AMo2pNYdY7MKO1R2B59sYXTX8bpnsVlMag+KmgnaMbeJFH/jGWEzfKq4XBz6VHQsAxGqPfIMRZz9IIx9b1UCMw8IoP6SSBS1WWUBw8Wdg165DgW8Zmfa5CEZ/EFUVqOe2mKm9pxDaBoRswjmMhYSG8oZI+Hxk/b8JcAja1pRxYKbCSwqQ7VAd4qcm2LZ0bSm1g6JFnwd066xpGb+hq06izmtWsBPf7DzUJRxcYwAVTkwmyBgJ1of1RdNop+7jEwzGCz9vy3zqS3TzQuYdIZ9OOI+0c15hGL9ZaPp/r8ieoMwqo/Qk7f60z5IrIweWUXfoig2H/5IJBekRDNxKSg== 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=5T/3Da5SgzU/Vy0hm23N8FJaF0+S35B8BrDUE/AdJb0=; b=k9WtwxmXPcwPaZYd5+/X1pcas+00QMW/3qTVoXQYky/N/ETMVkeyH7POzywAEjMXZfHsOEVEW+OVszHoUF432oketkAcj/MJvfktA5DBmCJ/NyzFaYr9oOtw7JgAjqm5gBdeTR5hwsrATrr0Owwmggm9XxA+E73de0VOPbTMcSAfa85/D66KfpZ3GUnHSPYayL0nOE6zESnekDNZLrUnG8WHVRpBvwI9jRFfEpTzVFy6XYs9bHWG2ugFo2ekVty4wkNaP93KWJVZ6o9nZShEMniYIPcfRnTaQWTRpuZcx+f+f/etoYSCg+DrAmh53G6FJLPaATRefPdBmo6Yzh9QQg== 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=5T/3Da5SgzU/Vy0hm23N8FJaF0+S35B8BrDUE/AdJb0=; b=O71fJvpsIe1Rlyp/OImnNOk7yc3Ncz4oN+EWYiPedXH017ke7MVknVqaxYQ5/oTdG/ZZ03aWtXUojF8GBMVvAE5sZWKj70+JAqiLwidQIP7GpjurbDOmVcRs9vRx4wATLy9K1z2nWp1d1gPfdwwiCXDYC2aoRIZT1fKsJmdbR8MHAWXcnZbhUHEQfNpjKrbjrJzU6SiUBjZaMBM1gQ0oxhjc90aoz8UtCld7AkQ70Q2LE4xUNupbwC8yZMqP1/ysARmJZwWUL1Fo3DGUqDcMzgNRoSwna3v+HSy5vFJ2idcnB1sTxuf3ceBAVCgOjIXQPzeFti+4ieQJwVTypz/QCg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by SN7PR12MB6768.namprd12.prod.outlook.com (2603:10b6:806:268::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:37 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:37 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 08/16] iommu/arm-smmu-v3: Put writing the context descriptor in the right order Date: Mon, 26 Feb 2024 13:07:19 -0400 Message-ID: <8-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0023.namprd15.prod.outlook.com (2603:10b6:207:17::36) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|SN7PR12MB6768:EE_ X-MS-Office365-Filtering-Correlation-Id: f91f606e-66e6-4179-e82d-08dc36ed6b1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pxvbKKz4UcfQpJ+q3p1ASe2PATlWa768uEiyr+sbQxIjGKAP8sesSKlEtJTzbR/jgQFmBYDCRzF+FBGe2Y2ZJ9IPTBBRGYUgtaJ96JMisF1cTLxHEc7TxZYmqYekTQfAwPaPUMS7u/R+WPIjJsdeMFwTMZn6FxA5XYSyaxnFmyKgqQWScwkpht2qWvdhONR5YwzMNd9aV5bj64bLAxLOUu5Jk6Yt3a7mWlPucaSb5xSTa5mlqrTXQI5aF58CRc6oZqMDCgURApVVl1SnZZQdNMvMgUIOb6rCe988k+9Y2wjpIFAWjlVqQ7iaqmkabIBdHEQBF9JrluDpZInOYsqR08YiqcYZO6sInic93h4KSHcc8LwyVuwphb1Mi0v414wn7hZSTrIhJxmXfqCI3PWM9R+dg9LxUSiIJ46Q75Ktv2Mf0HEjwXfxZD5KeHE8HWfXicrVEbcTwTXk7Is+XXdT0BfKtK9hXwGErm/ZnjkrZLY/9gQd1PzH4rQa3Kvi4Z480frpJLAJzQTCZspbo+XvbNGMJKhCiS8zV7mRy+/Y2VGdPIhspWio1IbxWaF8xWm4BtKxmEfNajScIDW+cgIjQF9aXaLB6bEmuAEojZIloofMamzR9XARKtTPTjmaSEOajKtMUijEGSeQFa8yLNfCYg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s9Z06JI+2c5MrxMHD0sO49YrXtpdNv+hM2CWr6h2u3p9K6edHkp7Mx+6cAFPnjqdikVW08WZcSmQ5lPtaP9zZ5qHB9viEQv1BpIe4LcH3lh4RkQ4UN88LfiRSlUqEk2A1lQLnC8mFTnnz39ppbamh7D9UTakdQIaAcfWyivo9GhlLGzAiPhD24EkvQULtYkkUxXNjgGazrkBnpIbkxxdo/yjrknzGpOtJ1FV/VukP32veB4It+DE8FvoplTF3r0qiYz06/4IMg6M0rDiLfmSL3eRCeTjSc/GOwSx0RYPBoORaCB73RCxYEUsUR70jO4bFJueTqAL1lqi8bWvbtgr6AhxeOL58R8eXHjf9wuiV3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NUVP5uJkWlEKiPYMW9NyIDxq5rltZSUd5uQnNDPYq1ahKNDOPqgfyHKW9q4iVjeNwEOYGqnSlMNFvrz0UBj86xm/Uh2AxilWrdi8fOsZnawg0JjkWISGWr23bgDPwVM7Too4i9HEWpz/I4jWpms4iPrvwsLV2J4JQD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f91f606e-66e6-4179-e82d-08dc36ed6b1e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:31.3411 (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: uIXQYka1EiC7prSrbhPxJlRokmgbUtXCBBfXIhhciKPYnD1zuU6Z0zaDzKgxvZJO X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090758_789085_EE1AA967 X-CRM114-Status: GOOD ( 19.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 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. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 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 597a8c5f965899..ec05743ee20847 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2522,14 +2522,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) @@ -2606,6 +2598,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); @@ -2615,15 +2618,23 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) } arm_smmu_make_cdtable_ste(&target, master); + 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 Feb 26 17:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572528 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 9FB45C48BF6 for ; Mon, 26 Feb 2024 17:09:09 +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=55An+1QY/nQOuNnv8mCWuPfTnvNgF4XRg+b8Gg2VBck=; b=1XOxCT/t96uBvB MprTkf1KyjnK/WeHN33xVbF1ZYHBYC2Cf+gw/raV+2ncENxqfT2N5jWduI2kuaSM97Ogka7KMGmt2 UYbjWcplwNymN2oAuL3duJD2TMRwCq69PfzCzB39nommTrcpHQ7twGgUtg9lnvGh+FhdIrGf/ilSv ZkIlTNsLgj+r4fbdOn2PXzHrgEWSwvrv5pp8dxwyNbyqhXS4pmHj5V2IzN8hQmKIfJFXUB2pstmZ1 SvRADY7XT1OTd0n+w8eDjd0eLI/pJ+DA3Tl4HmLiabdgvWpfzkKoZrlIvLYgOjaSy+9riqDFv7BsI M2l7VV+9kNynraJAb0LA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeTC-00000001qMk-2y3y; Mon, 26 Feb 2024 17:08:50 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSE-00000001ph5-08u0 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NYKUHTL3p3NCwac3JFBwS0ofHqIAZgNYaWHJkTtctyjmjT9JJjwraD20UK+nV/B1kXSpG585PBIdF20QwyIVAMKUq62ftruJSYXLMXNWvhBNwuKnJUORf42Oa3vulAasbsz7p+jIJ/9fa3h9VEqNH8WuYP97j0E9641yZh8Px3UtEtWYGJCQBSZL180Y/PQ12Z0kZs5UFDwl3GyNx5EiFWJ3bbAmOT12DJho4RYGG3jcYVPEviGLzOGaN08LvrAVaIbuQ+4rs51l1Bu9U6NHFKEgAK2tyF+45fcSbFtjbfJdWdJ1UEq/piSaDTswXoHj7csI1WUHVJG0DLW294APyA== 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=kNhxe6eMYEbii6HPeFDwaMDwArH9oJKo9Sih9qVvjY0=; b=ObP6BxfeS36viyZW12A1E6JjJwna8q4zSjvIPNy4YfA1+JY80XPqgMkXqsscj+iHTUjgpB1MhkIUlX9oPf65to3wFsv7YZHKaS/mGqZTLrpPku6sszk81FlJRdXK0vOgsQANg22eMhDhSMoepTFJ2XGw/t3WvTMUDjxU45ZubWSvL2aN1DRPaeetruJ5y97EsLq3Wo48W/KfxnuqXZ8XHmnZ9eOr6OPkzAMP3x1/hByPTQW+mOo8QhoZIV2GSq7ku50EvorFskU3/UXwxDE/DHUewccVpNDCHalZ50Rs6lsc/DChwCoXRuAsyAujq0NYbqhzB1MDu1So/UVQX0gdnQ== 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=kNhxe6eMYEbii6HPeFDwaMDwArH9oJKo9Sih9qVvjY0=; b=JV1mXfF/zmuMyGVenepl6w1ZEsm5kb3ciYIimFvO2QuR3qDE0Z+eNfsg3oOBNMA2xoollld3OvbjJkCwXL5c6+4MdjedMA1tyeMi2e0FtKi/6Ruxg1q0Caq5XD+pC1G5KI0s/vA783Teo0FcV4PT5lW9sQ+jW3azg4XiI56tdZDNXyuwUTfH170fGoS1FkZ30ofjgM8X/ZJyDDsfQfP/Ox4CMz/Rrhx6tXc2wLNj+x8MjLlXKyg3rypPg0aRQKHEYRS5rCUsU01XfQCkIqBRys8jLXNIxXITNRpoq540QwhW+0u+NfXS/qTdV1kxLAgxdR+qL/MfwH0Sy1uTgBA5AA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:34 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 09/16] iommu/arm-smmu-v3: Pass smmu_domain to arm_enable/disable_ats() Date: Mon, 26 Feb 2024 13:07:20 -0400 Message-ID: <9-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0017.namprd15.prod.outlook.com (2603:10b6:207:17::30) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 93b76a7c-207b-43f3-ba86-08dc36ed6a6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ax8ckTOoNOkpACU/BKr6FKu2mqzm6P+y7zsg557XQU9U5Lj8VCYFsd+zl2ib7h8+UGBrbE96dPdMrj3VcEJRUVx+ynV1a2S0uQCe/hmb0cu+L0U8CKnGaPO9FxnaZ9RN9rkpvgG9u6w4B4fb51HX7p0ahwQcYqL2ki7QaQ6Z+GZIjb8rnkuDieEBC4GxsOenMs8do5FYv+Z2W+KF2sVQf4XXDxdks78MMpRx6IpRfp2u0m0ZV4W0l3nKzcp9HUGDJWBFB9z8ybhkTc3jTr+BbMwiavpao78UVUhr5DWefm9u/M0vuJPjzDG2g26MRKkRtJxcdABqObZg3A5GEgCj5nrsus8k/e0oJhycLT2xgcA1FylH0Ya/MFunPebARV6uxjkfKAJfRvuVJXTaYsvhjSBVZkN+xwTK8Vzzo7gJOU9jVgI/ybNDmxlsczG9kVWNWzhRmZpZown01nZybIeVhikt2HNch9nRosMildGsv9OXjHUsI0hLRShXtPm7/2QqEAWkEAcGKeXloLU2bGOYH03tBSxR8fy1JrnGSmw0EKNed3hZGow2zEJT2z/TrqgmPZsleEE0oswuA1cRJKXigiwEziX3xoxCTDpOOtl1YzOuvhyO3GIOhf7Mkd6jddd3lQeXDYGTJrVc6SUHyo5ptw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DrEvga3yB0Yuch7uEF1ZLdFPn8nK9gp7lReOGeFNzqlsUkXAOjz6nKls3rsUePJl7gerIcDi9N8bYNqiNhg5ctDhuhlAcagGAndQFtP+C444UfGtZ61CUfdzd48kMGSXGa3tyx7YdBNULNkqsjHW6CvmySfRZoPtuT4gOWLAb75bwUlmNQMmnQb/lXaT02B3tbR/+ddcOAIJOYQqsmLHTQV5/q27WnHCD7mAPupfuXYLYO+TVOuyy5u9spwwHiWHiOhMuXdcvK3KSYt4ThLA4XYuEZAPV4Mq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Z9jylVCHJ9CiWuR6ERGrADEeOFCW7nZfYYFTh6ezonDRc4geS7szXv7IWP7IoBJrT+6G1jAdLVrQ8h8U+yPu/AFSdxZVdW3EjOoV3LyL3fj7tnIlJYa5cf6JWBDOLzNfSYYpdFHv3G6FVdUKUe9ebQcIgaF2W+0Yg62ydbzWf0Vi65WyWhSjPan5Lg7nqCsp2xwOrvcm0HUfAmBaaa9HvCnazAbHxgR2KHTb4l9A2u8WKGn13UQMgTAAFG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93b76a7c-207b-43f3-ba86-08dc36ed6a6e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.2126 (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: Q9xk8e3TXOIhdrlaPjmkhYTkfSKMeHhcfCxnpQVq56CKyTuIJF/bk4xtmzXsv+hM X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090750_466630_866CC393 X-CRM114-Status: UNSURE ( 9.53 ) 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 caller already has the domain, just pass it in. A following patch will remove master->domain. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index ec05743ee20847..9d36ddecf2ad64 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2421,12 +2421,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) @@ -2442,10 +2442,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; @@ -2514,7 +2513,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); @@ -2636,7 +2635,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 Feb 26 17:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572676 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 7B8EBC48BF6 for ; Mon, 26 Feb 2024 18:16:40 +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=kyyXJ7t9vmR2olpJbjV+e552zbu0sNG9qf3de/JiHDA=; b=gKTy4YnnTFNKx2 M8kj4246mB6doj21sBp5UIsEoJUMr+PqdVbJAaBrLVRMUPtEpuGKcKUm8+hY4wVn9b0/UP5Uto7t2 MxjE9KSfOFfrizoiRi6ZI7Hni56ZU107Y84Sr/qsUrzcb1YSa1OZyZnsuv4bhxLfSWFPLsMMKo9KP h4laupjWyz09LbdQKHag4NcDZ+GgTqFwU2CC3Vax/PdfZj9IjvAQigEfB3KrMt6SFezEluYnA2SNl 3Mx9r0yUJXLHifbxANZ3HLxQZxeLkfBvGKvtulVFhV2fS/I+5Kz9xN8wcG3zQrJZA2m2Zzt0Ezdld ikPVpyCP4eTbmsR0o1RQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1refWg-000000029DU-2O2Z; Mon, 26 Feb 2024 18:16:30 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSF-00000001pjD-01bC for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jfvEWh19vBVL3jloXjXPsRd9IA4+hyLuLJEyKNQGKbRGeHA0DU9mdYmhZOJIbs9eUOYKP0hjrRNscZAhsPXXEoKDYveVFTD4SDigse1Hz87AMkldWHgpLGgaa+sEhfYBVfT7bLVOkoNbgOADHF1cWIu4boUreQ1BAEspKAJqjjteB7m3zCCwgavo9xLwmVE93G4lo/fNqzi08u3YKsSXiRiwlufZgq0nKl8sD2F0o3PEi0Y6mX+GsH8NdDYcRhgXUvMXg9KwmhSSkUqkPWEyw6wB1CinvNZq6SrEC6fek2Jf+0pbkdYIAlMpA4wCGxnITm/8+Q0jFM2oDqoZcjbD0A== 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=/GzaHdu8XubOBxsSutXbFquuYh3EtV6Ivkf67pBgTM0=; b=b1RxZJ4fcvDgAfhkBFlZ3Hj7XkrNO399XW/+Njqk4d4Q4Qt8upmQ490nPEvu6hDk85PsXzOvYcLqgZFQN7SJoRQ5aRPYUsXEDECHYQ3BzQADACgPaME1NW8fEI+gtA7vJMSMmPwndNm6XQA4Lfub/Q2xPkGNd8sy1gbmZU5kIiOIl7SLBTpLE/hcF9/xSZ0dFxi8vU/ccgsP9zELL1Hsfbs23QVFw6vy/J2HanxcfKTHsf1jtmVw4n8Ozs1HtaoRhqmCX955ibnbR0EJpaHoB+oSwsFnmA7UDmFfSQOLC8JeSl5AklMLAobcbw59dIMeGYocK6Mzjv2ZpMGm64L2zw== 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=/GzaHdu8XubOBxsSutXbFquuYh3EtV6Ivkf67pBgTM0=; b=dABJ8X9tODDQGnB3cXE7XftfkY/qyc9+LPCcZSd5Qs9NBlN6+I8p0UfgGsf1hGWWb9ADKHvC6KodeBxOEz7ktRQsuJc9/9oS/fwdzvOJSjXRb0AUI2TEEGv6yMBLY5ozgH14fyOT262g1HG+J6FA/vbjinh3gdhPMaEMUmIKCj63nbRMZ883R7jBzPixcYg1LoOcM0fafP8OGA0Oz1AAmqQ5XojOE6ElnRRHQNj44FOV4NCbOQqa+6//NKyn8LJAnn3djLFdZkiaqDeeMoEwldZY80p5bw+do1JK1U3AYoJjO6wD3RY/uibn3hqvZiFXeMOUCjvLJ21WhykTpS5K6w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:33 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 10/16] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Mon, 26 Feb 2024 13:07:21 -0400 Message-ID: <10-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0046.namprd16.prod.outlook.com (2603:10b6:208:234::15) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: c3b9e8f6-3439-4da8-2d33-08dc36ed6a65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n4k/O9Nd56UY/e5rAFsQD8EZZLZAA7ElINDD+Pbg8TLVhtWeMcA238h7BwnbHgdWQKhgadryzQff0Y2941F9mYBYB4v+x6ycQl63DLlv+k2qloaTBAMDvAOrtOzBVJUYSc9jjqpmTd1tANRHUlY0pNReJo9s6Hx77vTVoj3n7VMN9XA2x8bLgwWqo/rA8h1u9lbU9EDrB+oNrOsK3V4veDARQbhwFRx2fw19KrWKx/O/qyYZJezGGq6a/Qqh8wCk0Kv2OpoU93JNFl4WaqnIAVR+e0R7zZhXPa5BMqB3pTMc1iDMFfQ/kDH5T5UPJrlhZvwp6RzqKFbiSM5hNR/QAVm/pBRmrWtL3WIMN6r/PP3KRuHXSqZkkjtvzV1AWbxmQYfwKvDKQcvB2WTAFfkFy6qt8DZ0tOxRWHWVj/pDVx6qdsoOxQS7x22jk6yb8pyZOSajFbHl+b0NthF6tJkSWfePgMqgrrdtzDGrg2djJ8fgcxcLGqlvi0Hva2EgdqMhnapShi93OYZ5Ebk5/WFFqrMlXQDm4ueAb04KZgOplaRKsjlSBmIut2mM1TLkbaHgcB2/jCPTInN5RxdmSBjWIrmUCBET+AXhwhk3OsKT2aXv7J4eUZehzG51Fi5l9z1ZBWOgxluo6WXGs6OKK7ojAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hGPqqvkZlkw9Y2IsPSQ3IKmv61ae5kSjCQ57IcPjxyiK6i5NWsaWViJmuJbn7NlL3oz+YxiDppV1uOU56q7fxi0yYHxFwZo99doEI54wI1JjZ8b1M1tecY1NRXMVh1+/2Y/iffc+YCsDN1lye5QyygI4jSQ+6NqLK/4rpKef55B+AbkylxWCBbJLqDi01qtCag/VC2K7tj7LcHIJgavpuNFovImhD5VPYj7HZZV0IKqQyOXuDuus7ylXpPDlle0H9TxPFMuAyX6IgvDn9f6KuFcpn4wymyZdDw7NsU51W51cLOfaaySfRKvoMNbijUOsid/UOVoBCktPmVic6w6IcfBF7a17X2uGe5JVsmYpM1K9IV+Ge71nkaMe/hWmAtmMsREJkYeKaEohrPGmoJASrV7Kru8vC0halfUF5H9Ehxcj3f4xCmHenCVn+a2chjeovcCgaa1HI7ie85G1HZomPAXCKAg5+p5k+BIjUIOEowi8shTLsUNFxFl66uP3zn95CeZE1yGMS5f+S6NpZggacHHgtNYrB8IqSk2cJm7HTvtARzL1Lz57dUmb4WlD0NUsAVRnEAPgsgfUEijRC93sOeMvqyf3RpEh82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ange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.1416 (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: 16r/jHl3EqcUEj2BGOwRlxnAyewgWp4eKD9LV4uaYLftEnnwtAifk/u/VB8WwPNM X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090751_340185_E98385D2 X-CRM114-Status: GOOD ( 15.97 ) 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. The master->domain is subtly protecting the master->domain_head against being unused as only PAGING domains will set master->domain and only paging domains use the master->domain_head. To make it simple keep the master->domain_head initialized so that the list_del() logic just does nothing for attached non-PAGING domains. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 26 ++++++++------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 10 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 9d36ddecf2ad64..19a7f0468149cf 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2507,19 +2507,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); + list_del_init(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - master->domain = NULL; master->ats_enabled = false; } @@ -2573,8 +2574,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 @@ -2593,10 +2592,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 @@ -2604,17 +2601,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); arm_smmu_install_ste_for_dev(master, &target); @@ -2640,7 +2633,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) out_list_del: spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_del(&master->domain_head); + list_del_init(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); out_unlock: @@ -2841,6 +2834,7 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; INIT_LIST_HEAD(&master->bonds); + INIT_LIST_HEAD(&master->domain_head); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); 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 eb669121f1954d..6b63ea7dae72da 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 Feb 26 17:07:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572526 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 EB429C5478C for ; Mon, 26 Feb 2024 17:09:03 +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=s9BPs2JEWBJA3d0fyyDtL18V/eIkdK02CBEGKfHeKQc=; b=cIJBJRToXkmI8i rwVas7uNGToJZGt6RUR/o2iDzuaUgXdSkjqPkwji78N1+Jh5Hol/mvOXLa9Y0x9VY9pspOPvhVzfL BtandSv0aekmTAGCmRoLaFHA96+qODPGQTeaxBOkTPS7mOwtApsUJVI5J+W9v71HGy+t5DKpY6big hto4PR5UL0+Co9P/BvXHGQGs+yZM0ul2uh6lHWr0a9rxk5ynZEmHxZQob/+gYimo82WlhN4Vy0qZh 9jn7BkVqMJ5qWkrlu/odK7lDRi+Yqe8Zmb8O+G7v0PYAu7XHHM87ErRusbCikxxl8CsB1WHtADh9L biHuHkA0HVFbvu7qUGgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeT9-00000001qKC-38Ms; Mon, 26 Feb 2024 17:08:47 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS7-00000001pjD-3Hmr for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kharzl4TjagmRfR25HtxBDQquL3yLY43k9T9M+cyDlS72Qf3NrxUZpDPPG5q23ypQfixljs8MDPqOI/gEFvEqwtv0XzEf70MgLM7IHRAYh6BXHoXymehiaenGRWKMS8M1VXLUsqtwHhGwSlDy1wiafpYw3MhXRPhAqSQsl78eZIMAVV1vzul7q85aAfDEgtbsVgS+U5PPnzEPvEQ55KY6WKeLpqSbzeASgdFera7Ox3Mp/Zc42kLbQ/X47SoFaBhbK0ucB6fKU6WQMeYcuAxX04sJYLX+eYUgExvndav8Sq9MbF/uJAARw4DD9dmrGchMiILGnWO6eDvdiJZUUAE+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WT5WpzhVRk5h+mxlCBtaMXTz2F5qzBR0/9sy9KnolEo=; b=Jp81lN1XlAahBhEdyd9VLPETfV6f7KSfOc6vZPUpyP4nffFqHvlU0CWt+ElT+a+mgG2LPlTSNphB3mElsEsf+AFVmhQxHqtsagRPic2rtzgMNASDWlT1YtuYkUJVhV4fn6O2G0exWVKkiIQvOhoOkit0SVuEuFfdCX8OFtuIcrgTIiBsMgDPZm8V8J+a5eh4+ITf5ValfoXgAD6dCiuHGdYJjlIqM9J86cKZ4Zn996HZppV5QBpe25NraLGcbdbr59clkwYvtqoFIYkgHnvur3uIHxFAfddUStH93haH+GB2xCZqvDrMoXUgWBpyUpAsOARO6Mj1aV+uiYf06fDCRQ== 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=WT5WpzhVRk5h+mxlCBtaMXTz2F5qzBR0/9sy9KnolEo=; b=ncpnqi17JjmxzvVtCxgsQbByNC+rnu0xwXUcTifzoAIVmfZVH7+luoqYGOoVqyUipnmNoLj/z1gGv0CMCbpkUx+GQOmVH0Wl8SEurz/HehcZd12A1snBfBC0HBPWzIMKA2oVuaWZcH0R/7hOkrWKukfjBrTydkp2pZvpePOtkhMkoXawBoT9p/YKzgkgwlAaC98YtjnkH4rz1rXaccK4m7ENRkkTm3USuMzo/aKRqTBrTbMRvvkvtNyXnZgkgs9utk11slT3gBLBTGmRs86i2tqV6vZZH7COo92Z9xvsv9mtWNlOnVW+2hIRiNtWXNwxsGmRCX7nyR83CqVoOwMxAw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:29 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 11/16] iommu/arm-smmu-v3: Check that the RID domain is S1 in SVA Date: Mon, 26 Feb 2024 13:07:22 -0400 Message-ID: <11-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR03CA0026.namprd03.prod.outlook.com (2603:10b6:208:23a::31) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 52c8e0ac-9f5c-436e-822f-08dc36ed69c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: az4D3yDGN+z2RvMx7chEhTrAI0oE1Lzg6p5FZcFzehAhPtBSBHkApX6ctfS+O8p1Pm8emhgf1yePqJyLlqp6m1e1ijPfzSF+vsm11BvyExMkoVlWD0QKVMoCvE1lFtLdwf+rCe558ZaNh5x0IXks7rhvnxA1rwJPAF1xJUBcl9JDusGQOogRUdG395r1Bfmn3WFnyaiJ9SkvBjbTDs5LhRjf3gRAwtFFSwh/NEoTG9jPOe7V5pKxR9VROnJ/sj1GG3jk25PcfI26tbm/+tzyi2yLP8kLFBm3xC5uCxqvhN/ThzV4l7Log2Hu1sFQS3qJy3zpIsk4SC94U00hNFtO1+eXCoX+X9nIBQrCE6FVTxOhnzshgdFUSs2jmIgIjWiN8C73JqZPimuxCgAdnTmRvlomOoxIVKG40TWmFPv95l9UwlVgshN1Bj8yGI3rw2AmXyMVpnaNEShwq/p05v2oxO/XaMthbvjsWN6QO38obf62Lxrejok0yGCd6Tw7i41QN/2J+Hs/JfNqpFhTVGoA6ocRzgHxK97PcP/qD40bFDtyFApJFr3jgjA76IHxUqk5ALhQzjpFC0B/qMXVa5rArhIKAFeuIAiAmCGZXq5NVNX82pllmNnyizUDUMN/Iwjk9ShrHyNGN8LpxKRmCbJZRBAomC5dpsTsk7HRIMC6Mdc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031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T94RR+RSYAMjlk8XZajBdOjeyVOEiAmrtOYM7HzgakR8cZ7CesI7sUjbSRR9r+NSV9lnzzdq99jNjyMzupRGCIq8xPQ9K6K5VD7xt9Ppnew8Lk8DU1REPUN7Tk+vpOmeXw6HCEb+0kSblsJl7HYc4zjDtslhQuu2ixMFcMYOXFVEN7yvSeYrFKlsjr2WmS1pPHqoAYpYRkPyu2AdWjTpgt53STE7RKKidOAIXMU4vNXOVOFDksXHCRA4s5n/urtQyicEpF8MGUOdB5+f+nRII0hxQ1Fm8aCkVH+mJGqx9aqSlaa7/XOFEDP2ddSLA5LtY+OvTGLMBQiEreC2kM+GNpQhNSaggc1Bp1/+qhQdHjKzHLmn9zBvL1WLtm9yj27AZArNVvrQNNwygi6QM3VJ0QeeTkSXwTaa56FzpBVWGt7lCWb1YXW1+rCOjwIug0IdJP+9mYWAHJEHOCgdsALED3GLEFh4R2txYKyYQ+1eKYgFqgXgoH9wupLjyBHLhHbsW235iBXR39+RhNmytm6pLwNS2WHi8KMHUc486SK7BdZb1Z+xvUuQc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52c8e0ac-9f5c-436e-822f-08dc36ed69c8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.1683 (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: IdpZ0JC0XgQH/kmlVV2ihxbjNC843DI5gz0gSL/iXDHh25XTb2MJLL+UmDbyf/ty X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090744_372113_F5F20237 X-CRM114-Status: GOOD ( 13.68 ) 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 SVA code only works if the RID domain is a S1 domain and has already installed the cdtable. Originally the check for this was in arm_smmu_sva_bind() but when the op was removed the test didn't get copied over to the new arm_smmu_sva_set_dev_pasid(). Without the test wrong usage usually will hit a WARN_ON() in arm_smmu_write_ctx_desc() due to a missing ctx table. However, the next patches wil change things so that an IDENTITY domain is not a struct arm_smmu_domain and this will get into memory corruption if the struct is wrongly casted. Fail in arm_smmu_sva_set_dev_pasid() if the STE does not have a S1, which is a proxy for the STE having a pointer to the CD table. Write it in a way that will be compatible with the next patches. Fixes: 386fa64fd52b ("arm-smmu-v3/sva: Add SVA domain support") Reported-by: Shameerali Kolothum Thodi Closes: https://lore.kernel.org/linux-iommu/2a828e481416405fb3a4cceb9e075a59@huawei.com/ Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 4a27fbdb2d8446..2610e82c0ecd0d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -364,7 +364,13 @@ static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, struct arm_smmu_bond *bond; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_domain *smmu_domain; + + if (!(domain->type & __IOMMU_DOMAIN_PAGING)) + return -ENODEV; + smmu_domain = to_smmu_domain(domain); + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) + return -ENODEV; if (!master || !master->sva_enabled) return -ENODEV; From patchwork Mon Feb 26 17:07:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572523 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 80048C54E4A for ; Mon, 26 Feb 2024 17:08: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=37FOOzFHyk0RzsUGOzCv2jHRPUgcy/iuLzxd1kOtcKI=; b=1RxeSZyLELP07H xpRuZeHtZ6RIygsgqp9ZrmS6Ki8Z13b64tZMJUlbdnNyLxGtMJvxPO5wiWoy+PkcDVFWxP4HKC/AQ P9JSPmiFLB1uo+M0fpb6ckArzbHod3/mI/mnKx5slmZYkKslcK6mOgO6QcUhIWpkTiC5GBvEtlH7S T9qbN6drpZBZo6BxGLHreW8M94tfwNllLCR4M0WHQaz8HdGHEV7+QuhrIBegXWOCg3TZ7PP7oEb8T t8m8l59FWgpvrmo+/bmBofPFNlsjYbyWCRF2zCS1r7ydijLJ04ae6LlfFFWbrVjN0jKgtqezBFyTn jCHlfULPy0AWpWAg75EQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeT3-00000001qFu-0drg; Mon, 26 Feb 2024 17:08:41 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSC-00000001pjD-0p20 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TfP6QE7Vk5kVII4geHCHSOk48FQcsyfidhuZIYF6NsJRWN5UlChpz0ij/NAcv3NrzfdeelbG+Had4vTGphAxpEl/1f2kH2una3jbIUbsOSP4PePf1PlyOi60bYSEAQsS2caOUzFfDHYrn4H6f6pKCKGZ1IzyPsUBlByQEJAsyl/IN0TzJcUd65UBxBtobYmVmNBXLxX4Sw/qlcla5PYi5lTtY+EsXaXFrCkaGvicTeMOaxJunQxZSE/bt3BCBXNtkkWusri7SdfHznQlwrXV8BiudKmT3GLAnuP35dYeeeNuI5n61XIyoFgF7jP+qZLlnC9huAh/GxWWi1GM6lkhsA== 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=qP+cPI9ElikO9HdrsNVCnD7mKvBON6I9/dK5f/bFbz8=; b=ksblEbMq4OyiRnMaNqueWFpDr1PQRQMascVyTrIQbOGz0TzolKBQUocDiOcuQpZvJ/Ndo5is5MAKNuqOJlu0336VWnJcnUOsWlNNPsTBFn3L1skiT5wt9ws63R8JYCQgQucqgKmBmE0v0JFF9THCgponLVTbiWwxRwXGnAYGQSyBsWFCCbfbUxT0VvleD2UoG6y55sdW+3Z25iNUtAW5sMYd3SnfDqRxcBP+sX4Gcvdb970Cmfip80sLDTcYYjAY4Zja1mud2+d+OXTm4U+IiDy5L8kwI7YasDtJSWzSe630xBxk/4aa+0NX1S+UCPAVol4KZlNQn7iNu8BOfz7SUw== 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=qP+cPI9ElikO9HdrsNVCnD7mKvBON6I9/dK5f/bFbz8=; b=RpgvknOcChHDA4GnZ+SNeE+a86VwUkYzvHy6IBdJJ2S5oPx5Pa5Ae93gUYIYCXhWes+8ZRUU+8TN8W/kh33yr8mCjXHFfVFy9Bawebnr9V4SLIcTb7b/I/ucRFeT82eWEKMEut0TtoZ25GaEQiDhQmDUfXCWxhJLLfLN00AA6qtI2icqCMbK8c1nNFY+TOCALcV/SHlCJ44xeXN5oT0XG+S9hCEbalgD91af1kvm0VPSxBoS/5ZY0PNoq+l9ZAeGEGJlZ4ChPXgiezvEeiICbU/LNWSTvC8YJL4zZ9hoExJa3hg6JoZH1zbDH4Dqk9kUDcmhJmCQxIsOmTuKSyNUnw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:32 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 12/16] iommu/arm-smmu-v3: Add a global static IDENTITY domain Date: Mon, 26 Feb 2024 13:07:23 -0400 Message-ID: <12-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0049.namprd16.prod.outlook.com (2603:10b6:208:234::18) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 66ece28d-a146-48a5-58dc-08dc36ed6a55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: maskoXF8ZPQkJieRapbjma7+enAuQGpoF3ZpRqrDiw+SrMwq9GJjQ12lGjgQc1OlClpU3SzNJugu2Ts2Y6v7PmjqdN4+9ETpYxRq3ib3ailM0iaeQ55wMRBQp89s23OTlziU26TF9kd3tSK+Zvu/Z0Jnhr7amCa8Fl05aeJuye25fcDp8U+qMuEGimD2i1+f+xGiyCnmO4X6Y/ngMhg0snxzuKNEAnCgj5nc1K8V3tsBkl4sxG2QncW9ec8I5DXtz0srJkQ1Oad2b7DQXg0v8dpkG9QkGhgh2FyPHx4nGijsf3BHWGauFgR/Gf+YNqEaQd4jBbPE6XEPbj5D7+Wm776VMRLzXg5yZJSkImxnksgwmYsSL9+OLkqnOiJezdjhmn5fHSWQ8D+7J4J/ZJFPpvQTHPoZAgw1RrkE14dL+o6LSKJF1Cuj51pUEvwrs/dMBCFVIQMpW9wloWTteb+2sL53jDRLLA9+8Gl3yPU5SvFgAeOY2k/obpxcj8zJKNu5hjqGeu27avtsyHgyzzhWj28BQ+FQBiOe4EHOisu7lzRyF3bV06nCeQOWbQKGPtMqOlQaLsQ5ndBKLijPefUswc+olw2ZqBEarhzc1rgtVGzsLtSs547bVOcdgYchbMYR X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fhfnIeXdNHZgFP3ROqHytWzXByp3xl1M8zOZQm8lEGXLGe1RmiQ+s7hAQHO88A3kgmQHWWwsDVPr65CTbUamVuMH2rhrpCH8y0d7UaileopdVcWxyIxXL2eQD3pmny7PjIl5kHhIlpJeSIAUqjav8l+2Pv1tDjD/zakbOo8h/Fp5xkQrOgcMC55sHY0Bo/7ytHSXHiDZ0sEEMxV9k/BdOgzERkGQ9HteNDS2q4IyicHwEt8lPZLRqsoIMJbzOnfkNLwcZ5bavAmmoznSo6VvrqU9BMXg65giwvCMP4uDkWuDvAsHIRPMH3MaEiRoenfV2KDWT6+N1lXZveJXFB34abyOudEPl63EPk2O27tGk1TRbzBgHlwQcK++RKQ/i1CBkodzSqymDoM10lKKy1yX8ZTOJlLMfhYXYXB7W1YGklFhhdigR0WoOC/BaQzV/BSZmgjvpG67RlA7aO+IxH28LS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LmfBRNE32jLc/vwDHCpuceKHLOPiZgo40xXNRs0TGCp254wA9Fec X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66ece28d-a146-48a5-58dc-08dc36ed6a55 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.9742 (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: /8sz0ZFQr350b1WiOFm3+fSMaEl0q/qaYJboUhwVyYyj7VAOunRquo4ah2mE7vY7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090748_355594_46626CDD X-CRM114-Status: GOOD ( 20.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Move to the new static global for identity domains. Move all the logic out of arm_smmu_attach_dev into an identity only function. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 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 19a7f0468149cf..842ff8a95baa12 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2200,8 +2200,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; /* @@ -2309,11 +2308,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; @@ -2511,7 +2505,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); @@ -2574,15 +2568,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); @@ -2619,13 +2605,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); @@ -2641,6 +2620,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) @@ -3030,6 +3063,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 6b63ea7dae72da..23baf117e7e4b5 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 Feb 26 17:07:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572674 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 95435C5478C for ; Mon, 26 Feb 2024 18:16:31 +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=6Us6xZVCA8h8GyDrkrGi1MRJ2UQ5bif4pERlMLNUph8=; b=V3nmZxR6PGrNO4 xJL9fe3G8uRXXN7XTOwL4etPpLtVea6nG/buwMAMjYuYq/5myQcMAO1QBOpdL3c7UyvKJ46x+im7X lIacmnGehsmOwdiljRT72wUORfXNmqylO1OCeNUvqqzqkztTCr6+yRQLrYNsoJGT/gek+3R/bdAWi 1ONP7stHrsvXAb0y+DmyvS9NkNJgunvEfCa0G7VCcs/Px71/KbMbQGlhd8mYSBloAv8eqb9XyUtKk 1PL0Qge3QkHd+I66WFkYrAYepURUZZHYGACpL4QlCRck/imbsIzfeQY8T02R2ckS/r6sZIkFPxdWZ CCicECEy7IVaGSa8pOvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1refWh-000000029Da-0aXa; Mon, 26 Feb 2024 18:16:31 +0000 Received: from mail-sn1nam02on2061d.outbound.protection.outlook.com ([2a01:111:f400:7ea9::61d] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSI-00000001pkC-0bWi for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fHChGi3sig2HHhuCcilpBGN3gtfJUWo1B7aYMWOykIZ5mZGi3wJH0itisT4J/7hqLFIC1YZqzrOFcFd7M6LbGG6E4XsloOztDsI0AwpZlxipIYB7xlTD3nBiSmV4LSpsJanpetuB3ih0Ru+i+6NgBbqikrK8dghX3Q5KipOboA4yifxAnhO1iQIFnGmoeo3PQydZ7ZNNDCDTNjxRp+OjD/ExU/d/xZgIlvXxzIwJe4NK3USDmTFOgnBQ2AoGL8sJQ/XvyFt9b1BuR8FuWveq9TNb3C0LWT5L/eeu8XOH3Ij/wdkd3b0IW+/OcIIQf6qRuRKZyFPi61yJrfNnUNflKA== 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=f+ji+QP2aCOzwqj6NjqZb3JKTosomI5nRxnuWErOoDo=; b=NutIQ5yEnqri6lrywWh9PEmioWx0hv3vb3L4SWSqfzAiPW7ep6v5CqaUzWlYoAW23yw5wYXv3vXJWNhuumUyFfAPuH+ZsEQWyRUNvuzfh0aCwy7XKJm/FF3JNSqJxLF3d4CFHrGgO0nANcxGPSuQXF9qvC/Tvf0wpt0vufUrCZSuwEL2fzMm6Sr3g+g1dqWfoc/+jaV4i5BAMp0W4sh8hmJr7NswzhxToZPZOdeccWXp090bLj1HeMOfs2pfKzWqTbb8UmZKkNgfp2ozurFhs9X8Kp9Z8SrMdTidnN+6g/hFt1p4TL9TFI8abJ9/+Eo6Hea/vfHKTm9tYAkwyGbTXw== 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=f+ji+QP2aCOzwqj6NjqZb3JKTosomI5nRxnuWErOoDo=; b=Hvkxi6R3V2R5fxrweFY4PmYInualU5J0ycbDkF0S2jAciHT238IrwMCXuiqhz6GXApyZ9n8I5ZcIC4XVBnIHmHFuNTo534JSq1ofsE1NOXKbocRRRIvGmctJSgVdfGyOD/jh+7hJUzs5uBYp/KqiHdjL/g8ZLr3qvbBFfMXiFGGyAl/uoWbeVpwEzHuVlvUoq3ZK85/0swBGHYrU8r9PZjb/RRXVDUXcLjRWAvP1GCK6yL8UrkIUWPAuJWU7mYATQVpgQCkI0ZK9RomA479vczIk4/f3WPv+Hf/RsLYxG2hhksUnkuvhAkjF088nsGOty1ESdbtn/w2/jeFY75Dvbg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:34 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 13/16] iommu/arm-smmu-v3: Add a global static BLOCKED domain Date: Mon, 26 Feb 2024 13:07:24 -0400 Message-ID: <13-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0009.namprd15.prod.outlook.com (2603:10b6:207:17::22) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 3aaa5234-2963-41ca-9eab-08dc36ed6a9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nf5MDYKpUMsOGcDFXPGWeTB2jvpp0FKBNsTN7fU8eMksjqQGmDP/f6UzhCNVUdg7ir/VU2gzu7o/qXJOQ2P27C6Le8UBp+lBaVaDZFlGLzYgHELq1C77m5qZL/i0Qsrcu3dgxSR/ACIBWbXYwpEntGE9CRALiqOlR08QVNULWfyJrkbjk2Xg7kVhwgJsrAo/RgrVgGCt6+4FFQdQ/OWyLicQqJNJqnvHMfCXm9Q3q2tog3G9qnukbLoPdR2c3M+43ejJIioL0guvS1ao1+0CSmCnHqw4c7TKk/RkB/sHyl6zwMWhNtyHPU6/hg89nGw6hSBUeer5e9OsWaUIW7mB9buyLgOvmB2fF2MNmeUuavZKkFV/UvQYM2RZPy402sKcc6XkZQXiHm6Q+0sNDA3Tsyf2yrUz3iLp56Lcdo/24ZyYlbOtedDOE02pFe/D4DlggHJuOYKhJsfMK0YYzNZ675UAVTWEkfQWGmwjJmLLvpaemVIoWkAjFK2EMsVGTzBAuBM3Q/1/XdeZPbRroVinsRd8ym3IFZ1jPorxHS+gW2K5BGjbV2f1hiMLZH+OKi2f7WQO/gKjcizVargu8qXXAf3rut8ZwhQu6CdyeHyQ40sYivuw7sbkBIs1VrHalq4zcafnns+p/aLfeSuL2NKzsw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-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RKKSTrJeQcT9mapJOb6cMWNDURsqhjHAfCAbqYT5dYqUvPnyMVHMZOg48mSYhDzevKp6ACXiTzkD3Hma89OoookOtRMDx3FimmgyzXrvsTlF/9MqUSF9PHd0Q71KDIHU4Efp4rqyIaPmh/9AHqXRKWzBQ2mKzhpiOWxiblBoeE/no+xj1nE7UfNSD5ifvWyUwtqFrLtuVIqsiqhodfk9XZMVMjAQt4uKC7Hfkpc5Llns/WPdRDnuTvVebI4ZoTrGwU5iXYMF6XrQ3UpRmdkEdwbPJ2XZqAj8NCuoDgydv1PdVQAIg7LKWLz4Kno/Njg0zf7xzBiuYtTt3X1d6lT1wZHZn2VSHKRdtfCxFxYKiGAsJQ7H0FbBRkRnG7cpqguONopdllPTkryGD92slx+mVFj3KJiFN00zNi4xxG9GKeD6H2jKmvcXAKChFbhMrbBAqiUYMY1TihUutHeJNLiry/P6u64aEwt/qAI7kgdSWy9u8oYq+Ntxexcs4OtQCSdCJ135uWJpsM20w8mrjs0r0i9P X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3aaa5234-2963-41ca-9eab-08dc36ed6a9b X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.4434 (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: gElgIMJ0vOKk75KoKxOLMI9PvqhUgkS5wSHeTy9rnfZWoPJKGCOqEpo+eIPB7IUN X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090754_480680_6280CCF2 X-CRM114-Status: UNSURE ( 8.95 ) 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. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 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 842ff8a95baa12..baec827e6ae446 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2674,6 +2674,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) @@ -3064,6 +3082,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 Feb 26 17:07:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572541 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 88DF9C5478C for ; Mon, 26 Feb 2024 17:11: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=5sfahZyovKNtWs9AV6MnM+a9bw9QX4TZU6RrvRneTg0=; b=2xDXYnMhHSuXOn 6m73Gt5xeYtO+lQrBd4zAb3j5yqqPV71bvYNwycdJeXAsKC+Ajbeprl5t0Dw6eYCEFwu3hMqgR0mg avto0hymPeDjE1FdJwBbkNwQ1pZMaKssJ4ksFj4F19KbWs41nWZlahMm7MKpOHMz3HvKb1uE9vJKS eAotNSYE3hMbKRWj+QaLLUMqOrep1uyM9fKZyz4N+cRnDldkjP+f9OqLgnCjm6OAlchrmsjBJH5OY JdT4a5WUFLpuM2iXUDjzMVLGGmOPxynxXuFustohAmsL5Nhticw1pkpAJHn5scCA2pbKwQSo9ZX6v D6OTcIqtOJ0dnpG/fA5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeVn-00000001rVy-3Vbo; Mon, 26 Feb 2024 17:11:31 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSO-00000001ph5-1Tg9 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:08:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rw28FjVxULC20x2h4wO/E3GNWkUMX05M9kTZt/UUmdEgZuthXXtcIF9IqX4h/EOrCwFCcvwu+LX2R3sY/ykR2etMoXcgVnqwOEH36Bi9MUFV59Irdc8JMiEK1xFbs3R55p9UTTH6UFawXiKft+pA65ezqCDtfNb1IYsceeMK6dS44NggliJ01smfuRtOMRA/4NZA6hvglQyM/mVIAqF1HBtVA8QfO028h1dtfXQL6ZgIteJvvqerSOriWWFHJfe0dPx1LvCl35k50gyFydEoi7Hy3+c8fJHIKkxyvBF9Eh4mDaqjOd6mNOpluEwTeNjp56YnMfAk1gD75iMHVEEG2g== 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=7bsm4AyVj6JAv4irvxq8zb1l2uVRXCJk8t63xPJB2GM=; b=EGbLGuqVlA3zXF3jlgHH+M/oZaBoyH1KXHXRTcgtywFu96/45j0f/hNT3h8lnfuqfxRDa0peSUa2kOpeh4/rlZ1U72NKb0rZeeb0iAR1A+45vBqclbbJ6/FOEMLB2+x08LmrQf6E2Siyg6LjFGdKaGgrcIHuRu95oB67HaD1sBb6mJbhEGOujR5D+hE8+PXWR/ivDWPXU2IMzW1/ywRqIo9curjgQPVWZzfsMl8Kg9EojtEpsp/J7nGjpxUw+m8UzoyJSy1xK06dE1hk0iI33KxOjAsEUd9oy8LVenTNTVwK6f07Zfgf/8ZLErjM5OU5p7K4PisM6tuxYxoLnXWY9g== 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=7bsm4AyVj6JAv4irvxq8zb1l2uVRXCJk8t63xPJB2GM=; b=J1A5cWx/mHF6xbQdgLAmt3YhuL3gItyFyTowMGvvWAV3/9l5AzUxmSvqL8iBr8WQWNg8bapcxGi6k82e+Wvjuh+9BgMu55m4MJuMFmH+YbUIfKaU6TDxbjcFAXQnMWINweL3y8poF0yKXPVCBUqbc1wnxxcePEghzLglaxaEbouqdvwB/ES4LCpNcDeJ/UW2R6oAOPwuidrVtDGYEYbwIwLR18aTtTIwjJeYtmcF+EOkbsXehqbtBVZe7ES1s/q+kryBM3Iy5uLhcSK5SoPAcAbM8N2v/GUqSs/cCYtMtcXtc+fCMpIf5splgI1HT/McnGns84BqrBdj0xwDI8MA/Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:36 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:36 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 14/16] iommu/arm-smmu-v3: Use the identity/blocked domain during release Date: Mon, 26 Feb 2024 13:07:25 -0400 Message-ID: <14-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0052.namprd16.prod.outlook.com (2603:10b6:208:234::21) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 440554e3-6684-492b-050d-08dc36ed6b0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R56mmCAsDp/lDa+JLaQUJ+ivTsdDuOxLUgp1QnumNJzp5G1HOG7mtVOLp/cUSlBoynbI/ITkg08Jrv478CTBf8ztah1Uzh0UNpfjmXIbtSF8bYyUS0vHUukkdJ1416WAk5bt9+6ZqHHcwOKjj8C+eJiuPx/d36tPqVuK1uVxlrNcTk3wS+ebGWstUOcKrrB5hJH0GeOYva86iaQwiKrrqoaEFVnTVaQGXx8DOfrtaqYzgFNx6k5oQ7J55tWP/4fE+CixvBL+appzE1cryrnL7b6u9wVtR1w6XDj217F9k+Mpa2ESRn5ivo0Dhrf/+s8uTfD1q6MMNFtvypNHN29lCWnB2lH+NIyb7rTOmabrdwpUw+0ukEEXvSj7GbrHaPwG+jscBnwQ34XwyXMfYlv1cpNfHBtHMgPCNiXEdCO05bDMjRc6bfMzeVM/8lIekTaW2Fq8rDk1dg169ftTTz5h/lHsJS7A7pMugyHpmECP/SdaBSbGLhu1uGhwGBUGwJEhENa0PmeyiMBjmaFwpYJN6wpwFECER0sypSEO8AVXW9r4PHDI1Tvmf2LtZGoYD86leSz5Cy1AtCivrHCihgnr2hv6Wd3tVoJTRxEI637h4bHmLy4EN/2xki9PcKhfll0Q X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zW0GhHDUQ/N+iZSh1T7/7VxEEmT32PMqda52ptUbSXcUdfCm7mQMg5csYkQcs9Vz92+LkPIAcPVLGQgqz9XvSdzPaCQvSZFeaZVN74RRtkO8QRP7RdV4nmTi+mx3H+q0WMsLaEoxzS3cWpv4lqg5ce0wlz+JEM4+KW5ss3RmCgkxqwJw/lKBgqZa49sPD0MYJKUfrFmdSLNrRGUuSX7baUZE0AdAbDB064GQ80VDPZzS2bKsJ3ITcdC17btmUZHvu/VwF6dbdnjxamEE06WeN5SeXlVJhg6q/SVRRp1OT4YvDmVoqBjuXec3bzc30xJMOxuW3N3RrVghTVUtjd4UrlzWJ356NZi0DKeBTZKWBK40cfZ/LmOAiow01XS2tg/FJRDmFUXd3LXfYIyw0LdKe68wCMOA0o/xSq0VYeuguL4howyaMIyPdfEWtd5A/cLfH1TYjiDqC5mhYXNKQq4B9QqJepSY+oXROVUXA0XgPPWb2YXjbo/K3yyZhyH0037Kbwzke74HGtbheXBsGEr10j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Exchange-CrossTenant-Network-Message-Id: 440554e3-6684-492b-050d-08dc36ed6b0f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:31.2294 (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: m5w6i5Q3W+Ab3Ip5ta/kUKWXFPNWl3N6eC5iiAo2OK4PF1XXgNCyZoKU16WnILZz X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090800_660236_06E8D064 X-CRM114-Status: UNSURE ( 9.01 ) 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 code by having release call arm_smmu_attach_dev_identity/blocked() instead of open coding this. Reviewed-by: Nicolin Chen Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 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 baec827e6ae446..1303e9c603fc6a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2924,19 +2924,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 Feb 26 17:07:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572521 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 33739C5478C for ; Mon, 26 Feb 2024 17:08:17 +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=QipVkOxMo0uw8azsXPGopdHY/RHISJn5qkPm5fnWT/c=; b=tZ5ebAKtxW3riN r4DiQgx9k4JYPYw6JB5bqgyrxsTNPJV8XZ+I3/iGkRZI0IJkzFLp+iAoJzKtxUESRTV3JA41GHxbe cjIXmich2uB5Ai37Bn/sr5godqxuhA53yhN+JE2cjt3D0iSp5z4G7FV3rh5g05FBGq+rB6VKrkrmx eERf5aNDwfMfan/3STtBZ/v5zg1tMklk8DRxz2ppPiyxHLs73v4hJVgAhQf6eHPpD14S+dHueQrhV 1VDdCHqIKA+Cf8AsAcXYrp6079dZJlvEsUWQpKPeZDtkJByDEdfgMY7aL9byXDtaIr8v2uHcHVOuU KxU/LG5PvuMs41NYvHPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSG-00000001pqK-17Ru; Mon, 26 Feb 2024 17:07:53 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS4-00000001ph5-41Rt for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VS62wjgdCGNB1GqS4pJY+/L6Oxu4+yCMvqG6uewXMD2uZPAk7mLLc01J+MYxI7blahnpG7Vd6+W9R1aGBc5AZGRkApzu0L9JKXiKFP3YnoCwH6gKO9Aei8NMMIdFlAD26GxuKwQ0inClGSKzYIY6Y0mElrrIBOML2VuJ/pYqD4ae5ugk76EQunWV4JrIvwXM9QZEnrEf6ueCsit3mUbGnTxCPDJJvS2KXLFNH9wRv3//lkiGc+CspcVyVolu6bx6CacM0kWCXUvGj5xRRLC2pFjpsGDI/K+q26uNuW27tu9Abk3bykHIfe7CaGVEUHcD+4g3cfKB9jVTm38JWpXfYA== 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=ZSWI2KHW5zcH0QlDKCwINPDZOpnQiCisbxGGeezTrcM=; b=H3qB34+KKatennzJa5ymTrdTA37PEsQYBaXwBaGUOtZnJIpfYevNRCa/EYkr0H1iC7wR2uOtzymXxD8bKm130BkwPilXGwQlysvwwHXUSIiYBtejQGDzJVlGYVEFUktXSdxXzYqk3FX7hjzeAeX5bgf9xIW9SzkUNnxmlhHt2V4jPLVkVfXpxtfvR/C3kzD0XqWS1p5a7hLfozWcaeibRu4tG3VPO/UYV9ArO9/9A5Xi7KZF088PgDcy0yNtc8XroAMsocmp9on+eSnaJDo7z95qw+FC5NWmfq6VaYgBeJQs6qUAxdjj6X44o3CsNyH1Xrf07n9s3F6ygbwWHGsGNQ== 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=ZSWI2KHW5zcH0QlDKCwINPDZOpnQiCisbxGGeezTrcM=; b=uGkibC8AVl8BNdLTx65N6dZ9EgoFkKRG9oGyzmFZk/HGTYZdnfXRbYxszUtIHfYOfp2Z9GH3Dk3l3VbULhZuGBAog/fK0eGYTCe6SfOVP8d75HXlBGa7VT+OUYiBawa3ZQWux0TXwAqtncvqxiVmkGYK8JniW/fVQ/HsR0C7XNUELmTLQdRDRWYrzZEpw/MPxTcZyZqjYoXOgyFpkfwEKzd4jvuuy4KPQZIT+gCJhI0B6DpWI1t5TOCndbYycWhP4ZMXX3dXOKPWhXhQddJsvTY2fWcPUxjZnkw5q5MOBucjZc2zAGsTzCaokwvvUrEWPxvc9rk9Vy0yb98Zr6IOTw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:30 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 15/16] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Mon, 26 Feb 2024 13:07:26 -0400 Message-ID: <15-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0025.namprd15.prod.outlook.com (2603:10b6:207:17::38) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d93afb7-7bc3-4dbb-becf-08dc36ed69cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bTLS03aqq1X9aYrJ1XUnu3AohMtuPvTqKY3+xErEbexnl7DjeuflxrER+A+ef6jHthg9FKw7JJQNorScQwP8momEjK9cXmvD1h4ah4/CIoc/L58ROvKn+M9Dwc6+i1SUiN13qQl3h0jJZowTAq5Ksjz/UiiI34YXopIUGZnSCvryIpL9yya+J84R/eFwQtx9pZMXyuXqK2Vd/flrW199gOcORGIW9BK9cZzcGblPpEIFpygxBwNrMdCJeXxQDYBukpZDrAgmuferc/F/ThK1SWw6UqNmwTlHENU4AyrV4UcNqVLhfKvCKISvxh/rZeI8a4VSMjQED1YupCg3Qi/GYdJUXLbukT00q9A5iEotKeb8fdFcNS/tVFkeCPIp03RumeSQpREH+Dzl8hZvbv1NDE/O0235IoE2DL8kjb+iDlDwLJy0tAosCzPppYxTTVgIJs4R9RyhumXjEpO3EypsM39Kq6vVOQegbKPwtDT9cje2cF1guL3B5I1WUV1V9Ih1dJaROT5qsZzMRyo67MGZ7L9gT2mX1VtEPNujTameCWtN8LIqPqhAQPlCbCTcE0VPzHIs5JO4V0JjNJAF7tWRED59stfWKdaOTQsLJsUzVXbituajdiN6bmF8fNAbr3w/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Dax2gul0eVi8XCU9bDdA0Zdr1dUOLKGtDeMC3fAcpMVNQ6AuZ542hKL2QDc4B7Rcquo13vnK2aung/UwdfgBKm7MSOnJdVOSA7igzGY5eBQ64Ar/8VlP4qdDyccvQo3C8QMG+ui3uZJl62mh05DQNYZSNqWD20bvmGkhfiThee1plhNOCTp8Xi8wnRL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7w/hRwv+KkxB4m6C3xNuNw743/BOsm6sS6imrmrgdgJOvUEeokhufwj7FkZTml3lgNjg4e/l24G+JwxTZE0oCMjuQ1k0JQvIt/kl+rKH1oqSF+exlE0Ajy6vxLdH6pT2wfRL8QoH6MAHpwqOqGEzL/BHnZ+kglJKtz4Fs1hdtf9FVsBm3nHx2jppB8EkL/J+C4gUfWCml3jijk+9yLqjTewx6XQ5ZI2OlDtTgICAO/FTY6yJvU0eus4S7xO1GOtGQmcky/LlBgfqDGtRLQUirrTRei0f0O2j3dHPkqMPuI3xXA3zy4e4I= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d93afb7-7bc3-4dbb-becf-08dc36ed69cb X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.2071 (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: JkC86n5lx58C4giJT63LebNHkApdKfrh62mMV11hE5HGJdU3kpLtwVZXbxqAxlch X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090741_178774_9517BE2E X-CRM114-Status: GOOD ( 15.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 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. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 35 +++++++++++---------- 1 file changed, 18 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 1303e9c603fc6a..ebd8362c8aa3ac 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -89,6 +89,9 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { { 0, NULL}, }; +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) { int i = 0; @@ -2242,12 +2245,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; @@ -2279,11 +2282,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 */ @@ -2296,17 +2299,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)) @@ -2345,17 +2348,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; } @@ -2547,10 +2551,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 Feb 26 17:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572538 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 6E59AC54E51 for ; Mon, 26 Feb 2024 17:11:47 +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=Z5nq1jEgldpuITWu7ceYMvKQ5kB6BaChLTObL1FCTsI=; b=puWwBt36gnsJh3 2j8fuTwp4KGGe0f4fGv16r9ZO7/4pv6qeLHTynk77CRW6TIBBM/3HL1B6MApH7arcXa7XFmhQR/BN JWk2UeZaZyHJI7AwXeniato/YBhvjajg7E9QcI26gKcdxEBYKKXT0Qy7z/ojLSsNfs6sKKrjhGVA4 R21p3RJCHnwsXrJMLnGNnLH5IQCOAJpEC5VmmrGWFIjeEfLE8LWnxoKSBURZAHxJjIw0HsnX/lovA w59Any12Nn+PSjUisICSbiUXDwTvzwIrDf7YI+7Cp5nR2CXhB7TtZYCWxdEyPKckfyXgDbmZ8kKI2 aN/X2o3dGCLzMlGRy9Tg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeVk-00000001rTV-19l1; Mon, 26 Feb 2024 17:11:28 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSI-00000001ph5-1Uea for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:08:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bk+4KDuBUWBRtL5vh3t8V5+/71reeouctdxe9HLyXkxV8kYeA6/9OXju2GTm2tEa53401HqVwFC5p0prvNow7ir3SBUH0D9pyVz97h0BMuRL57TMR5OvDGU7igdjbtdi+YoVdQs88cTTXw/m6l7kBLm9qFIFGvBHfj769kqnUdxKRSYfVgkUfQZYLTh0N0ETFRrVw6y6sHxsIPpkh13lqC+nkU8Ja/oYbOSq6PAkAhpJYaCuPzwFIxL2uaADq6jsJ4ifOGN2y3t/O/JBcFILjebAAZPv3iQTdigQuiveN0xO+tTpR9FOtZKypzTq9pDMb276+8zvWctsT8jhVt9gxw== 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=9HKnHrBwb+Z+1l+yckkMjT3Wrn3vM7nTUOTP4JZIUD8=; b=oSRceYM3sKF1XvQq9cB6OKZ9f131Bd7r4coivOKmoOjv+/zcK6ZxsDV8ccVuDqtBjQcqM/LtRcdbUvVDXp5De6yyzLGOs5f1RFRw9xZa6dpN9ohn6vCVCSOte+rfddfq5CV/T0SIIFeL/+luBgCed4IQiqGPMv2170Ifci6HW/MTVYF57TtuTazkyl1pr5xWnUMAVwsYL3d6ISAUKhSKn+WzSXu+OnZ6cZc8x/f9Bk16gI9jGNcBb6CuLJDI2NQ7dceSZi+I/e+cBqAmJyz8+c8FXj53CXCJQqnEJARV6A+WsA3RI7dz+Dbdejy2MajZPijuNKVyzcU3MuQYVz8HrQ== 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=9HKnHrBwb+Z+1l+yckkMjT3Wrn3vM7nTUOTP4JZIUD8=; b=Tr+nSZsCnHOashcbtSws+2MmRjuIBPQWV8pjoUubl7cCTzCqSWtMJaot6CHh8rt9UMFvuOI9fBsp+E90ilaVo5o+enxMe8qXignfGdPInyXIsE4ovgvKcY4F9JHp6WHsN4iw4zWXapp7LBkAi2+7+PhJ5e2ShrHIPd2Wsfeo53gk6OA8tMfv2IgPsCE1uDT51iEuqNYy/aL653LN5j1Koeyg8AfQPpRZrCZXbMk+/T7fIsUokNXYQzk8hN/D2ZV1yXI/CaB+cadER7qEUO0uLuDoeegXLehjBBbcik8VMHniJptSA8goU+zhT3kLzCJjh1zQ76PS5+p6n92WpDo6VQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:35 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 16/16] iommu/arm-smmu-v3: Convert to domain_alloc_paging() Date: Mon, 26 Feb 2024 13:07:27 -0400 Message-ID: <16-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0037.namprd16.prod.outlook.com (2603:10b6:208:234::6) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ae04752-1fab-49f0-ce70-08dc36ed6aa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8gmq6hnMkTkpgqNJYRsFfvQ2JRo3Ekc0EI6IrKlbeGw8hwfXF3IjbxrK93OUmdZDMe1elK2EKqUNh4kvYt2jSgPG5Jxb3y6aMBwKVJ2C5do3RQu72taPC63LWrh5SQkbN6okiZWRexTTI81kKXugbMjHTka99o6k9rr/fWQ/yQqryEfCj0X2ScCyvGvfwKAMYuXZM+Nu3JJTjST5TA/MFK9XFql30TiWSrCuApmXPBEG5gnpRMaK9iL7BTJRjvZDLLsqEzX75QvFdjYpwLS1OMnpMVFZ6kAUQTHK5da7kSFjCiHE2b86KG+hEDv8yUHGYxGM51qEB5DmocAH7/FkMHA+aKccNSrtoR1zIjIphkLLgY8EaaQzl4/ZfUlNvO8cfwlQCoJraB4jhA7RinTeAtt99uaye8p9EIoan/0RsHKozq4x/6ux973bfShO5QTL8EK99rDYcX2MLz0pkSjS2MuGmx/ijCA1wi00Bvvzv2UC9RrXpsCuiYYeuXMYxEMtS47TX0qnjsG/xf5TaGsMBCMpZWH7ixXhj21bV+dNvbRVqHEXQSX3ov/96h0L7kOrK0EIGYYRmDwogXUGjuXgzIrZ0ncINU2jIEceEsJi4xej5ugm13n5tnXyLyOgfe8cP/ZkH0/QSE7Cxt3uZYADMg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EyJxObzagnR8Sx25qZbOVq8kmHwNasVTl+hNBIEquw869ykaMbXRXYi0xkpDUl6NNTfa/Z4znOKZnKZwEQItbuNp4IL6CviHGe7tqnCzsubzljGmuezIzufE0teb6ZCdr5bR5aZlxlEX4Ue6OmpGzsmpaBsP1BrU92bQRHzQYH4K9s3NqOtGirLxEGHp5JbGpuT7MMgWAk/5FhvfzUuZVLh5o7TBWI8ilfWDiEV9RuQqBl3rSb/104WWz15bswU5b9ev0xvQBbjYAkNCXuu9VR5m+9wrI0pinhtuGkpGNJIhwlDIYbYhNqat8P8XiUsEyJicyu9xKw93/tKDybQ/1t6cfqynT6B3IH1vWSEnE3+vhYJwlV4BKQgJC0+FkwAz9QQF8cnaxmvjO00yvVaDS/qDNmZsymx0MxxxETLjr9FJojckwm3F1H+fPUj0ZWfKPYlduOZS9axT3yrYWlGGOid4172p29gnTBPm5uLoV67yzU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QOyxdOMgPRieFTX56UTJcu5M1v5xENh X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ae04752-1fab-49f0-ce70-08dc36ed6aa8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:30.5318 (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: R8JW88GMGh2FiEEf716Tz42g8gLvvKcQWrC7YswtG4OHVKtcH41cLr5fJQ+g2eLE X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090758_177164_AF3CC2BF X-CRM114-Status: GOOD ( 13.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 ++++++++++++++++----- 1 file changed, 17 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 ebd8362c8aa3ac..b7938f17222b4d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2197,14 +2197,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 ERR_PTR(-EOPNOTSUPP); +} - 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. @@ -2213,13 +2214,23 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) */ smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); if (!smmu_domain) - return NULL; + return ERR_PTR(-ENOMEM); mutex_init(&smmu_domain->init_mutex); INIT_LIST_HEAD(&smmu_domain->devices); 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); + int ret; + + ret = arm_smmu_domain_finalise(smmu_domain, master->smmu); + if (ret) { + kfree(smmu_domain); + return ERR_PTR(ret); + } + } return &smmu_domain->domain; } @@ -3083,6 +3094,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,