From patchwork Tue Jul 30 08:24:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liju-clr Chen X-Patchwork-Id: 13746969 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 1460619307E; Tue, 30 Jul 2024 08:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722327898; cv=none; b=PSM7yLmqMYz5vFCn8iPGRn/pdeRCB0hXTq/4p7zmX6PVSoxQvPDQSTex/KQB2kiuBy0THrHWyXhTRvZBAStP2tke/l+dFaU26iaQSN+KbdqOm6S/5lptv8bxTckSQmJreZrI9mpZauHvTMlF3DtZS/DX5/Jgl4zOGgZQChY0urA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722327898; c=relaxed/simple; bh=8QLPoC8eTa6ZK49DFQllk+fqeGbhnucVC+T/OZE6azg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d/geHykBmr8tiC00xSexiE88QRAbb9xf0PcMF59mQXur3JntwqAzfQnLr+gWjPsZlEH2UNgL5SGbHWpaN5CXjRbARVc2//MY0xpXLNupbzSmhkmgrwktKPc7FLs+K27QKBXWg+1z21FiZdD63Hs7IYyC9V1DvcOLAo8+MOPQTbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=OewOJkR5; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="OewOJkR5" X-UUID: 2db9e3084e4d11efb5b96b43b535fdb4-20240730 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=+0H8XR6/6gnQfW06sc06bIyBs/qL70M7zEHtdbRpeZI=; b=OewOJkR51YFhiLBWOCctBgULaxQe2w4sXRYXqNxLPD4ttCdCMuyVwTF9YgnKN0TQVZa1NyfjykwCBv5fetHAi4gAcM2kkQ9oNJvStZs0FYGbYW43Q4AJQF80HO2pL4ggfUvBNGhZoai1BiaDUf3nNi2o4UJ+Y97kfFeLN+8KZWg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.41,REQID:d3663610-99c2-4a92-9889-ada34bf604c2,IP:0,U RL:0,TC:0,Content:-25,EDM:-25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-50 X-CID-META: VersionHash:6dc6a47,CLOUDID:ba22e245-a117-4f46-a956-71ffeac67bfa,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:1,IP:nil,UR L:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,S PR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 2db9e3084e4d11efb5b96b43b535fdb4-20240730 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 456805199; Tue, 30 Jul 2024 16:24:45 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 30 Jul 2024 16:24:40 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 30 Jul 2024 16:24:39 +0800 From: Liju-clr Chen To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Catalin Marinas , Will Deacon , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Richard Cochran , Matthias Brugger , AngeloGioacchino Del Regno , Liju-clr Chen , Yingshiuan Pan , Ze-yu Wang CC: , , , , , , , Shawn Hsiao , PeiLun Suei , Chi-shen Yeh , Kevenny Hsieh Subject: [PATCH v12 20/24] virt: geniezone: Add tracing support for hyp call and vcpu exit_reason Date: Tue, 30 Jul 2024 16:24:32 +0800 Message-ID: <20240730082436.9151-21-liju-clr.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240730082436.9151-1-liju-clr.chen@mediatek.com> References: <20240730082436.9151-1-liju-clr.chen@mediatek.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N From: Liju Chen Add tracepoints for hypervisor calls and VCPU exit reasons in GenieZone driver. It aids performance debugging by providing more information about hypervisor operations and VCPU behavior. Command Usage: echo geniezone:* >> /sys/kernel/tracing/set_event echo 1 > /sys/kernel/tracing/tracing_on echo 0 > /sys/kernel/tracing/tracing_on cat /sys/kernel/tracing/trace For example: crosvm_vcpu0-4874 [007] ..... 94.757349: mtk_hypcall_enter: id=0xfb001005 crosvm_vcpu0-4874 [007] ..... 94.760902: mtk_hypcall_leave: id=0xfb001005 invalid=0 crosvm_vcpu0-4874 [007] ..... 94.760902: mtk_vcpu_exit: vcpu exit_reason=IRQ(0x92920003) This example tracks a hypervisor function call by an ID (`0xbb001005`) from initiation to termination, which is supported (invalid=0). A vCPU exit is triggered by an Interrupt Request (IRQ) (exit reason: 0x92920003). /* VM exit reason */ enum { GZVM_EXIT_UNKNOWN = 0x92920000, GZVM_EXIT_MMIO = 0x92920001, GZVM_EXIT_HYPERCALL = 0x92920002, GZVM_EXIT_IRQ = 0x92920003, GZVM_EXIT_EXCEPTION = 0x92920004, GZVM_EXIT_DEBUG = 0x92920005, GZVM_EXIT_FAIL_ENTRY = 0x92920006, GZVM_EXIT_INTERNAL_ERROR = 0x92920007, GZVM_EXIT_SYSTEM_EVENT = 0x92920008, GZVM_EXIT_SHUTDOWN = 0x92920009, GZVM_EXIT_GZ = 0x9292000a, }; Signed-off-by: Yi-De Wu Signed-off-by: Liju Chen Reviewed-by: Steven Rostedt (Google) --- arch/arm64/geniezone/vm.c | 4 ++ drivers/virt/geniezone/gzvm_vcpu.c | 3 ++ include/trace/events/geniezone.h | 84 ++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 include/trace/events/geniezone.h diff --git a/arch/arm64/geniezone/vm.c b/arch/arm64/geniezone/vm.c index 62ffb415354c..618de2ff9471 100644 --- a/arch/arm64/geniezone/vm.c +++ b/arch/arm64/geniezone/vm.c @@ -7,6 +7,8 @@ #include #include +#define CREATE_TRACE_POINTS +#include #include #include #include "gzvm_arch_common.h" @@ -44,11 +46,13 @@ int gzvm_hypcall_wrapper(unsigned long a0, unsigned long a1, .a6 = a6, .a7 = a7, }; + trace_mtk_hypcall_enter(a0); arm_smccc_1_2_hvc(&args, &res_1_2); res->a0 = res_1_2.a0; res->a1 = res_1_2.a1; res->a2 = res_1_2.a2; res->a3 = res_1_2.a3; + trace_mtk_hypcall_leave(a0, (res->a0 != ERR_NOT_SUPPORTED) ? 0 : 1); return gzvm_err_to_errno(res->a0); } diff --git a/drivers/virt/geniezone/gzvm_vcpu.c b/drivers/virt/geniezone/gzvm_vcpu.c index b0dc3e4f47d7..3b146148abf3 100644 --- a/drivers/virt/geniezone/gzvm_vcpu.c +++ b/drivers/virt/geniezone/gzvm_vcpu.c @@ -9,6 +9,8 @@ #include #include #include + +#include #include /* maximum size needed for holding an integer */ @@ -102,6 +104,7 @@ static long gzvm_vcpu_run(struct gzvm_vcpu *vcpu, void __user *argp) while (!need_userspace && !signal_pending(current)) { gzvm_arch_vcpu_run(vcpu, &exit_reason); + trace_mtk_vcpu_exit(exit_reason); switch (exit_reason) { case GZVM_EXIT_MMIO: diff --git a/include/trace/events/geniezone.h b/include/trace/events/geniezone.h new file mode 100644 index 000000000000..4fffd826ba67 --- /dev/null +++ b/include/trace/events/geniezone.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2023 MediaTek Inc. + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM geniezone + +#define _TRACE_GENIEZONE_H + +#include +#include + +#define GZVM_EXIT_REASONS \ +EM(UNKNOWN)\ +EM(MMIO)\ +EM(HYPERCALL)\ +EM(IRQ)\ +EM(EXCEPTION)\ +EM(DEBUG)\ +EM(FAIL_ENTRY)\ +EM(INTERNAL_ERROR)\ +EM(SYSTEM_EVENT)\ +EM(SHUTDOWN)\ +EMe(GZ) + +#undef EM +#undef EMe +#define EM(a) TRACE_DEFINE_ENUM(GZVM_EXIT_##a); +#define EMe(a) TRACE_DEFINE_ENUM(GZVM_EXIT_##a); + +GZVM_EXIT_REASONS + +#undef EM +#undef EMe + +#define EM(a) { GZVM_EXIT_##a, #a }, +#define EMe(a) { GZVM_EXIT_##a, #a } + +TRACE_EVENT(mtk_hypcall_enter, + TP_PROTO(unsigned long id), + + TP_ARGS(id), + + TP_STRUCT__entry(__field(unsigned long, id)), + + TP_fast_assign(__entry->id = id;), + + TP_printk("id=0x%lx", __entry->id) +); + +TRACE_EVENT(mtk_hypcall_leave, + TP_PROTO(unsigned long id, unsigned long invalid), + + TP_ARGS(id, invalid), + + TP_STRUCT__entry(__field(unsigned long, id) + __field(unsigned long, invalid) + ), + + TP_fast_assign(__entry->id = id; + __entry->invalid = invalid; + ), + + TP_printk("id=0x%lx invalid=%lu", __entry->id, __entry->invalid) +); + +TRACE_EVENT(mtk_vcpu_exit, + TP_PROTO(unsigned long exit_reason), + + TP_ARGS(exit_reason), + + TP_STRUCT__entry(__field(unsigned long, exit_reason)), + + TP_fast_assign(__entry->exit_reason = exit_reason;), + + TP_printk("vcpu exit_reason=%s(0x%lx)", + __print_symbolic(__entry->exit_reason, GZVM_EXIT_REASONS), + __entry->exit_reason) + +); + +/* This part must be outside protection */ +#include