Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: David Laight <David.Laight@ACULAB.COM>,
	'Kees Cook' <keescook@chromium.org>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Steven Zou <steven.zou@intel.com>,
	"intel-wired-lan@lists.osuosl.org"
	<intel-wired-lan@lists.osuosl.org>,
	"linux-hardening@vger.kernel.org"
	<linux-hardening@vger.kernel.org>
Subject: Re: [Intel-wired-lan] [PATCH net-next v3 1/7] overflow: add DEFINE_FLEX() for on-stack allocs
Date: Fri, 18 Aug 2023 12:28:15 +0200	[thread overview]
Message-ID: <3f61b3bc-61d4-6568-9bcb-6fd50553157c@intel.com> (raw)
In-Reply-To: <e8e109712a1b42288951c958d2f503a5@AcuMS.aculab.com>

On 8/18/23 09:14, David Laight wrote:
> From: Kees Cook
>> Sent: Thursday, August 17, 2023 6:00 PM
>>
>> On Thu, Aug 17, 2023 at 02:35:23PM +0000, David Laight wrote:
>>> From: Przemek Kitszel
>>>> Sent: Wednesday, August 16, 2023 3:06 PM
> ...
>>>> +#define DEFINE_FLEX(type, name, member, count)					\
>>>> +	union {									\
>>>> +		u8 bytes[struct_size_t(type, member, count)];			\
>>>> +		type obj;							\
>>>> +	} name##_u __aligned(_Alignof(type)) = {};				\
>>>
>>> You shouldn't need the _Alignof() it is the default.
>>
>> In the sense that since "type" is in the union, it's okay?
> 
> The alignment of the union is the larger of the alignments
> of all its members.
> Which is what you want.
> 
>>> I'm not sure you should be forcing the memset() either.
>>
>> This already got discussed: better to fail safe.
> 
> Perhaps call it DEFINE_FLEX_Z() to make this clear and
> give the option for a non-zeroing version later.
> Not everyone wants the expense of zeroing everything.

per Kees, zeroing should be removed by compiler when not needed:
https://lore.kernel.org/intel-wired-lan/202308101128.C4F0FA235@keescook/

Thanks for education on alignment!

> 
> ..
>>> You might want to add:
>>> 	Static_assert(is_constexpr(count), "DEFINE_FLEX: non-constant count " #count);
>>
>> That would be nice, though can Static_assert()s live in the middle of
>> variable definitions?
> 
> I checked and it is fine.
> (I double-checked by adding a statement and getting an error.)

Static_assert with nice wording definitively would make it better, 
thanks again!

> 
> 	David >
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 
> 

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

  reply	other threads:[~2023-08-18 10:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16 14:06 [Intel-wired-lan] [PATCH net-next v3 0/7] introduce DEFINE_FLEX() macro Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 1/7] overflow: add DEFINE_FLEX() for on-stack allocs Przemek Kitszel
2023-08-16 16:35   ` kernel test robot
2023-08-18 10:37     ` Przemek Kitszel
2023-08-18 11:10       ` Miguel Ojeda
2023-08-18 12:07         ` Philip Li
2023-08-19 10:06         ` Greg KH
2023-08-16 20:38   ` Kees Cook
2023-08-17 14:35   ` David Laight
2023-08-17 17:00     ` Kees Cook
2023-08-18  7:14       ` David Laight
2023-08-18 10:28         ` Przemek Kitszel [this message]
2023-08-18 10:49           ` David Laight
2023-08-23 20:52             ` Przemek Kitszel
2023-08-28 14:41               ` Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 2/7] ice: ice_sched_remove_elems: replace 1 elem array param by u32 Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 3/7] ice: drop two params of ice_aq_move_sched_elems() Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 4/7] ice: make use of DEFINE_FLEX() in ice_ddp.c Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 5/7] ice: make use of DEFINE_FLEX() for struct ice_aqc_add_tx_qgrp Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 6/7] ice: make use of DEFINE_FLEX() for struct ice_aqc_dis_txq_item Przemek Kitszel
2023-08-16 14:06 ` [Intel-wired-lan] [PATCH net-next v3 7/7] ice: make use of DEFINE_FLEX() in ice_switch.c Przemek Kitszel

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=3f61b3bc-61d4-6568-9bcb-6fd50553157c@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=steven.zou@intel.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