Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4996349rdb; Tue, 12 Dec 2023 16:07:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZGDNR53lO03dU9I6iJlKi48iDvYKKbNXeHQsMuothYBj6y5jIAV4IMpAwqneeERxZHR8r X-Received: by 2002:a17:90b:4ad0:b0:286:7616:4b74 with SMTP id mh16-20020a17090b4ad000b0028676164b74mr5580461pjb.99.1702426042603; Tue, 12 Dec 2023 16:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702426042; cv=none; d=google.com; s=arc-20160816; b=VWTubeBBwJr7lHkXf14RZYTzj4vV82Rj4VI7D4j3a1/6oO/j73R8r67x2/f0via+T6 oUwkSHenJIJ7uGGVqqnHccyvmAmnZwcLyL+fSUORIu49F7X4Ho5nFCPDUBn5mEXVVC/o 5w/W654Ktsoy3nVe17LZ9p7GwmZJj4m+lj7HFafteFAide9CUQMOBTLhnQ/1Ey4eUo0Z wtW0JYFPcVgXoKECzmsMJnYX6Sf5tRP2BBKU89+hfSwDDsO6P+IJ0fYtkiI0tslsx43x b3rpYDg5xZxA2Ku+Tb08Kaxy1gSJ5F0sTM67kyXP861ysBP0VkgO1+YLvIgdCDq6hZdG /vGw== 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=YG4rwMst//uzBl8lCmh1WsDiUmAxsOlA2EWBHH+q6Y0=; fh=xprWcyUKTLi4rhte7gFCvduD673j12awuFkCPnYDQVY=; b=FE/+8q7z/13QO78KFJFOi58UZdANcBEyqxxzxwuI4SmAEmZFYrEqv3q8JsYgEAh013 xtaBXQEsHmHcaH+/BMtEDF2B60ckdmgLjFv1mvwDjTkXKV9SXs0At3cImBdC0qZ0mycx Mb58Ymx1tLO1GreQ/buCsnKk5uqQgg7mCVNaqwaULyLVo/wiUs1onm0bV/byJcOSDKhX mzXUNQ7LmcThevcKhTp/k48Oa/i80pO88LbsrlnEEFbblqLbPqsz+djKXIigwLbvMGtm bDm9BOCyJy8P0uwuKA6QGh2Zg8ncbBfMNlRHvP7wUZB3G14xrU4UZOi36gZjI0qnjAsC yxSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ZBkod8vn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id pw6-20020a17090b278600b002856f3e5fe2si8825176pjb.3.2023.12.12.16.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 16:07:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ZBkod8vn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 24A1D80B81D3; Tue, 12 Dec 2023 16:07:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377703AbjLMAHI (ORCPT + 99 others); Tue, 12 Dec 2023 19:07:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377632AbjLMAG5 (ORCPT ); Tue, 12 Dec 2023 19:06:57 -0500 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5937A18E; Tue, 12 Dec 2023 16:06:57 -0800 (PST) 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) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 16:07:21 -0800 (PST) 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) -- 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