From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50D8AC433FE for ; Tue, 21 Sep 2021 21:17:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30ED560F70 for ; Tue, 21 Sep 2021 21:17:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234951AbhIUVSv (ORCPT ); Tue, 21 Sep 2021 17:18:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbhIUVSu (ORCPT ); Tue, 21 Sep 2021 17:18:50 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C765C061574; Tue, 21 Sep 2021 14:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=yQhIdAmJSx1dqatvz04cwJ8WL0F8XAnlHKdZajRA/10=; b=Gz9vzl3E2I3wt8s0h/gmPx6eF9 p5f9S7hhdmgnbrXBl60RIwmbYJGDvn/XX1w+vtXYRotqkhi358I4j1N6v2aqoUt7il+RO7byT9kAC Az/TZ/XjaKXKPYoymV6XrzIsqJ9EMTTJn3b8B1wi0voyn0GZ7x8oTO1MCoGxxa3iihCZyThA6wEiQ rscJkoYyKPIAtiI4ZHTaU6T0nCdtrX1oDvdTXiGh2albn9lMBx1ZpWiCa6tdFhBBFDG/dA+qImJhv /FT90lXYAJy2wz7bKbo5vmdeQakDqs0OOv0B9xVWjYOCy2thr5eJ7Kpk7fVLKySmmsAJrLVoPW4sB 0C2Rmc0A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mSn8Y-004qO5-Nh; Tue, 21 Sep 2021 21:17:10 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 31856981483; Tue, 21 Sep 2021 23:17:09 +0200 (CEST) Date: Tue, 21 Sep 2021 23:17:09 +0200 From: Peter Zijlstra To: Vasily Gorbik Cc: Ingo Molnar , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Frederic Weisbecker , Thomas Gleixner , Heiko Carstens , Sven Schnelle , Sumanth Korikkar , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] livepatch: Fix idle cpu's tasks transition Message-ID: <20210921211709.GE5106@worktop.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 21, 2021 at 07:43:16PM +0200, Peter Zijlstra wrote: > On Wed, Sep 15, 2021 at 04:18:01PM +0200, Vasily Gorbik wrote: > > > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c > > index 291b857a6e20..2846a879f2dc 100644 > > --- a/kernel/livepatch/transition.c > > +++ b/kernel/livepatch/transition.c > > @@ -278,6 +278,8 @@ static int klp_check_stack(struct task_struct *task, char *err_buf) > > * Try to safely switch a task to the target patch state. If it's currently > > * running, or it's sleeping on a to-be-patched or to-be-unpatched function, or > > * if the stack is unreliable, return false. > > + * > > + * Idle tasks are switched in the main loop when running. > > */ > > static bool klp_try_switch_task(struct task_struct *task) > > { > > @@ -308,6 +310,12 @@ static bool klp_try_switch_task(struct task_struct *task) > > rq = task_rq_lock(task, &flags); > > > > if (task_running(rq, task) && task != current) { > > + /* > > + * Idle task might stay running for a long time. Switch them > > + * in the main loop. > > + */ > > + if (is_idle_task(task)) > > + resched_curr(rq); > > snprintf(err_buf, STACK_ERR_BUF_SIZE, > > "%s: %s:%d is running\n", __func__, task->comm, > > task->pid); > > So 'recently' we grew try_invoke_on_locked_down_task() (yes, that's a > crap name), and I'm thinking this code is very similar to that. So > perhaps we re-use that. > > Perhaps have func() > 0 imply resched. > > I'll have a play... https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=sched/livepatch I'll write proper changelogs and post tomorrow,... (and fix robot fail, if any). (also, notes to later self: - task_try_func() might need to re-check on_rq after acquiring rq_lock - klp_send_signal() might want wake_up_process()/TASK_NORMAL due to TASK_IDLE )