From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964779AbWDUVLN (ORCPT ); Fri, 21 Apr 2006 17:11:13 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932481AbWDUVLN (ORCPT ); Fri, 21 Apr 2006 17:11:13 -0400 Received: from gateway-1237.mvista.com ([63.81.120.158]:10353 "EHLO gateway-1237.mvista.com") by vger.kernel.org with ESMTP id S932480AbWDUVLM (ORCPT ); Fri, 21 Apr 2006 17:11:12 -0400 Subject: Re: kfree(NULL) From: Daniel Walker To: Hua Zhong Cc: akpm@osdl.org, jmorris@namei.org, linux-kernel@vger.kernel.org In-Reply-To: <4449486F.8020108@gmail.com> References: <4449486F.8020108@gmail.com> Content-Type: text/plain Date: Fri, 21 Apr 2006 14:11:08 -0700 Message-Id: <1145653868.20843.31.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org I've been working on some code that records all the data for output to a proc entry . It's pretty light weight .. I'll send it once it's finished .. Daniel On Fri, 2006-04-21 at 14:02 -0700, Hua Zhong wrote: > Maybe something like this might be a useful debug option to detect unwise likely()/unlikely() usage? > > This is a quick hack (not submitted for inclusion), but it works on my box and detected certain points after boot. Anyone likes this idea? > > The reason I had to add printk_debug_likely() is that using printk directly gives compile error. It seems not to like asmlinkage for some reason..I guess likely/unlikely are too fundamental macros and the dependency gets too messy. Or maybe it could be fixed in a way I've not found. > > It increases kernel size by about 10%, but hey, it's a debugg option. :-) > > Sample print: > > possible (un)likely misuse at include/asm/mmu_context.h:32/switch_mm() > printk_debug_likely+0x25/0x31 schedule+0xb04/0xefa > __mutex_lock_slowpath+0x35a/0x89e real_lookup+0x1f/0xb3 > real_lookup+0x1f/0xb3 do_lookup+0x50/0xe8 > __link_path_walk+0xba1/0x125f link_path_walk+0x9d/0x166 > __handle_mm_fault+0x2fd/0x35b _atomic_dec_and_lock+0x22/0x2c > __link_path_walk+0x1018/0x125f link_path_walk+0x9d/0x166 > __handle_mm_fault+0x2fd/0x35b strncpy_from_user+0x94/0xb3 > do_path_lookup+0x35c/0x4d2 __user_walk_fd+0x84/0x9b > vfs_stat_fd+0x15/0x3c __handle_mm_fault+0x2fd/0x35b > sys_stat64+0xf/0x23 do_page_fault+0x30d/0x753 > copy_to_user+0x113/0x11c sys_rt_sigprocmask+0xae/0xc1 > sysenter_past_esp+0x54/0x75 > possible (un)likely misuse at kernel/sched.c:1638/context_switch() > printk_debug_likely+0x25/0x31 schedule+0xa97/0xefa > do_exit+0x75b/0x765 sys_exit_group+0x0/0xd > sysenter_past_esp+0x54/0x75 > possible (un)likely misuse at kernel/softlockup.c:59/softlockup_tick() > printk_debug_likely+0x25/0x31 softlockup_tick+0x88/0xf5 > update_process_times+0x35/0x57 timer_interrupt+0x3d/0x60 > handle_IRQ_event+0x21/0x4a __do_IRQ+0x132/0x1e7 > do_IRQ+0x9c/0xab common_interrupt+0x1a/0x20 > possible (un)likely misuse at kernel/sched.c:1645/context_switch() > printk_debug_likely+0x25/0x31 schedule+0xca8/0xefa > enqueue_hrtimer+0x5b/0x80 do_nanosleep+0x3b/0xc0 > hrtimer_nanosleep+0x45/0xe6 sys_lstat64+0xf/0x23 > hrtimer_wakeup+0x0/0x18 copy_from_user+0x11b/0x142 > sys_nanosleep+0x46/0x4e sysenter_past_esp+0x54/0x75 > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index f23d3c6..a6df5f7 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -58,9 +58,32 @@ #endif > * build go below this comment. Actual compiler/compiler version > * specific implementations come from the above header files > */ > +#define CONFIG_DEBUG_LIKELY > +#ifdef CONFIG_DEBUG_LIKELY > +extern int printk_debug_likely(const char *fmt, ...); > +extern int debug_likely_count_min_thresh; > +extern int debug_likely_print_max_thresh; > +#define __check_likely(x, v, uv) \ > + ({ static int _ckl_print_nr = 0; \ > + static unsigned int _ckl_s[2]; \ > + int _ckl_r = !!(x); \ > + _ckl_s[_ckl_r]++; \ > + if ((_ckl_s[v] == _ckl_s[uv]) && (_ckl_s[v] > debug_likely_count_min_thresh) \ > + && (_ckl_print_nr < debug_likely_print_max_thresh)) { \ > + _ckl_print_nr++; \ > + printk_debug_likely("possible (un)likely misuse at %s:%d/%s()\n", \ > + __FILE__, __LINE__, __FUNCTION__); \ > + } \ > + _ckl_r; }) > +#else > +#define __check_likely(x, v, uv) __builtin_expect(!!(x), v) > +#endif > + > +#define likely(x) __check_likely(x, 1, 0) > +#define unlikely(x) __check_likely(x, 0, 1) > > -#define likely(x) __builtin_expect(!!(x), 1) > -#define unlikely(x) __builtin_expect(!!(x), 0) > +//#define likely(x) __builtin_expect(!!(x), 1) > +//#define unlikely(x) __builtin_expect(!!(x), 0) > > /* Optimization barrier */ > #ifndef barrier > diff --git a/kernel/printk.c b/kernel/printk.c > index c056f33..cc09dca 100644 > --- a/kernel/printk.c > +++ b/kernel/printk.c > @@ -602,6 +602,30 @@ out: > EXPORT_SYMBOL(printk); > EXPORT_SYMBOL(vprintk); > > +#ifdef CONFIG_DEBUG_LIKELY > +int debug_likely_count_min_thresh = 100; > +int debug_likely_print_max_thresh = 1; > +int printk_debug_likely(const char *fmt, ...) > +{ > + int r = 0; > + static atomic_t recurse = ATOMIC_INIT(1); /* as a mutex */ > + if (atomic_dec_and_test(&recurse)) { > + va_list args; > + > + va_start(args, fmt); > + r = vprintk(fmt, args); > + va_end(args); > + dump_stack(); > + } > + atomic_inc(&recurse); > + > + return r; > +} > +EXPORT_SYMBOL(debug_likely_count_min_thresh); > +EXPORT_SYMBOL(debug_likely_print_max_thresh); > +EXPORT_SYMBOL(printk_debug_likely); > +#endif > + > #else > > asmlinkage long sys_syslog(int type, char __user *buf, int len) > >