From patchwork Mon Mar 6 14:22:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 735742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3vcMTF6qzDz9s7N; Tue, 7 Mar 2017 01:23:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b="LamBCu/k"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1cktXa-0005Zf-Nu; Mon, 06 Mar 2017 14:23:10 +0000 Received: from mail-it0-f48.google.com ([209.85.214.48]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1cktXM-0005Ux-Nt for kernel-team@lists.ubuntu.com; Mon, 06 Mar 2017 14:22:56 +0000 Received: by mail-it0-f48.google.com with SMTP id m27so5927672iti.1 for ; Mon, 06 Mar 2017 06:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=Z+fX5nFJTKwyo3ZGbRsxFw0WBdXEskpcXjfZ2F3Uj8o=; b=LamBCu/kdu+48ot5PsGr9Q+SN7obZGKCQUE+8v+4GJM9M1LBu/c9axitEUfqMTs9tG CWy55GJi97pf8IxnM9JlZ3r4slvSxm7z0tBcy+1pjsvsHdk8VdoDYb+QxHHllJTrIRmz 6OZd/PbJcsCdmgAurpMUaIvVnliLrT9ZP+2uAG6bBF3QTbIGIMXQRtFAPkCJaSnSOEGX g6S4FgN+LhdFOHp4NwqrMfW8sXCAiwyVqGG5myMKsrkPH9j6I9dpPq/ODJ8+ClCDm1yI RLuXBWrU0mMR23ODAaTgLUU0NtWsreeomhWfNNVwo7FPm65WZCMHM8hXDUhsBVlLnPmA kX0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Z+fX5nFJTKwyo3ZGbRsxFw0WBdXEskpcXjfZ2F3Uj8o=; b=VnC9z4gCQHzreUpcOAi6Yi5f6OUtyndjOBHzFTPAjF+LT28t3EQBC1zfsLLTnKZjq3 CKMQ34MIR5Skhv63Nv5qSGo+fsNQd9/zcFUbXtmCoQa6v7aiNhjbyku7QEadw7s2RT3Z zviGk7fDsEu2xJk6HIAlFwaxRZ9rszCI8l2OIaJwZg14Qbupfu6OzgWnM1Zccx2Fk6HW UOh7CMQC1t4DKV/1wisuU75ulkPOjkvaolBH322WvB7m7d9hF6Z32UJbka5X4zRYC4MU Yy+i8/bToR5Kyc5kOQO88kqd7/FHontgLGRXhDOwMJsdU0KpxmeUYPvPHcocrUn+s/Jm kqug== X-Gm-Message-State: AMke39m3UWO4LZi2ZXBof0oDi+myOjSuVJAvlSlhQLpGY/jrRULMEvJdlAjsSfw420Neyon0 X-Received: by 10.36.17.7 with SMTP id 7mr15516379itf.113.1488810175296; Mon, 06 Mar 2017 06:22:55 -0800 (PST) Received: from localhost.localdomain (host-98-127-250-84.bln-mt.client.bresnan.net. [98.127.250.84]) by smtp.gmail.com with ESMTPSA id y21sm3423935ioi.0.2017.03.06.06.22.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Mar 2017 06:22:54 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/4] powerpc/64: Fix checksum folding in csum_tcpudp_nofold and ip_fast_csum_nofold Date: Mon, 6 Mar 2017 07:22:39 -0700 Message-Id: <1488810161-6955-3-git-send-email-tim.gardner@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488810161-6955-1-git-send-email-tim.gardner@canonical.com> References: <1488810161-6955-1-git-send-email-tim.gardner@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Paul Mackerras BugLink: http://bugs.launchpad.net/bugs/1670247 These functions compute an IP checksum by computing a 64-bit sum and folding it to 32 bits (the "nofold" in their names refers to folding down to 16 bits). However, doing (u32) (s + (s >> 32)) is not sufficient to fold a 64-bit sum to 32 bits correctly. The addition can produce a carry out from bit 31, which needs to be added in to the sum to produce the correct result. To fix this, we copy the from64to32() function from lib/checksum.c and use that. Signed-off-by: Paul Mackerras Signed-off-by: Michael Ellerman (cherry picked from commit b492f7e4e07a28e706db26cf4943bb0911435426) Signed-off-by: Tim Gardner --- arch/powerpc/include/asm/checksum.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/checksum.h b/arch/powerpc/include/asm/checksum.h index 1e8fceb..5b1a6e3 100644 --- a/arch/powerpc/include/asm/checksum.h +++ b/arch/powerpc/include/asm/checksum.h @@ -53,17 +53,25 @@ static inline __sum16 csum_fold(__wsum sum) return (__force __sum16)(~((__force u32)sum + tmp) >> 16); } +static inline u32 from64to32(u64 x) +{ + /* add up 32-bit and 32-bit for 32+c bit */ + x = (x & 0xffffffff) + (x >> 32); + /* add up carry.. */ + x = (x & 0xffffffff) + (x >> 32); + return (u32)x; +} + static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, __wsum sum) { #ifdef __powerpc64__ - unsigned long s = (__force u32)sum; + u64 s = (__force u32)sum; s += (__force u32)saddr; s += (__force u32)daddr; s += proto + len; - s += (s >> 32); - return (__force __wsum) s; + return (__force __wsum) from64to32(s); #else __asm__("\n\ addc %0,%0,%1 \n\ @@ -123,8 +131,7 @@ static inline __wsum ip_fast_csum_nofold(const void *iph, unsigned int ihl) for (i = 0; i < ihl - 1; i++, ptr++) s += *ptr; - s += (s >> 32); - return (__force __wsum)s; + return (__force __wsum)from64to32(s); #else __wsum sum, tmp;