From patchwork Thu Apr 7 15:23:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12805344 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98D61C433FE for ; Thu, 7 Apr 2022 15:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344609AbiDGP0B (ORCPT ); Thu, 7 Apr 2022 11:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344613AbiDGPZ5 (ORCPT ); Thu, 7 Apr 2022 11:25:57 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2072.outbound.protection.outlook.com [40.107.100.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11558217984 for ; Thu, 7 Apr 2022 08:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dg3cBdiQCDh5WvWmZa014lOJFm6m6y0otozkEJEBwXNUte9HIhtr46XBMhXxJ9yNaIwNnzVi2LJSvZ8dfJmhkVhfRRmatqKZR/AtmF1FxnUavSPmJzUA5Gh87mD4OYeTv7VN6Xz48Jzz2EphhFIBDwf4Pi/lvlRg97B11GWFLuZSNswGQ3u3xVsg/Ofa3V5zyTzGY9SwAwLuyXU5BBV2W1ahnRNaYZtIqJz6A5xR/Au+SE5xRx0xVyv53nTA8m0S9QQ//A0TSaVddX3dT/Ode4iJx6NrGfBbACkfstQ7STqCKXbEN8zZw9x/jwQ4cbS7U1y3wDwEIP/xJzaq23v8oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VSr56/78CZWofxM5sl89INWslKmsLm9oE3hXmYMZxiY=; b=O4t3MataWfGXOyXE5lqBMEWdr/eXosabLthCZbrVltZ4pseOu/qy6CFDWqEF9qg/jxaqZypH00XnYmbh2hnnoFEpfCDBbyCZzu7qBWUClTyDHHX0tLgvhsfiWiBm8Jx5bBz/5OgZC8VBQR7O71N+eaA/YWTeFhvRv19bGaRJUxPxuvbDaiNxj5NZCwYSGGB2rZqK1uRyS1AYcSyERgWqdCGA1gmST6GpJOOEMx5yu/yx6CZ//ASe+Et16RHmrV404xSWD8L8iUcbRQiXvsZzdIm2PXd0rL8g1UoDvW2dYP1LzSdvCaev6V6tYUfFqPZjzCcElkkOO7T8+wy3NjeQVQ== 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=VSr56/78CZWofxM5sl89INWslKmsLm9oE3hXmYMZxiY=; b=bBPKQUpyF9xu5pFod0r1u0J3FmXI2Yoa0CwWoreYAlrTk/lHVmVU+niRHohUu+lVDPErGcki+tyTw7IrP/tdaV3KcabARdvKv6nCwArl6Zzm6EodfSjn5eDAPQiEYiJHpDsUyI6qm4coJV70ZzdDURwjtVS6qIe7yibNzLjeBWRBQeG7mu0zdAZbzvN/s06AS1JK/Vtjo3igOq4eMeFbPeqiNBx4Y5BrGqHWu1yY8Zt+sf1jOUyTdMjzJ3MKI8d5OtLs4urBZcJBwUwK6+GhJb+moBE/UYWcyd05ao8ysYemYf2ozwSRbz8y7q5BPMYXHNSNLEsVXcYQu03djgriiQ== Received: from MN0PR12MB5740.namprd12.prod.outlook.com (2603:10b6:208:373::10) by BYAPR12MB3239.namprd12.prod.outlook.com (2603:10b6:a03:137::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 15:23:50 +0000 Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by MN0PR12MB5740.namprd12.prod.outlook.com (2603:10b6:208:373::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Thu, 7 Apr 2022 15:23:49 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374%6]) with mapi id 15.20.5144.022; Thu, 7 Apr 2022 15:23:49 +0000 From: Jason Gunthorpe To: Alex Williamson , Lu Baolu , Cornelia Huck , David Woodhouse , iommu@lists.linux-foundation.org, Joerg Roedel , kvm@vger.kernel.org, Suravee Suthikulpanit , Will Deacon Cc: Christoph Hellwig , "Tian, Kevin" , Robin Murphy Subject: [PATCH v2 1/4] iommu: Introduce the domain op enforce_cache_coherency() Date: Thu, 7 Apr 2022 12:23:44 -0300 Message-Id: <1-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> In-Reply-To: <0-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0071.namprd03.prod.outlook.com (2603:10b6:610:cc::16) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea97f698-b07a-42da-feba-08da18aa9d51 X-MS-TrafficTypeDiagnostic: MN0PR12MB5740:EE_|BYAPR12MB3239:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4vuhx9RyLIZZIYJ2X3M75svE16UnvmTMeEQnZBDoouqWduI2NTTXEpWoZR6ZOLS38PGGS4klm03107/LBoZbqRmrJ+4B5HJ3VVNAUuFujpNt0KScI7szkIv/R0GIKgol7s91tkfYqSRNuP8Rd25kVlioaELDCQXzGCTVRE1Z4GG9XWePY4Z3kCaYF7Y6OjYZ1GqnG9b3XwSEej4ZGUT22MJht+tQRK9mJ1SrQDzl+NcAclhVuSw3D7KCF0fLXNh+cgFwE8OqVHj5C5im8REeWpjfHoIJCdlZVo+CvuEyZ2XfVyk8t5jmlusdnO5jY5m+wMHmtAlMSSXM3kvsFVNBXG8k9ZdRozq3EhmA8FinRSaxC2kfCxLOTUcNgbO8JmISBWMTpf5Pl8AGa80fKqKHBgMoWiEqzLusexrpd8WVofkwLTk7zt1wdbZNS4rLr3Ru6iMI9hwILZiaHaCBL1LRyDOU4ofisl7VaUDYPp7PY1wgWBT2IVXwwo4i3KPjZROrLJxjJgxGErjyNTxNrZ2QYuKfl0upZGKS79Sl2o8hReV2QTM536P3Amzko4HrIjKuwDWu5nmOO4csUMRIufTc77K1qwrF7YFHA+cCIYNKVxAXfFtranMqxkO6KN84L6hyu8g6JusO1WPA8fV/n1pfx32I/rIRd2FonC8JahcSYP8PDx+h1xWvWgrUDzk8V6Og X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN0PR12MB5740.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6666004)(86362001)(186003)(2906002)(508600001)(38100700002)(26005)(83380400001)(6512007)(6506007)(36756003)(8676002)(4326008)(66946007)(6486002)(66556008)(66476007)(5660300002)(7416002)(54906003)(8936002)(110136005)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CjHg0rznFdSuu29GB6kb6EXrLFxhttelGM8Ake/4Re0pgq15/33MhnWUvSBZo8kdNyno1oW5vtuM9ZjDG2eRRH4wbGirT3eBv23oD8RCjw6SEEbDV+jBcEJ2BdcDtv5kpyBDw7XQ01AWEvlSGrXORzcbkGzOCr+6DebPvEtRFSWsdBw5HGnX49Ail3OJqsSXkTec7cJACe5UVNJd8835I1IzlriFQTZSCs3RG6bN0UwGexw5NisnwmBm88UPi+rt1vB7YYLBmPnmL/gM7BYKm1z6bWbgvbwlG52nnt6fMYiPxVaxrAVjvBNP+2hNZz1RJDgPLepK/LFiMK8Ke62Q803BS/wmENfhocJH40F7oJyXt2E0La5tvH0Fx7Z8nFMsCHPMzBRBA6hBP+M+Ug3soZ5VU3Wu/SadzDdpvYzGYmxKvig+WcICVIobywhNU0QTIsDjkA2dWS2vpHByzDaB6lQUFj5hpfczsRwVqBXV3VgVciEjvQ4qu8j57v0fwDs/lXZDYeipMYePUb9dnc74CWHjeMUKX3Av4aGoV9sGsqhc4ZdUby5XssVusboMLp0F4U2YgCVeJDJP5oy+3ybwVUmsLaUh4uUcjMMSb8yaSXEK8WNjCjUoHY1aaHfLDIyKViQjAKWagPzPQ6trc7YVQEHEGJW6+pCTCLHjXeuJtZwYxw0md/e5J8IIApItqcLQngXyzlzSKfE3yIIgmLNIPtSBPx9LC2w6MJ1QBN2eIaVJR3OhlqinS2uU44GSAHSJW1u2OW3ABu2f2xLEiEG21BS4NoCrl24XwTWoJMeIK7SX2US9KuaykS5ce/FWJiyfKb4SKNMMRBllXg/JWqIvNDM3BZqj6wxvSNIGy4i6y1VZdx9YoVd33cO13JopBQe02wsF5RP9IA0/7Pw+UeA+HVDeGI2+sAh/WU5x/DpuNlFZUzDdFQTsXNERzvtdMyshgwqPbNd33SNfCgYNmZaLq+RmTJ7PPs+MsWuVKP+iOiS7HBxp3BHN+dw3XZNOf+9T7J/X4cG+CWahhietVjtPVBQXJNpgUDP/XLQC4wmWkIp9ZAjfDP5jP2IOVZd6f1l54y+gVP3yOZ1SNrI/suZb46pRZIiuswu9m7AXLuNkoiYpXr8cePNKsrducqT2I1c3EAiMsdutQOjljjf2rt4zeO8VDmeXlSFasa5k6/+U9tb8fvnFoAax6H3axPUG24Qfxluqdr9/ZVG+VW734LETkxheFHIY5sY3QQ9ZHZu+91a+cTOZnMoUxsJlOwMvQxA9kI6qZrDrcX2I8x9ers3d12K6icoeEs4cjAc0R6y7dG04S3OvY9MhgvZ8B2aJTVpoLMvVf2RIF81g2aeO76aJyWLzxf+EZdOPajp2YSFAs4Bb9Aiwj069XNiaoXW7p9Q9jqKxBVbsVXh4uNG8Z0/Qy4wcBfF8gY+cCICFPWQHM8FYyTI8UYJrqknWJOFTY5o1Z4BiFpAxL7bNOu/DSyAvQ0f+jVN4IIQ0nRTOw2NiourgLMzuszxgGGid3AYU/WqzqZtUJ6ni6g0IDMS8nJVLb/DskmTt630omEftxH9WDh8mYfCVpkddfLw+O02SGGsZwVcaGfoK+dhWd8gUhA2zEP6sfbcvedntG9mW71/IFCyrje7WcerqAYGiQqTJHGwK7GsH3Tn1GRGWlFbpANQGX1qH33AV4bxxrdhSX/6i4LYKaiE1nn7aReAbEa2E5D9gO8ltKZxmeH9Bfwon53iJSg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea97f698-b07a-42da-feba-08da18aa9d51 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2022 15:23:49.0499 (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: yakn5ZXZ1+wZm4OfzvGr2Wa8rp+myQUNHw6cso4HmFXCjQeu8FdmlFtjZRMjMMOB X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3239 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This new mechanism will replace using IOMMU_CAP_CACHE_COHERENCY and IOMMU_CACHE to control the no-snoop blocking behavior of the IOMMU. Currently only Intel and AMD IOMMUs are known to support this feature. They both implement it as an IOPTE bit, that when set, will cause PCIe TLPs to that IOVA with the no-snoop bit set to be treated as though the no-snoop bit was clear. The new API is triggered by calling enforce_cache_coherency() before mapping any IOVA to the domain which globally switches on no-snoop blocking. This allows other implementations that might block no-snoop globally and outside the IOPTE - AMD also documents such a HW capability. Leave AMD out of sync with Intel and have it block no-snoop even for in-kernel users. This can be trivially resolved in a follow up patch. Only VFIO will call this new API. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu --- drivers/iommu/amd/iommu.c | 7 +++++++ drivers/iommu/intel/iommu.c | 14 +++++++++++++- include/linux/intel-iommu.h | 1 + include/linux/iommu.h | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index a1ada7bff44e61..e500b487eb3429 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2271,6 +2271,12 @@ static int amd_iommu_def_domain_type(struct device *dev) return 0; } +static bool amd_iommu_enforce_cache_coherency(struct iommu_domain *domain) +{ + /* IOMMU_PTE_FC is always set */ + return true; +} + const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, .domain_alloc = amd_iommu_domain_alloc, @@ -2293,6 +2299,7 @@ const struct iommu_ops amd_iommu_ops = { .flush_iotlb_all = amd_iommu_flush_iotlb_all, .iotlb_sync = amd_iommu_iotlb_sync, .free = amd_iommu_domain_free, + .enforce_cache_coherency = amd_iommu_enforce_cache_coherency, } }; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index df5c62ecf942b8..f08611a6cc4799 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4422,7 +4422,8 @@ static int intel_iommu_map(struct iommu_domain *domain, prot |= DMA_PTE_READ; if (iommu_prot & IOMMU_WRITE) prot |= DMA_PTE_WRITE; - if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) + if (((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) || + dmar_domain->enforce_no_snoop) prot |= DMA_PTE_SNP; max_addr = iova + size; @@ -4545,6 +4546,16 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, return phys; } +static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain) +{ + struct dmar_domain *dmar_domain = to_dmar_domain(domain); + + if (!dmar_domain->iommu_snooping) + return false; + dmar_domain->enforce_no_snoop = true; + return true; +} + static bool intel_iommu_capable(enum iommu_cap cap) { if (cap == IOMMU_CAP_CACHE_COHERENCY) @@ -4898,6 +4909,7 @@ const struct iommu_ops intel_iommu_ops = { .iotlb_sync = intel_iommu_tlb_sync, .iova_to_phys = intel_iommu_iova_to_phys, .free = intel_iommu_domain_free, + .enforce_cache_coherency = intel_iommu_enforce_cache_coherency, } }; diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 2f9891cb3d0014..1f930c0c225d94 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -540,6 +540,7 @@ struct dmar_domain { u8 has_iotlb_device: 1; u8 iommu_coherency: 1; /* indicate coherency of iommu access */ u8 iommu_snooping: 1; /* indicate snooping control feature */ + u8 enforce_no_snoop : 1; /* Create IOPTEs with snoop control */ struct list_head devices; /* all devices' list */ struct iova_domain iovad; /* iova's that belong to this domain */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 9208eca4b0d1ac..fe4f24c469c373 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -272,6 +272,9 @@ struct iommu_ops { * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush * queue * @iova_to_phys: translate iova to physical address + * @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. @@ -300,6 +303,7 @@ struct iommu_domain_ops { phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, 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); From patchwork Thu Apr 7 15:23:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12805346 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA5D9C433EF for ; Thu, 7 Apr 2022 15:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344631AbiDGP0E (ORCPT ); Thu, 7 Apr 2022 11:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344603AbiDGPZ6 (ORCPT ); Thu, 7 Apr 2022 11:25:58 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2064.outbound.protection.outlook.com [40.107.223.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ACD621798D for ; Thu, 7 Apr 2022 08:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kDZmkIZl2USMUrerl/+yHxj5PPSxinfIyieKecaw+AVLmB+yNYgDtFfIdl0cdN9VhYhklCKxbJidta7cH3ZNzIiV/CCbZZEg0LSVFa42Mvl6NDKgZVuwZSOp5JVmwjJIh0aeFBtYaNc4QOH1NOSFTPM4QLVE/gM5pu2Kyk5cOvkpcdoXFwo96DTqSrs8ywjc84nJzsxGkcz9C7r2nt8o4KkTlp/wWpAm0JKL46oXRKBDWc1VqR4tbVkLW2QQl6J8PqMJWxjTLyc364oT/sbntilEFmAr1J2sj2ktQIIUFs4FHPkkEvBJnNEqAaI6BHBP68KW6JdpM1GrrF/vdkFS7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z5nFN1+SconG4MBJis9L36RYrSREFNs6QvyM6I1b3kM=; b=Rudkqub5BylVXAEjHwmpWFLCyceUGlkOh9Jpycq8hh0o9Z3hxRsn68jNXCF6u4zUPvGSqVQksfahcLiIxgv5ATEGyPQOeTQRAq/YkQLjGBuJ4zWe6s16b1upc1nCorJ48Iav12ELKoLyw7p3JiDM/JbOjr2xZZzmeCThiI9cW2mSC2G4LkosfQ3RFVUUNc31ZGlwrVMcstYYaHgYXi8Vj0G+xwqZ7PqIMuphtTVjzSetzNbFmFGZs5tCcxMEiC9kS6csvIDEeOirqdtXyzUtS9+unSun7Q+O2Fxu7s10gbK8LUHPY7caKJr/VgXgsT4Ofytr8G/wIWeAYgCE0XT6Rw== 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=Z5nFN1+SconG4MBJis9L36RYrSREFNs6QvyM6I1b3kM=; b=Fddk51THbQqoLqYM0VdsHPMjI0qvyCD5p4vaMgotIZSEPQAyl9CuyBwSB8ymxh3qG+XVCD4v6kDXtHJd0IppmBLeQItn8ZHz321lCZAdHVzkwi0b3FIiwsSQzhNSs/xb/4wiS9kRuMLA36uST3dv0PQvUMBBoYkhox4L40ZcbiVVp+JyZcLec4s9HR1oDre3l/q49Dros4ZMibngAF1HXRYRO666Alq+8/8U7Hgc2HB//+L/8jXIw+Kmu22jSOcH3gFYBoBLtiz9WJ6wN6V+csLdy+9DMJbpJ4ap4Sxpk6X+XNMszS0dqFFZOR8OgEJ11op4eVTtwN41dxe0NTKaAw== Received: from MN0PR12MB5740.namprd12.prod.outlook.com (2603:10b6:208:373::10) by BYAPR12MB2742.namprd12.prod.outlook.com (2603:10b6:a03:6a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 15:23:51 +0000 Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by MN0PR12MB5740.namprd12.prod.outlook.com (2603:10b6:208:373::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.31; Thu, 7 Apr 2022 15:23:50 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374%6]) with mapi id 15.20.5144.022; Thu, 7 Apr 2022 15:23:50 +0000 From: Jason Gunthorpe To: Alex Williamson , Lu Baolu , Cornelia Huck , David Woodhouse , iommu@lists.linux-foundation.org, Joerg Roedel , kvm@vger.kernel.org, Suravee Suthikulpanit , Will Deacon Cc: Christoph Hellwig , "Tian, Kevin" , Robin Murphy Subject: [PATCH v2 2/4] vfio: Move the Intel no-snoop control off of IOMMU_CACHE Date: Thu, 7 Apr 2022 12:23:45 -0300 Message-Id: <2-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> In-Reply-To: <0-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0074.namprd03.prod.outlook.com (2603:10b6:610:cc::19) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b256706a-713a-4933-fc3d-08da18aa9d70 X-MS-TrafficTypeDiagnostic: MN0PR12MB5740:EE_|BYAPR12MB2742:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P1CKFm8SALBZA1OQGli24OrU8eCBjsEK2dsEWzHz+/v0BRA2F1hxS5Mp4F3YFHK7LcQCGaXP8cGlHSiZFVOjtBDEfSl5LO8fbKiomvbpvX4NyqF92kqrZ65FxctKts0MZtwQMJrISG4YjBRGbcF2upPek3M/UqeAcJ5oof+4GKAf1aKtHpUgttDGcUaTxxlMf4mTWnji1Pr1Ved7Sd1sXNyJxkgX9jMIj1RCBGMAQ9913P8KwW14s2i1KvejKElVJcvDFd9THoe8LediF+P6JO3l/k15RtHo7igprdKRR/xSRYpFVlW313w5IY9TL9stonWZaKsuiZ+RqkFp6X5mel9SLc/nMGlPi5InRdfcjrA5NwJG3ldwUdWpi1wTH9GOsLIcBzLMRIGEKAHGQSQGHvDtqelfAtJNl+z2aL38O9HUMNzIRAJm4kr+u6AZI0V+bQ5cewx3yo0+GzfMgXHZYyYmdqDpy+JgvTF6YdMy5ETdLTJJQEco5/wMo+3suD0ASGghx1c8W0ASrToN37hGPj1EDpwvRemFq0RZZX3yi2hlXnIlELLXgal2xPnRwHmBbNojcZPIxO1cFnNKkYdqzabOq19Ny4zJD7SE/I0XBi6fJPy8RMPicDZeeSTx0hzrSHYXNVVSXkWWkLUWBenACwrhBxry4zjpDUxdZZ0V/pd1SsDJYKLewNT5cfb/6fYu X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN0PR12MB5740.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(7416002)(6486002)(5660300002)(508600001)(8936002)(2616005)(6512007)(186003)(26005)(4326008)(2906002)(110136005)(6666004)(6506007)(38100700002)(66946007)(66556008)(8676002)(316002)(66476007)(54906003)(36756003)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eQHgF/QcvxzJkxY/GpeHMgJl8xg/gUYKN+K+OjkoX1JRmkziA/BM8eRH2XeZHwYbXNlpLYoGLJVUYDbtZivsEKM6/q/8ivUxIBJFjN4fIvb5qXHF9zVi9cog0uHmpWCTJ4NuZJksxzu2sYINW3PLFeWgLfm9PSA2K+WQ2ZiZezjW/KECUc+g52I9beNNwz/T3hv90EbyJq8BgGR1zzCjh6lwbdXOIqRTxCk9v7/YCKTu9oIpNHEH/+Ft6FkYqSSQ+yQdyPQtp1OyzLw8J/GLqGpoYfOAcrg6TIJ66MA7C1cAN4Ox/ir7dTJi9pc2s5Q3BW9vUJQKRIiKzkXl7rOZd6ar4qx9eopDRfcLGrto4eNjfIduC0TQSUNPi+QrJ1NYwTwA1b/Nlt6IF4whI9AmeCvNb8o6+/0Oem2xRY+UjTxy+lTmH90F4+VQriXsQvHWbp4UfuHbgnbKxffzBhxf8bvOxASObc6rQEQlM9rHJwU+RZSbL9OSdYnmfqNhcdAIuVhFJVHjs5TF+KVQxa2BNNhW9g4G0/sb7brG6poceRCTUv2xUBqi20uQUwx9rHyLYkuB5S7XQ6JY2kk06y//4ak3/ZZ0CgiPeTggVE+YIs8kfhxqK5hnb/1+oZoWNJy4m6Or4NEIl3ybRATM5fO4+YjAv8jDABd0WMciR5QOtpwfYvCrUmHWYu3/e+hN3nAQm61Tvld/gByFl1jjwDz+dadjoK033XTWfZiJkNvTktYV8AyBG2lQIrNV3+uOtBPb2FL1CR9auoelN6n/j+husKLp3eBKpecxFolkzhtxvUfGWg/cJGf//DaHoBKFVEiVuHSwUKUJ39ehjwYJb5CNfk8GsEpnvRb4QehzKRrXqw0LuOCXZqN/C+B4FmIj5fP6ROLtyKNLsH5JPDlxPislHH2kmSZTJVG4UlCQ9a8m3dP5NkcJe5kJiZUIMEhDkoJ0uGWPD6dhlklItf7mmmzy9ijVOoEhHVFjoWsE8shmhgTu03P7pR6RyP8V27YhDcZLlbKRyLf7gr1e6xhEM/3v2VWO8AnP48qbQ8nsi1En7WIpctpvIrzi+MmlL1gf5n2Levu40NKc1SdBaf0QKCabfux7ujyIRh53/wc1V9gS7qxJ//8hgMMLNh5do4+JApPlDWY6idVxS3YsAbMxrNgTCjzA+hXhkxNbz8CPWF3SkBdmntrFRR7A2Hk21j+yVJ8lUecH/9yjeqY0iOj3YMgjuSw+IAdRWBxGB+0YIX7ZeMBZwpD7GCOaBwWzRxeyVbGvcmq5VD2oDWc3u8gkMenN6xu4+FYum4nSrekSRrNmWneSQshO4781JZ2Nn4swhn+BNBc4dWJoQltgp13M9u5l6vni+6ldpFv4iWVQWZTevD8bIngWJlqh7hvzmO5yPxYK2ZwYPkDYt6BT68m+V2usNJq0AG4RZaF6NztzTstIbJ0EdJvAXvgeG93i55KV/Vg3LBBnfvH5k2J6feHQcg1UvPnP2MxRgW9yQcTMdMbQp4jQ9nG8w3bAFNdqmuPnrgiSjE4Z6SGH6nQcu3Z1WLvJ0z/ZbjF2nuQOus0LdDjDvdblf7exrl9femE9biGy13FYrIh41qRsRA5kI1JB/6nwptNcIHKAlCq9UoUNyF9OhLJ1Ww81/rCVjSggh3RYXkB+LlRCuxrSdJemwXULxKUpa8RPGKLAe7PkTJPlT3HVilfXgMLaNn6D9i+jTynqpCZy8KkbemVnnGELh+c0Z5x91w== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b256706a-713a-4933-fc3d-08da18aa9d70 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2022 15:23:49.2530 (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: m5bu7fNWUMdXbd6u7j6Hu6K7+I2Y8Km7LSKY39iHVkVyjXK//QFyiIAXRQnaqsVB X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2742 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org IOMMU_CACHE means "normal DMA to this iommu_domain's IOVA should be cache coherent" and is used by the DMA API. The definition allows for special non-coherent DMA to exist - ie processing of the no-snoop flag in PCIe TLPs - so long as this behavior is opt-in by the device driver. The flag is mainly used by the DMA API to synchronize the IOMMU setting with the expected cache behavior of the DMA master. eg based on dev_is_dma_coherent() in some case. For Intel IOMMU IOMMU_CACHE was redefined to mean 'force all DMA to be cache coherent' which has the practical effect of causing the IOMMU to ignore the no-snoop bit in a PCIe TLP. x86 platforms are always IOMMU_CACHE, so Intel should ignore this flag. Instead use the new domain op enforce_cache_coherency() which causes every IOPTE created in the domain to have the no-snoop blocking behavior. Reconfigure VFIO to always use IOMMU_CACHE and call enforce_cache_coherency() to operate the special Intel behavior. Remove the IOMMU_CACHE test from Intel IOMMU. Ultimately VFIO plumbs the result of enforce_cache_coherency() back into the x86 platform code through kvm_arch_register_noncoherent_dma() which controls if the WBINVD instruction is available in the guest. No other arch implements kvm_arch_register_noncoherent_dma(). Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Acked-by: Alex Williamson Reviewed-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 7 ++----- drivers/vfio/vfio_iommu_type1.c | 30 +++++++++++++++++++----------- include/linux/intel-iommu.h | 1 - 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f08611a6cc4799..8f3674e997df06 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -641,7 +641,6 @@ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) static void domain_update_iommu_cap(struct dmar_domain *domain) { domain_update_iommu_coherency(domain); - domain->iommu_snooping = domain_update_iommu_snooping(NULL); domain->iommu_superpage = domain_update_iommu_superpage(domain, NULL); /* @@ -4283,7 +4282,6 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width) domain->agaw = width_to_agaw(adjust_width); domain->iommu_coherency = false; - domain->iommu_snooping = false; domain->iommu_superpage = 0; domain->max_addr = 0; @@ -4422,8 +4420,7 @@ static int intel_iommu_map(struct iommu_domain *domain, prot |= DMA_PTE_READ; if (iommu_prot & IOMMU_WRITE) prot |= DMA_PTE_WRITE; - if (((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) || - dmar_domain->enforce_no_snoop) + if (dmar_domain->enforce_no_snoop) prot |= DMA_PTE_SNP; max_addr = iova + size; @@ -4550,7 +4547,7 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); - if (!dmar_domain->iommu_snooping) + if (!domain_update_iommu_snooping(NULL)) return false; dmar_domain->enforce_no_snoop = true; return true; diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 9394aa9444c10c..c13b9290e35759 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -84,8 +84,8 @@ struct vfio_domain { struct iommu_domain *domain; struct list_head next; struct list_head group_list; - int prot; /* IOMMU_CACHE */ - bool fgsp; /* Fine-grained super pages */ + bool fgsp : 1; /* Fine-grained super pages */ + bool enforce_cache_coherency : 1; }; struct vfio_dma { @@ -1461,7 +1461,7 @@ static int vfio_iommu_map(struct vfio_iommu *iommu, dma_addr_t iova, list_for_each_entry(d, &iommu->domain_list, next) { ret = iommu_map(d->domain, iova, (phys_addr_t)pfn << PAGE_SHIFT, - npage << PAGE_SHIFT, prot | d->prot); + npage << PAGE_SHIFT, prot | IOMMU_CACHE); if (ret) goto unwind; @@ -1771,7 +1771,7 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, } ret = iommu_map(domain->domain, iova, phys, - size, dma->prot | domain->prot); + size, dma->prot | IOMMU_CACHE); if (ret) { if (!dma->iommu_mapped) { vfio_unpin_pages_remote(dma, iova, @@ -1859,7 +1859,7 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain) return; ret = iommu_map(domain->domain, 0, page_to_phys(pages), PAGE_SIZE * 2, - IOMMU_READ | IOMMU_WRITE | domain->prot); + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); if (!ret) { size_t unmapped = iommu_unmap(domain->domain, 0, PAGE_SIZE); @@ -2267,8 +2267,15 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, goto out_detach; } - if (iommu_capable(bus, IOMMU_CAP_CACHE_COHERENCY)) - domain->prot |= IOMMU_CACHE; + /* + * If the IOMMU can block non-coherent operations (ie PCIe TLPs with + * no-snoop set) then VFIO always turns this feature on because on Intel + * platforms it optimizes KVM to disable wbinvd emulation. + */ + if (domain->domain->ops->enforce_cache_coherency) + domain->enforce_cache_coherency = + domain->domain->ops->enforce_cache_coherency( + domain->domain); /* * Try to match an existing compatible domain. We don't want to @@ -2279,7 +2286,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, */ list_for_each_entry(d, &iommu->domain_list, next) { if (d->domain->ops == domain->domain->ops && - d->prot == domain->prot) { + d->enforce_cache_coherency == + domain->enforce_cache_coherency) { iommu_detach_group(domain->domain, group->iommu_group); if (!iommu_attach_group(d->domain, group->iommu_group)) { @@ -2611,14 +2619,14 @@ static void vfio_iommu_type1_release(void *iommu_data) kfree(iommu); } -static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu) +static int vfio_domains_have_enforce_cache_coherency(struct vfio_iommu *iommu) { struct vfio_domain *domain; int ret = 1; mutex_lock(&iommu->lock); list_for_each_entry(domain, &iommu->domain_list, next) { - if (!(domain->prot & IOMMU_CACHE)) { + if (!(domain->enforce_cache_coherency)) { ret = 0; break; } @@ -2641,7 +2649,7 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu, case VFIO_DMA_CC_IOMMU: if (!iommu) return 0; - return vfio_domains_have_iommu_cache(iommu); + return vfio_domains_have_enforce_cache_coherency(iommu); default: return 0; } diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 1f930c0c225d94..bc39f633efdf03 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -539,7 +539,6 @@ struct dmar_domain { u8 has_iotlb_device: 1; u8 iommu_coherency: 1; /* indicate coherency of iommu access */ - u8 iommu_snooping: 1; /* indicate snooping control feature */ u8 enforce_no_snoop : 1; /* Create IOPTEs with snoop control */ struct list_head devices; /* all devices' list */ From patchwork Thu Apr 7 15:23:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12805343 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F20BC433F5 for ; Thu, 7 Apr 2022 15:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344607AbiDGPZ7 (ORCPT ); Thu, 7 Apr 2022 11:25:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344612AbiDGPZ5 (ORCPT ); Thu, 7 Apr 2022 11:25:57 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2064.outbound.protection.outlook.com [40.107.101.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF4D217994 for ; Thu, 7 Apr 2022 08:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WXxzgTX/VnQmIHSdqFN2whLnyAd2/zVOET5Tv4NIMeGkcUNGfA+0ekaYf3c5WP7NqlWeKtnoQ0GlvQXnAPd4wlla3/5ctXWCLvgzdTC6maKjnRxKOztMJiX03H0uelUFeyRlOi6x93y8TMUnW9L+YFZtxxkqbuZH88iHTNU6yVNyDLQDfx8geA4GNA6A01KOQgTWKCQuKCHojEpwW+lAEizFAE5IzaLE6a/vdW+fY9b4dr0wmxD5+3/KIIBCn/u/+Dwu4c7tCwUvDoGjDUqn6Abex7b+g6WIK4K8AirYpsGW6vLJgH3psjJPSFX/ZXIvp3k/T/4t3rBH+gG/y1v2bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dBfXtb0qKyKAC4Q4QQHeY6Ekv69FSJSiZz5PHSG6nwM=; b=YCWzWGWWp6wmBj2hRlFCLFBKDDHPkjqokkxHVMkTFConBSnYErjHTPH6gCBG8pZwq9n9sEwW/AEJBlo1ApemSabXzsFElAOXB6G4RyRtWangG4XkVCTFwZg3KafBxB4g/5Ox2T8l8bXE0GP9LdmtjwLertPGmtcSNeWwK//Kx5XuvdEHP27bZ1xnpVOvl4ZAiwOsX7KQ8tL9cCETdmYvGLiq69NDjLzyKhF5j2bvzXJo4PuNUlaNzmJlR+ylDkmKdbW4qVaIqpj03jUHaHKWip5tGfMrEzlFMafIFu2x2COQxt0lcy38Pf3Adg4W/3nhCdBmFxknt7PyedUHfBR0WA== 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=dBfXtb0qKyKAC4Q4QQHeY6Ekv69FSJSiZz5PHSG6nwM=; b=JzH8q2MmeA6Vp+bYUA82/jdzzDJwl7vSo4vvi3jAE2n6yW48FH0/sYv2PtJKX1Q39Tdv3gHiWu8VOgD3xzfcby6NthgjclxF0Lva1AIosvt3k2FQXZhrYGgdZmZbDiouyArvWv4Sg+U63ceGSfZdoy4rLRSXKECJ0TJDdPDYiOJ/TXk79QlHHS+SuTUj7VX3fO7tP/YBCbs5dRptc+lkjd+esZ4aOqQDZ/Q//w7EniCeYk2WGsRmPeAxyJ0fEzA3eOHvIbuL2BWJwIGomag9nrXuq9lP27tE7Tax6nIWecZMBJ+IdXKa2MEy/Bjj/+oqTW741FxXsKjwUQR6ezwp4g== Received: from MN2PR12MB4406.namprd12.prod.outlook.com (2603:10b6:208:268::23) by CY4PR12MB1590.namprd12.prod.outlook.com (2603:10b6:910:a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 15:23:52 +0000 Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by MN2PR12MB4406.namprd12.prod.outlook.com (2603:10b6:208:268::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 15:23:51 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374%6]) with mapi id 15.20.5144.022; Thu, 7 Apr 2022 15:23:51 +0000 From: Jason Gunthorpe To: Alex Williamson , Lu Baolu , Cornelia Huck , David Woodhouse , iommu@lists.linux-foundation.org, Joerg Roedel , kvm@vger.kernel.org, Suravee Suthikulpanit , Will Deacon Cc: Christoph Hellwig , "Tian, Kevin" , Robin Murphy Subject: [PATCH v2 3/4] iommu: Redefine IOMMU_CAP_CACHE_COHERENCY as the cap flag for IOMMU_CACHE Date: Thu, 7 Apr 2022 12:23:46 -0300 Message-Id: <3-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> In-Reply-To: <0-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0070.namprd03.prod.outlook.com (2603:10b6:610:cc::15) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 429520b2-e40c-4557-4cfd-08da18aa9dd5 X-MS-TrafficTypeDiagnostic: MN2PR12MB4406:EE_|CY4PR12MB1590:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HU4WB26nUOygG7FVea7+krtchOqJBjYz09ZL++0o0W019/FIuGLg7CqgAfwoN+l7jEOdi8xEyKm7TMSHnVWvRJIk9mkdeu7YkN2T1V+pnoKNZPBMFTkQfa/DsD1k5jn1EVRQ064eJk9mDTUIRG4/0GndliKyE8tQsaGc4o6JlA+BHgUQ7VLer2olp45lMgYsmINOuoSTBYfYkUD4YbeAJsq7cahqRpptfcLtsduT1eIMIBAGl4h/3k2l8GJXxZjoyw1v/sEpVf+oTSlTIbPwSyOmFkUzu5WGz1R0dHRUxRNtvYBC/lSh3hNi9Rep1YvtV77w9IeGoKiLMwiNsrTaGd9+c78jxY5RYFR8t6bQc8PzYaDljvLAxgcU0zXsRYnn3tQkecP4x0K5mc8Esta2omrUdPy5VV3ip8sOmkSiX/Nu/kv/Y0ecd1a+WOyNf823cmnQ+pwBcYeL6xgTJfyrgiICpCJ2Fng+TQ5jv3CkQ4RQfUa/6PR3oJDZfyB92qY9aBUuXeZsikDc2sAieToeo9eDTtXItDiE5uuzNB5/Et0LGdcJByU4qlPMAT3v3GBQnFfcf4iqB4iq2hYruFGxUlf93C2qu3R27b0lS7pizDg1Y5g+9EbPn7e2hRifs3fLgdZ4aEdGGwAC6Jd5lAqY7HrXt5aYBdKYcdAFwTvlbAZ6p9qleXkrwot8dJnfE6rN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4406.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(26005)(6512007)(66476007)(4326008)(8676002)(66946007)(66556008)(6486002)(186003)(2906002)(6666004)(86362001)(6506007)(5660300002)(7416002)(508600001)(8936002)(2616005)(36756003)(110136005)(83380400001)(316002)(38100700002)(54906003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MTh8Iko22jkIopCVEee2ULvZ41uTeXNRmrFKJvPdMj4m8bHe8q5xqs0PMkVcbyEJJdkXHIZNws29jqPaVDM/oAdRjRoPoJdrTeEb2lNmrTB5k1Eq7Gy68YmudWtqvDE/XSRkpOjsGu3G3Anx+iwqWacAqxEzSuDv1YuJk5ujBFc16+P5fIb5r2ThWMPCVBGxLbWrp93aIGxDdKm9v5q6U9mWd0xLUV94wDXJjRPzQhEtP9QBjIctbrKtWuNfcl4XlUTF3WFSxgCmrjan/3bbNNGm2KbgMqsL5z4572nt106A4MfxYmmHnsqkFxTOzZ5SK6AabBiMJTcZk+2O6fnn/D0c87GjKy2tvD1dyyKkt+B2rjN+PGWFSZoWmV+7giZT7HJJskLul7cOX8otv/wYGqKbvgtu5mRWupDDhb/VM+66v0LfF6SPXtSeW4B/wNmBC8s6ScdE7jO2Dw5BeUkolMwipRtwXBadx8h0PBIYorvtvuCS58zZAhUWQWB5l3GndYidWb9fs4P5Phw7+WwpqDaVY6U0zix7+MxHEE4wR0huvyWF54P1g7LelNobfwU3cusOrinEtmvC6+sw3JFuiPSl7+vChVFxHB0bEixr9a5ML39tv0qVi5EO8unHLGJ3pvMLxiGp4AMZ0mmNge5TjYc9TwK4F7hnSmTCRECcs3F9V9ZS1uK2Fe0l5KTuQKOLMSmJ0oMotoyzG08IcZwhZs+AD87OVhSXqgLAak6M8oZOOmmqE/HhMYwk2MUrStz8MSvKqBvKgNq4Zbc3y3kgYFMnwkZNn+aP4ymP4UJIEP+LPmezksFW5ZSaKR/VROn/cBV1LPU3KisWOCK54P2kU/pUsXUlDYVzc//L84iESZ+hjhZU0OEAQ2EpqqDAEFd2v6J0imZQBTpINHRyGQceuTgHakdTrSJ8qi5do8SDhKwlsyyPHWJIY1L3uBPcOw0YZ91+XF8MQp6t8zz3YXwhgfSIlMY/eqPxBFAUOV/4+8laHdoTxFxYAAKd6MJ26klk1EsLfflFqlQtX2JhPzoNW5/UNHyvk5Djai30RNyd7tCcUMeufvplWEkLh59bLuUPPyRnBTkojcADqcjeQo3shbNvtmarV6GcRtm4++V3OGXeL06LFXCewSbp6D9mC2AeGc9AaI8cyjiZdrAKgIu/Aa7iGqDRM5e9r8pZj4rtgN2Cxv8X/pQdTV2mEKAvxZWjnKqeyy19LsRHyGrm20d0WxUJ6HMLEQ8ht3eXfls1tEht50qyuG/JILnPOoWUetaDsv6UoEpsppO1xGdV8oWZFrhbuOim0SYUOkbRZWc+BE7fCxxr8C54wIUV/aFLQqhmmIl9Q11RjufLHFoMTvAOY1ii/TJvRG4sl/o8rB3rpnLfgOvnqHPPU4KDAiGkYIn6PXT3slMrYLdGIdRWUwAhuXwQG7TrirqnUp9kKNAZzI3wqCY6HvZkHGp4UOlzODWDhTXSGS+eqN0N/Voupjeb6M2b6ZeApqyY/OovalEyAv/10Kgi0S9mSxz7qwa5q/q5VKZ74k0K+z/ppptbg1zCNifqm7mUWl4KvkKgvGqzttVi/OpCJwqT1xq0h0R9NOK6iExzoO2DrfGvauPFi+Xd5YxlG6k9nLkoLs/CvNAQR8blgNnzu/xO+3CQO9zYmsWMUP/2jJZIpHaxgJ+P72hK/KsLU5Phozk2/9DM3XkRWDORKV8S6LBsYtPQh80gQfdCGMuU5/uGF7ZJeQNQqQcAuw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 429520b2-e40c-4557-4cfd-08da18aa9dd5 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2022 15:23:49.8636 (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: JUQGIMNCfW14ISXAIsam+1pxvFG6OkgypvLo1xWGHpdxWDf1g3V2N4LXMucKT05r X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1590 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org While the comment was correct that this flag was intended to convey the block no-snoop support in the IOMMU, it has become widely implemented and used to mean the IOMMU supports IOMMU_CACHE as a map flag. Only the Intel driver was different. Now that the Intel driver is using enforce_cache_coherency() update the comment to make it clear that IOMMU_CAP_CACHE_COHERENCY is only about IOMMU_CACHE. Fix the Intel driver to return true since IOMMU_CACHE always works. The two places that test this flag, usnic and vdpa, are both assigning userspace pages to a driver controlled iommu_domain and require IOMMU_CACHE behavior as they offer no way for userspace to synchronize caches. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 +- include/linux/iommu.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 8f3674e997df06..14ba185175e9ec 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4556,7 +4556,7 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain) static bool intel_iommu_capable(enum iommu_cap cap) { if (cap == IOMMU_CAP_CACHE_COHERENCY) - return domain_update_iommu_snooping(NULL); + return true; if (cap == IOMMU_CAP_INTR_REMAP) return irq_remapping_enabled == 1; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index fe4f24c469c373..fd58f7adc52796 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -103,8 +103,7 @@ static inline bool iommu_is_dma_domain(struct iommu_domain *domain) } enum iommu_cap { - IOMMU_CAP_CACHE_COHERENCY, /* IOMMU can enforce cache coherent DMA - transactions */ + IOMMU_CAP_CACHE_COHERENCY, /* IOMMU_CACHE is supported */ IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */ IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */ }; From patchwork Thu Apr 7 15:23:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12805345 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC0FFC433F5 for ; Thu, 7 Apr 2022 15:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344615AbiDGP0D (ORCPT ); Thu, 7 Apr 2022 11:26:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344614AbiDGPZ5 (ORCPT ); Thu, 7 Apr 2022 11:25:57 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2052.outbound.protection.outlook.com [40.107.92.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DA3217977 for ; Thu, 7 Apr 2022 08:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cIJ4EEz88PjAWX04s5/sTBJfM2M2c5e1X6Y0HeDGM0B6pI364ee+OmT+pcMaD3BqG2wVrUUFXu0puDnO5iYPlU4NJUSHJmetO4U4E9eLFp1cfnuW2dDh8eSUlVohp8/0e7vD2dItoi2OU/KlueTuQejEPN92Hy5E4T6HAiGLgCIS2x9fm2Pv8RP1qEt7xq18Mr++VAYTukdLRuOjBJd64flYKWC1znWdbu2jyZUEyzSLBHIC4ByMMRo5ZAQ7lrwC4FAzHv6emXPI9rhcElyQWpoNzOa7ohRnh4wqLrm6QQnVYQ15eK9HkLMJ0z6xegAq0XZQ1a3gss68YoGjAdBwCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FGS0YfgROEiFrfEW2D3h6jGezui7H3cOiH8aKT6+PO0=; b=WTS3a5DCfeawDBArjpnjLfj7CVaTKd2ymR4A/uDj/8djvkprDPeOcqExkhvKCVdbSCeDcT9p41XsCPZKv80uqipkJYWcxxLMViaWWZBvaDw2dIKxfMT9yrcyUVP6FrxomFl9bxfskzaK8HkoRmiPK0j0NiCIbrhldHpURJuP9MQDJUBKfZsLyx0pkLlevZAqYkehbMTp7z41q0BJTNvKuZ+h2I2k8NqwnD+JG4Vq+W9i11gk4rxrp2+PY/3T6ebaDd2Q9O5qWl1h17To6nTBv6AjGQkgXnIS0ZiNBlo/fDfwzseIp8A9+ObsQKxIir19DpBW33lUTBOKMcwij0CJNQ== 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=FGS0YfgROEiFrfEW2D3h6jGezui7H3cOiH8aKT6+PO0=; b=cJsQeyvqI7hRFN8iPSz39mZSVSbQBEvo7p6tIwVMs6GtXqOfzJrERK5HKWj4qvY1Na9OfDNJOWCKZ/f4/y16993pcWa2L5ALCsBNnvIHgmrdLUFcsTm3PS0qV8SWp6E2lZbWGgQqQMPlPfApyUpPrciaygpszNfFf/w3t6uWlTTyOy/12QkR4Mlebf9sb5PFF62CzANsRJ3Xweg8xbi8xQyHblQqltLt15sxDRX7Nwq9/tLVSUdeEfbae1VSAfU8qgCLH188c9B/TipUXDH5UJyn2fFvSNAF58PtQlSk3Bi1lw25wPSseHjM8Gjh4cXboThwvIWzQo6scIwER81M3w== Received: from MN2PR12MB3422.namprd12.prod.outlook.com (2603:10b6:208:ce::27) by BN8PR12MB3090.namprd12.prod.outlook.com (2603:10b6:408:67::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.21; Thu, 7 Apr 2022 15:23:51 +0000 Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by MN2PR12MB3422.namprd12.prod.outlook.com (2603:10b6:208:ce::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.22; Thu, 7 Apr 2022 15:23:50 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374%6]) with mapi id 15.20.5144.022; Thu, 7 Apr 2022 15:23:50 +0000 From: Jason Gunthorpe To: Alex Williamson , Lu Baolu , Cornelia Huck , David Woodhouse , iommu@lists.linux-foundation.org, Joerg Roedel , kvm@vger.kernel.org, Suravee Suthikulpanit , Will Deacon Cc: Christoph Hellwig , "Tian, Kevin" , Robin Murphy Subject: [PATCH v2 4/4] vfio: Require that devices support DMA cache coherence Date: Thu, 7 Apr 2022 12:23:47 -0300 Message-Id: <4-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> In-Reply-To: <0-v2-f090ae795824+6ad-intel_no_snoop_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0084.namprd03.prod.outlook.com (2603:10b6:610:cc::29) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6eeeee02-0e75-4b4b-edba-08da18aa9db3 X-MS-TrafficTypeDiagnostic: MN2PR12MB3422:EE_|BN8PR12MB3090:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o792b+nEs1O/uf6WFlLjb/kimCYNpjHW5FecSdsOdYfgOgo+67l3R3y1x0WpUdw/6n4xYk2fBH/FX51Y4YYoFU8hxxUSrWzjSVNgD+qVkMKtGUqisKAIOlVW9gKK9lesND0bvibScREAn489ZfNvSMOg3ZRxGtIDSqxWpfzNHMmpsHltExY57jCiy09yf2HoVPcFGrU2hBp+NsELKBrLM1AbNXTDhI9C5HyFarPQY5el18V4gkKjWkepRhEcm07deZUvdHdjQMVbFGsr7DD2pa3RHPfY2efZpKlJCFte/MWh2WTBzQU2NT83kuOH1CXwjngCI0UIsNjZcoMagHMY31+mPKxypm3t1GzyI+ZVGOCqGTmqSrF6CHR/O4N/OGhwH6V8tCsXRRcgtGxCeqwU5BRHvSWRyDfmXCn9E7ZUEecuCd2a8nuG/QKjeKh58hc97hKE30U0N+CPm2IcmaismcO07xJq+dyj5+NzZLyeAEYvyyAoef6+b5mItvTx7CGxzGRN8ijqPCeMdbsUWhwnpz4/3BUfTqzNgG9hsY9ghjTuxvGSnfKkGvoGrWj7BNWiacRmTj4CKIvioSV0S7odhmue6VZyERjBy9Qc1mo/PXF8yaaZ81IL/Drver2esznJAGIRERbldBH6kQSUXN25ssYctGXq5Pi67Tfi9z/ctBMrok2ONBXVlXU//3Pm2cT/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3422.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(26005)(186003)(2616005)(83380400001)(66556008)(5660300002)(8676002)(4326008)(2906002)(66476007)(8936002)(7416002)(66946007)(36756003)(86362001)(508600001)(6486002)(54906003)(6666004)(316002)(6512007)(110136005)(6506007)(38100700002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4IPCGzYJUv8EO7ckAfoeDUTmZ0Nzmhn8riCZJimesH6qTlRsgCBmr51tc5tAYm8O8S3NwNGwUKWaLn1OQLULEdJllHi2ytyHyuPjSL7ThJ29lXNUZu3KYJ+gQy01yQ0wkgyHmsPMLTUzWtNNGmRxjvTu0vzR1DghaTUWxexz/6KLIFnT+erqa23e8s1ls8O0pAA9YLgsE58sKcK+pcs4Qe+KDt+so5gdNwVwAqh+R7ctebytpOSYZAmi4XliEazdwNcMaUFkVyevitLn84YN5iFcYUTx0Ay7iYMKfHeEd1TRLoqAF8BZhLSAueXWCtgOWKWIm5wcG/av5jvuI7jRPvDfZhmL5Zk2jdCtGI1nd3izBale3v8W65Cx8lbf/d56USwvJIBLgvXunurL4LEcPGZeY8fGCh8dJHCq2xmtmvV4Qh+FMpRtRkguuvY3CfKcdnTmuHSbadejxCfMgMt0TshIML1rHMvfZv3FMgPv1Rer/Z8UKhEqQMctQVSBu0XuwryN8/5XLVyjkJ+16VW71MGe2U4P4PoTYllQv7EAH0sj4pHUpXjFODv8INMwihLJkIugm/UIRIK9VZMpNao/L0+EablSEvZVOJXcavf23z065oQqJrOvTLWzD8I8xfTMcXeYLIUrq3GE/IRXKpM5n1FuSavezyhMd19zZahSgsQ144ZqhetpP0dYKmomlrFBeFFC2yDvqO5MmQ7+mGxGm9FfIxCFG98XQINqSZkl/UHZ8h6ODBzvkdsDcamSpOuyDImoIfDUtzce8VECtvaRCa09vw/O/6ixiJqYqNHmWTkNgTpu6l7/9LrwZUgMDwfT1A941Rg+tzYsXhc0yTFkGQ1x3k5JIqKdyGXAUGCbkqIu/ISEBih4gotjVq2Sdiu7mz62ker41c5vtp+ewmmhj7WoI6OVzX1QMY4mxH8Z4EQxx8QvUsr3j3GAXF8xOFWJbLmcs4sxCerGpKDbOpGJ/kzBGi7NyO8lFvl1H1wSE52Wmf4c6meMliTV7pRBRJhVJKiFmtiymI+aH3j/HxoAi4dlACENsHuX3/+f1qppWkm9B15bxHSGLzYc9wV7UD6bLuvsn5onVIXVSpUNzTMYqGmqXs5LSp2VJEMjoTPuglKv/hVqEnnYQp9JcLk57YysyjSsRPSo33/qMqcdDW7admpVOK1I6Jr4nRk5ee2FG+z4tGkVzBketHObUbwIe/vFlVIDHR7cwlrhmUSDlAnXr7/48HTcGGZ+0DKPCz4w/yCRthuyFeIm9hCI7seJumaVlQR4rT/9Ld9TV27U5oa0HjUGRbEep48POF/245RoaDTxYn8Tcjk6QgiyOJaBVOoT/2MxkklIedf5I/u1VZV8p0BlXfs0SHHXRxXzODW+vth1BXdupk9ICHag9iw6sVY2EfHYVdGgvzt5jpPZxFKZZoSvwmgkDkWO9qDIFfhHsaBk8/5rSlpxSz5ZoGkLro+MCmNsEsMuQpR6MiRQI3FXotY5JZAS9nge9oskYOX1kalU/DKtVJrjvUVvVN5RXd/L1vo95cxFqEYe0A3p1abRvOlSTHHSsTTe/lNAurGfQ+71P1BjyCq4x5/GmiPYjHaGJ6oElo1H11Eqo8KeTCM0EHqiOUUoo4in1GLlzcMDmClARvmIuaeUdERQ7ksVfwwaOYuS9nAfbvm1t5TcuE26qN3xBBkHzp9JO/5xrW0Au0LHENDFW2iPyNxt2Y17Wld1hJBvkWPu6xMk1iiYpen4Sw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6eeeee02-0e75-4b4b-edba-08da18aa9db3 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2022 15:23:49.6449 (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: 3sxr0VdJx9i+GIfhhUnZouHrQHdxXgorBJsLSMZYKL0/vlhfw8QCfydhmw1FcOwm X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3090 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org IOMMU_CACHE means that normal DMAs do not require any additional coherency mechanism and is the basic uAPI that VFIO exposes to userspace. For instance VFIO applications like DPDK will not work if additional coherency operations are required. Therefore check IOMMU_CAP_CACHE_COHERENCY like vdpa & usnic do before allowing an IOMMU backed VFIO device to be created. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Acked-by: Alex Williamson --- drivers/vfio/vfio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index a4555014bd1e72..9edad767cfdad3 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -815,6 +815,13 @@ static int __vfio_register_dev(struct vfio_device *device, int vfio_register_group_dev(struct vfio_device *device) { + /* + * VFIO always sets IOMMU_CACHE because we offer no way for userspace to + * restore cache coherency. + */ + if (!iommu_capable(device->dev->bus, IOMMU_CAP_CACHE_COHERENCY)) + return -EINVAL; + return __vfio_register_dev(device, vfio_group_find_or_alloc(device->dev)); }