From patchwork Fri Aug 26 17:18:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 12956333 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 BDB14ECAAD9 for ; Fri, 26 Aug 2022 17:18:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50C5C94000A; Fri, 26 Aug 2022 13:18:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4944E940007; Fri, 26 Aug 2022 13:18:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30E5094000A; Fri, 26 Aug 2022 13:18:11 -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 195C0940007 for ; Fri, 26 Aug 2022 13:18:11 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ED023120F88 for ; Fri, 26 Aug 2022 17:18:10 +0000 (UTC) X-FDA: 79842401940.30.A3A049B Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf24.hostedemail.com (Postfix) with ESMTP id 79B9D180027 for ; Fri, 26 Aug 2022 17:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661534290; x=1693070290; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GCTeJYnVfz9emV2HwJCGmwSTFAShgS49A/17AEqM6p0=; b=IxGUz5ikRi61KZo9aceGnpAvph0j5B01HAFjkpDWLA5mAAvJdaOjVq8z t0tTFI47wbJYIdzjdtUy9DEVsQCIIc17RpoIYcJ8rnker+2kW3kCQTOzs 3N5H5I4vKIAKYJKRPU/LIOuLuOKV4Fv76bFfn0UF5AT8KgvxpzWNaIxNz ljThUOMA62Pzv/g/FT643zgDA5FVtC+nK66/Uh/sgWFUV+K2i7g73/wg5 BDJXtN3FX4gsbPnuaa3A7FTstQs02W5uAkdz8INDOxUvofoJb2sNvmhQC gworVkME+sc2adqk6WLeuLsb57pEtffnAEnP22n0UOqJKWk6zbUVg/Gzc Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="292134770" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="292134770" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 10:18:09 -0700 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="613590592" Received: from jodirobx-mobl2.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.108.22]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 10:18:08 -0700 Subject: [PATCH 3/4] mm/memory-failure: Fix detection of memory_failure() handlers From: Dan Williams To: akpm@linux-foundation.org, djwong@kernel.org Cc: Shiyang Ruan , Christoph Hellwig , Naoya Horiguchi , Al Viro , Dave Chinner , Goldwyn Rodrigues , Jane Chu , Matthew Wilcox , Miaohe Lin , Ritesh Harjani , nvdimm@lists.linux.dev, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Date: Fri, 26 Aug 2022 10:18:07 -0700 Message-ID: <166153428781.2758201.1990616683438224741.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <166153426798.2758201.15108211981034512993.stgit@dwillia2-xfh.jf.intel.com> References: <166153426798.2758201.15108211981034512993.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661534290; a=rsa-sha256; cv=none; b=pvDQD3PjrYxrFkf+Cz4pYwAaBcM6fLoGu6F5NTqbwYoI4B8ANoMV+2oFfKIKZlbQCtO4YO JGQ4uUh2SQD5v1hj8iqYFFH034nvX7y9mBmW87LJZvs2fW4Sk+JRluy1dDoaS9nAlEprKG 6kQAIcF0kXtwt0Mx4WpMu3jUSn9xK/o= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=IxGUz5ik; spf=pass (imf24.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661534290; 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:dkim-signature; bh=7p7mivAdUgdSv+63I5JywdT+moKuaglvOu3RH2hKPB4=; b=gbQq0mLIMLryjhRGfG7wVayVBw5MSnaJgl2wkHDFSijbllRA7yumDAa91v8RoElYMuebRt NDIYHwc7BBDY2YpqVXrtnG4dLyQc3K50WhAWC8cMZ76k/YlI8JONDkMfWTc7WeBMeHIP9u 48P+4FS0eTH+IWS8DdJtXyOCKAcl8Xs= X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=IxGUz5ik; spf=pass (imf24.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam08 X-Stat-Signature: xeb6hfwi53o97aj1r5w5ytpiywbhbnji X-Rspamd-Queue-Id: 79B9D180027 X-HE-Tag: 1661534290-298372 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: 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 Acked-by: Naoya Horiguchi Reviewed-by: Miaohe Lin Reviewed-by: Christoph Hellwig --- 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