mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	Vikash Garodia <vikash.garodia@oss.qualcomm.com>,
	Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>,
	Abhinav Kumar <abhinav.kumar@linux.dev>,
	Bryan O'Donoghue <bod@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
	Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
	Hungyu Lin <dennylin0707@gmail.com>,
	Stefan Schmidt <stefan.schmidt@linaro.org>,
	Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Joonhoe Kim <26rote@gmail.com>, Birk Skyum <birk.skyum@pm.me>
Subject: Re: [PATCH v2 2/3] media: qcom: iris: Wait for threaded IRQ completion during power-off
Date: Tue, 17 Nov 2026 13:47:20 +0530	[thread overview]
Message-ID: <b4a641c5-2e22-6216-7cad-ffeb270125a7@oss.qualcomm.com> (raw)
In-Reply-To: <c5444a64-ad14-403e-8453-0bb0a16dcfa8@linaro.org>


On 11/13/2026 6:25 AM, Bryan O'Donoghue wrote:
> On 11/11/2026 09:05, Vishnu Reddy wrote:
>> +void iris_acquire_core_lock(struct iris_core *core)
>> +{
>> +    mutex_lock(&core->lock);
>> +
>> +    while (READ_ONCE(core->irq_disabling)) {
>> +        mutex_unlock(&core->lock);
>> +        wait_event(core->irq_disable_waitqueue,
>> !READ_ONCE(core->irq_disabling));
>> +        mutex_lock(&core->lock);
>> +    }
>> +}
>> +
>
>> +static void iris_vpu_disable_irq(struct iris_core *core)
>> +{
>> +    WRITE_ONCE(core->irq_disabling, true);
>> +    mutex_unlock(&core->lock);
>> +    disable_irq(core->irq);
>> +    mutex_lock(&core->lock);
>> +    WRITE_ONCE(core->irq_disabling, false);
>> +    wake_up_all(&core->irq_disable_waitqueue);
>> +}
>> +
>
> Ouch, this is some mad amount of jumping through hoops.
>
> As General Pierre François Joseph Bosquet said of the Charge of the Light
> Brigade in the Crimean war "C’est magnifique, mais ce n’est pas la guerre" -
> It is magnificent, but it is not war.
>
> Why do we have to hold core->lock over iris_vpu_power_off() at all ?
>
> - What is the data-structure or
> - Logical state (the state variable I suspect)
> - Or guarantee of atomicity
>
> We are providing holding that lock ?
>
> These are pretty much rhetorical questions - the above locking scheme can't be
> right. It implies we are doing something wrong and not really fixing that
> wrong thing.
>
> Holding the lock across power_off() seems to be that wrong thing.
>
> disable_irq_nosync() seems to be a correct fix - so if our locking is so
> muddled we have to go to the above - there better be a fully reasoned and
> unavoidable reason why.
>
> Perhaps I'm being overly reductive here but - why not "just" refactor the code
> so that the power-off comes after the piece held in the lock ?
>
> i.e. push that into a worker and then do a synchronous wait on the worker ?
>
> The chatbot told me I was wrong about the worker because "it would deadlock"
> and I can't be bothered burning the tokens to tell it "I didn't mean hold the
> lock in the worker"
>
> It did make the point that it thinks the only thing being protected by the
> lock is
>
> intr_status = readl(core->reg_base + WRAPPER_INTR_STATUS);
> ...
> writel(CLEAR_XTENSA2HOST_INTR, core->reg_base + CPU_CS_A2HSOFTINTCLR);
>
> Which venus does like this:
>
> static irqreturn_t venus_isr(struct venus_core *core)       /* hfi_venus.c */
> {
>     status = readl(wrapper_base + WRAPPER_INTR_STATUS);
>     ...
>     writel(1, cpu_cs_base + CPU_CS_A2HSOFTINTCLR);
>     return IRQ_WAKE_THREAD;
> }
>
> i.e. power off in the IRQ.
>
> Perhaps even simpler - just do the power-off directly outside of the locked
> section... once the IRQ is quiescent ?
>
> Either way I don't think we have a good reason to hold this lock and can
> certainly find a way not to hold it - assuming the only thing we care about is
> kicking that register - do it in the IRQ why not else do a worker with a
> rendezvous or even more straight forward.
>
> void iris_core_deinit(struct iris_core *core)
> {
>     bool power_off = false;
>     int ret;
>
>     ret = pm_runtime_resume_and_get(core->dev);
>
>     mutex_lock(&core->lock);
>     if (core->state != IRIS_CORE_DEINIT) {
>         iris_fw_unload(core);
>         power_off = !ret;
>         iris_hfi_queues_deinit(core);
>         core->state = IRIS_CORE_DEINIT;
>     }
>     mutex_unlock(&core->lock);
>
>     if (power_off)
>         iris_vpu_power_off(core); <- this ?
>
>     if (!ret)
>         pm_runtime_put_sync(core->dev);
> }
>

Thanks for your review.

Moving iris_vpu_power_off() out of the core->lock section can lead to other
issues:
- A queued threaded IRQ handler can still access the registers while the VPU
is being powered down, as disable_irq_nosync() does not wait for it.
- A concurrent iris_core_init() can run while the VPU is still powered, and
the delayed power-off then shuts down the freshly initialized core.

I will rework this in the next revision, using your IRQF_ONESHOT suggestion
as well.

> ---
> bod

  reply	other threads:[~2026-11-17  8:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  9:05 [PATCH v2 0/3] media: qcom: iris: Fix IRQ synchronization " Vishnu Reddy
2026-11-11  9:05 ` [PATCH v2 1/3] Revert "media: qcom: iris: use disable_irq() during power-off" Vishnu Reddy
2026-11-13  0:55   ` Bryan O'Donoghue
2026-11-17  7:57     ` Vishnu Reddy
2026-11-11  9:05 ` [PATCH v2 2/3] media: qcom: iris: Wait for threaded IRQ completion during power-off Vishnu Reddy
2026-11-13  0:55   ` Bryan O'Donoghue
2026-11-17  8:17     ` Vishnu Reddy [this message]
2026-11-11  9:05 ` [PATCH v2 3/3] media: qcom: iris: Fix IRQ disable depth imbalance on watchdog interrupt Vishnu Reddy
2026-11-13  1:33   ` Bryan O'Donoghue

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=b4a641c5-2e22-6216-7cad-ffeb270125a7@oss.qualcomm.com \
    --to=busanna.reddy@oss.qualcomm.com \
    --cc=26rote@gmail.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=birk.skyum@pm.me \
    --cc=bod@kernel.org \
    --cc=bryan.odonoghue@linaro.org \
    --cc=dennylin0707@gmail.com \
    --cc=dikshita.agarwal@oss.qualcomm.com \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=hverkuil@kernel.org \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stefan.schmidt@linaro.org \
    --cc=vikash.garodia@oss.qualcomm.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

all inboxes | Powered by JetHome®