Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3326898imu; Sun, 11 Nov 2018 12:27:03 -0800 (PST) X-Google-Smtp-Source: AJdET5fwxLqReA5AT46tYwa1sl1r5HK23x06USvUTfpCEdY8Mm1pd1jR5hHC3XIidBHCfhevmjXn X-Received: by 2002:a17:902:9698:: with SMTP id n24-v6mr17760885plp.9.1541968023647; Sun, 11 Nov 2018 12:27:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968023; cv=none; d=google.com; s=arc-20160816; b=qNHIRjFeamPEAlJUKPim/lIDKrJApe5d6csTr/p/0h+j/EGnOgoloVFLq38dZ9OHTn 1gW9ScsbUpkVOeg57fw8vp2PvTVeb0ZritntZfVHJcdNHzUL+p0+h6Vn58Q7OQSWgiL7 0Wn37tfeQU+BYIzzk1psNukjUbIbjNbX37k45iQlgUndxbdxsvZNj78PetYHcxPF2bWh UrDKyLKWm5oVmZieP8YjJ1V7mnok2UUhQkJV+zHXNhJiRsisSMJLKZvHVv+YoZSGRxcD tatWTumS5Ubl8iJOVlbmQokHBKACIFWpZUEvRZSgBQOUxMhjsLeAX6LK+aI2AOH7C10q TUoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=INF612iHdFgZqNzzidBKHPx3nh+rZB+CmaMmNZhyDKo=; b=Vq4RAYi1o1Ig5hTeoYhlt6we859zwZ1SGBPJNIzPLy2TKxic4Ip7hriDnK+GfgfU7y GcpL8U+Y633qLT+gWSN0YbzWHWdgUgVjPvnvckKeQcj9DwtKwPf9qClxguQbqN71M9Ed qD0awd56GF4IKqmHF9c+gOlrFz2aJinKV/211UUYY8FT3GdWg2JNcDkbL34rFbxpDbrE PjSc+jwWUBOcBlGZfe7OX0O8sxFBECY99JIm+D+C6c9D+KKI4mLTPJ7B7KcOQYhDu2UM swN6NgzZ4rhAwSQ16CeyeHRsMDZAbmv3oE/T8Ci7oP9VoMqT2iYHqeU5CK9MZwVpVCuS Uvew== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11-v6si14176444pgm.102.2018.11.11.12.26.48; Sun, 11 Nov 2018 12:27:03 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731171AbeKLGP6 (ORCPT + 99 others); Mon, 12 Nov 2018 01:15:58 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50902 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730637AbeKLFs1 (ORCPT ); Mon, 12 Nov 2018 00:48:27 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsl-0000oO-H7; Sun, 11 Nov 2018 19:58:55 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsY-0001ma-B3; Sun, 11 Nov 2018 19:58:42 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Tom Zanussi" , "Shuah Khan" , "Masami Hiramatsu" , "Steven Rostedt (VMware)" , "Hiraku Toyooka" , "Ingo Molnar" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 294/366] ring_buffer: tracing: Inherit the tracing setting to next ring buffer In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu commit 73c8d8945505acdcbae137c2e00a1232e0be709f upstream. Maintain the tracing on/off setting of the ring_buffer when switching to the trace buffer snapshot. Taking a snapshot is done by swapping the backup ring buffer (max_tr_buffer). But since the tracing on/off setting is defined by the ring buffer, when swapping it, the 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 # cat tracing_on 0 /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 is an anomaly, because user doesn't know that each "ring_buffer" stores its own tracing-enable state and the snapshot is done by swapping ring buffers. Link: http://lkml.kernel.org/r/153149929558.11274.11730609978254724394.stgit@devbox Cc: Ingo Molnar Cc: Shuah Khan Cc: Tom Zanussi Cc: Hiraku Toyooka Fixes: debdd57f5145 ("tracing: Make a snapshot feature available from userspace") Signed-off-by: Masami Hiramatsu [ Updated commit log and comment in the code ] Signed-off-by: Steven Rostedt (VMware) [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- include/linux/ring_buffer.h | 1 + kernel/trace/ring_buffer.c | 16 ++++++++++++++++ kernel/trace/trace.c | 6 ++++++ 3 files changed, 23 insertions(+) --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -162,6 +162,7 @@ void ring_buffer_record_enable(struct ri 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); --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3165,6 +3165,22 @@ int ring_buffer_record_is_on(struct ring } /** + * 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. + * + * 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. + */ +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 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1046,6 +1046,12 @@ update_max_tr(struct trace_array *tr, st 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); + buf = tr->trace_buffer.buffer; tr->trace_buffer.buffer = tr->max_buffer.buffer; tr->max_buffer.buffer = buf;