Received: by 2002:a05:7208:c250:b0:86:f851:443 with SMTP id w16csp45600rbd; Tue, 11 Jun 2024 12:30:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuqhBFLOksXFaP2dYaWTW1kyEnRDgu64Bl8EaIyTnQ1vxwC9CKw8GLsAlDnEa6zi3kTo/oH+FC6bc7V486EQTC0OSOWVrwN0kyd0KH+w== X-Google-Smtp-Source: AGHT+IHm2rfnqMDUvCSe1QHeaMAQ2T8gHXzRGgU/2UJci6mQiUiNntRMYKdvRk7uKzVCUth6JuZ6 X-Received: by 2002:a17:90a:17ac:b0:2bd:d6c6:f454 with SMTP id 98e67ed59e1d1-2c32b518e4dmr4961284a91.21.1718134255954; Tue, 11 Jun 2024 12:30:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718134255; cv=pass; d=google.com; s=arc-20160816; b=YNyQ2/PKOdZz0reWhPNsWet1oacKV1feWY1bWOuEo94Tza0NNK4k1/rfcXvFoxTsmC 0P9pXyQH9LpsKcrTGQFMtJYnq/pegB2vXjDGK6oJ+bKbGtCXcOz55D6Tns1DbGYpSLaY c+pAiiX0HQ56ej0M75Us6Ennbs7l0qm4DU1/9S63Z1pfy1s3Qu4TRDqSE31fjevOYOsj 2wjVnA+I0Et5vxsd+ooV0jYAqB4i5d+f4hDZP1bk7GYzHkORJgBa8cgmU2Qj6oSeQWDP ne0hn4nRxNjc+EKiNTivSnK7ChAAQbjuqXw5xkh24zjeO9jdzqy2Nl4VpJNi/6XQQdgE LydA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=SOa9PLWIll50BYtpsFZxcaam1sKhNwb4nrz1sN6Ezh0=; fh=VQi8WXJrSHXxsfwqC9oAfi6LEiQC0Qv/w+aqrHCHJLs=; b=obbiFdR52w6hw4ZqCK5wfD2J47XL4biByezFfqUs7l3uln5wqPMO/s5BH3VL3/TiXR lmyxTidRcFZVw8+2TmjKX93jm1azmE3d255Jgm+VSd7BOkyeXBAcJg99ZRKghWpZtF5M cDn1CB4D8/CYHfXxwVA8LW/oyKIy7VNMU1438iICphDu3O682m2EsCg9LYQBL5DFAo5a dT3vyV360xSuJk/Edj7cy15EynrNg8vsnW6Bnjej2P4sBxqk4Bx+ePDBwxs13ISqcnEz NNrb3+wcG8OaCopKwPRKj47pxQ3F8iOBUG4rTEf6vLKWZE65jAtodjRIYNw17OR0xlGH HYaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-210508-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210508-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2d0e295f1si7316777a91.2.2024.06.11.12.30.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:30:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210508-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-210508-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210508-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EBAB2287BF1 for ; Tue, 11 Jun 2024 19:30:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BBBA155380; Tue, 11 Jun 2024 19:28:55 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED4B3152789; Tue, 11 Jun 2024 19:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718134133; cv=none; b=fawYRHaE+Qxv29I9ucxCVba8LXyiXI/kORbKNjzzCGA6o4K6WfQntwHsz4MpyFoR3SPILlroc5mniUKWp9cQw551504b+WykGyAYxmKXSaLyevkr7XcGK52kbCf7KFex10JvTs7EaQSWyMoqTR943GEJaiC8peG1L2MKu/l+Pjk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718134133; c=relaxed/simple; bh=mZTyYJB2LiFL7vhNFEBQuD6v2hbJlYmFFJs3Rt2sAQA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WHEn0D6kRV6xMu2NvTOcODzC7Ic8Rsd73rywsPWSV5ZqDNI7+SuEYVS1iaAY8fDdoUUgj4AbJLR2dx0LKLfhVF0VRWH25qmeFVG+ExuerwllOFYioT5iuRurrU0lzGXmYLcO+TgTK9mjGMsPN0qMiMW8NMJZJBsEi/iQiQBpJFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73094C4DE03; Tue, 11 Jun 2024 19:28:52 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sH7B6-00000001TuR-45zg; Tue, 11 Jun 2024 15:29:08 -0400 Message-ID: <20240611192908.835949908@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 11 Jun 2024 15:28:38 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Vincent Donnefort , Joel Fernandes , Daniel Bristot de Oliveira , Ingo Molnar , Peter Zijlstra , suleiman@google.com, Thomas Gleixner , Vineeth Pillai , Youssef Esmat , Beau Belgrave , Alexander Graf , Baoquan He , Borislav Petkov , "Paul E. McKenney" , David Howells , Mike Rapoport , Dave Hansen , Tony Luck , Guenter Roeck , Ross Zwisler , Kees Cook Subject: [PATCH v4 10/13] tracing/ring-buffer: Add last_boot_info file to boot instance References: <20240611192828.691638177@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: "Steven Rostedt (Google)" If an instance is mapped to memory on boot up, create a new file called "last_boot_info" that will hold information that can be used to properly parse the raw data in the ring buffer. It will export the delta of the addresses for text and data from what it was from the last boot. It does not expose actually addresses (unless you knew what the actual address was from the last boot). The output will look like: # cat last_boot_info text delta: -268435456 data delta: -268435456 The text and data are kept separate in case they are ever made different. Signed-off-by: Steven Rostedt (Google) --- include/linux/ring_buffer.h | 3 +++ kernel/trace/ring_buffer.c | 23 ++++++++++++++++++ kernel/trace/trace.c | 47 ++++++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 2 ++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index a50b0223b1d3..55de3798a9b9 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h @@ -94,6 +94,9 @@ struct trace_buffer *__ring_buffer_alloc_range(unsigned long size, unsigned flag unsigned long range_size, struct lock_class_key *key); +bool ring_buffer_last_boot_delta(struct trace_buffer *buffer, long *text, + long *data); + /* * Because the ring buffer is generic, if other users of the ring buffer get * traced by ftrace, it can produce lockdep warnings. We need to keep each diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index ab6b8a0ee8e1..8c1d7ea01e6f 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -2394,6 +2394,29 @@ struct trace_buffer *__ring_buffer_alloc_range(unsigned long size, unsigned flag return alloc_buffer(size, flags, order, start, start + range_size, key); } +/** + * ring_buffer_last_boot_delta - return the delta offset from last boot + * @buffer: The buffer to return the delta from + * @text: Return text delta + * @data: Return data delta + * + * Returns: The true if the delta is non zero + */ +bool ring_buffer_last_boot_delta(struct trace_buffer *buffer, long *text, + long *data) +{ + if (!buffer) + return false; + + if (!buffer->last_text_delta) + return false; + + *text = buffer->last_text_delta; + *data = buffer->last_data_delta; + + return true; +} + /** * ring_buffer_free - free a ring buffer. * @buffer: the buffer to free. diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index dfde26aa3211..dc4eee33d920 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6041,6 +6041,18 @@ ssize_t tracing_resize_ring_buffer(struct trace_array *tr, return ret; } +static void update_last_data(struct trace_array *tr) +{ + if (!tr->text_delta && !tr->data_delta) + return; + + /* Clear old data */ + tracing_reset_online_cpus(&tr->array_buffer); + + /* Using current data now */ + tr->text_delta = 0; + tr->data_delta = 0; +} /** * tracing_update_buffers - used by tracing facility to expand ring buffers @@ -6058,6 +6070,9 @@ int tracing_update_buffers(struct trace_array *tr) int ret = 0; mutex_lock(&trace_types_lock); + + update_last_data(tr); + if (!tr->ring_buffer_expanded) ret = __tracing_resize_ring_buffer(tr, trace_buf_size, RING_BUFFER_ALL_CPUS); @@ -6113,6 +6128,8 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf) mutex_lock(&trace_types_lock); + update_last_data(tr); + if (!tr->ring_buffer_expanded) { ret = __tracing_resize_ring_buffer(tr, trace_buf_size, RING_BUFFER_ALL_CPUS); @@ -6860,6 +6877,21 @@ tracing_total_entries_read(struct file *filp, char __user *ubuf, return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); } +static ssize_t +tracing_last_boot_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) +{ + struct trace_array *tr = filp->private_data; + struct seq_buf seq; + char buf[64]; + + seq_buf_init(&seq, buf, 64); + + seq_buf_printf(&seq, "text delta:\t%ld\n", tr->text_delta); + seq_buf_printf(&seq, "data delta:\t%ld\n", tr->data_delta); + + return simple_read_from_buffer(ubuf, cnt, ppos, buf, seq_buf_used(&seq)); +} + static int tracing_buffer_meta_open(struct inode *inode, struct file *filp) { struct trace_array *tr = inode->i_private; @@ -7499,6 +7531,13 @@ static const struct file_operations trace_time_stamp_mode_fops = { .release = tracing_single_release_tr, }; +static const struct file_operations last_boot_fops = { + .open = tracing_open_generic_tr, + .read = tracing_last_boot_read, + .llseek = generic_file_llseek, + .release = tracing_release_generic_tr, +}; + #ifdef CONFIG_TRACER_SNAPSHOT static const struct file_operations snapshot_fops = { .open = tracing_snapshot_open, @@ -9242,6 +9281,9 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size buf->buffer = ring_buffer_alloc_range(size, rb_flags, 0, tr->range_addr_start, tr->range_addr_size); + + ring_buffer_last_boot_delta(buf->buffer, + &tr->text_delta, &tr->data_delta); /* * This is basically the same as a mapped buffer, * with the same restrictions. @@ -9751,7 +9793,10 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) MEM_FAIL(1, "Could not allocate function filter files"); #ifdef CONFIG_TRACER_SNAPSHOT - if (!tr->range_addr_start) { + if (tr->range_addr_start) { + trace_create_file("last_boot_info", TRACE_MODE_READ, d_tracer, + tr, &last_boot_fops); + } else { trace_create_file("snapshot", TRACE_MODE_WRITE, d_tracer, tr, &snapshot_fops); } diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 2efa4cccdd3b..611be17fdc70 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -347,6 +347,8 @@ struct trace_array { /* The below is for memory mapped ring buffer */ unsigned long range_addr_start; unsigned long range_addr_size; + long text_delta; + long data_delta; struct trace_pid_list __rcu *filtered_pids; struct trace_pid_list __rcu *filtered_no_pids; -- 2.43.0