All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cornelia Huck <cohuck@redhat.com>
To: kwankhede@nvidia.com, alex.williamson@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	cordius.wu@huawei.com, eskultet@redhat.com,
	Cornelia Huck <cohuck@redhat.com>
Subject: [PATCH RFC] vfio/mdev: delay uevent after initialization complete
Date: Fri,  9 Feb 2018 11:27:16 +0100	[thread overview]
Message-ID: <20180209102716.32253-1-cohuck@redhat.com> (raw)

The registration code first registers the mdev device, and then
proceeds to populate sysfs. An userspace application that listens
for the ADD uevent is therefore likely to look for sysfs entries
that have not yet been created.

The canonical way to fix this is to use attribute groups that are
registered by the driver core before it sends the ADD uevent; I
unfortunately did not find a way to make this work in this case,
though.

An alternative approach is to suppress uevents before we register
with the core and generate the ADD uevent ourselves after the
sysfs infrastructure is in place.

Signed-off-by: Cornelia Huck <cohuck@redhat.com>
---

This feels like a band-aid, but I can't figure out how to handle creating
attribute groups when there's a callback in the parent involved.

This should address the issue with libvirt's processing of mdevs raised in
https://www.redhat.com/archives/libvir-list/2018-February/msg00023.html
- although libvirt will still need to deal with older kernels, of course.

Best to consider this an untested patch :)

---
 drivers/vfio/mdev/mdev_core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 126991046eb7..942e880d8e7f 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -335,6 +335,8 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
 	mdev->dev.release = mdev_device_release;
 	dev_set_name(&mdev->dev, "%pUl", uuid.b);
 
+	/* don't notify userspace until we're ready */
+	dev_set_uevent_suppress(&mdev->dev, 1);
 	ret = device_register(&mdev->dev);
 	if (ret) {
 		put_device(&mdev->dev);
@@ -350,6 +352,9 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
 		mdev_device_remove_ops(mdev, true);
 		goto create_failed;
 	}
+	/* all done, notify userspace */
+	dev_set_uevent_suppress(&mdev->dev, 0);
+	kobject_uevent(&mdev->dev.kobj, KOBJ_ADD);
 
 	mdev->type_kobj = kobj;
 	dev_dbg(&mdev->dev, "MDEV: created\n");
@@ -363,6 +368,10 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
 	return ret;
 
 create_failed:
+	/*
+	 * If we reach this, uevents are still suppressed for mdev->dev,
+	 * so we don't get a KOBJ_DEL uevent without a previous KOBJ_ADD.
+	 */
 	device_unregister(&mdev->dev);
 
 create_err:
-- 
2.13.6

             reply	other threads:[~2018-02-09 10:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 10:27 Cornelia Huck [this message]
2018-02-12 21:20 ` [PATCH RFC] vfio/mdev: delay uevent after initialization complete Alex Williamson
2018-02-13 13:09   ` Cornelia Huck
2018-02-14  0:15     ` Alex Williamson
2018-02-14 17:20       ` Cornelia Huck
2018-02-26 18:51         ` Cornelia Huck
2018-04-25 15:42         ` Greg Kroah-Hartman
2018-04-27 12:36           ` Cornelia Huck

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=20180209102716.32253-1-cohuck@redhat.com \
    --to=cohuck@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=cordius.wu@huawei.com \
    --cc=eskultet@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.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.