[PATCH 338/437] powerpc/kvm: convert to read/write iterators

Jens Axboe
2024-04-11T15:41:03Z

arch/powerpc/kvm/book3s_64_mmu_hv.c | 25 ++++++++++++-------------
arch/powerpc/kvm/book3s_64_mmu_radix.c | 19 ++++++++-----------
arch/powerpc/kvm/book3s_hv.c | 26 +++++++++++---------------
arch/powerpc/kvm/timing.c | 14 +++++++-------
4 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 2b1f0cdd8c18..254a267cac6f 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -1820,6 +1820,7 @@ static ssize_t kvm_htab_read(struct file *file, char __user *buf,

return nb;
}
+FOPS_READ_ITER_HELPER(kvm_htab_read);

static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
@@ -1943,6 +1944,7 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
return err;
return nb;
}
+FOPS_WRITE_ITER_HELPER(kvm_htab_write);

static int kvm_htab_release(struct inode *inode, struct file *filp)
{
@@ -1957,8 +1959,8 @@ static int kvm_htab_release(struct inode *inode, struct file *filp)
}

static const struct file_operations kvm_htab_fops = {
- .read = kvm_htab_read,
- .write = kvm_htab_write,
+ .read_iter = kvm_htab_read_iter,
+ .write_iter = kvm_htab_write_iter,
.llseek = default_llseek,
.release = kvm_htab_release,
};
@@ -2035,10 +2037,10 @@ static int debugfs_htab_release(struct inode *inode, struct file *file)
return 0;
}

-static ssize_t debugfs_htab_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t debugfs_htab_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct debugfs_htab_state *p = file->private_data;
+ struct debugfs_htab_state *p = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(to);
ssize_t ret, r;
unsigned long i, n;
unsigned long v, hr, gr;
@@ -2057,11 +2059,10 @@ static ssize_t debugfs_htab_read(struct file *file, char __user *buf,
n = p->chars_left;
if (n > len)
n = len;
- r = copy_to_user(buf, p->buf + p->buf_index, n);
+ r = copy_to_iter(p->buf + p->buf_index, n, to);
n -= r;
p->chars_left -= n;
p->buf_index += n;
- buf += n;
len -= n;
ret = n;
if (r) {
@@ -2097,11 +2098,10 @@ static ssize_t debugfs_htab_read(struct file *file, char __user *buf,
p->chars_left = n;
if (n > len)
n = len;
- r = copy_to_user(buf, p->buf, n);
+ r = copy_to_iter(p->buf, n, to);
n -= r;
p->chars_left -= n;
p->buf_index = n;
- buf += n;
len -= n;
ret += n;
if (r) {
@@ -2117,8 +2117,7 @@ static ssize_t debugfs_htab_read(struct file *file, char __user *buf,
return ret;
}

-static ssize_t debugfs_htab_write(struct file *file, const char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t debugfs_htab_write(struct kiocb *iocb, struct iov_iter *from)
{
return -EACCES;
}
@@ -2127,8 +2126,8 @@ static const struct file_operations debugfs_htab_fops = {
.owner = THIS_MODULE,
.open = debugfs_htab_open,
.release = debugfs_htab_release,
- .read = debugfs_htab_read,
- .write = debugfs_htab_write,
+ .read_iter = debugfs_htab_read,
+ .write_iter = debugfs_htab_write,
.llseek = generic_file_llseek,
};

diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 408d98f8a514..d33c92bbe6f2 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -1298,10 +1298,10 @@ static int debugfs_radix_release(struct inode *inode, struct file *file)
return 0;
}

-static ssize_t debugfs_radix_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t debugfs_radix_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct debugfs_radix_state *p = file->private_data;
+ struct debugfs_radix_state *p = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(to);
ssize_t ret, r;
unsigned long n;
struct kvm *kvm;
@@ -1328,11 +1328,10 @@ static ssize_t debugfs_radix_read(struct file *file, char __user *buf,
n = p->chars_left;
if (n > len)
n = len;
- r = copy_to_user(buf, p->buf + p->buf_index, n);
+ r = copy_to_iter(p->buf + p->buf_index, n, to);
n -= r;
p->chars_left -= n;
p->buf_index += n;
- buf += n;
len -= n;
ret = n;
if (r) {
@@ -1428,11 +1427,10 @@ static ssize_t debugfs_radix_read(struct file *file, char __user *buf,
p->chars_left = n;
if (n > len)
n = len;
- r = copy_to_user(buf, p->buf, n);
+ r = copy_to_iter(p->buf, n, to);
n -= r;
p->chars_left -= n;
p->buf_index = n;
- buf += n;
len -= n;
ret += n;
if (r) {
@@ -1450,8 +1448,7 @@ static ssize_t debugfs_radix_read(struct file *file, char __user *buf,
return ret;
}

-static ssize_t debugfs_radix_write(struct file *file, const char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t debugfs_radix_write(struct kiocb *iocb, struct iov_iter *from)
{
return -EACCES;
}
@@ -1460,8 +1457,8 @@ static const struct file_operations debugfs_radix_fops = {
.owner = THIS_MODULE,
.open = debugfs_radix_open,
.release = debugfs_radix_release,
- .read = debugfs_radix_read,
- .write = debugfs_radix_write,
+ .read_iter = debugfs_radix_read,
+ .write_iter = debugfs_radix_write,
.llseek = generic_file_llseek,
};

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 8e86eb577eb8..33ccdf765395 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2860,10 +2860,10 @@ static int debugfs_timings_release(struct inode *inode, struct file *file)
return 0;
}

-static ssize_t debugfs_timings_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t debugfs_timings_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct debugfs_timings_state *p = file->private_data;
+ struct debugfs_timings_state *p = iocb->ki_filp->private_data;
+ size_t len = iov_iter_count(to);
struct kvm_vcpu *vcpu = p->vcpu;
char *s, *buf_end;
struct kvmhv_tb_accumulator tb;
@@ -2910,23 +2910,19 @@ static ssize_t debugfs_timings_read(struct file *file, char __user *buf,
p->buflen = s - p->buf;
}

- pos = *ppos;
+ pos = iocb->ki_pos;
if (pos >= p->buflen)
return 0;
if (len > p->buflen - pos)
len = p->buflen - pos;
- n = copy_to_user(buf, p->buf + pos, len);
- if (n) {
- if (n == len)
- return -EFAULT;
- len -= n;
- }
- *ppos = pos + len;
+ n = !copy_to_iter_full(p->buf + pos, len, to);
+ if (n)
+ return -EFAULT;
+ iocb->ki_pos = pos + len;
return len;
}

-static ssize_t debugfs_timings_write(struct file *file, const char __user *buf,
- size_t len, loff_t *ppos)
+static ssize_t debugfs_timings_write(struct kiocb *iocb, struct iov_iter *from)
{
return -EACCES;
}
@@ -2935,8 +2931,8 @@ static const struct file_operations debugfs_timings_ops = {
.owner = THIS_MODULE,
.open = debugfs_timings_open,
.release = debugfs_timings_release,
- .read = debugfs_timings_read,
- .write = debugfs_timings_write,
+ .read_iter = debugfs_timings_read,
+ .write_iter = debugfs_timings_write,
.llseek = generic_file_llseek,
};

diff --git a/arch/powerpc/kvm/timing.c b/arch/powerpc/kvm/timing.c
index 25071331f8c1..1281aaef2b44 100644
--- a/arch/powerpc/kvm/timing.c
+++ b/arch/powerpc/kvm/timing.c
@@ -158,10 +158,10 @@ static int kvmppc_exit_timing_show(struct seq_file *m, void *private)
}

/* Write 'c' to clear the timing statistics. */
-static ssize_t kvmppc_exit_timing_write(struct file *file,
- const char __user *user_buf,
- size_t count, loff_t *ppos)
+static ssize_t kvmppc_exit_timing_write(struct kiocb *iocb,
+ struct iov_iter *from)
{
+ size_t count = iov_iter_count(from);
int err = -EINVAL;
char c;

@@ -169,13 +169,13 @@ static ssize_t kvmppc_exit_timing_write(struct file *file,
goto done;
}

- if (get_user(c, user_buf)) {
+ if (get_iter(&c, from)) {
err = -EFAULT;
goto done;
}

if (c == 'c') {
- struct seq_file *seqf = file->private_data;
+ struct seq_file *seqf = iocb->ki_filp->private_data;
struct kvm_vcpu *vcpu = seqf->private;
/* Write does not affect our buffers previously generated with
* show. seq_file is locked here to prevent races of init with
@@ -198,8 +198,8 @@ static int kvmppc_exit_timing_open(struct inode *inode, struct file *file)
static const struct file_operations kvmppc_exit_timing_fops = {
.owner = THIS_MODULE,
.open = kvmppc_exit_timing_open,
- .read = seq_read,
- .write = kvmppc_exit_timing_write,
+ .read_iter = seq_read_iter,
+ .write_iter = kvmppc_exit_timing_write,
.llseek = seq_lseek,
.release = single_release,
};
--
2.43.0