From patchwork Fri Dec 14 10:59:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 1878151 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 24D94DF230 for ; Fri, 14 Dec 2012 10:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752282Ab2LNK7b (ORCPT ); Fri, 14 Dec 2012 05:59:31 -0500 Received: from mail-la0-f46.google.com ([209.85.215.46]:46248 "EHLO mail-la0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323Ab2LNK73 (ORCPT ); Fri, 14 Dec 2012 05:59:29 -0500 Received: by mail-la0-f46.google.com with SMTP id p5so2677865lag.19 for ; Fri, 14 Dec 2012 02:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:from:cc:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; bh=zlAXwCds7Pcn+MY+2BdMSzKvZBtOxG74wa/tZJE84Ow=; b=hrsF98xWduKFIXYJcGZzZFMlCExkPx7Z37aKaTMTYkEslWVpz3lSXzbJY8BIE1Cdrt nVbrqMcjTHonnPWFK7qUm9cklqCSMIlgbu5Aai/4a0pz1cQ61RJ0Yimdk7cnFx6Q5Jwl NMDoNsAVviSHpf/pJgflvj4EZSDULcK3eaG737VGlTeR9RTAUpMdp8icvEnrQ24ltEpO 73mK3EnHhDyoNgRCKFEsgrbIHsLumtXBLmCZGiD45wnp7WU37Wet4m6TYu+V+q5UzOap V+AZPRj4jAq4b8P0jL5RKfoegsrvFGM15MXkImhiMTLs5lvZt5G9H8jFpP/jhd0Lt4Nh x4ww== Received: by 10.112.17.194 with SMTP id q2mr2214126lbd.7.1355482767471; Fri, 14 Dec 2012 02:59:27 -0800 (PST) Received: from localhost (swsoft-msk-nat.sw.ru. [195.214.232.10]) by mx.google.com with ESMTPS id n7sm1753744lbz.5.2012.12.14.02.59.25 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Dec 2012 02:59:25 -0800 (PST) Subject: [PATCH] cpufreq_stats: fix race between stats allocation and first usage To: linux-kernel@vger.kernel.org From: Konstantin Khlebnikov Cc: "Rafael J. Wysocki" , cpufreq , linux-pm Date: Fri, 14 Dec 2012 14:59:21 +0400 Message-ID: <20121214105921.5139.502.stgit@zurg> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This patch forces complete struct cpufreq_stats allocation for all cpus before registering CPUFREQ_TRANSITION_NOTIFIER notifier, otherwise in some conditions cpufreq_stat_notifier_trans() can be called in the middle of stats allocation, in this case cpufreq_stats_table already exists, but stat->freq_table is NULL. Signed-off-by: Konstantin Khlebnikov Cc: Rafael J. Wysocki Cc: cpufreq Cc: linux-pm --- <1>[ 363.116198] BUG: unable to handle kernel NULL pointer dereference at (null) <1>[ 363.116668] IP: [] cpufreq_stat_notifier_trans+0x64/0xf0 [cpufreq_stats] <4>[ 363.116977] PGD 23177e067 PUD 2349c1067 PMD 0 <4>[ 363.117151] Oops: 0000 [#1] SMP <4>[ 363.117151] last sysfs file: /sys/module/freq_table/initstate <4>[ 363.117151] CPU 5 <4>[ 363.117151] Modules linked in: cpufreq_stats(+)(U) [a lot] [last unloaded: umc] <4>[ 363.117151] <4>[ 363.117151] Pid: 1690, comm: kondemand/5 veid: 0 Tainted: P WC --------------- T 2.6.32-279.5.1.el6-042stab061.7-vz #112 042stab061_7 System manufacturer System Product Name/Crosshair IV Formula <4>[ 363.117151] RIP: 0010:[] [] cpufreq_stat_notifier_trans+0x64/0xf0 [cpufreq_stats] <4>[ 363.117151] RSP: 0018:ffff880234281920 EFLAGS: 00010246 <4>[ 363.117151] RAX: 00000000001e12e8 RBX: 0000000000000000 RCX: 00000000002ab980 <4>[ 363.117151] RDX: 0000000000000004 RSI: 0000000000000000 RDI: 0000000000000005 <4>[ 363.117151] RBP: ffff880234281940 R08: 0000000000000000 R09: 0000000000000000 <4>[ 363.117151] R10: 0000000000000000 R11: 2222222222222222 R12: ffff880218ce7400 <4>[ 363.117151] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 <4>[ 363.117151] FS: 00007f499ffe0700(0000) GS:ffff880031000000(0000) knlGS:0000000000000000 <4>[ 363.117151] CS: 0010 DS: 0018 ES: 0018 CR0: 000000008005003b <4>[ 363.117151] CR2: 0000000000000000 CR3: 0000000230af7000 CR4: 00000000000006e0 <4>[ 363.117151] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 <4>[ 363.117151] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 <4>[ 363.117151] Process kondemand/5 (pid: 1690, veid: 0, threadinfo ffff880234280000, task ffff8802330c48c0) <4>[ 363.117151] Stack: <4>[ 363.117151] ffffffff810cf4f3 0000000000000001 00000000ffffffff ffffffffa11a7ac0 <4>[ 363.117151] ffff880234281990 ffffffff815454a8 ffff880234281c80 0000000000000000 <4>[ 363.117151] ffff880234281a10 ffffffff833be978 ffffffff833be8e0 0000000000000001 <4>[ 363.117151] Call Trace: <4>[ 363.117151] [] ? is_module_text_address+0x23/0x30 <4>[ 363.117151] [] notifier_call_chain+0x58/0xb0 <4>[ 363.117151] [] __srcu_notifier_call_chain+0x5d/0x90 <4>[ 363.117151] [] srcu_notifier_call_chain+0x16/0x20 <4>[ 363.117151] [] cpufreq_notify_transition+0x12a/0x190 <4>[ 363.117151] [] powernowk8_target+0x628/0xb30 [powernow_k8] <4>[ 363.117151] [] __cpufreq_driver_target+0x8b/0x90 <4>[ 363.117151] [] do_dbs_timer+0x3b8/0x3bc [cpufreq_ondemand] <4>[ 363.117151] [] ? do_dbs_timer+0x0/0x3bc [cpufreq_ondemand] <4>[ 363.117151] [] worker_thread+0x264/0x440 <4>[ 363.117151] [] ? worker_thread+0x213/0x440 <4>[ 363.117151] [] ? worker_thread+0x0/0x440 <4>[ 363.117151] [] ? autoremove_wake_function+0x0/0x40 <4>[ 363.117151] [] ? worker_thread+0x0/0x440 <4>[ 363.117151] [] kthread+0x96/0xa0 <4>[ 363.117151] [] child_rip+0xa/0x20 <4>[ 363.117151] [] ? restore_args+0x0/0x30 <4>[ 363.117151] [] ? kthread+0x0/0xa0 <4>[ 363.117151] [] ? child_rip+0x0/0x20 <4>[ 363.117151] Code: 89 f9 48 8b 0c cd 20 53 9c 81 4c 8b 24 08 4d 85 e4 74 d3 8b 4a 08 41 8b 54 24 10 45 8b 6c 24 18 85 d2 74 22 49 8b 74 24 28 31 db <3b> 0e 75 10 eb 1a 66 0f 1f 44 00 00 48 63 c3 3b 0c 86 74 0c 83 <1>[ 363.117151] RIP [] cpufreq_stat_notifier_trans+0x64/0xf0 [cpufreq_stats] <4>[ 363.117151] RSP <4>[ 363.117151] CR2: 0000000000000000 --- drivers/cpufreq/cpufreq_stats.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index e40e508..9d7732b 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -364,18 +364,21 @@ static int __init cpufreq_stats_init(void) if (ret) return ret; + register_hotcpu_notifier(&cpufreq_stat_cpu_notifier); + for_each_online_cpu(cpu) + cpufreq_update_policy(cpu); + ret = cpufreq_register_notifier(¬ifier_trans_block, CPUFREQ_TRANSITION_NOTIFIER); if (ret) { cpufreq_unregister_notifier(¬ifier_policy_block, CPUFREQ_POLICY_NOTIFIER); + unregister_hotcpu_notifier(&cpufreq_stat_cpu_notifier); + for_each_online_cpu(cpu) + cpufreq_stats_free_table(cpu); return ret; } - register_hotcpu_notifier(&cpufreq_stat_cpu_notifier); - for_each_online_cpu(cpu) { - cpufreq_update_policy(cpu); - } return 0; } static void __exit cpufreq_stats_exit(void)