From nobody Tue Nov 30 01:35:37 2021 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 2AD9118BBC82; Tue, 30 Nov 2021 01:35:38 +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 4J34Y55GZhz3nKf; Tue, 30 Nov 2021 01:35:37 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9617F53EA; Tue, 30 Nov 2021 01:35:37 +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 1AU1Zb1C054605; Tue, 30 Nov 2021 01:35:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AU1ZbJc054604; Tue, 30 Nov 2021 01:35:37 GMT (envelope-from git) Date: Tue, 30 Nov 2021 01:35:37 GMT Message-Id: <202111300135.1AU1ZbJc054604@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 02e3eb8d482d - stable/13 - mbuf: Only allow extpg mbufs if the system has a direct map 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 02e3eb8d482d513f1870b36c523a8f39a1c67b94 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638236137; 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=2nh1SRx4AQlcnrAKNoCoxDgVNm8VnUVkB4f8tQTs+vI=; b=q5alA+imXfjJ+rbAl2jAbBuMZxBPnPm8WS5h2SWP40iupWtZEaeRuy0ZI4xiIK+jwSUZ4h vIe8odpme6513RreiCKr0oUZjyaA1myui/qWUrMCfdi/0G39elCdmFeA8x7qeHNtid2X1q 4CUoYNBdfg+EVip+iVE1w0Wo+vqQeKi0ymBY+4DXzB2GZIPnzvirrdgYY3bJxKdX7Z8UC0 EXSg5Gmb5mbn6snX3G2eN4Waf+XFuqZ2MMnDhxAVUU74JFxcJFNmEyNp7qxrYF8DUU8HCU hOXrVibksb88tO/HQYwX9K+YxAhwvSIHBeg3aZ/BXIyU9AhEKlQ+gTAaA0v6tg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638236137; a=rsa-sha256; cv=none; b=wLm8WYtEA9eDUewLpQ8Hs2eYlPhVsMH8FECXhj2bCedOkGyLhz2MTKZYuqet4wCIeKCi58 8Y+cjSgTx7x0jTKqPsy5HVgDKe8/FVvITninoTRNhatBchiUKFdkXF+sTDm9i8FNgYUGsU Zi5prP0BABwkUGd30G7KMqnHP54z+uJ0i/ttLeVMQHz3rgawyBqUW9RhsC3Mh6Wf+gqg0b zVn05sfvryGdQWI/Y3+3fWaTa2H12U+q24sP/PhaHxij55+VeAsyLduAxVt+EjY7mVmoRK OJxT2gvaZHYSWzFh1WxPRP46/CGez0rSg1nR+RDpvvJn6o7TLLBIKpOqaecdCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=02e3eb8d482d513f1870b36c523a8f39a1c67b94 commit 02e3eb8d482d513f1870b36c523a8f39a1c67b94 Author: Mark Johnston AuthorDate: 2021-11-16 18:31:04 +0000 Commit: Mark Johnston CommitDate: 2021-11-30 01:34:54 +0000 mbuf: Only allow extpg mbufs if the system has a direct map Some upcoming changes will modify software checksum routines like in_cksum() to operate using m_apply(), which uses the direct map to access packet data for unmapped mbufs. This approach of course does not work on platforms without a direct map, so we have to disallow the use of unmapped mbufs on such platforms. I believe this is the right tradeoff: we only configure KTLS on amd64 and arm64 today (and one KTLS consumer, NFS TLS, requires a direct map already), and the use of unmapped mbufs with plain sendfile is a recent optimization. If need be, m_apply() could be modified to create CPU-private mappings of extpg mbuf pages as a fallback. So, change mb_use_ext_pgs to be hard-wired to zero on systems without a direct map. Note that PMAP_HAS_DMAP is not a compile-time constant on some systems, so the default value of mb_use_ext_pgs has to be determined during boot. Reviewed by: jhb Discussed with: gallatin Sponsored by: The FreeBSD Foundation (cherry picked from commit fcaa890c4469118255d463495b4044eef484fa3e) --- sys/kern/kern_mbuf.c | 32 ++++++++++++++++++++++++++++++-- sys/rpc/rpcsec_tls/rpctls_impl.c | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c index 4e818d87a756..3a389e1f2fd3 100644 --- a/sys/kern/kern_mbuf.c +++ b/sys/kern/kern_mbuf.c @@ -116,9 +116,26 @@ int nmbjumbop; /* limits number of page size jumbo clusters */ int nmbjumbo9; /* limits number of 9k jumbo clusters */ int nmbjumbo16; /* limits number of 16k jumbo clusters */ -bool mb_use_ext_pgs = true; /* use M_EXTPG mbufs for sendfile & TLS */ -SYSCTL_BOOL(_kern_ipc, OID_AUTO, mb_use_ext_pgs, CTLFLAG_RWTUN, +bool mb_use_ext_pgs = false; /* use M_EXTPG mbufs for sendfile & TLS */ + +static int +sysctl_mb_use_ext_pgs(SYSCTL_HANDLER_ARGS) +{ + int error, extpg; + + extpg = mb_use_ext_pgs; + error = sysctl_handle_int(oidp, &extpg, 0, req); + if (error == 0 && req->newptr != NULL) { + if (extpg != 0 && !PMAP_HAS_DMAP) + error = EOPNOTSUPP; + else + mb_use_ext_pgs = extpg != 0; + } + return (error); +} +SYSCTL_PROC(_kern_ipc, OID_AUTO, mb_use_ext_pgs, CTLTYPE_INT | CTLFLAG_RW, &mb_use_ext_pgs, 0, + sysctl_mb_use_ext_pgs, "IU", "Use unmapped mbufs for sendfile(2) and TLS offload"); static quad_t maxmbufmem; /* overall real memory limit for all mbufs */ @@ -137,6 +154,7 @@ static void tunable_mbinit(void *dummy) { quad_t realmem; + int extpg; /* * The default limit for all mbuf related memory is 1/2 of all @@ -173,6 +191,16 @@ tunable_mbinit(void *dummy) if (nmbufs < nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) nmbufs = lmax(maxmbufmem / MSIZE / 5, nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16); + + /* + * Unmapped mbufs can only safely be used on platforms with a direct + * map. + */ + if (PMAP_HAS_DMAP) { + extpg = mb_use_ext_pgs; + TUNABLE_INT_FETCH("kern.ipc.mb_use_ext_pgs", &extpg); + mb_use_ext_pgs = extpg != 0; + } } SYSINIT(tunable_mbinit, SI_SUB_KMEM, SI_ORDER_MIDDLE, tunable_mbinit, NULL); diff --git a/sys/rpc/rpcsec_tls/rpctls_impl.c b/sys/rpc/rpcsec_tls/rpctls_impl.c index 110ba107540a..c495213b08e2 100644 --- a/sys/rpc/rpcsec_tls/rpctls_impl.c +++ b/sys/rpc/rpcsec_tls/rpctls_impl.c @@ -711,7 +711,7 @@ rpctls_getinfo(u_int *maxlenp, bool rpctlscd_run, bool rpctlssd_run) int error; size_t siz; - if (PMAP_HAS_DMAP == 0 || !mb_use_ext_pgs) + if (!mb_use_ext_pgs) return (false); siz = sizeof(enable); error = kernel_sysctlbyname(curthread, "kern.ipc.tls.enable",