Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1815064pxb; Mon, 20 Sep 2021 06:04:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe5Z9bsGaLbEsh7ggueaxIFlLUHxn/bn2R4xDpIxu6AnIk1aM7ZYFv02AOKCTo9XICJf2c X-Received: by 2002:a05:651c:206:: with SMTP id y6mr7705942ljn.98.1632143087762; Mon, 20 Sep 2021 06:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632143087; cv=none; d=google.com; s=arc-20160816; b=WewH9Yo4r+YQn63b18cDoSPnhbY+pn47XmIi6i9TgyKbaslbrXBQMcuCRhDxeluDRk +L+CV4zV5ZMp1HhztrJkllJ2n/f4xnPfBgyJ62shrK01JXBruoa4voagQ+ar32+lZbDH VxDzShs9Tjakm9rhim986VJU87d+v/VmGr79G1GSGcZVZlz+/r3tNJSs0HBqSXDwGI6g vZkUepEUe1eNW3Hs8mQT5WjyrWTuHpGokkgsxxr8gAI1+GbfgfYfGtP9K9hMWdwj0G6c xGNVmbpC6+Kh2YXmJEu71RA2xVbjuZJbSwmEBJnmOnNOGJGhWrdh92bxMM+cOccVCmq2 8kTA== 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=z+DyQBE+Aw6OsR4ekUpN555NEMRZAU9u2xlWGbDULjw=; b=ZflAr/nAnCW5mP3hBcSOTtQ5sU1jFoOOJbgY1GLWm58c3gcKw+VmiX3klxR4xDiCSj seZ5bT8DILdFVMFvlIBbPqA4ffrDwWqHuqs35oaKu5Yoj1F+kgrFsa043JT5sOhNm9tj DDp/UUhwNzyw78ileCjKVucytFrJi6U7/nAhcIX0Sfm4P13gYIcuLsaJkK6k70wzwRvD rxtmqaOgqaC5ckfgNvWFhp+BVjbrOzueokuIbezoj749yKv9e330E+chnit1lkqBGJs6 tqxajnj2XlSirXRYxtke4TB6tv6MJm496tHmt6wistDeareiJK7Z4IyME9Bs7KP/HxQ+ EIXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=NG+to2Ht; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si14748154ejv.617.2021.09.20.06.04.19; Mon, 20 Sep 2021 06:04:47 -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=@suse.com header.s=susede1 header.b=NG+to2Ht; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235754AbhITI30 (ORCPT + 99 others); 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: linux-kernel@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