From patchwork Thu Feb 6 23:16:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11369383 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 16C58112B for ; Thu, 6 Feb 2020 23:17:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD69F217BA for ; Thu, 6 Feb 2020 23:17:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD69F217BA 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 83F806B0006; Thu, 6 Feb 2020 18:17:37 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7EFB26B0007; Thu, 6 Feb 2020 18:17:37 -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 706546B0008; Thu, 6 Feb 2020 18:17:37 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 572BA6B0006 for ; Thu, 6 Feb 2020 18:17:37 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0B6613ABE for ; Thu, 6 Feb 2020 23:17:37 +0000 (UTC) X-FDA: 76461266154.24.shame87_830c97a1d445 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:29,LUA_SUMMARY:none X-HE-Tag: shame87_830c97a1d445 X-Filterd-Recvd-Size: 2381 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 23:17:36 +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:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,411,1574150400"; d="scan'208";a="232200537" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga003.jf.intel.com with ESMTP; 06 Feb 2020 15:17:32 -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 1/3] mm/sparsemem: adjust memmap only for SPARSEMEM_VMEMMAP Date: Fri, 7 Feb 2020 07:16:27 +0800 Message-Id: <20200206231629.14151-2-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: Only when SPARSEMEM_VMEMMAP is set, memmap returned from section_activate() points to sub-section page struct. Otherwise, memmap already points to the whole section page struct. This means only for SPARSEMEM_VMEMMAP, we need to adjust memmap for sub-section case. Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") Signed-off-by: Wei Yang CC: Dan Williams --- mm/sparse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/sparse.c b/mm/sparse.c index 586d85662978..b5da121bdd6e 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -886,7 +886,8 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn, section_mark_present(ms); /* Align memmap to section boundary in the subsection case */ - if (section_nr_to_pfn(section_nr) != start_pfn) + if (IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) && + section_nr_to_pfn(section_nr) != start_pfn) memmap = pfn_to_kaddr(section_nr_to_pfn(section_nr)); sparse_init_one_section(ms, section_nr, memmap, ms->usage, 0); From patchwork Thu Feb 6 23:16:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11369387 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 22DB3112B for ; Thu, 6 Feb 2020 23:18:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 07749214AF for ; Thu, 6 Feb 2020 23:18:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07749214AF 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 F1C2F6B0006; Thu, 6 Feb 2020 18:18:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ECD856B0008; Thu, 6 Feb 2020 18:18:42 -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 DE6EB6B000A; Thu, 6 Feb 2020 18:18:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id BD0896B0006 for ; Thu, 6 Feb 2020 18:18:42 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6842D180AD801 for ; Thu, 6 Feb 2020 23:18:42 +0000 (UTC) X-FDA: 76461268884.17.bee14_11b44e5415a50 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:30003: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:25,LUA_SUMMARY:none X-HE-Tag: bee14_11b44e5415a50 X-Filterd-Recvd-Size: 2303 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 23:18:41 +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:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,411,1574150400"; d="scan'208";a="232200544" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga003.jf.intel.com with ESMTP; 06 Feb 2020 15:17:35 -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 2/3] mm/sparsemem: get physical address to page struct instead of virtual address to pfn Date: Fri, 7 Feb 2020 07:16:28 +0800 Message-Id: <20200206231629.14151-3-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: memmap should be the physical address to page struct instead of virtual address to pfn. Since we call this only for SPARSEMEM_VMEMMAP, pfn_to_page() is valid at this point. Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") Signed-off-by: Wei Yang CC: Dan Williams --- mm/sparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/sparse.c b/mm/sparse.c index b5da121bdd6e..56816f653588 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -888,7 +888,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn, /* Align memmap to section boundary in the subsection case */ if (IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP) && section_nr_to_pfn(section_nr) != start_pfn) - memmap = pfn_to_kaddr(section_nr_to_pfn(section_nr)); + memmap = pfn_to_page(section_nr_to_pfn(section_nr)); sparse_init_one_section(ms, section_nr, memmap, ms->usage, 0); return 0; 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);