From: Chao Yu <chao@kernel.org>
To: zi-hao.huang@mediatek.com, Jens Axboe <axboe@kernel.dk>
Cc: chao@kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Sandeep Dhavale <dhavale@google.com>
Subject: Re: [PATCH v2] block: fix PF_BLOCK_TS/current->plug ordering in blk_finish_plug()
Date: Wed, 18 Nov 2026 11:31:40 +0800 [thread overview]
Message-ID: <8f11cfb9-7178-426d-b328-a024e57cb8c5@kernel.org> (raw)
In-Reply-To: <20261118-blk-plug-fix-v2-1-4acbeec5d512@mediatek.com>
On 11/18/26 10:31, Zi-Hao Huang via B4 Relay wrote:
> From: Zi-Hao Huang <zi-hao.huang@mediatek.com>
>
> blk_plug_invalidate_ts() runs on context switch and assumes that
> PF_BLOCK_TS set implies current->plug != NULL. blk_finish_plug() breaks
> this: it clears PF_BLOCK_TS in __blk_flush_plug() and then sets
> current->plug = NULL, with plain accesses.
>
> clang inlines __blk_flush_plug() and emits the store to current->plug
> before the store that clears the flag (arm64, Android common kernel):
>
> ldr w8, [x20, #0x44] // w8 = current->flags
> str xzr, [x20, #0xaa8] // current->plug = NULL
> and w8, w8, #0xdfffffff // w8 &= ~PF_BLOCK_TS <- preempted here
> str w8, [x20, #0x44] // current->flags = w8
>
> If an interrupt hits there and preempts the task, the task is later
> scheduled back in with PF_BLOCK_TS set and no plug, and
> blk_plug_invalidate_ts() writes to NULL + 0x20 (plug->cur_ktime):
>
> Unable to handle kernel NULL pointer dereference at 0000000000000020
> pc : __schedule+0x108c
> preempt_schedule_irq+0x48/0xa8
> el1_interrupt+0x48/0x8c
> blk_finish_plug+0x6c/0x18c
> ext4_do_writepages+0xd3c/0xef8
>
> The window is only a few instructions wide, so this is rare. It was hit
> at cycle 127 of a warm reboot stress test.
>
> Add a compiler barrier so the flag is cleared before the plug is
> dropped. A compiler barrier is enough because the race is with
> preemption of the same task on the same CPU. With the barrier, the same
> build stores current->flags before current->plug.
>
> Fixes: fad156c2af22 ("block: invalidate cached plug timestamp after task switch")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zi-Hao Huang <zi-hao.huang@mediatek.com>
> Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Oh, I didn't notice your v1 before sending mine, it looks good to me.
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
prev parent reply other threads:[~2026-11-18 3:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 2:31 Zi-Hao Huang via B4 Relay
2026-11-18 3:31 ` Chao Yu [this message]
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=8f11cfb9-7178-426d-b328-a024e57cb8c5@kernel.org \
--to=chao@kernel.org \
--cc=axboe@kernel.dk \
--cc=dhavale@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=zi-hao.huang@mediatek.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®