From: Alex Williamson alex.williamson@redhat.com
mainline inclusion from mainline-5.3 commit 1e4d09d2212d9e230b967f57bc8df463527dbd75 category: feature bugzilla: NA CVE: NA
-------------------------------------------------
This allows udev to trigger rules when a parent device is registered or unregistered from mdev.
Reviewed-by: Cornelia Huck cohuck@redhat.com Reviewed-by: Kirti Wankhede kwankhede@nvidia.com Signed-off-by: Alex Williamson alex.williamson@redhat.com Signed-off-by: Xiaoyang Xu xuxiaoyang2@huawei.com Reviewed-by: Yingtai Xie xieyingtai@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- 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 c4a4659..b768a6f 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -147,6 +147,8 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) { int ret; struct mdev_parent *parent; + char *env_string = "MDEV_STATE=registered"; + char *envp[] = { env_string, NULL };
/* check for mandatory ops */ if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups) @@ -198,6 +200,8 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) mutex_unlock(&parent_list_lock);
dev_info(dev, "MDEV: Registered\n"); + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); + return 0;
add_dev_err: @@ -221,6 +225,8 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) void mdev_unregister_device(struct device *dev) { struct mdev_parent *parent; + char *env_string = "MDEV_STATE=unregistered"; + char *envp[] = { env_string, NULL };
mutex_lock(&parent_list_lock); parent = __find_parent_device(dev); @@ -244,6 +250,9 @@ void mdev_unregister_device(struct device *dev) up_write(&parent->unreg_sem);
mdev_put_parent(parent); + + /* We still have the caller's reference to use for the uevent */ + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); } EXPORT_SYMBOL(mdev_unregister_device);