1. 24 Sep, 2016 1 commit
  2. 12 Apr, 2015 1 commit
  3. 30 Mar, 2015 1 commit
    • Al Viro's avatar
      saner iov_iter initialization primitives · bc917be8
      Al Viro authored
      
      iovec-backed iov_iter instances are assumed to satisfy several properties:
      	* no more than UIO_MAXIOV elements in iovec array
      	* total size of all ranges is no more than MAX_RW_COUNT
      	* all ranges pass access_ok().
      
      The problem is, invariants of data structures should be established in the
      primitives creating those data structures, not in the code using those
      primitives.  And iov_iter_init() violates that principle.  For a while we
      managed to get away with that, but once the use of iov_iter started to
      spread, it didn't take long for shit to hit the fan - missed check in
      sys_sendto() had introduced a roothole.
      
      We _do_ have primitives for importing and validating iovecs (both native and
      compat ones) and those primitives are almost always followed by shoving the
      resulting iovec into iov_iter.  Life would be considerably simpler (and safer)
      if we combined those primitives with initializing iov_iter.
      
      That gives us two new primitives - import_iovec() and compat_import_iovec().
      Calling conventions:
      	iovec = iov_array;
      	err = import_iovec(direction, uvec, nr_segs,
      			   ARRAY_SIZE(iov_array), &iovec,
      			   &iter);
      imports user vector into kernel space (into iov_array if it fits, allocated
      if it doesn't fit or if iovec was NULL), validates it and sets iter up to
      refer to it.  On success 0 is returned and allocated kernel copy (or NULL
      if the array had fit into caller-supplied one) is returned via iovec.
      On failure all allocations are undone and -E... is returned.  If the total
      size of ranges exceeds MAX_RW_COUNT, the excess is silently truncated.
      
      compat_import_iovec() expects uvec to be a pointer to user array of compat_iovec;
      otherwise it's identical to import_iovec().
      
      Finally, import_single_range() sets iov_iter backed by single-element iovec
      covering a user-supplied range -
      
      	err = import_single_range(direction, address, size, iovec, &iter);
      
      does validation and sets iter up.  Again, size in excess of MAX_RW_COUNT gets
      silently truncated.
      
      Next commits will be switching the things up to use of those and reducing
      the amount of iov_iter_init() instances.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      bc917be8
  4. 18 Feb, 2015 2 commits
  5. 29 Jan, 2015 1 commit
  6. 09 Dec, 2014 4 commits
  7. 27 Nov, 2014 9 commits
  8. 13 Nov, 2014 1 commit
    • Paul Mackerras's avatar
      Fix thinko in iov_iter_single_seg_count · ad0eab92
      Paul Mackerras authored
      
      The branches of the if (i->type & ITER_BVEC) statement in
      iov_iter_single_seg_count() are the wrong way around; if ITER_BVEC is
      clear then we use i->bvec, when we should be using i->iov.  This fixes
      it.
      
      In my case, the symptom that this caused was that a KVM guest doing
      filesystem operations on a virtual disk would result in one of qemu's
      threads on the host going into an infinite loop in
      generic_perform_write().  The loop would hit the copied == 0 case and
      call iov_iter_single_seg_count() to reduce the number of bytes to try
      to process, but because of the error, iov_iter_single_seg_count()
      would just return i->count and the loop made no progress and continued
      forever.
      
      Cc: stable@vger.kernel.org # 3.16+
      Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      ad0eab92
  9. 09 Oct, 2014 1 commit
    • Matthew Wilcox's avatar
      Add copy_to_iter(), copy_from_iter() and iov_iter_zero() · c35e0248
      Matthew Wilcox authored
      
      For DAX, we want to be able to copy between iovecs and kernel addresses
      that don't necessarily have a struct page.  This is a fairly simple
      rearrangement for bvec iters to kmap the pages outside and pass them in,
      but for user iovecs it gets more complicated because we might try various
      different ways to kmap the memory.  Duplicating the existing logic works
      out best in this case.
      
      We need to be able to write zeroes to an iovec for reads from unwritten
      ranges in a file.  This is performed by the new iov_iter_zero() function,
      again patterned after the existing code that handles iovec iterators.
      
      [AV: and export the buggers...]
      Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      c35e0248
  10. 27 Sep, 2014 1 commit
  11. 07 Aug, 2014 1 commit
  12. 06 May, 2014 9 commits
    • Al Viro's avatar
      bio_vec-backed iov_iter · 62a8067a
      Al Viro authored
      
      New variant of iov_iter - ITER_BVEC in iter->type, backed with
      bio_vec array instead of iovec one.  Primitives taught to deal
      with such beasts, __swap_write() switched to using that kind
      of iov_iter.
      
      Note that bio_vec is just a <page, offset, length> triple - there's
      nothing block-specific about it.  I've left the definition where it
      was, but took it from under ifdef CONFIG_BLOCK.
      
      Next target: ->splice_write()...
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      62a8067a
    • Al Viro's avatar
      optimize copy_page_{to,from}_iter() · 81055e58
      Al Viro authored
      
      if we'd ended up in the end of a segment, jump to the
      beginning of the next one (iov_offset = 0, iov++),
      rather than having the next primitive deal with that.
      
      Ought to be folded back...
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      81055e58
    • Al Viro's avatar
      new helper: copy_page_from_iter() · f0d1bec9
      Al Viro authored
      
      parallel to copy_page_to_iter().  pipe_write() switched to it (and became
      ->write_iter()).
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      f0d1bec9
    • Al Viro's avatar
      new helper: iov_iter_get_pages_alloc() · 91f79c43
      Al Viro authored
      
      same as iov_iter_get_pages(), except that pages array is allocated
      (kmalloc if possible, vmalloc if that fails) and left for caller to
      free.  Lustre and NFS ->direct_IO() switched to it.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      91f79c43
    • Al Viro's avatar
      new helper: iov_iter_npages() · f67da30c
      Al Viro authored
      
      counts the pages covered by iov_iter, up to given limit.
      do_block_direct_io() and fuse_iter_npages() switched to
      it.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      f67da30c
    • Al Viro's avatar
      new helper: iov_iter_get_pages() · 7b2c99d1
      Al Viro authored
      
      iov_iter_get_pages(iter, pages, maxsize, &start) grabs references pinning
      the pages of up to maxsize of (contiguous) data from iter.  Returns the
      amount of memory grabbed or -error.  In case of success, the requested
      area begins at offset start in pages[0] and runs through pages[1], etc.
      Less than requested amount might be returned - either because the contiguous
      area in the beginning of iterator is smaller than requested, or because
      the kernel failed to pin that many pages.
      
      direct-io.c switched to using iov_iter_get_pages()
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      7b2c99d1
    • Al Viro's avatar
      start adding the tag to iov_iter · 71d8e532
      Al Viro authored
      
      For now, just use the same thing we pass to ->direct_IO() - it's all
      iovec-based at the moment.  Pass it explicitly to iov_iter_init() and
      account for kvec vs. iovec in there, by the same kludge NFS ->direct_IO()
      uses.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      71d8e532
    • Al Viro's avatar
      new primitive: iov_iter_alignment() · 886a3911
      Al Viro authored
      
      returns the value aligned as badly as the worst remaining segment
      in iov_iter is.  Use instead of open-coded equivalents.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      886a3911
    • Al Viro's avatar
      kill iov_iter_copy_from_user() · e7c24607
      Al Viro authored
      
      all callers can use copy_page_from_iter() and it actually simplifies
      them.
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      e7c24607
  13. 02 Apr, 2014 1 commit