Re: [PATCH v2 1/3] nvme-tcp: use an aligned buffer for the TLS record type

From: David Laight

Date: Fri Nov 13 2026 - 08:44:17 EST


On Fri, 13 Nov 2026 06:34:06 -0500
Martin Belanger <martin.nvme.dev@xxxxxxxxx> wrote:

> On 11/12/26 17:37, David Laight wrote:
> > Is that right?
> > You are changing something that was CMSG_LEN(1) to one of CMSG_SPACE(1).
> >
> > I've a feeling it would be right if it was a struct, not a union.
>
> I think the union is right. buf[] covers the whole control message:
> the header, the data and the padding. CMSG_SPACE(1) already includes
> sizeof(struct cmsghdr). The cmsghdr member only gives the buffer its
> alignment. With a struct, the header would be counted twice.
>
> On x86_64, CMSG_LEN(1) is 17 and CMSG_SPACE(1) is 24. The union is 24
> bytes with 8-byte alignment. put_cmsg() writes CMSG_LEN(1) bytes and
> sets cmsg_len to 17, as before. It then advances msg_control by
> min(CMSG_SPACE(1), msg_controllen), so CMSG_SPACE() is the size it
> expects.

Ok, you are changing the size - which is what I noticed.
In this case it makes the on-stack buffer 4 bytes bigger - which
probably doesn't matter.

I'm sort of surprised it is 8 byte aligned.
Historically it would have been 4 byte aligned, and the kernel still
has to handle requests from 32 bit apps where I'm pretty sure the buffer
will only be 4 byte aligned.
But I've not checked and it isn't really relevant here.

David