Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84D7EC433FE for ; Sun, 6 Dec 2020 11:51:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1F24E229C5 for ; Sun, 6 Dec 2020 11:51:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F24E229C5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.45615.81053 (Exim 4.92) (envelope-from ) id 1klsZ8-0007jo-Kx; Sun, 06 Dec 2020 11:50:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 45615.81053; Sun, 06 Dec 2020 11:50:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1klsZ8-0007jh-Hf; Sun, 06 Dec 2020 11:50:58 +0000 Received: by outflank-mailman (input) for mailman id 45615; Sun, 06 Dec 2020 11:50:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1klsZ7-0007jc-1P for xen-devel@lists.xenproject.org; Sun, 06 Dec 2020 11:50:57 +0000 Received: from us-smtp-delivery-124.mimecast.com (unknown [216.205.24.124]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id c1b59f2b-76c4-45b2-9d98-fb1505625120; Sun, 06 Dec 2020 11:50:56 +0000 (UTC) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-547-BMajkwIfPnmK6VH6JJ9Bew-1; Sun, 06 Dec 2020 06:50:52 -0500 Received: by mail-ed1-f71.google.com with SMTP id ca7so4521800edb.12 for ; Sun, 06 Dec 2020 03:50:51 -0800 (PST) Received: from [192.168.1.36] (111.red-88-21-205.staticip.rima-tde.net. [88.21.205.111]) by smtp.gmail.com with ESMTPSA id m7sm7840045ejr.119.2020.12.06.03.50.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2020 03:50:49 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c1b59f2b-76c4-45b2-9d98-fb1505625120 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607255455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QXN11YjZ1vXjJBEYEKORWd+AxNil9vOhCUsNnGsnr90=; b=EBE+gLP1VnuZXkYYJXL5Tc1+GLAbpusfPwc0dNuTzw7ukVxINXFXPAqy+8ijESSE1m5UmA V6jE7nS8qPYnVABjwlIG5tvbXiVntISRAhVIdQ6BbnOMaHChg7qZoZo6EeSHlhnB4haDtQ Tb+BSyPxNxniUR9Lj2nUKOv1nvESOtI= X-MC-Unique: BMajkwIfPnmK6VH6JJ9Bew-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QXN11YjZ1vXjJBEYEKORWd+AxNil9vOhCUsNnGsnr90=; b=KaDTtXdx90ZYAb44gMZ4Bg/C05a2PGnc/GKi6LrJbeLAFq+h08mLC1jB/Y+F/AvPBx b+M6E9t1si3xxJSgPqMUGQ5fPhi2+2MnVKvFCc9uiqiKc+uME4xELSHEMe69uBG32yaU RdlrayVoFyD2KeeibLUXds7lb3au3cUm87RHTwH3lkAP2ZAFPd8oyRJZWr4GRT9JBWzG TaX3N3tXQJ6ZjjxgtvJhRTHOnxffh3P61Kp9smftb9+/18ORxffzEj9jM+APt9wuN4cc /RFJYbUCov+ENXUemzrL1SZmoDlY/Ep6ibRPjdk2Fmb3eDihsEO/+EmFEMAhgTG3J9CN qlPA== X-Gm-Message-State: AOAM531I8Ug8A2HNHN8jj579YTube+jM8K1dvRBwRp8mjwYqBEzzOYhw 8nesKUDxHORTOhGIxecV3v6VV80SuPSBnh9Lpwqv6I3N0RTPN8RwRflc8N9V5J+StvONFsjRG5Z ktqXfgF8a7LCTKb1UmE6bXdTGqXs= X-Received: by 2002:a17:907:3312:: with SMTP id ym18mr14924839ejb.437.1607255450929; Sun, 06 Dec 2020 03:50:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVzHdQ0gd9y0fPcxXvPsBOb9NLjGt7VCscZxHh6SgyV32IoDz5VTi23v/85YihGGm/4+5V7A== X-Received: by 2002:a17:907:3312:: with SMTP id ym18mr14924825ejb.437.1607255450726; Sun, 06 Dec 2020 03:50:50 -0800 (PST) Subject: Re: [PATCH 3/3] net: checksum: Introduce fine control over checksum type To: Bin Meng , qemu-devel@nongnu.org Cc: Peter Maydell , Alistair Francis , Paul Durrant , Li Zhijian , "Michael S. Tsirkin" , Andrew Jeffery , Jason Wang , Bin Meng , Joel Stanley , Beniamino Galvani , Zhang Chen , Stefano Stabellini , Peter Chubb , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , qemu-arm@nongnu.org, xen-devel@lists.xenproject.org, Anthony Perard , "Edgar E. Iglesias" , qemu-ppc@nongnu.org, David Gibson References: <1607220847-24096-1-git-send-email-bmeng.cn@gmail.com> <1607220847-24096-3-git-send-email-bmeng.cn@gmail.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <9f8cdb69-7b74-4034-223f-bfa62cb4e440@redhat.com> Date: Sun, 6 Dec 2020 12:50:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <1607220847-24096-3-git-send-email-bmeng.cn@gmail.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Ben, On 12/6/20 3:14 AM, Bin Meng wrote: > From: Bin Meng > > At present net_checksum_calculate() blindly calculates all types of > checksums (IP, TCP, UDP). Some NICs may have a per type setting in > their BDs to control what checksum should be offloaded. To support > such hardware behavior, introduce a 'csum_flag' parameter to the > net_checksum_calculate() API to allow fine control over what type > checksum is calculated. > > Existing users of this API are updated accordingly. > > Signed-off-by: Bin Meng > > --- > > hw/net/allwinner-sun8i-emac.c | 2 +- > hw/net/cadence_gem.c | 2 +- > hw/net/fsl_etsec/rings.c | 8 +++----- > hw/net/ftgmac100.c | 10 +++++++++- > hw/net/imx_fec.c | 15 +++------------ > hw/net/virtio-net.c | 2 +- > hw/net/xen_nic.c | 2 +- > include/net/checksum.h | 7 ++++++- When sending a such API refactor, patch is easier to review if you setup the scripts/git.orderfile config. > net/checksum.c | 18 ++++++++++++++---- > net/filter-rewriter.c | 4 ++-- > 10 files changed, 41 insertions(+), 29 deletions(-) ... > diff --git a/include/net/checksum.h b/include/net/checksum.h > index 05a0d27..7dec37e 100644 > --- a/include/net/checksum.h > +++ b/include/net/checksum.h > @@ -21,11 +21,16 @@ > #include "qemu/bswap.h" > struct iovec; > > +#define CSUM_IP 0x01 IMO this is IP_HEADER, > +#define CSUM_TCP 0x02 > +#define CSUM_UDP 0x04 and these IP_PAYLOAD, regardless the payload protocol. > +#define CSUM_ALL (CSUM_IP | CSUM_TCP | CSUM_UDP) Maybe CSUM_HEADER / CSUM_PAYLOAD / CSUM_FULL (aka RAW?). > + > uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); > uint16_t net_checksum_finish(uint32_t sum); > uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, > uint8_t *addrs, uint8_t *buf); > -void net_checksum_calculate(uint8_t *data, int length); > +void net_checksum_calculate(uint8_t *data, int length, int csum_flag); > > static inline uint32_t > net_checksum_add(int len, uint8_t *buf) > diff --git a/net/checksum.c b/net/checksum.c > index dabd290..70f4eae 100644 > --- a/net/checksum.c > +++ b/net/checksum.c > @@ -57,7 +57,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, > return net_checksum_finish(sum); > } > > -void net_checksum_calculate(uint8_t *data, int length) > +void net_checksum_calculate(uint8_t *data, int length, int csum_flag) > { > int mac_hdr_len, ip_len; > struct ip_header *ip; > @@ -108,9 +108,11 @@ void net_checksum_calculate(uint8_t *data, int length) > } > > /* Calculate IP checksum */ > - stw_he_p(&ip->ip_sum, 0); > - csum = net_raw_checksum((uint8_t *)ip, IP_HDR_GET_LEN(ip)); > - stw_be_p(&ip->ip_sum, csum); > + if (csum_flag & CSUM_IP) { > + stw_he_p(&ip->ip_sum, 0); > + csum = net_raw_checksum((uint8_t *)ip, IP_HDR_GET_LEN(ip)); > + stw_be_p(&ip->ip_sum, csum); > + } > > if (IP4_IS_FRAGMENT(ip)) { > return; /* a fragmented IP packet */ > @@ -128,6 +130,10 @@ void net_checksum_calculate(uint8_t *data, int length) > switch (ip->ip_p) { > case IP_PROTO_TCP: > { > + if (!(csum_flag & CSUM_TCP)) { > + return; > + } > + > tcp_header *tcp = (tcp_header *)(ip + 1); > > if (ip_len < sizeof(tcp_header)) { > @@ -148,6 +154,10 @@ void net_checksum_calculate(uint8_t *data, int length) > } > case IP_PROTO_UDP: > { > + if (!(csum_flag & CSUM_UDP)) { > + return; > + } > + > udp_header *udp = (udp_header *)(ip + 1); > > if (ip_len < sizeof(udp_header)) { ...