LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Parav Pandit <parav@mellanox.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"cohuck@redhat.com" <cohuck@redhat.com>,
	"kwankhede@nvidia.com" <kwankhede@nvidia.com>,
	"cjia@nvidia.com" <cjia@nvidia.com>
Subject: RE: [PATCHv4 3/3] vfio/mdev: Synchronize device create/remove with parent removal
Date: Thu, 30 May 2019 08:58:54 +0000	[thread overview]
Message-ID: <VI1PR0501MB22713FD54711E482C8627614D1180@VI1PR0501MB2271.eurprd05.prod.outlook.com> (raw)
In-Reply-To: <20190529085633.7fcdf7d2@x1.home>

Hi Alex,

> -----Original Message-----
> From: Alex Williamson <alex.williamson@redhat.com>
> Sent: Wednesday, May 29, 2019 8:27 PM

[..]
> >
> > diff --git a/drivers/vfio/mdev/mdev_core.c
> > b/drivers/vfio/mdev/mdev_core.c index 0bef0cae1d4b..c5401a8c6843
> > 100644
> > --- a/drivers/vfio/mdev/mdev_core.c
> > +++ b/drivers/vfio/mdev/mdev_core.c
> > @@ -102,11 +102,36 @@ static void mdev_put_parent(struct mdev_parent
> *parent)
> >  		kref_put(&parent->ref, mdev_release_parent);  }
> >
> 
> Some sort of locking semantics comment would be useful here, ex:
> 
> /* Caller holds parent unreg_sem read or write lock */
> 
Added.

> > +
> >  static int mdev_device_remove_cb(struct device *dev, void *data)  {
> > -	if (dev_is_mdev(dev))
> > -		mdev_device_remove(dev);
> > +	struct mdev_parent *parent;
> > +	struct mdev_device *mdev;
> >
> > +	if (!dev_is_mdev(dev))
> > +		return 0;
> > +
> > +	mdev = to_mdev_device(dev);
> > +	parent = mdev->parent;
> > +	mdev_device_remove_common(mdev);
> 
> 'parent' is unused here and we only use mdev once, so we probably don't need
> to put it in a local variable.
> 
Right left out from previous code.
Removed and refactored the code now.

> >  	return 0;
> >  }
> >
> > @@ -148,6 +173,7 @@ int mdev_register_device(struct device *dev, const
> struct mdev_parent_ops *ops)
> >  	}
> >
> >  	kref_init(&parent->ref);
> > +	init_rwsem(&parent->unreg_sem);
> >
> >  	parent->dev = dev;
> >  	parent->ops = ops;
> > @@ -206,13 +232,17 @@ void mdev_unregister_device(struct device *dev)
> >  	dev_info(dev, "MDEV: Unregistering\n");
> >
> >  	list_del(&parent->next);
> > +	mutex_unlock(&parent_list_lock);
> > +
> > +	down_write(&parent->unreg_sem);
> > +
> >  	class_compat_remove_link(mdev_bus_compat_class, dev, NULL);
> >
> >  	device_for_each_child(dev, NULL, mdev_device_remove_cb);
> >
> >  	parent_remove_sysfs_files(parent);
> > +	up_write(&parent->unreg_sem);
> >
> > -	mutex_unlock(&parent_list_lock);
> >  	mdev_put_parent(parent);
> >  }
> >  EXPORT_SYMBOL(mdev_unregister_device);
> > @@ -265,6 +295,12 @@ int mdev_device_create(struct kobject *kobj,
> >
> >  	mdev->parent = parent;
> >
> > +	ret = down_read_trylock(&parent->unreg_sem);
> > +	if (!ret) {
> > +		ret = -ENODEV;
> 
> I would have expected -EAGAIN or -EBUSY here, but I guess that since we
> consider the lock-out to deterministically be the parent going away that -
> ENODEV makes sense.  Ok.
> 
Yeah, I agree that ENODEV is more accurate error code as we don't want to tell user to retry so EAGAIN is less appropriate.
Sending v5.

      reply	other threads:[~2019-05-30  8:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-24 13:57 [PATCHv4 0/3] vfio/mdev: Improve vfio/mdev core module Parav Pandit
2019-05-24 13:57 ` [PATCHv4 1/3] vfio/mdev: Improve the create/remove sequence Parav Pandit
2019-05-24 13:57 ` [PATCHv4 2/3] vfio/mdev: Avoid creating sysfs remove file on stale device removal Parav Pandit
2019-05-24 13:57 ` [PATCHv4 3/3] vfio/mdev: Synchronize device create/remove with parent removal Parav Pandit
2019-05-29 14:56   ` Alex Williamson
2019-05-30  8:58     ` Parav Pandit [this message]

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=VI1PR0501MB22713FD54711E482C8627614D1180@VI1PR0501MB2271.eurprd05.prod.outlook.com \
    --to=parav@mellanox.com \
    --cc=alex.williamson@redhat.com \
    --cc=cjia@nvidia.com \
    --cc=cohuck@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='RE: [PATCHv4 3/3] vfio/mdev: Synchronize device create/remove with parent removal' \
    /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

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