From patchwork Tue Aug 6 23:41:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755513 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 53C2FC52D6F for ; Tue, 6 Aug 2024 23:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=o1sSWK9laM2BGthFnUvws9LO/P1JFlpBeLAmt4Rlb+A=; b=0d5f38vdSemhBAN009DtEc3m/+ 9mHqkTT4ZHLbMrhRmGcm6L5R2CBBeL/DNMuKQwr+feypZbT5ibvcd45fT3WaItyZwrDFQnk04Nwj/ X2cZEcHrz2GMEV0ZHFq8jTz3H82KzAHMKD4Is5x9J+1xiaiM/4f2WErEXAH/6qSqbG/iF3DvrgjgE hZ1RWDQ64LlPCHeZagPo+DAe66t+l7tAY5QPSfVEhnXvv4UVqlbwnUe0mGYo7Nfw+NdwRZXJni9DX IN5diyP6fvW2E59AmNAYrozhDcCrTH6gCigBjKadm7850QeNJM4CHrUbEUSWvSiBg9tU+uwC6Vkio YD3zGEJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTsb-00000003Mgi-01jy; Tue, 06 Aug 2024 23:46:13 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbToB-00000003Li5-2pcJ for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hgUkJrUF70bn+lJdMggGWavxbpLJoA1JTGFHVAeCau1nKihHCDOhG96Cb+k6ieiAJiLmkeYCsYDDy5M4QZV5VKc4scV8vKuKN5D19txGpzDXTS1sPctz/yX6r3GUMRe8KaPl7G8KT0xj7vYlzy+tnLkh4i4GZR3eEq2oy0uN3CbTgcnB6V1ODmSgJ1CawAHg+Yl/8nfHCLdukGyt2Xeqqyf1Yfm/PSGHQDK4qCL9vIYX3lIcDGB3Fwt09ztKad3tSQNi/BvmH/KEwXLFuNpAYCdkc7ydApPjFeKIsVna7D2GbRaURy8YYkuFtV5JHYhEeqLJSuv4VQy5iXU/FYxmyQ== 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=o1sSWK9laM2BGthFnUvws9LO/P1JFlpBeLAmt4Rlb+A=; b=NggNVZ/7uXP+Y3oas7VN9NEqwOngUeLRGPu/kOVZJzrm+m3H4pP2GuMJWIK9sM6WBGzE8+xfJDhEjKUZ+mtqiJ3093stmFUFPCb7ogmaz9KFpHfcffjGDNh0KDc1g1DlsGdGfcKn8wxXS5uh95xyRAZoHNzUPR/ODJ9JRRLGjbbwmJ6FsvIl7sdXkA5LA5vp+8KOBXrE22oryyodQLFYHjvmatdho2jQ2ZeIEBibx3W0Qqyk3Bb/LhOsxCJl4XtTeSGVcsrsus9yBV5d52yiOuUhyJc++NTltGhgTuhx07TYekb0BeqZUEGH66oY4pP1Qz7KGMW9/EsH8xbmYTtX3g== 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=o1sSWK9laM2BGthFnUvws9LO/P1JFlpBeLAmt4Rlb+A=; b=K8MbFPtge43buJWN2hjLb4pZce9ny1/z1wCKbQdz5JNqse9QgJkK5VNf7zXLqOA36UUesful1fggfFWiVOORpS9q076r+bZZ4X4pNdeAnyie52BVpC6pB8QRYnFRDT3UHV9rqcE4o/bq3zVN++iMaO+kXZAscVFqRbsxoy2sya42PxUrY/f9d5gpTt4lsTJkfQV+BPdqBSQ2HeZvBY17Q0vDUjECcKChJN0qCxJcDigjuwgEqFOjvao6BBp6Fx4pK/z4ovmJyuAy2EbI8b0JaRIdcUY5pfmMrKuyC6L+98DaFd7icP5KjBoItO3nCVB8OHHlglDtD/TJcuj9wLwh7g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:27 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:27 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 1/8] vfio: Remove VFIO_TYPE1_NESTING_IOMMU Date: Tue, 6 Aug 2024 20:41:14 -0300 Message-ID: <1-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN0PR03CA0049.namprd03.prod.outlook.com (2603:10b6:408:e7::24) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: 04c50e03-7cf1-41eb-7a3f-08dcb6714948 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: kayzKn46Nl4Mpw6D5EVliY1rR/rKNTU/GcHyDSdGqnUeSVkpLQbFky1cETvwliGCOxo3wqkngYnJSX5PSrK6m/ePJGrTjTVj5g8lz98Qlt9slvv4LEPcnOrgDY0h3Gv9HQPqJa9szPLloXOC5PuHtn8f3Ms6EGBhLKVPXaQOuK7Z1XANogWzrZpuYfW+ucLvB/cDcBrxxdvCuW4dH3zf0xzC9fwlv5lFRnFalhSR7Zp7B4OCsFNx6nripfZnUGb6rIxKg+yZ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fJv/hmow8lbe5KbakxXqDSXGVFo6+M3YurHiu9zY4+623xc/N96AlddJOm0gHvd07kuRLsQvi2iIWP/wjw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NNDr48GkL09AXJ5DCp4f5FJ+mZ+hBdDO3cT7tZDWKjw+Oqr+kHSEfpjkbHJ22ewBqfFB5xBVYtTLyP2SQPlvNbnK/0e1JzLAd9bhErkQtidheOHd1PtPe2dQkC19CQM4JligdaI6NZGDveSYqGrZMzSYf2BGk7u6rZ8oPZn084Oz/ZyIyjQLr3X2ttSfEhzXgdy9H/spMeCttuMU3jIAl41ZdJHYlJJe2vFRHt2pxQ3aH6cEWiwZV7gzQ2DnVvirHotpwTUheRCctMJ37VSPWzwFi4y2uI4G0r/mz45YAHTJN21A++pgMsKEd/mdk4gtXKMugv6HDoazzfwEi6Pxu02kSi08yshnitlE+sov9Jy4Ia4rjLm3lwTTIgbdWGv/4KBVOJ9OTRTbDE+qcKHzSd37gJXJizfmJVzuNXu/Yebmw2HE78WB40Gf1+InDYGfyuIwplhdN0AglgDXdokyE8RFd/gAeUYoEkKDF7rjcbQbkV4lsNQB9XAcwCJzMkjg86EUdjgw50mXxCk/OTwKeXTLjHwdFqGNf/37D9tokI8SXVnhtA40ruR48AKya3lGh7BSbD1XcIJRAtY0zeMVrVv1FO8p9JYG5/KRpvDcHhSsutsshPFlBW+FGn0wcgfIO6LwOmKwpCjxJaXBWM9V0T/tKL7Yumba7dnE0napCVXVwbKq4jwwrbaTDj3yYOC252eGn5FvikXpJqJ6xmd7RrSw8oRnorQbptrqdTk7Jyix3UhBe3X6Ss8vhgiUbHHg5UQaGOzPZ4JWiKrqp6qNfsRlPl7baAUHdG7DPgVitz8ViaSiBGFI0XGuHpV/gSjFPC+OSTzqL2/fiOc2SXc+5PsVuv1CJOl/n3180A7Cvf90MC2So5Ttzywd/kQ+35w/5pniWGB6jHMlbmw3/oHGCKnph/99rV3AWEl4aK6eun7uPvDZBXrH4j28eMX+/wjaSIgz/BbQIXa99uJct3vZ3HbBIqVd0lTuAMQmLgO8aeiMnoPjV8V55h5LiEAKl+0KH7/5/KGNXSdscwX5fbEe6Tt5vY4LaFUxIy2ywezKmlmusD93lCZDI9wXJFI2LCeRPlcjnPa7KJG5LQnbB2DBrK1kczLchzo/Hj5Yg/JFMHg8DFtTRMoA9OwNyKIA/ov3RG82pYqk8VJW0iRNxeo4M0GoWMdYNasfuLLm4Qh3ZzIAu0SqpC3YVbEU8310Nac57yXdX5VIu20wl0HhCZRHlGucfm3x/HSVFQjklU7bg7jHKmZTpDfcWrM16W0r4ygGMLpuhBdbkKzWBEE3oMFcLl2/hBPxvGt7aPi+mGWoJX2G6LXdPbzoyFgDOq0kERLKYrIyic3SXK3u8pKHJk1RAqXhujH/uwRbjFI8igM2dtJH1B+abDluVGyNuYMRJkxEisume0xuPjJJ2FQ+FIVBlWYKYcH0Qb2C7dO1R+9igV9yjkOEx68ygk+wEFaYf38+/OvGAVpuIb4VGHRGMJv1qCbTkcpWmkYtwWNpbGFHmanx3Q4RRR3kTdNiiJooq84CW5os/oxaaE2Wz930xWpDoBkoj7WoTTQPY48DRbi9X9U= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04c50e03-7cf1-41eb-7a3f-08dcb6714948 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:25.8898 (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: dy6oSR9+bUIhoYeHR69ZoDN7Ik7FZscNaVcp242MVpnWjMJg8sGYPhH6mtDektEX X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164139_979728_DF2F62F1 X-CRM114-Status: GOOD ( 20.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 This control causes the ARM SMMU drivers to choose a stage 2 implementation for the IO pagetable (vs the stage 1 usual default), however this choice has no significant visible impact to the VFIO user. Further qemu never implemented this and no other userspace user is known. The original description in commit f5c9ecebaf2a ("vfio/iommu_type1: add new VFIO_TYPE1_NESTING_IOMMU IOMMU type") suggested this was to "provide SMMU translation services to the guest operating system" however the rest of the API to set the guest table pointer for the stage 1 and manage invalidation was never completed, or at least never upstreamed, rendering this part useless dead code. Upstream has now settled on iommufd as the uAPI for controlling nested translation. Choosing the stage 2 implementation should be done by through the IOMMU_HWPT_ALLOC_NEST_PARENT flag during domain allocation. Remove VFIO_TYPE1_NESTING_IOMMU and everything under it including the enable_nesting iommu_domain_op. Just in-case there is some userspace using this continue to treat requesting it as a NOP, but do not advertise support any more. Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Acked-by: Alex Williamson Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 16 ---------------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 16 ---------------- drivers/iommu/iommu.c | 10 ---------- drivers/iommu/iommufd/vfio_compat.c | 7 +------ drivers/vfio/vfio_iommu_type1.c | 12 +----------- include/linux/iommu.h | 3 --- include/uapi/linux/vfio.h | 2 +- 7 files changed, 3 insertions(+), 63 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 e5db5325f7eaed..531125f231b662 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3331,21 +3331,6 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) return group; } -static int arm_smmu_enable_nesting(struct iommu_domain *domain) -{ - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - int ret = 0; - - mutex_lock(&smmu_domain->init_mutex); - if (smmu_domain->smmu) - ret = -EPERM; - else - smmu_domain->stage = ARM_SMMU_DOMAIN_S2; - mutex_unlock(&smmu_domain->init_mutex); - - return ret; -} - static int arm_smmu_of_xlate(struct device *dev, const struct of_phandle_args *args) { @@ -3467,7 +3452,6 @@ static struct iommu_ops arm_smmu_ops = { .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, - .enable_nesting = arm_smmu_enable_nesting, .free = arm_smmu_domain_free_paging, } }; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 723273440c2118..38dad1fd53b80a 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1558,21 +1558,6 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev) return group; } -static int arm_smmu_enable_nesting(struct iommu_domain *domain) -{ - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - int ret = 0; - - mutex_lock(&smmu_domain->init_mutex); - if (smmu_domain->smmu) - ret = -EPERM; - else - smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED; - mutex_unlock(&smmu_domain->init_mutex); - - return ret; -} - static int arm_smmu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks) { @@ -1656,7 +1641,6 @@ static struct iommu_ops arm_smmu_ops = { .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, - .enable_nesting = arm_smmu_enable_nesting, .set_pgtable_quirks = arm_smmu_set_pgtable_quirks, .free = arm_smmu_domain_free, } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ed6c5cb60c5aee..9da63d57a53cd7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2723,16 +2723,6 @@ static int __init iommu_init(void) } core_initcall(iommu_init); -int iommu_enable_nesting(struct iommu_domain *domain) -{ - if (domain->type != IOMMU_DOMAIN_UNMANAGED) - return -EINVAL; - if (!domain->ops->enable_nesting) - return -EINVAL; - return domain->ops->enable_nesting(domain); -} -EXPORT_SYMBOL_GPL(iommu_enable_nesting); - int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirk) { diff --git a/drivers/iommu/iommufd/vfio_compat.c b/drivers/iommu/iommufd/vfio_compat.c index a3ad5f0b6c59dd..514aacd6400949 100644 --- a/drivers/iommu/iommufd/vfio_compat.c +++ b/drivers/iommu/iommufd/vfio_compat.c @@ -291,12 +291,7 @@ static int iommufd_vfio_check_extension(struct iommufd_ctx *ictx, case VFIO_DMA_CC_IOMMU: return iommufd_vfio_cc_iommu(ictx); - /* - * This is obsolete, and to be removed from VFIO. It was an incomplete - * idea that got merged. - * https://lore.kernel.org/kvm/0-v1-0093c9b0e345+19-vfio_no_nesting_jgg@nvidia.com/ - */ - case VFIO_TYPE1_NESTING_IOMMU: + case __VFIO_RESERVED_TYPE1_NESTING_IOMMU: return 0; /* diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 0960699e75543e..13cf6851cc2718 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -72,7 +72,6 @@ struct vfio_iommu { uint64_t pgsize_bitmap; uint64_t num_non_pinned_groups; bool v2; - bool nesting; bool dirty_page_tracking; struct list_head emulated_iommu_groups; }; @@ -2199,12 +2198,6 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, goto out_free_domain; } - if (iommu->nesting) { - ret = iommu_enable_nesting(domain->domain); - if (ret) - goto out_domain; - } - ret = iommu_attach_group(domain->domain, group->iommu_group); if (ret) goto out_domain; @@ -2545,9 +2538,7 @@ static void *vfio_iommu_type1_open(unsigned long arg) switch (arg) { case VFIO_TYPE1_IOMMU: break; - case VFIO_TYPE1_NESTING_IOMMU: - iommu->nesting = true; - fallthrough; + case __VFIO_RESERVED_TYPE1_NESTING_IOMMU: case VFIO_TYPE1v2_IOMMU: iommu->v2 = true; break; @@ -2642,7 +2633,6 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu, switch (arg) { case VFIO_TYPE1_IOMMU: case VFIO_TYPE1v2_IOMMU: - case VFIO_TYPE1_NESTING_IOMMU: case VFIO_UNMAP_ALL: return 1; case VFIO_UPDATE_VADDR: diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 4d47f2c3331185..15d7657509f662 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -635,7 +635,6 @@ struct iommu_ops { * @enforce_cache_coherency: Prevent any kind of DMA from bypassing IOMMU_CACHE, * including no-snoop TLPs on PCIe or other platform * specific mechanisms. - * @enable_nesting: Enable nesting * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*) * @free: Release the domain after use. */ @@ -663,7 +662,6 @@ struct iommu_domain_ops { dma_addr_t iova); bool (*enforce_cache_coherency)(struct iommu_domain *domain); - int (*enable_nesting)(struct iommu_domain *domain); int (*set_pgtable_quirks)(struct iommu_domain *domain, unsigned long quirks); @@ -846,7 +844,6 @@ extern void iommu_group_put(struct iommu_group *group); extern int iommu_group_id(struct iommu_group *group); extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); -int iommu_enable_nesting(struct iommu_domain *domain); int iommu_set_pgtable_quirks(struct iommu_domain *domain, unsigned long quirks); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 2b68e6cdf1902f..c8dbf8219c4fcb 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -35,7 +35,7 @@ #define VFIO_EEH 5 /* Two-stage IOMMU */ -#define VFIO_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ +#define __VFIO_RESERVED_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ #define VFIO_SPAPR_TCE_v2_IOMMU 7 From patchwork Tue Aug 6 23:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755507 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 06182C52D6F for ; Tue, 6 Aug 2024 23:43:26 +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: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=jPiWfsDFtArTBCmfh/ouk56R0Z9znkLPRHaGoddn0Co=; b=aVSW3hWB4OcydC8pfpc+Bd3DNS vwSEHKqbwmkW+4cS0mU75qoyglg/1yLTB+7f42HkeJuKayxOKQPCnBWndx8l+0t8za8vr09uW97yl bMXiM7ASCuCUx4x8oW3jMJr2xE46gqvKxid696Xj8vRU1dw4OZzfLk+Qk2xS/UiE6/wFjAjlwn/LI gHTFuyQIvpwh1JJaPr30LIs7rNdd4PbDVdPwGmYbLkAl3VVJf/mT07LbMq9ZFRPfwXrvBlLsenfEB dKIMIKD6Yr7s3c/KXwkVM7KSrM9Dg0uYKDLNuJ+ptFdtUlTTWUkUHiufr+SxV1E8/HA6lF5/jsenC /Rp4vgrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTpd-00000003MAs-0B3c; Tue, 06 Aug 2024 23:43:09 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTo5-00000003Li5-2Nk8 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ACte1z2oFb9Xm0ikvUAEOpa70fGCBzs0okGB93kIRUzVmvgSK2UEJUufdc9/KodxOHNXWM70AkX4Qz72dPki+EEv66cbu66JfQ9emb5/vUzdKUvlD+obW2gbNhXctLMVJrF4UFL2ytyuNquiWbFfPQ+P0LmBij85ZXjPvEBSzhwmQx/jDirxnAZCJRECWbfCCYvVm5IHjGyE7ZzZsL5/T0OLP2Ta9LMdczNUSK73xNYJptqnMuZg27bQGOZnuFZ61kQoMGC+XVFD76429U26MgPwj+gsO12UxAMzD7MnchIfwEPHCkJiy+sGh/uX+vcdeq/7eDja/FtaVIIMPI4S2w== 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=jPiWfsDFtArTBCmfh/ouk56R0Z9znkLPRHaGoddn0Co=; b=m1SgV+JdZLwwaKt97gxyKraIj9lWnl5WuCxVyvSTTMjmxryCTVuvrEP4VPQTTG3k3SJyZT3eeb7RrTSOOK+kuQd52s0RUZe9oFR4F05CwUVqyXY6QOEm+1jPiBku9kDqDkM0XCvR/9McHKbCIdtf6kp7dh5GGhl4pRqK9ty+wmkK5R+/yDQp53IMPO7DomT6zhFE1mgvWSgOu5CiLBU7nwoJ8F3yv8bCalNx/qwmQh42JrsnGNk8HM58CSxhFJ5BG6YJxhSbfDkbJMZLs57sCnNLinm/B0bLofxBsQQGH42a0olDaFOlFxlhSgBGMVnwmFNsVFuZRX+9Ja4ZV2gZFg== 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=jPiWfsDFtArTBCmfh/ouk56R0Z9znkLPRHaGoddn0Co=; b=LvL3VrSVubPUnTmqHMh6fkvDAFQ3CCwL+3W2B86ZeqA/1qtrhM3YCNyv8dGYyfNvjIttqt8V2ftj6bsBUKW14p8BsaWU/yByPbcbA/kRkLaEMPCL3pJsWXo7gM/ueKHYtqy7z+7rTTDj21SJPG4rW/AclnJhwBKE+rkhLUNCvySs3OT6y0QG5QhIzjlc470yOPCWPwyXYDZzrvDQ18P6V7G5pXPX1hPdCbnniALPgyK0trV+SR4ctJLpWXjd0YvqMtklz0ilw0DgVGRhcwaHoHaGwhzdCUrv8JbLciaHtkWCY62SdRj92tOloFtikqVZ6bjAK7Hf+gwdnuZhu+6HOA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:24 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:24 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 2/8] iommu/arm-smmu-v3: Use S2FWB when available Date: Tue, 6 Aug 2024 20:41:15 -0300 Message-ID: <2-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0963.namprd03.prod.outlook.com (2603:10b6:408:109::8) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: c7f87cf6-49ce-4112-c9d1-08dcb6714805 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: K2VtNQxin51f4CNT7yfYmq3iKd/EWXIH11hgE8pSMQAEZHO8C7q031yZjLDBTRvzU01P22rleSS/+Q/V6kr8GkxtEsfOTK/7JKzEzwrfi4QNkRVOLHXvlh2/S8zsUCTQotufSEv6gF3Huthkv4Xs49nq0cvi6nfSRYeUNnC7CtHBfOhoeGnq5wxuYj5g5YAyJRhhPII1h2qoWIOWuqy1KdpN7D72PN/faeEh5rGRXPCLaZzE9sV8K0tv+9NPx0ydyLmYF6tEPdv38TU86mKr91N+V0eWhoCVeu31R0iPX7ESVlrWaJS8CS2vsLMXe1UH2wEwE4QdaoNMjOtp7YeNJ9lsHkiEtJjjumoYJi614EJzDJYs5pcOOJKDjp3ekdfXHVPw5/A+6jSfvZ0ZVvadJ2nKGZQfNsSK1urPydRLDhJ8WbxKDR1KMMoeC3F9FwpDX5c2KFkkvuI8Oy38VlXVAslqm5iCUuN8BI9u3H3M9FfyTMW4medai28w8l/zpT6LFBKIeRgK8R+5uptR43RTKHFQgVMuqpujW3zAmhbKCuN87iXJ5L4A1tAx9YtZUGGu67XfzUBfKd752z4BrmhkZAyNoj0jO6pS0r6J8G4gz4v61RcAOS8lDW2BqUmG1Aax4Y6tgi50lm4dJGC/PKe+DL0mjc0wcW8WqytT2SezydPfUtYkomBvTMrhGC54j7WvYn9wrGTGc3uAQtC04sxxnCzJUPVvdqm8v4J/fcTk5RymdWgooAIjkdjXWsOedAqyCT9vQbbg1JcR9kDU1O6FHzprZ6c4zOyV8gjqOIEcwxEz0qNymcVDRVIxUcGSltbWRq0pBHZXdaS4IVRTmzkoXQae+NTo5oGNzykD5Bt7MWGBMfl7V/gtOV5ZY0pJIdS+wu9RfBYsq3Bfmi1quZ5sWD0HqwvDmjR517zpQxSQs0v+dU/ZZts9fDO/I2f3MS4Bc7PsxaMuIoCAoWVnHmZ2TxHjgypr7Vus6mlSEGpyM9F3rVwW9HuGXfkxGFE23mYQMaf0XHOtgDGn/J8RaM1MHj+INOOshGhdwxJgNeh3TItgLzNUPeSHnak8iujkyWLl7aVrOc/Bxu0g0txkGRDi0UT0i3gW3NOHsj0Aa6+KE9XM5d31sEuTUphU97fMUJgPWElHVmbWszBQPlWOSfezfqYfk5IwwKMpI2NlwPHh6wi8jZ1t+G4BcolGVuOTLvU5NwpvDxxOxrW63bAx9WPW1gkiq8Z0pdc61OlCjxNBPjwo/JRxeq0iQ7GzGu+y1HjUEHTcAFtTuy8j9n3N87t9XFsrad/IfU+A58KcUp+Jxm2q7m/gm7VtRczhC2q2L6QXjaPDujVbeGvxfx6FkVqfFgCkuwvjwv56W3NGcleAr9ygTPFtS0cS7yDsdzp0T7ZV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OHd4GTyzuRu9NSj6V9nLT6JIEvNmDIx6iCZOHsUm3M2Oqy4JdBjIDix6asMrBstRk/eLiVkfgp63obblQdCts+M07EujlPcOsyycgBaO9Ia2mxnpB8kkMaDmbJPSx8yV+W3fqAPyWJfAxPgpGPNDeA0z0jtnecXUqfVuyohoPZKtv25oea+vG/3ch3WFDMDBCpYx7qJecAloIluwuAxur4KkDHx6x6O6LJTT7xT/nm8NMFLsxX/ArZWMA1vaaK6LkRfsFB/wb5aDyTO9i1QCcZGAGHZPjq8SqcZ4KOx40znv1OSsa/0sYkzPOksgPXlJmJCC4WtTCAW6OdQHUjqZZfOKOd4eH8LmuIS7Ih997mTUBQSnZOVN6wi5pV1k+kokCnFKqJlz2n+CAbKfC18zgOYkKEt9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jZEPFuo4XTRxDOpO+AhmAlCTXnYDxWW0TB0eY1YzVBj5jQTSjezalvuvJDiCpZyOMZxxl7V1syO0fZ10jwJFH9p+iYunkYs= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7f87cf6-49ce-4112-c9d1-08dcb6714805 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:23.6590 (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: hTyxZXN8JaUNLL4z5d4KB2ciglny4F/AaXveDZARfZc9U7M0ozzKTT+kI9eONqdK X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164133_640916_018E6EEF X-CRM114-Status: GOOD ( 17.39 ) 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 Force Write Back (FWB) changes how the S2 IOPTE's MemAttr field works. When S2FWB is supported and enabled the IOPTE will force cachable access to IOMMU_CACHE memory and deny cachable access otherwise. This is not especially meaningful for simple S2 domains, it apparently doesn't even force PCI no-snoop access to be coherent. However, when used with a nested S1, FWB has the effect of preventing the guest from choosing a MemAttr that would cause ordinary DMA to bypass the cache. Consistent with KVM we wish to deny the guest the ability to become incoherent with cached memory the hypervisor believes is cachable so we don't have to flush it. Turn on S2FWB whenever the SMMU supports it and use it for all S2 mappings. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 ++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +++ drivers/iommu/io-pgtable-arm.c | 24 +++++++++++++++++---- include/linux/io-pgtable.h | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 531125f231b662..7fe1e27d11586c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1612,6 +1612,8 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_1_EATS, ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + if (smmu->features & ARM_SMMU_FEAT_S2FWB) + target->data[1] |= cpu_to_le64(STRTAB_STE_1_S2FWB); if (smmu->features & ARM_SMMU_FEAT_ATTR_TYPES_OVR) target->data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); @@ -2400,6 +2402,8 @@ static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, pgtbl_cfg.oas = smmu->oas; fmt = ARM_64_LPAE_S2; finalise_stage_fn = arm_smmu_domain_finalise_s2; + if (smmu->features & ARM_SMMU_FEAT_S2FWB) + pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_ARM_S2FWB; break; default: return -EINVAL; @@ -4189,6 +4193,8 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) /* IDR3 */ reg = readl_relaxed(smmu->base + ARM_SMMU_IDR3); + if (FIELD_GET(IDR3_FWB, reg)) + smmu->features |= ARM_SMMU_FEAT_S2FWB; if (FIELD_GET(IDR3_RIL, reg)) smmu->features |= ARM_SMMU_FEAT_RANGE_INV; 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 8851a7abb5f0f3..7e8d2f36faebf3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -55,6 +55,7 @@ #define IDR1_SIDSIZE GENMASK(5, 0) #define ARM_SMMU_IDR3 0xc +#define IDR3_FWB (1 << 8) #define IDR3_RIL (1 << 10) #define ARM_SMMU_IDR5 0x14 @@ -258,6 +259,7 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) #define STRTAB_STE_1_S1CSH GENMASK_ULL(7, 6) #define STRTAB_STE_1_S1STALLD (1UL << 27) +#define STRTAB_STE_1_S2FWB (1UL << 25) #define STRTAB_STE_1_EATS GENMASK_ULL(29, 28) #define STRTAB_STE_1_EATS_ABT 0UL @@ -700,6 +702,7 @@ struct arm_smmu_device { #define ARM_SMMU_FEAT_ATTR_TYPES_OVR (1 << 20) #define ARM_SMMU_FEAT_HA (1 << 21) #define ARM_SMMU_FEAT_HD (1 << 22) +#define ARM_SMMU_FEAT_S2FWB (1 << 23) u32 features; #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index f5d9fd1f45bf49..62bbb6037e1686 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -106,6 +106,18 @@ #define ARM_LPAE_PTE_HAP_FAULT (((arm_lpae_iopte)0) << 6) #define ARM_LPAE_PTE_HAP_READ (((arm_lpae_iopte)1) << 6) #define ARM_LPAE_PTE_HAP_WRITE (((arm_lpae_iopte)2) << 6) +/* + * For !FWB these code to: + * 1111 = Normal outer write back cachable / Inner Write Back Cachable + * Permit S1 to override + * 0101 = Normal Non-cachable / Inner Non-cachable + * 0001 = Device / Device-nGnRE + * For S2FWB these code: + * 0110 Force Normal Write Back + * 0101 Normal* is forced Normal-NC, Device unchanged + * 0001 Force Device-nGnRE + */ +#define ARM_LPAE_PTE_MEMATTR_FWB_WB (((arm_lpae_iopte)0x6) << 2) #define ARM_LPAE_PTE_MEMATTR_OIWB (((arm_lpae_iopte)0xf) << 2) #define ARM_LPAE_PTE_MEMATTR_NC (((arm_lpae_iopte)0x5) << 2) #define ARM_LPAE_PTE_MEMATTR_DEV (((arm_lpae_iopte)0x1) << 2) @@ -458,12 +470,16 @@ static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data, */ if (data->iop.fmt == ARM_64_LPAE_S2 || data->iop.fmt == ARM_32_LPAE_S2) { - if (prot & IOMMU_MMIO) + if (prot & IOMMU_MMIO) { pte |= ARM_LPAE_PTE_MEMATTR_DEV; - else if (prot & IOMMU_CACHE) - pte |= ARM_LPAE_PTE_MEMATTR_OIWB; - else + } else if (prot & IOMMU_CACHE) { + if (data->iop.cfg.quirks & IO_PGTABLE_QUIRK_ARM_S2FWB) + pte |= ARM_LPAE_PTE_MEMATTR_FWB_WB; + else + pte |= ARM_LPAE_PTE_MEMATTR_OIWB; + } else { pte |= ARM_LPAE_PTE_MEMATTR_NC; + } } else { if (prot & IOMMU_MMIO) pte |= (ARM_LPAE_MAIR_ATTR_IDX_DEV diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h index f9a81761bfceda..aff9b020b6dcc7 100644 --- a/include/linux/io-pgtable.h +++ b/include/linux/io-pgtable.h @@ -87,6 +87,7 @@ struct io_pgtable_cfg { * attributes set in the TCR for a non-coherent page-table walker. * * IO_PGTABLE_QUIRK_ARM_HD: Enables dirty tracking in stage 1 pagetable. + * IO_PGTABLE_QUIRK_ARM_S2FWB: Use the FWB format for the MemAttrs bits */ #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) @@ -95,6 +96,7 @@ struct io_pgtable_cfg { #define IO_PGTABLE_QUIRK_ARM_TTBR1 BIT(5) #define IO_PGTABLE_QUIRK_ARM_OUTER_WBWA BIT(6) #define IO_PGTABLE_QUIRK_ARM_HD BIT(7) + #define IO_PGTABLE_QUIRK_ARM_S2FWB BIT(8) unsigned long quirks; unsigned long pgsize_bitmap; unsigned int ias; From patchwork Tue Aug 6 23:41:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755508 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 E2173C52D6F for ; Tue, 6 Aug 2024 23:43:52 +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: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=i8uELISHKDo8aopEsoXqsfcXZwuzDOSWDjKX+9+WdCY=; b=ynToIuTR+ibNL5OkBpVBPIwS3h k3fOJXmSKVWqjCeaL72X5MKxEJgObM7vvaZlBGnSngiwboa0yHxXmysbh7TxcCXSS6p10E+QMrVNE XN99VHQq3X8K+aBwbuU/MO4Sjmj2bh+gW4JqModapAL9eGfXTduvxB7oOQ0H+658+r7w8wP3LMzun v96Z2AQNxi0otZq3a+k3JWDxlsKemKSjdy9UWqbG6Fxu4iw/6tO4KMO2Ups8BNybrlorB2Z4zVMxR xhYjwzi4ixp7SRJp+5ZY/DybIgfZ5l7DximUI0lA3DFLOnPvY5C7jiCoMwRlA4H9VdhIDowfkIbbh mvD7yOjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTq7-00000003MG0-3Ioy; Tue, 06 Aug 2024 23:43:39 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTo6-00000003Li5-45Xs for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RZIXMJneVbg038vmtatxcM+jcrJEsG9TH64UBS2IcEGAlgE+Zr+cyszYw87fN9d69rUtlCJ5mzK8hv+8yYjuE3LkP65dx35FIYKFsZCNfgMv3c4qqvWwUJjK7SOzzBhCs+zj3NhtjetTsSng3h09H/lp1vCIdzGCdHPryVISwAYSaWjyMcXI3KkwverObBdlvBvaApksBRfBHx9JyN1YHFq0LVd/eTezr7itHlltCbvEqCKId3Yr8mOqWjHSwFhcLE4yb4ORiyMRQNHMza2gLtA8gQejBRNZe7DCQwSZN1X0SG3XqxCsUjCA4tpQzYsM2xgRowjl+sHf4YkLV0gPGA== 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=i8uELISHKDo8aopEsoXqsfcXZwuzDOSWDjKX+9+WdCY=; b=U3kTjate4F+8piwD7U3XA9H8jYZO/VuFNkeS+cBKVoOvJq6XH3IHf8j9HLpQECAzbQbYqrN4l2TgC/2k5VGPUYua2fZNMogarPqKMHifIe5lhSYrsYBBZT06geGkOYsS3U4zIqCehj7tWmaYEtW81mu/RzyDRr9naC8cWTfW1jsSQmfqrDCDHUGGm751ACTp8uGfg+TSGU/9ktBo+Ch9X89wsGmH14Ps9vYSNkUaPLIC4uPWsA0LonsBj1Au+ADp1F8dKkJUVlkTkQmw1YkHcoBdfPDq+7WqhMKDAD6WEJH+deo9k1HLj8s+plWRjeSVXkYuaSdqALxEz+l1YV6HFA== 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=i8uELISHKDo8aopEsoXqsfcXZwuzDOSWDjKX+9+WdCY=; b=t+Q9VHe1t5/ujrs0gEsOC0VovOk9ThfFuyCJgslmY/+P7jcPebvdHAicOFgw1FeJV3MByv8bZilDAqc1I/wej168W4SD/UDDLMLtCRXEGeFT0Q73UWjhsJzXHEplQXS2JtPumz8q7hZEP06P+rM8UGM2NRLzlEI7fvm3L1B7437xABmAqcdek3yZaVfqU6O4R+BlRsuvqmEnVoUIp+nK2/qGqBbSxi2WE3IUXedExDV/Sslqr+PmBSCpYv0sgDHG6CbhR8iwhhO0i22jCxo/mIiowMRZFYmFT1NwAzvHTjLPBvKG5303c1wSDyrYppUzIZVIdou+oo1T4CO/famSlQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:25 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:24 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 3/8] ACPI/IORT: Support CANWBS memory access flag Date: Tue, 6 Aug 2024 20:41:16 -0300 Message-ID: <3-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0362.namprd03.prod.outlook.com (2603:10b6:408:f7::7) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: 598044bf-73f0-428f-adf3-08dcb6714809 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: 6TTGCOTZKdwheB17rSPAtTHQapfdDbHh4PBINzchFkEGhv0RtteDzS8TjAzzHqolwqJf7lON+N0ZZaZM0yLA2tdNv9GiLqucSzxb+pUYOkoIY1chlXssDgLciT1akPh7aMb5vlBy/uwiZ0ooUWt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XSyp40SYT67Pi0eOCYlVTZk7mfnOj++SmUaNml60teYhfhMp0kkBsA031SFXy/+AfaS1gtKPo25yy5Z6YfmOkyxfbkW8TFp6xSMdgHUI7VAhT1T5Awo7SiEri8JQiqpZJdmuM1EsUKMRcq/fC5Amt2k9R/5IJgvaLjvMQflELgV/5lqT9Dnpriyqh9veQ6yKxoYhZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YOGJyPuKmC10oRUbGYBxjReeiHXJEw/5ZLFykLjQTjiWwwHUCckjsgHCVpY5spAo1KzQMvA1muboAokG/SeqDlhc5n6xGgXgRlQ6hIOEQoKPfmTfi+uJwVlHFcmp45ny02dwK1QUrKk9HfZr0jrRD1L7r9gcRvfrfI1NMbrTmeeqAuX+gg2XlKiMRbbcPZ7sUStlHFya4mDZrQUoidky1gvqK6ns78oeQSZ7UtXIqRroodAu7iDuN0OqE+vtYoOM6NOZT3cnJsGai/oW0lt/MlJuHb4ufuMi9nr+ywYp21S4eaJGzfF3G22DkqF3nQ8xs/XI2BOi8fJ02fkCubuI5wdNk5mOZ+1hYj/GC+Ji4rLysveyujCqehggD1JAGqy6KI1vz4L3nQJIRFG8ky3cwlAlSJfwAsEvlde26Zg29QVV/Meh1YWMQ8FDCHKEnXXoEY5VI/m+HEayFoZK/AKxNGdXcrohKdYCo/ElUlkJb3rqNTbQ7tHAdDu9GZ3cEfCN7oSEfmJoP//UF11JAYabPBnmge6WtL2TPhU7bSwsR4d4pEb79D+ANN32zQPpyQUPcrKm3m1m3hn5KOGm9IfadjuTiZiECtjJ6X3N3ttLHDHHTfUv8JcOgZorXHhMG3mA8Depc+FMMFYHse7Sq1zwBDV3Z9VB2BP1Lg9NT+BwSbvMBLEqSRJCOdVHEDveFXSMKw6rek2gwknLjcxwJhScRHhf5YKYr/x/AITGiA2q44th+mevV6pRvxSCbwqxHFx+xGKqOz4g/TLitJ1Uf2EDfSh+0zsAjQaDOPdKcI13JkxyGXaNRakiT67Lyz9JpTWaT+92RIrFVIgjx6aip7UvWfOX/5WXAV8AaGbKuCBbEt/NQCgVzOlrETcwSxXCUFA5k55AKqJEECSy3JiTO2AuKUOx3DwPkCQzD40WQ5SUPe1UqR2RG/bHo7ksbVSvZws3xsBnL70jTmz+0o/zFfeT7Ld6vWfKsBC4EbFmOjf8/t6xHMowIKgLw1p735w1qIhacPdy3ZguiyR0P8fPDqPGV0yN7OBD/sy2KDe8PY/YY1LaeQGMkAzR0QX+xVtVyAS5Mf2d8vwQyuHFF13ztabw1i9pOSHFWSzEiyvsmxvsniUZLPgypf4mdYiL0mHRqVOuyMqn0okVfuwzzsAx/yVFE+uV3XfZqtTXGpBQqTQ1XMyVG5FsGV42A5cRQQr1bCCcjJISuswrhhrVmOn4TAnps0IvONeV0vqa+2eu6xDSC70mAx2el6ygXjKGEzcC33tzMnCac5x37lqmtBD9zUuwK7YnQWMuiCQpu0CP8X6o0tw8M9ObiQ+ZaxXc8Fl0pZikCkW9NummZxI8Wo4MfYy9F+rK6o9Dpy629uHSSpoxKyAwy/Scg36nxbkJIscwvwwbhO5EPesWgrFiatTSDoqhG8xuxWbZYmGpTYWvb/i6IY9J/8JvUPgpijCdrHi0GqH8hg5NqNk/aDIfmWgVOkk59YhaunVN3pagoNGw9vRCCvWjMavalFMgCfWLosWoHqqRUDRXCC9FSUtBlb5/BfGDrwxok9eyjjf1GNeTi0O/CCs= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 598044bf-73f0-428f-adf3-08dcb6714809 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:23.6812 (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: 0HsDZqRW5Yr9ist6qP5NAfL4lTJpXVtdNehjcQhDXRkXtBLLDbTeKTiyfNPNfwXJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164135_049764_C20F0B96 X-CRM114-Status: GOOD ( 14.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolin Chen The IORT spec, Issue E.f (April 2024), adds a new CANWBS bit to the Memory Access Flag field in the Memory Access Properties table, mainly for a PCI Root Complex. This CANWBS defines the coherency of memory accesses to be not marked IOWB cacheable/shareable. Its value further implies the coherency impact from a pair of mismatched memory attributes (e.g. in a nested translation case): 0x0: Use of mismatched memory attributes for accesses made by this device may lead to a loss of coherency. 0x1: Coherency of accesses made by this device to locations in Conventional memory are ensured as follows, even if the memory attributes for the accesses presented by the device or provided by the SMMU are different from Inner and Outer Write-back cacheable, Shareable. Note that the loss of coherency on a CANWBS-unsupported HW typically could occur to an SMMU that doesn't implement the S2FWB feature where additional cache flush operations would be required to prevent that from happening. Add a new ACPI_IORT_MF_CANWBS flag and set IOMMU_FWSPEC_PCI_RC_CANWBS upon the presence of this new flag. CANWBS and S2FWB are similar features, in that they both guarantee the VM can not violate coherency, however S2FWB can be bypassed by PCI No Snoop TLPs, while CANWBS cannot. Thus CANWBS meets the requirements to set IOMMU_CAP_ENFORCE_CACHE_COHERENCY. Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/acpi/arm64/iort.c | 13 +++++++++++++ include/acpi/actbl2.h | 1 + include/linux/iommu.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 1b39e9ae7ac178..52f5836fa888db 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1218,6 +1218,17 @@ static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node) return pci_rc->ats_attribute & ACPI_IORT_ATS_SUPPORTED; } +static bool iort_pci_rc_supports_canwbs(struct acpi_iort_node *node) +{ + struct acpi_iort_memory_access *memory_access; + struct acpi_iort_root_complex *pci_rc; + + pci_rc = (struct acpi_iort_root_complex *)node->node_data; + memory_access = + (struct acpi_iort_memory_access *)&pci_rc->memory_properties; + return memory_access->memory_flags & ACPI_IORT_MF_CANWBS; +} + static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node, u32 streamid) { @@ -1335,6 +1346,8 @@ int iort_iommu_configure_id(struct device *dev, const u32 *id_in) fwspec = dev_iommu_fwspec_get(dev); if (fwspec && iort_pci_rc_supports_ats(node)) fwspec->flags |= IOMMU_FWSPEC_PCI_RC_ATS; + if (fwspec && iort_pci_rc_supports_canwbs(node)) + fwspec->flags |= IOMMU_FWSPEC_PCI_RC_CANWBS; } else { node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, iort_match_node_callback, dev); diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index e27958ef82642f..56ce7fc35312c8 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -524,6 +524,7 @@ struct acpi_iort_memory_access { #define ACPI_IORT_MF_COHERENCY (1) #define ACPI_IORT_MF_ATTRIBUTES (1<<1) +#define ACPI_IORT_MF_CANWBS (1<<2) /* * IORT node specific subtables diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 15d7657509f662..d1660ec23f263b 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -993,6 +993,8 @@ struct iommu_fwspec { /* ATS is supported */ #define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) +/* CANWBS is supported */ +#define IOMMU_FWSPEC_PCI_RC_CANWBS (1 << 1) /* * An iommu attach handle represents a relationship between an iommu domain From patchwork Tue Aug 6 23:41:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755506 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 4C9FAC49EA1 for ; Tue, 6 Aug 2024 23:42:52 +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: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=7VYPdcBQbLlrAWUS5pJUa5cwh/NlHTssas6dwFh2rlc=; b=hqPjj9AXQoAWmdSo1TSQ07IXBr 9FDLlspVgi+RBkX2T5ZOxFFMwNwpvPnNcgDH3xOsrQog/aOS4UgzNygDFoulUwynaTAPd9pRAcrY9 8ddvGOaI+0sHbYJ060A9XW7QJfVPsgYHGFdJDfXYdA2qLsrcYm0QE6EwEyZFambt6vowFjbRKtwaF PAp7jZVKBmEsKcFEXib0k4qV26ERA2jX49it5nH7PhkNP0zfKSaF5nwEqaGmaO3U1tXRFOtDKKXTd gv8Zfzmj0K79jP4Om8FVbF2iLFMRSniHawsW1C/rkosja/OLpHViRJETB6oEKQNUCnyCQA1mqrN7d mLA2a+rg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTp9-00000003M66-0qgH; Tue, 06 Aug 2024 23:42:39 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTo4-00000003Li5-0qwY for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y3Fe8hAfGftnx+YuaFJF331ATUZCTM8d67oKl9HB2g+HxH5Lh+rKuqa63JktDXmfAq2PmvbpZVynXqKJAPq0vo+aZxXkF7NGp57+Zwyhsi6lWOV3RQGymb9Q8lAQ7+xokeSJQ7ec89yDamwIjtsMglDzUhusTHeQgM21vJzWZrlfjFFZLptXT0zsbIRJ4Xgq6DvpXOzFVq/Qo+GlYfaUW51ud5nBDyEmlkY0MNTuC98tREwgjPyFibNIx9VX1J0f0ucflwea9ZMqVA7PuwvQ8lUH0iqVCv+LkW3sOeyQRqia/OrI0YAyRrBLN0AbSv1zHr93ZKJyXjn1q4p82xzNuQ== 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=7VYPdcBQbLlrAWUS5pJUa5cwh/NlHTssas6dwFh2rlc=; b=xLbDfp4UHuyHvvFYtTu1LECyHP6N52vCQi0wx37PtwLzbw4Le1jO/SE8n++k5xp35D8ARWSsuReXKUTWKuP/6HX5MO7E9JH3hsivesa0SL/w2DJQyYrBY7Zeqa6p/IaeVnQzyt/Jvtl+Kvd/wm3FcvtZPv0zh90nmpdNA3m1j6nsCaCAN4apuHmqvKPV2n+aT9xRl+VcP1KrZTJLwMjRDpTJcDxElDXG5gJThSTeQiYDMvcotKVUPK+hC8uFl4YjzhWMTj0nrJMLHm5JMdMC7OyRCFLIFJH3xDhM+9iXnJAyOek9omF8C3aD2XeOH4rYwcOtTGsxA05hao0HsvOGcw== 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=7VYPdcBQbLlrAWUS5pJUa5cwh/NlHTssas6dwFh2rlc=; b=Gpvq+JGYtdzbWud57bntAObNldGQuCt+5WSI4be7HIV+8NUXdqjOxyU91rPAIZOKoazJQiSF88pgnpW1xkZ8bM7c7JI+1hZ+RjZf5lshncmGNw+D69w28jaYhseduha7Ewm6T9oKDbEE6NncjP6oa7XITUUloMfQoC3xpBxLIr+TNNlk8tRQ3R5/Xhw7lzB7uK2zwHvOCZ7o2PtiipITaIHTLYxbUUiUuHasasCISQp0YjDbEiwTP1yYRMivc/QTaLhfE/FHErnWOrytBaIBzsBplMYnl9lD6pHJCIe57Xdm1uYtAwl6SFKlTvydMSn129ndNHttR0dSVAGZuwL4mA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:24 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:23 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 4/8] iommu/arm-smmu-v3: Report IOMMU_CAP_ENFORCE_CACHE_COHERENCY for CANWBS Date: Tue, 6 Aug 2024 20:41:17 -0300 Message-ID: <4-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0034.namprd03.prod.outlook.com (2603:10b6:408:fb::9) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: d3589e7c-1afa-4335-873a-08dcb67147e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: Q64wxfJYvmJ1Zxk+8KoH0m6x/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0sulD8q3Ol6jIYIulBh8ppu0Pt14Gki9WwZ5NzXqFbotQctsa2dnkKXkUE0yMG6HMa3yTOvymtPMdd9flArWeQF2jwwKFzQlIW9/1LMrbsHRSgh5xX7owmm82WcnfJKc6NpPIYGQS5cFp7cEBKVLX97GV5HbwFQSXjk8AMJ3qz1189W80iUZZnW7/51+c1l1HBrvNZ+7oUJCejx27nswbMeRRDuU5KkYXqNfkj/Pdphy1mgTeGqv6+BpiDd1+1X9ch7b6Ip5bFTm//j3U02zOlMjwTBVZ2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vxDb3sIV7OLDznY/22D3IqobQQ7Y9dOTSlaKQrm+C8O22pM1Zlf0m5ZbkPiVuaKlpO/QLRHTSvMI9rxXyeED8OmQCrHrMKKUEu+vgFcLe3TDpalgTL8OHA9rss1xXEl8KGtok5dpzWlEcPNmx4vNLZa4Xe3InRTOlL8UtC4/kU2nY5nJSzU3kd/ZMTMitI0zz8CzixbqbbL9Znb3a77bwt0/zNRevqOo1yi5p94KI5HnSv/5ffejW4LIyGhtriiIrRVgRNX39vZ33gFbWr4h/et+j8W51rsd4r989C8EIRPlQEZ/Opra5zyj7EjZm7EUSMQKw9g3KpbemSxtlBW6DkGhhsbxrSx7WCWDydLH3W/60pmqSgVzwzDmZt1Wm1Kzvv1jJM+Pef1LGHKTwpPzwnAk8orlTSMdSrx5NWVgmawj3JXhGa7mfTaYRyyRZ04rmg7qeI60sPTO1YNBuMKX60nYdtFDu7NFOwroQK4xz8264fpdWqvGC0vcxy1Eobgcc2aIHG35YgMwqqSCnO5P01RSCD11TLtyENLbuNUnjzfMPMp+/c6srnufFMlCEpm7tHFpMN5uctgg7/oAR1q4Uc8a7IlN4yYQkNtJem9KYsFF/WUhuQD/KjOckioKrvZl4c1O4+wSkMYJpcDKXDSodZP9HUhCqe1y42czIGWsnxuxqIajVVzUpd0i9oJlMz/AmjspCUV+/388j8kBa4G8QzZe5m/LhmTBog25lzpayF2FyHVo4UkjaZbr6GPK+CcJB77Rl8NDMYaBCWp9EZzJap1IZfWun1DFMVY+avozDIDKwPBMKSWVx1KogaxGT4qiHKXnLA+UN0RXPu0jxEjrAkF40X5i2kK45+9J410TUSEoEJzRrQtSqcksUsROz3tokhonaXlvAfkAWYcsHFeJCEhpKbb8koZ862qa95+9qxkq+dlZWtGEydghIHEKYi2ZzYoGwbzOXkN8KPhAECYYclXPB0Q+aLl9Rs6Lof4O2tV172VJtCr61s7dgBHML0gwmIZcleBOLqdOUOEMIktE7J7Vvtcx9eLwSrwbB8xrq+UDtGtSWOvy314XhCsTD1tNQThjoSirwJ2Iy3BgL4QBdYUxCCZZ23gMp2rdQurFmyohk6JQve2hlsiopg7/bNcxqZiytv3lzHzz1pEUltjraGhyAMx+TY/+k3mWQYNoLMX+hdmCah2CqijE17guBGMBFrYc8S0R2wn8lyzq/zFiu0cfVBvOt0e43Z6iNVXsqLLBp88UpWaHGof2VRfafYAYnw7U2vO1tiMKJcsUA9j6xcZLqSuh/4QFPK7hG6q0/0pvuaDvRnXkHX6N/E0Jy5SsUoeCvVg+HiE7+Nt9TpS4m0v6jQr1KiBe7kxAvEmgQCorjiaX/5j3u2F+9faechhs4XpPlaByM5EHD++auyx+tff8K6it/VmKgFclUFuuogS/r+5kBiup1X79AcqkmmVU3KznWQ0fOqcu2X29DGCLFRkjqmguhIBMtU7hKi5/ZTiqrRXVVcwirgfR57fYqDT3K6FwkilqkgbrVDlTVxkTNeI5AazivkB6ps2abNnj83s= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3589e7c-1afa-4335-873a-08dcb67147e9 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:23.4831 (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: jdeDDktDWrvWPnHt26bMyIeyZouJX57Npozku0AL1kJ7ZUR7OKKtZ+iQs/HRBJZF X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164132_273229_722BC621 X-CRM114-Status: GOOD ( 13.29 ) 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 HW with CANWBS is always cache coherent and ignores PCI No Snoop requests as well. This meets the requirement for IOMMU_CAP_ENFORCE_CACHE_COHERENCY, so let's return it. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 35 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 36 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 7fe1e27d11586c..998c01f4b3d2ee 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2253,6 +2253,9 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) case IOMMU_CAP_CACHE_COHERENCY: /* Assume that a coherent TCU implies coherent TBUs */ return master->smmu->features & ARM_SMMU_FEAT_COHERENCY; + case IOMMU_CAP_ENFORCE_CACHE_COHERENCY: + return dev_iommu_fwspec_get(dev)->flags & + IOMMU_FWSPEC_PCI_RC_CANWBS; case IOMMU_CAP_NOEXEC: case IOMMU_CAP_DEFERRED_FLUSH: return true; @@ -2263,6 +2266,28 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } +static bool arm_smmu_enforce_cache_coherency(struct iommu_domain *domain) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_master_domain *master_domain; + unsigned long flags; + bool ret = false; + + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(master_domain, &smmu_domain->devices, + devices_elm) { + if (!(dev_iommu_fwspec_get(master_domain->master->dev)->flags & + IOMMU_FWSPEC_PCI_RC_CANWBS)) + goto out; + } + + smmu_domain->enforce_cache_coherency = true; + ret = true; +out: + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + return ret; +} + struct arm_smmu_domain *arm_smmu_domain_alloc(void) { struct arm_smmu_domain *smmu_domain; @@ -2693,6 +2718,15 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * one of them. */ spin_lock_irqsave(&smmu_domain->devices_lock, flags); + if (smmu_domain->enforce_cache_coherency && + !(dev_iommu_fwspec_get(master->dev)->flags & + IOMMU_FWSPEC_PCI_RC_CANWBS)) { + kfree(master_domain); + spin_unlock_irqrestore(&smmu_domain->devices_lock, + flags); + return -EINVAL; + } + if (state->ats_enabled) atomic_inc(&smmu_domain->nr_ats_masters); list_add(&master_domain->devices_elm, &smmu_domain->devices); @@ -3450,6 +3484,7 @@ static struct iommu_ops arm_smmu_ops = { .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = arm_smmu_attach_dev, + .enforce_cache_coherency = arm_smmu_enforce_cache_coherency, .set_dev_pasid = arm_smmu_s1_set_dev_pasid, .map_pages = arm_smmu_map_pages, .unmap_pages = arm_smmu_unmap_pages, 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 7e8d2f36faebf3..79e1c7a9a218f9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -787,6 +787,7 @@ struct arm_smmu_domain { /* List of struct arm_smmu_master_domain */ struct list_head devices; spinlock_t devices_lock; + u8 enforce_cache_coherency; struct mmu_notifier mmu_notifier; }; From patchwork Tue Aug 6 23:41:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755505 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 0D00FC52D6F for ; Tue, 6 Aug 2024 23:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=sxJ7bYbfH+piw4qD2+PsYhdNNnsDu2LAPIrP6Tt4Dz4=; b=oZXuS753TF2ezwffQo/znXrLKT ccUfS22cgY1ZVr3zjbQyWxo5DnGtQy7l/5T1VJcgNsxI1XB+7/TEN/qK6qtkY/buI3+X3LAK7a55T aU3eCmzLlsje3e6CoUAyoBXJOeXZRbs9SedCY2clJ4LZSUBhoVMD389L4neBhCsi3ZaSrR/vAnwjL VT0wep9LiFfS9wtmbw2F7MFwEw5Gga0mMH2ytfpeH9wSOj/bo28BJDFjsioG6/0sK4smS/qauCbAY 1dO05npmMRRVrTN4AdB3YqoUDCactFC/j5BCrVP1WNS4nzSi8k8STLhUkBUoCpfZAiMQ2AG0LgjDu aWOjL2mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbToc-00000003LvJ-1onR; Tue, 06 Aug 2024 23:42:06 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTo2-00000003Li5-1F2Q for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Hchf+4lFLBj6bao8I3DkLUHm6LoVFEYGM+RVn6sAFy0Wb5ZiDRgEyvGLpL6Ie5IlJuSRgAXhHsaM61byl8+BpkMcp8bQvUkfb2MqSR/POnWGBBg50o0hPAVaeBqP3omNd9Zt5nVDyzCEoUwRIf6D+n08Pld2TPl5gac1PhPKSCY5Y3Ubbwgc2zhUB/t4O9HkfejVV6FK1d5mevyLZreAcInG57/kZqw6hsv+dQB/OOl/s9bAer4k1eDr0Wd4mMs4g2yI35ecwj7JrMDcD6ktl9rngYnKjPfqBLR6ypxA4OlXPbiJ7aTnCVLE0ldX9k3AMGRc5Q5Z/f7dzT8x4zZMJw== 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=sxJ7bYbfH+piw4qD2+PsYhdNNnsDu2LAPIrP6Tt4Dz4=; b=uTVE4Pd/OKSYXp2wC5wsafm9NBD9SwHycAKjdhF35L2B+M+l1qnYpiiF1dtnauVZH8UKCgm5nEG7er4ToGyi4cpcRym2wv7shMVPMLPi7Tg7xWW1rCQYMFmIhPigBrqgdINCji8UFsMJGXbjPgHGQCUDj2f+D0TuOkGG4CDL2ZwfW4R7/RQeuEN1or1I8ypyXIh8nyApb04He2+ofSZPGkNvdkxHG9crNI8Zr9HdSG+lzRHzkZV3tlEaQAehHJyFwPMQyVg3/52VpTrKqzAzz62GJ/FPgTNhxgxjuj2KqarzHF8sGaGEHMFJAYFQd/LlqwGdVahrXsnFnqUEQLEXWg== 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=sxJ7bYbfH+piw4qD2+PsYhdNNnsDu2LAPIrP6Tt4Dz4=; b=dxKRNco8drz4p1jMmwkGLSaNsAtK7CllOP1r5PG1KplsBHh6HFR4awyM0XdVqVWIpVDEc1Cif1A2C6iBf4POJWSyqanbz2EtzLx4r8gA6df69EOSKFuLd5eaVYmytKqu3c4vrsSqK+2UMhE8b87fkNLyG8FNdjF0iMr/k7Iz+Y/H+PZC7g2rAa7oCaLSeEn0YfXU+atiqZcljSyHuwIMHyidb28V4+7tjApe4qDIjNAIyWNL6ac4WvTndqBL0Pvppt8o6nlcwgEEK4ccqs6F2W4rL2MNDzczd+AkoUh1g38DDvxcDAjzhw21TTfm734/po4bxXX8bUT4olgWJCdtkA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:23 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:23 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 5/8] iommu/arm-smmu-v3: Support IOMMU_GET_HW_INFO via struct arm_smmu_hw_info Date: Tue, 6 Aug 2024 20:41:18 -0300 Message-ID: <5-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0964.namprd03.prod.outlook.com (2603:10b6:408:109::9) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: c505ee49-181b-49b5-d859-08dcb67147e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: JVxadVHn+nFm3mZEdyFsih6xNaZgpVv9Y57heZgtK+dBMN8q5FLzQj3m+W/oDW1bLd3tZomjR1NJvDyZZu+7NS8FrdcgHtaP/UxL8vZcrSUm1MRixS7v973lC3yysjyM5oa1ueU6QODmQAkIjC2Z66+EIyxo/5pFA5PNwoIiVzyuE+cb1crXKE50dgSKcgyDBPsoda7Fgg2qM93dDiMvLLI1KZfPZwIG1uBn2v1YGNuwqbq6eKLIZco7z2esLURnPwNxE5SXNNCXbEoT9Pzvj0HsvIPOFa5gKl0uxe71cq4Ui2Hwb9ypIlxxrNn49HEMY+ReApuvxjJanl5t/cC4aowHaSQbUmQPNtYBvxrILUkjZbTZyNv66uPAg0V8X9MLIJeahGjXtuGnlSzFIDnE1pW2pDxy9/i9tdUUMBULBspNHsoA/VJxmVFex7jI9V2Ae1JyrzhH2zlr9s8o7nwKqP0PGNcnAX7HGoAMVWtytB3YMSwU4+jh0Q6WZ2qOxugUxkq6jGFE2AlP5sZkjv9zfW26HviiHe+I05/P8f5Tj+qbCb+DjubCFfdg/9ezTpGTmr/au8xtSMXmHLtUPJ8oyTotc5UU7P3a91hujyn/Gq2HtqkliWRVkefQPKr+my7QBR4Cj5eWhb06EnD+OIGnlFLsqZfy4cHbGsHRKSGigIeGIp0En8pO3883DGWGu7VyUQyethXzVkdJNUvhiXJxYj1g4a0fQh5jPw3nHJXMAoqUNjQ1y7gOeYCVqgudp63EGE83m03PwHVx+c56NsMPxWub4jaPH4/cFeoTM/0g6OLongMSDseU8o20npzlWTKTdZw8+YZptgIpVAZGkgeAKakqmXLhhZk8cUHRUTxwUoxZPVddXvoOrlE35TJ2KwgBufZ8+buVJ/eRiJDs5OIJWuatM195XqU8BWacyH/gIzwITI2whPdPz55wwBfWlI31gDAg0y9T5zAD7gJb/p9+lEFn4+PPZO3fLOX+rKS8E+GJlH0wDIwF4jtxllB4jaKORCLwsU8BBD0jfe0Ra7XPcamXuoAifVNTahrTzJxDOVKSQW1jUw+o6u7Qrv9ExHgadM29xGWn5J/3O1LYDRriSx6C+stkyrQACMmbyAbwU7iRprvrU8l48jhRWLNceobCHreCV941K59k3gavK3mccAkWCf2fuOVB4+S2FE2BpQdhzBvUsHnGUym+tieBu9BhcQoF6Xa0XT52/HRudkvwopPjO0Yli/1soCyjhOZGnh0Kyh8lNYm1ww6gALFXhl5xvsjNNKUyt2WXiVKe6mBUyYa7CjP1UrvdXgvyUdRDvysHZtLb44ENG8v4BrZSgbS4059FbuAZndduJwbYOOjS3JOALN2+9rB/XBbCQnD/Gz62dh6ODNMdCfHE6YU91nHd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zM7HJl50qFelmeAMkfr8HOBf+5rmI0fbUcc/SR0I/o+rmVSrcRKbcGtIf8AoADmDQTTybG1OGlvCLd3RkVVBiXehruEgUw/plFeZMjSYRKqbok34VVB+1h/sag+jgIpzc4xGLHm9Vur1ppXmLz52zr3S9jI22q8p+PjQ6AazVpHroLG8lxMeJFDPqDTV7fZ54W6ZkTSwim+hF66uAsOyO+j/4ziTkcJz7myv5bBjrK+GS1wtOgdFJUz5zPHWOlx1q6cSkctC9IfSKaShjkiOg87Ls3H4B58dioQdZgH+AksyIom5QeqaiyU33PdBsbS3qQnjRKF9UrLcMxKrhYzyhidpYD2N8r1Un34VCnLcsk+z43abNUpWsXyGwPZAa/dwNGlo4f1dsJsqsL/9WzpUrbyV3zZbtldmc4KSRW1JkXNbKMed66XpL2r57KhBYNgGzJRZeIMQ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RhIrzIKQ5/yflHgtZ+Qc+3scXie2q/0D1oI3fG3qpI6VXVyje9k= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c505ee49-181b-49b5-d859-08dcb67147e1 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:23.4456 (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: JAZ+5g+KPZ7R5FLS2HzXA0GJOISYIMlA3qvX4/JroDnTKbYEBD9V2uu/nByAqH7j X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164130_522207_E322F1C6 X-CRM114-Status: GOOD ( 20.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolin Chen For virtualization cases the IDR/IIDR/AIDR values of the actual SMMU instance need to be available to the VMM so it can construct an appropriate vSMMUv3 that reflects the correct HW capabilities. For userspace page tables these values are required to constrain the valid values within the CD table and the IOPTEs. The kernel does not sanitize these values. If building a VMM then userspace is required to only forward bits into a VM that it knows it can implement. Some bits will also require a VMM to detect if appropriate kernel support is available such as for ATS and BTM. Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ include/uapi/linux/iommufd.h | 35 +++++++++++++++++++++ 3 files changed, 61 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 998c01f4b3d2ee..6bbe4aa7b9511c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2288,6 +2288,29 @@ static bool arm_smmu_enforce_cache_coherency(struct iommu_domain *domain) return ret; } +static void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct iommu_hw_info_arm_smmuv3 *info; + u32 __iomem *base_idr; + unsigned int i; + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return ERR_PTR(-ENOMEM); + + base_idr = master->smmu->base + ARM_SMMU_IDR0; + for (i = 0; i <= 5; i++) + info->idr[i] = readl_relaxed(base_idr + i); + info->iidr = readl_relaxed(master->smmu->base + ARM_SMMU_IIDR); + info->aidr = readl_relaxed(master->smmu->base + ARM_SMMU_AIDR); + + *length = sizeof(*info); + *type = IOMMU_HW_INFO_TYPE_ARM_SMMUV3; + + return info; +} + struct arm_smmu_domain *arm_smmu_domain_alloc(void) { struct arm_smmu_domain *smmu_domain; @@ -3467,6 +3490,7 @@ static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, + .hw_info = arm_smmu_hw_info, .domain_alloc_paging = arm_smmu_domain_alloc_paging, .domain_alloc_sva = arm_smmu_sva_domain_alloc, .domain_alloc_user = arm_smmu_domain_alloc_user, 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 79e1c7a9a218f9..58cd405652e06a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -80,6 +80,8 @@ #define IIDR_REVISION GENMASK(15, 12) #define IIDR_IMPLEMENTER GENMASK(11, 0) +#define ARM_SMMU_AIDR 0x1C + #define ARM_SMMU_CR0 0x20 #define CR0_ATSCHK (1 << 4) #define CR0_CMDQEN (1 << 3) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 4dde745cfb7e29..83b6e1cd338d8f 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -484,15 +484,50 @@ struct iommu_hw_info_vtd { __aligned_u64 ecap_reg; }; +/** + * struct iommu_hw_info_arm_smmuv3 - ARM SMMUv3 hardware information + * (IOMMU_HW_INFO_TYPE_ARM_SMMUV3) + * + * @flags: Must be set to 0 + * @__reserved: Must be 0 + * @idr: Implemented features for ARM SMMU Non-secure programming interface + * @iidr: Information about the implementation and implementer of ARM SMMU, + * and architecture version supported + * @aidr: ARM SMMU architecture version + * + * For the details of @idr, @iidr and @aidr, please refer to the chapters + * from 6.3.1 to 6.3.6 in the SMMUv3 Spec. + * + * User space should read the underlying ARM SMMUv3 hardware information for + * the list of supported features. + * + * Note that these values reflect the raw HW capability, without any insight if + * any required kernel driver support is present. Bits may be set indicating the + * HW has functionality that is lacking kernel software support, such as BTM. If + * a VMM is using this information to construct emulated copies of these + * registers it should only forward bits that it knows it can support. + * + * In future, presence of required kernel support will be indicated in flags. + */ +struct iommu_hw_info_arm_smmuv3 { + __u32 flags; + __u32 __reserved; + __u32 idr[6]; + __u32 iidr; + __u32 aidr; +}; + /** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware * info * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type + * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type */ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_NONE = 0, IOMMU_HW_INFO_TYPE_INTEL_VTD = 1, + IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2, }; /** From patchwork Tue Aug 6 23:41:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755512 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 D162CC52D6F for ; Tue, 6 Aug 2024 23:45: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=tOSPp3mKTqEcr4jZdc9I3lgbRYxHrlJiJCYECRK7t78=; b=PNZM0nLc9PVOHliaCB5vCd/YcU 036d1CxaLyXRReQflDlfGpv5GUhLWNALfEjWGcKp7NVZqv0SFKM1c/PQdlXbkyOkG4ctaMXzLdk/z Gn4iJF5l5zxvsqTX6u+515Fk1YwoJy0KXxyVjkSnO3BjeP5geAfd0FXt2+oXHlqkWRpxPphVqkQFf 8mKRxf1NW2ngsvR/WttQ2/553QVFLr3extfX8D9nzwEJgMSmmIT5KhwvFHDRMbtvGN2hs6qo0qE2q J2KiZk+8KB6hDtWZufNewf+wcVjaXcC0rjo9dHZ/5Nc74ZN70tJQvVNDpnX8WMZYLLquv68lX3BQI 7tppZUKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTs5-00000003MaV-3fUM; Tue, 06 Aug 2024 23:45:41 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbToA-00000003Li5-0A7N for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KQjthcM/JhRJ5oIgzb+vRaKtTzvpxy9kLhyevK5KqScfvPDhhCDiczd4JnNzz6JmaIWb3ZYjPtsK9qJeuq5SExpWWMYw948nS5QCdIALnSgGSPuC1I/1/jZVIIJyfucYlnXlbIslaNq0TUOpVICLEZspmIsSjAlnMUQuTbrfUHZIQEsf9wcjC5/xCudSCjBhSclKbz1m5SSOvWqWGawsw+kwDSjdx7tnFLlgjZr0H7qV3fAQ1N2N32pLVn1yrshq2FO9bxdeAFMDQWwtDPd+VHOysRawEyqG9Ql8Ej8OP6rxZUj3TgolTPoEHR+Uow+QZ/KWBcr9WN3NP34XdyykZQ== 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=tOSPp3mKTqEcr4jZdc9I3lgbRYxHrlJiJCYECRK7t78=; b=DmyLroBVzNRYY1GNsrSX0J8qveyD5GV31siIWIe02cgy5D24e7yBxCY4lGl4rdnOCL7NLfGGHKp0/Hr9s0JnoN+Um5Mbj0RSz0EOs13ard9djR9E29faDMIiJvL/v6p217jPx5QXMVCk03xG/gV8wagjO2wWM8j4/T98/qOA1IcWhE065JzzkP5wcVnmNoL8VGoWuetGYqt2OEeR32bHyMTFITJiZZxyUV7g2ZX1RJopiwpmIE5H/Wmj7rm2fOeETxj46iEb1HktAtXJ2DGFZJyGdi/EsJnQVUCgt+Y4HxNOg3TSJUQgVUbbFWkxshlONbCyxUz2bcrBoma6TmvwrA== 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=tOSPp3mKTqEcr4jZdc9I3lgbRYxHrlJiJCYECRK7t78=; b=r5p4OlWa0hisvvB6VeZbUscDHFEZOcezdXiu2qF2NBr2SLYAv7umBmlixpmsX61Xk0jjaZ/zlVh9f0FfBW0koR/ssbMnqx3L4l8yYIG1m9DpsWZRyDDv0xjtEZrNavaIqL0t48YgHF5pUxazEra/pVf3HuTZVQQy4dB1AQB72BnLURpAMHlqyzstGoRms349lwr7eRxOhzkgmR/4hhguGfowgY9JHcmPs2fkAL6v8jv2fJvTK0Q2zohL81yng8u3lXUnDb7QA2kzoVW/BpyZ79faeLsBb0HKgBVO3JAlIgB212smCVIjVJkBYSgaJLdWPc5EyDmN3Ryy+d3GmzkmOA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:27 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:27 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 6/8] iommu/arm-smmu-v3: Implement IOMMU_HWPT_ALLOC_NEST_PARENT Date: Tue, 6 Aug 2024 20:41:19 -0300 Message-ID: <6-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN7PR06CA0066.namprd06.prod.outlook.com (2603:10b6:408:34::43) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: 895b3b7a-9661-45de-6b38-08dcb6714948 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: +bfqhu0Ru+DKW2L7uLiKkn/LfVtDT81Ctfo1cy1Nd2H3vX1wLDxCK4o8yMTdqwYhdiL2/ueyWitIQ75kwcperPNh40veOxXC4fgz5dlHPtF8sFgl2XVusJNvdRTQ4LgFJu3+pNPyCFdgLshyZQn74J+w/KQrTiHU9m22vCQkVpuccf9Nxw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T1Mz4Lp1XyAkrBjRKmRWwEoTUGda97J56RH1/3lBjzuf0JV94NIHOHEeyfJORgcYkHYroAkTCiF9/pA8pNrAqcaK94nW04IlTYKnfa8M3gcPWB+nsgR3ALDiJf0MB5tt5p35G2VhZtxcz/psLP2sksaYM3+ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tscg6Yvnz9wXcTMkQuIcubgAY8AywkhtCmOp5VTjx/r92PDXmyLT3Dg7377AijqkoNrZeKt3IkCKlyeCAyxId1d4KQweCgPupJZcfhFXw1UrzgC3KPaUP3kQjdAxDaxjV18s5H0tkerM99x/jgiQwhP0Woai+hzPbs2n+hgsr16/2K6t1nBt7OZq6i9QLUUukwly8rP6B/fzT1jl0gjOLNFoddJRtXMx6O4lD/YaDUo+bNPhdmPW7Qcduq9xsTVBCeP/BvymqX/ZHOxCKmDQt6+mBk6oEo/PGmvgmlYRpcS/vCHI9AGw/AirwZ21xp+16gJ/ezq47WhR4eduboftup2YJsmzgOlgRiZS00l5swdrYyMFp3FFdeyTQLX+aSMqPw2Yxn0R/ee1eRxSSgxuthI18oJoxXGzXojEtgyuD6PEFD7zNiXVxVwx+WEJJcrNQDCHfNuSysY7+XbQP3Z6SZ1E/xf7kvOS83IJK7/iK7eEXyjBSojyGjBhhRLehtQp/uETWoNAfjVXmbr0PicBrK5/ZCvozBPlHV24EbGWdkpRPr/G2kkAoy1xyt2e/ykag0bfshvst5szsp4ooEIkEk1JyzWAnbogSBN7iY6BRlTuq2BNjgGEksFSEyz+wr4MQas90+MHM9m1/ub3FIdTY/Boeg24hR8OJctktODskebZMzNvTkIG5wmDXIyd4QfeJcVzXLq2lWk2w/w7uLudpk2Ph3+CQYNrVeO/z0eXQ4nv4nac/DAHtn0MSGdSctwmAMLfDVktZcOWnq6o3X8YKimV0iiurX5O00skPCaLHGYbm4PWkFsHo8GRaHYPrgu+3w1j96iIYwIy4apJ6hPox5fjPLuko0XrIbe2HT6bZTeh1TJLEhjd83pGTPOt0GSOUX1SgKNyZaHT224XXhWChJgPXnsoZ/gyGN7u5duMRHwcMNPWKDFPOtdVBOtwAhRvOnx5ub7GGZOqGXJrFfARUtGGc4z2fLvk9otWmR2TWwI/z2yBX554K+Ep1JiZo9gswSKqY6U9/KkPxH9WOBoX1rxXwcCAn94/NyBOCoU0PpTbFbsfacFhZ60GUcPaD1sIaBT4YJddJDfa3NDxflx4Uw2KaZoNGEuSby77n3c8J/OKP2UckAv4i5isivXI0ZdYISfa4RCa1XeBiGrZ3xmvkVmuiZzXl7EzDC3rFohc+ocN+V1fHZFXxVQvfQjhENnHyK5N1HhuBgncW7CAS0W4s67VINnpJbgv3BgtSna4AC4g9l4+nRnufVB4QtGc0h5fcvA7FwuPM5n83Vzhrfyg10inx4eYbetlDbhr9sbaJmQE1SAPuriJYhQ13f1SWaGieng6OaD7fy9z3wq6qznp7d8jUbAZNQ4xOxLXVfp6/6NASKcadotJoqnaq07xsYPp7KS9DZ98v5GFwFXgCD6QKLRxmJ8Hq9cDYv7YBU1RhFAz9kfBnKzWsiKme+I00XW41LXwZc5uv597OypUPheYLhnZ5zS4XkfBjAMmH7iOinY5jsnzNUy6+AL+uJ70jF+rI7i9YLXqf6A+QCkfKfihoLAyrdRu79giCIO5jLJTl+Y= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 895b3b7a-9661-45de-6b38-08dcb6714948 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:25.7838 (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: Jf4mLIfxqtuRGTpG9gIGgzBPwuaZQit+rBx5h8uQddgIVb7qj0BzeFx/uFm88Ax0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164138_169254_A776D2AB X-CRM114-Status: GOOD ( 10.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 For SMMUv3 the parent must be a S2 domain, which can be composed into a IOMMU_DOMAIN_NESTED. In future the S2 parent will also need a VMID linked to the VIOMMU and even to KVM. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 6bbe4aa7b9511c..5faaccef707ef1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3103,7 +3103,8 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, const struct iommu_user_data *user_data) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); - const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING; + const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING | + IOMMU_HWPT_ALLOC_NEST_PARENT; struct arm_smmu_domain *smmu_domain; int ret; @@ -3116,6 +3117,14 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, if (!smmu_domain) return ERR_PTR(-ENOMEM); + if (flags & IOMMU_HWPT_ALLOC_NEST_PARENT) { + if (!(master->smmu->features & ARM_SMMU_FEAT_TRANS_S2)) { + ret = -EOPNOTSUPP; + goto err_free; + } + smmu_domain->stage = ARM_SMMU_DOMAIN_S2; + } + smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED; smmu_domain->domain.ops = arm_smmu_ops.default_domain_ops; ret = arm_smmu_domain_finalise(smmu_domain, master->smmu, flags); From patchwork Tue Aug 6 23:41:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755511 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 C049EC52D6F for ; Tue, 6 Aug 2024 23:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=mo2Q5pdm1DdrPQ+FTWWBO7OGIkGdgEa++hYa2Vljj6w=; b=QNun2PTQTqAMxpItx+W3KpS9X/ UpVRSEaa4ptOtGVDLRQUajjk0SFpHGIdzMcVIgkLOHfC90uZ43tr9mQJyvs6S+ddshMQ2Q1QFGDay j9l9NDRHV5/+BfHJe9zpLreQAqbLlhimOeAgSFAcQzxrGTIjfLHxHRgTiUjEjDfy9W2setuPV1H8X AA33z880NTdUoH1BnOOfs61odClVxayqEgXcRWFfPMnekPFmmBy+qGxolH/aK4v6ubLW3rZQ9O75c SDUTHENbS/XMnJZhx8ZKX2UmfO1uEo0F4Ygn1Vt67fpQxpnj7Hzxlqgng1DtFk6AHsimxIMl85cgH jbYsRWzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTrb-00000003MUs-1mrk; Tue, 06 Aug 2024 23:45:11 +0000 Received: from mail-mw2nam10on2061c.outbound.protection.outlook.com ([2a01:111:f403:2412::61c] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTo9-00000003LjQ-3DDu for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hnmElfbtV8ye05VHpIaj//ehPbYeWaNIznVfzmHMz9pSqTHO7QUlWFv9rYOQzQz8kO7406APCMaYq8UURB+8vIPI8OSEX/YYxoGu3ASLb0ARoA5Et0fclPldp87VLzQXNMB4u0QjHTA0xLSzKimD39M/T2H6nA2WYilwBYOFy15oV5G7P62GF3Da/MF0m6xEaoyoutI5DBjI24TJQ62Nx2vxsQn/SEdscIx7l/df2V4j0IAX/0lePC+ACFSVKKGtTou6cC9Zbzu58Sl4XUY2CKLzb0osTKzE69v/0BFjjscVS0CxpEAHL3RPCfiFAjO1rzSKzLOCly9ci4trSMUSkA== 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=mo2Q5pdm1DdrPQ+FTWWBO7OGIkGdgEa++hYa2Vljj6w=; b=ZwOlGu9VZJVPcuut6oJyzeRGFl3yFWBuu/nnuWMzelk/hexvqAvtDMDeljHaIDwkw0a+LyT+TrUE7lNQEhqoWr+JIz51moPII1QmT0Z7WV4XtUF7qHfp/vgmt8gKOHCzZELYq+358yzDkx2dRgTu/i8orJ6o+MbmvIJeVCp9Qp+FSfmh40Z7GCYr6JuJ2yreV0H0CHDZL2hcHyJ9DwTlDJpVdBLMuMKbzH1LdLTO01gFB12JWCdlhPLWecqDiLxnGzxJ8R1fQxEtPGPvLJg3JIOf8i4wGw6BdRnQe7B3w3JVqdzxAZ+KSnEL1wovDBkQGb/Syz7IF8mI6zqgJaraxg== 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=mo2Q5pdm1DdrPQ+FTWWBO7OGIkGdgEa++hYa2Vljj6w=; b=d1hzAf/1sc9DEX+4BGJzMglMV/LlnPe9hkOscuYXC0zPTRDljRqSs0pvIDPM1OWpvOn+0/xqr844sZ5kmBwuOALZeRykaxbKO6yRRSRqy9dT7qLgr2216SK49KNJvxoep+fJg/xPjZQuLW9ctQXImvtJf9NWT37t89gZu87Bnf1GbnuSWBwLJKUq+4vmewQ7/TTHS1nDxoXK/fXoC6dnsAdPsEwMbun8q5nnkYRp+QndikAJDefF/ETr/g67BW0/h4YWa8vEVtwMLD6LGvlkp3VlfMIZIT10hyBJ/wy7PbrWUFB95j6NkoWQeyuS9vvupyh+uu+DYQlFm/l6eoQ/FQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:27 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:27 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 7/8] iommu/arm-smmu-v3: Support IOMMU_DOMAIN_NESTED Date: Tue, 6 Aug 2024 20:41:20 -0300 Message-ID: <7-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0987.namprd03.prod.outlook.com (2603:10b6:408:109::32) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: 400cba6c-8055-40d0-84c8-08dcb6714840 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: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ZMWz8dKsN3QZVIXHiTZQFQmnMcwaIicxe0PCtkGbnOXDUOtfnX8dx0/1okgVeQKO5D9A0kIV/w+o0Mj0K2rgbAAxibotVpU8ghs4pHryetrp89p0qP+dJLK+7qBJCMqN6ht55sahwMYP5oTka9CJHZNgTBobm8O5ltftVTs0EzuJqEc5I1/g++aBrACSUOvwmyrza/VYrRQ1PgDzAVP0KjE+Kpt8hhlUEPV3MuRl/D160l3xbucDmSTmZ9Qn/bK9Dc6rtGOlvqQsUxFnhZiPhHt61zwpe8EGKMuJLamheitgc6YxJpkEXkiQAfevVjDjyKnJWu/K1MaNnmIgZvCW1BN9xgAh/6bl9YuDbJtRIRv0lIQIx/Vh3m8UU7EePgu6tFwIIZNiPagE6w6pdDAzNn8Mi/Nqnsv9L X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HrGEFV6yAk6YanW9AtbZViZB2HmSgeGVbve9vyGYj3+JnXRVy39i6dhmRjuK4ji+AqVLbY5tSu38fLlxguU2eCszXHipOsnVIe28sQTC8J6X4uF7FGkXU2XP/w8CkWmeRmMxcLNljFoX81o2eYUdApywt3hr3vcAgIbRD9C1ZzgoRRXWKktO7AVoHQS9mn8hF6ala+fkalQE5+jntgni05IkY6aeosJqkPm9bF6wHUBYmLZHaOTr3DJEXuyRtOe1Yz4a1CVl91I3Ck5QODYscO7YvpvN272w1DMr6gHtCZUNdEz+3Mi1VjwKM8urj5sszLO19Z8h9iA4MPIntem1sMFbNyqC8p+OeD0PZzmXGsjJ9U9NN8lj4CkjEOULZaABWikDCXkN4v6qq4A5FUJV4R+AFLHTerrt5H9Fx+M69cc/zlvd+gFkgiYwL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fVeTb4t0VyAi8JsaQd2oicYi8BFq7pqHa2qRgGzZ0k3bKULVfe2JFI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 400cba6c-8055-40d0-84c8-08dcb6714840 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:24.1804 (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: kWOkmsdZHp0AE/+4O+p2T3ZcU6JvkwDU51lDMMkYkESaoyK0ECkX6p3OMetbZGQD X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164137_871047_4771CA5F X-CRM114-Status: GOOD ( 23.13 ) 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 For SMMUv3 a IOMMU_DOMAIN_NESTED is composed of a S2 iommu_domain acting as the parent and a user provided STE fragment that defines the CD table and related data with addresses translated by the S2 iommu_domain. The kernel only permits userspace to control certain allowed bits of the STE that are safe for user/guest control. IOTLB maintenance is a bit subtle here, the S1 implicitly includes the S2 translation, but there is no way of knowing which S1 entries refer to a range of S2. For the IOTLB we follow ARM's guidance and issue a CMDQ_OP_TLBI_NH_ALL to flush all ASIDs from the VMID after flushing the S2 on any change to the S2. Similarly we have to flush the entire ATC if the S2 is changed. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 211 +++++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 20 ++ include/uapi/linux/iommufd.h | 20 ++ 3 files changed, 247 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 5faaccef707ef1..5dbaffd7937747 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -295,6 +295,7 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) case CMDQ_OP_TLBI_NH_ASID: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_ASID, ent->tlbi.asid); fallthrough; + case CMDQ_OP_TLBI_NH_ALL: case CMDQ_OP_TLBI_S12_VMALL: cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); break; @@ -1640,6 +1641,59 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, } EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_s2_domain_ste); +static void arm_smmu_make_nested_cd_table_ste( + struct arm_smmu_ste *target, struct arm_smmu_master *master, + struct arm_smmu_nested_domain *nested_domain, bool ats_enabled) +{ + arm_smmu_make_s2_domain_ste(target, master, nested_domain->s2_parent, + ats_enabled); + + target->data[0] = cpu_to_le64(STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, + STRTAB_STE_0_CFG_NESTED)) | + (nested_domain->ste[0] & ~STRTAB_STE_0_CFG); + target->data[1] |= nested_domain->ste[1]; +} + +/* + * Create a physical STE from the virtual STE that userspace provided when it + * created the nested domain. Using the vSTE userspace can request: + * - Non-valid STE + * - Abort STE + * - Bypass STE (install the S2, no CD table) + * - CD table STE (install the S2 and the userspace CD table) + */ +static void arm_smmu_make_nested_domain_ste( + struct arm_smmu_ste *target, struct arm_smmu_master *master, + struct arm_smmu_nested_domain *nested_domain, bool ats_enabled) +{ + /* + * Userspace can request a non-valid STE through the nesting interface. + * We relay that into a non-valid physical STE with the intention that + * C_BAD_STE for this SID can be delivered to userspace. + */ + if (!(nested_domain->ste[0] & cpu_to_le64(STRTAB_STE_0_V))) { + memset(target, 0, sizeof(*target)); + return; + } + + switch (FIELD_GET(STRTAB_STE_0_CFG, + le64_to_cpu(nested_domain->ste[0]))) { + case STRTAB_STE_0_CFG_S1_TRANS: + arm_smmu_make_nested_cd_table_ste(target, master, nested_domain, + ats_enabled); + break; + case STRTAB_STE_0_CFG_BYPASS: + arm_smmu_make_s2_domain_ste( + target, master, nested_domain->s2_parent, ats_enabled); + break; + case STRTAB_STE_0_CFG_ABORT: + default: + arm_smmu_make_abort_ste(target); + break; + } +} + /* * This can safely directly manipulate the STE memory without a sync sequence * because the STE table has not been installed in the SMMU yet. @@ -2065,7 +2119,16 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, if (!master->ats_enabled) continue; - arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, &cmd); + if (master_domain->nested_parent) { + /* + * If a S2 used as a nesting parent is changed we have + * no option but to completely flush the ATC. + */ + arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, &cmd); + } else { + arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, + &cmd); + } for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; @@ -2192,6 +2255,16 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, } __arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S2 && + smmu_domain->nesting_parent) { + /* + * When the S2 domain changes all the nested S1 ASIDs have to be + * flushed too. + */ + cmd.opcode = CMDQ_OP_TLBI_NH_ALL; + arm_smmu_cmdq_issue_cmd_with_sync(smmu_domain->smmu, &cmd); + } + /* * Unfortunately, this can't be leaf-only since we may have * zapped an entire table. @@ -2608,13 +2681,15 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, ioasid_t ssid) { struct arm_smmu_master_domain *master_domain; + bool nested_parent = smmu_domain->domain.type == IOMMU_DOMAIN_NESTED; lockdep_assert_held(&smmu_domain->devices_lock); list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { if (master_domain->master == master && - master_domain->ssid == ssid) + master_domain->ssid == ssid && + master_domain->nested_parent == nested_parent) return master_domain; } return NULL; @@ -2634,6 +2709,9 @@ to_smmu_domain_devices(struct iommu_domain *domain) if ((domain->type & __IOMMU_DOMAIN_PAGING) || domain->type == IOMMU_DOMAIN_SVA) return to_smmu_domain(domain); + if (domain->type == IOMMU_DOMAIN_NESTED) + return container_of(domain, struct arm_smmu_nested_domain, + domain)->s2_parent; return NULL; } @@ -2664,6 +2742,7 @@ struct arm_smmu_attach_state { struct iommu_domain *old_domain; struct arm_smmu_master *master; bool cd_needs_ats; + bool disable_ats; ioasid_t ssid; /* Resulting state */ bool ats_enabled; @@ -2716,7 +2795,8 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * enabled if we have arm_smmu_domain, those always have page * tables. */ - state->ats_enabled = arm_smmu_ats_supported(master); + state->ats_enabled = !state->disable_ats && + arm_smmu_ats_supported(master); } if (smmu_domain) { @@ -2725,6 +2805,8 @@ static int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, return -ENOMEM; master_domain->master = master; master_domain->ssid = state->ssid; + master_domain->nested_parent = new_domain->type == + IOMMU_DOMAIN_NESTED; /* * During prepare we want the current smmu_domain and new @@ -3097,6 +3179,122 @@ static struct iommu_domain arm_smmu_blocked_domain = { .ops = &arm_smmu_blocked_ops, }; +static int arm_smmu_attach_dev_nested(struct iommu_domain *domain, + struct device *dev) +{ + struct arm_smmu_nested_domain *nested_domain = + container_of(domain, struct arm_smmu_nested_domain, domain); + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_attach_state state = { + .master = master, + .old_domain = iommu_get_domain_for_dev(dev), + .ssid = IOMMU_NO_PASID, + /* Currently invalidation of ATC is not supported */ + .disable_ats = true, + }; + struct arm_smmu_ste ste; + int ret; + + if (arm_smmu_ssids_in_use(&master->cd_table) || + nested_domain->s2_parent->smmu != master->smmu) + return -EINVAL; + + mutex_lock(&arm_smmu_asid_lock); + ret = arm_smmu_attach_prepare(&state, domain); + if (ret) { + mutex_unlock(&arm_smmu_asid_lock); + return ret; + } + + arm_smmu_make_nested_domain_ste(&ste, master, nested_domain, + state.ats_enabled); + arm_smmu_install_ste_for_dev(master, &ste); + arm_smmu_attach_commit(&state); + mutex_unlock(&arm_smmu_asid_lock); + return 0; +} + +static void arm_smmu_domain_nested_free(struct iommu_domain *domain) +{ + kfree(container_of(domain, struct arm_smmu_nested_domain, domain)); +} + +static const struct iommu_domain_ops arm_smmu_nested_ops = { + .attach_dev = arm_smmu_attach_dev_nested, + .free = arm_smmu_domain_nested_free, +}; + +static struct iommu_domain * +arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, + struct iommu_domain *parent, + const struct iommu_user_data *user_data) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct arm_smmu_nested_domain *nested_domain; + struct arm_smmu_domain *smmu_parent; + struct iommu_hwpt_arm_smmuv3 arg; + unsigned int eats; + unsigned int cfg; + int ret; + + if (!(master->smmu->features & ARM_SMMU_FEAT_NESTING)) + return ERR_PTR(-EOPNOTSUPP); + + /* + * Must support some way to prevent the VM from bypassing the cache + * because VFIO currently does not do any cache maintenance. + */ + if (!(fwspec->flags & IOMMU_FWSPEC_PCI_RC_CANWBS) && + !(master->smmu->features & ARM_SMMU_FEAT_S2FWB)) + return ERR_PTR(-EOPNOTSUPP); + + ret = iommu_copy_struct_from_user(&arg, user_data, + IOMMU_HWPT_DATA_ARM_SMMUV3, ste); + if (ret) + return ERR_PTR(ret); + + if (flags || !(master->smmu->features & ARM_SMMU_FEAT_TRANS_S1)) + return ERR_PTR(-EOPNOTSUPP); + + if (!(parent->type & __IOMMU_DOMAIN_PAGING)) + return ERR_PTR(-EINVAL); + + smmu_parent = to_smmu_domain(parent); + if (smmu_parent->stage != ARM_SMMU_DOMAIN_S2 || + smmu_parent->smmu != master->smmu) + return ERR_PTR(-EINVAL); + + /* EIO is reserved for invalid STE data. */ + if ((arg.ste[0] & ~STRTAB_STE_0_NESTING_ALLOWED) || + (arg.ste[1] & ~STRTAB_STE_1_NESTING_ALLOWED)) + return ERR_PTR(-EIO); + + cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(arg.ste[0])); + if (cfg != STRTAB_STE_0_CFG_ABORT && cfg != STRTAB_STE_0_CFG_BYPASS && + cfg != STRTAB_STE_0_CFG_S1_TRANS) + return ERR_PTR(-EIO); + + eats = FIELD_GET(STRTAB_STE_1_EATS, le64_to_cpu(arg.ste[1])); + if (eats != STRTAB_STE_1_EATS_ABT) + return ERR_PTR(-EIO); + + if (cfg != STRTAB_STE_0_CFG_S1_TRANS) + eats = STRTAB_STE_1_EATS_ABT; + + nested_domain = kzalloc(sizeof(*nested_domain), GFP_KERNEL_ACCOUNT); + if (!nested_domain) + return ERR_PTR(-ENOMEM); + + nested_domain->domain.type = IOMMU_DOMAIN_NESTED; + nested_domain->domain.ops = &arm_smmu_nested_ops; + nested_domain->s2_parent = smmu_parent; + nested_domain->ste[0] = arg.ste[0]; + nested_domain->ste[1] = arg.ste[1] & ~cpu_to_le64(STRTAB_STE_1_EATS); + + return &nested_domain->domain; +} + static struct iommu_domain * arm_smmu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, @@ -3108,9 +3306,13 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, struct arm_smmu_domain *smmu_domain; int ret; + if (parent) + return arm_smmu_domain_alloc_nesting(dev, flags, parent, + user_data); + if (flags & ~PAGING_FLAGS) return ERR_PTR(-EOPNOTSUPP); - if (parent || user_data) + if (user_data) return ERR_PTR(-EOPNOTSUPP); smmu_domain = arm_smmu_domain_alloc(); @@ -3123,6 +3325,7 @@ arm_smmu_domain_alloc_user(struct device *dev, u32 flags, goto err_free; } smmu_domain->stage = ARM_SMMU_DOMAIN_S2; + smmu_domain->nesting_parent = true; } smmu_domain->domain.type = IOMMU_DOMAIN_UNMANAGED; 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 58cd405652e06a..e149eddb568e7e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -240,6 +240,7 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) #define STRTAB_STE_0_CFG_BYPASS 4 #define STRTAB_STE_0_CFG_S1_TRANS 5 #define STRTAB_STE_0_CFG_S2_TRANS 6 +#define STRTAB_STE_0_CFG_NESTED 7 #define STRTAB_STE_0_S1FMT GENMASK_ULL(5, 4) #define STRTAB_STE_0_S1FMT_LINEAR 0 @@ -291,6 +292,15 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) #define STRTAB_STE_3_S2TTB_MASK GENMASK_ULL(51, 4) +/* These bits can be controlled by userspace for STRTAB_STE_0_CFG_NESTED */ +#define STRTAB_STE_0_NESTING_ALLOWED \ + cpu_to_le64(STRTAB_STE_0_V | STRTAB_STE_0_CFG | STRTAB_STE_0_S1FMT | \ + STRTAB_STE_0_S1CTXPTR_MASK | STRTAB_STE_0_S1CDMAX) +#define STRTAB_STE_1_NESTING_ALLOWED \ + 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_EATS) + /* * Context descriptors. * @@ -508,6 +518,7 @@ struct arm_smmu_cmdq_ent { }; } cfgi; + #define CMDQ_OP_TLBI_NH_ALL 0x10 #define CMDQ_OP_TLBI_NH_ASID 0x11 #define CMDQ_OP_TLBI_NH_VA 0x12 #define CMDQ_OP_TLBI_EL2_ALL 0x20 @@ -792,6 +803,14 @@ struct arm_smmu_domain { u8 enforce_cache_coherency; struct mmu_notifier mmu_notifier; + bool nesting_parent : 1; +}; + +struct arm_smmu_nested_domain { + struct iommu_domain domain; + struct arm_smmu_domain *s2_parent; + + __le64 ste[2]; }; /* The following are exposed for testing purposes. */ @@ -830,6 +849,7 @@ struct arm_smmu_master_domain { struct list_head devices_elm; struct arm_smmu_master *master; ioasid_t ssid; + u8 nested_parent; }; static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 83b6e1cd338d8f..76e9ad6c9403af 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -394,14 +394,34 @@ struct iommu_hwpt_vtd_s1 { __u32 __reserved; }; +/** + * struct iommu_hwpt_arm_smmuv3 - ARM SMMUv3 Context Descriptor Table info + * (IOMMU_HWPT_DATA_ARM_SMMUV3) + * + * @ste: The first two double words of the user space Stream Table Entry for + * a user stage-1 Context Descriptor Table. Must be little-endian. + * Allowed fields: (Refer to "5.2 Stream Table Entry" in SMMUv3 HW Spec) + * - word-0: V, Cfg, S1Fmt, S1ContextPtr, S1CDMax + * - word-1: S1DSS, S1CIR, S1COR, S1CSH, S1STALLD + * + * -EIO will be returned if @ste is not legal or contains any non-allowed field. + * Cfg can be used to select a S1, Bypass or Abort configuration. A Bypass + * nested domain will translate the same as the nesting parent. + */ +struct iommu_hwpt_arm_smmuv3 { + __aligned_le64 ste[2]; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table + * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE = 0, IOMMU_HWPT_DATA_VTD_S1 = 1, + IOMMU_HWPT_DATA_ARM_SMMUV3 = 2, }; /** From patchwork Tue Aug 6 23:41:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755510 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 4873BC52D6F for ; Tue, 6 Aug 2024 23:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=ATd2/dJfb5LCjxN+vqopITDXIqcNP6eKdl6pnEmq/zA=; b=ycf/cAQ1ar9BcSobTZcs868AZR 1/xroycIBjknNtpbtJHrdD+bixNabeOaskuXSDbGewoILFsmTQOf9vWnm2lMgEdczaqJN/tTEBVAG 2fiYDIqe8buW8TWgX07wfWzPTv23jX+0IXJU8zRib1QrEH8h7oMIRKV4rYgK6hRGedFc/R/esg7KZ t1Pm71M/NR/6r1+GDW4yiwTik7jGu5YP0fIIstxUMtMKmX3d/kyczJnz+SmzbO8TEoVpSecUudvFo zk8Y+HH9CBdPdaP4YtTohaXpcjeMUN/CosiONkV41opHzwZz4GPbLtUeFkSjw3I0uygzasu+XOSc1 5iqwY8+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTr6-00000003MPp-3xyC; Tue, 06 Aug 2024 23:44:40 +0000 Received: from mail-mw2nam10on2062d.outbound.protection.outlook.com ([2a01:111:f403:2412::62d] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTo8-00000003Li5-1Zra for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:41:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lHUtxsW/TuLgHxFb9YnnBnBmxTeUDemNOOirnLBgz4rzv2f4/o74iPcyw5U4bDezE1Kmj5dkLN+9+Dscb+Q+jaaTAc7s6XeFpE7+GQX4H2oY9mwOmpxyPyJ46pc0ZaldKsVl3JM6vqnyK/TmU0SWPu0/wXGAqadqKqSVvV7nyRFvY5SpI/ZvOsSit/tacrKyYsZRFkVdZFw1VzOWZXIBgdFXiZQXObAnjWWnchSbnfCdjo5+y9T2OsKexAT1CDYBbHT+O84mV8ZvulUs7pkQPo/ivy7AlfwyRI2YucM/nk2kkIAVox8DGdfift9sMaE6SqNnexy0biNS2LM87v4Jvg== 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=ATd2/dJfb5LCjxN+vqopITDXIqcNP6eKdl6pnEmq/zA=; b=qi6dLnhkE8WzuwzRkF2R1p/xddshAfK7JUSzuLQouZtL7VzWN8RgOmeLSdjC+XQrJfTcvYApahKlZKhV9BGeCDDtiKDDj0ugaBfb+Gc+AvKUYGguitqZsiLFWOAlJuCNCf45hZVGvjNrrrkTnyfdeQ3C4AXV4CTnLiQCOyjUDYhInRj6xAq+75y9vjqrutNP2BGdwOkFnI28ccJVREg97wMc6pVMI8hSGcU0Pds5TkiiY2Hher3sB+kmy6FYybdyiDKp4uF2Tk3/omPliNuL5VG4K0LuUzYemdOWiVxDyo57ZnpIWWw0+DKhNYUURPHh4xDKEl0t/uN3CwCPNqYBQg== 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=ATd2/dJfb5LCjxN+vqopITDXIqcNP6eKdl6pnEmq/zA=; b=XRkCrI2FLWpIr/v/KiBmm8uUqai9D9kQmJ431Lku4LF0/MPhP7L3Aplvyd3iGBeTc1PwIChNmsyaDrT2nzon4JSIFkoz/U24+zCojYNyf2AZ2TXxlvzxdvFCFRwOfGh2tyXHL4ztq0IXW/98EIzai5UeTmFqqxFLhE0sWu6j93U34aQ/L5f8G17ILYK0HFCk4z99ygqaWJio3orln8AXI1jvuoMQmpZW64LO6p2bNKC6TmFYXA0aUHqBmvfGsSgCEGe8wLe1m4zFgH/TkPx0FQulZy6OqpdztNjEMQ5didaXAgMlrnusmgbvNlA26ToHZIQwPHImOsgih1tAy5qEeA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by DS0PR12MB9422.namprd12.prod.outlook.com (2603:10b6:8:1bb::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 23:41:26 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:41:26 +0000 From: Jason Gunthorpe To: acpica-devel@lists.linux.dev, Alex Williamson , Hanjun Guo , 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: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH 8/8] iommu/arm-smmu-v3: Add arm_smmu_cache_invalidate_user Date: Tue, 6 Aug 2024 20:41:21 -0300 Message-ID: <8-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> In-Reply-To: <0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com> References: X-ClientProxiedBy: BN7PR06CA0045.namprd06.prod.outlook.com (2603:10b6:408:34::22) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|DS0PR12MB9422:EE_ X-MS-Office365-Filtering-Correlation-Id: 3aff12e2-947e-4b08-e972-08dcb671480f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014|921020; X-Microsoft-Antispam-Message-Info: 9jKFeSudMMsVXqZk+GBRiIbXyKjZLakjdIaDudSrvx92ynIusOXB24jna+F/cjaOyNXbtk7tHKJQCZ5TXHlG3Eu7MrNT2rTQA8BV77BEfi9cr5fJQ1Dg20XXBwneniR6dt5yhg0mM9S1VDxLyhDWrywTObbTEfZ0QWverVpw/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oNgZ6Jq6S6/Cisxwb0K6q1HYZM3/HOqXc/dVJDIKe6rariOR//fwaGQu+Ls2gO758+P/sVwuksXox6BMyGNf3s5JlqbI+IHsl8syceRLqkgG0jmjI8ER2HwHUSZi8wcNnBXgf7NkCo6dKqt4bvXhaiFcga6kI6XVdYV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(366016)(376014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GRzcTFent6MHQlRH6HsiI42j15rKQ251AXJ7PmQhEM1goCZBZZg/5/z/YFm5Vt6XwclfAqXRLrZNxhnveqZCu4ibNYSxLWVNKyXI/pxPrk5w2OeZ6GPYnsfUUxwRRjqPKxyfL7aET1/kW6Lp3hgzH6uGyG4jLUaMzPWw9q8C9ZmZXuumBDNnCiulf8Sd7xoNQja/zqRJbsX6Q4NsSKGI73gn+NpqO3Pgsoa3PaHjNEkI/cUgej59mekiCuy/1Mgzdd3xmqIXx+ytn7UXN3mH5upzxMYmC4K+h1H0Ou1Nb3dipPIFn8liDvPkx8qIO24QiSiskSJ6TuEpAwIJcI51wmMHr4WTf6Zy0aMKNPxL+Q5itcIyGIfUzafEG8I3pXCzDzcOGwzq0jNTvLxvWqYnuIZjOsRPblQxUq0r12ya2QVeI5S0xnfr5vhdO8uWZ8tZEpK8UapL5ftXXyeyRg1jMt3r5zLG7J2kcXEtVxo3sg4qrizqZbBgWoSSYVBQI+zXHbP8J93EN01fPd5vWqXammgoE+v0NjFBIDyGylGJyyn65jHYQCM/NTU5X2XQkeXq4z88yCctZWCM41cpnNrlngqukwM+Z+3VBavJe0SgseHA11W7Ju/xXhhjxMZbMBTtAuzo1PQc5zYRW+pNN+G34ZAHFjyc3ITIgL0f4Al7mPDa680Za+3mriqeBc/Zt/Cls0FLWOaKVRDYKTGlhHebSsHS8xRVLzTmr0HTSEBzOIRF7Q8u1691k/HQtsuINJ67vsnu+y4SXe0wP6Rwsej1MJNSVDRKsn9lVE0YtkE9vTQgcohVzqGw0+7pP2xgo1SwLovdnPuxY7u7PBywDksLSoDqdiwQ/xMZC0EIEAwkZESNRLFKh6/srmUiIGNbh/oAMHMQP7crTX0nQ6goAxBj8p6kb8+rIh5hSeFTnn/kZN4klezEBQH95Mh7POgaEMynqWdoo0LnRBGbJRC1+p0YOzHBTZQFGqPHCbr1sFTO2FoWwGgjvVuozhmKX3YIm+ZLICCpHInldPbxOmhOj4jG1gmndxJqXGhF+MbB2E2F8xXPduQN+Nb9RdAM0Mtaa5BMLPuCgP6+33rb2R859bh8SxLjAC+DQrI8TlkaTQWZ1f2UY9uvxBGsy20tJMqMB151WZFXiyj2JqRS/ezSFJH2ULPMsqDFGAOxpjwiO0pBPssfhhCbE7kX9JznGYcM8nVfUwRd8Gg3hXgRE+wss0GwIHKKlq/U+zAaxha60VsQLI+TsUBvfkTlfjVPq+j9w/mnVFOYyXZtwuw5wp1p1ept8f6vzJ8kp3mBXweGEyB3qzPE7Kg1igAn0hj9rgkS+f9d7E/ZFOjnI8BJO5TaY3X7/KCCNwbqT0h+lv5l3E8hixs/Ns34TB+Ju4+4Fjw4Ztl3VdvskQm+LDQRPWSC+KCOhqptugj92jcJreuTmFrb39/TiwVTDmfHovzchueCgRyGoPi2U7yOzcAtQbDOnRwVuTKvo7Ufywjjd1CxLkhpZ/L+M2ySp90/PXJKhxFmwy+D5E7Iyak5HmAOfm7fg6Qvwqti+8KxM2PLQ7jLAXRwJxA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3aff12e2-947e-4b08-e972-08dcb671480f X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:41:23.8126 (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: dKDVKFCkw4Exm/pIcXxfgDHo5MpnFsc54c0wcVzRsJvzJNtay3mRnPu85Ku1+YLa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9422 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_164136_563920_C64D2D12 X-CRM114-Status: GOOD ( 21.74 ) 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 From: Nicolin Chen Add arm_smmu_cache_invalidate_user() function for user space to invalidate IOTLB entries that are still cached by the hardware. Add struct iommu_hwpt_arm_smmuv3_invalidate defining an invalidation entry that is simply the native format of a 128-bit TLBI command. Scan commands against the permitted command list and fix their VMID fields. Co-developed-by: Eric Auger Signed-off-by: Eric Auger Signed-off-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 95 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + include/linux/iommu.h | 49 ++++++++++- include/uapi/linux/iommufd.h | 24 ++++++ 4 files changed, 168 insertions(+), 1 deletion(-) 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 5dbaffd7937747..24836f3269b3f4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3219,9 +3219,96 @@ static void arm_smmu_domain_nested_free(struct iommu_domain *domain) kfree(container_of(domain, struct arm_smmu_nested_domain, domain)); } +/* + * Convert, in place, the raw invalidation command into an internal format that + * can be passed to arm_smmu_cmdq_issue_cmdlist(). Internally commands are + * stored in CPU endian. + * + * Enforce the VMID on the command. + */ +static int +arm_smmu_convert_user_cmd(struct arm_smmu_nested_domain *nested_domain, + struct iommu_hwpt_arm_smmuv3_invalidate *cmd) +{ + u16 vmid = nested_domain->s2_parent->s2_cfg.vmid; + + cmd->cmd[0] = le64_to_cpu(cmd->cmd[0]); + cmd->cmd[1] = le64_to_cpu(cmd->cmd[1]); + + switch (cmd->cmd[0] & CMDQ_0_OP) { + case CMDQ_OP_TLBI_NSNH_ALL: + /* Convert to NH_ALL */ + cmd->cmd[0] = CMDQ_OP_TLBI_NH_ALL | + FIELD_PREP(CMDQ_TLBI_0_VMID, vmid); + cmd->cmd[1] = 0; + break; + case CMDQ_OP_TLBI_NH_VA: + case CMDQ_OP_TLBI_NH_VAA: + case CMDQ_OP_TLBI_NH_ALL: + case CMDQ_OP_TLBI_NH_ASID: + cmd->cmd[0] &= ~CMDQ_TLBI_0_VMID; + cmd->cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, vmid); + break; + default: + return -EIO; + } + return 0; +} + +static int arm_smmu_cache_invalidate_user(struct iommu_domain *domain, + struct iommu_user_data_array *array) +{ + struct arm_smmu_nested_domain *nested_domain = + container_of(domain, struct arm_smmu_nested_domain, domain); + struct arm_smmu_device *smmu = nested_domain->s2_parent->smmu; + struct iommu_hwpt_arm_smmuv3_invalidate *last_batch; + struct iommu_hwpt_arm_smmuv3_invalidate *cmds; + struct iommu_hwpt_arm_smmuv3_invalidate *cur; + struct iommu_hwpt_arm_smmuv3_invalidate *end; + int ret; + + cmds = kcalloc(array->entry_num, sizeof(*cmds), GFP_KERNEL); + if (!cmds) + return -ENOMEM; + cur = cmds; + end = cmds + array->entry_num; + + static_assert(sizeof(*cmds) == 2 * sizeof(u64)); + ret = iommu_copy_struct_from_full_user_array( + cmds, sizeof(*cmds), array, + IOMMU_HWPT_INVALIDATE_DATA_ARM_SMMUV3); + if (ret) + goto out; + + last_batch = cmds; + while (cur != end) { + ret = arm_smmu_convert_user_cmd(nested_domain, cur); + if (ret) + goto out; + + /* FIXME work in blocks of CMDQ_BATCH_ENTRIES and copy each block? */ + cur++; + if (cur != end && (cur - last_batch) != CMDQ_BATCH_ENTRIES - 1) + continue; + + ret = arm_smmu_cmdq_issue_cmdlist(smmu, last_batch->cmd, + cur - last_batch, true); + if (ret) { + cur--; + goto out; + } + last_batch = cur; + } +out: + array->entry_num = cur - cmds; + kfree(cmds); + return ret; +} + static const struct iommu_domain_ops arm_smmu_nested_ops = { .attach_dev = arm_smmu_attach_dev_nested, .free = arm_smmu_domain_nested_free, + .cache_invalidate_user = arm_smmu_cache_invalidate_user, }; static struct iommu_domain * @@ -3249,6 +3336,14 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, !(master->smmu->features & ARM_SMMU_FEAT_S2FWB)) return ERR_PTR(-EOPNOTSUPP); + /* + * FORCE_SYNC is not set with FEAT_NESTING. Some study of the exact HW + * defect is needed to determine if arm_smmu_cache_invalidate_user() + * needs any change to remove this. + */ + if (WARN_ON(master->smmu->options & ARM_SMMU_OPT_CMDQ_FORCE_SYNC)) + return ERR_PTR(-EOPNOTSUPP); + ret = iommu_copy_struct_from_user(&arg, user_data, IOMMU_HWPT_DATA_ARM_SMMUV3, ste); if (ret) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index e149eddb568e7e..3f7442f0167efb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -521,6 +521,7 @@ struct arm_smmu_cmdq_ent { #define CMDQ_OP_TLBI_NH_ALL 0x10 #define CMDQ_OP_TLBI_NH_ASID 0x11 #define CMDQ_OP_TLBI_NH_VA 0x12 + #define CMDQ_OP_TLBI_NH_VAA 0x13 #define CMDQ_OP_TLBI_EL2_ALL 0x20 #define CMDQ_OP_TLBI_EL2_ASID 0x21 #define CMDQ_OP_TLBI_EL2_VA 0x22 diff --git a/include/linux/iommu.h b/include/linux/iommu.h index d1660ec23f263b..b0323290cb6c72 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -491,7 +491,9 @@ static inline int __iommu_copy_struct_from_user_array( * @index: Index to the location in the array to copy user data from * @min_last: The last member of the data structure @kdst points in the * initial version. - * Return 0 for success, otherwise -error. + * + * Copy a single entry from a user array. Return 0 for success, otherwise + * -error. */ #define iommu_copy_struct_from_user_array(kdst, user_array, data_type, index, \ min_last) \ @@ -499,6 +501,51 @@ static inline int __iommu_copy_struct_from_user_array( kdst, user_array, data_type, index, sizeof(*(kdst)), \ offsetofend(typeof(*(kdst)), min_last)) + +/** + * iommu_copy_struct_from_full_user_array - Copy iommu driver specific user + * space data from an iommu_user_data_array + * @kdst: Pointer to an iommu driver specific user data that is defined in + * include/uapi/linux/iommufd.h + * @kdst_entry_size: sizeof(*kdst) + * @user_array: Pointer to a struct iommu_user_data_array for a user space + * array + * @data_type: The data type of the @kdst. Must match with @user_array->type + * + * Copy the entire user array. kdst must have room for kdst_entry_size * + * user_array->entry_num bytes. Return 0 for success, otherwise -error. + */ +static inline int +iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size, + struct iommu_user_data_array *user_array, + unsigned int data_type) +{ + unsigned int i; + int ret; + + if (user_array->type != data_type) + return -EINVAL; + if (!user_array->entry_num) + return -EINVAL; + if (likely(user_array->entry_len == kdst_entry_size)) { + if (copy_from_user(kdst, user_array->uptr, + user_array->entry_num * + user_array->entry_len)) + return -EFAULT; + } + + /* Copy item by item */ + for (i = 0; i != user_array->entry_num; i++) { + ret = copy_struct_from_user( + kdst + kdst_entry_size * i, kdst_entry_size, + user_array->uptr + user_array->entry_len * i, + user_array->entry_len); + if (ret) + return ret; + } + return 0; +} + /** * struct iommu_ops - iommu ops and capabilities * @capable: check capability diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 76e9ad6c9403af..f2d1677ddec445 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -682,9 +682,11 @@ struct iommu_hwpt_get_dirty_bitmap { * enum iommu_hwpt_invalidate_data_type - IOMMU HWPT Cache Invalidation * Data Type * @IOMMU_HWPT_INVALIDATE_DATA_VTD_S1: Invalidation data for VTD_S1 + * @IOMMU_HWPT_INVALIDATE_DATA_ARM_SMMUV3: Invalidation data for ARM SMMUv3 */ enum iommu_hwpt_invalidate_data_type { IOMMU_HWPT_INVALIDATE_DATA_VTD_S1 = 0, + IOMMU_HWPT_INVALIDATE_DATA_ARM_SMMUV3 = 1, }; /** @@ -723,6 +725,28 @@ struct iommu_hwpt_vtd_s1_invalidate { __u32 __reserved; }; +/** + * struct iommu_hwpt_arm_smmuv3_invalidate - ARM SMMUv3 cahce invalidation + * (IOMMU_HWPT_INVALIDATE_DATA_ARM_SMMUV3) + * @cmd: 128-bit cache invalidation command that runs in SMMU CMDQ. + * Must be little-endian. + * + * Supported command list: + * CMDQ_OP_TLBI_NSNH_ALL + * CMDQ_OP_TLBI_NH_VA + * CMDQ_OP_TLBI_NH_VAA + * CMDQ_OP_TLBI_NH_ALL + * CMDQ_OP_TLBI_NH_ASID + * + * This API does not support ATS invalidation. Userspace must not request EATS, + * or enable ATS in the IDR. + * + * -EIO will be returned if the command is not supported. + */ +struct iommu_hwpt_arm_smmuv3_invalidate { + __aligned_u64 cmd[2]; +}; + /** * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) * @size: sizeof(struct iommu_hwpt_invalidate)