Message ID | 20240209070935.1529844-1-kent.overstreet@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-59059-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp676972dyd; Thu, 8 Feb 2024 23:10:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDeDaPFCgkmG0H3/j+DDrhIA5DT9nDU84Q9QOk86zxtp4TZZpItcescxuB9DEDdM5nYoE4 X-Received: by 2002:a05:622a:120e:b0:42a:62e5:7733 with SMTP id y14-20020a05622a120e00b0042a62e57733mr969224qtx.23.1707462619523; Thu, 08 Feb 2024 23:10:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707462619; cv=pass; d=google.com; s=arc-20160816; b=k6Lv0PPd9RHwQx/dKYdFK1Gfu9rLIBAf7sp3ZyScnisaL3aZOYOIlGjLk69nLnXLkh Xd7SZOkzINeQrYPP9RzzV43g0ZUiCCdypvh8H5h4f0OCg8tBxpGUo9V0hJRZ1QhJXmIB H7e7cfHcNwc3nqkz3pBCiBPp6CptPKYG03BoJtXxGHS+RcfrctxjhMPkHP0c26/5L7E+ 6ycnMWGm7Uc/mSivrEViLVsg1aGcMW7LWGhrhOXXEZKVpaCA4R304mzNaBF+wuYmdhxb 1nhEJj+cLhtuGButCPLJYK30wUazhJgq4D/SJLs4dxgHJCIyXmsMdLjuycGQGhpKOVlR Qt0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=qSzX0INNFk+/IxT9nO7GVCJEW9cvWtprz6XblZoooLc=; fh=xdYNlCcZKIo7ijM37FxcJ6ax4ra8kkJ3mXn4Me2Cxlg=; b=xTvwP64QXUxt8DbYkm9ioyuTbAGLCs9rTRaYsjUpl2ZKbdF4m1YjKJg3CG7W+1ycuc FsAYuL48Nmf2dWBZOXcIAf5vZFchBNk/NbazCe0VPW3BIHea98cMZl0S4o/timvPfV+a 3MoH/gJXVPaGog+X4Kg7oEFcag+nEzOKElsDBlMZf7w+vSUuxm9mCbQOklLE9eEdgWj9 LlOtvcYCJyN6v6tGEsEI/NN0pvvPR6W10QdQCjNW9Y8cPPmFiLUiW0FdqAPlglG99JlL PSAvWEwdX94uzBer0hcQSZvY6BnxMQBpCghsQfs2XwtA7lu3ac9oTBBwB0oGi6uB9Foc hDxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ip52rqeC; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-59059-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59059-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCXfnxXl6tRzU6m9QmMY3gamZxlaSoIE9B/sf7+ef2p7V6J1TzFV3kg/abztG06tDKPJH6QefmICS0HUfsGgDllFykNc0g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j6-20020a05622a038600b0042c2d914903si1261395qtx.760.2024.02.08.23.10.19 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 23:10:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59059-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ip52rqeC; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-59059-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59059-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 50B021C23496 for <ouuuleilei@gmail.com>; Fri, 9 Feb 2024 07:10:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE1C465BA9; Fri, 9 Feb 2024 07:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ip52rqeC" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A45A657AB for <linux-kernel@vger.kernel.org>; Fri, 9 Feb 2024 07:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707462589; cv=none; b=VtZbpjL/bUnnTzOVB/wAQNn0uaer1mL/md3QOyYOhDjQckNH50RM9jwMBF1bnjoqCnQcrkWi72zJduAovJaYSV7+FdfgkfQuNstosF9LEU8qybXkzrUW9y1JLvac/RPj75eAXk26TeuuadKXMIrDlJEax2euKA49z2wJXvSMF/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707462589; c=relaxed/simple; bh=Q0X0MIWz596nOjuI5ehDFAtn9dxEZXwNG9nSazvV+8M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q6NuWHms3jys0FwfRz6HUcVoadSgGiP/m4mHWDe0x71uxrBLSWsGLDYVexdeVzsSxSG/Dgh5OS3V1W59oCrLtaKuMGJpj8EuYbD1z+eeyg0Ds/ZstVrRjQa1ZYPzvBt0RloE7ZYMEpyQCOMnnmxPbYfvhvJ69KNXMRI1PMTCrW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ip52rqeC; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707462584; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qSzX0INNFk+/IxT9nO7GVCJEW9cvWtprz6XblZoooLc=; b=ip52rqeCrIJZxKh6s7RJRBbmN7fgi4TPA8gqxpCTIVWuTcq2nNJxuKbMCi34EgGsqahVnv nk8vdgSf0KQ6jpJVYus7wl/iuoM631shzW46cHa5skCvSMC4Tsz9p4QnZsFeu9iRE/cBwq 2bBPPq9AUUptfj4cFywDxPjlLpd1QRg= From: Kent Overstreet <kent.overstreet@linux.dev> To: linux-kernel@vger.kernel.org Cc: Kent Overstreet <kent.overstreet@linux.dev>, Andrew Morton <akpm@linux-foundation.org>, fuyuanli <fuyuanli@didiglobal.com> Subject: [PATCH] kernel/hung_task.c: export sysctl_hung_task_timeout_secs Date: Fri, 9 Feb 2024 02:09:35 -0500 Message-ID: <20240209070935.1529844-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790404323530079068 X-GMAIL-MSGID: 1790404323530079068 |
Series |
kernel/hung_task.c: export sysctl_hung_task_timeout_secs
|
|
Commit Message
Kent Overstreet
Feb. 9, 2024, 7:09 a.m. UTC
needed for thread_with_file; also rare but not unheard of to need this
in module code, when blocking on user input.
one workaround used by some code is wait_event_interruptible() - but
that can be buggy if the outer context isn't expecting unwinding.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: fuyuanli <fuyuanli@didiglobal.com>
---
kernel/hung_task.c | 1 +
1 file changed, 1 insertion(+)
Comments
On Fri, 9 Feb 2024 02:09:35 -0500 Kent Overstreet <kent.overstreet@linux.dev> wrote: > needed for thread_with_file; also rare but not unheard of to need this > in module code, when blocking on user input. I see no bcachefs code in linux-next which uses this. All I have to go with is the above explanation-free assertion. IOW this patch is unreviewable. > one workaround used by some code is wait_event_interruptible() examples? > - but that can be buggy if the outer context isn't expecting unwinding. More explanation of this? > --- a/kernel/hung_task.c > +++ b/kernel/hung_task.c > @@ -43,6 +43,7 @@ static int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; > * Zero means infinite timeout - no checking done: > */ > unsigned long __read_mostly sysctl_hung_task_timeout_secs = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT; > +EXPORT_SYMBOL_GPL(sysctl_hung_task_timeout_secs); It seems strange that a module wouild want this. Makes one wonder what the heck is going on in there.
On Fri, Feb 09, 2024 at 02:13:24PM -0800, Andrew Morton wrote: > On Fri, 9 Feb 2024 02:09:35 -0500 Kent Overstreet <kent.overstreet@linux.dev> wrote: > > > needed for thread_with_file; also rare but not unheard of to need this > > in module code, when blocking on user input. > > I see no bcachefs code in linux-next which uses this. All I have to go > with is the above explanation-free assertion. IOW this patch is > unreviewable. > > > one workaround used by some code is wait_event_interruptible() > > examples? fs/bcachefs/util.h kthread_wait_event(); we use that - among other things - when the kthread is parked waiting for userspace to flip it on. TASK_INTERRUPTIBLE was the suggestion I got years ago, but I want to get away from it because - > > > - but that can be buggy if the outer context isn't expecting unwinding. > > More explanation of this? We're starting to think about this a bit more because of David Howell's proposal; the idea is that perhaps TASK_UNINTERRUPTIBLE vs. TASK_INTERURPTIBLE vs. TASK_KILLABLE should probably not be set at the waiting context, it should be set at the outer context where we would handle (or not handle) -ERESTARTSYS. think mutex_lock() vs. mutex_lock_killable(); that is bubbling up the context specification in an ad hoc way. This would regularize that. I've also seen bugs where code was doing a fixed TASK_INTERRUPTIBLE and the outer context wasn't expecting that - kthread creation does this. > > > --- a/kernel/hung_task.c > > +++ b/kernel/hung_task.c > > @@ -43,6 +43,7 @@ static int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; > > * Zero means infinite timeout - no checking done: > > */ > > unsigned long __read_mostly sysctl_hung_task_timeout_secs = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT; > > +EXPORT_SYMBOL_GPL(sysctl_hung_task_timeout_secs); > > It seems strange that a module wouild want this. Makes one wonder what > the heck is going on in there. specifically, this is for thread_with_file, where we've got a kthread hooked up to a file descriptor, effectively using it as both stdin and stdout. When the kthread reads from the fd, that can block for an unbounded amount of time - we're waiting on userspace input and it's totally fine.
On Fri, Feb 09, 2024 at 02:09:35AM -0500, Kent Overstreet wrote: > needed for thread_with_file; also rare but not unheard of to need this > in module code, when blocking on user input. > > one workaround used by some code is wait_event_interruptible() - but > that can be buggy if the outer context isn't expecting unwinding. I don't think just exporting the variable ad thus allowing write access is a good idea. If we want to keep going down the route of this hack we should add an accessor function that returns the value. The cleaner solution would be a new task state that explicitly marks code than can sleep forever without triggerring the hang check. Although this might be a bit invaѕive and take a while.
On Wed, 14 Feb 2024 21:26:34 -0800 Christoph Hellwig <hch@infradead.org> wrote: > On Fri, Feb 09, 2024 at 02:09:35AM -0500, Kent Overstreet wrote: > > needed for thread_with_file; also rare but not unheard of to need this > > in module code, when blocking on user input. > > > > one workaround used by some code is wait_event_interruptible() - but > > that can be buggy if the outer context isn't expecting unwinding. > > I don't think just exporting the variable ad thus allowing write > access is a good idea. If we want to keep going down the route of > this hack we should add an accessor function that returns the value. > > The cleaner solution would be a new task state that explicitly > marks code than can sleep forever without triggerring the hang > check. Although this might be a bit invaѕive and take a while. A new PF_whatever flag would solve that simply? Which are the potential use sites for such a thing?
On Thu, Feb 15, 2024 at 10:55:09AM -0800, Andrew Morton wrote: > On Wed, 14 Feb 2024 21:26:34 -0800 Christoph Hellwig <hch@infradead.org> wrote: > > > On Fri, Feb 09, 2024 at 02:09:35AM -0500, Kent Overstreet wrote: > > > needed for thread_with_file; also rare but not unheard of to need this > > > in module code, when blocking on user input. > > > > > > one workaround used by some code is wait_event_interruptible() - but > > > that can be buggy if the outer context isn't expecting unwinding. > > > > I don't think just exporting the variable ad thus allowing write > > access is a good idea. If we want to keep going down the route of > > this hack we should add an accessor function that returns the value. > > > > The cleaner solution would be a new task state that explicitly > > marks code than can sleep forever without triggerring the hang > > check. Although this might be a bit invaѕive and take a while. I had the same thought. > A new PF_whatever flag would solve that simply? TASK_* flags are separate from PF_* flags, fortunately, and it doesn't look like anything but TASK_* flags go in task_struct->__state, so this shouldn't be a difficult change. > Which are the potential use sites for such a thing? There's a few places in the block layer that are using the sysctl value; those will be easy to fix. There's definitely more places abusing TASK_INTERRUPTIBLE, but aside from the ones in my code I can't think of a way to search for them. But the block layer ones look a little suspect to me: the commit message indicates they were added becasue discards on some devices can take > 100 seconds - which is true, but this is a more general problem, there's other places we block on IO. Might want to give this some more thought.
On Thu, Feb 15, 2024 at 06:26:59PM -0500, Kent Overstreet wrote: > There's a few places in the block layer that are using the sysctl value; > those will be easy to fix. There's definitely more places abusing > TASK_INTERRUPTIBLE, but aside from the ones in my code I can't think of > a way to search for them. I think any kthread that is woken using wake_up_process or a wait queue is a good candidate.
diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 9a24574988d2..b2fc2727d654 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -43,6 +43,7 @@ static int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; * Zero means infinite timeout - no checking done: */ unsigned long __read_mostly sysctl_hung_task_timeout_secs = CONFIG_DEFAULT_HUNG_TASK_TIMEOUT; +EXPORT_SYMBOL_GPL(sysctl_hung_task_timeout_secs); /* * Zero (default value) means use sysctl_hung_task_timeout_secs: