Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3644446imm; Mon, 20 Aug 2018 02:11:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPygp1MgyQr0+kmHKGPYg8TyXF1xzu9na4bJQ+cdO2ud8FG5NPEoRMWFfUdR4o+SiIpsGAxD X-Received: by 2002:a17:902:561:: with SMTP id 88-v6mr44045274plf.320.1534756286240; Mon, 20 Aug 2018 02:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534756286; cv=none; d=google.com; s=arc-20160816; b=NmdDAHL+UGtZCnLNJIuTxGi9Sg0FHVKPB8LrOGfq4GzuJpSu2oTW2kiLGXnQRbWRgs ZYaSbDJNckzX9s/Jywgo93asjMZj1cqO6DM/YPq92l7b8ee0gTQY9rqUydu8QZh2pUPO mBzcsDQ7xbwtdb4u3exm1245dHB4VoluyGU/MFCHUvqAzrWAuCxGwshcHAofRPebCV9j zauepWoblvmzZTeddPuemLddHlWZb1ZuA6w6xiT6ikuGY53XDbrrRxBQs3l0Zi41xA7b jQAvt4ToqSNHH+toppnbYZ7Z7SjPGgK5ieDo8oDcieZlH6ayGLQqxkuk7jd808n6ICor aU7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5xmGoUK6xJF7Sq+G8aAwE9OhxfFRT5CZyMEOmSUlmgs=; b=tNjtmGVk2l4it9HGW9GefoF0z+yDQGNhI4hh46hsqrmWH1WAT0LIwo/pkmGLd3jhz5 LY3WYLNYX0ecSVUqnPGsTCk8ok0++zHDXLg5vp93/WGK+jpvenlp6wewP7S6ZiqIvcrS c/eFGqynDTBUKE2Ue7vWr3I4J2XeGPZJUHjoB/Mxn6nVLQpcH+txhMFOMHTP1rcDz2v6 SKK+FpDn/SL4PDgjOGZEIBUKEUwh8E7R5ODFNOEqzvrFkGGDM6sW294rAOQ+kwQYP+d1 J5nCK9Pmkbiw4NxVincu4jq/87fvTtLNyyeDx6XDcIrJE9RqqE38GHhE8ubxuCHg5CnC bTgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11-v6si8963544plz.333.2018.08.20.02.11.10; Mon, 20 Aug 2018 02:11:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726217AbeHTMYz (ORCPT + 99 others); Mon, 20 Aug 2018 08:24:55 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:55918 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbeHTMYz (ORCPT ); Mon, 20 Aug 2018 08:24:55 -0400 Received: from 79.184.253.33.ipv4.supernova.orange.pl (79.184.253.33) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 46afced0d44f25f0; Mon, 20 Aug 2018 11:10:05 +0200 From: "Rafael J. Wysocki" To: Henry Willard Cc: viresh.kumar@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] cpufreq: governor: Protect cpufreq governor_data Date: Mon, 20 Aug 2018 11:07:49 +0200 Message-ID: <2923321.jmYcvy9DfS@aspire.rjw.lan> In-Reply-To: <1534291262-4207-1-git-send-email-henry.willard@oracle.com> References: <1534291262-4207-1-git-send-email-henry.willard@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, August 15, 2018 2:01:02 AM CEST Henry Willard wrote: > If cppc_cpufreq.ko is deleted at the same time that tuned-adm is > changing profiles, there is a small chance that a race can occur > between cpufreq_dbs_governor_exit() and cpufreq_dbs_governor_limits() > resulting in a system failure when the latter tries to use > policy->governor_data that has been freed by the former. > > This patch uses gov_dbs_data_mutex to synchronize access. > > Signed-off-by: Henry Willard > --- > drivers/cpufreq/cpufreq_governor.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c > index 1d50e97d49f1..43416ee55849 100644 > --- a/drivers/cpufreq/cpufreq_governor.c > +++ b/drivers/cpufreq/cpufreq_governor.c > @@ -555,12 +555,20 @@ void cpufreq_dbs_governor_stop(struct cpufreq_policy *policy) > > void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy) > { > - struct policy_dbs_info *policy_dbs = policy->governor_data; > + struct policy_dbs_info *policy_dbs; > + > + /* Protect gov->gdbs_data against cpufreq_dbs_governor_exit */ > + mutex_lock(&gov_dbs_data_mutex); > + policy_dbs = policy->governor_data; > + if (!policy_dbs) > + goto out; > > mutex_lock(&policy_dbs->update_mutex); > cpufreq_policy_apply_limits(policy); > gov_update_sample_delay(policy_dbs, 0); > > mutex_unlock(&policy_dbs->update_mutex); > +out: > + mutex_unlock(&gov_dbs_data_mutex); > } > EXPORT_SYMBOL_GPL(cpufreq_dbs_governor_limits); > Applied, thanks!