Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3708912imm; Mon, 25 Jun 2018 03:22:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLRIep/kzaUbX4KoRz+Sh3/3sxDCoJ1Yez8OlGHy530Q4U+w7OdYkdOGuCWzLkMILINsN2Z X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr12485221pfa.227.1529922157607; Mon, 25 Jun 2018 03:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529922157; cv=none; d=google.com; s=arc-20160816; b=K8rZpkpyLClQ8iTo8GqZ5ybfL9ShzxiCi5bxU0OyFfjwYRffVWb8lMLpnU9fO4Om06 D/TX4GCYK/A8IRq+POMopQxTLER4cQKhUdQwUGht9hPysMoBd1XTwGPRDV7bbpE063fn b1H+RosTHCG8S6JB8j/3/jM0ZTgXAjOphR7Ts1IsjTGB6qDc2e75psP8c9AcajHZAevX L65cwHDfZxih2mAP31ZyqS8tx6OQ4usGCX6Mx6+mBwiB47lN484bhf5iCpYubZ4eaKE6 QM2jh4/gFC1QeeYP+zyTC/REWxWl0SpQtZaD49wUnva8JCb3EAnlZSxv4deDCYDVSDpN YDvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=qMoNVMja4deEv5w5VhRFMvaJcv79vSnxCCgyAxOWTU8=; b=kBHOgFq0cGNqlF5ojvfrIYlYe+/q940XMxMD/XVP1byEW7pfXzggSj17k1ZMQspHWB bCwcM0W1GEJtYwnni+JnI0GgRlHczwvkPmZnALT2q1imtEHrxsQ4o6ZuxmnPMyXhQRa4 IIAg96T/5gYBF3qyc8bxfqOpf/Z+D0uLw11bA7oGjXSdwqjJ8AxxKRHYA7adnv7jcRPl Ou97dJix8j81QPH0+c5SpmizxfFWDvZfy8adtU6OjvOXNpecBbIXvrvRNKFJndb/vLUQ NdUm0Xob1ODYNrmK45uykJnH68EdLp1hqatvfsOE8yMLjZ9gu6TZtXE9uhY7/fgSxd1b Iwnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11-v6si11764860pgq.480.2018.06.25.03.22.23; Mon, 25 Jun 2018 03:22:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755231AbeFYKVO (ORCPT + 99 others); Mon, 25 Jun 2018 06:21:14 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:34101 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755044AbeFYKVM (ORCPT ); Mon, 25 Jun 2018 06:21:12 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXOcQ-0001jC-OH; Mon, 25 Jun 2018 12:21:10 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fXOcI-0007T2-79; Mon, 25 Jun 2018 12:21:02 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Oleg Nesterov , "Eric W . Biederman" , "Rafael J . Wysocki" , Andrew Morton , Gavin Schenk , kernel@pengutronix.de Subject: [PATCH] RFC: siox: don't create a thread without starting it Date: Mon, 25 Jun 2018 12:20:56 +0200 Message-Id: <20180625102056.28468-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On a machine with a siox device I see: [ 241.130465] INFO: task siox-0:626 blocked for more than 120 seconds. [ 241.136996] Not tainted 4.17.0-20180520-1-g6248d1b64190-dirty #8 [ 241.146831] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 241.154868] siox-0 D 0 626 2 0x00000000 [ 241.163241] [] (__schedule) from [] (schedule+0x58/0xc8) [ 241.172142] [] (schedule) from [] (kthread+0xc4/0x140) [ 241.180899] [] (kthread) from [] (ret_from_fork+0x14/0x34) [ 241.188315] Exception stack(0xc72a7fb0 to 0xc72a7ff8) [ 241.196327] 7fa0: 00000000 00000000 00000000 00000000 [ 241.204721] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 241.215861] 7fe0: 00000000 00000000 00000000 00000000 00000013 00000000 when I just boot without any other siox-related action. So the kthread (created in drivers/siox/siox-core.c:siox_master_register()) is never started. While you could argue that there is little reason to not start the thread there also is little reason to actually do it. peterz in #kernelnewbies said "[...] kernel/kthread.c:kthread() should really be using __set_current_state(TASK_IDLE), I suppose". This however seems to interfere with problems fixed in a076e4bca2fd ("freezer: fix kthread_create vs freezer theoretical race"). So I wonder where the real problem is and how it can be fixed. Explicitly-not-signed-off-for-discussion-by: Uwe Kleine-König --- drivers/siox/siox-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/siox/siox-core.c b/drivers/siox/siox-core.c index 16590dfaafa4..cef307c0399c 100644 --- a/drivers/siox/siox-core.c +++ b/drivers/siox/siox-core.c @@ -715,17 +715,17 @@ int siox_master_register(struct siox_master *smaster) dev_set_name(&smaster->dev, "siox-%d", smaster->busno); + mutex_init(&smaster->lock); + INIT_LIST_HEAD(&smaster->devices); + smaster->last_poll = jiffies; - smaster->poll_thread = kthread_create(siox_poll_thread, smaster, - "siox-%d", smaster->busno); + smaster->poll_thread = kthread_run(siox_poll_thread, smaster, + "siox-%d", smaster->busno); if (IS_ERR(smaster->poll_thread)) { smaster->active = 0; return PTR_ERR(smaster->poll_thread); } - mutex_init(&smaster->lock); - INIT_LIST_HEAD(&smaster->devices); - ret = device_add(&smaster->dev); if (ret) kthread_stop(smaster->poll_thread); -- 2.17.1