mbox series

[RFC,net-next,v4,0/7] introduce DEFINE_FLEX() macro

Message ID 20230904123107.116381-1-przemyslaw.kitszel@intel.com (mailing list archive)
Headers show
Series introduce DEFINE_FLEX() macro | expand

Message

Przemek Kitszel Sept. 4, 2023, 12:31 p.m. UTC
Add DEFINE_FLEX() macro, that helps on-stack allocation of structures
with trailing flex array member.
Expose __struct_size() macro which reads size of data allocated
by DEFINE_FLEX().

Accompany new macros introduction with actual usage,
in the ice driver - hence targeting for netdev tree
- please me know if it is best approach here?

Obvious benefits include simpler resulting code, less heap usage,
less error checking. Less obvious is the fact that compiler has
more room to optimize, and as a whole, even with more stuff on the stack,
we end up with overall better (smaller) report from bloat-o-meter:
add/remove: 8/6 grow/shrink: 7/18 up/down: 2211/-2270 (-59)
(individual results in each patch).

v4: _Static_assert() to ensure compiletime const count param
v3: tidy up 1st patch
v2: Kees: reusing __struct_size() instead of doubling it as a new macro

Przemek Kitszel (7):
  overflow: add DEFINE_FLEX() for on-stack allocs
  ice: ice_sched_remove_elems: replace 1 elem array param by u32
  ice: drop two params of ice_aq_move_sched_elems()
  ice: make use of DEFINE_FLEX() in ice_ddp.c
  ice: make use of DEFINE_FLEX() for struct ice_aqc_add_tx_qgrp
  ice: make use of DEFINE_FLEX() for struct ice_aqc_dis_txq_item
  ice: make use of DEFINE_FLEX() in ice_switch.c

 drivers/net/ethernet/intel/ice/ice_common.c | 20 ++-----
 drivers/net/ethernet/intel/ice/ice_ddp.c    | 39 ++++---------
 drivers/net/ethernet/intel/ice/ice_lag.c    | 48 ++++------------
 drivers/net/ethernet/intel/ice/ice_lib.c    | 23 ++------
 drivers/net/ethernet/intel/ice/ice_sched.c  | 56 ++++++------------
 drivers/net/ethernet/intel/ice/ice_sched.h  |  6 +-
 drivers/net/ethernet/intel/ice/ice_switch.c | 63 +++++----------------
 drivers/net/ethernet/intel/ice/ice_xsk.c    | 22 +++----
 include/linux/compiler_types.h              | 32 +++++++----
 include/linux/fortify-string.h              |  4 --
 include/linux/overflow.h                    | 35 ++++++++++++
 11 files changed, 130 insertions(+), 218 deletions(-)


base-commit: bd6c11bc43c496cddfc6cf603b5d45365606dbd5

Comments

Przemek Kitszel Sept. 4, 2023, 12:37 p.m. UTC | #1
On 9/4/23 14:31, Przemek Kitszel wrote:
> Add DEFINE_FLEX() macro, that helps on-stack allocation of structures
> with trailing flex array member.
> Expose __struct_size() macro which reads size of data allocated
> by DEFINE_FLEX().
> 
> Accompany new macros introduction with actual usage,
> in the ice driver - hence targeting for netdev tree
> - please me know if it is best approach here?

I have put this question in each revision up to now,
but perhaps no one noticed it, so making it stand out.

> 
> Obvious benefits include simpler resulting code, less heap usage,
> less error checking. Less obvious is the fact that compiler has
> more room to optimize, and as a whole, even with more stuff on the stack,
> we end up with overall better (smaller) report from bloat-o-meter:
> add/remove: 8/6 grow/shrink: 7/18 up/down: 2211/-2270 (-59)
> (individual results in each patch).
> 
> v4: _Static_assert() to ensure compiletime const count param
> v3: tidy up 1st patch
> v2: Kees: reusing __struct_size() instead of doubling it as a new macro
> 
> Przemek Kitszel (7):
>    overflow: add DEFINE_FLEX() for on-stack allocs
>    ice: ice_sched_remove_elems: replace 1 elem array param by u32
>    ice: drop two params of ice_aq_move_sched_elems()
>    ice: make use of DEFINE_FLEX() in ice_ddp.c
>    ice: make use of DEFINE_FLEX() for struct ice_aqc_add_tx_qgrp
>    ice: make use of DEFINE_FLEX() for struct ice_aqc_dis_txq_item
>    ice: make use of DEFINE_FLEX() in ice_switch.c
> 
>   drivers/net/ethernet/intel/ice/ice_common.c | 20 ++-----
>   drivers/net/ethernet/intel/ice/ice_ddp.c    | 39 ++++---------
>   drivers/net/ethernet/intel/ice/ice_lag.c    | 48 ++++------------
>   drivers/net/ethernet/intel/ice/ice_lib.c    | 23 ++------
>   drivers/net/ethernet/intel/ice/ice_sched.c  | 56 ++++++------------
>   drivers/net/ethernet/intel/ice/ice_sched.h  |  6 +-
>   drivers/net/ethernet/intel/ice/ice_switch.c | 63 +++++----------------
>   drivers/net/ethernet/intel/ice/ice_xsk.c    | 22 +++----
>   include/linux/compiler_types.h              | 32 +++++++----
>   include/linux/fortify-string.h              |  4 --
>   include/linux/overflow.h                    | 35 ++++++++++++
>   11 files changed, 130 insertions(+), 218 deletions(-)
> 
> 
> base-commit: bd6c11bc43c496cddfc6cf603b5d45365606dbd5
Kees Cook Sept. 5, 2023, 3:53 a.m. UTC | #2
On September 4, 2023 5:31:00 AM PDT, Przemek Kitszel <przemyslaw.kitszel@intel.com> wrote:
>Add DEFINE_FLEX() macro, that helps on-stack allocation of structures
>with trailing flex array member.
>Expose __struct_size() macro which reads size of data allocated
>by DEFINE_FLEX().
>
>Accompany new macros introduction with actual usage,
>in the ice driver - hence targeting for netdev tree
>- please me know if it is best approach here?

Yes, I'm fine with this. The changes to the string headers are relatively localized.