Re: [PATCH v2] x86/mce: Reduce number of machine checks taken during recovery

From: Peter Zijlstra
Date: Fri Dec 24 2021 - 06:50:22 EST


On Thu, Dec 23, 2021 at 12:07:01PM -0800, Luck, Tony wrote:
> diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
> index e6ac38587b40..26781cbe7e37 100644
> --- a/arch/x86/lib/copy_user_64.S
> +++ b/arch/x86/lib/copy_user_64.S
> @@ -212,6 +212,7 @@ EXPORT_SYMBOL(copy_user_enhanced_fast_string)
> * Don't try to copy the tail if machine check happened
> *
> * Input:
> + * eax x86 trap number - set by fixup_excpetion()

That's inaccurate, fixup_exception() (event if it's spelled correctly)
does not unconditionally set the trap number in RAX, that's only done by
ex_handler_fault() (or ex_handler_sgx()), which means all flows into
this function must pass through: EX_TYPE_FAULT, EX_TYPE_FAULT_MCE or
EX_TYPE_COPY.

Boris might fix up your comment if he applies I suppose..

> * rdi destination
> * rsi source
> * rdx count
> @@ -220,12 +221,20 @@ EXPORT_SYMBOL(copy_user_enhanced_fast_string)
> * eax uncopied bytes or 0 if successful.
> */
> SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail)
> + cmp $X86_TRAP_MC,%eax
> + je 3f
> +
> movl %edx,%ecx
> 1: rep movsb
> 2: mov %ecx,%eax
> ASM_CLAC
> RET
>
> +3:
> + movl %edx,%eax
> + ASM_CLAC
> + RET
> +
> _ASM_EXTABLE_CPY(1b, 2b)
>
> .Lcopy_user_handle_align:
>
> base-commit: 82a8954acd93ae95d6252fb93a3d210c8f71b093
> --
> 2.31.1
>