[PATCH 220/437] misc: cxl: convert to read/write iterators

From: Jens Axboe
Date: Thu Apr 11 2024 - 12:28:50 EST


Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/misc/cxl/api.c | 7 +++----
drivers/misc/cxl/cxl.h | 2 +-
drivers/misc/cxl/file.c | 23 +++++++++++------------
include/misc/cxl.h | 3 +--
4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index d85c56530863..54e1f5b917e2 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -375,10 +375,9 @@ __poll_t cxl_fd_poll(struct file *file, struct poll_table_struct *poll)
return afu_poll(file, poll);
}
EXPORT_SYMBOL_GPL(cxl_fd_poll);
-ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
- loff_t *off)
+ssize_t cxl_fd_read(struct kiocb *iocb, struct iov_iter *to)
{
- return afu_read(file, buf, count, off);
+ return afu_read(iocb, to);
}
EXPORT_SYMBOL_GPL(cxl_fd_read);

@@ -410,7 +409,7 @@ struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
if (fops) {
PATCH_FOPS(open);
PATCH_FOPS(poll);
- PATCH_FOPS(read);
+ PATCH_FOPS(read_iter);
PATCH_FOPS(release);
PATCH_FOPS(unlocked_ioctl);
PATCH_FOPS(compat_ioctl);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index 6ad0ab892675..6b6738b28f69 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -1045,7 +1045,7 @@ int afu_release(struct inode *inode, struct file *file);
long afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
int afu_mmap(struct file *file, struct vm_area_struct *vm);
__poll_t afu_poll(struct file *file, struct poll_table_struct *poll);
-ssize_t afu_read(struct file *file, char __user *buf, size_t count, loff_t *off);
+ssize_t afu_read(struct kiocb *iocb, struct iov_iter *to);
extern const struct file_operations afu_fops;

struct cxl *cxl_guest_init_adapter(struct device_node *np, struct platform_device *dev);
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 012e11b959bc..c911bd785f26 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -385,7 +385,7 @@ __poll_t afu_poll(struct file *file, struct poll_table_struct *poll)
}

static ssize_t afu_driver_event_copy(struct cxl_context *ctx,
- char __user *buf,
+ struct iov_iter *to,
struct cxl_event *event,
struct cxl_event_afu_driver_reserved *pl)
{
@@ -403,14 +403,13 @@ static ssize_t afu_driver_event_copy(struct cxl_context *ctx,
}

/* Copy event header */
- if (copy_to_user(buf, event, sizeof(struct cxl_event_header))) {
+ if (!copy_to_iter_full(event, sizeof(struct cxl_event_header), to)) {
ctx->afu_driver_ops->event_delivered(ctx, pl, -EFAULT);
return -EFAULT;
}

/* Copy event data */
- buf += sizeof(struct cxl_event_header);
- if (copy_to_user(buf, &pl->data, pl->data_size)) {
+ if (!copy_to_iter_full(&pl->data, pl->data_size, to)) {
ctx->afu_driver_ops->event_delivered(ctx, pl, -EFAULT);
return -EFAULT;
}
@@ -419,11 +418,11 @@ static ssize_t afu_driver_event_copy(struct cxl_context *ctx,
return event->header.size;
}

-ssize_t afu_read(struct file *file, char __user *buf, size_t count,
- loff_t *off)
+ssize_t afu_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct cxl_context *ctx = file->private_data;
+ struct cxl_context *ctx = iocb->ki_filp->private_data;
struct cxl_event_afu_driver_reserved *pl = NULL;
+ size_t count = iov_iter_count(to);
struct cxl_event event;
unsigned long flags;
int rc;
@@ -447,7 +446,7 @@ ssize_t afu_read(struct file *file, char __user *buf, size_t count,
goto out;
}

- if (file->f_flags & O_NONBLOCK) {
+ if (iocb->ki_filp->f_flags & O_NONBLOCK) {
rc = -EAGAIN;
goto out;
}
@@ -505,9 +504,9 @@ ssize_t afu_read(struct file *file, char __user *buf, size_t count,
spin_unlock_irqrestore(&ctx->lock, flags);

if (event.header.type == CXL_EVENT_AFU_DRIVER)
- return afu_driver_event_copy(ctx, buf, &event, pl);
+ return afu_driver_event_copy(ctx, to, &event, pl);

- if (copy_to_user(buf, &event, event.header.size))
+ if (!copy_to_iter_full(&event, event.header.size, to))
return -EFAULT;
return event.header.size;

@@ -525,7 +524,7 @@ const struct file_operations afu_fops = {
.owner = THIS_MODULE,
.open = afu_open,
.poll = afu_poll,
- .read = afu_read,
+ .read_iter = afu_read,
.release = afu_release,
.unlocked_ioctl = afu_ioctl,
.compat_ioctl = afu_compat_ioctl,
@@ -536,7 +535,7 @@ static const struct file_operations afu_master_fops = {
.owner = THIS_MODULE,
.open = afu_master_open,
.poll = afu_poll,
- .read = afu_read,
+ .read_iter = afu_read,
.release = afu_release,
.unlocked_ioctl = afu_ioctl,
.compat_ioctl = afu_compat_ioctl,
diff --git a/include/misc/cxl.h b/include/misc/cxl.h
index d8044299d654..3758f9c8f83f 100644
--- a/include/misc/cxl.h
+++ b/include/misc/cxl.h
@@ -196,8 +196,7 @@ int cxl_fd_release(struct inode *inode, struct file *file);
long cxl_fd_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm);
__poll_t cxl_fd_poll(struct file *file, struct poll_table_struct *poll);
-ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
- loff_t *off);
+ssize_t cxl_fd_read(struct kiocb *iocb, struct iov_iter *to);

/*
* For EEH, a driver may want to assert a PERST will reload the same image
--
2.43.0