Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp157624pxb; Tue, 12 Jan 2021 23:38:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvLgO4vKglX4Vj3Ff+CQKaR6HLcvGzFPbrvaKFkmq5GR2EMMymAjbJQtTLucqgWp9uQNcT X-Received: by 2002:a17:906:cb86:: with SMTP id mf6mr615081ejb.57.1610523492044; Tue, 12 Jan 2021 23:38:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610523492; cv=none; d=google.com; s=arc-20160816; b=nslBwssKZYUSg4x1NkP/PnjU4MQZRlCbZ4VTl7/rK1oitqRWmJmxVel5sejBgxtNeL 62zFB8+C9S/uzQms7NDOOuDpDJUZrHVRLDfPyIjGv7C6H0ppymNjK6swu8T4WchLWOSd /rMGfeEuiNShbBj2L5duMm76lPurcUTUOeSNU9SImAOfqSnE2PHP2j/dRZiAni2Fiyv/ 6RJmAjQadDPhhaqM0rzKV73IhCpA7OmjCJ5Kr9fQSRN8ErM1Ibh263+u8il30zZkJiL/ qkkQslVGMeMWTHqHpSbT4XfLfnvH4VWRS7i73heaydrlrpfk+8KABnJ38hnSdcqy74C/ IEkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=sKBtfharZF2BlYetmqWS3fI5ffli3qhmE3iv0HH9sLw=; b=M7vnA4pJ2ljlblaSGqCj9pFd5trFmpBwrxJCqkgWgZLLAV15eOb2ijR5HM2B0X/nvO bHDPsmHHe+ZSiN06WioinZqtPmPvPf5p7xTUgUTPv6mf0HWWvIIz9PjyHLJx443ZunXV hNGcEmDy6W47SFuGH+5vCT/GRhKRzf0rUCe519PcRfFdlEUTHtfvmBxhDQ5XQ4QAyYuU LqpK8RZtKnGMYKfjoen/s3Cji4ocfkUqSxh1NTsuOBICdYoTP2zsb/vidMsiq/zF0p6T hs5AlSQpNsffjCSm8KxRUf+pxmrwZtbKwfuVHLu2MYrAaJ1ivx59u2GJxe1zpD92iozA vSXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e13si628999edz.214.2021.01.12.23.37.48; Tue, 12 Jan 2021 23:38:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726463AbhAMHgK (ORCPT + 99 others); Wed, 13 Jan 2021 02:36:10 -0500 Received: from mga01.intel.com ([192.55.52.88]:51012 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbhAMHgJ (ORCPT ); Wed, 13 Jan 2021 02:36:09 -0500 IronPort-SDR: 46t7xAEYRZoO9WmE0Lh1UYss4wjTx5MatGrMspAM5k71O7li0mNfvgzjPBUTHAtinMFY9gBicW I0PsQkVxySgQ== X-IronPort-AV: E=McAfee;i="6000,8403,9862"; a="196799236" X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="196799236" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:28 -0800 IronPort-SDR: TxaCVHWg9sHbgbbnmaJoX83Ad9yllXRKmlOa04N3hMfRvtzA0XjaxcTjtdpq8+VY66nf+DHuVm hoYIkt//vKDw== X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="397639445" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:28 -0800 Subject: [PATCH v3 2/6] mm: Teach pfn_to_online_page() to consider subsection validity From: Dan Williams To: linux-mm@kvack.org Cc: Qian Cai , Michal Hocko , Oscar Salvador , David Hildenbrand , vishal.l.verma@intel.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jan 2021 23:35:27 -0800 Message-ID: <161052332755.1805594.9846390935351758277.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161052331545.1805594.2356512831689786960.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161052331545.1805594.2356512831689786960.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pfn_section_valid() determines pfn validity on subsection granularity where pfn_valid() may be limited to coarse section granularity. Explicitly validate subsections after pfn_valid() succeeds. Fixes: b13bc35193d9 ("mm/hotplug: invalid PFNs from pfn_to_online_page()") Cc: Qian Cai Cc: Michal Hocko Cc: Oscar Salvador Reported-by: David Hildenbrand Signed-off-by: Dan Williams --- mm/memory_hotplug.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 55a69d4396e7..9f37f8a68da4 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -308,11 +308,27 @@ 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; + + /* + * Save some code text when online_section() + + * pfn_section_valid() are sufficient. + */ + if (IS_ENABLED(CONFIG_HAVE_ARCH_PFN_VALID)) + if (!pfn_valid(pfn)) + 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);