Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3736961iob; Sat, 7 May 2022 13:32:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLyBLl3To2DWjzsS1pXtfUWTSwJJWk3M4vIkTUXpN1d0yWV5r7bl2HMaDdRzF0/MzZ/oRK X-Received: by 2002:a63:8848:0:b0:3ab:2967:df83 with SMTP id l69-20020a638848000000b003ab2967df83mr7456510pgd.77.1651955546317; Sat, 07 May 2022 13:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651955546; cv=none; d=google.com; s=arc-20160816; b=VsAddWJBU751sGIuA91uAoOoxmrxHv3QxpuUZciriBLuzieKOVBMTtXh/Qt8V36Xy7 hULsYVBV3rkLlK8WyOHBgHKGtoHi3WiLArjd7CHV0+FGFmYzjo/J/coNt+F9F5kgZiBi s/tcyTJX3jkexHAX/Ctc5A9GWs4qfPGIsoffGnxW8JUSlxJ+gP5L44BlHF+lG/3MAJKQ wmPXJ6IUoq/DWoIX2kEJCg2+n5xXKPd0ubA4UoSXfKdb6mqHIGOznhJM9eOpl+uWfwoL kaDdDFDxO/N1WGVCBagLog71WmjeWCHKOM/UQxSLIy5+TCwu2bL1GvhaYcQB8S6BMxPS mrcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=loJPvEBkvaCRVR2uXepxymN3F2HOBM5EJsH2kSvroDY=; b=G2Ld7jkuarhP6emgnX80abe5FEn0Ydc8hBWWHsfPWVGzT1bJuWCHErPY9jDPLpTmKm +wv/FCH7ne3s0PSzMH7NHaFTtua77jxm+qhIvJ2GAWcllwAWh3HUQP6I4Jt3bZjeQ0os 2IazeNoyltNymVGN6RUPEjUVBhDsAfKDxny8piyl3PNfGGedG+aB5AahRuPHFOboM0tx VJJJgsmhFr1JalEbks3ZIVfH+xGI3uWBYCBxU+dywSr6dDh2eTeTiBzRoNv9KeUZdwxf yQrLl2c2rHVuhvXr/ELdgCFzwVumd3rfHzlEDnPT222jf5pcpLFzfVO57+Q0ob7fb4Rr 6SIw== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020a63d716000000b003aa810be6aasi8275143pgg.85.2022.05.07.13.32.08; Sat, 07 May 2022 13:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1446739AbiEGRub convert rfc822-to-8bit (ORCPT + 99 others); Sat, 7 May 2022 13:50:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1446729AbiEGRu3 (ORCPT ); Sat, 7 May 2022 13:50:29 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A7E1101DF for ; Sat, 7 May 2022 10:46:42 -0700 (PDT) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 247GLWrP022328 for ; Sat, 7 May 2022 10:46:41 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net (PPS) with ESMTPS id 3fwn141dbf-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 07 May 2022 10:46:41 -0700 Received: from twshared11660.23.frc3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 7 May 2022 10:46:39 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id B3D8F758C0BC; Sat, 7 May 2022 10:46:33 -0700 (PDT) From: Song Liu To: , CC: , , , , , , Song Liu Subject: [RFC] sched,livepatch: call klp_try_switch_task in __cond_resched Date: Sat, 7 May 2022 10:46:28 -0700 Message-ID: <20220507174628.2086373-1-song@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: PmbTh2tn02r-V5hhQDXv3p2rgpoxkNnq X-Proofpoint-ORIG-GUID: PmbTh2tn02r-V5hhQDXv3p2rgpoxkNnq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-07_06,2022-05-06_01,2022-02-23_01 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Busy kernel threads may block the transition of livepatch. Call klp_try_switch_task from __cond_resched to make the transition easier. Signed-off-by: Song Liu --- include/linux/livepatch.h | 2 ++ kernel/livepatch/transition.c | 2 +- kernel/sched/core.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index 2614247a9781..a9209f62550a 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -236,6 +236,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs, unsigned int symindex, unsigned int secindex, const char *objname); +bool klp_try_switch_task(struct task_struct *task); #else /* !CONFIG_LIVEPATCH */ static inline int klp_module_coming(struct module *mod) { return 0; } @@ -253,6 +254,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs, return 0; } +bool klp_try_switch_task(struct task_struct *task) { return true; } #endif /* CONFIG_LIVEPATCH */ #endif /* _LINUX_LIVEPATCH_H_ */ diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index f6310f848f34..4257a8eec64b 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -278,7 +278,7 @@ static int klp_check_stack(struct task_struct *task, char *err_buf) * running, or it's sleeping on a to-be-patched or to-be-unpatched function, or * if the stack is unreliable, return false. */ -static bool klp_try_switch_task(struct task_struct *task) +bool klp_try_switch_task(struct task_struct *task) { static char err_buf[STACK_ERR_BUF_SIZE]; struct rq *rq; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a7302b7b65f2..41d1c7a86912 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6990,6 +6990,9 @@ SYSCALL_DEFINE0(sched_yield) #if !defined(CONFIG_PREEMPTION) || defined(CONFIG_PREEMPT_DYNAMIC) int __sched __cond_resched(void) { + if (unlikely(klp_patch_pending(current))) + klp_try_switch_task(current); + if (should_resched(0)) { preempt_schedule_common(); return 1; -- 2.30.2