From patchwork Thu Jul 23 08:45:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11680427 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 46649722 for ; Thu, 23 Jul 2020 08:45:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 10ECC22BF5 for ; Thu, 23 Jul 2020 08:45:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="GCrjKx2L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10ECC22BF5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 04E176B0006; Thu, 23 Jul 2020 04:45:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F40EA6B0007; Thu, 23 Jul 2020 04:45:49 -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 E57046B0008; Thu, 23 Jul 2020 04:45:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id CF6266B0006 for ; Thu, 23 Jul 2020 04:45:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 599C5123CD4 for ; Thu, 23 Jul 2020 08:45:49 +0000 (UTC) X-FDA: 77068707618.08.copy51_610998626f3d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 35894181A0987 for ; Thu, 23 Jul 2020 08:45:49 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,roger.pau@citrix.com,,RULES_HIT:30051:30054:30064:30070,0,RBL:216.71.155.175:@citrix.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;04yggm43n4raf7ygb4r41pyippdkgyccr1rbyieea9breqcnccedm7kmwypzykh.diwi3abyyjscosbywoydzemm8gdnna66jpy67awnhogk7tjsr7dg6f6dco1tfc3.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: copy51_610998626f3d X-Filterd-Recvd-Size: 6713 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jul 2020 08:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595493948; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HV5BAB3Ru+vHQcQzkwyNhWTtfNyeOXATqykTtgvMic0=; b=GCrjKx2LH9UI7VWjDa32fZHX+Q5Uaol/3moX0qjzQbWTDzr+d0TuaJOO mmtzDEi6Q9T/zUaiJUdQqNczExaLgSQQL86Vsv1jVcU0s8HqUu/La8zkJ jP79kYdDw8ZuKI7CLQk/Jq2UT8wqBgsMbh9ho+7CJqus5dTonUOfDzmL7 o=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: /mIOgJ6nw15sfd0b279IBlNRDY5Nc/NmPHLXeuRpP2hUXdEHF/oClU3qjsdqiiOLB/BuhRSbNl nbjw/gt+W3wDj2jF6DT0XSktpe4Zqmlt2xmpB7AG4FyTFqXbTd2NY9fPEyULGuSGVDm1gFktgP oWYZD4McskbIE3NygSE93KjKBlC3y/FF1T0eCUAmq/8EKHHJkx05LMCudAbEgXxGSkpuyxJ3tc 6R7bGAAfT8lxXca6nDVQi926JeyOCRMiPU56n91TlftuXTsC8Itt0sWuiP6ZibQ8knT3xBPR6Y e3c= X-SBRS: 2.7 X-MesageID: 23346344 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,386,1589256000"; d="scan'208";a="23346344" From: Roger Pau Monne To: CC: Roger Pau Monne , Boris Ostrovsky , Juergen Gross , "Stefano Stabellini" , Andrew Morton , , Subject: [PATCH 3/3] memory: introduce an option to force onlining of hotplug memory Date: Thu, 23 Jul 2020 10:45:23 +0200 Message-ID: <20200723084523.42109-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200723084523.42109-1-roger.pau@citrix.com> References: <20200723084523.42109-1-roger.pau@citrix.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 35894181A0987 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: 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é Nacked-by: David Hildenbrand --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini Cc: Andrew Morton 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);