linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: <linux-kernel@vger.kernel.org>
Cc: Roger Pau Monne <roger.pau@citrix.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Juergen Gross <jgross@suse.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	<xen-devel@lists.xenproject.org>, <linux-mm@kvack.org>
Subject: [PATCH 3/3] memory: introduce an option to force onlining of hotplug memory
Date: Thu, 23 Jul 2020 10:45:23 +0200	[thread overview]
Message-ID: <20200723084523.42109-4-roger.pau@citrix.com> (raw)
In-Reply-To: <20200723084523.42109-1-roger.pau@citrix.com>

Add an extra option to add_memory_resource that overrides the memory
hotplug online behavior in order to force onlining of memory from
add_memory_resource unconditionally.

This is required for the Xen balloon driver, that must run the
online page callback in order to correctly process the newly added
memory region, note this is an unpopulated region that is used by Linux
to either hotplug RAM or to map foreign pages from other domains, and
hence memory hotplug when running on Xen can be used even without the
user explicitly requesting it, as part of the normal operations of the
OS when attempting to map memory from a different domain.

Setting a different default value of memhp_default_online_type when
attaching the balloon driver is not a robust solution, as the user (or
distro init scripts) could still change it and thus break the Xen
balloon driver.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: xen-devel@lists.xenproject.org
Cc: linux-mm@kvack.org
---
 drivers/xen/balloon.c          |  2 +-
 include/linux/memory_hotplug.h |  3 ++-
 mm/memory_hotplug.c            | 16 ++++++++++------
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 292413b27575..fe0e0c76834b 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -346,7 +346,7 @@ static enum bp_state reserve_additional_memory(void)
 	mutex_unlock(&balloon_mutex);
 	/* add_memory_resource() requires the device_hotplug lock */
 	lock_device_hotplug();
-	rc = add_memory_resource(nid, resource);
+	rc = add_memory_resource(nid, resource, true);
 	unlock_device_hotplug();
 	mutex_lock(&balloon_mutex);
 
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 375515803cd8..1793619fe4a6 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -342,7 +342,8 @@ extern void clear_zone_contiguous(struct zone *zone);
 extern void __ref free_area_init_core_hotplug(int nid);
 extern int __add_memory(int nid, u64 start, u64 size);
 extern int add_memory(int nid, u64 start, u64 size);
-extern int add_memory_resource(int nid, struct resource *resource);
+extern int add_memory_resource(int nid, struct resource *resource,
+			       bool force_online);
 extern int add_memory_driver_managed(int nid, u64 start, u64 size,
 				     const char *resource_name);
 extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index da374cd3d45b..2491588d3f86 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1002,7 +1002,10 @@ static int check_hotplug_memory_range(u64 start, u64 size)
 
 static int online_memory_block(struct memory_block *mem, void *arg)
 {
-	mem->online_type = memhp_default_online_type;
+	bool force_online = arg;
+
+	mem->online_type = force_online ? MMOP_ONLINE
+					: memhp_default_online_type;
 	return device_online(&mem->dev);
 }
 
@@ -1012,7 +1015,7 @@ static int online_memory_block(struct memory_block *mem, void *arg)
  *
  * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG
  */
-int __ref add_memory_resource(int nid, struct resource *res)
+int __ref add_memory_resource(int nid, struct resource *res, bool force_online)
 {
 	struct mhp_params params = { .pgprot = PAGE_KERNEL };
 	u64 start, size;
@@ -1076,8 +1079,9 @@ int __ref add_memory_resource(int nid, struct resource *res)
 	mem_hotplug_done();
 
 	/* online pages if requested */
-	if (memhp_default_online_type != MMOP_OFFLINE)
-		walk_memory_blocks(start, size, NULL, online_memory_block);
+	if (memhp_default_online_type != MMOP_OFFLINE || force_online)
+		walk_memory_blocks(start, size, (void *)force_online,
+				   online_memory_block);
 
 	return ret;
 error:
@@ -1100,7 +1104,7 @@ int __ref __add_memory(int nid, u64 start, u64 size)
 	if (IS_ERR(res))
 		return PTR_ERR(res);
 
-	ret = add_memory_resource(nid, res);
+	ret = add_memory_resource(nid, res, false);
 	if (ret < 0)
 		release_memory_resource(res);
 	return ret;
@@ -1158,7 +1162,7 @@ int add_memory_driver_managed(int nid, u64 start, u64 size,
 		goto out_unlock;
 	}
 
-	rc = add_memory_resource(nid, res);
+	rc = add_memory_resource(nid, res, false);
 	if (rc < 0)
 		release_memory_resource(res);
 
-- 
2.27.0



       reply	other threads:[~2020-07-23  8:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200723084523.42109-1-roger.pau@citrix.com>
2020-07-23  8:45 ` Roger Pau Monne [this message]
2020-07-23 11:37   ` David Hildenbrand
2020-07-23 11:52     ` David Hildenbrand
2020-07-23 12:23     ` Roger Pau Monné
2020-07-23 12:28       ` Jürgen Groß
2020-07-23 12:31         ` David Hildenbrand
2020-07-23 13:08         ` Roger Pau Monné
2020-07-23 13:14           ` David Hildenbrand
2020-07-23 13:25             ` Roger Pau Monné
2020-07-23 13:20           ` Jürgen Groß
2020-07-23 13:39             ` Roger Pau Monné
2020-07-23 13:49               ` Jürgen Groß
2020-07-23 13:22       ` David Hildenbrand
2020-07-23 13:47         ` David Hildenbrand
2020-07-23 13:53           ` Jürgen Groß
2020-07-23 13:59         ` Roger Pau Monné
2020-07-23 15:10           ` Jürgen Groß
2020-07-23 16:03             ` Andrew Cooper
2020-07-23 16:22             ` Roger Pau Monné
2020-07-23 17:39               ` David Hildenbrand
2020-07-24  7:28                 ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200723084523.42109-4-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=akpm@linux-foundation.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox