diff mbox series

[v4,2/2] mm/hwpoison: Add in-use hugepage hwpoison filter judgement

Message ID 20220221021521.2329075-1-luofei@unicloud.com (mailing list archive)
State New
Headers show
Series [v4,1/2] mm/hwpoison: Avoid the impact of hwpoison_filter() return value on mce handler | expand

Commit Message

luofei Feb. 21, 2022, 2:15 a.m. UTC
After successfully obtaining the reference count of the huge
page, it is still necessary to call hwpoison_filter() to make a
filter judgement, otherwise the filter hugepage will be unmaped
and the related process may be killed.

Signed-off-by: luofei <luofei@unicloud.com>
---
 mm/memory-failure.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Miaohe Lin Feb. 21, 2022, 12:05 p.m. UTC | #1
On 2022/2/21 10:15, luofei wrote:
> After successfully obtaining the reference count of the huge
> page, it is still necessary to call hwpoison_filter() to make a
> filter judgement, otherwise the filter hugepage will be unmaped
> and the related process may be killed.
> 

LGTM. Thanks.

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

BTW: It seems there is also another missing call to hwpoison_filter() when we
encounter free_buddy_page in memory_failure(). But I'am not sure.

> Signed-off-by: luofei <luofei@unicloud.com>
> ---
>  mm/memory-failure.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 59d6d939a752..17a7b0a94ab9 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -1548,6 +1548,17 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags)
>  	lock_page(head);
>  	page_flags = head->flags;
>  
> +	if (hwpoison_filter(p)) {
> +		if (TestClearPageHWPoison(head))
> +			num_poisoned_pages_dec();
> +		put_page(p);
> +		if (flags & MF_MCE_HANDLE)
> +			res = -EHWPOISON;
> +		else
> +			res = 0;
> +		goto out;
> +	}
> +
>  	/*
>  	 * TODO: hwpoison for pud-sized hugetlb doesn't work right now, so
>  	 * simply disable it. In order to make it work properly, we need
>
diff mbox series

Patch

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 59d6d939a752..17a7b0a94ab9 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1548,6 +1548,17 @@  static int memory_failure_hugetlb(unsigned long pfn, int flags)
 	lock_page(head);
 	page_flags = head->flags;
 
+	if (hwpoison_filter(p)) {
+		if (TestClearPageHWPoison(head))
+			num_poisoned_pages_dec();
+		put_page(p);
+		if (flags & MF_MCE_HANDLE)
+			res = -EHWPOISON;
+		else
+			res = 0;
+		goto out;
+	}
+
 	/*
 	 * TODO: hwpoison for pud-sized hugetlb doesn't work right now, so
 	 * simply disable it. In order to make it work properly, we need