From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Fengnan Chang <changfengnan@bytedance.com>,
Jens Axboe <axboe@kernel.dk>, Sasha Levin <sashal@kernel.org>,
asml.silence@gmail.com, io-uring@vger.kernel.org
Subject: [PATCH AUTOSEL 6.12 07/21] io_uring: make fallocate be hashed work
Date: Mon, 30 Jun 2025 16:45:22 -0400 [thread overview]
Message-ID: <20250630204536.1358327-7-sashal@kernel.org> (raw)
In-Reply-To: <20250630204536.1358327-1-sashal@kernel.org>
From: Fengnan Chang <changfengnan@bytedance.com>
[ Upstream commit 88a80066af1617fab444776135d840467414beb6 ]
Like ftruncate and write, fallocate operations on the same file cannot
be executed in parallel, so it is better to make fallocate be hashed
work.
Signed-off-by: Fengnan Chang <changfengnan@bytedance.com>
Link: https://lore.kernel.org/r/20250623110218.61490-1-changfengnan@bytedance.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
**YES**
This commit should definitely be backported to stable kernel trees.
Here's my extensive analysis:
## Why this is a critical bug fix:
1. **Data Integrity Issue**: The commit fixes a race condition where
multiple fallocate operations on the same file could execute in
parallel through io_uring. Looking at the implementation in
io_uring/sync.c:107, fallocate calls `vfs_fallocate()` which modifies
file allocation state. Without proper serialization, concurrent
fallocate operations can cause:
- Data corruption
- Inconsistent file metadata
- Filesystem-level race conditions in block allocation
2. **Consistency with Similar Operations**: By examining
io_uring/opdef.c, I found that all other file-modifying operations
already have `hash_reg_file = 1`:
- IORING_OP_WRITEV
- IORING_OP_WRITE_FIXED
- IORING_OP_WRITE
- IORING_OP_SPLICE
- IORING_OP_TEE
- IORING_OP_FTRUNCATE
- IORING_OP_WRITEV_FIXED
3. **Clear Precedent**: When ftruncate support was added in commit
b4bb1900c12e, it was correctly implemented with `hash_reg_file = 1`
from the start. The fact that fallocate was missing this flag appears
to be an oversight that this commit corrects.
## Why it's safe to backport:
1. **Minimal Change**: Single line addition with no architectural
changes
2. **Well-Understood Fix**: The `hash_reg_file` mechanism is well-
established and used by all similar operations
3. **No Breaking Changes**: The only effect is proper serialization of
fallocate operations per-file, which is the correct and expected
behavior
4. **Low Risk**: This change cannot introduce new bugs - it only
prevents existing race conditions
## How it differs from the "NO" examples:
Unlike the provided similar commits which were:
- Adding new features (io_uring fallocate support)
- Performance optimizations (hashing changes, __read_mostly)
- Code cleanup (removing unused fields, refactoring)
This commit fixes a **correctness bug** that can lead to data corruption
in production systems using io_uring with fallocate operations.
The commit follows stable kernel rules perfectly: it's a critical bug
fix that's minimal, contained, and addresses a real user-facing issue
without introducing new functionality or risks.
io_uring/opdef.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index a2be3bbca5ffa..5dc1cba158a06 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -214,6 +214,7 @@ const struct io_issue_def io_issue_defs[] = {
},
[IORING_OP_FALLOCATE] = {
.needs_file = 1,
+ .hash_reg_file = 1,
.prep = io_fallocate_prep,
.issue = io_fallocate,
},
--
2.39.5
next prev parent reply other threads:[~2025-06-30 20:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 20:45 [PATCH AUTOSEL 6.12 01/21] ublk: sanity check add_dev input for underflow Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 02/21] atm: idt77252: Add missing `dma_map_error()` Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 03/21] um: vector: Reduce stack usage in vector_eth_configure() Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 04/21] ASoC: SOF: Intel: hda: Use devm_kstrdup() to avoid memleak Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 05/21] Revert "PCI/ACPI: Fix allocated memory release on error in pci_acpi_scan_root()" Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 06/21] ALSA: hda/realtek: Add mic-mute LED setup for ASUS UM5606 Sasha Levin
2025-06-30 20:45 ` Sasha Levin [this message]
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 08/21] ASoC: amd: yc: add quirk for Acer Nitro ANV15-41 internal mic Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 09/21] ALSA: hda/realtek - Enable mute LED on HP Pavilion Laptop 15-eg100 Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 10/21] ALSA: hda/realtek: Add quirks for some Clevo laptops Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 11/21] net: usb: qmi_wwan: add SIMCom 8230C composition Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 12/21] driver: bluetooth: hci_qca:fix unable to load the BT driver Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 13/21] HID: lenovo: Add support for ThinkPad X1 Tablet Thin Keyboard Gen2 Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 14/21] net: mana: Record doorbell physical address in PF mode Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 15/21] btrfs: fix assertion when building free space tree Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 16/21] vt: add missing notification when switching back to text mode Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 17/21] bpf: Adjust free target to avoid global starvation of LRU map Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 18/21] riscv: vdso: Exclude .rodata from the PT_DYNAMIC segment Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 19/21] HID: Add IGNORE quirk for SMARTLINKTECHNOLOGY Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 20/21] HID: quirks: Add quirk for 2 Chicony Electronics HP 5MP Cameras Sasha Levin
2025-06-30 20:45 ` [PATCH AUTOSEL 6.12 21/21] HID: nintendo: avoid bluetooth suspend/resume stalls Sasha Levin
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=20250630204536.1358327-7-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=changfengnan@bytedance.com \
--cc=io-uring@vger.kernel.org \
--cc=patches@lists.linux.dev \
--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