kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Cornelia Huck <cohuck@redhat.com>
Cc: kwankhede@nvidia.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, cordius.wu@huawei.com,
	eskultet@redhat.com
Subject: Re: [PATCH RFC] vfio/mdev: delay uevent after initialization complete
Date: Mon, 12 Feb 2018 14:20:57 -0700	[thread overview]
Message-ID: <20180212142057.66e2b15c@w520.home> (raw)
In-Reply-To: <20180209102716.32253-1-cohuck@redhat.com>

On Fri,  9 Feb 2018 11:27:16 +0100
Cornelia Huck <cohuck@redhat.com> wrote:

> 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 :)

I agree, this feels like a band-aide.  If every device in the kernel
needs to suppress udev events until until some key component is added,
that suggests that either udev is broken in general or not being used
as intended.  Zongyong submitted a different proposal to fix this
here[1].  That proposal seems a bit more sound and has precedence
elsewhere in the kernel.  What do you think of that approach?  We
don't need both afaict.  Thanks,

Alex

[1]https://patchwork.kernel.org/patch/10196197/

> ---
>  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:

  reply	other threads:[~2018-02-12 21:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 10:27 [PATCH RFC] vfio/mdev: delay uevent after initialization complete Cornelia Huck
2018-02-12 21:20 ` Alex Williamson [this message]
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=20180212142057.66e2b15c@w520.home \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).