From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
Kees Cook <keescook@chromium.org>,
"David S. Miller" <davem@davemloft.net>,
Paolo Abeni <pabeni@redhat.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
<netdev@vger.kernel.org>, <linux-hardening@vger.kernel.org>,
Simon Horman <horms@kernel.org>, "Jiri Pirko" <jiri@resnulli.us>,
Daniel Borkmann <daniel@iogearbox.net>,
Coco Li <lixiaoyan@google.com>,
Amritha Nambiar <amritha.nambiar@intel.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] netdev: Use flexible array for trailing private bytes
Date: Fri, 1 Mar 2024 15:30:03 +0100 [thread overview]
Message-ID: <77d3f074-8cb6-466b-ab31-a7b0bac659d0@intel.com> (raw)
In-Reply-To: <CANn89iLSLPn5PyXNQcA2HO0e5jGYvHKhTh_9_EMmfbTJKZPfbg@mail.gmail.com>
From: Eric Dumazet <edumazet@google.com>
Date: Fri, 1 Mar 2024 14:25:37 +0100
> On Fri, Mar 1, 2024 at 1:59 PM Alexander Lobakin
> <aleksander.lobakin@intel.com> wrote:
>>
>> From: Eric Dumazet <edumazet@google.com>
>> Date: Fri, 1 Mar 2024 09:03:55 +0100
>>
>>> On Fri, Mar 1, 2024 at 7:59 AM Jakub Kicinski <kuba@kernel.org> wrote:
>>>>
>>>> On Thu, 29 Feb 2024 13:30:22 -0800 Kees Cook wrote:
>>
>> Re WARN_ONCE() in netdev_priv(): netdev_priv() is VERY hot, I'm not sure
>> we want to add checks there. Maybe under CONFIG_DEBUG_NET?
>>
>>>
>>>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>>>> index 118c40258d07..b476809d0bae 100644
>>>>> --- a/include/linux/netdevice.h
>>>>> +++ b/include/linux/netdevice.h
>>>>> @@ -1815,6 +1815,8 @@ enum netdev_stat_type {
>>>>> NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */
>>>>> };
>>>>>
>>>>> +#define NETDEV_ALIGN 32
>>>>
>>>> Unless someone knows what this is for it should go.
>>>> Align priv to cacheline size.
>>>
>>> +2
>>>
>>
>> Maybe
>>
>>> #define NETDEV_ALIGN L1_CACHE_BYTES
>>
>> #define NETDEV_ALIGN max(SMP_CACHE_BYTES, 32)
>
> Why would we care if some arches have a very small SMP_CACHE_BYTES ?
Oh sorry, I thought %SMP_CACHE_BYTES is 1 when !SMP.
We can then just add ____cacheline_aligned to both struct net_device and
its ::priv flex array and that's it.
I like the idea of declaring priv explicitly rather than doing size +
ptr magic. But maybe we could just add this flex array to struct
net_device and avoid introducing a new structure.
> Bet it !
>
> IMO nothing in networking mandates this minimal 32 byte alignment.
>
>>
>> ?
>>
>> (or even max(1 << INTERNODE_CACHE_SHIFT, 32))
>
> I do not think so.
>
> INTERNODE_CACHE_SHIFT is a bit extreme on allyesconfig on x86 :/
> (with CONFIG_X86_VSMP=y)
>
>
>>
>>>
>>> or a general replacement of NETDEV_ALIGN....
>>>
>>>
>>
>> + I'd align both struct net_device AND its private space to
>> %NETDEV_ALIGN and remove this weird PTR_ALIGN. {k,v}malloc ensures
>> natural alignment of allocations for at least a couple years already
>> (IOW if struct net_device is aligned to 64, {k,v}malloc will *always*
>> return a 64-byte aligned address).
>
> I think that with SLAB or SLOB in the past with some DEBUG options
> there was no such guarantee.
>
> But this is probably no longer the case, and heavy DEBUG options these
> days (KASAN, KFENCE...)
> do not expect fast networking anyway.
Thanks,
Olek
next prev parent reply other threads:[~2024-03-01 14:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 21:30 [PATCH] netdev: Use flexible array for trailing private bytes Kees Cook
2024-02-29 22:15 ` Gustavo A. R. Silva
2024-03-01 6:59 ` Jakub Kicinski
2024-03-01 8:03 ` Eric Dumazet
2024-03-01 12:58 ` Alexander Lobakin
2024-03-01 13:25 ` Eric Dumazet
2024-03-01 14:30 ` Alexander Lobakin [this message]
2024-03-01 17:35 ` Jakub Kicinski
2024-03-04 14:32 ` Alexander Lobakin
2024-03-04 15:24 ` Jakub Kicinski
2024-03-01 11:41 ` Greg KH
2024-03-06 13:16 ` Breno Leitao
2024-03-06 15:06 ` Jakub Kicinski
2024-03-06 23:42 ` Kees Cook
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=77d3f074-8cb6-466b-ab31-a7b0bac659d0@intel.com \
--to=aleksander.lobakin@intel.com \
--cc=amritha.nambiar@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gustavoars@kernel.org \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixiaoyan@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;
as well as URLs for NNTP newsgroup(s).