public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Josh Law <objecting@objecting.org>
To: Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, Josh Law <objecting@objecting.org>
Subject: [PATCH 4/7] lib/iov_iter: account for iov_offset in iov_iter_single_seg_count() folioq path
Date: Fri, 13 Mar 2026 18:10:35 +0000	[thread overview]
Message-ID: <20260313181038.30018-5-objecting@objecting.org> (raw)
In-Reply-To: <20260313181038.30018-1-objecting@objecting.org>

When the block layer calls iov_iter_single_seg_count() to size a
segment for a folioq-backed iterator — as happens during large
buffered writes through cachefiles or fscache — the function returns
the full folio size without subtracting iov_offset.  After a partial
transfer has advanced iov_offset into the middle of a folio, this
over-reports the remaining data in the current segment.

The iovec and bvec paths both subtract iov_offset (e.g.
iter_iov(i)->iov_len - i->iov_offset), but the folioq path omits it.

Found by reviewing the function for consistency across iterator types
and comparing each branch's treatment of iov_offset.

Subtract iov_offset from the folio size to match the behavior of the
other iterator types.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/iov_iter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 6a7959bfc849..375512beefc5 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -682,7 +682,8 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)
 	}
 	if (unlikely(iov_iter_is_folioq(i)))
 		return !i->count ? 0 :
-			umin(folioq_folio_size(i->folioq, i->folioq_slot), i->count);
+			umin(folioq_folio_size(i->folioq, i->folioq_slot) - i->iov_offset,
+			     i->count);
 	return i->count;
 }
 EXPORT_SYMBOL(iov_iter_single_seg_count);
-- 
2.34.1


  parent reply	other threads:[~2026-03-13 18:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 18:10 [PATCH 0/7] lib/iov_iter: fix bugs found via cross-function consistency review Josh Law
2026-03-13 18:10 ` [PATCH 1/7] lib/iov_iter: fix missing allocation failure check in iov_iter_extract_bvec_pages() Josh Law
2026-03-13 18:16   ` Caleb Sander Mateos
2026-03-13 18:20     ` Josh Law
2026-03-13 18:22       ` Caleb Sander Mateos
2026-03-13 18:10 ` [PATCH 2/7] lib/iov_iter: add NULL check on folioq->prev in iov_iter_folioq_revert() Josh Law
2026-03-13 18:10 ` [PATCH 3/7] lib/iov_iter: fix misplaced parenthesis in iov_iter_restore() kvec check Josh Law
2026-03-23 12:39   ` Christian Brauner
2026-03-23 15:16     ` Josh Law
2026-03-13 18:10 ` Josh Law [this message]
2026-03-13 18:10 ` [PATCH 5/7] lib/iov_iter: account for iov_offset in iov_iter_gap_alignment() Josh Law
2026-03-13 18:10 ` [PATCH 6/7] lib/iov_iter: guard iov_iter_alignment() against zero-count iovec/bvec iterators Josh Law
2026-03-13 18:10 ` [PATCH 7/7] lib/iov_iter: add missing should_fail_usercopy() in copy_to_user_iter_mc() Josh Law

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=20260313181038.30018-5-objecting@objecting.org \
    --to=objecting@objecting.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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