From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2B99864D; Sat, 21 Dec 2024 12:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734784493; cv=none; b=TSK2XGJW4OIqyqeq6+nvxsqWKH72nJfqZBdWSi2Tt3YLrM/XUCHGDN7NUh6+sJyy3RWPtLxPZJSSJ2q82HQ09TI9yeJoTUbpJ5tDHVidow2V4NimasP33QIrIoC0pWHavHh+ouyNJVrCdhboX/3r+SYCdW1+UwbOwWG+jOMYF38= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734784493; c=relaxed/simple; bh=mJh65cE8FpJnhcgX4NYekYpaa0p+s7y+XkLuWQvx+YY=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=WWJbp8XUfmD0KLSxa4pgdCQk4Dx8wfasM7Z+jbEGb5xwhlXFwFQ7upJbSSTEMsNIIN64sYxBQ0iXXizvNt1ZfTQtShGAp6RM2Bto11ayTpYJFj5JDnXmNx9tWz1i/rldCGV6VlnRDKoTmLgMoJVrwOKvbzD5W8joAmoagUjQ6d4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Er7xCeD9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Er7xCeD9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A087C4CECE; Sat, 21 Dec 2024 12:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734784492; bh=mJh65cE8FpJnhcgX4NYekYpaa0p+s7y+XkLuWQvx+YY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Er7xCeD9KIZUg6+fdQRcrAsfzMhj8fh9cjF3x83fWt8QglmFFHpKCmFhPjhF+fxQy Ys+3Fm2Gh2Uz19PlsrF8AMWFHmN+XRIj4oDkJGR8fk3Ils/c9eiQLOhIOCu+84LBcA T0qs2VHHg//aP16oq1G4fUsmRkcmxM2W9Pbfpo14Q0nRt86OIzv2veB2Z7s0f+R7Yg le4zFjvwK0IoCWmZKEzWLjm/Ri4XhybuUH/DJH7BHb50t4PMWo/pUsJJWKITk8f2Qy DyI02tlAco34X19KI+kaoe7t3T8D9fZQVchzyMDvK3aw8uEyTqXwY4WpQHNv9hdehJ Jvf4jJWXprrlQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tOyh0-005vOL-95; Sat, 21 Dec 2024 12:34:50 +0000 Date: Sat, 21 Dec 2024 12:34:48 +0000 Message-ID: <86r061p63b.wl-maz@kernel.org> From: Marc Zyngier To: James Clark Cc: kvmarm@lists.linux.dev, oliver.upton@linux.dev, suzuki.poulose@arm.com, coresight@lists.linaro.org, Joey Gouly , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Alexander Shishkin , Mark Brown , Anshuman Khandual , James Morse , "Rob Herring (Arm)" , Shiqi Liu , Fuad Tabba , Raghavendra Rao Ananta , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 7/8] KVM: arm64: Support trace filtering for guests In-Reply-To: <20241127100130.1162639-8-james.clark@linaro.org> References: <20241127100130.1162639-1-james.clark@linaro.org> <20241127100130.1162639-8-james.clark@linaro.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: james.clark@linaro.org, kvmarm@lists.linux.dev, oliver.upton@linux.dev, suzuki.poulose@arm.com, coresight@lists.linaro.org, joey.gouly@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mike.leach@linaro.org, alexander.shishkin@linux.intel.com, broonie@kernel.org, anshuman.khandual@arm.com, james.morse@arm.com, robh@kernel.org, shiqiliu@hust.edu.cn, tabba@google.com, rananta@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Wed, 27 Nov 2024 10:01:24 +0000, James Clark wrote: > > For nVHE, switch the filter value in and out if the Coresight driver > asks for it. This will support filters for guests when sinks other than > TRBE are used. > > For VHE, just write the filter directly to TRFCR_EL1 where trace can be > used even with TRBE sinks. > > Signed-off-by: James Clark > --- > arch/arm64/include/asm/kvm_host.h | 5 +++++ > arch/arm64/kvm/debug.c | 28 ++++++++++++++++++++++++++++ > arch/arm64/kvm/hyp/nvhe/debug-sr.c | 1 + > 3 files changed, 34 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index ba251caa593b..cce07887551b 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -613,6 +613,7 @@ struct kvm_host_data { > #define KVM_HOST_DATA_FLAG_HAS_SPE 0 > #define KVM_HOST_DATA_FLAG_HAS_TRF 1 > #define KVM_HOST_DATA_FLAG_TRBE_ENABLED 2 > +#define KVM_HOST_DATA_FLAG_GUEST_FILTER 3 Guest filter what? This is meaningless. > unsigned long flags; > > struct kvm_cpu_context host_ctxt; > @@ -1387,6 +1388,8 @@ void kvm_clr_pmu_events(u64 clr); > bool kvm_set_pmuserenr(u64 val); > void kvm_enable_trbe(void); > void kvm_disable_trbe(void); > +void kvm_set_trfcr(u64 guest_trfcr); > +void kvm_clear_trfcr(void); > #else > static inline void kvm_set_pmu_events(u64 set, struct perf_event_attr *attr) {} > static inline void kvm_clr_pmu_events(u64 clr) {} > @@ -1396,6 +1399,8 @@ static inline bool kvm_set_pmuserenr(u64 val) > } > static inline void kvm_enable_trbe(void) {} > static inline void kvm_disable_trbe(void) {} > +static inline void kvm_set_trfcr(u64 guest_trfcr) {} > +static inline void kvm_clear_trfcr(void) {} > #endif > > void kvm_vcpu_load_vhe(struct kvm_vcpu *vcpu); > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > index 0c340ae7b5d1..9266f2776991 100644 > --- a/arch/arm64/kvm/debug.c > +++ b/arch/arm64/kvm/debug.c > @@ -337,3 +337,31 @@ void kvm_disable_trbe(void) > host_data_clear_flag(TRBE_ENABLED); > } > EXPORT_SYMBOL_GPL(kvm_disable_trbe); > + > +void kvm_set_trfcr(u64 guest_trfcr) Again. Is this the guest's view? or the host view while running the guest? I asked the question on the previous patch, and you didn't reply. > +{ > + if (is_protected_kvm_enabled() || WARN_ON_ONCE(preemptible())) > + return; > + > + if (has_vhe()) > + write_sysreg_s(guest_trfcr, SYS_TRFCR_EL12); > + else { > + *host_data_ptr(guest_trfcr_el1) = guest_trfcr; > + host_data_set_flag(GUEST_FILTER); > + } Oh come on. This is basic coding style, see section 3 in Documentation/process/coding-style.rst. > +} > +EXPORT_SYMBOL_GPL(kvm_set_trfcr); > + > +void kvm_clear_trfcr(void) > +{ > + if (is_protected_kvm_enabled() || WARN_ON_ONCE(preemptible())) > + return; > + > + if (has_vhe()) > + write_sysreg_s(0, SYS_TRFCR_EL12); > + else { > + *host_data_ptr(guest_trfcr_el1) = 0; > + host_data_clear_flag(GUEST_FILTER); > + } > +} > +EXPORT_SYMBOL_GPL(kvm_clear_trfcr); Why do we have two helpers? Clearly, calling kvm_set_trfcr() with E{1,0}TRE=={0,0} should result in *disabling* things. Except it doesn't, and you should fix it. Once that is fixed, it becomes obvious that kvm_clear_trfcr() serves no purpose. To sum it up, KVM's API should reflect the architecture instead of making things up. > diff --git a/arch/arm64/kvm/hyp/nvhe/debug-sr.c b/arch/arm64/kvm/hyp/nvhe/debug-sr.c > index 9479bee41801..7edee7ace433 100644 > --- a/arch/arm64/kvm/hyp/nvhe/debug-sr.c > +++ b/arch/arm64/kvm/hyp/nvhe/debug-sr.c > @@ -67,6 +67,7 @@ static void __trace_do_switch(u64 *saved_trfcr, u64 new_trfcr) > static bool __trace_needs_switch(void) > { > return host_data_test_flag(TRBE_ENABLED) || > + host_data_test_flag(GUEST_FILTER) || > (is_protected_kvm_enabled() && host_data_test_flag(HAS_TRF)); Wouldn't it make more sense to just force the "GUEST_FILTER" flag in the pKVM case, and drop the 3rd term altogether? M. -- Without deviation from the norm, progress is not possible.