Message ID | 20231202092041.14084-1-yan.y.zhao@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1674364vqy; Sat, 2 Dec 2023 01:49:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLG+pFuWW+M6iS9/jl4HKyx/fF6Y1tXyD9Roq+7LdAafeLBJZaukOjWKbbAOt+HRA11USG X-Received: by 2002:a05:6871:522a:b0:1fb:75b:1301 with SMTP id ht42-20020a056871522a00b001fb075b1301mr1413963oac.83.1701510593029; Sat, 02 Dec 2023 01:49:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510592; cv=none; d=google.com; s=arc-20160816; b=ThwuJ7VhvF5A0OHRpkLnB5GS8m1ZdaMx6OD3ASOqyY8eF8t3fifVQ8GJUKDABYE98D DoOkStHPIa7vouqHUXowQIOQiCkQZJVvdEj6TAjrMXhXmmhypoztd/+KUEAef7HeoNvz SpPKLsM8Vr/cvAVGMfTyLYhxIqM3QRB1W5Nrzew7//I8nrC4xKpNLP44yBQQbwQ0/ZDR gjtnxWwaWXepFh5a9oV5GCbV00qSCRdhaPSTqsggNYmoWXBS2tH2jCXftciv3UB77MJm gyBRLihjNz+naLATQKxPMfXgwJb5EIejYLChf19CYxQtCFHsN1KNHr9mw7OV9fdjqWlq 0/yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=+mp9bGBwSTpOuIM4TJcqfmMZiBvtz3b8IDb54P1bD3E=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=hVMKkvI2B/pJAggQatgNX1GtK2g/WSVBTuZy7PogGP6RrJsOqkxcsslIpIBkUQjwDb eqViJuSanw2Ko4Ur3jNR5UnfzLRoWpevaHO0X9ewb+VE5ADb7NWThrUX9p8XvSd2zeAj N/jFHBrXdnWVPz3p/Wsdr6PKw4qS5SCXKwPpdKZmtMjft5zjr5aOwxKWnHKSfHrwsbSz b0ZemPCFo9Zt2VnqTfLJ1pJsUsIIr7HFhJx1+HlSGMHNzDFuHwN/kfg0qfxxyBQ5KH8z 1K8vU0VShb4ajgpPdJx47k8VnnMWp8viq+5xGaL/eSMqNU3YdaTvEkRjcYE/kPKBhJBQ exRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=avJdL1ij; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id f22-20020a63f116000000b00578ea9a0b93si4772285pgi.890.2023.12.02.01.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:49:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=avJdL1ij; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4A098834BA5C; Sat, 2 Dec 2023 01:49:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232326AbjLBJtj (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Sat, 2 Dec 2023 04:49:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjLBJth (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 2 Dec 2023 04:49:37 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0D84134; Sat, 2 Dec 2023 01:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510584; x=1733046584; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Lo5VlYM9pcr8va0tr3dWmZ/2vpXpVd1PrW/H2X7PBXI=; b=avJdL1ijTwbTKlTIlEeFphxcjD+BQDaAQYMOEHo6LKb+6R77offDuTjp Kv18skulvLIg3B+yEDvGTXVUaM/kssdH+Eo99j/S0QzBygQaj2I9MqWyx tIqtJFtq0rp1fHe4syDerp9AWm2m1aW6IK7A9/A+alkLEABb8VM4Ak6yO zasIih/PIMSYxTTLGBX8YYDBKD/lO/7EXfa753eLjb/xwZm6CVvfm2q65 TpcI9w+uy25oEr/7v2N/TGNO9KOKSfcDvrp83IENeFcEWJ2GD4kJpf//I i/VaqBSmyv1NCCMibMeJZWSiHJXmOoAX+dnAeDeNRz4QxKLSTWp3riT40 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="392459180" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="392459180" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:49:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="887937515" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="887937515" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:49:36 -0800 From: Yan Zhao <yan.y.zhao@intel.com> To: iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alex.williamson@redhat.com, jgg@nvidia.com, pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, yi.l.liu@intel.com, Yan Zhao <yan.y.zhao@intel.com> Subject: [RFC PATCH 11/42] iommu: Add new domain op cache_invalidate_kvm Date: Sat, 2 Dec 2023 17:20:41 +0800 Message-Id: <20231202092041.14084-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231202091211.13376-1-yan.y.zhao@intel.com> References: <20231202091211.13376-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:49:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784163171418972474 X-GMAIL-MSGID: 1784163171418972474 |
Series |
Sharing KVM TDP to IOMMU
|
|
Commit Message
Yan Zhao
Dec. 2, 2023, 9:20 a.m. UTC
On KVM invalidates mappings that are shared to IOMMU stage 2 paging
structures, IOMMU driver needs to invalidate hardware TLBs accordingly.
The new op cache_invalidate_kvm is called from IOMMUFD to invalidate
hardware TLBs upon receiving invalidation notifications from KVM.
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
include/linux/iommu.h | 5 +++++
1 file changed, 5 insertions(+)
Comments
On Sat, Dec 02, 2023 at 05:20:41PM +0800, Yan Zhao wrote: > On KVM invalidates mappings that are shared to IOMMU stage 2 paging > structures, IOMMU driver needs to invalidate hardware TLBs accordingly. > > The new op cache_invalidate_kvm is called from IOMMUFD to invalidate > hardware TLBs upon receiving invalidation notifications from KVM. Why? SVA hooks the invalidation directly to the mm, shouldn't KVM also hook the invalidation directly from the kvm? Why do we need to call a chain of function pointers? iommufd isn't adding any value in the chain here. Jason
On Mon, Dec 04, 2023 at 11:09:45AM -0400, Jason Gunthorpe wrote: > On Sat, Dec 02, 2023 at 05:20:41PM +0800, Yan Zhao wrote: > > On KVM invalidates mappings that are shared to IOMMU stage 2 paging > > structures, IOMMU driver needs to invalidate hardware TLBs accordingly. > > > > The new op cache_invalidate_kvm is called from IOMMUFD to invalidate > > hardware TLBs upon receiving invalidation notifications from KVM. > > Why? > > SVA hooks the invalidation directly to the mm, shouldn't KVM also hook > the invalidation directly from the kvm? Why do we need to call a chain > of function pointers? iommufd isn't adding any value in the chain > here. Do you prefer IOMMU vendor driver to register as importer to KVM directly? Then IOMMUFD just passes "struct kvm_tdp_fd" to IOMMU vendor driver for domain creation. Actually both ways are ok for us. The current chaining way is just to let IOMMU domain only managed by IOMMUFD and decoupled to KVM.
On Tue, Dec 05, 2023 at 02:40:28PM +0800, Yan Zhao wrote: > On Mon, Dec 04, 2023 at 11:09:45AM -0400, Jason Gunthorpe wrote: > > On Sat, Dec 02, 2023 at 05:20:41PM +0800, Yan Zhao wrote: > > > On KVM invalidates mappings that are shared to IOMMU stage 2 paging > > > structures, IOMMU driver needs to invalidate hardware TLBs accordingly. > > > > > > The new op cache_invalidate_kvm is called from IOMMUFD to invalidate > > > hardware TLBs upon receiving invalidation notifications from KVM. > > > > Why? > > > > SVA hooks the invalidation directly to the mm, shouldn't KVM also hook > > the invalidation directly from the kvm? Why do we need to call a chain > > of function pointers? iommufd isn't adding any value in the chain > > here. > Do you prefer IOMMU vendor driver to register as importer to KVM directly? > Then IOMMUFD just passes "struct kvm_tdp_fd" to IOMMU vendor driver for domain > creation. Yes, this is what we did for SVA Function pointers are slow these days, so it is preferred to go directly. Jason
On Tue, Dec 05, 2023 at 10:52:27AM -0400, Jason Gunthorpe wrote: > On Tue, Dec 05, 2023 at 02:40:28PM +0800, Yan Zhao wrote: > > On Mon, Dec 04, 2023 at 11:09:45AM -0400, Jason Gunthorpe wrote: > > > On Sat, Dec 02, 2023 at 05:20:41PM +0800, Yan Zhao wrote: > > > > On KVM invalidates mappings that are shared to IOMMU stage 2 paging > > > > structures, IOMMU driver needs to invalidate hardware TLBs accordingly. > > > > > > > > The new op cache_invalidate_kvm is called from IOMMUFD to invalidate > > > > hardware TLBs upon receiving invalidation notifications from KVM. > > > > > > Why? > > > > > > SVA hooks the invalidation directly to the mm, shouldn't KVM also hook > > > the invalidation directly from the kvm? Why do we need to call a chain > > > of function pointers? iommufd isn't adding any value in the chain > > > here. > > Do you prefer IOMMU vendor driver to register as importer to KVM directly? > > Then IOMMUFD just passes "struct kvm_tdp_fd" to IOMMU vendor driver for domain > > creation. > > Yes, this is what we did for SVA > > Function pointers are slow these days, so it is preferred to go > directly. Ok. Will do in this way. thanks!
diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0ce23ee399d35..0b056d5a6b3a3 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -636,6 +636,9 @@ struct iommu_ops { * forward a driver specific error code to user space. * Both the driver data structure and the error code * must be defined in include/uapi/linux/iommufd.h + * @cache_invalidate_kvm: Synchronously flush hardware TLBs for KVM managed + * stage 2 IO page tables. + * The @domain must be IOMMU_DOMAIN_KVM. * @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 @@ -665,6 +668,8 @@ struct iommu_domain_ops { int (*cache_invalidate_user)(struct iommu_domain *domain, struct iommu_user_data_array *array, u32 *error_code); + void (*cache_invalidate_kvm)(struct iommu_domain *domain, + unsigned long iova, unsigned long size); phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);