From patchwork Tue Feb 6 15:12:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547495 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 0A635C4828D for ; Tue, 6 Feb 2024 15:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9sMn99n5cmQDbnmUBh6mYfpliwnrxJtnHjMAv84E/mc=; b=E+EyzjEwU0FJsV TJYjXFVyugEFMJF8zaiI0KXAVfMkdIx7g8x1uW2OnifncNuFJ9meKSN24HEiMTLzytYZLZl9Hc8Sa q9A1FivGGaTJzqZewxIWlIBqJlVCah6YSbKyaQmiP+FptlqcmrT3/xnTZCTdxjVfb4zcAeCZRAGSb /z/VFW505V0dkfJ9HpuiuaNCoAfLvloPriGu+arjyCyNRk/ba8kjoJNIegDP9MDVapUmFnMW+WdBP 3UT84dWVkmdfh3gOW5ZpeNu3EzDRCn7CvlUcctS+2RHpVpj2p57X5rv9yKDc8Qhdcs06NgutceJXH 7tQK81e9fcrUUUs75M2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8K-000000081N8-1J1i; Tue, 06 Feb 2024 15:13:12 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8F-000000081KG-2dTM for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C0yYYaSQuwjBtTE2CDYz3SOZ8wL8VKq+HoXRBWxCTmz2yth9CPAUMV3rhEBU1nJu8cTu7DO1b7sy7/Hgv1EQQNo5SI5iEuka9WDEP05J4PXItVbRDMxPVFkX5cX3E0IVzmvhfTR1G4opQ5UD/HvHxiQzVU+o0KIzs/NikfD0JEXBlPkW2Xz2298spocEfU9H5uDi31/NEI7HUEUSUXI3gdNJMHIu1JmNAWeVWNV9zUA6a9iwE1foIYvhs6X3LZk64vBJrCFXPi1t6Yh1FWD2UuIpWP1hgLFXJZiRn/rHSmJUNvvYAr9IsHr0Tef5y/9kBUzxs0NwljaqmeVsSFMj1w== 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=+I5D2gPNRHK/MBD0rY5Aas2fW2RWXiI3aJggcLD4G5s=; b=NjyA4fcBvDn4DXdW1SxmogQaWTr31cKDwHp0UIRAC4fwFdbZJAE+A4wWDKC8ytSToff8c3QKXJHxGuODqc/82bnEsWKxq3FgDgQOR+IjN0+XAtirb6gj27Bg/qDXPmbK+yliImaJ+UIi3rrsYl083bUnDtEGuyeIZD3mTq9xudUDueiuhMpReeFSgaABIXV/uP0xbW353urGyH5x7mFEtv26fOYD6z53FxMrGa1JuD5bSsmGqV6QQxFt65gWF9/VLQFoyMj3Ogfym2249eAJlrUCR/szjXH7DdnubJCUmpqriOmd3AoAZSxV0ic5kjP3vIcgmQCnXz/o627IX+z6uQ== 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=+I5D2gPNRHK/MBD0rY5Aas2fW2RWXiI3aJggcLD4G5s=; b=jF5dtJmw40JctffQclqv16HAoSyrlCsguNK7XwhKy+QuDy7+48QGvhUcZK+TRXwcEYhnWVe5g7r8YK/4IzCWmaCOkItarOpqI+sOjKCWxrjF6tDwUQNcKzdEUGNG8cPZjNFTIgwrr2fkRm0aG36pphSIcy8mubTB73a8uuNvYXYXdTzsCeEWXJ4eA5hXMppA04B9MCj3caoEI+FW4ARHO+x1S4RzTM2WBVPqkp9bvJwbQa+IGu9F1dRww2R1ec93wZSbGGA0R0B2STuUIiQAgDyX3dnkG+JfupFaOmWXlSVY2z7MThAh8WlYjTYA3NVrNi5Lcuh0i3swZ4LP0ozn8A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CY5PR12MB9056.namprd12.prod.outlook.com (2603:10b6:930:34::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.15; Tue, 6 Feb 2024 15:12:55 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:12:55 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 01/17] iommu/arm-smmu-v3: Make STE programming independent of the callers Date: Tue, 6 Feb 2024 11:12:38 -0400 Message-ID: <1-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0008.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::13) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY5PR12MB9056:EE_ X-MS-Office365-Filtering-Correlation-Id: 6dc53d6a-367e-4147-75ff-08dc27261838 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Choav4hEW8ZUN5DH1M+LyCJZkL7rA8zmntFgm3QlaCjNFHLwme0pikJkcvWKfAKwF9PNlTZgYfAPOCFuYtaigEVFyiUjFsd5xxwKN/APu4KxDoJcGTlF/Moj0ezYDF8D6ajkTYDmifeWzBtCOYCeNmoPCeKeFtmimcQl7ekmKSuESga9AnO36XN8Cmsx88wKKpt6Y+MOVP6Jc6a7FYdwiPsjHQRTpxRIY8tpfx6MLVdfrq3vxTWKH57G2ExRWPVW/6eybQ2Al4RdMJjQdGJ7gIzExfP7phq7ARe8P04Kn4m0LGYS7VNrmyX9+d+SiYg05D6bKzcvBYbXDSJ+DR5OFNwAZA+WkLQpdgsK/dHZuZ72MlKjipEQ9Uf+B43no4/Vh6uXjtuYZUsIC2ZioGxmR92L6cx8SodHKNxXMeuuHaX7xSzMn2rZYnoomTmtRXmBpP7ThpG0xKSMddKiWZQ5keiYHQqwQfCPOcaJb5bFDjEs9pibHjJPyi4ud5EV3aAUvE2juGgO71Ai0S9IkxleFQHgW+Ne+236LBPzZ4KIpPXt/juzRUVy4yv76dJD01MgX4OQHQB7IPB1AkUmsevSr80yy3XePMVbaBWhb7AHvE8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(136003)(376002)(39860400002)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(316002)(110136005)(83380400001)(54906003)(66556008)(2616005)(38100700002)(6666004)(6506007)(26005)(6512007)(30864003)(5660300002)(86362001)(7416002)(6486002)(478600001)(2906002)(8676002)(66946007)(4326008)(36756003)(8936002)(66476007)(41300700001)(66899024)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7+Md2t2zM8F68AdAr57JXu+AudL140gRMeH4qtIEEgFMZoQjVfBnXkNRrxmEJR1YlKzvyOklSAWRfX4IV5mXLn5D3AlBk7+RySGUTEbIy65gsnzCj+6fZtewTfkA7PRX7GPfaGA+fglg+I4im+taRsqiUDjeJkyLPcq9Iygvq+sLMpxCNIYUcNw507hzZzqN8Q5z4I7IOpDVmDoN3TQypoDCopjlQytTRTj6tg3byXLnkoSL8m/F95b0DLtxHY+/r9UXc0DRcyMUd0wTIfIZz9UaLEk885GmMB3ez00VnU2ZytR9wczL23vI4R+43oRZFGH0gCmzcw4H2XvMMhehs0/qpGoDHlgT+wUvkjrqtmDkG57nyZ5AQqcDzI/4heMr0z6AAMON+cXZkh6GbzEMg02JUhho+xol1Kk5ou9daUCSZXMBEDZo8lhVj9gNu9yDyvW13xm4owuQBee7lHaVKg7WfJbmfmrDerp76UH6o4a50VV03IJFcG7EamD5/BVUorVHZlvmj/QpmgjI/sQnYAsWP05CB5m/PHQQmCyJ4uGbQoyONl+/TbhCHKJHNkzDXECzmINGS5P0cfpvgNSDxRI3q1lFEcvoKPYTSucbU6rTs2bpBIin31FqRSitbCnY9+q00eQjD80aDe9QFEJit5Gd5GKRPdoMkzWzlBN3rIpKdugOpULo5Tw5UyatoHjz6k2AKlOcv+Y16UmAh7zG5BoLjitVMjsCV/cnUsGKMkvXBY3dog7WrB/TbBtf+6AHClmMkzy5N2rE+prBQW2oWl4WvoeaQQW/bx6Ax+ka+gBGLk8gakgop6AWLjGQxndQYIRKK/SdOFM9OWhKmSK/bRFUWl3MzmUC1Cy861JD9GzjKWURz6wyFTrr0kAToS/SFwR1QzcvOit65LvG9IJGpXeoA9s59rjPtHmv2qtWu6HFErEpN9Wwj3WMCl7Fxh9aBO0GDAyP/o15lGhaz8yRwpbEmvnq94kET9fyxzxzUuhxYL3bgW7QugTJM2f/sgooLamHbpEgTAzhu4FpH/eBfgdbpTHwhXW/31wWFfvhUNknCHTT+HNbSukl7PYdb/lUonfYZhuRzXaijdEDSNY9Zlil7buEV0hXwBxHUCge0/M3n2l/z/+OXUTV57yOnxBSUNjeikgSDKbv1BHxrlImi+Avr6Od7Y5DrXQOaEUHSAhS/ZyTy7MPtGtkRb7sXdOR5QCog1WmZEMHXw9hEWhwHjZUMYrWwOOjf2MZS4TwaYTMC+NRySutfsV52v1HOaX0JDi2XzQP6gPbrnJ69aM9fC+QN/OyKpSJbyV2gh0mGNlu+JQxROT2Uka7wcMSI42NPNY3vLdR+G4LRKtjg/Jmq4AJ24vN9Gea/1oCyrXJ2vNS265K55W0tDMpS8YzibH5dU46dkHBlXzCUYUeVOtqg4iknQsyyr9s9mzZU9bFDltGdCM9A1tLWTe8GEg/D/I/Pq1Y2DTNwSO/ezkWg6D5S5i7iuViJ5SIzCBjLH/nA+AGK5nUnpRpHsFhGLiAWEbV8hG+KpYxRqshiTz0qn5BuoLK/vcA1VvDlVJW93huaZQ= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6dc53d6a-367e-4147-75ff-08dc27261838 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.0563 (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: 6ZTheOO7fB/2gOHWOhXJ+jFLQmMbAevzsyvsLaMk3pYfd/W7UjSF3+/iG7xB7zJe X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9056 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071307_753659_7D6CA11A X-CRM114-Status: GOOD ( 34.78 ) 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_entry() 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. Signed-off-by: Michael Shavit Reviewed-by: Michael Shavit Reviewed-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 330 ++++++++++++++++---- 1 file changed, 263 insertions(+), 67 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..f0b915567cbcdc 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,21 @@ enum arm_smmu_msi_index { ARM_SMMU_MAX_MSIS, }; +struct arm_smmu_entry_writer_ops; +struct arm_smmu_entry_writer { + const struct arm_smmu_entry_writer_ops *ops; + struct arm_smmu_master *master; +}; + +struct arm_smmu_entry_writer_ops { + unsigned int num_entry_qwords; + __le64 v_bit; + void (*get_used)(const __le64 *entry, __le64 *used); + void (*sync)(struct arm_smmu_entry_writer *writer); +}; + +#define NUM_ENTRY_QWORDS (sizeof(struct arm_smmu_ste) / sizeof(u64)) + static phys_addr_t arm_smmu_msi_cfg[ARM_SMMU_MAX_MSIS][3] = { [EVTQ_MSI_INDEX] = { ARM_SMMU_EVTQ_IRQ_CFG0, @@ -971,6 +986,140 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } +/* + * 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(struct arm_smmu_entry_writer *writer, + const __le64 *entry, const __le64 *target, + __le64 *unused_update) +{ + __le64 target_used[NUM_ENTRY_QWORDS] = {}; + __le64 cur_used[NUM_ENTRY_QWORDS] = {}; + u8 used_qword_diff = 0; + unsigned int i; + + writer->ops->get_used(entry, cur_used); + writer->ops->get_used(target, target_used); + + for (i = 0; i != writer->ops->num_entry_qwords; 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[i] & ~target_used[i]); + + /* Bits can change because they are not currently being used */ + unused_update[i] = (entry[i] & cur_used[i]) | + (target[i] & ~cur_used[i]); + /* + * Each bit indicates that a used bit in a qword needs to be + * changed after unused_update is applied. + */ + if ((unused_update[i] & target_used[i]) != target[i]) + used_qword_diff |= 1 << i; + } + return used_qword_diff; +} + +static bool entry_set(struct arm_smmu_entry_writer *writer, __le64 *entry, + const __le64 *target, unsigned int start, + unsigned int len) +{ + bool changed = false; + unsigned int i; + + for (i = start; len != 0; len--, i++) { + if (entry[i] != target[i]) { + WRITE_ONCE(entry[i], target[i]); + changed = true; + } + } + + if (changed) + writer->ops->sync(writer); + 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_entry(struct arm_smmu_entry_writer *writer, + __le64 *entry, const __le64 *target) +{ + unsigned int num_entry_qwords = writer->ops->num_entry_qwords; + __le64 unused_update[NUM_ENTRY_QWORDS]; + u8 used_qword_diff; + + used_qword_diff = + arm_smmu_entry_qword_diff(writer, 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[critical_qword_index] = + entry[critical_qword_index]; + entry_set(writer, entry, unused_update, 0, num_entry_qwords); + entry_set(writer, entry, target, critical_qword_index, 1); + entry_set(writer, 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[0] = entry[0] & (~writer->ops->v_bit); + entry_set(writer, entry, unused_update, 0, 1); + entry_set(writer, entry, target, 1, num_entry_qwords - 1); + entry_set(writer, 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(writer, entry, target, 0, num_entry_qwords)); + } +} + static void arm_smmu_sync_cd(struct arm_smmu_master *master, int ssid, bool leaf) { @@ -1238,50 +1387,126 @@ arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) WRITE_ONCE(*dst, cpu_to_le64(val)); } -static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid) +struct arm_smmu_ste_writer { + struct arm_smmu_entry_writer writer; + u32 sid; +}; + +/* + * 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 __le64 *ent, __le64 *used_bits) { + unsigned int cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(ent[0])); + + used_bits[0] = cpu_to_le64(STRTAB_STE_0_V); + if (!(ent[0] & cpu_to_le64(STRTAB_STE_0_V))) + return; + + /* + * See 13.5 Summary of attribute/permission configuration fields for the + * SHCFG behavior. It is only used for BYPASS, including S1DSS BYPASS, + * and S2 only. + */ + if (cfg == STRTAB_STE_0_CFG_BYPASS || + cfg == STRTAB_STE_0_CFG_S2_TRANS || + (cfg == STRTAB_STE_0_CFG_S1_TRANS && + FIELD_GET(STRTAB_STE_1_S1DSS, le64_to_cpu(ent[1])) == + STRTAB_STE_1_S1DSS_BYPASS)) + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_SHCFG); + + used_bits[0] |= cpu_to_le64(STRTAB_STE_0_CFG); + switch (cfg) { + case STRTAB_STE_0_CFG_ABORT: + case STRTAB_STE_0_CFG_BYPASS: + break; + case STRTAB_STE_0_CFG_S1_TRANS: + used_bits[0] |= cpu_to_le64(STRTAB_STE_0_S1FMT | + STRTAB_STE_0_S1CTXPTR_MASK | + STRTAB_STE_0_S1CDMAX); + used_bits[1] |= + cpu_to_le64(STRTAB_STE_1_S1DSS | STRTAB_STE_1_S1CIR | + STRTAB_STE_1_S1COR | STRTAB_STE_1_S1CSH | + STRTAB_STE_1_S1STALLD | STRTAB_STE_1_STRW); + used_bits[1] |= cpu_to_le64(STRTAB_STE_1_EATS); + used_bits[2] |= cpu_to_le64(STRTAB_STE_2_S2VMID); + break; + case STRTAB_STE_0_CFG_S2_TRANS: + used_bits[1] |= + cpu_to_le64(STRTAB_STE_1_EATS); + used_bits[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[3] |= cpu_to_le64(STRTAB_STE_3_S2TTB_MASK); + break; + + default: + memset(used_bits, 0xFF, sizeof(struct arm_smmu_ste)); + WARN_ON(true); + } +} + +static void arm_smmu_ste_writer_sync_entry(struct arm_smmu_entry_writer *writer) +{ + struct arm_smmu_ste_writer *ste_writer = + container_of(writer, struct arm_smmu_ste_writer, writer); struct arm_smmu_cmdq_ent cmd = { .opcode = CMDQ_OP_CFGI_STE, .cfgi = { - .sid = sid, + .sid = ste_writer->sid, .leaf = true, }, }; - arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); + arm_smmu_cmdq_issue_cmd_with_sync(writer->master->smmu, &cmd); +} + +static const struct arm_smmu_entry_writer_ops arm_smmu_ste_writer_ops = { + .sync = arm_smmu_ste_writer_sync_entry, + .get_used = arm_smmu_get_ste_used, + .v_bit = cpu_to_le64(STRTAB_STE_0_V), + .num_entry_qwords = sizeof(struct arm_smmu_ste) / sizeof(u64), +}; + +static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, + struct arm_smmu_ste *ste, + const struct arm_smmu_ste *target) +{ + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_ste_writer ste_writer = { + .writer = { + .ops = &arm_smmu_ste_writer_ops, + .master = master, + }, + .sid = sid, + }; + + arm_smmu_write_entry(&ste_writer.writer, ste->data, target->data); + + /* It's likely that we'll want to use the new STE soon */ + if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH)) { + struct arm_smmu_cmdq_ent + prefetch_cmd = { .opcode = CMDQ_OP_PREFETCH_CFG, + .prefetch = { + .sid = sid, + } }; + + arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); + } } static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_ste *dst) { - /* - * This is hideously complicated, but we only really care about - * three cases at the moment: - * - * 1. Invalid (all zero) -> bypass/fault (init) - * 2. Bypass/fault -> translation/bypass (attach) - * 3. Translation/bypass -> bypass/fault (detach) - * - * Given that we can't update the STE atomically and the SMMU - * doesn't read the thing in a defined order, that leaves us - * with the following maintenance requirements: - * - * 1. Update Config, return (init time STEs aren't live) - * 2. Write everything apart from dword 0, sync, write dword 0, sync - * 3. Update Config, sync - */ - u64 val = le64_to_cpu(dst->data[0]); - bool ste_live = false; + u64 val; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = NULL; struct arm_smmu_s2_cfg *s2_cfg = NULL; struct arm_smmu_domain *smmu_domain = master->domain; - struct arm_smmu_cmdq_ent prefetch_cmd = { - .opcode = CMDQ_OP_PREFETCH_CFG, - .prefetch = { - .sid = sid, - }, - }; + struct arm_smmu_ste target = {}; if (smmu_domain) { switch (smmu_domain->stage) { @@ -1296,22 +1521,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 +1531,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 +1543,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 +1552,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 +1561,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, } if (s2_cfg) { - BUG_ON(ste_live); - dst->data[2] = cpu_to_le64( + target.data[2] = cpu_to_le64( FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | #ifdef __BIG_ENDIAN @@ -1368,23 +1570,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 Tue Feb 6 15:12:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547497 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 5D29CC4829D for ; Tue, 6 Feb 2024 15:13: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=TZz4vGRaRJgt5kj8Ze3ys9Gz/HtR0mBhg8jAv8O+oJ4=; b=mfToLncc4h7RRb ru1v6YHD3LAmrWCgcED8xXxfXEQbWzSHyv7GE+lW/Bn+h2woCnB3dO4Bo0y+CNztO/DVnISZab/WL TiP1WWL9POPJfdIuMz+3deCPdkbS0ROcfVCHaGh1MYNmrINbTKvyzpQwSwWfSmzCavXHWLmotywxg LLJuz69+PQbm9/B2hVUtA+UDCKjHe7Ybf7GmPRw2snFtd255CFdLKYMtkt7c3YONhal8CjsR5ZXoM H7gvlYZHQqIClyNDCUd8QG4EBnH7FVUcn+fM4hUpj3qPOkHoG/WL6aQ/wqpn91Stq1nt9rHhwA0xz kwe2TUWVo+UIlozDufMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8P-000000081Rd-3Eus; Tue, 06 Feb 2024 15:13:17 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8H-000000081KG-2jRy for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SIrXy1vp7GyuK/P6j+FCOXqx4rJbpxCwR995lFj5DcDlwzyViWtFwm/PjVy+Kd1kHi6wWmI0G/4KdDViEfPcGt+8HWt3riNNXyeGDkhIMd6KIZoH4o4YGhCMlpQoD+QrHkjDNlbXcOsmfNSK0Z7G7bg4/spoFtAatIumHqvLD5lgx2yghx+j83EM3ZNdrDs1jg61bwpZ8JvIJJeJfw09Vc7H5wilb8dNGc3dGRrniej8ivoYKxE0Phq8cY/2/8+uVshcbZrEv4QLDN10UrDt5fnCP40ktQIbyQ5VWsPWucXutp4+7duKdzHtgsmnVqaY5njU4KiOFbTkdPJXHRx5lQ== 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=cl2D0SBsu5wOHnADSxmOIpgcLebBg+x/x95uXFL1poI=; b=nMCUfTo+xRPGcrWl6peiwhAPFrIA/tY0KWw+hdgsj19Cwv/iu05eBpGwE6rdbAC2iPVgiMj4LDQ/R7XHID6xsWcrx0i1+CXA+nWi/uso6KvZPH4OctItlex4cvF1T9y2kVTESAxO89KSHqkL/kqxLOQlisPPSjW/1O/oemjMPUm/3ugJtX0Hx1ZQolhZn48bv8EqeoM8x1+G3oxY+UWVWmiaTrMqNY0vQDLMrGHHSZbatO37tzhgKkDOnxFUhlSUWlDn6S8T5pj0BavfVrXTmgWwrld8HxmUvNuwGks3KmgnER16aLHrMcR0aIqTq7t5HQrqIbWLY2S8Bbl6YLf1aA== 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=cl2D0SBsu5wOHnADSxmOIpgcLebBg+x/x95uXFL1poI=; b=KKXQtVK0LkyaSLwHT8BlmAYW6euyZiInYAMTMPKYwqaM+9/NoLfYCy+gE0n1xN3bKjD6WrTfJTrVtZvpFu75SAM37+R6VEaVr5IQlbzcKgtpMFbfQyQt7qLjk9NZ6Bj4GP3P9yjBuXy7cqDeX9LDGealTNd//J9Bll7aQEqMND13iDuyP6dHebFS5esiFZq/YBzUby+KO2mP9zk6S8BhZLsCbdETv/kraYGvrihtE/Th2ZpL8q8uOztX+/M8NL0HT9qx1VoVKoV7VG10ZsjywXsB4lQVKY1b9+pXvkRkV1cBvMSe2GqlwiA8i4AkYMPo6OBmtSZoUsa3rdwT+KgwWw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CY5PR12MB9056.namprd12.prod.outlook.com (2603:10b6:930:34::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.15; Tue, 6 Feb 2024 15:12:55 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:12:55 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 02/17] iommu/arm-smmu-v3: Consolidate the STE generation for abort/bypass Date: Tue, 6 Feb 2024 11:12:39 -0400 Message-ID: <2-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0030.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::35) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY5PR12MB9056:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f5ff0b0-f658-4f82-7820-08dc2726184e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RBSnNIVwGg9qcAmIvA4Y0OLGLrtVnEIiZjV4pye9EpOFYhEzGjcp+pc1vPcbYinDIQHPeC5Rk9jypLZXRzfn1gICyiaAQrKu+76VSR7iLXLmRxwYx1+0QeuJmdbKAyidcgd16uLqUxZeTSyttNDtOPbobt8w0xSNqhuEv1GJY4/639pHcZVlst77v2LPqUsMvIxJsyjY5aHvimatXLH4gN1xqX0mqAEr7wFJBAQz1r50gb9J0gfAPR6pYQx3WC+9bYmb3JygNWMUqYAXE6WEEONCklJR7ldwe+FHIDCjBuSmBEvQGLv6qEcyJx+MB837L4bKpSh7umfJCbmQl12kB75Yf7O2QGybRziUxjwFGomj5zOfc88pG2q0PAeS8pMn0uh4ns5vcABWixXOKqQelFsQR08X6i9M/t4WpndwyWcZuOfugYTttl9IR14UO9s7R9T6lcbi6daWQooLmRG/J1y9cfx5DRIVtcFgKRbYENBezL+h9CM7biXizIbielgFSsBd2tlFJ0AB3vMhDxUwmGSWFylTcnPq6LwijcJVBHWIXNY1KUvD5RkA1Es5GQMRI8w8u4ZdKY9QCKduWNvI/iy96/kdoCuPPYximfaNd4Y= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(136003)(376002)(39860400002)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(316002)(110136005)(83380400001)(54906003)(66556008)(2616005)(38100700002)(6666004)(6506007)(26005)(6512007)(5660300002)(86362001)(7416002)(6486002)(478600001)(2906002)(8676002)(66946007)(4326008)(36756003)(8936002)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D218N0Rh0QZinxL0bTaurPaJD9hF9sm9XPa9sgUAoyyAaz3AKF62QSstGR8EiaGqSYxSGdcKA7s+LMG747ap6o5r5UxJ6uaRJ/8yQbXN4d2KUui0EP8u97ysT3ABpQmZEMG3p3wRPzBrKyTWX4Te0T2Erd3/sxtT6qGDgU/yLv4CHswSb3NkTKSuhv7LOlCgKkxy/3GizhB7VIHFVOt1djfrN93HwArhiM2ozWlppelH9ujaOZfSj9nBFB/bUCV+rG2Fl/PaqwjDrpmZSHuz+tr9ghHrK2KnWh48aUgcqWXPhkuz+G1c5Gl2fi1r6K4THOqCjhI4RHWzG6uyS1vl6xQnAsQSGkrzZNSOvWEkyVlfOLABCxGJTkhRr9B9YDEIRjvPwD2Pro4Q0h9/pLP6MXN+YzFKgKtzpy9tJ2YIhAWgrHomKfWxtxHdlTzxcfEecPPvLO3+7po45cuP07zjnuzEQBw/N4BP/A0bZnRzvbv7FJh/vvVacuTWnlPMuG2IEBcRg+3nUHLdjvXn3PQlPoLjmDavFd0JnNPjtLZKbOtKhCio4BwFabho68MQmzOedsqmH+cNgc5to4iQCaQxP1xFL7gw31WVs4uhaqt/eyZFwie7bH8nIjHcZ2CJhrDB3CDPvvH5eAPAThDW652NfYysSjUnQneh+1MnoJDwwcIJIXIi0hK/lruP4J+/cisUWQw9wbuV+YMQ4gnL+p3XTj2gfI2zQoQ3bu9FUa009dxIc4hJ6r59UI35vRYDPOWfpmgAFrCDNHDePcquZWYrTCRo7InOprYgR0MrGrJtQHowQSOpxUOaS9Lf79PydKm8p/1wk/s8LLSfgrSNtipL1yV2vVjR6XvCa+kUds3yY8QzEGY8jLbx8ad2tMwWdvTVcxJ6hq+Xfw8Uzakui/WNntv0CuaT1rXX0nz+/puvHjVx0iSkWaD3l5OHzialqpd12wdm+A9f7kSrZWdVGG6M2eSm1NGuyKorIVR8sw5Wv0+C395pgDmj77JSLGw8l3i1M6gjTYW5n9IC518wYw4u0w9Mx8x6KCpk2MpYYuglAL8GJf+ZzxKwQV1wwDQ9A+gnKnJ5ZNo3H7b5PWfxmfRyXsRjC1qqU0c+MNGcVSyhULK/jU83gamFJGqj3hAA0iRU8RZvvdVZsaL715gE6hiBC/ULMV8B9gaTlZGxNH2D+PNFHWRQ85+xw8hocul3u4TCo9DFA6jDAK6VqeOVVj9q3YbHAsdR02uYcSufNdYEni55LVJKI+8GpHrtwl5z6qRjWvGjJ3fXQJqXPYGGIDLCnADJeprGSaWcbDS6EqPeiivnk7SJBSxBX5lsxJJ7PTDx6Jpp6VToLVP2cNssMiwu6eGR0+Q6SbA7FZ26Jc7dyK8uSCV9vamXUTdvI2UBD7To8bERlWC4/cJ6QRGtB+sApQB3Z13V/6cSEML5ww83DnQYWa1gLX5QKgzrjiSkSw3Q3SO4e6LrOU7HMXV7g5OfuB+xx20UI9hxZeSBirdcIbHHAnc65UcFaIPtN1oaUiLzEduDlfaPYdTx5EqKMShKFqJ4IBNO7qQ0W00ITHslPdI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f5ff0b0-f658-4f82-7820-08dc2726184e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.1270 (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: Vk97teK6gujfuMvCMhtFvIPHal21QbRf8ru4ImuDPjFJ4ezajVgEmwnxvA1B1GAW X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9056 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071309_741158_DF1DDB54 X-CRM114-Status: GOOD ( 16.41 ) 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. 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 | 97 ++++++++++++--------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index f0b915567cbcdc..6123e5ad95822c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1498,6 +1498,24 @@ static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, } } +static void arm_smmu_make_abort_ste(struct arm_smmu_ste *target) +{ + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT)); +} + +static void arm_smmu_make_bypass_ste(struct arm_smmu_ste *target) +{ + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS)); + target->data[1] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); +} + static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_ste *dst) { @@ -1508,37 +1526,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; @@ -1583,22 +1595,20 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, 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. + */ static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, - unsigned int nent, bool force) + unsigned int nent) { unsigned int i; - u64 val = STRTAB_STE_0_V; - - if (disable_bypass && !force) - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); - else - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); for (i = 0; i < nent; ++i) { - strtab->data[0] = cpu_to_le64(val); - strtab->data[1] = cpu_to_le64(FIELD_PREP( - STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); - strtab->data[2] = 0; + if (disable_bypass) + arm_smmu_make_abort_ste(strtab); + else + arm_smmu_make_bypass_ste(strtab); strtab++; } } @@ -1626,7 +1636,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT, false); + arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT); arm_smmu_write_strtab_l1_desc(strtab, desc); return 0; } @@ -3245,7 +3255,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); cfg->strtab_base_cfg = reg; - arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents, false); + arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); return 0; } @@ -3956,7 +3966,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; @@ -3969,8 +3978,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_init_bypass_stes() + */ + arm_smmu_make_bypass_ste( + arm_smmu_get_step_for_sid(smmu, rmr->sids[i])); } } From patchwork Tue Feb 6 15:12:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547572 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 1180AC48297 for ; Tue, 6 Feb 2024 16:16: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=/5uebLlPDwgP/caCLJQSVKFxoNCSqkfyHKQGUF6d0S4=; b=h/1qePNTP7yOtF dwLJKx+VWlwUt4NcMvldgDwGBi4FWcVVzFCfLQqfk/1gbf0ZYseENAg04TzXiS1eEDfIryjnb1efs wp/9LPu+eNaaMHcb/2UaFc3cXBvTH8D0lojlh+F8pKcFtX1aSbAM5YN4H+ljuu+I0V0zoVr49kkk5 vq6b5HZ1JQuCLxZQggEP6yVCgcqjyML+EAqRh0MN8M2llEG0SdhEc1BTFsy/LjxfXz62tAKSfWqQ/ oCvWz1U6RH9DlOH+S6cKAA8aWE7vUHoKOmymVOCw9FA+Spxfum/ATr9TiEOawMozhZ5SYoL4jnpHD /+UtDmu9mneBLcxTcNnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO73-00000008E3r-1bqW; Tue, 06 Feb 2024 16:15:57 +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 1rXN8f-000000081SH-0sLN for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G34fjJSpQ0kduLsXZJ5c84oZvNJXqsRDxdjbLNpynr1tYApV/0zGTCB+Smkn/L4wGLLB7lCuY9ZEz6/CtaxnYWXgltYvGPUTo7GNmjC0JS4qWFrJXQlmRcibUv/ZRKj1/i5tSnIPqYwnWzhWX2Oe4TYXW8cJH5311yuadm2eQrJw1K1/kF03D9ug+k3lWg5Sc5tPIn6SmM4aq5N2Vlc1e4DJqSF7WGubIuyjuwG5NeUhyAGevDfwnK/D4ylE2+AONEzz61tZtsHskJVgsZTqo45tbf9ovzwXmk4kEbVo8c/iZKJSkNH+4usyUjxmeO4ZczYGSXXIWm0NSK2TR1QJPA== 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=l+Dk12EO8hDjmK2ptvYw0ZTw5jV4QwOm9fbHYW3yr6I=; b=oR2p/PWEQ9XcEBCPrp5CEzPQEAspYwRTWXcOUOgMgc5pJp5p3xfOmRFA/GALVu+xsaEBFFo4nuyZ84f4C9iNRoCgOHYI0dTvpiACH9aaGnXCe0VtfGVzPVvBVMbtMbDJRQin1BL7ias0OwB48JIiCuiUu2n2yVyxXarrfhGUJ1k8/n3b83cNDemyHCWuYgEz1HzKIHUOTXmV61vhpsm4vKNciH8INOCU4DL7lgiWGQzL8i0NQre8/VChetGw/WOkFCnMzwNuSO1hiv6QMwYiQ+VsIwkhGrzICJahMWXJHHdLM9bqjz5I1VLWo7UueQ+JbqpJq3pCn9Vw0Nb7+ZQSIg== 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=l+Dk12EO8hDjmK2ptvYw0ZTw5jV4QwOm9fbHYW3yr6I=; b=k9as0WuOqCFotxgbT6s+H0BbHNODDZgBl0xvlpQgTm+T74rqQdDhdm1IfJXLRst3/NBKgFJhOtiXK1Ukjo9FwlVjo7yU5PDxsIv3ak6XAJ0AejIKvsGX9kdwI/cn0caMJvLPz17oou0CEWLQgzv8ik8tIOlQN7Aeax1qEtVVDuY5ALvi/mNcLwhsueKflce5U828CnYNYjlBnooqFB+FuA02AkqpkgT/pRC6KCqR06QQ6psRoGwshNqBmTguy39aCWe3bmBqg6jnm0Lec3CMJBYwedGWI1FUIVoJXcSGQWjPJlqNL2/wlSH2JAQfNHsAEsfSGIH6xM4+87dR0Honlg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:08 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:08 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 03/17] iommu/arm-smmu-v3: Move arm_smmu_rmr_install_bypass_ste() Date: Tue, 6 Feb 2024 11:12:40 -0400 Message-ID: <3-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0011.namprd13.prod.outlook.com (2603:10b6:208:160::24) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: de6da36d-4e02-4fec-7bed-08dc272619f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jGf6wn1ME46N0JSoZSEtfWdSUJ6+Ur+wUvdOh4qzSOxyysVMlD/xZqJRr7KJ7nuV/n1o5DZEWaOu9cyJqVpwnsCmEFHI0C80YvbMcUa7icNRrVIt7ywzGQ+9aCJlbH4jtPlyefpLTqu02Wbfv3xCHMie+0jDI7K2ieLtfivPJvittUTqPf4Y2luvnsG7Q/PSx37oHoFRBQ+FuVnYgFXp5uGSV3AZxrKmBwapAEmt/RHjMhcF825/NIzkKmEJu2zB9q8fMGZYOOW0XloicdK0A7INEetgHs8uyNAnz9dC35Ph7rKf633btX1slKzrlvcWsyFn5DRdWs3FbwtHK2Zxc7iVyTfUAWAQU3bgjiHDGHtR+923d7Lkh/MSVggdomwQXnRjJBG7lw69LZcBfY4A2Y/ybgz2saENXsLs0HPF0LlWpQWLhOOslI5DZWkd04N3Zd2b+rH+ubDkuqbopWDnBPrK9DInZAnre1onju/GEZ6ZJcQwleRRHyUfk4/7rajQ5/myiog1zwstAhxgX67FqEd/xk9CLmipdCfm3uyNs/qn6AGcN09VTEhPbUIMjG8LJRZaOAxWcz8vE34Y3DDNyNSuLjO2uDJbLW6K1bhM7KE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CZnadTZy/exl7cjmSNwDRV0EjLlHvdpxOyW0GncN9GUeEMvg4tMaY0f+ZJxZW0MKTJ7BQdxpCL4QccH1jTSnrz2qnq2aDBBOweY1QpI/W2T+r5k3yWT1Bl3PIh6GPoHPFqRN97vvBDnYTDkaRmznsRcjrWUVFmkcRV5axCEiP2IUPq8830sMtNIOv5z5xt/jBnj02VfLSad5kIdyL44BK8g4tSEPrBJDMqqFfc98z5w91IdWE2S1PqrOgg9V82dRrHjJQanjgB5P4gvtYqVwwoCZqHqCQZd43oau+55G5EE+CUwKh7BsWyM3wEZBAjaB4L1KCwxYB6wzcVtGBfYX5ePIIUyWEVD/vK6+BGXweZBiOXxwUgoiUIft1ZDxjvrcETZTf0A1oFqfSZrmp/8Pkm4y3dr0ES7XFV7t6yBbfyts7WuhJJOjS77jdLKvyu00VsfvHN8MhccgqX5MNM24TWlMclOnfsEuj+6gknVMjcTDkpUKBBb7cufCcvvxKXvEoToV5xAOCzI8YReBnEdE7cLYmZKPiBF+1OKnZeFV0wN4iVJEXxisoPsTbmpWH6eekK6FF4NL8aEGKKQH+IlTJhytqQHIZJ3P2/WeFi4vlJE8wjsooJMzVp2Rba8FC0SZVi9HAWC6sJQhaEdBlZWu/pwhjYClO7vnk6P94kSEwkr6jb0sp5tP4dvIdbqAIdFdrlRHja+X9jYoCr9ZcXbLBFxkFYjYmBTp8NcozdnqNxFvYbIPqYieJi37EUuDNzb4jg+/Ds/dFGNA+YXSppmlhOm2svXFe6zTOSs0VzWgb5uVy32NMTybNoh1On65KN3e0lTDYlwtJRcK01FYqHE8E9P95Cq3Qy80Z8KoDf33suF3v7GnOmvmvegIJSRIWQcf9LHCPWLzA56EmL2u0pEqF5OhrJW8Fn7qhh0/iGRRjPpH+jhasBDEq18nDolgga72bg3/CVI2SDPtNa+X4ergQK6AyoumDHA71C9xC7HdWQbTEF9z3IeYoYXty5QTL3OLL/KaslPtvasgjs1Yi46r4ENClvbTXAeb3lkKU4B+CMjMVNKTK4OCuJldxnIbw93Lt/RLlmj+uRw1TRfQKdxZ4Yj3Y2xEnSbQCoOhlKjyo+yoTOUBL+dK8yQQPduVJv5DUaFJ4EFD7BOg/DbWMELJwl12/hNU/7mX48Fh6F8iuvfod/Y0v9xmdJ0IZT2LLDUQKnER8wsqdxvZvoaqmDlKcMyIZ8jaEqZsYiP9FpLo56ZWLgsPyr6rWD9nSmA4sU/2Tj4AJvTnzq8o0suYYw8UMzF/aytaXgFVpKDchiN6OhsPBb4q9cZZUnWu+sTKbmMR3YoyXBzGsB4otE6D06aj6cL+uCc7V69D48zcdlOJHqvp39tpZsGlZvCKTH37TwEnsnOzzbecMzqSSOB+iMuOi/o9uEsVwu2+z+/UNjHBBIbEKKLZ6qDd+OMP2D2Sh2+EtIHF3wWCSOYy3n8bcQZW8bzUD76wRQcPXxb1ph+RUx5uOLHPSSWwYYqcycdgpgmOoybTP00CmRBePNu2UbaeUQGrQOPYX0wzmFv2eMOYBmKE8u/Z5dCPwTRG8rG5lRS0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: de6da36d-4e02-4fec-7bed-08dc272619f9 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:57.9205 (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: NE7wcQEcB678n/y93kiI5Fc2L3lHYaT2F6CpZHqG4EOCtNZ4sjOxo94yy9s0/hmw X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071333_572549_2337E002 X-CRM114-Status: GOOD ( 12.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Logically arm_smmu_init_strtab() is the function that allocates and populates the stream table with the initial value of the STEs. After this function returns the stream table should be fully ready. arm_smmu_rmr_install_bypass_ste() adjusts the initial stream table to force any SIDs that the FW says have IOMMU_RESV_DIRECT to use bypass. This ensures there is no disruption to the identity mapping during boot. Put arm_smmu_rmr_install_bypass_ste() into arm_smmu_init_strtab(), it already executes immediately after arm_smmu_init_strtab(). No functional change intended. 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 6123e5ad95822c..2ab36dcf7c61f5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -101,6 +101,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { { 0, NULL}, }; +static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu); + static void parse_driver_options(struct arm_smmu_device *smmu) { int i = 0; @@ -3256,6 +3258,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) cfg->strtab_base_cfg = reg; arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); + return 0; } @@ -3279,6 +3282,8 @@ static int arm_smmu_init_strtab(struct arm_smmu_device *smmu) ida_init(&smmu->vmid_map); + /* Check for RMRs and install bypass STEs if any */ + arm_smmu_rmr_install_bypass_ste(smmu); return 0; } @@ -4073,9 +4078,6 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Record our private device structure */ platform_set_drvdata(pdev, smmu); - /* Check for RMRs and install bypass STEs if any */ - arm_smmu_rmr_install_bypass_ste(smmu); - /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); if (ret) From patchwork Tue Feb 6 15:12:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547570 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 A2332C48297 for ; Tue, 6 Feb 2024 16:16: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=M9CbssaCsdcRnR6oe+yexY9oMcIwrdI+J/XkhPJ0vJ4=; b=X0w3fLc7i/yyIU UpGwsH+vXSzFR9GMHKKr19C7EVxO287Ch+JI71aDW38qwE6fOatLHyA57Cu5dUO/4isdHv2E3PGRQ DYh0J4QSnezOG2efFzZRmd3ig6Rx1cYZlqlxFJzgPDOQpvpOugxZlurkSnRsH5jLSf5ErPE7M74Zi 5V8aREjGfbsgYjbFuXUB4Do31uisKhdBfUugeOL+0G+eOnVBQUoUMeas9zz9sneQWbJLwmLjpBVUN 7j5VAqSFHx4PZ8wDLxm1AwL6Zh12Peu473sy6r8HQ7sak1cMhzeBFZvT+wuOcT3MJnwAPjO6bBKFy cp61xfgORzGPfa9NB7VQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO6z-00000008E19-1GMM; Tue, 06 Feb 2024 16:15:53 +0000 Received: from mail-mw2nam10on20601.outbound.protection.outlook.com ([2a01:111:f403:2412::601] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8M-000000081OF-3lCD for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KaAJ8J+KEji5xEQxuDWt8mdhfMBZCl54ta1mO4UYrJnn7ON3SDE+EYCDL0OYXXL4e2jiD4ZkPNgTOrY3K3SLg+LyBB5FPykp70hFpJnOtLyuuOkqdZkvzJv9jiumMMOxxfYhcqAgXA78vV7GPE6q0B5C8psZLkZsjD9LWa/GoKG/iuzS2IOzXnqJxgUht3k0bqCts4lG5NQfscQ9pIzt19971sIfyA3NMJOcFt0oZvy6G/qRWpbX7lyygpXjRRpMFuhPl5MS8HX4hfTBTRWFI/dYMu1rPtQtlLGNbAuTltje7b2+utEnM0GkromcTo7vncxB9TuaUFzTFLfgXeCEKw== 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=ATPzBLtDX0KwUQwxQ9j/aCeqHcWInQAliwQPfgKxHJ8=; b=hGV92Efwh/DFAOWBPvMVq2dOvVqVQ0asb1hdrSaQuXUOzbMPJxeBzJ6TKAwmIFzn/qaMWo/0G13y+nIkKDWnHbbdUsKAUeeTSyEPblpit0Rm6KERbJREsk8gkmmSmfPaVa08/dsIzJ0qIxCvgPI8zlCQ8kLRn9/LiVyAgs5kh+8sH4ChIjAnPJS8Ih15ipGg1LvoplnYTXHKN5Z0lPtFFtH8WARC82BO94lziNZx/xgzA/arSRfREuTJvkvCQvE+Uwd+BKaz3csHYU3OaJQ9hAQRbpe/y+UqnBH21ev2DpbEeO3nSOE8I9o0kzeVtb7X3fPfYdb3bF+PGQX4MQ4RYA== 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=ATPzBLtDX0KwUQwxQ9j/aCeqHcWInQAliwQPfgKxHJ8=; b=djuPwLVvWWJ2yO7jBWJQUQxBmrVr1IUn4knRFXXxaHrbp0B/J0CZofTujzFPCtEI7JnFNbytZBTBMSly7mUc+MgJvRS2fs1H1pUMeumFxuFiBQXaw2xtt6XxUXrsRcqoEUSb0//95FzsgDCWTscxOqkyFJ2qgSH+YWpGBs5FhP/JcIlHNn/PMU7M8SPrb7XWZIb6YwHfmhhz+O7F45QyWAq9mnptQ6ha5zlthOViqtK75LGxBr5s78PZbUcYNhKkeKDosnl5Mkja6aJX/wd5TyJnw08FnBhem6kEwQF5Zo/uVckWy1oT62AnuUQQp0jKMtlRaFmhfwKh8+CJ7kXoZQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:01 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:00 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 04/17] iommu/arm-smmu-v3: Move the STE generation for S1 and S2 domains into functions Date: Tue, 6 Feb 2024 11:12:41 -0400 Message-ID: <4-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0004.namprd13.prod.outlook.com (2603:10b6:208:160::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 6319dc91-7147-4e23-1b07-08dc2726188a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JI2a8vom1MnG9cM58g33V1S61fFI3nAsbNvx7VuT+9vjsp/4OvFBBzkUjX42RJJPDVjVMq2f/S04jppfJyyMT0we5NOLUwk8u59luC4X5994R1iI3t086j6I1GYBVCIr7SD7J92W6a91dhLvgn57QHT+oEMAAPwPODFMNxfneFlhsU4jAurDKVi98Z/SBkclzxT8Ki5VNt0Cb+PGyl2sBLiKDmsy/e6sa929pCXnOZp5O22kDeRqmKmOm8Tu6t6rZWoRQ7WJjvFgGdtrOpXivdRlZT+YT2bVS1jNAX0FhYn+GXJRy5/+qna48CvTr1rKzqYfrpf+OZf2xOktGaRYHlSVjjJr71+vhHoDoIcvDjzipfsZo/qSdlKOjuN8TuF2bVzvn8JOBjZy4uRCZ64z+2rDby+tB0VcelNUQ57ftofqfccNxCS3c8NDYoJ3fZCOaMse7fChKb8Q6fB6dShEGcNqim+jYP83y+tcrPb8da1eVSoNPfywYcenxWHcNCN99fOZnV+7mubF1HmeNRh6E/yJrg9Uoc+Kin0esjA45eQFDOzj2wzc+Uww4fChi6pv7X9j17FuuCw2OL2iScdMjeftsqzSPz4B2yXEdI9MN9o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: usifx7nyjWJKMy74y6d1UtADM0xZD/URwEVQUdJevo//8CgcFtpgzN0cOt49czqjWbn8hguLWMThJncPnuMZdCGWhm9ommWBdM8KVopLQLRFhBUgEWsBpEBmDbtERsaExLYofmkEeMC9zyynft0s4uak1UvheC/WbuMgWupRRYru0L9v5I85Ww/hfzq9yr6ENOs2HdcYo9mkS5borq8DvzQL64GzCTC/uoAoupnwBuuVemixr2e7cgjpPI++vwe6UYgY3AjkjnaJHpwSWcnwc0emQLd4SV9d5zQbMkYh4jajsNk8oVav/M8c7j4ZyQXD0jyJrrvbnN/VOMEjS+8vtobX+PpuRBuYt2G8E5UBzhijrOkptKYQZhustoBXZmUTycUYo/x4CyAayyOwlfa03c49zh5tCh/OYeAvtb4g/OIxUfyUqWe2yqSUiyNdKCoCTmZbDp8WQSiUPSkYbHumiL8INkJneexSmQ+PgueNTncbMJ3SEtcFX9iye9R63o86QEnZ9fH19Xwk1N1bHzjX0lp2M1+zfFDutrDz/8lmH58zNwJFXjSb9SekX2ljy41ScGt1cv6vZdGV3wNs6QE+R/aHlwm/e8LU87fdyWq8hYWmLR5KAoDqS0T/jWHrNWYCFVbYPCOqdRwLhrz80mG2NPfgl89ZACO41gGcjtPt+0P7ppau7ev21D58JmkOS9qhIhy/ItkaOBquFdmKlDjp3ocQSpu1rILMe9ku7L73qkcYqHTaBiD+w9sgqLXzvWxOJ7Z3/CDWkIvi8G0xrK2ZxQcPKBCBHoTlxeFoe1bJWvY2sq30Zcd4bPhhLKe5RBwerVuOT3WKYBSCi/dT2GunPmlQgMb/Pm+iTPibhwZEV7f7EpLRvxwTG4OFUmMMRbVzTcnTysJ6HL/m9d4zwGABk/f/ouXK3NxnXmuhut6FpVGS2m5yySqZIoouefqt77wezGJRxVLLuMNkoXiq+ej9EFobm2P0i4WApiOSGwZk/JXpTI+WRKT3Z1cV4cGoqu/DxkxZ0Nz024zM7MUYxi81XHSsR+2pL8yOQaPzrZXbQsgw301jAHQOHq/X/d2BtTQquSDqEIF28zW33/VFKon8McR2qm/JRutHCFvCy6g9DIhO3J6ufp2xdFjmp1g3D8e7Mrd0cGcIGNyBhfrlA2Bxxr1xrHy3lhzV0joZetp0OcvK6jTjAxollRAnt82i5hunHaSOj5Radm4sGx9AMhb9kBJOl0qAC4wOy+WsDhdEM6mza8gEYGskiavuSe+1AEUY7iUCcxygzM44+EXx+HT7+OM+JzUUa+4uTt0q7tTz7tYadttfoidBcZxyWD0Jk3BaTBRcxhuiGTaMpJZTalZz3X3vbKPmBbmO1G3R76pblYW2kSgYNwKr/qxP4IslNADEDISeKAzK/XeVYJCpOxwnKal7k5dCTmZCQHrqTNQS9RxNAsjmmwHUawxsI+R/vkXGGMeCxbjMrgqsYYvYDJAqwzRs4ZNqia7l3MI3BF+2YeN022NnZb2pS+qqwp0Pq+0/53cnWArohwnxLAl696/jOhLiXkfekp4/O/5op2ea2vz3s1/xc5TGxO3UrF8c1jVD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6319dc91-7147-4e23-1b07-08dc2726188a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.5323 (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: ofk8j2gbz794I2tqB/XY+Jxf3w4s7ssOwUb6DJscGAqWO7ewiL5PfjAcEmSH/N2e X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071315_087905_2F633575 X-CRM114-Status: GOOD ( 16.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 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 | 136 ++++++++++++-------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 84 insertions(+), 53 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 2ab36dcf7c61f5..893df3e76400ec 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1518,13 +1518,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_NON_SHARABLE)); + + 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 = {}; @@ -1539,61 +1615,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[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); } 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..53695dbc9b33f3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -249,6 +249,7 @@ struct arm_smmu_ste { #define STRTAB_STE_1_STRW_EL2 2UL #define STRTAB_STE_1_SHCFG GENMASK_ULL(45, 44) +#define STRTAB_STE_1_SHCFG_NON_SHARABLE 0UL #define STRTAB_STE_1_SHCFG_INCOMING 1UL #define STRTAB_STE_2_S2VMID GENMASK_ULL(15, 0) From patchwork Tue Feb 6 15:12:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547496 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 A37DCC4829B for ; Tue, 6 Feb 2024 15:13: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=dzAomNM3TDfX2IyKGBoUaa5j5Gb8UsBteeGgS9gznoI=; b=wc1LH1vXhzXEaF FKOyBPksjRkCkQ9Kv21FhKAVNHrqdXg3DnSmbV2Zl4rCi3I9NSCWx2V1iXpuj8k4SodXPoeDEuLCp GvCKfu5/rbmXp9h9jAOGukmk0poBlWX/yvxrTFPKHM6IycLfDZaYNnejeflCG/0/fKwdVqDOPkCsf 9V9V3DC4xG0rYS9Ba+Wr4LoXn9NTBDWCjmUpusdBjiVNSBpDgU612bq+aaTB+h+JUR7kj3xKnWSD4 5roNuA4Q1unIST1bgk5X5DkFDi+HgXd6gtcH7B9jXZFUKSM+7q64N1B+CtD8J4ZUojPNK/J3pnraU x27ilkBCnLavUdVHU4uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8O-000000081Qj-2xC9; Tue, 06 Feb 2024 15:13:16 +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 1rXN8H-000000081Kg-1RnU for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z7Ue+Z6O4CkKA3OAYlQqyIbQq4K7l60BFjD9GW0VZ1XMvHo0maAOKqqixSqzo1kwm3qb0oTRdl4v+ZFHFMnDq2SeChTDlPfuEHwFzCoTTtxE3Hp1S26I/Wnbh5+xduPrwZg1ZWq0Ya80VA8izJB/jzF47HGerYsCBI6kZ+fitK4kK95Cw+rdLDNTPRe5oZc8ogWR+MseoBpIJmeye6HyDXccxU1cQ3YHoKq1bNsv+eeEVLrI5XL9hxqzwolvUWPCqMDSNw0Dti5Lt8uVnzloHJ6CllhaR1qMcX31vzrNHzSIeAqX+XjnthUdTMbUFGupcRTYcbsYjHEiCq0oq3exPg== 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=J0ighcIRQax7XCaG1DLtcRtYK00PDJ1RDaxqVIZPL6A=; b=X3U8sahXSCtk8BzgvBv86vamIt0QuxFr2niHs+YLS915eu0cC8K7GABjxnN0Yk+BdFpSXtn4hPiqQzeMRXwYXKI08u2gp56CU3XISZbWklNpWh0r260Ap6srM9dGbi/rVeC+4kEmt4IuGRhnaeDcr0DZVi4hTqEl4zBy5QI0pEdJz1axv17nQX/uonnUKpAvs/wdpehJ/eWh26bR5MeS9PSHAFBqG3N+MYkocyG9AtJ6r6oEflCi9EY2AL6qmmTCmMC11d+1mxWk0I8mC/0dEpDJFi4E6kFuz67Nmv/39MZbNhSu5uwBoFiEtQBGHHYK+hgGT3JnLBC+DGU+k01VYw== 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=J0ighcIRQax7XCaG1DLtcRtYK00PDJ1RDaxqVIZPL6A=; b=bE5OmpN4nk7wfBgmncUPFOVWKk5uS4mX7GltmJEPgLEi7sC1CxscnJcbwhcNZskNpYzqSymLMur+HwLBlAIzCCMaIwvkG8l2EYykEceM+V6jK3E2KzVNDyqjW/22OIebA8D16cbUOrhVfWnvIqZp9WOTXHkkDrCBKmY56ghYIwkNWEqc5Qx/67Mi0VV1vEQij1rcYyYkTLZjVaNQhO57p+//Z99F12g2sKMpJZRGAtA1oG6P1yxFLQkAiWPO5OBzzKpxzO6eLlPbl/FHDMbLFycGt/aHpWEPbKgj5YtPckNiN2IqjkMA29t0diL81/+o5WIZfDGuPr6WjGUx69lcoQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:12:59 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:12:59 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 05/17] iommu/arm-smmu-v3: Build the whole STE in arm_smmu_make_s2_domain_ste() Date: Tue, 6 Feb 2024 11:12:42 -0400 Message-ID: <5-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0002.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: d926bce6-d496-4804-1867-08dc27261881 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZAeVtXizDmYAw+WT/RrRugTuau9tOZ9foYcTdXZM1rMVKJc/J9EFKzfmTJL9rAGRCwMtumyXK2Tlk3KcnnXaENghc2nIScJJltjv0+ZiJpNLb4b5OenQZvjqkUybpNjiA+ejPmXM2QEd5B7/ENnbI01oG+KbVTqoSHGCkMQDtvID3CE3xGriA4yuiOFAqWFwh2VAWp+yiGnWLTHNvdaootNsMVNRPPjoq1nY9/qBq0pjhKwpgtvsTyNsyL0kf9mflkQpmTqNA24tB34g/Ni0yQYjlTus5pXUTMjeazJI5wyj4xpzjsyWAfuEaU2kZ+/GjJtA+vYFAbNP0+2zGRiCZvZK0ga54WoSi9Hl5AUg73/lf/xMa7bPdeEVce8WoiQi2tGNyHJmJ6xG8+rdp9Hy4jOARgiRvuM85yPTN0ldxQhn05x1uwcbnm9UYzTj/Hcqe8KxFqs+kD4P81orLnt7jkQcxODwe1zYwFP3pCqIcG1Xl3Gx7cWjmSbzILVl6yhdA+xvX/DYiTWIyWKWjh0HmYmqy/ItgYqz4/mIvgpJpw87DM5upddDXEoDCTxgbHhluk2X5/E4T8oTndKMk2LlBcf0NVoRYlrfd7NxF4Y1k6w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z9oqUijKTv4wu+VJwTvG9eK1cqQmNQoLYH8bfBwvnIq4f0JuNlv55yfZcgq4Or3x0Fvv/KyidI7ISBct67pLN7HCcNRPJZoih7cYCLSbGzy2zwwPYmTfe6bVE8/3yX1Crn+Xy56UdQqgPp2RFI1vMosKuG88NDcxTb/PtEcpzgwyOhsATEqGEkgq5BnES+s3I3TraNs5omM4ILOY9DKTUCir0c/zFy2C18/Uu5uDR3N7DxO7+idqSoB+2Q2b7w59lZYQVgruM1EwV6l1d1h8pkgRx7DSHhvnsVQZKAI/d3HWTHvY1UqOtcwxSoN2/1Yubq6Sm5eShvDiy81LIPXp0hVj7BB5ZskSa9TIrmX9TFFjMCJn950Ig5CBhPYt7qQ+PSZVRZ+Fo+JIQdcvlfs4h6Obx05hk22Moh9Tx1Mr2ZXaVwdmIY4A0kjnVIcm3kiEhSLBwPFsrLNTlgbV8IpWuuYS1CXUBbrs6Vh1oZAem1k1YrDTTXID745oHuQo1q9jEibyZ3oOqLreXzZXLOfiTfioXVuUvQUIvSvGJn7D7BVSg1G3dKijScxnlVJ/u0oDGB1Sw3p0Sc3C/NRvXRPlkk0zC+uWvpjwO7VlUNVfhh5+i88AC9HimbXpkT4BUoPLigcqYJFZ1WQBlXCswj0wt3pFNe6SvKVU7gJUD3o+MWzIPByqgFn/hdWo1YCKWaqXKJb+rgW8VsmmqSjCXgJq7JNwabNgnttFHyb+qhSZqIEEFiETDt7lioOrCo/GOC+//nkJm46h7CoAjFsCFqv/7Kj/mL7SK2Wnk3s8VSh0KYUcrKsp6a8m2INrHtSsM1U/N9cCUVukBskOm+sse8lNFz+1R4yqcKFp9yO5t2tNzwsbmwM6sOjaPqWGeBC0MNH6S1LAHHMjisk5VlaR/j727kp6bo4r9DkAZFFrM1m2JRKWpOwuB9XuZwz8WYILebpExyrZ2XrYtg/EUL3m1xYrP6jK832JT93GKVcB4yWJ1GJht1EOUyr9KW7iqpEgFk7RNZk3n43NcaJo0zvametxWpr6dL62AsZaxQRKTmasspuPOsRABlQbcGfUAN8AqLp736pb+xf0f+9QHpWO00e7hI0Sj0zhrV0Q2LQt2rWNpE9hRnWfLDgXNNA8pV+5mAzez5UE8l6kn5wUd7lmK866TI3s5Fy8e4RnpoiY2ci7WeFhav/BMlXJqvoZkpr3lKvsR6AlLNiA7wJbErsvi9Wc0RHDXShRyRY/f7WjhzWKVaX6yZcL5xsHk+zlE3P+wcRoleREYZpZy/rUeO+uOlyJWQcqv4zcIfnYIDvgOS5hPxr8JFj5jPGcKV0N4x3SXI8bKze142pHdgyQ5Xy6g4CmQ7mFash0RN2ZPyIhU4r7NHL2yGDneH0XY7IsihliZRr2xl6h3YasCs6ouhuywAOkMQyXKSvLR/P4p0S6bCNpUjjrXbh7G5HYvZH6yyjeeAeDTX1IerSIDjzeOmZ7TQnxn+5CQSrcXynYTnwNhmbhgg/HGu1a3uBLR3FKES9XBNL/TWCsoATab95ul/SddF0uUgEc/f4iUTQwU/DYUbieK2JvxpSp7wePthbO0vPOdRrB X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d926bce6-d496-4804-1867-08dc27261881 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.4050 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ms0e1URhGVYmLMwlUJw+O5+dHbuUG/t4RO3zFg15Yo18n0Q6cfsixyEbjaNK3dOc X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071309_412453_0CF16F7B X-CRM114-Status: GOOD ( 10.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 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 893df3e76400ec..417b2c877ff311 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1573,6 +1573,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( @@ -1585,9 +1590,16 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_NON_SHARABLE)); + 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 | @@ -1595,7 +1607,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, @@ -2355,7 +2368,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, @@ -2363,16 +2375,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 53695dbc9b33f3..cbf4b57719b7b9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -610,8 +610,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 Tue Feb 6 15:12:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547505 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 6E4BBC48297 for ; Tue, 6 Feb 2024 15:14:20 +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=gEz1avjKgnA9My3xqqVXPbsgbzKmbsvVwPTdRQBm70s=; b=YCbTevvhqWKBDT FCSrTN5EpYdozQW/r6cqHg6rpdgU92wbrTKgeAzYBFqgr+WuPeTMXVWtenzTM01RqFrfpdwlynWn7 MFqjqFrA8hNDOy6ySWB+jKUu7Q06ASjE2hFJzefLfIu5Kv4ms0dfWO7n0wLWyMU6OEtrtwyxo5fkU Adyz4REIXjeuvnMXYLJanshbm2vk+MYUvLvToJqRYawQDdPu2JRviyzlU9DnPNM5sZLmyztDNLXpQ 0Gakh+On3Oc41zYTksUiAoTx8vmgDU9xRG/jxOi2MPTcbmHgIjLyGlqDaPrV0vY65ECekM4CqbAEq r1Y0ZIlszXwOWX/GZSLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN9C-00000008218-3Hz2; Tue, 06 Feb 2024 15:14:06 +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 1rXN8Y-000000081Kg-3Zu6 for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOuT3pcjWutJC2gwLdSdEAYkaidxADTrIkwrbUK3KpY0YaO4R3f9MzE+4PFF0T2YPZ7COrqIJOV81EI2T9PxIcHoa5toaMaOZnk5pAkmcCjXK/axlZLxaEdWDUD9Fa7SbaFWIDVosnkko3LExJoEVC4Rk509Sd2+qDbQlqv/0wsgVzACH/uABQJT+WjSm6EY3cyOddW/5oSIhbIX+Z1zPGjhJxwVFU/cOWKPniQN5QWy7hhU+mucooJXR5UHieHvCUZnIVtmQPQ1GhNsyIn+hmQ2JhWDfwhRCPXIjNrqE/ta/+B9vlw38zG5YY+Dhg5CIXqMwITf/cRXUMbanM+G/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AmbBf6iGO/chNEbaaFsqN8af+lT4e4v8BQTAP2Gaddw=; b=JewzguSVJWK7b9OdNZSDxDKrvAK+7E2tdmjHEESkHhMOTZ5b9+1mF5tB5BMBldGJW855KRNKdQpKIXROP2o1g3NWAixQKpYGXgHF1TdP42WOq2x7FHcsYtsKpIgSuQU3tIaDnZudfOVFq/BYWkPtFk6IggzyJlwdVJxCM9LSo9Qz6490yBXBFofA1y38PKHzJ1v0+Ttu57KP2rhtSbX30qlq6x7bHUu6i57Gq7fSWuOCiTua55UhmcqCfkwp1Y9nqjHPGveuBXFPX4hP3Z9F6xWmKg94r1iHgzz6CLRqEuGueL22NGMWjIXDI8LWVsA75qb4/xzmQ5hqXlrn+i23CA== 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=AmbBf6iGO/chNEbaaFsqN8af+lT4e4v8BQTAP2Gaddw=; b=cJCvGka8UuYZYAMU9bZ+yRIwwAwy14vaCqPvdXDukLYDPqcR9dy/q3IBSW6uXxI0RcHseDCqvSLXmybAw4YxKjBY2yRECFCRo5+7Bw7tPKolOAn7HPPT+De+8MYPeD94Py8H/HiznQ7aZ/K3RlMjiTXGq/jQpP4xdg/4NHnTmDofhhCcu7KDZ9kooqjj+ns6io/Rekkxak4wqZkUhLehIPTsjOsrlmohWOKyyfR7JVeC8xvZztkIkjHJU7nO27qcniSzBGMiHPhXiKL2nj+Cswh9giPielYTgumYCpm1Gleg1TZVDlsIxFg0pf6E+vqVAy9Y160H5+O/0+C4ZcWCEA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:06 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:06 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 06/17] iommu/arm-smmu-v3: Hold arm_smmu_asid_lock during all of attach_dev Date: Tue, 6 Feb 2024 11:12:43 -0400 Message-ID: <6-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0051.namprd15.prod.outlook.com (2603:10b6:208:237::20) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 0997f36e-eec0-4a52-94bf-08dc2726192e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pxALT3K8oe7CU7pgoNLqTctQ8FUsORd82wiKL2VA46/S9w4jdE4SAY3A2ruiukXX8qgvFOvqgLdzd/58+tfcWFXDFq8VC19N/2knp6R7ATZv8aFKM6BqrHxmqTfCjvELwruXap/fLtdkeXglGe2XRo2Y4uquPulAYsNjAIW+nV2+yjHsCo9UITp01yn8qRQGd/pWB5vs+Qweks4ZcEueL+5PDa7HHkN1bvn5kCVRRLP8uo27UkZ46Bx0xfmqQ2cLjdTOZ/WAGlOxA2Nlh863Ne57HAEO/NJayuq9atm8DTor+d7OuW13iKeCx9YLVRh+moA2SHPQYC4zLcvPfRU8uk9KUAFcQ9xg9Gm49tWxzoB99QGvVkHcp/IUNC3PfQLIy3Obt195ki3GCVL/d5VISVDULjXhz2PacSlcegamL3JbyTvaE2rmLNtnojINZI8X2S+qcA2V7FvD1jUWjHppfRs4o8brPQhCX3cuVLp5WEcHdstY51XiXzurprgQyuU2Jj5MG5MaKkJeHGMCajTH3+5Emi6f6dtSqZIGHDx2jofWXbMeCssHKMpjaf/yyzACz78IjsvsPIWIjLot/al/k93vXKESPphSdvBA7U+J9hk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lmLi0yUOrbgd/w//zciqV5fz3a8v1Sv6owYpaZn8qsBLvFCMjKV7ABMOVgLwwPhybehw9MaSGa2YHVyL5XDSwT+R0aAwGSFC4aNteg7OUKNr4NPNeu4CuAbgoTzhugzxn+8Aw+bO9a7QeqBI0vCwWSbEzOmlteSnV+q7peK7b8Z/j0QCRUEhZkZIBnm65spLCnh2ZlEZshFkirB0ts+5zBBB6a0mc+fG15SQMg04FWdYVPcCNJsp4npTuvtH5SX1sl1mN3dk+7CW8WlqpB8hTR4aKk/GZm0cWcuaa61o1484TiUv9TndvqIf1bUo30DeAOabpEvoCEAbuwvA4mN1hRGjNFenY1mY+hm0Ewzwb0q6taIJIOzeXWlFWfkNGfpN3/QIGAcBegT6L3YNu1SXG/d+zXKsfMe2OW5yIsD5YmR/5nnU3xUVryivPjQlkhlGPH1krzy0IUOgwMpnE8F78pB2U5vaDleJBV1WJlpRXsxZ3VxrbNrv+R4m0uAsCIK5gHTdEDRiWSyOxAYnBMZGl75+4HJIbCVpFAYW0GtZun7VNgFoSnS9NW1+M5BXztA5l8sbw2rs28YKvkcYvRNpaC+rnRm/0CA9JGvddX2tvm/1zsHeeudqxIF1PJcuHtdeM1ZdIdWwhE70WHcgYqGKJOTqorAPKl46o12OPQY2zdg+JNYFGS+xbsPvcndT09ZAlDM2UEdv8rfk/DJrGJ09+wYiiCrvAjfGBcwOtiWn5Lw2hiKtjZUh/guWZRoNc6GEBg5B6guqMr5RcfMeRzzAcyuR8p1LUGUgfkiqCucN0MewuKU90/kCp9cmowxJgCbzqxI/qAk/eqH4BoMDi2N1xzD36cf2bcSjMaBurfRvqGKXtvhhQu0nxKTTjWH4TTiMo0Fqx4eM9MYPPO8Ab1qmZZroo8frxfx1pZFmA/DeNl18c5OOUfivqbHprCsZokDdTqZEc6cCacrrZp+9KpAHAGeY/0zqL/3EGPzOcaMTQXAB2lhtGpQKGqbKnLeyJS/qYC8ULIv54QHuscC9P6GKrBTz/FDeAPhdkWVAwTiwQBl0Oi2/JfbVikjmbZ/I5es2cnEpUjwEGj2BwjeHgCxlRe8SeJlFEU+zN5ucD5Iyjf4o4EduqBBfEpSO69XR9j1G/mVRAGsafeypXLxry0+dqq6nrJ6V40jxUk7v4FqM9W4Mfoxtmf2u0FJ+5XbsM19UtaSTipi7enVjcj9wiI1Np4HypbGOE0fcBFm/J91FOTH++SWdvzYdZirMtWLqCzQd3t+v6TOg8zFbOVLrjvSmHKHkBE5/IuX9HO4FHl7jwVun/U23cIhDyuNuqCi01oR5gNrWYmVZZnxV9Pn1hSM09kZmHqGvz5nBlurnka+6vtsHwfUwb4h78Yu4qarjSs4poaqUlvwbf9unGEoRswn54Xc2etuIwbZeNL7pffsbTSyNh3EdHvpLpa6hMVQYg3ku7yMcaT72ZuB+3yndEa65FU4L5YIDS63Nkb0HStmKrvsJw1ewgvmkMUbcI1kUP7KxYHf7eImXlrD9FfqwtgQ3TrObI8D8hdoKk6DZhz0r1hag+xJloLcfAC+t0oB1OVWY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0997f36e-eec0-4a52-94bf-08dc2726192e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:56.5541 (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: NloO1ve7PD+1JdDCEx6DOFnhNkKspeKkUVhb3lIDVClDy2xBbI721nygkBI6fB0N X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071327_313551_030E657A X-CRM114-Status: GOOD ( 19.96 ) 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. 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 Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- 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 417b2c877ff311..1229545ae6db4e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2639,8 +2639,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) { @@ -2655,6 +2653,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; /* @@ -2680,13 +2688,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; @@ -2696,13 +2698,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 Tue Feb 6 15:12:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547502 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 70294C4828D for ; Tue, 6 Feb 2024 15:14: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=LzQhlYtNsF1wOqbSqCPMP9cDc+KtFZsgbMA2Xu07AGc=; b=lGmq6ADGWFLlXA a5DTjnzWXE2nYL9afcqC4Hnl/+biqOaiZwRXvO0J0WT7QRJrPpginIsNOLmbR1Ze6TiEDC6FJ1t7O B138wdmxDMgDeiScTtE5P5JLHOQjWMNyL4GJwQyEDpKsvj2lYdW2PUOnTUb0+u6I9OCVINf2JtzIV 56C4kgjp30r1q4V2Ll2FWwm50NHFoFLoZ8Bi4FOEts0W4INVn1aDtHSI5ZuidypcGW7nzftEtSAbq I3ccvFtf85BHfkTotTqtXGcvwmqf0fGY8zu+UWDR758E1qFWm38xgNgassgjhXlV/4s9EN6w+EKdY R3suXLCEFg+iDmJQusiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN92-000000081tw-2YoO; Tue, 06 Feb 2024 15:13:56 +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 1rXN8P-000000081Kg-1qEk for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YSXN21rL2WS9sQ5ySB7OZ+4Qz53h+4VEG3SLynwa3gew+gxmr5w+0XooAbsyazZ/nNmzJ4ZS7EDenzIXRSPpadRRcTkpTbTvp1w/+GS1zqNnb5FBeje5EukXaWQhSj/Q9Fql9a/Rfiu6XkKULZQKAiPmQoDZTuQozSRALFDw0C/YE8OUdy4GfQ2Qgpwzis7wh1fCYK5Dc8HMNEG4OEsHKCUWTzHxU0YgDL/lZaRrHFhGdxmnsfpLReIImwzwHgSq4yRirYnxVggU5m9bkf+V09a+gcEOGa+67f0UEQusUkfGPVUzDIQsnREOFOifcGcrwMGTfHnElxR8Vn6y0nwAAg== 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=jDaL8iCsrN3cG8xsMKrhBAKxDr5uGda1SYKKuRZihrQ=; b=Au5+p0WeM9elHaERu0c7Z3kvvgqJ0NWj9/oenZrNjVNUAdRXBRmv5mImG81JILz1wuOFhxCC5J+u2uEMNmnPUAUHWrF8P5bIIQH2pfyBqfeSbaoepwsN0W+2tOsahbQfASy9lktxD8E9g7SjPmRMgI5VKqgTdtt1IYSf+pi1qKwTVeLt3RAPckgHtACiwrdlA00YTdFpzmYGVwtCSwvdGsNzYK9s45Nkqgt/TARG/H2dXI64SxK4gYsilRnvzgtYIir7uikc6uQK0iLA6YnFiwHsKIJV4HDp49VABkbkStW7C5qc7krIV1lBFCpZ/R8ZkhDC9/Uq0+D5xHkiMJ3r1w== 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=jDaL8iCsrN3cG8xsMKrhBAKxDr5uGda1SYKKuRZihrQ=; b=jRGEjs9Sphkpp6OuUUmkvpyTQzN++yCEdFXLG9rQ4fwVWYLQbJZY9TsPBUuiUeMsO508rRGB1Hdbldhe0Zi9A8MctKkQsWyBxHHBUlFVupKZxqJbBq5zGaq5X8vEurq9pqEyhBpVCjLdDBbGxFvhKEpjqK/xjY6w5RmFU1SANWQHKjbM6Sv3dNwwwem9Bb/dcWji3D4rHAvMeaOBQjH/x2i1x3jA8LP3TSnsVUNKqXm8poHr29bVCyC99f/hbCRwoFFLzpnnE1owJs8wvQFNLnO/fALXo8apWeamtyjRIMrTBMmeZKS1dqGg1BK6Qi8t3CYpsq8GslQqtPDRRus70w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:04 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:04 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 07/17] iommu/arm-smmu-v3: Compute the STE only once for each master Date: Tue, 6 Feb 2024 11:12:44 -0400 Message-ID: <7-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0019.namprd13.prod.outlook.com (2603:10b6:208:160::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a0c522d-9326-497d-8cb5-08dc272618ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VYL5HpLu60kjVF1gTK2wg9adJ6gKSyq2KcaPJDUy+E/yNrDnBCqwVno3HaXmbC70OHvFa0vlbrhZcrUTRvBHxZ6uir+X+fv6/U7In8o/RmFpg4z70EJz8HAWj9YT2xZLWeQYqy7p55gI9CjT+WMLUqBpRIkl6Z1evbWc+M7jqErt8aRAh4tQveXa+3X0zBmMnCMUFzLMltgwPHLLAuIunWvSDlF8wGJDmd9Py0dGbsuevzx84z/Jx5dBqLvl3sHHqaYnuGQ9k4rUixJO5vHnM8x28sYX58a2xn6VwH24Slr62zoH0uJN3RMdk+HVZQ5ywcIvnyf57OyH/zq7uP8oP9TAeWEN5cjeeb0naO42Lw93txEshi7JYAXC1aX70mlM4UccqCt93paMK3ffmtEP5Kr9XyeZu3zbHzrFvOW7HZtBC+VaQxFWEXN0kxiTbb5pIOeB6m06/Zjf9KCc5v21VvEVss6p3dSDRfz0R72ekeBxUIRcTUeTzR2ynPw0SdYzcySX25xx2IhnW8dJm24OPbOVyKPbEuKAzxobJWLPZJgUHlahNNci0NP3gjuFH6nqWETntO0zg//Qngjd1XE/Xqj36yebFKhu15xvGkDDDeM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NbZqARf8j54aSRQYtO4/p1RLdi/hYYI3M4MWAzbsfKSiNgi3bxiVd6g9sJcmPQDpEU7hpVVT18o3s2FB701WNufsGn9zEZicZcoeQOqQwaQKNUS2t+B66gvkREvA+39zj9oa2Ig/tN7jgARTYY5D+61qQ1JVhGGALGbRQZpecHd/idq/oWTbUN3y+Lfzdqsoa+CK1DAqlfyU5H0pMZDRsQn/Ku3RNEHyI6N52GNoJgkzer7EEEer6WGZ/P93XZgg9Glc9Cd/4Mll/qzXae7mhCJzLkqSeJwBSxFBEczxe7Qt71+8pJ2Y3a/6DasLmKk1v/bJBymb7t0U5WYRebjuo6gkBtMTViUdr6BOhqmepKrZvCmLkHsjt6T2E6oNiAjTcnB0dqirpyg9FpMoJraIiKkDGDjZGLt+edBCX0Wj828pfFxCT7dKL1bQGvEG4jzU4EPucj7T7FmyqR7eTHS/AYvEH2cV8LdnwIXDPNnsZBE7UKRPTqjMkzyX/H01ux82wo/RJiWE66+Njt1OfNdSssyAtVrNKNAiTkz0/xLGXWS+oMzQ1QMWlJSBJEUOX9p9pii6kXtqcb7y8YfdBz+sfLTHF8Xj1iXdreduULkIoO8u8sr7gBw3KIUJcDBx3WQhWGPTSnOSKPT1boaISLpg7FVqouQFGTkDsnOzzkyrntIEcbAcVl3i9UtWbuGS9mrPdAE7Oj2NDssu0o2GscbsI+IQPNOo4voc/sltmYokbXUdQgKj8fCZLrcFUcgFwzaVNcg7mnqa35d7TThlO62wUtcSENST29GppYwwdSXWqC2Aehgz+u5Tg64ieVKyUPUKe6OMck+yZD5C+PSF61Bnp67EE8eT2ejTwGCIGmu2Wvqy/B9vxD5uT5xKmN1qoOOlmyrrQ0STysXYpp9Og4hbILj/vVOkXQpEAEBfA832Zop4Gy8F50wV5BER4BMjU2qFQe1f2w1X+XtEM0HmvJs/PLhepy33lUhwjDpQmqgYq0At4BweUpms/tfcjURrqynwbHlYDqRp0vTWchAgbGp02ZLiO8lonnR99Lr45hlleuQiGnWLalWhxCuv3ZWQi+Zms/EIq00ezI8gH6EE3EuG01I738NVVUSprOtU5ulqnIkZg4LfKvddY/Vu0Yfr6ckZB9MEtWjVdWeTGzt5qQxoLQLQAMJEEgCSuAmFFlDnPltpf6UeoSHba0ylKLPGp7IpLpGKUpg7r+ubjCTu3kYBjNgrPR07dlEhr4/FG7KIFhTufQpbeBUeouoOCwWd/vh7/ZdXkRjlwQZitLELxsNXWNU2cOIjIDBtxHcsAwD9WBs2ZyJCDQbs+Lqjqq+HhDA5yWrDM9B41JwZVTXPXb0kt53WXHRTgH2y9R/GUuiEwyNHVloyEcHhknsSOTB1dVg1/U3P/7QOOKQ0Quebw+s54rqNTr21HcP41oPnpo4dGNu/BEze2JTWYeCYopV1s1jHw6Gb/twxg8Ytrg1ZgEJTqoOcVDRhCgNLxsNZtEiU5F/ibdakzJLEqURp2CL7t0ADqr04u7uyoIJ0B9uEW3QrINvb1LHPauM40q9FgbafBxltqglWXqMf1VxGxZjlrnez X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a0c522d-9326-497d-8cb5-08dc272618ea X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:56.1101 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0n/KkvRUPK6kT2cIpD9eYalNEB8jOEU0SEb8ZtEEpKJhBdBChWnOCxadgv/HdGgk X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071317_527986_5BD86505 X-CRM114-Status: GOOD ( 16.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 1229545ae6db4e..1138e868c4d73e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1611,35 +1611,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. @@ -2466,7 +2437,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; @@ -2483,7 +2455,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); } } @@ -2590,6 +2562,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) @@ -2603,7 +2576,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 @@ -2618,6 +2595,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); @@ -2679,7 +2657,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) { @@ -2693,9 +2672,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 Tue Feb 6 15:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547500 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 8AB93C4829B for ; Tue, 6 Feb 2024 15:13:35 +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=1dzJ3smADbWaHSprF+LtVIpoZ1sAnBYM8uUpeMfig8Q=; b=KvrdhcEhhV262n AgxPJmKhBJrkVAP/WrzwG0pb1k2PBsxu22JzGjIBxeiOra2x7pluCRpAhHUKOALS/zkGDehS/HaNt CdTpApbzxdVTLytYNlZPICA5Q3N1EdmgTJyiuNtIHE5maWn+RYMQSfAMllnnHcX0+KErPgzdqPl1v lFf81Z+W7BeiAoUu1qYt970QmRVx88GYHOJIR14AIaoX5zk8Rbsq/PlsSItBU/3kcrfksPVAAeZkX 2mhWRHh5Vo1lYIxkxGSSsgUP5EXpIAJHN7MXcZi2AXPltsV7av284VjnYIpN1TJvA1OXZgKoPR4iX HAZ7eKXjaAy0ufyjqKoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8S-000000081Tg-2mbt; Tue, 06 Feb 2024 15:13:20 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8K-000000081KG-2PIT for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VTehXGQYygm0mC2Dfai9/lNrP+RXI6EiVkYZ1Kywp4/eY4Ku4eIf9Ni9M6MzwtjrDPaFRkekK4a1mMB6nA9RHPRVPC4grbpNvGxFGDJIO+5uvSc2Quv1WkNpl0McSxW7WX3MBuF4TqBC9i8a/S2iZwfBgvIYv5qokTny7bUodOnr9EsSr7oIr6bvJqcmB62LmZnfNZtu8wByK3bQfws5z5K+ef7Cu3Ue2PxMUpwy/uPLzr88aTSdzpprBgyRqi71VyUMkAvgtcqfYzExRVx2HDJSf5qIrEIqsxWUfq41k2eiUZ147fVZ6D81MvvGamA7c3REdASPj/SvN1qu8eTV4Q== 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=n+bt37hTuYpnkRrBIpijxkYGil7ZRe5EF6XUVOULzsE=; b=NEd9sSAV0jOWix1eY5pQOCiUydBt3qS3mm5DdEA2vtYCbts06z+zUbEtVegtUFcVOyDXvykcaJEWmZb6CVOKRs0wbLQ1zf184kF48qY+MIt/5wbvJk+OwJfOMO5GEXjr0OsLbT5Z3TpuzbnvpgRH/szg4xBnfRSt8N2q/u+6J8O14r9KHp5RYKopf+EAJ6AAepVaZdkBQTJdKz324K9CwEH/URpTxBUt33JmMWZGk4z6xeVjad02SPQtNmD4a6dfc8tcBSZTA2J7R4M/TPZ2SQ5K1W+fs17SgjqmsL9AhhhLb7OBy+N+xUADXOSzS9+i44qmPiaPjdc7whRwu15W0Q== 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=n+bt37hTuYpnkRrBIpijxkYGil7ZRe5EF6XUVOULzsE=; b=fsz9xqG08Yz6HUxugM24MogpvoTOZKyESbad1b75LU84lmW+66pc2hgKHTRcvSZne2NRkXqZrlNl5TF22wo65gmnb/GVM07hEeDZfy3rVljN6cpCT8irymbaUISSaOsQ3E3lsDiZ72AeWXzOeZE6vNm5DNqb9MHHzKikKrWp2Ix0kWF9fmn7Tq9s/OfQ7GfDFO94cHCI3aJGA1CXKv+Fkc2xrD22zODHXOxDu/8D0W8nuMe6wDPy65XvwmQBxge78Q3jofxwc7Xo1Z7lbPGji+u/izpP8JdSaWizY4cAnJkUrWZOKw0TTC40yS6mSuXp2vp4o30ZRA5I/oOAwylZ3A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CY5PR12MB9056.namprd12.prod.outlook.com (2603:10b6:930:34::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.15; Tue, 6 Feb 2024 15:12:58 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:12:58 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 08/17] iommu/arm-smmu-v3: Do not change the STE twice during arm_smmu_attach_dev() Date: Tue, 6 Feb 2024 11:12:45 -0400 Message-ID: <8-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY5PR12MB9056:EE_ X-MS-Office365-Filtering-Correlation-Id: e3ef8969-2d10-4b70-11f5-08dc2726186f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MWP6bNDORkS9dFcXzjOCr38MwqaWzcyMRIMV0mf9kiLVFpaGk09Hgxso79Od64m99kuqMX/mM45XqmmfFY16tubW8n12IBDnocGtpOE75obs+I1l+4d/DsvRJSU+0qliR+uHVMwe4s8w10EvBiP2uqqb/cA8KmiORetSe4EG7Cg8BTHYtN5FJfXZpNMmWTjnovsbX2xw82nseeKVtEon0TyqNs/JEryYT/9JnRBKs5BMqosz75o1JthCCxDEXWS7zmlIvSG6YL7an5GNZVNjrwPcyTcmk7rBkGVFgI+Ex5Yr3rTcwzjZVIg2jbfxnkaiC2eqziGJqG4V03fkmV0u2cs3MbFv2fCQcKFT4wRGecyQUfpiu/N01EpI0fBP5VFhcwNc1DTU+cyzBC8CCSAj/yNZOJrwkYMpk7Bs5pivJN4K1o53r+PPw21oGVvG6BeYY4Jip7cEO5vYK5WTST5zuRrwVSrBGirMpmwG7NS2raR2n6rDEI+y1X1H8gWItvVR1dv30uONASAuQWF51U04bner6I1r9NynBimbCdngkIHTJOlAX6XyW9jp6EVFih1xpxjILXbe+3dX0reGfzFM3CV0ZE722nqJ7/z188IVVyQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(136003)(376002)(39860400002)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(316002)(110136005)(83380400001)(54906003)(66556008)(2616005)(38100700002)(6666004)(6506007)(26005)(6512007)(5660300002)(86362001)(7416002)(6486002)(478600001)(2906002)(8676002)(66946007)(4326008)(36756003)(8936002)(66476007)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QRHCxPDGDXM2+TKdFruln4GzTEMLqZqxX0thY1y0AZNBqRJTo3CiGwa+ELxPsUVcWAm633zSQAiCyewDK47xfjVq94pSg4etOgmhiyAgs9OHWgF32bKSfrzTwT74y9l/ahlyTQpy/WFZdUZPUyAUfrSFF/hAn4sjIPDbkHwrW2EXEf2vso/5i2vu2fSGBmU3xOLWftFeQFWinkN2tVp89BTDyR+JtQY2j7VgFZ4wQnwy+AFo//mQZCKbqInlIE9Fpk5PLq5E/gkwR/KE4dav6ch4xX0SykAygKYKv8SDLEA3csj8dpSLUvrhDRD5CKPnqSahDzYwivyEmLGYOf8OK+9yrX9IgQfxH/Gn17ofm29gJvlHoG7GRAVxbJKFB2iOhgUHZGqMqJ170ng17h2TDuEPb9l3LkKcB8d5KvwcXTCOWyX8yoX38Y6XAa7+Nv35clmxBX8p4UlQULNTQuksdLgopXiESaEfmwGf5/CXRBw1YyIMH6T0B1FbqzWEN720jQCl4OlE+po/Gxvd7kK0mVPwzHl5yTJebU6J0pxMG6jPUSKG98avEob0feADZtnu7gePi36Ww6ucimatOrrCftcPaDDzljgestMafta1Nx7HLPNbkZYEWaBI0/4GkErfL7gY26BsQ9/WcXD2lj3AyJDsXFDsjyz1owl9eUMfG5iW11miiWdscJ2SAlBOC0FNcD46V6SlptSBgPZ7qPCU2vPyMOa/EIkhEeSMLvT8nQ3l2+mbn09gCJiIcYKVxNTkm7pYypKDlLBSNOlcI4PHjrDc893dgbTDXALBjrxO2EWr/95TeEdHcGWv+SHBTYgEF9npuxVTyy2OHzMDuxfI/3PUaFXtgCcM+kKMjripzjSH79CcaWr4GJ/ZcDsReyWP2i1le8Piy1LQuh9wewrU5JTD+MwWUteTDNQk/kVLwqXyvULVpMxJi/eGL0jP3fCSuhb+c7FsK9nxtWVWsBT5OJ+d6RODIGCFd9eQJCHygLDclz+/59cHPLGL8Wvwt/quxRUDdVENeVAGFRKWWHlkG/x1e7DxDg0XNGJruX504V70BM7J7MSv9qPX8cWKfVaOlN2zqYAAYUv1Kq7rbQD5PJVWOiHHOtQIh09J/WNwRYIyz3gU9MKVwUG843+ZK93iEa1dklFN5DwkFHpNV5W/dxPmBJ5VW0hrO8UVcIH2YQWdkW/h7otp5VRhzkkQ2qXVVUU3TA6lisD6fxOE9fIsqG2/fUcwACvAg+ruVCyoSeV0UNzjDQzjjvRsD/+aWhqFUZGWzrLXrhEJDsybefGXMh0NNnwrTl8bhKofoqGQeBjcoQD4xiEbmChUWrKOAwxIuAKc/CopG3VvDXUaNPKz+uympBvcKoSwzhbRQXusySgjd6Qfk8NqCJ/B8PC014QXRxdoUSE2FolxAgcXWQSlk2s06dD9CXgSUvV6wm3hW1F6+oCzSwfE+gJbXzNdFCXF4/4cYHYaYOBapQGvl1UT9MRSreC4wLmm1XnXWYl4qkqyIL6DZztjS8ta3WY1uBeYLfFWmCpNXn0NziaZ+bN8LViWD2KsujRxMNfwnvqrnSACz19E1ZB2aZKjC40nokJp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3ef8969-2d10-4b70-11f5-08dc2726186f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.3051 (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: yy35xImYlVsW2tYRMX3CVb5wiXrrLp52tkvW1wiOS5bwJbNAmRyQCl3gIyoD++Jq X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9056 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071312_752913_C551723E X-CRM114-Status: GOOD ( 15.71 ) 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 1138e868c4d73e..340f3dc82c9ce0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2562,7 +2562,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) @@ -2576,11 +2575,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 @@ -2928,9 +2922,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 Tue Feb 6 15:12:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547501 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 5A7D6C48297 for ; Tue, 6 Feb 2024 15:13:37 +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=A8YQnbxlAspzK//OLYkDtOD0NjzfxWbwEGySpfu5qYI=; b=q9sJL/oFdlGFxG jReUNzxm4x96Zf7OH1/Viw8kkX9RVU/eO3VobsthCg1M6pEBamCG+sXc8ZX0UhSC0owvEkOh4RIv4 d+GnCg0Z/Lfe6OZETzKhbDeltcD7ATcx6KdenmXVPpvKF1xn/J9VgMffdcYK3/Usm3a27mGpQISwX bsG4YHJUf6TrRkH3SG63Bs+9IgBFA6SJzre1tpO1ho10u3vKBYvluHVaAdPhTQnE6LbAEICl+tKZE C+ayBa5U8LWLJfGt54TUDgN3aa1x5f9H/10Xe5rVQq264ESdCQbn4uFU6M8rJQcGB4fkip/lesnZc v2jsO+cVllthCGiGkCtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8U-000000081Vb-2zXm; Tue, 06 Feb 2024 15:13:22 +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 1rXN8K-000000081Kg-3Nlo for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mkpq93f+rJlteNq8VEShUIlG7UjLR+Ipc0NjT1v6P3JxPv+KJlTMOUpF8gv+9N29gHPLaWS+TM3C8rDZOXTkzqGcqTaC2M/KruIEYcTxGEXpgsnHNKP8ZjUTqiEqHNNj2+L4pbaVKKlz391uQYsI9Yds2CctynRc+RKbZiQCmF+HANiGea75hutqEFv6cwnOS1XErBbdwl5QfIyV2QnQLfZQ7OnDskoTn5T3pKXIziAb2Cy7AMof8Bo/QCMbDpTE/lcYbdOAOedBDdQ03tSeDqSPrsdniUZFpXqceVgBhnInP3ZPFyKYHZVEyQSu+Kt0bCJHt0fkCrMPbm+qjOHqKw== 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=UM/ppWWIu5pAtBD0apLAHYEv4grf7RF/g6mQ9fRdN7s=; b=YgQzqHn0851jn/ysNuRNrE9wIp0STgdelnvMS7iV7XIe4ZnM6gsdyeikiq0SFHVuTaWy/awaKU2S6VYoItGKzXprhuqXDg+R5uF7yWS0h3FcVghU37t3nJC8Luv5CFwd/CODkIIj656k8iliqqxj6AHhPu+qnH3dNInsAIyBlcVyR9Ys8Jno460aNwYsR10y/OHjEDToZlB9vc5DaZuJGZxuhZI+o5EE7yiMO3Rz86piWGEKrF0onos/aLlAvEOwZV+FQtSXNHMJ4Z0paxOtTIfx467Xv+xnL7Rkz7Do3vy7Ts6QG+zcR7o8SJGCe4cpURcLRxMRHy7JyrZZMVVTQQ== 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=UM/ppWWIu5pAtBD0apLAHYEv4grf7RF/g6mQ9fRdN7s=; b=doRbDtcVLJ16Hkm1/jNUg3hvCviE8M4HnuM32DKOPa2pNNlAq9MKGVcLOvHNzgANZBcMZVokfaBd+YC5eRZclzRBqfypJdA6z0HbyeLcRWB6/ebj/T4OHfRKvzu3vrTTsHO29mBxOxhbOZhSrsMsKkgDcBryObSx+iqWBzDQWnOyjTcAz/aOoJauMk0WloO8Ec2MKWw8ty4/qOZm8r2Y1pxKsvkvdOCsHAyNzDXoV2WKSfhSCHoPvOssP98v/OGJKYF0C18xlU/9p6RpS9MFD91NM1MkZ++Ebx8zyB7FaLu5AQ0RcOEtMBhVvWqJ44NGJkg1fL547WnOjTuJXSFeHA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:02 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:02 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 09/17] iommu/arm-smmu-v3: Put writing the context descriptor in the right order Date: Tue, 6 Feb 2024 11:12:46 -0400 Message-ID: <9-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0023.namprd13.prod.outlook.com (2603:10b6:208:160::36) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d032be7-de04-4f45-79c5-08dc2726189e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4VoyJUJaSaeCnKPFYFw3kqlG5aaKu4XN4qtRqhFxa8VKoY2Buhn3yG1lMd1W7pDxIAnEORd6bTXh/fD9PfkfKuzF5aTEvMAQ21V3Ufo5kZ4lZdFBz/fciEvDrOJHtPwpexL+tRJ8ySSIvZBQ9Mk+OvlEDdj23Geyz2PLDmzAxugQs6NahxlD879XjxiM6njsdE4fZB0qBHg9+07KDoHz0OCeapeF3cFj1/NTW1RCxWHzZeAZFTg3dediAeHoUTaTRhCoBJaeQdF9QBsFqEKb7COAGQ+xAx1+yg0MYhp1mesUJ+A9MPbte3DElaPso+RV3OapCEsyf0uQDt/6fTia4ttzuv3lkNp1DlH9FoaMuJGsUqTc1Y4Vd1Fnv1KCeTcXwcj3ri8+lZFCU803QRaaJYY/eHF7GRz23T0uVRGIgmSnJcRJqyzOD5bI4c31rJ176uFJqqgmdrS4dc6BxV66VglDdysx3jgCPBUjMJBShckeZBrmEhAO+AuqEMBEAY35YzBMh742KYh486FbfhhlBzqVKEPqMvzbzwjZuIwOrj4ye44/i+UuG2SdPqwlLOr5s+R6dhiT9RVIo0BkAP9b4/Kpd6c/srUooFj2pr9cL8k= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001)(66899024)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MIH4ovvasTh8gOhpEcX6J/IKZoc8/8cLRs4G+gELNoQZdzDxt8MZm4tm+eW6w9CURuCwk4qKuA3vMb67rJkKgonGAjL0GZtzGt5dt5EMBCXfZ3lgKtjfTjhIZ/Wl/zKCOzNotSv2f2yBZukRuzrnEE6XEP7NTWDPYv0rcvvHN3DYHr5VeL6M/ePRZkaI8hlvIjb+WaMZjtgxusiiFduDlbZnVcpx4SY95s3hP0bnJCx46AstMnE4bjxcUBR2Ec7eZRRXBOV7OrTg6P2HS6scNtWFdBuduXTJlZKzk8wzG3tpopHm1lr26PZvk3yG/r2WGpjzS2mX+ATPSh4TZpzNb3dl5l79CUkmDYyzaL6ygJTxd9zd6nYJpN89i7hWIwCnCR4D9nRP7RbFz295Vl219NAQlDT2pq/BEQzWDIt8OBmjtddDr8mhvs5SCMkX5xhTVdismnexs/UDkJojPf2kiKIcx4Qs8C/m74oz8jgBBswe3J677x1qP4uzsOwZYKT2lqJ4AA+rHtEPI5D0LWHmMbLBLmkyGpf10Nwu4lPNEC1O1QNB3Uri3PwBZSpm7CUZ3bMo6qrQ43LQhUpbrnWTGZf7E+7BIpYo5CRp4kyOhjwBHzO1lseEJYNsYaRGIJaa21SeXgRsal7HQ6uBd/5pq2DuFsOD2m2YUQS5fiPVZSh1HQMDCec95IMxJAlCWf04R0eUet/uA/DKNG8YI9tyR9lvcEEID1istv20Mcu1QDC3L7Vc14OrwCmbfDHBUaWYq6m71hK8V9p+ZXPYdlRGsaC5gLCgU148IGfHGGIcaB8AEBNIzvg2M4P2YK3mxBvh/Vo6EnAklOXoEv8N00eYt5i8LorsFWMcIpyhYkBHhHqVkaOcak4nspMvlBOVp8M3C5Lvksn7byBA2W4EKzMTY4aVbamLXxGVAp1LepuDwgOvMes5vqG7FzSb+OMLkjZ0RHU4b7wV/fxWLP2Bk0kY8iD6nX694DaKw2iBlNuauhYCe73eaMzAmmBIGyojTHNWhUqkzGXRjZs0vK1etEE5c/VFN6myD7QFARJjF5qLPLVsi7KFgTA7j9+BN9eeH/cmK6PVVXzmAeRxd3so3kqu1MHuceZ1Vc9M59lJ3/biIsWLxDyrRx9GR1DbeKWzzqh41bgIuhXxnPx6kF/wghQ14yXL1+mrnGvL2JtAfYnWRZ2ZIObhZlab+WcggfBJzFAH27SJBC/FQ+Phu27SpWuDlFZeNCOUHlBWu7BVTQPIME1ib9xM+cOmo0JdawbAawLEH1C6SPbJeyLtRHGRUfsLTVJjDs2v4Xw8mz/ON3XMkZoi3d/FckJiK/Z7N8dlEmjWx7WMhah4hdBLXnQpOvQCRE9EjIBV3dkAh2KPB/3RWLc4FjJyw35SZguUDoDsn6D3YeZ8hHyBlnhIdZeJmZ6hcuY0YUXjASKPcPB6dYdloSvqdXOYf72BDC4yj4ulwl9AR3kEDRhw/o8URX4jmdK7x2+89QMSCPZKYFEj16iBvXqrKySHV/CxbkYvVwr9KI4PIshG9l96lJb8acKdmVvMZV85OAQILGDpCquVtJHHI/y8sjxOxHC2UIP36zkqQ+WD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d032be7-de04-4f45-79c5-08dc2726189e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.6387 (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: DmDnbubN437alRQQZvgsfbRdH4VhVDyyT2efCqlDauQMO5bJBun/wDsQNHITj9li X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071312_968296_F09245E0 X-CRM114-Status: GOOD ( 20.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- 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 340f3dc82c9ce0..2a6ac0af932c54 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2575,14 +2575,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) @@ -2659,6 +2651,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); @@ -2668,15 +2671,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 Tue Feb 6 15:12:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547494 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 F13A5C48297 for ; Tue, 6 Feb 2024 15:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6gimdU0yJBtFTqw5YJOV9S9RtcUOEl87hlGG4rgxk8s=; b=I1j5ROTrg0QAJb 2YfzYoz+7GetT/t37L31xdK42FNw1fjP3cB+BmLmb+Tn+4SQOhGlqzuuq7TVmzsikGhcfHAY69xk5 urXwFGUYEswjqor6Ss1gDWsI4W5vzrBepzlQaaC4qnmeetI5/i/mUbULfJghx8YvNHucqnhUe2bE4 EWKaqvv/y/di5Ax+jwBIVf58IC/AnsgxPyd2fgOftFJ3ZhwbpbjNuMHKa9TC1c5DBJ9gf/uHk82EZ E47lL5pGFpMyGduhtHvgAFKZQMxveX4DvzlLFuj+TC6WRczWaneYdk8xOT9QNnSU4LkHtSuP+o3+7 diCwx9C1P4eTkXxtlv+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8J-000000081M9-320t; Tue, 06 Feb 2024 15:13:11 +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 1rXN8F-000000081Kg-3Ggr for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H08100+VjsbtXQ4mz+DdE1SoVzOJ8QrLSIV86Pg2TFZjftXvvg7Bag6i0LLTS1hixT5h/Klm2GLlJc9QfoXjjPwrmHxcA2NaQnXL+MT7Hmz9J4vjcPhAskww8726DMnT+JU+V4ujnxzD5c0YZz1OT1rz0SZxNHn5i8zMbcSujejuBC5gBrqb9f+k7lIhcBLjqt3Z3rWeUx8K9WoLBplfHIbuoTO09OIfPMb1YZSsr+0mgOMuRnYdtF/4eCusOlgMLOQI7pQhwx9Iym9bLLizru5sPr84jbfEiXiWbiS5Izuyl88ujFxEyhomTq/On6sHkPf0s1XWzfVM999xV4ymxw== 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=jelnYfSZtSukW9U8Ez1I9xV3Nrrum3dHvFOiJLjtmCI=; b=oEnCF4e8alMwEXrkS3031YMijiCPOxBawMXMECjzkcxmCrVStFU99xUbdsaxHZUwiI0Jdv4BLmgxi1VJGssaNdm0ynUr1p3ZfgIz3xuCdv78IDKQgvd9SVSedjp2nrDSXBGgJXtVYRXD8wMxnzssIMMAgmsAyK/2LC2Wuyfrac2zXJmQ9i0mL6KFG3RXTEmLS3rU6tO9NcZGK7J6pZQL0m3di254sME/CH5bVH1bQ9z8z5MeqGx7SaOyrWZYU0badquubXYL78OEMlI6wjwMtOrJglQlUH2PXgfh3ToiTJbU3YTG6WQzoVA3g2VjC+lZzlMCxGx/31diy3MJ0IX6yw== 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=jelnYfSZtSukW9U8Ez1I9xV3Nrrum3dHvFOiJLjtmCI=; b=WgtjBNEMJUSTq5K3FfgE31h9vaAIFkAcV4kY43TYdZcbSHsByESQplWetNb3qkdZE6O4Cs9kGwk96C/ExlNUgBwt6J1qmuQaae+BrirCozcyNX7hjBG2fCNp2aNk3fmXDNX4Octit7FLJi4ftRWP2ahzuXd5rsAk6gHDCtQ/Hc3ea1DRMD/EUnWnwOHSmmSA43eV2CLqR1RxpMELhuRaux+DIowofBSJ8KsDiyT/FS/igmO4yQtk/9oa5pEomO7Tbblx33gOdrvmP88gHxdB/rETc+2JMIJAJQhBQWzmzevk8pvddiq0mLf3i8O1+3U7so3jgN1mMxv0AOjC1rkW9A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:12:58 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:12:58 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 10/17] iommu/arm-smmu-v3: Pass smmu_domain to arm_enable/disable_ats() Date: Tue, 6 Feb 2024 11:12:47 -0400 Message-ID: <10-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0001.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::6) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ada73d9-c9c2-48bd-d1d3-08dc27261873 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NXxnyge+J66xwiRsOExetgromZ65I8koXHcafpStaYjTvn9ZpSjhxo2fZGglYJQ+NBXIEbLHEG3b5VJVxuLK0VOqF+h+djJyaGYuR+xNGqCC8HdaarCjG6PRGOpH0c9MZ/PzNlPvq4CAaZRRov2BkLoS/piuTpNRSEqiQPFvaVvhZ/GFDSPz8I5G/JTejfCdFdVqOYQEVTghTtoqmhTC0T1Cr/8kntTvzxKOShXLo6qxIB98jqeSQTlhibqtxrg986NvjqhA6Arl6Ftse0VlTljsFkYS39n0AnCRQx4b87cTaFPmJAnlGiIRVnhccbMH3YA2uEPr3WavnxPSl9vUPPna0Lf2ukGA70nNyKSmGD1dkZUXPAJIE+TA6GpLW6G73NprKYkmK7EsZzksgbVXApr4gw47EkVD06a0C50oYZo7rdiLmhv/kig0F3TAMgYTN+W0zaAbKdFpMSerbXywmBO7YKQwFM0pmhrv7agluGvgkY84XPU8Iky6p/U0Iboy76qlD3zPyOxigQmzzJ7abf08tHv0bNBy4l0nqVE4SUP3YTlyMqXoGXlLbRv4/PJf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BK6OBqmcVp5D7XgUddth32oThnV/VdK+kuIoMiDx7VxQD7BAqCnzOB7/fa4uDCtrLit98iv3sEgacaH85u/HmQDzGtbzj4I2d32jziFyLL9kPBRD3PU7pCOsTfKt30Nb7uYmq7geaioaTH08SeUkHBL55NEM9Ehs8IMu7SZhox8o5frBfvKHcg3XlsBXy/gBYBF3QsaBjvIXL7MaVDhHxFOzsxyUfZe7fN7OO+CEiaTsDb5SJHDccxgIu8ZgyYe3/yZVp7nroTs1yfCjfViZdobPQR8xEL/Cp+32o2Q+YcD+ujdPWgxzNI/vcWi6/4onm61fe9EbyEhQd1tW5Px7nh+z7SnPVVBCfhkGIN1jcGCMcho5uhJlletk/XnFI6UHSeEZghSjVAR7Wb20oJRJ2S5DLWOYPkIMACE0f4vQ391PlzHDlcWaAg1/160DnoGDLvpqP0U0Os8jJl1BB1v1UCbw1x4LjWLKSb1BBEUSFcp+wqoDIdeU8v1hpFQ781W6DVMPGBDmEVYX8vwyUsk/SW98uExDyTxXuoe+z/JV8f8YWn+q2ylAxUG//JsJv+J/6tsgE5sM2dBPVbHHiNVl6QI3E4ry7PgVuu281msb+c6oQjyMD9RaZwD5xLNfrMRWmMl+ZP59auW5ZMnZyazMr1m+J18G2ViDWxe3v6cefm67UVI0QL6CauNaHLldpYoa6zE1GAFycIqYRC1TE3VTfAn277xszFjqnIJyVhNihON+mOLaWipvEpAtcTJ4He+wCEuGWWiP5qIwkJgEHIkXmWZaFht536rcIw9wH524NYZU2wmxEG6Gzl5rQDP52YTVT34iIbOzz5pv8QkI/RkijsrJMYQhtfCs2E+Nv/55vbHoqUDGXddjdKk6VAWrJlyxmL/+tfu+16YlHQcdNF8ZwEURAUU0gZidh1Qcz3QB1IX+XBoinypvpifImkE/IKEOW56yV1qqFKCwIXyUIMP6JkWrTR4QJMJbB3PjeDvvE/U21Kg280lOF4wiRt4A/a8Bos9wyyTp6C17HwLstFTJJT/92toDoNNB8yVFclGpuK1pleAnDUbnKSOl2XPSuDXWY1gQdUx4AJH495SCjDqpBh6Wc1F22qnx/vwh+pXvE/Yp1d01od/iVZYXiSnuC5V8ahUDCY9A2d5tEtqHgcYg8w4vGn+vSF+uGCkaFQ7HJ4PKq9tlWv9CBK8BC+l8IkzWCFSeaS3TqGyIRrKraCi7DurF50AoEGdtlPret1yEHzH5Qc96QnJRnWm+ib4pgNYBRTR/nUHmcseVYjSpThEYOx2zP7T99FWZKPs7E0Euh1kjPcmOVEvQZBJdZvlQn+Ohv14Civ5K+U/s9x8We3sTZ3bbmpu8sNi3Wi44yKpW9KHrsPPrbZym8Fa9LnYcKi5GmvY1/nOg6NyersbtDJUjTwTWcDltMJlyRNWxyTepShTNOUhYuNR0uvYrKgZTvmPUA7yN5q+Lzp+LjGmKFMfhlQ8yD+hCSdf+X1zywXuCaz7Hc2i1nq0x7XgutuplMc8F6gsNhATyX7L12xGn4mpp2hUALuFwiz9eEZc5ZmEG1TO+lFli7AZEd/X+N8R/HuAn X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ada73d9-c9c2-48bd-d1d3-08dc27261873 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.3336 (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: ptccVQrFt62fjOXCfDhE09ACaQJilwxJHRsr91dcrSt2mxanNM24zdA+aVnC5DML X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071307_845098_DADD2DAF X-CRM114-Status: UNSURE ( 9.85 ) 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- 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 2a6ac0af932c54..133f13f33df124 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2474,12 +2474,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) @@ -2495,10 +2495,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; @@ -2567,7 +2566,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); @@ -2689,7 +2688,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 Tue Feb 6 15:12:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547569 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 DEECFC4828D for ; Tue, 6 Feb 2024 16:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=g9RwF4MA4u6f5QsrdXwMw047PhooNQReXukCJZQ9TcM=; b=vJURbMJTr4xA13 nNZDaOUS76XM+JmZ7MDkOi9pM9I2QcFndReFGjLvkuridHPN6eYAj2WX5mOj6WRoKgGKaH2jNvUvu fTFM9c69ImdyUFD3au7V5kyz8ClHGTgNM4vgyFNt5mUktOjkm+ucbrGaC0HioSqyvdOemCIigySig ygt7KduFhKE0sHv5VXSi9PIrS6yfkLmbW7yNLPA7eGbkSt5D5Z0mCeZgPjzJgJQaNvIXe7oYzqooy 3XeEzijZTOOwuhzdwS3ZYo6Uz7ovTYegwrj4M2stM/wSqOVPr9lr8tdykkJlTi1Qs/AzLXhvXG+td ZYIUo0EISGfSGk4/I/pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO70-00000008E1s-0wrL; Tue, 06 Feb 2024 16:15:54 +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 1rXN8N-000000081Kg-24do for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhRbiNfxEeEmM1RI7mIeKh0SW5khwDoGcRpBhd7k+TBu3t8lw1b8teg1ogD6PWOlskkeWJ6D8i+BuwDxfYg3AFr6r8H9eKTDs7g3oodkImu+E/XesE+NOTfq4S0O8lcK7822mPSFJB+GiAEVAYLsizOCEAVtqoji8f0tLA20Ig6TzRsYmu213gaa+K6CylDroiQeOt1xW1ppvcNhqGXeC/12yiN8EOMGTwgLJ2wDSwqZN6YNvNuH0vZxqANhhL0BQMweCXlIkFf55CZ7wHyKa6gEe4JAFlmYEFSwmFo4f5lJrKLx9AfPvIHmdXOXZVi/j+3tVLCmdD+jww84lw2vjg== 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=zsFErtEFV3maUSqhykvMDMh7NNOem07IZG8xZFo30z0=; b=Kf/HjbX0uhZkj4xfHCOsw7/de45HSgR2TOgKsT+7DGUt79A3KpMtXOPWCtmFo19se3qckM6jVSmR19wPMspZM8m+/7vxFvA4QNZNS9GTWADo3SG8rekBzpYJj6SUDUlYUcIywrvp9CQoqRIqFtsC+SRlM5NzCqkjFaCzOxu8rYyY2wVb6/9bxstngYvoSuNH/fweAOCjVuXD0qOiTz5dlzVjQd86d1/ZWF8H4Q5bzBfqYFQDZ5HhUGAQ0j305gLCvwwnxkySufC3S/2VcJyJcNv36t2vKIctN2gjCqA19Sow59GwT4Hpg/++KfkWmyygPqltydbfNdRwx16TKfKLTw== 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=zsFErtEFV3maUSqhykvMDMh7NNOem07IZG8xZFo30z0=; b=iQX1QLSxezM/3W/RWDWAn+WHFSfBKHQ/kfwrFI7TbQC5CRaU/XzCvgSgQBquB1ejWl4PzlNl5p+kn0ozip46bUy8FRxqcGufpCSkBcd/pQX939y+0r4tYjsLfaPgPTs0ucds9qf0dE0895bVWKwJCCD6YzAoS8AEnz0xISVtS0yfUoMEfiJu1d1UzZbaONobkpG+i2qAyvV4SuS4bcjonOUz9zPodyAfYnqs42HfqWovoyd8gwaSBeHlwyWTqMAVXw+5HRRZUiHIyiwfRAxSb9k2+GD+pC6SgGW9jqeVmFUFP6m8Tmj1QFbCWglBpZo1EX9h7Pas0IC451Z0tKDCIQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:03 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:02 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 11/17] iommu/arm-smmu-v3: Remove arm_smmu_master->domain Date: Tue, 6 Feb 2024 11:12:48 -0400 Message-ID: <11-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0006.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::11) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 7dbad165-385a-4cc3-5874-08dc272618bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dS/xgbIkPBmEZdABCsb1xmV+QP5XbklYLBXLgVgjhLB30kZ0txIUGY6akSleXzj4tmw0lj5k4RMYlpX3TfimisgSRR2NGHuX/Qm3wl+r2FNQ1+it8990H4L7qzSJgiyR+Ltw5vb4V+6jgldAzbYcLacboNXCy7icTQROLfMEN0X/USNc+TqTvwdNjuXHDV2CV0ZRrJ0lyyCyNI6WsOm/ii+kOkqFr3nhJ8wka8tQHa1V6TRJ+H5KAO2a5qWqY0Nx/Qhi88pI52lRty6QI+iNp0lIe/RbkXHxyl4oG82yuc6lI4c3AAG3CZfXF7Tum/emKJCU9ELVrLq0HGUpuXxBm9+MjyeFC5hu/5eZZUua99pKg/GiRsKcgIgRJ57D7ohYh2NJUzbNHMIgrBXNq61ZxYJPjnxM9a+fxAQeTqXPhzMLfMGjDVQpvzNvZiCFi4b1ap4VP44+VU1tXEdlmGyYosX5QiWtqNr49nOCh6Bhn0x4FL9WLlskdGJm87Wj5qEVlKUdRHPURlsLoqWppTv362umW0iWyN4Z9qHLdiADo92Jlq7/EBnIymKFplhALy9z X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MJMGH3fFnzIhD7LhJk2JLHArUHcETl4Wd1Roc0u9KySxu1YEKtZZINxpLieoraxw1BWvLOY6LtTtQQ4VTKmNVYKMhvChl3/XoCRAdZQ0UrDEZ1DJvp5MzhdR2UrikpYlkmcGtAsZEh7XxFPYFMJhI//c7Dq61+ODPITnui6WyKDT+RGFnHc9Azwy5TaxYqePEByb79kYKYC4QJGPr8Mm8FKqdAPM1S+63oppSd2OAPtPF8PuRNOqh5zBDkZRc9uuchP5TnHQcMutbEKHgAfNGiEAmUvrZlo2wzVw4bbyrEQb1uGueNZpQRTTYEGsSyphOZDJ5HOYOM4kTTPBxwXeQ+T7flZ3i7SzS4LGTtVPfAK739RZXeC/We2wUhebBchzuvL8L3C5oSbUAx3wKnRHT0yTbO7yf8H2YCbIGx58mbAa7/QrVBNVg6ACtwRph+7cONMtfDWg+PT+xq+uafs58DKA0UGHg0D64Vu+jf/g7icfuaIXafLR2zrdQ5FZ43PzkilmUsflvNILL4yPjSCFY8U6k1nKubCOo/S2Ta8quP/C9IWr+Lw4rs1GudRNPnZ3jBFVO0WjDNYmg6i00Gc3Jyfj5qWXdadgQfKM+NOb69Yp1oolDD461Rp+AvqcfdHYAAvfFgiaGxdfMS0Xgna1TA9TlIXcn17O4GtObhaV3cwhsjOH/akVSyZqwb1Q3rHUTB1kd2Ff0b23VkxjYoTA6isF+LNJGPlPXrpVBros0ac87b/RuJBCDx3en1qfwl4Ds8ougHOU4CQoZJ2UCpwNr2DMS3B1r8muXODIaBvRNJdEtuiumQwe+Q2FEPwcZHc3MyzYpdrqrjoqw83pDHJvLVHxBngQ/mdny82pwFzNjGRTsa8hTSOTLpLXJd5VpmD9dgSRB+OzjuXt5F8kkp3w0B8HdLBO4g9PD2dL1PufPbX92kENxWVYSFQSmgt+qzh33mcBXqKDdoXJzMiJulSIP46PNC2FNvRmkVEZ/xTrsjNYmoj8eqc8cfl4KvogET9jX25RVJIRb6YjgKnOgxLTFLITjFseTbaKT/YTTq+gweouufhZSiQtkBnP2HzMrqivT6McyUK54lDeqpRWib40nytPZK9XXmHmG3TDi4/fKucQN9qVOjGi0Qhbeah8c6VZYtlPfID6/HlsaZH0crljk0EgQshUJRbpHiY8UzqKvb6uzAHfZPy3mrfoUeTbQhWcN4vKO6egdnLMtl8e2QeN6sOPz2SQxIETb3mbYPxUmVzBKeHLDrP6O8CFZnZ2sN7RFWxCKnRAevx0p6OuXocbylDv2dw04u9F7F+Ru3yGj7sm8I//YPnKDvdI3Jut4ljMh0espWF0xJWzI35a3HJcrctCWgllMACV/qtgJ5lannY9fquKTVwCF3/qCoF8UnfyS5Wk0rb3MBn+P3IUdYzQJuzoiOgaFerlqQOwGOLfVpkOZst2JrgQ8CNPYj5WdGE54TnmA+huhgSQ9oUElBXMch+E+3DPCwAHjuZe9SNSBD9X+halF0XFkXV7RGH8b8Tfbu/z1eaM2G/klG+dOQCxQZtXyJaVmKiMprZHYXe92QlqthnKsdRXtfLo8dS3UsS1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7dbad165-385a-4cc3-5874-08dc272618bc X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.8158 (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: UBLWSZNW6hCn0Z4+JsZawq5aN1/kDcLACRtTGEoC5p5iKnEH3FPArQYd/2De7IQi X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071315_690368_70CB8E1B X-CRM114-Status: GOOD ( 16.84 ) 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 domain_head against being unused, change the domain_head to be INIT'd when the master is not attached to a domain instead of garbage/zero. Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- 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 133f13f33df124..a98707cd1efccb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2560,19 +2560,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; } @@ -2626,8 +2627,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 @@ -2646,10 +2645,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 @@ -2657,17 +2654,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); @@ -2693,7 +2686,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: @@ -2894,6 +2887,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 cbf4b57719b7b9..587f99701ad30f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -696,7 +696,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 Tue Feb 6 15:12:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547499 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 5AD4DC4829E for ; Tue, 6 Feb 2024 15:13:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HT0cZSWcRzyi+FgSgRDSjYz6TKM9vI4ouV0mU+GRnv4=; b=sB/xjNk7Ulz/TA hcO3QwKDK6d49FDIyE1RoxOaEiRtwEIFcf8AsIv/WnOFGFSMzkz6F8bJbae75oFk/Ox/xLmMD192r sTSrtiN85w8R9Jwutb1ZFb7gLym43Mhzo4GNXT4VZnSPFC5M7WkDnU5ZLYhPc8uhIeP2dToDLJufb biYhtb2ZD/m+llqScCgYLMyhkSpn5LGJ9jsj/9cJ6jy5TA/dWTtcFYgxX7g1t0IcbGClw7AZ7zkGS LkEwiks6/lepPzkelcEOkJAudAHg4jE94DtVeQNb9QIcS0PrGus3PMZNLUbPblpl396AVVg8ptmdn /liR6vTH2BJZ6h0EMelg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8Q-000000081S6-2m0L; Tue, 06 Feb 2024 15:13:18 +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 1rXN8I-000000081Kg-3Wcs for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ii7rBI9JZiFn/eVJQx9I9EKmYmM+U72sEdt9nMm8DWSlqxmT4Fq/SzIbzwh9f7VCrxdX88renDPUWmrgeSXRStQQr0vBHUQ/OFdFvT37fWdeD0zlrzP4412fYxp1LcalugP2SMSABCsWOBEm8nzn95kklBUNknepXG+CjDQVI4JWkht3f0djMpzwhyVXPtahe3lnwYEb+vM8RFy7rQC6DrYBtz4OcJ7akQCBgJIzxomN/tKiUieLPovxHFHVHdH8viyLzueXQIRoGuJr/zodSvtF0MhidQNFxF/4/XHN23O17MyKCmnscxrU+IBkcgTd3As4mfYh/m8xiPh0E4xNWA== 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=qBx3y/XF/XyoM6h0gRPZSbM2AT00TTHUiueO5GMraww=; b=K+WZsEdT0/5Di/gM1oGvaUGwD414Q3oz9no0FFx4TaoGgJEh/8OhwHI8WkbQnfeT3uM6sUc9a+KgOXZEmh5kkUni4GndKdOOcRIVvH3d00DZUhQatk95WTopAXaGB0mOz/mQBxhoBkiMRZ7tyF9XU5ZJpV5slHnwOPvG86oMbSfgZEtSADBX9OiqarAd3N7I4F1AcoE7yw/vNqMpTECQRFTn6WkTmX97/7GMi0xML9G1/35ERbcakR6GYMhSlq5b4O2SS+/JZm/Qp633eOoa+82X3pxmazC7ODA3Cc1+n13UcKzRHV9KFC18bsm3VJRqfMg03hBN2F3JitZD/SsS5w== 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=qBx3y/XF/XyoM6h0gRPZSbM2AT00TTHUiueO5GMraww=; b=UsCST/33kvO7vfXVtUbhxM+wdaB3ec3uQabtHxFSxWJY9X5V/XNpYm2BB6hY2RlKTu39QaO3k1NmZQZz8WscOFU7ituUh5ZLdgkyYFSbNmuDIAgSdgokD7vo0NE/0DLcfhf7c8dT1ms3CYPw6ha+8cG65Mp0RJ3nayejyvjKyeYyuxjBsbdtEK4gVGpKWimjkKD25UC+qKDf4G7lHH+YcDOGsjqBtY5edD7WLmNMpHWV6cijkuW8yJJRrZWlj1ch1/oh74RPDpV2r3Nt+H9g5fOQ1SRezgXH8RbWmvFftNlhNmcg82WhCMiNzcrA1o642oI3m64pSVedO06YNoqB1A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:01 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:01 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 12/17] iommu/arm-smmu-v3: Check that the RID domain is S1 in SVA Date: Tue, 6 Feb 2024 11:12:49 -0400 Message-ID: <12-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0055.namprd15.prod.outlook.com (2603:10b6:208:237::24) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 91cef892-e048-450d-73f5-08dc27261897 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BTtGGSwfb8WUH9FmDvGWN8UH+8kT+mA7q5HOJi43CG5KQ/OvyZoBsl8nc0lLmLDKvZ9shCYIsJDJjpkrPMT9QlB/JFcEgSWuX2ZpYFCv9xhMbfIhp/m4FJq/1/7/cygM7e1JltiZRylRvJYU+U+s5Aa/3af2l0gV3sPNWDC3rV1P1hlhZJyBOL3rahpMSg6q6KZ+zgi/15K7KyLFoGqHflNEydbfyDdRWbiG0gAkLVv+sIxcqI9XG+ztGRQBvcsGxVI+cqc/8Cmr9JczaVza7c9Bbj5don+QMaQ/YJYiECKNL1bwxVVqtIicw5h/Ch8Zl1EbedQXtc1tnFnnE5DBhyogZcyamCOclczLjPB0b1VKoQVeDtqjo19G2KSI83HQ5mmqSKN6pAxsMNaCOL7cNOgeRx4NdV/IyEVIo4/4MnAdiBt3BSPM22b9LU4qDPiHUxkWKeVLDdYKbKV1Kuroa3ZAs0Ne+jDEEb89EvSpV8bkpZ8dpGsBNx3WORA54Zr/gOiifNXsjfwmIHQQZOMzxRxJg1Z3+TZHLYtwT2nIFwwMkpBIVBMgLeykwXalVZ86bLRjwdON2DeVIQnUlN0kqz6FRoJ5aiCu0hUHNFMtGHQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(966005)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JvCBl6mkDOzKFH6ZvaW1WEgttHoKI50tBf+x8S1KM2bF/v97M2JR09Qcxz5weOAJlNT9LJJPOXhvjB1EYTtsdBStjB+F66G0L0BvAQ3gEec9/8Vq243i3t1aiet9orPoLB1vHsehHfR4ZxdqCPfvYtWsNbDXuwnhf2dG4RyTDldbXPvb9fQZ0PCyZ0Z6PDupvADCT/V2qkP4N8J0wBVqRgZRI2ss+jDjWLtlUyzntXiFWxdqjEd33ebWHjMT+QPnWMj64qMNh1MjCj2YPpVSh/dqATM+c0QcHFU809H6CAsMW6soF6i9IIm2iVXae21c5eJaCRtlGpnz0cyc0M5SyKNkBwNplR6e68LfM+0yusdJBHVfKh69VfBXycj18aqxayEm36s4DkE/fj0hkNVH1dWywHrwygKKnmbjkFFM2Jeye/YTZylKUcakilJTCK8uEIWtTZsdgFEQ7sNMdcV3nsgwJjm1b8mpIlNehYOr9uZ3az0JuEQ9DNpTkDcFtJulJne9PSvmBkGAiqfz2qysHPFN7+PhqiE3K81W3fIzbfZhtlsmle9GYVxsMt3bkg10GiZUY7deb0hmdz7bH+rS3/UKfDrIXyNrQ8ShDJOzGSXPY6WOUez1fsT4MIj7Vb9nR3xXFWKef4QVxaJZBEzuucnK4xwlfd46ghU1hoe72P6eXw3IS7QmuSoaI1Vj7h9H2mHajQ7GAgOL+LBjJw9ad34X3CVx/4KlEAKhsQeIIeWlxH80sleyo4RPLfsKokqm/SrNeLhB4DYpqlXrCb4Qf0THzWhqVZu7IH6M/K0YkrvKk275MTcqpwS08cTvCJKBvVAqXCRAGZMUdoVJFHoDLlmgg2FvyEpFDlHU4YC04ZaGvWCxpI9tem8twiZKSqheZ7mdcIKFPHrY5+iDzwesmo/bA4oJ6K/1SmuBokVV74xQJ7az3eb4Q7IulG7C3mLSkNVZxK5QSi5aPjYNFKkFxk24xcnee7yY6yITN1F7lI5MPzv8QgqmSIVeW4I/L0tLN5grUjNQRxKkgSApvNq7p7nWprZIpvBM+EetbINe4jGOeK+Fqu5ABOfLI8G8jRPb3SG+OmCHADQJhaDEEibr5gRt+5lp0bqR2KyKuLb7u32MslHjuPK43+5D+BmIihH++8b+YkjSvdYtSNkLnK9BgA89j7n2FYkQGg3DKcXSHe86nyZtkJV/G+Q77Fwj6535vBsb7MjEGc3b0K3pAdpDarpKp3F1Q41s3PCNe9Ul15Htt3iwfFDMVqjUgU87Bwc0S2hDZFFmSLuoROmK+H2X+z6UUb4oC1FIhkV4cQIxYo3fBbVkVhxGh1ItWa9bfh+rGIeVlFBJWpNCiidRi18BJpQrIj5wtcCGEVsHITj2MAC7MVgVnivR4PqRNBeoiBuLALTr1JkkijljFU6CC5XDfoWYIwdi+UNwguMYBVBRZIMgoWt7qVerpdJanlZKhDXg6ci+59mA3e/UWSRZdk2fZdPqaIrmxx+EhmCm9X4UQTqHZtkX/sRBk8xit3MgpQG43bZi7iEKHJpUIE8KYPECAxs41lmQokqqls6DN2bmVu4yVkyFCTBRz0DF431r6UJ+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91cef892-e048-450d-73f5-08dc27261897 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.6007 (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: LrmafPwhvtAhOJRlORlY5196s0/QrJmtMztTIlW/+wAOPNIltkI8OAZd0+HKEEoG X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071310_941550_19E06273 X-CRM114-Status: GOOD ( 13.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/ 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 05722121f00e70..540f524ecf018b 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 @@ -387,7 +387,13 @@ static int __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm) 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 Tue Feb 6 15:12:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547571 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 A284DC4829B for ; Tue, 6 Feb 2024 16:16:04 +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=w5x0rw0OmMzSCxq6pStMpKwufRSv8suyAslKWW28FNM=; b=QNtuOglGxfXjW1 dm24t+nH1BMxFhHCczUJDhYsfRdYRqyHXjx/wGhu7/JBO3M4uSUge2gATw1yQdI1S325LSTog4i1+ tXv9nY+ize5oZuSpPi367jFL8ju9hYZESDxcG/0OcfX1JtvgUm6KDALr+NPfUXGZkFzSI7bptrN+i Mo0QLvP5bJR6FDsmVjDlB37qUFodUizqzY4/htws8Wu/xq4zYRKcqe2sPMtiMC5qC0m0k6St1Ags7 lMORjuTifx1HsSMzoLLllZzBldu5iUm4bwfkymBwFVOyCu62/qIxh9xF0oMpcDwBgSFj8MjFdbf/N 1RxXjvpbumzFFl/sXnhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO70-00000008E22-2MoJ; Tue, 06 Feb 2024 16:15:54 +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 1rXN8a-000000081SH-2eQS for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c4m60eudJXHaLWmRfCDReouaZUqPXgppU5mhzrmpiv3nLiwy97quMIo/BZ1p9zvT8j7cyvmbc/1fSocyXIy+QjTovraeArWxjBhvp4zpTQQtLy57BMMF4f3x/dPJwayGGk7NooH1M3I6krw7T4493XEUGlgJQn8f3SWhMqKhZNFgcfwEiWeFX1E8If1OdGHigcfTLls+cRBJqs6cPSa2XrKFTrB8eGq4aM2xFJ+f2PfLQBsLFfl0pmiipVZaQrjaF4r6GYh9Qx0Zi5nU3M6bfaVzDaDyc9umt0xhdyWmO7r2kO3Dgs3uKzVoTG6FiQ8uWIkwu+a+3xkjkw+MG7DmJQ== 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=neQ3Ln94OMYkFN41cp+XL2Ok9wGJ1AglbofXvFxu0uI=; b=kpRa+fa0LTd5QYt2c7B3IFaGcKENi4+v4E9Okf6UKXB8SXRu1bd/BMeIMbXbyAlZ30aCIzrBceyWWPQNO992MC8yeDEkmNwb4s4uw6bWPFnMkmJN6sntvCRviNYqjNXTJjxX1vd5WPtF+vTZ53EH5qns0matf3eH5ENgw6UtFEVl9oVrCk+Sie02vYtTKpVXlV728ibh2F6tUE0rtz85WM2QI3Lmw/yRUSmByDQ6S6iAz6E40qh2O3rLuGpd9FEZTPW5ZrjCvbUOQ/FcZ9+amuc2NUzOXKoQMtuwL1gWp3im1aolV1txfbFdcHLRalaevCSYz3rIzzbkBJwOrIgOQw== 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=neQ3Ln94OMYkFN41cp+XL2Ok9wGJ1AglbofXvFxu0uI=; b=IMXoIWFSFt974ZhuoEb5sct+5/sV0yspZYo7g2NHD3v0DfFduXaGzFmxLNKobUgkyxXsTDZqY7GFcgtY62+ngCEBuFxkOkB9gHix4lYaSHITK9H5qK7imS7Yd3eZ5w/bVeR7ffM7sNa7V1Vw1IlxbwtxXAVWhCEgZ+QSFvXvMDcpg0Z9wCDUgnR5hee+R+J+wXFIZxAt4hp/1xuCGmYoi9Ksj0HhE6//ti6aeE6dD5XmsoOoyTZ19V1pDd2Ykowp1babtYCuGWYquAX0+yy11BT7SAFSysv9a0ARVrnmw+KL1iyMp/IH0mBUTwcEOUBy7IJMClOAm08sytzAWl17PA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:06 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:06 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 13/17] iommu/arm-smmu-v3: Add a global static IDENTITY domain Date: Tue, 6 Feb 2024 11:12:50 -0400 Message-ID: <13-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0015.namprd13.prod.outlook.com (2603:10b6:208:160::28) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: b4dafb2d-3e26-4961-e89e-08dc2726192e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iqxyVAIJxmazbk21KRSI+t07eRhVbHTUJ3Uv8zkWYi7faet1w36T47ZDr48xfKDsrTmxkXx7Plll9XnFRiQ+8P0PUo5Jiq/Q/mCB3FjW2CSX3EMyBZPJ2L8bnU+AMQx7WNuj1QB3KaF8ehgqcbbbRFOL1NZ+mJ9cjXImJ48VZgIiFwpIBjEeWVMBqVE+GM/nQEJPI45NRS1OSwlHHnkySwaDn/+flkZ6WZnvSY27XbRwqoVF6Cx42cJwI1OPU81DboCdA9EHHDoAgyuZf7OFJEK8fPhYMe5q/8MWxdTwbeZpKQ3JP8dENMWPYvm6zQeMNqxB31ltsrGSiVT8jZXi40gEqY8EVnDDELddy3AJBzEnukLQweblb8IIi5NN6EbvfBv8anX3Y2CTwOoEebPxwsW466ztra1oWoytKiW+MIbVU3bz9izIh3cq/lK5uaRKG8V3q6sqSWXQwB4YAD+MwIroioYo92KevRR64+5WhRMHrd/HGidbCOpiZAZfdDVRGXjodP+ED7DcrlrPzc+EqhavDFbt0Dkg/512upvncCm/aRlWk67p9Dh1y1UoVe7I X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hblDwt2yvKqjcpZ7+MBppk/WXC3KJRpnAXAAtrfd+Lwov2a9ubyVGgwEC27+4MAdnEWwL24lpacTO0ipCdrhNYodKsIKc/n0+MyfHnVrNhnxGE3wGfG7FSyIW53cymhvsHl91s/qbkd96DNZmRII6iCPn6Von+a6KP0hfh6fkjmsEeCHBUgZm6GnRbOseaSKPXW8ow5LFC71I0PeAvE6k09eBfoMw3snLRMcMo1IGwHxHOXs2BI1BlCqksGykE6Bzpn9Q6onRUM9at8dsRydzmhEg+drZ6OsXD4LgboVHBiZX6eG+fyUX+3AGsnctlAclolsY8boJZSgzzWrfb80Gjeer4TTGTy5dJOMsoc66Unh0RfpqZmKWUw//zPR/TB37tZiiCR+wlclBfLyRx/SOlrRH2PrwQaCBIhDnfDATsKGTE4jw5Tnq+qwiHDJi4/rfNQbTVKsPM9zqhNr9eP7rj1Tr+4vRVSJ7lGCb8kVuaiIPx51g8srilj6jPduKXxezQQHz/0PyQJygXz+dI+k2KLLvqUp4Ly1TTy7MU8BT59GSK0NpnE1qAxNtW7e1hkoR3ebEsNuDUTR0GrhGEh+q+cPkT+5be8Q2jT3w2YvwyGPMwHCDz8K8zJUVSMRoBh+HwsRW5XlILErXrPQDITa9MThD0TlIl80bZ8vhXETRpqHJCbW/sXdkkVMrzmuJDCTRcxwDdmY+JFtmVmPImHR2CeP0T2iAtcwU9VAgkF4TgAjhfuvqDVZ1LHMhknFTsnuOfLtp7qFJ/ek9W8zieDK+VQaNk3v6gHi0l3s9VWF9WsCe26yrIfYwoD2VzjpyMEAzPAkgWkvrwVstqg4RC8o2IWf/Yun/xsatuWn0YWVXqcDdSTMTeS59AfDJxDBxWZm+Zi8yx+8lx7duuOrIqLC71I+ICx+ZpZzNfEZMoIgD2HDlHsjN1RbLRRmimQHVy6TkfD7XgU7H1TEuX+BokcxkiqoMC00HpN9EgPlAjGlbhnLDlqLgKkwS+6hI0w4wvwg0zD4Jfe9YAFOVSFjL0FTHYPUxxH+xLQQWr6OaOlVna89Cu0hYSYGWf2IqRF2cB9saWBsP3nciNHDiCIt1069BVIOc1baQTw53EopyXtG2Pf21XNqAhC2oI2hFVj/RQknTDt1qv2TNfubX7It7MG+8qN8a5z0grsAK9xDDqdNwGxCAUp22Ywi5+gLVJlc15EI/u8yHolFiSfw4PUJj+6himLCv5lLupIMlmeUqIBw4hR+nFC7AWNX8gIzQ0FL7hpD01q/84RKXeH53jOcNRJK2qEILT+T31pVj05tC/+bTvNl8Y5G/AYEQHNaTDpFBCJ/QKNLwIVSaP2kg1WR21FFU2B9ApxPIaMuPRssHUlyagXoBPtJnJLcxJyLpAQ5xlo1UAtkYteET0s3tgneEetzoe/bC0iCTLxGqUf3h4fpodqWjfrAepwoNOHbY/BfpeyRTtpqHDlcnyAGP6zcsGnotwOOHFK+r/mWhgkfgLOlbLC80X6NISCogAViGjF6NnJu3Z9m/vLRo3vFKTPXJoGwcS64qd5XBqcDztVLgbkALucxPXZ9Z4XsQ1gI2AktqOaW X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4dafb2d-3e26-4961-e89e-08dc2726192e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:56.5763 (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: qa/uK79N9VHqxdSblSqo3A6MWWrmBKzSG6IsMZjvpAUKClPdg553+4v9EdLVr/Dp X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071329_135135_088B089D X-CRM114-Status: GOOD ( 20.25 ) 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 a98707cd1efccb..a940b5ff96843c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2253,8 +2253,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; /* @@ -2362,11 +2361,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; @@ -2564,7 +2558,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); @@ -2627,15 +2621,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); @@ -2672,13 +2658,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); @@ -2694,6 +2673,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) @@ -3083,6 +3116,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 587f99701ad30f..23d8ab9a937aa6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -713,7 +713,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 Tue Feb 6 15:12:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547498 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 6D90CC4828D for ; Tue, 6 Feb 2024 15:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c9uHqeGKyI79FVfoUI6iHgozci+/qwBKVj4Fg6itOtQ=; b=SIKZvmK/uvVpg/ 266l4gw5+LMsrFCP3bDjfugFEaLUKe7Nth89oXLNIZog4lUShRYNPoEDFFUla+itTjr9ycWQVXWaI iiTP4//f6Cu3h3FFyOcxCneSY/5GQ9oc9SyVr9dIKEc+ZIniI88Y5MJVgZGcGhuvMXo/8iCbyyJKa B9tiEm5Ft5xlA9J+ly2xiLePj7Wj2tVvftDKnPFRWyoGI2WgQKS3fNdDfQRK0om/9POE/GBH3Lc+D UcFX8vZ/Ulk+Hj+hDbv43Xolhp7Jaxx3S6/i75SY2SgMRu/KGTgfgomT6Zi2V/KCTpT8BOKTmUFjt 7lHYuZyFS5j2kVaERZIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8R-000000081Sk-2mNj; Tue, 06 Feb 2024 15:13:19 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8J-000000081KG-0OAo for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RJWGqq0AqPoRQzYq0b316XOm+m+D84+01gKdws23yiJqHGJG0oqqtU20TaSDmMhuw0pKtJXMlO4/r+f2W/fw006QCMS21J8y12B3tsQtPNGNswEXmDEgx+PxmXuBZhgjLhAQ7ceX772x75lZ2bJS2NPhLPbfDz5vldlfLDLkYcXjWoumwRC53mLrq0vmYhMZ4Bf4br4jBbJOtZnq7Z/jOgFGRtIveKCHtMdlbG26CswcjXJq1IC8IrM8diWnBYDnLhOlZ9QE088oc9ZYT7cMdeOIe7tmwVykA1WxOq4PAZMvcBSAXjgfH/hZEpRB23v41pRWG4j7y9EyB4qNli7JDA== 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=3MTlkhWEC9fX18quSmtS4wAXnXr4cMfsGl3GZP3+oA4=; b=oX4RpOeuqkGdFjL5DA+CKxgkd8lrTrwqX5kQO++ash2yQnZnzwz+4Uc8ittVyXHgqApAREjQAQpwSZiVPI/CVbmMPcfNMwVaf0Q0trS8oWP7VtltpsiyNz0nQSvP8xZ/kUmkIYZT8irGhVIVKhuaGWMqwTp7/Wn4duk+X/nnx9aUHz5pkwUX8bp2Qnu0eTQIkdXUf1X0hbE8EiE9ZE0xMgOv6rxpYzUmSgxIL4do4JXfvqeIcQb0OloyTzAXB3RuZloW3fIVG3Hpa8Xq4NGc8IdMTj5GZ2dfkgSbLrrYve7Alw2gYC4Y+rfdXXI40/NkaEGEiqjdXjMjsxCzOw7TRg== 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=3MTlkhWEC9fX18quSmtS4wAXnXr4cMfsGl3GZP3+oA4=; b=lITDn6LHy+jCV9ylvqDG69Rmv64Zi+fos6FJjLd2ZQDEq6r/O7iSpOmhnMobpqrVc3Xou8b+zrjsc/m53AQ9ZoHA3NrXNQWTV3UzlaXDpg18hWSkIs0721N3PYP7DKVeXopoQVJ9t3kKHP2AT27QNYub3FpXeM8kz5tnCMqhil71egqd/+DRgvHTkDAc+Jra3XMLyayelXehCUrg+XqXQKMKChM0lEmSdOl5A1MWveHQheQAacv6Q1nm2/QP2dEQcjtgvP9uZQnGHuX8/CcgdMwW+vuXwccYvnthy1WeZJkRY+dGKPoVephsS6H2M4i+RX7BGFz0u9II9mzoZ8Pi5w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CY5PR12MB9056.namprd12.prod.outlook.com (2603:10b6:930:34::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.15; Tue, 6 Feb 2024 15:12:57 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:12:57 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 14/17] iommu/arm-smmu-v3: Add a global static BLOCKED domain Date: Tue, 6 Feb 2024 11:12:51 -0400 Message-ID: <14-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0001.namprd13.prod.outlook.com (2603:10b6:208:160::14) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY5PR12MB9056:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d2055ec-166a-4f82-ef41-08dc27261857 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6REEQfWKDJs+PTafMeXbhpX2uul7HNEPaDicsOCxLqjPgBlxtJ0rGBd5hrFAFDu2JMZARsfwVSxLehBIizcpnvC8Khq749dvVliF/F1Vj/ocCdMDTJHeVl3YkeD8ONFftIlAqhOuQ0ClD+b/xihx1mIOcdPKPezZSZSLeQlBuTephisfbaflw56BxEs+Jj8C9z5ojq+8wIf4WJn2OKQygwGX3uqH+RIOd9WpuEnUnGQ0V5mzyQqDlSutIJTQttEBFFfJwK0cn4sfW2iMfoSRw6ES40FP4bqckzXr4u4cuzzOGACUMZUoH6ZuankulAY+TX5FcaMmfydmgU7xkjx2gBAfIF8KgbIwZrK3Qi3mpNwgjnhDuCp1F7MqcHAS6XNrFyuvKOayXa4/sxKOCiURTApdQQkGUc1MVB3sdcTmGKD6WMjLJs+pSr2JcSaEZHITDkEGwF8kCpY7SYNC7cE5qj6G/JN7o+nz1xKeMc2VjGBo29GGZBtBQ6A2ipb/zP4s9SJxCAKua9Yntz36tcuyQOMoAj8BxzIjDn1epan5XA4Hx+Xl3X4C+Sj98w062OyU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(136003)(376002)(39860400002)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(316002)(110136005)(83380400001)(54906003)(66556008)(2616005)(38100700002)(6666004)(6506007)(26005)(6512007)(5660300002)(86362001)(7416002)(6486002)(478600001)(2906002)(8676002)(66946007)(4326008)(36756003)(8936002)(15650500001)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YMKzEjOTVvEh9MKgAJXwiS4f5ycPvWfFpqgVGmYyUraKsXUszmBGF9lg4hB0e3+dPOt1lhbQ80WbxqYHAw4/k1U1QiSiWoND+wazvfOdLinpOejzgtLPjNnEjoHM7L7pkACZ9ZJj+Mrk6QmTpCPwQ7B0f3z3zCXKLXYm2EJd0PReuB+B83fLnVpeP2k7DpdbsPzP0hu7c7oHDZaOZ0zI8EUXsf4YYqpi/U7ZqJJ7ef0RrHHHCR44dYUmi4JBtvxeGqdGfJ2BXNsvzLtKf7F2aPFZ5FvVEPE610PLviMBEC4oiTfr7BS9JOL7ejolv/fh9scMshpKlzjZQg/o8kRTcB1hU2ygUuJV14Lv8rnydO1gHbocBrSlIcPX8JRFOfu2hetIMPUczzrCYE2whBUjpFeYdDzBvERl5VH+KGTu8XoDJSTL7an0fsoA8D7lXoucazIDwerRkV4oNvAKSKF/D4EpVXjG6x3VcHCmrseR8SLU7uumpKf+j/Bl4xYJxwcTfxJBmRcPRLoO+Lnus2V48S8GrXYmx/D14QMZm1Uag01xfPrRw/CC4AYG72gD15Z0mko63yTgGK2xhdEAKhHIUBqRgguBx7EMynK1PmqNSPSNNTt7T5cFwEwkD/2ajZm8INUmum0poaI2SNagTXPGAKk6ibd501/A8kUmYRI7QTKFqNTXBOkTmbd1S/fK9bGd7ccUvmR9AVZYpbQ4Ck8qQy6+eQv7llnpomhgjfZTBOdnrf8RD2tnUC5zVmRzphSs9BJH9hHoz1gTTqr9lTJlcakqDxSCc6J+/G0Yr9Npx4rz2qc/FD30XBiM4eQ9dve1fv8WukmzXdEriyP9XRYFXg5/yd5fmQxgN+bY7B4gy3DdUq+alaOm1WlnFtR7BwoSurg2EcQDvuYd/UP/c2j/q8mMjZZEox043L8UYOjFvKy9vhJ2DAlY3086HT3UZpbya0WzqURfK1HVaV0L58xOkeb4nw8dLzTbttiAgCE3RKOeRePLzPbl1mMEqmqSvewK6yQ8GV5ICSKt9jAhXSXZ4YNdpxsm2LhcqqRWNJaJBS1gxEu3gTPu3AnZb62m3/nEfgifzSrQ/L7h/61xpecPCibixFqKjC02xGg12osO0BKvgDZoB+v/DYa2WU/Y/TE+5f2xTiDTXFQo/82LOILnUI4T16ACXgP3gpYaPZpgtwbqzUuWA1S7CiaDQNdN56GUv4k+ArdSfAyuAJMOtB6ZR+NyBZdMM5s5mH7yEwp/egLCXWQ/CL7SE6wZY9kpUFAFQSVIrw2EIVZxnKQkAu0YYwbIutK4StXoEQ5PnTsMXpsNUNb3QY1uQizp+Uxrs/NgOrFIF2gylW+Ey0Dg8ADo1b7fbVTtpmMIvXjKL9bbpR6MQmODnl7+7DcVcBkm2mivGLuJb5DliDgC/cRw0yFQ0TqJ+WVge0Qg1EOyYZShd0nPsJ78gyMKAm/do5bNq27ndA/UrBqbNUJJa6ksD4SuZkexCcA96M0JdbSWjl/A7CMYXMrLB5HatuyQwutUTXTke/DJQrB/H6VVdbuiH6rKeoAAKB0KwAGxjT7vrjAFTlo= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d2055ec-166a-4f82-ef41-08dc27261857 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.1734 (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: g8falV3Q6phKjcCIfiJ0aWbmZuhM2PbyHLawDXhrZs+quJmaCLrTuC1Uyh0ANOaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9056 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071311_178558_41FE59ED X-CRM114-Status: UNSURE ( 9.06 ) 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 a940b5ff96843c..9271f3a035b5b8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2727,6 +2727,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) @@ -3117,6 +3135,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 Tue Feb 6 15:12:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547503 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 F1D4BC4828D for ; Tue, 6 Feb 2024 15:14:12 +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=UqSrB4h+530fv0u8NH1F0DF7Ko/rjO9wxQucZ90RXaU=; b=pwN4emikrIiPUP DDTEM2EwavTz3tzvTPKdmvt+WKnkHclxaia3imM+5sg22lfAHLJYPeFBZjCk/szowknZ9+PpYkV/K /S7EMZk5MfM4oz7Xlcx5WLYYmkzvK1JIW4Z1u90/JbdVPGb+mpaWI/BCMNbRpv1EfRF4pEExNn8iu VdGZsmjdFMdQ6hD2806YADhmiHh98vwAALLEtvSxpBZ8ll5YGSfSWMF6TXzy1F/yNBGe6F1zRj0B6 6ht6knVOooMJyyzr+D+pQTqxd790wr7GQmUK+j3IPO1Jf1WXsA6KRoYC6m3Z1ZltpD3hYjnPW87pY R6QMwW2KUdvblMTlpAdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN96-000000081wY-2qPF; Tue, 06 Feb 2024 15:14:00 +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 1rXN8V-000000081Kg-3sbh for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ke6YKfxm6Lm6wivjVEk7pdfCgsvrdx2q6sgJRERoEIHX0tAMuYx/0HnBlgisz7wGbMIXVYxKQcobX23ENP5jnHBEViWychPOXSiad3eSxqRZ8lLyzGlkJMfLmAwdOzntRDWDSmf63NT0dLY9jTpxZTZ4qE7oppgl2RKJ+B18aoMq5xWG1qaT7Hv0UUgcdU2qx9pVXGPt8qvlIb1dpJMW6m0e2vpMkBgNIiDin72cs68/AkXMLN4N8GuL6cY0bG0O0U4Q2/8RIa159DDJPQvYUNtyPBJwnOdU4+jBVXetgsWpWrxDRkmZuw6p01ujbeARZVGJ4L3FpTuJ9w0flTQKkg== 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=sW7tNq7eII2YgxdUp8hr/WJuijsGCbYer4kJFcT6kv8=; b=L8R1q8sgNDvz4iff5Fszb09avJ+vs45agcLZYyCuUay+D0TlkX6HZyqErobZk31DD98o47zMZTyr3xcgcV1sXXnwJAgqv5JSw6DcZKVYgTGYO1guJ2vd9u5uWPSW6rY6JUaWSh3nPFeWv6ItI9jUmX9zeiqgmEf6CKyITZacNQw2k+k6sPePFenm2bmMyBjex4VSt8LB6q5Pl/9/AeEd8HummelAcWZNtCKvszmt1LEyCgdZ9i2tuCapBTZrZd9odcR8PL/TYZtjSxo2KHs4sSSoEFkPe+Eh9A4C9duOxWeRYZXUjY/mosZOMf+uFkhAz1xYni/HN/6++MIpAjlaOw== 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=sW7tNq7eII2YgxdUp8hr/WJuijsGCbYer4kJFcT6kv8=; b=Efrnc4nWdvlwoK4u1MU5Sfi4q4YLe+pKWm/+HmQ6AHHxmWBWIJmvV3Z02sRmuqwLVPBT4DIBP1zcNYsaVL5cRzqtZZOOAnxRbIC+dEHrLXA514lAj4N+M9LrI8oi9JM/3X6VEevt26ICUfNLmqXA3n5NYElAWw29ujJBQwsQlXEbAoruzxFh3/PnD5f2ZiqlGgWLa2dpP4aDMMM+Jsx54a47QvDglrm9luXuDhZQsrp8vDXQ5EKWqoL+AmNvTsbOv/Az1C2BDflsAvLuDgqZAw8qrcXKRennC4iuL1yBIRtLOECTU04Y9oL7Lql5Dv9iGUe2nwbRbAiWOOLdPv7MIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:03 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:03 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 15/17] iommu/arm-smmu-v3: Use the identity/blocked domain during release Date: Tue, 6 Feb 2024 11:12:52 -0400 Message-ID: <15-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF00016410.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 18e8a1a8-39a4-4dda-cde7-08dc272618da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I4Zr5oJZO6K5I1XRHuc8tR9YhyjQdl3EwsPx/H6ZcJrGIT5Ef160JJSw/nd9V0W5xebhKWJLITjySwUp2pGVNCdIrjrk+zE2P/xmKe49eXxwRKp0IbIHG20/SgS2tiUVyYCqYpBuZmPl824OddTfNZVsFegriEz5eExDtwHTZ7GL7IIzuwggJIcxtSMHazIjT8Uk+zb+lyQLBqAv8oEKRo28PwmB3Qb6xxML37olB2YyYSdVSqwMrKhNfs3Oxtsrz1/B3UjqZdOvCtS7K4ffJjh8vjVVggU31ihuTFu9rq0IW6D/SrSIIVAG/Xm/sN8i/X8vdoFBLSuMd1YA9WX/UsNsyD5dPKv6RCQ2chwnZ2Od/DxozADjpBal83yPX2R1H3VBCamT/WrFh/QLLNJbNDPtqDV35Ul2YbbLkxT+/PH+0n6GmIBp3ru66vzE0QgaEuSRg9fd+tZLZ2zAr99mHWhada07AH2VQO+BA0NoOxGjKMFM17CwhbhNcnsZ9IPFVKqiiTQg5FxU4Qu1NAmcJyHZVylQLWRkWPNnThLmKovMS5+GTZCDpZ3yCA+mTlKJ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(15650500001)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i0KqCXxrX5TSLTK7K1gVOsk45NevrScTbjGMI0c9hXcfmW8hkA0sBltLpX3XTkzVqTCdL9wJtUqAsJSMgppG4Oc92+HsArmyxsEkHGufM3zlI9sSEiLtEldmtoOsZPhKrO4HDeqyyWbCWX2zY/7xCx/XDLq/gJrr6z0hFxx+KHjo7ZfLXYiwrisVlWYL1xoBQbNrHVcQgSQNRsuHhSBZ9oUIg8ZQZ9RVifenRRuj3cEB9SmQM799jhnjMC/c59nlLCPXtlPn/asvEDDJZUm5k075eYKCIUr5nJ0/T20rkXNCO9/VoiHLOsZlxXb63qjDzhl7gdiit8zYs7PqtLsD4pwDyhZokd9PiE4xngEnliW678B+NRrFtZDqGiOJIjRIU0oYb4YkJD/rX97GXNtNz02i/cBaEXvjyHZ3T4CmLi8do2cvlmRVDq0iiFMCq6YK/SW8bozGi1u7om5vcxM9QqjxvDHYqpvaQjnY9uLWVuz7s7tYOwz2k1+HDOaryQDyAnjKcU+du6Aqyt//4ATlMKB77LHQS6Q5qYMqj1+zGTKUH0QnnesoSYUUZq2mW7IuiENg3GqAQg7YvULlQ8pGWM6V88kLDPOQzDy4mKWxjP9R+my2FFcGo5o/1yrLP6507g3StOgAyH+4ci74WhKvewmCwk6BSOLbp6/Y5/BT0LHGxVjL5julPz+IRtMiJdbA+2LqTV8kxX4M9pmK2Kk/+YTdmYzSaSXAkMfJNGcWyX4sXfZs7SwTh1pAXyam4d7bthQ4Y6DfcPO/BLnJGM1Iz9tHxRWpIEFElN79dwwqa8rh1530OiHlfPrdQf8GeZWdqJxsk/N+wmYc4K4grjYFUd1C50k8qzjMeuZPVqjpfy2iD6ONoJyCLpNHL0NhdqGCBvKJa5E5XM2tNDhZUiTBfBtPmbQSP/kAxn71jam2f9iR6flucxkGa+u/4HJFjlXq72gDHE5ogKfahncU7LbUB/K1Pn1XTB1MRKnVAVdxeQqggJNukeE2QBcHav5fqlZIhWDsUYm9MxNLpDzozoA8RweW2MCq8sBL3rpsQCCAj4wsrR1hwSF/w8jnDRYj1LysCUY9Hu6WhN4HMfKeYKrNL5YUog+epZhTe7Upc/OgDPaAohWw9IyGBKYfyXs/VDnotgCyDGHi9MY0FTfzCkIUBKv0hqMQTHCH3tkjPyMswHNMfO3QfUz8RNo/vQmwLznG9xTyBqFp7N9vs8c3198VUvEe+nwmd2/BYJDnulEP/J9YktAO8yMu0oud7EdxAEmqnvpSEqHo/eLKWfd/leqOH/L+O2Y4lXCgdaRnd4prpV8T6MUM/d1//qRHbyPr92x7xI/buvoY5CW2sTkygRQNg2Ne+uX06wAPDbNXCb0atF5hvnRT+z8JWS/tFHlT0OFsnmTIzVs8QNiXTz4VU3X2afbe8PnjMkqQh7yV2sCZpZ95VlnQ7J7kJJvEjn+IFBB1qF+jHbG6HptLJySu1w7VQ/9w4dOM7CXrD1IZXpq1vRKaNWNNqUvhmJ1Wq3iZwMsgVOHKqzaqRi8fqYDFwne4RwDDrNTav2DUVpDr9RBlQuQO7siRhq0qwXYqhtQGmsPO X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18e8a1a8-39a4-4dda-cde7-08dc272618da X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:55.9991 (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: dnSZ/ZZH0hWGvi9Q8bOmdnqpLbMpZVoYsrhm5Gs9fa6eOIo7r9ND25NwEmBH63Ys X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071324_335582_6F6816E2 X-CRM114-Status: UNSURE ( 9.02 ) 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 9271f3a035b5b8..27a2792a6acd76 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2977,19 +2977,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 Tue Feb 6 15:12:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547504 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 CDA78C48297 for ; Tue, 6 Feb 2024 15:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tjk777wzkFcx9I9hPRE+PnCG6zRX32WDelB6rI6RbGE=; b=aB1zABE0d7DvCx 2Yc9FESu3IE/hZd11jA++kwkna8VG8SuuGHroe+HVXFF78rDtbR2s+BJP9Wco9buWgGQGnsm2lEUC ijbRw5kLKkOUopLle2esISJbgOtNevrUSTbiXCADZRQYFq5KBNpSbzb1sZHv343QNcXOZm9Mx1ygv dlpuSNpo6Q9uUpnvRKIJNGINEBePuaX/4IjqzQKLKmKsPH8sOc4E2jt/azuHZ2u7kLeh6T/rhuccx M3XWJbRPZ0Snfh8yh55PjhoTzVUoFTakJ7drWcVXROHFp2Y5hPw8B4KM4w6s8t1IN4E2mRSJPYq46 VitHWjwSV1jVClBjeJ0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN94-000000081up-21b9; Tue, 06 Feb 2024 15:13:58 +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 1rXN8S-000000081Kg-2sXb for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V6xRjCWnZ1S+MP2z66SOBt1jqbfu4AMxpJRdkfI4kQawfnHB2h5O+DVWUsIBo+0iF1YpqxH09kbIS/EWb1LCjtrava9yXqYeV/e9gtd/Rco5+Gv+cAtUP6K7mmeBlj4PK8vLNO/twNhU/gFQyqGEAsi0ye4uzP8MuLtJ0MGtkbUVULEaDRfoKgpXCbHqz9SmamJgBMgzKHYd265y8JNdbEQZbQBC3TMn5KZ0CUun3+EzEnJ0IqKzqzG2Y0qrSoo7G/y5wwd1LSXL/kbkfyDmWbU1aqk1b0IO5rUWxC2IHWSfJFL4kp6yXoYRw3NZMMK/8X2N2wyr9jP2+TevvQBOEg== 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=8uzCZbZUIXBDLszoJSY2OR36PxPIYFQ2QBqrMyC+aQ4=; b=ajUN/5l6CDjwTis4uQ/KzHU7ymwjFkHGJxJ8biciblg1ZoErVigpcRZpBqB0n5SmcfbCtsCT6xXlzhsIhHCFKpb52CRq5Nqj1oCwSzSCIR3NHXs70TRxCwLTFK6/jJw3XhWfqkUxPOihEz5VecIXqf0g4VilMcqojgL4a0QlxXOZflyhp5U5uSVIZedo6HJ3HV8R+/LlDuiaArV5fbi7sW8XOEma49mhzs/eNm+XaTPHt/SKJsjxVdhtLWEx6K/ExuGAZ5zM37Wrok6wwqQ/NeEpWKiHhIeINLoHKCbxATDkPwQKqfRrQ0STdojLK1353ade2odAQ+eR9OO5oWUc+w== 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=8uzCZbZUIXBDLszoJSY2OR36PxPIYFQ2QBqrMyC+aQ4=; b=CuEgqV25wRtNJe0vivvw4VlLUr8Nd3Z2Td/8PIf+1WGn9XibR8g0VJEu7SSB3JaY8n13mwfbVKS0fbolw63OiOVgNnLZZOfROxh9mPFLPL6FZmAOh7j84+5TUguHjDLeEFwmx2MObMYHDDcUNQ0G0v8FcnwC4r8yQ/qeuGKJ1G9wyC532cPvte0cUHyDQBXrxXkTcnP017nzBr8kcAL2OB9J9t9aNA5J5KJ28JQXuMatWZMqXSUr5tOE0nBW7yYnwN5NVEK6Yz84NyFhE3Omim8/F398U+FjcsGIxrv0WRnT73oi4ZmkrPTCGmHCSPGo388cfL69rQbkc54vdO3mtA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:05 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:05 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 16/17] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Tue, 6 Feb 2024 11:12:53 -0400 Message-ID: <16-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0006.namprd13.prod.outlook.com (2603:10b6:208:160::19) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 02422cb2-1b74-40af-dfc4-08dc2726192b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D2vpMqCd++UJrjpTzE3PVQUEGXdtNwm4UAsmiNqdqv2CYuC25ZBkDQIcd5wCSnHd8qfWLA+8txOeTBxauOCQfcqDFakZkaEtCO8QgXhiX5h0VBH2/hk8QXfvQmb5BFYXlECxclHWwplnW2h7nRMhVZn4gQ7clVloqAXwujiYcgRazd4qT6h4XoXdr2/QQYgHMBDah6TSNc+D1YvtmwGrUDF03rfSdjDZ4etQuzTcZ8zvdPQ7cwDfqmbdMjtZF4xvYo4tEJt8QJ1tT9b6a/GzVPtsswgRqOwW9GJcW+qimZQrs+HthzuQWfkN7HvY7ExnESjsFB2z6dkNo3I+pJAyOCSFSBN9A//yfBaPFYISR3Q956U1dTvkq22WNOeb6TwCBcta8ILreHS0YVdSUnDGXJgWQHy2mok6IGVkHuosoHIegRA2NoKRAd8frM3zOVKjMvsKrB9O0P1oM+txg1EjKwYthpjPFnIzy8BEq2yocxCQz+YwpnUuBaUjYToWqPVeSIpSGC+rW/EsT4h3PJJTSVJNdDbRRHrNkZAMAt6w2jw0bFT69Q0/lZ36s2eSmhJ0 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 44igk/2x98ih+N0ruiRIs0OAIJZQ3nB5lFKxhMt4iDUE1yUYAMQCuLfiALjtHGxYfudhpLM3HR6nwQ9sFwDLkmRUWyYy4H2RYs+JHwZ3Pr7+HFcURJ3fsT+QDevo20fOGef0zIZ2WOS5gIY/oriBq1DSuSAN8Y7VtKupJM9EqlKtOmlNH22FsftikWMDdgpg4g7E7+QWS+fEMqKsxYHIde+e0+DlZ0k70fOvD/hrdFFMpdPnELQ1sXvwZafHrFHly/eZBtaYe7uDbMxIWrjq1DTEi89CZ2A1Mu5H8lQhRf1g60vFcIZ1w/n6Nq5AZ7iN3jX9obRY235/MzC8+HTlACdIBA6sGk9nQP43QiKIcfyF4vaw3EqiN6ohckkGYdZcowwp5J38P1AqnjNjxlM20oPY/UVl0CjfdeCS7U9XhRpuSOBf8KmUbYyDy4FhmnEeNDgf09E/cTKE75kouE6NeJ9samp/xegum2AkXjrZ6CDz0crZ685w3fOEE9e+etYOaAjt0GL4Nqr9/3KwkUx89PVm17cUfSY7s2ITtSWWNB7i+uoFCl/MTNHc0cNilTEI/0RyDrc9yeafJ8FS1LzkF/7/JYpGkiJJ1LMK5AAq8eHxNepCGCRf9GTAzorTdY9Tt+woSGozx9C1piwYoDfAVwWHljr+XF40wJEe7IDn5TfCTgqYY8I+mr4iDAtbxojuTVR2oCS9bKgNX4arL/UGp0KTe6EtKIK4j+71OoiIXtysEp/kGjXkW2SqHru4m9vJOIpV1gVkFRvf8F019YU/lZ3UYNwIzrvbQJErUtXCCjgB9yHOAuorBXsztQjtU1IDlSYt7u3oUXgwTQLjrmCba8KiWZDE3ijsZpPaI6+zNL8FEgC82t1XNvqRMtMgiaUiQH2qeFU1lWtGOEJuDqR1EyK6O0tIreffblPk3nifC3RAE+SEoz9YjUQCaI7tCvGOS5VBFw9PKzZ8WjElFP4n35b4c1rWGN9A6wh9IblowokrlgOQ7gFpmqfSPJIv7NT9rYav7QOU5tMlKDGL/iMt4vuIX3y9hRHLgxYfCVN41X4i7mmlge8OooEGY3bGQBEV2PDWXxGTDmfvvbDVcWS79OD9vADItdSyyIGuUn6+qQObIO1ao9o25aXwPTT14GaQI65MQDbz698g1l10BrB9SQyUKdVUDFgaAtrMKfUvi2JlswvLZd6l8JXG2gaWp+uxWUMpjlFohkXKcT4HbqAO8DqPJlbC1MQFMWeTblAdgWbTqp/TCyitAKeJVugN7KhpN7VcOpQdmyjFwWonhLi0Bq+LlMjIV3qyNB3f7eA5xYScGmb6HLJDZfS+K43dk+6iYMMhQqbEIuY6T7gUcymdkhVhepHo2LkEmHpB+kZgVwMoI/oo3immmo6uiO7fo3doJPAcsWKAjwdiAIYZ8AeMCWiGuvhab6eBThpuYfMxpSaJlkM6CB9LNhZm3hYTp02FoiabgrzqR8WRm7k61fsvlkCVtrVKfsfvpxc/OQ/bajKTRmLLoU0WVtc6H1CcraAUN0WAT7nJ1Ffiw7o9s6CTejZ920he7K3SVnm0XXYHCtTat1gtEH5YndftWGoNK2RJ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02422cb2-1b74-40af-dfc4-08dc2726192b X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:56.5130 (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: bTNk6GB6E37WHfqVz98+vZiYdzJpyW/SKnzlqLDO+uvsrVIERW7wVZ5KXIHDqrup X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071320_914481_A7EA19E0 X-CRM114-Status: GOOD ( 15.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 27a2792a6acd76..7116874c332ffd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -102,6 +102,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { }; static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu); +static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_device *smmu); static void parse_driver_options(struct arm_smmu_device *smmu) { @@ -2295,12 +2297,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; @@ -2332,11 +2334,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 */ @@ -2349,17 +2351,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)) @@ -2398,17 +2400,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; } @@ -2600,10 +2603,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 Tue Feb 6 15:12:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547573 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 F269CC4828D for ; Tue, 6 Feb 2024 16:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6j+X/tFrRuwwWm2HjGdSiroIfixJ4XRUJvNbnbvkkIg=; b=oJ9oVYULoMkcv3 F9c2ssviCCJ+lkzAoJpUos0CQZZTSM5TlZkrJRlatX5RkArkR3YJWuGBDY2YXYr5O1Ew+hD+fZ8yS WgmSz643p5XD0AIbF1h3LeTrmOxuZ6C6etpYiKcyYyfcfrxJOhtOCMg/QXtdGpzS5e9L1I572snTs GIC2qT6qVpg7T98Lm0w+zf+8YIq5Hob4WW9bpj5olKo19etNjrvvCMpvhW748OdWl9qAZIo9NcXuY L2iqaIRqJpt0kYJy1XxQmiqgl1dg0VENL+cv+B7oRwxHSCQ4dOooMmvA/dN2QRtFZ8V3HJn7nQ4yn rzBrzVpVlkNx8aYTw16w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXO71-00000008E2q-3AIW; Tue, 06 Feb 2024 16:15:55 +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 1rXN8d-000000081Kg-0NBx for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R+1NOuVIKVJA33Bh/BFuFbrKK+mC0/VNuAL+FszmwcF/9OzZvF3rfDjtejAuBBkFAwnIUwEPn/GbkrMyGmN+EWXlxlBAI8eGHVoYp0qYH0q+qPgUZKNgEVgRz4Fn0a8N0XJh1L4eYYiRlRkpHKuPtyjr/VtjU2/JeCkDOsg+QjyO2+EXA/Z4EaNe+p9AVrReAoQkg3NKJMnONCO/9rUrwt+egwoOJN+phUaL+BeF+CzmjSUZDaGmU78VX6gSe87U5Z9LyJexEfQ57I8rGcReif/ac1pOyx21+rYHtrOWV8fsUp0O+KMHC8pKzh4kLVJ2x0W1GmMOaNr7Mpgp7ydCMQ== 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=qoyh75BViievlqyr0zoccpkZVfxb9X8pkM3NWQ8Ut+w=; b=T1lAN7Kfk+LJYmqLQFfLyIyogLkRwkppYLrDki5FtJugd2j1To7dy5OeBe0Y3yCKCCxcAQ1XCYpyxrWANX9GUsKfSbX3uCFtJchZ5ITCwkDbgHtScoYCwRmvXOP3/1BCatgpikYfK5u0Eodmp1epV0G29njtLWlTQg5n8yx90wMRO62N7kWigcE4Af6tqZocgHoDSKG5PLUBs5ud9PWqXnipuY8u5dh6TfotOahXM0SjjCfdc/qHl5c+NwSEWDHc3O2zA0P3rqtEucdtocs3Ig0Heh+/9aavdX61k8m/1gH0TyE5pVtFyQNxO9bSUMLxTjF/Myqv0RuUs9X+0v2sHw== 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=qoyh75BViievlqyr0zoccpkZVfxb9X8pkM3NWQ8Ut+w=; b=IB4AhPXSL9Bw1purrVRxwsEKJr5ZP9RkjKypkwhIGq+v+01J+fpDBsvjtElQtBubLIS0cQ+gafMFvAZGGU8D9AXMtArniWxHQlRyow4auOVh5sReWN5bzd2tHcQPEcMexvjWaewGoX5AJopUO7McFB4PQPsyNDob5zNJPBL34yBgFS3k4PQfO4usE/X/9VORHUHvq+CBdMNRPuu3V6QdsETuBGME5StNdsHCLZHhGvPdz3XB0GXNwGOs+BYL0eWwYqCNvqP5zyBH11eOCcWMUQEAEmD/D//uaMy9ZynvEW9tV25lMa/NAcJmBci/v5i8mY21/KWhZuTG5mdu8wNMKQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:07 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7270.012; Tue, 6 Feb 2024 15:13:07 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 17/17] iommu/arm-smmu-v3: Convert to domain_alloc_paging() Date: Tue, 6 Feb 2024 11:12:54 -0400 Message-ID: <17-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF00016411.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1004:0:9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 371f71d5-40e3-4277-ee84-08dc272619e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bmkeY2adzF4SVKZ09q9+YCiKZIvpddFTBdBKZP04T42iUT4ooYnkbrtfzepS/s0mGykbwkmjHwTBvWQFQTlH2wRmrq20eCGWPhGR2WhRCxx4e7x+SsMMtzKxqnNK6AoNnYQbYOhdYt635KI55Z9VsBeR1R9Ixg5VzIoeWCB846p9y1bvehy2UsroICaCLbAEjcLdoCBKIMD33fchLG5tg+ToR5ziokg6okiAn8BApYChYT/aD2ZphWhjGbgocIIAoEhL9fy1h+KvysUDLZoArjW1Pj2S48xF3Jh2reb8tdjQ+93ZYqpmBpovgKDasSI90mdRryO/JI2qq9GciQ4Vx3RbYv+3MZdwNmlxclYr1znqUN3gSQaUAywT6WWqF3ER4M+6bYsfYh5oxdtcK6gXXYlrFaLaLI34IQLt8Tx1HmLU+89VZ47MGBafp0HWtd7eWsIvk7AZrzz7joyj+LhVtWOBFcwQ+4OfmRFjSSSXbE08xtqqQWmDApIuzRsowd68byKAmn7NagdVwDFWf/OhuEC/jnvoIyP2Xj9FJ0UtnIZFBoUDo6q/jDF9kDTrfGTb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HHkRzIJcdmVUHCvSt9hil2wRpqApkzM2upTKY6wAtM3xA52fJM8KUBmuutS7RdhtdOO1HXcvsfolqR4MUdINurchTU3gDt9CkJgUa1Zj+eU09ZNtB1zm+n3pCGAmIHia8Wt5LXDxTEobGvY4oeb5kK8vpO8j6MyZf6CI1XdUG8MS7eZxSbG1f2qXS6ZZqTMIh9L+zswwmpIpx02S5PF4rjrUcQyYLLraD/dGAps7kghbq2eLPQ1u00XQXoiwCwN6F0HNqZ1pWhhgd/zDX8wpuUD+Md7HgeFYz/zVXH01h5DD/zX6qTdFbXM1cVSaAo7UCK+96q8N2AHAs43EvPaYaxUhZfBSe5bChmktFPAvkQCEJHPCdRmOyo1Z81WlgIxuQAQtEBi+v8fW8odqYFUhvOutanNb2ZQtDkVt9e/71NPpYQekMsaQoNl+N/7UV7hKgJ6b1U83quP9a3cMvvCRbn1t98cRYFzD39/uD9JJ8QTTzoOZ27azNMjePBK9eHNxWwxk+8xyYWFr3yIRtQov8NyQ6MsebnByhxlG58EaQtNChtDm5XUJqqnPCgptEXL0EUR7IxNPQoqWG40VjnVZMGj1UiLZuDN0DrbzO6mRsNSysvtGETPIhfYLjnerE2JE+rh8IoOmtg+Tup1OWLK4BpLpRy0+H+9nfcd8IM9aZy+1t1kcmKPEDqROQhBghiy/wcvIOKauAxcG9vErBvsHBtI2k+CisjVS77CeuwkMV0A64GZ7xxCFo6e9KdYPXVvbHzqaTHxK94pgVzu+ZvCbPBoKT/pVwzvMcJjBpCsWzQmS16lR95eMK8OgRqPAi1By87eA9K/DNxmx2puJuY13ScBRlhbnBy4Y6K8fx2wI6d8e3Bmwe5sWe2TdFOKVXe9kTiiwDhCTkSJVPxW7J/kaNVBMeBVj7xbWA3eCEErp9EQ/3HzxwgeIJoTwVXrNeMddh6kKCFwkkKiJV6TzNfr39FbGK2c9ic7KqU7x0LrVr4TerBFBOuImNJI7leOu6QqLfUu8MyTmydDVy7t/2QqTEnpsttXdwLM+BUgbK5XCEQ6edmP4la8GgB+2SxZOr4dHj8RzyzdhjoNSvJ0gBCle3vpLhTiopo5m1p5OVH479q+9LD5zh8PfK2XMyP/BOqkfDGdm++UiP7kITdOqO8AojrVVx5uCVXOPmIG8wMvOyqa4QAE6/70hDx0TubIncdYHhr/bObXDXAWCinsvuBknOoemNqrrSGU8qeqkCq7KBk1vyJUafYj8mV97xa5sIaZEVpHNVJsNLXs/vC1i6FdwHArUzkUaGIGKDB9cDFlilmzedyzCFvw6qpd8VxgH5GzwRwZrzpXZ67uZoNVYkHyZtV3iCe+Om/85OPTezi1XfqZvTQXtLtE8o0bAKHxesJMQgP8gB6e+K5fjBxG38eIDQF06Uh5l4icFKZu0HifzAwE8zis1pLbgN9n7ijPWx//JzEwHXx1Uugfi5CKpYddyRfIj/jQFct2UVe8rEV5tVDy4+I/AyvzYKWkBIxSXdmeYt1dbHo3UPvLJXiVZXrE9AUDl+tbv6HCJao0QvKW57Hxc0fMWIwPrnEIZ+re5QXsC X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 371f71d5-40e3-4277-ee84-08dc272619e0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:57.7343 (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: 6Q+icFWjD/f3WEQozOcrmbg5GD282iBP+J19kLH730AT2Izi7gJQhfT0oX3oRt1s X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071331_645286_0AC2ECD5 X-CRM114-Status: GOOD ( 13.25 ) 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 7116874c332ffd..ab2f5ac4020d71 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2249,14 +2249,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. @@ -2265,13 +2266,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; } @@ -3135,6 +3146,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,