From nobody Thu May 5 20:57:45 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 155361AB7E5B; Thu, 5 May 2022 20:57:46 +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 4KvQy202gSz3HxM; Thu, 5 May 2022 20:57:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651784266; 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=ha/YO5dQOmRY40RHjX3m6sgSNUXwFWzd2noIeAcge1o=; b=q4oW1LyD2x+Mnz1o2z2LEdTF7hT06TPfPKOaCl2xFcWGTsDoseSS/W6LP4ZRYJ+dSSQV2v WlE16bwAjJHTUHY/GBjTN1OgbJvJwgOIYMJrxmfBK8AGOy1MD1vJt0+5LTbZO4CxQ76rAl uTFWcY1s6uf/KkkNtbkD94BHWDWG/Ft3K8MeeZe6mQ9AwsXUVLoi5rp54p7oLmFfQLRVV/ 4hA+Fhr+5fuKzybzcScydEKInM0XpEdSjylifvbD0bdTz8uWaJ6SpDv9Cq5/Am5xBj+jJ+ rVfQzy3gud9M26e7tMui9aNuwKkKVwddMyOULJ4KCBhoTLIJhrRx2B5rLi3noA== 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 D53196BBC; Thu, 5 May 2022 20:57:45 +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 245KvjB3025011; Thu, 5 May 2022 20:57:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 245Kvj8t025010; Thu, 5 May 2022 20:57:45 GMT (envelope-from git) Date: Thu, 5 May 2022 20:57:45 GMT Message-Id: <202205052057.245Kvj8t025010@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: 6a50157090f2 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6a50157090f2d0c5ab8c570d9cf2e2e3535dbdbf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651784266; 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=ha/YO5dQOmRY40RHjX3m6sgSNUXwFWzd2noIeAcge1o=; b=W0YRPgbLZmfAIAAcJZQHqkaPD4Mlfcb3JIg1I5bW2xCsrfR0aSgqq6pgvkWScONNJqLgSL dGvCJGexyKdMxrdrCaXTzoRH91bdN9SX/43ZhVbcErhSyusIhNn9546P3HvuZZK0DEEMDo 4EdQSUJEU0Wzgo24xSmGfEt+v6lxjpTTesa1YLWB7rG4stEX0YAnCLVMalbwyj7HGgMTmq bxcdMPO0IOX8hgw1fTcYXhgMZQJ7MuLyGMd5vIBVTr3Pe+9wtc9MFz6LGfbG7oRayu59Pv x2oAaVOQOEhu8MQgMB/paph+Kg0i1Ll+w5Q/pr9YsPuDyECTV7DjLo1awDp2Ew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651784266; a=rsa-sha256; cv=none; b=PuWV4jtehxMcd1faKXkXSk/u8xznpUPndTIHsn29+87AC5ojXtRAnmPBgLJSOsUH27EnCN uj+yGH35izaEhC15Y1AtlhU75ZCild/eoIM+vnvlG8D2D7QAAJxRaWiSjZCp9AwjdbujuT OhgODfKEV1kpyAO4cPzttdvU7vsfAxRd7HTwFqkJDgaGhg3ox/eN/Y3gYCwKzd+BwHLMQw cqBWm8x9+w4JxBBWYk224dq+D3LUH9va+8p27IhJXjCkaLaJFkwiLDkCN2zbQ5p/ALDJ+n B/R8JsY9EE9l0yXpi2//1LCiG9zf7gRDd3oN5EgAHZboG5rlk4RvKev9VJlfWA== 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=6a50157090f2d0c5ab8c570d9cf2e2e3535dbdbf commit 6a50157090f2d0c5ab8c570d9cf2e2e3535dbdbf Author: Bjoern A. Zeeb AuthorDate: 2022-05-05 20:43:34 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-05-05 20:54:44 +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 MFC after: 3 days --- 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