From nobody Fri Nov 12 14:44:11 2021 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 CCDFB18474BD; Fri, 12 Nov 2021 14:44:11 +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 4HrLvH5S09z4Tbj; Fri, 12 Nov 2021 14:44:11 +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 9B712210F6; Fri, 12 Nov 2021 14:44:11 +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 1ACEiBPf093920; Fri, 12 Nov 2021 14:44:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ACEiB7q093919; Fri, 12 Nov 2021 14:44:11 GMT (envelope-from git) Date: Fri, 12 Nov 2021 14:44:11 GMT Message-Id: <202111121444.1ACEiB7q093919@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: 7e34088b7800 - stable/12 - LinuxKPI: add net_ratelimit() 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: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 7e34088b7800b39a42807c0fde1537bdcbb1cd62 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=7e34088b7800b39a42807c0fde1537bdcbb1cd62 commit 7e34088b7800b39a42807c0fde1537bdcbb1cd62 Author: Hans Petter Selasky AuthorDate: 2021-11-12 14:43:36 +0000 Commit: Hans Petter Selasky CommitDate: 2021-11-12 14:43:36 +0000 LinuxKPI: add net_ratelimit() Add a net_ratelimit() compat implementation based on ppsratecheck(). Add a sysctl to allow tuning of the number of messages. Sponsored-by: The FreeBSD Foundation Reviewed-by: hselasky Differential Revision: https://reviews.freebsd.org/D29399 (cherry picked from commit bc042266b2bfc3f52f685df7ccdd6e857b4b9da9) --- sys/compat/linuxkpi/common/include/linux/net.h | 10 ++++++++++ sys/compat/linuxkpi/common/src/linux_compat.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/net.h b/sys/compat/linuxkpi/common/include/linux/net.h index 282a45d2db32..5365cd0e9552 100644 --- a/sys/compat/linuxkpi/common/include/linux/net.h +++ b/sys/compat/linuxkpi/common/include/linux/net.h @@ -76,4 +76,14 @@ sock_release(struct socket *so) soclose(so); } + +int linuxkpi_net_ratelimit(void); + +static inline int +net_ratelimit(void) +{ + + return (linuxkpi_net_ratelimit()); +} + #endif /* _LINUX_NET_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 7175c0f87364..bb649e42ab8c 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -97,6 +98,12 @@ int linuxkpi_debug; SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug, CTLFLAG_RWTUN, &linuxkpi_debug, 0, "Set to enable pr_debug() prints. Clear to disable."); +static struct timeval lkpi_net_lastlog; +static int lkpi_net_curpps; +static int lkpi_net_maxpps = 99; +SYSCTL_INT(_compat_linuxkpi, OID_AUTO, net_ratelimit, CTLFLAG_RWTUN, + &lkpi_net_maxpps, 0, "Limit number of LinuxKPI net messages per second."); + MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat"); #include @@ -2514,6 +2521,14 @@ linux_dump_stack(void) #endif } +int +linuxkpi_net_ratelimit(void) +{ + + return (ppsratecheck(&lkpi_net_lastlog, &lkpi_net_curpps, + lkpi_net_maxpps)); +} + #if defined(__i386__) || defined(__amd64__) bool linux_cpu_has_clflush; #endif