From nobody Wed Feb 11 02:55:18 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1682224013; cv=none; d=zohomail.com; s=zohoarc; b=WIPxZEDM2rbrw78INzLaP/g3omPOxfhcfxRTox6tfxJN5fhe1GdeneAU5WtlaSjo/KLBPBZJvy3fFBLY+mMcBaxsxlPT1QbP5eyi5jDchjS0rl1NGnfFBYCcYiTbbwSLfh77j6fVWq1SaLkN47znu6KiAfV0p6702tkK0mhjPTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682224013; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=Tf7RTaLsnhPFaO33gH3V02nVhxW08NwrHw4dctZzlhs=; b=MhhVS+eO9DQYrqESD8AdbEDPqdos3B3rvwvY3aQ3z1c2zntBWtqBzYe0qw3QMvy+8lZ4FnkWVEBsdneeM722OnGZAmM5LzAFwYEW2GMwRO1uR9aVDeo0vLqwPgNb6oCAvuaJd1Ez6AHnUudeIvwSBM8T7eNw9DVGsrIaKCvzlMA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682224013890139.07975017760464; Sat, 22 Apr 2023 21:26:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqRDZ-0005d1-Tc; Sun, 23 Apr 2023 00:20:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqRDV-0005Ea-JH for qemu-devel@nongnu.org; Sun, 23 Apr 2023 00:20:49 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pqRDS-0001KM-EV for qemu-devel@nongnu.org; Sun, 23 Apr 2023 00:20:49 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-51b33c72686so2553997a12.1 for ; Sat, 22 Apr 2023 21:20:46 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id f1-20020a170902ff0100b001a5059861adsm4596996plj.224.2023.04.22.21.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 21:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1682223645; x=1684815645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tf7RTaLsnhPFaO33gH3V02nVhxW08NwrHw4dctZzlhs=; b=450uYsT0RgEkZS23/oPUqPOQgL5nrhQZ54047scs9RC1UNI56o8dwzJd/+lrWigID4 5U3wxxo9diidsco7fvFEgIZVyPWmXEGVaazzgd8WMKcpmNX+5bwCvavOqfYMN1ssaULv Lb0qmueys4S0+lINhB0vYRWVguesv329QihmC8dhjGsFeYg54xYCf7eZddMQuoutRUVA syW9Oj87jsOUYpORxWY1c6YAcznsPJQX6AAiRKUQPsj9Ca4N/24/AUDFRviDdowWTw6e dynD2JtPOQTJxm3eg67jtOWoEJan9orXK65VIOp2Dv0nnPYqag+Z0euA6dlLM9lk2BNH f2pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682223645; x=1684815645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tf7RTaLsnhPFaO33gH3V02nVhxW08NwrHw4dctZzlhs=; b=e2D+xhNi+CX8gf86KYigIgBh3cMJBwvADWh1JWSploV8Jc3Qe44BZnINVumZtBkBfL Tax2O5S7vdg5OitOTc97LQdTjx9Z13AblkauhH7VpGEa/rvXBR3rbLwM4vIQTKcFoWAx ZVoogPaZoOCoN23BNmes66QUTU/gBJ6bapOQszFcTIDcmtlLawI6zuAhzQzGs5dokikF 3mKcCBYmpgvy3v23EpkCLnnfnlW4fjSpUsyf2axz90z+k41VGnsHl1PuiGNJVTbS6a/5 HD/aUGIs6QpS/GfPEeBCyqXqFx4iz2FyqCpwp+9g9yC9g+tU4ug93fBaQxtSdWrCytMS DyPg== X-Gm-Message-State: AAQBX9cMOKDivEpzFL7vFPK/zJweIUq4HtT2X2vjhN3CiBnwVGQzet8m C07GYdPWm7cId/t/SpgzPSYX9A== X-Google-Smtp-Source: AKy350Z4K6jkphDRhIMC7mmB5ymIgmuzqZBU7mLLBBxpRR8cb2gZftRtME2RcnSAPGTL/jNQb/tBsA== X-Received: by 2002:a17:90a:b102:b0:246:f8a8:af02 with SMTP id z2-20020a17090ab10200b00246f8a8af02mr10046329pjq.5.1682223645298; Sat, 22 Apr 2023 21:20:45 -0700 (PDT) From: Akihiko Odaki To: Cc: Sriram Yagnaraman , Jason Wang , Dmitry Fleytman , "Michael S . Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Beraldo Leal , Cleber Rosa , Laurent Vivier , Paolo Bonzini , qemu-devel@nongnu.org, Tomasz Dzieciol , Akihiko Odaki Subject: [PATCH v3 36/47] igb: Implement Rx SCTP CSO Date: Sun, 23 Apr 2023 13:18:22 +0900 Message-Id: <20230423041833.5302-37-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423041833.5302-1-akihiko.odaki@daynix.com> References: <20230423041833.5302-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::52c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1682224015049100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Akihiko Odaki Reviewed-by: Sriram Yagnaraman --- hw/net/igb_regs.h | 1 + include/net/eth.h | 4 ++- include/qemu/crc32c.h | 1 + hw/net/e1000e_core.c | 5 ++++ hw/net/igb_core.c | 15 +++++++++- hw/net/net_rx_pkt.c | 64 +++++++++++++++++++++++++++++++++++-------- net/eth.c | 4 +++ util/crc32c.c | 8 ++++++ 8 files changed, 89 insertions(+), 13 deletions(-) diff --git a/hw/net/igb_regs.h b/hw/net/igb_regs.h index e6ac26dc0e..4b4ebd3369 100644 --- a/hw/net/igb_regs.h +++ b/hw/net/igb_regs.h @@ -670,6 +670,7 @@ union e1000_adv_rx_desc { #define E1000_ADVRXD_PKT_IP6 BIT(6) #define E1000_ADVRXD_PKT_TCP BIT(8) #define E1000_ADVRXD_PKT_UDP BIT(9) +#define E1000_ADVRXD_PKT_SCTP BIT(10) =20 static inline uint8_t igb_ivar_entry_rx(uint8_t i) { diff --git a/include/net/eth.h b/include/net/eth.h index 048e434685..75e7f1551c 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -224,6 +224,7 @@ struct tcp_hdr { #define IP_HEADER_VERSION_6 (6) #define IP_PROTO_TCP (6) #define IP_PROTO_UDP (17) +#define IP_PROTO_SCTP (132) #define IPTOS_ECN_MASK 0x03 #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) #define IPTOS_ECN_CE 0x03 @@ -379,7 +380,8 @@ typedef struct eth_ip4_hdr_info_st { typedef enum EthL4HdrProto { ETH_L4_HDR_PROTO_INVALID, ETH_L4_HDR_PROTO_TCP, - ETH_L4_HDR_PROTO_UDP + ETH_L4_HDR_PROTO_UDP, + ETH_L4_HDR_PROTO_SCTP } EthL4HdrProto; =20 typedef struct eth_l4_hdr_info_st { diff --git a/include/qemu/crc32c.h b/include/qemu/crc32c.h index 5b78884c38..88b4d2b3b3 100644 --- a/include/qemu/crc32c.h +++ b/include/qemu/crc32c.h @@ -30,5 +30,6 @@ =20 =20 uint32_t crc32c(uint32_t crc, const uint8_t *data, unsigned int length); +uint32_t iov_crc32c(uint32_t crc, const struct iovec *iov, size_t iov_cnt); =20 #endif diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 0c0c45a6ce..c06c8b20c8 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -1114,6 +1114,11 @@ e1000e_verify_csum_in_sw(E1000ECore *core, return; } =20 + if (l4hdr_proto !=3D ETH_L4_HDR_PROTO_TCP && + l4hdr_proto !=3D ETH_L4_HDR_PROTO_UDP) { + return; + } + if (!net_rx_pkt_validate_l4_csum(pkt, &csum_valid)) { trace_e1000e_rx_metadata_l4_csum_validation_failed(); return; diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index a3267c0b7a..01d2788cf6 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -1220,7 +1220,7 @@ igb_build_rx_metadata(IGBCore *core, uint16_t *vlan_tag) { struct virtio_net_hdr *vhdr; - bool hasip4, hasip6; + bool hasip4, hasip6, csum_valid; EthL4HdrProto l4hdr_proto; =20 *status_flags =3D E1000_RXD_STAT_DD; @@ -1280,6 +1280,10 @@ igb_build_rx_metadata(IGBCore *core, *pkt_info |=3D E1000_ADVRXD_PKT_UDP; break; =20 + case ETH_L4_HDR_PROTO_SCTP: + *pkt_info |=3D E1000_ADVRXD_PKT_SCTP; + break; + default: break; } @@ -1312,6 +1316,15 @@ igb_build_rx_metadata(IGBCore *core, =20 if (igb_rx_l4_cso_enabled(core)) { switch (l4hdr_proto) { + case ETH_L4_HDR_PROTO_SCTP: + if (!net_rx_pkt_validate_l4_csum(pkt, &csum_valid)) { + trace_e1000e_rx_metadata_l4_csum_validation_failed(); + goto func_exit; + } + if (!csum_valid) { + *status_flags |=3D E1000_RXDEXT_STATERR_TCPE; + } + /* fall through */ case ETH_L4_HDR_PROTO_TCP: *status_flags |=3D E1000_RXD_STAT_TCPCS; break; diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 1de42b4f51..3575c8b9f9 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -16,6 +16,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/crc32c.h" #include "trace.h" #include "net_rx_pkt.h" #include "net/checksum.h" @@ -554,32 +555,73 @@ _net_rx_pkt_calc_l4_csum(struct NetRxPkt *pkt) return csum; } =20 -bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid) +static bool +_net_rx_pkt_validate_sctp_sum(struct NetRxPkt *pkt) { - uint16_t csum; + size_t csum_off; + size_t off =3D pkt->l4hdr_off; + size_t vec_len =3D pkt->vec_len; + struct iovec *vec; + uint32_t calculated =3D 0; + uint32_t original; + bool valid; =20 - trace_net_rx_pkt_l4_csum_validate_entry(); + for (vec =3D pkt->vec; vec->iov_len < off; vec++) { + off -=3D vec->iov_len; + vec_len--; + } =20 - if (pkt->l4hdr_info.proto !=3D ETH_L4_HDR_PROTO_TCP && - pkt->l4hdr_info.proto !=3D ETH_L4_HDR_PROTO_UDP) { - trace_net_rx_pkt_l4_csum_validate_not_xxp(); + csum_off =3D off + 8; + + if (!iov_to_buf(vec, vec_len, csum_off, &original, sizeof(original))) { return false; } =20 - if (pkt->l4hdr_info.proto =3D=3D ETH_L4_HDR_PROTO_UDP && - pkt->l4hdr_info.hdr.udp.uh_sum =3D=3D 0) { - trace_net_rx_pkt_l4_csum_validate_udp_with_no_checksum(); + if (!iov_from_buf(vec, vec_len, csum_off, + &calculated, sizeof(calculated))) { return false; } =20 + calculated =3D crc32c(0xffffffff, + (uint8_t *)vec->iov_base + off, vec->iov_len - off= ); + calculated =3D iov_crc32c(calculated ^ 0xffffffff, vec + 1, vec_len - = 1); + valid =3D calculated =3D=3D le32_to_cpu(original); + iov_from_buf(vec, vec_len, csum_off, &original, sizeof(original)); + + return valid; +} + +bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid) +{ + uint32_t csum; + + trace_net_rx_pkt_l4_csum_validate_entry(); + if (pkt->hasip4 && pkt->ip4hdr_info.fragment) { trace_net_rx_pkt_l4_csum_validate_ip4_fragment(); return false; } =20 - csum =3D _net_rx_pkt_calc_l4_csum(pkt); + switch (pkt->l4hdr_info.proto) { + case ETH_L4_HDR_PROTO_UDP: + if (pkt->l4hdr_info.hdr.udp.uh_sum =3D=3D 0) { + trace_net_rx_pkt_l4_csum_validate_udp_with_no_checksum(); + return false; + } + /* fall through */ + case ETH_L4_HDR_PROTO_TCP: + csum =3D _net_rx_pkt_calc_l4_csum(pkt); + *csum_valid =3D ((csum =3D=3D 0) || (csum =3D=3D 0xFFFF)); + break; + + case ETH_L4_HDR_PROTO_SCTP: + *csum_valid =3D _net_rx_pkt_validate_sctp_sum(pkt); + break; =20 - *csum_valid =3D ((csum =3D=3D 0) || (csum =3D=3D 0xFFFF)); + default: + trace_net_rx_pkt_l4_csum_validate_not_xxp(); + return false; + } =20 trace_net_rx_pkt_l4_csum_validate_csum(*csum_valid); =20 diff --git a/net/eth.c b/net/eth.c index 5307978486..7f02aea010 100644 --- a/net/eth.c +++ b/net/eth.c @@ -211,6 +211,10 @@ void eth_get_protocols(const struct iovec *iov, size_t= iovcnt, size_t iovoff, *l5hdr_off =3D *l4hdr_off + sizeof(l4hdr_info->hdr.udp); } break; + + case IP_PROTO_SCTP: + l4hdr_info->proto =3D ETH_L4_HDR_PROTO_SCTP; + break; } } =20 diff --git a/util/crc32c.c b/util/crc32c.c index 762657d853..ea7f345de8 100644 --- a/util/crc32c.c +++ b/util/crc32c.c @@ -113,3 +113,11 @@ uint32_t crc32c(uint32_t crc, const uint8_t *data, uns= igned int length) return crc^0xffffffff; } =20 +uint32_t iov_crc32c(uint32_t crc, const struct iovec *iov, size_t iov_cnt) +{ + while (iov_cnt--) { + crc =3D crc32c(crc, iov->iov_base, iov->iov_len) ^ 0xffffffff; + iov++; + } + return crc ^ 0xffffffff; +} --=20 2.40.0