Re: [PATCH 3/4] mm/memory-failure: Fix detection of memory_failure() handlers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2022/8/27 1:18, Dan Williams wrote:
> Some pagemap types, like MEMORY_DEVICE_GENERIC (device-dax) do not even
> have pagemap ops which results in crash signatures like this:
> 
>   BUG: kernel NULL pointer dereference, address: 0000000000000010
>   #PF: supervisor read access in kernel mode
>   #PF: error_code(0x0000) - not-present page
>   PGD 8000000205073067 P4D 8000000205073067 PUD 2062b3067 PMD 0
>   Oops: 0000 [#1] PREEMPT SMP PTI
>   CPU: 22 PID: 4535 Comm: device-dax Tainted: G           OE    N 6.0.0-rc2+ #59
>   Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
>   RIP: 0010:memory_failure+0x667/0xba0
>  [..]
>   Call Trace:
>    <TASK>
>    ? _printk+0x58/0x73
>    do_madvise.part.0.cold+0xaf/0xc5
> 
> Check for ops before checking if the ops have a memory_failure()
> handler.
> 
> Fixes: 33a8f7f2b3a3 ("pagemap,pmem: introduce ->memory_failure()")
> Cc: Shiyang Ruan <ruansy.fnst@xxxxxxxxxxx>
> Cc: Christoph Hellwig <hch@xxxxxx>
> Cc: Darrick J. Wong <djwong@xxxxxxxxxx>
> Cc: Naoya Horiguchi <naoya.horiguchi@xxxxxxx>
> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> Cc: Dave Chinner <david@xxxxxxxxxxxxx>
> Cc: Goldwyn Rodrigues <rgoldwyn@xxxxxxx>
> Cc: Jane Chu <jane.chu@xxxxxxxxxx>
> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
> Cc: Miaohe Lin <linmiaohe@xxxxxxxxxx>
> Cc: Ritesh Harjani <riteshh@xxxxxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>

LGTM. Thanks for fixing this.

Reviewed-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>

Thanks,
Miaohe Lin


> ---
>  include/linux/memremap.h |    5 +++++
>  mm/memory-failure.c      |    2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/memremap.h b/include/linux/memremap.h
> index 19010491a603..c3b4cc84877b 100644
> --- a/include/linux/memremap.h
> +++ b/include/linux/memremap.h
> @@ -139,6 +139,11 @@ struct dev_pagemap {
>  	};
>  };
>  
> +static inline bool pgmap_has_memory_failure(struct dev_pagemap *pgmap)
> +{
> +	return pgmap->ops && pgmap->ops->memory_failure;
> +}
> +
>  static inline struct vmem_altmap *pgmap_altmap(struct dev_pagemap *pgmap)
>  {
>  	if (pgmap->flags & PGMAP_ALTMAP_VALID)
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 14439806b5ef..8a4294afbfa0 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -1928,7 +1928,7 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags,
>  	 * Call driver's implementation to handle the memory failure, otherwise
>  	 * fall back to generic handler.
>  	 */
> -	if (pgmap->ops->memory_failure) {
> +	if (pgmap_has_memory_failure(pgmap)) {
>  		rc = pgmap->ops->memory_failure(pgmap, pfn, 1, flags);
>  		/*
>  		 * Fall back to generic handler too if operation is not
> 
> 
> .
> 




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux