Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1185731ybk; Sun, 10 May 2020 08:43:57 -0700 (PDT) X-Google-Smtp-Source: APiQypJqlGu1PMkd6AciDq/fR+aqHP6+UIsCb5mxGAns7mhLQNQOZ+n/G2ibno+16fUg8hBCYZ04 X-Received: by 2002:aa7:dd95:: with SMTP id g21mr9883151edv.148.1589125437108; Sun, 10 May 2020 08:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589125437; cv=none; d=google.com; s=arc-20160816; b=tcFRsMNYxzcXybRIyt6cuufgjo8iiz9LAvn5GfWhBTBr9OlKKu3avLZz03rMJ5MwiP WW0/XNzWpX6ykTlZp9Sfep3KNPtOLdlkSuNqzvTvmvDRQgUyjQA2qhjrJWo90jNEZzcA 6MEXppv/aY/uAsm+7ME2e2VTHekASiqbWR3NyXTY+2BZXzhfs7cQarkmrzQwTgNOh7Xe qACpV/LrfxYhCxXXd0WVODwLA10Yq/AqZrQFQUXW2QiQTv65mvG6DYz2HSbnDs6XbfwA IB+U4uqKWoBYCagey4pRSp/W7AY3+hDajUqwp7jq0jIADsuUMg0VDq2coO4/VHTDLdQ+ HEhA== 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 :message-id:subject:cc:to:from:date; bh=5OcmyZD2Sc16dPdefvzBp2v0sjy0f30oLCJeeP+3uF8=; b=NLd0SVogiXSBQOwq18c47zhqQYvxO9q2crlp3Xh6NNq633gHQ0sqzarsS6N370afle 9TMqbf4giMRqUEe6eFsPbWEubQrlLIdxrA3D0pkbyjPWqCG+aV6vrvwJduJY8kRF6cJo T8ZDLZJSPOWZu8eI7WqygoLPfm4EH9pAMYGc7I8o3LHcSmKdRrEi9FdSj2ZjCOl/Yv2g EmkPDyyAbcgHeqIZUKU6AOVbiD9b4lmWEyxG3YZMXFo8CAWjf6tbj4u3mbBGtkhWv3+r 4mbEIQFGjE95UVfmEpJB4OwMn7AuAZqZhaKZf5KAk9QZO9oQMotAoBByWlndl33QwBv2 NSxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dh5si4316492edb.577.2020.05.10.08.43.34; Sun, 10 May 2020 08:43:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728683AbgEJPmN (ORCPT + 99 others); Sun, 10 May 2020 11:42:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:43488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726104AbgEJPmN (ORCPT ); Sun, 10 May 2020 11:42:13 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7D39420736; Sun, 10 May 2020 15:42:12 +0000 (UTC) Date: Sun, 10 May 2020 11:42:10 -0400 From: Steven Rostedt To: LKML Cc: Ingo Molnar , Joel Fernandes , Xiao Yang Subject: [PATCH] tracing: Wait for preempt irq delay thread to execute Message-ID: <20200510114210.15d9e4af@oasis.local.home> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org \From: "Steven Rostedt (VMware)" A bug report was posted that running the preempt irq delay module on a slow machine, and removing it quickly could lead to the thread created by the modlue to execute after the module is removed, and this could cause the kernel to crash. The fix for this was to call kthread_stop() after creating the thread to make sure it finishes before allowing the module to be removed. Now this caused the opposite problem on fast machines. What now happens is the kthread_stop() can cause the kthread never to execute and the test never to run. To fix this, add a completion and wait for the kthread to execute, then wait for it to end. This issue caused the ftracetest selftests to fail on the preemptirq tests. Cc: stable@vger.kernel.org Fixes: d16a8c31077e ("tracing: Wait for preempt irq delay thread to finish") Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/preemptirq_delay_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/trace/preemptirq_delay_test.c b/kernel/trace/preemptirq_delay_test.c index c4c86de63cf9..312d1a0ca3b6 100644 --- a/kernel/trace/preemptirq_delay_test.c +++ b/kernel/trace/preemptirq_delay_test.c @@ -16,6 +16,7 @@ #include #include #include +#include static ulong delay = 100; static char test_mode[12] = "irq"; @@ -28,6 +29,8 @@ MODULE_PARM_DESC(delay, "Period in microseconds (100 us default)"); MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt, irq, or alternate (default irq)"); MODULE_PARM_DESC(burst_size, "The size of a burst (default 1)"); +static struct completion done; + #define MIN(x, y) ((x) < (y) ? (x) : (y)) static void busy_wait(ulong time) @@ -114,6 +117,8 @@ static int preemptirq_delay_run(void *data) for (i = 0; i < s; i++) (testfuncs[i])(i); + complete(&done); + set_current_state(TASK_INTERRUPTIBLE); while (!kthread_should_stop()) { schedule(); @@ -128,15 +133,18 @@ static int preemptirq_delay_run(void *data) static int preemptirq_run_test(void) { struct task_struct *task; - char task_name[50]; + init_completion(&done); + snprintf(task_name, sizeof(task_name), "%s_test", test_mode); task = kthread_run(preemptirq_delay_run, NULL, task_name); if (IS_ERR(task)) return PTR_ERR(task); - if (task) + if (task) { + wait_for_completion(&done); kthread_stop(task); + } return 0; } -- 2.20.1