From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 873A5224CA for ; Mon, 23 Oct 2023 18:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="noRhcJwh" Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910E4FD for ; Mon, 23 Oct 2023 11:31:21 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1c9d4e38f79so25533725ad.2 for ; Mon, 23 Oct 2023 11:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698085881; x=1698690681; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wPnBqAKtu7qfmlWwJUK17l0J3rYG4g6m8kBJfqHBWcI=; b=noRhcJwhCQfXlnR6nfDGhLsP3UYBi2y7YHr2RGSwCp2duqgu/TN2ecnH1nS4lco7J/ /OjqbzZ2DpoEZUSwx5b4QGw2bbD19cBsH8/rBdq0ZxbEOXvXkMSz0Ny+uBDCkbPUWVgo fotd9a9N8BdpoO3Fno7JblFiRbIzTdxFp5CBHxZOQs524v6jtEPfKznXMhBGuklpd5aK 348Hbd8fCbf9Wxg4SFpl3+ei52or/r9tntS2EmpeOPisvSnn61mirLtexxTIfpCWCtdR I9vLYKtr7cN9QuHwZ4AW3cPWMn1ZInQPDLDGnPLhba6gJvjGZBWnIECfr7amhNrW/qw3 djVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698085881; x=1698690681; 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=wPnBqAKtu7qfmlWwJUK17l0J3rYG4g6m8kBJfqHBWcI=; b=JrVjyRq98y5trAfO7VQN/ieDEwOQGlNzYHxWEEz04BzpCV95HcHkd88/RxnS+bGR3O WSxEDgR5QFEV0R8yedIUQkG6iTYR/YjPDlLckJqaWfneA7ddwhrTXMgNpA2fBBNT6KSG T46GUq57ABMzsCaEdCfCpbm9IOg2fE+r6HveVwHc0CVtrGV9hIXs3owkTg7Pd+tPD6Ps hPE1bVfRrvxNloyQ6GCfcJ5rL0MJahVh4an/rsdEjOm1bxlLNuU0qYdZX6jZseSxmu9D iBc/MAYmUuiguuUfYwCk4XHJsypW+Ofvfg8PnjUiI8lakd5lYp3wz9jdwW5TwYtaJmvx 3brg== X-Gm-Message-State: AOJu0YzNNUENRIGtdrUT5kT6q7RcY+Hi1MJQHkbUlW7TMLAoew0X+mda zORMdN96QgVQ6WLZENeDMIgbjN4= X-Google-Smtp-Source: AGHT+IG+XvWazJNWN5c7NNnSVe2lrJdtfauU4L3Qq2lLLg+ikexd9cjwYoiGnk2YQZO9DGNX/ZkD6CQ= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:902:968d:b0:1ca:7a4c:834d with SMTP id n13-20020a170902968d00b001ca7a4c834dmr206694plp.13.1698085881006; Mon, 23 Oct 2023 11:31:21 -0700 (PDT) Date: Mon, 23 Oct 2023 11:31:19 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231019174944.3376335-1-sdf@google.com> <20231019174944.3376335-12-sdf@google.com> Message-ID: Subject: Re: [PATCH bpf-next v4 11/11] xsk: Document tx_metadata_len layout From: Stanislav Fomichev To: Magnus Karlsson 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, hawk@kernel.org, yoong.siang.song@intel.com, netdev@vger.kernel.org, xdp-hints@xdp-project.net Content-Type: text/plain; charset="utf-8" On 10/23, Magnus Karlsson wrote: > On Thu, 19 Oct 2023 at 19:50, Stanislav Fomichev wrote: > > > > - how to use > > - how to query features > > - pointers to the examples > > > > Signed-off-by: Stanislav Fomichev > > --- > > Documentation/networking/index.rst | 1 + > > Documentation/networking/xsk-tx-metadata.rst | 77 ++++++++++++++++++++ > > 2 files changed, 78 insertions(+) > > create mode 100644 Documentation/networking/xsk-tx-metadata.rst > > > > diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst > > index 2ffc5ad10295..f3c2566d6cad 100644 > > --- a/Documentation/networking/index.rst > > +++ b/Documentation/networking/index.rst > > @@ -122,6 +122,7 @@ Refer to :ref:`netdev-FAQ` for a guide on netdev development process specifics. > > xfrm_sync > > xfrm_sysctl > > xdp-rx-metadata > > + xsk-tx-metadata > > > > .. only:: subproject and html > > > > diff --git a/Documentation/networking/xsk-tx-metadata.rst b/Documentation/networking/xsk-tx-metadata.rst > > new file mode 100644 > > index 000000000000..b7289f06745c > > --- /dev/null > > +++ b/Documentation/networking/xsk-tx-metadata.rst > > @@ -0,0 +1,77 @@ > > +================== > > +AF_XDP TX Metadata > > +================== > > + > > +This document describes how to enable offloads when transmitting packets > > +via :doc:`af_xdp`. Refer to :doc:`xdp-rx-metadata` on how to access similar > > +metadata on the receive side. > > + > > +General Design > > +============== > > + > > +The headroom for the metadata is reserved via ``tx_metadata_len`` in > > +``struct xdp_umem_reg``. The metadata length is therefore the same for > > +every socket that shares the same umem. The metadata layout is a fixed UAPI, > > +refer to ``union xsk_tx_metadata`` in ``include/uapi/linux/if_xdp.h``. > > +Thus, generally, the ``tx_metadata_len`` field above should contain > > +``sizeof(union xsk_tx_metadata)``. > > + > > +The headroom and the metadata itself should be located right before > > +``xdp_desc->addr`` in the umem frame. Within a frame, the metadata > > +layout is as follows:: > > + > > + tx_metadata_len > > + / \ > > + +-----------------+---------+----------------------------+ > > + | xsk_tx_metadata | padding | payload | > > + +-----------------+---------+----------------------------+ > > + ^ > > + | > > + xdp_desc->addr > > + > > +An AF_XDP application can request headrooms larger than ``sizeof(struct > > +xsk_tx_metadata)``. The kernel will ignore the padding (and will still > > +use ``xdp_desc->addr - tx_metadata_len`` to locate > > +the ``xsk_tx_metadata``). For the frames that shouldn't carry > > +any metadata (i.e., the ones that don't have ``XDP_TX_METADATA`` option), > > +the metadata area is ignored by the kernel as well. > > + > > +The flags field enables the particular offload: > > + > > +- ``XDP_TX_METADATA_TIMESTAMP``: requests the device to put transmission > > + timestamp into ``tx_timestamp`` field of ``union xsk_tx_metadata``. > > +- ``XDP_TX_METADATA_CHECKSUM``: requests the device to calculate L4 > > + checksum. ``csum_start`` specifies byte offset of there the checksumming > > nit: of there -> where > > > + should start and ``csum_offset`` specifies byte offset where the > > + device should store the computed checksum. > > +- ``XDP_TX_METADATA_CHECKSUM_SW``: requests checksum calculation to > > + be done in software; this mode works only in ``XSK_COPY`` mode and > > + is mostly intended for testing. Do not enable this option, it > > + will negatively affect performance. > > + > > +Besides the flags above, in order to trigger the offloads, the first > > +packet's ``struct xdp_desc`` descriptor should set ``XDP_TX_METADATA`` > > +bit in the ``options`` field. Also not that in a multi-buffer packet > > nit: not -> note Thank you for both, will fix!