From nobody Thu Apr 07 20:57:00 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 836E31A9F648; Thu, 7 Apr 2022 20:57:00 +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 4KZDG436bKz3hGN; Thu, 7 Apr 2022 20:57:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649365020; 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=cwqIIf3PVinUL4y6gLJXZfZpHONyNcAPqnuSg7XQtUU=; b=bG3yjK6MQ8qyUq9sc/yi2FPZPC5rpaqzAQquOyjKyuR1UIjqajj/1Z2CWBDQOlF1YNwqU8 M0O4YdqF7A1/lVlbDK4/dzw0fPZ7ZdqWWX8UHnKXHpcmq3sOf1+t90I2eur6YPhFlnT7i+ uwNc94tXyPa87JyUECIvjMo9UA8KAwl7iYBFlyGravVE4twyW8cHJrjP53Zh3kbFv5gGeG 1ThDbJOIGJZYgzUFhbKUrb/Q4igeEcaJU6cIBvXNhSmJrPd1ZfZyZTmLo687hn3C2Rgo/M phXOra8zZfuj9NddtRyIA/qTNPgM9cJdIIeCn5nUxipO27679jJrNmU/xafABQ== 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 4BF9E174D0; Thu, 7 Apr 2022 20:57:00 +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 237Kv0lL028477; Thu, 7 Apr 2022 20:57:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 237Kv0EE028476; Thu, 7 Apr 2022 20:57:00 GMT (envelope-from git) Date: Thu, 7 Apr 2022 20:57:00 GMT Message-Id: <202204072057.237Kv0EE028476@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: 9df5f29caf1a - main - LinuxKPI: skbuff: handle dev_alloc_skb() correctly 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: 9df5f29caf1a818999d0e908cab95c83bd1f4323 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649365020; 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=cwqIIf3PVinUL4y6gLJXZfZpHONyNcAPqnuSg7XQtUU=; b=mbtxLFGw734VVQqmBKyaKWJLEcMdiTrKFAbHpuQvCin3xLnOj9TTChNnKXtxJxDy7WqKUm 8E98SWRzv9BqZft0DuXZp2L6Yq6DvUEykBwH9h5/7uW0dThyUQ8ENKln+a7hUVs+EDYwNn 19Rwa/7BMcxBouxJLBUklvERbinMA7SMzBjsrJBsXwQJiDOgDE+u7fbkahV32OAbaohAFM kvahwHrzodZEKKYh4Zs6xrQZmYOYpOt8hJHnZIAhwFxxxurB7/9GvOSXLf0OlH0IMLVX5T AhoAvQYHwxcrTZqjxy6ZIxJFV3tDgI8jh9iePwGtIgzRZe/hkpa6TnM67+hOHQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649365020; a=rsa-sha256; cv=none; b=DrlG73YXqIYIOB2+AmeaPJ3hp2BjEEcVi4+mK5WdZ2oq/F5MgQVWfG7v0e4nfw0XO5utF0 lPm5GUiGNVkEdlH9ZW7xd5gxPARpuiL/8Z+TtbcyiyL2XkRq+L+99sSfKh3V2psU5+Hm2e g5lqctxkWGW9q7T43Tu6z5V+nVJIPCXkwmhpCfho9v3xgwRJtWY643Sod+zn+4zUxksg+R dSvU0HJEhvMJ7pSr7fkkROo5L6cf+LycuNpzE1Ks4ZbZ27jIwQvahp9vCWjxEWjQ8Akob4 xOdOP0daDFxBQm7kDx/5k1Iv5jrSXaOX9BbDU3ypQ0AQ5/JblLNdp6luJvk5yQ== 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=9df5f29caf1a818999d0e908cab95c83bd1f4323 commit 9df5f29caf1a818999d0e908cab95c83bd1f4323 Author: Bjoern A. Zeeb AuthorDate: 2022-04-07 18:06:55 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-04-07 20:55:53 +0000 LinuxKPI: skbuff: handle dev_alloc_skb() correctly dev_alloc_skb() comapred to alloc_skb() reserves some headroom at the beginning of the skb which is used by drivers. Split the code for the two cases and reserve NET_SKB_PAD space, which should at least be 32 octets. Sponsored by: The FreeBSD Foundation MFC after: 3 days --- sys/compat/linuxkpi/common/include/linux/skbuff.h | 8 +++++--- sys/compat/linuxkpi/common/src/linux_skbuff.c | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/skbuff.h b/sys/compat/linuxkpi/common/include/linux/skbuff.h index 21ea7ee560e2..79d65c0169b3 100644 --- a/sys/compat/linuxkpi/common/include/linux/skbuff.h +++ b/sys/compat/linuxkpi/common/include/linux/skbuff.h @@ -38,6 +38,7 @@ #ifndef _LINUXKPI_LINUX_SKBUFF_H #define _LINUXKPI_LINUX_SKBUFF_H +#include #include #include #include @@ -84,7 +85,7 @@ enum sk_buff_pkt_type { PACKET_OTHERHOST, }; -#define NET_SKB_PAD CACHE_LINE_SIZE /* ? */ +#define NET_SKB_PAD max(CACHE_LINE_SIZE, 32) struct sk_buff_head { /* XXX TODO */ @@ -168,6 +169,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); void linuxkpi_kfree_skb(struct sk_buff *); /* -------------------------------------------------------------------------- */ @@ -187,7 +189,7 @@ __dev_alloc_skb(size_t len, gfp_t gfp) { struct sk_buff *skb; - skb = alloc_skb(len, gfp); + skb = linuxkpi_dev_alloc_skb(len, gfp); SKB_IMPROVE(); SKB_TRACE(skb); return (skb); @@ -198,7 +200,7 @@ dev_alloc_skb(size_t len) { struct sk_buff *skb; - skb = alloc_skb(len, GFP_NOWAIT); + skb = __dev_alloc_skb(len, GFP_NOWAIT); SKB_IMPROVE(); SKB_TRACE(skb); return (skb); diff --git a/sys/compat/linuxkpi/common/src/linux_skbuff.c b/sys/compat/linuxkpi/common/src/linux_skbuff.c index efb97fa2f126..dfa9dfb2ceb4 100644 --- a/sys/compat/linuxkpi/common/src/linux_skbuff.c +++ b/sys/compat/linuxkpi/common/src/linux_skbuff.c @@ -80,7 +80,7 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp) skb = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO); if (skb == NULL) return (skb); - skb->_alloc_len = size; + skb->_alloc_len = len; skb->truesize = size; skb->head = skb->data = skb->tail = (uint8_t *)(skb+1); @@ -90,7 +90,24 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp) skb->shinfo = (struct skb_shared_info *)(skb->end); - SKB_TRACE_FMT(skb, "data %p size %zu", skb->data, size); + SKB_TRACE_FMT(skb, "data %p size %zu", (skb) ? skb->data : NULL, size); + return (skb); +} + +struct sk_buff * +linuxkpi_dev_alloc_skb(size_t size, gfp_t gfp) +{ + struct sk_buff *skb; + size_t len; + + len = size + NET_SKB_PAD; + skb = linuxkpi_alloc_skb(len, gfp); + + if (skb != NULL) + skb_reserve(skb, NET_SKB_PAD); + + SKB_TRACE_FMT(skb, "data %p size %zu len %zu", + (skb) ? skb->data : NULL, size, len); return (skb); }