Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3b2deb0

Browse files
committed
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 <[email protected]>
1 parent e03ad4e commit 3b2deb0

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
@@ -1784,6 +1784,30 @@ struct iovec *iovec_from_user(const struct iovec __user *uvec,
17841784
return iov;
17851785
}
17861786

1787+
/*
1788+
* Single segment iovec supplied by the user, import it as ITER_UBUF.
1789+
*/
1790+
static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec,
1791+
struct iovec **iovp, struct iov_iter *i,
1792+
bool compat)
1793+
{
1794+
struct iovec *iov = *iovp;
1795+
ssize_t ret;
1796+
1797+
if (compat)
1798+
ret = copy_compat_iovec_from_user(iov, uvec, 1);
1799+
else
1800+
ret = copy_iovec_from_user(iov, uvec, 1);
1801+
if (unlikely(ret))
1802+
return ret;
1803+
1804+
ret = import_ubuf(type, iov->iov_base, iov->iov_len, i);
1805+
if (unlikely(ret))
1806+
return ret;
1807+
*iovp = NULL;
1808+
return i->count;
1809+
}
1810+
17871811
ssize_t __import_iovec(int type, const struct iovec __user *uvec,
17881812
unsigned nr_segs, unsigned fast_segs, struct iovec **iovp,
17891813
struct iov_iter *i, bool compat)
@@ -1792,6 +1816,9 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec,
17921816
unsigned long seg;
17931817
struct iovec *iov;
17941818

1819+
if (nr_segs == 1)
1820+
return __import_iovec_ubuf(type, uvec, iovp, i, compat);
1821+
17951822
iov = iovec_from_user(uvec, nr_segs, fast_segs, *iovp, compat);
17961823
if (IS_ERR(iov)) {
17971824
*iovp = NULL;

0 commit comments

Comments
 (0)