[PATCH 038/437] debugfs: convert to ->read_iter()

Jens Axboe
2024-04-11T15:32:35Z

arch/powerpc/kernel/dawr.c | 10 ++-
drivers/base/regmap/regmap-debugfs.c | 32 ++++++---
drivers/misc/mei/debugfs.c | 12 ++--
fs/debugfs/file.c | 104 ++++++++++++++++++---------
include/linux/debugfs.h | 24 +++----
kernel/sched/debug.c | 9 ++-
6 files changed, 114 insertions(+), 77 deletions(-)

diff --git a/arch/powerpc/kernel/dawr.c b/arch/powerpc/kernel/dawr.c
index 909a05cd2809..03ab57564a18 100644
--- a/arch/powerpc/kernel/dawr.c
+++ b/arch/powerpc/kernel/dawr.c
@@ -59,9 +59,7 @@ static void disable_dawrs_cb(void *info)
set_dawr(i, &null_brk);
}

-static ssize_t dawr_write_file_bool(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t dawr_write_file_bool(struct kiocb *iocb, struct iov_iter *from)
{
struct arch_hw_breakpoint null_brk = {0};
size_t rc;
@@ -72,7 +70,7 @@ static ssize_t dawr_write_file_bool(struct file *file,
set_dawr(0, &null_brk) != H_SUCCESS)
return -ENODEV;

- rc = debugfs_write_file_bool(file, user_buf, count, ppos);
+ rc = debugfs_write_file_bool(iocb, from);
if (rc)
return rc;

@@ -84,8 +82,8 @@ static ssize_t dawr_write_file_bool(struct file *file,
}

static const struct file_operations dawr_enable_fops = {
- .read = debugfs_read_file_bool,
- .write = dawr_write_file_bool,
+ .read_iter = debugfs_read_file_bool,
+ .write_iter = dawr_write_file_bool,
.open = simple_open,
.llseek = default_llseek,
};
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index fb84cda92a75..571b5c00a28e 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -456,9 +456,9 @@ static int regmap_access_show(struct seq_file *s, void *ignored)

DEFINE_SHOW_ATTRIBUTE(regmap_access);

-static ssize_t regmap_cache_only_write_file(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t __regmap_cache_only_write_file(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
{
struct regmap *map = container_of(file->private_data,
struct regmap, cache_only);
@@ -497,15 +497,21 @@ static ssize_t regmap_cache_only_write_file(struct file *file,
return count;
}

+static ssize_t regmap_cache_only_write_file(struct kiocb *iocb,
+ struct iov_iter *from)
+{
+ return vfs_write_iter(iocb, from, __regmap_cache_only_write_file);
+}
+
static const struct file_operations regmap_cache_only_fops = {
.open = simple_open,
- .read = debugfs_read_file_bool,
- .write = regmap_cache_only_write_file,
+ .read_iter = debugfs_read_file_bool,
+ .write_iter = regmap_cache_only_write_file,
};

-static ssize_t regmap_cache_bypass_write_file(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t __regmap_cache_bypass_write_file(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
{
struct regmap *map = container_of(file->private_data,
struct regmap, cache_bypass);
@@ -537,10 +543,16 @@ static ssize_t regmap_cache_bypass_write_file(struct file *file,
return count;
}

+static ssize_t regmap_cache_bypass_write_file(struct kiocb *iocb,
+ struct iov_iter *from)
+{
+ return vfs_write_iter(iocb, from, __regmap_cache_bypass_write_file);
+}
+
static const struct file_operations regmap_cache_bypass_fops = {
.open = simple_open,
- .read = debugfs_read_file_bool,
- .write = regmap_cache_bypass_write_file,
+ .read_iter = debugfs_read_file_bool,
+ .write_iter = regmap_cache_bypass_write_file,
};

void regmap_debugfs_init(struct regmap *map)
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c
index 3b098d4c8e3d..b2e9fa911817 100644
--- a/drivers/misc/mei/debugfs.c
+++ b/drivers/misc/mei/debugfs.c
@@ -133,17 +133,15 @@ static int mei_dbgfs_devstate_show(struct seq_file *m, void *unused)
}
DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_devstate);

-static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t mei_dbgfs_write_allow_fa(struct kiocb *iocb, struct iov_iter *from)
{
struct mei_device *dev;
int ret;

- dev = container_of(file->private_data,
+ dev = container_of(iocb->ki_filp->private_data,
struct mei_device, allow_fixed_address);

- ret = debugfs_write_file_bool(file, user_buf, count, ppos);
+ ret = debugfs_write_file_bool(iocb, from);
if (ret < 0)
return ret;
dev->override_fixed_address = true;
@@ -152,8 +150,8 @@ static ssize_t mei_dbgfs_write_allow_fa(struct file *file,

static const struct file_operations mei_dbgfs_allow_fa_fops = {
.open = simple_open,
- .read = debugfs_read_file_bool,
- .write = mei_dbgfs_write_allow_fa,
+ .read_iter = debugfs_read_file_bool,
+ .write_iter = mei_dbgfs_write_allow_fa,
.llseek = generic_file_llseek,
};

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index c6f4a9a98b85..c6ff9084bc0f 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -26,21 +26,19 @@

struct poll_table_struct;

-static ssize_t default_read_file(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t default_read_file_iter(struct kiocb *iocb, struct iov_iter *to)
{
return 0;
}

-static ssize_t default_write_file(struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t default_write_file_iter(struct kiocb *iocb, struct iov_iter *from)
{
- return count;
+ return iov_iter_count(from);
}

const struct file_operations debugfs_noop_file_operations = {
- .read = default_read_file,
- .write = default_write_file,
+ .read_iter = default_read_file_iter,
+ .write_iter = default_write_file_iter,
.open = simple_open,
.llseek = noop_llseek,
};
@@ -872,8 +870,9 @@ void debugfs_create_atomic_t(const char *name, umode_t mode,
}
EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);

-ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t __debugfs_read_file_bool(struct file *file,
+ char __user *user_buf, size_t count,
+ loff_t *ppos)
{
char buf[2];
bool val;
@@ -893,10 +892,16 @@ ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
buf[1] = '\n';
return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
}
+
+ssize_t debugfs_read_file_bool(struct kiocb *iocb, struct iov_iter *to)
+{
+ return vfs_read_iter(iocb, to, __debugfs_read_file_bool);
+}
EXPORT_SYMBOL_GPL(debugfs_read_file_bool);

-ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t __debugfs_write_file_bool(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
{
bool bv;
int r;
@@ -914,23 +919,28 @@ ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,

return count;
}
+
+ssize_t debugfs_write_file_bool(struct kiocb *iocb, struct iov_iter *from)
+{
+ return vfs_write_iter(iocb, from, __debugfs_write_file_bool);
+}
EXPORT_SYMBOL_GPL(debugfs_write_file_bool);

static const struct file_operations fops_bool = {
- .read = debugfs_read_file_bool,
- .write = debugfs_write_file_bool,
+ .read_iter = debugfs_read_file_bool,
+ .write_iter = debugfs_write_file_bool,
.open = simple_open,
.llseek = default_llseek,
};

static const struct file_operations fops_bool_ro = {
- .read = debugfs_read_file_bool,
+ .read_iter = debugfs_read_file_bool,
.open = simple_open,
.llseek = default_llseek,
};

static const struct file_operations fops_bool_wo = {
- .write = debugfs_write_file_bool,
+ .write_iter = debugfs_write_file_bool,
.open = simple_open,
.llseek = default_llseek,
};
@@ -957,8 +967,8 @@ void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent,
}
EXPORT_SYMBOL_GPL(debugfs_create_bool);

-ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t __debugfs_read_file_str(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
{
struct dentry *dentry = F_DENTRY(file);
char *str, *copy = NULL;
@@ -991,10 +1001,15 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,

return ret;
}
-EXPORT_SYMBOL_GPL(debugfs_create_str);

-static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+ssize_t debugfs_read_file_str(struct kiocb *iocb, struct iov_iter *to)
+{
+ return vfs_read_iter(iocb, to, __debugfs_read_file_str);
+}
+
+static ssize_t __debugfs_write_file_str(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
{
struct dentry *dentry = F_DENTRY(file);
char *old, *new = NULL;
@@ -1044,21 +1059,26 @@ static ssize_t debugfs_write_file_str(struct file *file, const char __user *user
return r;
}

+static ssize_t debugfs_write_file_str(struct kiocb *iocb, struct iov_iter *from)
+{
+ return vfs_write_iter(iocb, from, __debugfs_write_file_str);
+}
+
static const struct file_operations fops_str = {
- .read = debugfs_read_file_str,
- .write = debugfs_write_file_str,
+ .read_iter = debugfs_read_file_str,
+ .write_iter = debugfs_write_file_str,
.open = simple_open,
.llseek = default_llseek,
};

static const struct file_operations fops_str_ro = {
- .read = debugfs_read_file_str,
+ .read_iter = debugfs_read_file_str,
.open = simple_open,
.llseek = default_llseek,
};

static const struct file_operations fops_str_wo = {
- .write = debugfs_write_file_str,
+ .write_iter = debugfs_write_file_str,
.open = simple_open,
.llseek = default_llseek,
};
@@ -1083,9 +1103,10 @@ void debugfs_create_str(const char *name, umode_t mode,
debugfs_create_mode_unsafe(name, mode, parent, value, &fops_str,
&fops_str_ro, &fops_str_wo);
}
+EXPORT_SYMBOL_GPL(debugfs_create_str);

-static ssize_t read_file_blob(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t __read_file_blob(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
{
struct debugfs_blob_wrapper *blob = file->private_data;
struct dentry *dentry = F_DENTRY(file);
@@ -1100,8 +1121,13 @@ static ssize_t read_file_blob(struct file *file, char __user *user_buf,
return r;
}

-static ssize_t write_file_blob(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t read_file_blob(struct kiocb *iocb, struct iov_iter *to)
+{
+ return vfs_read_iter(iocb, to, __read_file_blob);
+}
+
+static ssize_t __write_file_blob(struct file *file, const char __user *user_buf,
+ size_t count, loff_t *ppos)
{
struct debugfs_blob_wrapper *blob = file->private_data;
struct dentry *dentry = F_DENTRY(file);
@@ -1117,9 +1143,14 @@ static ssize_t write_file_blob(struct file *file, const char __user *user_buf,
return r;
}

+static ssize_t write_file_blob(struct kiocb *iocb, struct iov_iter *from)
+{
+ return vfs_write_iter(iocb, from, __write_file_blob);
+}
+
static const struct file_operations fops_blob = {
- .read = read_file_blob,
- .write = write_file_blob,
+ .read_iter = read_file_blob,
+ .write_iter = write_file_blob,
.open = simple_open,
.llseek = default_llseek,
};
@@ -1197,8 +1228,8 @@ static int u32_array_open(struct inode *inode, struct file *file)
return nonseekable_open(inode, file);
}

-static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len,
- loff_t *ppos)
+static ssize_t __u32_array_read(struct file *file, char __user *buf, size_t len,
+ loff_t *ppos)
{
size_t size = strlen(file->private_data);

@@ -1206,6 +1237,11 @@ static ssize_t u32_array_read(struct file *file, char __user *buf, size_t len,
file->private_data, size);
}

+static ssize_t u32_array_read(struct kiocb *iocb, struct iov_iter *to)
+{
+ return vfs_read_iter(iocb, to, __u32_array_read);
+}
+
static int u32_array_release(struct inode *inode, struct file *file)
{
kfree(file->private_data);
@@ -1217,7 +1253,7 @@ static const struct file_operations u32_array_fops = {
.owner = THIS_MODULE,
.open = u32_array_open,
.release = u32_array_release,
- .read = u32_array_read,
+ .read_iter = u32_array_read,
.llseek = no_llseek,
};

@@ -1341,7 +1377,7 @@ static const struct file_operations debugfs_devm_entry_ops = {
.owner = THIS_MODULE,
.open = debugfs_devm_entry_open,
.release = single_release,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek
};

diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index c9c65b132c0f..ad417d079ec9 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -162,14 +162,11 @@ void debugfs_create_devm_seqfile(struct device *dev, const char *name,

bool debugfs_initialized(void);

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

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

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

/**
* struct debugfs_cancellation - cancellation data
@@ -376,23 +373,20 @@ static inline void debugfs_create_devm_seqfile(struct device *dev,
{
}

-static inline ssize_t debugfs_read_file_bool(struct file *file,
- char __user *user_buf,
- size_t count, loff_t *ppos)
+static inline ssize_t debugfs_read_file_bool(struct kiocb *iocb,
+ struct iov_iter *to)
{
return -ENODEV;
}

-static inline ssize_t debugfs_write_file_bool(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static inline ssize_t debugfs_write_file_bool(struct kiocb *iocb,
+ struct iov_iter *from)
{
return -ENODEV;
}

-static inline ssize_t debugfs_read_file_str(struct file *file,
- char __user *user_buf,
- size_t count, loff_t *ppos)
+static inline ssize_t debugfs_read_file_str(struct kiocb *iocb,
+ struct iov_iter *to)
{
return -ENODEV;
}
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 8d5d98a5834d..686a21ea1791 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -284,8 +284,7 @@ __read_mostly bool sched_debug_verbose;
static struct dentry *sd_dentry;

-static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf,
- size_t cnt, loff_t *ppos)
+static ssize_t sched_verbose_write(struct kiocb *iocb, struct iov_iter *from)
{
ssize_t result;
bool orig;
@@ -294,7 +293,7 @@ static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf,
mutex_lock(&sched_domains_mutex);

orig = sched_debug_verbose;
- result = debugfs_write_file_bool(filp, ubuf, cnt, ppos);
+ result = debugfs_write_file_bool(iocb, from);

if (sched_debug_verbose && !orig)
update_sched_domain_debugfs();
@@ -313,8 +312,8 @@ static ssize_t sched_verbose_write(struct file *filp, const char __user *ubuf,
#endif

static const struct file_operations sched_verbose_fops = {
- .read = debugfs_read_file_bool,
- .write = sched_verbose_write,
+ .read_iter = debugfs_read_file_bool,
+ .write_iter = sched_verbose_write,
.open = simple_open,
.llseek = default_llseek,
};
--
2.43.0