Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265939 > unrolled thread

[PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

Started byTony Luck <tony.luck@intel.com>
First post2015-11-09 19:50 +0100
Last post2015-11-12 22:20 +0100
Articles 7 — 5 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup  tables Tony Luck <tony.luck@intel.com> - 2015-11-09 19:50 +0100
    Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check  fixup tables Borislav Petkov <bp@alien8.de> - 2015-11-10 12:30 +0100
      Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check  fixup tables "Luck, Tony" <tony.luck@intel.com> - 2015-11-10 23:10 +0100
    Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check  fixup tables Andy Lutomirski <luto@kernel.org> - 2015-11-12 05:20 +0100
      Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check  fixup tables "Luck, Tony" <tony.luck@intel.com> - 2015-11-12 20:50 +0100
        Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check  fixup tables Andy Lutomirski <luto@amacapital.net> - 2015-11-12 21:10 +0100
          Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check  fixup tables "Luck, Tony" <tony.luck@intel.com> - 2015-11-12 22:20 +0100

#1265939 — [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

FromTony Luck <tony.luck@intel.com>
Date2015-11-09 19:50 +0100
Subject[PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qsZFU-1HI-19@gated-at.bofh.it>
Copy the existing page fault fixup mechanisms to create a new table
to be used when fixing machine checks. Note:
1) At this time we only provide a macro to annotate assembly code
2) We assume all fixups will in code builtin to the kernel.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 arch/x86/include/asm/asm.h        |  7 +++++++
 arch/x86/include/asm/uaccess.h    |  1 +
 arch/x86/mm/extable.c             | 16 ++++++++++++++++
 include/asm-generic/vmlinux.lds.h |  6 ++++++
 include/linux/module.h            |  1 +
 kernel/extable.c                  | 14 ++++++++++++++
 6 files changed, 45 insertions(+)

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 189679aba703..f2fa7973f18f 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -58,6 +58,13 @@
 	.long (to) - . + 0x7ffffff0 ;				\
 	.popsection
 
+# define _ASM_MCEXTABLE(from, to)				\
+	.pushsection "__mcex_table", "a" ;			\
+	.balign 8 ;						\
+	.long (from) - . ;					\
+	.long (to) - . ;					\
+	.popsection
+
 # define _ASM_NOKPROBE(entry)					\
 	.pushsection "_kprobe_blacklist","aw" ;			\
 	_ASM_ALIGN ;						\
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a8df874f3e88..b8231301a224 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -111,6 +111,7 @@ struct exception_table_entry {
 #define ARCH_HAS_SEARCH_EXTABLE
 
 extern int fixup_exception(struct pt_regs *regs);
+extern int fixup_mcexception(struct pt_regs *regs);
 extern int early_fixup_exception(unsigned long *ip);
 
 /*
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 903ec1e9c326..5b328ae00365 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -49,6 +49,22 @@ int fixup_exception(struct pt_regs *regs)
 	return 0;
 }
 
+int fixup_mcexception(struct pt_regs *regs)
+{
+	const struct exception_table_entry *fixup;
+	unsigned long new_ip;
+
+	fixup = search_mcexception_tables(regs->ip);
+	if (fixup) {
+		new_ip = ex_fixup_addr(fixup);
+
+		regs->ip = new_ip;
+		return 1;
+	}
+
+	return 0;
+}
+
 /* Restricted version used during very early boot */
 int __init early_fixup_exception(unsigned long *ip)
 {
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 1781e54ea6d3..21bb20d1172a 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -473,6 +473,12 @@
 		VMLINUX_SYMBOL(__start___ex_table) = .;			\
 		*(__ex_table)						\
 		VMLINUX_SYMBOL(__stop___ex_table) = .;			\
+	}								\
+	. = ALIGN(align);						\
+	__mcex_table : AT(ADDR(__mcex_table) - LOAD_OFFSET) {		\
+		VMLINUX_SYMBOL(__start___mcex_table) = .;		\
+		*(__mcex_table)						\
+		VMLINUX_SYMBOL(__stop___mcex_table) = .;		\
 	}
 
 /*
diff --git a/include/linux/module.h b/include/linux/module.h
index 3a19c79918e0..ffecbfcc462c 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -270,6 +270,7 @@ extern const typeof(name) __mod_##type##__##name##_device_table		\
 
 /* Given an address, look for it in the exception tables */
 const struct exception_table_entry *search_exception_tables(unsigned long add);
+const struct exception_table_entry *search_mcexception_tables(unsigned long a);
 
 struct notifier_block;
 
diff --git a/kernel/extable.c b/kernel/extable.c
index e820ccee9846..261c3e2816db 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -34,6 +34,8 @@ DEFINE_MUTEX(text_mutex);
 
 extern struct exception_table_entry __start___ex_table[];
 extern struct exception_table_entry __stop___ex_table[];
+extern struct exception_table_entry __start___mcex_table[];
+extern struct exception_table_entry __stop___mcex_table[];
 
 /* Cleared by build time tools if the table is already sorted. */
 u32 __initdata __visible main_extable_sort_needed = 1;
@@ -45,6 +47,8 @@ void __init sort_main_extable(void)
 		pr_notice("Sorting __ex_table...\n");
 		sort_extable(__start___ex_table, __stop___ex_table);
 	}
+	if (__stop___mcex_table > __start___mcex_table)
+		sort_extable(__start___mcex_table, __stop___mcex_table);
 }
 
 /* Given an address, look for it in the exception tables. */
@@ -58,6 +62,16 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr)
 	return e;
 }
 
+/* Given an address, look for it in the machine check exception tables. */
+const struct exception_table_entry *search_mcexception_tables(
+				    unsigned long addr)
+{
+	const struct exception_table_entry *e;
+
+	e = search_extable(__start___mcex_table, __stop___mcex_table-1, addr);
+	return e;
+}
+
 static inline int init_kernel_text(unsigned long addr)
 {
 	if (addr >= (unsigned long)_sinittext &&
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1266416 — Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

FromBorislav Petkov <bp@alien8.de>
Date2015-11-10 12:30 +0100
SubjectRe: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qtfhE-4pX-19@gated-at.bofh.it>
In reply to#1265939
On Fri, Nov 06, 2015 at 12:57:03PM -0800, Tony Luck wrote:
> Copy the existing page fault fixup mechanisms to create a new table
> to be used when fixing machine checks. Note:
> 1) At this time we only provide a macro to annotate assembly code
> 2) We assume all fixups will in code builtin to the kernel.
> 
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
>  arch/x86/include/asm/asm.h        |  7 +++++++
>  arch/x86/include/asm/uaccess.h    |  1 +
>  arch/x86/mm/extable.c             | 16 ++++++++++++++++
>  include/asm-generic/vmlinux.lds.h |  6 ++++++
>  include/linux/module.h            |  1 +
>  kernel/extable.c                  | 14 ++++++++++++++
>  6 files changed, 45 insertions(+)
> 
> diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
> index 189679aba703..f2fa7973f18f 100644
> --- a/arch/x86/include/asm/asm.h
> +++ b/arch/x86/include/asm/asm.h
> @@ -58,6 +58,13 @@
>  	.long (to) - . + 0x7ffffff0 ;				\
>  	.popsection
>  
> +# define _ASM_MCEXTABLE(from, to)				\

Maybe add an intermediary macro which abstracts the table name:

#define __ASM_EXTABLE(from, to, table)
...

and then do

#define _ASM_EXTABLE(from, to)		__ASM_EXTABLE(from, to, "__ex_table")
#define _ASM_MCEXTABLE(from, to)	__ASM_EXTABLE(from, to, "__mcex_table")

> +	.pushsection "__mcex_table", "a" ;			\
> +	.balign 8 ;						\
> +	.long (from) - . ;					\
> +	.long (to) - . ;					\
> +	.popsection
> +
>  # define _ASM_NOKPROBE(entry)					\
>  	.pushsection "_kprobe_blacklist","aw" ;			\
>  	_ASM_ALIGN ;						\
> diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
> index a8df874f3e88..b8231301a224 100644
> --- a/arch/x86/include/asm/uaccess.h
> +++ b/arch/x86/include/asm/uaccess.h
> @@ -111,6 +111,7 @@ struct exception_table_entry {
>  #define ARCH_HAS_SEARCH_EXTABLE
>  
>  extern int fixup_exception(struct pt_regs *regs);
> +extern int fixup_mcexception(struct pt_regs *regs);
>  extern int early_fixup_exception(unsigned long *ip);
>  
>  /*
> diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
> index 903ec1e9c326..5b328ae00365 100644
> --- a/arch/x86/mm/extable.c
> +++ b/arch/x86/mm/extable.c
> @@ -49,6 +49,22 @@ int fixup_exception(struct pt_regs *regs)
>  	return 0;
>  }
>  
> +int fixup_mcexception(struct pt_regs *regs)
> +{
> +	const struct exception_table_entry *fixup;
> +	unsigned long new_ip;
> +
> +	fixup = search_mcexception_tables(regs->ip);
> +	if (fixup) {
> +		new_ip = ex_fixup_addr(fixup);
> +
> +		regs->ip = new_ip;
> +		return 1;
> +	}
> +
> +	return 0;
> +}

Yeah, all that duplication might raise some brows but I'd guess
special-handling MCA in the normal exception paths might make the code
a bit too ugly...

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1266809 — Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

From"Luck, Tony" <tony.luck@intel.com>
Date2015-11-10 23:10 +0100
SubjectRe: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qtpgZ-2up-1@gated-at.bofh.it>
In reply to#1266416
On Tue, Nov 10, 2015 at 12:21:16PM +0100, Borislav Petkov wrote:
> > +# define _ASM_MCEXTABLE(from, to)				\
> 
> Maybe add an intermediary macro which abstracts the table name:
> 
> #define __ASM_EXTABLE(from, to, table)
> ...
> 
> and then do
> 
> #define _ASM_EXTABLE(from, to)		__ASM_EXTABLE(from, to, "__ex_table")
> #define _ASM_MCEXTABLE(from, to)	__ASM_EXTABLE(from, to, "__mcex_table")

That looks a bit nicer.
> 
> Yeah, all that duplication might raise some brows but I'd guess
> special-handling MCA in the normal exception paths might make the code
> a bit too ugly...

The 0-day robot berated me for bloating the i386-tinyconfig by 88 bytes.
I guess I can put the new functions inside #ifdef CONFIG_MEMORY_FAILURE
to save them from that. Enterprise kernels that turn this option on can
probably live with 88 bytes.

-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1267605 — Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

FromAndy Lutomirski <luto@kernel.org>
Date2015-11-12 05:20 +0100
SubjectRe: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qtRwB-417-3@gated-at.bofh.it>
In reply to#1265939
On 11/06/2015 12:57 PM, Tony Luck wrote:
> Copy the existing page fault fixup mechanisms to create a new table
> to be used when fixing machine checks. Note:
> 1) At this time we only provide a macro to annotate assembly code
> 2) We assume all fixups will in code builtin to the kernel.

Shouldn't the first step be to fixup failures during user memory access?

>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
>   arch/x86/include/asm/asm.h        |  7 +++++++
>   arch/x86/include/asm/uaccess.h    |  1 +
>   arch/x86/mm/extable.c             | 16 ++++++++++++++++
>   include/asm-generic/vmlinux.lds.h |  6 ++++++
>   include/linux/module.h            |  1 +
>   kernel/extable.c                  | 14 ++++++++++++++
>   6 files changed, 45 insertions(+)
>
> diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
> index 189679aba703..f2fa7973f18f 100644
> --- a/arch/x86/include/asm/asm.h
> +++ b/arch/x86/include/asm/asm.h
> @@ -58,6 +58,13 @@
>   	.long (to) - . + 0x7ffffff0 ;				\
>   	.popsection
>
> +# define _ASM_MCEXTABLE(from, to)				\
> +	.pushsection "__mcex_table", "a" ;			\
> +	.balign 8 ;						\
> +	.long (from) - . ;					\
> +	.long (to) - . ;					\
> +	.popsection
> +

This does something really weird to rax.  (Also, what happens on 32-bit 
kernels?  There's no bit 63.)

Please at least document it clearly.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1268235 — Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

From"Luck, Tony" <tony.luck@intel.com>
Date2015-11-12 20:50 +0100
SubjectRe: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qu62C-4HV-21@gated-at.bofh.it>
In reply to#1267605
On Wed, Nov 11, 2015 at 08:14:56PM -0800, Andy Lutomirski wrote:
> On 11/06/2015 12:57 PM, Tony Luck wrote:
> >Copy the existing page fault fixup mechanisms to create a new table
> >to be used when fixing machine checks. Note:
> >1) At this time we only provide a macro to annotate assembly code
> >2) We assume all fixups will in code builtin to the kernel.
> 
> Shouldn't the first step be to fixup failures during user memory access?

We already have code to recover from machine checks encountered
while the processor is executing ring3 code.

This series is gently extending to ring0 code in some places that look
to be high enough profile to warrant the attention (and that we have
some plan for a recovery action). Initial user will be filessytem code
using NVDIMM as storage. I.e. lots of memory accessed by a small amount
of code. If we get a machine check reading the NVDIMM, then we turn it
into -EIO.

> This does something really weird to rax.  (Also, what happens on 32-bit
> kernels?  There's no bit 63.)

32-bit kernels are out of luck for this - but I don't feel bad about it -
you simply cannot run a 32-bit kernel on machines that have this level
of recovery (they have too much memory to boot 32-bit kernels).

> Please at least document it clearly.

Will do.

-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1268242 — Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

FromAndy Lutomirski <luto@amacapital.net>
Date2015-11-12 21:10 +0100
SubjectRe: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qu6lY-55s-17@gated-at.bofh.it>
In reply to#1268235
On Thu, Nov 12, 2015 at 11:44 AM, Luck, Tony <tony.luck@intel.com> wrote:
> On Wed, Nov 11, 2015 at 08:14:56PM -0800, Andy Lutomirski wrote:
>> On 11/06/2015 12:57 PM, Tony Luck wrote:
>> >Copy the existing page fault fixup mechanisms to create a new table
>> >to be used when fixing machine checks. Note:
>> >1) At this time we only provide a macro to annotate assembly code
>> >2) We assume all fixups will in code builtin to the kernel.
>>
>> Shouldn't the first step be to fixup failures during user memory access?
>
> We already have code to recover from machine checks encountered
> while the processor is executing ring3 code.

I meant failures during copy_from_user, copy_to_user, etc.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1268283 — Re: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables

From"Luck, Tony" <tony.luck@intel.com>
Date2015-11-12 22:20 +0100
SubjectRe: [PATCH 1/3] x86, ras: Add new infrastructure for machine check fixup tables
Message-ID<qu7rI-5JW-15@gated-at.bofh.it>
In reply to#1268242
On Thu, Nov 12, 2015 at 12:04:36PM -0800, Andy Lutomirski wrote:
> > We already have code to recover from machine checks encountered
> > while the processor is executing ring3 code.
> 
> I meant failures during copy_from_user, copy_to_user, etc.

Yes.  copy_from_user() will be pretty interesting from a coverage point
of view.  We can recover by sending a SIGBUS to the process just like
we would have if the process had accessed the data directly rather than
passing the address to the kernel to acccess it.

copy_to_user() is a lot harder. The machine check is on the kernel side
of the copy. If we are copying from page cache as part of a read(2)
syscall from a regular file we can probably nuke the page from the cache
and return -EIO to the user.  Other cases may be possible, but I don't
immediately see any way to do it as a general case.

-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web