From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 B4F0323D7F0 for ; Tue, 18 Aug 2026 08:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787042335; cv=none; b=oa0IdoO+uSA47GLTA9rhMSypIL/MwxHlPbEXwfFDWycoPUH0gFJPVqVyYFGU3wc2eDIo4ZssTRgFqV5RBIrPevQGFQ+yCOsfgzRlL1VAtIn4QoIn+kki2jbcw/c9HbWduJHzLlaupLuluyCtB/1IciFIKGN5N7Ll1MTHtR7ARII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787042335; c=relaxed/simple; bh=10C+aKkndvTFwjX2ouUKHjE0IojdR2l9XxRR/+V6Onk=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=Ea/J2t9PejD/qpOntHbVvlg50oD+rpJyDK5CV0nINSiIef6GxTwpnlP9EK3SHeEyjJgTFrnjf9wb5mQ2LYfx0rpqmvAPriklCVqqKGgL6EMZT8xfz6DlatdKPGjaGBEVGqdrZbPDMefaZoBrKe93KKmDrkqVP8VqKi1KlQZ92I8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=G2SnlebW; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=jiYl1uhF; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="G2SnlebW"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="jiYl1uhF" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67I8BSbs3991394 for ; Tue, 18 Aug 2026 08:38:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= dLREtGWTkSUjn29exUK1OZ2N4OeeZT3AxstfVt1QzL4=; b=G2SnlebWQFAfqrBg MIWuVmTjzzbvVrcxU8L1W9tLHSRXllDFerL6wnMJZ85+SdeKajwlHIKuw4NVudTP 5ZC0ilbhyXHoFEo6NhiJIVBKhqLx/Gztk2ZQWSWRBkQAGdiqMoPX8qMoj+qXXvoD q+5Q/bdwoMfb7weXIOev2UxBcQstbEicMKUg5e1TZVjKjMuyYA1Sf6bCu/8shSRb 3/E3m7Nw3bgLJ63opTOEHACXXLZV0dlhPH3p4YknjWhWv+sh4DkMlXwLr/lw7GzB UA3EVkyeuLpxFQU11+FwHZZv/l0qUEPldTnYNXoqS4HDTrU8w9bn2U8hRvyLfsVp DfxOsA== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g4f5psa7c-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 18 Aug 2026 08:38:52 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38e7ff7b375so5764617a91.1 for ; Tue, 18 Aug 2026 01:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787042332; x=1787647132; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:cc :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=dLREtGWTkSUjn29exUK1OZ2N4OeeZT3AxstfVt1QzL4=; b=jiYl1uhFk2zi9zsvhzxCKa3bv9enulcHbei2chbGz3T57uV7++AAW+s9FLLsIbqmZ6 Qjq+GwKjp9f8PokTEPQaihascnB4vbgosWMn9YDS50Xodfwek/oMKkk/loLI3+5t8t4I VG8wBs16a95RgcVFN7Pgdo8tPUluk4Yxtc3kvMAcuoHPvlU9ELuqP13vhxz2fwpBKJLw jTrJ9v/WdgZGwrqAVvJjV9hdxesGBbvlZyQdqgZufLpxZdGWFBZmRlfSrkMnUhYC1Fvd 3nez2FjVaYSHxDIIAaxixug+J+/b1GrGij/ZzgyY7eMrxqWyj2JW04vZbd9/Fv0dD+XS ldRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787042332; x=1787647132; h=content-transfer-encoding:content-type:in-reply-to:from:cc :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dLREtGWTkSUjn29exUK1OZ2N4OeeZT3AxstfVt1QzL4=; b=ftoXZ5nE0fdQfdPHc4P6hkEPUO8FJX6Lyp74EjhiFPPR8eG662geJErtbUhCymF3ce 3fcrBrvvh8KW/8dWGJDg537GIuKcy8SO8+Isd/H+Ltkx1NQvNM+n/T9JSHZjVBPfVF1L Zk/9w2vewHM8XuaYRtXLi+mXvXrxyh536T5pKQce057y5WCIFV2Y1conr651GTy4oHM3 fYXurSlHvuhMV+70kKm8g/bBXe7YA6Xxl9I1x/EM5b9uBLBsid7x4hhsEey4o0rmYIWJ +SVPiYbw8ajOx071aBpxNJKyYtgE/4qx4uYY1rtR2IENkbh4Jd5VMb8KCPnPf6cI50fA lNjA== X-Forwarded-Encrypted: i=1; AHgh+Rr0qWCDpzgUAak1ekJxw0TaDeNwyYk/OsKb2+EesSYI12lIFR2Wo/WqHU4UePWSZoHQXcCtKXChBzRuhbU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxow+5YyBOgOh9XuBgaHfKEOMj5901VwGD65ofL3/Ia5IQ8Vk5L RZG3KNag7L7kZcnft7MW+56gOFekAcPoZeCvHx9yh2PG+w71GoFhFtkg1cV+z0yiiOfgee0Y/zb xYjL2xiTYA9AYOSbZV9TrGSBRZdYqFOjaqVtSfmeg8wbOHZ2+JPWNczG/b/RFpQqcFYY= X-Gm-Gg: AR+sD13XNtuehr3QSBJdUyBlWP6Vkz7wkdqBsChV0MuNz3AGJDzuv8Z+pCIiBpWIdCa fhKSFg2xk8g61vVMVEmMj6zz2xP+ozsNAzIWhc21Vkdcfi8vixI4nL74d7aAvWr11MPwfGfqubv NXpBjdebJkyn3srgJJjrGCrv9xwzdJr+CIsBo3Z05NAK+svA0XxE2EK/QqEsMyVYqo1CwzK5Frh 8fI/sir8WINPsTeQ3FNKjTpfJDl3a6bfek8l94lQ/BLRzIJt+2lv+rJCUgRJ1OOIpvsEZV6K6XH fkxIm3wfrTJe2OlZ9aSDUhTvvIfDOVgV28G5ABVeU16veAWEupFhgEDZWhpDSOYYIzvN7awkW9p cur7aKgN5xGul7IIvmiu92CwELS4y X-Received: by 2002:a17:90b:3842:b0:38e:524:8797 with SMTP id 98e67ed59e1d1-3933b89a285mr27085464a91.13.1787042332056; Tue, 18 Aug 2026 01:38:52 -0700 (PDT) X-Received: by 2002:a17:90b:3842:b0:38e:524:8797 with SMTP id 98e67ed59e1d1-3933b89a285mr27085430a91.13.1787042331483; Tue, 18 Aug 2026 01:38:51 -0700 (PDT) Received: from [10.239.133.197] ([114.94.8.21]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3933b71e1f9sm5281522a91.3.2026.08.18.01.38.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Aug 2026 01:38:50 -0700 (PDT) Message-ID: <95d8a7fc-1167-4cba-b3ca-9d88e9f0f165@oss.qualcomm.com> Date: Tue, 18 Aug 2026 16:38:45 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?UTF-8?B?UmU6IOetlOWkjTogW+WklumDqOmCruS7tl0gUmU6IFtQQVRDSCB2MiAx?= =?UTF-8?Q?/2=5D_cpufreq=3A_acpi-cpufreq=3A_fix_P-state_index_mismatch_in_ex?= =?UTF-8?Q?tract=5Fio=28=29?= To: "Li,Rongqing" , "Rafael J . Wysocki" , Viresh Kumar , "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20260813090145.2450-1-lirongqing@baidu.com> <20260813090145.2450-2-lirongqing@baidu.com> <6c7fc9bf3fb54d94893b0de76dfa2897@baidu.com> Content-Language: en-US Cc: zhongqiu.han@oss.qualcomm.com From: Zhongqiu Han In-Reply-To: <6c7fc9bf3fb54d94893b0de76dfa2897@baidu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=S+/pBosP c=1 sm=1 tr=0 ts=6a841a1c cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=Uz3yg00KUFJ2y2WijEJ4bw==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=5KLPUuaC_9wA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=zuLzuavZAAAA:8 a=IrGDMXkZbe6EnHNMZBoA:9 a=QEXdDO2ut3YA:10 a=rl5im9kqc5Lf4LNbBjHf:22 X-Proofpoint-GUID: rginETmL9mA_EqXVc5cL_q_R-m3VoyDN X-Proofpoint-ORIG-GUID: rginETmL9mA_EqXVc5cL_q_R-m3VoyDN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODE4MDA2MyBTYWx0ZWRfX6Q5vfap+6Clw HIg2xONh2YNlgEBJisoU46Xl2wdPBnnTZOryUz16lnUCe97ECYii5Q61c1ZWdsDpUanjSrQ4WKg U1aK0KeSrJtaZWaG69Q3Q4jcWBXzsKROMETkSMQwgm7HS5v8UIpJQXMfGIO7U647/KPObgVitoU /OUPv6WvKMfFAqHHur9jWrR0JSZ7U6DMRtrvyvW9qci1FVp1r3qh4TGkh2ZXQ86l0V3i2BWdp3Q 4vpj7Unu4jW8/Q+O8E7pqfu9HHuYs7lOO5GPNERgvh/qFmx/UGynO/6VEeet76BvtG7RqNVTqgQ BTRubr4EZk0gy0lQSW9St8dVA8TPzBPGkZ18st+PMNK1q29MkVNyzinPZNcr1vKgq1BBCi1ZJyb JhFqJeGpX16Vpx9qdghUK5MWmZDgKWJaycSPmDS8Q6gbN+xRaSUhtFYTkJg7wTOY5oGpUdG0hqK twiZJgtnoHt3idwBssQ== X-Proofpoint-Spam-Info: AW1haW4tMjYwODE4MDA2MyBTYWx0ZWRfXxkpR5EDoRZMZ XSSccoJvOQNZdMxF4olvsJrLXSk63vFqRBQGLGH0ZWboJ/5QQDhV0GQqFoTVofB9WH/HVKPLDKB k95izyiS6zoUqDSBNIpRjWLz4FPmaiI= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-17_04,2026-08-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 impostorscore=0 adultscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608180063 On 8/18/2026 2:46 PM, Li,Rongqing wrote: >>> When policy->freq_table is built in acpi_cpufreq_cpu_init(), entries >>> with duplicate frequencies are skipped. The original P-state index for >>> each remaining entry is stored in freq_table[].driver_data, so the >>> index space of freq_table no longer matches perf->states[]. >>> >>> extract_io() walks perf->states[] with index i and uses the same i to >>> index policy->freq_table[i]. This causes two problems when duplicate >>> frequencies exist: >>> >>> - Returning the frequency of the wrong P-state >>> - Returning 0 from a zeroed tail entry, or even CPUFREQ_TABLE_END >>> (~1u) reported as 0xfffffffe kHz >> >> AFAICT, It may be worth expanding the changelog to cover the consequences >> described below , particularly the resulting divergence between the hardware >> state and the cpufreq core's view of the current >> frequency: >> >> Furthermore, extract_io() is only reachable on ACPI_ADR_SPACE_SYSTEM_IO >> platforms, where cpufreq_driver->get is not installed, so its only caller in >> practice is check_freqs(), i.e. only when the acpi_pstate_strict module >> parameter is set. >> >> There, the mismatched lookup makes the frequency comparison fail even >> though drv_write() has already switched the hardware to the requested P-state. >> So check_freqs() sleeps through all 100 iterations - at least >> ~1 ms of usleep_range() plus 100 cross-CPU calls and I/O port reads, all with >> policy->rwsem held - and ->target_index() returns -EAGAIN. perf >> ->state is therefore left at its previous value while the hardware sits >> at the new one. >> >> The core then restores policy->cur to the old frequency, and because >> __cpufreq_driver_target() returns early when the requested frequency equals >> policy->cur, the driver is not called again for it - so the control register is not >> rewritten and the CPU is left running at a frequency the core does not know >> about. >> >> >>> >>> Fix it by walking policy->freq_table with cpufreq_for_each_entry() and >>> using perf->states[pos->driver_data].status, aligning with extract_msr(). >>> >>> Fixes: 8cee1eed8e78 ("cpufreq: ACPI: Remove freq_table from >>> acpi_cpufreq_data") >> >> The real tag should be fe27cb358835 ("[CPUFREQ][2/8] acpi: >> reorganize code to make MSR support addition easier") >> >> That commit added both the entry-skipping loop with the freq_table[].index >> (now .driver_data) back-pointer, which is what makes the two indices diverge, >> and the faulty lookup itself -- back then in a function called extract_freq(). >> dde9f7ba60ad ("[CPUFREQ][3/8] acpi >> cpufreq: Pull in MSR based transition support") merely renamed it to >> extract_io(). >> > > Thanks, I will send v3 Thanks, I will review the patch v2 2/2 > > [Li,Rongqing] > > >> >>> Signed-off-by: Li RongQing >>> --- >>> drivers/cpufreq/acpi-cpufreq.c | 9 ++++----- >>> 1 file changed, 4 insertions(+), 5 deletions(-) >>> >>> diff --git a/drivers/cpufreq/acpi-cpufreq.c >>> b/drivers/cpufreq/acpi-cpufreq.c index 21639d9..1abe9ab 100644 >>> --- a/drivers/cpufreq/acpi-cpufreq.c >>> +++ b/drivers/cpufreq/acpi-cpufreq.c >>> @@ -197,14 +197,13 @@ static unsigned extract_io(struct cpufreq_policy >> *policy, u32 value) >>> { >>> struct acpi_cpufreq_data *data = policy->driver_data; >>> struct acpi_processor_performance *perf; >>> - int i; >>> + struct cpufreq_frequency_table *pos; >>> >>> perf = to_perf_data(data); >>> >>> - for (i = 0; i < perf->state_count; i++) { >>> - if (value == perf->states[i].status) >>> - return policy->freq_table[i].frequency; >>> - } >>> + cpufreq_for_each_entry(pos, policy->freq_table) >>> + if (value == perf->states[pos->driver_data].status) >>> + return pos->frequency; >>> return 0; >>> } >>> >> >> >> -- >> Thx and BRs, >> Zhongqiu Han > -- Thx and BRs, Zhongqiu Han