From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 8CE3D5A0274 for ; Thu, 29 Feb 2024 08:06:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709190372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DElU4Q5yM9d27j/RQ92JxFOwQBmvNg52BHMBv4ZwJns=; b=ElBSnBMFHBb3veTB8O10B6UUfrkk7Y3kW+074/Rr4CwJxNSFfwjag2LJNtQGl0UEkYEVOB h8ojXlSKPoqaSQXNnLxwRCjWRKBKB61d0YUSA6yNMlu6esAQen490MCF1OeBvxuLtcBFMk hnvV7O8kv+J8XXuLoHr1ulNqUXLQ55g= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-ZgWBDw-cMdGeuksRIltVvQ-1; Thu, 29 Feb 2024 02:06:10 -0500 X-MC-Unique: ZgWBDw-cMdGeuksRIltVvQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2f71c83b7eso54425666b.1 for ; Wed, 28 Feb 2024 23:06:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709190369; x=1709795169; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DElU4Q5yM9d27j/RQ92JxFOwQBmvNg52BHMBv4ZwJns=; b=kuexYdFWlzoSLpI+i27B4GxHwoAXV1T8LzSCXgryE9pUuinYcX0lA/0V1pb5u3rEpt LjwQojGtv+8N0iR+P5EAadR9bVGWhaHIXptW6qGtAtbBotHCQ96rRdFTT0qyL9yHrVMG o832fqKJ2PfGmXJoOajLPoI9mgi5IdxNLccVn3vRFKXMT+Ia8+RuVX+Ar1qMwKOKKuZo aLSFoOPN0YA1yGyo837akSNCnekUsBczNNUgqD6QA64IZbcIYo2bbZYs27RTKbieM5ls vm5HrpJWCEqkAy3LGV5d4LdNICp5eXBSBbOGjuvvqrLWWu93wj3l94+DDmj+UmSF1mSA 7PiQ== X-Gm-Message-State: AOJu0YxNMPFhviae/qf+bt91jRHjkvwPJty4N4th1olRtx8BwfwRKN/V S9KaY4kKPY/h7ZftTz/RC8Fwo55D9+P7jdXU7uqNPKuMyx5fkAl34pKH3r2c8C1g+9OldYlKyUK gzeOgGdFinTAAMaM59M/+LeYNmFZWyXXdK/QPrsWWxnyaYfG0cQ== X-Received: by 2002:a17:906:40d1:b0:a3e:73c8:cd27 with SMTP id a17-20020a17090640d100b00a3e73c8cd27mr787547ejk.73.1709190369573; Wed, 28 Feb 2024 23:06:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmWSnHVWJrnFh0himHQ/x4r0Twr5djVXisn+TmM03I7Sj2t5p5SLIxOMxBxlyzxcb0ep1Xjg== X-Received: by 2002:a17:906:40d1:b0:a3e:73c8:cd27 with SMTP id a17-20020a17090640d100b00a3e73c8cd27mr787526ejk.73.1709190369179; Wed, 28 Feb 2024 23:06:09 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id w8-20020a170906b18800b00a43fe2d3062sm361961ejy.158.2024.02.28.23.06.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2024 23:06:08 -0800 (PST) Date: Thu, 29 Feb 2024 08:05:09 +0100 From: Stefano Brivio To: David Gibson , Laurent Vivier Subject: Re: [PATCH v3 7/9] checksum: introduce functions to compute the header part checksum for TCP/UDP Message-ID: <20240229080509.4f534831@elisabeth> In-Reply-To: References: <20240217150725.661467-1-lvivier@redhat.com> <20240217150725.661467-8-lvivier@redhat.com> <04c99072-02ea-46a9-aac6-23116cb05fa1@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: HBNQVXJ6J3JTMEHKP7JAQYQAFHM7VRUH X-Message-ID-Hash: HBNQVXJ6J3JTMEHKP7JAQYQAFHM7VRUH X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 29 Feb 2024 11:38:53 +1100 David Gibson wrote: > On Wed, Feb 28, 2024 at 02:26:18PM +0100, Laurent Vivier wrote: > > On 2/19/24 04:08, David Gibson wrote: > > > On Sat, Feb 17, 2024 at 04:07:23PM +0100, Laurent Vivier wrote: > > > > > > [...] > > > > > > > +/** > > > > + * proto_ipv6_header_psum() - Calculates the partial checksum of an > > > > + * IPv6 header for UDP or TCP > > > > + * @payload_len: Payload length > > > > + * @proto: Protocol number > > > > + * @saddr: Source address > > > > + * @daddr: Destination address > > > > + * Returns: Partial checksum of the IPv6 header > > > > + */ > > > > +uint32_t proto_ipv6_header_psum(uint16_t payload_len, uint8_t protocol, > > > > + struct in6_addr saddr, struct in6_addr daddr) > > > > > > Hrm, this is passing 2 16-byte IPv6 addresses by value, which might > > > not be what we want. > > > > The idea here is to avoid the pointer alignment problem (&ip6h->saddr and > > &ip6h->daddr can be misaligned). > > Ah, right. That's a neat idea, but I'm not sure it really helps: I > think it will just move the misaligned access from inside the function > to the call site, where we try to marshal the parameter from something > unaligned. I haven't tested this yet, but note that this is generally okay: the problem is *dereferencing* an unaligned pointer. But if you load memory from an aligned pointer, and extract a value from this memory, it's all fine. Speaking MIPS, this is not safe on all CPU models: la $1, 1002 # s1 now contains the value 1002 lw $2, 0($1) # load word from memory at 1002 + 0 into s2 but this is: la $1, 1000 # s1 now contains the value 1000 la $2, 1004 # s3 now contains the value 1004 lw $3, 0($1) # load word from memory at 1000 + 0 into s3 lw $4, 0($3) # load word from memory at 1004 + 0 into s4 sll $5, $3, 16 # 16-bit shift left s3 into s5 srl $6, $4, 16 # 16-bit shift right s4 into s6 or $2, $5, $6 # OR s5 and s6 into s2 On x86, as far as I know, mov will digest the equivalent of the first version without issues. > > Is it a better solution to copy the content of ip6h->saddr and ip6h->daddr > > to some local variables and then provide the pointers of the local variables > > to proto_ipv6_header_psum()? > > Honestly, I'm not sure. I think it's pretty much the same. Let the compiler pass 16-byte variables by value, and it will generally do this for us, but only if needed. -- Stefano