From nobody Sat Oct 4 03:09:33 2025 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 324BA1F1306 for ; Fri, 3 Oct 2025 13:39:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759498766; cv=none; b=UUhPHaCMPYRlNVTD/AdpRuH1y5PkJDFEMUJyekQCC4KBh7h8HGuMcGDtrbYAqdol/XUiRyUVXmBYrNOXNwPH3RJ5LK7MCVew12pPueUj5fEjU/lpBjv0kiYVK3+GXhOcudW/MESqMFRT60CfidPZhIKLfkj5juz492658A15FBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759498766; c=relaxed/simple; bh=jTAlnSa7AOMdWm9cZwFdWCnXMdLuV1ot4YyzNmol8bI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AfnK/jWGBMRKg8c4CSEKB8nnkDBUfjifT/RPSwzA9IxiV0fkVYwMYLmDrMUkft8wbh7hXdOSvCVovX6Qf1BY9k2OUeBZQ73I8z07HzDukAIe1n47K+eLWx25VCOMFm/lAqbvZGZoFSIIAuej3AFsiic0c3oGpm/z5UDTglQgUEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vj/oMjSH; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vj/oMjSH" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3ed9557f976so1554702f8f.3 for ; Fri, 03 Oct 2025 06:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759498761; x=1760103561; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zQpWFI+mvDhlS6QzvPWKy0HH/MqUOwvvkoBBWzfvzIQ=; b=vj/oMjSHEelftMKmuq0sPB+nNpqCf88zkI02QbW01tdGtsU+4N+53kyWlXL/0rGOKS C/CUeB5gjIHBg+RFN1lfUd1znFXet3dCr+MexcKcP6xEWGKn7qi+AyVtLF9Qg5JUzita R15tA+6e4qMBvhxu0/z3L2wdOxNN88IQ0hsVR4EgSxpZWDWV01fi+0U1PGtH0v+YwOU3 Oa+a9QbxcXqdVn0N8sCp5lfi1+VkZGahQic3HQdbqgoqn115Kd+AwQjoGpHEjlW7lRm+ 6SzL5QxmtrPOtmW52D3VG1aXRCPpEB2K+x6bYqa6zdIq/dhFUXH5Sill16oHQVuNZiiX lVlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759498761; x=1760103561; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zQpWFI+mvDhlS6QzvPWKy0HH/MqUOwvvkoBBWzfvzIQ=; b=YQTJ1DHylCWoeNTBcIxVD62TUfhucm2ghUCEIgKhHopvQq6hccWPMR7FHgN4xc/l8x vthHhK6kAqkJ/zAAPWR0aDORAWFoxGmSHHK9/R6KS/NktLH3ppBCiq6CigAMQArI6vsB h/xh11hIA3DTD2nzhRZxxXHHQdbpdtO/P6m0YeJB+CuX6fUBEQWcTEMoo2P3uAVEJdPT QSGQENva7vNyEpAxJL4qV3XtVlEG7QOCNxj6f+NdUn5Fkuqmbqby22vkQEqUKh32uNgd eC+9p+KZ3okUZBh4c8yvLuBM+zEXxUvocElACmdbuBRC8u8xq39B+EE5HgBmQ66nsK2w Gmgw== X-Forwarded-Encrypted: i=1; AJvYcCXTYyw/D8O9HDmzglAZTf1e9sBCkqcw23Tf7bbYiImsXMNs+zthidoPn04m2cwpGNdyvOZb6obxbr/AxUE=@vger.kernel.org X-Gm-Message-State: AOJu0YxKiTOUfxdH82IElqWFI/QvoBc/Q2DhMmptohlHZ3Se08zH1tMK 3l2tUZuYkIClFBGIMNIx5BFpqx6FONUFF0rCpqcCDpPNEfpQrsCdhAcviVl5foUsBYUmfnj5oPk KK2FUAJrhi3u6vbZnmJar/A== X-Google-Smtp-Source: AGHT+IG52bRYhXeAJFDgF8uvfHA2+/FCR+eKvs+CIPgd7e1dd8btx3CvmT6Gt+2L3xnnRQYWHWkcwf2OxLo8X/Rp X-Received: from wmpj2.prod.google.com ([2002:a05:600c:4882:b0:46e:684e:1977]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5885:0:b0:3ee:13b1:d70e with SMTP id ffacd0b85a97d-425671aa0b6mr2309114f8f.40.1759498761198; Fri, 03 Oct 2025 06:39:21 -0700 (PDT) Date: Fri, 3 Oct 2025 14:38:23 +0100 In-Reply-To: <20251003133825.2068970-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251003133825.2068970-1-vdonnefort@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251003133825.2068970-27-vdonnefort@google.com> Subject: [PATCH v7 26/28] KVM: arm64: Add hyp_enter/hyp_exit events to pKVM hyp From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jstultz@google.com, qperret@google.com, will@kernel.org, aneesh.kumar@kernel.org, kernel-team@android.com, linux-kernel@vger.kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hyp_enter and hyp_exit events are logged by the hypervisor any time it is entered and exited. Signed-off-by: Vincent Donnefort diff --git a/arch/arm64/include/asm/kvm_hypevents.h b/arch/arm64/include/as= m/kvm_hypevents.h index d6e033c96c52..ce3953bc884a 100644 --- a/arch/arm64/include/asm/kvm_hypevents.h +++ b/arch/arm64/include/asm/kvm_hypevents.h @@ -7,4 +7,21 @@ #include #endif =20 +HYP_EVENT(hyp_enter, + HE_PROTO(void), + HE_STRUCT( + ), + HE_ASSIGN( + ), + HE_PRINTK() +); + +HYP_EVENT(hyp_exit, + HE_PROTO(void), + HE_STRUCT( + ), + HE_ASSIGN( + ), + HE_PRINTK() +); #endif diff --git a/arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h b/arch/arm64/kvm/h= yp/include/nvhe/arm-smccc.h new file mode 100644 index 000000000000..4b69d33e4f2d --- /dev/null +++ b/arch/arm64/kvm/hyp/include/nvhe/arm-smccc.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +#include + +#undef arm_smccc_1_1_smc +#define arm_smccc_1_1_smc(...) \ + do { \ + trace_hyp_exit(); \ + __arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__); \ + trace_hyp_enter(); \ + } while (0) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 3369dd0c4009..e00931fd194f 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -26,10 +26,10 @@ * the duration and are therefore serialised. */ =20 -#include #include #include =20 +#include #include #include #include diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/h= yp-main.c index aebed41f7de7..f8361520967b 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -12,6 +12,7 @@ #include #include #include +#include #include =20 #include @@ -716,7 +717,9 @@ static void handle_host_hcall(struct kvm_cpu_context *h= ost_ctxt) =20 static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt) { + trace_hyp_exit(); __kvm_hyp_host_forward_smc(host_ctxt); + trace_hyp_enter(); } =20 static void handle_host_smc(struct kvm_cpu_context *host_ctxt) @@ -740,6 +743,8 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr =3D read_sysreg_el2(SYS_ESR); =20 + trace_hyp_enter(); + switch (ESR_ELx_EC(esr)) { case ESR_ELx_EC_HVC64: handle_host_hcall(host_ctxt); @@ -754,4 +759,6 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) default: BUG(); } + + trace_hyp_exit(); } diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe= /psci-relay.c index c3e196fb8b18..64d1d418df1d 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -6,11 +6,12 @@ =20 #include #include +#include #include -#include #include #include =20 +#include #include #include =20 @@ -205,6 +206,7 @@ asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bo= ol is_cpu_on) struct psci_boot_args *boot_args; struct kvm_cpu_context *host_ctxt; =20 + trace_hyp_enter(); host_ctxt =3D host_data_ptr(host_ctxt); =20 if (is_cpu_on) @@ -221,6 +223,7 @@ asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bo= ol is_cpu_on) write_sysreg_el1(INIT_SCTLR_EL1_MMU_OFF, SYS_SCTLR); write_sysreg(INIT_PSTATE_EL1, SPSR_EL2); =20 + trace_hyp_exit(); __host_enter(host_ctxt); } =20 diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/swi= tch.c index d3b9ec8a7c28..66ed30135815 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -7,7 +7,6 @@ #include #include =20 -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -308,10 +308,13 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu) __debug_switch_to_guest(vcpu); =20 do { + trace_hyp_exit(); + /* Jump in the fire! */ exit_code =3D __guest_enter(vcpu); =20 /* And we're baaack! */ + trace_hyp_enter(); } while (fixup_guest_exit(vcpu, &exit_code)); =20 __sysreg_save_state_nvhe(guest_ctxt); --=20 2.51.0.618.g983fd99d29-goog