From nobody Sun Feb 8 09:27:51 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010012.outbound.protection.outlook.com [52.101.61.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDF0F307AC6; Tue, 6 Jan 2026 07:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767685020; cv=fail; b=Ma+yoctdUw82XptP21pXRn8aa1wBNTMJXvpNoC+YyfIGKBafiP32GXzgZAvmo0uNrDqtKeO58ZVkVVs8BoUk+lFQK+G/Q3uNYZ7kx1pco2Pk/cZOcLYbg+BTb4G8fbmncAd2zMyNmT6qRKfuai5n4CNZHAd+dD42qBu18fRb9TM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767685020; c=relaxed/simple; bh=Q4Bw5AGIqlKXpei00q0Q3uXX8lt2x5odEZEGiAQlHJE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GU2WoCkgEZXxEh6glEc2VrgOPuwuJhgc/+zpRuEwjWZY2jsZ3cFjiOGqZPgwtORqEgk6upBCGv9L4jGJR+ITvz8BU9gm6dxKGoAnq5LecnRmNYSCSCfwOuGY0tNqbx6PMGkWIUGudredTVbzzAD0ujOUL3CAFVw+HXvv4p5O+2Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=IoVZFgAt; arc=fail smtp.client-ip=52.101.61.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="IoVZFgAt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bkwDiQNVxECuIMSb62DzT/ijVfzAJ/q2mHxPyKWCiLx8fQyT0wmH2yAkx0qMUGWBb0qbWqjRjlkNSc2EOWoOMNpAZ8Unz20nVQF14wfEkEXp7J1qQftsY9CoOI12s9FRRP7j7PQsLFl/86pEIN1c2A/NHaAIrrqft6BwfASMSzrNpy+jgbS0dA+jXWwzEhJEDUD3RDsW0OnARxTIi6Q0bE5rZ4AlmFIgaAFAvJ40xVmfnJvgJj4SqFtDm7kkC1mdMHtYyct8wYF7vcpRRDC6x6JdmJc9gX19F6VHI9umf1fpJ9hJlTnegwjsnecOdxrhCZJrVptrwWjPGwYHsg01Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=h17OfjEwAZjCwZYe65rqWcI/WIAtXskVA0VSGWVAtuQ=; b=bDxN+NHZcxZdtKvBnhWom/0o9WVdLoEONZ4aH+O5pY3xUGLMR0ZG4scwoafvjYbbizz8N3A8QgR1TJ3Nh0v3MuxbHN2uJeX0cVgthetggMjlt/Si6nAqlxMlYW19r/PinuqAbXCLSYttf0b64TE9nTC35EC7qTSHKxxiLv9/vtmvRNH3qApFiAIbMXokS4t21WDQxibp0NFAEZw633NLnkPApmU0lbrFgPZ96G/Wkr7Xn4BhSJSCCBqn3ncEjkyLdca9buNZrICVE/MK6+OKXyBwmEK+3px4gyhx0KYzSeF0abZ5smax18u03ClMpSHBYAECGduWmE5UfSiJc7vusA== 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 (0) 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=h17OfjEwAZjCwZYe65rqWcI/WIAtXskVA0VSGWVAtuQ=; b=IoVZFgAtsW7j4CyX9/KWGQQlSgBK3HFbavRXq018BBS+y72DvDNi8hLkfhe27ELTinhr9MAI2fw/k7HIPriI0bpfxjL8ljlyLy94CiTonoVJxHl+MUsHl4Ea1ZHDbSb5HMU9y1rceW81qelUgbxVsbRP3pIBH7/xZTLs6DngLNo= Received: from PH7P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:326::9) by IA1PR12MB9737.namprd12.prod.outlook.com (2603:10b6:208:465::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9478.4; Tue, 6 Jan 2026 07:36:55 +0000 Received: from CY4PEPF0000FCC3.namprd03.prod.outlook.com (2603:10b6:510:326:cafe::f8) by PH7P220CA0017.outlook.office365.com (2603:10b6:510:326::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9478.5 via Frontend Transport; Tue, 6 Jan 2026 07:36:53 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CY4PEPF0000FCC3.mail.protection.outlook.com (10.167.242.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.1 via Frontend Transport; Tue, 6 Jan 2026 07:36:54 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Tue, 6 Jan 2026 01:36:50 -0600 From: K Prateek Nayak To: Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , "Rafael J. Wysocki" , Viresh Kumar , Srinivas Pandruvada , Len Brown , "Sebastian Andrzej Siewior" , Clark Williams , Bert Karwatzki , , , CC: Perry Yuan Subject: [RFC PATCH 1/2] cpufreq/amd-pstate: Pass the policy to amd_pstate_update() Date: Tue, 6 Jan 2026 07:36:07 +0000 Message-ID: <20260106073608.278644-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260106073608.278644-1-kprateek.nayak@amd.com> References: <20260106073608.278644-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC3:EE_|IA1PR12MB9737:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c328065-095f-44be-e018-08de4cf65da3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?SDUGK+4EaAFxqtm83xZuSFLDfgMPTk7jcz0tJCegmyzezDJtPaw090ntufY7?= =?us-ascii?Q?MrPb9alKCYJFWF7iYUWf2SnMwo7mx4Yg7Z40+z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VGGql0AlSDVULLVsMKNsr7nJvstvQyD8QQoR7+SKHunm?= =?us-ascii?Q?TT6EWy4OodrG8waQdRh1sKC93U/nNkliyZdTycDX3M5cF0JCP6MepJlmXHVB?= =?us-ascii?Q?4GTGkNAzQZV6Tuh779rx5tUVdjDISaFIDdx+aMnRckNQwt2vgoiq+YSHgJT+?= =?us-ascii?Q?Tykt6apoeBj2lbL1MIdD/8/nljV03P4MdDvKlQlpz9CNuO9Mn6O5atkndDkd?= =?us-ascii?Q?oBS27urXh5+5HvykKGv2hD2mwsgu36bcEvrBYfr5xODcJoQ0H1V9L1P2FtKL?= =?us-ascii?Q?bXjYmaOpe/kl01lZpLS0m0ivD8ybGQ9pOpnZ6y+w0AI6JIAO2FvPlcabOgdH?= =?us-ascii?Q?i91kIqlgg5P+VQWza5a+wu+3PfS+OrRKTiIPuxscxt+lk3pIgC89N+QT8D5V?= =?us-ascii?Q?9tGlF8KYpRr3gf7NHEDzsh78hwJkOH4VQZcoYKc8DgABxFHPouiXvYGAbqYb?= =?us-ascii?Q?sDdJspvuCGOUhbo5v7VU+9cMH+B1UQNlxHRTBYywWFqZNTGCfLbCjkRqSaEj?= =?us-ascii?Q?mRcxZ5ZrdYiCv4iV1ZvsfCEkFjfkfbM5EV/LovNdR8Iaef9qsAfPTBFGlL80?= =?us-ascii?Q?E7CmRuKV+RfGkHBcHVp7P5nEwd8hIjoRDxqqyLGC?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2026 07:36:54.9004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c328065-095f-44be-e018-08de4cf65da3 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9737 Content-Type: text/plain; charset="utf-8" All callers of amd_pstate_update() already have a reference to the cpufreq_policy object. Pass the entire policy object and grab the cpudata using "policy->driver_data" instead of passing the cpudata and unnecessarily grabbing another read-side reference to the cpufreq policy object when it is already available in the caller. No functional changes intended. Signed-off-by: K Prateek Nayak Acked-by: Viresh Kumar Reviewed-by: Mario Limonciello (AMD) --- drivers/cpufreq/amd-pstate.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index c45bc98721d2..5818a92d96b9 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -565,15 +565,12 @@ static inline bool amd_pstate_sample(struct amd_cpuda= ta *cpudata) return true; } =20 -static void amd_pstate_update(struct amd_cpudata *cpudata, u8 min_perf, +static void amd_pstate_update(struct cpufreq_policy *policy, u8 min_perf, u8 des_perf, u8 max_perf, bool fast_switch, int gov_flags) { - struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cpufreq_cpu_= get(cpudata->cpu); + struct amd_cpudata *cpudata =3D policy->driver_data; union perf_cached perf =3D READ_ONCE(cpudata->perf); =20 - if (!policy) - return; - /* limit the max perf when core performance boost feature is disabled */ if (!cpudata->boost_supported) max_perf =3D min_t(u8, perf.nominal_perf, max_perf); @@ -675,7 +672,7 @@ static int amd_pstate_update_freq(struct cpufreq_policy= *policy, if (!fast_switch) cpufreq_freq_transition_begin(policy, &freqs); =20 - amd_pstate_update(cpudata, perf.min_limit_perf, des_perf, + amd_pstate_update(policy, perf.min_limit_perf, des_perf, perf.max_limit_perf, fast_switch, policy->governor->flags); =20 @@ -737,7 +734,7 @@ static void amd_pstate_adjust_perf(unsigned int cpu, if (max_perf < min_perf) max_perf =3D min_perf; =20 - amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true, + amd_pstate_update(policy, min_perf, des_perf, max_perf, true, policy->governor->flags); } =20 --=20 2.34.1 From nobody Sun Feb 8 09:27:51 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013041.outbound.protection.outlook.com [40.93.201.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88CDB309F0D; Tue, 6 Jan 2026 07:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767685038; cv=fail; b=ts0U7sTNUTz70r/dbbxwJ/bssixacwXPNw4nRV+lLt6uPLLSGDuwKeD7PYXMK3URmdiOU0yHkcS57pjtBO4wB0j5PLLBqIdu6G3czeugcoFkcxUIB4Pfk7PApH7RSFjR0cuXddwfKWCMVmCl1LrOdQ9NbC1fdBnXmWg51CJekmk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767685038; c=relaxed/simple; bh=6SzxRa1LZhGGAdIopSAsbN34jCL9MjCFJqD28BwiXB4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CSyXcqcUKb1wfCl+DLLdK5+u0nFjsywUd6SKunNkzN4MSFNROI14IElsFA0ecxrqy8ZFvFNc4muNrlv3RUtYrOZiV9TBLyEcuRI375HBsTNXQq89GNYD/lqven/zBlVjqjT5x55ZAhSXBIX7JlXb2MdF4C1beAjN8ziHfSI0jdY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=jzfVqHUG; arc=fail smtp.client-ip=40.93.201.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="jzfVqHUG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=G1vyNiHY5gjJg4Wv3Bh5fNk7iRmIko9qfeLOoEqixiuMB/5FV+wt1+HYTY4/dSX0Snzh9hT9oEDJ+UOLbkiIIroH8aqKJ4GviIVAWp15roDbUOgyf1CBzVqkCqN0GXYGIjFFHXdz0c5cDV9ud5FJUoge/g8JNmSxyGaG2Jb0X2TMqCdc1sW0bER3Mh2knVomIcOt4bYds689yG9YDpPej/qWhv6VBI5X8ED+rCF1qmKi0jrFhJVtgkkDEWGwrifyoxfs9kkIQT880S8szLpdZl+1SsdpOhoyu7o28pBRyNltEoW88h+1AhgQD0urVkLoSUPLZeETRWK7+7GYJ/c+IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=i3kgHTKrBU5x4ZhYXd7n8Yb2GCtEZLBPZtunWwAWUnY=; b=i+oXnQBNsGltwQ5W7xuUunZVtU3yi5WWmftbdt1NIKA/Vij1SX+fHki+C1/S4kljnXJfV9j5REB548Ogv+BH3u5+jdI5bFW4U5gkbLBOiaIfahBTaorS33tKIpG+LkueL3KCbtiaNdz70rKPu8G9h/TJYXqg18lnlYgejLbEGsHawb15AyQFcVb5M9U+ayQImO6LdqkKUV6wnf9y3RqMLiTU5iMqywk1IDu2On3ud7rPy7PLFRKjV9BFzxMD/qSN00T1X3IMBvICq1CV8k/oYsXnSr7i2vMKFh1SOeWQ8DqQrQl7WUtO50BhOoh+m/Jcokjg4N/igAhbHzu0drNjVQ== 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 (0) 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=i3kgHTKrBU5x4ZhYXd7n8Yb2GCtEZLBPZtunWwAWUnY=; b=jzfVqHUGjrjiKrPA4/QWwG0zxFIRI7MKuJW49thBcJWoMrJigSN+uA8cUrviWkcD+cdjRihoB/B9+fix0N/KM6lWJPXFV9iWmQFW+dKtd/+m4+zgoAcFg3zjoWEwu9UsFpE6Ee1Bzx1KFCKqbHgbXjC8HZ5U1kDngR8HvXRnNio= Received: from PH1PEPF0001330A.namprd07.prod.outlook.com (2603:10b6:518:1::19) by SA5PPF7D510B798.namprd12.prod.outlook.com (2603:10b6:80f:fc04::8d0) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9478.4; Tue, 6 Jan 2026 07:37:12 +0000 Received: from CY4PEPF0000FCC2.namprd03.prod.outlook.com (2a01:111:f403:f910::1) by PH1PEPF0001330A.outlook.office365.com (2603:1036:903:47::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9499.2 via Frontend Transport; Tue, 6 Jan 2026 07:37:12 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CY4PEPF0000FCC2.mail.protection.outlook.com (10.167.242.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.1 via Frontend Transport; Tue, 6 Jan 2026 07:37:12 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Tue, 6 Jan 2026 01:37:07 -0600 From: K Prateek Nayak To: Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , "Rafael J. Wysocki" , Viresh Kumar , Srinivas Pandruvada , Len Brown , "Sebastian Andrzej Siewior" , Clark Williams , Bert Karwatzki , , , CC: Perry Yuan Subject: [RFC PATCH 2/2] cpufreq: Pass the policy to cpufreq_driver->adjust_perf() Date: Tue, 6 Jan 2026 07:36:08 +0000 Message-ID: <20260106073608.278644-3-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260106073608.278644-1-kprateek.nayak@amd.com> References: <20260106073608.278644-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC2:EE_|SA5PPF7D510B798:EE_ X-MS-Office365-Filtering-Correlation-Id: 251d0c4f-a1e6-4c9e-88fd-08de4cf66818 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026|921020|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vKLAApL26tOVyHalY0NR5dqywPTyuJ43S3O6HgOTWLGvc/lJYDWlwD4CAdee?= =?us-ascii?Q?q8hWNdKXY+zmCFUwWOELbkCiuxzDz+4fF4j10swJyMdaq/fsLmUM3mnMMO03?= =?us-ascii?Q?q54fRDcptRL9XM2rBgIWhwQ8LYSHyQL8H8xhJxrkJWQyRzJ5RdiJK2vB6xPN?= =?us-ascii?Q?nWlnJo0vGAZDZcZ01xM2Sg1TZ5GyMrQDUaB+qtwBgdfyTUMrwQ+/H1/CNw/Z?= =?us-ascii?Q?vDjfLzn42Z76IBPFM3cRZ8yEM1X7PGg802kbYZcxdadoDd8N1F5W7iYwW/HA?= =?us-ascii?Q?okPkrgxIqYxHfUq2IrBx6HsoMKU/yZHIwTZ3I/IrQEe3C0cPv2v3CbPDXb8i?= =?us-ascii?Q?8uYCLHYfearxRHGAtC2h7lrMR3n1hCNQ/5Rl1npttmfYrvvENJ1q2+xNIDlR?= =?us-ascii?Q?UYfmavJhPj9H9iMDsjRNbIWHdd2bAnqTYmUTAQfAhjawvQjIApebwa+djT+n?= =?us-ascii?Q?BvZu7TNuLxSpHCKMhf/RNwYs69cGZaeAy3dqhcFTY3KlURFL9nHEdJTMlnep?= =?us-ascii?Q?LliBHGFd0eMnS5aqmgMz2e/ofNyfumBi3uL6i3K++lu6+RxNKYChnHQivWQv?= =?us-ascii?Q?LZfo/ceb9Q2KuTFME2leYDhDmX/erXZXdQ3x3xvoWUW85I6yWQj7GJJPYbJg?= =?us-ascii?Q?xT4nVtP6Q0W6oTzfsq94UUo2DrjaXtVygRrxxT1pOzDbGv6QQo/7eEYMwsGO?= =?us-ascii?Q?Blp/op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ispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700013)(1800799024)(82310400026)(921020)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2026 07:37:12.4385 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 251d0c4f-a1e6-4c9e-88fd-08de4cf66818 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA5PPF7D510B798 Content-Type: text/plain; charset="utf-8" cpufreq_cpu_get() can sleep on PREEMPT_RT in presence of concurrent writer(s), however amd-pstate depends on fetching the cpudata via the policy's driver data which necessitates grabbing the reference. Since schedutil governor can call "cpufreq_driver->update_perf()" during sched_tick/enqueue/dequeue with rq_lock held and IRQs disabled, fetching the policy object using the cpufreq_cpu_get() helper in the scheduler fast-path leads to "BUG: scheduling while atomic" on PREEMPT_RT [1]. Pass the cached cpufreq policy object in sg_policy to the update_perf() instead of just the CPU. The CPU can be inferred using "policy->cpu". The lifetime of cpufreq_policy object outlasts that of the governor and the cpufreq driver (allocated when the CPU is onlined and only reclaimed when the CPU is offlined / the CPU device is removed) which makes it safe to be referenced throughout the governor's lifetime. Link: https://lore.kernel.org/all/20250731092316.3191-1-spasswolf@web.de/ [= 1] Signed-off-by: K Prateek Nayak Acked-by: Viresh Kumar Reported-by: Bert Karwatzki --- drivers/cpufreq/amd-pstate.c | 3 +-- drivers/cpufreq/cpufreq.c | 4 ++-- drivers/cpufreq/intel_pstate.c | 4 ++-- include/linux/cpufreq.h | 4 ++-- kernel/sched/cpufreq_schedutil.c | 5 +++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 5818a92d96b9..455e58a9b738 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -697,13 +697,12 @@ static unsigned int amd_pstate_fast_switch(struct cpu= freq_policy *policy, return policy->cur; } =20 -static void amd_pstate_adjust_perf(unsigned int cpu, +static void amd_pstate_adjust_perf(struct cpufreq_policy *policy, unsigned long _min_perf, unsigned long target_perf, unsigned long capacity) { u8 max_perf, min_perf, des_perf, cap_perf; - struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cpufreq_cpu_= get(cpu); struct amd_cpudata *cpudata; union perf_cached perf; =20 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 50dde2980f1b..8bdc8f9b8d86 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2244,12 +2244,12 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); * parallel with either ->target() or ->target_index() or ->fast_switch() = for * the same CPU. */ -void cpufreq_driver_adjust_perf(unsigned int cpu, +void cpufreq_driver_adjust_perf(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity) { - cpufreq_driver->adjust_perf(cpu, min_perf, target_perf, capacity); + cpufreq_driver->adjust_perf(policy, min_perf, target_perf, capacity); } =20 /** diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index ec4abe374573..8d25f0f2925c 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -3237,12 +3237,12 @@ static unsigned int intel_cpufreq_fast_switch(struc= t cpufreq_policy *policy, return target_pstate * cpu->pstate.scaling; } =20 -static void intel_cpufreq_adjust_perf(unsigned int cpunum, +static void intel_cpufreq_adjust_perf(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity) { - struct cpudata *cpu =3D all_cpu_data[cpunum]; + struct cpudata *cpu =3D all_cpu_data[policy->cpu]; u64 hwp_cap =3D READ_ONCE(cpu->hwp_cap_cached); int old_pstate =3D cpu->pstate.current_pstate; int cap_pstate, min_pstate, max_pstate, target_pstate; diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 0465d1e6f72a..fd26b3a4aa28 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -367,7 +367,7 @@ struct cpufreq_driver { * conditions) scale invariance can be disabled, which causes the * schedutil governor to fall back to the latter. */ - void (*adjust_perf)(unsigned int cpu, + void (*adjust_perf)(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity); @@ -612,7 +612,7 @@ struct cpufreq_governor { /* Pass a target to the cpufreq driver */ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq); -void cpufreq_driver_adjust_perf(unsigned int cpu, +void cpufreq_driver_adjust_perf(struct cpufreq_policy *policy, unsigned long min_perf, unsigned long target_perf, unsigned long capacity); diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedu= til.c index 0ab5f9d4bc59..307f3076635e 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -461,6 +461,7 @@ static void sugov_update_single_perf(struct update_util= _data *hook, u64 time, unsigned int flags) { struct sugov_cpu *sg_cpu =3D container_of(hook, struct sugov_cpu, update_= util); + struct sugov_policy *sg_policy =3D sg_cpu->sg_policy; unsigned long prev_util =3D sg_cpu->util; unsigned long max_cap; =20 @@ -482,10 +483,10 @@ static void sugov_update_single_perf(struct update_ut= il_data *hook, u64 time, if (sugov_hold_freq(sg_cpu) && sg_cpu->util < prev_util) sg_cpu->util =3D prev_util; =20 - cpufreq_driver_adjust_perf(sg_cpu->cpu, sg_cpu->bw_min, + cpufreq_driver_adjust_perf(sg_policy->policy, sg_cpu->bw_min, sg_cpu->util, max_cap); =20 - sg_cpu->sg_policy->last_freq_update_time =3D time; + sg_policy->last_freq_update_time =3D time; } =20 static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 t= ime) --=20 2.34.1