x86, powerpc: Rename memcpy_mcsafe() to copy_mc_to_{user, kernel}()
authorDan Williams <dan.j.williams@intel.com>
Tue, 6 Oct 2020 03:40:16 +0000 (20:40 -0700)
committerBorislav Petkov <bp@suse.de>
Tue, 6 Oct 2020 09:18:04 +0000 (11:18 +0200)
commitec6347bb43395cb92126788a1a5b25302543f815
tree98a65bc27c57de7d21fdf657e0e94a95bb50935f
parented9705e4ad1c19ae51ed0cb4c112f9eb6dfc69fc
x86, powerpc: Rename memcpy_mcsafe() to copy_mc_to_{user, kernel}()

In reaction to a proposal to introduce a memcpy_mcsafe_fast()
implementation Linus points out that memcpy_mcsafe() is poorly named
relative to communicating the scope of the interface. Specifically what
addresses are valid to pass as source, destination, and what faults /
exceptions are handled.

Of particular concern is that even though x86 might be able to handle
the semantics of copy_mc_to_user() with its common copy_user_generic()
implementation other archs likely need / want an explicit path for this
case:

  On Fri, May 1, 2020 at 11:28 AM Linus Torvalds <torvalds@linux-foundation.org> wrote:
  >
  > On Thu, Apr 30, 2020 at 6:21 PM Dan Williams <dan.j.williams@intel.com> wrote:
  > >
  > > However now I see that copy_user_generic() works for the wrong reason.
  > > It works because the exception on the source address due to poison
  > > looks no different than a write fault on the user address to the
  > > caller, it's still just a short copy. So it makes copy_to_user() work
  > > for the wrong reason relative to the name.
  >
  > Right.
  >
  > And it won't work that way on other architectures. On x86, we have a
  > generic function that can take faults on either side, and we use it
  > for both cases (and for the "in_user" case too), but that's an
  > artifact of the architecture oddity.
  >
  > In fact, it's probably wrong even on x86 - because it can hide bugs -
  > but writing those things is painful enough that everybody prefers
  > having just one function.

Replace a single top-level memcpy_mcsafe() with either
copy_mc_to_user(), or copy_mc_to_kernel().

Introduce an x86 copy_mc_fragile() name as the rename for the
low-level x86 implementation formerly named memcpy_mcsafe(). It is used
as the slow / careful backend that is supplanted by a fast
copy_mc_generic() in a follow-on patch.

One side-effect of this reorganization is that separating copy_mc_64.S
to its own file means that perf no longer needs to track dependencies
for its memcpy_64.S benchmarks.

 [ bp: Massage a bit. ]

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Cc: <stable@vger.kernel.org>
Link: http://lore.kernel.org/r/CAHk-=wjSqtXAqfUJxFtWNwmguFASTgB0dz1dT3V-78Quiezqbg@mail.gmail.com
Link: https://lkml.kernel.org/r/160195561680.2163339.11574962055305783722.stgit@dwillia2-desk3.amr.corp.intel.com
39 files changed:
arch/powerpc/Kconfig
arch/powerpc/include/asm/string.h
arch/powerpc/include/asm/uaccess.h
arch/powerpc/lib/Makefile
arch/powerpc/lib/copy_mc_64.S [new file with mode: 0644]
arch/powerpc/lib/memcpy_mcsafe_64.S [deleted file]
arch/x86/Kconfig
arch/x86/Kconfig.debug
arch/x86/include/asm/copy_mc_test.h [new file with mode: 0644]
arch/x86/include/asm/mce.h
arch/x86/include/asm/mcsafe_test.h [deleted file]
arch/x86/include/asm/string_64.h
arch/x86/include/asm/uaccess.h
arch/x86/include/asm/uaccess_64.h
arch/x86/kernel/cpu/mce/core.c
arch/x86/kernel/quirks.c
arch/x86/lib/Makefile
arch/x86/lib/copy_mc.c [new file with mode: 0644]
arch/x86/lib/copy_mc_64.S [new file with mode: 0644]
arch/x86/lib/memcpy_64.S
arch/x86/lib/usercopy_64.c
drivers/md/dm-writecache.c
drivers/nvdimm/claim.c
drivers/nvdimm/pmem.c
include/linux/string.h
include/linux/uaccess.h
include/linux/uio.h
lib/Kconfig
lib/iov_iter.c
tools/arch/x86/include/asm/mcsafe_test.h [deleted file]
tools/arch/x86/lib/memcpy_64.S
tools/objtool/check.c
tools/perf/bench/Build
tools/perf/bench/mem-memcpy-x86-64-lib.c [deleted file]
tools/testing/nvdimm/test/nfit.c
tools/testing/selftests/powerpc/copyloops/.gitignore
tools/testing/selftests/powerpc/copyloops/Makefile
tools/testing/selftests/powerpc/copyloops/copy_mc_64.S [new symlink]
tools/testing/selftests/powerpc/copyloops/memcpy_mcsafe_64.S [deleted symlink]