From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EC1F606A325 for ; Tue, 1 Dec 2026 16:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=vWGioSxB; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=PN/J+ZIO DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=q9V+nqafQ+B8ing4yDjICkT8sunuLD8OCx8w9VjxgAU=; b=vWGioSxB4u50SYauqS6wAEndbP C5cAv+8kaofFUluHxDXtjLVA7xfLxJ5NHPb6LlA/05P02wBjV05HOm84SfpIi7mupn759eEoCGcT6 5sn1POqTiRA0KE+CQnB21E7gahRWgFUUfEJMKDk+pKZvOmyoQexGn8+XRV5Sn5M3608mavybeuPJk cQc2FQx7ZqJFc/6J7Td7LMip1Y1wzABvgJY+b8/FbxrkYVi2jRyuHQorNmIlgIshImhaf1opAZW32 O9RvCjxbePAMruwuznFSUQYZUnJ90Iy92kNgunPfeOZZVRJ1HnI4A6YQH6xjsCBbXD0WN0iyl76Hw z5c73XQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYQJe-00000008eE1-0UO2; Tue, 01 Dec 2026 16:03:02 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYQJb-00000008eD8-3oJT for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 16:02:49 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2607D1516; Tue, 1 Dec 2026 08:02:44 -0800 (PST) Received: from arm.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D20043F7D8; Tue, 1 Dec 2026 08:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796140966; bh=zPk3QhBrBjZaRItuI1xlOAUBzHpX9dVTv2s0k5w4r10=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PN/J+ZIONUzyTGhsAkll53nDXY/1CbIfjiAi27olSvgUubRNnTv2t4YyZxmXs1cY7 1bAbYaQSUFIuxK82YOjfwJWwIhXf5kjf3hQdOnHXrVXCDaBxsWLDQTrB3b/eFggBrF OlIjkc77UkSpFUZRQb/cVAFod1DFnQOyi5guf1TE= Date: Tue, 1 Dec 2026 16:02:40 +0000 From: Catalin Marinas To: jai.menon@datadoghq.com Cc: Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Robin Murphy Subject: Re: [PATCH] arm64: csum: Fix carry loss in ip_fast_csum() Message-ID: References: <20261130-arm64-ip-fast-csum-carry-v1-1-009f6a39adad@datadoghq.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130-arm64-ip-fast-csum-carry-v1-1-009f6a39adad@datadoghq.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_080248_011857_4E18F17B X-CRM114-Status: GOOD ( 19.85 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, Nov 30, 2026 at 03:32:57PM +0000, Jai Menon via B4 Relay wrote: > From: Jai Menon > > ip_fast_csum() accumulates the trailing 32-bit header words without > end-around carry. Overflow of the 64-bit accumulator produces > incorrect IPv4 header checksums on TX and false checksum failures on RX. Thanks for this. The bug is real and we should fix it, but it's probably not urgent for -rc. I think it's really hard to hit in practice based on my analysis with an LLM: it needs the high 32 bits of the first 16-byte sum to be all ones, which for an unfragmented header means e.g. a source address ending in .191.255 (DF) or .255.255 (no DF), together with one specific IP ID. Linux recently started sending DF packets with ID 0, which never triggers it for a unicast source. When it does hit, it's a packet drop, not some permanent communication failure. > All five arm64 checksum KUnit tests passed with GCC 15.2 and Clang 22. > Reference checks covered all valid IPv4 header lengths, all byte > alignments modulo 16, and both byte orders. Could we have (as a separate patch) a KUnit test that exercises this carry loss? Just to show its status before and after this patch. > diff --git a/arch/arm64/include/asm/checksum.h b/arch/arm64/include/asm/checksum.h > index dc52b7336..d32969b16 100644 > --- a/arch/arm64/include/asm/checksum.h > +++ b/arch/arm64/include/asm/checksum.h > @@ -23,18 +23,25 @@ static inline __sum16 csum_fold(__wsum csum) > static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) > { > __uint128_t tmp; > - u64 sum; > + u64 sum, tail; > int n = ihl; /* we want it signed */ > > tmp = *(const __uint128_t *)iph; > - iph += 16; > + tail = *(const u32 *)(iph + 16); > + iph += 20; > n -= 4; > - tmp += ((tmp >> 64) | (tmp << 64)); > - sum = tmp >> 64; > - do { > - sum += *(const u32 *)iph; > + while (--n > 0) { > + tail += *(const u32 *)iph; > iph += 4; > - } while (--n > 0); > + } > + > + /* Feed the pair's carry into the tail addition, then fold its carry. */ > + asm("adds\t%0, %1, %2\n\t" > + "adcs\t%0, %0, %3\n\t" > + "adc\t%0, %0, xzr" > + : "=&r" (sum) > + : "r" ((u64)tmp), "r" ((u64)(tmp >> 64)), "r" (tail) > + : "cc"); > > sum += ((sum >> 32) | (sum << 32)); > return csum_fold((__force __wsum)(sum >> 32)); I'm not keen on inline asm if we can avoid it. I think we can use __builtin_add_overflow() or something like accumulate() in arch/arm64/lib/csum.c. -- Catalin