Skip to content

Commit 6bf8f22

Browse files
yishaihjgunthorpe
authored andcommitted
IB/mlx5: Introduce MLX5_IB_OBJECT_DEVX_ASYNC_CMD_FD
Introduce MLX5_IB_OBJECT_DEVX_ASYNC_CMD_FD and its initial implementation. This object is from type class FD and will be used to read DEVX async commands completion. The core layer should allow the driver to set object from type FD in a safe mode, this option was added with a matching comment in place. Signed-off-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent ce4eee5 commit 6bf8f22

5 files changed

Lines changed: 104 additions & 5 deletions

File tree

‎drivers/infiniband/core/rdma_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ void uverbs_close_fd(struct file *f)
801801
/* Pairs with filp->private_data in alloc_begin_fd_uobject */
802802
uverbs_uobject_put(uobj);
803803
}
804+
EXPORT_SYMBOL(uverbs_close_fd);
804805

805806
/*
806807
* Drop the ucontext off the ufile and completely disconnect it from the

‎drivers/infiniband/core/uverbs_uapi.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,18 @@ static int uapi_merge_obj_tree(struct uverbs_api *uapi,
188188
obj_elm->type_attrs = obj->type_attrs;
189189
obj_elm->type_class = obj->type_attrs->type_class;
190190
/*
191-
* Today drivers are only permitted to use idr_class
192-
* types. They cannot use FD types because we currently have
193-
* no way to revoke the fops pointer after device
194-
* disassociation.
191+
* Today drivers are only permitted to use idr_class and
192+
* fd_class types. We can revoke the IDR types during
193+
* disassociation, and the FD types require the driver to use
194+
* struct file_operations.owner to prevent the driver module
195+
* code from unloading while the file is open. This provides
196+
* enough safety that uverbs_close_fd() will continue to work.
197+
* Drivers using FD are responsible to handle disassociation of
198+
* the device on their own.
195199
*/
196200
if (WARN_ON(is_driver &&
197-
obj->type_attrs->type_class != &uverbs_idr_class))
201+
obj->type_attrs->type_class != &uverbs_idr_class &&
202+
obj->type_attrs->type_class != &uverbs_fd_class))
198203
return -EINVAL;
199204
}
200205

‎drivers/infiniband/hw/mlx5/devx.c‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,38 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_QUERY)(
11681168
cmd_out, cmd_out_len);
11691169
}
11701170

1171+
struct devx_async_event_queue {
1172+
spinlock_t lock;
1173+
wait_queue_head_t poll_wait;
1174+
struct list_head event_list;
1175+
};
1176+
1177+
struct devx_async_cmd_event_file {
1178+
struct ib_uobject uobj;
1179+
struct devx_async_event_queue ev_queue;
1180+
};
1181+
1182+
static void devx_init_event_queue(struct devx_async_event_queue *ev_queue)
1183+
{
1184+
spin_lock_init(&ev_queue->lock);
1185+
INIT_LIST_HEAD(&ev_queue->event_list);
1186+
init_waitqueue_head(&ev_queue->poll_wait);
1187+
}
1188+
1189+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_ASYNC_CMD_FD_ALLOC)(
1190+
struct uverbs_attr_bundle *attrs)
1191+
{
1192+
struct devx_async_cmd_event_file *ev_file;
1193+
1194+
struct ib_uobject *uobj = uverbs_attr_get_uobject(
1195+
attrs, MLX5_IB_ATTR_DEVX_ASYNC_CMD_FD_ALLOC_HANDLE);
1196+
1197+
ev_file = container_of(uobj, struct devx_async_cmd_event_file,
1198+
uobj);
1199+
devx_init_event_queue(&ev_file->ev_queue);
1200+
return 0;
1201+
}
1202+
11711203
static int devx_umem_get(struct mlx5_ib_dev *dev, struct ib_ucontext *ucontext,
11721204
struct uverbs_attr_bundle *attrs,
11731205
struct devx_umem *obj)
@@ -1313,6 +1345,38 @@ static int devx_umem_cleanup(struct ib_uobject *uobject,
13131345
return 0;
13141346
}
13151347

1348+
static ssize_t devx_async_cmd_event_read(struct file *filp, char __user *buf,
1349+
size_t count, loff_t *pos)
1350+
{
1351+
return -EINVAL;
1352+
}
1353+
1354+
static int devx_async_cmd_event_close(struct inode *inode, struct file *filp)
1355+
{
1356+
uverbs_close_fd(filp);
1357+
return 0;
1358+
}
1359+
1360+
static __poll_t devx_async_cmd_event_poll(struct file *filp,
1361+
struct poll_table_struct *wait)
1362+
{
1363+
return 0;
1364+
}
1365+
1366+
const struct file_operations devx_async_cmd_event_fops = {
1367+
.owner = THIS_MODULE,
1368+
.read = devx_async_cmd_event_read,
1369+
.poll = devx_async_cmd_event_poll,
1370+
.release = devx_async_cmd_event_close,
1371+
.llseek = no_llseek,
1372+
};
1373+
1374+
static int devx_hot_unplug_async_cmd_event_file(struct ib_uobject *uobj,
1375+
enum rdma_remove_reason why)
1376+
{
1377+
return 0;
1378+
};
1379+
13161380
DECLARE_UVERBS_NAMED_METHOD(
13171381
MLX5_IB_METHOD_DEVX_UMEM_REG,
13181382
UVERBS_ATTR_IDR(MLX5_IB_ATTR_DEVX_UMEM_REG_HANDLE,
@@ -1440,6 +1504,22 @@ DECLARE_UVERBS_NAMED_OBJECT(MLX5_IB_OBJECT_DEVX_UMEM,
14401504
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_UMEM_REG),
14411505
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_UMEM_DEREG));
14421506

1507+
1508+
DECLARE_UVERBS_NAMED_METHOD(
1509+
MLX5_IB_METHOD_DEVX_ASYNC_CMD_FD_ALLOC,
1510+
UVERBS_ATTR_FD(MLX5_IB_ATTR_DEVX_ASYNC_CMD_FD_ALLOC_HANDLE,
1511+
MLX5_IB_OBJECT_DEVX_ASYNC_CMD_FD,
1512+
UVERBS_ACCESS_NEW,
1513+
UA_MANDATORY));
1514+
1515+
DECLARE_UVERBS_NAMED_OBJECT(
1516+
MLX5_IB_OBJECT_DEVX_ASYNC_CMD_FD,
1517+
UVERBS_TYPE_ALLOC_FD(sizeof(struct devx_async_cmd_event_file),
1518+
devx_hot_unplug_async_cmd_event_file,
1519+
&devx_async_cmd_event_fops, "[devx_async_cmd]",
1520+
O_RDONLY),
1521+
&UVERBS_METHOD(MLX5_IB_METHOD_DEVX_ASYNC_CMD_FD_ALLOC));
1522+
14431523
static bool devx_is_supported(struct ib_device *device)
14441524
{
14451525
struct mlx5_ib_dev *dev = to_mdev(device);
@@ -1457,5 +1537,8 @@ const struct uapi_definition mlx5_ib_devx_defs[] = {
14571537
UAPI_DEF_CHAIN_OBJ_TREE_NAMED(
14581538
MLX5_IB_OBJECT_DEVX_UMEM,
14591539
UAPI_DEF_IS_OBJ_SUPPORTED(devx_is_supported)),
1540+
UAPI_DEF_CHAIN_OBJ_TREE_NAMED(
1541+
MLX5_IB_OBJECT_DEVX_ASYNC_CMD_FD,
1542+
UAPI_DEF_IS_OBJ_SUPPORTED(devx_is_supported)),
14601543
{},
14611544
};

‎include/rdma/uverbs_types.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct uverbs_obj_fd_type {
157157

158158
extern const struct uverbs_obj_type_class uverbs_idr_class;
159159
extern const struct uverbs_obj_type_class uverbs_fd_class;
160+
void uverbs_close_fd(struct file *f);
160161

161162
#define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \
162163
sizeof(char))

‎include/uapi/rdma/mlx5_user_ioctl_cmds.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,20 @@ enum mlx5_ib_devx_umem_methods {
113113
MLX5_IB_METHOD_DEVX_UMEM_DEREG,
114114
};
115115

116+
enum mlx5_ib_devx_async_cmd_fd_alloc_attrs {
117+
MLX5_IB_ATTR_DEVX_ASYNC_CMD_FD_ALLOC_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
118+
};
119+
120+
enum mlx5_ib_devx_async_cmd_fd_methods {
121+
MLX5_IB_METHOD_DEVX_ASYNC_CMD_FD_ALLOC = (1U << UVERBS_ID_NS_SHIFT),
122+
};
123+
116124
enum mlx5_ib_objects {
117125
MLX5_IB_OBJECT_DEVX = (1U << UVERBS_ID_NS_SHIFT),
118126
MLX5_IB_OBJECT_DEVX_OBJ,
119127
MLX5_IB_OBJECT_DEVX_UMEM,
120128
MLX5_IB_OBJECT_FLOW_MATCHER,
129+
MLX5_IB_OBJECT_DEVX_ASYNC_CMD_FD,
121130
};
122131

123132
enum mlx5_ib_flow_matcher_create_attrs {

0 commit comments

Comments
 (0)