From patchwork Fri Dec 22 19:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 13503763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86D0BC41535 for ; Fri, 22 Dec 2023 19:53:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24DEF6B006E; Fri, 22 Dec 2023 14:53:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FC5C6B0082; Fri, 22 Dec 2023 14:53:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 075ED8D0013; Fri, 22 Dec 2023 14:53:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E6AD78D0012 for ; Fri, 22 Dec 2023 14:53:18 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AF87C80802 for ; Fri, 22 Dec 2023 19:53:18 +0000 (UTC) X-FDA: 81595503276.09.EEFA625 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by imf02.hostedemail.com (Postfix) with ESMTP id A042A80014 for ; Fri, 22 Dec 2023 19:53:16 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=Sz5pvVqw; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf02.hostedemail.com: domain of "prvs=71347c2e1=graf@amazon.de" designates 99.78.197.217 as permitted sender) smtp.mailfrom="prvs=71347c2e1=graf@amazon.de" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703274796; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MGZgj7MpJhCqNq0rnds5z2tkCyQdgvCc34iYycu1T5U=; b=w8i7ZhaausINYlFStgF0m1b5ZUvPx+gv/ObABx1T4jtNYIPgSbv0sF0F+rS1TgwjGntFoo fHyBevl2jbHX0u0G4D8H8YKEjLtW44vBuRd1Low+h5uUMtMG6v216/UpF8QScwhptROdi7 K9r9Etbxvf6WpZ+JfNTLRWcIUhQ7HL0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=Sz5pvVqw; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf02.hostedemail.com: domain of "prvs=71347c2e1=graf@amazon.de" designates 99.78.197.217 as permitted sender) smtp.mailfrom="prvs=71347c2e1=graf@amazon.de" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703274796; a=rsa-sha256; cv=none; b=DKXuNL4QwQy5S2JgwLp16ADF8TSkHpkWJRctWOCLFiKpR9WZyKyG96ewx1Natu0AZayov6 OgyKjrDanHkf5ARFilyo6nv5TlP/MrQuJET3Srd262eZLcbeFVb3G/tCg0x4+0qiAbTLUB 8qsI6UU7pI5qLTTGYzh6FQav+Gi4XiI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1703274796; x=1734810796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MGZgj7MpJhCqNq0rnds5z2tkCyQdgvCc34iYycu1T5U=; b=Sz5pvVqw2jRMXcD7bK9fBooL/swI6tGg7WHUWgQaTm0j95V/Do9hB4uT rXaPm6HaD8ygNZHEoanX49YY6L8qR749qUMVN6FfodOOiAdElW4PUCCBh TDtM+L65xiPrSKgsSSw5DJWNVZgCKUgeAeRKC06prUuznm/+XMzMLO3om A=; X-IronPort-AV: E=Sophos;i="6.04,297,1695686400"; d="scan'208";a="261447211" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-7dc0ecf1.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 19:53:13 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan2.iad.amazon.com [10.32.235.34]) by email-inbound-relay-iad-1e-m6i4x-7dc0ecf1.us-east-1.amazon.com (Postfix) with ESMTPS id 506F080944; Fri, 22 Dec 2023 19:53:06 +0000 (UTC) Received: from EX19MTAUWA002.ant.amazon.com [10.0.38.20:4780] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.47.55:2525] with esmtp (Farcaster) id d8dd3a1b-7891-4d9e-b0b4-b1661fc60c63; Fri, 22 Dec 2023 19:53:05 +0000 (UTC) X-Farcaster-Flow-ID: d8dd3a1b-7891-4d9e-b0b4-b1661fc60c63 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; Fri, 22 Dec 2023 19:53:04 +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:53:00 +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 14/17] tracing: Add kho serialization of trace events Date: Fri, 22 Dec 2023 19:51:41 +0000 Message-ID: <20231222195144.24532-9-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231222195144.24532-1-graf@amazon.com> References: <20231222193607.15474-1-graf@amazon.com> <20231222195144.24532-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.253.83.51] X-ClientProxiedBy: EX19D036UWB004.ant.amazon.com (10.13.139.170) To EX19D020UWC004.ant.amazon.com (10.13.138.149) X-Rspam-User: X-Stat-Signature: 83611zjbk3zcmwo6i6fbopt4i5ghqksk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A042A80014 X-HE-Tag: 1703274796-521237 X-HE-Meta: U2FsdGVkX18NH76vkp1RcahPoLJkbLi6W1ydcaArJKk+iOZf7XFkxQbOL6BuU7PXHmhCNIqlBsa3xdiUE6plyt0otKQtgu7i3dOa5CyCOWJcW49N0RovwhWCyuCBhMm88WThuhzQ8Qje2ExykOiOjIH5iOcGYGENVT9TjU6GYqPwUXvNil8JMh5LUjahBArM7LrUg2oU7oOSeIt8AN9GZwxIse230FBfCw6VcPIaGqXGFO4Tu833uvzLtiLiDYOcRwWHUCtbFV+t+uNTVXsfA8ECuDNj+CVrF6EpIKTUK00zH6FGfOA4qISXxVnNwxrW0J8qjUZCWIEDD0am7u+2kKBz9TwsgIdaBqKKgFvHbewquHx8KYAUnZcZ+/Bd0VE29rMna07Y+4wS8lK3Zs02bXOCZL1wTK7MtLujnLnWirAPIIYLfWYjRdvRDNIwEtDc6H5bDO+ZxfXoG8IzdG6cGn6MeB0g/fVzVXjI4/mxeoFfEOIyCiiSeEDaUMIb03xVux8ZhG37J+kNDA9G8CeL1qzl39/GJ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mGk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Events and thus their parsing handle in ftrace have dynamic IDs that get assigned whenever the event is added to the system. If we want to parse trace events after kexec, we need to link event IDs back to the original trace event that existed before we kexec'ed. There are broadly 2 paths we could take for that: 1) Save full event description across KHO, restore after kexec, merge identical trace events into a single identifier. 2) Recover the ID of post-kexec added events so they get the same ID after kexec that they had before kexec This patch implements the second option. It's simpler and thus less intrusive. However, it means we can not fully parse affected events when the kernel removes or modifies trace events across a kho kexec. Signed-off-by: Alexander Graf --- v1 -> v2: - Leave anything that requires a name in trace.c to keep buffers unnamed entities - Put events as array into a property, use fingerprint instead of names to identify them - Reduce footprint without CONFIG_FTRACE_KHO --- kernel/trace/trace.c | 1 + kernel/trace/trace_output.c | 89 +++++++++++++++++++++++++++++++++++++ kernel/trace/trace_output.h | 5 +++ 3 files changed, 95 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 94e30dfacfd1..b9ce8cf24d02 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -10634,6 +10634,7 @@ static int trace_kho_notifier(struct notifier_block *self, err |= fdt_begin_node(fdt, "ftrace"); err |= fdt_property(fdt, "compatible", compatible, sizeof(compatible)); + err |= trace_kho_write_events(fdt); err |= trace_kho_write_trace_array(fdt, &global_trace); err |= fdt_end_node(fdt); diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 3e7fa44dc2b2..7d8815352e20 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "trace_output.h" @@ -669,6 +671,93 @@ int trace_print_lat_context(struct trace_iterator *iter) return !trace_seq_has_overflowed(s); } +/** + * event2fp - Return fingerprint of an event + * @event: The event to fingerprint + * + * For KHO, we need to match events before and after kexec to recover its type + * id. This function returns a hash that combines an event's name, and all of + * its fields' lengths. + */ +static u32 event2fp(struct trace_event *event) +{ + struct ftrace_event_field *field; + struct trace_event_call *call; + struct list_head *head; + const char *name; + u32 crc32 = ~0; + + /* Low type numbers are static, nothing to checksum */ + if (event->type && event->type < __TRACE_LAST_TYPE) + return event->type; + + call = container_of(event, struct trace_event_call, event); + name = trace_event_name(call); + if (name) + crc32 = crc32_le(crc32, name, strlen(name)); + + head = trace_get_fields(call); + list_for_each_entry(field, head, link) + crc32 = crc32_le(crc32, (char *)&field->size, sizeof(field->size)); + + return crc32; +} + +struct trace_event_map { + u32 crc32; + u32 type; +}; + +static int __maybe_unused _trace_kho_write_events(void *fdt) +{ + struct trace_event_call *call; + int count = __TRACE_LAST_TYPE - 1; + struct trace_event_map *map; + int err = 0; + int i; + + down_read(&trace_event_sem); + /* Allocate an array that we can place all maps into */ + list_for_each_entry(call, &ftrace_events, list) + count++; + + map = vmalloc(count * sizeof(*map)); + if (!map) + return -ENOMEM; + + /* Then fill the array with all crc32 values */ + count = 0; + for (i = 1; i < __TRACE_LAST_TYPE; i++) + map[count++] = (struct trace_event_map) { + .crc32 = count, + .type = count, + }; + + list_for_each_entry(call, &ftrace_events, list) { + struct trace_event *event = &call->event; + + map[count++] = (struct trace_event_map) { + .crc32 = event2fp(event), + .type = event->type, + }; + } + up_read(&trace_event_sem); + + /* And finally write it into a DT variable */ + err |= fdt_property(fdt, "events", map, count * sizeof(*map)); + + vfree(map); + return err; +} + +#ifdef CONFIG_FTRACE_KHO +int trace_kho_write_events(void *fdt) +{ + return _trace_kho_write_events(fdt); +} +#endif + + /** * ftrace_find_event - find a registered event * @type: the type of event to look for diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h index dca40f1f1da4..07481f295436 100644 --- a/kernel/trace/trace_output.h +++ b/kernel/trace/trace_output.h @@ -25,6 +25,11 @@ extern enum print_line_t print_event_fields(struct trace_iterator *iter, extern void trace_event_read_lock(void); extern void trace_event_read_unlock(void); extern struct trace_event *ftrace_find_event(int type); +#ifdef CONFIG_FTRACE_KHO +extern int trace_kho_write_events(void *fdt); +#else +static inline int trace_kho_write_events(void *fdt) { return -EINVAL; } +#endif extern enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags, struct trace_event *event);