Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp16989rdb; Mon, 4 Dec 2023 18:26:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHw0cCDJR8wyKzEYqRkDk2c5dLV8e3E9nYyBGj9BCt2Ove6VS5jTLBbuhjlCOKV0CYtxCl1 X-Received: by 2002:a05:6a20:e129:b0:181:6b3d:ca1c with SMTP id kr41-20020a056a20e12900b001816b3dca1cmr876985pzb.3.1701743190904; Mon, 04 Dec 2023 18:26:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743190; cv=none; d=google.com; s=arc-20160816; b=mqYJn9ZJ97X1L62KwO11wOi0fwRqVIhrJCZ/Tuf0ylM6nSZXE8b74QRbFIKeVwvZc2 J3wUzMVYLZl125vVbt9bbeshtV1UMDyV5igKcsKvsIuSLljd7RjPikvPBA7k2nrItoFo hHb0834KgodRe1tXl6I9bAuhljPXflGKKOKxf9uztavt8uIzrS/soj3nL76nwUvZqekG Hc6LR5oSafk4/qgJV8C3AYwjACVLa2DXzlYze2T/yUE4dWH6jGYl0qMwwVACWXnTiFAK cqK5NlSzUbaYGAwmMIidLBQabVJch6Yq2UYOJdwVN6wDwup0VvGijxY8BMBqnAqFpIiY DSdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yGsLus4r20WEhHIEUwFMWqvoY3KD5tmxwmXqu9yESi4=; fh=DgGXwGbnyiv1Rvt/NkXbEKOXDvWVLBCb4IpCdacEJoI=; b=OyG9inV5kAwRiyon/+fRI5JtON+FU81p/m45KWeFw32LX7DfA9XkDXzSxJZQP2BdPA 8grHNJqmKla9AEcwOKUh/q0yFnvgCHwAfd5OA1S76Dl1lYgpiMStrBf7B0sE3qa8UYaj somdhMK/tENOfqY3KgCx/iuQ9VeYMtzVrXH20/1PjjnOz8m3zPnPgXbdOZ3NtaM5+HmU XoPguwTHClAVtnuq2h5JQiEaQfqlCWBJKN264X+t1qN1aRWK4qQBBtyGAM1xAN/p2yqF aqZSev63bfParOnEzLuDvEk6WZSJIHopFyR28c+Re1QBXYD6D6QP+/bFts40pK/4l9EG S8Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=LtctdxV8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l6-20020a63f306000000b005c1e716256asi8818271pgh.218.2023.12.04.18.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:26:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=LtctdxV8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 5DA5880AD13F; Mon, 4 Dec 2023 18:26:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344098AbjLECZY (ORCPT + 99 others); Mon, 4 Dec 2023 21:25:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344092AbjLECYW (ORCPT ); Mon, 4 Dec 2023 21:24:22 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A690518B; Mon, 4 Dec 2023 18:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=yGsLus4r20WEhHIEUwFMWqvoY3KD5tmxwmXqu9yESi4=; b=LtctdxV88ZB9dZnAzKcrsyJRmK 3tN0NMX6g3+akOw4y3ZNae1A3WM5uC6dRSRxk6bOx3aJe8VdZMcHFaxBG74+d99D+waBD/i98aJwV QU/6GapyrDEWQvaNpCZpTxGjvEIcZIboUFseYoKgzl7oI6yttsI4siDtFjqWhqLxpOU6ImEd/fFbW zm6wfLREYe0TezDiEYLrnFGjLo3kTnRvEA9LAJvSbpQ6piFK5m/36cm/rPWhAbx9N1NdpzSFfe3Oc LoXFth9KtYsZr1nAQfqwCkznKqpzSctgzBXjzTVJq4pvxKAvKggqk4moJXHMSraFWvOm8IRc9e98R iXfHokZQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1rAL6k-00793Z-2V; Tue, 05 Dec 2023 02:24:22 +0000 From: Al Viro To: linux-arch@vger.kernel.org Cc: gus Gusenleitner Klaus , Al Viro , Thomas Gleixner , lkml , Ingo Molnar , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "David S. Miller" , "dsahern@kernel.org" , "kuba@kernel.org" , Paolo Abeni , Eric Dumazet Subject: [PATCH v2 12/18] x86: merge ip_fast_csum() for 32bit and 64bit Date: Tue, 5 Dec 2023 02:24:12 +0000 Message-Id: <20231205022418.1703007-21-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231205022418.1703007-1-viro@zeniv.linux.org.uk> References: <20231205022100.GB1674809@ZenIV> <20231205022418.1703007-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:26:22 -0800 (PST) Identical, except that 32bit version uses asm volatile where 64bit one uses plain asm. The former had become pointless when memory clobber got added to both versions... Signed-off-by: Al Viro --- arch/x86/include/asm/checksum.h | 43 ++++++++++++++++++++++++++++++ arch/x86/include/asm/checksum_32.h | 37 ------------------------- arch/x86/include/asm/checksum_64.h | 43 ------------------------------ 3 files changed, 43 insertions(+), 80 deletions(-) diff --git a/arch/x86/include/asm/checksum.h b/arch/x86/include/asm/checksum.h index eaa5dda09bee..5e617a380537 100644 --- a/arch/x86/include/asm/checksum.h +++ b/arch/x86/include/asm/checksum.h @@ -26,6 +26,49 @@ static inline __sum16 csum_fold(__wsum sum) return (__force __sum16)(~(__force u32)sum >> 16); } +/* + * This is a version of ip_compute_csum() optimized for IP headers, + * which always checksum on 4 octet boundaries. + * + * By Jorge Cwik , adapted for linux by + * Arnt Gulbrandsen. + */ + +/** + * ip_fast_csum - Compute the IPv4 header checksum efficiently. + * iph: ipv4 header + * ihl: length of header / 4 + */ +static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) +{ + unsigned int sum; + + asm(" movl (%1), %0\n" + " subl $4, %2\n" + " jbe 2f\n" + " addl 4(%1), %0\n" + " adcl 8(%1), %0\n" + " adcl 12(%1), %0\n" + "1: adcl 16(%1), %0\n" + " lea 4(%1), %1\n" + " decl %2\n" + " jne 1b\n" + " adcl $0, %0\n" + " movl %0, %2\n" + " shrl $16, %0\n" + " addw %w2, %w0\n" + " adcl $0, %0\n" + " notl %0\n" + "2:" + /* Since the input registers which are loaded with iph and ihl + are modified, we must also specify them as outputs, or gcc + will assume they contain their original values. */ + : "=r" (sum), "=r" (iph), "=r" (ihl) + : "1" (iph), "2" (ihl) + : "memory"); + return (__force __sum16)sum; +} + # ifdef CONFIG_X86_32 # include # else diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h index 4e96d0473f88..d920e6c335bc 100644 --- a/arch/x86/include/asm/checksum_32.h +++ b/arch/x86/include/asm/checksum_32.h @@ -55,43 +55,6 @@ static inline __wsum_fault csum_and_copy_from_user(const void __user *src, return ret; } -/* - * This is a version of ip_compute_csum() optimized for IP headers, - * which always checksum on 4 octet boundaries. - * - * By Jorge Cwik , adapted for linux by - * Arnt Gulbrandsen. - */ -static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) -{ - unsigned int sum; - - asm volatile("movl (%1), %0 ;\n" - "subl $4, %2 ;\n" - "jbe 2f ;\n" - "addl 4(%1), %0 ;\n" - "adcl 8(%1), %0 ;\n" - "adcl 12(%1), %0;\n" - "1: adcl 16(%1), %0 ;\n" - "lea 4(%1), %1 ;\n" - "decl %2 ;\n" - "jne 1b ;\n" - "adcl $0, %0 ;\n" - "movl %0, %2 ;\n" - "shrl $16, %0 ;\n" - "addw %w2, %w0 ;\n" - "adcl $0, %0 ;\n" - "notl %0 ;\n" - "2: ;\n" - /* Since the input registers which are loaded with iph and ihl - are modified, we must also specify them as outputs, or gcc - will assume they contain their original values. */ - : "=r" (sum), "=r" (iph), "=r" (ihl) - : "1" (iph), "2" (ihl) - : "memory"); - return (__force __sum16)sum; -} - static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, __wsum sum) diff --git a/arch/x86/include/asm/checksum_64.h b/arch/x86/include/asm/checksum_64.h index d261b4124ca6..b80c82590d8d 100644 --- a/arch/x86/include/asm/checksum_64.h +++ b/arch/x86/include/asm/checksum_64.h @@ -11,49 +11,6 @@ #include #include -/* - * This is a version of ip_compute_csum() optimized for IP headers, - * which always checksum on 4 octet boundaries. - * - * By Jorge Cwik , adapted for linux by - * Arnt Gulbrandsen. - */ - -/** - * ip_fast_csum - Compute the IPv4 header checksum efficiently. - * iph: ipv4 header - * ihl: length of header / 4 - */ -static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) -{ - unsigned int sum; - - asm(" movl (%1), %0\n" - " subl $4, %2\n" - " jbe 2f\n" - " addl 4(%1), %0\n" - " adcl 8(%1), %0\n" - " adcl 12(%1), %0\n" - "1: adcl 16(%1), %0\n" - " lea 4(%1), %1\n" - " decl %2\n" - " jne 1b\n" - " adcl $0, %0\n" - " movl %0, %2\n" - " shrl $16, %0\n" - " addw %w2, %w0\n" - " adcl $0, %0\n" - " notl %0\n" - "2:" - /* Since the input registers which are loaded with iph and ihl - are modified, we must also specify them as outputs, or gcc - will assume they contain their original values. */ - : "=r" (sum), "=r" (iph), "=r" (ihl) - : "1" (iph), "2" (ihl) - : "memory"); - return (__force __sum16)sum; -} - /** * csum_tcpup_nofold - Compute an IPv4 pseudo header checksum. * @saddr: source address -- 2.39.2