From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by mail.toke.dk (Postfix) with ESMTPS id B2ED1A3C9AC for ; Mon, 13 Nov 2023 18:02:51 +0100 (CET) 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=20230601 header.b=AuNmlJX9 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5be72cd8d11so65647327b3.3 for ; Mon, 13 Nov 2023 09:02:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699894970; x=1700499770; darn=xdp-project.net; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=PAJhDBnKSX8hMywTnbhs2D/NpNn8H7rbhedPkq9pcUg=; b=AuNmlJX9i7sCeV90rvKx8Vwb/4LbPIsCG4V8REC9ob3/CsYyluko7qaULtv7hXEY0H dEDpMydoJDe7cCni1E3dQRKEXJYHu7EChc89JrJhihuCt5FyXbpy0R034JfKIt04aifZ yQtLtbMVb0ShLrYXm9zbwHXDK4/imx5+r5x6nquN0RvwBPPg7z0ircWwt89WY1rAOwxk fexzbx63KuYahRuonD/uRxl/QAnC/aEGeQHp3oPbDtFXPpOCMo+LHc/5dOBoDk6btD80 7kVztbo5c1gxfSkIzj+bwa+MzgKIlMS8dHJjCJhmdTjkPfdG3AkkefqiqaUcxQp2LAqd ck7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699894970; x=1700499770; h=content-transfer-encoding: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=PAJhDBnKSX8hMywTnbhs2D/NpNn8H7rbhedPkq9pcUg=; b=pIPNG/Q2VqSQ8BzeiosyudwEfIfN6D6W0Lvi62m28LEAR99m/5NHhvJfSe/0xSQwLn pLadJQZxL+AP0ECyIsF8QiEV4mGFeVDCJJhofsorSf8/pgyUTHfmBpCccSRY171lF2yo FX1l7DXNQhvLtxipamk9pb+7lzZXgLOxnOyraGof/L/MNkiasreiK1ha+gs8THM1HiSc mTgA8AfHNrhuqFbbTUsLFK2XR+bQqUKoZvL+Q40AW3gNEIHT2SDMfDQUxPimBp5DZ1JE En3kfAaGpjEE4NCfCsR5xDTIO5ofHdR7uXiaj31fSgJaHaOFm2Re/Nn+SimetCUylbMe NpIw== X-Gm-Message-State: AOJu0YwzfFb0QxltEbjPt5XEfDq4YnLaTPsx8XBxDMfKdPglG44uy0CX dLCxVbjNIEZOzzxtn/JDQjcTcYs= X-Google-Smtp-Source: AGHT+IFZlJzNBRz95LZBqclb+YjjBicOGP4YIjHzDU2LitrspIlAvgFGBM0RoSZXrWON7epmyCoFpU4= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a05:690c:a9d:b0:5c1:47e1:fb45 with SMTP id ci29-20020a05690c0a9d00b005c147e1fb45mr172083ywb.0.1699894970352; Mon, 13 Nov 2023 09:02:50 -0800 (PST) Date: Mon, 13 Nov 2023 09:02:48 -0800 In-Reply-To: <2ed17b27-f211-4f58-95b5-5a71914264f3@kernel.org> Mime-Version: 1.0 References: <20231102225837.1141915-1-sdf@google.com> <20231102225837.1141915-3-sdf@google.com> <2ed17b27-f211-4f58-95b5-5a71914264f3@kernel.org> Message-ID: From: Stanislav Fomichev To: Jesper Dangaard Brouer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KSWUF66TF6D4EZMZLDDZES42MB7ORX4K X-Message-ID-Hash: KSWUF66TF6D4EZMZLDDZES42MB7ORX4K X-MailFrom: 3ulZSZQMKCeEVGIJRRJOH.FRPaGS-KLQWVaGS-SURMHFW.QHW@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: bpf@vger.kernel.org, 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, 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, yoong.siang.song@intel.com, netdev@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] Re: [PATCH bpf-next v5 02/13] xsk: Add TX timestamp and TX checksum offload support List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 11/13, Jesper Dangaard Brouer wrote: >=20 >=20 > On 11/13/23 15:10, Stanislav Fomichev wrote: > > On Mon, Nov 13, 2023 at 5:16=E2=80=AFAM Jesper Dangaard Brouer wrote: > > >=20 > > >=20 > > > On 11/2/23 23:58, Stanislav Fomichev wrote: > > > > diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xd= p.h > > > > index 2ecf79282c26..b0ee7ad19b51 100644 > > > > --- a/include/uapi/linux/if_xdp.h > > > > +++ b/include/uapi/linux/if_xdp.h > > > > @@ -106,6 +106,41 @@ struct xdp_options { > > > > #define XSK_UNALIGNED_BUF_ADDR_MASK \ > > > > ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1) > > > >=20 > > > > +/* Request transmit timestamp. Upon completion, put it into tx_tim= estamp > > > > + * field of struct xsk_tx_metadata. > > > > + */ > > > > +#define XDP_TXMD_FLAGS_TIMESTAMP (1 << 0) > > > > + > > > > +/* Request transmit checksum offload. Checksum start position and = offset > > > > + * are communicated via csum_start and csum_offset fields of struc= t > > > > + * xsk_tx_metadata. > > > > + */ > > > > +#define XDP_TXMD_FLAGS_CHECKSUM (1 << 1) > > > > + > > > > +/* AF_XDP offloads request. 'request' union member is consumed by = the driver > > > > + * when the packet is being transmitted. 'completion' union member= is > > > > + * filled by the driver when the transmit completion arrives. > > > > + */ > > > > +struct xsk_tx_metadata { > > > > + union { > > > > + struct { > > > > + __u32 flags; > > > > + > > > > + /* XDP_TXMD_FLAGS_CHECKSUM */ > > > > + > > > > + /* Offset from desc->addr where checksumming = should start. */ > > > > + __u16 csum_start; > > > > + /* Offset from csum_start where checksum shou= ld be stored. */ > > > > + __u16 csum_offset; > > > > + } request; > > > > + > > > > + struct { > > > > + /* XDP_TXMD_FLAGS_TIMESTAMP */ > > > > + __u64 tx_timestamp; > > > > + } completion; > > > > + }; > > > > +}; > > >=20 > > > This looks wrong to me. It looks like member @flags is not avail at > > > completion time. At completion time, I assume we also want to know i= f > > > someone requested to get the timestamp for this packet (else we could > > > read garbage). > >=20 > > I've moved the parts that are preserved across tx and tx completion > > into xsk_tx_metadata_compl. > > This is to address Magnus/Maciej feedback where userspace might race > > with the kernel. > > See: https://lore.kernel.org/bpf/ZNoJenzKXW5QSR3E@boxer/ > >=20 >=20 > Does this mean that every driver have to extend their TX-desc ring with > sizeof(struct xsk_tx_metadata_compl)? > Won't this affect the performance of this V5? Yes, but it doesn't have to be a descriptor. Might be some internal driver completion queue (as in the case of mlx5). And definitely does affect performance :-( (see all the static branches to disable it) =20 > $ pahole -C xsk_tx_metadata_compl > ./drivers/net/ethernet/stmicro/stmmac/stmmac.ko > struct xsk_tx_metadata_compl { > __u64 * tx_timestamp; /* 0 8 */ >=20 > /* size: 8, cachelines: 1, members: 1 */ > /* last cacheline: 8 bytes */ > }; >=20 > Guess, I must be misunderstanding, as I was expecting to see the @flags > member being preserved across, as I get the race there. > > Looking at stmmac driver, it does look like this xsk_tx_metadata_compl > is part of the TX-ring for completion (tx_skbuff_dma) and the > tx_timestamp data is getting stored here. How is userspace AF_XDP > application getting access to the tx_timestamp data? > I though this was suppose to get stored in metadata data area (umem)? > > Also looking at the code, the kernel would not have a "crash" race on > the flags member (if we preserve in struct), because the code checks the > driver HW-TS config-state + TX-descriptor for the availability of a > HW-TS in the descriptor. xsk_tx_metadata_compl stores a pointer to the completion timestamp in the umem, so everything still arrives via the metadata area. We want to make sure the flags are not changing across tx and tx completion= . Instead of saving the flags, we just use that xsk_tx_metadata_compl to signal to the completion that "I know that I've requested the tx completion timestamp, please put it at this address in umem". I store the pointer instead of flags to avoid doing pointer math again at completion. But it's an implementation detail and somewhat abstracted from the drivers (besides the fact that it's probably has to fit in 8 bytes). > > > Another thing (I've raised this before): It would be really practical= to > > > store an u64 opaque value at TX and then read it at Completion time. > > > One use-case is a forwarding application storing HW RX-time and > > > comparing this to TX completion time to deduce the time spend process= ing > > > the packet. > >=20 > > This can be another member, right? But note that extending > > xsk_tx_metadata_compl might be a bit complicated because drivers have > > to carry this info somewhere. So we have to balance the amount of > > passed data between the tx and the completion. >=20 > I don't think my opaque value proposal is subject to same race problem. > I think this can be stores in metadata area and across tx and tx > completion, because any race on a flags change is the userspace > programmers problem, as it cannot cause any kernel crash (given kernel > have no need to read this). Thinking about it, I don't think this needs any special handing? You can request sizeof(struct xsk_tx_metadata) + sizeof(opaque data) as metadata. The kernel won't touch the 'opaque data' part. Or am I missing something?