From nobody Tue Apr 22 23:46:19 2025 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 4ZhzQh1yb5z5tMYT; Tue, 22 Apr 2025 23:46:20 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZhzQg6pJhz3qPF; Tue, 22 Apr 2025 23:46:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745365580; 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=5SI9tHl51a0VbZQdsfZz/M+WaigY+6BeRBLD5AfXQqc=; b=aNZ8+aogiozv/l5XHIG3xPvc2SntnzS/RNowoQ/CScTi6dvHuvrGCltjVYXI9KnS7LrCEp 5V1cT6sR5Dg727gsDSq8Z6fQF+DIWcQC7S1UGhnIqO1mZYkBvvdfbuUUWs7r0yJ0xNG1XE B56J0XNEbE4I/Uaznv/z2/di2odGAakkjBscc2ha5FOavgzSa6ZwIqPQqPRFnhu+EnzmNM DJ+4K0M3rLUbFXtB/+6Sl67ziUedplsPBONK3xr+HhvHQCJQqWc6WMWPUVGcLj87efDf2p hQtJwIPg4uHXykp/4XpLT8b8cwA8YyInqeRDILF0OgdngW7peWcBubj8xX1nrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745365580; a=rsa-sha256; cv=none; b=uVZhPNhpA0IW8odNW12ruKj5OfQeYaUrn1MY6X8TbBSu7m+PIoBmfym7lZyeRyCuYaopzc M8dYbASYmrMcAYI4jShow4N9xKRy+bnuz36iICDQDDqgPr6JcDLNMgwSsaC7Lsi+kHbNf9 JFFg/FxobLC9HewxlJnTRBeFq8ZaR668jtELxBuKenllK3sobPQKnkE7DHtXdgRFhfFgKb JK1yNDCiNnVGxGaqqRFZyJEvoj2Fz87/1auCX07/sP+T6jdHP9W+t8Mj4gNzrZv+3OkXCO HibMwkO+8ywJhmelizFDkuVSdl7kNBzDi7oGWAqRroCXgxx066d1OGtmYIYvRA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745365580; 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=5SI9tHl51a0VbZQdsfZz/M+WaigY+6BeRBLD5AfXQqc=; b=KYl158bhp75QnztsYsaikuzh0lOJeEVjItIRyj+96QPkATarpDMLTZ+cjGg2BNMgAGSso0 JlNFPsiRGHIDVI1rICiQmGrq9wpcuCMNNhUiiBXUhOja4bI7AIcT4eN3foVOOWcH67unNw UMAcTQHyFOjml+bw/GkdaYoAnGy7HS/5OD8fsuWfcVg11wz13L9W0LRq501hcVJLbE5Sfn 4znq/SIcr8DFHbIKWWIgC9uQxZBCwkECw2Oqin9maZUujmpyteXdeWyqlhmupG0ZWJPyXF Gh+syYfNmzA0A3ymjwNY6UOOWmZdpCm9RVNMjdRy+7W3Sggd4yjIVOYyMYD5bw== 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 4ZhzQg5fpPzgkW; Tue, 22 Apr 2025 23:46:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53MNkJYB009810; Tue, 22 Apr 2025 23:46:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53MNkJY3009805; Tue, 22 Apr 2025 23:46:19 GMT (envelope-from git) Date: Tue, 22 Apr 2025 23:46:19 GMT Message-Id: <202504222346.53MNkJY3009805@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: e6c91f8e5be6 - main - LinuxKPI: skbuff: rewrite data allocation to use __kmalloc by default 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-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: e6c91f8e5be66d774bc07f4055aa38fb2e287ff6 Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=e6c91f8e5be66d774bc07f4055aa38fb2e287ff6 commit e6c91f8e5be66d774bc07f4055aa38fb2e287ff6 Author: Bjoern A. Zeeb AuthorDate: 2025-04-22 20:53:47 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-04-22 23:45:49 +0000 LinuxKPI: skbuff: rewrite data allocation to use __kmalloc by default Put tunable/contigmalloc code under SKB_DMA32_MALLOC and remove the __LP64__ checks for simplicity. #define SKB_DMA32_MALLOC to be set so that the code stays enabled as busdma still has trouble bouncing contiguous memory with nseg=1 if it is multiple pages. Switch the other code to use __kmalloc() which now automatically provides physically contiguous memory and deals with freeing as well. This code should in theroy be enough now. If people use iwlwifi(4) pre-22000 (9xxx 8xxx ...) chipsets on Laptops with more than 64GB of memory they may see bounce errors as well now. Sposnored by: The FreeBSD Foundation MFC after: 3 days --- sys/compat/linuxkpi/common/src/linux_skbuff.c | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_skbuff.c b/sys/compat/linuxkpi/common/src/linux_skbuff.c index d454e5fc3ab8..2fea4d69b844 100644 --- a/sys/compat/linuxkpi/common/src/linux_skbuff.c +++ b/sys/compat/linuxkpi/common/src/linux_skbuff.c @@ -67,22 +67,26 @@ SYSCTL_INT(_compat_linuxkpi_skb, OID_AUTO, debug, CTLFLAG_RWTUN, static uma_zone_t skbzone; -#ifdef __LP64__ +#define SKB_DMA32_MALLOC +#ifdef SKB_DMA32_MALLOC /* * Realtek wireless drivers (e.g., rtw88) require 32bit DMA in a single segment. * busdma(9) has a hard time providing this currently for 3-ish pages at large * quantities (see lkpi_pci_nseg1_fail in linux_pci.c). * Work around this for now by allowing a tunable to enforce physical addresses - * allocation limits on 64bit platforms using "old-school" contigmalloc(9) to - * avoid bouncing. + * allocation limits using "old-school" contigmalloc(9) to avoid bouncing. + * Note: with the malloc/contigmalloc + kmalloc changes also providing physical + * contiguous memory, and the nseg=1 limit for bouncing we should in theory be + * fine now and not need any of this anymore, however busdma still has troubles + * boncing three contiguous pages so for now this stays. */ static int linuxkpi_skb_memlimit; SYSCTL_INT(_compat_linuxkpi_skb, OID_AUTO, mem_limit, CTLFLAG_RDTUN, &linuxkpi_skb_memlimit, 0, "SKB memory limit: 0=no limit, " "1=32bit, 2=36bit, other=undef (currently 32bit)"); -#endif static MALLOC_DEFINE(M_LKPISKB, "lkpiskb", "Linux KPI skbuff compat"); +#endif struct sk_buff * linuxkpi_alloc_skb(size_t size, gfp_t gfp) @@ -103,14 +107,12 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp) return (skb); len = size; +#ifdef SKB_DMA32_MALLOC /* * Using our own type here not backing my kmalloc. * We assume no one calls kfree directly on the skb. */ -#ifdef __LP64__ - if (__predict_true(linuxkpi_skb_memlimit == 0)) { - p = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO); - } else { + if (__predict_false(linuxkpi_skb_memlimit != 0)) { vm_paddr_t high; switch (linuxkpi_skb_memlimit) { @@ -125,10 +127,9 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp) len = roundup_pow_of_two(len); p = contigmalloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO, 0, high, PAGE_SIZE, 0); - } -#else - p = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO); + } else #endif + p = __kmalloc(len, linux_check_m_flags(gfp) | M_ZERO); if (p == NULL) { uma_zfree(skbzone, skb); return (NULL); @@ -272,7 +273,12 @@ linuxkpi_kfree_skb(struct sk_buff *skb) skb->head = NULL; } - free(skb->head, M_LKPISKB); +#ifdef SKB_DMA32_MALLOC + if (__predict_false(linuxkpi_skb_memlimit != 0)) + free(skb->head, M_LKPISKB); + else +#endif + kfree(skb->head); uma_zfree(skbzone, skb); }