Skip to contentSkip to conversation

mm, Make __get_user_pages return -EHWPOISON for HWPOISON page optionally

PATCH In review Huang Ying 5 participants 11 messages Jan 13, 2011 – Jan 28, 2011

Subsystems (4)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

PATCH 1/2 mm, Make __get_user_pages return -EHWPOISON for HWPOISON page optionally

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton <[email protected]>
---
 include/asm-generic/errno.h |    2 +
 include/linux/mm.h          |   17 +++++++++++++
 mm/memory.c                 |   55 +++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 71 insertions(+), 3 deletions(-)
include/asm-generic/errno.h +2 -0
@@ -108,4 +108,6 @@
 
 #define ERFKILL		132	/* Operation not possible due to RF-kill */
 
+#define EHWPOISON	133	/* Memory page has hardware error */
+
 #endif
include/linux/mm.h +17 -0
@@ -860,6 +860,22 @@ int get_user_pages(struct task_struct *t
 			struct page **pages, struct vm_area_struct **vmas);
 int get_user_pages_fast(unsigned long start, int nr_pages, int write,
 			struct page **pages);
+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,
+			    unsigned long start, int nr_pages, int write,
+			    int force, struct page **pages,
+			    struct vm_area_struct **vmas);
+#else
+static inline int get_user_pages_hwpoison(struct task_struct *tsk,
+					  struct mm_struct *mm,
+					  unsigned long start, int nr_pages,
+					  int write, int force,
+					  struct page **pages,
+					  struct vm_area_struct **vmas) {
+	return get_user_pages(tsk, mm, start, nr_pages,
+			      write, force, pages, vmas);
+}
+#endif
 struct page *get_dump_page(unsigned long addr);
 
 extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
@@ -1415,6 +1431,7 @@ struct page *follow_page(struct vm_area_
 #define FOLL_GET	0x04	/* do get_page on page */
 #define FOLL_DUMP	0x08	/* give error on hole if it would be zero */
 #define FOLL_FORCE	0x10	/* get_user_pages read/write w/o permission */
+#define FOLL_HWPOISON	0x20	/* check page is hwpoisoned */
 
 typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
 			void *data);
mm/memory.c +52 -3

67 lines not on this page · raw message

#1 lore raw
Quoted 18 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>

include/linux/mm.h int get_user_pages(struct task_struct *t · line 868

Quoted 6 lines
include/linux/mm.h +6 -0
+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,
+			    unsigned long start, int nr_pages, int write,
+			    int force, struct page **pages,
+			    struct vm_area_struct **vmas);
+#else

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#2 lore raw
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>
Quoted 9 lines

include/linux/mm.h int get_user_pages(struct task_struct *t · line 868

Quoted 6 lines
include/linux/mm.h +6 -0
+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,
+			    unsigned long start, int nr_pages, int write,
+			    int force, struct page **pages,
+			    struct vm_area_struct **vmas);
+#else

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Or export __get_user_pages()?

Best Regards,
Huang Ying

#3 lore raw
Quoted 27 lines · Huang Ying
Quoted 26 lines · Avi Kivity
Quoted 24 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>

+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,

 +			    unsigned long start, int nr_pages, int write,
 +			    int force, struct page **pages,
 +			    struct vm_area_struct **vmas);

+#else

Quoted 4 lines
Quoted 2 lines

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Or export __get_user_pages()?

That's better, yes.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#4 lore raw

Hi, Andrew,

Quoted 28 lines · Avi Kivity
Quoted 27 lines · Huang Ying
Quoted 26 lines · Avi Kivity
Quoted 24 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>

+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,

 +			    unsigned long start, int nr_pages, int write,
 +			    int force, struct page **pages,
 +			    struct vm_area_struct **vmas);

+#else

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Or export __get_user_pages()?

That's better, yes.

Do you think it is a good idea to export __get_user_pages() instead of adding get_user_pages_noio() and get_user_pages_hwpoison()?

Best Regards,
Huang Ying

#5 lore raw
Quoted 34 lines · Huang Ying

Hi, Andrew,

Quoted 31 lines · Avi Kivity
Quoted 30 lines · Huang Ying
Quoted 28 lines · Avi Kivity
Quoted 18 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>
Quoted 6 lines

+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,

 +			    unsigned long start, int nr_pages, int write,
 +			    int force, struct page **pages,
 +			    struct vm_area_struct **vmas);

+#else

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Or export __get_user_pages()?

That's better, yes.

Do you think it is a good idea to export __get_user_pages() instead of adding get_user_pages_noio() and get_user_pages_hwpoison()?

Better Andrew and/or Linus should decide it.

author
#6 lore raw

Hi, Andrew,

Quoted 35 lines · Marcelo Tosatti
Quoted 34 lines · Huang Ying

Hi, Andrew,

Quoted 31 lines · Avi Kivity
Quoted 30 lines · Huang Ying
Quoted 28 lines · Avi Kivity
Quoted 18 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>
Quoted 6 lines

+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,

 +			    unsigned long start, int nr_pages, int write,
 +			    int force, struct page **pages,
 +			    struct vm_area_struct **vmas);

+#else

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Or export __get_user_pages()?

That's better, yes.

Do you think it is a good idea to export __get_user_pages() instead of adding get_user_pages_noio() and get_user_pages_hwpoison()?

Better Andrew and/or Linus should decide it.

We really need your comments about this.

Best Regards,
Huang Ying

maintainer
#7 lore raw
Quoted 40 lines · On Thu, 27 Jan 2011 15:29:05 +0800 Huang Ying <[email protected]> wrote:

Hi, Andrew,

Quoted 37 lines · Marcelo Tosatti
Quoted 36 lines · Huang Ying

Hi, Andrew,

Quoted 33 lines · Avi Kivity
Quoted 31 lines · Huang Ying
Quoted 26 lines · Avi Kivity
Quoted 18 lines · Huang Ying

Make __get_user_pages return -EHWPOISON for HWPOISON page only if FOLL_HWPOISON is specified. With this patch, the interested callers can distinguish HWPOISON page from general FAULT page, while other callers will still get -EFAULT for pages, so the user space interface need not to be changed.

get_user_pages_hwpoison is added as a variant of get_user_pages that can return -EHWPOISON for HWPOISON page.

This feature is needed by KVM, where UCR MCE should be relayed to guest for HWPOISON page, while instruction emulation and MMIO will be tried for general FAULT page.

The idea comes from Andrew Morton.

Cc Andrew Morton<[email protected]>
Quoted 6 lines

+#ifdef CONFIG_MEMORY_FAILURE
+int get_user_pages_hwpoison(struct task_struct *tsk, struct mm_struct *mm,

 +			    unsigned long start, int nr_pages, int write,
 +			    int force, struct page **pages,
 +			    struct vm_area_struct **vmas);

+#else

Quoted 2 lines

Since we'd also like to add get_user_pages_noio(), perhaps adding a flags field to get_user_pages() is better.

Or export __get_user_pages()?

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

That's better, yes.

Do you think it is a good idea to export __get_user_pages() instead of adding get_user_pages_noio() and get_user_pages_hwpoison()?

Better Andrew and/or Linus should decide it.

We really need your comments about this.

Export __get_user_pages(), I guess. We don't need hwpoison/kvm-specific stuff in mm/memory.c and get_user_pages_hwpoison()/get_user_pages_noio() are very thin wrappers.

The number of args to these functions is getting nutty - you'll probably find that it is beneficial to inline these wrapepr functions, if the number of callsites is small.

#8 lore raw

I personally would consider it cleaner to have clearly defined wrappers instead of complicted flags in the caller.

Quoted 3 lines

The number of args to these functions is getting nutty - you'll probably find that it is beneficial to inline these wrapepr functions, if the number of callsites is small.

Really the functions are so heavy weight it should not matter. The problem with inlining is that you end up with the code in the header file and I personally find that much harder to browse instead of having everything in one file.

Also longer term we'll get compilers that can do cross-file inlining for optimized builds.

So please better avoid these kinds of micro optimizations unless it's a really really extremly speed critical path.

Thanks,

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
maintainer
#9 lore raw
Quoted 11 lines · On Fri, 28 Jan 2011 01:57:11 +0100 Andi Kleen <[email protected]> wrote:

I personally would consider it cleaner to have clearly defined wrappers instead of complicted flags in the caller.

Quoted 3 lines

The number of args to these functions is getting nutty - you'll probably find that it is beneficial to inline these wrapepr functions, if the number of callsites is small.

Really the functions are so heavy weight it should not matter. The problem with inlining is that you end up with the code in the header file and I personally find that much harder to browse instead of having everything in one file.

You'll cope.

Quoted 2 lines

Also longer term we'll get compilers that can do cross-file inlining for optimized builds.

Which we'll probably need to turn off all over the place :(

Quoted 2 lines

So please better avoid these kinds of micro optimizations unless it's a really really extremly speed critical path.

It's not just speed and it's not just .text size, either. Calling a ten-arg function consumes stack space.

#10 lore raw
Quoted 4 lines
Quoted 2 lines

Also longer term we'll get compilers that can do cross-file inlining for optimized builds.

Which we'll probably need to turn off all over the place :(

Why?

Quoted 6 lines
Quoted 3 lines

So please better avoid these kinds of micro optimizations unless it's a really really extremly speed critical path.

It's not just speed and it's not just .text size, either. Calling a ten-arg function consumes stack space.

gcc is pretty good at handling tail calls. Take a look at the code it generates.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.