All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	kvm@vger.kernel.org, "Rafael J. Wysocki" <rafael@kernel.org>
Subject: [PATCH 04/10] driver core: Don't return EPROBE_DEFER to userspace during sysfs bind
Date: Mon,  7 Jun 2021 21:55:46 -0300	[thread overview]
Message-ID: <4-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> (raw)
In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com>

EPROBE_DEFER is an internal kernel error code and it should not be leaked
to userspace via the bind_store() sysfs. Userspace doesn't have this
constant and cannot understand it.

Further, it doesn't really make sense to have userspace trigger a deferred
probe via bind_store(), which could eventually succeed, while
simultaneously returning an error back.

Resolve this by preventing EPROBE_DEFER from triggering a deferred probe
and simply relay the whole situation back to userspace as a normal -EAGAIN
code.

Put this in the device_driver_attach() so the EPROBE_DEFER remains
contained to dd.c and the probe() implementations.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/base/dd.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7fb58e6219b255..edda7aad43a3f7 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -516,12 +516,17 @@ static DEVICE_ATTR_RO(state_synced);
 enum {
 	/* Set on output if the -ERR has come from a probe() function */
 	PROBEF_DRV_FAILED = 1 << 0,
+	/*
+	 * Set on input to call driver_deferred_probe_add() if -EPROBE_DEFER
+	 * is returned
+	 */
+	PROBEF_SCHEDULE_DEFER = 1 << 1,
 };
 
 static int really_probe(struct device *dev, struct device_driver *drv,
 			unsigned int *flags)
 {
-	int ret = -EPROBE_DEFER;
+	int ret;
 	int local_trigger_count = atomic_read(&deferred_trigger_count);
 	bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
 			   !drv->suppress_bind_attrs;
@@ -533,15 +538,18 @@ static int really_probe(struct device *dev, struct device_driver *drv,
 		 * wait_for_device_probe() right after that to avoid any races.
 		 */
 		dev_dbg(dev, "Driver %s force probe deferral\n", drv->name);
-		driver_deferred_probe_add(dev);
-		return ret;
+		if (*flags & PROBEF_SCHEDULE_DEFER)
+			driver_deferred_probe_add(dev);
+		return -EPROBE_DEFER;
 	}
 
 	ret = device_links_check_suppliers(dev);
-	if (ret == -EPROBE_DEFER)
-		driver_deferred_probe_add_trigger(dev, local_trigger_count);
-	if (ret)
+	if (ret) {
+		if (ret == -EPROBE_DEFER && *flags & PROBEF_SCHEDULE_DEFER)
+			driver_deferred_probe_add_trigger(dev,
+							  local_trigger_count);
 		return ret;
+	}
 
 	atomic_inc(&probe_count);
 	pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
@@ -664,7 +672,9 @@ static int really_probe(struct device *dev, struct device_driver *drv,
 	case -EPROBE_DEFER:
 		/* Driver requested deferred probing */
 		dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
-		driver_deferred_probe_add_trigger(dev, local_trigger_count);
+		if (*flags & PROBEF_SCHEDULE_DEFER)
+			driver_deferred_probe_add_trigger(dev,
+							  local_trigger_count);
 		break;
 	case -ENODEV:
 	case -ENXIO:
@@ -853,7 +863,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
 	struct device_attach_data *data = _data;
 	struct device *dev = data->dev;
 	bool async_allowed;
-	int flags = 0;
+	int flags = PROBEF_SCHEDULE_DEFER;
 	int ret;
 
 	ret = driver_match_device(drv, dev);
@@ -1043,7 +1053,9 @@ static void __device_driver_unlock(struct device *dev, struct device *parent)
  * @dev: Device to attach it to
  *
  * Manually attach driver to a device. Will acquire both @dev lock and
- * @dev->parent lock if needed. Returns 0 on success, -ERR on failure.
+ * @dev->parent lock if needed. Returns 0 on success, -ERR on failure. If
+ * EPROBE_DEFER is returned from probe() then no background probe is scheduled
+ * and -EAGAIN will be returned.
  */
 int device_driver_attach(struct device_driver *drv, struct device *dev)
 {
@@ -1061,6 +1073,8 @@ int device_driver_attach(struct device_driver *drv, struct device *dev)
 
 	__device_driver_unlock(dev, dev->parent);
 
+	if (ret == -EPROBE_DEFER)
+		return -EAGAIN;
 	return ret;
 }
 
@@ -1068,7 +1082,7 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
 {
 	struct device *dev = _dev;
 	struct device_driver *drv;
-	unsigned int flags = 0;
+	unsigned int flags = PROBEF_SCHEDULE_DEFER;
 	int ret;
 
 	__device_driver_lock(dev, dev->parent);
@@ -1083,6 +1097,7 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
 
 static int __driver_attach(struct device *dev, void *data)
 {
+	unsigned int flags = PROBEF_SCHEDULE_DEFER;
 	struct device_driver *drv = data;
 	int ret;
 
@@ -1128,7 +1143,9 @@ static int __driver_attach(struct device *dev, void *data)
 		return 0;
 	}
 
-	device_driver_attach(drv, dev);
+	__device_driver_lock(dev, dev->parent);
+	driver_probe_device(drv, dev, &flags);
+	__device_driver_unlock(dev, dev->parent);
 
 	return 0;
 }
-- 
2.31.1


  parent reply	other threads:[~2021-06-08  0:56 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08  0:55 [PATCH 00/10] Allow mdev drivers to directly create the vfio_device Jason Gunthorpe
2021-06-08  0:55 ` [Intel-gfx] " Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 01/10] driver core: Do not continue searching for drivers if deferred probe is used Jason Gunthorpe
2021-06-08  5:51   ` Christoph Hellwig
2021-06-08  6:44   ` Greg Kroah-Hartman
2021-06-08 12:16     ` Jason Gunthorpe
2021-06-08 13:13       ` Greg Kroah-Hartman
2021-06-08 13:53         ` Jason Gunthorpe
2021-06-08  7:35   ` Greg Kroah-Hartman
2021-06-08 12:17     ` Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 02/10] driver core: Pull required checks into driver_probe_device() Jason Gunthorpe
2021-06-08  5:59   ` Christoph Hellwig
2021-06-08 12:21     ` Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 03/10] driver core: Flow the return code from ->probe() through to sysfs bind Jason Gunthorpe
2021-06-08  6:07   ` Christoph Hellwig
2021-06-08 23:53     ` Jason Gunthorpe
2021-06-08  6:47   ` Greg Kroah-Hartman
2021-06-08 12:30     ` Jason Gunthorpe
2021-06-08 13:16       ` Greg Kroah-Hartman
2021-06-08 14:03         ` Jason Gunthorpe
2021-06-08  0:55 ` Jason Gunthorpe [this message]
2021-06-08  6:14   ` [PATCH 04/10] driver core: Don't return EPROBE_DEFER to userspace during " Christoph Hellwig
2021-06-08  7:37   ` Greg Kroah-Hartman
2021-06-08  0:55 ` [PATCH 05/10] driver core: Export device_driver_attach() Jason Gunthorpe
2021-06-08  6:19   ` Christoph Hellwig
2021-06-08 12:33     ` Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 06/10] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
2021-06-08  0:55   ` [Intel-gfx] " Jason Gunthorpe
2021-06-08  6:20   ` Christoph Hellwig
2021-06-08  6:20     ` [Intel-gfx] " Christoph Hellwig
2021-06-11 12:40   ` Cornelia Huck
2021-06-11 12:40     ` [Intel-gfx] " Cornelia Huck
2021-06-14 12:35     ` Jason Gunthorpe
2021-06-14 12:35       ` [Intel-gfx] " Jason Gunthorpe
2021-06-14 12:35       ` Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 07/10] vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind Jason Gunthorpe
2021-06-08  6:21   ` Christoph Hellwig
2021-06-08  0:55 ` [PATCH 08/10] vfio/mtty: Convert to use vfio_register_group_dev() Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 09/10] vfio/mdpy: " Jason Gunthorpe
2021-06-08  0:55 ` [PATCH 10/10] vfio/mbochs: " Jason Gunthorpe
2021-06-08  6:22 ` [PATCH 00/10] Allow mdev drivers to directly create the vfio_device Christoph Hellwig
2021-06-08  6:22   ` [Intel-gfx] " Christoph Hellwig
2021-06-14 14:34 ` Kirti Wankhede
2021-06-14 14:34   ` [Intel-gfx] " Kirti Wankhede
2021-06-14 14:34   ` Kirti Wankhede
2021-06-14 14:36   ` Jason Gunthorpe
2021-06-14 14:36     ` [Intel-gfx] " Jason Gunthorpe
2021-06-14 14:36     ` Jason Gunthorpe
2021-06-14 15:08 Allow mdev drivers to directly create the vfio_device (v2 / alternative) Christoph Hellwig
2021-06-14 15:08 ` [PATCH 04/10] driver core: Don't return EPROBE_DEFER to userspace during sysfs bind Christoph Hellwig
2021-06-14 22:43   ` Jason Gunthorpe
2021-06-14 22:43     ` Jason Gunthorpe
2021-06-15 13:35 Allow mdev drivers to directly create the vfio_device (v3) Christoph Hellwig
2021-06-15 13:35 ` [PATCH 04/10] driver core: Don't return EPROBE_DEFER to userspace during sysfs bind Christoph Hellwig
2021-06-15 14:03   ` Cornelia Huck
2021-06-15 14:03     ` Cornelia Huck
2021-06-15 19:36   ` Alex Williamson
2021-06-15 19:36     ` Alex Williamson
2021-06-17 14:22 Allow mdev drivers to directly create the vfio_device (v4) Christoph Hellwig
2021-06-17 14:22 ` [PATCH 04/10] driver core: Don't return EPROBE_DEFER to userspace during sysfs bind Christoph Hellwig

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=4-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvm@vger.kernel.org \
    --cc=rafael@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.