lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <VI1PR0501MB22713FD54711E482C8627614D1180@VI1PR0501MB2271.eurprd05.prod.outlook.com>
Date:   Thu, 30 May 2019 08:58:54 +0000
From:   Parav Pandit <parav@...lanox.com>
To:     Alex Williamson <alex.williamson@...hat.com>
CC:     "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "cohuck@...hat.com" <cohuck@...hat.com>,
        "kwankhede@...dia.com" <kwankhede@...dia.com>,
        "cjia@...dia.com" <cjia@...dia.com>
Subject: RE: [PATCHv4 3/3] vfio/mdev: Synchronize device create/remove with
 parent removal

Hi Alex,

> -----Original Message-----
> From: Alex Williamson <alex.williamson@...hat.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ