netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org,
	Maxime Chevallier <maxime.chevallier@bootlin.com>
Subject: Re: [PATCH net-next v1 3/4] net: selftest: add checksum mode support and SW checksum handling
Date: Mon, 21 Apr 2025 15:32:46 +0100	[thread overview]
Message-ID: <20250421143246.GK2789685@horms.kernel.org> (raw)
In-Reply-To: <20250416161439.2922994-4-o.rempel@pengutronix.de>

On Wed, Apr 16, 2025 at 06:14:38PM +0200, Oleksij Rempel wrote:
> Introduce `enum net_test_checksum_mode` to support both CHECKSUM_COMPLETE
> and CHECKSUM_PARTIAL modes in selftest packet generation.
> 
> Add helpers to calculate and apply software checksums for TCP/UDP in
> CHECKSUM_COMPLETE mode, and refactor checksum handling into a dedicated
> function `net_test_set_checksum()`.
> 
> Update PHY loopback tests to use CHECKSUM_COMPLETE by default to avoid
> hardware offload dependencies and improve reliability.
> 
> Also rename loopback test names to clarify checksum type and transport.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Unfortunately this patch does not apply against net-next
(or at any rate, the series did not at the time it was submitted).
Please rebase and repost.

> ---
>  net/core/selftests.c | 218 ++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 206 insertions(+), 12 deletions(-)
> 
> diff --git a/net/core/selftests.c b/net/core/selftests.c

...

> +/**
> + * net_test_setup_sw_csum - Compute and apply software checksum
> + *                          (CHECKSUM_COMPLETE)
> + * @skb: Socket buffer with transport header set
> + * @iph: Pointer to IPv4 header inside skb
> + *
> + * This function computes and fills the transport layer checksum (TCP or UDP),
> + * and sets skb->ip_summed = CHECKSUM_COMPLETE.
> + *
> + * Returns 0 on success, or negative error code on failure.
> + */
> +static int net_test_setup_sw_csum(struct sk_buff *skb,
> +				  struct iphdr *iph)
> +{
> +	int transport_offset = skb_transport_offset(skb);
> +	int transport_len = skb->len - transport_offset;
> +	__be16 final_csum;
> +	__wsum csum;
> +
> +	switch (iph->protocol) {
> +	case IPPROTO_TCP:
> +		if (!pskb_may_pull(skb,
> +				   transport_offset + sizeof(struct tcphdr)))
> +			return -EFAULT;
> +
> +		tcp_hdr(skb)->check = 0;
> +		break;
> +	case IPPROTO_UDP:
> +		if (!pskb_may_pull(skb,
> +				   transport_offset + sizeof(struct udphdr)))
> +			return -EFAULT;
> +
> +		udp_hdr(skb)->check = 0;
> +		break;
> +	default:
> +		pr_err("net_selftest: unsupported proto for sw csum: %u\n",
> +		       iph->protocol);
> +		return -EINVAL;
> +	}
> +
> +	csum = skb_checksum(skb, transport_offset, transport_len, 0);
> +	final_csum = csum_tcpudp_magic(iph->saddr, iph->daddr, transport_len,
> +				       iph->protocol, csum);

Sparse is unhappy about integer type annotations around here.
The 'final_csum =' line above is line number 101.

  .../selftests.c:101:20: warning: incorrect type in assignment (different base types)
  .../selftests.c:101:20:    expected restricted __be16 [usertype] final_csum
  .../selftests.c:101:20:    got restricted __sum16
  .../selftests.c:105:28: warning: incorrect type in assignment (different base types)
  .../selftests.c:105:28:    expected restricted __be16 [usertype] final_csum
  .../selftests.c:105:28:    got restricted __sum16 [usertype]
  .../selftests.c:108:37: warning: incorrect type in assignment (different base types)
  .../selftests.c:108:37:    expected restricted __sum16 [usertype] check
  .../selftests.c:108:37:    got restricted __be16 [usertype] final_csum
  .../selftests.c:110:37: warning: incorrect type in assignment (different base types)
  .../selftests.c:110:37:    expected restricted __sum16 [usertype] check
  .../selftests.c:110:37:    got restricted __be16 [usertype] final_csum

> +
> +	if (iph->protocol == IPPROTO_UDP && final_csum == 0)
> +		final_csum = CSUM_MANGLED_0;
> +
> +	if (iph->protocol == IPPROTO_TCP)
> +		tcp_hdr(skb)->check = final_csum;
> +	else
> +		udp_hdr(skb)->check = final_csum;
> +
> +	skb->ip_summed = CHECKSUM_COMPLETE;
> +
> +	return 0;
> +}

...

-- 
pw-bot: changes-requested

  reply	other threads:[~2025-04-21 14:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-16 16:14 [PATCH net-next v1 0/4] net: selftest: improve test string formatting and checksum handling Oleksij Rempel
2025-04-16 16:14 ` [PATCH net-next v1 1/4] net: selftests: drop test index from net_selftest_get_strings() Oleksij Rempel
2025-04-21 14:33   ` Simon Horman
2025-04-16 16:14 ` [PATCH net-next v1 2/4] net: selftest: prepare for detailed error handling in net_test_get_skb() Oleksij Rempel
2025-04-21 14:33   ` Simon Horman
2025-04-16 16:14 ` [PATCH net-next v1 3/4] net: selftest: add checksum mode support and SW checksum handling Oleksij Rempel
2025-04-21 14:32   ` Simon Horman [this message]
2025-04-16 16:14 ` [PATCH net-next v1 4/4] net: selftest: add PHY loopback tests with HW checksum offload Oleksij Rempel
2025-04-21 14:33   ` Simon Horman

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=20250421143246.GK2789685@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).