Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp594336ybj; Thu, 7 May 2020 03:07:32 -0700 (PDT) X-Google-Smtp-Source: APiQypJtt1lTn+MgmWGF7bcQCdMDXcw50UPvJlHXKp1wdvPUnA6CNz00pcOEAg07+TjmvfPIPNNW X-Received: by 2002:a17:906:938c:: with SMTP id l12mr9604888ejx.338.1588846052168; Thu, 07 May 2020 03:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588846052; cv=none; d=google.com; s=arc-20160816; b=b+0zmni3Q+e7RnxSi55ORye6U6XijMx27t+nb0JdvID9AUA+AxmX3urJyEAYoPtC1r 3nj1ipSz7LOouaIi248AU18s/NXDI1lZgr6wgv1UuUG6trMoQNZsgKzn0dpALzKfbquJ U8A5L3I8H+vwqJW+QFji3XXM1THfTEfM/aE4+CQP6TnqcOlAN09uePrV2IAzURiJ5Iom +e1CYE6BMvttK7yGYnPdCdhO5YgfmXlSvS8O7WDImk7QFgYS0Rg8hSpaTKkIYO+x2pW6 +X6aEOlaPblGhCLvqslp8KMcypLZL6ST/9SIg2UQZ/a7qVxzFBPwlFqyMSSgS3YU2Dw3 +H0Q== 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:in-reply-to :references:subject:cc:to:mime-version:user-agent:from:date :message-id; bh=a6PL2RuMub6YEkWyhNbvhzbvcOJtbV++27uSxkqikc4=; b=tnI863A0pRIvRagxjZG4DRpHE5c3KZMcBpNZOws7L/BKw0mHTNG2eGb8CUYO/d+/K1 vm+5p+bGHR1dLt2xKii0QDxO51Ixh1m3IXnmVuWuceXZZwVFnw1xVEfcl8zYi+8XRloU yMg2GX6tKOYC9o9l8h6YJ0UEMCQ3KALRlVgB75YdNPTz9DToo2Kmlu1xyOPwthy3A5e5 sqoR1DiGE59Irmcv58Pv1Te06Yu+rfNjth6nZbbkH6bYNpqThgRHiaFoMWZmLXCU7IG6 2WqfPkdEOWcIh+daDNgtWBzjXfsfSQEuq7E0A8VQVmtgWqh24hMp9rWmdJG7Ny6f4Pg2 DPmg== 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 v28si3047518edd.176.2020.05.07.03.07.07; Thu, 07 May 2020 03:07:32 -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 S1726638AbgEGKFM (ORCPT + 99 others); Thu, 7 May 2020 06:05:12 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:48571 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725985AbgEGKFM (ORCPT ); Thu, 7 May 2020 06:05:12 -0400 X-IronPort-AV: E=Sophos;i="5.73,362,1583164800"; d="scan'208";a="91544946" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 May 2020 18:05:08 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 52B994CE2E7D; Thu, 7 May 2020 18:05:05 +0800 (CST) Received: from [10.167.220.69] (10.167.220.69) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 7 May 2020 18:05:04 +0800 Message-ID: <5EB3DD4E.7060000@cn.fujitsu.com> Date: Thu, 7 May 2020 18:05:02 +0800 From: Xiao Yang User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.2; zh-CN; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: Steven Rostedt CC: Joel Fernandes , , Ingo Molnar Subject: Re: [PATCH] tracing: Wait for preempt irq delay thread to finish 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> <20200506103017.72abd2cd@gandalf.local.home> In-Reply-To: <20200506103017.72abd2cd@gandalf.local.home> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.167.220.69] X-ClientProxiedBy: G08CNEXCHPEKD05.g08.fujitsu.local (10.167.33.203) To G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) X-yoursite-MailScanner-ID: 52B994CE2E7D.AC111 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Steven, Thanks for your further investigation. I used the following ways to test your fix patch on my slow vm and didn't see any issue: 1) Insert and remove preemptirq_delay_test in loops. 2) Insert preemptirq_delay_test, write to /sys/kernel/preemptirq_delay_test/trigger and remove preemptirq_delay_test in loops. 3) Ran irqsoff_tracer.tc in loops. BTW: For irqsoff_tracer.tc, should we extend code to test the burst feature and the sysfs trigger? Reviewed-by: Xiao Yang Thanks, Xiao Yang On 2020/5/6 22:30, Steven Rostedt wrote: > 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; >