From: Zhu Ling <zhuling2709@phytium.com.cn>
To: ulfh@kernel.org
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
fengjun@phytium.com.cn, wangyinfeng@phytium.com.cn,
Zhu Ling <zhuling2709@phytium.com.cn>
Subject: [PATCH] mmc: block: Mark the end of a truncated scatterlist
Date: Wed, 4 Nov 2026 16:07:05 +0800 [thread overview]
Message-ID: <20261104080705.103689-1-zhuling2709@phytium.com.cn> (raw)
mmc_blk_data_prep() maps the remaining block request before trimming the
scatterlist to the size of the current transfer, for example during
single-block error recovery.
When the transfer needs fewer SG entries, the trimming updates sg_len and
the length of the final retained entry but leaves SG_END on the original
last entry. A host calling sg_last(data->sg, data->sg_len) on this list
will hit its end-marker assertion.
This assertion was reported during read recovery with a Phytium host
driver in a vendor Linux 6.6 kernel. The same trimming logic is present in
mainline.
Mark the final retained entry as the end of the scatterlist. Subsequent
blk_rq_map_sg() calls can still extend the list: blk_next_sg() clears
premature end markers before advancing to the next entry.
Fixes: 6a79e391df29 ("mmc_block: ensure all sectors that do not have errors are read")
Signed-off-by: Zhu Ling <zhuling2709@phytium.com.cn>
---
1. I could not find an MMC-specific statement explicitly permitting an
unterminated SG prefix. Feedback from MMC maintainers on this
interpretation would be appreciated.
2. bcm2835_prepare_dma() checks sg_is_last() before dma_map_sg().
No failure has been reproduced with that driver.
3. A userspace metadata reproducer triggers the sg_last() assertion with
the original trimming loop. With this change, 120 flat-SG cases and
36 chained-SG cases pass, including truncation boundaries and rebuilding
a longer list.
drivers/mmc/core/block.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -1506,6 +1506,7 @@
data_size -= sg->length;
if (data_size <= 0) {
sg->length += data_size;
+ sg_mark_end(sg);
i++;
break;
}
reply other threads:[~2026-11-04 8:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261104080705.103689-1-zhuling2709@phytium.com.cn \
--to=zhuling2709@phytium.com.cn \
--cc=fengjun@phytium.com.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ulfh@kernel.org \
--cc=wangyinfeng@phytium.com.cn \
/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®