From patchwork Tue Jan 22 08:06:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 10775033 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 C432713B5 for ; Tue, 22 Jan 2019 08:06:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6EF12A93A for ; Tue, 22 Jan 2019 08:06:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA6C02AB2E; Tue, 22 Jan 2019 08:06:46 +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 433EC2A93A for ; Tue, 22 Jan 2019 08:06:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430028E0001; Tue, 22 Jan 2019 03:06:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC4D8E0004; Tue, 22 Jan 2019 03:06:42 -0500 (EST) 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 245BD8E0005; Tue, 22 Jan 2019 03:06:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id BFD4C8E0003 for ; Tue, 22 Jan 2019 03:06:41 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id m19so8990312edc.6 for ; Tue, 22 Jan 2019 00:06:41 -0800 (PST) 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=MO7zVBScx4eOfNmGeNgwSEUXAjOZFizyaRYLdrd5bU4=; b=OfkDYg+JNFxiZiDKbVcSPN7iWxW7UDrifn/LOAuSI9jae0E3Vc6TgSQdilsKX8H/3q 9C68vqrSYH7QhVnPxXFpnLPsdNTWmsvqc7ZTZ70xo4R0rdhAzgcr4+0Xiw1YwnqIvhg0 72gERU8eplZBJiEFxCaI3gVJ5Bdzpyx8uQ11B42JTcx+bNMrKiEGsOS5oa4fJl2jjvEN xtY4J1+X76y74K86r5J4H0dFm6XwHjRPwp2ur9uBh4yP7zYs59z9wrM7pV0mLYccJTS8 e/8NPTRlCf0wPwFvNeAsxoGLtXG1BRN6cKsQ/eV1muRB6fXgnXXmI6dx+kKgbru9MOMB GoLw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=jgross@suse.com X-Gm-Message-State: AJcUukfm1tKRJ2venXLrF7er/ko8hcgi0rFPdXAdOz8nAgNzhygdkbbl VPGK3G5zSfgL0uWtSBb4jSkI8M3ozAf+Pae6FwpYTNOW2r2mGafSOUtt/E/IsJ8OBMX0gMw3NAn cSZ8pzSKICka8F5DinveRDOD61u9yVDnkVI+rSJwiy2cwyRrRa5ggsHCqYsyNVEewEQ== X-Received: by 2002:a17:906:2e4f:: with SMTP id r15-v6mr27241264eji.198.1548144401250; Tue, 22 Jan 2019 00:06:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN6znf8k3pgx4e+eMKr10tfXdbpfSnoIfXftkjNJcYfFf08MWP3L6LGLbjCa/72XhhiNd6+g X-Received: by 2002:a17:906:2e4f:: with SMTP id r15-v6mr27241213eji.198.1548144400108; Tue, 22 Jan 2019 00:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548144400; cv=none; d=google.com; s=arc-20160816; b=dUxjoaeUACmtTRI1j1CtYRyaE68yk368wmC4l5SMzPG+3P6aNH/VwpETXgB+Y987zw hQKf3IomBoHoQisdQXXkv0TYgVz+tBHMpwVz2pimRgm0mJlzIJDL+plP0PescR6pu3yc nna4l49Ui+3MC+I/VdC0IYNtmwQ9YiM8QbUfW0wRqZyq2Z0kanuy+AGpxYHmfGm9rFcD V9ByKsXyOK1Sru+7j+cesZAG7q6j3B0IsQNpaeWZmmuYY8AzB0S69dfowMUdOZjzyK7Z 14+E526hkXt9pAM+UNnGN2u8gkEp2Mc9U5pPanIEcmFC6e3TDX/iDUG468/sKxHZOm8p Q0Aw== 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=MO7zVBScx4eOfNmGeNgwSEUXAjOZFizyaRYLdrd5bU4=; b=P14DsVZqyt1VozHLtu4PavKBDjqWCXVjXb0Uq3JVBAKtSKnynGzdeizZO9hFnOQeAX YhpZ4q/Nirt00RpKcTI4HPVDPFEbvaL/I1pVuDNwl0pL0cEzPwPNGwAU1+GEbMPj9Nub iSI+211g/MgdsqGksyGP/ie/fwQnh1TG1QI8EO/XpwkL5LZcNvPFCsQrHsZiAGFmmIsE IvhOzD4lfBUqIO1NibrnnpzVIm+mv8CCJzjqhX9Zt95oB+/ZGfD7N7ElRdcNNLtYbi3B 4FMsySvUZlbwdBQU0FxTb1XzwSFjOnHPYjwFumnKDDm1urY6TVUUaoKUjzJmgUaJXDse DhyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=jgross@suse.com Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id r24si3443008edp.187.2019.01.22.00.06.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 00:06:39 -0800 (PST) Received-SPF: pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=jgross@suse.com X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2B2C8AC3A; Tue, 22 Jan 2019 08:06:39 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, x86@kernel.org, linux-mm@kvack.org Cc: boris.ostrovsky@oracle.com, sstabellini@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, Juergen Gross Subject: [PATCH 1/2] x86: respect memory size limiting via mem= parameter Date: Tue, 22 Jan 2019 09:06:27 +0100 Message-Id: <20190122080628.7238-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190122080628.7238-1-jgross@suse.com> References: <20190122080628.7238-1-jgross@suse.com> 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 When limiting memory size via kernel parameter "mem=" this should be respected even in case of memory made accessible via a PCI card. Today this kind of memory won't be made usable in initial memory setup as the memory won't be visible in E820 map, but it might be added when adding PCI devices due to corresponding ACPI table entries. Not respecting "mem=" can be corrected by adding a global max_mem_size variable set by parse_memopt() which will result in rejecting adding memory areas resulting in a memory size above the allowed limit. Signed-off-by: Juergen Gross --- arch/x86/kernel/e820.c | 5 +++++ include/linux/memory_hotplug.h | 2 ++ mm/memory_hotplug.c | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 50895c2f937d..e67513e2cbbb 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -881,6 +882,10 @@ static int __init parse_memopt(char *p) e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1); +#ifdef CONFIG_MEMORY_HOTPLUG + max_mem_size = mem_size; +#endif + return 0; } early_param("mem", parse_memopt); diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 07da5c6c5ba0..fb6bd0022d41 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -98,6 +98,8 @@ extern void __online_page_free(struct page *page); extern int try_online_node(int nid); +extern u64 max_mem_size; + extern bool memhp_auto_online; /* If movable_node boot option specified */ extern bool movable_node_enabled; diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index b9a667d36c55..7fc2a87110a3 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -96,10 +96,16 @@ void mem_hotplug_done(void) cpus_read_unlock(); } +u64 max_mem_size = -1; + /* add this memory to iomem resource */ static struct resource *register_memory_resource(u64 start, u64 size) { struct resource *res, *conflict; + + if (start + size > max_mem_size) + return ERR_PTR(-E2BIG); + res = kzalloc(sizeof(struct resource), GFP_KERNEL); if (!res) return ERR_PTR(-ENOMEM); From patchwork Tue Jan 22 08:06:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 10775031 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 ED6CE13B5 for ; Tue, 22 Jan 2019 08:06:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEC562A93A for ; Tue, 22 Jan 2019 08:06:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D222B2AB2E; Tue, 22 Jan 2019 08:06:44 +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 A64B82A93A for ; Tue, 22 Jan 2019 08:06:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24C128E0006; Tue, 22 Jan 2019 03:06:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1A9D48E0001; Tue, 22 Jan 2019 03:06:42 -0500 (EST) 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 0C1AB8E0005; Tue, 22 Jan 2019 03:06:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id A51FA8E0001 for ; Tue, 22 Jan 2019 03:06:41 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id b3so9024824edi.0 for ; Tue, 22 Jan 2019 00:06:41 -0800 (PST) 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=Hkn/H6wRl5CXt170DQFWWBGCucNqpPEm5tuMMldE3pw=; b=GLdhFfv4a9+z68E7Jx4ecnxSaswB9uSzoERcLVK8WJLYmJ37wR8Q6pqvvOe6sjfQMY dlot8dXhlKbULfk48S/ktse3GiAJVUXwwJZWByXHlzikPskKJmOO8Q+LJs70OZ2xtCKd 4CCJwhvHz5Ha8uFZ7pvDPEurljsrsRRzomdnMEl9de8vEiMzqwMmAqjrM8wrkhRrOgSe OnOW/Ixad0U/dWlPaONgxgOBRzE/0M5cMqvKUCZX6XvW3Xei6f6Pf/30WR8nIZDtIJXe vhI5T409yDDADf4MNCizeI1H5ktVi74f/cCrgZh890zSYqmn8bNX261AAyTH374zDiW2 NbcQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=jgross@suse.com X-Gm-Message-State: AJcUukc6wun4TNLDgoO4kSnxx5HGqSLhoUVcecjV3GKZss7atygQYhsR hOnersf0jpn4jgyjZ1VX3EsbyhglrNTZtdgNpDKBq5IsCMuCSVP896gvL571S89BPzw669KJO+3 O6Q+vVQm8gH5jgB4AyJ2VvuyT/SK6zPnwtU1r+5qYdpYJOLEMckHyxpXJLGOAWyq6Dg== X-Received: by 2002:aa7:d0c5:: with SMTP id u5mr28947321edo.158.1548144401119; Tue, 22 Jan 2019 00:06:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN4TUx9mtEfO0xdY38QOfsPB/G/kyfxPNI9oSxDl0KPjtqu3rq7XEzpLywY8NA3LVVcPqB+L X-Received: by 2002:aa7:d0c5:: with SMTP id u5mr28947264edo.158.1548144400108; Tue, 22 Jan 2019 00:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548144400; cv=none; d=google.com; s=arc-20160816; b=wv+WDFfceljeEJGyV6wyCo2mwhKxa8dTuGxUY9ASTdA1Uzd7pC8OOTImDbWxy1o3Ru 9L1An1cBMqES9osBfzvKijGWWHthniqPYkBMW9YhScZ7lifk/U3wjCAPlWsN54O+S3gN e49S8a4ojONsawJW8oJJq4Zg/264uPNdjnqE5XsbZy/TpnajDsmmdJ/X9Ri38WkHLwvj 4s4nsUe+qiH9MwOtTl2easVr5+6Ob9rzVTHEAsa1E9lCSIjvfu4xAcfBj83Ov7RfZvge lxtvo0DJAm5IIBEjNezHW1sfF7NU18ci7YRnBpDqKDeRIx0raHN4B/52gJJilHdoegpw MSZA== 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=Hkn/H6wRl5CXt170DQFWWBGCucNqpPEm5tuMMldE3pw=; b=N8DABij1YmYQLy0y/nwtJ6AsvjSvhRxITZ0zjfdT+IksHqeuJH+g32Osczgdr4fDmT u4zF+E1K+MiOHd4duP4y4Y1usXEWZNspQfBoy1H/xabaqJ/6OAEt0gMrRfYuthXr05ma pXBw/7S6F8XHauV2OHbz6y2STF0PAqJt8LRSZQkOOXp/+2KmOl2wD7RAtaJ3iCuGz+ZS 4EqbjUck+m/jw2YAdJ3K9C43x3y0GhmntvF4kaOn8ApzNAc1EfUMIko5X7XC4QIXYmQ3 tx4l3P6LexK9TjQ+WiikRqQs/8RV5YqGs2Zqf1UCU70IIe/oVJ/G1WHgjTNBsdYVpRuV oQvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=jgross@suse.com Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id y49si4099576edd.80.2019.01.22.00.06.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 00:06:39 -0800 (PST) Received-SPF: pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jgross@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=jgross@suse.com X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2B335AC91; Tue, 22 Jan 2019 08:06:39 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, x86@kernel.org, linux-mm@kvack.org Cc: boris.ostrovsky@oracle.com, sstabellini@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, Juergen Gross Subject: [PATCH 2/2] x86/xen: dont add memory above max allowed allocation Date: Tue, 22 Jan 2019 09:06:28 +0100 Message-Id: <20190122080628.7238-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190122080628.7238-1-jgross@suse.com> References: <20190122080628.7238-1-jgross@suse.com> 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 Don't allow memory to be added above the allowed maximum allocation limit set by Xen. Trying to do so would result in cases like the following: [ 584.559652] ------------[ cut here ]------------ [ 584.564897] WARNING: CPU: 2 PID: 1 at ../arch/x86/xen/multicalls.c:129 xen_alloc_pte+0x1c7/0x390() [ 584.575151] Modules linked in: [ 584.578643] Supported: Yes [ 584.581750] CPU: 2 PID: 1 Comm: swapper/0 Not tainted 4.4.120-92.70-default #1 [ 584.590000] Hardware name: Cisco Systems Inc UCSC-C460-M4/UCSC-C460-M4, BIOS C460M4.4.0.1b.0.0629181419 06/29/2018 [ 584.601862] 0000000000000000 ffffffff813175a0 0000000000000000 ffffffff8184777c [ 584.610200] ffffffff8107f4e1 ffff880487eb7000 ffff8801862b79c0 ffff88048608d290 [ 584.618537] 0000000000487eb7 ffffea0000000201 ffffffff81009de7 ffffffff81068561 [ 584.626876] Call Trace: [ 584.629699] [] dump_trace+0x59/0x340 [ 584.635645] [] show_stack_log_lvl+0xea/0x170 [ 584.642391] [] show_stack+0x21/0x40 [ 584.648238] [] dump_stack+0x5c/0x7c [ 584.654085] [] warn_slowpath_common+0x81/0xb0 [ 584.660932] [] xen_alloc_pte+0x1c7/0x390 [ 584.667289] [] pmd_populate_kernel.constprop.6+0x40/0x80 [ 584.675241] [] phys_pmd_init+0x210/0x255 [ 584.681587] [] phys_pud_init+0x1da/0x247 [ 584.687931] [] kernel_physical_mapping_init+0xf5/0x1d4 [ 584.695682] [] init_memory_mapping+0x18d/0x380 [ 584.702631] [] arch_add_memory+0x59/0xf0 Signed-off-by: Juergen Gross --- arch/x86/xen/setup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index d5f303c0e656..5929a6ba5c25 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -785,6 +786,10 @@ char * __init xen_memory_setup(void) /* How many extra pages do we need due to remapping? */ max_pages += xen_foreach_remap_area(max_pfn, xen_count_remap_pages); +#ifdef CONFIG_MEMORY_HOTPLUG + max_mem_size = PFN_PHYS(max_pages); +#endif + if (max_pages > max_pfn) extra_pages += max_pages - max_pfn;