Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp54712pxb; Tue, 21 Sep 2021 18:35:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwikrUa/YjTXFlHlVgOA+g0cwxS2+JyKCx1euK8Wd968TrWbRHk8TTFJ482rtpFL/JSbylI X-Received: by 2002:a92:cdad:: with SMTP id g13mr13717704ild.103.1632274510383; Tue, 21 Sep 2021 18:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632274510; cv=none; d=google.com; s=arc-20160816; b=Fp2x4UDVtBMBsOGm51RSUfgsZpT4/QzdEpexUZkqPuTFtKv+lfLYy9iVt0Lqy/KUMC eKJIwH0+ick/vR7VNYt7gmGOfD04RNVY2AB/4Piw5os5CDuUwmi1CtflJgtQZo7bStSb mlPvtk1/wbbb4pQzDvDtoFA6ULMTX7SFGW3luH3PlFHF8bNDZulGOjQ5YROGVlLGAE6G oRXVdhN9IODOLZEvf5m/9qJKwIbaELYztVETzWf6/OZLi9/pjUIXBqfU0+xEPNnX8Y/C O/DxZnCFioznqO5TXDoTxGWiqnaMTX2tPBeShR8n6DaCnc/jjKDMd06+/D4nhOdDyvkK XM4g== 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=yQhIdAmJSx1dqatvz04cwJ8WL0F8XAnlHKdZajRA/10=; b=B32JyG0TIbPTvRDPY5Gvz6yspbOqLUyO3X5/bmiKLSDCJcxYe0CjGypqErydnNpwtE u7c8W3EgR0x2+F/OrbRvyFnVc9q9+nXZE9qnIanM6XotpXWSjmUlC8/WKX0SJMmOQwld U5+7jqXFrZ0MvdkSzx1lHhmokfn23QbF7OWkUS8VCR645dynje5dDCCSjyeVZiwYIdkX hi98/Arl8Kx5cL7qO+aeyxF4DM9B3RHfmxDlueYLWDYTPo/9uhjNTf4qH1kB1biaNyEE qFr9DgNk0GXBuyIj+/5JxBSVLuvoow1HVBwMEUsZsNc5BbQicb4HqAYsRyjxhdwliUTl 5h5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Gz9vzl3E; 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 ay23si1032405iob.33.2021.09.21.18.34.55; Tue, 21 Sep 2021 18:35:10 -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=Gz9vzl3E; 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 S231297AbhIUVSu (ORCPT + 99 others); Tue, 21 Sep 2021 17:18:50 -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 )