From patchwork Mon Nov 21 03:51:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhouyi Zhou X-Patchwork-Id: 23523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1377076wrr; Sun, 20 Nov 2022 20:00:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf74q1+2YiAFvO/sYZWOKBeaiS1ltGd09CKfedcPIjbCO42Hc7iIV18qZ36pWAHzYgfLIHDb X-Received: by 2002:a05:6402:2903:b0:469:b282:1b9d with SMTP id ee3-20020a056402290300b00469b2821b9dmr651648edb.43.1669003246425; Sun, 20 Nov 2022 20:00:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669003246; cv=none; d=google.com; s=arc-20160816; b=Wxv2B8fQkqJpatqLnjP1dRY7IEA/dRdX1ewDVYTOlQOEHYxBd9/nrx+2UftYav2LSr +pWWi+OX24GWpZ74cu4BjTTeYfrVMRXRBMJgrYm7frpma0nvmRUyAls9/PK+Qdg9KrSv Efxqj9OUV5pZGMRk3QWObOVe750t6sRuZC3TA7z8G6/6qu96aX907xBwisswX+bKNDNG LqatmGMEtFn6YghjgzAYbLCQIyzs7JNpuGJHfAhSFEapT2zNBsSw1sApO2QW0lm0RMRL BaC7EnLZdd04sKiu4FQ/3Ih1Xuo+r9eyCpmjWPKvlmfWjQKaDLlSZSIG9toOChIChRUq qOgw== 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:dkim-signature; bh=GxntLd/ct95PDR+cb+voA3PVWvgQd225Bxlaz4kUMug=; b=K+e55Mls83aETXeZ+ItePUhUpXlXpMXWc/OwW4uh8XZKx/z1O9O3c8AlrX1Ef8dx04 cZLBOrxEor5hPTA90g/0AK7Y7EDA/jMQmCsMHMkiqplL5xqp4ZdDxuNkjIFLeysy2upV CEF+JMom127+yK/BItFU8B8fNvi95MSEtncxWtXJoMGSUk1OexDC0d54VkVfLPSTmR1M lhAYL7n5QxoNLbqGSLu1hmwZbp/xly3CTUOQau6Qc1r36fSaNGfs85KQkZ3na9uYg+Fh AaTC7Ccavnw+csMCvd5k7ahBBKI8KTd0WpnFB/wG3fXVW6pO17Jq3+ZcW1yWtBpQ+Yhk ggHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=G3+BJ6h3; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10-20020a1709061c4a00b007707ab4be28si6997654ejg.972.2022.11.20.20.00.16; Sun, 20 Nov 2022 20:00:46 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=G3+BJ6h3; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229628AbiKUDvw (ORCPT + 99 others); Sun, 20 Nov 2022 22:51:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiKUDvu (ORCPT ); Sun, 20 Nov 2022 22:51:50 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D57521EEF0 for ; Sun, 20 Nov 2022 19:51:49 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id 130so10190317pfu.8 for ; Sun, 20 Nov 2022 19:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GxntLd/ct95PDR+cb+voA3PVWvgQd225Bxlaz4kUMug=; b=G3+BJ6h3S2AwsBJvMKzpLcRAMmfnvNbqghjwS3l9dKG7H2nqHRd+WuWvUxxO4V9t7o pSkW2ykPq5piIQ6mXp6Jk628w6L1iflshHCNR7Rk9ja3KpcvZVkXod+WBOpoTGddqns4 aYz9RO+oEVhTlg7TbVQ8KS/5s4DKt7L+GUMxrPRsn1rvd97A1Ir+OszygWwOKvVmmvOZ 7jSHc4PX2jnGsX6hOL9G/KVsr7G28ajHEBhISEL00cgRSDqdHgSBEAtjOsK4TanESi0F +W65wypspVWFZHnYM5w2Scbxv2l99dKfkH7N6xwNvQeI6JXAOlKDnMaR3tDTRQ6UiFlD qBfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GxntLd/ct95PDR+cb+voA3PVWvgQd225Bxlaz4kUMug=; b=RcabOpsUUrQQH9VqXRUeOy0/e9OEnlHTl9uB05izlRu4H1DIijpgUdTsBbPKIANMub NiluQT6NHejmWkYQNxgvrvEY4zZ73gPOOeuTizeqiyM4qxdn9fA3hAq68s51gR6ITS1S p9BJAGi+M44qVChJDG1RWCQnhnu22dsLB5xDXcwggOgIFGKO7eTyEJJMWpbOaMQ+QZI7 xQCvb5tTa04SnQcZbfmsNJhyWu7C6vt5tKZqcRMmATriIPTeQlzTZ3vIUM84zdn47pGv z75m1BWkyG5EjDM2IzEKeQE3RkNf/T1mdj4/Ui6P8XwvCBD/jjpgT7wl2Rng8Czhl4Y9 NadA== X-Gm-Message-State: ANoB5pkxKu3wKt51CKHhc/6TtTf91L15b99Amx+qT6HkTDuEdPwdDuAb PPF6+5Xs4nVU9unuguTGJmoFGUI1v3LOjA== X-Received: by 2002:a63:d241:0:b0:439:8688:a98d with SMTP id t1-20020a63d241000000b004398688a98dmr5641021pgi.424.1669002709390; Sun, 20 Nov 2022 19:51:49 -0800 (PST) Received: from localhost.localdomain ([194.5.48.82]) by smtp.gmail.com with ESMTPSA id o14-20020a170902d4ce00b00186acb14c4asm8476124plg.67.2022.11.20.19.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Nov 2022 19:51:49 -0800 (PST) From: Zhouyi Zhou To: fweisbec@gmail.com, tglx@linutronix.de, mingo@kernel.org, dave@stgolabs.net, paulmck@kernel.org, josh@joshtriplett.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Zhouyi Zhou Subject: [PATCH linux-next][RFC]torture: avoid offline tick_do_timer_cpu Date: Mon, 21 Nov 2022 11:51:40 +0800 Message-Id: <20221121035140.118651-1-zhouzhouyi@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750076747779663113?= X-GMAIL-MSGID: =?utf-8?q?1750076747779663113?= During CPU-hotplug torture (CONFIG_NO_HZ_FULL=y), if we try to offline tick_do_timer_cpu, the operation will fail because in function tick_nohz_cpu_down: ``` if (tick_nohz_full_running && tick_do_timer_cpu == cpu) return -EBUSY; ``` Above bug was first discovered in torture tests performed in PPC VM of Open Source Lab of Oregon State University, and reproducable in RISC-V and X86-64 (with additional kernel commandline cpu0_hotplug). In this patch, we avoid offline tick_do_timer_cpu by distribute the offlining cpu among remaining cpus. Signed-off-by: Zhouyi Zhou --- include/linux/tick.h | 1 + kernel/time/tick-common.c | 1 + kernel/time/tick-internal.h | 1 - kernel/torture.c | 10 ++++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index bfd571f18cfd..23cc0b205853 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -14,6 +14,7 @@ #include #ifdef CONFIG_GENERIC_CLOCKEVENTS +extern int tick_do_timer_cpu __read_mostly; extern void __init tick_init(void); /* Should be core only, but ARM BL switcher requires it */ extern void tick_suspend_local(void); diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 46789356f856..87b9b9afa320 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -48,6 +48,7 @@ ktime_t tick_next_period; * procedure also covers cpu hotplug. */ int tick_do_timer_cpu __read_mostly = TICK_DO_TIMER_BOOT; +EXPORT_SYMBOL_GPL(tick_do_timer_cpu); #ifdef CONFIG_NO_HZ_FULL /* * tick_do_timer_boot_cpu indicates the boot CPU temporarily owns diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h index 649f2b48e8f0..8953dca10fdd 100644 --- a/kernel/time/tick-internal.h +++ b/kernel/time/tick-internal.h @@ -15,7 +15,6 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device); extern ktime_t tick_next_period; -extern int tick_do_timer_cpu __read_mostly; extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast); extern void tick_handle_periodic(struct clock_event_device *dev); diff --git a/kernel/torture.c b/kernel/torture.c index 789aeb0e1159..bccbdd33dda2 100644 --- a/kernel/torture.c +++ b/kernel/torture.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -358,7 +359,16 @@ torture_onoff(void *arg) schedule_timeout_interruptible(HZ / 10); continue; } +#ifdef CONFIG_NO_HZ_FULL + /* do not offline tick do timer cpu */ + if (tick_nohz_full_running) { + cpu = (torture_random(&rand) >> 4) % maxcpu; + if (cpu >= tick_do_timer_cpu) + cpu = (cpu + 1) % (maxcpu + 1); + } else +#else cpu = (torture_random(&rand) >> 4) % (maxcpu + 1); +#endif if (!torture_offline(cpu, &n_offline_attempts, &n_offline_successes, &sum_offline, &min_offline, &max_offline))