Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp833865pxb; Wed, 13 Jan 2021 17:49:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJych3byIGWZqP5sZ5P88vNJG+/MM/Q5BLhSsDHTcQjqSEHg4fg0g///3taOGXfiSExPLbne X-Received: by 2002:aa7:d0d4:: with SMTP id u20mr1906919edo.203.1610588948073; Wed, 13 Jan 2021 17:49:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610588948; cv=none; d=google.com; s=arc-20160816; b=Jsvpbr5SVfzWc6cd/NJ1DX9hxD5n27kGSpS8s6J3OBKpWiV+Qj0Jfx0xP0GRZXRl05 6NC2FgkLZFnto04Atu1SXLVkX6AoWuai07kfVPx8K6wEkRs44E9xX9yhgQ9St4RPG/Dc qWMyYEafbH6mkBzQOybYFnQsRB9eHdFtOhQIEUxC3J+p9ii10UcUWpYDMFpoOqlhhpkR nDS+gvF4K8M3TXRBx8NsPyxOrdhYIr7auH1LSfkF6ZyRqXHlsPJjiqB5tP51sGxCgYJj /cN4f1gMSR40L2IK/ovpQQyZ8W6Bd6QXsBN3uSv6wiCDq4nsLnSP1iR7gwNqZRdmBFZr cUag== 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=kCjwKL//m0Qk4SxmZHfeN2vZ9SsG2c/PIzypixKv9jw=; b=nj19pRvh5e+7c5yncAHh7KK4sFnuT0EC/frsUaZsSIWbKvpb4D85Qpgxm9MfRZXqBE j3E+AHsvZKsoORS5P66uxIj1TMfp6tfHZVeWMJ1I6IsqsET56RFwjwcK2QR7fDpGwa1G +FHImY5SwGBNzofGiAfeh1z8vq/P6A3p9HssOXnhPtl27AtMAVMrKVwrmBhtA6fX/hnP PJsiYIOW9cgtM/mW/g/7FhgI/L2KsphfOZzqeGWHU2jL1IyByGeyiDCCTKxkDhGJuvr1 tt8sSJlvNoxX+3gvYF4xfw9nZdNfpvUePuOPxCe0FfV88IU7OBetIubnxfp708ChX7E4 7M6g== 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 u14si1845890edo.600.2021.01.13.17.48.45; Wed, 13 Jan 2021 17:49:08 -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 S1728223AbhANBqx (ORCPT + 99 others); Wed, 13 Jan 2021 20:46:53 -0500 Received: from mga12.intel.com ([192.55.52.136]:65494 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbhANA4d (ORCPT ); Wed, 13 Jan 2021 19:56:33 -0500 IronPort-SDR: F3a9celQliSO1lFha5Zfbp6Ylc6DByay8bENunqwbZKhOxCLQLVPoGMW9tNMFGG8f2Lbuassx4 vLyeU/QK7iCw== X-IronPort-AV: E=McAfee;i="6000,8403,9863"; a="157470355" X-IronPort-AV: E=Sophos;i="5.79,345,1602572400"; d="scan'208";a="157470355" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2021 16:43:21 -0800 IronPort-SDR: 9Fkr+vtQiYNC6KHDg9P1BPiU9cebLEwQpH+qEGsboHEOeqGHMwn1rVIknyF06J25kU7XVFeJZt t66Bu++NFWuw== X-IronPort-AV: E=Sophos;i="5.79,345,1602572400"; d="scan'208";a="348995326" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2021 16:43:21 -0800 Subject: [PATCH v4 2/5] mm: Teach pfn_to_online_page() to consider subsection validity From: Dan Williams To: akpm@linux-foundation.org Cc: Qian Cai , Michal Hocko , Oscar Salvador , David Hildenbrand , David Hildenbrand , Oscar Salvador , linux-mm@kvack.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Wed, 13 Jan 2021 16:43:21 -0800 Message-ID: <161058500148.1840162.4365921007820501696.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161058499000.1840162.702316708443239771.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161058499000.1840162.702316708443239771.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 Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador Signed-off-by: Dan Williams --- mm/memory_hotplug.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 55a69d4396e7..d0c81f7a3347 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -308,11 +308,26 @@ 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) && !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);