mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: "Krishna Chaitanya Chundru" <krishna.chundru@oss.qualcomm.com>,
	"Viresh Kumar" <vireshk@kernel.org>, "Nishanth Menon" <nm@ti.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Bjorn Andersson" <andersson@kernel.org>,
	"Konrad Dybcio" <konradybcio@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v4 2/7] OPP: Move refcount and key update for readability in _opp_table_find_key()
Date: Mon, 25 Aug 2025 15:59:37 +0200	[thread overview]
Message-ID: <4066c0b4-807f-401e-baaa-25f4891f10ac@samsung.com> (raw)
In-Reply-To: <20250820-opp_pcie-v4-2-273b8944eed0@oss.qualcomm.com>

On 20.08.2025 10:28, Krishna Chaitanya Chundru wrote:
> Refactor _opp_table_find_key() to improve readability by moving the
> reference count increment and key update inside the match condition block.
>
> Also make the 'assert' check mandatory instead of treating it as optional.
>
> Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>

This patch landed in today's linux-next (20250825) as commit 
b5323835f050 ("OPP: Reorganize _opp_table_find_key()"). In my tests I 
found that it causes regressions on my test boards. Reverting this 
change on top of linux-next fixes booting of all the affected boards.

Here are kernel logs with lockdep enabled:

1. Exynos4412-based Odroid-U3 board (ARM 32bit):

============================================
WARNING: possible recursive locking detected
6.17.0-rc3-next-20250825 #10901 Not tainted
--------------------------------------------
kworker/u16:0/12 is trying to acquire lock:
cf896040 (&devfreq->lock){+.+.}-{3:3}, at: devfreq_notifier_call+0x30/0x124

but task is already holding lock:
cf896040 (&devfreq->lock){+.+.}-{3:3}, at: devfreq_monitor+0x1c/0x1a4

other info that might help us debug this:
  Possible unsafe locking scenario:

        CPU0
        ----
   lock(&devfreq->lock);
   lock(&devfreq->lock);

  *** DEADLOCK ***

  May be due to missing lock nesting notation

4 locks held by kworker/u16:0/12:
  #0: c289d0b4 ((wq_completion)devfreq_wq){+.+.}-{0:0}, at: 
process_one_work+0x1b0/0x70c
  #1: f0899f18 
((work_completion)(&(&devfreq->work)->work)#2){+.+.}-{0:0}, at: 
process_one_work+0x1dc/0x70c
  #2: cf896040 (&devfreq->lock){+.+.}-{3:3}, at: devfreq_monitor+0x1c/0x1a4
  #3: c2e78c4c (&(&opp_table->head)->rwsem){++++}-{3:3}, at: 
blocking_notifier_call_chain+0x28/0x60

stack backtrace:
CPU: 2 UID: 0 PID: 12 Comm: kworker/u16:0 Not tainted 
6.17.0-rc3-next-20250825 #10901 PREEMPT
Hardware name: Samsung Exynos (Flattened Device Tree)
Workqueue: devfreq_wq devfreq_monitor
Call trace:
  unwind_backtrace from show_stack+0x10/0x14
  show_stack from dump_stack_lvl+0x68/0x88
  dump_stack_lvl from print_deadlock_bug+0x370/0x380
  print_deadlock_bug from __lock_acquire+0x1428/0x29ec
  __lock_acquire from lock_acquire+0x134/0x388
  lock_acquire from __mutex_lock+0xac/0x10c0
  __mutex_lock from mutex_lock_nested+0x1c/0x24
  mutex_lock_nested from devfreq_notifier_call+0x30/0x124
  devfreq_notifier_call from notifier_call_chain+0x84/0x1d4
  notifier_call_chain from blocking_notifier_call_chain+0x44/0x60
  blocking_notifier_call_chain from _opp_kref_release+0x3c/0x5c
  _opp_kref_release from exynos_bus_target+0x24/0x70
  exynos_bus_target from devfreq_set_target+0x8c/0x2e8
  devfreq_set_target from devfreq_update_target+0x9c/0xf8
  devfreq_update_target from devfreq_monitor+0x28/0x1a4
  devfreq_monitor from process_one_work+0x24c/0x70c
  process_one_work from worker_thread+0x1b8/0x3bc
  worker_thread from kthread+0x13c/0x264
  kthread from ret_from_fork+0x14/0x28
Exception stack(0xf0899fb0 to 0xf0899ff8)

...


2. Exynos5422-based Odroid-XU3 board (ARM 32bit):

8<--- cut here ---
Unable to handle kernel NULL pointer dereference at virtual address 
00000000 when read
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in:
CPU: 7 UID: 0 PID: 68 Comm: kworker/u34:1 Not tainted 
6.17.0-rc3-next-20250825 #10901 PREEMPT
Hardware name: Samsung Exynos (Flattened Device Tree)
Workqueue: devfreq_wq devfreq_monitor
PC is at _opp_compare_key+0x30/0xb4
LR is at 0xfffffffc
pc : [<c09831c4>]    lr : [<fffffffc>]    psr: 20000013
sp : f0a89de0  ip : cfb0e94c  fp : c1574880
r10: c14095a4  r9 : f0a89e44  r8 : c2a9c010
r7 : cfb0ea80  r6 : 00000001  r5 : cfb0e900  r4 : 00000001
r3 : 00000000  r2 : cfb0e900  r1 : cfb0ea80  r0 : cfaf5800
Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: 4000406a  DAC: 00000051
Register r0 information: slab kmalloc-1k start cfaf5800 pointer offset 0 
size 1024
Register r1 information: slab kmalloc-128 start cfb0ea80 pointer offset 
0 size 128
Register r2 information: slab kmalloc-128 start cfb0e900 pointer offset 
0 size 128
Register r3 information: NULL pointer
Register r4 information: non-paged memory
Register r5 information: slab kmalloc-128 start cfb0e900 pointer offset 
0 size 128
Register r6 information: non-paged memory
Register r7 information: slab kmalloc-128 start cfb0ea80 pointer offset 
0 size 128
Register r8 information: slab kmalloc-1k start c2a9c000 pointer offset 
16 size 1024
Register r9 information: 2-page vmalloc region starting at 0xf0a88000 
allocated at kernel_clone+0x58/0x3c4
Register r10 information: non-slab/vmalloc memory
Register r11 information: non-slab/vmalloc memory
Register r12 information: slab kmalloc-128 start cfb0e900 pointer offset 
76 size 128
Process kworker/u34:1 (pid: 68, stack limit = 0x050eb3d7)
Stack: (0xf0a89de0 to 0xf0a8a000)
..
Call trace:
  _opp_compare_key from _set_opp+0x78/0x50c
  _set_opp from dev_pm_opp_set_rate+0x15c/0x21c
  dev_pm_opp_set_rate from panfrost_devfreq_target+0x2c/0x3c
  panfrost_devfreq_target from devfreq_set_target+0x8c/0x2e8
  devfreq_set_target from devfreq_update_target+0x9c/0xf8
  devfreq_update_target from devfreq_monitor+0x28/0x1a4
  devfreq_monitor from process_one_work+0x24c/0x70c
  process_one_work from worker_thread+0x1b8/0x3bc
  worker_thread from kthread+0x13c/0x264
  kthread from ret_from_fork+0x14/0x28
Exception stack(0xf0a89fb0 to 0xf0a89ff8)
...
---[ end trace 0000000000000000 ]---


3. Qualcomm Technologies, Inc. Robotics RB5(ARM 64bit):

ufshcd-qcom 1d84000.ufshc: freq-table-hz property not specified
ufshcd-qcom 1d84000.ufshc: ufshcd_populate_vreg: Unable to find 
vdd-hba-supply regulator, assuming enabled
ufshcd-qcom 1d84000.ufshc: Failed to find OPP for MIN frequency
ufshcd-qcom 1d84000.ufshc: ufshcd_pltfrm_init: OPP parse failed -34
ufshcd-qcom 1d84000.ufshc: error -ERANGE: ufshcd_pltfrm_init() failed
ufshcd-qcom 1d84000.ufshc: probe with driver ufshcd-qcom failed with 
error -34



> ---
>   drivers/opp/core.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index a36c3daac39cd0bdd2a1f7e9bad5b92f0c756153..bf49709b8c39271431772924daf0c003b45eec7f 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -544,24 +544,22 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table,
>   	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
>   
>   	/* Assert that the requirement is met */
> -	if (assert && !assert(opp_table, index))
> +	if (!assert(opp_table, index))
>   		return ERR_PTR(-EINVAL);
>   
>   	guard(mutex)(&opp_table->lock);
>   
>   	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
>   		if (temp_opp->available == available) {
> -			if (compare(&opp, temp_opp, read(temp_opp, index), *key))
> +			if (compare(&opp, temp_opp, read(temp_opp, index), *key)) {
> +				/* Increment the reference count of OPP */
> +				*key = read(opp, index);
> +				dev_pm_opp_get(opp);
>   				break;
> +			}
>   		}
>   	}
>   
> -	/* Increment the reference count of OPP */
> -	if (!IS_ERR(opp)) {
> -		*key = read(opp, index);
> -		dev_pm_opp_get(opp);
> -	}
> -
>   	return opp;
>   }
>   
>
Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


  parent reply	other threads:[~2025-08-25 13:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20  8:28 [PATCH v4 0/7] OPP: Add support to find OPP for a set of keys Krishna Chaitanya Chundru
2025-08-20  8:28 ` [PATCH v4 1/7] " Krishna Chaitanya Chundru
2025-08-22  6:50   ` Viresh Kumar
2025-08-20  8:28 ` [PATCH v4 2/7] OPP: Move refcount and key update for readability in _opp_table_find_key() Krishna Chaitanya Chundru
2025-08-22  6:51   ` Viresh Kumar
     [not found]   ` <CGME20250825135939eucas1p206b6e2b5ba115f51618c773a1f37939c@eucas1p2.samsung.com>
2025-08-25 13:59     ` Marek Szyprowski [this message]
2025-08-25 15:56       ` Krishna Chaitanya Chundru
2025-08-26  6:10         ` Viresh Kumar
2025-08-26  6:06       ` Viresh Kumar
2025-08-26  7:26         ` Marek Szyprowski
2025-08-26  8:24           ` Viresh Kumar
2025-08-26 11:25       ` Krzysztof Kozlowski
2025-08-20  8:28 ` [PATCH v4 3/7] arm64: dts: qcom: sm8450: Add opp-level to indicate PCIe data rates Krishna Chaitanya Chundru
2025-08-26  5:57   ` Manivannan Sadhasivam
2025-08-26  6:08   ` Manivannan Sadhasivam
2025-08-20  8:28 ` [PATCH v4 4/7] arm64: dts: qcom: sm8550: " Krishna Chaitanya Chundru
2025-08-20  8:28 ` [PATCH v4 5/7] arm64: dts: qcom: sm8650: " Krishna Chaitanya Chundru
2025-08-20  8:28 ` [PATCH v4 6/7] arm64: dts: qcom: x1e80100: " Krishna Chaitanya Chundru
2025-08-20  8:28 ` [PATCH v4 7/7] PCI: qcom: Use frequency and level based OPP lookup Krishna Chaitanya Chundru
2025-08-20  8:55   ` Neil Armstrong
2025-08-26  5:54   ` Manivannan Sadhasivam
2025-08-25 16:44 ` [PATCH v4 0/7] OPP: Add support to find OPP for a set of keys Wasim Nazir
2025-08-26  5:20   ` Viresh Kumar
2025-08-26  5:36     ` Viresh Kumar
2025-08-26  8:27       ` Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4066c0b4-807f-401e-baaa-25f4891f10ac@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=andersson@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=krishna.chundru@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=nm@ti.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=vireshk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®