summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVignesh Raghavendra <vigneshr@ti.com>2023-01-28 13:58:28 +0530
committerVignesh Raghavendra <vigneshr@ti.com>2023-01-28 13:58:37 +0530
commit0e60f588dbe43d7b2353e75f943e75e0cc5bb59c (patch)
treeab54e92e77ec08fba74cb45ab838e1d55a99e2cc /lib
parentd4b479823b2fc569ff0219ea72c940079df404b5 (diff)
parent0fe4548663f7dc2c3b549ef54ce9bb6d40a235be (diff)
Merge tag 'v5.10.162' of https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux into ti-linux-5.10.y-cicd
This is the 5.10.162 stable release * tag 'v5.10.162' of https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux: (198 commits) Linux 5.10.162 io_uring: pass in EPOLL_URING_WAKE for eventfd signaling and wakeups eventfd: provide a eventfd_signal_mask() helper eventpoll: add EPOLL_URING_WAKE poll wakeup flag Revert "proc: don't allow async path resolution of /proc/self components" Revert "proc: don't allow async path resolution of /proc/thread-self components" net: remove cmsg restriction from io_uring based send/recvmsg calls task_work: unconditionally run task_work from get_signal() signal: kill JOBCTL_TASK_WORK io_uring: import 5.15-stable io_uring task_work: add helper for more targeted task_work canceling kernel: don't call do_exit() for PF_IO_WORKER threads kernel: stop masking signals in create_io_thread() x86/process: setup io_threads more like normal user space threads arch: ensure parisc/powerpc handle PF_IO_WORKER in copy_thread() arch: setup PF_IO_WORKER threads like PF_KTHREAD entry/kvm: Exit to user mode when TIF_NOTIFY_SIGNAL is set kernel: allow fork with TIF_NOTIFY_SIGNAL pending coredump: Limit what can interrupt coredumps kernel: remove checking for TIF_NOTIFY_SIGNAL ... Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/iov_iter.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 1b0a349fbcd9..650554964f18 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1836,24 +1836,38 @@ int import_single_range(int rw, void __user *buf, size_t len,
}
EXPORT_SYMBOL(import_single_range);
-int iov_iter_for_each_range(struct iov_iter *i, size_t bytes,
- int (*f)(struct kvec *vec, void *context),
- void *context)
+/**
+ * iov_iter_restore() - Restore a &struct iov_iter to the same state as when
+ * iov_iter_save_state() was called.
+ *
+ * @i: &struct iov_iter to restore
+ * @state: state to restore from
+ *
+ * Used after iov_iter_save_state() to bring restore @i, if operations may
+ * have advanced it.
+ *
+ * Note: only works on ITER_IOVEC, ITER_BVEC, and ITER_KVEC
+ */
+void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state)
{
- struct kvec w;
- int err = -EINVAL;
- if (!bytes)
- return 0;
-
- iterate_all_kinds(i, bytes, v, -EINVAL, ({
- w.iov_base = kmap(v.bv_page) + v.bv_offset;
- w.iov_len = v.bv_len;
- err = f(&w, context);
- kunmap(v.bv_page);
- err;}), ({
- w = v;
- err = f(&w, context);})
- )
- return err;
+ if (WARN_ON_ONCE(!iov_iter_is_bvec(i) && !iter_is_iovec(i)) &&
+ !iov_iter_is_kvec(i))
+ return;
+ i->iov_offset = state->iov_offset;
+ i->count = state->count;
+ /*
+ * For the *vec iters, nr_segs + iov is constant - if we increment
+ * the vec, then we also decrement the nr_segs count. Hence we don't
+ * need to track both of these, just one is enough and we can deduct
+ * the other from that. ITER_KVEC and ITER_IOVEC are the same struct
+ * size, so we can just increment the iov pointer as they are unionzed.
+ * ITER_BVEC _may_ be the same size on some archs, but on others it is
+ * not. Be safe and handle it separately.
+ */
+ BUILD_BUG_ON(sizeof(struct iovec) != sizeof(struct kvec));
+ if (iov_iter_is_bvec(i))
+ i->bvec -= state->nr_segs - i->nr_segs;
+ else
+ i->iov -= state->nr_segs - i->nr_segs;
+ i->nr_segs = state->nr_segs;
}
-EXPORT_SYMBOL(iov_iter_for_each_range);