From patchwork Mon Oct 20 17:03:53 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Travis X-Patchwork-Id: 5117 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 175CE483D5 for ; Tue, 21 Oct 2008 04:22:27 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from relay.sgi.com (relay1.sgi.com [192.48.171.29]) by ozlabs.org (Postfix) with ESMTP id 8EDBBDDF67 for ; Tue, 21 Oct 2008 04:03:29 +1100 (EST) Received: from polaris-admin.engr.sgi.com (polaris-admin.engr.sgi.com [192.102.97.111]) by relay1.corp.sgi.com (Postfix) with ESMTP id 63AE88F8128; Mon, 20 Oct 2008 10:03:24 -0700 (PDT) Received: by polaris-admin.engr.sgi.com (Postfix, from userid 5508) id 61AF9517CAF8; Mon, 20 Oct 2008 10:03:24 -0700 (PDT) Message-Id: <20081020170324.280990000@polaris-admin.engr.sgi.com> References: <20081020170319.539427000@polaris-admin.engr.sgi.com> User-Agent: quilt/0.46-1 Date: Mon, 20 Oct 2008 10:03:53 -0700 From: Mike Travis To: Ingo Molnar , Rusty Russell Subject: [PATCH 34/35] cpumask: debug options for cpumasks Content-Disposition: inline; filename=cpumask:check-all-ops-for-limits.patch Cc: davej@codemonkey.org.uk, Jeremy Fitzhardinge , Jes Sorensen , IA64 , S390 , peterz@infradead.org, Jack Steiner , linux-kernel@vger.kernel.org, Eric Dumazet , PowerPC , Andi Kleen , Thomas Gleixner , Yinghai Lu , "H. Peter Anvin" , SPARC , Andrew Morton , David Miller X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org It's useful to check that no one is accessing > nr_cpumask_bits for cpumasks. This also allows you to turn on CONFIG_CPUMASKS_OFFSTACK even for smaller CONFIG_NR_CPUS. From: Rusty Russell Signed-off-by: Rusty Russell Signed-off-by: Mike Travis --- include/linux/cpumask.h | 23 +++++++++++++++++------ lib/Kconfig.debug | 6 ++++++ lib/cpumask.c | 3 +++ 3 files changed, 26 insertions(+), 6 deletions(-) --- test-compile.orig/include/linux/cpumask.h +++ test-compile/include/linux/cpumask.h @@ -217,23 +217,34 @@ extern cpumask_t _unused_cpumask_arg_; } #endif /* CONFIG_NR_CPUS > BITS_PER_LONG */ +/* verify cpu argument to cpumask_* operators */ +static inline unsigned int cpumask_check(unsigned int cpu) +{ +#ifdef CONFIG_DEBUG_PER_CPU_MAPS + /* This breaks at runtime. */ + BUG_ON(cpu >= nr_cpumask_bits); +#endif /* CONFIG_DEBUG_PER_CPU_MAPS */ + return cpu; +} + /* cpumask_* operators */ static inline void cpumask_set_cpu(int cpu, volatile struct cpumask *dstp) { - set_bit(cpu, cpumask_bits(dstp)); + set_bit(cpumask_check(cpu), cpumask_bits(dstp)); } static inline void cpumask_clear_cpu(int cpu, volatile struct cpumask *dstp) { - clear_bit(cpu, cpumask_bits(dstp)); + clear_bit(cpumask_check(cpu), cpumask_bits(dstp)); } /* No static inline type checking - see Subtlety (1) above. */ -#define cpumask_test_cpu(cpu, cpumask) test_bit((cpu), (cpumask)->bits) +#define cpumask_test_cpu(cpu, cpumask) \ + test_bit(cpumask_check(cpu), (cpumask)->bits) static inline int cpumask_test_and_set_cpu(int cpu, struct cpumask *addr) { - return test_and_set_bit(cpu, cpumask_bits(addr)); + return test_and_set_bit(cpumask_check(cpu), cpumask_bits(addr)); } static inline void cpumask_setall(struct cpumask *dstp) @@ -367,8 +378,8 @@ static inline int cpumask_cpuremap(int o const struct cpumask *oldp, const struct cpumask *newp) { - return bitmap_bitremap(oldbit, cpumask_bits(oldp), cpumask_bits(newp), - nr_cpumask_bits); + return bitmap_bitremap(cpumask_check(oldbit), cpumask_bits(oldp), + cpumask_bits(newp), nr_cpumask_bits); } static inline void cpumask_remap(struct cpumask *dstp, --- test-compile.orig/lib/Kconfig.debug +++ test-compile/lib/Kconfig.debug @@ -766,6 +766,12 @@ config SYSCTL_SYSCALL_CHECK to properly maintain and use. This enables checks that help you to keep things correct. +config DEBUG_PER_CPU_MAPS + bool "Cpumask debug checks" + ---help--- + Extra debugging for cpumasks. + eg. to make sure accesses to cpumasks are < nr_cpu_ids. + source kernel/trace/Kconfig config PROVIDE_OHCI1394_DMA_INIT --- test-compile.orig/lib/cpumask.c +++ test-compile/lib/cpumask.c @@ -11,6 +11,9 @@ EXPORT_SYMBOL(cpumask_first); int cpumask_next(int n, const cpumask_t *srcp) { + /* -1 is a legal arg here. */ + if (n != -1) + cpumask_check(n); return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1); } EXPORT_SYMBOL(cpumask_next);