Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14F33C61DB3 for ; Fri, 27 Jan 2023 16:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232385AbjA0Qxg (ORCPT ); Fri, 27 Jan 2023 11:53:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231382AbjA0Qxe (ORCPT ); Fri, 27 Jan 2023 11:53:34 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1589C761C6; Fri, 27 Jan 2023 08:53:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 81771CE0A36; Fri, 27 Jan 2023 16:52:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21A53C433D2; Fri, 27 Jan 2023 16:52:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674838358; bh=4PEOSgaSNZcRyv2+4Vf4N0LKGu/uE0t/eNTGrTjQCE8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tDh7dRFiEDjTkn4QUY9DLfEhv4hvKDWOhuQFr/co53t+6RPG8/mbbd5IK3vfgBt4u M15ZbDdGsTTvA/8kqxutPALB+tbijKfZqnH4ZLBndUu/BFDLGqFuw28pcR52cr1hyG MbjAq0l6vdbGGWV2GbQzFQRwGqw6NXabRaExO2g01wSKMkkrL4muK4RfzJI6rCAjG3 3Z8kQ4YNkKGSOx6j7VjdfP682dkniDgwBbYkhjFA1OhOGJ0qRssXq8m4B0h/uFgKa9 EPR2bCInKU59FsqGVXDYnl3T98HdVXsie8++FxlNWSZvS1Z0QiHmX5CMik5q8CPozA 5Q07DNmxQ4H8Q== Date: Fri, 27 Jan 2023 08:52:36 -0800 From: Josh Poimboeuf To: Peter Zijlstra Cc: Petr Mladek , Joe Lawrence , kvm@vger.kernel.org, "Michael S. Tsirkin" , netdev@vger.kernel.org, Jiri Kosina , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, "Seth Forshee (DigitalOcean)" , live-patching@vger.kernel.org, Miroslav Benes Subject: Re: [PATCH 0/2] vhost: improve livepatch switching for heavily loaded vhost worker kthreads Message-ID: <20230127165236.rjcp6jm6csdta6z3@treble> References: <20230120-vhost-klp-switching-v1-0-7c2b65519c43@kernel.org> <20230127044355.frggdswx424kd5dq@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 27, 2023 at 11:37:02AM +0100, Peter Zijlstra wrote: > On Thu, Jan 26, 2023 at 08:43:55PM -0800, Josh Poimboeuf wrote: > > Here's another idea, have we considered this? Have livepatch set > > TIF_NEED_RESCHED on all kthreads to force them into schedule(), and then > > have the scheduler call klp_try_switch_task() if TIF_PATCH_PENDING is > > set. > > > > Not sure how scheduler folks would feel about that ;-) Hmmmm, with preemption I guess the above doesn't work for kthreads calling cond_resched() instead of what vhost_worker() does (explicit need_resched/schedule). > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c > index f1b25ec581e0..06746095a724 100644 > --- a/kernel/livepatch/transition.c > +++ b/kernel/livepatch/transition.c > @@ -9,6 +9,7 @@ > > #include > #include > +#include > #include "core.h" > #include "patch.h" > #include "transition.h" > @@ -334,6 +335,16 @@ static bool klp_try_switch_task(struct task_struct *task) > return !ret; > } > > +static int __stop_try_switch(void *arg) > +{ > + return klp_try_switch_task(arg) ? 0 : -EBUSY; > +} > + > +static bool klp_try_switch_task_harder(struct task_struct *task) > +{ > + return !stop_one_cpu(task_cpu(task), __stop_try_switch, task); > +} > + > /* > * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set. > * Kthreads with TIF_PATCH_PENDING set are woken up. Doesn't work for PREEMPT+!ORC. Non-ORC reliable unwinders will detect preemption on the stack and automatically report unreliable. -- Josh