From nobody Sat Jul 30 21:40:52 2022 X-Original-To: dev-commits-src-main@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 4LwHr42szkz4Xng1; Sat, 30 Jul 2022 21:40:52 +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 4LwHr42S4zz44sj; Sat, 30 Jul 2022 21:40:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659217252; 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=eFMtciL/RGtBFpM++xzLe1ktImflzegqpiwmrti72hM=; b=ByUHWOBjK4XdHbCCKZsUhKGXGolBt5MX57d8Qd2BnLixkKTJvaPzrGqkF0Br8dRDHrMMSJ pdWR+acWWQTPVL3bEF+3R8zHiVeQ7oH1v4Z+Owv6w5pwKD1TyTvV/fkgL4yIlBuFxpmB5R 7p675GgjXf127ZGrLV5YbrXqesTErZI6PyuTtQWxPvZpsMo/2mlQ5q1FX54eGmJK7QIjMO TaS20/2M1jsZqP2P/lZ8vgRh8U3+lpVQIg97Uw5WsxidWY7wfN1DhgcDsYvTp+oBsxWjy5 pTzCVOLc6mWeptlN+JMyCLrX/dP1DCKCIHAy9SRkk/ep5w9hG8SYEs875aMzXg== 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 4LwHr41VkzzVhc; Sat, 30 Jul 2022 21:40:52 +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 26ULequ3030661; Sat, 30 Jul 2022 21:40:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26ULeqfO030660; Sat, 30 Jul 2022 21:40:52 GMT (envelope-from git) Date: Sat, 30 Jul 2022 21:40:52 GMT Message-Id: <202207302140.26ULeqfO030660@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4690e20eed17 - main - tools/uma/smrstress: fix kthread exit List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4690e20eed17a6e79a67a8d10874fdc67a1c4ccf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659217252; 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=eFMtciL/RGtBFpM++xzLe1ktImflzegqpiwmrti72hM=; b=oHZmosIHgq8TFlMhh6CV6kcMoGcYEApbVffnSaw2HyK7w2PjX7lMeLxvsGbo54wle8N1Yp lCaj6fx5cJpqOPByIrV8MhoVV5y2Jha/Few9gKO/dcOxZlnnMel26QIqExAsSttaXEhfX8 IMdbbUquDXdq6Fd/nFt9zDDs7n4WVek7dvlrAupW/NQ4TU+pV0F7GzPA85IqumwvDG4QNZ AlVEXU+UiYnBMbrq+UqyA1EPDEXpJ3menmQ3sY5KoTzv0fNGrYBfi3Iq7uuiMuV0G8v4XS gXlo7/g9wGeha/RFRXU8hWCR4pq/XMQtzx41XBLzJ+PaVrjx9YBkDJVSK/fD4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659217252; a=rsa-sha256; cv=none; b=B2T3TKVpfoJ1jDlVUrIw8sz+UV5Vei+bmNNqcr5ixkDSIX7UjlO1EnV+QWBvZl/sqfeIbg Nzv9ZEv6E7akeyCuUZULyatxfBEXIXBEa+A57weXCawkEh+o2w/dtZJb3pwKQDJSWUr4Ke 0fjq+U9zZIf+Bd8cf4C9tJgnfU6KTyygvMpniP3tUEU+A146w/DX8VMy2DNLyjG99jSAaH Nsi+qCKFKKdEuNn9n/868S2fQ1EmXsjyOqjNg1y05ilvaCKWB455i0/xeX7J2zlgOL6DrN HOlg95a6P06MRtKnVTHh3vaVWrXHH8Bg1fAelnRSLfCdhS3wqiOnywXWaO0L/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4690e20eed17a6e79a67a8d10874fdc67a1c4ccf commit 4690e20eed17a6e79a67a8d10874fdc67a1c4ccf Author: Konstantin Belousov AuthorDate: 2022-07-30 18:54:34 +0000 Commit: Konstantin Belousov CommitDate: 2022-07-30 21:40:12 +0000 tools/uma/smrstress: fix kthread exit By convention, kernel threads must call kthread_exit() instead of blindly returning from the thread function. We have some safety measure in fork_exit(), which checks for the P_KPROC p_flag and does kthread_exit() for kernel thread that forgot to do it itself. But this workaround only works for kernel threads belonging to the kernel process. If a kernel thread is attached to the normal process with live userspace, and does not call kthread_exit(), then the workaround is not activated, and for amd64 at least, the return from the thread function/fork_exit() results in the return to userspace with the copy of frame from the thread that did kthread_add(). Practically for smrstress, this destroys the user stack of the still active frame in the other thread, which was the caller of kthread_add(). Fix it by adding kthread_exit() to the thread function. Reported and tested by: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D35999 --- tools/uma/smrstress/smrstress.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/uma/smrstress/smrstress.c b/tools/uma/smrstress/smrstress.c index 7e7ee4ea065c..2cf5f50ffae4 100644 --- a/tools/uma/smrstress/smrstress.c +++ b/tools/uma/smrstress/smrstress.c @@ -123,6 +123,7 @@ smrs_thread(void *arg) else smrs_read(); atomic_add_int(&smrs_completed, 1); + kthread_exit(); } static void