Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5123083iob; Mon, 9 May 2022 09:04:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdCrHLokp5jPWc0gBwyvmrSvgT0U7z9uc4cvZtMZfei0P1dZMAgbm5n5YRVny9c8oX5PmL X-Received: by 2002:a81:e24c:0:b0:2eb:4513:3793 with SMTP id z12-20020a81e24c000000b002eb45133793mr14919009ywl.204.1652112285197; Mon, 09 May 2022 09:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652112285; cv=none; d=google.com; s=arc-20160816; b=KEz6A/8MzEkCko9hVqAzQjjmOv3CNvSMrXXgJXpd1GE/K0ByEFMftDCItAECi5S3mm F+jV+CPLsDuUwk/+g+6nnIB3wouBGg7Y5KBFNkliyXf6qSHbHRcbDEoodFKH1Aa4hDjK KjefXleWcy6h69/jqUuUpFWoY88/Gjuj8wOU+ni+jf5HArASMvSYzlAX+4zF3TUNNOXU yxjxS8/BkPoZA5918gmWlBc2NUs0pwkKyOW/JIrWnLB6yv1YKhwhpB14UeY94PWJ+vGg TTl6k59Tnz49CouDj1LLOR0vCrHFx+2j74626zF8fRaN40MN89Bvu5wymn/ifThmH51N pJCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=Y0/VBrFqKnAWk7brpNaoE5FKOKpsXKfW3zfpFf4yiYI=; b=ZbUaZ0oLTZz4d8YCCYUziIQveTW8BbcXMIV3d1zLNq5tGm1q1nEPaoO4aRg8mnK4qS UEgNkfKXLpPuPXdL5x9muXtllggs6hXiCgAd59B5dawgqfOiMwtgcoZP+0JCeZqH2DRb XjdlxzphN/Oo1wU6kdz4hbxo5oVrjHvtgiqMtcAFTvcvwLLyq5VefXbeHxuGjrv5+nQr dbJmy/qBBYOjA4dMIB2rg89KOXfKrKnjw/V72WW1gEVdB28AjYVAPhlKG2rkH593t/e3 +t1phtIw0wC+E+S8ZBnpYuE5MxpuRkRWnNmXwFZdG3Z3jH0+rwMz/HUH0HbxrkAnHoWy TEhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e8-20020a81a708000000b002f8ec0e57b4si10768798ywh.353.2022.05.09.09.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 09:04:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F3E4B45AE8; Mon, 9 May 2022 09:00:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238752AbiEIQEl (ORCPT + 99 others); Mon, 9 May 2022 12:04:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238726AbiEIQEk (ORCPT ); Mon, 9 May 2022 12:04:40 -0400 X-Greylist: delayed 483 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 09 May 2022 09:00:45 PDT Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0472F0D; Mon, 9 May 2022 09:00:44 -0700 (PDT) Received: from [2603:3005:d05:2b00:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1no5gT-0002xt-UY; Mon, 09 May 2022 11:52:29 -0400 Date: Mon, 9 May 2022 11:52:27 -0400 From: Rik van Riel To: Song Liu Cc: , , , , , , , Subject: [RFC] sched,livepatch: call stop_one_cpu in klp_check_and_switch_task Message-ID: <20220509115227.6075105e@imladris.surriel.com> In-Reply-To: <20220507174628.2086373-1-song@kernel.org> References: <20220507174628.2086373-1-song@kernel.org> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: riel@shelob.surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After talking with Peter, this seems like it might be a potential approach to fix the issue for kernels both with PREEMPT enabled and disabled. If this looks like a reasonable approach to people, we can run experiments with this patch on a few thousand systems, and compare it with the kernel live patch transition latencies (and number of failures) on a kernel without that patch. Does this look like an approach that could work? ---8<--- sched,livepatch: call stop_one_cpu in klp_check_and_switch_task If a running task fails to transition to the new kernel live patch after the first attempt, use the stopper thread to preempt it during subsequent attempts at switching to the new kernel live patch. Signed-off-by: Rik van Riel diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index 5d03a2ad1066..26e9e5f09822 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" @@ -281,6 +282,11 @@ static int klp_check_and_switch_task(struct task_struct *task, void *arg) return 0; } +static int kpatch_dummy_fn(void *dummy) +{ + return 0; +} + /* * 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 @@ -315,6 +321,9 @@ static bool klp_try_switch_task(struct task_struct *task) case -EBUSY: /* klp_check_and_switch_task() */ pr_debug("%s: %s:%d is running\n", __func__, task->comm, task->pid); + /* Preempt the task from the second KLP switch attempt. */ + if (klp_signals_cnt) + stop_one_cpu(task_cpu(task), kpatch_dummy_fn, NULL); break; case -EINVAL: /* klp_check_and_switch_task() */ pr_debug("%s: %s:%d has an unreliable stack\n",