mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhenguo Yao <yaozhenguo1@gmail.com>
To: bhelgaas@google.com, alex.williamson@redhat.com
Cc: cohuck@redhat.com, jgg@ziepe.ca, mgurtovoy@nvidia.com,
	yishaih@nvidia.com, kvm@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	yaozhenguo@jd.com, Zhenguo Yao <yaozhenguo1@gmail.com>
Subject: [PATCH v1 2/2] vfio-pci: Don't do device reset when ignore_reset is setting
Date: Thu, 14 Oct 2021 17:57:48 +0800	[thread overview]
Message-ID: <20211014095748.84604-3-yaozhenguo1@gmail.com> (raw)
In-Reply-To: <20211014095748.84604-1-yaozhenguo1@gmail.com>

In some scenarios, vfio device can't do any reset in initialization
process. For example: Nvswitch and GPU A100 working in Shared NVSwitch
Virtualization Model. In such mode, The GPUs can't do any reset when
Guest VM is booting up.

So, Using ignore_reset to control whether to do PCI reset in
initialization. In Shared NVSwitch Virtualization Model, GPUs will
ignore reset when Gust VM booting up.

Signed-off-by: Zhenguo Yao <yaozhenguo1@gmail.com>
---
 drivers/vfio/pci/vfio_pci_core.c | 48 ++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 68198e0f2a63..83d3ef5d3a9c 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -254,11 +254,13 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev)
 	if (ret)
 		return ret;
 
-	/* If reset fails because of the device lock, fail this path entirely */
-	ret = pci_try_reset_function(pdev);
-	if (ret == -EAGAIN) {
-		pci_disable_device(pdev);
-		return ret;
+	if (!pdev->ignore_reset) {
+		/* If reset fails because of the device lock, fail this path entirely */
+		ret = pci_try_reset_function(pdev);
+		if (ret == -EAGAIN) {
+			pci_disable_device(pdev);
+			return ret;
+		}
 	}
 
 	vdev->reset_works = !ret;
@@ -388,25 +390,30 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
 	 */
 	pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
 
-	/*
-	 * Try to get the locks ourselves to prevent a deadlock. The
-	 * success of this is dependent on being able to lock the device,
-	 * which is not always possible.
-	 * We can not use the "try" reset interface here, which will
-	 * overwrite the previously restored configuration information.
-	 */
-	if (vdev->reset_works && pci_dev_trylock(pdev)) {
-		if (!__pci_reset_function_locked(pdev))
-			vdev->needs_reset = false;
-		pci_dev_unlock(pdev);
+	if (!pdev->ignore_reset) {
+		/*
+		 * Try to get the locks ourselves to prevent a deadlock. The
+		 * success of this is dependent on being able to lock the device,
+		 * which is not always possible.
+		 * We can not use the "try" reset interface here, which will
+		 * overwrite the previously restored configuration information.
+		 */
+		if (vdev->reset_works && pci_dev_trylock(pdev)) {
+			if (!__pci_reset_function_locked(pdev))
+				vdev->needs_reset = false;
+			pci_dev_unlock(pdev);
+		}
 	}
 
 	pci_restore_state(pdev);
 out:
 	pci_disable_device(pdev);
 
-	if (!vfio_pci_dev_set_try_reset(vdev->vdev.dev_set) && !disable_idle_d3)
-		vfio_pci_set_power_state(vdev, PCI_D3hot);
+	if (!pdev->ignore_reset) {
+		if (!vfio_pci_dev_set_try_reset(vdev->vdev.dev_set) &&
+					!disable_idle_d3)
+			vfio_pci_set_power_state(vdev, PCI_D3hot);
+	}
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_disable);
 
@@ -919,6 +926,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 
 		if (!vdev->reset_works)
 			return -EINVAL;
+		if (vdev->pdev->ignore_reset)
+			return -EINVAL;
 
 		vfio_pci_zap_and_down_write_memory_lock(vdev);
 		ret = pci_try_reset_function(vdev->pdev);
@@ -1007,6 +1016,9 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 		bool slot = false;
 		int group_idx, count = 0, ret = 0;
 
+		if (vdev->pdev->ignore_reset)
+			return -EINVAL;
+
 		minsz = offsetofend(struct vfio_pci_hot_reset, count);
 
 		if (copy_from_user(&hdr, (void __user *)arg, minsz))
-- 
2.27.0


  parent reply	other threads:[~2021-10-14  9:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14  9:57 [PATCH v1 0/2] Add ablility of VFIO driver to ignore reset when device don't need it Zhenguo Yao
2021-10-14  9:57 ` [PATCH v1 1/2] PCI: Add ignore_reset sysfs interface to control whether to do device reset in PCI drivers Zhenguo Yao
2021-10-14  9:57 ` Zhenguo Yao [this message]
2021-10-14 12:48 ` [PATCH v1 0/2] Add ablility of VFIO driver to ignore reset when device don't need it Alex Williamson
2021-10-14 13:37   ` Zhenguo Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014095748.84604-3-yaozhenguo1@gmail.com \
    --to=yaozhenguo1@gmail.com \
    --cc=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=cohuck@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mgurtovoy@nvidia.com \
    --cc=yaozhenguo@jd.com \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®