Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp937404lqs; Fri, 14 Jun 2024 09:43:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVG5HvX6SZ/1l1QsdJqNv+Mi8EsdX7W313UUkhI/oFxyA3VoKPje+bgXrdb/J6BHUiwYKt5s6ptsSyXTPqVnwl9wsanLFX/PN1nCMuJFg== X-Google-Smtp-Source: AGHT+IGDxtlXszfn+yznXONaKvpEuFegQOCGSXm/BP5HuZVoTju4veoCPJ7eGw4chkqcPzrMsKXJ X-Received: by 2002:a17:902:e5c9:b0:1f5:e796:f26d with SMTP id d9443c01a7336-1f8625c16b0mr34991105ad.3.1718383401219; Fri, 14 Jun 2024 09:43:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718383401; cv=pass; d=google.com; s=arc-20160816; b=u2BCdQwQSTplSURblpW8JZAVcRp0pxxxmXOfMCRJKh8AB0+coGRS4T2QJJ0Ld5ST2D HaepvMFzm1WaM6duLRXSHLfgt9hDMMu0lx7Pol9Q9FCGCAYx6R1J3vJeJAkdlubOHxJj M7xIIkzWgqJ6dU23LZIZhSFIJhxH2NTSzMynEf7HDttUqUyJt7ayiOH5/sxqguk4sK0D FXMR9WjeqJfCousMhEBBpO8xuvdA0qvllOJWEYpZdnvf9XqhXx+FKQL14rqvor3se5fj +vWubmAZS9x3Jnv8AGO/PD+jwQiuw30HSh4+6qbu2J5KLokvA3XTAJJGCrR9nn/2EyRd 58jg== 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=PLc42HZgdgi2upNcPOpT66sNRkGtdUALY/nBgF9ZDlM=; fh=I4e9yJ7BaAsllzPNkUeXv9TYH5MglgJtJt86EB805OA=; b=PcrCcK9hx05SYCMmc3mf7cYd2P9xS4d2Ui/nelosz2Lkn0qLyz4ryl9HfGowJpSTx/ 7VJheDIL5auph1V72tapn+ztTHT+GNfTQkrAqkL34WekF9awixRiJ16XrjLkHzNfizjP St4TCnGpA1LMY66r+XEZ6nE4KOSXaa5Xxvjk+V6oMFyfE4fR89x3c6C7FSnSo78jOrnX rByFik31MZ7C23A6+xbzUOIOAlZKpnXOG09H5JZ/CFRYcpic5Da1Lgra8h6dsVQiYjPA Mbi8keY1I2l95FHSmvyGfdMISx4Ev91KcIIRTped43tUpQcGcaZfdO9tyZuDvIMTqpOK bFrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-215257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215257-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 d9443c01a7336-1f855e55471si38661515ad.181.2024.06.14.09.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 09:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215257-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-215257-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215257-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 2BD4C28A0E1 for ; Fri, 14 Jun 2024 16:33:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5EAB1A38D4; Fri, 14 Jun 2024 16:30:53 +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 2F5AD199398 for ; Fri, 14 Jun 2024 16:30:49 +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=1718382649; cv=none; b=h5c5pDDJAqjyMjM5V4GQO6nt7v2XP8VHLLT3fWe9T2w2FRSgIbwn6cetah81MaxXn8Nbl9Mpoyo3nvOHLxc7yXLqkpjTjFC7/EU6GXBo7cJ8+8sF9GobGeN6LhpeA10wMItQq6rRffFBz6JkuMgPL+c2CX656grSsg00Jl9Rtlg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718382649; c=relaxed/simple; bh=ZHBXI+jB6jbRohzJeTq5RKkD6KRiROjXJbEJFW5LzTw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=G22ANm0H/8UDSVJQDKU9UQLbm03HqtTvg47qI11exvy9N+CuGb+/cRsFXFHrFWdNll1FjJRkIIkaaNRFRd7IL+F8Mfd4/dmOZ+UwN7FFpaCGk1B7CGTwO2bOjYgtZb0uxSLWGGW+gKBKEqgYgWzg/w1oOs86Mh08LzAZRalktDg= 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 053E0C4AF48; Fri, 14 Jun 2024 16:30:49 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sI9pY-00000001ruQ-0PDS; Fri, 14 Jun 2024 12:31:12 -0400 Message-ID: <20240614163111.956572328@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 14 Jun 2024 12:30:26 -0400 From: Steven Rostedt To: linux-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 , 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: [for-next][PATCH 11/13] tracing: Handle old buffer mappings for event strings and functions References: <20240614163015.456541709@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)" Use the saved text_delta and data_delta of a persistent memory mapped ring buffer that was saved from a previous boot, and use the delta in the trace event print output so that strings and functions show up normally. That is, for an event like trace_kmalloc() that prints the callsite via "%pS", if it used the address saved in the ring buffer it will not match the function that was saved in the previous boot if the kernel remaps itself between boots. For RCU events that point to saved static strings where only the address of the string is saved in the ring buffer, it too will be adjusted to point to where the string is on the current boot. Link: https://lkml.kernel.org/r/20240612232026.821020753@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Vincent Donnefort Cc: Joel Fernandes Cc: Daniel Bristot de Oliveira Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Vineeth Pillai Cc: Youssef Esmat Cc: Beau Belgrave Cc: Alexander Graf Cc: Baoquan He Cc: Borislav Petkov Cc: "Paul E. McKenney" Cc: David Howells Cc: Mike Rapoport Cc: Dave Hansen Cc: Tony Luck Cc: Guenter Roeck Cc: Ross Zwisler Cc: Kees Cook Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index dc4eee33d920..71cca10581d6 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3671,8 +3671,11 @@ static void test_can_verify(void) void trace_check_vprintf(struct trace_iterator *iter, const char *fmt, va_list ap) { + long text_delta = iter->tr->text_delta; + long data_delta = iter->tr->data_delta; const char *p = fmt; const char *str; + bool good; int i, j; if (WARN_ON_ONCE(!fmt)) @@ -3691,7 +3694,10 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt, j = 0; - /* We only care about %s and variants */ + /* + * We only care about %s and variants + * as well as %p[sS] if delta is non-zero + */ for (i = 0; p[i]; i++) { if (i + 1 >= iter->fmt_size) { /* @@ -3720,6 +3726,11 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt, } if (p[i+j] == 's') break; + + if (text_delta && p[i+1] == 'p' && + ((p[i+2] == 's' || p[i+2] == 'S'))) + break; + star = false; } j = 0; @@ -3733,6 +3744,24 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt, iter->fmt[i] = '\0'; trace_seq_vprintf(&iter->seq, iter->fmt, ap); + /* Add delta to %pS pointers */ + if (p[i+1] == 'p') { + unsigned long addr; + char fmt[4]; + + fmt[0] = '%'; + fmt[1] = 'p'; + fmt[2] = p[i+2]; /* Either %ps or %pS */ + fmt[3] = '\0'; + + addr = va_arg(ap, unsigned long); + addr += text_delta; + trace_seq_printf(&iter->seq, fmt, (void *)addr); + + p += i + 3; + continue; + } + /* * If iter->seq is full, the above call no longer guarantees * that ap is in sync with fmt processing, and further calls @@ -3751,6 +3780,14 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt, /* The ap now points to the string data of the %s */ str = va_arg(ap, const char *); + good = trace_safe_str(iter, str, star, len); + + /* Could be from the last boot */ + if (data_delta && !good) { + str += data_delta; + good = trace_safe_str(iter, str, star, len); + } + /* * If you hit this warning, it is likely that the * trace event in question used %s on a string that @@ -3760,8 +3797,7 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt, * instead. See samples/trace_events/trace-events-sample.h * for reference. */ - if (WARN_ONCE(!trace_safe_str(iter, str, star, len), - "fmt: '%s' current_buffer: '%s'", + if (WARN_ONCE(!good, "fmt: '%s' current_buffer: '%s'", fmt, seq_buf_str(&iter->seq.seq))) { int ret; -- 2.43.0