From nobody Wed Feb 16 02:21:10 2022 X-Original-To: dev-commits-src-all@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 7729119D10C8; Wed, 16 Feb 2022 02:21:10 +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 4Jz1sf2xLlz4nPp; Wed, 16 Feb 2022 02:21:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644978070; 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=wZZxhy5bdz8vlWyG2fXH5RafDWFaqFVd2pvarPekIMc=; b=cuLjhgzrf17U2JUeJLSAsCAx8LPXKbtt+pllPmtTrZDl9WWh3tz16nDpp7QyFH0Zfm/aSK mVqXfBErypZWzEEHIraZBG1FhWmAHEE+4YJl3HuLRP1Pzvnek975cTq/bCGwCI/l8lUHZm 0J0B1QVDzFYcwhK8Lq7VvoC4Ko53i/X4+hE3Wq9BIKhXeuu2AcD2Ua68F7OaeWxC8JAMKW U6ma+vLFlNClJejtLQy7ahMUwi6iRSt7yAggUkLJi0Lc6C1UwG2ZPAmFklbSkNgEoGVxjG nxzZhq1/yC8f5tyhHgxfaMq4E+h02QHDXq/5R9RLJm91Qb/kstpdAGFRZOCucw== 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 4533A5D1C; Wed, 16 Feb 2022 02:21:10 +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 21G2LApM000717; Wed, 16 Feb 2022 02:21:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21G2LAlR000716; Wed, 16 Feb 2022 02:21:10 GMT (envelope-from git) Date: Wed, 16 Feb 2022 02:21:10 GMT Message-Id: <202202160221.21G2LAlR000716@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: 6baea3312d92 - main - LinuxKPI: skbuff updates List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 6baea3312d92cd7eb25f5b9e0e474132636f62d9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644978070; 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=wZZxhy5bdz8vlWyG2fXH5RafDWFaqFVd2pvarPekIMc=; b=QtUH/J1d6HCOEb3aXif6TltzHjVBin/gHrV3Np2tHVR6HzUho+3VTpgTDuTtVuEMSMT9E+ 6OEUXiaoPtdLDmdI3Nc2DZ7R4SlBKWHDMdw3TEPlOHjsbW3z4T5TUreWJki7aVQhXBMlgX 7xhfl+BfD9d8W6spAmU1UHnsX84b0DmQM2u/NM+U7yAmxHZl/vESg8QT3Y8HzanVF3WYqW KuY0BAcx6a/0qlb/TrJMSaQDJbNULw4rFkK7hDK2hAEv+pFOmSA+vtzmdetpM/ALTvuAXu ejE0yWLcdZGA3kV6ndMv7hYZrp6wi4dKwq/Ej8dg2549Px2QCSNzx1zXEWqL7w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644978070; a=rsa-sha256; cv=none; b=wfbM9LTpBMqV9QXbt8PgIsL7u2RNYetQAgkVUZjJEDFqe1m3DcymktS02ftzoULJY0FXuU cUgJKTcvwqiGgjAlWKbGMbkCzHEvj5L6VVgHUXt79yM9HJbbL46cckaXNyG79lfjSEPtn1 VVPxoknh8oukLqwDARgW2pvhBolrccIddm2jJNFfIBDRJWdAsNS7xoDHxzPNsiCU7yw0mT ShZGV4MfVHfse/hzXD/1YENqHZ1jiXRLvw81EJqbatISjqwcSCJekGvg/a4/t/OhfP6oll Llpywq1LxqopEvbRs97OOTDW4kxR1ZjthpahADX+UWm7ftpceVMazxFQ7RekGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=6baea3312d92cd7eb25f5b9e0e474132636f62d9 commit 6baea3312d92cd7eb25f5b9e0e474132636f62d9 Author: Bjoern A. Zeeb AuthorDate: 2022-02-16 02:10:10 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-02-16 02:10:10 +0000 LinuxKPI: skbuff updates Various updates to skbuff for new/updated drivers and some housekeeping: - update types and struct members, add new (stub) functions - improve freeing of frags. - fix an issue with sleeping during alloc for dev_alloc_skb(). - Adjust a KASSERT for skb_reserve() which apparently can be called multiple times if no data was put into the skb yet. - move the sysctl from linux_8022.c (which may be in a different module) to linux_skbuff.c so in case we turn debugging on we do not run into unresolved symbols. Rename the sysctl variable to be less conflicting and update debugging macros along with that; also add IMPROVE(). - add DDB support to show an skbuff. - adjust comments/whitespace. No functional changes intended for iwlwifi. Sponsored by: The FreeBSD Foundation (partially) MFC after: 3 days --- sys/compat/linuxkpi/common/include/linux/skbuff.h | 151 ++++++++++++++++++---- sys/compat/linuxkpi/common/src/linux_80211.c | 8 -- sys/compat/linuxkpi/common/src/linux_skbuff.c | 104 +++++++++++++-- 3 files changed, 220 insertions(+), 43 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/skbuff.h b/sys/compat/linuxkpi/common/include/linux/skbuff.h index 37fb6109c784..f5954a9c33cf 100644 --- a/sys/compat/linuxkpi/common/include/linux/skbuff.h +++ b/sys/compat/linuxkpi/common/include/linux/skbuff.h @@ -1,6 +1,6 @@ /*- - * Copyright (c) 2020-2021 The FreeBSD Foundation - * Copyright (c) 2021 Bjoern A. Zeeb + * Copyright (c) 2020-2022 The FreeBSD Foundation + * Copyright (c) 2021-2022 Bjoern A. Zeeb * * This software was developed by Björn Zeeb under sponsorship from * the FreeBSD Foundation. @@ -43,28 +43,39 @@ #include #include #include +#include +#include /* #define SKB_DEBUG */ #ifdef SKB_DEBUG - #define DSKB_TODO 0x01 -#define DSKB_TRACE 0x02 -#define DSKB_TRACEX 0x04 -extern int debug_skb; - -#define SKB_TRACE(_s) if (debug_skb & DSKB_TRACE) \ - printf("SKB_TRACE %s:%d %p\n", __func__, __LINE__, _s) -#define SKB_TRACE2(_s, _p) if (debug_skb & DSKB_TRACE) \ - printf("SKB_TRACE %s:%d %p, %p\n", __func__, __LINE__, _s, _p) -#define SKB_TRACE_FMT(_s, _fmt, ...) if (debug_skb & DSKB_TRACE) \ - printf("SKB_TRACE %s:%d %p" _fmt "\n", __func__, __LINE__, _s, __VA_ARGS__) -#define SKB_TODO() if (debug_skb & DSKB_TODO) \ - printf("SKB_TODO %s:%d\n", __func__, __LINE__) +#define DSKB_IMPROVE 0x02 +#define DSKB_TRACE 0x10 +#define DSKB_TRACEX 0x20 +extern int linuxkpi_debug_skb; + +#define SKB_TODO() \ + if (linuxkpi_debug_skb & DSKB_TODO) \ + printf("SKB_TODO %s:%d\n", __func__, __LINE__) +#define SKB_IMPROVE(...) \ + if (linuxkpi_debug_skb & DSKB_IMPROVE) \ + printf("SKB_IMPROVE %s:%d\n", __func__, __LINE__) +#define SKB_TRACE(_s) \ + if (linuxkpi_debug_skb & DSKB_TRACE) \ + printf("SKB_TRACE %s:%d %p\n", __func__, __LINE__, _s) +#define SKB_TRACE2(_s, _p) \ + if (linuxkpi_debug_skb & DSKB_TRACE) \ + printf("SKB_TRACE %s:%d %p, %p\n", __func__, __LINE__, _s, _p) +#define SKB_TRACE_FMT(_s, _fmt, ...) \ + if (linuxkpi_debug_skb & DSKB_TRACE) \ + printf("SKB_TRACE %s:%d %p " _fmt "\n", __func__, __LINE__, _s, \ + __VA_ARGS__) #else +#define SKB_TODO() do { } while(0) +#define SKB_IMPROVE(...) do { } while(0) #define SKB_TRACE(_s) do { } while(0) #define SKB_TRACE2(_s, _p) do { } while(0) #define SKB_TRACE_FMT(_s, ...) do { } while(0) -#define SKB_TODO() do { } while(0) #endif enum sk_buff_pkt_type { @@ -80,7 +91,7 @@ struct sk_buff_head { struct sk_buff *next; struct sk_buff *prev; size_t qlen; - int lock; /* XXX TYPE */ + spinlock_t lock; }; enum sk_checksum_flags { @@ -107,6 +118,7 @@ struct skb_shared_info { enum skb_shared_info_gso_type gso_type; uint16_t gso_size; uint16_t nr_frags; + struct sk_buff *frag_list; skb_frag_t frags[64]; /* XXX TODO, 16xpage? */ }; @@ -170,13 +182,24 @@ alloc_skb(size_t size, gfp_t gfp) return (skb); } +static inline struct sk_buff * +__dev_alloc_skb(size_t len, gfp_t gfp) +{ + struct sk_buff *skb; + + skb = alloc_skb(len, gfp); + SKB_IMPROVE(); + SKB_TRACE(skb); + return (skb); +} + static inline struct sk_buff * dev_alloc_skb(size_t len) { struct sk_buff *skb; - skb = alloc_skb(len, GFP_KERNEL); - /* XXX TODO */ + skb = alloc_skb(len, GFP_NOWAIT); + SKB_IMPROVE(); SKB_TRACE(skb); return (skb); } @@ -220,8 +243,15 @@ static inline void skb_reserve(struct sk_buff *skb, size_t len) { SKB_TRACE(skb); +#if 0 + /* Apparently it is allowed to call skb_reserve multiple times in a row. */ KASSERT(skb->data == skb->head, ("%s: skb %p not empty head %p data %p " "tail %p\n", __func__, skb, skb->head, skb->data, skb->tail)); +#else + KASSERT(skb->len == 0 && skb->data == skb->tail, ("%s: skb %p not " + "empty head %p data %p tail %p len %u\n", __func__, skb, + skb->head, skb->data, skb->tail, skb->len)); +#endif skb->data += len; skb->tail += len; } @@ -302,9 +332,9 @@ skb_put(struct sk_buff *skb, size_t len) skb->tail += len; skb->len += len; #ifdef SKB_DEBUG - if (debug_skb & DSKB_TRACEX) + if (linuxkpi_debug_skb & DSKB_TRACEX) printf("%s: skb %p (%u) head %p data %p tail %p end %p, s %p len %zu\n", - __func__, skb,skb->len, skb->head, skb->data, skb->tail, skb->end, + __func__, skb, skb->len, skb->head, skb->data, skb->tail, skb->end, s, len); #endif return (s); @@ -392,7 +422,7 @@ skb_add_rx_frag(struct sk_buff *skb, int fragno, struct page *page, SKB_TRACE(skb); #ifdef SKB_DEBUG - if (debug_skb & DSKB_TRACEX) + if (linuxkpi_debug_skb & DSKB_TRACEX) printf("%s: skb %p head %p data %p tail %p end %p len %u fragno %d " "page %#jx offset %ju size %zu truesize %u\n", __func__, skb, skb->head, skb->data, skb->tail, skb->end, skb->len, fragno, @@ -567,6 +597,14 @@ skb_dequeue_tail(struct sk_buff_head *q) return (skb); } +static inline void +__skb_queue_head(struct sk_buff_head *q, struct sk_buff *skb) +{ + + SKB_TRACE2(q, skb); + __skb_queue_after(q, (struct sk_buff *)q, skb); +} + static inline void skb_queue_head(struct sk_buff_head *q, struct sk_buff *skb) { @@ -578,10 +616,19 @@ skb_queue_head(struct sk_buff_head *q, struct sk_buff *skb) static inline uint32_t skb_queue_len(struct sk_buff_head *head) { + SKB_TRACE(head); return (head->qlen); } +static inline uint32_t +skb_queue_len_lockless(const struct sk_buff_head *head) +{ + + SKB_TRACE(head); + return (READ_ONCE(head->qlen)); +} + static inline void __skb_queue_purge(struct sk_buff_head *q) { @@ -715,10 +762,26 @@ skb_mark_not_on_list(struct sk_buff *skb) } static inline void -skb_queue_splice_init(struct sk_buff_head *qa, struct sk_buff_head *qb) +skb_queue_splice_init(struct sk_buff_head *q, struct sk_buff_head *h) { - SKB_TRACE2(qa, qb); - SKB_TODO(); + struct sk_buff *b, *e; + + SKB_TRACE2(q, h); + + if (skb_queue_empty(q)) + return; + + /* XXX do we need a barrier around this? */ + b = q->next; + e = q->prev; + + b->prev = (struct sk_buff *)h; + h->next = b; + e->next = h->next; + h->next->prev = e; + + h->qlen += q->qlen; + __skb_queue_head_init(q); } static inline void @@ -753,12 +816,12 @@ __skb_linearize(struct sk_buff *skb) return (ENXIO); } -static inline bool +static inline int pskb_expand_head(struct sk_buff *skb, int x, int len, gfp_t gfp) { SKB_TRACE(skb); SKB_TODO(); - return (false); + return (-ENXIO); } /* Not really seen this one but need it as symmetric accessor function. */ @@ -823,4 +886,38 @@ csum_unfold(__sum16 sum) return (sum); } +static inline void +skb_reset_tail_pointer(struct sk_buff *skb) +{ + + SKB_TRACE(skb); + skb->tail = (uint8_t *)(uintptr_t)(skb->data - skb->head); + SKB_TRACE(skb); +} + +static inline struct sk_buff * +skb_get(struct sk_buff *skb) +{ + + SKB_TODO(); /* XXX refcnt? as in get/put_device? */ + return (skb); +} + +static inline struct sk_buff * +skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom) +{ + + SKB_TODO(); + return (NULL); +} + +static inline void +skb_copy_from_linear_data(const struct sk_buff *skb, void *dst, size_t len) +{ + + SKB_TRACE(skb); + /* Let us just hope the destination has len space ... */ + memcpy(dst, skb->data, len); +} + #endif /* _LINUXKPI_LINUX_SKBUFF_H */ diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c index 8bce01c25f5b..a1010b23f76f 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.c +++ b/sys/compat/linuxkpi/common/src/linux_80211.c @@ -72,14 +72,6 @@ __FBSDID("$FreeBSD$"); static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "Linux KPI 80211 compat"); -/* -------------------------------------------------------------------------- */ -/* These are unrelated to 802.11 sysctl bug debugging during 802.11 work so * - * keep them here rather than in a more general file. */ - -int debug_skb; -SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_skb, CTLFLAG_RWTUN, - &debug_skb, 0, "SKB debug level"); - /* -------------------------------------------------------------------------- */ int debug_80211; diff --git a/sys/compat/linuxkpi/common/src/linux_skbuff.c b/sys/compat/linuxkpi/common/src/linux_skbuff.c index e9935e65b466..0a4974d74d9d 100644 --- a/sys/compat/linuxkpi/common/src/linux_skbuff.c +++ b/sys/compat/linuxkpi/common/src/linux_skbuff.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 2020-2021 The FreeBSD Foundation - * Copyright (c) 2021 Bjoern A. Zeeb + * Copyright (c) 2020-2022 The FreeBSD Foundation + * Copyright (c) 2021-2022 Bjoern A. Zeeb * * This software was developed by Björn Zeeb under sponsorship from * the FreeBSD Foundation. @@ -38,13 +38,31 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_ddb.h" + #include #include #include #include +#include + +#ifdef DDB +#include +#endif #include #include +#include + +#ifdef SKB_DEBUG +SYSCTL_DECL(_compat_linuxkpi); +SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, skb, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, + "LinuxKPI skbuff"); + +int linuxkpi_debug_skb; +SYSCTL_INT(_compat_linuxkpi_skb, OID_AUTO, debug, CTLFLAG_RWTUN, + &linuxkpi_debug_skb, 0, "SKB debug level"); +#endif static MALLOC_DEFINE(M_LKPISKB, "lkpiskb", "Linux KPI skbuff compat"); @@ -56,7 +74,7 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp) len = sizeof(*skb) + size + sizeof(struct skb_shared_info); /* - * Using or own type here not backing my kmalloc. + * Using our own type here not backing my kmalloc. * We assume no one calls kfree directly on the skb. */ skb = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO); @@ -78,7 +96,7 @@ void linuxkpi_kfree_skb(struct sk_buff *skb) { struct skb_shared_info *shinfo; - uint16_t fragno; + uint16_t fragno, count; SKB_TRACE(skb); if (skb == NULL) @@ -103,11 +121,81 @@ linuxkpi_kfree_skb(struct sk_buff *skb) ("%s: skb %p m %p != NULL\n", __func__, skb, skb->m)); shinfo = skb->shinfo; - for (fragno = 0; fragno < nitems(shinfo->frags); fragno++) { - - if (shinfo->frags[fragno].page != NULL) - __free_page(shinfo->frags[fragno].page); + for (count = fragno = 0; + count < shinfo->nr_frags && fragno < nitems(shinfo->frags); + fragno++) { + + if (shinfo->frags[fragno].page != NULL) { + struct page *p; + + p = shinfo->frags[fragno].page; + shinfo->frags[fragno].size = 0; + shinfo->frags[fragno].offset = 0; + shinfo->frags[fragno].page = NULL; + __free_page(p); + count++; + } } free(skb, M_LKPISKB); } + +#ifdef DDB +DB_SHOW_COMMAND(skb, db_show_skb) +{ + struct sk_buff *skb; + int i; + + if (!have_addr) { + db_printf("usage: show skb \n"); + return; + } + + skb = (struct sk_buff *)addr; + + db_printf("skb %p\n", skb); + db_printf("\tnext %p prev %p\n", skb->next, skb->prev); + db_printf("\tlist %d\n", skb->list); + db_printf("\t_alloc_len %u len %u data_len %u truesize %u mac_len %u\n", + skb->_alloc_len, skb->len, skb->data_len, skb->truesize, + skb->mac_len); + db_printf("\tcsum %#06x l3hdroff %u l4hdroff %u priority %u qmap %u\n", + skb->csum, skb->l3hdroff, skb->l4hdroff, skb->priority, skb->qmap); + db_printf("\tpkt_type %d dev %p sk %p\n", + 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("\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", + skb->shinfo, skb->m, skb->m_free_func); + + if (skb->shinfo != NULL) { + struct skb_shared_info *shinfo; + + shinfo = skb->shinfo; + db_printf("\t\tgso_type %d gso_size %u nr_frags %u\n", + shinfo->gso_type, shinfo->gso_size, shinfo->nr_frags); + for (i = 0; i < nitems(shinfo->frags); i++) { + struct skb_frag *frag; + + frag = &shinfo->frags[i]; + if (frag == NULL || frag->page == NULL) + continue; + db_printf("\t\t\tfrag %p fragno %d page %p %p " + "offset %ju size %zu\n", + frag, i, frag->page, linux_page_address(frag->page), + (uintmax_t)frag->offset, frag->size); + } + } + db_printf("\tcb[] %p {", skb->cb); + for (i = 0; i < nitems(skb->cb); i++) { + db_printf("%#04x%s", + skb->cb[i], (i < (nitems(skb->cb)-1)) ? ", " : ""); + } + db_printf("}\n"); + + db_printf("\t_spareu16_0 %#06x __scratch[0] %p\n", + skb->_spareu16_0, skb->__scratch); +}; +#endif