[PATCH 407/437] infiniband/mlx5: convert to read/write iterators

Jens Axboe
2024-04-11T15:43:04Z

drivers/infiniband/hw/mlx5/cong.c | 19 ++++++++--------
drivers/infiniband/hw/mlx5/devx.c | 24 +++++++++----------
drivers/infiniband/hw/mlx5/main.c | 20 ++++++++--------
drivers/infiniband/hw/mlx5/mr.c | 38 +++++++++++++++----------------
4 files changed, 49 insertions(+), 52 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/cong.c b/drivers/infiniband/hw/mlx5/cong.c
index a78a067e3ce7..b7ca85f516fc 100644
--- a/drivers/infiniband/hw/mlx5/cong.c
+++ b/drivers/infiniband/hw/mlx5/cong.c
@@ -368,10 +368,10 @@ static int mlx5_ib_set_cc_params(struct mlx5_ib_dev *dev, u32 port_num,
return err;
}

-static ssize_t set_param(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t set_param(struct kiocb *iocb, struct iov_iter *from)
{
- struct mlx5_ib_dbg_param *param = filp->private_data;
+ struct mlx5_ib_dbg_param *param = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
int offset = param->offset;
char lbuf[11] = { };
u32 var;
@@ -380,7 +380,7 @@ static ssize_t set_param(struct file *filp, const char __user *buf,
if (count > sizeof(lbuf))
return -EINVAL;

- if (copy_from_user(lbuf, buf, count))
+ if (!copy_from_iter_full(lbuf, count, from))
return -EFAULT;

lbuf[sizeof(lbuf) - 1] = '\0';
@@ -392,10 +392,9 @@ static ssize_t set_param(struct file *filp, const char __user *buf,
return ret ? ret : count;
}

-static ssize_t get_param(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t get_param(struct kiocb *iocb, struct iov_iter *to)
{
- struct mlx5_ib_dbg_param *param = filp->private_data;
+ struct mlx5_ib_dbg_param *param = iocb->ki_filp->private_data;
int offset = param->offset;
u32 var = 0;
int ret;
@@ -409,14 +408,14 @@ static ssize_t get_param(struct file *filp, char __user *buf, size_t count,
if (ret < 0)
return ret;

- return simple_read_from_buffer(buf, count, pos, lbuf, ret);
+ return simple_copy_to_iter(lbuf, &iocb->ki_pos, ret, to);
}

static const struct file_operations dbg_cc_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .write = set_param,
- .read = get_param,
+ .write_iter = set_param,
+ .read_iter = get_param,
};

void mlx5_ib_cleanup_cong_debugfs(struct mlx5_ib_dev *dev, u32 port_num)
diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index 253fea374a72..a73c9ba11912 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -2595,11 +2595,11 @@ void mlx5_ib_devx_cleanup(struct mlx5_ib_dev *dev)
}
}

-static ssize_t devx_async_cmd_event_read(struct file *filp, char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t devx_async_cmd_event_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct devx_async_cmd_event_file *comp_ev_file = filp->private_data;
+ struct devx_async_cmd_event_file *comp_ev_file = iocb->ki_filp->private_data;
struct devx_async_event_queue *ev_queue = &comp_ev_file->ev_queue;
+ size_t count = iov_iter_count(to);
struct devx_async_data *event;
int ret = 0;
size_t eventsz;
@@ -2609,7 +2609,7 @@ static ssize_t devx_async_cmd_event_read(struct file *filp, char __user *buf,
while (list_empty(&ev_queue->event_list)) {
spin_unlock_irq(&ev_queue->lock);

- if (filp->f_flags & O_NONBLOCK)
+ if (iocb->ki_filp->f_flags & O_NONBLOCK)
return -EAGAIN;

if (wait_event_interruptible(
@@ -2639,7 +2639,7 @@ static ssize_t devx_async_cmd_event_read(struct file *filp, char __user *buf,
list_del(ev_queue->event_list.next);
spin_unlock_irq(&ev_queue->lock);

- if (copy_to_user(buf, &event->hdr, eventsz))
+ if (!copy_to_iter_full(&event->hdr, eventsz, to))
ret = -EFAULT;
else
ret = eventsz;
@@ -2670,18 +2670,18 @@ static __poll_t devx_async_cmd_event_poll(struct file *filp,

static const struct file_operations devx_async_cmd_event_fops = {
.owner = THIS_MODULE,
- .read = devx_async_cmd_event_read,
+ .read_iter = devx_async_cmd_event_read,
.poll = devx_async_cmd_event_poll,
.release = uverbs_uobject_fd_release,
.llseek = no_llseek,
};

-static ssize_t devx_async_event_read(struct file *filp, char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t devx_async_event_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct devx_async_event_file *ev_file = filp->private_data;
+ struct devx_async_event_file *ev_file = iocb->ki_filp->private_data;
struct devx_event_subscription *event_sub;
struct devx_async_event_data *event;
+ size_t count = iov_iter_count(to);
int ret = 0;
size_t eventsz;
bool omit_data;
@@ -2701,7 +2701,7 @@ static ssize_t devx_async_event_read(struct file *filp, char __user *buf,
while (list_empty(&ev_file->event_list)) {
spin_unlock_irq(&ev_file->lock);

- if (filp->f_flags & O_NONBLOCK)
+ if (iocb->ki_filp->f_flags & O_NONBLOCK)
return -EAGAIN;

if (wait_event_interruptible(ev_file->poll_wait,
@@ -2743,7 +2743,7 @@ static ssize_t devx_async_event_read(struct file *filp, char __user *buf,

spin_unlock_irq(&ev_file->lock);

- if (copy_to_user(buf, event_data, eventsz))
+ if (!copy_to_iter_full(event_data, eventsz, to))
/* This points to an application issue, not a kernel concern */
ret = -EFAULT;
else
@@ -2785,7 +2785,7 @@ static void devx_free_subscription(struct rcu_head *rcu)

static const struct file_operations devx_async_event_fops = {
.owner = THIS_MODULE,
- .read = devx_async_event_read,
+ .read_iter = devx_async_event_read,
.poll = devx_async_event_poll,
.release = uverbs_uobject_fd_release,
.llseek = no_llseek,
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index c2b557e64290..f531568cfead 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -3154,25 +3154,25 @@ static int mlx5_ib_rn_get_params(struct ib_device *device, u32 port_num,
return mlx5_rdma_rn_get_params(to_mdev(device)->mdev, device, params);
}

-static ssize_t delay_drop_timeout_read(struct file *filp, char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t delay_drop_timeout_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct mlx5_ib_delay_drop *delay_drop = filp->private_data;
+ struct mlx5_ib_delay_drop *delay_drop = iocb->ki_filp->private_data;
char lbuf[20];
int len;

len = snprintf(lbuf, sizeof(lbuf), "%u\n", delay_drop->timeout);
- return simple_read_from_buffer(buf, count, pos, lbuf, len);
+ return simple_copy_to_iter(lbuf, &iocb->ki_pos, len, to);
}

-static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t delay_drop_timeout_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct mlx5_ib_delay_drop *delay_drop = filp->private_data;
+ struct mlx5_ib_delay_drop *delay_drop = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
u32 timeout;
u32 var;

- if (kstrtouint_from_user(buf, count, 0, &var))
+ if (kstrtouint_from_iter(from, count, 0, &var))
return -EFAULT;

timeout = min_t(u32, roundup(var, 100), MLX5_MAX_DELAY_DROP_TIMEOUT_MS *
@@ -3189,8 +3189,8 @@ static ssize_t delay_drop_timeout_write(struct file *filp, const char __user *bu
static const struct file_operations fops_delay_drop_timeout = {
.owner = THIS_MODULE,
.open = simple_open,
- .write = delay_drop_timeout_write,
- .read = delay_drop_timeout_read,
+ .write_iter = delay_drop_timeout_write,
+ .read_iter = delay_drop_timeout_read,
};

static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev,
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index a8ee2ca1f4a1..779da5c2f911 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -366,14 +366,14 @@ static int resize_available_mrs(struct mlx5_cache_ent *ent, unsigned int target,
}
}

-static ssize_t size_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t size_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct mlx5_cache_ent *ent = filp->private_data;
+ struct mlx5_cache_ent *ent = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
u32 target;
int err;

- err = kstrtou32_from_user(buf, count, 0, &target);
+ err = kstrtou32_from_iter(from, count, 0, &target);
if (err)
return err;

@@ -404,10 +404,9 @@ static ssize_t size_write(struct file *filp, const char __user *buf,
return err;
}

-static ssize_t size_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t size_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct mlx5_cache_ent *ent = filp->private_data;
+ struct mlx5_cache_ent *ent = iocb->ki_filp->private_data;
char lbuf[20];
int err;

@@ -416,24 +415,24 @@ static ssize_t size_read(struct file *filp, char __user *buf, size_t count,
if (err < 0)
return err;

- return simple_read_from_buffer(buf, count, pos, lbuf, err);
+ return simple_copy_to_iter(lbuf, &iocb->ki_pos, err, to);
}

static const struct file_operations size_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .write = size_write,
- .read = size_read,
+ .write_iter = size_write,
+ .read_iter = size_read,
};

-static ssize_t limit_write(struct file *filp, const char __user *buf,
- size_t count, loff_t *pos)
+static ssize_t limit_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct mlx5_cache_ent *ent = filp->private_data;
+ struct mlx5_cache_ent *ent = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
u32 var;
int err;

- err = kstrtou32_from_user(buf, count, 0, &var);
+ err = kstrtou32_from_iter(from, count, 0, &var);
if (err)
return err;

@@ -450,10 +449,9 @@ static ssize_t limit_write(struct file *filp, const char __user *buf,
return count;
}

-static ssize_t limit_read(struct file *filp, char __user *buf, size_t count,
- loff_t *pos)
+static ssize_t limit_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct mlx5_cache_ent *ent = filp->private_data;
+ struct mlx5_cache_ent *ent = iocb->ki_filp->private_data;
char lbuf[20];
int err;

@@ -461,14 +459,14 @@ static ssize_t limit_read(struct file *filp, char __user *buf, size_t count,
if (err < 0)
return err;

- return simple_read_from_buffer(buf, count, pos, lbuf, err);
+ return simple_copy_to_iter(lbuf, &iocb->ki_pos, err, to);
}

static const struct file_operations limit_fops = {
.owner = THIS_MODULE,
.open = simple_open,
- .write = limit_write,
- .read = limit_read,
+ .write_iter = limit_write,
+ .read_iter = limit_read,
};

static bool someone_adding(struct mlx5_mkey_cache *cache)
--
2.43.0