diff options
author | Dan Williams <dan.j.williams@intel.com> | 2018-07-08 16:46:12 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-07-15 18:05:05 -0400 |
commit | ca146f6f091e47b3fd18d6a7e76ec0297d202e0f (patch) | |
tree | 473101ada06498159f8c9f09a1aa4d6d8360ab8b | |
parent | abd08d7d245397bcbded8c6c29ff79a36b3875b0 (diff) |
lib/iov_iter: Fix pipe handling in _copy_to_iter_mcsafe()
By mistake the ITER_PIPE early-exit / warning from copy_from_iter() was
cargo-culted in _copy_to_iter_mcsafe() rather than a machine-check-safe
version of copy_to_iter_pipe().
Implement copy_pipe_to_iter_mcsafe() being careful to return the
indication of short copies due to a CPU exception.
Without this regression-fix all splice reads to dax-mode files fail.
Reported-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Tested-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Fixes: 8780356ef630 ("x86/asm/memcpy_mcsafe: Define copy_to_iter_mcsafe()")
Link: http://lkml.kernel.org/r/153108277278.37979.3327916996902264102.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | lib/iov_iter.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 09fb73ad9d54..8be175df3075 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c | |||
@@ -596,6 +596,37 @@ static unsigned long memcpy_mcsafe_to_page(struct page *page, size_t offset, | |||
596 | return ret; | 596 | return ret; |
597 | } | 597 | } |
598 | 598 | ||
599 | static size_t copy_pipe_to_iter_mcsafe(const void *addr, size_t bytes, | ||
600 | struct iov_iter *i) | ||
601 | { | ||
602 | struct pipe_inode_info *pipe = i->pipe; | ||
603 | size_t n, off, xfer = 0; | ||
604 | int idx; | ||
605 | |||
606 | if (!sanity(i)) | ||
607 | return 0; | ||
608 | |||
609 | bytes = n = push_pipe(i, bytes, &idx, &off); | ||
610 | if (unlikely(!n)) | ||
611 | return 0; | ||
612 | for ( ; n; idx = next_idx(idx, pipe), off = 0) { | ||
613 | size_t chunk = min_t(size_t, n, PAGE_SIZE - off); | ||
614 | unsigned long rem; | ||
615 | |||
616 | rem = memcpy_mcsafe_to_page(pipe->bufs[idx].page, off, addr, | ||
617 | chunk); | ||
618 | i->idx = idx; | ||
619 | i->iov_offset = off + chunk - rem; | ||
620 | xfer += chunk - rem; | ||
621 | if (rem) | ||
622 | break; | ||
623 | n -= chunk; | ||
624 | addr += chunk; | ||
625 | } | ||
626 | i->count -= xfer; | ||
627 | return xfer; | ||
628 | } | ||
629 | |||
599 | /** | 630 | /** |
600 | * _copy_to_iter_mcsafe - copy to user with source-read error exception handling | 631 | * _copy_to_iter_mcsafe - copy to user with source-read error exception handling |
601 | * @addr: source kernel address | 632 | * @addr: source kernel address |
@@ -627,10 +658,8 @@ size_t _copy_to_iter_mcsafe(const void *addr, size_t bytes, struct iov_iter *i) | |||
627 | const char *from = addr; | 658 | const char *from = addr; |
628 | unsigned long rem, curr_addr, s_addr = (unsigned long) addr; | 659 | unsigned long rem, curr_addr, s_addr = (unsigned long) addr; |
629 | 660 | ||
630 | if (unlikely(i->type & ITER_PIPE)) { | 661 | if (unlikely(i->type & ITER_PIPE)) |
631 | WARN_ON(1); | 662 | return copy_pipe_to_iter_mcsafe(addr, bytes, i); |
632 | return 0; | ||
633 | } | ||
634 | if (iter_is_iovec(i)) | 663 | if (iter_is_iovec(i)) |
635 | might_fault(); | 664 | might_fault(); |
636 | iterate_and_advance(i, bytes, v, | 665 | iterate_and_advance(i, bytes, v, |