Skip to contentSkip to conversation

mm,hwpoison: check mm when killing accessing process

PATCH Applied Shuai Xue 4 participants 7 messages Sep 14, 2022 – Sep 15, 2022

Subsystems (2)
lore
Share & tools
lore

Shuai Xue

author
#0 lore raw

PATCH 1/1 mm,hwpoison: check mm when killing accessing process

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")
---
 mm/memory-failure.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/memory-failure.c +4 -0
index 14439806b5ef..7553917ce820 100644
@@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	};
 	priv.tk.tsk = p;
 
+	if (!p->mm)
+		return -EFAULT;
+
 	mmap_read_lock(p->mm);
 	ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops,
 			      (void *)&priv);
@@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	else
 		ret = 0;
 	mmap_read_unlock(p->mm);
+
 	return ret > 0 ? -EHWPOISON : -EFAULT;
 }
 
Signature · 1 line
2.20.1.12.g72788fdb
maintainer
#1 lore raw
Quoted 9 lines · On Wed, 14 Sep 2022 14:49:35 +0800 Shuai Xue <[email protected]> wrote:

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

Quoted 6 lines

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Thanks.

When fixing a bug, please always describe the user-visible effects of tha bug. I'm thinking "null pointer deref crashes the kernel".

Quoted 2 lines
Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")

I'll add cc:stable.

Quoted 13 lines
mm/memory-failure.c +3 -0
@@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	};
 	priv.tk.tsk = p;
 
+	if (!p->mm)
+		return -EFAULT;
+
 	mmap_read_lock(p->mm);
 	ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops,
 			      (void *)&priv);

mm/memory-failure.c static int kill_accessing_process(struct task_struct *p, unsigned long pfn, · line 759

Quoted 6 lines
mm/memory-failure.c +1 -0
@@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	else
 		ret = 0;
 	mmap_read_unlock(p->mm);
+
 	return ret > 0 ? -EHWPOISON : -EFAULT;
 }

This is an unrelated change which doesn't appear to match the style in memory-failure.c, so I'll drop this hunk.

author
#2 lore raw
Quoted 15 lines · Andrew Morton
Quoted 13 lines · On Wed, 14 Sep 2022 14:49:35 +0800 Shuai Xue <[email protected]> wrote:

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

Quoted 7 lines
Quoted 2 lines

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Thanks.

When fixing a bug, please always describe the user-visible effects of tha bug. I'm thinking "null pointer deref crashes the kernel".

Got it. Thank you :)

Quoted 5 lines
Quoted 3 lines
Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")

I'll add cc:stable.

Thanks.

Quoted 7 lines
Quoted 7 lines
mm/memory-failure.c +0 -0
@@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	};
 	priv.tk.tsk = p;
 
Quoted 16 lines

mm/memory-failure.c static int kill_accessing_process(struct task_struct *p, unsigned long pfn, · line 759

Quoted 13 lines
mm/memory-failure.c +4 -0
+	if (!p->mm)
+		return -EFAULT;
+
 	mmap_read_lock(p->mm);
 	ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops,
 			      (void *)&priv);
@@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	else
 		ret = 0;
 	mmap_read_unlock(p->mm);
+
 	return ret > 0 ? -EHWPOISON : -EFAULT;
 }

This is an unrelated change which doesn't appear to match the style in memory-failure.c, so I'll drop this hunk.

I see, thanks.

Cheers,
Shuai

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Shuai Xue
Quoted 13 lines · Shuai Xue

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

Quoted 5 lines

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")

Thanks for fixing.

Thanks,
Miaohe Lin

Quoted 27 lines
---
 mm/memory-failure.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/memory-failure.c +4 -0
index 14439806b5ef..7553917ce820 100644
@@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	};
 	priv.tk.tsk = p;
 
+	if (!p->mm)
+		return -EFAULT;
+
 	mmap_read_lock(p->mm);
 	ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops,
 			      (void *)&priv);
@@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	else
 		ret = 0;
 	mmap_read_unlock(p->mm);
+
 	return ret > 0 ? -EHWPOISON : -EFAULT;
 }
 
author
#4 lore raw
Quoted 20 lines · Miaohe Lin
Quoted 13 lines · Shuai Xue

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

Quoted 5 lines

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")
Quoted 6 lines

Thanks for fixing.

Thanks,
Miaohe Lin

Thank you for your review.

Cheers,
Shuai

Quoted 29 lines
Quoted 29 lines

---
 mm/memory-failure.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/memory-failure.c +4 -0
index 14439806b5ef..7553917ce820 100644
@@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	};
 	priv.tk.tsk = p;
 
+	if (!p->mm)
+		return -EFAULT;
+
 	mmap_read_lock(p->mm);
 	ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops,
 			      (void *)&priv);
@@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn,
 	else
 		ret = 0;
 	mmap_read_unlock(p->mm);
+
 	return ret > 0 ? -EHWPOISON : -EFAULT;
 }
 
Acked-by on v1 1/1
#5 lore raw
In reply to Shuai Xue
Quoted 13 lines · Shuai Xue

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

Quoted 5 lines

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")

Thank you for the patch, the fix itself makes sense to me. I agree with this patch with applying comments from Andrew.

author
#6 lore raw
Quoted 17 lines · Naoya Horiguchi
Quoted 16 lines · Shuai Xue

The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure().

When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that:

- holds mmap locking of current->mm
- does pagetable walk to find the error virtual address
- and sends SIGBUS to the current process with error info.

However, the mm of kworker is not valid. Therefore, check mm when killing accessing process.

Quoted 7 lines
Quoted 2 lines
Fixes a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")

Thank you for the patch, the fix itself makes sense to me. I agree with this patch with applying comments from Andrew.

Thank you for prompt review.

Cheers,
Shuai