From patchwork Mon Nov 26 18:10:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Baltieri X-Patchwork-Id: 1805861 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id F29F03FC54 for ; Mon, 26 Nov 2012 18:11:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932141Ab2KZSLR (ORCPT ); Mon, 26 Nov 2012 13:11:17 -0500 Received: from mail-ee0-f46.google.com ([74.125.83.46]:35891 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932171Ab2KZSKb (ORCPT ); Mon, 26 Nov 2012 13:10:31 -0500 Received: by mail-ee0-f46.google.com with SMTP id e53so4643012eek.19 for ; Mon, 26 Nov 2012 10:10:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=Boy+xS5WlfR/O5bygEW1GFJ8rjNH88Y5yWfjEm+nm1c=; b=YseH8jgZXYgfttGH7cRiUzGgmeFmKEXgmNvxquUzBTHnWmTJqmof6aTvzeUOfR/tfd l5ybECkxZe7DTZgaPSRQuTfpyjV3A+MjtlmrGear+Wr6rZi15aOVs/Je5JQ1idOMU82j n694wUoEmxxho8plnWi/F4I1/AyeKptEJ+tFBYoeWEm0wbj0jH99BOKnkBcMBqZsDUsv WtPtYSlzlK6f5acnZQz59s6ZwE6JDSkLd0RFCj7a0s+GUiNLF09smfOEIXy8QP701Y3Q FVu21f3YGHktOjmnD0sLgokg5t+PhAzR+ehoRs+dZIx3WL5H48nmZ3MTm39Cn8RjMuOa bXkQ== Received: by 10.14.173.69 with SMTP id u45mr24685339eel.21.1353953429923; Mon, 26 Nov 2012 10:10:29 -0800 (PST) Received: from localhost ([2a01:2029:1:1304:8e70:5aff:feac:ad8]) by mx.google.com with ESMTPS id b2sm4079555eep.9.2012.11.26.10.10.26 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 26 Nov 2012 10:10:29 -0800 (PST) From: Fabio Baltieri To: "Rafael J. Wysocki" , cpufreq@vger.kernel.org, linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Fabio Baltieri Subject: [PATCH] cpufreq: ondemand: update sampling rate only on right CPUs Date: Mon, 26 Nov 2012 19:10:12 +0100 Message-Id: <1353953412-20667-1-git-send-email-fabio.baltieri@linaro.org> X-Mailer: git-send-email 1.7.12.1 X-Gm-Message-State: ALoCoQmGQNzD+hxIggFRdtb0uBEESihR+gDxjS8p1+hEIFMBwwxiXSVtzshQmVUl0F5D8Z24mpkW Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Fix cpufreq_gov_ondemand to skip CPU where another governor is used. The bug present itself as NULL pointer access on the mutex_lock() call, an can be reproduced on an SMP machine by setting the default governor to anything other than ondemand, setting a single CPU's governor to ondemand, then changing the sample rate by writing on: > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate Backtrace: Nov 26 17:36:54 balto kernel: [ 839.585241] BUG: unable to handle kernel NULL pointer dereference at (null) Nov 26 17:36:54 balto kernel: [ 839.585311] IP: [] __mutex_lock_slowpath+0xb2/0x170 [snip] Nov 26 17:36:54 balto kernel: [ 839.587005] Call Trace: Nov 26 17:36:54 balto kernel: [ 839.587030] [] mutex_lock+0x22/0x40 Nov 26 17:36:54 balto kernel: [ 839.587067] [] store_sampling_rate+0xbf/0x150 Nov 26 17:36:54 balto kernel: [ 839.587110] [] ? __do_page_fault+0x1cc/0x4c0 Nov 26 17:36:54 balto kernel: [ 839.587153] [] kobj_attr_store+0xf/0x20 Nov 26 17:36:54 balto kernel: [ 839.587192] [] sysfs_write_file+0xcd/0x140 Nov 26 17:36:54 balto kernel: [ 839.587234] [] vfs_write+0xac/0x180 Nov 26 17:36:54 balto kernel: [ 839.587271] [] sys_write+0x52/0xa0 Nov 26 17:36:54 balto kernel: [ 839.587306] [] ? do_page_fault+0xe/0x10 Nov 26 17:36:54 balto kernel: [ 839.587345] [] system_call_fastpath+0x16/0x1b Signed-off-by: Fabio Baltieri --- Hi Rafael, this is based on a clean linux-pm linux-next branch (i.e. not with my other patch-set applied), so expect a context conflict if both are applied. Thanks, Fabio drivers/cpufreq/cpufreq_ondemand.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index cca3e9f..7731f7c 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c @@ -40,6 +40,10 @@ static struct dbs_data od_dbs_data; static DEFINE_PER_CPU(struct od_cpu_dbs_info_s, od_cpu_dbs_info); +#ifndef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND +static struct cpufreq_governor cpufreq_gov_ondemand; +#endif + static struct od_dbs_tuners od_tuners = { .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, @@ -279,6 +283,10 @@ static void update_sampling_rate(unsigned int new_rate) policy = cpufreq_cpu_get(cpu); if (!policy) continue; + if (policy->governor != &cpufreq_gov_ondemand) { + cpufreq_cpu_put(policy); + continue; + } dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu); cpufreq_cpu_put(policy);