From patchwork Sat Oct 22 07:21:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1097668wrr; Sat, 22 Oct 2022 01:08:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Nke6/lAYOxBj2AkJJKhxSkVwLa7per5uczOC3095/c3+txHTfuwftlJAvWio3nqq4C6vH X-Received: by 2002:a63:6b88:0:b0:46a:ff3c:b64a with SMTP id g130-20020a636b88000000b0046aff3cb64amr19490215pgc.196.1666426104837; Sat, 22 Oct 2022 01:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666426104; cv=none; d=google.com; s=arc-20160816; b=eyBw8ONJKZ35BfRPqkGVG6QcgUAMYw6EhE/HxOHBo54j3r+sojTnin/dGm12mikJSb +I0oU0vvqMkURf0FFBrosQeogyjSDY5HGn6BjhBm1EQ4lbq3ljBGcG+mbBrHwnmv65pM 4xUbW753/EalO3xWHNIXva7OMF4lCabh18cgnJ8AZi8dB4Ugowj25auN2QfrYBTjHEeS E75pU6h7Loh25kjTZewpS4ayfA29yW5ypbQSzvIUXjGy/0udkXvUHIWTl4C3u9CtzlD0 MaywFVlFIa4hugqpa5qHlhfIKQP+4xMM8/rkpnXEB2gqxYcqgoehO5n4aa35myxEHaJz O6JA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3HMUYsBs4eeRUSKQEVmNLXfw6bQYHl6eAy4MdNuGz1U=; b=gSokB2b+WPuD9Fn65/K/7Ccn7BYs/+If+tvttG8bnh91KzgHR8oqEQWrgMWRGh5vf8 lTiMhg6uegs+1AAuKBagD79t5LCAIjvhvzrOw6xVd01GkxyfNeYNqdszS/gXbRiiNyh7 U/BZ0+YkqaXO50/SDpau2xJ307TQ6mfXu/hsNIVyJJqBWfPKu1eJjF9/4k62Qc+Y4BLr hrw/d2o3L2gTOqD8bfj5czBwd0rWGJNqSM1y1yApTA8vVu9m2l7araW29lRB447BL2E3 F22PYSXzWsMCBgq5jcffpzKxR059L8biPSH5T/UHyTg5os1cB7gceDZHI5uila58eUKq 9Y/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vwWMIRYb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020a170902bb8600b00176b8830921si23385378pls.294.2022.10.22.01.08.12; Sat, 22 Oct 2022 01:08:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vwWMIRYb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232808AbiJVIHz (ORCPT + 99 others); Sat, 22 Oct 2022 04:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232764AbiJVIEK (ORCPT ); Sat, 22 Oct 2022 04:04:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B1627A318; Sat, 22 Oct 2022 00:51:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 86C83B82E0B; Sat, 22 Oct 2022 07:42:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8F63C433D6; Sat, 22 Oct 2022 07:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424530; bh=yXakOncocmAMdyM9Kp+4spb4pV7+704OueZkYTIj4p4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vwWMIRYb/WksO+dtHAvjxqdWQdJ+2b90933D5mq6B7UlZXA6yX8zuFwkKW8iaGQJg cRM7Mq4c2eKreL5d4N1Zq9aQH76XAorPd8e33bToX9N5C692mx9glGATkSHSgyovNs klqjagQGJyUPzBMKhRiONVEbsaJ1ovkLLEcBSUYU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Huang Rui , Perry Yuan , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.19 181/717] cpufreq: amd-pstate: Fix initial highest_perf value Date: Sat, 22 Oct 2022 09:21:00 +0200 Message-Id: <20221022072447.617589858@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747374418986926538?= X-GMAIL-MSGID: =?utf-8?q?1747374418986926538?= From: Perry Yuan [ Upstream commit bedadcfb011fef55273bd686e8893fdd8911dcdb ] To avoid some new AMD processors use wrong highest perf when amd pstate driver loaded, this fix will query the highest perf from MSR register MSR_AMD_CPPC_CAP1 and cppc_acpi interface firstly, then compare with the highest perf value got by calling amd_get_highest_perf() function. The lower value will be the correct highest perf we need to use. Otherwise the CPU max MHz will be incorrect if the amd_get_highest_perf() did not cover the new process family and model ID. Like this lscpu info, the max frequency is incorrect. Vendor ID: AuthenticAMD Socket(s): 1 Stepping: 2 CPU max MHz: 5410.0000 CPU min MHz: 400.0000 BogoMIPS: 5600.54 Fixes: 3743d55b289c2 (x86, sched: Fix the AMD CPPC maximum performance value on certain AMD Ryzen generations) Acked-by: Huang Rui Signed-off-by: Perry Yuan Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/amd-pstate.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 9ac75c1cde9c..365f3ad166a7 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -152,6 +152,7 @@ static inline int amd_pstate_enable(bool enable) static int pstate_init_perf(struct amd_cpudata *cpudata) { u64 cap1; + u32 highest_perf; int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &cap1); @@ -163,7 +164,11 @@ static int pstate_init_perf(struct amd_cpudata *cpudata) * * CPPC entry doesn't indicate the highest performance in some ASICs. */ - WRITE_ONCE(cpudata->highest_perf, amd_get_highest_perf()); + highest_perf = amd_get_highest_perf(); + if (highest_perf > AMD_CPPC_HIGHEST_PERF(cap1)) + highest_perf = AMD_CPPC_HIGHEST_PERF(cap1); + + WRITE_ONCE(cpudata->highest_perf, highest_perf); WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1)); WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1)); @@ -175,12 +180,17 @@ static int pstate_init_perf(struct amd_cpudata *cpudata) static int cppc_init_perf(struct amd_cpudata *cpudata) { struct cppc_perf_caps cppc_perf; + u32 highest_perf; int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); if (ret) return ret; - WRITE_ONCE(cpudata->highest_perf, amd_get_highest_perf()); + highest_perf = amd_get_highest_perf(); + if (highest_perf > cppc_perf.highest_perf) + highest_perf = cppc_perf.highest_perf; + + WRITE_ONCE(cpudata->highest_perf, highest_perf); WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf); WRITE_ONCE(cpudata->lowest_nonlinear_perf,