[PATCH 084/437] locking/lock_events: convert to read/write iterators

Jens Axboe
2024-04-11T15:34:05Z

kernel/locking/lock_events.c | 18 +++++++++---------
kernel/locking/lock_events.h | 4 ++--
kernel/locking/qspinlock_stat.h | 7 +++----
3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/locking/lock_events.c b/kernel/locking/lock_events.c
index e68d82099558..1f1efb123a1b 100644
--- a/kernel/locking/lock_events.c
+++ b/kernel/locking/lock_events.c
@@ -20,6 +20,7 @@
#include <linux/sched.h>
#include <linux/sched/clock.h>
#include <linux/fs.h>
+#include <linux/uio.h>

#include "lock_events.h"

@@ -58,8 +59,7 @@ DEFINE_PER_CPU(unsigned long, lockevents[lockevent_num]);
/*
* The lockevent_read() function can be overridden.
*/
-ssize_t __weak lockevent_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+ssize_t __weak lockevent_read(struct kiocb *iocb, struct iov_iter *to)
{
char buf[64];
int cpu, id, len;
@@ -68,7 +68,7 @@ ssize_t __weak lockevent_read(struct file *file, char __user *user_buf,
/*
* Get the counter ID stored in file->f_inode->i_private
*/
- id = (long)file_inode(file)->i_private;
+ id = (long)file_inode(iocb->ki_filp)->i_private;

if (id >= lockevent_num)
return -EBADF;
@@ -77,7 +77,7 @@ ssize_t __weak lockevent_read(struct file *file, char __user *user_buf,
sum += per_cpu(lockevents[id], cpu);
len = snprintf(buf, sizeof(buf) - 1, "%llu\n", sum);

- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
}

/*
@@ -85,15 +85,15 @@ ssize_t __weak lockevent_read(struct file *file, char __user *user_buf,
*
* When idx = reset_cnts, reset all the counts.
*/
-static ssize_t lockevent_write(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t lockevent_write(struct kiocb *iocb, struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
int cpu;

/*
* Get the counter ID stored in file->f_inode->i_private
*/
- if ((long)file_inode(file)->i_private != LOCKEVENT_reset_cnts)
+ if ((long)file_inode(iocb->ki_filp)->i_private != LOCKEVENT_reset_cnts)
return count;

for_each_possible_cpu(cpu) {
@@ -110,8 +110,8 @@ static ssize_t lockevent_write(struct file *file, const char __user *user_buf,
* Debugfs data structures
*/
static const struct file_operations fops_lockevent = {
- .read = lockevent_read,
- .write = lockevent_write,
+ .read_iter = lockevent_read,
+ .write_iter = lockevent_write,
.llseek = default_llseek,
};

diff --git a/kernel/locking/lock_events.h b/kernel/locking/lock_events.h
index a6016b91803d..0210d1abc4d7 100644
--- a/kernel/locking/lock_events.h
+++ b/kernel/locking/lock_events.h
@@ -58,7 +58,7 @@ static inline void __lockevent_add(enum lock_events event, int inc)

#endif /* CONFIG_LOCK_EVENT_COUNTS */

-ssize_t lockevent_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos);
+struct kiocb;
+ssize_t lockevent_read(struct kiocb *iocb, struct iov_iter *to);

#endif /* __LOCKING_LOCK_EVENTS_H */
diff --git a/kernel/locking/qspinlock_stat.h b/kernel/locking/qspinlock_stat.h
index e625bb410aa2..efaabdcfcddc 100644
--- a/kernel/locking/qspinlock_stat.h
+++ b/kernel/locking/qspinlock_stat.h
@@ -33,8 +33,7 @@ static DEFINE_PER_CPU(u64, pv_kick_time);
* 3. pv_hash_hops
* Average hops/hash = pv_hash_hops/pv_kick_unlock
*/
-ssize_t lockevent_read(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+ssize_t lockevent_read(struct kiocb *iocb, struct iov_iter *to)
{
char buf[64];
int cpu, id, len;
@@ -43,7 +42,7 @@ ssize_t lockevent_read(struct file *file, char __user *user_buf,
/*
* Get the counter ID stored in file->f_inode->i_private
*/
- id = (long)file_inode(file)->i_private;
+ id = (long)file_inode(iocb->ki_filp)->i_private;

if (id >= lockevent_num)
return -EBADF;
@@ -91,7 +90,7 @@ ssize_t lockevent_read(struct file *file, char __user *user_buf,
len = snprintf(buf, sizeof(buf) - 1, "%llu\n", sum);
}

- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+ return simple_copy_to_iter(buf, &iocb->ki_pos, len, to);
}

/*
--
2.43.0