Skip to contentSkip to conversation

mm, Make __get_user_pages return -EHWPOISON for HWPOISON page

PATCH In review Huang Ying 2 participants 4 messages Apr 27, 2010 – Apr 28, 2010

Subsystems (3)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

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

With this patch, the caller of __get_user_pages can distinguish HWPOISON page from general FAULT page. This 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.

---
 include/asm-generic/errno.h |    2 ++
 mm/memory.c                 |    5 +++--
 2 files changed, 5 insertions(+), 2 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
mm/memory.c +3 -2
@@ -1432,9 +1432,10 @@ int __get_user_pages(struct task_struct
 				if (ret & VM_FAULT_ERROR) {
 					if (ret & VM_FAULT_OOM)
 						return i ? i : -ENOMEM;
-					if (ret &
-					    (VM_FAULT_HWPOISON|VM_FAULT_SIGBUS))
+					if (ret & VM_FAULT_SIGBUS)
 						return i ? i : -EFAULT;
+					if (ret & VM_FAULT_HWPOISON)
+						return i ? i : -EHWPOISON;
 					BUG();
 				}
 				if (ret & VM_FAULT_MAJOR)
maintainer
#1 lore raw
Quoted 26 lines · On Tue, 27 Apr 2010 15:04:18 +0800 Huang Ying <[email protected]> wrote:

With this patch, the caller of __get_user_pages can distinguish HWPOISON page from general FAULT page. This 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.

---
 include/asm-generic/errno.h |    2 ++
 mm/memory.c                 |    5 +++--
 2 files changed, 5 insertions(+), 2 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
mm/memory.c +0 -0
@@ -1432,9 +1432,10 @@ int __get_user_pages(struct task_struct
 				if (ret & VM_FAULT_ERROR) {
 					if (ret & VM_FAULT_OOM)

mm/memory.c int __get_user_pages(struct task_struct · line 1441

Quoted 10 lines
mm/memory.c +3 -2
 						return i ? i : -ENOMEM;
-					if (ret &
-					    (VM_FAULT_HWPOISON|VM_FAULT_SIGBUS))
+					if (ret & VM_FAULT_SIGBUS)
 						return i ? i : -EFAULT;
+					if (ret & VM_FAULT_HWPOISON)
+						return i ? i : -EHWPOISON;
 					BUG();
 				}
 				if (ret & VM_FAULT_MAJOR)

This will cause various code paths (eg: fs/direct-io.c) to return -EHWPOISON to userspace, will it not?

author
#2 lore raw
Quoted 34 lines · Andrew Morton
Quoted 31 lines · On Tue, 27 Apr 2010 15:04:18 +0800 Huang Ying <[email protected]> wrote:

With this patch, the caller of __get_user_pages can distinguish HWPOISON page from general FAULT page. This 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.

---
 include/asm-generic/errno.h |    2 ++
 mm/memory.c                 |    5 +++--
 2 files changed, 5 insertions(+), 2 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
mm/memory.c +2 -2
@@ -1432,9 +1432,10 @@ int __get_user_pages(struct task_struct
 				if (ret & VM_FAULT_ERROR) {
 					if (ret & VM_FAULT_OOM)
 						return i ? i : -ENOMEM;
-					if (ret &
-					    (VM_FAULT_HWPOISON|VM_FAULT_SIGBUS))
+					if (ret & VM_FAULT_SIGBUS)
 						return i ? i : -EFAULT;
+					if (ret & VM_FAULT_HWPOISON)
Quoted 8 lines

mm/memory.c int __get_user_pages(struct task_struct · line 1441

Quoted 5 lines
mm/memory.c +1 -0
+						return i ? i : -EHWPOISON;
 					BUG();
 				}
 				if (ret & VM_FAULT_MAJOR)

This will cause various code paths (eg: fs/direct-io.c) to return -EHWPOISON to userspace, will it not?

Yes. I think it may be returned to userspace. Do we need to keep the userspace errno interface like this?

If it is, we can check whether the virtual page is hwpoisoned via going through the page table because the hwpoisoned virtual page has a special swap entry in page table.

Best Regards,
Huang Ying

maintainer
#3 lore raw
Quoted 24 lines · On Wed, 28 Apr 2010 09:50:12 +0800 Huang Ying <[email protected]> wrote:
Quoted 3 lines · Andrew Morton

On Tue, 27 Apr 2010 15:04:18 +0800
Huang Ying <[email protected]> wrote:

...

Quoted 8 lines
Quoted 8 lines
mm/memory.c +2 -2
 				if (ret & VM_FAULT_ERROR) {
 					if (ret & VM_FAULT_OOM)
 						return i ? i : -ENOMEM;
-					if (ret &
-					    (VM_FAULT_HWPOISON|VM_FAULT_SIGBUS))
+					if (ret & VM_FAULT_SIGBUS)
 						return i ? i : -EFAULT;
+					if (ret & VM_FAULT_HWPOISON)
Quoted 8 lines

mm/memory.c int __get_user_pages(struct task_struct · line 1441

Quoted 5 lines
mm/memory.c +1 -0
+						return i ? i : -EHWPOISON;
 					BUG();
 				}
 				if (ret & VM_FAULT_MAJOR)

This will cause various code paths (eg: fs/direct-io.c) to return -EHWPOISON to userspace, will it not?

Quoted 2 lines

Yes. I think it may be returned to userspace. Do we need to keep the userspace errno interface like this?

I don't think we should extend the kernel interface in a non-posix fashion without good reason and some thought. manpages and glibc will need to be updated, etc..

Quoted 3 lines

If it is, we can check whether the virtual page is hwpoisoned via going through the page table because the hwpoisoned virtual page has a special swap entry in page table.

Spose so. Or you could perhaps extend __get_user_pages() by adding a new FOLL_HWPOISON and make it return -EHWPOISON only if FOLL_HWPOISON was set, and require that the __get_user_pages(FOLL_HWPOISON) caller rewrite -EHWPOISON to something else. But I didn't think about that very hard.