Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: Oliver Upton <oliver.upton@linux.dev>, kvmarm@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Mingwei Zhang <mizhang@google.com>,
	Colton Lewis <coltonlewis@google.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	James Clark <james.clark@linaro.org>,
	james.clark2@arm.com
Subject: Re: [PATCH 03/15] KVM: arm64: Track presence of SPE/TRBE in kvm_host_data instead of vCPU
Date: Mon, 11 Nov 2024 15:58:13 +0000	[thread overview]
Message-ID: <80c6cafa-dc17-4a47-8fae-9eea03e69f15@arm.com> (raw)
In-Reply-To: <fac9f76d-d7e4-4a1a-844a-85c64af581b6@arm.com>

On 11/11/2024 13:47, Suzuki K Poulose wrote:
> Cc: James Clark
> 
> Hi Oliver
> 
> On 08/11/2024 22:24, Oliver Upton wrote:
>> Add flags to kvm_host_data to track if SPE/TRBE is present +
>> programmable on a per-CPU basis. Set the flags up at init rather than
>> vcpu_load() as the programmability of these buffers is unlikely to
>> change.
>>
> 
> Heads up, there is a similar change from James Clark here :
> 
> https://lkml.kernel.org/r/20241101155412.1152709-6-james.clark2@arm.com

Ah, bad. That patch isn't on the public list yet. Never mind ;-). I will 
leave James to deal with this series ;-).

For context, James is trying to enable Guest filtering for CoreSight 
trace, v6 of that one is available here :

https://lkml.kernel.org/r/20240226113044.228403-1-james.clark@arm.com

Suzuki


> 
> This change as such looks good to me.
> 
> Suzuki
> 
>> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
>> ---
>>   arch/arm64/include/asm/kvm_host.h  | 18 ++++++++-------
>>   arch/arm64/kvm/arm.c               |  3 ---
>>   arch/arm64/kvm/debug.c             | 36 ++++++++----------------------
>>   arch/arm64/kvm/hyp/nvhe/debug-sr.c |  8 +++----
>>   4 files changed, 23 insertions(+), 42 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/ 
>> asm/kvm_host.h
>> index ad514434f3fe..07da4129f1d1 100644
>> --- a/arch/arm64/include/asm/kvm_host.h
>> +++ b/arch/arm64/include/asm/kvm_host.h
>> @@ -610,6 +610,10 @@ struct cpu_sve_state {
>>    * field.
>>    */
>>   struct kvm_host_data {
>> +#define KVM_HOST_DATA_FLAG_HAS_SPE    0
>> +#define KVM_HOST_DATA_FLAG_HAS_TRBE    1
>> +    unsigned long flags;
>> +
>>       struct kvm_cpu_context host_ctxt;
>>       /*
>> @@ -911,10 +915,6 @@ struct kvm_vcpu_arch {
>>   #define EXCEPT_AA64_EL2_SERR    __vcpu_except_flags(7)
>>   /* Guest debug is live */
>>   #define DEBUG_DIRTY        __vcpu_single_flag(iflags, BIT(4))
>> -/* Save SPE context if active  */
>> -#define DEBUG_STATE_SAVE_SPE    __vcpu_single_flag(iflags, BIT(5))
>> -/* Save TRBE context if active  */
>> -#define DEBUG_STATE_SAVE_TRBE    __vcpu_single_flag(iflags, BIT(6))
>>   /* SVE enabled for host EL0 */
>>   #define HOST_SVE_ENABLED    __vcpu_single_flag(sflags, BIT(0))
>> @@ -1310,6 +1310,12 @@ DECLARE_KVM_HYP_PER_CPU(struct kvm_host_data, 
>> kvm_host_data);
>>        &this_cpu_ptr_hyp_sym(kvm_host_data)->f)
>>   #endif
>> +#define host_data_test_flag(flag)                    \
>> +    (test_bit(KVM_HOST_DATA_FLAG_##flag, host_data_ptr(flags)))
>> +#define host_data_set_flag(flag)                    \
>> +    (set_bit(KVM_HOST_DATA_FLAG_##flag, host_data_ptr(flags)))
>> +
>> +
>>   /* Check whether the FP regs are owned by the guest */
>>   static inline bool guest_owns_fp_regs(void)
>>   {
>> @@ -1370,10 +1376,6 @@ static inline bool 
>> kvm_pmu_counter_deferred(struct perf_event_attr *attr)
>>       return (!has_vhe() && attr->exclude_host);
>>   }
>> -/* Flags for host debug state */
>> -void kvm_arch_vcpu_load_debug_state_flags(struct kvm_vcpu *vcpu);
>> -void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu);
>> -
>>   #ifdef CONFIG_KVM
>>   void kvm_set_pmu_events(u64 set, struct perf_event_attr *attr);
>>   void kvm_clr_pmu_events(u64 clr);
>> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
>> index ab1bf9ccf385..3822774840e1 100644
>> --- a/arch/arm64/kvm/arm.c
>> +++ b/arch/arm64/kvm/arm.c
>> @@ -617,15 +617,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, 
>> int cpu)
>>       vcpu_set_pauth_traps(vcpu);
>> -    kvm_arch_vcpu_load_debug_state_flags(vcpu);
>> -
>>       if (!cpumask_test_cpu(cpu, vcpu->kvm->arch.supported_cpus))
>>           vcpu_set_on_unsupported_cpu(vcpu);
>>   }
>>   void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
>>   {
>> -    kvm_arch_vcpu_put_debug_state_flags(vcpu);
>>       kvm_arch_vcpu_put_fp(vcpu);
>>       if (has_vhe())
>>           kvm_vcpu_put_vhe(vcpu);
>> diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
>> index 90ecf1210bd0..97d0c6fd5f61 100644
>> --- a/arch/arm64/kvm/debug.c
>> +++ b/arch/arm64/kvm/debug.c
>> @@ -294,40 +294,22 @@ void kvm_arm_clear_debug(struct kvm_vcpu *vcpu)
>>       }
>>   }
>> -void kvm_arch_vcpu_load_debug_state_flags(struct kvm_vcpu *vcpu)
>> +void kvm_init_host_debug_data(void)
>>   {
>> -    u64 dfr0;
>> +    u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
>> +
>> +    if (cpuid_feature_extract_signed_field(dfr0, 
>> ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
>> +        *host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
>> +                                  read_sysreg(pmcr_el0));
>> -    /* For VHE, there is nothing to do */
>>       if (has_vhe())
>>           return;
>> -    dfr0 = read_sysreg(id_aa64dfr0_el1);
>> -    /*
>> -     * If SPE is present on this CPU and is available at current EL,
>> -     * we may need to check if the host state needs to be saved.
>> -     */
>>       if (cpuid_feature_extract_unsigned_field(dfr0, 
>> ID_AA64DFR0_EL1_PMSVer_SHIFT) &&
>> -        !(read_sysreg_s(SYS_PMBIDR_EL1) & BIT(PMBIDR_EL1_P_SHIFT)))
>> -        vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_SPE);
>> +        !(read_sysreg_s(SYS_PMBIDR_EL1) & PMBIDR_EL1_P))
>> +        host_data_set_flag(HAS_SPE);
>> -    /* Check if we have TRBE implemented and available at the host */
>>       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);
>> -}
>> -
>> -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);
>> -}
>> -
>> -void kvm_init_host_debug_data(void)
>> -{
>> -    u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
>> -
>> -    if (cpuid_feature_extract_signed_field(dfr0, 
>> ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
>> -        *host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
>> -                                  read_sysreg(pmcr_el0));
>> +        host_data_set_flag(HAS_TRBE);
>>   }
>> diff --git a/arch/arm64/kvm/hyp/nvhe/debug-sr.c b/arch/arm64/kvm/hyp/ 
>> nvhe/debug-sr.c
>> index 1e2a26d0196e..858bb38e273f 100644
>> --- a/arch/arm64/kvm/hyp/nvhe/debug-sr.c
>> +++ b/arch/arm64/kvm/hyp/nvhe/debug-sr.c
>> @@ -82,10 +82,10 @@ static void __debug_restore_trace(u64 trfcr_el1)
>>   void __debug_save_host_buffers_nvhe(struct kvm_vcpu *vcpu)
>>   {
>>       /* Disable and flush SPE data generation */
>> -    if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_SPE))
>> +    if (host_data_test_flag(HAS_SPE))
>>           __debug_save_spe(host_data_ptr(host_debug_state.pmscr_el1));
>>       /* Disable and flush Self-Hosted Trace generation */
>> -    if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_TRBE))
>> +    if (host_data_test_flag(HAS_TRBE))
>>           __debug_save_trace(host_data_ptr(host_debug_state.trfcr_el1));
>>   }
>> @@ -96,9 +96,9 @@ void __debug_switch_to_guest(struct kvm_vcpu *vcpu)
>>   void __debug_restore_host_buffers_nvhe(struct kvm_vcpu *vcpu)
>>   {
>> -    if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_SPE))
>> +    if (host_data_test_flag(HAS_SPE))
>>           
>> __debug_restore_spe(*host_data_ptr(host_debug_state.pmscr_el1));
>> -    if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_TRBE))
>> +    if (host_data_test_flag(HAS_TRBE))
>>           
>> __debug_restore_trace(*host_data_ptr(host_debug_state.trfcr_el1));
>>   }
> 
> 


  reply	other threads:[~2024-11-11 15:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08 22:24 [PATCH 00/15] KVM: arm64: Debug cleanups Oliver Upton
2024-11-08 22:24 ` [PATCH 01/15] KVM: arm64: Drop MDSCR_EL1_DEBUG_MASK Oliver Upton
2024-11-08 22:24 ` [PATCH 02/15] KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts Oliver Upton
2024-11-11 11:00   ` Suzuki K Poulose
2024-11-12  7:22     ` Oliver Upton
2024-11-08 22:24 ` [PATCH 03/15] KVM: arm64: Track presence of SPE/TRBE in kvm_host_data instead of vCPU Oliver Upton
2024-11-11 13:47   ` Suzuki K Poulose
2024-11-11 15:58     ` Suzuki K Poulose [this message]
2024-11-11 16:09       ` James Clark
2024-11-11 18:17         ` Oliver Upton
2024-11-08 22:24 ` [PATCH 04/15] KVM: arm64: Move host SME/SVE tracking flags to host data Oliver Upton
2024-11-09 11:39   ` Marc Zyngier
2024-11-08 22:24 ` [PATCH 05/15] KVM: arm64: Evaluate debug owner at vcpu_load() Oliver Upton
2024-11-08 22:24 ` [PATCH 06/15] KVM: arm64: Advance debug_owner state machine for sysreg traps Oliver Upton
2024-11-09 11:47   ` Marc Zyngier
2024-11-08 22:24 ` [PATCH 07/15] KVM: arm64: Clean up KVM_SET_GUEST_DEBUG handler Oliver Upton
2024-11-08 22:24 ` [PATCH 08/15] KVM: arm64: Select debug state to save/restore based on debug owner Oliver Upton
2024-11-09 11:57   ` Marc Zyngier
2024-11-09 17:13     ` Oliver Upton
2024-11-08 22:24 ` [PATCH 09/15] KVM: arm64: Remove debug tracepoints Oliver Upton
2024-11-09 12:02   ` Marc Zyngier
2024-11-09 13:17     ` Marc Zyngier
2024-11-08 22:24 ` [PATCH 10/15] KVM: arm64: Remove vestiges of debug_ptr Oliver Upton
2024-11-08 22:24 ` [PATCH 11/15] KVM: arm64: Use debug_owner to track if debug regs need save/restore Oliver Upton
2024-11-09 12:11   ` Marc Zyngier
2024-11-09 17:18     ` Oliver Upton
2024-11-09 22:37       ` Marc Zyngier
2024-11-09 23:46         ` Oliver Upton
2024-11-08 22:24 ` [PATCH 12/15] KVM: arm64: Reload vCPU for accesses to OSLAR_EL1 Oliver Upton
2024-11-08 22:24 ` [PATCH 13/15] KVM: arm64: Compute MDCR_EL2 at vcpu_load() Oliver Upton
2024-11-09 12:28   ` Marc Zyngier
2024-11-08 22:24 ` [PATCH 14/15] KVM: arm64: Don't hijack guest context MDSCR_EL1 Oliver Upton
2024-11-09 12:59   ` Marc Zyngier
2024-11-08 22:24 ` [PATCH 15/15] KVM: arm64: Manage software step state at load/put Oliver Upton
2024-11-09 13:13 ` [PATCH 00/15] KVM: arm64: Debug cleanups Marc Zyngier
2024-11-09 17:08   ` Oliver Upton

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=80c6cafa-dc17-4a47-8fae-9eea03e69f15@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=coltonlewis@google.com \
    --cc=james.clark2@arm.com \
    --cc=james.clark@linaro.org \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=mizhang@google.com \
    --cc=oliver.upton@linux.dev \
    --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