Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3020165pxb; Tue, 12 Jan 2021 04:30:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpzDoPv+sd+olBfR0jmcgB7qyTTC6/kTqmM33NNTV8VIHI8XTqkTot20lVYTqNviGKSxY2 X-Received: by 2002:a05:6402:1d15:: with SMTP id dg21mr3205982edb.280.1610454657160; Tue, 12 Jan 2021 04:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610454657; cv=none; d=google.com; s=arc-20160816; b=agS2/KE8UWZKXkhLJxqEzmcTsFrVnCzu1mPBNuwp3gsBDnmJgUcvXREQRrqxbuEhGY RL01bHMh5136ph/kh0PuUUi9y2a/Rq2b7GnJEJmeaFTMGtrLQ1xvGDJ8ICFtkCvysLRY zi4cV/wkmkQ4vtzq5gtbzbNIOLxcNhOplZwWjqJx3mY093wud1qh6G65fPAxSdqoUcjI JSHlh9HOaTryO60oYITnyvxiEfGMGTKa8aWM0U7J7EHF9UDd24NJSsO4C5Vd7JeNg5Ux yjnndkAO27Mkbr17jkOYuvp8T+yw9xOyK9XO5T4CXecJL1flTnJy0vEvdcCH1p0HIde2 3U8Q== 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=ceq/C7qoaokKfOxVHcL5AEIzCH3J+xg9pfxFxa2Ydx4=; b=GIKfv2WTmXYFdO5J8u+UnI0At5E2fSmn5ER0yT9eoXA9btyMtVrXqv+qYw/0noqtWG Cgl1oeEAdVQiuOQ2R0NmX/BizI/ERpPtiYOpUL/rK+Jdmmm7r9g8mCi0G/dYsjXEGj7Z ZOYVMVJNKOctZdBZpQaGH0obdhAUHxU+oYyz+4FOyiTrGEDZXW0gmT8J1b6JgWW6yX3l mogVlp8JjklhR2sxalA3XfvHmRa5J8QT3HFYUudtnibYS79A72LKAWc7O70mv2/N2OMa qjm6pra1DucO0vVyzCtHDYf/YJ8jegOhRxBOGXghoL3hMW7/5AUyjDVlMf9ydMzSKqQV dUwg== 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 i8si1257446edr.271.2021.01.12.04.30.33; Tue, 12 Jan 2021 04:30:57 -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 S2392685AbhALJfa (ORCPT + 99 others); Tue, 12 Jan 2021 04:35:30 -0500 Received: from mga04.intel.com ([192.55.52.120]:27794 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392682AbhALJf3 (ORCPT ); Tue, 12 Jan 2021 04:35:29 -0500 IronPort-SDR: 8ahfpQxhPov/wvTUaKZQPfDDwmXuyKdE9Z3tetVHCERTM9UYe7C6Nn0BKKv/GZJwHmdZrRLDEL /UycvJYeNynQ== X-IronPort-AV: E=McAfee;i="6000,8403,9861"; a="175431841" X-IronPort-AV: E=Sophos;i="5.79,341,1602572400"; d="scan'208";a="175431841" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 01:34:47 -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 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. 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);