Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp120399lqg; Wed, 10 Apr 2024 18:26:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUVSApG9kl8s2SdAiPQbEXY6pllfOib5WVAD8hgQucJyQbJtHyC9M1yYgBLGYEpBcs6nA1B+fxVhcnAxM+xlpI8t05BNBI5zG+tZsi8iw== X-Google-Smtp-Source: AGHT+IGIEhDgHKY5xWQ+2aEnW+LgXccX5P/9DfHAqL6o8mB7Gkd7YTBVyPHxe/qQ3Yz+p+krJ8OR X-Received: by 2002:a17:902:e943:b0:1e5:5042:2a59 with SMTP id b3-20020a170902e94300b001e550422a59mr458748pll.1.1712798799845; Wed, 10 Apr 2024 18:26:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712798799; cv=pass; d=google.com; s=arc-20160816; b=iLsJGr/rGpbRy96PAYEWiBpeUTdlWAxNvlYTnbmvqW353JtximamNabSWWAancsyLE 2AHsiiP2ktMDA9PJoWcQiNlRxwj4/NRkFGkfbSqXLZcENpxfl/AtuEuWO9Ps7ptF5M9X KzGY9X+iCc84gSwoozq/HO/Wo0LbP6rJ3sgxMECVHExOTIvPu10NDDLyrcg5jCi+oF0n RxZYPKeaklefYRMA0QQhqJCBYIyu/inZ9fBQ6cjIF2DNbLvScbnE4Uj6Ga2AHD+BEXVH e7VdtS2CHPW5Br+8Q6C8Ii5Yevr68H7jLJEow0MimVIcpKdYW5Q54NXwV5e4gVae7O8M QvTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:subject:cc:to :from:date:user-agent:message-id; bh=BhdWhQscMQjFTZosWVAC25CLQzhMrCyiVDdFeWlGcCc=; fh=Ix7vUKcZB54T3hGcALQhA/BzgLD1qNEu9GE2SGoxGjs=; b=AnQ4S8b3uhhziey9goVKHRXbDat9fRRVix0vSNtWCJts5EUqp3rFKyhQDazzEaHCTU j0O09Ws+PoZhJCyK2uaRBiHm87m4myRsBxXiouzS5hu+lsNAGO35+06K3KqMJTthWn0U KmTR5K0gWBNDCaWCnqlNIKZYTjF0TbJ44CUFq1DJjWP24Tm62pCQqlsKJQniAAPJ4Ya1 rvIbAd71B4eNZwJ5+6xA/iGZnvQvq+0kXBw5JRwZ5v8jvMMwSaY+w+pWLyRsIg2EX3CC vAkMk7TliIj0Ger575MjV8TOLU2pTC5nJlPNewgAbvzc494VbHqUcZNhk8nXKE9I5IrM emrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-139619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139619-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 m10-20020a170902db0a00b001dcd4f9fd0dsi298918plx.455.2024.04.10.18.26.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 18:26:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139619-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-139619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139619-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 6CE56285579 for ; Thu, 11 Apr 2024 01:26:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19E106311D; Thu, 11 Apr 2024 01:26:27 +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 8120360DD3; Thu, 11 Apr 2024 01:26:26 +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=1712798786; cv=none; b=n3SPRQPdOzsDA/r4BS/ofxTuzXghLEcQFsmbVAvmzAt29sAqNapWT+N+G8TIyeWiTAGPFOpBYffO7POA4DTQK1H2r7e1Zw6cTIYFmuUF8fZwjJIXgjR7jD1meUGQonnTQU3+K0tjCkkQdg/qmslNsLPlo89Jx9hZNpgqOesGvlc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798786; c=relaxed/simple; bh=KPoDWQ9hvCZiBeldTjLP52gzqCk/sQ42RdM0IR1xDk0=; h=Message-ID:Date:From:To:Cc:Subject; b=J8Hk5INFDvTzMT6RuGOcgRvWAEfnzsCEy0lh+P78QaK++AuJyeT0+U89WLxWmzYxwR2WYnUewXiDOCdtfwqu0Cux9IA4yQvnRJ5Htd+sQm/Hu73aHKyBzadsUB1zCdLss4CHwz/yF6eFfufNSWBVBspQpN2uW3qh35V2ZNLfCjc= 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 01537C433F1; Thu, 11 Apr 2024 01:26:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rujFQ-00000000nTy-0sQj; Wed, 10 Apr 2024 21:29:04 -0400 Message-ID: <20240411012541.285904543@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 10 Apr 2024 21:25:41 -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 Subject: [PATCH v2 00/11] tracing: Persistent traces across a reboot or crash Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This is a way to map a ring buffer instance across reboots. The requirement is that you have a memory region that is not erased. I tested this on a Debian VM running on qemu on a Debian server, and even tested it on a baremetal box running Fedora. I was surprised that it worked on the baremetal box, but it does so surprisingly consistently. I changed things up since the POC version (which this is no longer a proof of concept, but now a serious patch set). https://lore.kernel.org/linux-trace-kernel/20240306015910.766510873@goodmis.org/ I got rid of the variables that needed to be set: trace_buffer_start and trace_buffer_size The allocation of the mapping require a new interface (not in this patch set yet, as it will be added for pstore or the wildcard memmap that is under RFC). That is, either a new patch will be added to connect pstore, or if the new wildcard memmap option is accepted, it can be created with: memmap=12M*4096:trace trace_instance=boot_mapped@trace But that is to come later. If you want to test this code, I have the command line version available at: git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git branch: trace/ring-buffer-prealloc The name of the instance no longer defined by the kernel but by the calling code. The memory reserved is used by the ring buffer of this instance. It acts like a memory mapped instance so it has some limitations. It does not allow snapshots nor does it allow tracers which use a snapshot buffer (like irqsoff and wakeup tracers). On boot up, when setting up the ring buffer, it looks at the current content and does a vigorous test to see if the content is valid. It even walks the events in all the sub-buffers to make sure the ring buffer meta data is correct. If it determines that the content is valid, it will reconstruct the ring buffer to use the content it has found. If the buffer is valid, on the next boot, the boot_mapped instance will contain the data from the previous boot. You can cat the trace or trace_pipe file, or even run trace-cmd extract on it to make a trace.dat file that holds the date. This is much better than dealing with a ftrace_dump_on_opps (I wish I had this a decade ago!) There are still some limitations of this buffer. One is that it assumes that the kernel you are booting back into is the same one that crashed. At least the trace_events (like sched_switch and friends) all have the same ids. This would be true with the same kernel as the ids are determined at link time. Module events could possible be a problem as the ids may not match. This version of the patch series saves a text function and a data string address in the persistent memory, and this is used to calculate the delta between text and data addresses of the new boot up. Now function tracing and "%pS" still work across boots. Even the RCU trace events that point to static strings work as well! The delta is exported by a new file in the instance called "last_boot_info" that has something like this: # cat last_boot_info text delta: -268435456 data delta: -268435456 This can be used by trace-cmd that reads the trace_pipe_raw data and now can figure out how to map the print_formats and kallsyms to the raw data in the buffers. This is no longer a POC as it seems to be working as expected. This is based on top of Vincent Donnefort's ring buffer user space mapping code: https://lore.kernel.org/linux-trace-kernel/20240406173649.3210836-1-vdonnefort@google.com/ Enjoy... Steven Rostedt (Google) (11): ring-buffer: Allow mapped field to be set without mapping ring-buffer: Add ring_buffer_alloc_range() ring-buffer: Add ring_buffer_meta data tracing: Implement creating an instance based on a given memory region ring-buffer: Add output of ring buffer meta page ring-buffer: Add test if range of boot buffer is valid ring-buffer: Validate boot range memory events ring-buffer: Save text and data locations in mapped meta data tracing/ring-buffer: Add last_boot_info file to boot instance tracing: Handle old buffer mappings for event strings and functions tracing: Update function tracing output for previous boot buffer ---- include/linux/ring_buffer.h | 20 ++ kernel/trace/ring_buffer.c | 837 ++++++++++++++++++++++++++++++++++++++++---- kernel/trace/trace.c | 167 ++++++++- kernel/trace/trace.h | 7 + kernel/trace/trace_output.c | 9 +- 5 files changed, 953 insertions(+), 87 deletions(-)