Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 34b1aba

Browse files
jgunthorpezhiwang1
authored andcommitted
vfio/mdev: Use the driver core to create the 'remove' file
The device creator is supposed to use the dev.groups value to add sysfs files before device_add is called, not call sysfs_create_files() after device_add() returns. This creates a race with uevent delivery where the extra attribute will not be visible. This was being done because the groups had been co-opted by the mdev driver, now that prior patches have moved the driver's groups to the struct device_driver the dev.group is properly free for use here. Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Zhi Wang <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Kirti Wankhede <[email protected]> Reviewed-by: Zhi Wang <[email protected]>
1 parent aea1162 commit 34b1aba

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

drivers/vfio/mdev/mdev_core.c

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid)
269269
mdev->dev.parent = parent->dev;
270270
mdev->dev.bus = &mdev_bus_type;
271271
mdev->dev.release = mdev_device_release;
272+
mdev->dev.groups = mdev_device_groups;
272273
mdev->type = type;
273274
/* Pairs with the put in mdev_device_release() */
274275
kobject_get(&type->kobj);

drivers/vfio/mdev/mdev_private.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct mdev_type {
3232
unsigned int type_group_id;
3333
};
3434

35+
extern const struct attribute_group *mdev_device_groups[];
36+
3537
#define to_mdev_type_attr(_attr) \
3638
container_of(_attr, struct mdev_type_attribute, attr)
3739
#define to_mdev_type(_kobj) \

drivers/vfio/mdev/mdev_sysfs.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,20 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
244244

245245
static DEVICE_ATTR_WO(remove);
246246

247-
static const struct attribute *mdev_device_attrs[] = {
247+
static struct attribute *mdev_device_attrs[] = {
248248
&dev_attr_remove.attr,
249249
NULL,
250250
};
251251

252+
static const struct attribute_group mdev_device_group = {
253+
.attrs = mdev_device_attrs,
254+
};
255+
256+
const struct attribute_group *mdev_device_groups[] = {
257+
&mdev_device_group,
258+
NULL
259+
};
260+
252261
int mdev_create_sysfs_files(struct mdev_device *mdev)
253262
{
254263
struct mdev_type *type = mdev->type;
@@ -262,15 +271,8 @@ int mdev_create_sysfs_files(struct mdev_device *mdev)
262271
ret = sysfs_create_link(kobj, &type->kobj, "mdev_type");
263272
if (ret)
264273
goto type_link_failed;
265-
266-
ret = sysfs_create_files(kobj, mdev_device_attrs);
267-
if (ret)
268-
goto create_files_failed;
269-
270274
return ret;
271275

272-
create_files_failed:
273-
sysfs_remove_link(kobj, "mdev_type");
274276
type_link_failed:
275277
sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev));
276278
return ret;
@@ -280,7 +282,6 @@ void mdev_remove_sysfs_files(struct mdev_device *mdev)
280282
{
281283
struct kobject *kobj = &mdev->dev.kobj;
282284

283-
sysfs_remove_files(kobj, mdev_device_attrs);
284285
sysfs_remove_link(kobj, "mdev_type");
285286
sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev));
286287
}

0 commit comments

Comments
 (0)