Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2939571pxb; Tue, 21 Sep 2021 10:45:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCQYct9HpRN82CFHWlYa16Gc4S/3PkIrZnd6WbPe9gJGfdl5g1p6q1iVpDIhuN/TFiQ9Nh X-Received: by 2002:a05:6638:61c:: with SMTP id g28mr1074871jar.117.1632246311295; Tue, 21 Sep 2021 10:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632246311; cv=none; d=google.com; s=arc-20160816; b=TjD2e5dC9P4V8NdBBAMwEZIyY6flezU8rqJGafChAx73JBNOZJhYo0253OAqd7IEY/ bZXOQu6Bi3dHCBP4uZI4aIgea2OQJNPWpOxjYu9OjiU6WpGZmh7NO8SDx1F296v9R20M 4HxD9Eq4vnO44Hxsz8pIxctBmk4IiJzJU+UCwl/mRjpcxzQ+ThRWNCIR0Y996WkpNdaX 5Jih3sEavUcN4dCEc8P5C4SaC53YvQbR/aiT3tSOlRC1xGXV0I4AyIXhe8Mbap8i7R4h goRHkxXCiT6mttglzr/6y8YSTY6VNfXXUp59zxuZ/TtkndqTMxQXcckMdKQm2Raa1/05 sn+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=a2OzgtMmGpk6woPpOvOOcLPpmrGPO53fLZOixEExQ+g=; b=yX4nq49rjYfoH/AdgnKWooKQiXOzvGUYswoXhTKXeUx2+r8+IDOxT3ti2PxzplOY+H kL0MQw4rvXmetdYI/JM2oGh61mgX8zvqBthvxwA7jbqT2qG2FsEa+5JSXY2OdJppQCts asNHg+awWGeqxUAI4YRCgovOeopg28C8EIOHVatfs4aKI5M2L54F9sKSm/l8euTOsKlw EeVqXQN4rxjjXqKwbX1wPMz/y9Y6XTSvkOTO/OBUeCIYq7FxA6kew9OQiAbFnziNosZ7 vQm+//C1s4q2u6dLX20wPIGbpEZ6YVoR0iBgPcRZE8QXPEUJewEjeinzd4aN7k55joHl h9oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=I5os7sMI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si6852958ila.152.2021.09.21.10.44.52; Tue, 21 Sep 2021 10:45:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=I5os7sMI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230425AbhIURpA (ORCPT + 99 others); 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: linux-kernel@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...