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_CR_TRAILER, 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 BC98CC433EF for ; Mon, 20 Sep 2021 08:28:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A12F7610FB for ; Mon, 20 Sep 2021 08:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235727AbhITI30 (ORCPT ); Mon, 20 Sep 2021 04:29:26 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:53922 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231966AbhITI3Y (ORCPT ); Mon, 20 Sep 2021 04:29:24 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id A308220041; Mon, 20 Sep 2021 08:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1632126477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=z+DyQBE+Aw6OsR4ekUpN555NEMRZAU9u2xlWGbDULjw=; b=NG+to2HtxbQTOVZ92SXq71NNm3suX62MSSCS0DG8Dzkt2SOl0aaJWr7OFRj2xRRUWCLbRx qu2yQLCH3VZ8clBv4ql6+se/US9y9NQ3xKkE5B/xk0RLVYX4USkLMuy4fww6ZHUWKdcVxO BhNcXBbSJUgymBT6UNyb2loDiU+5cUA= Received: from suse.cz (unknown [10.100.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7F7CBA3B87; Mon, 20 Sep 2021 08:27:57 +0000 (UTC) Date: Mon, 20 Sep 2021 10:27:57 +0200 From: Petr Mladek To: Ingo Molnar , Peter Zijlstra , Josh Poimboeuf Cc: Vasily Gorbik , Jiri Kosina , Miroslav Benes , 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 2021-09-15 16:18:01, Vasily Gorbik wrote: > On an idle system with large amount of cpus it might happen that > klp_update_patch_state() is not reached in do_idle() for a long periods > of time. With debug messages enabled log is filled with: > [ 499.442643] livepatch: klp_try_switch_task: swapper/63:0 is running > > without any signs of progress. Ending up with "failed to complete > transition". > > On s390 LPAR with 128 cpus not a single transition is able to complete > and livepatch kselftests fail. Tests on idling x86 kvm instance with 128 > cpus demonstrate similar symptoms with and without CONFIG_NO_HZ. > > To deal with that, since runqueue is already locked in > klp_try_switch_task() identify idling cpus and trigger rescheduling > potentially waking them up and making sure idle tasks break out of > do_idle() inner loop and reach klp_update_patch_state(). This helps to > speed up transition time while avoiding unnecessary extra system load. > > Reviewed-by: Petr Mladek > Acked-by: Miroslav Benes > Signed-off-by: Vasily Gorbik > --- > Ingo/Peter, as Josh mentioned, could you please ack if you are ok with > livepatch calling this private scheduler interface? Ingo, Peter, Josh, could anyone please ack that it is acceptable to call resched_curr(rq) from the livepatch code? Or is there a better way to make an idle task go through the main cycle? Best Regards, Petr > > Changes since v1: > - added comments suggested by Petr > lkml.kernel.org/r/patch.git-a4aad6b1540d.your-ad-here.call-01631177886-ext-3083@work.hours > > Previous discussion and RFC PATCH: > lkml.kernel.org/r/patch.git-b76842ceb035.your-ad-here.call-01625661932-ext-1304@work.hours > > kernel/livepatch/transition.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > 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); > -- > 2.25.4