Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759373AbcJYPSS (ORCPT ); Tue, 25 Oct 2016 11:18:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60288 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759329AbcJYPSO (ORCPT ); Tue, 25 Oct 2016 11:18:14 -0400 Date: Tue, 25 Oct 2016 17:16:40 +0200 From: Oleg Nesterov To: Roman Pen Cc: Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Tejun Heo , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] kthread: fix possible infinite wait for parking when kthread exits meanwhile Message-ID: <20161025151639.GE4326@redhat.com> References: <20161025110525.9100-1-roman.penyaev@profitbricks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161025110525.9100-1-roman.penyaev@profitbricks.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 25 Oct 2016 15:18:14 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1178 Lines: 44 Well. I was going to ignore this patch, I will leave this to Thomas anyway... But can't resist, because I have to admit I dislike this one too ;) On 10/25, Roman Pen wrote: > > int kthread_park(struct task_struct *k) > { > - struct kthread *kthread = to_live_kthread_and_get(k); > + struct kthread *kthread; > int ret = -ENOSYS; > > - if (kthread) { > - if (!test_bit(KTHREAD_IS_PARKED, &kthread->flags)) { > + /* > + * Here we try to be careful and handle the case, when kthread > + * is going to die and will never park. But why? IMO we should not complicate this code for the case when the kernel thread crashes. > + do { > + kthread = to_live_kthread_and_get(k); > + if (!kthread) > + break; > + if (!__kthread_isparked(kthread)) { > set_bit(KTHREAD_SHOULD_PARK, &kthread->flags); > if (k != current) { > wake_up_process(k); > wait_for_completion(&kthread->parked); > } > } > + if (k == current || __kthread_isparked(kthread)) > + /* The way out */ > + ret = 0; And why do we need to restart if __kthread_isparked() is false? In this case we know that we were woken up by the exiting kthread which won't park anyway. Oleg.