From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com,
yuzenghui@huawei.com, will@kernel.org, catalin.marinas@arm.com,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
james.clark@linaro.org, mark.rutland@arm.com,
james.morse@arm.com
Subject: Re: [RFC PATCH v6 17/35] KVM: arm64: Add writable SPE system registers to VCPU context
Date: Mon, 5 Jan 2026 16:42:34 +0000 [thread overview]
Message-ID: <aVvp-vp47ZIc5vfH@raptor> (raw)
In-Reply-To: <3ccbd4df-92a3-4d70-9ed8-c4a5658508d1@arm.com>
Hi Suzuki,
On Tue, Dec 16, 2025 at 11:54:54AM +0000, Suzuki K Poulose wrote:
> On 14/11/2025 16:06, Alexandru Elisei wrote:
> > Add the writable SPE registers to the VCPU context. The registers for now
> > have generic accessors, with proper handling to be added. PMSIDR_EL1 and
> > PMBIDR_EL1 are not part of the VCPU context because they are read-only
> > registers.
..
> > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
> > index 3ad6b7c6e4ba..0821ebfb03fa 100644
> > --- a/arch/arm64/kvm/debug.c
> > +++ b/arch/arm64/kvm/debug.c
> > @@ -38,19 +38,28 @@ static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu)
> > {
> > preempt_disable();
> > - /*
> > - * This also clears MDCR_EL2_E2PB_MASK and MDCR_EL2_E2TB_MASK
> > - * to disable guest access to the profiling and trace buffers
> > - */
> > vcpu->arch.mdcr_el2 = FIELD_PREP(MDCR_EL2_HPMN,
> > *host_data_ptr(nr_event_counters));
> > + /*
> > + * This also clears MDCR_EL2_E2PB_MASK to disable guest access to the
> > + * trace buffer.
>
> nit: MDCR_EL2_E2TB_MASK is for the trace buffer.
Indeed, I'll fix.
Thanks,
Alex
>
>
> Suzuki
>
>
> > + */
> > vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM |
> > - MDCR_EL2_TPMS |
> > MDCR_EL2_TTRF |
> > MDCR_EL2_TPMCR |
> > MDCR_EL2_TDRA |
> > MDCR_EL2_TDOSA);
> > + if (vcpu_has_spe(vcpu)) {
> > + /* Set buffer owner to EL1 and trap the buffer registers. */
> > + vcpu->arch.mdcr_el2 |= FIELD_PREP(MDCR_EL2_E2PB, MDCR_EL2_E2PB_EL1_TRAP);
> > + /* Leave TPMS zero and don't trap the sampling registers. */
> > + } else {
> > + /* Trap the sampling registers. */
> > + vcpu->arch.mdcr_el2 |= MDCR_EL2_TPMS;
> > + /* Leave E2PB zero and trap the buffer registers. */
> > + }
> > +
> > /* Is the VM being debugged by userspace? */
> > if (vcpu->guest_debug)
> > /* Route all software debug exceptions to EL2 */
> > diff --git a/arch/arm64/kvm/spe.c b/arch/arm64/kvm/spe.c
> > index 0c4896c6a873..5b3dc622cf82 100644
> > --- a/arch/arm64/kvm/spe.c
> > +++ b/arch/arm64/kvm/spe.c
> > @@ -8,6 +8,7 @@
> > #include <linux/kvm_host.h>
> > #include <linux/perf/arm_spe_pmu.h>
> > +#include <asm/kvm_emulate.h>
> > #include <asm/kvm_spe.h>
> > #include <asm/sysreg.h>
> > @@ -78,6 +79,18 @@ u8 kvm_spe_get_pmsver_limit(void)
> > return min(pmsver, ID_AA64DFR0_EL1_PMSVer_V1P5);
> > }
> > +bool kvm_spe_write_sysreg(struct kvm_vcpu *vcpu, int reg, u64 val)
> > +{
> > + __vcpu_assign_sys_reg(vcpu, val, reg);
> > +
> > + return true;
> > +}
> > +
> > +u64 kvm_spe_read_sysreg(struct kvm_vcpu *vcpu, int reg)
> > +{
> > + return __vcpu_sys_reg(vcpu, reg);
> > +}
> > +
> > static u64 max_buffer_size_to_pmbidr_el1(u64 size)
> > {
> > u64 msb_idx, num_bits;
> > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> > index ac859c39c2be..5eeea229b46e 100644
> > --- a/arch/arm64/kvm/sys_regs.c
> > +++ b/arch/arm64/kvm/sys_regs.c
> > @@ -1374,6 +1374,28 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
> > return 0;
> > }
> > +static unsigned int spe_visibility(const struct kvm_vcpu *vcpu,
> > + const struct sys_reg_desc *r)
> > +{
> > + if (vcpu_has_spe(vcpu))
> > + return 0;
> > +
> > + return REG_HIDDEN;
> > +}
> > +
> > +static bool access_spe_reg(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
> > + const struct sys_reg_desc *r)
> > +{
> > + u64 val = p->regval;
> > + int reg = r->reg;
> > +
> > + if (p->is_write)
> > + return kvm_spe_write_sysreg(vcpu, reg, val);
> > +
> > + p->regval = kvm_spe_read_sysreg(vcpu, reg);
> > + return true;
> > +}
> > +
> > /* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */
> > #define DBG_BCR_BVR_WCR_WVR_EL1(n) \
> > { SYS_DESC(SYS_DBGBVRn_EL1(n)), \
> > @@ -1406,6 +1428,14 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
> > .reset = reset_pmevtyper, \
> > .access = access_pmu_evtyper, .reg = (PMEVTYPER0_EL0 + n), }
> > +#define SPE_TRAPPED_REG(name) \
> > + SYS_DESC(SYS_##name), .reg = name, .access = access_spe_reg, \
> > + .reset = reset_val, .val = 0, .visibility = spe_visibility
> > +
> > +#define SPE_UNTRAPPED_REG(name) \
> > + SYS_DESC(SYS_##name), .reg = name, .access = undef_access, \
> > + .reset = reset_val, .val = 0, .visibility = spe_visibility
> > +
> > /* Macro to expand the AMU counter and type registers*/
> > #define AMU_AMEVCNTR0_EL0(n) { SYS_DESC(SYS_AMEVCNTR0_EL0(n)), undef_access }
> > #define AMU_AMEVTYPER0_EL0(n) { SYS_DESC(SYS_AMEVTYPER0_EL0(n)), undef_access }
> > @@ -3323,19 +3353,19 @@ static const struct sys_reg_desc sys_reg_descs[] = {
> > { SYS_DESC(SYS_FAR_EL1), access_vm_reg, reset_unknown, FAR_EL1 },
> > { SYS_DESC(SYS_PAR_EL1), NULL, reset_unknown, PAR_EL1 },
> > - { SYS_DESC(SYS_PMSCR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSNEVFR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSICR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSIRR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSFCR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSEVFR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSLATFR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSIDR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMBLIMITR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMBPTR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMBSR_EL1), undef_access },
> > - { SYS_DESC(SYS_PMSDSFR_EL1), undef_access },
> > - /* PMBIDR_EL1 is not trapped */
> > + { SPE_UNTRAPPED_REG(PMSCR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSNEVFR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSICR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSIRR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSFCR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSEVFR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSLATFR_EL1) },
> > + { SYS_DESC(SYS_PMSIDR_EL1), .access = undef_access },
> > + { SPE_TRAPPED_REG(PMBLIMITR_EL1) },
> > + { SPE_TRAPPED_REG(PMBPTR_EL1) },
> > + { SPE_TRAPPED_REG(PMBSR_EL1) },
> > + { SPE_UNTRAPPED_REG(PMSDSFR_EL1) },
> > + { SYS_DESC(SYS_PMBIDR_EL1), .access = undef_access },
> > { PMU_SYS_REG(PMINTENSET_EL1),
> > .access = access_pminten, .reg = PMINTENSET_EL1,
>
next prev parent reply other threads:[~2026-01-05 16:42 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 16:06 [RFC PATCH v6 00/35] KVM: arm64: Add Statistical Profiling Extension (SPE) support Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 01/35] arm64/sysreg: Add new SPE fields Alexandru Elisei
2025-12-10 18:38 ` Leo Yan
2025-12-12 9:39 ` Alexandru Elisei
2025-12-15 21:42 ` Suzuki K Poulose
2025-11-14 16:06 ` [RFC PATCH v6 02/35] arm64/sysreg: Define MDCR_EL2.E2PB values Alexandru Elisei
2025-12-15 21:33 ` Suzuki K Poulose
2025-11-14 16:06 ` [RFC PATCH v6 03/35] KVM: arm64: Add CONFIG_KVM_ARM_SPE Kconfig option Alexandru Elisei
2026-01-09 16:29 ` James Clark
2026-01-12 11:26 ` Alexandru Elisei
2026-01-12 12:09 ` James Clark
2026-01-12 12:14 ` James Clark
2026-01-12 15:18 ` Alexandru Elisei
2026-01-13 10:25 ` Alexandru Elisei
2026-01-13 15:00 ` James Clark
2026-01-13 17:03 ` Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 04/35] perf: arm_spe_pmu: Move struct arm_spe_pmu to a separate header file Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 05/35] KVM: arm64: Add KVM_CAP_ARM_SPE capability Alexandru Elisei
2025-12-14 12:18 ` Leo Yan
2025-12-15 11:46 ` Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 06/35] KVM: arm64: Add KVM_ARM_VCPU_SPE VCPU feature Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 07/35] HACK! KVM: arm64: Disable SPE virtualization if protected KVM is enabled Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 08/35] HACK! KVM: arm64: Enable SPE virtualization only in VHE mode Alexandru Elisei
2025-12-15 17:49 ` Leo Yan
2025-11-14 16:06 ` [RFC PATCH v6 09/35] HACK! KVM: arm64: Disable SPE virtualization if nested virt is enabled Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 10/35] KVM: arm64: Add a new VCPU device control group for SPE Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 11/35] KVM: arm64: Add SPE VCPU device attribute to set the interrupt number Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 12/35] KVM: arm64: Add SPE VCPU device attribute to set the SPU device Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 13/35] perf: arm_spe_pmu: Add PMBIDR_EL1 to struct arm_spe_pmu Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 14/35] KVM: arm64: Add SPE VCPU device attribute to set the max buffer size Alexandru Elisei
2026-01-09 16:29 ` James Clark
2026-01-12 11:28 ` Alexandru Elisei
2026-01-12 11:50 ` James Clark
2026-01-12 14:03 ` Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 15/35] KVM: arm64: Add SPE VCPU device attribute to initialize SPE Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 16/35] KVM: arm64: Advertise SPE version in ID_AA64DFR0_EL1.PMSver Alexandru Elisei
2025-12-16 11:40 ` Suzuki K Poulose
2026-01-05 16:42 ` Alexandru Elisei
2025-11-14 16:06 ` [RFC PATCH v6 17/35] KVM: arm64: Add writable SPE system registers to VCPU context Alexandru Elisei
2025-12-16 11:54 ` Suzuki K Poulose
2026-01-05 16:42 ` Alexandru Elisei [this message]
2025-11-14 16:06 ` [RFC PATCH v6 18/35] perf: arm_spe_pmu: Add PMSIDR_EL1 to struct arm_spe_pmu Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 19/35] KVM: arm64: Trap PMBIDR_EL1 and PMSIDR_EL1 Alexandru Elisei
2026-01-09 16:29 ` James Clark
2026-01-12 11:28 ` Alexandru Elisei
2026-01-12 11:54 ` James Clark
2026-01-13 12:48 ` Alexandru Elisei
2026-01-13 14:22 ` James Clark
2025-11-14 16:07 ` [RFC PATCH v6 20/35] KVM: arm64: config: Use functions from spe.c to test FEAT_SPE_{FnE,FDS} Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 21/35] KVM: arm64: Check for unsupported CPU early in kvm_arch_vcpu_load() Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 22/35] KVM: arm64: VHE: Context switch SPE state Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 23/35] KVM: arm64: Allow guest SPE physical timestamps only if perfmon_capable() Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 24/35] KVM: arm64: Handle SPE hardware maintenance interrupts Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 25/35] KVM: arm64: Add basic handling of SPE buffer control registers writes Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 26/35] KVM: arm64: Add comment to explain how trapped SPE registers are handled Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 27/35] KVM: arm64: Make MTE functions public Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 28/35] KVM: arm64: at: Use callback for reading descriptor Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 29/35] KVM: arm64: Pin the SPE buffer in the host and map it at stage 2 Alexandru Elisei
2026-01-09 16:29 ` James Clark
2026-01-09 16:35 ` James Clark
2026-01-12 12:01 ` Alexandru Elisei
2026-01-13 14:18 ` James Clark
2025-11-14 16:07 ` [RFC PATCH v6 30/35] KVM: Propagate MMU event to the MMU notifier handlers Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 31/35] KVM: arm64: Handle MMU notifiers for the SPE buffer Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 32/35] KVM: Add KVM_EXIT_RLIMIT exit_reason Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 33/35] KVM: arm64: Implement locked memory accounting for the SPE buffer Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 34/35] KVM: arm64: Add hugetlb support for SPE Alexandru Elisei
2025-11-14 16:07 ` [RFC PATCH v6 35/35] KVM: arm64: Allow the creation of a SPE enabled VM Alexandru Elisei
2025-12-11 16:34 ` [RFC PATCH v6 00/35] KVM: arm64: Add Statistical Profiling Extension (SPE) support Leo Yan
2025-12-12 10:18 ` Alexandru Elisei
2025-12-12 11:15 ` Leo Yan
2025-12-12 11:54 ` Alexandru Elisei
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=aVvp-vp47ZIc5vfH@raptor \
--to=alexandru.elisei@arm.com \
--cc=catalin.marinas@arm.com \
--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=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.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