From patchwork Mon Oct 15 15:30:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10642057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7AB0925 for ; Mon, 15 Oct 2018 15:31:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D66D529AF4 for ; Mon, 15 Oct 2018 15:31:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAAD129B0A; Mon, 15 Oct 2018 15:31:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F9D729AF4 for ; Mon, 15 Oct 2018 15:31:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F1256B0266; Mon, 15 Oct 2018 11:30:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6C7DF6B026A; Mon, 15 Oct 2018 11:30:59 -0400 (EDT) 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 5BFC76B0269; Mon, 15 Oct 2018 11:30:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id EADA16B0266 for ; Mon, 15 Oct 2018 11:30:58 -0400 (EDT) Received: by mail-wm1-f69.google.com with SMTP id 203-v6so14566790wmv.1 for ; Mon, 15 Oct 2018 08:30:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Klahqg36Ibpp1aNBF2mqe1EkWDF8ejY5IvTH1L9cox0=; b=fTq3cThmJTz7Cjk63EeXAkvD79MeKc1YOd4RU+XMzx4WWgNS/fHFMwRudxKuowdGur jZTgm1bUvPY8rLkJrOLf8Tbks2nvcfFOs4rNXAGoEGX4CbVERCoshURMNIZeSWp0upAx Gk9SRZiX3j/+i3zNVhvB2m5tGNMq9FVBRaDychesslVfn54VVN+AwBULv4ZhibFpCE6+ qMflqCAZvgn202ATHIsBuV1BbTvsL1ccj3rbvV97j/iGY7B+BFfacTP6ODjlsVqtJ/a4 TvJhioTrSmvn8kTwp+2oR6lxDUYhQuWY1EDZK7r/dTGIrKD3k9n6VtZiVG2S1BpfA0s2 y2Xg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Gm-Message-State: ABuFfohppLFtJQ53G3n2z8STjvCH3Jwe1fMoBjsG2K5x8tU7v8RK0Cqv RdaaW6H1vUMTs4B3q9fmT36hLKZzzK913skH18K+M6hwfZ4zrun4xx9DfXKc/VHRE2mun7vnGKa zDXGsdCTqghUrGyoaOs6C95rIYktDVwXKlSxTR3Vfsx84QhBsB8yF1O/99N+geaMqEXNkkA3OJY 32nwBaO3lcAQ3OgpWLaBy4tsujfoyRkZMxDpHwUHNtP1w2dSYlXn69EOfPrygJ2rdAxW6K/nh3h CUpcbmSgOEtFdHbRdmWKRNu6EZ2hxw+x5tZM2R9HxBtpvGuQbYPbF6Fk1Z9wkh3RDaTn3sK8G2f H8jRhDOXR1wC64L5Ip1uYuHMChX+mLn2V8fSGiAKjxa44W5gKMF4DlfE00vvKTqAXPwPg2aZjQ= = X-Received: by 2002:a1c:1fcd:: with SMTP id f196-v6mr13724462wmf.19.1539617458425; Mon, 15 Oct 2018 08:30:58 -0700 (PDT) X-Received: by 2002:a1c:1fcd:: with SMTP id f196-v6mr13724385wmf.19.1539617457135; Mon, 15 Oct 2018 08:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539617457; cv=none; d=google.com; s=arc-20160816; b=T5kJKwWB576IWFnQmIT3SPxmBHvwUXrMLirxkmE6aGcADFZbvF2X+UsGoNnzVDMG8o AxRFucEwHPHfO2qGgjvoqacujfcqsI/kwgRQAuGhJ8yP+GZSb9CzfJz6CvunfJgRFhZi UeC2I0xqw5BYc0C+KyzjDvmNOvgM8OMX9G99iTSngZS2aAbTUyWIzAWwh7vAUYVEHFx5 BMXDXz+mADDcJjuQ+Bv6svtweHXrMDqmddnNh45c3gghTSK3m70sx2J52YVMf3D+f+EI aEOEJclJ+3+3T+kM5mJSUn+xgxpjS6tx8OPVJWjE5C3btBN8AFQ1bh51/9pkQxU7K24R UoBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Klahqg36Ibpp1aNBF2mqe1EkWDF8ejY5IvTH1L9cox0=; b=uLhSaOcQArkPBfG6M8EcsYg8GkHzf+nPuSL5DHsCTWd3bhTT3yEsCJ255H+dlWtiz6 dDIa4tuqutF8hOnyGj+mDKNb8JnDMu/l+gOoidlU/RleAjl3xvg+ejMZnZcS3HUMPUI1 +b6LUk6M4jXyACC5vQZCXmNjs918iiP10MRQCJ18M9uIvA+VWChrgmP24GYkt32ymJn3 1JjWlOFymiu4qlUvkNg7Ra45pBNi/C7ZCH4v/gJwmQ1YpDW81Axh2aKf1ATX6SxP4qgm wrOH+MNLvdvP0AusYgRLA1NSJBlyHSAM5IpMhZcrCcVEkZXIbnsqYKksc0htAI6BLc1M 7C3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n10-v6sor6181089wru.35.2018.10.15.08.30.56 for (Google Transport Security); Mon, 15 Oct 2018 08:30:57 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Google-Smtp-Source: ACcGV63nfd9R6AR3e3vbj7HTCbnZ88O29I9amv7MEzGUb9OehmaMgfI4iu+IKzdZbTsWPOrwkvXJBw== X-Received: by 2002:a5d:4409:: with SMTP id z9-v6mr13979691wrq.227.1539617456804; Mon, 15 Oct 2018 08:30:56 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id a1-v6sm8859612wrt.79.2018.10.15.08.30.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 08:30:54 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id E588A1251F0; Mon, 15 Oct 2018 17:30:52 +0200 (CEST) From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, yasu.isimatu@gmail.com, rppt@linux.vnet.ibm.com, malat@debian.org, linux-kernel@vger.kernel.org, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, dave.jiang@intel.com, linux-mm@kvack.org, alexander.h.duyck@linux.intel.com, Oscar Salvador Subject: [PATCH 5/5] mm/memory-hotplug: Rework unregister_mem_sect_under_nodes Date: Mon, 15 Oct 2018 17:30:34 +0200 Message-Id: <20181015153034.32203-6-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181015153034.32203-1-osalvador@techadventures.net> References: <20181015153034.32203-1-osalvador@techadventures.net> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Salvador This tries to address another issue about accessing unitiliazed pages. Jonathan reported a problem [1] where we can access steal pages in case we hot-remove memory without onlining it first. This time is in unregister_mem_sect_under_nodes. This function tries to get the nid from the pfn and then tries to remove the symlink between mem_blk <-> nid and vice versa. Since we already know the nid in remove_memory(), we can pass it down the chain to unregister_mem_sect_under_nodes. There we can just remove the symlinks without the need to look into the pages. [1] https://www.spinics.net/lists/linux-mm/msg161316.html Signed-off-by: Oscar Salvador Tested-by: Jonathan Cameron --- drivers/base/memory.c | 9 ++++----- drivers/base/node.c | 38 +++++++------------------------------- include/linux/memory.h | 2 +- include/linux/node.h | 9 ++++----- mm/memory_hotplug.c | 2 +- 5 files changed, 17 insertions(+), 43 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 0e5985682642..3d8c65d84bea 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -744,8 +744,7 @@ unregister_memory(struct memory_block *memory) device_unregister(&memory->dev); } -static int remove_memory_section(unsigned long node_id, - struct mem_section *section, int phys_device) +static int remove_memory_section(unsigned long nid, struct mem_section *section) { struct memory_block *mem; @@ -759,7 +758,7 @@ static int remove_memory_section(unsigned long node_id, if (!mem) goto out_unlock; - unregister_mem_sect_under_nodes(mem, __section_nr(section)); + unregister_mem_sect_under_nodes(nid, mem); mem->section_count--; if (mem->section_count == 0) @@ -772,12 +771,12 @@ static int remove_memory_section(unsigned long node_id, return 0; } -int unregister_memory_section(struct mem_section *section) +int unregister_memory_section(int nid, struct mem_section *section) { if (!present_section(section)) return -EINVAL; - return remove_memory_section(0, section, 0); + return remove_memory_section(nid, section); } #endif /* CONFIG_MEMORY_HOTREMOVE */ diff --git a/drivers/base/node.c b/drivers/base/node.c index 86d6cd92ce3d..65bc5920bd3d 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -453,40 +453,16 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) return 0; } -/* unregister memory section under all nodes that it spans */ -int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +/* + * This mem_blk is going to be removed, so let us remove the link + * to the node and vice versa + */ +void unregister_mem_sect_under_nodes(int nid, struct memory_block *mem_blk) { - NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); - unsigned long pfn, sect_start_pfn, sect_end_pfn; - - if (!mem_blk) { - NODEMASK_FREE(unlinked_nodes); - return -EFAULT; - } - if (!unlinked_nodes) - return -ENOMEM; - nodes_clear(*unlinked_nodes); - - sect_start_pfn = section_nr_to_pfn(phys_index); - sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; - for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { - int nid; - - nid = get_nid_for_pfn(pfn); - if (nid < 0) - continue; - if (!node_online(nid)) - continue; - if (node_test_and_set(nid, *unlinked_nodes)) - continue; - sysfs_remove_link(&node_devices[nid]->dev.kobj, + sysfs_remove_link(&node_devices[nid]->dev.kobj, kobject_name(&mem_blk->dev.kobj)); - sysfs_remove_link(&mem_blk->dev.kobj, + sysfs_remove_link(&mem_blk->dev.kobj, kobject_name(&node_devices[nid]->dev.kobj)); - } - NODEMASK_FREE(unlinked_nodes); - return 0; } int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn) diff --git a/include/linux/memory.h b/include/linux/memory.h index a6ddefc60517..d75ec88ca09d 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -113,7 +113,7 @@ extern int register_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb); int hotplug_memory_register(int nid, struct mem_section *section); #ifdef CONFIG_MEMORY_HOTREMOVE -extern int unregister_memory_section(struct mem_section *); +extern int unregister_memory_section(int nid, struct mem_section *); #endif extern int memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..dddead9937ab 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -72,8 +72,8 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); extern int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg); -extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index); +extern void unregister_mem_sect_under_nodes(int nid, + struct memory_block *mem_blk); #ifdef CONFIG_HUGETLBFS extern void register_hugetlbfs_with_node(node_registration_func_t doregister, @@ -105,10 +105,9 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, { return 0; } -static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +static inline void unregister_mem_sect_under_nodes(int nid, + struct memory_block *mem_blk) { - return 0; } static inline void register_hugetlbfs_with_node(node_registration_func_t reg, diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 6b98321aa52f..66ccbb5b8a88 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -528,7 +528,7 @@ static int __remove_section(int nid, struct mem_section *ms, if (!valid_section(ms)) return ret; - ret = unregister_memory_section(ms); + ret = unregister_memory_section(nid, ms); if (ret) return ret;