From patchwork Fri Dec 22 19:36:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 182768 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1289698dyi; Fri, 22 Dec 2023 11:39:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhJHllR3oRjHshRDInoMPxwLrOVXexoa1+I34CfSaSMYGNfS+fMhFpMfn8S3CPG08q47tY X-Received: by 2002:a05:6214:4112:b0:67f:2195:a5ba with SMTP id kc18-20020a056214411200b0067f2195a5bamr2481492qvb.50.1703273996495; Fri, 22 Dec 2023 11:39:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703273996; cv=none; d=google.com; s=arc-20160816; b=NXPL6UX4ty2fZI+qx1kQFc4OLPGvxUOBovT2o6NJJ2+sO592r5Tle48N0CCOw7jjnW Fx4HNYy/MweobuFtp4PfyAFNXTl1XNOLainBgYm7x8VGugJ9Cx2264knwKZJtTMZxTZf 29/6J6U4hGa8bb/XarQDo/lwvTzXDCz/R3kijgH1+cXEbYOl3D7e1Ut7hoOPTbgR/txm 5oBllk4oOlK7Q/swqon3OUvnTWrBVedt4b6tymTN/QfeWJy/diKrTeq9ABWkiM1potnT oZqv5HGGndaPman0+jHoe9C7qgq3v/Afx/trSvBnJ1ZzQTbyBy8J13la/ilrsJ6vmTRX FZfg== 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=qmhUZjf5F0irRMFPH4YUunFpNZODTBv7SKMl/vOJmCU=; fh=xprWcyUKTLi4rhte7gFCvduD673j12awuFkCPnYDQVY=; b=g/oxWLWv22U3xOajFElWT/gDyNPB/0y8jNz2VGSZt3OWfTvOAXc1iCpdM1K29oW7Ds Z5ATLgzpT70vUQvp3jQJeZEhMpUuWuLk9Yd6wxYTPAXIkM8jXmmY/pBHCCHqRubuCKcg fIMctgnfJBJErnRuvFDdde0zBL0gFF6IXSnBmzIbuG9IVympeip0qJmEcZLxxcgq1FPf QM2yHil8FtlElJ4e0suOI6n2pus8bjRCj1BhFXrIShAOMD6yBEH6IZv5gE+a2J9eFEOr f9RrVnjvdw/X7OE1G9XA8gZfPdxZbeW6nKy57MsVdpi5ZTOZq5ZMa+Wp2AFWbrWLsrFQ GM2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=eAtqzVKd; spf=pass (google.com: domain of linux-kernel+bounces-10026-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10026-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v18-20020a0cdd92000000b0065ae2cc68f3si4747092qvk.387.2023.12.22.11.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 11:39:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10026-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=eAtqzVKd; spf=pass (google.com: domain of linux-kernel+bounces-10026-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10026-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4B03E1C20891 for ; Fri, 22 Dec 2023 19:39:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E10BE31742; Fri, 22 Dec 2023 19:38:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="eAtqzVKd" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) (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 0916831723; Fri, 22 Dec 2023 19:38:10 +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=1703273891; x=1734809891; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qmhUZjf5F0irRMFPH4YUunFpNZODTBv7SKMl/vOJmCU=; b=eAtqzVKdECYu+n2gePGRkHUjztmVDVHbcPLtf8gb+RFjZtC8+G4Dpfe6 YRVmhsqakOEo+kpei26Fh7jKEng1Xf4D3QwFZIXc2nVyWC+QXwDDqjyYa ln91AmDjNGLTNEVTopMPcm1Wr6nAfo0dhJ8M8HM06prJTHCn8y4wHcp5b k=; X-IronPort-AV: E=Sophos;i="6.04,297,1695686400"; d="scan'208";a="692781574" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-1197e3af.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 19:38:06 +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-2a-m6i4x-1197e3af.us-west-2.amazon.com (Postfix) with ESMTPS id 2C677100395; Fri, 22 Dec 2023 19:38:04 +0000 (UTC) Received: from EX19MTAUWA002.ant.amazon.com [10.0.21.151:8114] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.6.30:2525] with esmtp (Farcaster) id 118258fa-6e62-4bd3-8f88-fab34a1b9f0a; Fri, 22 Dec 2023 19:38:03 +0000 (UTC) X-Farcaster-Flow-ID: 118258fa-6e62-4bd3-8f88-fab34a1b9f0a 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:38:02 +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:58 +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 11/17] tracing: Introduce kho serialization Date: Fri, 22 Dec 2023 19:36:01 +0000 Message-ID: <20231222193607.15474-12-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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786012234459398053 X-GMAIL-MSGID: 1786012234459398053 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 --- v1 -> v2: - Remove ifdefs --- kernel/trace/trace.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 199df497db07..6ec31879b4eb 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,8 @@ static struct tracer *trace_types __read_mostly; */ DEFINE_MUTEX(trace_types_lock); +static bool trace_in_kho; + /* * serialize the access of the ring buffer * @@ -10560,12 +10563,56 @@ void __init early_trace_init(void) init_events(); } +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, +}; + void __init trace_init(void) { trace_event_init(); if (boot_instance_index) enable_instances(); + + if (IS_ENABLED(CONFIG_FTRACE_KHO)) + register_kho_notifier(&trace_kho_nb); } __init static void clear_boot_tracer(void)