Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp265292lqn; Fri, 12 Apr 2024 00:03:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXH2VpVPS4SBOHF2mfW1pI45Ly3si7O4Ifp5+lgyxf+mXsCGWTY7ntzw5NgL+cJMOqNpQXnAqsUjCBlby2gWG+N4SJ8W2YgnqzzyQRy+Q== X-Google-Smtp-Source: AGHT+IEcbB2GOAYmBa+tEdoxiHNG1kD8Y744SI4LqpvSA85sBmNwM4FWaGSj+qwDN2Qm1US5Nec4 X-Received: by 2002:a17:906:1713:b0:a51:8979:a7e6 with SMTP id c19-20020a170906171300b00a518979a7e6mr1345702eje.14.1712905428343; Fri, 12 Apr 2024 00:03:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712905428; cv=pass; d=google.com; s=arc-20160816; b=G7xl+rnBCMcEe1yuF0/VVkH/saiSE9SofOvF6R7o+vY2Dv3/qHj7I/odHZiG7FIpeS cFll34bmkNpVBT8CG/dybKPZ9k3xJ1uInmxE/shLFOQWyHgiysQlAGRO/gMEM3YDnIYU xngUXUMyEqxf2ooMVnMMeI0cDusqiSZPmKXQlMAU/F94ANtJa6n/2fgPFsLslbvbnHyU XuX4zXAN0QsEW5uTnjZ2Pgcg0DOAa2ziZRShukEECIewZve5Ch4FD72GZdrvGDxGD2Ow x7L5dr1JUwH4U2s8r/+0aTul92Tdc8msAAU7sU2MlCzOE/ulLF6yd5VtIgmTaYhn56al yebg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RvqAJLclmygd/KaYK6kKF+HTkiMHUHtz8dfFia/SmYY=; fh=N0E7aQANPyt0+K/4JzHblmSjZpqEZzwskGUWRTyqEws=; b=H4hEJ16Vc55YgGPlIjpSbWZ+hXqbR4vRWRz1oYkt+Vv/4yV3CqHoimKQIMeY3hU8Z7 TXEnFGGdSzOany6dum17YyvqaYYSaBTmxIJohs2PhkBdcfQiAfOrWr0FyeQM3OYw2Qrc yYOO1pOIAYHPlvXsUq4mi7zyl56K5krtcFPGgjdfOhbBlzM/ZxZCGIDJ7zJ6pGR/qHPQ 2AvLSX3mdeDir80Mi/l3PuWc7Fv+EgY5hh0NAFsTPRDeZIJkzsj99S+oo0DL8yck1Ue5 I57WW22z/ocIXDemvJRNxdQ/idmNoYcb4Cou3iQKYiUz2/0yxMwzDZE1ABXa31SGNpZy yYyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=DxsfAisp; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-142095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142095-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b4-20020a170906490400b00a522c013936si871669ejq.87.2024.04.12.00.03.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 00:03:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=DxsfAisp; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-142095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142095-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.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 am.mirrors.kernel.org (Postfix) with ESMTPS id E37F71F223E5 for ; Fri, 12 Apr 2024 07:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1963A5A7AB; Fri, 12 Apr 2024 06:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="DxsfAisp" 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 5D7945339D; Fri, 12 Apr 2024 06:57:59 +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=1712905083; cv=none; b=SX23OpZ318jo4vBgharChXWxjZ6r6CDdPkPq5KpKlixFd/tSbHRvfbC4DAGiVvNaEuxcejChv3kV9pfU1GMQqiYEY60OOGUHemsnP986ARDgty56M/iaUOt17CQVwcicT2t5sMGEUTE6Kann7kUUz2STuganQ+imj1bG0Swa3B0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712905083; c=relaxed/simple; bh=p/b3gEbC9bj8WBEn6G2zXQf0fplABZW3DLXEB9QJE7M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hYjVUIbQ8zMv+EySY1tXI0v9clhnMaProACdUmD9LE9Iupoj4ndNLjWtrhbCW0UNEwH+rTKdRXsZrVmUAv5z3uFyVDaVyAKGYTyQqqTkBguItazhK9rPb+72JVOBivDxXBBef6j55ZZpk/G0ub/dIVnxi/HVqsJEUXMWrZDErQ8= 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=DxsfAisp; 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 X-UUID: f9a0a768f89911eeb8927bc1f75efef4-20240412 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=RvqAJLclmygd/KaYK6kKF+HTkiMHUHtz8dfFia/SmYY=; b=DxsfAispzeSFbnvRoOTWWVZZquOuNjN+2ZdIj1Fj+PJiY7WBxhsXifpTe3ucS3JV/ZUk3ESOY+ZbzYArEYP0XYa70SUZNqyNpxWZvrnSyltpX1Eg8FfGlpWJAsP3dstMRKzWBPem80wwj+LZyjK3l0j50GQhXy2fURpO2XGyFXQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:a5f94f02-bd1a-4142-8e4c-f1bf217b0048,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:6f543d0,CLOUDID:2d3fd4fa-ed05-4274-9204-014369d201e8,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: f9a0a768f89911eeb8927bc1f75efef4-20240412 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1612116802; Fri, 12 Apr 2024 14:57:49 +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; Fri, 12 Apr 2024 14:57:48 +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; Fri, 12 Apr 2024 14:57:48 +0800 From: Yi-De Wu To: Yingshiuan Pan , Ze-Yu Wang , Yi-De Wu , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Catalin Marinas , Will Deacon , Richard Cochran , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , David Bradil , Trilok Soni , My Chuang , Shawn Hsiao , PeiLun Suei , Liju Chen , Willix Yeh , Kevenny Hsieh Subject: [PATCH v10 20/21] virt: geniezone: Add tracing support for hyp call and vcpu exit_reason Date: Fri, 12 Apr 2024 14:57:17 +0800 Message-ID: <20240412065718.29105-21-yi-de.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240412065718.29105-1-yi-de.wu@mediatek.com> References: <20240412065718.29105-1-yi-de.wu@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N 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: Liju-clr Chen Signed-off-by: Yi-De Wu --- arch/arm64/geniezone/vm.c | 4 ++ drivers/virt/geniezone/gzvm_vcpu.c | 5 +- include/trace/events/geniezone.h | 84 ++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 include/trace/events/geniezone.h diff --git a/arch/arm64/geniezone/vm.c b/arch/arm64/geniezone/vm.c index a477546c5a1a..c00142f2e942 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 e135d9388090..28bd690e4b7c 100644 --- a/drivers/virt/geniezone/gzvm_vcpu.c +++ b/drivers/virt/geniezone/gzvm_vcpu.c @@ -10,6 +10,8 @@ #include #include #include + +#include #include /* maximum size needed for holding an integer */ @@ -103,6 +105,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: @@ -141,11 +144,9 @@ static long gzvm_vcpu_run(struct gzvm_vcpu *vcpu, void __user *argp) default: pr_err("vcpu unknown exit\n"); need_userspace = true; - goto out; } } -out: if (copy_to_user(argp, vcpu->run, sizeof(struct gzvm_vcpu_run))) return -EFAULT; if (signal_pending(current)) { 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 -- 2.18.0