From patchwork Wed Mar 24 10:28:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5b6Q56aP5rW3?= X-Patchwork-Id: 12160649 X-Patchwork-Delegate: shuah@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C801C433C1 for ; Wed, 24 Mar 2021 10:29:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06734619E3 for ; Wed, 24 Mar 2021 10:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbhCXK2x (ORCPT ); Wed, 24 Mar 2021 06:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235816AbhCXK2L (ORCPT ); Wed, 24 Mar 2021 06:28:11 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B300AC0613E0 for ; Wed, 24 Mar 2021 03:28:07 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id g10so7677274plt.8 for ; Wed, 24 Mar 2021 03:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=WEBWemoFlRUxDAbCOU3NDRqXpUI03UUvlFIm/pLjApQ=; b=CYYeJbjrV8vZbCZbbhcN71gEbVRP0wGfVvYukP1jBaKV/abhvcAEEhipldOWxkq9rn z3o5RensIhxNdOFL2duyElfITMGckHutAnuWJ9tMF8iUBT4eAp9ata7bKiWZOFhRJqIq 3IPFUnNsSgCPLn1OUhtyamVjXXWCgupWH1rDWGmrujf+4O/Eh2xvrw9QocRbI4lW4GzS qlfmrB1tNM5DvzAR+ZNCNBwZx5iylxKVLjhgZ2UJWbSYC09lMXdhgIfcw3OV77sSOfWP rzMSnGrvRB/ch/LojbAcn86mMBf5pJwPm4EIfwmQnavbbcDyIZAA1HrN5eBooM6xIVUo eGGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=WEBWemoFlRUxDAbCOU3NDRqXpUI03UUvlFIm/pLjApQ=; b=BgXk4T3QUDbCBiHqNIhUf8EFbl4HUE6QqsBCEo7EIsgcbcRoDip3UMliv7j6IgzYGj mpQvLxCWM4SYewfFM23CKbur62sWFTLnYuJVUoeOglXu1Oa4ccngh91sd5fVGo86QZeB 3lO/TL+y8uBYmPV/SdVyuZdC067HWtwjzNtg3U551T5BRoAaLNeUHAEu+019AgMmiXC2 RyBW/3Px3MuTILTH77X4KqsGmEVmoQIByEv5nfEQq5KtEUSPMdH9bCuXD1FgLT92S9lR VxmPJC3Y6XevNwHt1+wSzVAz+a2nZRZUbRvfElW6d5iAlcKEtPymFplcifsSkEqdYJm+ BEZw== X-Gm-Message-State: AOAM531WOzOZV+lhkTHS3vswQQIujoSz0vGCF7jwrlp1rqxiHdOIkBsA zkai7wYTcTeimNqpnmAu+cc= X-Google-Smtp-Source: ABdhPJxdHo/ZM+cnOAGT6X96x1jRbbr1j93R/LIDztG82wVbDY1bssL5bIHxXpiKyuLtoWdb5KwJWw== X-Received: by 2002:a17:90a:f2d5:: with SMTP id gt21mr2888722pjb.197.1616581687195; Wed, 24 Mar 2021 03:28:07 -0700 (PDT) Received: from MacBook-Pro.local ([103.112.79.203]) by smtp.gmail.com with ESMTPSA id gf20sm1968176pjb.39.2021.03.24.03.28.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 03:28:06 -0700 (PDT) To: linux@dominikbrodowski.net, sherry.hurwitz@amd.com, trenn@suse.com, linux-pm@vger.kernel.org Cc: lishujin@kuaishou.com From: xufuhai Subject: [PATCH 2/2] cpupower: fix amd cpu (family >= 0x17) active state issue Message-ID: Date: Wed, 24 Mar 2021 18:28:03 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: xufuhai If the read_msr function is executed by a non-root user, the function returns -1, which means that there is no permission to access /dev/cpu/%d/msr, but cpufreq_has_boost_support should also return -1 immediately, and should not follow the original logic to return 0, which will cause amd The cpupower tool returns the turbo active status as 0. Reproduce procedure: cpupower frequency-info Signed-off-by: xufuhai Signed-off-by: chenguanqiao Signed-off-by: lishujin --- tools/power/cpupower/utils/helpers/misc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index fc6e34511721..be96f9ce18eb 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -30,10 +30,15 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, */ if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB_MSR) { - if (!read_msr(cpu, MSR_AMD_HWCR, &val)) { + ret = read_msr(cpu, MSR_AMD_HWCR, &val); + if (!ret) { if (!(val & CPUPOWER_AMD_CPBDIS)) *active = 1; - } + } else + /* no permission to access /dev/cpu/%d/msr, return -1 immediately, + * and should not follow the original logic to return 0 + */ + return ret; } else { ret = amd_pci_get_num_boost_states(active, states); if (ret)