From patchwork Wed Sep 14 20:26:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Blanchard X-Patchwork-Id: 114703 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 95B75B7481 for ; Thu, 15 Sep 2011 06:26:32 +1000 (EST) Received: from kryten (unknown [32.97.110.52]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id 53222B6F99; Thu, 15 Sep 2011 06:26:19 +1000 (EST) Date: Thu, 15 Sep 2011 06:26:15 +1000 From: Anton Blanchard To: gregkh@suse.de, nfont@austin.ibm.com Subject: [PATCH] memory hotplug: Refuse to add unaligned memory regions Message-ID: <20110915062615.782bc4df@kryten> X-Mailer: Claws Mail 3.7.8 (GTK+ 2.24.4; i686-pc-linux-gnu) Mime-Version: 1.0 Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org The sysfs memory probe interface allows unaligned regions to be added: # echo 0xffffff > /sys/devices/system/memory/probe # cat /proc/iomem 00ffffff-01fffffe : System RAM 01ffffff-02fffffe : System RAM 02ffffff-03fffffe : System RAM 03ffffff-04fffffe : System RAM 04ffffff-05fffffe : System RAM Return -EINVAL instead of creating these bad regions. Signed-off-by: Anton Blanchard Index: linux-build/drivers/base/memory.c =================================================================== --- linux-build.orig/drivers/base/memory.c 2011-08-11 08:25:55.005941391 +1000 +++ linux-build/drivers/base/memory.c 2011-08-11 08:28:27.938580440 +1000 @@ -380,9 +380,13 @@ memory_probe_store(struct class *class, u64 phys_addr; int nid; int i, ret; + unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block; phys_addr = simple_strtoull(buf, NULL, 0); + if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) + return -EINVAL; + for (i = 0; i < sections_per_block; i++) { nid = memory_add_physaddr_to_nid(phys_addr); ret = add_memory(nid, phys_addr,