Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4996940rdb; Tue, 12 Dec 2023 16:08:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2PJLf5gp9lo53m2+lAwz+PFPHglhSx4y/PRIUyJfALdLI0IQeV1323zp8tNQcEOeyrPwN X-Received: by 2002:a05:6e02:1d0c:b0:35d:5cfd:3eb2 with SMTP id i12-20020a056e021d0c00b0035d5cfd3eb2mr11248161ila.0.1702426106662; Tue, 12 Dec 2023 16:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702426106; cv=none; d=google.com; s=arc-20160816; b=jqi8lffmk7ubNzoytuMkmu0ng9L9eQ1B5k5TFZ6rYiG7nKcRtgXoHzFyKCIdqwI+zZ MtUsz9U2lH9lQ5HHKaz76j9htvKKJueckeWCnFop6H7sp95B0zmPvUL1Mec5tgPmobSA F30pIeNUhH7krhbmMe90XgohNzz3KkHQpSAHgRoi5yuZOJYE9CvRQL/3wcO4r3rzpXcV d2E1FdaUQI85UpilQSGT+6wOGkY81LmIqRvyG+RC6qiaGu3GByvBN1dwYv8RCYlwre8n qCwQ/Lac91VdNPgpeK2L9O1sTyZELXDxZcWsHaBLKW7scrhzdS59FlFCIpqmgrpZ6Swd MbDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ijxY/skruFfgxp/KO2yhFBX0a87YYNVgJHNp25q/K2g=; fh=xprWcyUKTLi4rhte7gFCvduD673j12awuFkCPnYDQVY=; b=nsl6iZO/418GMH49j/vaUxlQ0V9aPUMFYfgAotdXsT/KZyDEFcHFPwrh+tx4Q3NWwa 6DlyclznYi7IgAsmIvBJ379xbwc7BOd/byB5CXgolTf4TLjAuag2L1RZTkVxeV1668HN 8VKQqXHmq5u/lY5yMXIGB2wUyDxc3MvsoSZ0j+JiDq508xkGXtSAHBNb2TZhLE5fykGs Cojxdad2MCZlVujOopCMcg/h9NphMGSsToDzVTlmwOicIcZU2EJL7Y3uLs8PUnFDZxjW DG5NQaVWJTY8EqHYzsxnfzyaQrKIujTL32Ana02wxNBE/YhaNsRJjzjui1GKOkbdSmO0 Uu3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=R7NSmQrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z25-20020a656659000000b005c67791904bsi8119106pgv.777.2023.12.12.16.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 16:08:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=R7NSmQrU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3A43980896A8; Tue, 12 Dec 2023 16:08:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377870AbjLMAH4 (ORCPT + 99 others); Tue, 12 Dec 2023 19:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377876AbjLMAHr (ORCPT ); Tue, 12 Dec 2023 19:07:47 -0500 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF7DC171F; Tue, 12 Dec 2023 16:07:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1702426050; x=1733962050; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ijxY/skruFfgxp/KO2yhFBX0a87YYNVgJHNp25q/K2g=; b=R7NSmQrUAop5SGqsD8840QQUTTgeEG6R8+wfoNYtOjYuIbwvdLvde1VW 5d+VaOun9FxuUzm6mgBiYxJCAbrImxyXOx0apfhi3NCOUk9CjJGeu+nYh HdTUt24cbcxcal1AevcOQhzmzyDXmDfkEkXBCI622UVvK0RppoC1zKDlZ Y=; X-IronPort-AV: E=Sophos;i="6.04,271,1695686400"; d="scan'208";a="50248355" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-00fceed5.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 00:07:28 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-00fceed5.us-east-1.amazon.com (Postfix) with ESMTPS id 96E81A0B0F; Wed, 13 Dec 2023 00:07:20 +0000 (UTC) Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:13591] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.2.31:2525] with esmtp (Farcaster) id d7626d9c-b144-446f-b11a-bed8a3932442; Wed, 13 Dec 2023 00:07:19 +0000 (UTC) X-Farcaster-Flow-ID: d7626d9c-b144-446f-b11a-bed8a3932442 Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 13 Dec 2023 00:07:19 +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; Wed, 13 Dec 2023 00:07:15 +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 14/15] tracing: Recover trace events from kexec handover Date: Wed, 13 Dec 2023 00:04:51 +0000 Message-ID: <20231213000452.88295-15-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213000452.88295-1-graf@amazon.com> References: <20231213000452.88295-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.253.83.51] X-ClientProxiedBy: EX19D037UWB002.ant.amazon.com (10.13.138.121) To EX19D020UWC004.ant.amazon.com (10.13.138.149) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 16:08:23 -0800 (PST) This patch implements all logic necessary to match a new trace event that we add against preserved trace events from kho. If we find a match, we give the new trace event the old event's identifier. That way, trace read-outs are able to make sense of buffer contents again because the parsing code for events looks at the same identifiers. Signed-off-by: Alexander Graf --- kernel/trace/trace_output.c | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 113de40c616f..d2e2a6346322 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -749,6 +749,67 @@ void trace_event_read_unlock(void) up_read(&trace_event_sem); } +/** + * trace_kho_fill_event_type - restore event type info from KHO + * @event: the event type to enumerate + * + * Event types are semi-dynamically generated. To ensure that + * their identifiers match before and after kexec with KHO, + * let's match up unique name identifiers and fill in the + * respective ID information if we booted with KHO. + */ +static bool trace_kho_fill_event_type(struct trace_event *event) +{ +#ifdef CONFIG_FTRACE_KHO + const char *path = "/ftrace/events"; + void *fdt = kho_get_fdt(); + int err, len, off, id; + const void *p; + + if (!fdt) + return false; + + if (WARN_ON(!event->name)) + return false; + + pr_debug("Trying to revive event '%s'", event->name); + + off = fdt_path_offset(fdt, path); + if (off < 0) { + pr_debug("Could not find '%s' in DT", path); + return false; + } + + err = fdt_node_check_compatible(fdt, off, "ftrace,events-v1"); + if (err) { + pr_warn("Node '%s' has invalid compatible", path); + return false; + } + + p = fdt_getprop(fdt, off, event->name, &len); + if (!p) { + pr_warn("Event '%s' not found", event->name); + return false; + } + + if (len != sizeof(event->type)) { + pr_warn("Event '%s' has invalid length", event->name); + return false; + } + + id = *(const u32 *)p; + + /* Mark ID as in use */ + if (ida_alloc_range(&trace_event_ida, id, id, GFP_KERNEL) != id) + return false; + + event->type = id; + return true; +#endif + + return false; +} + /** * register_trace_event - register output for an event type * @event: the event type to register @@ -777,7 +838,9 @@ int register_trace_event(struct trace_event *event) if (WARN_ON(!event->funcs)) goto out; - if (!event->type) { + if (trace_kho_fill_event_type(event)) { + pr_debug("Recovered '%s' as id=%d", event->name, event->type); + } else if (!event->type) { event->type = alloc_trace_event_type(); if (!event->type) goto out; -- 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