[RFC,16/42] iommufd: Enable device feature IOPF during device attachment to KVM HWPT
Message ID | 20231202092311.14392-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 r17csp1675051vqy; Sat, 2 Dec 2023 01:52:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0sgPMSGMrfmPwXpjfuL0Nkb8mP7q2U18KhmlUWooXdd0drEhg7byq8Rr2dUv7PNQuMmiE X-Received: by 2002:aca:1903:0:b0:3b8:b063:6bb8 with SMTP id l3-20020aca1903000000b003b8b0636bb8mr1043223oii.103.1701510737980; Sat, 02 Dec 2023 01:52:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510737; cv=none; d=google.com; s=arc-20160816; b=iAt/LlDwIbu2iq68yjlTFnY35VpnSf9KirMUlUeJ3Y3KaD/2aB19zBZiQjGefhAe8n PzBz1c9T+m42t0xVHt21oPiuPCfQrpuscnDYzIFoyxtoNn5p+ShfqwLAS/VhOEaPaSEn 0PWNy0FxBfHeRytvnD5pbHAW5q9kzPjMY/fEedqOQv4EwUL6Mkf4MgQnZ7FzFEqSKu74 exgkCeIP6ucPEeuEDjT+u+PrE7AVMLHJd49TqhRPlOXt380YEO4Zz9qRn4Qnqcj3NqVo JhQZ4/7Sja+pSZ41KjMNTiZNkU1cI3yO1kpPGXa5RQ1oBoioXF19HQ/hXaWgiao/+x5v yoTw== 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=zH0tfA6EEh+fSWd0rDIXW6u2CjytqocOzjRYeHReprE=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=pR+BUFYm5v8DTAwLdlOfpCQs8WwvGTWjxqjXM0O4X14I2gqhF27yr0hEmAoMjq8H9M 3Ei9yM97BvtUYpQIM2ldnWcfT58kOBl7a3LhwIKFhduP61umxI3cSEFEPAUgB3gUX9Zt EA6/xXxwTBnwwrukJy5PvVh9s2YZylDZgMbAZ7boWPu/DE3nxHHxCtxwFYAckRcU6kvz J0a1IRlDbRu85PU/aO1bx6m9F2vPdnxYQ3XlM8+SQIutwPKAS8V5OZWl/EnG2lr0301w 0+dJVJpLV9Yk5y6wv90v7ZIbhIEqi8YLyGt06qcY72qcEc5wjbh4B4YHmftA1cNqkrO4 nyDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="exT2k//C"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id y11-20020a056a001c8b00b006cd985454f6si4764585pfw.76.2023.12.02.01.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:52:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="exT2k//C"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 653EA8031E8C; Sat, 2 Dec 2023 01:52:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232394AbjLBJwE (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Sat, 2 Dec 2023 04:52:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjLBJwD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 2 Dec 2023 04:52:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29CF0134; Sat, 2 Dec 2023 01:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510730; x=1733046730; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=qgwPOU0dccalAjjMk9ImV6B09aYt2Eqp8Z37kksWeQw=; b=exT2k//CH2x7cUhAJhUegDfTCDhV71i78bd0gAb/uE0KpTicm/uXnRly rd5BX4U4jpO+4ZnXXBskmf+HbPTAaGoxkYSGTIUYC+ZQGX9Co/ikeA+QV M0kN07q46Q8GLWExk61fN6jckTLAYhig/95FHtyY44kpx2zoIA0zdiDGf hIA9TI8myjUZezXYjYvDuH1CVRrWsYFgmDLTCzlsKjR+nYMfCarkG1g0N 6yvlo4IOxBvvcZWRbDvr7aIjXxLgL0icm+DfhB7GzNQIWajujJmxXlG/M frOT8coGfYEO2nhT+WYQuyVE2PMiBr0BdRCbAVPK12msBK7R+51faR/F2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="6886663" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="6886663" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:52:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="746280168" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="746280168" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:52:05 -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 16/42] iommufd: Enable device feature IOPF during device attachment to KVM HWPT Date: Sat, 2 Dec 2023 17:23:11 +0800 Message-Id: <20231202092311.14392-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 groat.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 (groat.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:52:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784163323655521601 X-GMAIL-MSGID: 1784163323655521601 |
Series |
Sharing KVM TDP to IOMMU
|
|
Commit Message
Yan Zhao
Dec. 2, 2023, 9:23 a.m. UTC
Enable device feature IOPF during device attachment to KVM HWPT and abort
the attachment if feature enabling is failed.
"pin" is not done by KVM HWPT. If VMM wants to create KVM HWPT, it must
know that all devices attached to this HWPT support IOPF so that pin-all
is skipped.
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
drivers/iommu/iommufd/device.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
Comments
On Sat, Dec 02, 2023 at 05:23:11PM +0800, Yan Zhao wrote: > Enable device feature IOPF during device attachment to KVM HWPT and abort > the attachment if feature enabling is failed. > > "pin" is not done by KVM HWPT. If VMM wants to create KVM HWPT, it must > know that all devices attached to this HWPT support IOPF so that pin-all > is skipped. > > Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> > --- > drivers/iommu/iommufd/device.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c > index 83af6b7e2784b..4ea447e052ce1 100644 > --- a/drivers/iommu/iommufd/device.c > +++ b/drivers/iommu/iommufd/device.c > @@ -381,10 +381,26 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, > goto err_unresv; > idev->igroup->hwpt = hwpt; > } > + if (hwpt_is_kvm(hwpt)) { > + /* > + * Feature IOPF requires ats is enabled which is true only > + * after device is attached to iommu domain. > + * So enable dev feature IOPF after iommu_attach_group(). > + * -EBUSY will be returned if feature IOPF is already on. > + */ > + rc = iommu_dev_enable_feature(idev->dev, IOMMU_DEV_FEAT_IOPF); > + if (rc && rc != -EBUSY) > + goto err_detach; I would like to remove IOMMU_DEV_FEAT_IOPF completely please Jason
On Mon, Dec 04, 2023 at 02:36:03PM -0400, Jason Gunthorpe wrote: > On Sat, Dec 02, 2023 at 05:23:11PM +0800, Yan Zhao wrote: > > Enable device feature IOPF during device attachment to KVM HWPT and abort > > the attachment if feature enabling is failed. > > > > "pin" is not done by KVM HWPT. If VMM wants to create KVM HWPT, it must > > know that all devices attached to this HWPT support IOPF so that pin-all > > is skipped. > > > > Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> > > --- > > drivers/iommu/iommufd/device.c | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c > > index 83af6b7e2784b..4ea447e052ce1 100644 > > --- a/drivers/iommu/iommufd/device.c > > +++ b/drivers/iommu/iommufd/device.c > > @@ -381,10 +381,26 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, > > goto err_unresv; > > idev->igroup->hwpt = hwpt; > > } > > + if (hwpt_is_kvm(hwpt)) { > > + /* > > + * Feature IOPF requires ats is enabled which is true only > > + * after device is attached to iommu domain. > > + * So enable dev feature IOPF after iommu_attach_group(). > > + * -EBUSY will be returned if feature IOPF is already on. > > + */ > > + rc = iommu_dev_enable_feature(idev->dev, IOMMU_DEV_FEAT_IOPF); > > + if (rc && rc != -EBUSY) > > + goto err_detach; > > I would like to remove IOMMU_DEV_FEAT_IOPF completely please So, turn on device PRI during device attachment in IOMMU vendor driver?
On Tue, Dec 05, 2023 at 03:14:09PM +0800, Yan Zhao wrote: > > I would like to remove IOMMU_DEV_FEAT_IOPF completely please > > So, turn on device PRI during device attachment in IOMMU vendor driver? If a fault requesting domain is attached then PRI should just be enabled in the driver Jason
On Tue, Dec 05, 2023 at 10:53:41AM -0400, Jason Gunthorpe wrote: > On Tue, Dec 05, 2023 at 03:14:09PM +0800, Yan Zhao wrote: > > > > I would like to remove IOMMU_DEV_FEAT_IOPF completely please > > > > So, turn on device PRI during device attachment in IOMMU vendor driver? > > If a fault requesting domain is attached then PRI should just be > enabled in the driver > Right, it makes sense!
diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 83af6b7e2784b..4ea447e052ce1 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -381,10 +381,26 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, goto err_unresv; idev->igroup->hwpt = hwpt; } + if (hwpt_is_kvm(hwpt)) { + /* + * Feature IOPF requires ats is enabled which is true only + * after device is attached to iommu domain. + * So enable dev feature IOPF after iommu_attach_group(). + * -EBUSY will be returned if feature IOPF is already on. + */ + rc = iommu_dev_enable_feature(idev->dev, IOMMU_DEV_FEAT_IOPF); + if (rc && rc != -EBUSY) + goto err_detach; + } refcount_inc(&hwpt->obj.users); list_add_tail(&idev->group_item, &idev->igroup->device_list); mutex_unlock(&idev->igroup->lock); return 0; +err_detach: + if (list_empty(&idev->igroup->device_list)) { + iommu_detach_group(hwpt->domain, idev->igroup->group); + idev->igroup->hwpt = NULL; + } err_unresv: if (hwpt_is_paging(hwpt)) iopt_remove_reserved_iova(&to_hwpt_paging(hwpt)->ioas->iopt, @@ -408,6 +424,8 @@ iommufd_hw_pagetable_detach(struct iommufd_device *idev) if (hwpt_is_paging(hwpt)) iopt_remove_reserved_iova(&to_hwpt_paging(hwpt)->ioas->iopt, idev->dev); + if (hwpt_is_kvm(hwpt)) + iommu_dev_disable_feature(idev->dev, IOMMU_DEV_FEAT_IOPF); mutex_unlock(&idev->igroup->lock); /* Caller must destroy hwpt */