From patchwork Thu Jul 23 08:45:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 11680435 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 3CA97722 for ; Thu, 23 Jul 2020 08:47:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17F5F22B47 for ; Thu, 23 Jul 2020 08:47:38 +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="cYG1g6MN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17F5F22B47 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jyWrQ-00060e-Lg; Thu, 23 Jul 2020 08:45:52 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jyWrP-00060P-Kz for xen-devel@lists.xenproject.org; Thu, 23 Jul 2020 08:45:51 +0000 X-Inumbo-ID: e7f7ddb4-ccc0-11ea-a26b-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e7f7ddb4-ccc0-11ea-a26b-12813bfff9fa; Thu, 23 Jul 2020 08:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595493949; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aDtTphrzz9VOwTJvjWtl31/5xlDEnj/EJHimWB6gA4o=; b=cYG1g6MNbDcE+RkR9QpcLmYcP656KCgk6rKsTHEwJllY/GeMMe/hPbBY uFaqKj/RyU3+q+35QZ9jgWQ9Kvku5d8IGOPA3VaEV791IxfNDZmXObc3X X4zaZmkl/nMNt+DReP8Bty0TPXM4HJrxiAszvZqIH6RfkHQU8uMYjlD/J A=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: FWgaZAI6RoWQ6RqerM/hehVavtzAH7kBf/6J3Itw9DAyS7asko2A0WA2QUDT8/3hNJsqelSZhx aGmvB+UAcjhoS8QAFOir6owrVHYiklIGssIJbF2bknAmpy3xPWKLguU8S9RRbMH3bf0+cva/3N uWbogJ0Gm1FH42uL71Ft0fG/1RAiD2Rw7MHlwe8wv+Cn7R/dGiTSxubqWMgwlXk5nExHTGmjb4 pCwIbJGW/hdprKdJesLAO/DCcfjT/aOM9VhVGAf07YUdfu+XW0GCx/J8nODk0DNNXrGa4pMW2b 11g= X-SBRS: 2.7 X-MesageID: 23212752 X-Ironport-Server: esa5.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="23212752" From: Roger Pau Monne To: Subject: [PATCH 1/3] xen/balloon: fix accounting in alloc_xenballooned_pages error path Date: Thu, 23 Jul 2020 10:45:21 +0200 Message-ID: <20200723084523.42109-2-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-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , stable@vger.kernel.org, xen-devel@lists.xenproject.org, Boris Ostrovsky , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" target_unpopulated is incremented with nr_pages at the start of the function, but the call to free_xenballooned_pages will only subtract pgno number of pages, and thus the rest need to be subtracted before returning or else accounting will be skewed. Signed-off-by: Roger Pau Monné Cc: stable@vger.kernel.org --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini Cc: xen-devel@lists.xenproject.org --- drivers/xen/balloon.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 77c57568e5d7..3cb10ed32557 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -630,6 +630,12 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages) out_undo: mutex_unlock(&balloon_mutex); free_xenballooned_pages(pgno, pages); + /* + * NB: free_xenballooned_pages will only subtract pgno pages, but since + * target_unpopulated is incremented with nr_pages at the start we need + * to remove the remaining ones also, or accounting will be screwed. + */ + balloon_stats.target_unpopulated -= nr_pages - pgno; return ret; } EXPORT_SYMBOL(alloc_xenballooned_pages); From patchwork Thu Jul 23 08:45:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 11680429 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 B8062138C for ; Thu, 23 Jul 2020 08:46:26 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 930FF2080D for ; Thu, 23 Jul 2020 08:46:26 +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="cEw9Qk0m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 930FF2080D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jyWrM-000608-3A; Thu, 23 Jul 2020 08:45:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jyWrK-000601-BA for xen-devel@lists.xenproject.org; Thu, 23 Jul 2020 08:45:46 +0000 X-Inumbo-ID: e5b30b28-ccc0-11ea-86e9-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e5b30b28-ccc0-11ea-86e9-bc764e2007e4; Thu, 23 Jul 2020 08:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595493945; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7Tw4G/V7kxbTklR4OkIgBDvRcTQey+xrJa3KZIIL0yE=; b=cEw9Qk0mB8sVOcLppdzc0VDIW4CjWqlAkd7PXOqAhHnIr3kitvmi6cDW vkcrwmmWMri0R/FSrwWrqnGuAF1D4A6Hene82kvGCHIbJ5j3e962UVXiK V3Fo1Q9DrVvM/ZdFBf865gwFLLBVNd2MeOp90RrnK/YGzeuMrPKnCi1mL k=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: XvT0C2bz7SBG/PGU4X8x9SKjeEDHKXC2DnQh4Ohf3AOgAn+fTf2GBFquaKPJBrljF3EVlbn2no Lzfc3CouKYANDaPfndD65nop2ySPLmK0BRz+SfUhqzhkTkvyl+hHr4Z0fdpAz1X2ZWwbByPwxE txf4kH+VPc2cNl/2s6fQcd2ImZSNihdbZ55qd9S6RkyMdKww02zAxd/G43mz0DnCOq5uctvKGf qm8BXn1hp7fmezUGGl0A0/xagekyzRUqjT8GjK/+LO+PDB2u/KfTu3f//hJBi5jthWymPxhGdP Ppc= X-SBRS: 2.7 X-MesageID: 23880204 X-Ironport-Server: esa4.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="23880204" From: Roger Pau Monne To: Subject: [PATCH 2/3] xen/balloon: make the balloon wait interruptible Date: Thu, 23 Jul 2020 10:45:22 +0200 Message-ID: <20200723084523.42109-3-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-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , stable@vger.kernel.org, xen-devel@lists.xenproject.org, Boris Ostrovsky , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" So it can be killed, or else processes can get hung indefinitely waiting for balloon pages. Signed-off-by: Roger Pau Monné Cc: stable@vger.kernel.org --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini Cc: xen-devel@lists.xenproject.org --- drivers/xen/balloon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 3cb10ed32557..292413b27575 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c @@ -568,11 +568,13 @@ static int add_ballooned_pages(int nr_pages) if (xen_hotplug_unpopulated) { st = reserve_additional_memory(); if (st != BP_ECANCELED) { + int rc; + mutex_unlock(&balloon_mutex); - wait_event(balloon_wq, + rc = wait_event_interruptible(balloon_wq, !list_empty(&ballooned_pages)); mutex_lock(&balloon_mutex); - return 0; + return rc ? -ENOMEM : 0; } } 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: Roger Pau Monne X-Patchwork-Id: 11680437 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 ADDF313B1 for ; Thu, 23 Jul 2020 08:47:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A52F22B43 for ; Thu, 23 Jul 2020 08:47:39 +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="FJa9WUs8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A52F22B43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jyWrQ-00060W-CY; Thu, 23 Jul 2020 08:45:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jyWrP-000601-9x for xen-devel@lists.xenproject.org; Thu, 23 Jul 2020 08:45:51 +0000 X-Inumbo-ID: e754dd1c-ccc0-11ea-86e9-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e754dd1c-ccc0-11ea-86e9-bc764e2007e4; 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=1595493947; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HV5BAB3Ru+vHQcQzkwyNhWTtfNyeOXATqykTtgvMic0=; b=FJa9WUs8X32R49Gny9LcDfi+OAAzS8rkILr5MSX2CHs6KNAJ1R/WLpQd hJ36omV7R8YdktvCBiVbEDfI8fNtgonGZtby1k/pzULG7qrtyljmUlNDz MB+f0qhwHclrZyI+eB/Mmya3IEflQY3Vmn04QIT1oeUwt62ab0GeI3eUq Q=; 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: 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-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , linux-mm@kvack.org, xen-devel@lists.xenproject.org, Boris Ostrovsky , Andrew Morton , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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);