Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1683966imj; Thu, 14 Feb 2019 10:16:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IYVn/q3zj5NPYo3MQV/zTbnFhf0tMwBQOhN3XcK2fUid9RawR/tnrobK6A+ICgEzoihNOVL X-Received: by 2002:a17:902:780a:: with SMTP id p10mr5721115pll.54.1550168172040; Thu, 14 Feb 2019 10:16:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550168172; cv=none; d=google.com; s=arc-20160816; b=hlNYtYj9a2raqJfucANS4c7dppEi9A7/WPhmzkXSlA15sj6ttOblWWlTjPWKeJRIOw gfvB4bFY3UrzXl1b50AnrTq3DBirA1ZD5CEtd7p2XkaZQO0fGrUB2IHoThG5kdozUtQ+ I0dQ1h2VrDLJuR4RKf1++KOKMH4yZzwQqTF7eZjn+Ro1ZKfsnxdbdn26BObeAz+/mbC6 gxX9ez6poR28gq+67Q/9CJvw9lYKRwbIxCuRPvPS6hHY3hnL/A2P0b8XQo9M2XyCcsGy Mx0HRCNtBY2B3WH0FWZX5xTA2XwicTq9c0TxQ2b0e1diKTI6nqHexbLFlqoWAuslvfYw 24UA== 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=unNMsV12tL80oKyx5Trd2XJzSyu0F4NB8jKTV2bBJy8=; b=WNDA6ElIPNC/aVEg2aD/XL8B6dJDcs1w0LraRRWn0nNKCK/rFjsF/UYFZAuaNCAED/ nhSFUWk2JbSaDxE44KK1jklvgsnnv7ZVTYVwfwhy+1i6w4x22Gukv6By7oqBjJ4iNDvq L5RIgLDj8yT/GBdhA1Ylk6jdBjl1cKiforpQpthhivtmB+ZmZr7xip/4+dJyYXcH4wJq ZsJKeN+iQEJe8eV8tNivpghcCNWVWtbj6vXGt3nZjr5go3WcDjqQYujiMJrc4nrkR3xR s7q/GhxVnty2i4daqLuyw2G0EY3VflycjsHS+95c2+t9H7kh6ANAfvIrPs4SVdoaUTHR PQUw== 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 e129si2805385pgc.333.2019.02.14.10.15.55; Thu, 14 Feb 2019 10:16:12 -0800 (PST) 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 S2394282AbfBNKmr (ORCPT + 99 others); Thu, 14 Feb 2019 05:42:47 -0500 Received: from mx2.suse.de ([195.135.220.15]:55010 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2438491AbfBNKmp (ORCPT ); Thu, 14 Feb 2019 05:42:45 -0500 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 E7FA7B0BA; Thu, 14 Feb 2019 10:42:43 +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 v3 1/2] x86: respect memory size limiting via mem= parameter Date: Thu, 14 Feb 2019 11:42:39 +0100 Message-Id: <20190214104240.24428-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190214104240.24428-1-jgross@suse.com> References: <20190214104240.24428-1-jgross@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Ingo Molnar --- 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 368267c1b71b..cfd12078172a 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -100,6 +100,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 124e794867c5..519f9db063ff 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 = U64_MAX; + /* 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); -- 2.16.4