From patchwork Sun Feb 9 10:48:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372051 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 3809513A4 for ; Sun, 9 Feb 2020 10:48:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF9122080C for ; Sun, 9 Feb 2020 10:48:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jCTwpBB0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF9122080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DF8006B000A; Sun, 9 Feb 2020 05:48:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D81426B000C; Sun, 9 Feb 2020 05:48:44 -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 BAB5C6B000D; Sun, 9 Feb 2020 05:48:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 9EA856B000A for ; Sun, 9 Feb 2020 05:48:44 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4919121EA for ; Sun, 9 Feb 2020 10:48:44 +0000 (UTC) X-FDA: 76470265368.05.fire48_2f0eb4899762e X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.com,RULES_HIT:30012:30034:30054,0,RBL:207.211.31.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: fire48_2f0eb4899762e X-Filterd-Recvd-Size: 4506 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=mdBVxRpLdO0s6+uT+hO6BEgqaFn2MQXMmuMNW77AADU=; b=jCTwpBB0lbPQpo0LwiLLrGnwcwej4hVApfF+fCULWnTQFTaqm8K2TKW+EUie5bJy3ZexfP 8W5VXmOQQH7Q1iS8Di2iU4QpjcrQSfnq2BXHlR6u+7vHraZK2puq4AO+vG627P/CKd5o51 nxLdNIcfCBHdh0kNCxmUOdANraLeA+o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-QKsqChD3ODO-MNUh75hE4A-1; Sun, 09 Feb 2020 05:48:37 -0500 X-MC-Unique: QKsqChD3ODO-MNUh75hE4A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D09613E5; Sun, 9 Feb 2020 10:48:36 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id A40B610013A7; Sun, 9 Feb 2020 10:48:33 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 1/7] mm/sparse.c: Introduce new function fill_subsection_map() Date: Sun, 9 Feb 2020 18:48:20 +0800 Message-Id: <20200209104826.3385-2-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: Wrap the codes filling subsection map in section_activate() into fill_subsection_map(), this makes section_activate() cleaner and easier to follow. Signed-off-by: Baoquan He --- mm/sparse.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index c184b69460b7..9ad741ccbeb6 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -788,24 +788,28 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, depopulate_section_memmap(pfn, nr_pages, altmap); } -static struct page * __meminit section_activate(int nid, unsigned long pfn, - unsigned long nr_pages, struct vmem_altmap *altmap) +/** + * fill_subsection_map - fill subsection map of a memory region + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This clears the related subsection map inside one section, and only + * intended for hotplug. + * + * Return: + * * 0 - On success. + * * -EINVAL - Invalid memory region. + * * -EEXIST - Subsection map has been set. + */ +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) { - DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; struct mem_section *ms = __pfn_to_section(pfn); - struct mem_section_usage *usage = NULL; + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; unsigned long *subsection_map; - struct page *memmap; int rc = 0; subsection_mask_set(map, pfn, nr_pages); - if (!ms->usage) { - usage = kzalloc(mem_section_usage_size(), GFP_KERNEL); - if (!usage) - return ERR_PTR(-ENOMEM); - ms->usage = usage; - } subsection_map = &ms->usage->subsection_map[0]; if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) @@ -816,6 +820,25 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, bitmap_or(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); + return rc; +} + +static struct page * __meminit section_activate(int nid, unsigned long pfn, + unsigned long nr_pages, struct vmem_altmap *altmap) +{ + struct mem_section *ms = __pfn_to_section(pfn); + struct mem_section_usage *usage = NULL; + struct page *memmap; + int rc = 0; + + if (!ms->usage) { + usage = kzalloc(mem_section_usage_size(), GFP_KERNEL); + if (!usage) + return ERR_PTR(-ENOMEM); + ms->usage = usage; + } + + rc = fill_subsection_map(pfn, nr_pages); if (rc) { if (usage) ms->usage = NULL; From patchwork Sun Feb 9 10:48:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372049 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 0413213A4 for ; Sun, 9 Feb 2020 10:48:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C4F082080C for ; Sun, 9 Feb 2020 10:48:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OTnH8P62" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4F082080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E44746B0008; Sun, 9 Feb 2020 05:48:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DF5856B000A; Sun, 9 Feb 2020 05:48: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 CE3046B000C; Sun, 9 Feb 2020 05:48:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id B3CBB6B0008 for ; Sun, 9 Feb 2020 05:48:43 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 54295181AC9CC for ; Sun, 9 Feb 2020 10:48:43 +0000 (UTC) X-FDA: 76470265326.13.bite27_2efeeec6d090c X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,,RULES_HIT:30012:30034:30054,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: bite27_2efeeec6d090c X-Filterd-Recvd-Size: 4758 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=DsolEyvsq2X/4Ojh8CIm2FaqZo6yUXk19oty1TTx+uA=; b=OTnH8P62+f0q9hv1T3aE5feHHm5T9t5GDPAp+B6XCP/Vr4ght12cWvZQKl8dNyJEh5zS2e AAR0ZgxHWKwq8yHCSgR6H6AUlgHopfSZCUva7WPaTTVxIf1y4uInXMwbUeSa+bQrN9y9L4 t/c0/lmN9kMGZRX2xWnReo2+G0VR7iU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-296-BC8TcIIyM92RShLolccTZA-1; Sun, 09 Feb 2020 05:48:40 -0500 X-MC-Unique: BC8TcIIyM92RShLolccTZA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60B0013F7; Sun, 9 Feb 2020 10:48:39 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD3A310013A7; Sun, 9 Feb 2020 10:48:36 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 2/7] mm/sparse.c: Introduce a new function clear_subsection_map() Date: Sun, 9 Feb 2020 18:48:21 +0800 Message-Id: <20200209104826.3385-3-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: Wrap the codes clearing subsection map of one memory region in section_deactivate() into clear_subsection_map(). Signed-off-by: Baoquan He --- mm/sparse.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 9ad741ccbeb6..696f6b9f706e 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -726,14 +726,25 @@ static void free_map_bootmem(struct page *memmap) } #endif /* CONFIG_SPARSEMEM_VMEMMAP */ -static void section_deactivate(unsigned long pfn, unsigned long nr_pages, - struct vmem_altmap *altmap) +/** + * clear_subsection_map - Clear subsection map of one memory region + * + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This is only intended for hotplug, and clear the related subsection + * map inside one section. + * + * Return: + * * -EINVAL - Section already deactived. + * * 0 - Subsection map is emptied. + * * 1 - Subsection map is not empty. + */ +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) { DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 }; struct mem_section *ms = __pfn_to_section(pfn); - bool section_is_early = early_section(ms); - struct page *memmap = NULL; unsigned long *subsection_map = ms->usage ? &ms->usage->subsection_map[0] : NULL; @@ -744,8 +755,28 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION), "section already deactivated (%#lx + %ld)\n", pfn, nr_pages)) - return; + return -EINVAL; + + bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); + if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) + return 0; + + return 1; +} + +static void section_deactivate(unsigned long pfn, unsigned long nr_pages, + struct vmem_altmap *altmap) +{ + struct mem_section *ms = __pfn_to_section(pfn); + bool section_is_early = early_section(ms); + struct page *memmap = NULL; + int rc; + + + rc = clear_subsection_map(pfn, nr_pages); + if(IS_ERR_VALUE((unsigned long)rc)) + return; /* * There are 3 cases to handle across two configurations * (SPARSEMEM_VMEMMAP={y,n}): @@ -763,8 +794,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, * * For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified */ - bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); - if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) { + if (!rc) { unsigned long section_nr = pfn_to_section_nr(pfn); /* From patchwork Sun Feb 9 10:48:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372053 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 72CC6109A for ; Sun, 9 Feb 2020 10:48:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 24D9920820 for ; Sun, 9 Feb 2020 10:48:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Aq7USx2R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24D9920820 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 236956B000C; Sun, 9 Feb 2020 05:48:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1E7CE6B000D; Sun, 9 Feb 2020 05:48:50 -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 0FE536B000E; Sun, 9 Feb 2020 05:48:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id ED66D6B000C for ; Sun, 9 Feb 2020 05:48:49 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 91E4F2C2E for ; Sun, 9 Feb 2020 10:48:49 +0000 (UTC) X-FDA: 76470265578.05.fight42_2fe46c031700a X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.com,RULES_HIT:30012:30034:30054:30056,0,RBL:207.211.31.81:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:83,LUA_SUMMARY:none X-HE-Tag: fight42_2fe46c031700a X-Filterd-Recvd-Size: 11159 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:48:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245328; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=BjmlLwbM15Iw1XaV2XX7Yb6G5vXJWaDZ45CriLnjpJE=; b=Aq7USx2RjBzBUFpiXxu63Z1N3SAveT/9FkP5h+ibfF6P/1qNvt7+yd9g5slBblPvzETov6 +4F2ydqWii48S/cIpptmTACCOpj/an8zlQVGYuOcFw4HQLDrj8mf7Q2zuGcDK1WnN3W5es 91GScDTjS362aMVrzILxqXQIoBLXJdQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-_cTvP-uWOhuV4nE6QFv07w-1; Sun, 09 Feb 2020 05:48:44 -0500 X-MC-Unique: _cTvP-uWOhuV4nE6QFv07w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B37988017CC; Sun, 9 Feb 2020 10:48:42 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDB8E10013A7; Sun, 9 Feb 2020 10:48:39 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 3/7] mm/sparse.c: only use subsection map in VMEMMAP case Date: Sun, 9 Feb 2020 18:48:22 +0800 Message-Id: <20200209104826.3385-4-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: Currently, subsection map is used when SPARSEMEM is enabled, including VMEMMAP case and !VMEMMAP case. However, subsection hotplug is not supported at all in SPARSEMEM|!VMEMMAP case, subsection map is unnecessary and misleading. Let's adjust code to only allow subsection map being used in SPARSEMEM|VMEMMAP case. Signed-off-by: Baoquan He Reviewed-by: Wei Yang --- include/linux/mmzone.h | 2 + mm/sparse.c | 231 ++++++++++++++++++++++------------------- 2 files changed, 124 insertions(+), 109 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 462f6873905a..fc0de3a9a51e 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1185,7 +1185,9 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec) #define SUBSECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SUBSECTION_MASK) struct mem_section_usage { +#ifdef CONFIG_SPARSEMEM_VMEMMAP DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION); +#endif /* See declaration of similar field in struct zone */ unsigned long pageblock_flags[0]; }; diff --git a/mm/sparse.c b/mm/sparse.c index 696f6b9f706e..cf55d272d0a9 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -209,41 +209,6 @@ static inline unsigned long first_present_section_nr(void) return next_present_section_nr(-1); } -static void subsection_mask_set(unsigned long *map, unsigned long pfn, - unsigned long nr_pages) -{ - int idx = subsection_map_index(pfn); - int end = subsection_map_index(pfn + nr_pages - 1); - - bitmap_set(map, idx, end - idx + 1); -} - -void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) -{ - int end_sec = pfn_to_section_nr(pfn + nr_pages - 1); - unsigned long nr, start_sec = pfn_to_section_nr(pfn); - - if (!nr_pages) - return; - - for (nr = start_sec; nr <= end_sec; nr++) { - struct mem_section *ms; - unsigned long pfns; - - pfns = min(nr_pages, PAGES_PER_SECTION - - (pfn & ~PAGE_SECTION_MASK)); - ms = __nr_to_section(nr); - subsection_mask_set(ms->usage->subsection_map, pfn, pfns); - - pr_debug("%s: sec: %lu pfns: %lu set(%d, %d)\n", __func__, nr, - pfns, subsection_map_index(pfn), - subsection_map_index(pfn + pfns - 1)); - - pfn += pfns; - nr_pages -= pfns; - } -} - /* Record a memory area against a node. */ void __init memory_present(int nid, unsigned long start, unsigned long end) { @@ -432,12 +397,134 @@ static unsigned long __init section_map_size(void) return ALIGN(sizeof(struct page) * PAGES_PER_SECTION, PMD_SIZE); } +static void subsection_mask_set(unsigned long *map, unsigned long pfn, + unsigned long nr_pages) +{ + int idx = subsection_map_index(pfn); + int end = subsection_map_index(pfn + nr_pages - 1); + + bitmap_set(map, idx, end - idx + 1); +} + +void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) +{ + int end_sec = pfn_to_section_nr(pfn + nr_pages - 1); + unsigned long nr, start_sec = pfn_to_section_nr(pfn); + + if (!nr_pages) + return; + + for (nr = start_sec; nr <= end_sec; nr++) { + struct mem_section *ms; + unsigned long pfns; + + pfns = min(nr_pages, PAGES_PER_SECTION + - (pfn & ~PAGE_SECTION_MASK)); + ms = __nr_to_section(nr); + subsection_mask_set(ms->usage->subsection_map, pfn, pfns); + + pr_debug("%s: sec: %lu pfns: %lu set(%d, %d)\n", __func__, nr, + pfns, subsection_map_index(pfn), + subsection_map_index(pfn + pfns - 1)); + + pfn += pfns; + nr_pages -= pfns; + } +} + +/** + * clear_subsection_map - Clear subsection map of one memory region + * + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This is only intended for hotplug, and clear the related subsection + * map inside one section. + * + * Return: + * * -EINVAL - Section already deactived. + * * 0 - Subsection map is emptied. + * * 1 - Subsection map is not empty. + */ +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; + DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 }; + struct mem_section *ms = __pfn_to_section(pfn); + unsigned long *subsection_map = ms->usage + ? &ms->usage->subsection_map[0] : NULL; + + subsection_mask_set(map, pfn, nr_pages); + if (subsection_map) + bitmap_and(tmp, map, subsection_map, SUBSECTIONS_PER_SECTION); + + if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION), + "section already deactivated (%#lx + %ld)\n", + pfn, nr_pages)) + return -EINVAL; + + bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); + + if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) + return 0; + + return 1; +} + +/** + * fill_subsection_map - fill subsection map of a memory region + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This clears the related subsection map inside one section, and only + * intended for hotplug. + * + * Return: + * * 0 - On success. + * * -EINVAL - Invalid memory region. + * * -EEXIST - Subsection map has been set. + */ +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + struct mem_section *ms = __pfn_to_section(pfn); + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; + unsigned long *subsection_map; + int rc = 0; + + subsection_mask_set(map, pfn, nr_pages); + + subsection_map = &ms->usage->subsection_map[0]; + + if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) + rc = -EINVAL; + else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION)) + rc = -EEXIST; + else + bitmap_or(subsection_map, map, subsection_map, + SUBSECTIONS_PER_SECTION); + + return rc; +} + #else static unsigned long __init section_map_size(void) { return PAGE_ALIGN(sizeof(struct page) * PAGES_PER_SECTION); } +void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) +{ +} + +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + return 0; +} +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + return 0; +} + struct page __init *__populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap) { @@ -726,45 +813,6 @@ static void free_map_bootmem(struct page *memmap) } #endif /* CONFIG_SPARSEMEM_VMEMMAP */ -/** - * clear_subsection_map - Clear subsection map of one memory region - * - * @pfn - start pfn of the memory range - * @nr_pages - number of pfns to add in the region - * - * This is only intended for hotplug, and clear the related subsection - * map inside one section. - * - * Return: - * * -EINVAL - Section already deactived. - * * 0 - Subsection map is emptied. - * * 1 - Subsection map is not empty. - */ -static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) -{ - DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; - DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 }; - struct mem_section *ms = __pfn_to_section(pfn); - unsigned long *subsection_map = ms->usage - ? &ms->usage->subsection_map[0] : NULL; - - subsection_mask_set(map, pfn, nr_pages); - if (subsection_map) - bitmap_and(tmp, map, subsection_map, SUBSECTIONS_PER_SECTION); - - if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION), - "section already deactivated (%#lx + %ld)\n", - pfn, nr_pages)) - return -EINVAL; - - bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); - - if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) - return 0; - - return 1; -} - static void section_deactivate(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { @@ -818,41 +866,6 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, depopulate_section_memmap(pfn, nr_pages, altmap); } -/** - * fill_subsection_map - fill subsection map of a memory region - * @pfn - start pfn of the memory range - * @nr_pages - number of pfns to add in the region - * - * This clears the related subsection map inside one section, and only - * intended for hotplug. - * - * Return: - * * 0 - On success. - * * -EINVAL - Invalid memory region. - * * -EEXIST - Subsection map has been set. - */ -static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) -{ - struct mem_section *ms = __pfn_to_section(pfn); - DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; - unsigned long *subsection_map; - int rc = 0; - - subsection_mask_set(map, pfn, nr_pages); - - subsection_map = &ms->usage->subsection_map[0]; - - if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) - rc = -EINVAL; - else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION)) - rc = -EEXIST; - else - bitmap_or(subsection_map, map, subsection_map, - SUBSECTIONS_PER_SECTION); - - return rc; -} - static struct page * __meminit section_activate(int nid, unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { From patchwork Sun Feb 9 10:48:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372055 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 DD6C9109A for ; Sun, 9 Feb 2020 10:48:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A906920820 for ; Sun, 9 Feb 2020 10:48:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TVrHNgho" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A906920820 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8779F6B000D; Sun, 9 Feb 2020 05:48:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 828A76B000E; Sun, 9 Feb 2020 05:48:52 -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 7171D6B0010; Sun, 9 Feb 2020 05:48:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id 5AFF56B000D for ; Sun, 9 Feb 2020 05:48:52 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 14AE2181AC9CC for ; Sun, 9 Feb 2020 10:48:52 +0000 (UTC) X-FDA: 76470265704.14.limit25_30493e71a8822 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.com,RULES_HIT:30012:30054,0,RBL:207.211.31.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: limit25_30493e71a8822 X-Filterd-Recvd-Size: 3159 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=cyQkz0IDAp8YMg8SL+7hb0Hu6kCeVjMVDG1Pwv2+n44=; b=TVrHNgho0lBqyVSHupWkRQPm0jZTOIgp9PqUB8/0oK7Ezy3Vb9UBU6qnvAXvFZh+0mlnKt Y/SLbtOjkjMbYshcxWhlwhBPJHBAg4Yw0TIiCyyu8HPeayVZX7MJYeI3Q7ik34x6aCOmmm zIDGPRaYg3Y/dCsDDc4jzrj/KGhURb0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-nuHf9OQHP6e8st3LnJLrKw-1; Sun, 09 Feb 2020 05:48:47 -0500 X-MC-Unique: nuHf9OQHP6e8st3LnJLrKw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE4A6107ACC4; Sun, 9 Feb 2020 10:48:45 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E54510013A7; Sun, 9 Feb 2020 10:48:42 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 4/7] mm/sparse.c: Use __get_free_pages() instead in populate_section_memmap() Date: Sun, 9 Feb 2020 18:48:23 +0800 Message-Id: <20200209104826.3385-5-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: This removes the unnecessary goto, and simplify codes. Signed-off-by: Baoquan He Reviewed-by: Wei Yang --- mm/sparse.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index cf55d272d0a9..36e6565ec67e 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -751,23 +751,19 @@ static void free_map_bootmem(struct page *memmap) struct page * __meminit populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap) { - struct page *page, *ret; + struct page *ret; unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION; - page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size)); - if (page) - goto got_map_page; + ret = (void*)__get_free_pages(GFP_KERNEL|__GFP_NOWARN, + get_order(memmap_size)); + if (ret) + return ret; ret = vmalloc(memmap_size); if (ret) - goto got_map_ptr; + return ret; return NULL; -got_map_page: - ret = (struct page *)pfn_to_kaddr(page_to_pfn(page)); -got_map_ptr: - - return ret; } static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, From patchwork Sun Feb 9 10:48:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372057 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 4584117EF for ; Sun, 9 Feb 2020 10:48:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12C622080C for ; Sun, 9 Feb 2020 10:48:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GQTHfOwy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12C622080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C48BB6B000E; Sun, 9 Feb 2020 05:48:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BD3C66B0010; Sun, 9 Feb 2020 05:48:53 -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 A9BCD6B0032; Sun, 9 Feb 2020 05:48:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id 929146B000E for ; Sun, 9 Feb 2020 05:48:53 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 379F6180AD801 for ; Sun, 9 Feb 2020 10:48:53 +0000 (UTC) X-FDA: 76470265746.26.bag00_30713950b5d06 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.com,RULES_HIT:30012:30054:30070:30074,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: bag00_30713950b5d06 X-Filterd-Recvd-Size: 4842 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245332; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=avDH489Kezk0JZkoC0zLQWdCP4dLpS7AfZ6UHFu6JUE=; b=GQTHfOwyQsExVvI++eSRxFC5FQqB3pew4puO2w6fu8sXbdljk4//5SB0sJ7ToZiROHXTdt NgdKfhjs/C3Nvb9oJCymPiRxIhm5Owtqvz0yqInRHBNu0P91ulAXp6nKmPq9JYYOHddheM Uoafy0NxFFHmoRQ4escrxBsBumNI5dQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-Y1RO4sIjPpW_7FwABGULVA-1; Sun, 09 Feb 2020 05:48:50 -0500 X-MC-Unique: Y1RO4sIjPpW_7FwABGULVA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3618913E5; Sun, 9 Feb 2020 10:48:49 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A8E410013A7; Sun, 9 Feb 2020 10:48:46 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 5/7] mm/sparse.c: update code comment about section activate/deactivate Date: Sun, 9 Feb 2020 18:48:24 +0800 Message-Id: <20200209104826.3385-6-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: It's helpful to note that sub-section is only supported in SPARSEMEM_VMEMMAP case, but not in SPARSEMEM|!VMEMMAP case. Add sentences into the code comment above sparse_add_section. And move the code comments inside section_deactivate() to be above it, this makes code cleaner. Signed-off-by: Baoquan He --- mm/sparse.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 36e6565ec67e..a7e78bfe0dce 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -809,6 +809,23 @@ static void free_map_bootmem(struct page *memmap) } #endif /* CONFIG_SPARSEMEM_VMEMMAP */ +/* + * To deactivate a memory region, there are 3 cases across two + * two configurations (SPARSEMEM_VMEMMAP={y,n}): + * + * 1/ deactivation of a partial hot-added section (only possible + * in the SPARSEMEM_VMEMMAP=y case). + * a/ section was present at memory init + * b/ section was hot-added post memory init + * 2/ deactivation of a complete hot-added section + * 3/ deactivation of a complete section from memory init + * + * For 1/, when subsection_map does not empty we will not be + * freeing the usage map, but still need to free the vmemmap + * range. + * + * For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified + */ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { @@ -821,23 +838,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, rc = clear_subsection_map(pfn, nr_pages); if(IS_ERR_VALUE((unsigned long)rc)) return; - /* - * There are 3 cases to handle across two configurations - * (SPARSEMEM_VMEMMAP={y,n}): - * - * 1/ deactivation of a partial hot-added section (only possible - * in the SPARSEMEM_VMEMMAP=y case). - * a/ section was present at memory init - * b/ section was hot-added post memory init - * 2/ deactivation of a complete hot-added section - * 3/ deactivation of a complete section from memory init - * - * For 1/, when subsection_map does not empty we will not be - * freeing the usage map, but still need to free the vmemmap - * range. - * - * For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified - */ + if (!rc) { unsigned long section_nr = pfn_to_section_nr(pfn); @@ -913,6 +914,11 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, * * This is only intended for hotplug. * + * Note that the added memory region is either section aligned, or + * sub-section aligned. The sub-section aligned region can only be + * hot added in SPARSEMEM_VMEMMAP case, please refer to ZONE_DEVICE + * part of memory-model.rst for more details. + * * Return: * * 0 - On success. * * -EEXIST - Section has been present. From patchwork Sun Feb 9 10:48:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372059 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 D3A9713A4 for ; Sun, 9 Feb 2020 10:49:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9706520733 for ; Sun, 9 Feb 2020 10:49:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cmYCdzm3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9706520733 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CBE446B0010; Sun, 9 Feb 2020 05:49:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C46BF6B0032; Sun, 9 Feb 2020 05:49:03 -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 B5CFA6B0036; Sun, 9 Feb 2020 05:49:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 9D2E66B0010 for ; Sun, 9 Feb 2020 05:49:03 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 395A4180AD801 for ; Sun, 9 Feb 2020 10:49:03 +0000 (UTC) X-FDA: 76470266166.13.route71_31e5f6ab2831b X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.com,RULES_HIT:30029:30054:30056:30064,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: route71_31e5f6ab2831b X-Filterd-Recvd-Size: 3915 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=UrkcXvm7NMV0Re5AiF6mLhLz+8rfznTN3+Xg74sBVcE=; b=cmYCdzm3YbRiHp2ZSnKkor+xhMZmNdx3tU5rxQ5jdPy0496kkQC1f/WGf0KAvoxPVykR0j yMMZEfnjUIuD9t4aB/XNYRXNwn3Yl8bwB19R7SQSkaeS/afD1XiKLf7m8t2LQ0KLz/ABbJ P3P96nuvC8yepkYgwCvEGU/V2Llh+7w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-DwMZTUXjOn61rZpMJ1k2qQ-1; Sun, 09 Feb 2020 05:48:57 -0500 X-MC-Unique: DwMZTUXjOn61rZpMJ1k2qQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 27B441005510; Sun, 9 Feb 2020 10:48:56 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id C41ED10013A7; Sun, 9 Feb 2020 10:48:49 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 6/7] mm/sparsemem: pfn_to_page is not valid yet on SPARSEMEM Date: Sun, 9 Feb 2020 18:48:25 +0800 Message-Id: <20200209104826.3385-7-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: From: Wei Yang When we use SPARSEMEM instead of SPARSEMEM_VMEMMAP, pfn_to_page() doesn't work before sparse_init_one_section() is called. This leads to a crash when hotplug memory. PGD 0 P4D 0 Oops: 0002 [#1] SMP PTI CPU: 3 PID: 8 Comm: kworker/u16:0 Tainted: G W 5.5.0-next-20200205+ #339 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 Workqueue: kacpi_hotplug acpi_hotplug_work_fn RIP: 0010:__memset+0x24/0x30 Call Trace: sparse_add_section+0x150/0x1d8 __add_pages+0xbf/0x150 add_pages+0x12/0x60 add_memory_resource+0xc8/0x210 ? wake_up_q+0xa0/0xa0 __add_memory+0x62/0xb0 acpi_memory_device_add+0x13f/0x300 acpi_bus_attach+0xf6/0x200 acpi_bus_scan+0x43/0x90 acpi_device_hotplug+0x275/0x3d0 acpi_hotplug_work_fn+0x1a/0x30 process_one_work+0x1a7/0x370 worker_thread+0x30/0x380 ? flush_rcu_work+0x30/0x30 kthread+0x112/0x130 ? kthread_create_on_node+0x60/0x60 ret_from_fork+0x35/0x40 We should use memmap as it did. Fixes: ba72b4c8cf60 ("mm/sparsemem: support sub-section hotplug") Signed-off-by: Wei Yang Acked-by: David Hildenbrand Reviewed-by: Baoquan He CC: Dan Williams Signed-off-by: Baoquan He --- mm/sparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/sparse.c b/mm/sparse.c index a7e78bfe0dce..623755e88255 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -944,7 +944,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn, * Poison uninitialized struct pages in order to catch invalid flags * combinations. */ - page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages); + page_init_poison(memmap, sizeof(struct page) * nr_pages); ms = __nr_to_section(section_nr); set_section_nid(section_nr, nid); From patchwork Sun Feb 9 10:48:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372061 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 365F1109A for ; Sun, 9 Feb 2020 10:49:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE0DF2080C for ; Sun, 9 Feb 2020 10:49:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JCrrvn5W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE0DF2080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 14CC26B0032; Sun, 9 Feb 2020 05:49:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0FC826B0036; Sun, 9 Feb 2020 05:49:07 -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 011A36B0037; Sun, 9 Feb 2020 05:49:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id DC07F6B0032 for ; Sun, 9 Feb 2020 05:49:06 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8DEF38248047 for ; Sun, 9 Feb 2020 10:49:06 +0000 (UTC) X-FDA: 76470266292.04.grape42_3264d4b71d159 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.com,RULES_HIT:30029:30054:30056,0,RBL:207.211.31.81:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: grape42_3264d4b71d159 X-Filterd-Recvd-Size: 3802 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245345; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=z6n+AuP+O2svMC+qLOpajdzRjteK4YpkRxZlBgrn3yM=; b=JCrrvn5Wfq47/mk4yJUUIP04ep1hhvftSVkQLxjquJzJC/eyfnM/hcEyHD0IaabKsMnYnR 8+s2cnVPflRJFb45BoIeQNA741BTtU76nt8JDHTNeVhvRhKc8rG5Pwrj2BIRDjQJOaEcVS 4M/Fy2XY7RS9vsQNUcSd8FUrb8/8J/M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-6lR6WDWaM16ElUdnDR3Lyg-1; Sun, 09 Feb 2020 05:49:01 -0500 X-MC-Unique: 6lR6WDWaM16ElUdnDR3Lyg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E8BE184AEA0; Sun, 9 Feb 2020 10:49:00 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC73010013A7; Sun, 9 Feb 2020 10:48:56 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 7/7] mm/hotplug: fix hot remove failure in SPARSEMEM|!VMEMMAP case Date: Sun, 9 Feb 2020 18:48:26 +0800 Message-Id: <20200209104826.3385-8-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 section_deactivate(), pfn_to_page() doesn't work any more after ms->section_mem_map is resetting to NULL in SPARSEMEM|!VMEMMAP case. It caused hot remove failure, the trace is: kernel BUG at mm/page_alloc.c:4806! invalid opcode: 0000 [#1] SMP PTI CPU: 3 PID: 8 Comm: kworker/u16:0 Tainted: G W 5.5.0-next-20200205+ #340 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 Workqueue: kacpi_hotplug acpi_hotplug_work_fn RIP: 0010:free_pages+0x85/0xa0 Call Trace: __remove_pages+0x99/0xc0 arch_remove_memory+0x23/0x4d try_remove_memory+0xc8/0x130 ? walk_memory_blocks+0x72/0xa0 __remove_memory+0xa/0x11 acpi_memory_device_remove+0x72/0x100 acpi_bus_trim+0x55/0x90 acpi_device_hotplug+0x2eb/0x3d0 acpi_hotplug_work_fn+0x1a/0x30 process_one_work+0x1a7/0x370 worker_thread+0x30/0x380 ? flush_rcu_work+0x30/0x30 kthread+0x112/0x130 ? kthread_create_on_node+0x60/0x60 ret_from_fork+0x35/0x40 Let's defer the ->section_mem_map resetting after depopulate_section_memmap() to fix it. Signed-off-by: Baoquan He --- mm/sparse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/sparse.c b/mm/sparse.c index 623755e88255..345d065ef6ce 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -854,13 +854,15 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, ms->usage = NULL; } memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); - ms->section_mem_map = (unsigned long)NULL; } if (section_is_early && memmap) free_map_bootmem(memmap); else depopulate_section_memmap(pfn, nr_pages, altmap); + + if(!rc) + ms->section_mem_map = (unsigned long)NULL; } static struct page * __meminit section_activate(int nid, unsigned long pfn,