x86/mce: Add _ASM_EXTABLE_CPY for copy user access
authorYouquan Song <youquan.song@intel.com>
Tue, 6 Oct 2020 21:09:07 +0000 (14:09 -0700)
committerBorislav Petkov <bp@suse.de>
Wed, 7 Oct 2020 09:19:11 +0000 (11:19 +0200)
commit278b917f8cb9b02923c15249f9d1a5769d2c1976
tree25cbc480b5629996070e83d41db35a5b5700cdc0
parenta05d54c41ecfa1a322b229b4e5ce50c157284f74
x86/mce: Add _ASM_EXTABLE_CPY for copy user access

_ASM_EXTABLE_UA is a general exception entry to record the exception fixup
for all exception spots between kernel and user space access.

To enable recovery from machine checks while coping data from user
addresses it is necessary to be able to distinguish the places that are
looping copying data from those that copy a single byte/word/etc.

Add a new macro _ASM_EXTABLE_CPY and use it in place of _ASM_EXTABLE_UA
in the copy functions.

Record the exception reason number to regs->ax at
ex_handler_uaccess which is used to check MCE triggered.

The new fixup routine ex_handler_copy() is almost an exact copy of
ex_handler_uaccess() The difference is that it sets regs->ax to the trap
number. Following patches use this to avoid trying to copy remaining
bytes from the tail of the copy and possibly hitting the poison again.

New mce.kflags bit MCE_IN_KERNEL_COPYIN will be used by mce_severity()
calculation to indicate that a machine check is recoverable because the
kernel was copying from user space.

Signed-off-by: Youquan Song <youquan.song@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20201006210910.21062-4-tony.luck@intel.com
arch/x86/include/asm/asm.h
arch/x86/include/asm/mce.h
arch/x86/lib/copy_user_64.S
arch/x86/mm/extable.c