2016-11-16 23:46:13 +03:00
|
|
|
/*
|
|
|
|
* Mediated device interal definitions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
* Author: Neo Jia <cjia@nvidia.com>
|
|
|
|
* Kirti Wankhede <kwankhede@nvidia.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MDEV_PRIVATE_H
|
|
|
|
#define MDEV_PRIVATE_H
|
|
|
|
|
|
|
|
int mdev_bus_register(void);
|
|
|
|
void mdev_bus_unregister(void);
|
|
|
|
|
2016-12-30 18:13:41 +03:00
|
|
|
struct mdev_parent {
|
|
|
|
struct device *dev;
|
|
|
|
const struct mdev_parent_ops *ops;
|
|
|
|
struct kref ref;
|
|
|
|
struct list_head next;
|
|
|
|
struct kset *mdev_types_kset;
|
|
|
|
struct list_head type_list;
|
|
|
|
};
|
|
|
|
|
2016-12-30 18:13:44 +03:00
|
|
|
struct mdev_device {
|
|
|
|
struct device dev;
|
|
|
|
struct mdev_parent *parent;
|
2019-01-10 22:00:27 +03:00
|
|
|
guid_t uuid;
|
2016-12-30 18:13:44 +03:00
|
|
|
void *driver_data;
|
|
|
|
struct kref ref;
|
|
|
|
struct list_head next;
|
|
|
|
struct kobject *type_kobj;
|
vfio/mdev: Check globally for duplicate devices
When we create an mdev device, we check for duplicates against the
parent device and return -EEXIST if found, but the mdev device
namespace is global since we'll link all devices from the bus. We do
catch this later in sysfs_do_create_link_sd() to return -EEXIST, but
with it comes a kernel warning and stack trace for trying to create
duplicate sysfs links, which makes it an undesirable response.
Therefore we should really be looking for duplicates across all mdev
parent devices, or as implemented here, against our mdev device list.
Using mdev_list to prevent duplicates means that we can remove
mdev_parent.lock, but in order not to serialize mdev device creation
and removal globally, we add mdev_device.active which allows UUIDs to
be reserved such that we can drop the mdev_list_lock before the mdev
device is fully in place.
Two behavioral notes; first, mdev_parent.lock had the side-effect of
serializing mdev create and remove ops per parent device. This was
an implementation detail, not an intentional guarantee provided to
the mdev vendor drivers. Vendor drivers can trivially provide this
serialization internally if necessary. Second, review comments note
the new -EAGAIN behavior when the device, and in particular the remove
attribute, becomes visible in sysfs. If a remove is triggered prior
to completion of mdev_device_create() the user will see a -EAGAIN
error. While the errno is different, receiving an error during this
period is not, the previous implementation returned -ENODEV for the
same condition. Furthermore, the consistency to the user is improved
in the case where mdev_device_remove_ops() returns error. Previously
concurrent calls to mdev_device_remove() could see the device
disappear with -ENODEV and return in the case of error. Now a user
would see -EAGAIN while the device is in this transitory state.
Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Halil Pasic <pasic@linux.ibm.com>
Acked-by: Zhenyu Wang <zhenyuw@linux.intel.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2018-05-15 22:53:55 +03:00
|
|
|
bool active;
|
2016-12-30 18:13:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
|
|
|
|
#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
|
|
|
|
|
2016-11-16 23:46:13 +03:00
|
|
|
struct mdev_type {
|
|
|
|
struct kobject kobj;
|
|
|
|
struct kobject *devices_kobj;
|
2016-12-30 18:13:38 +03:00
|
|
|
struct mdev_parent *parent;
|
2016-11-16 23:46:13 +03:00
|
|
|
struct list_head next;
|
|
|
|
struct attribute_group *group;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_mdev_type_attr(_attr) \
|
|
|
|
container_of(_attr, struct mdev_type_attribute, attr)
|
|
|
|
#define to_mdev_type(_kobj) \
|
|
|
|
container_of(_kobj, struct mdev_type, kobj)
|
|
|
|
|
2016-12-30 18:13:38 +03:00
|
|
|
int parent_create_sysfs_files(struct mdev_parent *parent);
|
|
|
|
void parent_remove_sysfs_files(struct mdev_parent *parent);
|
2016-11-16 23:46:13 +03:00
|
|
|
|
|
|
|
int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
|
|
|
|
void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
|
|
|
|
|
2019-01-10 22:00:27 +03:00
|
|
|
int mdev_device_create(struct kobject *kobj,
|
|
|
|
struct device *dev, const guid_t *uuid);
|
2016-11-16 23:46:13 +03:00
|
|
|
int mdev_device_remove(struct device *dev, bool force_remove);
|
|
|
|
|
|
|
|
#endif /* MDEV_PRIVATE_H */
|