Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7044475imm; Tue, 24 Jul 2018 07:32:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdweOWSRfbS7DTRfjInYuw+9v9jP7c0qGvJzqA2hG8Vpt6W+slL8NWxUMjs8wXn4HyxOhlP X-Received: by 2002:a65:620b:: with SMTP id d11-v6mr16823420pgv.429.1532442758384; Tue, 24 Jul 2018 07:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532442758; cv=none; d=google.com; s=arc-20160816; b=j8CT+Qt0XhneCQN4pE1T4orPFc1Es79RjZDnICtgvfNAQm+rqZUXExKY5vhfeluAmg W2eNcs1R8R1IlM8Tr1L3OvQ1kVkYTAUS176PTyzcdwSA+ruTxYq6MF6OtgSztGOes2Bp jUOLhh2UV6v9e3P6B3loRf2Kw2ddtyVF1OwGmUziciayo7ywicEWMUSr59y/+vKnfwjX fAqE4HWtEgq7NMRkm5xhCK9xxAJISTSf0rg4bAD2U8mbQE0em1CLwa0NdARaE6kSk7i8 bEvCHBefyPlAyes2nVQEtnpanFsKN0GEEg6KSdTWf4Nk7zRkC1NAszV0fFbeuTD0L71N cHNQ== 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 :dkim-signature:arc-authentication-results; bh=7uLv9z7yvUJRjWWxLeQnb2EK7hSB4FMtEqMqpzsLeTw=; b=Vqt0v3O4kt+unBdtT8qqj72af0/Duda8ax+MKxO3VxLW/cfa+zgczOT8G2orLkT0DQ tvKkMZ0K5DMygHTdMNMSGi/PeziDB82GNSHQYN3ariV8T8FYHdWPML2X0eGjzgybzVBv nOR2YBT44ttq1i7wEyHrmNkktRlRmmOWwCOuoRgEyhc/umqplHA2XvEU6WVSlm5LFp/3 GZxiU86i+aVoDlR9r/HRrEf9WanMonj+vsasrOENOQrXRzASshIsnGZb7iKUyX+nUiVm zgar/yuydSgfsASHUModIhO8CDRF+SNmq0WJDYZsHMhdxRk34XM21/FK/WAYjGlBsk6f 92TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CP7HQxs9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 138-v6si11540554pga.188.2018.07.24.07.32.23; Tue, 24 Jul 2018 07:32:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CP7HQxs9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388692AbeGXPhQ (ORCPT + 99 others); Tue, 24 Jul 2018 11:37:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:52968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388583AbeGXPhQ (ORCPT ); Tue, 24 Jul 2018 11:37:16 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 6D89020852; Tue, 24 Jul 2018 14:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1532442631; bh=CrJj+Us7dTtuY77AIw5INzO7z2eawipCdaB99hdwOvc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CP7HQxs91SXEZEhjQJ/JK9aZr5tmE5B9FhZo9ktNq+JcqgfTuKnFo9Li8taTxTuyl 5gsoCHV2HC8mVfcr/A8ZLkS8WGRSdoF8KUvQFevfprvj8v6s3zBtiXtjXZcw5TjuWi WnT8V9OgvHtWpWFWZM7rMYoZ6GSFXIRN+BwWFdrE= Date: Tue, 24 Jul 2018 23:30:28 +0900 From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Shuah Khan , Tom Zanussi , Hiraku Toyooka , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 2/3] [BUGFIX] ring_buffer: tracing: Inherit the tracing setting to next ring buffer Message-Id: <20180724233028.7b53739f46352001854d5799@kernel.org> In-Reply-To: <20180723222534.368ea01b@vmware.local.home> References: <153149923649.11274.14970833360963898112.stgit@devbox> <153149929558.11274.11730609978254724394.stgit@devbox> <20180723222534.368ea01b@vmware.local.home> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-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 On Mon, 23 Jul 2018 22:25:34 -0400 Steven Rostedt wrote: > On Sat, 14 Jul 2018 01:28:15 +0900 > Masami Hiramatsu wrote: > > > Inherit the tracing on/off setting on ring_buffer to next > > trace buffer when taking a snapshot. > > > > Taking a snapshot is done by swapping with backup ring buffer > > (max_tr_buffer). But since the tracing on/off setting is set > > in the ring buffer, when swapping it, tracing on/off setting > > can also be changed. This causes a strange result like below; > > > > /sys/kernel/debug/tracing # cat tracing_on > > 1 > > /sys/kernel/debug/tracing # echo 0 > tracing_on > > /sys/kernel/debug/tracing # echo 1 > snapshot > > /sys/kernel/debug/tracing # cat tracing_on > > 1 > > /sys/kernel/debug/tracing # echo 1 > snapshot > > /sys/kernel/debug/tracing # cat tracing_on > > 0 > > > > We don't touch tracing_on, but snapshot changes tracing_on > > setting each time. This must be a bug, because user never know > > that each "ring_buffer" stores tracing-enable state and > > snapshot is done by swapping ring buffers. > > > > This patch fixes above strange behavior. > > > > > OK, so the issue is that the tracing_on state is saved with the buffer > itself. And when we swap the buffer, we also swap the state. > > > > Fixes: commit debdd57f5145 ("tracing: Make a snapshot feature available from userspace") > > Signed-off-by: Masami Hiramatsu > > Cc: Steven Rostedt > > Cc: Ingo Molnar > > Cc: Hiraku Toyooka > > Cc: stable@vger.kernel.org > > --- > > include/linux/ring_buffer.h | 1 + > > kernel/trace/ring_buffer.c | 12 ++++++++++++ > > kernel/trace/trace.c | 6 ++++++ > > 3 files changed, 19 insertions(+) > > > > diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h > > index b72ebdff0b77..003d09ab308d 100644 > > --- a/include/linux/ring_buffer.h > > +++ b/include/linux/ring_buffer.h > > @@ -165,6 +165,7 @@ void ring_buffer_record_enable(struct ring_buffer *buffer); > > void ring_buffer_record_off(struct ring_buffer *buffer); > > void ring_buffer_record_on(struct ring_buffer *buffer); > > int ring_buffer_record_is_on(struct ring_buffer *buffer); > > +int ring_buffer_record_is_set_on(struct ring_buffer *buffer); > > void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu); > > void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu); > > > > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c > > index 6a46af21765c..4038ed74ab95 100644 > > --- a/kernel/trace/ring_buffer.c > > +++ b/kernel/trace/ring_buffer.c > > @@ -3227,6 +3227,18 @@ int ring_buffer_record_is_on(struct ring_buffer *buffer) > > } > > > > /** > > + * ring_buffer_record_is_set_on - return true if the ring buffer is set writable > > + * @buffer: The ring buffer to see if write is set enabled > > + * > > + * Returns true if the ring buffer is set writable by ring_buffer_record_on(). > > + * Note that this does NOT mean it is in a writable state. > > I'd add a little more context here. Something like: > > * It may return true when the ring buffer has been disabled by > * ring_buffer_record_disable(), as that is a temporary disabling of > * the ring buffer. Looks nice to me :) It makes the meaning clearer. Thanks! > > -- Steve > > > + */ > > +int ring_buffer_record_is_set_on(struct ring_buffer *buffer) > > +{ > > + return !(atomic_read(&buffer->record_disabled) & RB_BUFFER_OFF); > > +} > > + > > +/** > > * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer > > * @buffer: The ring buffer to stop writes to. > > * @cpu: The CPU buffer to stop > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > > index 2556d8c097d2..bbd5a94a7ef1 100644 > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -1378,6 +1378,12 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) > > > > arch_spin_lock(&tr->max_lock); > > > > + /* Inherit the recordable setting from trace_buffer */ > > + if (ring_buffer_record_is_set_on(tr->trace_buffer.buffer)) > > + ring_buffer_record_on(tr->max_buffer.buffer); > > + else > > + ring_buffer_record_off(tr->max_buffer.buffer); > > + > > swap(tr->trace_buffer.buffer, tr->max_buffer.buffer); > > > > __update_max_tr(tr, tsk, cpu); > -- Masami Hiramatsu