All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libceph: use iov_iter_extract_pages() in ceph_msg_data_iter_next()
@ 2026-08-17 22:16 Tal Zussman
  2026-08-19  5:44 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Tal Zussman @ 2026-08-17 22:16 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko
  Cc: David Howells, Matthew Wilcox (Oracle), Christoph Hellwig,
	ceph-devel, linux-kernel, Tal Zussman

ceph_msg_data_iter_next() gets a page reference from
iov_iter_get_pages2() only to immediately drop it, asserting that the
page is pinned some other way. The FIXME here predates
iov_iter_extract_pages(), which takes no reference for kernel-backed
iterators.

CEPH_MSG_DATA_ITER data only comes from osd_req_op_extent_osd_iter(),
whose only caller passes the netfs read iterator, which is always
kernel-backed. Use iov_iter_extract_pages() and remove the put and the
assertion. The messenger still relies on the upper layers to keep the
pages alive while it uses them, as it did before. Extracting from a
user-backed iterator would pin pages that nothing unpins, so add a
precautionary warn in ceph_msg_data_add_iter().

This removes the last caller of PageWriteback(), allowing the page
flag accessors to be removed in a future patch.

Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
The assertion is the last caller of PageWriteback() in the tree. The
removal of the PG_writeback page flag accessors will be sent
separately.
---
 net/ceph/messenger.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index fd9c9e64dc8a..e08c3330b9f2 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -996,28 +996,17 @@ static void ceph_msg_data_iter_cursor_init(struct ceph_msg_data_cursor *cursor,
 static struct page *ceph_msg_data_iter_next(struct ceph_msg_data_cursor *cursor,
 					    size_t *page_offset, size_t *length)
 {
-	struct page *page;
+	struct page *page, **ppage = &page;
 	ssize_t len;
 
 	if (cursor->lastlen)
 		iov_iter_revert(&cursor->iov_iter, cursor->lastlen);
 
-	len = iov_iter_get_pages2(&cursor->iov_iter, &page, PAGE_SIZE,
-				  1, page_offset);
+	len = iov_iter_extract_pages(&cursor->iov_iter, &ppage, PAGE_SIZE,
+				     1, 0, page_offset);
 	BUG_ON(len < 0);
 
 	cursor->lastlen = len;
-
-	/*
-	 * FIXME: The assumption is that the pages represented by the iov_iter
-	 *	  are pinned, with the references held by the upper-level
-	 *	  callers, or by virtue of being under writeback. Eventually,
-	 *	  we'll get an iov_iter_get_pages2 variant that doesn't take
-	 *	  page refs. Until then, just put the page ref.
-	 */
-	VM_BUG_ON_PAGE(!PageWriteback(page) && page_count(page) < 2, page);
-	put_page(page);
-
 	*length = min_t(size_t, len, cursor->resid);
 	return page;
 }
@@ -1967,6 +1956,9 @@ void ceph_msg_data_add_iter(struct ceph_msg *msg,
 {
 	struct ceph_msg_data *data;
 
+	/* the messenger never unpins pages, so the iterator must not pin them */
+	WARN_ON_ONCE(iov_iter_extract_will_pin(iter));
+
 	data = ceph_msg_data_add(msg);
 	data->type = CEPH_MSG_DATA_ITER;
 	data->iter = *iter;

---
base-commit: fce4f3da41f1145cfa400002ce3a66e4a89a1902
change-id: 20260808-ceph-msgr-writeback-a67d25e28f1e

Best regards,
-- 
Tal Zussman <tz2294@columbia.edu>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] libceph: use iov_iter_extract_pages() in ceph_msg_data_iter_next()
  2026-08-17 22:16 [PATCH] libceph: use iov_iter_extract_pages() in ceph_msg_data_iter_next() Tal Zussman
@ 2026-08-19  5:44 ` Christoph Hellwig
  2026-08-19 14:07   ` Tal Zussman
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2026-08-19  5:44 UTC (permalink / raw)
  To: Tal Zussman
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, David Howells,
	Matthew Wilcox (Oracle), Christoph Hellwig, ceph-devel,
	linux-kernel

On Mon, Aug 17, 2026 at 06:16:56PM -0400, Tal Zussman wrote:
> ceph_msg_data_iter_next() gets a page reference from
> iov_iter_get_pages2() only to immediately drop it, asserting that the
> page is pinned some other way. The FIXME here predates
> iov_iter_extract_pages(), which takes no reference for kernel-backed
> iterators.
> 
> CEPH_MSG_DATA_ITER data only comes from osd_req_op_extent_osd_iter(),
> whose only caller passes the netfs read iterator, which is always
> kernel-backed. Use iov_iter_extract_pages() and remove the put and the
> assertion. The messenger still relies on the upper layers to keep the
> pages alive while it uses them, as it did before. Extracting from a
> user-backed iterator would pin pages that nothing unpins, so add a
> precautionary warn in ceph_msg_data_add_iter().

Yikes, this goes through like three layers of pointless abstraction
for a single user :(

But trying to unwind those it comes from ceph_netfs_issue_read, which
is the netfs issue_read method, which is used for all kinds of
reads, but it does seem like for direct reads it uses the kinda
interesting netfs_extract_user_iter helper to turn the user iov
into a kernel one, which makes all of this such a freakin' mess.

So yeah, the analysis is right, at the same time using
iov_iter_extract_pages is just as weird as the old version.  Someone
really needs to clean up all the mess in both netfs and ceph :(

> This removes the last caller of PageWriteback(), allowing the page
> flag accessors to be removed in a future patch.
> 
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
> The assertion is the last caller of PageWriteback() in the tree. The
> removal of the PG_writeback page flag accessors will be sent
> separately.

What about just killing that assert and leaving the rest of this
mess in place until it is sorted out properly?  iov_iter_get_pages2
is a pretty good marker for that, and it would be sad to loose that.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libceph: use iov_iter_extract_pages() in ceph_msg_data_iter_next()
  2026-08-19  5:44 ` Christoph Hellwig
@ 2026-08-19 14:07   ` Tal Zussman
  2026-08-19 14:26     ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Tal Zussman @ 2026-08-19 14:07 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, David Howells,
	Matthew Wilcox (Oracle), ceph-devel, linux-kernel

On 8/19/26 1:44 AM, Christoph Hellwig wrote:
> On Mon, Aug 17, 2026 at 06:16:56PM -0400, Tal Zussman wrote:
>> ceph_msg_data_iter_next() gets a page reference from
>> iov_iter_get_pages2() only to immediately drop it, asserting that the
>> page is pinned some other way. The FIXME here predates
>> iov_iter_extract_pages(), which takes no reference for kernel-backed
>> iterators.
>> 
>> CEPH_MSG_DATA_ITER data only comes from osd_req_op_extent_osd_iter(),
>> whose only caller passes the netfs read iterator, which is always
>> kernel-backed. Use iov_iter_extract_pages() and remove the put and the
>> assertion. The messenger still relies on the upper layers to keep the
>> pages alive while it uses them, as it did before. Extracting from a
>> user-backed iterator would pin pages that nothing unpins, so add a
>> precautionary warn in ceph_msg_data_add_iter().
> 
> Yikes, this goes through like three layers of pointless abstraction
> for a single user :(
> 
> But trying to unwind those it comes from ceph_netfs_issue_read, which
> is the netfs issue_read method, which is used for all kinds of
> reads, but it does seem like for direct reads it uses the kinda
> interesting netfs_extract_user_iter helper to turn the user iov
> into a kernel one, which makes all of this such a freakin' mess.
> 
> So yeah, the analysis is right, at the same time using
> iov_iter_extract_pages is just as weird as the old version.  Someone
> really needs to clean up all the mess in both netfs and ceph :(
> 
>> This removes the last caller of PageWriteback(), allowing the page
>> flag accessors to be removed in a future patch.
>> 
>> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
>> ---
>> The assertion is the last caller of PageWriteback() in the tree. The
>> removal of the PG_writeback page flag accessors will be sent
>> separately.
> 
> What about just killing that assert and leaving the rest of this
> mess in place until it is sorted out properly?  iov_iter_get_pages2
> is a pretty good marker for that, and it would be sad to loose that.
> 

I'm perfectly happy to do that. I just want the PageWriteback() gone
and wanted to try to fix it properly rather than just delete the BUG()
or throw in a page_folio(). But seems like "properly" in this case may
be a deeper hole than I want to jump in to right now ;)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libceph: use iov_iter_extract_pages() in ceph_msg_data_iter_next()
  2026-08-19 14:07   ` Tal Zussman
@ 2026-08-19 14:26     ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-08-19 14:26 UTC (permalink / raw)
  To: Tal Zussman
  Cc: Christoph Hellwig, Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko,
	David Howells, Matthew Wilcox (Oracle), ceph-devel, linux-kernel

On Wed, Aug 19, 2026 at 05:07:05PM +0300, Tal Zussman wrote:
> I'm perfectly happy to do that. I just want the PageWriteback() gone
> and wanted to try to fix it properly rather than just delete the BUG()
> or throw in a page_folio(). But seems like "properly" in this case may
> be a deeper hole than I want to jump in to right now ;)

I'd vote for just removing it and unraveling that rest slowly.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-19 14:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 22:16 [PATCH] libceph: use iov_iter_extract_pages() in ceph_msg_data_iter_next() Tal Zussman
2026-08-19  5:44 ` Christoph Hellwig
2026-08-19 14:07   ` Tal Zussman
2026-08-19 14:26     ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.