From patchwork Wed May 17 16:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wyes Karny X-Patchwork-Id: 683816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F53CC77B75 for ; Wed, 17 May 2023 16:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229458AbjEQQ3W (ORCPT ); Wed, 17 May 2023 12:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjEQQ3V (ORCPT ); Wed, 17 May 2023 12:29:21 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2067.outbound.protection.outlook.com [40.107.93.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D92238682; Wed, 17 May 2023 09:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q8u3QsfiXEFaULDZhbLp0zGFzK1afA2Iw0vkNHvo18xQoX2PtYnqH26PEBszhzUHtejiHJnqCJxAWj/bYYPeWrLhLZFpGHzTzN1ERDCw9iaWgNUuTsSWu8FONW+dAlSJkHT7GBVOofQGiJ6PHnytEbYarA/Bz/rlSeUxCLXWqkDj6xSaKMOEDf10MyKwFV7+42mpqbfl5eVq1MxFmt3SnFhvnM4PW7XmxZDSTqkbg4WiL62yFjxe5yjy+zFEd8+XypZ6lLiY4IXVTkumDuO5nR7tAhjX4CeGCDyB+6aelN05nVzoXyGI/znGU1RRZ+hZS/D3Z/9fsnW19fYfiTxH8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JYc4SnWDZAlkPdAhitrjJxoj6jNPhcC968l940yDx3M=; b=QS6Vu4fAgQuIz0o8ArRMGYM9QMMFCIs53s6QmEZOrySnXkHfETksTOKfzJgxmbWPd1DpAu0lnt8QBRtN28RrJ5hKbnUQ0D1I3lSvmV/6iVGmrZdKehnvG/zw54paNIBNb0Twk6nSFBrTfRxLfqhqOmZwtCjXHGKh7bvM3xBzv7uRJZOlnJDQw6TD5EYvcNSiCIouYEC/iHm8/t/oWEZgpz6kOMwnjypI6k71ueWMTRn1VQNhXRmCZfpYNT7pYUT8QWaBUbd4Np6Q5mGfxbTTkRRRea30F2OFdkWm7Kwd2BPzVZGVwft2LNM7TQK2Le0Ipk/5/ot83fLX89PUpWLxoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JYc4SnWDZAlkPdAhitrjJxoj6jNPhcC968l940yDx3M=; b=XhibRrJVP7BwH84HhCxC+20cH9OP8/1mIt0zIPVyCUGxLUqXnEQ+XVHaf88sbtZ/Lx8+NweSMUy+9qUkdxy6TRMKBCG1+I2kwgUCiAO5js/c1Xq5nW+ZeMaVTQfM2TGHKlvY0Bixj59fZQq6nzhSn32o/1zyMIuKr9tQjsq8RU0= Received: from BN9PR03CA0904.namprd03.prod.outlook.com (2603:10b6:408:107::9) by PH0PR12MB8007.namprd12.prod.outlook.com (2603:10b6:510:28e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Wed, 17 May 2023 16:29:17 +0000 Received: from BN8NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:408:107:cafe::35) by BN9PR03CA0904.outlook.office365.com (2603:10b6:408:107::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.18 via Frontend Transport; Wed, 17 May 2023 16:29:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT056.mail.protection.outlook.com (10.13.177.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.17 via Frontend Transport; Wed, 17 May 2023 16:29:16 +0000 Received: from beas.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 17 May 2023 11:29:09 -0500 From: Wyes Karny To: , , CC: , , , Wyes Karny Subject: [PATCH v4 1/3] amd_pstate: Add ->fast_switch() callback Date: Wed, 17 May 2023 16:28:15 +0000 Message-ID: <20230517162817.8538-2-wyes.karny@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230517162817.8538-1-wyes.karny@amd.com> References: <20230517162817.8538-1-wyes.karny@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT056:EE_|PH0PR12MB8007:EE_ X-MS-Office365-Filtering-Correlation-Id: a06b4506-44b0-4619-4290-08db56f3dbc5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dShs4QRcq1lJP9QD88aZR/gMx/yRy2Utaure9m+8nDkCWyh00u4ELYT4qlyGVp4a8XZ60CcoPkm1ordzZHWa82X1QHthFbWguD9NpG+pvapFckT2656DWmIrEL706E9Xgx3yw6/a/v6hLEDgGR/3/l1+fnG8HRs5GG6CUDQsdzthufMl7mdKzsDCIWIiHOG6U5id7+Sueuy9kg/1ryc0ctA2RI9Z4pOue+1AVAmA978wtztWJbkImAO+PrdA8+uPoj4tgcw7Bf5ah0U/Ifv4qX0uxgaNSH9l6s8snzkPRdHIGWGHXwqWiUNbn+q6bVXdVQLdzFSNo8unX3s5VFdPnX6huMIxA241Q6jBRKltrNuh/GQlg5FNB7ksL3+k6+CPXHJbl+4F/qTV1tyCKMQHDJXuQmDVbUI9nCf2NL1ohpdakBcIOa4ez3+Yg/TMV9rVXv8ylLYDAn7FVx/u8jEIQHbDcgjkFyBwMB49LyLQ3/kzmaA7Rpfi3jh9Bi+D4GfTCAhnhYNOcKFlmFi+PEzifLQ9UUaXq8DZFo5d7lnhhmrqiyAsAzHEcOYtwTZeZ1FQfqpL3tL9Hh2Lrv5yBA41j2gmmFIgWcfrS8xONIUgTovZVCW4f/EVR5hyt6YOSfiDOwtz+sl2L/yX3RuF2vTvWrIlRrK/LSYXAcf/PVzJxNT+afyCD4SRLHEeAZ6V7rh7zv2KAGkyIjzv1PYP928Dhb3LwAiJ6L6mFLz9jqk3bQoeR0sMDBd3rwbjK+yIlCL8wOTs7ZQjfgND0GPzStQpBOV0WeFcso3LkxVxv02CU1s= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(136003)(346002)(39860400002)(396003)(376002)(451199021)(36840700001)(46966006)(40470700004)(5660300002)(8936002)(86362001)(44832011)(336012)(426003)(8676002)(2616005)(82310400005)(47076005)(36860700001)(83380400001)(81166007)(82740400003)(1076003)(356005)(26005)(186003)(16526019)(40460700003)(41300700001)(7696005)(478600001)(6666004)(110136005)(316002)(40480700001)(70206006)(54906003)(70586007)(36756003)(4326008)(2906002)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2023 16:29:16.6924 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a06b4506-44b0-4619-4290-08db56f3dbc5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8007 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: "Gautham R. Shenoy" Schedutil normally calls the adjust_perf callback for drivers with adjust_perf callback available and fast_switch_possible flag set. However, when frequency invariance is disabled and schedutil tries to invoke fast_switch. So, there is a chance of kernel crash if this function pointer is not set. To protect against this scenario add fast_switch callback to amd_pstate driver. Fixes: 1d215f0319c2 ("cpufreq: amd-pstate: Add fast switch function for AMD P-State") Signed-off-by: Wyes Karny Signed-off-by: Gautham R. Shenoy --- drivers/cpufreq/amd-pstate.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 5a3d4aa0f45a..45711fc0a856 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -444,9 +444,8 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy) return 0; } -static int amd_pstate_target(struct cpufreq_policy *policy, - unsigned int target_freq, - unsigned int relation) +static int amd_pstate_update_freq(struct cpufreq_policy *policy, + unsigned int target_freq, bool fast_switch) { struct cpufreq_freqs freqs; struct amd_cpudata *cpudata = policy->driver_data; @@ -465,14 +464,37 @@ static int amd_pstate_target(struct cpufreq_policy *policy, des_perf = DIV_ROUND_CLOSEST(target_freq * cap_perf, cpudata->max_freq); - cpufreq_freq_transition_begin(policy, &freqs); + WARN_ON(fast_switch && !policy->fast_switch_enabled); + /* + * If fast_switch is desired, then there aren't any registered + * transition notifiers. See comment for + * cpufreq_enable_fast_switch(). + */ + if (!fast_switch) + cpufreq_freq_transition_begin(policy, &freqs); + amd_pstate_update(cpudata, min_perf, des_perf, - max_perf, false, policy->governor->flags); - cpufreq_freq_transition_end(policy, &freqs, false); + max_perf, fast_switch, policy->governor->flags); + + if (!fast_switch) + cpufreq_freq_transition_end(policy, &freqs, false); return 0; } +static int amd_pstate_target(struct cpufreq_policy *policy, + unsigned int target_freq, + unsigned int relation) +{ + return amd_pstate_update_freq(policy, target_freq, false); +} + +static unsigned int amd_pstate_fast_switch(struct cpufreq_policy *policy, + unsigned int target_freq) +{ + return amd_pstate_update_freq(policy, target_freq, true); +} + static void amd_pstate_adjust_perf(unsigned int cpu, unsigned long _min_perf, unsigned long target_perf, @@ -715,6 +737,7 @@ static int amd_pstate_cpu_exit(struct cpufreq_policy *policy) freq_qos_remove_request(&cpudata->req[1]); freq_qos_remove_request(&cpudata->req[0]); + policy->fast_switch_possible = false; kfree(cpudata); return 0; @@ -1309,6 +1332,7 @@ static struct cpufreq_driver amd_pstate_driver = { .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS, .verify = amd_pstate_verify, .target = amd_pstate_target, + .fast_switch = amd_pstate_fast_switch, .init = amd_pstate_cpu_init, .exit = amd_pstate_cpu_exit, .suspend = amd_pstate_cpu_suspend, From patchwork Wed May 17 16:28:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wyes Karny X-Patchwork-Id: 683162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E782FC77B7D for ; Wed, 17 May 2023 16:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjEQQak (ORCPT ); Wed, 17 May 2023 12:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjEQQaj (ORCPT ); Wed, 17 May 2023 12:30:39 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AD4EE45; Wed, 17 May 2023 09:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CbpqAAOZ+scgKbhMuI/1RMV2/eWhDjYkCzBaeqKZecxAy5vUdCGLAX2hLNMnF8PhPu2XdxbBm4pM3yeQqHGd1t6HwxslvxAlAr/0Evml01HwtC1/lwkjXcp0dzr3/EWE40Camm00yALUOfdGGZKlHwis824KH47S8Q4MMLQiOHwBeMmFAPt2/bZ/Brp/3z96U9kx0Tc+fao6kI5oeVzHSTcLJqSw6XweeCe9U/iV/jlg5q+wSRDzv6CYo8ScGabb1MJDZ+J0OtDSPCqBuQMkQJfN+HKJgtvbV5rUMh3oy73bMPs8uyhncOT7j0cd00pMj8LssiCA3gTQSvHkSL5Ztg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/4b09leER36s5g2t8mNZPHivLrhBHuZySAZB9obu22A=; b=DoGiYYL02o7VCqHzoRmRAuM89ldEp+6dSdYwj9ASq5GwAPCIXHlvfFndnFtP//P4LdvaiSzGGS8sqXn/ZjZEVR04dhcjMaPUQkwpa83Adg/iMvNzfVFtAiKH4OxAWos83vvYmSgQzPBbzCydidQySjwvig5zN1ohVdxt6rJCDHSah+LTvsAZiNenzoS7tL3rxxGKFt5lxgw0J3RnGGrXgIG465P8a+Z4gubEJBin7huz1ErgshRRMpkmCSaF6esUvafKUb5THApLpB4VzN3DMgaUIGW9Jf8Mz3FojU7SyPFaqfUs5aHzJfpgwYyAK2gqSdU75t0Rmy7BsaYuIbAs3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/4b09leER36s5g2t8mNZPHivLrhBHuZySAZB9obu22A=; b=wF+a8r/t2zyZuOCgu0mtNmnHyvLKXEfg3mf8T7Z8TxBSekPKB4zY4YNKryinzhbXv+riM5xPhski3BG8lWeNzCcvkxvUg04UKHbd/z9pr6G/fo93ZgNJlsGL4hefwFXxdPqHSuHzToFC9MPJHSszpgi3ZHytyiV5lLdFk11ffug= Received: from BN1PR13CA0016.namprd13.prod.outlook.com (2603:10b6:408:e2::21) by CY8PR12MB8410.namprd12.prod.outlook.com (2603:10b6:930:6d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Wed, 17 May 2023 16:30:33 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::5c) by BN1PR13CA0016.outlook.office365.com (2603:10b6:408:e2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.5 via Frontend Transport; Wed, 17 May 2023 16:30:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.18 via Frontend Transport; Wed, 17 May 2023 16:30:33 +0000 Received: from beas.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 17 May 2023 11:30:06 -0500 From: Wyes Karny To: , , CC: , , , Wyes Karny Subject: [PATCH v4 2/3] cpufreq/amd-pstate: Remove fast_switch_possible flag from active driver Date: Wed, 17 May 2023 16:28:16 +0000 Message-ID: <20230517162817.8538-3-wyes.karny@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230517162817.8538-1-wyes.karny@amd.com> References: <20230517162817.8538-1-wyes.karny@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT008:EE_|CY8PR12MB8410:EE_ X-MS-Office365-Filtering-Correlation-Id: dd91b11a-8683-4759-5c68-08db56f4094d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +nN++Sk5z7ND5Gz08aPHDt5UdJGp5VLF/Zc6jRfSDKRhRMdRgCtA5RQxlZkjEcebLkFdfuPkM/RATL6TOBor3tiqs5f6cIirxo37IMZLW4ZJS/7KeZQDXS2nRHHVSiiNfak3TIp3S4AthanSdObeulO+p8FVOOaGL8uWTHWVqXV8TPbSm1Y+7kqLSTZc7Jt6jkTMCkVs2+Q3Boia285fTZU3USfdW2jsl5jmvLG4f3LNjZvJupWjIUSoPFF9xV6jZIECZA7z7GGH8qvTO+r0RrePdCPps28p2Q0YnV6dQx+iM1MDcTGZ1USFyjVYiOSq9dsQetw3xHaVhIJAM3w0soHkbr4qxS88UBs6S9PEM4dsfgXtlg+kfJPvm7nIemBi1fjPfrv4F4A/GDMw1KDov/weog1P6iiU2TAVxfbhkKQcjkNPOL68VzkqQiNqoKYZ1RzefKJfz+HWTI2ySU8zaWxJi0BYgJYR3Min+8oN5uapcFZ8uctd/jWazSWp4bX8pFsiBVYjUTfdWFXUROiSmqWu9LYY4vOCQvEbUId4ZVkOWmfoZIohJAs/UA6rdie/8BL/5VhUl3PKzsE0Wy/DSxCCipoE3Cs18J4sHxYG/BkGxdN9Sy2CUWfZm0erbdRpYOBw+O45k6mCqWwA8C2IUmdsXLhTvIhM/qDQeSAhzbW+Uc83sv6bh686hv48BLR6iw1PwVQdbkfC6cVL/tPGXl6R5cGekvKEjLEYT7CI/5R/dSpL7zvW3cAODRfjTS1/B1ACfUBItUWv9IgIAtaJUiTfwOEPPGoypZ4i9u0qVDs= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(376002)(346002)(396003)(136003)(451199021)(40470700004)(46966006)(36840700001)(5660300002)(8676002)(8936002)(44832011)(336012)(426003)(2616005)(82310400005)(81166007)(47076005)(186003)(82740400003)(83380400001)(1076003)(36860700001)(356005)(26005)(16526019)(40460700003)(7696005)(478600001)(6666004)(110136005)(316002)(40480700001)(86362001)(41300700001)(70206006)(54906003)(70586007)(36756003)(4326008)(2906002)(2101003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2023 16:30:33.0662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd91b11a-8683-4759-5c68-08db56f4094d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8410 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org amd_pstate active mode driver is only compatible with static governors. Therefore it doesn't need fast_switch functionality. Remove fast_switch_possible flag from amd_pstate active mode driver. Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors") Signed-off-by: Wyes Karny --- drivers/cpufreq/amd-pstate.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 45711fc0a856..ac54779f5a49 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1102,7 +1102,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) policy->policy = CPUFREQ_POLICY_POWERSAVE; if (boot_cpu_has(X86_FEATURE_CPPC)) { - policy->fast_switch_possible = true; ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); if (ret) return ret; @@ -1125,7 +1124,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) static int amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy) { pr_debug("CPU %d exiting\n", policy->cpu); - policy->fast_switch_possible = false; return 0; } From patchwork Wed May 17 16:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wyes Karny X-Patchwork-Id: 683815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C8A8C77B7D for ; Wed, 17 May 2023 16:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbjEQQaq (ORCPT ); Wed, 17 May 2023 12:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjEQQam (ORCPT ); Wed, 17 May 2023 12:30:42 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::600]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08EA05FDF; Wed, 17 May 2023 09:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BQJXa52zHOG95jNSqBBK2qrvaeajeSW6T26hSkGdpTZatxOwuMvM+qXL/evKfjPLkbVJdKhni+Gihlm5YoiB6fI5LN1AlrTzs3y3gUjgWtj7K9kr5Lh+2d6JxpZWoIRoLb9sujwAg0px2zak+7BbJvKkqG5m9NLuqx08SUCt4J1xlIB/MY+1q8qfO0SbmEeUhqW/rEhAv41NQjmT2ljzSNWglfBkcf4R0W3uVz+8xTXtpoFnDWZBq2T8hYpI2mymncHfOw00xaw4+VNuM3b3iUglk5xXOrLRB0O49IPUawfZc+yZJ0CnlcdaqJ7/YM0SdWsZKWWFPcLE7TlSejWGjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yKsX6FtXJrK9YU1t6JxfuHJ1PC4JDhdf2NNtKaFKVSM=; b=OfVwwmXUfpsYBCmH6ufk8okpHNZZ4GApB7GkWUuNvbw9MdS5GnI275tif/MgzyfcP30VMs06Dwn3NnsNloJsxhceSD/g3XzbHa3+Ut/09pq4FLxcS8JYvexHE4jOj8dHsi8rUHQkGaU2Pzhpz90cVQ7A6Ngd0Vvol0rbGaFwHlhKEa/yLqCRrBzjIa4SWZ+q77/PKn/3odNia0zLEnOB55j1wYOKeemwLDwhaC8DdJvNcOB0uJym4nRShxykgmOZVqFaXmHijLiKKclTf6hQjqSESLAKWP/AKh1YqNsRZawaZffIwpIAKVKr4x6FuDVyref17Wa8CtJH/YlN8SageQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yKsX6FtXJrK9YU1t6JxfuHJ1PC4JDhdf2NNtKaFKVSM=; b=2SGNpkzCq9vI1C8lLUnxNLRFz7wsBlz8krtaQG3CkLVmtb9ElawOJ1e39abbsi+tQI3YF+UFn0B/Gxd8uZcQJb/anCEGQyvCWjagOyvst7IYXaJM6Td1nffc8BQxAeOnjn3Z1r17cUxSUDgKrpEcVVVBQkp8+qYSvIBsh9U1fQs= Received: from BN9PR03CA0164.namprd03.prod.outlook.com (2603:10b6:408:f4::19) by DS0PR12MB6535.namprd12.prod.outlook.com (2603:10b6:8:c0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Wed, 17 May 2023 16:30:35 +0000 Received: from BN8NAM11FT075.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f4:cafe::1) by BN9PR03CA0164.outlook.office365.com (2603:10b6:408:f4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17 via Frontend Transport; Wed, 17 May 2023 16:30:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT075.mail.protection.outlook.com (10.13.176.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.18 via Frontend Transport; Wed, 17 May 2023 16:30:35 +0000 Received: from beas.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 17 May 2023 11:30:32 -0500 From: Wyes Karny To: , , CC: , , , Wyes Karny Subject: [PATCH v4 3/3] cpufreq: Return failure if fast_switch is not set and fast_switch_possible is set Date: Wed, 17 May 2023 16:28:17 +0000 Message-ID: <20230517162817.8538-4-wyes.karny@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230517162817.8538-1-wyes.karny@amd.com> References: <20230517162817.8538-1-wyes.karny@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT075:EE_|DS0PR12MB6535:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ababee1-a5d9-463b-6690-08db56f40acf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xuMcOYEKfio8OydOUHWzEGNgvH8RcK7HSLIqvF+lzEYUYAGqZyO3FY5QXihCeVgpO8xgCSeXHXThV480UyApbZx/+gra/RUvksfvlrZeu+Ht9DSs1KXe6gpGApDmJq+H1raubzm1v/wHojVKT6pzZO8i25tQkxmAbq+f+y63EjyMFprazf+54Z/GBO5bGrQDdEKVVPJxl2FBDrlAW1ZUB0vb/eQRsGMk8m8yQ9LbT+kR/RgL0wS8+3+RMp7YdsuSLPNRi63b/3aRq/perzyjY5A1KnAIO7t29WFanVmMjEClHok4nlt4Q8zSYplMFZfirEUC5P2h8kjlrCSyyFrlG9bv/OfRFFo3OQ3X8IfLHfM2Kz8JNWXqQmp2pUnJ08BWZ/W8E0cmsxEr4bRKK0UTWnjvesFFKRHj3xxZVf8NyytZPCtzdGa9Z99R+szvy7E6mdwYw3CXBiXezJ+zBCXtFo2ifErKZSiKtYDUy/WQpzIQeJ91WMtd2MsIoktcySlMEYPDp7+Xl0E7vMU9v4JKGKhjGacL1+rR1Vn3A+BXZrGAgXeLhoN1AX7rlun+m+aTHKgSQDpB5s1dtFiECyXxnIErG/xcwwKT0P7NSaRMeZG0cdP2bmFGLoOiUnKKe6bo2W1tP66dEeyxvN0Ka3rXHEnVfrsU+ySgDqV9hDmdPG33a0Pqf9LUirvkoEHRDgMOFps3dFU6TqUBv2avhKND5L3HrEMxObNOSNCghEkVbe4PBaFKBcanShMYrCCn+gH3Qafxw6GWEyxqYLyWD1BiVqMoN0nYRnjc8ALtOj8Gze0= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(346002)(136003)(396003)(39860400002)(376002)(451199021)(40470700004)(36840700001)(46966006)(26005)(40460700003)(1076003)(7696005)(36860700001)(36756003)(47076005)(40480700001)(83380400001)(426003)(336012)(2616005)(356005)(86362001)(82310400005)(82740400003)(186003)(16526019)(81166007)(2906002)(8936002)(478600001)(4326008)(316002)(44832011)(110136005)(54906003)(5660300002)(8676002)(70586007)(70206006)(6666004)(41300700001)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2023 16:30:35.5961 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ababee1-a5d9-463b-6690-08db56f40acf X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT075.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6535 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org If fast_switch_possible flag is set by the scaling driver, the governor is free to select fast_switch function even if adjust_perf is set. Some scaling drivers which use adjust_perf don't set fast_switch thinking that the governor would never fall back to fast_switch. But the governor can fall back to fast_switch even in runtime if frequency invariance is disabled due to some reason. This could crash the kernel if the driver didn't set the fast_switch function pointer. Therefore, return failure in cpufreq_online function if fast_switch is not set and fast_switch_possible is set. Signed-off-by: Wyes Karny --- drivers/cpufreq/cpufreq.c | 5 +++++ include/linux/cpufreq.h | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 6b52ebe5a890..7835ba4fa34c 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1376,6 +1376,11 @@ static int cpufreq_online(unsigned int cpu) goto out_free_policy; } + if (policy->fast_switch_possible && !cpufreq_driver->fast_switch) { + pr_err("fast_switch_possible is enabled but fast_switch callback is not set\n"); + ret = -EINVAL; + goto out_destroy_policy; + } /* * The initialization has succeeded and the policy is online. * If there is a problem with its frequency table, take it diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 26e2eb399484..8cdf77bb3bc1 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -340,7 +340,9 @@ struct cpufreq_driver { /* * ->fast_switch() replacement for drivers that use an internal * representation of performance levels and can pass hints other than - * the target performance level to the hardware. + * the target performance level to the hardware. If driver is setting this, + * then it needs to set fast_switch also. Because in certain scenario scale + * invariance could be disabled and governor can switch back to fast_switch. */ void (*adjust_perf)(unsigned int cpu, unsigned long min_perf,