From nobody Fri Jun 03 16:43:08 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 480061BD3D41; Fri, 3 Jun 2022 16:43:09 +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 4LF7wr6zSMz3sGh; Fri, 3 Jun 2022 16:43:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654274589; 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=fB+AVthXJzA9ov9WyNdKpvaA8yuCrsUqMYyBcCAH8KU=; b=k7pCF/3klFOEiP/QvAEXlKW/NBxNNIZooxYd/nt+bl/XztfcTsXZ7ZK+5QVk1Zp7tmjWJK rJ3yLNJmmhPW1YmonM4oMbB5VuH/QdcC9tnuWh8hnJ/4QzUGJAt8EBgBBzkDUx6beGyCVn XvTuhPx0Pj60aROKD1BlsazgOZpjXZr/gR9QMbnUUA1q7jU5w9gs3WWgisS8STmMQEo55X 7cInv6/Z25TjOKaYWVV1XhfXWabn+wuBKIeXboKuKo93PMeqg0tQIFGhQ99hRr7VnQqHOF Ut/F4iCVkwDgB4Sgsbtq84yISIOdhrFEvdQo+goMkhzP3pEEYpR4ODizclA9fg== 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 AC8FF4F2E; Fri, 3 Jun 2022 16:43:08 +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 253Gh85F021748; Fri, 3 Jun 2022 16:43:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 253Gh8Aj021747; Fri, 3 Jun 2022 16:43:08 GMT (envelope-from git) Date: Fri, 3 Jun 2022 16:43:08 GMT Message-Id: <202206031643.253Gh8Aj021747@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: 1f10f8aa0fae - stable/13 - LinuxKPI: skbuff: add memlimit tunable for 64bit systems 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 1f10f8aa0fae57d44175169a5c9f42e9dbee399f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654274589; 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=fB+AVthXJzA9ov9WyNdKpvaA8yuCrsUqMYyBcCAH8KU=; b=AO06Z8MGNCutMPqaeLnimyMGbk7+I5pX0l/hMx9raoIaxaeU5P35IknVBxFmonSPYXhTrs bvCrioJU6Oa4UHGIzJ6uhacqV8GyGXlZwrnpsNS7bwg7biy3CdbNIwdCSBfQ+79uwuzvel OvbZcHWAlFTpipf/LCeYJNEfV6OO46lr9uPcMxevbBU7RK5RJZDZUj06W7TbXa2mgrxIJQ g8fJBd/TMDa8w8kNT0M2pIkL1ce9AZxrnCSv9/T3PDzFWXgEeqPQ+AFkqP8VW83YhBtgBq 3MFbP6FUj/d1NcFY7DT05oNjwsa4JVQeP0MqN11Ke/YDV5zM78ye/RZ4//AddQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1654274589; a=rsa-sha256; cv=none; b=GqF60GtOOaWQe1kM50bRMwdqB1UrhiFKxIK4y6YeMxK5e3OLvk9cR3clzyh8JVcD4q4ahG 7/lJ+6s38MgWAGXJM1sMvyHC7nfbqYm9ejMItNUFahI5QGY6wWwwo6IR12KhZw+4otlwXi e/5wwm/lgnixRoetKq/syt+OOhODvQNRwnynALTbzQWHuMHWOUTu+wjWzGPlCBVSuMK4T4 1H0QiHavZQi+XGG6pop01VS3SIBEBPdp4Bj1sxV0KnaxzIat46I/ignOMhAufEWEWUv/wK jAEqffcpDOGdidI1BGKiO3PlRmmimLImz3AJ8UU7u73LEzgoiH2DabKoGQfeSA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=1f10f8aa0fae57d44175169a5c9f42e9dbee399f commit 1f10f8aa0fae57d44175169a5c9f42e9dbee399f Author: Bjoern A. Zeeb AuthorDate: 2022-05-05 20:43:34 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-06-03 15:48:15 +0000 LinuxKPI: skbuff: add memlimit tunable for 64bit systems Some drivers, such as Realtek's 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 e86707418c8e8). Work around this for now by allowing a tunable to enforce physical addresses allocation limits on 64bit platforms (ignoring PAE) using "old-school" contigmalloc(9) to avoid bouncing. A patch needing a custom kernel compiled was tested in the last weeks by rtw88 users providing the 32bit limit only hardcoded. The 36bit limit can be found in iwlwifi so is added as a testing option along. This is put in as a bandaid for now, so people no longer need to patch and compile their own kernels to use rtw88 and to allow us to MFC the driver as well before the amounts of commits to track increases by much more. Sponsored by: The FreeBSD Foundation (cherry picked from commit 6a50157090f2d0c5ab8c570d9cf2e2e3535dbdbf) --- sys/compat/linuxkpi/common/src/linux_skbuff.c | 48 ++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/src/linux_skbuff.c b/sys/compat/linuxkpi/common/src/linux_skbuff.c index df1f6439c694..fb0fcaf99239 100644 --- a/sys/compat/linuxkpi/common/src/linux_skbuff.c +++ b/sys/compat/linuxkpi/common/src/linux_skbuff.c @@ -53,17 +53,35 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef __LP64__ +#include +#endif -#ifdef SKB_DEBUG SYSCTL_DECL(_compat_linuxkpi); SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, skb, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "LinuxKPI skbuff"); +#ifdef SKB_DEBUG int linuxkpi_debug_skb; SYSCTL_INT(_compat_linuxkpi_skb, OID_AUTO, debug, CTLFLAG_RWTUN, &linuxkpi_debug_skb, 0, "SKB debug level"); #endif +#ifdef __LP64__ +/* + * 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. + */ +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"); struct sk_buff * @@ -77,7 +95,28 @@ linuxkpi_alloc_skb(size_t size, gfp_t gfp) * 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)) { + skb = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO); + } else { + vm_paddr_t high; + + switch (linuxkpi_skb_memlimit) { + case 2: + high = (0xfffffffff); /* 1<<36 really. */ + break; + case 1: + default: + high = (0xffffffff); /* 1<<32 really. */ + break; + } + len = roundup_pow_of_two(len); + skb = contigmalloc(len, M_LKPISKB, + linux_check_m_flags(gfp) | M_ZERO, 0, high, PAGE_SIZE, 0); + } +#else skb = malloc(len, M_LKPISKB, linux_check_m_flags(gfp) | M_ZERO); +#endif if (skb == NULL) return (skb); skb->_alloc_len = len; @@ -194,7 +233,14 @@ linuxkpi_kfree_skb(struct sk_buff *skb) } } +#ifdef __LP64__ + if (__predict_true(linuxkpi_skb_memlimit == 0)) + free(skb, M_LKPISKB); + else + contigfree(skb, skb->_alloc_len, M_LKPISKB); +#else free(skb, M_LKPISKB); +#endif } #ifdef DDB