Linux 9p file system development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Howells" <dhowells@redhat.com>
Cc: v9fs@lists.linux.dev, "Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH v19 09/17] netfs: Change netfs_writeback_single() to not look inside the iterator
Date: Thu, 19 Nov 2026 09:09:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-222790@kernel.org> (raw)
In-Reply-To: <20261119083851.3306418-10-dhowells@redhat.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] netfs: netfs_write_collection() wakes waiter before
  netfs_wb_end()
--

commit 551b21c53964c5580e9753fdbf5df8744277ee38
Author: David Howells <dhowells@redhat.com>

netfs: Change netfs_writeback_single() to not look inside the iterator

This commit changes netfs_writeback_single() to submit the entire buffer
iterator as a single unsliced subrequest per available stream and wait
synchronously for the write to complete before returning.

> diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
> index 63b0e2599c3c6..0fcfb5ab49bdd 100644
> --- a/fs/netfs/write_issue.c
> +++ b/fs/netfs/write_issue.c
[ ... ]
> @@ -789,36 +667,42 @@ int netfs_writeback_single(struct address_space *mapping,
>  		goto couldnt_start;
>  	}
>  
> +	wreq->buffer.iter = *iter;
> +	wreq->len = len;
> +	wreq->submitted = wreq->len;
> +
>  	__set_bit(NETFS_RREQ_OFFLOAD_COLLECTION, &wreq->flags);
>  	trace_netfs_write(wreq, netfs_write_trace_writeback_single);
>  	netfs_stat(&netfs_n_wh_writepages);
>  
> -	if (__test_and_set_bit(NETFS_RREQ_UPLOAD_TO_SERVER, &wreq->flags))
> -		wreq->netfs_ops->begin_writeback(wreq);
> +	for (int s = 0; s < NR_IO_STREAMS; s++) {
> +		struct netfs_io_subrequest *subreq;
> +		struct netfs_io_stream *stream = &wreq->io_streams[s];
> +
> +		if (!stream->avail)
> +			continue;
>  
> -	for (fq = (struct folio_queue *)iter->folioq; fq; fq = fq->next) {
> -		for (int slot = 0; slot < folioq_count(fq); slot++) {
> -			struct folio *folio = folioq_folio(fq, slot);
> -			size_t part = umin(folioq_folio_size(fq, slot), size);
> +		netfs_prepare_write(wreq, stream, 0);
> +		/* Allocation not allowed to fail in writeback. */
>  
> -			_debug("wbiter %lx %llx", folio->index, atomic64_read(&wreq->issued_to));
> +		subreq = stream->construct;
> +		subreq->len = wreq->len;
> +		stream->submit_len = subreq->len;
> +		stream->submit_extendable_to = iov_iter_count(iter) - len;
>  
> -			ret = netfs_write_folio_single(wreq, folio);
> -			if (ret < 0)
> -				goto stop;
> -			size -= part;
> -			if (size <= 0)
> -				goto stop;
> -		}
> +		netfs_issue_write(wreq, stream);
>  	}
>  
> -stop:
> -	for (int s = 0; s < NR_IO_STREAMS; s++)
> -		netfs_issue_write(wreq, &wreq->io_streams[s]);
>  	netfs_all_subreqs_queued(wreq);
> -
>  	netfs_wake_collector(wreq);
>  
> +	/* TODO: Might want to be async here if WB_SYNC_NONE, but then need to
> +	 * wait before modifying.
> +	 */
> +	ret = netfs_wait_for_write(wreq);
> +	if (ret > 0)
> +		ret = 0;

[Severity: Medium]
Can netfs_writeback_single() return while NETFS_ICTX_WB_LOCK is still held
by the collector worker?

Because NETFS_RREQ_OFFLOAD_COLLECTION is set, netfs_wait_for_write() waits
for the workqueue thread running netfs_write_collection() to clear
NETFS_RREQ_IN_PROGRESS, which happens before netfs_wb_end() releases
NETFS_ICTX_WB_LOCK:

CPU0                                    CPU1 (kworker)
netfs_writeback_single()
  netfs_wb_begin(ictx, ...)
  netfs_wake_collector(wreq)
  netfs_wait_for_write(wreq)
                                        netfs_write_collection()
                                          netfs_wake_rreq_flag(wreq,
                                            NETFS_RREQ_IN_PROGRESS, ...)
  /* returns to caller */
  netfs_wb_begin(ictx, true)
    /* sees NETFS_ICTX_WB_LOCK set */   <-- spurious lock conflict
                                          netfs_wb_end(ictx)

An immediate subsequent WB_SYNC_NONE writeback on the same inode (such as
afs_dir_writepages() after releasing validate_lock) can see
NETFS_ICTX_WB_LOCK still set, re-mark the inode dirty via
netfs_single_mark_inode_dirty(), and skip the writeback pass.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119083851.3306418-1-dhowells@redhat.com?part=9

  reply	other threads:[~2026-11-19  9:09 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  8:38 [PATCH v19 00/17] netfs, iov_iter: Use a chain of bio_vec arrays instead of folio_queue David Howells
2026-11-19  8:38 ` [PATCH v19 01/17] iov_iter: Fix kunit test to remove __init and __refdata marks David Howells
2026-11-19  8:47   ` sashiko-bot
2026-11-19  9:21   ` Wang Yibo
2026-11-19  8:38 ` [PATCH v19 02/17] block: Add a function to kmap one page of a multipage bio_vec David Howells
2026-11-19  8:44   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 03/17] iov_iter: Add a segmented queue of bio_vec[] David Howells
2026-11-19  8:52   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 04/17] netfs: Add some tools for managing bvecq chains David Howells
2026-11-19  9:07   ` sashiko-bot
2026-11-19 11:49   ` David Howells
2026-11-19  8:38 ` [PATCH v19 05/17] iov_iter: Add an API document for the bvecq structure David Howells
2026-11-19  8:53   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 06/17] iov_iter: Add a bvecq kunit test David Howells
2026-11-19  8:50   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 07/17] afs: Fix an inconsistency in the symlink code David Howells
2026-11-19  8:57   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 08/17] netfs: Explicitly pass tail padding to netfs_writeback_single() David Howells
2026-11-19  9:15   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 09/17] netfs: Change netfs_writeback_single() to not look inside the iterator David Howells
2026-11-19  9:09   ` sashiko-bot [this message]
2026-11-19  8:38 ` [PATCH v19 10/17] netfs: Pass the write length to request creation where appropriate David Howells
2026-11-19  8:56   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 11/17] afs: Use a bvecq to hold dir content rather than folioq David Howells
2026-11-19  9:29   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 12/17] cifs: Use a bvecq for buffering instead of a folioq David Howells
2026-11-19  9:10   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 13/17] smbdirect: Support ITER_BVECQ in smbdirect_map_sges_from_iter() David Howells
2026-11-19  9:15   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 14/17] netfs: Switch folioq to bvecq David Howells
2026-11-19  9:38   ` sashiko-bot
2026-11-19 11:49   ` David Howells
2026-11-19  8:38 ` [PATCH v19 15/17] smbdirect: Remove support for ITER_FOLIOQ from smbdirect_map_sges_from_iter() David Howells
2026-11-19  9:13   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 16/17] iov_iter: Remove ITER_FOLIOQ David Howells
2026-11-19  9:20   ` sashiko-bot
2026-11-19  8:38 ` [PATCH v19 17/17] netfs: Remove folio_queue David Howells
2026-11-19  9:18   ` sashiko-bot

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=sashiko-outbox-222790@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jlayton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=v9fs@lists.linux.dev \
    /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