[PATCH 079/437] rv: convert to read/write iterators

From: Jens Axboe
Date: Thu Apr 11 2024 - 11:56:49 EST


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
kernel/trace/rv/rv.c | 58 +++++++++++++++++------------------
kernel/trace/rv/rv_reactors.c | 32 +++++++++----------
2 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c
index 2f68e93fff0b..7402b77a1b89 100644
--- a/kernel/trace/rv/rv.c
+++ b/kernel/trace/rv/rv.c
@@ -209,15 +209,14 @@ void rv_put_task_monitor_slot(int slot)
/*
* This section collects the monitor/ files and folders.
*/
-static ssize_t monitor_enable_read_data(struct file *filp, char __user *user_buf, size_t count,
- loff_t *ppos)
+static ssize_t monitor_enable_read_data(struct kiocb *iocb, struct iov_iter *to)
{
- struct rv_monitor_def *mdef = filp->private_data;
+ struct rv_monitor_def *mdef = iocb->ki_filp->private_data;
const char *buff;

buff = mdef->monitor->enabled ? "1\n" : "0\n";

- return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff)+1);
+ return simple_copy_to_iter(buff, &iocb->ki_pos, strlen(buff)+1, to);
}

/*
@@ -279,14 +278,15 @@ int rv_enable_monitor(struct rv_monitor_def *mdef)
/*
* interface for enabling/disabling a monitor.
*/
-static ssize_t monitor_enable_write_data(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t monitor_enable_write_data(struct kiocb *iocb,
+ struct iov_iter *from)
{
- struct rv_monitor_def *mdef = filp->private_data;
+ struct rv_monitor_def *mdef = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);
int retval;
bool val;

- retval = kstrtobool_from_user(user_buf, count, &val);
+ retval = kstrtobool_from_iter(from, count, &val);
if (retval)
return retval;

@@ -305,30 +305,29 @@ static ssize_t monitor_enable_write_data(struct file *filp, const char __user *u
static const struct file_operations interface_enable_fops = {
.open = simple_open,
.llseek = no_llseek,
- .write = monitor_enable_write_data,
- .read = monitor_enable_read_data,
+ .write_iter = monitor_enable_write_data,
+ .read_iter = monitor_enable_read_data,
};

/*
* Interface to read monitors description.
*/
-static ssize_t monitor_desc_read_data(struct file *filp, char __user *user_buf, size_t count,
- loff_t *ppos)
+static ssize_t monitor_desc_read_data(struct kiocb *iocb, struct iov_iter *to)
{
- struct rv_monitor_def *mdef = filp->private_data;
+ struct rv_monitor_def *mdef = iocb->ki_filp->private_data;
char buff[256];

memset(buff, 0, sizeof(buff));

snprintf(buff, sizeof(buff), "%s\n", mdef->monitor->description);

- return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff) + 1);
+ return simple_copy_to_iter(buff, &iocb->ki_pos, strlen(buff) + 1, to);
}

static const struct file_operations interface_desc_fops = {
.open = simple_open,
.llseek = no_llseek,
- .read = monitor_desc_read_data,
+ .read_iter = monitor_desc_read_data,
};

/*
@@ -469,7 +468,7 @@ static int available_monitors_open(struct inode *inode, struct file *file)

static const struct file_operations available_monitors_ops = {
.open = available_monitors_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = seq_release
};
@@ -507,10 +506,10 @@ static int enabled_monitors_open(struct inode *inode, struct file *file)
return seq_open(file, &enabled_monitors_seq_ops);
};

-static ssize_t enabled_monitors_write(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t enabled_monitors_write(struct kiocb *iocb, struct iov_iter *from)
{
char buff[MAX_RV_MONITOR_NAME_SIZE + 2];
+ size_t count = iov_iter_count(from);
struct rv_monitor_def *mdef;
int retval = -EINVAL;
bool enable = true;
@@ -522,7 +521,8 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user

memset(buff, 0, sizeof(buff));

- retval = simple_write_to_buffer(buff, sizeof(buff) - 1, ppos, user_buf, count);
+ retval = simple_copy_from_iter(buff, &iocb->ki_pos, sizeof(buff) - 1,
+ from);
if (retval < 0)
return -EFAULT;

@@ -565,8 +565,8 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user

static const struct file_operations enabled_monitors_ops = {
.open = enabled_monitors_open,
- .read = seq_read,
- .write = enabled_monitors_write,
+ .read_iter = seq_read_iter,
+ .write_iter = enabled_monitors_write,
.llseek = seq_lseek,
.release = seq_release,
};
@@ -591,14 +591,13 @@ bool rv_monitoring_on(void)
/*
* monitoring_on general switcher.
*/
-static ssize_t monitoring_on_read_data(struct file *filp, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t monitoring_on_read_data(struct kiocb *iocb, struct iov_iter *to)
{
const char *buff;

buff = rv_monitoring_on() ? "1\n" : "0\n";

- return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff) + 1);
+ return simple_copy_to_iter(buff, &iocb->ki_pos, strlen(buff) + 1, to);
}

static void turn_monitoring_off(void)
@@ -642,13 +641,14 @@ static void turn_monitoring_on_with_reset(void)
turn_monitoring_on();
}

-static ssize_t monitoring_on_write_data(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t monitoring_on_write_data(struct kiocb *iocb,
+ struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
int retval;
bool val;

- retval = kstrtobool_from_user(user_buf, count, &val);
+ retval = kstrtobool_from_iter(from, count, &val);
if (retval)
return retval;

@@ -673,8 +673,8 @@ static ssize_t monitoring_on_write_data(struct file *filp, const char __user *us
static const struct file_operations monitoring_on_fops = {
.open = simple_open,
.llseek = no_llseek,
- .write = monitoring_on_write_data,
- .read = monitoring_on_read_data,
+ .write_iter = monitoring_on_write_data,
+ .read_iter = monitoring_on_read_data,
};

static void destroy_monitor_dir(struct rv_monitor_def *mdef)
diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c
index 6aae106695b6..0649acd03726 100644
--- a/kernel/trace/rv/rv_reactors.c
+++ b/kernel/trace/rv/rv_reactors.c
@@ -128,7 +128,7 @@ static int available_reactors_open(struct inode *inode, struct file *file)

static const struct file_operations available_reactors_ops = {
.open = available_reactors_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = seq_release
};
@@ -183,11 +183,10 @@ static void monitor_swap_reactors(struct rv_monitor_def *mdef, struct rv_reactor
rv_enable_monitor(mdef);
}

-static ssize_t
-monitor_reactors_write(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t monitor_reactors_write(struct kiocb *iocb, struct iov_iter *from)
{
char buff[MAX_RV_REACTOR_NAME_SIZE + 2];
+ size_t count = iov_iter_count(from);
struct rv_monitor_def *mdef;
struct rv_reactor_def *rdef;
struct seq_file *seq_f;
@@ -201,7 +200,8 @@ monitor_reactors_write(struct file *file, const char __user *user_buf,

memset(buff, 0, sizeof(buff));

- retval = simple_write_to_buffer(buff, sizeof(buff) - 1, ppos, user_buf, count);
+ retval = simple_copy_from_iter(buff, &iocb->ki_pos, sizeof(buff) - 1,
+ from);
if (retval < 0)
return -EFAULT;

@@ -214,7 +214,7 @@ monitor_reactors_write(struct file *file, const char __user *user_buf,
/*
* See monitor_reactors_open()
*/
- seq_f = file->private_data;
+ seq_f = iocb->ki_filp->private_data;
mdef = seq_f->private;

mutex_lock(&rv_interface_lock);
@@ -269,10 +269,10 @@ static int monitor_reactors_open(struct inode *inode, struct file *file)

static const struct file_operations monitor_reactors_ops = {
.open = monitor_reactors_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = seq_release,
- .write = monitor_reactors_write
+ .write_iter = monitor_reactors_write
};

static int __rv_register_reactor(struct rv_reactor *reactor)
@@ -371,15 +371,13 @@ bool rv_reacting_on(void)
return READ_ONCE(reacting_on);
}

-static ssize_t reacting_on_read_data(struct file *filp,
- char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t reacting_on_read_data(struct kiocb *iocb, struct iov_iter *to)
{
char *buff;

buff = rv_reacting_on() ? "1\n" : "0\n";

- return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff)+1);
+ return simple_copy_to_iter(buff, &iocb->ki_pos, strlen(buff)+1, to);
}

static void turn_reacting_off(void)
@@ -396,13 +394,13 @@ static void turn_reacting_on(void)
smp_wmb();
}

-static ssize_t reacting_on_write_data(struct file *filp, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t reacting_on_write_data(struct kiocb *iocb, struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
int retval;
bool val;

- retval = kstrtobool_from_user(user_buf, count, &val);
+ retval = kstrtobool_from_iter(from, count, &val);
if (retval)
return retval;

@@ -427,8 +425,8 @@ static ssize_t reacting_on_write_data(struct file *filp, const char __user *user
static const struct file_operations reacting_on_fops = {
.open = simple_open,
.llseek = no_llseek,
- .write = reacting_on_write_data,
- .read = reacting_on_read_data,
+ .write_iter = reacting_on_write_data,
+ .read_iter = reacting_on_read_data,
};

/**
--
2.43.0