From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 EE8053590A9 for ; Tue, 31 Mar 2026 07:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774941064; cv=none; b=CnFz54qyd4fg8RFp5BqOTlsDvS27jyKZraxxsG2ls0bAnxuL/ZS7ABp4c/7vyTKTr+KnHNUMj2rn1b+U0jdyGg363OmHKZ8vpqK/OMqqircaXlEgrUXkSnaoYVBoQzLNgVRyX2xs4FnA1fnQTTArlBLhLU1ApWIrDze2ZMOSN0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774941064; c=relaxed/simple; bh=6R4gXuB/h+BJWvQ+CyjpXaet8ZV90sqEMx6l3shGFgY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MWFQ4F3BlJgbpcPJz4IQi9cDM+v/uwhlrSA5NUtFoXuS6PwcMVB2gOAkPUTJInEAqODUBHnqtIi9jZP/8Su9qotKv9BjOw4ar/RdrgIjBYR3H4aopFAz4sYFapDVzuqDn7KO8fAP6FuWbVNXs4HdzJlE8tCJdyortpwAMOEOAlI= 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=UomUmIDB; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=DPT2joVq; arc=none smtp.client-ip=205.220.180.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="UomUmIDB"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="DPT2joVq" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62V5RVM01841971 for ; Tue, 31 Mar 2026 07:11:02 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= kDYIGHGFRibBsxSj/d6PGjsRu/pA4unCsga4OGe4mtY=; b=UomUmIDBAzA2628x 5ofCNxClgq3C3hXQdeWbeoKtrdKqzw+ioQ7qUIQX7AkQ6Q/PahtQw8AoE4sz5ixA R0Q942wTzktlnfwhj8HISfZlOEbR0nh2DwqnBRDcLwEpY7JMcNMzfkWdrBNyZU4J P5+Ltnwb+zz8E/RLZ9QO3EDT7WNbUYBkhg7zr4t2Plo5bWrznwtb4aC0SAY+gJjy 9lOfalfWbxY61yqfF/rzu30elsjMNieJTvZ9LnLjLa7ZiBzg19N8oyTQaONAJUmK MX8h1X2fjKm14Su5LDDItHr08cDNBd0K9yz00pg223tgMq9S9oClchhZYVOSuUnq VMMiJw== Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4d80rshs39-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 31 Mar 2026 07:11:01 +0000 (GMT) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-c769e2b1bd0so1119727a12.2 for ; Tue, 31 Mar 2026 00:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1774941060; x=1775545860; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kDYIGHGFRibBsxSj/d6PGjsRu/pA4unCsga4OGe4mtY=; b=DPT2joVqw+oVfMxFofMMqPusxrjEHLkBk+sT9aOrt4x4xA3TInyS/CXtPRKn6kaBS7 IHFkN5F7G2rbPMsoFcEJmoBkAuwAY9bd4s+D7+wCWLiZTQT9z0A/GL5eOWcLNsPqAeix HJx+kFPxQ+nR7ljXByCgAdU0FD5GeveUWkiWj2h79wigJ9Q9IgK8bMfTnhlu1rELT1H1 FoPs4CiQM26Y3olUTYRK/3OBA0RZRPolHebwzK5URd1hC569cUdDPrRTD0udILjh77gV GoVD4IBkQSfLUV2e/cY9b6jSdeTCbxI2rADkdAOMo3B23KINr1/WJsoxijtfOvQzgBOi 37BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774941061; x=1775545861; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc: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; bh=kDYIGHGFRibBsxSj/d6PGjsRu/pA4unCsga4OGe4mtY=; b=DWV7S0OHYVR3fS/9cAcLfb+72aXD/rJpkrwTtKp5VcJndpS6QPRKt3qbQ4QXXMfe+p GuwGmp0mHL9UJq4V+VXJQNmyRgoe3BbLSJSnREcGnN7msTKl0JFhzTztq4/Slvjzdhmf azu16z2Ivj/V96ljkpk75Vdm2RkEbVkfPPVtFGNDxgjUc367t44UhyIyDKdcwzdSpFLT x2SrRJGkNhiGgtU/lTKqNAt/BLKECyFim1cgECQS587bqjxGZg7zd913IWiCyAgsOErW iHYdZbrGyxkvsy1olRhvm8SJRFXEjcQNj1dzk8xljbIqSsmaBOpcZ4rR6rfx4ZIDZJE/ o49A== X-Forwarded-Encrypted: i=1; AJvYcCXwNDP94X+GZGDv3ga5InMD9MseYzPusT/7hS6oRzJOaqNy1tggISP94KBCVWzwRPVL1vax3V5ZLmcEUw4=@vger.kernel.org X-Gm-Message-State: AOJu0YxITW1Mi2tMAKkDijNtXu+yiCRNgL8YP4QxcvObwa3LyP/LhOdF t54Cee9kQlsz8H0CM1cdchVEJmNlYUD5/+84laauxVljbTSCZ0yQmqpodRL8qn37rfcUWeHDyT5 vXKT6C6sr4Mz+tPVRmLv8g68LVBnsESgFshu9gkFQD5/CJgp2HIBX4eCspsHypFuLkoc= X-Gm-Gg: ATEYQzxERXH3cGCpMxia0N+UN21P/l3QLx97JIucwQQ0IjNFp2sOXtvVKc2fgo3kKjV l0owtoQ6WFgxM6S3xwsSc8ij61VpFybl1CJHvnocCAhh/oc83BzLBB/xXv4ZeOXH60N8ubSWy3Q AFeJX7GXqem1pCKF6pP2NOqaAeC+9Vi3VGIewBi9r8L7cj2n2Es6mo6/x4fIwrGzo459EmNkCvg mBnreZg6Cr8Yq0cIQ8dwSxp8fTmwxSV2MaXcGm6yIT/CTNl+6KnaHy/dLyRKjQvcV2pG0wgPgar qdQKDTuScPpTyq5kePimqkYuOxI0vPwoSVLHfTOsrf6TRvEB04Uavp9wUeUzuGSm1zmm+1SzUSw 0DN2j/MRtaBeIn7QzJhOODPwB8QwsNwPFgySR8rsymjOlAFy5vNYHoGJyFtGWQUh3Zx5DGntvAk mPqCL/mwqgVwYm2JNt X-Received: by 2002:a05:6a00:4147:b0:827:2ee4:c90f with SMTP id d2e1a72fcca58-82c9605dbb2mr13455056b3a.53.1774941060521; Tue, 31 Mar 2026 00:11:00 -0700 (PDT) X-Received: by 2002:a05:6a00:4147:b0:827:2ee4:c90f with SMTP id d2e1a72fcca58-82c9605dbb2mr13455011b3a.53.1774941059890; Tue, 31 Mar 2026 00:10:59 -0700 (PDT) Received: from [10.133.33.66] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca846d8a9sm9732615b3a.19.2026.03.31.00.10.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Mar 2026 00:10:59 -0700 (PDT) Message-ID: Date: Tue, 31 Mar 2026 15:10:54 +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: Re: [PATCH] cpufreq: Allocate QoS freq_req objects with policy To: Viresh Kumar , "Rafael J. Wysocki" , Pierre Gondois , Lifeng Zheng Cc: linux-pm@vger.kernel.org, Vincent Guittot , Sumit Semwal , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, zhongqiu.han@oss.qualcomm.com References: Content-Language: en-US From: Zhongqiu Han In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: oHsgM8lVUVisUr2fRg8M88EUsl52rYFk X-Authority-Analysis: v=2.4 cv=VInQXtPX c=1 sm=1 tr=0 ts=69cb7385 cx=c_pps a=rz3CxIlbcmazkYymdCej/Q==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=KKAkSRfTAAAA:8 a=kjUqTUbl9X0R13TV6OoA:9 a=QEXdDO2ut3YA:10 a=bFCP_H2QrGi7Okbo017w:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: oHsgM8lVUVisUr2fRg8M88EUsl52rYFk X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzMxMDA2NyBTYWx0ZWRfX5+ETPphFO23s 74Uukizp6HIxHZO5sdLnaWtQqvSOUik/AC1dhG54i9LnaOd/SQKw+CoegpTIt2cXPdwwWdnXixO vr+0CuaEgjzc54od5RSirl8PhyFZQEzv6xEqJMzhVF3lbT6PqLh4seXDYTFR3iFD6CWuOg7l06F Nkjordwhf8eGqsuGS5WlcVhKLsj3tVWzRcss2mDnNqKwZ3WuY59eRQG0BsivqBRcLwrtOuyPBZW zPJ+e7ofE+dK1iNC9FynJjjzCvBynywxBZUX/wPuhtiPN/x0wEKD1XoSPRubWD94jhzIswp7poc Giv9Oa81s68jItJD9V6xPrNsCeo9P/SqIg6KzK+uWRuCeqqx1CVuxCNOs4EfX+JtkUpngAQ2vPS D5Z5KhtuJV5Cjg5dBdzScJPd9GrDdVBzYpQLzQ6ZJY6HGg7WhtQqNahnGrbU5makzKY3rkqJZyp Ne5Qt+TiKfRqk0OPtUg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-31_02,2026-03-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 spamscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603310067 On 3/31/2026 1:03 PM, Viresh Kumar wrote: > A recent change exposed a bug in the error path: if > freq_qos_add_request(boost_freq_req) fails, min_freq_req may remain a > valid pointer even though it was never successfully added. During policy > teardown, this leads to an unconditional call to > freq_qos_remove_request(), triggering a WARN. > > The current design allocates all three freq_req objects together, making > the lifetime rules unclear and error handling fragile. > > Simplify this by allocating the QoS freq_req objects at policy > allocation time. The policy itself is dynamically allocated, and two of > the three requests are always needed anyway. This ensures consistent > lifetime management and eliminates the inconsistent state in failure > paths. > > Reported-by: Zhongqiu Han > Fixes: 6e39ba4e5a82 ("cpufreq: Add boost_freq_req QoS request") > Signed-off-by: Viresh Kumar Thanks for the elegant solution. It looks good to me. Reviewed-by: Zhongqiu Han > --- > drivers/cpufreq/cpufreq.c | 53 +++++++++++---------------------------- > include/linux/cpufreq.h | 6 ++--- > 2 files changed, 17 insertions(+), 42 deletions(-) > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index c0aa970c7a67..f4a949f1e48f 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -614,7 +614,7 @@ static int policy_set_boost(struct cpufreq_policy *policy, bool enable) > return ret; > } > > - ret = freq_qos_update_request(policy->boost_freq_req, policy->cpuinfo.max_freq); > + ret = freq_qos_update_request(&policy->boost_freq_req, policy->cpuinfo.max_freq); > if (ret < 0) { > policy->boost_enabled = !policy->boost_enabled; > cpufreq_driver->set_boost(policy, policy->boost_enabled); > @@ -769,7 +769,7 @@ static ssize_t store_##file_name \ > if (ret) \ > return ret; \ > \ > - ret = freq_qos_update_request(policy->object##_freq_req, val);\ > + ret = freq_qos_update_request(&policy->object##_freq_req, val); \ > return ret >= 0 ? count : ret; \ > } > > @@ -1374,7 +1374,7 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) > /* Cancel any pending policy->update work before freeing the policy. */ > cancel_work_sync(&policy->update); > > - if (policy->max_freq_req) { > + if (freq_qos_request_active(&policy->max_freq_req)) { > /* > * Remove max_freq_req after sending CPUFREQ_REMOVE_POLICY > * notification, since CPUFREQ_CREATE_POLICY notification was > @@ -1382,12 +1382,13 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) > */ > blocking_notifier_call_chain(&cpufreq_policy_notifier_list, > CPUFREQ_REMOVE_POLICY, policy); > - freq_qos_remove_request(policy->max_freq_req); > + freq_qos_remove_request(&policy->max_freq_req); > } > > - freq_qos_remove_request(policy->min_freq_req); > - freq_qos_remove_request(policy->boost_freq_req); > - kfree(policy->min_freq_req); > + if (freq_qos_request_active(&policy->min_freq_req)) > + freq_qos_remove_request(&policy->min_freq_req); > + if (freq_qos_request_active(&policy->boost_freq_req)) > + freq_qos_remove_request(&policy->boost_freq_req); > > cpufreq_policy_put_kobj(policy); > free_cpumask_var(policy->real_cpus); > @@ -1452,57 +1453,31 @@ static int cpufreq_policy_online(struct cpufreq_policy *policy, > cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); > > if (new_policy) { > - unsigned int count; > - > for_each_cpu(j, policy->related_cpus) { > per_cpu(cpufreq_cpu_data, j) = policy; > add_cpu_dev_symlink(policy, j, get_cpu_device(j)); > } > > - count = policy->boost_supported ? 3 : 2; > - policy->min_freq_req = kzalloc(count * sizeof(*policy->min_freq_req), > - GFP_KERNEL); > - if (!policy->min_freq_req) { > - ret = -ENOMEM; > - goto out_destroy_policy; > - } > - > if (policy->boost_supported) { > - policy->boost_freq_req = policy->min_freq_req + 2; > - > ret = freq_qos_add_request(&policy->constraints, > - policy->boost_freq_req, > + &policy->boost_freq_req, > FREQ_QOS_MAX, > policy->cpuinfo.max_freq); > - if (ret < 0) { > - policy->boost_freq_req = NULL; > + if (ret < 0) > goto out_destroy_policy; > - } > } > > ret = freq_qos_add_request(&policy->constraints, > - policy->min_freq_req, FREQ_QOS_MIN, > + &policy->min_freq_req, FREQ_QOS_MIN, > FREQ_QOS_MIN_DEFAULT_VALUE); > - if (ret < 0) { > - kfree(policy->min_freq_req); > - policy->min_freq_req = NULL; > + if (ret < 0) > goto out_destroy_policy; > - } > - > - /* > - * This must be initialized right here to avoid calling > - * freq_qos_remove_request() on uninitialized request in case > - * of errors. > - */ > - policy->max_freq_req = policy->min_freq_req + 1; > > ret = freq_qos_add_request(&policy->constraints, > - policy->max_freq_req, FREQ_QOS_MAX, > + &policy->max_freq_req, FREQ_QOS_MAX, > FREQ_QOS_MAX_DEFAULT_VALUE); > - if (ret < 0) { > - policy->max_freq_req = NULL; > + if (ret < 0) > goto out_destroy_policy; > - } > > blocking_notifier_call_chain(&cpufreq_policy_notifier_list, > CPUFREQ_CREATE_POLICY, policy); > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > index b6f6c7d06912..9b10eb486ece 100644 > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -79,9 +79,9 @@ struct cpufreq_policy { > * called, but you're in IRQ context */ > > struct freq_constraints constraints; > - struct freq_qos_request *min_freq_req; > - struct freq_qos_request *max_freq_req; > - struct freq_qos_request *boost_freq_req; > + struct freq_qos_request min_freq_req; > + struct freq_qos_request max_freq_req; > + struct freq_qos_request boost_freq_req; > > struct cpufreq_frequency_table *freq_table; > enum cpufreq_table_sorting freq_table_sorted; -- Thx and BRs, Zhongqiu Han