From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754089AbdKAPGY (ORCPT ); Wed, 1 Nov 2017 11:06:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:39490 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750848AbdKAPGX (ORCPT ); Wed, 1 Nov 2017 11:06:23 -0400 Date: Wed, 1 Nov 2017 16:06:19 +0100 (CET) From: Miroslav Benes To: jpoimboe@redhat.com, jeyu@kernel.org, jikos@kernel.org cc: pmladek@suse.com, lpechacek@suse.cz, pavel@ucw.cz, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Oleg Nesterov , Michael Ellerman , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andy Lutomirski , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: Re: [PATCH v3 1/2] livepatch: send a fake signal to all blocking tasks In-Reply-To: <20171031114853.841-2-mbenes@suse.cz> Message-ID: References: <20171031114853.841-1-mbenes@suse.cz> <20171031114853.841-2-mbenes@suse.cz> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +/* > + * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set. > + * Kthreads with TIF_PATCH_PENDING set are woken up. Only admin can request this > + * action currently. > + */ > +void klp_force_signals(void) > +{ > + struct task_struct *g, *task; > + > + pr_notice("signaling remaining tasks\n"); > + > + read_lock(&tasklist_lock); > + for_each_process_thread(g, task) { > + if (!klp_patch_pending(task)) > + continue; > + > + /* > + * There is a small race here. We could see TIF_PATCH_PENDING > + * set and decide to wake up a kthread or send a fake signal. > + * Meanwhile the task could migrate itself and the action > + * would be meaningless. It is not serious though. > + */ > + if (task->flags & PF_KTHREAD) { > + /* > + * Wake up a kthread which still has not been migrated. > + */ > + wake_up_process(task); So this is not as safe as one would hope. It tries to wake all TASK_NORMAL tasks, which could cause headaches. Let's make it wake_up_state(task, TASK_INTERRUPTIBLE); to wake only kthreads sleeping interruptedly. Thanks Petr for spotting this (offline). Miroslav > + } else { > + /* > + * Send fake signal to all non-kthread tasks which are > + * still not migrated. > + */ > + spin_lock_irq(&task->sighand->siglock); > + signal_wake_up(task, 0); > + spin_unlock_irq(&task->sighand->siglock); > + } > + } > + read_unlock(&tasklist_lock); > +}