Re: [PATCH 1/2] nfsd: fix type mismatch and explain host-endian xdr buffer usage

Jeff Layton <[email protected]> Mon, 03 Aug 2026 12:23:39 -0400
Newsgroups gmane.linux.kernel,gmane.linux.nfs
Message-ID <[email protected]>
On Mon, 2026-08-03 at 12:04 -0400, Chuck Lever wrote:
>=20
> On Mon, Aug 3, 2026, at 11:43 AM, Jeff Layton wrote:
> > On Mon, 2026-08-03 at 11:32 -0400, Chuck Lever wrote:
> > >=20
> > > On Mon, Aug 3, 2026, at 10:49 AM, Jeff Layton wrote:
> > > > sparse flagged this type mismatch. Also the xdr buffer usage is a b=
it
> > > > non-standard, so explain what we're doing and why.
> > > >=20
> > > > Fixes: 4b64b811f368 ("nfsd: add notification handlers for dir event=
s")
> > > > Reported-by: kernel test robot <[email protected]>
> > > > Closes:=20
> > > > https://lore.kernel.org/oe-kbuild-all/202607310455.AT0GoC5j-lkp@int=
el.com/
> > > > Signed-off-by: Jeff Layton <[email protected]>
> > > > ---
> > > >  fs/nfsd/nfs4xdr.c | 11 ++++++++---
> > > >  1 file changed, 8 insertions(+), 3 deletions(-)
> > > >=20
> > > > diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> > > > index a47eb544b99f..5cbb4a415384 100644
> > > > --- a/fs/nfsd/nfs4xdr.c
> > > > +++ b/fs/nfsd/nfs4xdr.c
> > > > @@ -4383,13 +4383,18 @@ nfsd4_setup_notify_entry4(struct notify_ent=
ry4=20
> > > > *ne, struct xdr_stream *xdr,
> > > >  	struct path path =3D nf->nf_file->f_path;
> > > >  	struct nfsd4_fattr_args args =3D { };
> > > >  	const u32 *reqmask;
> > > > -	uint32_t *attrmask;
> > > > +	u32 *attrmask;
> > > >  	__be32 status;
> > > >  	bool parent;
> > > >  	int ret;
> > > >=20
> > > > -	/* Reserve space for attrmask */
> > > > -	attrmask =3D xdr_reserve_space(xdr, 3 * sizeof(uint32_t));
> > > > +	/*
> > > > +	 * attrmask is the host-order bmval[3] that nfsd4_encode_attr_val=
s()
> > > > +	 * consumes and that ne_attrs.attrmask.element points at. It must
> > > > +	 * outlive this call, so steal a few words from the xdr stream to=
 hold
> > > > +	 * it.
> > > > +	 */
> > > > +	attrmask =3D (u32 *)xdr_reserve_space(xdr, 3 * sizeof(*attrmask))=
;
> > > >  	if (!attrmask)
> > > >  		return false;
> > >=20
> > > I still don't understand what's going on. "Steal a few words to hold =
it"
> > > sounds like you're trying to avoid a kmalloc call. Is this code reser=
ving
> > > space in the XDR stream, or isn't it? If it is, then accessing those =
bytes
> > > has to be done with a big-endian pointer, the same way it is done at =
every
> > > other xdr_reserve_space() call site. Storing host-order bytes that ar=
e not
> > > part of an opaque into an XDR stream is just... wrong.
> > >=20
> > > If you're doing the usual "reserve and backfill the encoded data late=
r"
> > > dance, then spell it the way everyone else does so us poor human read=
ers
> > > can recognize that's what's going on.
> >=20
> > It's using a small piece of the xdr buffer (3 32-bit words) to hold the
> > host-endian bitmap fields that will later be encoded into the stream
> > when the encoding is actually done.
> >=20
> > This piece is not accessed by anything else and there is plenty of room
> > in the buffer, so I don't see the issue here. Can you elaborate on why
> > you feel that this is a problem?
>=20
> Well A-number-1 is that it's a hack and technical debt. It just
> isn't obvious what's going on, it needs a four-line comment to
> explain it, and it opens the door to people copy-pasting it to
> other encoders.
>=20

Ok.

> Number 2 is that the XDR stream buffer is ephemeral. There are
> conditions that callers must stick to to keep that pointer valid
> for the lifetime of the xdr_stream.
>=20

We only need these allocations to stick around until the encoding is
done. They have almost the same lifetime as the xdr buffer itself which
is why allocating from it made sense.

> Number 3: Yes, we have a sordid history of grabbing a piece of
> the xdr_buf's tail iov for temporary storage. That doesn't make
> it wise to do, and assumes behavior about that buffer that is
> not guaranteed by sunrpc's API contracts. That makes life hard
> when future changes need to change that buffer to, say, a page
> rather than kmalloc'd memory. Or when I want to convert this
> code to use xdrgen instead of hand-rolled encoding.
>=20

I had no idea this practice was suddenly forbidden. That has certainly
not been communicated to me in any of the previous review rounds over
the last couple of years.


> So what you've done is fine for operational prototype code, but
> not something we can carry forward as production code. The sparse
> warning is a canary, it's not the actual structural problem.
>=20

Does this mean you intend to drop dir delegation series again?

Allocating from the xdr stream in order to hold host-endian fields is
done in several places in this code. Reworking that will be a
substantial effort.
--=20
Jeff Layton <[email protected]>