public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: Vladimir Oltean <olteanv@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	"Przemek Kitszel" <przemyslaw.kitszel@intel.com>,
	Masahiro Yamada <masahiroy@kernel.org>,
	netdev <netdev@vger.kernel.org>, <linux-kbuild@vger.kernel.org>,
	Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: Re: [PATCH net-next v3 3/9] lib: packing: add pack_fields() and unpack_fields()
Date: Fri, 8 Nov 2024 14:53:11 -0800	[thread overview]
Message-ID: <1b5543ee-c460-4b3d-8a93-a51c9a5d82f1@intel.com> (raw)
In-Reply-To: <20241108183104.wfzvav42zgslqofy@skbuf>



On 11/8/2024 10:31 AM, Vladimir Oltean wrote:
> On Fri, Nov 08, 2024 at 01:24:07PM +0200, Vladimir Oltean wrote:
>> On Thu, Nov 07, 2024 at 11:50:34AM -0800, Jacob Keller wrote:
>>> +#define DECLARE_PACKED_FIELDS_S(name, buffer_sz) \
>>> +	const size_t __ ## name ## _buffer_sz __pf_section_s = buffer_sz; \
>>> +	const struct packed_field_s name[] __pf_section_s
>>
>> This will need sorting out - how to make this declaration macro
>> compatible with the "static" keyword. The obvious way (to group the
>> field array and the buffer size into a structure) doesn't work. It loses
>> the ARRAY_SIZE() of the fields, which is important to the pack_fields()
>> and unpack_fields() wrappers.
>>
>> Maybe a different tool is needed for checking that no packed fields
>> exceed the buffer size? Forcing the buffer size be a symbol just because
>> that's what modpost works with seems unnatural.
>>
>> If we knew the position of the largest field array element in C, and if
>> we enforced that all pack_fields() use a strong type (size included) for
>> the packed buffer, we'd have all information inside the pack_fields()
>> macro, because we only need to compare the largest field against the
>> buffer size. We could just have that part as a BUILD_BUG_ON() wrapped
>> inside the pack_fields() macro itself. And have the compile-time checks
>> spill over between C and modpost...
>>
>> Not to mention, pack_fields() would have one argument less: pbuflen.
> 
> I was thinking something like this (attached). I still don't like
> modpost more than the assertions in C code, because it imposes more
> constraints upon the library user which didn't exist before. Though
> without the extra restrictions added in this patch (just ascending order
> for packed fields + strong type for packed buffer), I don't think the
> modpost variant is going to work, or is going to become extremely complex.

To me, the restrictions seem acceptable. You can always wrap an
arbitrary void buffer into a sized type via a structure.

I do agree that modpost isn't perfect with respect to the C code, but I
dislike the sheer size of the macros generated and the complexity added
to the build system.

My preferred solution is unfortunately not available in C: having the
compiler evaluate a constant function. There is a C++ extension that
does that, but it doesn't seem like GCC has enabled such support in the
C even as an extension.

I'd prefer to keep allowing both ascending and descending order, because
I think those are both valid orderings depending on how you're thinking
about the fields (little vs big endian).

  reply	other threads:[~2024-11-08 22:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 19:50 [PATCH net-next v3 0/9] lib: packing: introduce and use (un)pack_fields Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 1/9] lib: packing: create __pack() and __unpack() variants without error checking Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 2/9] lib: packing: demote truncation error in pack() to a warning in __pack() Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 3/9] lib: packing: add pack_fields() and unpack_fields() Jacob Keller
2024-11-08  7:47   ` kernel test robot
2024-11-08 11:24   ` Vladimir Oltean
2024-11-08 18:31     ` Vladimir Oltean
2024-11-08 22:53       ` Jacob Keller [this message]
2024-11-08 22:49     ` Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 4/9] ice: remove int_q_state from ice_tlan_ctx Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 5/9] ice: use structures to keep track of queue context size Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 6/9] ice: use <linux/packing.h> for Tx and Rx queue context data Jacob Keller
2024-11-08  8:08   ` kernel test robot
2024-11-07 19:50 ` [PATCH net-next v3 7/9] ice: reduce size of queue context fields Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 8/9] ice: move prefetch enable to ice_setup_rx_ctx Jacob Keller
2024-11-07 19:50 ` [PATCH net-next v3 9/9] ice: cleanup Rx queue context programming functions Jacob Keller

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=1b5543ee-c460-4b3d-8a93-a51c9a5d82f1@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=anthony.l.nguyen@intel.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=vladimir.oltean@nxp.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