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 C9881C001DB for ; Tue, 8 Aug 2023 11:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=m2XJDdrCrsMQt9RKay7XcueF8sRYWhIkJ4g/e9Rh3HM=; b=Fp4Luzi/ZoNmxl 41vnQFW+1dwNw+qjResGQdvC+5TZZf9AoPYatePlgcBCUQNiHbPmz0ZxZRX3CcBfh84mLiWpidW5g chCvVfY/aqHG3yztTsXL1mMZrVWgyt/m17AG1OMvyiWaE9UyAxj6Anjb8waiT8gYcN/QfR++tsTLm BgYUOGUUQrzHS09zUEON27IJEM3HOE5iTaQpHsR6flGx2q4Dr0Rsqcu0r+u4/dVe6n1tO/tDSwDhs lBJFt9+3eWjd7ux+eEAhdolRkLFaRquvh2SWDgUFCD04t+aAVky/fpIqPvxB5qYwWHnxKDUCjD8aC YY4ejF/Y4ggTTNgqvQOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qTKVf-002R3r-24; Tue, 08 Aug 2023 11:04:19 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qTKVc-002R2s-2u for linux-arm-kernel@lists.infradead.org; Tue, 08 Aug 2023 11:04:18 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8798E624B6; Tue, 8 Aug 2023 11:04:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB25BC433C7; Tue, 8 Aug 2023 11:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691492654; bh=DvFRtMOY4iagkM51r9J4zb/PTZkURRwsD+PlGC3bhCQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=f0PqxTwgl8WsCHtX6Gsfios7cRzmexMQGyXxFqIvsasO6WhgwyKOsQIGNYUWy9Q0Q WFWIZp7AoBkeuetrWWQDu3JhDAkHH+HweDSyEZWwuhKMdVJq4Nlri8/e/QvyxpLiIG RTWQHAwHatWRR4/8g+/ImbUYL0euknmk67PiPnhag8u/Q988jiwJd1uCae2ysYBOR1 kYd2BUtnUq4ElPR8ONnIxo13uYX/dMyyV4l8vVDWu1dJV6hDkWM1bTB/JBTKdnaI82 tgjlVVtO7V2UeOLm/93dm00MtjQNGvwE2LW9HrzE1Zwbq8nQnYAAHYTAqWnOkBTsOQ I7B40TIGjvj2Q== Received: from [104.132.45.110] (helo=wait-a-minute.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 1qTKVY-00372P-FV; Tue, 08 Aug 2023 12:04:12 +0100 Date: Tue, 08 Aug 2023 12:04:19 +0100 Message-ID: <871qgdre18.wl-maz@kernel.org> From: Marc Zyngier To: James Clark Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Leo Yan , Alexander Shishkin , Anshuman Khandual , Rob Herring , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/3] arm64: KVM: Support exclude_guest for Coresight trace in nVHE In-Reply-To: <20230804101317.460697-3-james.clark@arm.com> References: <20230804101317.460697-1-james.clark@arm.com> <20230804101317.460697-3-james.clark@arm.com> 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/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 104.132.45.110 X-SA-Exim-Rcpt-To: james.clark@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mike.leach@linaro.org, leo.yan@linaro.org, alexander.shishkin@linux.intel.com, anshuman.khandual@arm.com, robh@kernel.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230808_040417_045089_F7046C07 X-CRM114-Status: GOOD ( 32.05 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 04 Aug 2023 11:13:12 +0100, James Clark wrote: > > Currently trace will always be generated in nVHE as long as TRBE isn't > being used. To allow filtering out guest trace, re-apply the filter > rules before switching to the guest. > > The TRFCR restore function remains the same. > > Signed-off-by: James Clark > --- > arch/arm64/kvm/debug.c | 7 ++++ > arch/arm64/kvm/hyp/nvhe/debug-sr.c | 56 +++++++++++++++++++++++++++--- > 2 files changed, 59 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > index 8725291cb00a..ebb4db20a859 100644 > --- a/arch/arm64/kvm/debug.c > +++ b/arch/arm64/kvm/debug.c > @@ -335,10 +335,17 @@ void kvm_arch_vcpu_load_debug_state_flags(struct kvm_vcpu *vcpu) > if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_TraceBuffer_SHIFT) && > !(read_sysreg_s(SYS_TRBIDR_EL1) & TRBIDR_EL1_P)) > vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_TRBE); > + /* > + * Save TRFCR on nVHE if FEAT_TRF exists. This will be done in cases > + * where DEBUG_STATE_SAVE_TRBE doesn't completely disable trace. > + */ > + if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_TraceFilt_SHIFT)) > + vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_TRFCR); > } > > void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu) > { > vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_SPE); > vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRBE); > + vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRFCR); > } > diff --git a/arch/arm64/kvm/hyp/nvhe/debug-sr.c b/arch/arm64/kvm/hyp/nvhe/debug-sr.c > index 4558c02eb352..0e8c85b29b92 100644 > --- a/arch/arm64/kvm/hyp/nvhe/debug-sr.c > +++ b/arch/arm64/kvm/hyp/nvhe/debug-sr.c > @@ -51,13 +51,17 @@ static void __debug_restore_spe(u64 pmscr_el1) > write_sysreg_s(pmscr_el1, SYS_PMSCR_EL1); > } > > -static void __debug_save_trace(u64 *trfcr_el1) > +/* > + * Save TRFCR and disable trace completely if TRBE is being used. Return true > + * if trace was disabled. > + */ > +static bool __debug_save_trace(u64 *trfcr_el1) > { > *trfcr_el1 = 0; > > /* Check if the TRBE is enabled */ > if (!(read_sysreg_s(SYS_TRBLIMITR_EL1) & TRBLIMITR_EL1_E)) > - return; > + return false; While you're refactoring this code, please move the zeroing of *trfcr_el1 under the if statement. > /* > * Prohibit trace generation while we are in guest. > * Since access to TRFCR_EL1 is trapped, the guest can't > @@ -68,6 +72,8 @@ static void __debug_save_trace(u64 *trfcr_el1) > isb(); > /* Drain the trace buffer to memory */ > tsb_csync(); > + > + return true; > } > > static void __debug_restore_trace(u64 trfcr_el1) > @@ -79,14 +85,55 @@ static void __debug_restore_trace(u64 trfcr_el1) > write_sysreg_s(trfcr_el1, SYS_TRFCR_EL1); > } > > +#if IS_ENABLED(CONFIG_PERF_EVENTS) As previously stated, just always compile this. There shouldn't be anything here that's so large that it becomes a candidate for exclusion. Hell, even the whole of NV+pKVM are permanent features, even of most people won't use *any* of that. > +static inline void __debug_save_trfcr(struct kvm_vcpu *vcpu) > +{ > + u64 trfcr; > + struct kvm_etm_event etm_event = vcpu->arch.host_debug_state.etm_event; > + > + /* No change if neither are excluded */ > + if (!etm_event.exclude_guest && !etm_event.exclude_host) { > + /* Zeroing prevents restoring a stale value */ > + vcpu->arch.host_debug_state.trfcr_el1 = 0; I find this "zero means do nothing" part very odd. I can see it is already done, but I really dislike this sort of assumption to avoid writing to a register. I'd really prefer we track another version of TRFCR_EL1, compare host and guest, and decide to avoid writing if they are equal. At least, it would be readable. And in the end, expressing *everything* in terms of the register would really help, instead of the exclude_* stuff that has no place in the low-level arch code. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel