Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1014922rdb; Fri, 22 Dec 2023 11:40:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0E3RcZgcAEiTWBg1+ABk4wn3MUIiDVJBYe6udSyqMeTULWjpEKAPMHLySU8crWbM0VDU/ X-Received: by 2002:a05:6830:217:b0:6db:8c4e:5769 with SMTP id em23-20020a056830021700b006db8c4e5769mr1951160otb.56.1703274045763; Fri, 22 Dec 2023 11:40:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703274045; cv=none; d=google.com; s=arc-20160816; b=j3/cAqvrZIXjM/tpZkzixsCdEv1wZZwScgvOV+2Afnft4QFdz93NjikZephbb1ZOw1 t0CiXtRLW8h0ra8t0AKhC1xhPzf24pH+71pKlf1CQ6alNVLhosXQlY6cUToK2zDZGyzP /HVfUr5VSFlsGSv9rj10snnpjVHvzVN7ud+tYcmqOtA4Hhhn0MpOeRnWFwcsXPQI8rI3 +5BK0W+RdAHCgPZNi6x7g33N/aMDGLq16XhfWIO8Ce4xejN0khUCkcYkNAqoRXSugi0p gRLfKjzrapUSt61+8FbjD8rJsA+9vofVQJvizCkHme3rbuSSun85Z4ZSMj/YNQ5+PX91 MFBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dwhP9TX+qhNuxIBvRPP4G1COkpJHtM0yxRM6jOIEYyk=; fh=xprWcyUKTLi4rhte7gFCvduD673j12awuFkCPnYDQVY=; b=wHkxAMn4ygMhR8P+mv0CudKCfMOFYYjS1/h7Wt/eJyoHjYSlV25qU7lfBBgicGUc4M Np0HmsY4KcqW7UReso08859lzn/FzmxT6mTd6V5TVijJFRd+gVDoa4+iB/j952W2zFBh sIi6tJOTHkTBH2TnfPro7zjZ6fwNkKS+V7VbmIqdRh0bvCtXgopK5SiV4kmHnWFIdCKV 3FpQX0sH5tECk7rKufJMjDbSDEXTEwdTICvfsbJezhoQKeRxmNcn8OOTDNyvkBAA/wK7 igfWD3XXV6F6QBWmHg1SQqRThs6EXbCC0gZwaI9SuMceppVmKjjeTVUNAbA8h+vAJw/Z 5HHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Nc+djFcL; spf=pass (google.com: domain of linux-kernel+bounces-10025-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10025-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n127-20020a632785000000b005cdfdcc946dsi661220pgn.512.2023.12.22.11.40.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 11:40:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10025-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Nc+djFcL; spf=pass (google.com: domain of linux-kernel+bounces-10025-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10025-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 97511B21701 for ; Fri, 22 Dec 2023 19:39:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 468012F845; Fri, 22 Dec 2023 19:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Nc+djFcL" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) (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 1AFCB2EAFB; Fri, 22 Dec 2023 19:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1703273882; x=1734809882; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dwhP9TX+qhNuxIBvRPP4G1COkpJHtM0yxRM6jOIEYyk=; b=Nc+djFcLtOo1/jrRWNhcnyN36l9OooUXEchfkaUJkwzb4hlHwHWJtSQG rt51UPPkILwo+2859r+K9vwkQCIUe02+qdqo2a3kzgdIKXuJ0cb23zSyl gRxssphazQFfBVlXb/Ib1gEuKxmunfHOGPdyQXy0czncBDwxm2bFpP59b 8=; X-IronPort-AV: E=Sophos;i="6.04,297,1695686400"; d="scan'208";a="262157740" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-1box-2bm6-32cf6363.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 19:38:00 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-1box-2bm6-32cf6363.us-west-2.amazon.com (Postfix) with ESMTPS id BDB358B25B; Fri, 22 Dec 2023 19:37:58 +0000 (UTC) Received: from EX19MTAUWB002.ant.amazon.com [10.0.7.35:5256] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.6.144:2525] with esmtp (Farcaster) id ce48a30f-05bb-48a3-9e16-f52e7034e6f9; Fri, 22 Dec 2023 19:37:58 +0000 (UTC) X-Farcaster-Flow-ID: ce48a30f-05bb-48a3-9e16-f52e7034e6f9 Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 22 Dec 2023 19:37:58 +0000 Received: from dev-dsk-graf-1a-5ce218e4.eu-west-1.amazon.com (10.253.83.51) by EX19D020UWC004.ant.amazon.com (10.13.138.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 22 Dec 2023 19:37:54 +0000 From: Alexander Graf To: CC: , , , , , , , Eric Biederman , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Rob Herring" , Steven Rostedt , "Andrew Morton" , Mark Rutland , "Tom Lendacky" , Ashish Kalra , James Gowans , Stanislav Kinsburskii , , , , Anthony Yznaga , Usama Arif , David Woodhouse , Benjamin Herrenschmidt Subject: [PATCH v2 10/17] tracing: Initialize fields before registering Date: Fri, 22 Dec 2023 19:36:00 +0000 Message-ID: <20231222193607.15474-11-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231222193607.15474-1-graf@amazon.com> References: <20231222193607.15474-1-graf@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D041UWA004.ant.amazon.com (10.13.139.9) To EX19D020UWC004.ant.amazon.com (10.13.138.149) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit With KHO, we need to know all event fields before we allocate an event type for a trace event so that we can recover it based on a previous execution context. Before this patch, fields were only initialized after we allocated a type id. After this patch, we try to allocate it early as well. This patch leaves the old late initialization logic in place. The field init code already validates whether there are any fields present, which means it's legal to call it multiple times. This way we're sure we don't miss any call sites. Signed-off-by: Alexander Graf --- include/linux/trace_events.h | 1 + kernel/trace/trace_events.c | 14 +++++++++----- kernel/trace/trace_events_synth.c | 14 +++++++++----- kernel/trace/trace_events_user.c | 4 ++++ kernel/trace/trace_probe.c | 4 ++++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index d68ff9b1247f..8fe8970b48e3 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -842,6 +842,7 @@ extern int trace_define_field(struct trace_event_call *call, const char *type, extern int trace_add_event_call(struct trace_event_call *call); extern int trace_remove_event_call(struct trace_event_call *call); extern int trace_event_get_offsets(struct trace_event_call *call); +extern int trace_event_define_fields(struct trace_event_call *call); int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set); int trace_set_clr_event(const char *system, const char *event, int set); diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index f29e815ca5b2..fbf8be1d2806 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -462,6 +462,11 @@ static void test_event_printk(struct trace_event_call *call) int trace_event_raw_init(struct trace_event_call *call) { int id; + int ret; + + ret = trace_event_define_fields(call); + if (ret) + return ret; id = register_trace_event(&call->event); if (!id) @@ -2402,8 +2407,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name, return NULL; } -static int -event_define_fields(struct trace_event_call *call) +int trace_event_define_fields(struct trace_event_call *call) { struct list_head *head; int ret = 0; @@ -2592,7 +2596,7 @@ event_create_dir(struct eventfs_inode *parent, struct trace_event_file *file) file->ei = ei; - ret = event_define_fields(call); + ret = trace_event_define_fields(call); if (ret < 0) { pr_warn("Could not initialize trace point events/%s\n", name); return ret; @@ -2978,7 +2982,7 @@ __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr) if (eventdir_initialized) return event_create_dir(tr->event_dir, file); else - return event_define_fields(call); + return trace_event_define_fields(call); } static void trace_early_triggers(struct trace_event_file *file, const char *name) @@ -3015,7 +3019,7 @@ __trace_early_add_new_event(struct trace_event_call *call, if (!file) return -ENOMEM; - ret = event_define_fields(call); + ret = trace_event_define_fields(call); if (ret) return ret; diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index 846e02c0fb59..4db41218ccf7 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -880,17 +880,21 @@ static int register_synth_event(struct synth_event *event) INIT_LIST_HEAD(&call->class->fields); call->event.funcs = &synth_event_funcs; call->class->fields_array = synth_event_fields_array; + call->flags = TRACE_EVENT_FL_TRACEPOINT; + call->class->reg = trace_event_reg; + call->class->probe = trace_event_raw_event_synth; + call->data = event; + call->tp = event->tp; + + ret = trace_event_define_fields(call); + if (ret) + goto out; ret = register_trace_event(&call->event); if (!ret) { ret = -ENODEV; goto out; } - call->flags = TRACE_EVENT_FL_TRACEPOINT; - call->class->reg = trace_event_reg; - call->class->probe = trace_event_raw_event_synth; - call->data = event; - call->tp = event->tp; ret = trace_add_event_call(call); if (ret) { diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c index 9365ce407426..b9837e987525 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1900,6 +1900,10 @@ static int user_event_trace_register(struct user_event *user) { int ret; + ret = trace_event_define_fields(&user->call); + if (ret) + return ret; + ret = register_trace_event(&user->call.event); if (!ret) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 4dc74d73fc1d..da73a02246d8 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1835,6 +1835,10 @@ int trace_probe_register_event_call(struct trace_probe *tp) trace_probe_name(tp))) return -EEXIST; + ret = trace_event_define_fields(call); + if (ret) + return ret; + ret = register_trace_event(&call->event); if (!ret) return -ENODEV; -- 2.40.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879