From: Oliver Upton <oliver.upton@linux.dev>
To: James Clark <james.clark@linaro.org>
Cc: suzuki.poulose@arm.com, coresight@lists.linaro.org,
kvmarm@lists.linux.dev, Marc Zyngier <maz@kernel.org>,
Joey Gouly <joey.gouly@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Mike Leach <mike.leach@linaro.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Mark Rutland <mark.rutland@arm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
"Rob Herring (Arm)" <robh@kernel.org>,
Shiqi Liu <shiqiliu@hust.edu.cn>, Fuad Tabba <tabba@google.com>,
James Morse <james.morse@arm.com>,
Mark Brown <broonie@kernel.org>,
Raghavendra Rao Ananta <rananta@google.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 11/12] KVM: arm64: Swap TRFCR on guest switch
Date: Tue, 26 Nov 2024 08:23:32 -0800 [thread overview]
Message-ID: <Z0X2BBBaDejFfATp@linux.dev> (raw)
In-Reply-To: <5f2eb0fa-c7ca-4e25-b713-6a9bf3d355b9@linaro.org>
On Thu, Nov 21, 2024 at 12:50:10PM +0000, James Clark wrote:
>
>
> On 20/11/2024 5:31 pm, Oliver Upton wrote:
> > On Tue, Nov 12, 2024 at 10:37:10AM +0000, James Clark wrote:
> > > +void kvm_set_trfcr(u64 host_trfcr, u64 guest_trfcr)
> > > +{
> > > + if (kvm_arm_skip_trace_state())
> > > + return;
> > > +
> > > + if (has_vhe())
> > > + write_sysreg_s(guest_trfcr, SYS_TRFCR_EL12);
> > > + else
> > > + if (host_trfcr != guest_trfcr) {
> > > + *host_data_ptr(host_debug_state.trfcr_el1) = guest_trfcr;
> >
> > Huh? That's going into host_debug_state, which is the dumping grounds
> > for *host* context when entering a guest.
> >
> > Not sure why we'd stick a *guest* value in there...
> >
>
> Only to save a 3rd storage place for trfcr when just the register and one
> place is technically enough. But yes if it's more readable to have
> guest_trfcr_el1 separately then that makes sense.
Yeah, since this is all per-cpu data at this point rather than per-vCPU,
it isn't the end of the world to use a few extra bytes.
> That works, it would be nice to have it consistent and have it that way for
> filtering, like kvm_set_guest_trace_filters(bool kernel, bool user). But I
> suppose we can justify not doing it there because we're not really
> interpreting the TRFCR value just writing it whole.
Agreed, the biggest thing I'd want to see in the exported interfaces
like this is to have enable/disable helpers to tell KVM when a driver
wants KVM to start/stop managing a piece of state while in a guest.
Then the hypervisor code can blindly save/restore some opaque values to
whatever registers it needs to update.
> > What if trace is disabled in the guest or in the host? Do we need to
> > synchronize when transitioning from an enabled -> disabled state like we
> > do today?
> >
>
> By synchronize do you mean the tsb_csync()? I can only see it being
> necessary for the TRBE case because then writing to the buffer is fatal.
> Without TRBE the trace sinks still work and the boundary of when exactly
> tracing is disabled in the kernel isn't critical.
Ack, I had the blinders on that we cared only about TRBE here.
> > I took a stab at this, completely untested of course && punts on
> > protected mode. But this is _generally_ how I'd like to see everything
> > fit together.
> >
>
> Would you expect to see the protected mode stuff ignored if I sent another
> version more like yours below? Or was that just skipped to keep the example
> shorter?
Skipped since I slapped this together in a hurry.
> I think I'm a bit uncertain on that one because removing HAS_TRBE means you
> can't check if TRBE is enabled or not in protected mode and it will go wrong
> if it is.
The protected mode hypervisor will need two bits of information.
Detecting that the feature is present can be done in the kernel so long
as the corresponding static key / cpucap is toggled before we drop
privileges.
Whether or not it is programmable + enabled is a decision that must be
made by observing hardware state from the hypervisor before entering a
guest.
[...]
> > +void kvm_enable_trbe(u64 guest_trfcr)
> > +{
> > + if (WARN_ON_ONCE(preemptible()))
> > + return;
> > +
> > + if (has_vhe()) {
> > + write_sysreg_s(guest_trfcr, SYS_TRFCR_EL12);
> > + return;
> > + }
> > +
> > + *host_data_ptr(guest_trfcr_el1) = guest_trfcr;
> > + host_data_set_flag(HOST_TRBE_ENABLED);
>
> FWIW TRBE and TRF are separate features, so this wouldn't do the filtering
> correctly if TRBE wasn't in use, but I can split it out into
> separate kvm_enable_trbe(void) and kvm_set_guest_filters(u64 guest_trfcr).
KVM manages the same piece of state (TRFCR_EL1) either way though right?
The expectation I had is that KVM is informed any time a trace session
(TRBE or otherwise) is enabled/disabled on a CPU, likely with a TRFCR_EL1
of 0 if guest mode is excluded.
The function names might need massaging, but I was hoping to have a
single set of enable/disable knobs to cover all bases here.
--
Thanks,
Oliver
next prev parent reply other threads:[~2024-11-26 16:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 10:36 [PATCH v7 00/12] kvm/coresight: Support exclude guest and exclude host James Clark
2024-11-12 10:37 ` [PATCH v7 01/12] arm64/sysreg: Add a comment that the sysreg file should be sorted James Clark
2024-11-12 10:37 ` [PATCH v7 02/12] tools: arm64: Update sysreg.h header files James Clark
2024-11-12 10:37 ` [PATCH v7 03/12] arm64/sysreg/tools: Move TRFCR definitions to sysreg James Clark
2024-11-12 10:37 ` [PATCH v7 04/12] KVM: arm64: Make vcpu flag macros more generic James Clark
2024-11-18 9:00 ` Marc Zyngier
2024-11-18 9:22 ` James Clark
2024-11-12 10:37 ` [PATCH v7 05/12] KVM: arm64: Move SPE and TRBE flags to host data James Clark
2024-11-12 10:37 ` [PATCH v7 06/12] KVM: arm64: Add flag for FEAT_TRF James Clark
2024-11-12 10:37 ` [PATCH v7 07/12] KVM: arm64: arm_spe: Give SPE enabled state to KVM James Clark
2024-11-20 9:16 ` Oliver Upton
2024-11-20 9:43 ` James Clark
2024-11-12 10:37 ` [PATCH v7 08/12] KVM: arm64: Don't hit sysregs to see if SPE is enabled or not James Clark
2024-11-12 10:37 ` [PATCH v7 09/12] KVM: arm64: coresight: Give TRBE enabled state to KVM James Clark
2024-11-12 10:37 ` [PATCH v7 10/12] KVM: arm64: Don't hit sysregs to see if TRBE is enabled or not James Clark
2024-11-12 10:37 ` [PATCH v7 11/12] KVM: arm64: Swap TRFCR on guest switch James Clark
2024-11-20 17:31 ` Oliver Upton
2024-11-21 12:50 ` James Clark
2024-11-26 16:23 ` Oliver Upton [this message]
2024-11-27 10:08 ` James Clark
2024-11-12 10:37 ` [PATCH v7 12/12] coresight: Pass guest TRFCR value to KVM James Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z0X2BBBaDejFfATp@linux.dev \
--to=oliver.upton@linux.dev \
--cc=alexander.shishkin@linux.intel.com \
--cc=anshuman.khandual@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=coresight@lists.linaro.org \
--cc=james.clark@linaro.org \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mike.leach@linaro.org \
--cc=rananta@google.com \
--cc=robh@kernel.org \
--cc=shiqiliu@hust.edu.cn \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).