From: "Denis Efremov (Oracle)" <efremov@linux.com>
To: bouldrenough <bouldrenough@gmail.com>, linux-block@vger.kernel.org
Subject: Re: floppy: buffer_chain_size() misdirected DMA in 2.6.12..5.12 (gone since 3d86739c6343)
Date: Tue, 24 Nov 2026 01:15:06 +0400 [thread overview]
Message-ID: <ad52104c-2d86-474d-9778-070fbbf35e77@linux.com> (raw)
In-Reply-To: <CAB0dmhH+Bc=A-3PMneQaEzkMsQxnhjpNYtA+OAaUUwZEcgTxPw@mail.gmail.com>
Hello,
Thank you for the report.
On 21/11/2026 07:00, bouldrenough wrote:
> Hello,
>
> This is a report for the record, not a patch for mainline: the code is
> already gone. It may help anyone still maintaining or using older kernels
> on low-memory machines.
>
> The bug was found, diagnosed and fixed by Claude, Anthropic's AI model
> (Claude Opus 5.5, in Claude Code), while building a Linux distribution
> for a real 386SX/20 with 16MB of RAM (Linux 3.7.10). I am the owner of
> the machine and am sending this on its behalf; the analysis below is
> Claude's, and I have reviewed it.
>
> In drivers/block/floppy.c, buffer_chain_size() decides how much of a
> request can be DMAed straight from its pages:
>
> rq_for_each_segment(bv, current_req, iter) {
> if (page_address(bv.bv_page) + bv.bv_offset != base + size)
> break;
> size += bv.bv_len;
> }
>
> rq_for_each_segment() is two nested loops (bios, then segments), so the
> break only leaves the inner one. If the next bio's first page happens to
> sit right after the run so far, it is counted as contiguous, and
> make_raw_rw_request() DMAs across the gap. On a write, the floppy gets
> another page's data, silently; on a read, the DMA would land in memory
> outside the request.
I guess what actually happens is a later page gets earlier sectors' data,
and the skipped page is marked complete without ever being filled.
>
> It only matters where the page cache is below MAX_DMA_ADDRESS, so in
> practice machines with 16MB of RAM or less.
I think this limit applies only to x86, MAX_DMA_ADDRESS is ~0UL on sparc,
powerpc and parisc.
On the 386 it misplaced 4KB
> blocks of dd-to-/dev/fd0 writes about one write in four, and on every
> write under memory pressure. A debug patch logging each write just before
> setup_DMA() showed, for one request:
>
> DEC pos450 chain14 segs ac5400+3072 ac2000+4096 ac6000+4096
> W c12 h1 s1 n14 DIR phys ac5400 -> sectors 456-463 held 464-471
>
> (all pages still under writeback and at the right page-cache index).
>
> The same loop is in 2.6.12 (written out as rq_for_each_bio +
> bio_for_each_segment) through 5.12. Commit 3d86739c6343 ("floppy: always
> use the track buffer", 5.13) removed the direct path as a cleanup and
> with it this bug.
I think it's worth to send the patch to 5.10 LTS branch. Are you interested
in preparing it or will let me do it?
I don't think backporting of 3d86739c6343 ("floppy: always use the track
buffer") is a right choice for 5.10. 5.10 doesn't have memcpy_{to,from}_page
and we should take your patch instead:
https://gist.githubusercontent.com/agmorion/bc94c0f989334e28e2f1b03ec97733a3/raw/a48235cf721a2dc50d2f47115eaf78ba9c181252/floppy-buffer-chain-v5.10.patch
If you'll decide to prepare the patch yourself, you will need to update the
comment /* (rq_for_each_segment is two nested loops ...) */ because it fails
checkpatch.pl check and will need to describe the problem in commit message
with explanation why it's better to use your stable-only fix instead of
backporting 3d86739c6343 (missing prerequisites + backport is larger),
use '[PATCH 5.10.y]' prefix for submission and send it to stable@vger.kernel.org
If we will take it to 5.10 there is a high chance such projects as CIP and
OpenELA also will take it. They still support old kernels.
Let me know if you want to prepare the submission yourself.
>
> The fix for affected versions is to leave both loops:
>
> - break;
> + goto out;
> ...
> +out:
> return size >> 9;
>
> It was tested on the real 386 with 3.7.10; patches for 2.6.32 to 5.12 and
> the full write-up, with a test method, are at:
> https://gist.github.com/agmorion/bc94c0f989334e28e2f1b03ec97733a3
Thanks,
Denis
prev parent reply other threads:[~2026-11-23 21:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 3:00 floppy: buffer_chain_size() misdirected DMA in 2.6.12..5.12 (gone since 3d86739c6343) bouldrenough
2026-11-23 21:15 ` Denis Efremov (Oracle) [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=ad52104c-2d86-474d-9778-070fbbf35e77@linux.com \
--to=efremov@linux.com \
--cc=bouldrenough@gmail.com \
--cc=linux-block@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