Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp48685lqq; Wed, 12 Jun 2024 16:20:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOq7M2L9JeHg50+HYq/MWtccmwFibKoHV0UwX3YEgQaLNzS91ftJuig+2nQbka601iLcO1+ENNtGox2vCae8PPTIXLPZWtKeuJlPqyTw== X-Google-Smtp-Source: AGHT+IEGVJQ0gvuwmLrMmhNPvZQG0r/kUWNLhozbMJt9Ik8pHX0XMVtdhgTHi1gHdL5kg2Ty0x6O X-Received: by 2002:a05:6a20:3d84:b0:1af:4faf:e4a8 with SMTP id adf61e73a8af0-1b8a9b8c0a7mr3627296637.33.1718234425796; Wed, 12 Jun 2024 16:20:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718234425; cv=pass; d=google.com; s=arc-20160816; b=g4+svkxvWe24bilYbWf8w8VJrFDVX8DRwod2GUzgsoObZuEzFqiMeQ/h5ZNVO+DZmE 4nosHTe1qb+kIaD/UuqXJAcy7RYC8Dmw13j9a3fgRuVtk1Pra4Avz1SrYL2NiMciIBgP nbmaQ2D3is5rCg+x5erbL9prmjEvKaFzbZ6qnPL/gL+6tE78kFys8P+KSylmegGvQRfi c8CEnKW2zgxovwJApRGsYR8Oy7VHTwJXDbj8qhujSIn4LvIt2ZcOchcwPESYvRHgI9E8 GQP3YcoaA/GoZ/xd1LMgmYyfZ0ugurvnpL47qULm91OtAQ/Slhg8cTTakUxKwEDntkCs rI4w== 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=VfDiamoAWOkdiK2DnlBq4U3JDZdJumVi6dwfG63t8pk=; fh=VQi8WXJrSHXxsfwqC9oAfi6LEiQC0Qv/w+aqrHCHJLs=; b=ArgiAYXoOzefL4QqYzIveJ+co32/LhtllIOn9zFlVhM1R3MetJrO6lB2bRjjEbPsNq jcmNeqfD+decPOedt719baI/aDZ9o1Jjs9kxWV4BUOfHRxSUs/LQpE3P4acsFt5Z6Q5+ x3rVM33ZF+FPfA1E987O1N4N2eBgp1FdQeGIOK1vbbYPnKUAwdqug0s7lGcJy9Xe96FO IzJmzWOB7qMTLlc9SliJY7n+n7lMCvK0lideTLV3R5yon6nfwOweyg21Tvd4H5vCqV/j SW6Dqyg08moZmSz0lJmOFfB+QAz51d+T3sDnqvOtBbmVdaaiyetfso/qo82lGTbpzFaL sFnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-212363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212363-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 41be03b00d2f7-6fee310d27esi57916a12.421.2024.06.12.16.20.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 16:20:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212363-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-212363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212363-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 627EA2847BD for ; Wed, 12 Jun 2024 23:20:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D2D512D770; Wed, 12 Jun 2024 23:20:07 +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 DFB9912CD9C; Wed, 12 Jun 2024 23:20:06 +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=1718234406; cv=none; b=Brpqx01tDYPL/YyP11w6ocItxBZ5Eldx/CFlQWpXlkY39mSi99CcPZ1isAsCaPfBDIZ6tNHBU7keJCQ+nzZb3Vyt1j2iwdDKCDGeyOM2LRLlgC7HiefQqA3n4Zws6F+7wPL9MtY0Ped+CwENpZ1PrQVUcz+KPff+WPIrSBCDW58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718234406; c=relaxed/simple; bh=9izWBiUn4btPp4JKk//NvRQngzq37tS1fZLVd3/TOF0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=QIdprIkCaBdxdraOLfXoR9famP9kwApFtjdwYdRayR95dGiEvUdmdKxc32AFCW4LZiJGP1vhuzyYbM6NvBAG9WKaqj6SMR+GdU5ivP+VQZFEEPCa2fNJN2RARSIRZ3FrY67syKGVFySEwY6BpxcGaJN0+bEd2a+iPYUAfGvVWE0= 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 98483C4AF62; Wed, 12 Jun 2024 23:20:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sHXGT-00000001dby-3Uin; Wed, 12 Jun 2024 19:20:25 -0400 Message-ID: <20240612232025.692086240@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 12 Jun 2024 19:19: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 v6 04/13] tracing: Implement creating an instance based on a given memory region References: <20240612231934.608252486@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)" Allow for creating a new instance by passing in an address and size to map the ring buffer for the instance to. This will allow features like a pstore memory mapped region to be used for an tracing instance ring buffer that can be retrieved from one boot to the next. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 50 +++++++++++++++++++++++++++++++++++--------- kernel/trace/trace.h | 6 +++++- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 578a49ff5c32..ff2b504fbe00 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4921,6 +4921,11 @@ static int tracing_open(struct inode *inode, struct file *file) static bool trace_ok_for_array(struct tracer *t, struct trace_array *tr) { +#ifdef CONFIG_TRACER_SNAPSHOT + /* arrays with mapped buffer range do not have snapshots */ + if (tr->range_addr_start && t->use_max_tr) + return false; +#endif return (tr->flags & TRACE_ARRAY_FL_GLOBAL) || t->allow_instances; } @@ -8664,11 +8669,13 @@ tracing_init_tracefs_percpu(struct trace_array *tr, long cpu) tr, cpu, &tracing_entries_fops); #ifdef CONFIG_TRACER_SNAPSHOT - trace_create_cpu_file("snapshot", TRACE_MODE_WRITE, d_cpu, - tr, cpu, &snapshot_fops); + if (!tr->range_addr_start) { + trace_create_cpu_file("snapshot", TRACE_MODE_WRITE, d_cpu, + tr, cpu, &snapshot_fops); - trace_create_cpu_file("snapshot_raw", TRACE_MODE_READ, d_cpu, - tr, cpu, &snapshot_raw_fops); + trace_create_cpu_file("snapshot_raw", TRACE_MODE_READ, d_cpu, + tr, cpu, &snapshot_raw_fops); + } #endif } @@ -9205,7 +9212,18 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size buf->tr = tr; - buf->buffer = ring_buffer_alloc(size, rb_flags); + if (tr->range_addr_start && tr->range_addr_size) { + buf->buffer = ring_buffer_alloc_range(size, rb_flags, 0, + tr->range_addr_start, + tr->range_addr_size); + /* + * This is basically the same as a mapped buffer, + * with the same restrictions. + */ + tr->mapped++; + } else { + buf->buffer = ring_buffer_alloc(size, rb_flags); + } if (!buf->buffer) return -ENOMEM; @@ -9242,6 +9260,10 @@ static int allocate_trace_buffers(struct trace_array *tr, int size) return ret; #ifdef CONFIG_TRACER_MAX_TRACE + /* Fix mapped buffer trace arrays do not have snapshot buffers */ + if (tr->range_addr_start) + return 0; + ret = allocate_trace_buffer(tr, &tr->max_buffer, allocate_snapshot ? size : 1); if (MEM_FAIL(ret, "Failed to allocate trace buffer\n")) { @@ -9342,7 +9364,9 @@ static int trace_array_create_dir(struct trace_array *tr) } static struct trace_array * -trace_array_create_systems(const char *name, const char *systems) +trace_array_create_systems(const char *name, const char *systems, + unsigned long range_addr_start, + unsigned long range_addr_size) { struct trace_array *tr; int ret; @@ -9368,6 +9392,10 @@ trace_array_create_systems(const char *name, const char *systems) goto out_free_tr; } + /* Only for boot up memory mapped ring buffers */ + tr->range_addr_start = range_addr_start; + tr->range_addr_size = range_addr_size; + tr->trace_flags = global_trace.trace_flags & ~ZEROED_TRACE_FLAGS; cpumask_copy(tr->tracing_cpumask, cpu_all_mask); @@ -9425,7 +9453,7 @@ trace_array_create_systems(const char *name, const char *systems) static struct trace_array *trace_array_create(const char *name) { - return trace_array_create_systems(name, NULL); + return trace_array_create_systems(name, NULL, 0, 0); } static int instance_mkdir(const char *name) @@ -9479,7 +9507,7 @@ struct trace_array *trace_array_get_by_name(const char *name, const char *system goto out_unlock; } - tr = trace_array_create_systems(name, systems); + tr = trace_array_create_systems(name, systems, 0, 0); if (IS_ERR(tr)) tr = NULL; @@ -9672,8 +9700,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 - trace_create_file("snapshot", TRACE_MODE_WRITE, d_tracer, - tr, &snapshot_fops); + if (!tr->range_addr_start) { + trace_create_file("snapshot", TRACE_MODE_WRITE, d_tracer, + tr, &snapshot_fops); + } #endif trace_create_file("error_log", TRACE_MODE_WRITE, d_tracer, diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 749a182dab48..5dd48932509c 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -336,7 +336,6 @@ struct trace_array { bool allocated_snapshot; spinlock_t snapshot_trigger_lock; unsigned int snapshot; - unsigned int mapped; unsigned long max_latency; #ifdef CONFIG_FSNOTIFY struct dentry *d_max_latency; @@ -344,6 +343,11 @@ struct trace_array { struct irq_work fsnotify_irqwork; #endif #endif + /* The below is for memory mapped ring buffer */ + unsigned int mapped; + unsigned long range_addr_start; + unsigned long range_addr_size; + struct trace_pid_list __rcu *filtered_pids; struct trace_pid_list __rcu *filtered_no_pids; /* -- 2.43.0