From nobody Mon Nov 28 21:16:24 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NLdZ114p5z4hxPQ; Mon, 28 Nov 2022 21:16:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NLdZ10bZ2z3PDQ; Mon, 28 Nov 2022 21:16:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669670185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7biYt+4Mp/c6TTmBNDuV7oQ5L2Qwm3WK+yOwfbh+GBE=; b=Hstq4jw1pD4d02g+OXBFsx591seAvCPH7i3WQ5PqZm93+HqSJT3ve2tJ5gg7kVGnQ9hVWn BB62EQ4C0BfO+TJKuURtZtg16buFGnv/bXEyDllef+btUys7fynZwZW6mjfTDa8HthyIkG cH4Dm4M8DCj6LND7oYTEEZPrQRd6l5R4xue8aN886HkcEwUaMp3ctRZxrRhiN3/CZ1i7eS ZuoH0YSv6zmZPp91SmvO/XYe87tp0Y2Ps3MBfFwmR7dn0HlEOEnLJYL8q7SrcYnpHS/LMm tcpEwPnCczCbzJc2UonBWouVtUM7uh3COaLP5p6mxvRM6qppz7s5M9WCNBaMjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669670185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7biYt+4Mp/c6TTmBNDuV7oQ5L2Qwm3WK+yOwfbh+GBE=; b=H921yFMCKj99NeGZKjh+2HjyGn4C0M9e8ou+ZFCVR0i4rm3rGjCj545k8gI+1RT6kaTO+W hDRuFhkXVx3Ru6Lo+OO08OO3RFX4r5EAtS4oWFRSKwpNxfrilOMlIPEO2gea30zi/TQWSP VqtqOmll060TS8jawcrmWIPQFWmT9Vh326wO0TJILo1NYtDVdvsZXrsfB/V/Di1MS+fnTq 47mUwSKynw5nGCMv/7USkxSLGrU1gjhsMV4SjlZLTG6ZaHYxhS5+zKlp8xvMIHw8mFO3xz HrirTNC2fk+FCw9HasZc2ocMAkk8gV7kyh7zv7UxMrFweZk2YvWXPhglHM88Rg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669670185; a=rsa-sha256; cv=none; b=JzoNsPwNYDnVRzXSwuD50HWJda04Rr6SqMP/CpQHZtGD9Wl0juY29Wra++uaMR5Rvw/NSc a8knLE59e3yIA5ZKHS9mttx80X9jmQCwm4eOdp78oNtvaswSXziSUHYJZPRz6gtTKCkCDz EU3FtIYhv/WaqPU2VtP8mUCp1V+JKBaMtRgHO4aQ/sbSseBl+F16jxNXuBQ4rIG4BklSHe Sg4r5YPtsNIpGE4EetBBS9eE+iLDA1NFwBwgJU3lJ0uOGyYjJcb4mN54KncePNKxWUbeQu 5pfXK/VU8UwOS13oxXSrvH8f9s1bVajXO8pxDHFniqHh+aEgbDAckDEViclr3Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NLdZ06lNgzs0X; Mon, 28 Nov 2022 21:16:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2ASLGOdw008832; Mon, 28 Nov 2022 21:16:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2ASLGOcv008831; Mon, 28 Nov 2022 21:16:24 GMT (envelope-from git) Date: Mon, 28 Nov 2022 21:16:24 GMT Message-Id: <202211282116.2ASLGOcv008831@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 5504bd59a39b - main - LinuxKPI: SKB update List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5504bd59a39ba0bd0014308ff1aa5d4899432a3e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=5504bd59a39ba0bd0014308ff1aa5d4899432a3e commit 5504bd59a39ba0bd0014308ff1aa5d4899432a3e Author: Bjoern A. Zeeb AuthorDate: 2022-11-28 20:54:57 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-11-28 20:54:57 +0000 LinuxKPI: SKB update - skb_reset_tail_pointer(): we do not do offsets so do a plain reset - skb_add_rx_frag(): adjust data_len to keep track of the frag - based on that implement skb_is_nonlinear() and skb_linearize() - implement build_skb() and adjust linuxkpi_kfree_skb() and ddb macro. Sponsored by: The FreeBSD Foundation (partially) MFC after: 3 days --- sys/compat/linuxkpi/common/include/linux/skbuff.h | 56 +++++++++++++---------- sys/compat/linuxkpi/common/src/linux_skbuff.c | 33 ++++++++++++- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/skbuff.h b/sys/compat/linuxkpi/common/include/linux/skbuff.h index 992cc2d44b39..35d5a1fd9b80 100644 --- a/sys/compat/linuxkpi/common/include/linux/skbuff.h +++ b/sys/compat/linuxkpi/common/include/linux/skbuff.h @@ -143,7 +143,8 @@ struct sk_buff { uint16_t l4hdroff; /* transport header offset from *head */ uint32_t priority; uint16_t qmap; /* queue mapping */ - uint16_t _spareu16_0; + uint16_t _flags; /* Internal flags. */ +#define _SKB_FLAGS_SKBEXTFRAG 0x0001 enum sk_buff_pkt_type pkt_type; /* "Scratch" area for layers to store metadata. */ @@ -174,6 +175,7 @@ struct sk_buff { struct sk_buff *linuxkpi_alloc_skb(size_t, gfp_t); struct sk_buff *linuxkpi_dev_alloc_skb(size_t, gfp_t); +struct sk_buff *linuxkpi_build_skb(void *, size_t); void linuxkpi_kfree_skb(struct sk_buff *); struct sk_buff *linuxkpi_skb_copy(struct sk_buff *, gfp_t); @@ -241,6 +243,16 @@ dev_kfree_skb_irq(struct sk_buff *skb) dev_kfree_skb(skb); } +static inline struct sk_buff * +build_skb(void *data, unsigned int fragsz) +{ + struct sk_buff *skb; + + skb = linuxkpi_build_skb(data, fragsz); + SKB_TRACE(skb); + return (skb); +} + /* -------------------------------------------------------------------------- */ /* XXX BZ review this one for terminal condition as Linux "queues" are special. */ @@ -467,6 +479,7 @@ skb_add_rx_frag(struct sk_buff *skb, int fragno, struct page *page, shinfo->frags[fragno].size = size; shinfo->nr_frags = fragno + 1; skb->len += size; + skb->data_len += size; skb->truesize += truesize; /* XXX TODO EXTEND truesize? */ @@ -748,13 +761,6 @@ skb_frag_size(const skb_frag_t *frag) return (-1); } -static inline bool -skb_is_nonlinear(struct sk_buff *skb) -{ - SKB_TRACE(skb); - return ((skb->data_len > 0) ? true : false); -} - #define skb_walk_frags(_skb, _frag) \ for ((_frag) = (_skb); false; (_frag)++) @@ -859,6 +865,13 @@ skb_network_header(struct sk_buff *skb) return (skb->head + skb->l3hdroff); } +static inline bool +skb_is_nonlinear(struct sk_buff *skb) +{ + SKB_TRACE(skb); + return ((skb->data_len > 0) ? true : false); +} + static inline int __skb_linearize(struct sk_buff *skb) { @@ -867,6 +880,13 @@ __skb_linearize(struct sk_buff *skb) return (ENXIO); } +static inline int +skb_linearize(struct sk_buff *skb) +{ + + return (skb_is_nonlinear(skb) ? __skb_linearize(skb) : 0); +} + static inline int pskb_expand_head(struct sk_buff *skb, int x, int len, gfp_t gfp) { @@ -940,7 +960,10 @@ skb_reset_tail_pointer(struct sk_buff *skb) { SKB_TRACE(skb); +#ifdef SKB_DOING_OFFSETS_US_NOT skb->tail = (uint8_t *)(uintptr_t)(skb->data - skb->head); +#endif + skb->tail = skb->data; SKB_TRACE(skb); } @@ -969,14 +992,6 @@ skb_copy_from_linear_data(const struct sk_buff *skb, void *dst, size_t len) memcpy(dst, skb->data, len); } -static inline struct sk_buff * -build_skb(void *data, unsigned int fragsz) -{ - - SKB_TODO(); - return (NULL); -} - static inline int skb_pad(struct sk_buff *skb, int pad) { @@ -1002,15 +1017,6 @@ napi_consume_skb(struct sk_buff *skb, int budget) SKB_TODO(); } -static inline bool -skb_linearize(struct sk_buff *skb) -{ - - SKB_TRACE(skb); - SKB_TODO(); - return (false); -} - #define SKB_WITH_OVERHEAD(_s) \ (_s) - ALIGN(sizeof(struct skb_shared_info), CACHE_LINE_SIZE) diff --git a/sys/compat/linuxkpi/common/src/linux_skbuff.c b/sys/compat/linuxkpi/common/src/linux_skbuff.c index df8e3fda8d56..c23a59b3c536 100644 --- a/sys/compat/linuxkpi/common/src/linux_skbuff.c +++ b/sys/compat/linuxkpi/common/src/linux_skbuff.c @@ -150,6 +150,28 @@ linuxkpi_dev_alloc_skb(size_t size, gfp_t gfp) return (skb); } +struct sk_buff * +linuxkpi_build_skb(void *data, size_t fragsz) +{ + struct sk_buff *skb; + + if (data == NULL || fragsz == 0) + return (NULL); + + /* Just allocate a skb without data area. */ + skb = linuxkpi_alloc_skb(0, GFP_KERNEL); + if (skb == NULL) + return (NULL); + + skb->_flags |= _SKB_FLAGS_SKBEXTFRAG; + skb->truesize = fragsz; + skb->head = skb->data = data; + skb_reset_tail_pointer(skb); /* XXX is that correct? */ + skb->end = (void *)((uintptr_t)skb->head + fragsz); + + return (skb); +} + struct sk_buff * linuxkpi_skb_copy(struct sk_buff *skb, gfp_t gfp) { @@ -233,6 +255,13 @@ linuxkpi_kfree_skb(struct sk_buff *skb) } } + if ((skb->_flags & _SKB_FLAGS_SKBEXTFRAG) != 0) { + void *p; + + p = skb->head; + skb_free_frag(p); + } + #ifdef __LP64__ if (__predict_true(linuxkpi_skb_memlimit == 0)) free(skb, M_LKPISKB); @@ -268,6 +297,7 @@ DB_SHOW_COMMAND(skb, db_show_skb) skb->pkt_type, skb->dev, skb->sk); db_printf("\tcsum_offset %d csum_start %d ip_summed %d protocol %d\n", skb->csum_offset, skb->csum_start, skb->ip_summed, skb->protocol); + db_printf("\t_flags %#06x\n", skb->_flags); /* XXX-BZ print names? */ db_printf("\thead %p data %p tail %p end %p\n", skb->head, skb->data, skb->tail, skb->end); db_printf("\tshinfo %p m %p m_free_func %p\n", @@ -298,7 +328,6 @@ DB_SHOW_COMMAND(skb, db_show_skb) } db_printf("}\n"); - db_printf("\t_spareu16_0 %#06x __scratch[0] %p\n", - skb->_spareu16_0, skb->__scratch); + db_printf("\t__scratch[0] %p\n", skb->__scratch); }; #endif