From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by mail.toke.dk (Postfix) with ESMTPS id 338A1A1BE24 for ; Tue, 25 Jul 2023 02:00:14 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20221208 header.b=CeAYCGEZ Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-563396c1299so4372535a12.2 for ; Mon, 24 Jul 2023 17:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690243212; x=1690848012; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8lu7z7JckF+WwjvByshwT9Vj3+m/MkD61H4qOkk5aNU=; b=CeAYCGEZVercQMn2M4u8tm+S8E8/ZMIntk511s3YBa3sjjjDaQeDB89nxHzTMcdc8H VmPb5kg1eRc3hwcxHLKD1HVkFJP6g/aTF9NNHeGRu0oy1TIFZd8aL2Pwo5h2iRHu09oN Aw964QV4AxLVTEo5YWQ7M5SEuUggz3fF0DTl0ZshssiHQ5H1UGT5nW83UnAon1T27I/L hlYnUGW4IbnpLdmhMmB1izUCuQQXeFx+6ASHDu7qoB03nNCzrPQZ16CBcNhNgcrjKBK0 dfICa7J/arw0HCfFrMBpvq0OYtFr6XIkaApzEvbXF8dGOWqWvpTX/MCn7FHwbapjQhmd 0GMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690243213; x=1690848013; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8lu7z7JckF+WwjvByshwT9Vj3+m/MkD61H4qOkk5aNU=; b=jVlipcBtKfacWZkoDEVqgIpp7n3LTqvup5yWhf3GymAFsH+Cxx5rUF1O2BZ87FkH22 01ztjrUTCR83txF6vgTn00tZy6MAcvsQ7LF2WW8bpVzqSHrbdgvORsUxoxbBGtf6hXo3 ddw0E5utCnwlXohTSmAalat4U5952fjhyo/zTlDSjHgo78VoqqefynN/tSpGG5XzEHug cg2IstJy6xzNb3CjJk6WN1NmSpQf5xKX4lqIhkmZg6XKqMhsKNoqkhQjnf87E+EpWyhT oeLA6gIzpZy6BmV/3HlnZBr5gLsM+U4yJuL0f9oX3lXnnqEffBTqg2T7lPCZNSXVNThM K74Q== X-Gm-Message-State: ABy/qLY+p7G0yUKaNkqEfszNu/S0kTyhoGbt0Q3xMdUw+Kws9Otf6TXr Vq8R6mhN/qWOu0IgjQ0MSCI2wPw= X-Google-Smtp-Source: APBJJlGLpmeK7I0G8oMupZCuwtKhOQsRExw1BOzpw9G2DFmlhD/kyCi1xNOsaUFXgOiN4vcFH6ktcDM= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a63:3549:0:b0:55c:5c64:2c73 with SMTP id c70-20020a633549000000b0055c5c642c73mr46597pga.6.1690243212600; Mon, 24 Jul 2023 17:00:12 -0700 (PDT) Date: Mon, 24 Jul 2023 16:59:56 -0700 In-Reply-To: <20230724235957.1953861-1-sdf@google.com> Mime-Version: 1.0 References: <20230724235957.1953861-1-sdf@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230724235957.1953861-8-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: QOJZAE2WW74SL3EOARBVYOSNWE6LJOEJ X-Message-ID-Hash: QOJZAE2WW74SL3EOARBVYOSNWE6LJOEJ X-MailFrom: 3jBC_ZAMKCdUJ467FF7C5.3FDO4G-89EKJO4G-GIFA53K.E5K@flex--sdf.bounces.google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, kuba@kernel.org, toke@kernel.org, willemb@google.com, dsahern@kernel.org, magnus.karlsson@intel.com, bjorn@kernel.org, maciej.fijalkowski@intel.com, hawk@kernel.org, netdev@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] [RFC net-next v4 7/8] selftests/bpf: Add TX side to xdp_metadata List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Request TX timestamp and make sure it's not empty. Request TX checksum offload (SW-only) and make sure it's resolved to the correct one. Signed-off-by: Stanislav Fomichev --- .../selftests/bpf/prog_tests/xdp_metadata.c | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c index 626c461fa34d..04477a557b8c 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c @@ -48,6 +48,7 @@ static int open_xsk(int ifindex, struct xsk *xsk) { int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; const struct xsk_socket_config socket_config = { + .tx_metadata_len = sizeof(struct xsk_tx_metadata), .rx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, .tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, .bind_flags = XDP_COPY, @@ -138,6 +139,7 @@ static void ip_csum(struct iphdr *iph) static int generate_packet(struct xsk *xsk, __u16 dst_port) { + struct xsk_tx_metadata *meta; struct xdp_desc *tx_desc; struct udphdr *udph; struct ethhdr *eth; @@ -151,10 +153,14 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) return -1; tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx); - tx_desc->addr = idx % (UMEM_NUM / 2) * UMEM_FRAME_SIZE; + tx_desc->addr = idx % (UMEM_NUM / 2) * UMEM_FRAME_SIZE + sizeof(struct xsk_tx_metadata); printf("%p: tx_desc[%u]->addr=%llx\n", xsk, idx, tx_desc->addr); data = xsk_umem__get_data(xsk->umem_area, tx_desc->addr); + meta = data - sizeof(struct xsk_tx_metadata); + memset(meta, 0, sizeof(*meta)); + meta->flags = XDP_TX_METADATA_TIMESTAMP; + eth = data; iph = (void *)(eth + 1); udph = (void *)(iph + 1); @@ -178,11 +184,17 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) udph->source = htons(AF_XDP_SOURCE_PORT); udph->dest = htons(dst_port); udph->len = htons(sizeof(*udph) + UDP_PAYLOAD_BYTES); - udph->check = 0; + udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, + ntohs(udph->len), IPPROTO_UDP, 0); memset(udph + 1, 0xAA, UDP_PAYLOAD_BYTES); + meta->flags |= XDP_TX_METADATA_CHECKSUM | XDP_TX_METADATA_CHECKSUM_SW; + meta->csum_start = sizeof(*eth) + sizeof(*iph); + meta->csum_offset = offsetof(struct udphdr, check); + tx_desc->len = sizeof(*eth) + sizeof(*iph) + sizeof(*udph) + UDP_PAYLOAD_BYTES; + tx_desc->options |= XDP_TX_METADATA; xsk_ring_prod__submit(&xsk->tx, 1); ret = sendto(xsk_socket__fd(xsk->socket), NULL, 0, MSG_DONTWAIT, NULL, 0); @@ -194,13 +206,21 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) static void complete_tx(struct xsk *xsk) { - __u32 idx; + struct xsk_tx_metadata *meta; __u64 addr; + void *data; + __u32 idx; if (ASSERT_EQ(xsk_ring_cons__peek(&xsk->comp, 1, &idx), 1, "xsk_ring_cons__peek")) { addr = *xsk_ring_cons__comp_addr(&xsk->comp, idx); printf("%p: complete tx idx=%u addr=%llx\n", xsk, idx, addr); + + data = xsk_umem__get_data(xsk->umem_area, addr); + meta = data - sizeof(struct xsk_tx_metadata); + + ASSERT_NEQ(meta->tx_timestamp, 0, "tx_timestamp"); + xsk_ring_cons__release(&xsk->comp, 1); } } @@ -221,6 +241,7 @@ static int verify_xsk_metadata(struct xsk *xsk) const struct xdp_desc *rx_desc; struct pollfd fds = {}; struct xdp_meta *meta; + struct udphdr *udph; struct ethhdr *eth; struct iphdr *iph; __u64 comp_addr; @@ -257,6 +278,7 @@ static int verify_xsk_metadata(struct xsk *xsk) ASSERT_EQ(eth->h_proto, htons(ETH_P_IP), "eth->h_proto"); iph = (void *)(eth + 1); ASSERT_EQ((int)iph->version, 4, "iph->version"); + udph = (void *)(iph + 1); /* custom metadata */ @@ -270,6 +292,9 @@ static int verify_xsk_metadata(struct xsk *xsk) ASSERT_EQ(meta->rx_hash_type, 0, "rx_hash_type"); + /* checksum offload */ + ASSERT_EQ(udph->check, 0x1c72, "csum"); + xsk_ring_cons__release(&xsk->rx, 1); refill_rx(xsk, comp_addr); -- 2.41.0.487.g6d72f3e995-goog