From patchwork Thu Oct 31 00:20: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: 13857367 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 F3C0AE68941 for ; Thu, 31 Oct 2024 00:45: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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:In-Reply-To:References:List-Owner; bh=ApablPWdZRedlpNbUkrkPL4rex9wYFi3vjncKGpG+IA=; b=UjzXFHFO4GzqcEx/KVofkG5sTY SIpb0Y4jxVkWb/LAP5pHuQJjOuT75YIqqC7oy5ejAkbLgMyIPRgMJCsGh15WA+AzTkYCCxFNR7upW E/9jrVadEtiNe/PlxL0LdyuItZ3Pl5nXq+PJWjHKQMyXqM0SiRWKsGDGSSZF10RRIyiDezS40UZkX B3zB1MCqCwDHcgVe1ytzpdziS974ewG1Jk33pm/jAdcuaHhuy5etvPf6Fos5uR1nHoDjPIqn4F6Lw YE6/40sEqj46jECoBFntgPZu7kwpyQnT67VRN6LaLxUdnGPXW3eEXD+0OeE0rP5kZdHiDjRy0mHP7 7uUbWkJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6JIz-00000002Azy-0GDy; Thu, 31 Oct 2024 00:44:53 +0000 Received: from mail-dm3nam02on2060b.outbound.protection.outlook.com ([2a01:111:f403:2405::60b] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6IwC-000000028U2-0mgn for linux-arm-kernel@lists.infradead.org; Thu, 31 Oct 2024 00:21:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u8xt6hXIl2VQlpJSXPWYPKXRYOY1cs/RNFaLVezylBamCl5V7rZ1j9ND9rknDfpd8vP48JyFnCghuK4Mv5zabcWwTwq+9SuiSTT8orJvJ3p464l6C4HoVCvtBXGypg9N+9FCx4AkKtOpbjxOGfqB6LIdorkfQMODlhi/Z1A5SjYnAY6nxvihRRBAItAK4XMZ296wfPQskeJm1lUiqcs9pYNJLR7mWwEjcJePdtDirXQBNdJstOBdF3OqrzKP2fBPWA4wEwHlIqidMx7zwH8yrESQjcTAAk9BUmC2b8TatTKI9dcnL7TqWDTddxGjvBYlEh07m0Jjbq/4kkperyryBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ApablPWdZRedlpNbUkrkPL4rex9wYFi3vjncKGpG+IA=; b=BaCwYCDoMdoU4VeK5kKEPYp26RRTR174AwdFZPS0SuqOsXq5ENVxTUzWZHYVxuBY0iPtqnb/PJTqcf3OCLUwH5ElnOLCEfd/4LPjcdXN/JpqJk9uXcyZaIQWwBTa03CJdg5Z1f249if1WpXgyaouGSB2l+9ZdBhzqDWDopbkTbbvuTuoMmElPEKwaY7U79P5QFztcNv2mrKE2EbpKSoPta9OVAqOdhJPEud10FfobgQcPuaLUd8vVyy/Xp6cqBB6Zp9FEveSEwhAwDJq05HEfVW5OQriYJppOkRkaJQkuIjs6YzTRyS6OYBnSRNFQIs7ep9QiHwaYQGfJ/65Al7NDQ== 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=ApablPWdZRedlpNbUkrkPL4rex9wYFi3vjncKGpG+IA=; b=sWDqy9nCMhkZRlGVI99ykwxJE+QXlaOokw8yIGaben83rhn6HVOpRpqFQVTIeKw3fDvpPPyWlV5yTk9WcDRzDAaWi381ZUICQqobfbXfzpmS9hkNvo6HqFM0IOW+hrX4kiRfuO55QhBZdnf+Jf5rMaNEChK3KS6F6vwh3jFBtW/F32NKNuDlXxQ7nt8TPEtRWOLYm2wPn1mnca4/buLiWFHql8oflQ1M1NMpPiCSHA6esGeC5HUsMrEN/fKHTke4UHzDdXyqnoVWL3Em+9PMSD2voPl4a4DFCBGGzJTq7SDZ+R5tK7D1NTEabTfG4SeuKnuPfdJacdN1G6ro+30ZLQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) by DM4PR12MB7573.namprd12.prod.outlook.com (2603:10b6:8:10f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Thu, 31 Oct 2024 00:21:01 +0000 Received: from CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732]) by CH3PR12MB8659.namprd12.prod.outlook.com ([fe80::6eb6:7d37:7b4b:1732%4]) with mapi id 15.20.8093.018; Thu, 31 Oct 2024 00:21:01 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, iommu@lists.linux.dev, Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, Len Brown , linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , "Rafael J. Wysocki" , Robert Moore , Robin Murphy , Sudeep Holla , Will Deacon Cc: Alex Williamson , Donald Dutile , Eric Auger , Hanjun Guo , Jean-Philippe Brucker , Jerry Snitselaar , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, "Rafael J. Wysocki" , Shameerali Kolothum Thodi , Mostafa Saleh Subject: [PATCH v4 00/12] Initial support for SMMUv3 nested translation Date: Wed, 30 Oct 2024 21:20:44 -0300 Message-ID: <0-v4-9e99b76f3518+3a8-smmuv3_nesting_jgg@nvidia.com> X-ClientProxiedBy: BL0PR02CA0069.namprd02.prod.outlook.com (2603:10b6:207:3d::46) To CH3PR12MB8659.namprd12.prod.outlook.com (2603:10b6:610:17c::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB8659:EE_|DM4PR12MB7573:EE_ X-MS-Office365-Filtering-Correlation-Id: 588937fa-3544-424c-024d-08dcf941e49c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024|921020; X-Microsoft-Antispam-Message-Info: nHilo8lClFrHwtyuuCx/cAd9JaxF0e2o4teiB5G9X8brS9JSFnowL21IV9F2Evvq+xEUgbesxtybqKsNoSJl5VBJVnSaBLVT3Bal/s7TU1hddMcMTA1gEjHiDbNwhrQqoSrAETuyNukt5DPgCd/bHczLESV7ziDptEjtTyOa/AjAJYjKT/EmyoplGDkzsCfBPGcoCMawq2WSXj7LD6YlliFtqSI/fjp2W+01B4Pl0h82NRwemI3liTON2VTuM1PXG1J8V/49z40PQIX7omZqJJWOEEX3I+MPaH1ZfLthRpBnR04RXZh+CU70eSlnB7vj7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am-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB8659.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JkGYOOOD08SQGErbeK4VNEKnXj89+XtSY4DhwSMze7C/jnjhrzmuCsA1gIxFA5yKZ2OD8oSibiaBBpUtebOxf6EcDo1C50houPeyiRZM8lw8o1SEW7S/ZjMv09AOCjCBOtjIvW4mwkWfnvbAyIigSHT7y42kwvFnGE7lksW1IB/Sth7nZS7j9WIRIF/4aIi+XUXLRfQOKNuy165FMKZfwKf5SjOLVCjpnpmRJDxwWPREK7Lnp16/LbkkB52bn0gdcuv8tCv12ClNs8M+RFZDyMTL52nXnMjpRMIK1YMKZ952wMGMhHsjNSFEj0R+KKfCeHqj61CxV+Gd9/OUqMnkwi21K83qS6FQky4smPkIholYDFn2UbZvsvu+ksLE2wLw5EwXAeEBSgQgA9nybigNtk5VcisxmYpipgizuAOvwAjpy8wBVTQpzNaVlzCOvJtva7GqcimegFSYxldbET5GI0Wg3AZTFrfiOG6DmFgCXd9tLgrZi3NgIol+tCjb0aO4G/UdHqITO2hRczG9qGQ+mXKarpanNCz3W9xuxsIcc/T1jXcY+kRn8NRyuWZgAA69UYXRWSV1sHtbdRCvviWPCti76QUOjYLTQc6V+ELytB1SXr6V9YDo7ivpYPAshN6Mo78FiB4i78nGQCBh5/7GwiPVvglaCbNYJAj0q2I1C0wgE56kvaoVoeqb/5PhCMS2lrZ6wQWA7PbVSQ0/VPeXrR6IDPgUNsLWK5GbOnECzbWoeB4LPBPmTlyj5GvCP9QR9vrQCrSDw4NKilAv0XbgVh9KpPFqgCs3Bg5mh66SZ4OZsDIHUZEUvDmgtDQbGta1RTvm4gK5OdmSEsFngWEPkLH1qJZE1y5fpLkZg3/3WbIOycAtyMkvgLo7CHBSyOcbbeWU6Ju2uRo/5Xjhzu120Jhz6WHWD/sukpq4fqCczPk+rAlzDpko/9jgU+NyspjN/rfsCoOlGUFtkFcgFq3rcGj1xpTc9+SpsNQRwcUM0ikSd7TXw5F2caZTFf2jPVrsptyS1jzEw8Fd7PbWQ/y5rjr1JQMxM0NW0ShWYo64vPeTHWaUYBd6Sx/iLf6B4cYWhkm4Xbte3JEvbyAJmgP2jJ2o9l0Jw4twCWLLigl5piFp00dNkpCo4XsEzwVxnpD0NMxkr3pn59LAiW1XcrbjtQvdvmzeq//p+fVdQAqXj4ZXZraCqtC2ZHCtcLzSv0oV+YHQvaKw2VK/N7qoyJd7Bq6YeDD0ylFL5s3qv0eNKPBwtgxKCg1fXsdRq/S9iNmm1ZfD2akvDOSuSV3nEXtnMc1Q1fjuhCbmmbopUZefmUclHIg601shO6EP00UxM9ezyJkVK1H3xkcaseG/YaAXvea9XwnsIF93hicQsOTT9dZZpptBmYUarPz1MJFhkrHkrPnUre/OWO+N45ajIsElerylYgYJm0AlMCGccepIIv6rNB42HYhKTc1KMz17H+280CfwUqUOvj5V6dRzX8k8QxoHlxzfJVQqQ3PZ4VDEg3xFfUD+BIEdf7x98IJy5AMbUdWFJRUR6bUA21sTEBOAL/TcpZQ5CkgrX7O3krG4jaA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 588937fa-3544-424c-024d-08dcf941e49c X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB8659.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 00:20:58.4586 (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: GtVWlhbDf9K+nv9ZAHozbKvB85jhrGf7wdfSOMEX/PJj3rwSNH2UJWwI/scDM0OF X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7573 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241030_172120_279095_787350AC X-CRM114-Status: GOOD ( 23.60 ) 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 now based on Nicolin's iommufd patches for vIOMMU and will need to go through the iommufd tree, please ack] This brings support for the IOMMFD ioctls: - IOMMU_GET_HW_INFO - IOMMU_HWPT_ALLOC_NEST_PARENT - IOMMU_VIOMMU_ALLOC - IOMMU_DOMAIN_NESTED - IOMMU_HWPT_INVALIDATE - ops->enforce_cache_coherency() This is quite straightforward as the nested STE can just be built in the special NESTED domain op and fed through the generic update machinery. The design allows the user provided STE fragment to control several aspects of the translation, including putting the STE into a "virtual bypass" or a aborting state. This duplicates functionality available by other means, but it allows trivially preserving the VMID in the STE as we eventually move towards the vIOMMU owning the VMID. Nesting support requires the system to either support S2FWB or the stronger CANWBS ACPI flag. This is to ensure the VM cannot bypass the cache and view incoherent data, currently VFIO lacks any cache flushing that would make this safe. Yan has a series to add some of the needed infrastructure for VFIO cache flushing here: https://lore.kernel.org/linux-iommu/20240507061802.20184-1-yan.y.zhao@intel.com/ Which may someday allow relaxing this further. The VIOMMU object provides the framework to allow the invalidation path to translate the vSID to a pSID and then issue the correct physical invalidation. This is all done in the kernel as pSID has to limited. Future patches will extend VIOMMU to handle specific HW features like vMPAM and NVIDIA's vCMDQ. Remove VFIO_TYPE1_NESTING_IOMMU since it was never used and superseded by this. This is the first series in what will be several to complete nesting support. At least: - IOMMU_RESV_SW_MSI related fixups https://lore.kernel.org/linux-iommu/cover.1722644866.git.nicolinc@nvidia.com/ - vCMDQ hypervisor support for direct invalidation queue assignment https://lore.kernel.org/linux-iommu/cover.1712978212.git.nicolinc@nvidia.com/ - KVM pinned VMID using vIOMMU for vBTM https://lore.kernel.org/linux-iommu/20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com/ - Cross instance S2 sharing - Virtual Machine Structure using vIOMMU (for vMPAM?) - Fault forwarding support through IOMMUFD's fault fd for vSVA The vIOMMU series is essential to allow the invalidations to be processed for the CD as well. It is enough to allow qemu work to progress. This is on github: https://github.com/jgunthorpe/linux/commits/smmuv3_nesting v4: - Rebase on Nicolin's patches - Add user_pasid_table=1 to support fault reporting on NESTED domains - Reorder STRTAB constants - Fix whitespace - Roll in the patches Nicolin had and merge together into a logical order Includes vIOMMU, ATS and invalidation patches v3: https://patch.msgid.link/r/0-v3-e2e16cd7467f+2a6a1-smmuv3_nesting_jgg@nvidia.com - Rebase on v6.12-rc2 - Revise commit messages - Consolidate CANWB checks into arm_smmu_master_canwbs() - Add CONFIG_ARM_SMMU_V3_IOMMUFD to compile out iommufd only features like nesting - Shift code into arm-smmu-v3-iommufd.c - Add missed IS_ERR check - Add S2FWB to arm_smmu_get_ste_used() - Fixup quirks checks - Drop ARM_SMMU_FEAT_COHERENCY checks for S2FWB - Limit S2FWB to S2 Nesting Parent domains "just in case" v2: https://patch.msgid.link/r/0-v2-621370057090+91fec-smmuv3_nesting_jgg@nvidia.com - Revise commit messages - Guard S2FWB support with ARM_SMMU_FEAT_COHERENCY, since it doesn't make sense to use S2FWB to enforce coherency on inherently non-coherent hardware. - Add missing IO_PGTABLE_QUIRK_ARM_S2FWB validation - Include formal ACPIA commit for IORT built using generate/linux/gen-patch.sh - Use FEAT_NESTING to block creating a NESTING_PARENT - Use an abort STE instead of non-valid if the user requests a non-valid vSTE - Consistently use 'nest_parent' for naming variables - Use the right domain for arm_smmu_remove_master_domain() when it removes the master - Join bitfields together - Drop arm_smmu_cache_invalidate_user patch, invalidation will exclusively go via viommu v1: https://patch.msgid.link/r/0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com Jason Gunthorpe (7): vfio: Remove VFIO_TYPE1_NESTING_IOMMU iommu/arm-smmu-v3: Report IOMMU_CAP_ENFORCE_CACHE_COHERENCY for CANWBS iommu/arm-smmu-v3: Implement IOMMU_HWPT_ALLOC_NEST_PARENT iommu/arm-smmu-v3: Expose the arm_smmu_attach interface iommu/arm-smmu-v3: Support IOMMU_DOMAIN_NESTED iommu/arm-smmu-v3: Use S2FWB for NESTED domains iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED Nicolin Chen (5): ACPICA: IORT: Update for revision E.f ACPI/IORT: Support CANWBS memory access flag iommu/arm-smmu-v3: Support IOMMU_GET_HW_INFO via struct arm_smmu_hw_info iommu/arm-smmu-v3: Support IOMMU_VIOMMU_ALLOC iommu/arm-smmu-v3: Support IOMMU_HWPT_INVALIDATE using a VIOMMU object drivers/acpi/arm64/iort.c | 13 + drivers/iommu/Kconfig | 9 + drivers/iommu/arm/arm-smmu-v3/Makefile | 1 + .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 393 ++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 139 +++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 92 +++- drivers/iommu/arm/arm-smmu/arm-smmu.c | 16 - drivers/iommu/io-pgtable-arm.c | 27 +- drivers/iommu/iommu.c | 10 - drivers/iommu/iommufd/vfio_compat.c | 7 +- drivers/vfio/vfio_iommu_type1.c | 12 +- include/acpi/actbl2.h | 3 +- include/linux/io-pgtable.h | 2 + include/linux/iommu.h | 5 +- include/uapi/linux/iommufd.h | 83 ++++ include/uapi/linux/vfio.h | 2 +- 16 files changed, 712 insertions(+), 102 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c base-commit: 9ffbeb478d44c57b9b2e263750b1056e5faebc9b Tested-by: Nicolin Chen