All of lore.kernel.org
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>,
	Jacob Keller <jacob.e.keller@intel.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>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next v8 03/10] lib: packing: add pack_fields() and unpack_fields()
Date: Thu, 5 Dec 2024 00:43:35 +0100	[thread overview]
Message-ID: <4c0cf560-e18f-4980-918e-8a322afd866e@intel.com> (raw)
In-Reply-To: <20241204171215.hb5v74kebekwhca4@skbuf>

On 12/4/24 18:12, Vladimir Oltean wrote:
> On Tue, Dec 03, 2024 at 03:53:49PM -0800, Jacob Keller wrote:

Amazing stuff :), I really like the fact that you both keep striving for
the best result, even way past the point of cut off of most other ;)

> diff --git a/scripts/gen_packed_field_checks.c b/scripts/gen_packed_field_checks.c
> index 09a21afd640b..fabbb741c9a8 100644
> --- a/scripts/gen_packed_field_checks.c
> +++ b/scripts/gen_packed_field_checks.c
> @@ -9,15 +9,9 @@ int main(int argc, char **argv)
>   {
>   	for (int i = 1; i <= MAX_PACKED_FIELD_SIZE; i++) {
>   		printf("#define CHECK_PACKED_FIELDS_%d(fields) ({ \\\n", i);

[i]
@i in range 1..MAX_PACKED_FIELD_SIZE; inclusive

> -		printf("\ttypeof(&(fields)[0]) _f = (fields); \\\n");
> -		printf("\tBUILD_BUG_ON(ARRAY_SIZE(fields) != %d); \\\n", i);
>   
>   		for (int j = 0; j < i; j++)
> -			printf("\tCHECK_PACKED_FIELD(_f[%d]); \\\n", j);
> -
> -		for (int j = 1; j < i; j++)
> -			printf("\tCHECK_PACKED_FIELD_OVERLAP(_f[0].startbit < _f[1].startbit, _f[%d], _f[%d]); \\\n",
> -			       j - 1, j);
> +			printf("\tCHECK_PACKED_FIELD(fields, %d); \\\n", j);

[j]
@j < @i

>   
>   		printf("})\n\n");
>   	}
> 
> And there's one more thing I tried, which mostly worked. That was to
> express CHECK_PACKED_FIELDS_N in terms of CHECK_PACKED_FIELDS_N-1.
> This further reduced the auto-generated code size from 1478 lines to 302
> lines, which I think is appealing.

a lot :)

> 
> diff --git a/scripts/gen_packed_field_checks.c b/scripts/gen_packed_field_checks.c
> index fabbb741c9a8..bac85c04ef20 100644
> --- a/scripts/gen_packed_field_checks.c
> +++ b/scripts/gen_packed_field_checks.c
> @@ -10,9 +10,10 @@ int main(int argc, char **argv)
>   	for (int i = 1; i <= MAX_PACKED_FIELD_SIZE; i++) {
>   		printf("#define CHECK_PACKED_FIELDS_%d(fields) ({ \\\n", i);

same as [i] above, ok

>   
> -		for (int j = 0; j < i; j++)
> -			printf("\tCHECK_PACKED_FIELD(fields, %d); \\\n", j);
> +		if (i != 1)
> +			printf("\tCHECK_PACKED_FIELDS_%d(fields); \\\n", i - 1);
>   
> +		printf("\tCHECK_PACKED_FIELD(fields, %d); \\\n", i);

prior to the change CHECK_PACKED_FIELD() was called on values smaller
than MAX_PACKED_FIELD_SIZE, compare with [j] above, now you call it also
for the MAX one

>   		printf("})\n\n");
>   	}
>   
> 
> The problem is that, for some reason, it introduces this sparse warning:
> 
> ../lib/packing_test.c:436:9: warning: invalid access past the end of 'test_fields' (24 24)
> ../lib/packing_test.c:448:9: warning: invalid access past the end of 'test_fields' (24 24)
> 

off by one error? see above

> Nobody accesses past element 6 (ARRAY_SIZE) of test_fields[]. I ran the
> KUnit with kasan and I saw no warning. The strace warning comes from
> check_access() in flow.c, but I don't have any energy left today to go
> further into this.
> 
> I'm suspecting either a strace bug/false positive, or some sort of
> variable name aliasing issue which I haven't identified yet.

PS. incremental diff in a single patch is harder to apply, but easier to
review, comment both in a single reply == great idea

  parent reply	other threads:[~2024-12-04 23:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-03 23:53 [PATCH net-next v8 00/10] lib: packing: introduce and use (un)pack_fields Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 01/10] lib: packing: create __pack() and __unpack() variants without error checking Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 02/10] lib: packing: demote truncation error in pack() to a warning in __pack() Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 03/10] lib: packing: add pack_fields() and unpack_fields() Jacob Keller
2024-12-04 17:12   ` Vladimir Oltean
2024-12-04 18:47     ` Jacob Keller
2024-12-04 23:24     ` Jacob Keller
2024-12-04 23:52       ` Vladimir Oltean
2024-12-05  0:23         ` Jacob Keller
2024-12-04 23:43     ` Przemek Kitszel [this message]
2024-12-05  9:52       ` Vladimir Oltean
2024-12-05 21:26         ` Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 04/10] lib: packing: document recently added APIs Jacob Keller
2024-12-04 23:26   ` Vladimir Oltean
2024-12-04 23:31   ` Vladimir Oltean
2024-12-03 23:53 ` [PATCH net-next v8 05/10] ice: remove int_q_state from ice_tlan_ctx Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 06/10] ice: use structures to keep track of queue context size Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 07/10] ice: use <linux/packing.h> for Tx and Rx queue context data Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 08/10] ice: reduce size of queue context fields Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 09/10] ice: move prefetch enable to ice_setup_rx_ctx Jacob Keller
2024-12-03 23:53 ` [PATCH net-next v8 10/10] 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=4c0cf560-e18f-4980-918e-8a322afd866e@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=anthony.l.nguyen@intel.com \
    --cc=edumazet@google.com \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.