Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1423775imm; Tue, 2 Oct 2018 08:01:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV611NgVegTlZV63HStI6TJwE8yWmAVWetxCq69SFi+wD3slUB2vdBbihBLI1c353k9bQ5rjP X-Received: by 2002:a63:6c04:: with SMTP id h4-v6mr14870180pgc.290.1538492484020; Tue, 02 Oct 2018 08:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538492483; cv=none; d=google.com; s=arc-20160816; b=Q5Tgna4wsv4JDMoA/hdfaOk/aF/wc+ZHn3/gqKGDVQuSxvDoDUEg0rfdGCbKsAritN dZgReCRmefP+4gTWxdkZofAnI4jhhA15P9/KrIDQDIOGHwKmaXM9WnXfKdefx8mrWRzQ W43oowDk4nYGcJG8QOw3xchIdxWvu8gJI9BXo13BkqSnEVnK9t8UQh9cAdveigmu6Sh/ ytdZWM0IJK6/jXB+DBEPlaF7Ap6gLpJ1CYvsQ/0kf1UDH1/RRfvZOXydkOE+NitHP4yG MA49302ITRMFJqhq/DjZR6Ouojwb+H3koKBWy576UWM3g+pqoVtfJOLgifUQMH4z2n4/ vDxg== 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=PhCT3TBAUk3AvVLhiqqr/i+tBqrnuE7S7sAJRx6RsvU=; b=adGwpHrJ1Nk7+Iml6lOiu2WvqrfAliAYrSgkFp8Xei+NVTxaUtmAqn2TshXnvgg387 g9j38kmEeYsEi7Nd0lkPrCb06fEsMr4p/+/vkmza63OUgRYEMg4y97Up8JJpYaP42G+N bJvwmEtcLbFYutRcFliSm+/0B2oHbB6A/RAldEBrHbgnMY7+6J944RJgOdO3xIneZ11Z AXLGqFfP1yuIhkKblh52St4u8jZ1LAE8IWT28UdgZhCxmdC/eZvbP5iU88B5XKQXrODM kzMhmdoBl3a39twWPoQ6IbiZN69gfTDTXkwNo11VEhof+DsZCqXskkMjOY23viLXRZTv +jCA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14-v6si14511692pgk.346.2018.10.02.08.01.08; Tue, 02 Oct 2018 08:01:23 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729377AbeJBVoo (ORCPT + 99 others); Tue, 2 Oct 2018 17:44:44 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39473 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729201AbeJBVom (ORCPT ); Tue, 2 Oct 2018 17:44:42 -0400 Received: by mail-wr1-f67.google.com with SMTP id 61-v6so1876197wrb.6 for ; Tue, 02 Oct 2018 08:00:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PhCT3TBAUk3AvVLhiqqr/i+tBqrnuE7S7sAJRx6RsvU=; b=W7UG4bzRCBDM+5sSqHITZZZvCiLcVb8JkHnf8tryfpmlJ3u5+TSYTpAPTkLhaoNM36 YArc6daKO2BRe4z448CHKFEWhl3xFvLIUQkYpF7mjGqnC6YuyctbncLe5l396DWhSq+N 4aOSm7g9z8GSabl1Xo1GbbinJYe3p5OtPyY0pQliAfoYS6xFuZVj5iyatZxZxk4j+7OI uKEieDADc88Nkt5WaRsFPnmTMeS350ErNOdn16p+y6HGldGEUAtzXrBPqxLIY62bZ/EN mInVBeUJkJ22PNAMdhYVNKYnByhueL1bSQC4vMbJZDb5uuv3t6kz2O2YymrjqlrHjPCE pmzQ== X-Gm-Message-State: ABuFfojLscHahsLMD6mKeaQBl9yBct7VuwOkcKebqwaS4zDWbJc/Is0/ cs8yymtJc6Rpfa0lPHsBl6I= X-Received: by 2002:adf:9c12:: with SMTP id f18-v6mr11165017wrc.93.1538492451294; Tue, 02 Oct 2018 08:00:51 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id q200-v6sm14232186wmd.2.2018.10.02.08.00.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 08:00:50 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 444CE12572C; Tue, 2 Oct 2018 17:00:48 +0200 (CEST) From: Oscar Salvador To: linux-mm@kvack.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, Oscar Salvador Subject: [RFC PATCH v3 5/5] mm/memory-hotplug: Rework unregister_mem_sect_under_nodes Date: Tue, 2 Oct 2018 17:00:29 +0200 Message-Id: <20181002150029.23461-6-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181002150029.23461-1-osalvador@techadventures.net> References: <20181002150029.23461-1-osalvador@techadventures.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/base/memory.c | 9 ++++----- drivers/base/node.c | 38 +++++++------------------------------- include/linux/memory.h | 2 +- include/linux/node.h | 7 ++----- mm/memory_hotplug.c | 2 +- 5 files changed, 15 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..e8aa9e6d95f9 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -72,8 +72,7 @@ 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 +104,8 @@ 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 1f71aebd598b..e7a38471fdc2 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; -- 2.13.6