From nobody Tue Apr 29 11:41:48 2025 X-Original-To: dev-commits-src-branches@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 4Zmz1T1QSWz5tvJ4; Tue, 29 Apr 2025 11:41:49 +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 4Zmz1S3vk9z3ws5; Tue, 29 Apr 2025 11:41:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745926908; 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=3TWyhh92uWuHMlvzqp5EwXMBQZ2FAHUrv6FbmZg70YQ=; b=FFWg0w2WJotYWreOpbMe3TtmAIjhUh0E/HUjRdLhir9yZz9AwhyqcckzFyxQ2DGzcWXpaW SI8gQTnuxtfzbtU/Nubdb0FxaCIu75H/7Epf4QW3QfWRwJinrrWqFI6CWaWKQCkaYvSn4J skY/ZYdAbDtHH+MI1a68+PAPHiFBcFCNk1nwU+F0byJxeB60aHZ1acO4OYzFClaWtEIntH gwNCZEfDiaykjhGPYR+BMLfuqVP65wHG9fNj5VTrkL00LQaiZ6FyzPDqJ1/tORiR6TDj+S KzQI1pJi0pdYqvulGqcx3vZFPtLYCFxqBu2H8eXxqCKs/ljvMyDaY1Bn/HmR7A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745926908; a=rsa-sha256; cv=none; b=EvBs6hhcNLcq2wkQYWmCUrbB3fMFzWBo9i7BV5JTGjFYh1dgIZ10OGJbLe4F7x4FFYanU7 24jyYxqoNFVs1Ow/whufZqHznUNCy1gaehG1FL8xVO4A1C6ZY9hOL/QO0NJBPQZtcCSEYV 1MDWuHW/cWgENg916F0MrGfXsYTD27+pR5s1H5MlF06WXy+emgcUrCY2/Ni431Ir6aVxW9 K7CWiOnS63vr5sDeIY3/3Iv+eUqQGozSPlBira5bU90f1Z1kq4BkpzkiW2ApxZmhsX7khA QSQ/LJQ5xjPOapleoWDGW32WILt4Ea7Dq98q1bOTJb4mpXAEbkcLj5yPsx+Byw== 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=1745926908; 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=3TWyhh92uWuHMlvzqp5EwXMBQZ2FAHUrv6FbmZg70YQ=; b=rZnP0FmDvKRqb3rX9//R2r2m4fksR1p46xf1InV/J0AoIFASY4qotylT+WiLMmfRyMqJqv NfqW3kngMw7vSd8B2fUOo+AGfrajnaoi9zgAD+cY9ZI+GF6t2fkDSM6OFoi4+MB3uT4lGH sC8XUM2UzsQcql9UkR6+YTfvxkWzfMeqj/p8p3vYmq8llRdU/JbizPQ8E/XBYnLsO6ILP3 abZozvpNEP/4QulQh8UQT3qFIW6KGxRsk32N/QMJWQXhe1QKPCUE7MXIcsENscmthNK+vN 0N5YJF7iSV5DrnLaS89XEZrr9SCqQ6xkIIQQJv+E/dzmN36D7edepac0AqVfXQ== 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 4Zmz1S3RWFz3jC; Tue, 29 Apr 2025 11:41:48 +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 53TBfmCk046129; Tue, 29 Apr 2025 11:41:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53TBfmR6046126; Tue, 29 Apr 2025 11:41:48 GMT (envelope-from git) Date: Tue, 29 Apr 2025 11:41:48 GMT Message-Id: <202504291141.53TBfmR6046126@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: df71d2753d00 - stable/14 - LinuxKPI: skbuff: rewrite data allocation to use __kmalloc by default List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: df71d2753d007c51d1722044877e1a4ade867aa4 Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=df71d2753d007c51d1722044877e1a4ade867aa4 commit df71d2753d007c51d1722044877e1a4ade867aa4 Author: Bjoern A. Zeeb AuthorDate: 2025-04-22 20:53:47 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-04-29 10:49:30 +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 (apart from the 36bit check as that would overflow the variable with the constant value). 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 (cherry picked from commit e6c91f8e5be66d774bc07f4055aa38fb2e287ff6) (cherry picked from commit cd649cfc7ab23a8a36218977c60ed20afe48aea9) --- sys/compat/linuxkpi/common/src/linux_skbuff.c | 32 +++++++++++++++++---------- 1 file changed, 20 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..abfb642ba708 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,20 +107,20 @@ 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) { +#ifdef __LP64__ case 2: high = (0xfffffffff); /* 1<<36 really. */ break; +#endif case 1: default: high = (0xffffffff); /* 1<<32 really. */ @@ -125,10 +129,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 +275,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); }