public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Charlie Jenkins <charlie@rivosinc.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
	David Laight <David.Laight@aculab.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] lib: checksum: Use aligned accesses for ip_fast_csum and csum_ipv6_magic tests
Date: Mon, 12 Feb 2024 06:26:14 +0000	[thread overview]
Message-ID: <20240212062614.GI608142@ZenIV> (raw)
In-Reply-To: <20240207-fix_sparse_errors_checksum_tests-v6-2-4caa9629705b@rivosinc.com>

On Wed, Feb 07, 2024 at 04:22:51PM -0800, Charlie Jenkins wrote:
> +	struct csum_ipv6_magic_data {
> +		const struct in6_addr saddr;
> +		const struct in6_addr daddr;
> +		unsigned int len;
> +		__wsum csum;
> +		unsigned char proto;
> +	} data, *data_ptr;

Huh?

> +	int num_tests = MAX_LEN / WORD_ALIGNMENT - sizeof(struct csum_ipv6_magic_data);
> +
> +	for (int i = 0; i < num_tests; i++) {
> +		data_ptr = (struct csum_ipv6_magic_data *)(random_buf + (i * WORD_ALIGNMENT));
> +
> +		cpu_to_be32_array((__be32 *)&data.saddr, (const u32 *)&data_ptr->saddr,
> +				  sizeof_field(struct csum_ipv6_magic_data, saddr) / 4);
> +		cpu_to_be32_array((__be32 *)&data.daddr, (const u32 *)&data_ptr->daddr,
> +				  sizeof_field(struct csum_ipv6_magic_data, daddr) / 4);
> +		data.len = data_ptr->len;
> +		data.csum = (__force __wsum)htonl((__force u32)data_ptr->csum);

What are those cpu_to_be32() about?  Checksum calculations *DO* *NOT* involve
any endianness conversions.  At any point.

Replace those assignments with memcpy() and be done with that - that will take
care of unaligned accesses.

Result will have host-independent memory representation.  The only place where you
might want to play with byteswaps (only 16-bit ones) is if you initialized the
array of expected results with u16 constants.  That will have opposite memory
representations on l-e and b-e, so you'll need to byteswap to compare with
what you get from function.  Alternatively, make it an array of bytes and
do
	sum16 = csum_ipv6_magic(saddr, daddr, len, proto, csum);
	if (memcmp(sum16, expected_csum_ipv6_magic + i * 2, 2))
		complain

That's it.

  parent reply	other threads:[~2024-02-12  6:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  0:22 [PATCH v6 0/2] lib: checksum: Fix issues with checksum tests Charlie Jenkins
2024-02-08  0:22 ` [PATCH v6 1/2] lib: checksum: Fix type casting in checksum kunits Charlie Jenkins
2024-02-08  0:22 ` [PATCH v6 2/2] lib: checksum: Use aligned accesses for ip_fast_csum and csum_ipv6_magic tests Charlie Jenkins
2024-02-08  2:45   ` Guenter Roeck
2024-02-12  6:26   ` Al Viro [this message]
2024-02-12 17:18     ` Guenter Roeck
2024-02-12 18:09       ` Charlie Jenkins
2024-02-12 18:26         ` Guenter Roeck
2024-02-12 18:12       ` Al Viro
2024-02-12 18:34         ` Guenter Roeck
2024-02-12 18:41           ` Charlie Jenkins
2024-02-12 18:43         ` Al Viro
2024-02-08  1:45 ` [PATCH v6 0/2] lib: checksum: Fix issues with checksum tests Andrew Morton
2024-02-08  2:09   ` Charlie Jenkins
2024-02-08  2:44     ` Guenter Roeck
2024-02-08  2:47       ` Palmer Dabbelt
2024-02-08  4:15 ` Guenter Roeck
2024-02-11 19:18 ` Guenter Roeck
2024-02-12  5:26   ` Charlie Jenkins
2024-02-12 17:10     ` Guenter Roeck
2024-02-16  9:01       ` Geert Uytterhoeven
2024-02-12 12:46   ` Geert Uytterhoeven

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=20240212062614.GI608142@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=David.Laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=charlie@rivosinc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=palmer@dabbelt.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