From: Damien Le Moal <dlemoal@kernel.org>
To: Niklas Cassel <cassel@kernel.org>, Richard Weinberger <richard@nod.at>
Cc: sashiko-bot <sashiko-bot@kernel.org>,
stable@vger.kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH] ata: libata-sff: fix race between IRQ deferral and ata_sff_flush_pio_task()
Date: Thu, 22 Oct 2026 09:48:37 +0200 [thread overview]
Message-ID: <2099889b-6483-4f4b-bc9c-723159528cd3@kernel.org> (raw)
In-Reply-To: <20261020101107.1449635-2-cassel@kernel.org>
On 2026/10/20 12:11, Niklas Cassel wrote:
> Commit 4a2e5409472e ("ata: libata-sff: don't busy-wait for PIO data-in
> command completion") allowed the interrupt handler to queue
> ap->sff_pio_task from ata_sff_hsm_move() when a PIO data-in command is
> still busy after its final data block.
>
> ata_sff_flush_pio_task(), however, was written under the assumption that
> cancel_delayed_work_sync() is enough to prevent sff_pio_task from being
> queued again before the HSM state is reset to HSM_ST_IDLE and
> sff_pio_task_link is cleared.
>
> The flush runs early during error handling, at a point where the timed
> out command is still active, the port is not frozen yet, and interrupts
> are still being serviced. If the final data-block interrupt of a PIO
> data-in command is serviced in the window between
> cancel_delayed_work_sync() and the reset of hsm_task_state, the
> interrupt handler queues sff_pio_task after the cancel has completed.
> When that work item then executes on ata_sff_wq after the flush cleared
> ap->sff_pio_task_link, ata_sff_pio_task() hits
> BUG_ON(ap->sff_pio_task_link == NULL) while holding the host lock with
> interrupts disabled; alternatively it proceeds on a stale link while
> error handling owns the port.
>
> Fix this by resetting hsm_task_state to HSM_ST_IDLE before cancelling
> the work item. Once the state is IDLE, __ata_sff_port_intr() can no
> longer enter ata_sff_hsm_move(), so the interrupt handler can no longer
> queue the pio task, and cancel_delayed_work_sync() drains whatever was
> queued before the reset.
>
> Also make ata_sff_pio_task() bail out quietly when the HSM state was
> marked idle by the flush, both at entry and after re-acquiring the port
> lock following ata_msleep(), since a work item can already be running
> when the flush resets the state.
>
> Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/linux-ide/sashiko-outbox-177477@kernel.org/
> Fixes: 4a2e5409472e ("ata: libata-sff: don't busy-wait for PIO data-in command completion")
> Cc: stable@vger.kernel.org
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
Looks good.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-10-22 7:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 10:11 [PATCH] ata: libata-sff: fix race between IRQ deferral and ata_sff_flush_pio_task() Niklas Cassel
2026-10-22 7:48 ` Damien Le Moal [this message]
2026-10-22 8:15 ` Niklas Cassel
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=2099889b-6483-4f4b-bc9c-723159528cd3@kernel.org \
--to=dlemoal@kernel.org \
--cc=cassel@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=richard@nod.at \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.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