Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp194028imm; Tue, 14 Aug 2018 17:02:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwHfLrxy2wc6pua4d0ykP6Zp2qmLlYNiPSt1wF7eTeHrtHNsvcEIZ9ulWkE1i8nCe9pkdO9 X-Received: by 2002:a62:9cd7:: with SMTP id u84-v6mr25563682pfk.90.1534291367408; Tue, 14 Aug 2018 17:02:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534291367; cv=none; d=google.com; s=arc-20160816; b=OtpR+V4r0sJBRa7YsotfxE7kS2sB6KwmNz7KEw5fvO3iCWj84SfuE2ykLtV9gnyhPn +5diWzl8jT3qg5cClCSgzlXnChu5W74FNRUOJcmquS3eKFQVIV1geQzacTklOO3XY/DV xy1h2gmKCx7OmOP6/VyQIGWCVsEV8yt2AJSBDGWQEH2HrjViA+viJ0K5lsEWVryL5aYC TsxFOgYBoAibA4aGbOjKzjNLPky78/b0Tl/H8Xokkry7prLiN1l4b0Bm4ZyHW4IqqKJk JjeK7PD/6ZdvYPoQ1LcXroyl/KluFwmkTsOpbj4fFkSqJBSXVcUG3i2sTjvNibX2JCC0 O94Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=TjBbYw3cFiY8mZloTMS2iTIORWvNHLIcrS+6TBIACts=; b=vXT3Hx1QQJebl9tbgmzSSfKn4xN57Ns4J5jwraMMlzIc5cZuRRJwHn4ODuzdFqdfEB /8WohTFD5vPD8YuQ43k+hH/laHKiihWbpZXxuq7XoS183iC0sTzKIX24NRXpYQZSZn/i nuWK8baCeSoCgIJxAqhx/K8jhjLXdy17fNXdk8LE486W8cW+F5C1DnjEXLw6FO7x2N9T MTqDAsWKdzi3v3zqheA4+nreeuTDPu2g1GDoZ7Fx96HdrKjF9A53yrDipGb+h3PG0kun mVsfVnIE1YMYVbsGgttqOKKoFTyAsPt+1dGTFdkfBjFKrrFiDf1Yiurku46FXqcRNslI 7DGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=HFK16bZR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64-v6si5897131pli.56.2018.08.14.17.02.32; Tue, 14 Aug 2018 17:02:47 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=HFK16bZR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbeHOCvS (ORCPT + 99 others); Tue, 14 Aug 2018 22:51:18 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:58062 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726375AbeHOCvS (ORCPT ); Tue, 14 Aug 2018 22:51:18 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7ENsvpL059074; Wed, 15 Aug 2018 00:01:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=TjBbYw3cFiY8mZloTMS2iTIORWvNHLIcrS+6TBIACts=; b=HFK16bZRXrlfHmt+6BGo3QpOHfdH5XX8oz5EFlkia5utS7ys009Hf9EjTJcreawyn+FM A6Tncmbh3KZSd8Ks/6LaMwDDplshksdJCi7Ys87EuxE1ZZoPkL4i5DABer2hRVVRt0Xf Tdvzmgrc/TpXXN+s0bn1OLsYg1JIBpDylR7hl1rB1VXupD62cNq5a/FRd3a/q8rxwepF aWR8pia84VrJgmXmryicaJvn5T7Se9lw5QmBgzbEpMozcqjTrEu/7L7my/FfLt96TBZz WCsftVkkr9m/iO7k1JM3FNfHVO6FwsfYqiAg2kHolEClrdmPgPjwLUXA/KRr3K/HqTbe CQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2ksreq2mub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Aug 2018 00:01:38 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7F01bxZ025232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Aug 2018 00:01:37 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7F01aSc020839; Wed, 15 Aug 2018 00:01:36 GMT Received: from hwillard-linux.us.oracle.com (/10.211.52.73) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 14 Aug 2018 17:01:36 -0700 From: Henry Willard To: , Cc: , , Subject: [PATCH] cpufreq: governor: Protect cpufreq governor_data Date: Tue, 14 Aug 2018 17:01:02 -0700 Message-Id: <1534291262-4207-1-git-send-email-henry.willard@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8985 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=832 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808140239 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 1.8.3.1