mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									e03ad4ee27
								
							
						
					
					
						commit
						3b2deb0e46
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		| 
						 | 
					@ -1784,6 +1784,30 @@ struct iovec *iovec_from_user(const struct iovec __user *uvec,
 | 
				
			||||||
	return iov;
 | 
						return iov;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Single segment iovec supplied by the user, import it as ITER_UBUF.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec,
 | 
				
			||||||
 | 
									   struct iovec **iovp, struct iov_iter *i,
 | 
				
			||||||
 | 
									   bool compat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct iovec *iov = *iovp;
 | 
				
			||||||
 | 
						ssize_t ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (compat)
 | 
				
			||||||
 | 
							ret = copy_compat_iovec_from_user(iov, uvec, 1);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							ret = copy_iovec_from_user(iov, uvec, 1);
 | 
				
			||||||
 | 
						if (unlikely(ret))
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = import_ubuf(type, iov->iov_base, iov->iov_len, i);
 | 
				
			||||||
 | 
						if (unlikely(ret))
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
						*iovp = NULL;
 | 
				
			||||||
 | 
						return i->count;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t __import_iovec(int type, const struct iovec __user *uvec,
 | 
					ssize_t __import_iovec(int type, const struct iovec __user *uvec,
 | 
				
			||||||
		 unsigned nr_segs, unsigned fast_segs, struct iovec **iovp,
 | 
							 unsigned nr_segs, unsigned fast_segs, struct iovec **iovp,
 | 
				
			||||||
		 struct iov_iter *i, bool compat)
 | 
							 struct iov_iter *i, bool compat)
 | 
				
			||||||
| 
						 | 
					@ -1792,6 +1816,9 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec,
 | 
				
			||||||
	unsigned long seg;
 | 
						unsigned long seg;
 | 
				
			||||||
	struct iovec *iov;
 | 
						struct iovec *iov;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (nr_segs == 1)
 | 
				
			||||||
 | 
							return __import_iovec_ubuf(type, uvec, iovp, i, compat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	iov = iovec_from_user(uvec, nr_segs, fast_segs, *iovp, compat);
 | 
						iov = iovec_from_user(uvec, nr_segs, fast_segs, *iovp, compat);
 | 
				
			||||||
	if (IS_ERR(iov)) {
 | 
						if (IS_ERR(iov)) {
 | 
				
			||||||
		*iovp = NULL;
 | 
							*iovp = NULL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue