From owner-svn-src-stable@freebsd.org Sat Jan 20 12:31:22 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E6D46ECEAAA; Sat, 20 Jan 2018 12:31:22 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C18287753F; Sat, 20 Jan 2018 12:31:22 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0F0561C680; Sat, 20 Jan 2018 12:31:22 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0KCVLXI097620; Sat, 20 Jan 2018 12:31:21 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0KCVLEI097619; Sat, 20 Jan 2018 12:31:21 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201801201231.w0KCVLEI097619@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 20 Jan 2018 12:31:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328193 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 328193 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jan 2018 12:31:23 -0000 Author: kib Date: Sat Jan 20 12:31:21 2018 New Revision: 328193 URL: https://svnweb.freebsd.org/changeset/base/328193 Log: MFC r327917: Add sysctl debug.kdb.stack_overflow. Modified: stable/11/sys/kern/subr_kdb.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/subr_kdb.c ============================================================================== --- stable/11/sys/kern/subr_kdb.c Sat Jan 20 12:19:02 2018 (r328192) +++ stable/11/sys/kern/subr_kdb.c Sat Jan 20 12:31:21 2018 (r328193) @@ -82,6 +82,7 @@ static int kdb_sysctl_enter(SYSCTL_HANDLER_ARGS); static int kdb_sysctl_panic(SYSCTL_HANDLER_ARGS); static int kdb_sysctl_trap(SYSCTL_HANDLER_ARGS); static int kdb_sysctl_trap_code(SYSCTL_HANDLER_ARGS); +static int kdb_sysctl_stack_overflow(SYSCTL_HANDLER_ARGS); static SYSCTL_NODE(_debug, OID_AUTO, kdb, CTLFLAG_RW, NULL, "KDB nodes"); @@ -107,6 +108,10 @@ SYSCTL_PROC(_debug_kdb, OID_AUTO, trap_code, CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, NULL, 0, kdb_sysctl_trap_code, "I", "set to cause a page fault via code access"); +SYSCTL_PROC(_debug_kdb, OID_AUTO, stack_overflow, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, NULL, 0, + kdb_sysctl_stack_overflow, "I", "set to cause a stack overflow"); + SYSCTL_INT(_debug_kdb, OID_AUTO, break_to_debugger, CTLFLAG_RWTUN | CTLFLAG_SECURE, &kdb_break_to_debugger, 0, "Enable break to debugger"); @@ -221,6 +226,36 @@ kdb_sysctl_trap_code(SYSCTL_HANDLER_ARGS) (*fp)(0x11111111, 0x22222222, 0x33333333); return (0); } + +static void kdb_stack_overflow(volatile int *x) __noinline; +static void +kdb_stack_overflow(volatile int *x) +{ + + if (*x > 10000000) + return; + kdb_stack_overflow(x); + *x += PCPU_GET(cpuid) / 1000000; +} + +static int +kdb_sysctl_stack_overflow(SYSCTL_HANDLER_ARGS) +{ + int error, i; + volatile int x; + + error = sysctl_wire_old_buffer(req, sizeof(int)); + if (error == 0) { + i = 0; + error = sysctl_handle_int(oidp, &i, 0, req); + } + if (error != 0 || req->newptr == NULL) + return (error); + x = 0; + kdb_stack_overflow(&x); + return (0); +} + void kdb_panic(const char *msg)