From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by mail.toke.dk (Postfix) with ESMTPS id 84022A17D9A for ; Fri, 7 Jul 2023 21:30:15 +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=vjhQf7Ue Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c4cda9d3823so2296304276.1 for ; Fri, 07 Jul 2023 12:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688758214; x=1691350214; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YNeiLsP2ysetsS22wf97er69882nLpLke7h5hg62src=; b=vjhQf7UeZi4iSSl+zjdVwMHpRxZGdJ2WQGb4BNvj+5SC27UI/pcyPbrCOinabSt3qL fZgMHKBtFfuab13GKStIHZaFnRGYvanWYcZt+M8TdEjrwio2Ik6Vtu3CgqhGVHrvUcCH DsUpJ1P9BRgW5vLFJipw1uV5AJe27BEQaN1bx+jG8nmO06NkjNVQwZHujk58Q6p7GBN+ 8vtckUw5O2u+VZmLVauHNNTOOOQY87Pkx8wUfcaZoeVfqd2YLCzHqzLf0PMUR+F5m105 pWq3eblnojGB56h8nslAvnCuGI/Q7NhTNctnsRkJVWco61g8+4u+woXy8wH7v/p/KZyP +ncA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688758214; x=1691350214; 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=YNeiLsP2ysetsS22wf97er69882nLpLke7h5hg62src=; b=b4TnB/mICgWumDdjVqHZMFef0ggyF494mF4MTAeRfU1enLMfT5+ssR6GRPYeT4Sw4E Ed6zR0fRu7tFgo5XUfInMhGL93F9BP95Tu8khBsTPrRX7PiiHdaMfVeI6aLIFayv07WQ fE8DmqgtlQ+7eSzF/trBOsP2HzePfkyV0WYn+oZ6HeaRuT6KaQvtYh2QL9GtLZ7ygA+h fsnglc+9P9WmWWmKhuGNldM29+Ymk+TNbYqvIlrH3CvNYL8OMSRR5GXBJNxbNzFgycrR 0j0/Bwv027D5XznKLll9KrLK9Td3tKfP83KG7TPLl3KogqzfKtpuFyBFG7j762Q+vIp2 +GWA== X-Gm-Message-State: ABy/qLano2I8OjupaahDlykHgYipeeZMKTwezkw/jSMrkR2mutsdokoq pMitkI3hUqZtgY+HBR1s1DJYJpY= X-Google-Smtp-Source: APBJJlGYyTJ0jrYZW5x3PBXckuNrfwyr4DJoJKZK02+MHpTg5wF2qpjK8Pb3aDnMicNV2jhzCPf45ZM= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a25:b193:0:b0:c01:e1c0:3b8f with SMTP id h19-20020a25b193000000b00c01e1c03b8fmr27742ybj.6.1688758213863; Fri, 07 Jul 2023 12:30:13 -0700 (PDT) Date: Fri, 7 Jul 2023 12:29:55 -0700 In-Reply-To: <20230707193006.1309662-1-sdf@google.com> Mime-Version: 1.0 References: <20230707193006.1309662-1-sdf@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230707193006.1309662-4-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: YNSABQ3EGKXLQWGJTK5FMWJ55JI7ODI7 X-Message-ID-Hash: YNSABQ3EGKXLQWGJTK5FMWJ55JI7ODI7 X-MailFrom: 3xWeoZAMKCWISDFGOOGLE.COMXDP-HINTSXDP-PROJECT.NET@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 bpf-next v3 03/14] xsk: Support XDP_TX_METADATA_LEN List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: For zerocopy mode, tx_desc->addr can point to the arbitrary offset and carry some TX metadata in the headroom. For copy mode, there is no way currently to populate skb metadata. Introduce new XDP_TX_METADATA_LEN that indicates how many bytes to treat as metadata. Metadata bytes come prior to tx_desc address (same as in RX case). Signed-off-by: Stanislav Fomichev --- include/net/xdp_sock.h | 1 + include/net/xsk_buff_pool.h | 1 + include/uapi/linux/if_xdp.h | 1 + net/xdp/xsk.c | 35 +++++++++++++++++++++++++++++++++-- net/xdp/xsk_buff_pool.c | 1 + net/xdp/xsk_queue.h | 7 ++++--- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index e96a1151ec75..30018b3b862d 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -51,6 +51,7 @@ struct xdp_sock { struct list_head flush_node; struct xsk_buff_pool *pool; u16 queue_id; + u8 tx_metadata_len; bool zc; enum { XSK_READY = 0, diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h index a8d7b8a3688a..751fea51a6af 100644 --- a/include/net/xsk_buff_pool.h +++ b/include/net/xsk_buff_pool.h @@ -75,6 +75,7 @@ struct xsk_buff_pool { u32 chunk_size; u32 chunk_shift; u32 frame_len; + u8 tx_metadata_len; /* inherited from xsk_sock */ u8 cached_need_wakeup; bool uses_need_wakeup; bool dma_need_sync; diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h index a78a8096f4ce..2374eafff7db 100644 --- a/include/uapi/linux/if_xdp.h +++ b/include/uapi/linux/if_xdp.h @@ -63,6 +63,7 @@ struct xdp_mmap_offsets { #define XDP_UMEM_COMPLETION_RING 6 #define XDP_STATISTICS 7 #define XDP_OPTIONS 8 +#define XDP_TX_METADATA_LEN 9 struct xdp_umem_reg { __u64 addr; /* Start of packet data area */ diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 5a8c0dd250af..6ef7bc4f514c 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -485,6 +485,7 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs, int err; hr = max(NET_SKB_PAD, L1_CACHE_ALIGN(dev->needed_headroom)); + hr = max(hr, L1_CACHE_ALIGN((u32)xs->tx_metadata_len)); tr = dev->needed_tailroom; len = desc->len; @@ -493,14 +494,21 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs, return ERR_PTR(err); skb_reserve(skb, hr); - skb_put(skb, len); + skb_put(skb, len + xs->tx_metadata_len); buffer = xsk_buff_raw_get_data(xs->pool, desc->addr); - err = skb_store_bits(skb, 0, buffer, len); + buffer -= xs->tx_metadata_len; + + err = skb_store_bits(skb, 0, buffer, len + xs->tx_metadata_len); if (unlikely(err)) { kfree_skb(skb); return ERR_PTR(err); } + + if (xs->tx_metadata_len) { + skb_metadata_set(skb, xs->tx_metadata_len); + __skb_pull(skb, xs->tx_metadata_len); + } } skb->dev = dev; @@ -1137,6 +1145,29 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, mutex_unlock(&xs->mutex); return err; } + case XDP_TX_METADATA_LEN: + { + int val; + + if (optlen < sizeof(val)) + return -EINVAL; + if (copy_from_sockptr(&val, optval, sizeof(val))) + return -EFAULT; + + if (val >= 256) + return -EINVAL; + if (val % 4) + return -EINVAL; + + mutex_lock(&xs->mutex); + if (xs->state != XSK_READY) { + mutex_unlock(&xs->mutex); + return -EBUSY; + } + xs->tx_metadata_len = val; + mutex_unlock(&xs->mutex); + return 0; + } default: break; } diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c index 26f6d304451e..66ff9c345a67 100644 --- a/net/xdp/xsk_buff_pool.c +++ b/net/xdp/xsk_buff_pool.c @@ -85,6 +85,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs, XDP_PACKET_HEADROOM; pool->umem = umem; pool->addrs = umem->addrs; + pool->tx_metadata_len = xs->tx_metadata_len; INIT_LIST_HEAD(&pool->free_list); INIT_LIST_HEAD(&pool->xsk_tx_list); spin_lock_init(&pool->xsk_tx_list_lock); diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index 6d40a77fccbe..c8d287c18d64 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -133,12 +133,13 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) { - u64 offset = desc->addr & (pool->chunk_size - 1); + u64 addr = desc->addr - pool->tx_metadata_len; + u64 offset = addr & (pool->chunk_size - 1); if (offset + desc->len > pool->chunk_size) return false; - if (desc->addr >= pool->addrs_cnt) + if (addr >= pool->addrs_cnt) return false; if (desc->options) @@ -149,7 +150,7 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) { - u64 addr = xp_unaligned_add_offset_to_addr(desc->addr); + u64 addr = xp_unaligned_add_offset_to_addr(desc->addr) - pool->tx_metadata_len; if (desc->len > pool->chunk_size) return false; -- 2.41.0.255.g8b1d071c50-goog