Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2068326ybv; Thu, 6 Feb 2020 15:19:56 -0800 (PST) X-Google-Smtp-Source: APXvYqz9jM0/wMCJZ1PpWJHeqx6XE453tzrUXpd0XxZYvKfIO/NA2Q6Y8fPBIMfmHIEyJ/GbjLuv X-Received: by 2002:a9d:4c92:: with SMTP id m18mr435706otf.168.1581031196754; Thu, 06 Feb 2020 15:19:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581031196; cv=none; d=google.com; s=arc-20160816; b=F9khl/zeAAcLg5BwlN/BcQcCLPu1SoG/34hq2Y1HAxsDK8p4xE4GjxS5q5WVJ0Xa43 0r/nI8SFdCKXqC+mKkePCdowizaV3B69RmrNfXVgGHDDASlVQnyWtuGcFvk01iup+LwH YXhVTBX2SxllTM43vrByMTt4UISDwUiazthTHyfkNoRbwMpq7qGtCyAQNWTt+Z0I6EV7 RDqI+BZN0KLmF2hbenT51mMzka51yq9Ozb1IO3ZHofMcrvM3h4paqlwZbR3UVN4ZouJc PK04ElKt5kdntMvb1X8x2Kc2SFVJlHYLnGoWLRxgkK2yHNz99Fbhgn6InpKaxmoJsuWs ly4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=7h3bOXYjZkLjQ235J5TJNVphweX3n9vbiNkGIKwMLNU=; b=vA9M9/mePJZHgZbaRI5S1N4QFd8Emg6LO2LKcKFPCpJb1VeSXcYSW8NeI6OjRUG92w p4b5LDRoCOrz5tGFJeVIA3TXeTyutQIdVhh5KYxsNfXSTIeA6Z0HoBEB0zEBD0jaQKvJ VXq1aPL95+FyzoPuEx3nKBh0nw9nrc7+Ui1kocQLokm39IcbULcfZwbUDbDeTFGXpc7w XaCVlClTmLJxBf/1GNFmlX0FCwUiozTHVtknaJQ+F8eU3ZHjg+JwawYYGk/1BHIZfR+C hyfOhDwjrFFX7doHHUyLEGF7sPOagptmtOHZ+Kyii9psl7Xn7aNfviwWAo5DFN+NU3xg twHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id t127si3018688oih.45.2020.02.06.15.19.41; Thu, 06 Feb 2020 15:19:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727387AbgBFXRm (ORCPT + 99 others); Thu, 6 Feb 2020 18:17:42 -0500 Received: from mga03.intel.com ([134.134.136.65]:6959 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbgBFXRk (ORCPT ); Thu, 6 Feb 2020 18:17:40 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1