Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
To: Jonas Karlman <jonas@kwiboo.se>,
	Detlev Casanova <detlev.casanova@collabora.com>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Hans Verkuil <hverkuil@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Heiko Stuebner <heiko@sntech.de>,
	linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v5 0/3] media: rkvdec: fix the clk leaks on unbind
Date: Fri,  4 Dec 2026 09:31:19 +0100	[thread overview]
Message-ID: <20261204083123.30740-1-pavone.lawyer@gmail.com> (raw)

Hi,

This is v5, the one Nicolas was waiting for after my self-review of
v4. v4 was a single patch; it is now three.

Patch 1 splits the V4L2 teardown in remove(): the media and video
devices are unregistered first and the V4L2 device is released last.
It is the split I proposed in my reply to v4, moved to the front so
that no step of the series leaves /dev/videoN registered after the
empty IOMMU domain is freed. Patch 2 is Jonas Karlman's fix for the
clock reference leak on unbind, with his authorship, rebased on
patch 1. Patch 3 makes remove() suspend the device also when
something still holds a runtime PM usage count.

Patches 1 and 3 should fix both leaks without patch 2; I did not
measure that combination. I kept patch 2 because it is Jonas's and it
is the smaller fix. Patches 2 and 3 carry the Fixes tag and need
patch 1: without it they call the suspend callback after the driver
data is cleared.

Base: media-committers next at 04b69b3a8acc. Igor Velkov's "Do not
keep the clocks enabled from probe" is not in it yet. I tested with
it applied on top, rebuilt locally from the list posting. With it the
idle enable count is 0, so the v4 numbers (1 -> 2 and 1 -> 1) no
longer apply.

Test: ROCK 5B+ (RK3588), one decoder instance, fdc38000.video-codec,
five clocks. After one unbind while idle and six unbinds with
power/control set to "on", starting from 0, the final clk enable
count is:

  base (next + Velkov)        7
  patches 1-2                 6
  patches 1-3                 0

An unbind while idle runs remove() with the autosuspend timer still
pending. The base leaves the clocks enabled there, and patch 2 fixes
it: the count is 0 after that unbind with patches 1-2. An unbind with
a usage count held, which is what power/control "on" does, cannot
suspend through autosuspend. That case still leaks one count per
unbind with patches 1-2, and patch 3 fixes it.

With the device active the count reads 2, not 1, because the power
domain also enables the clocks through its pm_clk list (3 on hclk and
aclk, which the IOMMU uses too).

What I did not test:

 - No decode was running during any unbind. A job already running
   when remove() starts is still not waited for.
 - All tests ran with Velkov's change applied; I did not test the
   series on plain media next.
 - CONFIG_PM=n: not built; arm64 selects PM through ARCH_ROCKCHIP.
   With PM=n pm_runtime_force_suspend() is a stub that returns 0.
 - I did not exercise the error path of pm_runtime_force_suspend(),
   which turns runtime PM back on.
 - One board only.

The driver builds with W=1 and no warnings after each patch.

Changes since v4:

 - Rebased on media next (04b69b3a8acc).
 - Split in three: the teardown split is new patch 1, Jonas's fix is
   patch 2, patch 3 is new.
 - Dropped the Assisted-by tags. The tools are declared below.
 - New measurements, redone on the new base.

v4: https://lore.kernel.org/all/20260717154505.83935-1-pavone.lawyer@gmail.com/

I used Claude (Anthropic) to draft the commit messages, the code of
patches 1 and 3 and the measurement script. I reviewed every line,
ran the tests on my board and checked the raw counts.

Francesco Saverio Pavone (2):
  media: rkvdec: split the V4L2 teardown and unregister the devices
    first
  media: rkvdec: suspend the device in remove when a usage count is held

Jonas Karlman (1):
  media: rkvdec: fix clk reference leak on unbind

 drivers/media/platform/rockchip/rkvdec/rkvdec.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)


base-commit: 04b69b3a8acc04460cebf03820e2ee1ec77b549b
-- 
2.54.0



             reply	other threads:[~2026-12-04  8:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  8:31 Francesco Saverio Pavone [this message]
2026-12-04  8:31 ` [PATCH v5 1/3] media: rkvdec: split the V4L2 teardown and unregister the devices first Francesco Saverio Pavone
2026-12-04  8:31 ` [PATCH v5 2/3] media: rkvdec: fix clk reference leak on unbind Francesco Saverio Pavone
2026-12-04  8:31 ` [PATCH v5 3/3] media: rkvdec: suspend the device in remove when a usage count is held Francesco Saverio Pavone

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=20261204083123.30740-1-pavone.lawyer@gmail.com \
    --to=pavone.lawyer@gmail.com \
    --cc=detlev.casanova@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=hverkuil@kernel.org \
    --cc=jonas@kwiboo.se \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    /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