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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 9D8FFC4332F for ; Tue, 21 Sep 2021 17:43:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87826611ED for ; Tue, 21 Sep 2021 17:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbhIURpA (ORCPT ); Tue, 21 Sep 2021 13:45:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbhIURo7 (ORCPT ); Tue, 21 Sep 2021 13:44:59 -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 9B6F8C061574; Tue, 21 Sep 2021 10:43:30 -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=a2OzgtMmGpk6woPpOvOOcLPpmrGPO53fLZOixEExQ+g=; b=I5os7sMIFl2i1UmHdrajeHi+xW XBO+ZEeHOom+1PPrXwszjpQUos2Xo1bBktJ7J9wIemW/1cndJLEVJ42gtPV6bHSNdte43CCGb/kiW n9NUP+xXpfoax7cTGABhNvqvlP+QTeVjhx7lOS88wul5r5BV/PURM4ZLFGX8OiKjABWEyPew0xPYz FO2cnYum4z+o1FOMjtktnuc2mJq2kI4P25hcTRBWsID8yyZxPZuFTjfArxok1oZ0/+Egf3gC/vV3r qFr0It7LM56SV0FSgkCOPja53jcUaFu3zFvaUeNMZnvetFfWsU7OqnWIHHHopqxoAegc3HVMjmh2K B43mzaVg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mSjna-004o6w-5i; Tue, 21 Sep 2021 17:43:18 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BDB89300252; Tue, 21 Sep 2021 19:43:16 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A7DF720303903; Tue, 21 Sep 2021 19:43:16 +0200 (CEST) Date: Tue, 21 Sep 2021 19:43:16 +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: 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: live-patching@vger.kernel.org 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...