All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charlie Jenkins <charlie@rivosinc.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	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 13:41:28 -0500	[thread overview]
Message-ID: <ZcpmWINCFWd4331h@ghost> (raw)
In-Reply-To: <c5d8a333-aff5-49e1-a7ee-29a023266d2d@roeck-us.net>

On Mon, Feb 12, 2024 at 10:34:10AM -0800, Guenter Roeck wrote:
> On 2/12/24 10:12, Al Viro wrote:
> > On Mon, Feb 12, 2024 at 09:18:14AM -0800, Guenter Roeck wrote:
> > 
> > > Almost. Turns out the csum parameter of csum_ipv6_magic() needs to be in
> > > network byte order, and the length parameter needs to be in host byte order.
> > > So instead of
> > > 	data.len = data_ptr->len;
> > > 	data.csum = (__force __wsum)htonl((__force u32)data_ptr->csum);
> > > it needs to be something like
> > > 	data.len = ntohl(data_ptr->len);
> > > 	data.csum = data_ptr->csum;
> > > 
> > > Also, as you mentioned, either the returned checksum or the expected
> > > checksum needs to be converted for the comparison because one is in
> > > network byte order and the other in host byte order.
> > 
> >          for (int i = 0; i < NUM_IPv6_TESTS; i++) {
> > 		struct args {
> > 			struct in6_addr saddr;
> > 			struct in6_addr daddr;
> > 			__be32 len;
> > 			__wsum csum;
> > 			unsigned char proto;
> > 		} __packed data = (struct args *)(random_buf + i);
> >                  CHECK_EQ(cpu_to_le16(expected_csum_ipv6_magic[i]),
> >                           csum_ipv6_magic(data.saddr, data.daddr, ntohl(data.len),
> > 					 data.proto, data.sum));
> >          }
> > and to hell with field-by-field copying.  __packed here will tell the compiler
> > that alignment of the entire thing is 1 - the total size of fields is 41 bytes,
> > so "no padding" translates into "can't even assume that address is even".
> > 
> 
> Except that the data pointer needs to be aligned because otherwise architectures
> not supporting unaligned accesses will bail out (as observed on mps2-an385).
> But then I am no longer sure if that is correct - maybe csum_ipv6_magic()
> is supposed to be able to handle unaligned accesses. If so, maybe it would be
> more appropriate to skip this test on the affected architectures.
> 
> Guenter
> 

We can align this against IP_ALIGNMENT since it should always be aligned
against the IP header + NET_IP_ALIGN.

- Charlie


  reply	other threads:[~2024-02-12 18:41 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
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 [this message]
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=ZcpmWINCFWd4331h@ghost \
    --to=charlie@rivosinc.com \
    --cc=David.Laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=palmer@dabbelt.com \
    --cc=viro@zeniv.linux.org.uk \
    /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.