Re: [PATCH v1 3/7] mm: rename and move page_is_poisoned()

Mike Rapoport
2021-05-02T06:32:58Z

On Thu, Apr 29, 2021 at 02:25:15PM +0200, David Hildenbrand wrote:
> Commit d3378e86d182 ("mm/gup: check page posion status for coredump.")
> introduced page_is_poisoned(), however, v5 [1] of the patch used
> "page_is_hwpoison()" and something went wrong while upstreaming. Rename the
> function and move it to page-flags.h, from where it can be used in other
> -- kcore -- context.
>
> Move the comment to the place where it belongs and simplify.
>
> [1] https://lkml.kernel.org/r/20210322193318.377c9ce9@alex-virtual-machine
>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>

> ---
> include/linux/page-flags.h | 7 +++++++
> mm/gup.c | 6 +++++-
> mm/internal.h | 20 --------------------
> 3 files changed, 12 insertions(+), 21 deletions(-)

Nice :)

>
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index 04a34c08e0a6..b8c56672a588 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -694,6 +694,13 @@ PAGEFLAG_FALSE(DoubleMap)
> TESTSCFLAG_FALSE(DoubleMap)
> #endif
>
> +static inline bool is_page_hwpoison(struct page *page)
> +{
> + if (PageHWPoison(page))
> + return true;
> + return PageHuge(page) && PageHWPoison(compound_head(page));
> +}
> +
> /*
> * For pages that are never mapped to userspace (and aren't PageSlab),
> * page_type may be used. Because it is initialised to -1, we invert the
> diff --git a/mm/gup.c b/mm/gup.c
> index ef7d2da9f03f..000f3303e7f2 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -1536,7 +1536,11 @@ struct page *get_dump_page(unsigned long addr)
> if (locked)
> mmap_read_unlock(mm);
>
> - if (ret == 1 && is_page_poisoned(page))
> + /*
> + * We might have hwpoisoned pages still mapped into user space. Don't
> + * read these pages when creating a coredump, access could be fatal.
> + */
> + if (ret == 1 && is_page_hwpoison(page))
> return NULL;
>
> return (ret == 1) ? page : NULL;
> diff --git a/mm/internal.h b/mm/internal.h
> index cb3c5e0a7799..1432feec62df 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -97,26 +97,6 @@ static inline void set_page_refcounted(struct page *page)
> set_page_count(page, 1);
> }
>
> -/*
> - * When kernel touch the user page, the user page may be have been marked
> - * poison but still mapped in user space, if without this page, the kernel
> - * can guarantee the data integrity and operation success, the kernel is
> - * better to check the posion status and avoid touching it, be good not to
> - * panic, coredump for process fatal signal is a sample case matching this
> - * scenario. Or if kernel can't guarantee the data integrity, it's better
> - * not to call this function, let kernel touch the poison page and get to
> - * panic.
> - */
> -static inline bool is_page_poisoned(struct page *page)
> -{
> - if (PageHWPoison(page))
> - return true;
> - else if (PageHuge(page) && PageHWPoison(compound_head(page)))
> - return true;
> -
> - return false;
> -}
> -
> extern unsigned long highest_memmap_pfn;
>
> /*
> --
> 2.30.2
>

--
Sincerely yours,
Mike.