From patchwork Tue Jan 12 09:34:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 12012895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C20CC433DB for ; Tue, 12 Jan 2021 09:34:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1D2622EBF for ; Tue, 12 Jan 2021 09:34:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1D2622EBF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 291058D007E; Tue, 12 Jan 2021 04:34:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23F5B8D0051; Tue, 12 Jan 2021 04:34:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12F2F8D007E; Tue, 12 Jan 2021 04:34:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id F1F8B8D0051 for ; Tue, 12 Jan 2021 04:34:51 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B8B56908B for ; Tue, 12 Jan 2021 09:34:51 +0000 (UTC) X-FDA: 77696613582.26.shirt06_5d10c3727514 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 9E0691804B65A for ; Tue, 12 Jan 2021 09:34:51 +0000 (UTC) X-HE-Tag: shirt06_5d10c3727514 X-Filterd-Recvd-Size: 3572 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 09:34:50 +0000 (UTC) IronPort-SDR: bHhUu2CssoPQQn2qt06K9jtj2x29CrehnzxrioGv2jMBhQF37up1ucrqnL/xlRhNEPJwunwgCs kNuA5eOOZ9rw== X-IronPort-AV: E=McAfee;i="6000,8403,9861"; a="165095488" X-IronPort-AV: E=Sophos;i="5.79,341,1602572400"; d="scan'208";a="165095488" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 01:34:48 -0800 IronPort-SDR: F+QHxLFNOOiU2I7WoXCiKIDJj6S1wHU/yGPTRdWIb32AROKUSDXxZnOHt8KVKHCCGYMkr7zU2f ZIsgw8hhmZsQ== X-IronPort-AV: E=Sophos;i="5.79,341,1602572400"; d="scan'208";a="400110663" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 01:34:47 -0800 Subject: [PATCH v2 2/5] mm: Teach pfn_to_online_page() to consider subsection validity From: Dan Williams To: linux-mm@kvack.org Cc: Qian Cai , Michal Hocko , David Hildenbrand , vishal.l.verma@intel.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jan 2021 01:34:47 -0800 Message-ID: <161044408728.1482714.9086710868634042303.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161044407603.1482714.16630477578392768273.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161044407603.1482714.16630477578392768273.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 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: pfn_section_valid() determines pfn validity on subsection granularity. pfn_valid_within() internally uses pfn_section_valid(), but gates it with early_section() to preserve the traditional behavior of pfn_valid() before subsection support was added. pfn_to_online_page() wants the explicit precision that pfn_valid() does not offer, so use pfn_section_valid() directly. Since pfn_to_online_page() already open codes the validity of the section number vs NR_MEM_SECTIONS, there's not much value to using pfn_valid_within(), just use pfn_section_valid(). This loses the valid_section() check that pfn_valid_within() was performing, but that was already redundant with the online check. Fixes: b13bc35193d9 ("mm/hotplug: invalid PFNs from pfn_to_online_page()") Cc: Qian Cai Cc: Michal Hocko Reported-by: David Hildenbrand --- mm/memory_hotplug.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 55a69d4396e7..a845b3979bc0 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -308,11 +308,19 @@ static int check_hotplug_memory_addressable(unsigned long pfn, struct page *pfn_to_online_page(unsigned long pfn) { unsigned long nr = pfn_to_section_nr(pfn); + struct mem_section *ms; + + if (nr >= NR_MEM_SECTIONS) + return NULL; + + ms = __nr_to_section(nr); + if (!online_section(ms)) + return NULL; + + if (!pfn_section_valid(ms, pfn)) + return NULL; - if (nr < NR_MEM_SECTIONS && online_section_nr(nr) && - pfn_valid_within(pfn)) - return pfn_to_page(pfn); - return NULL; + return pfn_to_page(pfn); } EXPORT_SYMBOL_GPL(pfn_to_online_page);