From patchwork Fri Mar 24 14:05:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 743190 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 3vqQF86wpVz9s8M; Sat, 25 Mar 2017 01:06:04 +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="zi5ZoGFO"; 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 1crPqr-0001bd-L0; Fri, 24 Mar 2017 14:06:01 +0000 Received: from mail-it0-f52.google.com ([209.85.214.52]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1crPqj-0001Ys-QZ for kernel-team@lists.ubuntu.com; Fri, 24 Mar 2017 14:05:53 +0000 Received: by mail-it0-f52.google.com with SMTP id 190so2174936itm.0 for ; Fri, 24 Mar 2017 07:05:53 -0700 (PDT) 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=zi5ZoGFOhAVpBLYTR3I+7KM3loEG+xy/uf+PEX/OnMLfqLtKzikAxg9rG5MiG8sULK lYddrhcj0ce5pvJDsqZnu12natM2ffRvcPtdS7uRRInB5vvd+lvElnEn5vv1Kf5LgWNl 6BpG30BVU3DtgIhk0PPfMtHswF2nRQfFuNFtgRAMeIG+bHA/vInNVvWbD/390ykaObhc /XMZxpF8f+QLuBmAF4geHJ8qSDbVwq+GO9pNRsps9B1QFVF+YB3FKSf6ABDinN0CkZMD IyfYMpDchrVymoi/YnZhZtx761wrrqkRz6iIfvudYfhJMI7QIIqd2fpabI2CNfPnuwWq M0oQ== 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=Q/NpTUi/1JV29OYhXRGAF+W21xloyH5FJ+hqqtvr7zwzF+YZ9O1oOpHQCsqnpk4ZG5 OSZ9WsWFaM7v8W9kbz7D4i8lqReZiHbMW3P7Uzp4AKIV6iMtUzIm8cmusbxoKcdyFIij +2ebyyhVj5fCjuGbx9Q2DmGLoZKVaQqo1cRz8S41bWVfFu/+aGqjZiPSufOBFnCGdWZO Sj6ojIGAhoUV5qj8Kcj4/DgENTWqj2Z7ghcDzHzCGbP1Vn/Eabq0D+soSuIExY2rD0b/ CQ5ZeDKl7qeHNLeQqITKQpijmHGXb8q9+bN9t/ctyoycqhC/DoFKQCuZfrRsHsiT/2Vg brGA== X-Gm-Message-State: AFeK/H3fDnFL7WCHZvo60gwr6uymkNZtw58ABNClTonFuExuyYGct0Zlu96bLkns+yxelxFG X-Received: by 10.36.115.145 with SMTP id y139mr3243363itb.123.1490364352463; Fri, 24 Mar 2017 07:05:52 -0700 (PDT) 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 i7sm1249173ioe.48.2017.03.24.07.05.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:05:51 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 5/7] powerpc/64: Fix checksum folding in csum_tcpudp_nofold and ip_fast_csum_nofold Date: Fri, 24 Mar 2017 08:05:38 -0600 Message-Id: <1490364340-4350-6-git-send-email-tim.gardner@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490364340-4350-1-git-send-email-tim.gardner@canonical.com> References: <1488810161-6955-1-git-send-email-tim.gardner@canonical.com> <1490364340-4350-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;