Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp86728ybj; Wed, 6 May 2020 12:10:42 -0700 (PDT) X-Google-Smtp-Source: APiQypI642NaQU0di7OBMIUDElc5S+tRXM2rypnunkPuWDDYb8YcyEoZKtGErpZdzy2PqNuVeylK X-Received: by 2002:a17:906:72c8:: with SMTP id m8mr9127467ejl.318.1588792241838; Wed, 06 May 2020 12:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588792241; cv=none; d=google.com; s=arc-20160816; b=UYWzlUjdcC16wzjcuvO8GtPVCECSGDzz5H2Bp4+HMbnmm/t6y2fPem4X215IWu698y +jyljJRKBLfvQdpiWx/ev5fKp4IAJpP0c9AN4qjf7WhThNwXLBlDb5NTvtkgYmSH8iL2 irZriFZoO5fU23CCVjAwRIoUsixtjwk3waib5TlbmQG4utol3F8DZizBQB0A+M4CzKWy eRQSbrQTpTBN8AV640zGDNHstWjJLubePKwYozHCX0abCO/xUc7ESdE3AcZSHHDQ/Rim gAgUTMlxySRlvLC/OnE1EKUr6G3+p21kc0H/rGhI4mU4rBaxxjxi9XrGk9KYKPB5eDUo /h1w== 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=aqBRrjb/7fRVXwkMURAmIG5jQp2YLNRgRl7ti045IV4=; b=YWeksu6u3T/5HwFEjgaI3LRYydC45cV3pHYrDwTBhd6BzOT+fbK+3gQC7ZND8092dr Bz3xt4jhMmmIUmhB4sSs3MIX7hl4O4C603rkLt2PppuXQMtRNvHbCl5ncO44oDlM3Rub Z/zUPB33F8N5s+Nonc1QcXHBHinZmJnfbTP2NhQ3juNXEDDSMmMK3i9AWAHz1xzDOm6v Z5aNDWSgYOYfJXG6vETJQpIxaKtsTKXeeEgbm0p5DW+5v9XPWhWzd62GUGneqSlkx8Uu rSl30U6MU+aRO6dmEBVEwntqcrtNo1pEPHb1vt7dmH1ZcAjzF5XhWz6XnytbxDlA8iMo SgwQ== 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 y9si1626717edv.534.2020.05.06.12.10.19; Wed, 06 May 2020 12:10:41 -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 S1728983AbgEFOaU (ORCPT + 99 others); Wed, 6 May 2020 10:30:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:49618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728740AbgEFOaU (ORCPT ); Wed, 6 May 2020 10:30:20 -0400 Received: from gandalf.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 4B77820769; Wed, 6 May 2020 14:30:19 +0000 (UTC) Date: Wed, 6 May 2020 10:30:17 -0400 From: Steven Rostedt To: Joel Fernandes Cc: Xiao Yang , linux-kernel@vger.kernel.org, Ingo Molnar Subject: [PATCH] tracing: Wait for preempt irq delay thread to finish Message-ID: <20200506103017.72abd2cd@gandalf.local.home> In-Reply-To: <20200506093805.1f86f3f0@gandalf.local.home> References: <20200424223630.224895-1-joel@joelfernandes.org> <5EA80319.7080005@cn.fujitsu.com> <20200428104409.0995ceb0@gandalf.local.home> <20200428104543.3926eaaf@gandalf.local.home> <5EA96AE8.6000707@cn.fujitsu.com> <20200429123141.580f89ce@gandalf.local.home> <20200429191224.GA75562@google.com> <20200506093805.1f86f3f0@gandalf.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)" Running on a slower machine, it is possible that the preempt delay kernel thread may still be executing if the module was immediately removed after added, and this can cause the kernel to crash as the kernel thread might be executing after its code has been removed. There's no reason that the caller of the code shouldn't just wait for the delay thread to finish, as the thread can also be created by a trigger in the sysfs code, which also has the same issues. Link: http://lore.kernel.org/r/5EA2B0C8.2080706@cn.fujitsu.com Cc: stable@vger.kernel.org Fixes: 793937236d1ee ("lib: Add module for testing preemptoff/irqsoff latency tracers") Reported-by: Xiao Yang Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/preemptirq_delay_test.c | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/kernel/trace/preemptirq_delay_test.c b/kernel/trace/preemptirq_delay_test.c index 31c0fad4cb9e..c4c86de63cf9 100644 --- a/kernel/trace/preemptirq_delay_test.c +++ b/kernel/trace/preemptirq_delay_test.c @@ -113,22 +113,42 @@ static int preemptirq_delay_run(void *data) for (i = 0; i < s; i++) (testfuncs[i])(i); + + set_current_state(TASK_INTERRUPTIBLE); + while (!kthread_should_stop()) { + schedule(); + set_current_state(TASK_INTERRUPTIBLE); + } + + __set_current_state(TASK_RUNNING); + return 0; } -static struct task_struct *preemptirq_start_test(void) +static int preemptirq_run_test(void) { + struct task_struct *task; + char task_name[50]; snprintf(task_name, sizeof(task_name), "%s_test", test_mode); - return kthread_run(preemptirq_delay_run, NULL, task_name); + task = kthread_run(preemptirq_delay_run, NULL, task_name); + if (IS_ERR(task)) + return PTR_ERR(task); + if (task) + kthread_stop(task); + return 0; } static ssize_t trigger_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { - preemptirq_start_test(); + ssize_t ret; + + ret = preemptirq_run_test(); + if (ret) + return ret; return count; } @@ -148,11 +168,9 @@ static struct kobject *preemptirq_delay_kobj; static int __init preemptirq_delay_init(void) { - struct task_struct *test_task; int retval; - test_task = preemptirq_start_test(); - retval = PTR_ERR_OR_ZERO(test_task); + retval = preemptirq_run_test(); if (retval != 0) return retval; -- 2.20.1