Archive-only list for patches
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Bernd Schubert <bschubert@ddn.com>,
	Miklos Szeredi <mszeredi@redhat.com>,
	Sasha Levin <sashal@kernel.org>,
	miklos@szeredi.hu, linux-fsdevel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.18-6.6] fuse: Always flush the page cache before FOPEN_DIRECT_IO write
Date: Tue,  9 Dec 2025 22:48:57 -0500	[thread overview]
Message-ID: <20251210034915.2268617-16-sashal@kernel.org> (raw)
In-Reply-To: <20251210034915.2268617-1-sashal@kernel.org>

From: Bernd Schubert <bschubert@ddn.com>

[ Upstream commit 1ce120dcefc056ce8af2486cebbb77a458aad4c3 ]

This was done as condition on direct_io_allow_mmap, but I believe
this is not right, as a file might be open two times - once with
write-back enabled another time with FOPEN_DIRECT_IO.

Signed-off-by: Bernd Schubert <bschubert@ddn.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Analysis Summary

### 1. WHAT THE COMMIT FIXES

This commit addresses a **data coherency bug** in FUSE when a file can
be opened twice with different modes:
- **File descriptor A**: opened normally with page cache (write-back
  caching enabled)
- **File descriptor B**: opened with `FOPEN_DIRECT_IO` flag

**The Bug:**
The original code only flushed dirty pages before direct I/O when
`fc->direct_io_allow_mmap` was enabled. However, dirty pages can exist
regardless of this flag - they can come from a write-back cached file
handle to the same file.

**Data corruption scenario:**
1. Write data via normal cached file handle → creates dirty pages in
   page cache
2. Write to same location via FOPEN_DIRECT_IO handle → goes directly to
   backend storage
3. Later, dirty pages from step 1 flush to disk → **OVERWRITE** the
   direct IO data

This causes **data loss/corruption** where writes via direct I/O are
silently overwritten.

### 2. CODE CHANGE ANALYSIS

The change is minimal:
```c
- if (fopen_direct_io && fc->direct_io_allow_mmap) {
+       if (fopen_direct_io) {
```

Simply removes the `&& fc->direct_io_allow_mmap` condition, making the
`filemap_write_and_wait_range()` call happen for **all**
`FOPEN_DIRECT_IO` operations, not just when `direct_io_allow_mmap` is
enabled.

### 3. STABLE CRITERIA CHECK

| Criterion | Assessment |
|-----------|------------|
| Obviously correct | ✅ The fix is logically sound - always flush dirty
pages before direct IO |
| Fixes real bug | ✅ Data corruption/loss in specific multi-fd scenarios
|
| Important issue | ✅ Data corruption is severe |
| Small and contained | ✅ Single condition removal, one file |
| No new features | ✅ Pure correctness fix |
| Clean application | ✅ Should apply cleanly |

### 4. RISK ASSESSMENT

**Risk: LOW**
- The change is **conservative** - it flushes *more* often, not less
- Worst case: slight performance regression from additional sync
  operations
- Best case: prevents data corruption in mixed cached/direct IO
  scenarios
- The affected code path (`fuse_direct_io`) is well-established

### 5. BACKPORT CONCERNS

**Negative signals:**
- No `Cc: stable@vger.kernel.org` tag
- No `Fixes:` tag pointing to `b5a2a3a0b7766` (which introduced the
  incomplete logic)

**Positive signals:**
- Small, surgical fix
- Fixes data corruption (high severity)
- Maintainer-reviewed (signed off by Miklos Szeredi, FUSE maintainer)
- Safe direction of change

### 6. VERSION APPLICABILITY

The original buggy commit (`b5a2a3a0b7766`) was merged in v6.10, so this
fix applies to:
- v6.10.y through current stable trees

### 7. USER IMPACT

Affects FUSE users who:
- Use FOPEN_DIRECT_IO feature
- Have the same file opened through multiple file descriptors with
  different caching modes
- This is not a theoretical scenario - FUSE servers like libfuse can
  legitimately have files accessed this way

### CONCLUSION

Despite the absence of explicit `Cc: stable` tags, this commit **should
be backported**. It fixes a real data corruption bug with a minimal,
obviously correct change. The fix is safe (more synchronization, not
less), small, and addresses a serious issue. The lack of stable tags
appears to be an oversight rather than an indication the fix isn't
needed in stable. Data corruption bugs in filesystems are exactly the
type of issue stable trees exist to fix.

**YES**

 fs/fuse/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index f1ef77a0be05b..c5c82b3807911 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1607,7 +1607,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
 	if (!ia)
 		return -ENOMEM;
 
-	if (fopen_direct_io && fc->direct_io_allow_mmap) {
+	if (fopen_direct_io) {
 		res = filemap_write_and_wait_range(mapping, pos, pos + count - 1);
 		if (res) {
 			fuse_io_free(ia);
-- 
2.51.0


  parent reply	other threads:[~2025-12-10  3:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10  3:48 [PATCH AUTOSEL 6.18-6.17] functionfs: fix the open/removal races Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] scsi: qla2xxx: Use reinit_completion on mbx_intr_comp Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] via_wdt: fix critical boot hang due to unnamed resource allocation Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] ti-sysc: allow OMAP2 and OMAP4 timers to be reserved on AM33xx Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.15] scsi: qla2xxx: Fix lost interrupts with qlini_mode=disabled Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.12] exfat: zero out post-EOF page cache on file extension Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.12] scsi: smartpqi: Add support for Hurray Data new controller PCI device Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.12] scsi: ufs: host: mediatek: Fix shutdown/suspend race condition Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] powerpc/addnote: Fix overflow on 32-bit builds Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.6] fuse: Invalidate the page cache after FOPEN_DIRECT_IO write Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] ipmi: Fix __scan_channels() failing to rescan channels Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] scsi: qla2xxx: Fix initiator mode with qlini_mode=exclusive Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.17] um: init cpu_tasks[] earlier Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] reset: fix BIT macro reference Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] clk: mvebu: cp110 add CLK_IGNORE_UNUSED to pcie_x10, pcie_x11 & pcie_x4 Sasha Levin
2025-12-10  3:48 ` Sasha Levin [this message]
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] firmware: imx: scu-irq: Init workqueue before request mbox channel Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.17] scsi: lpfc: Fix reusing an ndlp that is marked NLP_DROPPED during FLOGI Sasha Levin
2025-12-10  3:49 ` [PATCH AUTOSEL 6.18-5.10] exfat: fix remount failure in different process environments Sasha Levin
2025-12-10  3:49 ` [PATCH AUTOSEL 6.18-5.10] ipmi: Fix the race between __scan_channels() and deliver_response() 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=20251210034915.2268617-16-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bschubert@ddn.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@redhat.com \
    --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