From patchwork Mon Jun 20 07:33:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yigal Korman X-Patchwork-Id: 9186775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 570D86075F for ; Mon, 20 Jun 2016 07:34:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43FE923B23 for ; Mon, 20 Jun 2016 07:34:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38AEC24DA1; Mon, 20 Jun 2016 07:34:49 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6D0723B23 for ; Mon, 20 Jun 2016 07:34:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7F8211A1E20; Mon, 20 Jun 2016 00:35:17 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com [IPv6:2a00:1450:400c:c09::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 43A191A1E20 for ; Mon, 20 Jun 2016 00:35:16 -0700 (PDT) Received: by mail-wm0-x229.google.com with SMTP id r201so48346552wme.1 for ; Mon, 20 Jun 2016 00:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plexistor-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=8mAsS0ZHf3KB6DqJO8x+QjgCVPABQc9GKATdbyowgm8=; b=0uzuVt39ACL3dBbWyq9BFyykP3fWWaukAKCa+KyJH53yu8ok16Wwo3iusKLWt3MBbL HbPG8M2TT70KuWnJOU2RuRx6324eR4GHsP092QdqDXPM8dPEanuFvj+7RumJXXcbCeu1 Waxfd70GlZl5L6fyCTkh8vneJn2dt7T4q+h4AN+JyCtbvgdvhfVT0ntIm7TDprzrhUwk uHPDYloUHNhRzyH5+6q+UwZw3Ehyrq1NEpYvXX/Yc5Iraj6muXc021ZL8tWSDQms9YFv 0+6cHnWkw3/XuDoTinC7l8DzcAlb1GiiSpluspc4Ddlgl+IHnMqYr+q9tNqPlFiWRRza pAPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8mAsS0ZHf3KB6DqJO8x+QjgCVPABQc9GKATdbyowgm8=; b=TyTwR7vjBWDPyQwfHS/tuG6XZ8gbAvG4vwiWEepVVoX3Mksn+y+qBadJ7ZmRSkpSvJ CM9tmVn6qx+qa7g9L4KDIyxJF6AFxJ+D47vYNkAUx/aAlv/Ddt9ShCdNR3HSMfCLaFtE HpSICNLfmOIHXf3ts2Zhf52CpqMwSAYiaqVTZeXXPWjmtKF8j/h/e5ciysQZUYyMBewz F6CP75i+qXx2TJbjKK5Xdcdeiu7jL3322pwlO9k43iLJHLMsKcjD7ouygaF13KzcQ3Hq 7lsVpwsl/RV22/CUxNXZIP7pA5bjt7wIGmOA/ZNgF+hOqQOaqOfRvgHYwas7RWmiXkEN oPPQ== X-Gm-Message-State: ALyK8tJl1yXXdxcE3Hq3S1wTzlprb81BlaTFVnl0AmTZYraBopVyDB6PS8Yqf2K0IwrU3g== X-Received: by 10.28.214.73 with SMTP id n70mr9508934wmg.13.1466408085645; Mon, 20 Jun 2016 00:34:45 -0700 (PDT) Received: from yigal-pc.plexistor.com.localdomain ([207.232.55.62]) by smtp.gmail.com with ESMTPSA id wb10sm62180079wjc.8.2016.06.20.00.34.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 00:34:43 -0700 (PDT) From: Yigal Korman To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86/mm: only allow memmap=XX!YY over existing RAM Date: Mon, 20 Jun 2016 10:33:59 +0300 Message-Id: <1466408039-7497-1-git-send-email-yigal@plexistor.com> X-Mailer: git-send-email 1.9.3 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Before this patch, passing a range that is beyond the physical memory range will succeed, the user will see a /dev/pmem0 and will be able to access it. Reads will always return 0 and writes will be silently ignored. I've gotten more than one bug report about mkfs.{xfs,ext4} or nvml failing that were eventually tracked down to be wrong values passed to memmap. This patch prevents the above issue by instead of adding a new memory range, only update a RAM memory range with the PRAM type. This way, passing the wrong memmap will either not give you a pmem at all or give you a smaller one that actually has RAM behind it. And if someone still needs to fake a pmem that doesn't have RAM behind it, they can simply do memmap=XX@YY,XX!YY. Signed-off-by: Yigal Korman Acked-by: Dan Williams Acked-by: Johannes Thumshirn Tested-by: Boaz Harrosh --- arch/x86/kernel/e820.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 621b501..4bd4207 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -878,7 +878,7 @@ static int __init parse_memmap_one(char *p) e820_add_region(start_at, mem_size, E820_RESERVED); } else if (*p == '!') { start_at = memparse(p+1, &p); - e820_add_region(start_at, mem_size, E820_PRAM); + e820_update_range(start_at, mem_size, E820_RAM, E820_PRAM); } else e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);