From patchwork Thu Feb 6 23:16:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11369385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A821F138D for ; Thu, 6 Feb 2020 23:17:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F10921775 for ; Thu, 6 Feb 2020 23:17:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F10921775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9023A6B0007; Thu, 6 Feb 2020 18:17:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8B3516B0008; Thu, 6 Feb 2020 18:17:43 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F0BE6B000A; Thu, 6 Feb 2020 18:17:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 69D9C6B0007 for ; Thu, 6 Feb 2020 18:17:43 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 04A2A2C18 for ; Thu, 6 Feb 2020 23:17:43 +0000 (UTC) X-FDA: 76461266406.15.class60_915f42c6d355 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,richardw.yang@linux.intel.com,:akpm@linux-foundation.org:osalvador@suse.de:dan.j.williams@intel.com::linux-kernel@vger.kernel.org:bhe@redhat.com:david@redhat.com:richardw.yang@linux.intel.com,RULES_HIT:30054:30064,0,RBL:192.55.52.151:@linux.intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: class60_915f42c6d355 X-Filterd-Recvd-Size: 2579 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 23:17:42 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 15:17:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,411,1574150400"; d="scan'208";a="232200556" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga003.jf.intel.com with ESMTP; 06 Feb 2020 15:17:38 -0800 From: Wei Yang To: akpm@linux-foundation.org, osalvador@suse.de, dan.j.williams@intel.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, bhe@redhat.com, david@redhat.com, Wei Yang Subject: [PATCH 3/3] mm/sparsemem: avoid memmap overwrite for non-SPARSEMEM_VMEMMAP Date: Fri, 7 Feb 2020 07:16:29 +0800 Message-Id: <20200206231629.14151-4-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200206231629.14151-1-richardw.yang@linux.intel.com> References: <20200206231629.14151-1-richardw.yang@linux.intel.com> 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: In case of SPARSEMEM, populate_section_memmap() would allocate memmap for the whole section, even we just want a sub-section. This would lead to memmap overwrite if we a sub-section to an already populated section. Just return the populated memmap for non-SPARSEMEM_VMEMMAP case. Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") Signed-off-by: Wei Yang CC: Dan Williams --- mm/sparse.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/sparse.c b/mm/sparse.c index 56816f653588..c75ca40db513 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -836,6 +836,16 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, if (nr_pages < PAGES_PER_SECTION && early_section(ms)) return pfn_to_page(pfn); + /* + * If it is not SPARSEMEM_VMEMMAP, we always populate memmap for the + * whole section, even for a sub-section. + * + * Return its memmap if already populated to avoid memmap overwrite. + */ + if (!IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) && + valid_section(ms)) + return __section_mem_map_addr(ms); + memmap = populate_section_memmap(pfn, nr_pages, nid, altmap); if (!memmap) { section_deactivate(pfn, nr_pages, altmap);