All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm,hwpoison: check mm when killing accessing process
@ 2022-09-14  6:49 Shuai Xue
  2022-09-14 22:35 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Shuai Xue @ 2022-09-14  6:49 UTC (permalink / raw)
  To: naoya.horiguchi, linmiaohe, akpm
  Cc: linux-mm, linux-kernel, cuibixuan, baolin.wang, zhuo.song, xueshuai

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")
Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
---
 mm/memory-failure.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 14439806b5ef..7553917ce820 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -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;
 }
 
-- 
2.20.1.12.g72788fdb


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm,hwpoison: check mm when killing accessing process
  2022-09-14  6:49 [PATCH] mm,hwpoison: check mm when killing accessing process Shuai Xue
@ 2022-09-14 22:35 ` Andrew Morton
  2022-09-15  1:36   ` Shuai Xue
  2022-09-15  1:45 ` Miaohe Lin
  2022-09-15  1:48 ` Naoya Horiguchi
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2022-09-14 22:35 UTC (permalink / raw)
  To: Shuai Xue
  Cc: naoya.horiguchi, linmiaohe, linux-mm, linux-kernel, cuibixuan,
	baolin.wang, zhuo.song, Huang Ying

On Wed, 14 Sep 2022 14:49:35 +0800 Shuai Xue <xueshuai@linux.alibaba.com> 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.
> 
> 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".

> Fixes: a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")
> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>

I'll add cc:stable.

> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -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;
>  }

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm,hwpoison: check mm when killing accessing process
  2022-09-14 22:35 ` Andrew Morton
@ 2022-09-15  1:36   ` Shuai Xue
  0 siblings, 0 replies; 7+ messages in thread
From: Shuai Xue @ 2022-09-15  1:36 UTC (permalink / raw)
  To: Andrew Morton
  Cc: naoya.horiguchi, linmiaohe, linux-mm, linux-kernel, cuibixuan,
	baolin.wang, zhuo.song, Huang Ying



在 2022/9/15 AM6:35, Andrew Morton 写道:
> On Wed, 14 Sep 2022 14:49:35 +0800 Shuai Xue <xueshuai@linux.alibaba.com> 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.
>>
>> 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 :)

> 
>> Fixes: a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address")
>> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
> 
> I'll add cc:stable.

Thanks.

> 
>> --- a/mm/memory-failure.c
>> +++ b/mm/memory-failure.c
>> @@ -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;
>>  }
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm,hwpoison: check mm when killing accessing process
  2022-09-14  6:49 [PATCH] mm,hwpoison: check mm when killing accessing process Shuai Xue
  2022-09-14 22:35 ` Andrew Morton
@ 2022-09-15  1:45 ` Miaohe Lin
  2022-09-15  2:06   ` Shuai Xue
  2022-09-15  1:48 ` Naoya Horiguchi
  2 siblings, 1 reply; 7+ messages in thread
From: Miaohe Lin @ 2022-09-15  1:45 UTC (permalink / raw)
  To: Shuai Xue
  Cc: linux-mm, linux-kernel, cuibixuan, baolin.wang, zhuo.song,
	naoya.horiguchi, akpm

On 2022/9/14 14:49, Shuai Xue 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.
> 
> 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")
> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>

Thanks for fixing.

Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>

Thanks,
Miaohe Lin


> ---
>  mm/memory-failure.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 14439806b5ef..7553917ce820 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -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;
>  }
>  
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm,hwpoison: check mm when killing accessing process
  2022-09-14  6:49 [PATCH] mm,hwpoison: check mm when killing accessing process Shuai Xue
  2022-09-14 22:35 ` Andrew Morton
  2022-09-15  1:45 ` Miaohe Lin
@ 2022-09-15  1:48 ` Naoya Horiguchi
  2022-09-15  2:08   ` Shuai Xue
  2 siblings, 1 reply; 7+ messages in thread
From: Naoya Horiguchi @ 2022-09-15  1:48 UTC (permalink / raw)
  To: Shuai Xue
  Cc: linmiaohe, akpm, linux-mm, linux-kernel, cuibixuan, baolin.wang,
	zhuo.song, Naoya Horiguchi

On Wed, Sep 14, 2022 at 02:49:35PM +0800, Shuai Xue 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.
>
> 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")
> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>

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

Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm,hwpoison: check mm when killing accessing process
  2022-09-15  1:45 ` Miaohe Lin
@ 2022-09-15  2:06   ` Shuai Xue
  0 siblings, 0 replies; 7+ messages in thread
From: Shuai Xue @ 2022-09-15  2:06 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: linux-mm, linux-kernel, cuibixuan, baolin.wang, zhuo.song,
	naoya.horiguchi, akpm



在 2022/9/15 AM9:45, Miaohe Lin 写道:
> On 2022/9/14 14:49, Shuai Xue 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.
>>
>> 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")
>> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
> 
> Thanks for fixing.
> 
> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
> 
> Thanks,
> Miaohe Lin

Thank you for your review.

Cheers,
Shuai

> 
> 
>> ---
>>  mm/memory-failure.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
>> index 14439806b5ef..7553917ce820 100644
>> --- a/mm/memory-failure.c
>> +++ b/mm/memory-failure.c
>> @@ -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;
>>  }
>>  
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mm,hwpoison: check mm when killing accessing process
  2022-09-15  1:48 ` Naoya Horiguchi
@ 2022-09-15  2:08   ` Shuai Xue
  0 siblings, 0 replies; 7+ messages in thread
From: Shuai Xue @ 2022-09-15  2:08 UTC (permalink / raw)
  To: Naoya Horiguchi
  Cc: linmiaohe, akpm, linux-mm, linux-kernel, cuibixuan, baolin.wang,
	zhuo.song, Naoya Horiguchi



在 2022/9/15 AM9:48, Naoya Horiguchi 写道:
> On Wed, Sep 14, 2022 at 02:49:35PM +0800, Shuai Xue 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.
>>
>> 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")
>> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
> 
> Thank you for the patch, the fix itself makes sense to me.
> I agree with this patch with applying comments from Andrew.
> 
> Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>

Thank you for prompt review.

Cheers,
Shuai

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-15  2:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14  6:49 [PATCH] mm,hwpoison: check mm when killing accessing process Shuai Xue
2022-09-14 22:35 ` Andrew Morton
2022-09-15  1:36   ` Shuai Xue
2022-09-15  1:45 ` Miaohe Lin
2022-09-15  2:06   ` Shuai Xue
2022-09-15  1:48 ` Naoya Horiguchi
2022-09-15  2:08   ` Shuai Xue

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.