From patchwork Wed Nov 17 19:44:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1556364 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Bop8X9xU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HvYL33Z0bz9s1l for ; Thu, 18 Nov 2021 06:44:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mnQrQ-0001MZ-Be; Wed, 17 Nov 2021 19:44:48 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mnQrO-0001MH-MZ for kernel-team@lists.ubuntu.com; Wed, 17 Nov 2021 19:44:46 +0000 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 1A3573F1AF for ; Wed, 17 Nov 2021 19:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1637178285; bh=nlBpyZwrjx1V+gxF8U1z4BzxT5fhgLtEft+NhutmoJI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Bop8X9xUvc5ZkE0VpoVoiTNOuImISwA+kVBzn8PnbiY0ojuy2a5SBFsVDUSPczoer eGzmDoSU8aii27rqxn47BAyhxcE8cIGsFVFtLJDIoIOe6qoZyGONoX9R1H+0p6enqE 82lmNedtdIWxjFC4/qbroVnRsK8AyT6HQXZTfqDPe1vgK6R/CiV397IzqW2SrgvLLU LlXVtdbmjS+/aLFQxSOOlj6VNlNLhrA/2KcqKkxppdXHVfw2AiTHRh/yRLoSPR3x2T YlR564zno3hWUXnvOjEZxvwuFdu0Lmz9Q342XV1KwP4mK72zJSBv2XmCXpRqUdGvFj NmXyqJx/iUqWA== Received: by mail-il1-f200.google.com with SMTP id h14-20020a056e021d8e00b002691dcecdbaso2481886ila.23 for ; Wed, 17 Nov 2021 11:44:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nlBpyZwrjx1V+gxF8U1z4BzxT5fhgLtEft+NhutmoJI=; b=wINkHxMg4u/3YaHZhv5QdJW4c6erXXnI7aWQ0cJblsOgN5xSsXchO3+lXZrU3ZVX/d qvOlDo1eSlFOlauUsq5T3XfmeE9Pktax2pf3hfla9CLdCErWIjGq+8cHCtb1cOTZyvwm /3o2IVM1EXRbPF98Yfycmx38j9/nAAl0MjWPMi/uOInK8GYZQnxuy9eDXUNSp9+p5CFJ ihfInh4/3Uf+3VEHIOmEWhDuPNyWkmEiexFP7lSR7/U8CA+QnpIlFpaZA4LJHq2GF6N9 ufpK/P4i9l5Ey2o5+x7SAz0StLjaSgiwYeZ59a5sgg35dR7uW4J0s55g0Ks/Z3PlMsqC Gcog== X-Gm-Message-State: AOAM531/yo9JDRoZVhKtMulJSF/VLRSC2SMbutTyW9htUClPse6FbxzS xwwVWX3wcSLfBIaXTLH0pjygubjyWlIBd8agYg0p7GYAngLKSYo4QcsoNezvwfu9fgeg9bBKLFB yyHu5GT+CHqs1PC2eDamdvxWVSrLvpiIt+IHrxhJsaw== X-Received: by 2002:a6b:e007:: with SMTP id z7mr13213840iog.58.1637178281874; Wed, 17 Nov 2021 11:44:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9quPxWO7ix0nAFctj+Yr4tEGqv6Z5+fWIr4j5PRv3LQJ51JF1kNHfSgQdqpvscAjeCgmOcg== X-Received: by 2002:a6b:e007:: with SMTP id z7mr13213820iog.58.1637178281619; Wed, 17 Nov 2021 11:44:41 -0800 (PST) Received: from localhost.localdomain ([108.175.235.223]) by smtp.gmail.com with ESMTPSA id o1sm448620ilj.41.2021.11.17.11.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 11:44:40 -0800 (PST) From: Philip Cox To: kernel-team@lists.ubuntu.com Subject: [SRU][H, I][PATCH 1/1] cpufreq: intel_pstate: Clear HWP desired on suspend/shutdown and offline Date: Wed, 17 Nov 2021 14:44:35 -0500 Message-Id: <20211117194435.175399-2-philip.cox@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211117194435.175399-1-philip.cox@canonical.com> References: <20211117194435.175399-1-philip.cox@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/1950584 Commit a365ab6b9dfb ("cpufreq: intel_pstate: Implement the ->adjust_perf() callback") caused intel_pstate to use nonzero HWP desired values in certain usage scenarios, but it did not prevent them from being leaked into the confugirations in which HWP desired is expected to be 0. The failing scenarios are switching the driver from the passive mode to the active mode and starting a new kernel via kexec() while intel_pstate is running in the passive mode. To address this issue, ensure that HWP desired will be cleared on offline and suspend/shutdown. Fixes: a365ab6b9dfb ("cpufreq: intel_pstate: Implement the ->adjust_perf() callback") Reported-by: Julia Lawall Tested-by: Julia Lawall Signed-off-by: Rafael J. Wysocki (cherry picked from commit dbea75fe18f60e364de6d994fc938a24ba249d81) Signed-off-by: Philip Cox Acked-by: Stefan Bader --- drivers/cpufreq/intel_pstate.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index d483383dcfb9..d2089adcebc3 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -910,9 +910,16 @@ static void intel_pstate_hwp_offline(struct cpudata *cpu) */ value &= ~GENMASK_ULL(31, 24); value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached); - WRITE_ONCE(cpu->hwp_req_cached, value); } + /* + * Clear the desired perf field in the cached HWP request value to + * prevent nonzero desired values from being leaked into the active + * mode. + */ + value &= ~HWP_DESIRED_PERF(~0L); + WRITE_ONCE(cpu->hwp_req_cached, value); + value &= ~GENMASK_ULL(31, 0); min_perf = HWP_LOWEST_PERF(cpu->hwp_cap_cached); @@ -2766,6 +2773,27 @@ static int intel_cpufreq_cpu_exit(struct cpufreq_policy *policy) return intel_pstate_cpu_exit(policy); } +static int intel_cpufreq_suspend(struct cpufreq_policy *policy) +{ + intel_pstate_suspend(policy); + + if (hwp_active) { + struct cpudata *cpu = all_cpu_data[policy->cpu]; + u64 value = READ_ONCE(cpu->hwp_req_cached); + + /* + * Clear the desired perf field in MSR_HWP_REQUEST in case + * intel_cpufreq_adjust_perf() is in use and the last value + * written by it may not be suitable. + */ + value &= ~HWP_DESIRED_PERF(~0L); + wrmsrl_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value); + WRITE_ONCE(cpu->hwp_req_cached, value); + } + + return 0; +} + static struct cpufreq_driver intel_cpufreq = { .flags = CPUFREQ_CONST_LOOPS, .verify = intel_cpufreq_verify_policy, @@ -2775,7 +2803,7 @@ static struct cpufreq_driver intel_cpufreq = { .exit = intel_cpufreq_cpu_exit, .offline = intel_pstate_cpu_offline, .online = intel_pstate_cpu_online, - .suspend = intel_pstate_suspend, + .suspend = intel_cpufreq_suspend, .resume = intel_pstate_resume, .update_limits = intel_pstate_update_limits, .name = "intel_cpufreq",