From: Jeff Layton <jlayton@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>,
Chuck Lever <chuck.lever@oracle.com>, Neil Brown <neilb@suse.de>,
Olga Kornievskaia <kolga@netapp.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: Ingo Molnar <mingo@redhat.com>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nfsd_copy_write_verifier: use read_seqbegin() rather than read_seqbegin_or_lock()
Date: Fri, 27 Oct 2023 16:28:29 -0400 [thread overview]
Message-ID: <702fe81a44d3526cd2ec87bf8cd79741ac0d0782.camel@kernel.org> (raw)
In-Reply-To: <20231026145018.GA19598@redhat.com>
On Thu, 2023-10-26 at 16:50 +0200, Oleg Nesterov wrote:
> The usage of read_seqbegin_or_lock() in nfsd_copy_write_verifier()
> is wrong. "seq" is always even and thus "or_lock" has no effect,
> this code can never take ->writeverf_lock for writing.
>
> I guess this is fine, nfsd_copy_write_verifier() just copies 8 bytes
> and nfsd_reset_write_verifier() is supposed to be very rare operation
> so we do not need the adaptive locking in this case.
>
> Yet the code looks wrong and sub-optimal, it can use read_seqbegin()
> without changing the behaviour.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
> fs/nfsd/nfssvc.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
> index c7af1095f6b5..094b765c5397 100644
> --- a/fs/nfsd/nfssvc.c
> +++ b/fs/nfsd/nfssvc.c
> @@ -359,13 +359,12 @@ static bool nfsd_needs_lockd(struct nfsd_net *nn)
> */
> void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn)
> {
> - int seq = 0;
> + unsigned seq;
>
> do {
> - read_seqbegin_or_lock(&nn->writeverf_lock, &seq);
> + seq = read_seqbegin(&nn->writeverf_lock);
> memcpy(verf, nn->writeverf, sizeof(nn->writeverf));
> - } while (need_seqretry(&nn->writeverf_lock, seq));
> - done_seqretry(&nn->writeverf_lock, seq);
> + } while (read_seqretry(&nn->writeverf_lock, seq));
> }
>
> static void nfsd_reset_write_verifier_locked(struct nfsd_net *nn)
Reviewed-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2023-10-27 20:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 16:30 nfsd_copy_write_verifier: wrong usage of read_seqbegin_or_lock() Oleg Nesterov
2023-10-25 17:00 ` Chuck Lever
2023-10-25 17:39 ` Oleg Nesterov
2023-10-25 17:47 ` Oleg Nesterov
2023-10-25 17:57 ` Chuck Lever
2023-10-25 18:10 ` Oleg Nesterov
2023-10-25 17:54 ` Oleg Nesterov
2023-10-25 18:07 ` Chuck Lever
2023-10-25 18:19 ` Oleg Nesterov
2023-10-26 14:50 ` [PATCH] nfsd_copy_write_verifier: use read_seqbegin() rather than read_seqbegin_or_lock() Oleg Nesterov
[not found] ` <ZTvc0Z6DJEYXI/TL@tissot.1015granger.net>
2023-10-27 19:34 ` Oleg Nesterov
2023-10-27 19:40 ` Chuck Lever III
2023-10-27 20:28 ` Jeff Layton [this message]
2023-10-27 22:52 ` NeilBrown
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=702fe81a44d3526cd2ec87bf8cd79741ac0d0782.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=kolga@netapp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=neilb@suse.de \
--cc=oleg@redhat.com \
--cc=tom@talpey.com \
/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