From patchwork Wed Dec 13 00:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 13490146 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 9874AC4332F for ; Wed, 13 Dec 2023 00:07:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F6E06B03C5; Tue, 12 Dec 2023 19:07:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AA506B03C6; Tue, 12 Dec 2023 19:07:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DB0F6B03C7; Tue, 12 Dec 2023 19:07:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EE25F6B03C5 for ; Tue, 12 Dec 2023 19:06:59 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D011B40AB8 for ; Wed, 13 Dec 2023 00:06:59 +0000 (UTC) X-FDA: 81559854558.15.C307C34 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by imf29.hostedemail.com (Postfix) with ESMTP id A3B8E120020 for ; Wed, 13 Dec 2023 00:06:57 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=ZBkod8vn; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf29.hostedemail.com: domain of "prvs=704f7accf=graf@amazon.de" designates 99.78.197.218 as permitted sender) smtp.mailfrom="prvs=704f7accf=graf@amazon.de" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702426017; 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=YG4rwMst//uzBl8lCmh1WsDiUmAxsOlA2EWBHH+q6Y0=; b=hCehv6Ad7eSojZSwtijpDw9K3Ou/11OeaPUXDROoCqygbntT39a3qi/UhrZGokAVUieBco /S5eccUpTJJNE8fhC9NFrPa6FQl299xL9ELS8e0vFkmhGMT6F9NgsicvaRMRH8v0q6aPxc JGHBXHXONArKFilndKCn3mvnq/jQwwA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=ZBkod8vn; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf29.hostedemail.com: domain of "prvs=704f7accf=graf@amazon.de" designates 99.78.197.218 as permitted sender) smtp.mailfrom="prvs=704f7accf=graf@amazon.de" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702426017; a=rsa-sha256; cv=none; b=V+Z5D6E7O3WuUCcr8zXTU8cIZSpbY9rPUb/g0pw95UhYCi5LTmk4VnmIvlIJv2EGNPvGKl GkvvAzttXtjrSwYA8SpKZDUsntD9LNaUMsqVfXjX7Lh651TAKkk2gqt173y9VAg3fdUiP8 VIf530/lO6Xea7fKU5NnEHWI95dsREY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1702426018; x=1733962018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YG4rwMst//uzBl8lCmh1WsDiUmAxsOlA2EWBHH+q6Y0=; b=ZBkod8vn6sA9dHhEWtz1kRQZvJTdFsBXS+osxx8h9RCflDvvbGdNSsOK jRX4i4MCEmD/LL/MpuvPMBywPScO3+zWno93v71Zz3FTdRBAGsPPQvOpc WLSLtUKLYfRRpXjS7vzd13YA+VOY2MXEBO5OOZyvAGtr3euXqfoq/VJZi 4=; X-IronPort-AV: E=Sophos;i="6.04,271,1695686400"; d="scan'208";a="259290025" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-m6i4x-ed19f671.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; 13 Dec 2023 00:06:55 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan3.pdx.amazon.com [10.39.38.70]) by email-inbound-relay-pdx-2b-m6i4x-ed19f671.us-west-2.amazon.com (Postfix) with ESMTPS id 69799881F9; Wed, 13 Dec 2023 00:06:53 +0000 (UTC) Received: from EX19MTAUWC002.ant.amazon.com [10.0.38.20:53530] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.18.147:2525] with esmtp (Farcaster) id 28ae9c8f-1014-431a-84b5-e7284b5dddc6; Wed, 13 Dec 2023 00:06:53 +0000 (UTC) X-Farcaster-Flow-ID: 28ae9c8f-1014-431a-84b5-e7284b5dddc6 Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) 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:06:42 +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:06:38 +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 10/15] tracing: Introduce kho serialization Date: Wed, 13 Dec 2023 00:04:47 +0000 Message-ID: <20231213000452.88295-11-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: EX19D036UWB002.ant.amazon.com (10.13.139.139) To EX19D020UWC004.ant.amazon.com (10.13.138.149) X-Rspam-User: X-Stat-Signature: q7fpxmp1hw4bbfz7z1z7dgzhunq8nizg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A3B8E120020 X-HE-Tag: 1702426017-169650 X-HE-Meta: U2FsdGVkX184g81MydVckEBM/Om23TIQPvU87oqshj4KWHsmg6SZV2OGNr9QAiMhRNKvlV+nyE5H5B+zbzV6Wbmez7/D9wotLymD92d1c8ayazTzIyClqLaqIRfTpfbUfvXWcsXj9ToyURlLsX1wVnonzoHlkkJ3qYUHlpF3dR+y/iXUst80Olk0/jhnuaN3EKhv8JkIYAfRXyXIann8VRfMbmIpoN8yAtbN0rEqRpPDeCccEhXt99p6SovB9xkex2PeVTkRw495lGNciCNtvmSUipI0ePUbnuj0pJY8qlfQ3yts94Fs4B2Sz2ZcxdbEYN4le56iNlk1tbqt+Tv1N2FBAg/elu7VnSZYg/KSiIhMuzi93uL5rDmPXQGN4RZECnNke5FaCUU+X542r54jX/R5ODB9ktcIffH+AU8Q4c1y+oTRH1Z+Fa87E2MSfOM2ewcy4UKqFlm+ql3CfVsxV5UzpqZITmtHyiwpW6GXWN+LdIrW7G2kfRGz+0dGL1S+dfBR74H2VGJenJEM8A6h4do4H6ptlE+LqOilpop6+BNIUGuAlNOsT70fCUsOWdAk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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: We want to be able to transfer ftrace state from one kernel to the next. To start off with, let's establish all the boiler plate to get a write hook when KHO wants to serialize and fill out basic data. Follow-up patches will fill in serialization of ring buffers and events. Signed-off-by: Alexander Graf --- kernel/trace/trace.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 7700ca1be2a5..3e7f61cf773e 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -866,6 +867,10 @@ static struct tracer *trace_types __read_mostly; */ DEFINE_MUTEX(trace_types_lock); +#ifdef CONFIG_FTRACE_KHO +static bool trace_in_kho; +#endif + /* * serialize the access of the ring buffer * @@ -10591,12 +10596,59 @@ void __init early_trace_init(void) init_events(); } +#ifdef CONFIG_FTRACE_KHO +static int trace_kho_notifier(struct notifier_block *self, + unsigned long cmd, + void *v) +{ + const char compatible[] = "ftrace-v1"; + void *fdt = v; + int err = 0; + + switch (cmd) { + case KEXEC_KHO_ABORT: + if (trace_in_kho) + mutex_unlock(&trace_types_lock); + trace_in_kho = false; + return NOTIFY_DONE; + case KEXEC_KHO_DUMP: + /* Handled below */ + break; + default: + return NOTIFY_BAD; + } + + if (unlikely(tracing_disabled)) + return NOTIFY_DONE; + + err |= fdt_begin_node(fdt, "ftrace"); + err |= fdt_property(fdt, "compatible", compatible, sizeof(compatible)); + err |= fdt_end_node(fdt); + + if (!err) { + /* Hold all future allocations */ + mutex_lock(&trace_types_lock); + trace_in_kho = true; + } + + return err ? NOTIFY_BAD : NOTIFY_DONE; +} + +static struct notifier_block trace_kho_nb = { + .notifier_call = trace_kho_notifier, +}; +#endif + void __init trace_init(void) { trace_event_init(); if (boot_instance_index) enable_instances(); + +#ifdef CONFIG_FTRACE_KHO + register_kho_notifier(&trace_kho_nb); +#endif } __init static void clear_boot_tracer(void)