Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4256041imm; Mon, 25 Jun 2018 12:23:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKICSzIp0kP0O6sgXr0pHG5gwLyk0aLq8eoqBeCXHhFw0xrOT4Esfm3J2mpN5dG4Q7RwfZak X-Received: by 2002:a62:3481:: with SMTP id b123-v6mr3584882pfa.4.1529954618602; Mon, 25 Jun 2018 12:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529954618; cv=none; d=google.com; s=arc-20160816; b=o0H/yN/3SO2Gt85AWYa7CI987JGIce7nLNkp2/qmk4OjHrhW+y0JVj2gnAr97t0gSL Xr1HkqIWJrqs2eEb/rgap8NPO2epZSGcsfonA7QMsCqzualX5c5d/RtXTDOq0r6IbX8n vn1YGtpPdOt2JOlojIAGfZDn9b8BvRLhdSDNIBGYlUWS6EQlIFP+p1Ag29oERpO1fbj+ /F/Ia+VV0H609hCYqByG7qerT4tp3FvmDed1Q87lWxAfylH6TxG8/YszDlGmr3iE0TSN g9qk0ZGe8jDJRE4qXycGWG5Bn4Tls4HCHsaT3aeYEyYQ6e+RnJzycTZM8ypc919MniOg 4IqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=41N/qSwtLBZWwpDDWtqU3f5wzy+ghzGHpaLiZD4ogGA=; b=ZrCmrSAo9le6GIvvBhMQNeuirH6VbXK7VSXgJ22rIAC9zjNdBQhRYuGu0AGuHn5zjl tehLRhn7jIqaxvNnSYH+qp45MwSvtOQrSo8AYUVSsautbD6EvWdMJKmgtYN9TaAIwRuv 1jliFaNZ7Fmlx5s0aNLd4aoziI6waCn6IoE44TsMyLcSdl8FZzLAv29bdgTuE5NfhQ55 fZcJUxl2tvt3i397hQY5W2v71ExO/Qm1KE3qUDdOSTj+6eqkZpzG4n2CdYzskbqxSiDB 7qUX+YNwAxjrqPJHR8p9xyFm34yerdU8mhx8bpdnwJIsZGI2Dwd25HeJ4vm8csuCbpYe Xz4Q== 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 o11-v6si12280657pgq.506.2018.06.25.12.23.23; Mon, 25 Jun 2018 12:23:38 -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 S935026AbeFYTV1 (ORCPT + 99 others); Mon, 25 Jun 2018 15:21:27 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:39301 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934943AbeFYTV0 (ORCPT ); Mon, 25 Jun 2018 15:21:26 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXX3E-0005Eh-ND; Mon, 25 Jun 2018 21:21:24 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fXX3B-0003ou-Lk; Mon, 25 Jun 2018 21:21:21 +0200 Date: Mon, 25 Jun 2018 21:21:21 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Oleg Nesterov , "Eric W . Biederman" , "Rafael J . Wysocki" , Andrew Morton , Gavin Schenk , kernel@pengutronix.de Subject: Re: [PATCH] RFC: siox: don't create a thread without starting it Message-ID: <20180625192121.k3hx32xbbhqkyfu4@pengutronix.de> References: <20180625102056.28468-1-u.kleine-koenig@pengutronix.de> <20180625125105.GZ2494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180625125105.GZ2494@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 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 Hello Peter, On Mon, Jun 25, 2018 at 02:51:05PM +0200, Peter Zijlstra wrote: > On Mon, Jun 25, 2018 at 12:20:56PM +0200, Uwe Kleine-K?nig wrote: > > 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. > > Well, you really _should_ wake up the thread. That first wakeup really > is part of the whole 'create/setup' kthread pattern. ok > > 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"). > > I don't think so, that patch has an issue with INTERRUPTIBLE, but IDLE > very much doesn't allow signals like INTERRUPTIBLE does. I don't think I can provide a good commit log for s/TASK_UNINTERRUPTIBLE/TASK_IDLE/ in kernel/kthread.c:kthread(). But I can confirm that this patch makes the warning go away, so if you want to address this, you can add my Tested-by:. > > So I wonder where the real problem is and how it can be fixed. > > Without the first wakeup, the kthread will not run the provided function > and we can therefore argue the creation is incomplete. I really feel you > should just wake the thing up to land in your own wait-condition-loop. > > That said, irrespective of the whole UNINTERRUPTIBLE/IDLE thing, I find > this construct fairly fragile. We rely on not getting any spurious > wakeups without a 'special' state. Well, if the thread is woken up unintentionally nothing happens (apart from the lock and the list that I moved in my patch that might not be initialized yet; this should be fixed for sure). It just enters the thread's own wait-condition-loop. So you could argue that the wakeup call is just overhead that isn't necessary until the thread is really needed. (I won't argue, I can accept your opinion and do the wakeup.) > The only reason this doesn't normally happen is because it's a new > task, but since it is already hashed, it might well be possible to > trick someone into sending a wakeup. Is this an ack for the RFC patch you replied to? Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |