From: "Luck, Tony" <tony.luck@intel.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Tony Luck <tony.luck@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Borislav Petkov <bp@alien8.de>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>
Subject: Re: [PATCH v13] x86, mce: Add memcpy_trap()
Date: Thu, 25 Feb 2016 11:33:49 -0800 [thread overview]
Message-ID: <56cf571d44495b2cf@agluck-desk.sc.intel.com> (raw)
In-Reply-To: <20160225085624.GA13833@gmail.com>
For reference below is what I'd hoped to be able to do with
copy_from_user() [obviously needs to not just replace that
ALTERNATIVE_2 setup in _copy_from_user ... would have to invent
an ALTERNATIVE_3 to pick the new function for people willing
to sacrifice speed for recoverability]
BUT ... there are a maze of twisty little other places that
also need to be fixed:
1) There is iov_iter_fault_in_readable() that uses fault_in_pages_readable()
to pre-fault the first (and last) page using a raw __get_user() call.
2) I tried to avoid that by injecting my error to the middle of a page,
but still ended up in a "rep mov" copy function instead of mine. Not
sure which one because no output from the core that died. :-(
-Tony
diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
index 982ce34f4a9b..e31d8964ac09 100644
--- a/arch/x86/lib/copy_user_64.S
+++ b/arch/x86/lib/copy_user_64.S
@@ -38,11 +38,15 @@ ENTRY(_copy_from_user)
jc bad_from_user
cmpq TI_addr_limit(%rax),%rcx
ja bad_from_user
+#if 1
+ jmp copy_from_user_with_mce_check
+#else
ALTERNATIVE_2 "jmp copy_user_generic_unrolled", \
"jmp copy_user_generic_string", \
X86_FEATURE_REP_GOOD, \
"jmp copy_user_enhanced_fast_string", \
X86_FEATURE_ERMS
+#endif
ENDPROC(_copy_from_user)
.section .fixup,"ax"
diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
index 0a42327a59d7..c377a70474e0 100644
--- a/arch/x86/lib/usercopy_64.c
+++ b/arch/x86/lib/usercopy_64.c
@@ -6,6 +6,8 @@
* Copyright 2002 Andi Kleen <ak@suse.de>
*/
#include <linux/module.h>
+#include <linux/mm.h>
+#include <asm/traps.h>
#include <asm/uaccess.h>
/*
@@ -86,3 +88,25 @@ copy_user_handle_tail(char *to, char *from, unsigned len)
memset(to, 0, len);
return len;
}
+
+__visible unsigned long
+copy_from_user_with_mce_check(void *to, const void __user *from, unsigned n)
+{
+ struct memcpy_trap_ret r;
+
+ stac();
+ r = memcpy_trap(to, (__force void *)from, n);
+ clac();
+
+ if (likely(r.bytes_left == 0))
+ return 0;
+
+ if (r.trap_nr == X86_TRAP_MC) {
+ volatile void *fault_addr = (volatile void *)from + n - r.bytes_left;
+ phys_addr_t p = virt_to_phys(fault_addr);
+
+ memory_failure(p >> PAGE_SHIFT, MCE_VECTOR, 0);
+ }
+
+ return r.bytes_left;
+}
next prev parent reply other threads:[~2016-02-25 19:33 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 18:20 [PATCH v11 0/4] Machine check recovery when kernel accesses poison Tony Luck
2016-02-17 18:20 ` [PATCH v11 1/4] x86: Expand exception table to allow new handling options Tony Luck
2016-02-18 10:19 ` [tip:ras/core] x86/mm: Expand the exception table logic " tip-bot for Tony Luck
2016-02-17 18:20 ` [PATCH v11 4/4] x86: Create a new synthetic cpu capability for machine check recovery Tony Luck
2016-02-18 10:19 ` [tip:x86/asm] x86/cpufeature: " tip-bot for Tony Luck
2016-02-17 18:20 ` [PATCH v11 3/4] x86, mce: Add __mcsafe_copy() Tony Luck
2016-02-18 8:21 ` Ingo Molnar
2016-02-18 9:59 ` Peter Zijlstra
2016-02-18 10:19 ` Ingo Molnar
2016-02-18 10:29 ` Borislav Petkov
2016-02-18 10:35 ` Peter Zijlstra
2016-02-18 14:59 ` Luck, Tony
2016-02-19 7:58 ` Ingo Molnar
2016-02-19 8:43 ` Peter Zijlstra
2016-02-19 9:51 ` Ingo Molnar
2016-02-18 10:29 ` Borislav Petkov
2016-02-18 10:34 ` Ingo Molnar
2016-02-18 10:36 ` Borislav Petkov
2016-02-18 18:48 ` Ingo Molnar
2016-02-18 21:14 ` [PATCH v12] x86, mce: Add memcpy_trap() Luck, Tony
2016-02-19 9:10 ` Ingo Molnar
2016-02-19 17:53 ` [PATCH v13] " Luck, Tony
2016-02-24 17:38 ` Tony Luck
2016-02-24 18:35 ` Linus Torvalds
2016-02-24 19:27 ` Tony Luck
2016-02-24 19:37 ` Linus Torvalds
2016-02-25 8:56 ` Ingo Molnar
2016-02-25 19:33 ` Luck, Tony [this message]
2016-02-25 20:39 ` Linus Torvalds
2016-02-25 22:11 ` Andy Lutomirski
2016-02-18 19:47 ` [PATCH v14] x86, mce: Add memcpy_mcsafe() Tony Luck
2016-03-02 20:47 ` Luck, Tony
2016-03-08 17:37 ` [tip:ras/core] x86/mm, x86/mce: " tip-bot for Tony Luck
2016-03-10 19:26 ` [PATCH v14] x86, mce: " Mika Penttilä
2016-03-10 19:37 ` Luck, Tony
2016-03-11 22:10 ` Tony Luck
2016-03-11 22:14 ` Dan Williams
2016-03-12 17:16 ` Ingo Molnar
2016-03-13 1:12 ` Linus Torvalds
2016-03-13 9:25 ` Ingo Molnar
2016-03-14 22:33 ` [PATCH] x86/mm, x86/mce: Fix return type/value for memcpy_mcsafe() Tony Luck
2016-03-16 8:06 ` [tip:x86/urgent] " tip-bot for Tony Luck
2016-02-26 0:58 ` [PATCH v13] x86, mce: Add memcpy_trap() Linus Torvalds
2016-02-26 1:19 ` Andy Lutomirski
2016-02-26 2:38 ` Linus Torvalds
2016-02-18 18:12 ` [PATCH v11 3/4] x86, mce: Add __mcsafe_copy() Linus Torvalds
2016-02-18 18:51 ` Ingo Molnar
2016-02-18 18:52 ` Luck, Tony
2016-02-18 20:14 ` Ingo Molnar
2016-02-18 21:33 ` Dan Williams
2016-02-17 18:20 ` [PATCH v11 2/4] x86, mce: Check for faults tagged in EXTABLE_CLASS_FAULT exception table entries Tony Luck
2016-02-18 10:19 ` [tip:ras/core] x86/mce: " tip-bot for Tony Luck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56cf571d44495b2cf@agluck-desk.sc.intel.com \
--to=tony.luck@intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.