Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3731789rwb; Sun, 20 Nov 2022 21:04:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6DHjoKiyVAEniJVNTuYDJuZmGmExmGAIiAkgpbLlvYyt3st/PZjcHjhH0wH0ZqUSn7fOQn X-Received: by 2002:a17:906:2e82:b0:7ae:44b2:cb7f with SMTP id o2-20020a1709062e8200b007ae44b2cb7fmr64152eji.437.1669007064270; Sun, 20 Nov 2022 21:04:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669007064; cv=none; d=google.com; s=arc-20160816; b=P2eauObFLN90r228Ac448SfQwfcXO+Hs7Z6Rxbs0q7PQBgJxSnOO5h1BU2EH1NWgww x4+p035WGBoFzspSxd6agtGUCoY0glOEEV0e6iwRmVIAaOmeMduP+FO5TO+Fk36BvewO +55kwq948O0THKXPeL3T7y1SC/ra5xN5zRsBJj01/PyG5C5RkTUb04PowxGvHY8QAfBK tLc+Ti/vlvYWZNCMi0KoKjC6p3vK30HoaXV9qfH1dEWsiB8OyiGtgAlM234bOtYKp6wv PLoTRfLji+F81nw52XKql14Z6Uc79znD+sg+YlzxGixfZPoeuzMgycwcSOCJATWIkj1X n3mg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k14-20020a170906a38e00b0078dd73ae297si4492859ejz.172.2022.11.20.21.04.02; Sun, 20 Nov 2022 21:04:24 -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 + 90 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 Content-Transfer-Encoding: 8bit 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 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)) -- 2.34.1