Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp522698pxu; Thu, 7 Jan 2021 10:49:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCTK85JLza/RzdJP81KqtV5dwholLEwCTy9YiJdAFILMLmW+Zglx8NPl8tMm8tYh5AtAIW X-Received: by 2002:a50:cd57:: with SMTP id d23mr2644826edj.95.1610045340720; Thu, 07 Jan 2021 10:49:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610045340; cv=none; d=google.com; s=arc-20160816; b=SM1j7GqPd+J8n3LgLaNIY5WyR0E0V8H+8zF7m/3swYYQRkh9fsipbGgzMsvM+J53Qj zgMWtyrn2OvNoEuF2q3K3lug3IjPuMcmmOvbqYP/IbVD5lpfTyv/9CTUZF9m2i9rr9v4 d7WZPA9OozyYKhrYPsGMewcFAQ6Sj50uF3gfL7A7qFmr+ul3B7CNIumgF2sKobdjmc6+ ngBaa6Ux6B5vHrnKirSdg1thpNLeNxowXzYh1UhkVCZMKwblxB+D7ClrUYDGEG213Ubh qXvqDBB9V/CvLvL06y4CRdndw01e+buKct9qJP4l7JjwEzzrM7BzB4riAhcExBUyXrZ+ tCwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UrFde48EqHYB4Gxzlr0U1Dl3oGTSUpyAQFzTvAw2k18=; b=Y0ZjMNb7yw6JxyA0IGwvWl0z6R7Q8EwHeJS/igMusHyf+IG4pervfBTWQqSS2oWDiZ Rsbectt3H0J1q8pFmLH76HDx5X5LPhl5etrQmV00hovY8TABFf46WEmI3hHXSuKUWvKF JtH2MfKCCyTpiedjI4QlTk7PQU9dHh3NL1aFjpxX8LFEQfwnCUpMYrfXhJqspolukPmp qYBVsQfAn8e8pJNkx3a1mNN6FjSP/hOscV4H5pO+xO61/O5zyiJcCfx/PjFnxUECKrPi 6P2fxIRWx/fCUwjazl+NEBnoOrceoN1PXAZ2ssDGRhULasMXDUPSaxiv0MEX/+4boQl7 CZ9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si2608046ejy.327.2021.01.07.10.48.37; Thu, 07 Jan 2021 10:49:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729279AbhAGSpQ (ORCPT + 99 others); Thu, 7 Jan 2021 13:45:16 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:53232 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729259AbhAGSpO (ORCPT ); Thu, 7 Jan 2021 13:45:14 -0500 Received: from 89-64-81-64.dynamic.chello.pl (89.64.81.64) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.537) id c4c52b1d753055a3; Thu, 7 Jan 2021 19:44:32 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Srinivas Pandruvada , Chen Yu Subject: [PATCH v1 1/3] cpufreq: intel_pstate: Always read hwp_cap_cached with READ_ONCE() Date: Thu, 07 Jan 2021 19:42:15 +0100 Message-ID: <1993550.StjdRojnlU@kreacher> In-Reply-To: <5701645.lOV4Wx5bFT@kreacher> References: <5701645.lOV4Wx5bFT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Because intel_pstate_get_hwp_max() which updates hwp_cap_cached may run in parallel with the readers of it, annotate all of the read accesses to it with READ_ONCE(). Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/intel_pstate.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -914,7 +914,7 @@ static void intel_pstate_hwp_offline(str } value &= ~GENMASK_ULL(31, 0); - min_perf = HWP_LOWEST_PERF(cpu->hwp_cap_cached); + min_perf = HWP_LOWEST_PERF(READ_ONCE(cpu->hwp_cap_cached)); /* Set hwp_max = hwp_min */ value |= HWP_MAX_PERF(min_perf); @@ -1750,6 +1750,7 @@ static int hwp_boost_hold_time_ns = 3 * static inline void intel_pstate_hwp_boost_up(struct cpudata *cpu) { u64 hwp_req = READ_ONCE(cpu->hwp_req_cached); + u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached); u32 max_limit = (hwp_req & 0xff00) >> 8; u32 min_limit = (hwp_req & 0xff); u32 boost_level1; @@ -1776,14 +1777,14 @@ static inline void intel_pstate_hwp_boos cpu->hwp_boost_min = min_limit; /* level at half way mark between min and guranteed */ - boost_level1 = (HWP_GUARANTEED_PERF(cpu->hwp_cap_cached) + min_limit) >> 1; + boost_level1 = (HWP_GUARANTEED_PERF(hwp_cap) + min_limit) >> 1; if (cpu->hwp_boost_min < boost_level1) cpu->hwp_boost_min = boost_level1; - else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(cpu->hwp_cap_cached)) - cpu->hwp_boost_min = HWP_GUARANTEED_PERF(cpu->hwp_cap_cached); - else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(cpu->hwp_cap_cached) && - max_limit != HWP_GUARANTEED_PERF(cpu->hwp_cap_cached)) + else if (cpu->hwp_boost_min < HWP_GUARANTEED_PERF(hwp_cap)) + cpu->hwp_boost_min = HWP_GUARANTEED_PERF(hwp_cap); + else if (cpu->hwp_boost_min == HWP_GUARANTEED_PERF(hwp_cap) && + max_limit != HWP_GUARANTEED_PERF(hwp_cap)) cpu->hwp_boost_min = max_limit; else return;