public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "David Laight" <david.laight.linux@gmail.com>
Cc: "Eric Biggers" <ebiggers@kernel.org>,
	netdev@vger.kernel.org, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Eric Dumazet" <edumazet@google.com>,
	"Neal Cardwell" <ncardwell@google.com>,
	"Kuniyuki Iwashima" <kuniyu@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	"David Ahern" <dsahern@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Dmitry Safonov" <0x7f454c46@gmail.com>
Subject: Re: [PATCH net-next v2 2/5] net/tcp-ao: Use crypto library API instead of crypto_ahash
Date: Tue, 28 Apr 2026 18:38:51 +0200	[thread overview]
Message-ID: <97b79659-5fa1-4085-8c2b-3140fb663acc@app.fastmail.com> (raw)
In-Reply-To: <20260428111008.6ab7981b@pumpkin>



On Tue, 28 Apr 2026, at 12:10, David Laight wrote:
> On Tue, 28 Apr 2026 08:34:47 +0200
> "Ard Biesheuvel" <ardb@kernel.org> wrote:
>
>> On Tue, 28 Apr 2026, at 03:24, David Laight wrote:
>> > On Mon, 27 Apr 2026 10:27:24 -0700
>> > Eric Biggers <ebiggers@kernel.org> wrote:
>> >  
>> >> Currently the kernel's TCP-AO implementation does the MAC and KDF
>> >> computations using the crypto_ahash API.  This API is inefficient and
>> >> difficult to use, and it has required extensive workarounds in the form
>> >> of per-CPU preallocated objects (tcp_sigpool) to work at all.
>> >> 
>> >> Let's use lib/crypto/ instead.  This means switching to straightforward
>> >> stack-allocated structures, virtually addressed buffers, and direct
>> >> function calls.  It also means removing quite a bit of error handling.
>> >> This makes TCP-AO quite a bit faster.
>> >> 
>> >> This also enables many additional cleanups, which later commits will
>> >> handle: removing tcp-sigpool, removing support for crypto_tfm cloning,
>> >> removing more error handling, and replacing more dynamically-allocated
>> >> buffers with stack buffers based on the now-statically-known limits.
>> >> 
>> >> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
>> >> Signed-off-by: Eric Biggers <ebiggers@kernel.org>  
>> > ...  
>> >> @@ -344,33 +444,26 @@ static int tcp_v4_ao_calc_key(struct tcp_ao_key *mkt, u8 *key,
>> >>  	struct kdf_input_block {
>> >>  		u8                      counter;
>> >>  		u8                      label[6];
>> >>  		struct tcp4_ao_context	ctx;
>> >>  		__be16                  outlen;
>> >> -	} __packed * tmp;  
>> >
>> > That looks a bit horrid.
>> > I also had a feeling that the compiler sometimes rejects non-packed structures
>> > inside packed ones.
>> > Perhaps nest the whole thing inside another structure that has an initial
>> > u8 pad and is marked __packed __aligned(4).
>> > Then the assignments to the fields of 'ctx' will be known to be aligned
>> > even when tcp4_ao_context is also __packed.
>> >  
>> 
>> Agree with Eric that this has no bearing on this patch,
>
> true - just the in the same code.
>
>> but I'm not sure
>> I see the problem here. 'ctx' will not be packed, and appear misaligned
>> in struct kdf_input_block, but that would only matter if the address of
>> the ctx field were taken and passed to a function taking a pointer to
>> struct tcp4_ao_context (which would expect it to appear naturally
>> aligned).
>> 
>> Having a feeling about what the compiler sometimes rejects is not
>> actionable feedback - could you be more specific about which problem
>> you think needs to be solved here? Are you concerned about unaligned
>> accesses when populating the struct?
>
> (It was 2am and the side effects of a cold were stopping me sleeping...)
>
> I tend to double-check __packed because it gets misused in places
> where you really want the compiler to error implicit padding rather
> than generate expensive misaligned access code.
>
> But I am sure I remember some build warning that needed __packed added
> to the definition of a structure embedded in a __packed structure.
> I don't think it was only the arm OABI (which pads structures to 2 bytes).
> Historically this has never mattered (even the 'address of packed member'
> error is moderately recent - well sometime in the last 20 years).
>
> In this case (and the ipv6 code) 'struct tcp4_ao_context' can just be
> marked __packed.
> Or, since this is the only place it is used, possibly just inlined
> into 'struct kdf_input_block' - which may not even need to be named.
>

What would that achieve, exactly? You still haven't explained what is
wrong with the code. Or are you really claiming that structs lacking
the packed attribute are not permitted as fields in __packed structs?






  reply	other threads:[~2026-04-28 16:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27 17:27 [PATCH net-next v2 0/5] Reimplement TCP-AO using crypto library Eric Biggers
2026-04-27 17:27 ` [PATCH net-next v2 1/5] net/tcp-ao: Drop support for most non-RFC-specified algorithms Eric Biggers
2026-04-27 17:27 ` [PATCH net-next v2 2/5] net/tcp-ao: Use crypto library API instead of crypto_ahash Eric Biggers
2026-04-28  1:24   ` David Laight
2026-04-28  1:35     ` Eric Biggers
2026-04-28  6:34     ` Ard Biesheuvel
2026-04-28 10:10       ` David Laight
2026-04-28 16:38         ` Ard Biesheuvel [this message]
2026-04-27 17:27 ` [PATCH net-next v2 3/5] net/tcp-ao: Use stack-allocated MAC and traffic_key buffers Eric Biggers
2026-04-27 17:27 ` [PATCH net-next v2 4/5] net/tcp-ao: Return void from functions that can no longer fail Eric Biggers
2026-04-27 17:27 ` [PATCH net-next v2 5/5] net/tcp: Remove tcp_sigpool Eric Biggers
2026-04-27 19:09 ` [PATCH net-next v2 0/5] Reimplement TCP-AO using crypto library Dmitry Safonov
2026-04-27 20:01   ` Eric Biggers
2026-04-27 23:20     ` Eric Biggers
2026-04-28 16:26       ` Simo Sorce
2026-04-28 17:30         ` Eric Biggers
2026-04-27 22:55   ` Jakub Kicinski
2026-04-28  0:00     ` Dmitry Safonov
2026-04-28  5:41       ` Ard Biesheuvel

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=97b79659-5fa1-4085-8c2b-3140fb663acc@app.fastmail.com \
    --to=ardb@kernel.org \
    --cc=0x7f454c46@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=edumazet@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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