From nobody Fri Sep 25 23:09:46 2026 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.83]) (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 B1AC73B8124; Mon, 7 Sep 2026 19:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=85.215.255.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788808948; cv=pass; b=sYHPSAeRUCtY9X+SpBTwi1qtkUuGGx9XQpQ25Og+axle3ggAaLSzEbHzi8b5j1B2cyth9JUedp5PQ0jyku+KAXlIEH8kBYBePmhYloAXEYjVOW3BkizVmyZNQerIu8ejav45Be8wY1cJMVjO9h3erup54e6gPTN+Ky9TfjIUyCc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788808948; c=relaxed/simple; bh=oY3N3aHhyFfh4TzdkQGcKa9+tBM0Re+wcfe7XgEUdQw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Ws47AA0v/1D4uUMGbAVVQhZqXYpsSVl9HMk5qVgVVMiymgB9j81S+QI3rOfAXCgabjAD8mDBgPWAhZx5bPvkzsdKKAqIBZg20nJjcP5zEkFVkdK7bpmKD689E5+O/kjUGmqWu7EgIPJu8MixkaRMXuLRRJes/uzQxFbT06P9BoI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de; spf=none smtp.mailfrom=iokpp.de; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=HVV+iKUy; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=TZJej+8O; arc=pass smtp.client-ip=85.215.255.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=iokpp.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="HVV+iKUy"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="TZJej+8O" ARC-Seal: i=1; a=rsa-sha256; t=1788808910; cv=none; d=strato.com; s=strato-dkim-0002; b=f3CgaXosVKj0voLF5H29DYWyVqZWzQy/U42OBfdP1EfBUR3VnmxW/F/yJaJ+jAJ503 oI+4WcvU3nXFDj86Dh6Y2SXU9jB7wz39bfXi/+mNpy/L4/DLfNXlVUx3Xl8ERBt4xIHX AlxtLrsPL/etnSjDPwqVl2AzMJhCZWDEyjS5CK/HRpnZGVqV3TJ2Be8H5qKW9rOnZ9WL n/1CQVTxPS83YaXyMu/Z48HqfbKk2zGnuGxETF880mss7sSkftsYNaUDLevE6rsUki71 xjM3p/66qQSempBAjMgjHN9+655DBNM/MIaP/mtEbn5VzWEedW7rdkt1zYbgEFo1W15c /AWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808910; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=mgEDvvUNxzael5eFRubLpo0j0BX0Gh6Xo8vGAYGbwIs=; b=SS4eDPcoODmhhM0oRPxnOqJ03ngM44pivAI0/ycOkEH1j5kk7HhQTQ82qIJfSJGyxY PmuzLHmHfbHPlMWcfFRNtvjuh1CSorltol+KhspMrXRXJYQ/uifVjUWrxrcMj3kY+LnU IUxgKftAbwpPTrUmlV+d+WJ4VkCQNW25uf8k1qQd1TQvCNRW6KFqwOh0PFLNEOGt4MjA puWzxVE5LYaKX/G7FX0WaXqphCGT5RnH8PMnRFJWYJGL7om1B+OmrdY/43PYg2pPEtAS pybPj8WtBNppDw8A06zwwEa7+tDiTcDSgCJCV31Rprbm+XN221rqO1i8tdpGB4i1akLp Iapw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808910; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=mgEDvvUNxzael5eFRubLpo0j0BX0Gh6Xo8vGAYGbwIs=; b=HVV+iKUyhncLDmqI5A5pR1XzNA2dWSiBOg0FGjC6hU46J4aPvMcAyX4XGHAZx9PZUY p+w9kZrZxiOnyRWTadikdcFMRRpGVm4qPg1AK9b7Xba/88dRWUxWYhtjXWO8rcGhsbby YnexmsKZQT4pzt6iaq6eo3pG9vs6OwRfWcWRrmuxGlalWsQvT2yGOyvRcxFsXLSLfnj/ tWP1MMIKTU/WzegN7nxZ1W1myo3d8SBB9P9hnB7BYJFJ9pNCyLcrUhYptMmKlCo3kKJP xHa0y9hkkgOKvQKilderIaqHqxjIf/C49+5FvjxatDTvmpME2yngmswC3cnQwD7Nqclc rPEQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1788808910; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=mgEDvvUNxzael5eFRubLpo0j0BX0Gh6Xo8vGAYGbwIs=; b=TZJej+8OrSygUvZRg7g/kGK24CZeRD7GGlvZ9rYg7fnDlwPIrwNsWRGAHDx5hI6wBb 22VhmvDi/ZpmQuKMCNAA== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSfNuhhDSDt3O0JuBIIyqXfWze4EsqKg=" Received: from Munilab01-lab.. by smtp.strato.de (RZmta 55.6.2 AUTH) with ESMTPSA id ze37e1287JLnCsJ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 7 Sep 2026 21:21:49 +0200 (CEST) From: Bean Huo To: linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, MyungJoo Ham , Kyungmin Park , Chanwoo Choi , "Martin K . Petersen" , "James E . J . Bottomley" , Avri Altman , Bart Van Assche , Alim Akhtar , Stanley Jhu , Bean Huo Subject: [PATCH v2 1/4] PM / devfreq: Fall back to previous_freq when get_cur_freq() fails Date: Mon, 7 Sep 2026 21:21:37 +0200 Message-Id: <20260907192140.2701755-2-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260907192140.2701755-1-beanhuo@iokpp.de> References: <20260907192140.2701755-1-beanhuo@iokpp.de> 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 Content-Type: text/plain; charset="utf-8" From: Bean Huo devfreq_set_target() calls the optional ->get_cur_freq() callback to get the frequency that is passed as freqs.old to the DEVFREQ_PRECHANGE and DEVFREQ_POSTCHANGE notifiers, but it does not check the return value. If the callback fails without setting @freq, cur_freq is never assigned, and an uninitialized stack value is passed to the notifiers. hisi_uncore_get_cur_freq() can hit this. It returns -ENODEV without setting @freq when its PCC channel is missing. On the mailbox error path it sets @freq to 0 instead, so that the core does not read a random value. The other two callers, cur_freq_show() and devfreq_monitor_resume(), already check the return value and use devfreq->previous_freq when the callback fails. Do the same in devfreq_set_target(). This does not seem to cause a visible problem today. The passive governor is the only DEVFREQ_TRANSITION_NOTIFIER user in the tree, and it only reads freqs.new. So this patch is not marked for stable. Fixes: 0fe3a66410a3 ("PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER not= ifier") Signed-off-by: Bean Huo Reviewed-by: Avri Altman Reviewed-by: Jie Zhan =20 Reviewed-by: Stanley Jhu --- drivers/devfreq/devfreq.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index f08fc6966eae..f20d9a660779 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -348,9 +348,8 @@ static int devfreq_set_target(struct devfreq *devfreq, = unsigned long new_freq, unsigned long cur_freq; int err =3D 0; =20 - if (devfreq->profile->get_cur_freq) - devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq); - else + if (!devfreq->profile->get_cur_freq || + devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq)) cur_freq =3D devfreq->previous_freq; =20 freqs.old =3D cur_freq; --=20 2.34.1 From nobody Fri Sep 25 23:09:46 2026 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [85.215.255.81]) (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 E332446A5FB; Mon, 7 Sep 2026 19:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=85.215.255.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788809094; cv=pass; b=SZJABxXGkvtNnw3FCtVMNO/odBkybmqxyprfD2mj54P9YVbiX507NiCE74arlUTOMQy/qf+f+L5Bt1ZuOXVkxjtcW3Lx/iYBj9zCmY0SABzklbI6zP10ycjrDpB3rxO1LwfH/S7t1xMOBymGfrc4EMcrPznyXm4nQWKxtnq1KXY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788809094; c=relaxed/simple; bh=pGmlDyj6kEi/pZlOxdkNgatuXW5yQ2y4hlNY1o1vB18=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=GeEwuGnomC2YpF0fq3nmw0u/YtYy7gkXrg9q0LYgz1lNvuXxxqIVw/EcpwuVOs/28relkpYY0oK8Jnfm/nambaaQBrqWwWpUOvPY0G/XNYW4V9vTPQ9iymQRqzrAqjvZ9n5Hp8iTR95UZdBDZvE8FBWD1F6m/bNFwJjjzfbjMdc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de; spf=none smtp.mailfrom=iokpp.de; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=hoeZzi4u; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=4wX1GCC5; arc=pass smtp.client-ip=85.215.255.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=iokpp.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="hoeZzi4u"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="4wX1GCC5" ARC-Seal: i=1; a=rsa-sha256; t=1788808910; cv=none; d=strato.com; s=strato-dkim-0002; b=Dbf6iZZv5k4DYBI00dHHz/LyZqAEzYBim6OKB5X4T1Iu1duuYfE7sc0cHXyt/vTTqP k9HzC7WSKyJxlvAUm4ef45fBV7fwed1J3pgv7YQvpjB/goq5Bl3rFwAcLm5HFF5v7AtC FfsNfr1E2fMpxyzeJDctlOqgqccnwXnbk3PwxyX4NAi/Eh5YPGZlQxk0rmQWJtnM4dKO EF9EBo3eYISBn8tnFi2TQCdC0BjGA2el9ch8x8335zIezkmtyehggxNgZrTGVBbR9Lij 5xhPm4ZbNA3Ewwz09NZPNIEBWoJikUIDzlaewc4I5WJhHxS48Y/CKla9yAycPTEkJQY+ thPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808910; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=HYkoDkMO58/ar+Od/v2oKjQULCGRUjQgFPoaO/nCErs=; b=a9hsPhzpWEK+J8Q7oBE4P9D5A8MioXb/BjmS411DxhV5oCx9U2EmTVFBYZZ1gFQ3Bc MaJeiezxhQswCtq1ZCsbAD63ZGf54AKi5q3OkY7CoTZziUuDwHmefB60t19y0khoTAda +rnIeVQyIkjnJohL7u9wFQ9JKDuj8pbHc5OtSRNfDnvxCW5InwYBhA3fOrM0dEht6pds 0N2q1+TzKejmApuAYmODl+UJLbF7LuIhG2KNg8XEV3N7+F3EzZrWBfB79/JY3+rsSDS6 xBKYcXuJFKUvZGPpR1FKhiyhGLhXQytBSCJ6SIyl9mPGlaf6EbowI8cfHnUN/S93iWz/ 9+ig== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808910; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=HYkoDkMO58/ar+Od/v2oKjQULCGRUjQgFPoaO/nCErs=; b=hoeZzi4ucGWuVVVxta++wmKuilSUj6VY70xayZhCw3gKEZJpyuTa4lZswF5Ct8lgjH COajdiBMXViACpUrelXTZtBB0cjcDtg5R9ZFh7UsgXawKSh/Yp6Q2qxtpH7tp2C8cJ5/ +LfMX/K/0AyBkX+JZSy27wjoPK8gNRRozR+plSuyWKqME1VjGTQkpgTjtTsdyY9yxX4n +GtObN4iawWQs/W+UVxyMCOGgfRDXTTmCMRd+Zvzh+2DYdxVsAyNqc4W6vPH4jTCyJE0 +0YZLgypluO5siZagOQocnzLDdpdfBAxcrN5yVzbeA7o4fTIoHnIAowKWNMRFTuqzySR r9/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1788808910; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=HYkoDkMO58/ar+Od/v2oKjQULCGRUjQgFPoaO/nCErs=; b=4wX1GCC5PhtDW1UuaMNyX5SxcuiOqyUcFqgGWShMg4vC3u9r4ZKoIWpZ6Sx3elfC1t xkIhWiWNBEExOs1Jd4Dg== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSfNuhhDSDt3O0JuBIIyqXfWze4EsqKg=" Received: from Munilab01-lab.. by smtp.strato.de (RZmta 55.6.2 AUTH) with ESMTPSA id ze37e1287JLoCsK (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 7 Sep 2026 21:21:50 +0200 (CEST) From: Bean Huo To: linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, MyungJoo Ham , Kyungmin Park , Chanwoo Choi , "Martin K . Petersen" , "James E . J . Bottomley" , Avri Altman , Bart Van Assche , Alim Akhtar , Stanley Jhu , Bean Huo Subject: [PATCH v2 2/4] PM / devfreq: Add more details to the get_cur_freq() comment Date: Mon, 7 Sep 2026 21:21:38 +0200 Message-Id: <20260907192140.2701755-3-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260907192140.2701755-1-beanhuo@iokpp.de> References: <20260907192140.2701755-1-beanhuo@iokpp.de> 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 Content-Type: text/plain; charset="utf-8" From: Bean Huo The comment for ->get_cur_freq() only says that the device should provide the frequency at which it is operating. It does not tell the driver author which unit to use, what the return value means, or that the frequency should be one of @freq_table. These have to be found by reading the devfreq core. Add these details to the comment. Signed-off-by: Bean Huo Reviewed-by: Avri Altman Reviewed-by: Jie Zhan > --- Reviewed-by: Stanley Jhu --- include/linux/devfreq.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index dc1075dc3446..809ef29b9af5 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -90,8 +90,11 @@ struct devfreq_dev_status { * use this directly. Instead, governors are recommended * to use devfreq_update_stats() along with * devfreq.last_status. - * @get_cur_freq: The device should provide the current frequency - * at which it is operating. + * @get_cur_freq: The device should provide the frequency, in Hz, at + * which it is currently operating, and return 0, or a + * negative errno on failure. The frequency should be one + * of @freq_table, as it is used for the transition + * statistics. * @exit: An optional callback that is called when devfreq * is removing the devfreq object due to error or * from devfreq_remove_device() call. If the user --=20 2.34.1 From nobody Fri Sep 25 23:09:46 2026 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.170]) (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 3D7A0525A7F; Mon, 7 Sep 2026 19:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=81.169.146.170 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788809097; cv=pass; b=pQ6jmGxCDSU50ENc57wmHCNe+CueQJWiWZgREl8FxhlrwGX4DCSV6BZbRYIh1S+VRJh50iGpZe4U3u9xCK3ghSc3Fk0/KB6Tyn7I59u75fbepwrdNioYsHJs9HeksNTTqPKt2TRlfIEDPlZiZTigjvt+cZeFbis1g095U9K4vPc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788809097; c=relaxed/simple; bh=z8/LbN4GvRWMa1Awdne7SOiBoRZtd5hXxbxRwoQKATg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Nri4R5QtM53sYQ1wEkWF+h/jQ+bmFo2F+3G44kr1eQpoGfdwRFtuHz4cpX0bl6YLG4J6v1c9AJm83vIiXsxvD5GuIOII7lIRlRu09U1wdshJAmhQcYxPdytnzwQFl0/l/N4IzbJ9ZRWmpGcB0M2tbQAMGc75XjT2AP3tGy3ZrGk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de; spf=none smtp.mailfrom=iokpp.de; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=aUpF6NbI; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=aFAtzatz; arc=pass smtp.client-ip=81.169.146.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=iokpp.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="aUpF6NbI"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="aFAtzatz" ARC-Seal: i=1; a=rsa-sha256; t=1788808911; cv=none; d=strato.com; s=strato-dkim-0002; b=Roq2zVfMow6OGRqxVJ4LnyPsdK0PW/lS5HQoFrwojtVYbo67qehH9PpG0iZtPUkN/e jeAT2psUcXdqGfT/qXUNB34vQ7+QBDOyi1m9zNrD53v0eOiTo7wFhdcUWMucBkZcX+li zNBLg/s9dxyJNKx8Dadso2T5JO2Pw4IqK8tOUvFAamoJrmui+LV74ieqZxGEpzJvcV6i tSXm1zrHGDjmILZIZyNrQ7Emc9lA8vKOtexfwiShSmMm+WU7GuFOQSBBIVN14cJFdHjZ fONEG+few2uFQl+Khcj/FjYPSIy7bhXjJhUasqzl4fvJxQK/8RRkPQESf30ndUh6E7+H nKCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808911; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=H1cbDq3VQhnovGC+0efoWjTcvl/McAtBG8RhbfSzmqc=; b=d7v01WLBA+DF2h5oDJFGsuaEGdtvFVgwj4Bm9vLB9EQqjfdzZ6H7wCvRYShGwH6QSq U1FyMXUpACqdZ5ta0RZSbMDdj77LHfrv2Xz6IH7O4VDG6WkzacLNFSFiyPK5yKqocTD7 s8qpvQHM20xvEpj2afGo9pOakiuOyyAQLWFnwfsixsoYXS7AHgtg4Vfd3734IuYPRJG2 rPtRdoHVoX34aQhJNnIElhRE/wR2FjD8kAYjNlXfHaK1Wz4mqF0HLcXUa2N0avErymTV 08uJXQrELoC70cQUNTRxXV0T99raoy3iJrNoWn5kX5iFdgIEGMHgkbwvfK1HPN/UjYhz 5/Vw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808911; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=H1cbDq3VQhnovGC+0efoWjTcvl/McAtBG8RhbfSzmqc=; b=aUpF6NbIhaoFLdkqKRNUJ4kIrLNEkx5XV+ItCQwdPr2BSelo83zRTbrxWyKVkLvcAt QQmY2/J/WqUsANVttNBLx1U1vZnIhpJX4Mm+/ta4pcniVNT3hLK1CRWoLxgmfNUwbfUZ H1OPx/gCdVItQkes+lxWYpUpOxUVy56JJKOccWHHQPVZkGra1hS6q7cJprwQi7xejZUM +L/rSaRPeW42p5Tlvs1g7uJeXHDMbSO9ztaji1d+0uo6dlNjqJM6Fsjv/cE0DW8y92TH wDhKOAFSEUQMd9+hcfuV2MgkWlbRw1q/sI0iYF0Vc/s4CmkdcsAbizaOcBXLKYU4q5Sn i3KA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1788808911; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=H1cbDq3VQhnovGC+0efoWjTcvl/McAtBG8RhbfSzmqc=; b=aFAtzatzxbnvhyQiApug5jvZMhDc3bwSQ91a8nFFH/EDmi1zKiIRfA+nTHmht5r0Fl 9ekp4U4Cmpr98ivtYFCQ== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSfNuhhDSDt3O0JuBIIyqXfWze4EsqKg=" Received: from Munilab01-lab.. by smtp.strato.de (RZmta 55.6.2 AUTH) with ESMTPSA id ze37e1287JLoCsL (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 7 Sep 2026 21:21:50 +0200 (CEST) From: Bean Huo To: linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, MyungJoo Ham , Kyungmin Park , Chanwoo Choi , "Martin K . Petersen" , "James E . J . Bottomley" , Avri Altman , Bart Van Assche , Alim Akhtar , Stanley Jhu , Bean Huo Subject: [PATCH v2 3/4] scsi: ufs: core: Record the frequency the controller starts at Date: Mon, 7 Sep 2026 21:21:39 +0200 Message-Id: <20260907192140.2701755-4-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260907192140.2701755-1-beanhuo@iokpp.de> References: <20260907192140.2701755-1-beanhuo@iokpp.de> 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 Content-Type: text/plain; charset="utf-8" From: Bean Huo ufshcd_init_clocks() puts the controller at its highest frequency, but nothing writes that down. clk_scaling.target_freq stays 0, and devfreq_dev_profile.initial_freq is never set, so devfreq->previous_freq is 0 as well. With use_pm_opp this shows up in a few places. The target_freq attribute reads 0 until the governor scales for the first time. ufshcd_devfreq_get_dev_status() reports 0 Hz, which makes the ondemand governor ask for the maximum frequency. ufshcd_devfreq_target() then sees 0 !=3D max and runs a full ufshcd_devfreq_scale(), which holds up the queue for up to a second only to set the same OPP and the same gear again. Without OPPs the frequency is not reported as 0, but previous_freq is, and devfreq_update_status() then drops the first time_in_state update. Record the maximum frequency in ufshcd_devfreq_init() instead. ufshcd_add_lus() runs after ufshcd_probe_hba() has geared up to hba->max_pwr_info.info, so the clocks and the gear are both at their maximum by the time we get here. The only difference is that the first governor poll no longer redoes work that is already done. From the second poll on nothing changes, because target_freq held the maximum frequency there anyway. That first scale also re-applied the gear that ufshcd_vops_freq_to_gear_speed() maps the maximum frequency to, so it quietly corrected the link if the OPP table and the gear negotiated at probe disagreed. That does not happen any more. On ufs-qcom the two cannot disagree, because ufs_qcom_negotiate_pwr_mode() clamps the gear through ufshcd_negotiate_pwr_params() against the same controller capability the OPP table is written from. clki->max_freq is the right value in both modes. ufshcd_parse_clock_min_max_freq() fills it from the highest OPP, and ufshcd_clkscale_enable_store() already uses it the same way. Suggested-by: Stanley Jhu Signed-off-by: Bean Huo Reviewed-by: Stanley Jhu --- drivers/ufs/core/ufshcd.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 2ba244cf40ac..351c76094b9f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1681,11 +1681,6 @@ static int ufshcd_devfreq_get_dev_status(struct devi= ce *dev, if (!scaling->window_start_t) goto start_window; =20 - /* - * If current frequency is 0, then the ondemand governor considers - * there's no initial frequency set. And it always requests to set - * to max. frequency. - */ if (hba->use_pm_opp) { stat->current_frequency =3D hba->clk_scaling.target_freq; } else { @@ -1727,12 +1722,21 @@ static int ufshcd_devfreq_init(struct ufs_hba *hba) if (list_empty(clk_list)) return 0; =20 + clki =3D list_first_entry(clk_list, struct ufs_clk_info, list); + if (!hba->use_pm_opp) { - clki =3D list_first_entry(clk_list, struct ufs_clk_info, list); dev_pm_opp_add(hba->dev, clki->min_freq, 0); dev_pm_opp_add(hba->dev, clki->max_freq, 0); } =20 + /* + * ufshcd_init_clocks() has already set the clocks to the highest + * frequency, and nothing has changed them since. Save that frequency, + * so that devfreq and the clock scaling code know where we start. + */ + hba->clk_scaling.target_freq =3D clki->max_freq; + hba->vps->devfreq_profile.initial_freq =3D clki->max_freq; + ufshcd_vops_config_scaling_param(hba, &hba->vps->devfreq_profile, &hba->vps->ondemand_data); devfreq =3D devfreq_add_device(hba->dev, --=20 2.34.1 From nobody Fri Sep 25 23:09:46 2026 Received: from mo4-p02-ob.smtp.rzone.de (mo4-p02-ob.smtp.rzone.de [81.169.146.168]) (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 C776440B38C; Mon, 7 Sep 2026 19:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=81.169.146.168 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788808949; cv=pass; b=a0ZWYYvVzKpqbeGziY0niBovjs4WD3JCvC5vx6tAC3KxbQ3RiT2zefiyqQnZXWrEYuAbKQGFUFJvd2da+fKfjSAi0CWcSro3HYrTX5pPqa7MLHvcAhzDa1ZPRkY/SboUt0GZQlbfkDOH0WHXqnbH/F9FqMkYG5lBDN8L8/YYZKc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788808949; c=relaxed/simple; bh=WVcZN2qQ0/zx88UtIawoSa+m72wtgSHdvJZC+985PIQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=LmKaeN+utQN8OsSEofzzXP+u967QWK5YrVlgiXyUENCPzJAVzZo6EuAXNeLD9gq1Q3FxK72FtrimARngY2zK8PUvKgJTiMe1CSOH6ybTB6CX6tKkJ38E60pkWVTh7kUYGsstVPUtkb0oxaOx9UhajGVoXTTG3Xrvgc29HfWL+dU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de; spf=none smtp.mailfrom=iokpp.de; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=WnpwjYRy; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b=HjCvzsss; arc=pass smtp.client-ip=81.169.146.168 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iokpp.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=iokpp.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="WnpwjYRy"; dkim=permerror (0-bit key) header.d=iokpp.de header.i=@iokpp.de header.b="HjCvzsss" ARC-Seal: i=1; a=rsa-sha256; t=1788808912; cv=none; d=strato.com; s=strato-dkim-0002; b=Mqtx+zC9VLV9peiyhUUB+1sRyiiUkb9oze9ZgNvbX2hf4OZN/wiyQv03SkCjEv5N5i itG/Ftef2/5AFeinlvUtxi4rhXkfYnt5jqaTEijGIuRLeb2Xo+B6ZeHp/G6yq8RRSQvx mhhY4h0+psN0kGbIWywWi3oIrrknxvzrESbzO5m0Ln3DCPZHblfxvBNUFQ3oUGX7jykv PWjIw43ybn9cU7/hqIwPQInWqMiabmhirLFLlLKpfmznxEE5VtAEUf/7Zjsoogf4a9BA 6egfgC1hNmrgH9dAI6QiDjcs42QwH5jZ5nhazd19Tv/TRj96yVNt3q1ROmLEVQGGzUmL CbSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808912; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DUSGuKHy21V6+GxO0cBGC7fg9zg1br9ErHo5MOH0l5k=; b=iFi8WeKD9AgllmoyVkRQBQgQpyzxz5CR1pwdZOIXyeUGrZ+YZwdrLiQqNG6kUid6yg qmCVb6xyva8fvthotLfBZKc+Foey8XtbrpTODGwwCpkkEdFmcl/k/V8XBtcFwzzP5jEb MkRpkjxmp9gBh21e9z4ypgzqJ9FoP3zCajAWI5JKhtOUYgnLc56JY9s2fJk1JI6wugPT pB7NHKv6P5c9hK+YK/8EU1mjdZs2SB4HhPaZumfvdPWa+WPBl3/Dn8IFhAKci5OLIZ4M dSBpbiC3fHIJUoxadHlND6Oy9By4d2U8omhiz5Zjrmre+XtPPAfDJ7e04PlP7cq0dGIM ptQQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1788808912; s=strato-dkim-0002; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DUSGuKHy21V6+GxO0cBGC7fg9zg1br9ErHo5MOH0l5k=; b=WnpwjYRysPBpVK2144EiBrZzXLjF1ZF4L+aMdWY0m8M4mIWwD4r6pHlNcTNgSCuwqd +jqKQk2yvMr/kGil+N5IF5CuD4MidimD9u41lk7UH7CB1j2+EahxTq2njFIFjfz/0PvQ ORNsdUVgKWFl1w+uHJ5By0jOSzwLhu5X7L92LgFgvWZNCKyI2xlXoyw5y5jOekdZKDmD LlQkdYEA0fDek6z1IoBHj6vy/AjP6zl+BfHsXg0DzRNSjz2wtEkIP9iOYOfXHbkZ4QuQ 64jJMrJ8uRqNXLx8C28HIrkmBlA8xFQjPn1d91QF5RdOr6Pgb7icdGJexzX72VxGIDzd 98NQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1788808912; s=strato-dkim-0003; d=iokpp.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=DUSGuKHy21V6+GxO0cBGC7fg9zg1br9ErHo5MOH0l5k=; b=HjCvzsssk1zxPL+z/cvOee9WfNLGzT2RcBiahUiLemAakIfOGvPIvdwUtHjP0DdptQ uvkjB+j0p/x/t+GVLwCQ== X-RZG-AUTH: ":LmkFe0i9dN8c2t4QQyGBB/NDXvjDB6pBSfNuhhDSDt3O0JuBIIyqXfWze4EsqKg=" Received: from Munilab01-lab.. by smtp.strato.de (RZmta 55.6.2 AUTH) with ESMTPSA id ze37e1287JLpCsN (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 7 Sep 2026 21:21:51 +0200 (CEST) From: Bean Huo To: linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, MyungJoo Ham , Kyungmin Park , Chanwoo Choi , "Martin K . Petersen" , "James E . J . Bottomley" , Avri Altman , Bart Van Assche , Alim Akhtar , Stanley Jhu , Bean Huo Subject: [PATCH v2 4/4] scsi: ufs: core: Report the current clock frequency to devfreq Date: Mon, 7 Sep 2026 21:21:40 +0200 Message-Id: <20260907192140.2701755-5-beanhuo@iokpp.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260907192140.2701755-1-beanhuo@iokpp.de> References: <20260907192140.2701755-1-beanhuo@iokpp.de> 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 Content-Type: text/plain; charset="utf-8" From: Bean Huo When a driver does not provide a ->get_cur_freq() callback, the cur_freq sysfs attribute shows devfreq->previous_freq, which only tracks the scaling that the governor itself did. The UFS controller is also scaled outside the governor. The clearest example is writing 0 to clkscale_enable: ufshcd_clkscale_enable_store() sets the clocks to max_freq through ufshcd_devfreq_scale() and suspends the governor, so devfreq_set_target() is never called. After that, cur_freq keeps showing the last frequency the governor chose instead of the one the controller runs at, and it does so as long as clock scaling stays disabled. Add ufshcd_devfreq_get_cur_freq(). It reports clk_scaling.target_freq when OPPs are used and the first clock's curr_freq otherwise, the same values that ufshcd_devfreq_get_dev_status() reports. Signed-off-by: Bean Huo Reviewed-by: Avri Altman Reviewed-by: Stanley Jhu --- drivers/ufs/core/ufshcd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 351c76094b9f..bac95e891de5 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1711,6 +1711,26 @@ static int ufshcd_devfreq_get_dev_status(struct devi= ce *dev, return 0; } =20 +static int ufshcd_devfreq_get_cur_freq(struct device *dev, unsigned long *= freq) +{ + struct ufs_hba *hba =3D dev_get_drvdata(dev); + + if (!ufshcd_is_clkscaling_supported(hba)) + return -EINVAL; + + if (hba->use_pm_opp) { + *freq =3D hba->clk_scaling.target_freq; + } else { + struct ufs_clk_info *clki; + + clki =3D list_first_entry(&hba->clk_list_head, + struct ufs_clk_info, list); + *freq =3D clki->curr_freq; + } + + return 0; +} + static int ufshcd_devfreq_init(struct ufs_hba *hba) { struct list_head *clk_list =3D &hba->clk_list_head; @@ -9616,6 +9636,7 @@ static struct ufs_hba_variant_params ufs_hba_vps =3D { .devfreq_profile.polling_ms =3D 100, .devfreq_profile.target =3D ufshcd_devfreq_target, .devfreq_profile.get_dev_status =3D ufshcd_devfreq_get_dev_status, + .devfreq_profile.get_cur_freq =3D ufshcd_devfreq_get_cur_freq, .ondemand_data.upthreshold =3D 70, .ondemand_data.downdifferential =3D 5, }; --=20 2.34.1