From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF462F417F3 for ; Mon, 9 Mar 2026 16:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wZNlRO5e/MGzFMVxx7Ks/cRDmNOcF7u1/X5pARmyFgQ=; b=jDq2SUjwVnnEBthM1N6A38xEV1 XlqyX2niQQBOixykVZDTzqURaSkSNkXr+PMcSWSbWdd1W421Z0ZCK/EZ1R5wty/LBT/pPSg0sh/MO WVnL+OOgr1h6c3A1jQB7CamgyQBFafN4eFfyrbFU4mB0hVrnH2jhzGXjNiq5UHJ5LCusMre7iOTju PhhG4gAhka6jC/VlLTZoPJK3i4gu4KF0DTFKbr/kOLIvylRXIwku4YKVPWFSoHeKxGsUiOpmY5Tio YFoujsfR+AFfuoRIyJOuVXVvI2Kw6yrFRfn10tiVn0lqIgo1v4IyMBRCr/MZXQb4rPL59D8YZV4vH X9QBlmxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzdRs-00000007iMh-3OWQ; Mon, 09 Mar 2026 16:27:16 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vzdR8-00000007hJU-1Hs0 for linux-arm-kernel@lists.infradead.org; Mon, 09 Mar 2026 16:26:33 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-485389bf0daso8421465e9.0 for ; Mon, 09 Mar 2026 09:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773073587; x=1773678387; darn=lists.infradead.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=wZNlRO5e/MGzFMVxx7Ks/cRDmNOcF7u1/X5pARmyFgQ=; b=JYH4ogAonPDQH8h6WqRJ2fGzKLMzWJGT1r4FdAnYdh+n4MFElqsNnl+7XBBsyXQ8ta 9iyiUQYQnoja9Bxd43yQ3z8W1rAmH3Np4VHzs3VQHoZfObbwsVifBqmtQf1TEcavBVIp wfuWYsB5zM88mvfOsjizpWwvZ5RqDq7ukuaTnmBXcLRCOK/VMVI/zMr8zzpCxxBWKul1 iApf8AdgW0kPHDH3vglkCd94m1iIQH9MyotOPplck5Z12Fn6g1S1Y/IGxrh1S1x/NlSD QDM+p8YZYv1Dqwz0KysBHLJYC9Ne4GSOzMWOXdi9+uaTu4DXHyUguA9b2x4ldi00EK35 Yy9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773073587; x=1773678387; 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=wZNlRO5e/MGzFMVxx7Ks/cRDmNOcF7u1/X5pARmyFgQ=; b=DRxcvgxPJWrJtmnYE3NTaodLg/seVjS92YijKB24Chn5l7xoippMTOpSAMdTnmqdco rCs7nTlIwI3t3NhXaiGzsHlCTtx5R6aUS5uPdv/x2o9M+7JHpYrWMWRxF5b5DRDyr60b lMpJbD5G37Ga90LHpSG8krextXBSfz94Ad2SwGXxnBLmMgK/e9FxKhcD6OYtvvkevA5O Y2uH0pdtmJXOsLhWebAMUc6WRBaJ5vbzv04irFsMtqWR4AO38rI70LNbbEZV/AgW9OV8 eUuXsJDLhb54FfSH5qxgmzRN4oKFXEzrZNQWbBRn7JFKbm2TdgJ1O0QXqEOAnS44iFkM n5ow== X-Forwarded-Encrypted: i=1; AJvYcCUzBwwd6yh9ttOrrO0y8ByzhZTy6xbl/21ZplnAeY6KTQkJJ70WKan/cCvC8ExchzG5xf1jCYXgbp3HLP23N54X@lists.infradead.org X-Gm-Message-State: AOJu0YyZwz+Ee8GyIBjImyWVQJIxBn+htbC/4aD6JUfhHqyfD+Ho5yd/ 5skN6HSFNU7hi6x8UxGUh3XFKgMqnauiJGIsYx9g3IXhqG9Ed01zpBKkUmHXDd17QeZZmTpXFUm o964EabXTUVP6UMnB1xWV1g== X-Received: from wmet19.prod.google.com ([2002:a05:600c:2ad3:b0:47f:c96e:8381]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3ba2:b0:485:35ba:1d81 with SMTP id 5b1f17b1804b1-48535ba1ea6mr94547295e9.21.1773073586927; Mon, 09 Mar 2026 09:26:26 -0700 (PDT) Date: Mon, 9 Mar 2026 16:25:12 +0000 In-Reply-To: <20260309162516.2623589-1-vdonnefort@google.com> Mime-Version: 1.0 References: <20260309162516.2623589-1-vdonnefort@google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260309162516.2623589-27-vdonnefort@google.com> Subject: [PATCH v14 26/30] KVM: arm64: Add trace reset to the nVHE/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-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260309_092630_454897_8CF2AF35 X-CRM114-Status: GOOD ( 12.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make the hypervisor reset either the whole tracing buffer or a specific ring-buffer, on remotes/hypervisor/trace or per_cpu//trace write access. Signed-off-by: Vincent Donnefort diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 9c4fe3bfbfff..66abf77cf371 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -94,6 +94,7 @@ enum __kvm_host_smccc_func { __KVM_HOST_SMCCC_FUNC___tracing_enable, __KVM_HOST_SMCCC_FUNC___tracing_swap_reader, __KVM_HOST_SMCCC_FUNC___tracing_update_clock, + __KVM_HOST_SMCCC_FUNC___tracing_reset, }; #define DECLARE_KVM_VHE_SYM(sym) extern char sym[] diff --git a/arch/arm64/kvm/hyp/include/nvhe/trace.h b/arch/arm64/kvm/hyp/include/nvhe/trace.h index fd641e1b1c23..44912869d184 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/trace.h +++ b/arch/arm64/kvm/hyp/include/nvhe/trace.h @@ -12,6 +12,7 @@ void __tracing_unload(void); int __tracing_enable(bool enable); int __tracing_swap_reader(unsigned int cpu); void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc); +int __tracing_reset(unsigned int cpu); #else static inline void *tracing_reserve_entry(unsigned long length) { return NULL; } static inline void tracing_commit_entry(void) { } @@ -21,5 +22,6 @@ static inline void __tracing_unload(void) { } static inline int __tracing_enable(bool enable) { return -ENODEV; } static inline int __tracing_swap_reader(unsigned int cpu) { return -ENODEV; } static inline void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc) { } +static inline int __tracing_reset(unsigned int cpu) { return -ENODEV; } #endif #endif diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 02d5271199d5..9b05f0c87586 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -625,6 +625,13 @@ static void handle___tracing_update_clock(struct kvm_cpu_context *host_ctxt) __tracing_update_clock(mult, shift, epoch_ns, epoch_cyc); } +static void handle___tracing_reset(struct kvm_cpu_context *host_ctxt) +{ + DECLARE_REG(unsigned int, cpu, host_ctxt, 1); + + cpu_reg(host_ctxt, 1) = __tracing_reset(cpu); +} + typedef void (*hcall_t)(struct kvm_cpu_context *); #define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x @@ -671,6 +678,7 @@ static const hcall_t host_hcall[] = { HANDLE_FUNC(__tracing_enable), HANDLE_FUNC(__tracing_swap_reader), HANDLE_FUNC(__tracing_update_clock), + HANDLE_FUNC(__tracing_reset), }; static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) diff --git a/arch/arm64/kvm/hyp/nvhe/trace.c b/arch/arm64/kvm/hyp/nvhe/trace.c index 2c8e6f49d7de..a6ca27b18e15 100644 --- a/arch/arm64/kvm/hyp/nvhe/trace.c +++ b/arch/arm64/kvm/hyp/nvhe/trace.c @@ -287,3 +287,20 @@ void __tracing_update_clock(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc) /* ...we can now override the old one and swap. */ trace_clock_update(mult, shift, epoch_ns, epoch_cyc); } + +int __tracing_reset(unsigned int cpu) +{ + int ret = -ENODEV; + + if (cpu >= hyp_nr_cpus) + return -EINVAL; + + hyp_spin_lock(&trace_buffer.lock); + + if (hyp_trace_buffer_loaded(&trace_buffer)) + ret = simple_ring_buffer_reset(per_cpu_ptr(trace_buffer.simple_rbs, cpu)); + + hyp_spin_unlock(&trace_buffer.lock); + + return ret; +} diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c index 1e5fc27f0e9d..09bc192e3514 100644 --- a/arch/arm64/kvm/hyp_trace.c +++ b/arch/arm64/kvm/hyp_trace.c @@ -313,7 +313,7 @@ static int hyp_trace_swap_reader_page(unsigned int cpu, void *priv) static int hyp_trace_reset(unsigned int cpu, void *priv) { - return 0; + return kvm_call_hyp_nvhe(__tracing_reset, cpu); } static int hyp_trace_enable_event(unsigned short id, bool enable, void *priv) -- 2.53.0.473.g4a7958ca14-goog