Skip to content

Commit a34605b

Browse files
author
Ming Lei
committed
iov_iter: import single vector iovecs as ITER_UBUF
JIRA: https://issues.redhat.com/browse/RHEL-87739 commit 3b2deb0 Author: Jens Axboe <axboe@kernel.dk> Date: Fri Mar 24 14:37:19 2023 -0600 iov_iter: import single vector iovecs as ITER_UBUF Add a special case to __import_iovec(), which imports a single segment iovec as an ITER_UBUF rather than an ITER_IOVEC. ITER_UBUF is cheaper to iterate than ITER_IOVEC, and for a single segment iovec, there's no point in using a segmented iterator. Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 75f107f commit a34605b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/iov_iter.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,30 @@ struct iovec *iovec_from_user(const struct iovec __user *uvec,
18291829
return iov;
18301830
}
18311831

1832+
/*
1833+
* Single segment iovec supplied by the user, import it as ITER_UBUF.
1834+
*/
1835+
static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec,
1836+
struct iovec **iovp, struct iov_iter *i,
1837+
bool compat)
1838+
{
1839+
struct iovec *iov = *iovp;
1840+
ssize_t ret;
1841+
1842+
if (compat)
1843+
ret = copy_compat_iovec_from_user(iov, uvec, 1);
1844+
else
1845+
ret = copy_iovec_from_user(iov, uvec, 1);
1846+
if (unlikely(ret))
1847+
return ret;
1848+
1849+
ret = import_ubuf(type, iov->iov_base, iov->iov_len, i);
1850+
if (unlikely(ret))
1851+
return ret;
1852+
*iovp = NULL;
1853+
return i->count;
1854+
}
1855+
18321856
ssize_t __import_iovec(int type, const struct iovec __user *uvec,
18331857
unsigned nr_segs, unsigned fast_segs, struct iovec **iovp,
18341858
struct iov_iter *i, bool compat)
@@ -1837,6 +1861,9 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec,
18371861
unsigned long seg;
18381862
struct iovec *iov;
18391863

1864+
if (nr_segs == 1)
1865+
return __import_iovec_ubuf(type, uvec, iovp, i, compat);
1866+
18401867
iov = iovec_from_user(uvec, nr_segs, fast_segs, *iovp, compat);
18411868
if (IS_ERR(iov)) {
18421869
*iovp = NULL;

0 commit comments

Comments
 (0)