From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F73EECAAD5 for ; Tue, 30 Aug 2022 02:49:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1F286B0073; Mon, 29 Aug 2022 22:49:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCF846B0074; Mon, 29 Aug 2022 22:49:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B96B9940007; Mon, 29 Aug 2022 22:49:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AA1E56B0073 for ; Mon, 29 Aug 2022 22:49:43 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 74070120CCB for ; Tue, 30 Aug 2022 02:49:43 +0000 (UTC) X-FDA: 79854728646.13.2548003 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id 569DD1C0010 for ; Tue, 30 Aug 2022 02:49:42 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MGsBJ557MzkWTJ; Tue, 30 Aug 2022 10:46:00 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 30 Aug 2022 10:49:37 +0800 Subject: Re: [PATCH 3/4] mm/memory-failure: Fix detection of memory_failure() handlers To: Dan Williams CC: Shiyang Ruan , Christoph Hellwig , Naoya Horiguchi , Al Viro , Dave Chinner , Goldwyn Rodrigues , Jane Chu , Matthew Wilcox , Ritesh Harjani , , , , , , References: <166153426798.2758201.15108211981034512993.stgit@dwillia2-xfh.jf.intel.com> <166153428781.2758201.1990616683438224741.stgit@dwillia2-xfh.jf.intel.com> From: Miaohe Lin Message-ID: Date: Tue, 30 Aug 2022 10:49:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <166153428781.2758201.1990616683438224741.stgit@dwillia2-xfh.jf.intel.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661827782; a=rsa-sha256; cv=none; b=03iuqS1WjZBSVvccw5+i6vH+Kw8dQpnKey5CtCuH7Kv+dKeeGKbfKnZJsa6NcFm1cO7S2k HygDc2NCI4YZEJsgY7xpfrmTiGQ22fKmZ349nS2zAymsk8jyLjazhmnY6QfXresXTaHs3b iofNxdNRUFqQWL8BeYN7rYw9Fe3Bn7g= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661827782; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=48KNrtggxwyIo2TOssSYkh/gEO1Cr/YeUDVGRwima3E=; b=LVL/m8YEQ5dPPEDSPGX27k1B5A2K4sd/lsVwoecDZrM1v6Osxdl1/jQEJRWEUYcyO//HF8 oGMblKn28icZ79+zy656u3fv3jnY8aEj9R4m9FFmnQtYYiPKObmMQvvzA1xEXz8xrneCpA II6k/PMprr4vrOwrrUf/CU1do5K224I= Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam05 X-Stat-Signature: yqskuaatefxe1h37tz6o8uiwu86j16p9 X-Rspamd-Queue-Id: 569DD1C0010 X-Rspam-User: X-HE-Tag: 1661827782-687118 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: > > ? _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 > Cc: Christoph Hellwig > Cc: Darrick J. Wong > Cc: Naoya Horiguchi > Cc: Al Viro > Cc: Dave Chinner > Cc: Goldwyn Rodrigues > Cc: Jane Chu > Cc: Matthew Wilcox > Cc: Miaohe Lin > Cc: Ritesh Harjani > Cc: Andrew Morton > Signed-off-by: Dan Williams LGTM. Thanks for fixing this. Reviewed-by: Miaohe Lin 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 > > > . >