linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Murray <andrew.murray@arm.com>
To: Christoffer Dall <christoffer.dall@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Julien Thierry <julien.thierry@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v10 5/5] arm64: KVM: Enable support for :G/:H perf event modifiers
Date: Mon, 4 Mar 2019 09:40:57 +0000	[thread overview]
Message-ID: <20190301105410.GB40984@e119886-lin.cambridge.arm.com> (raw)
In-Reply-To: <20190218220019.GB28113@e113682-lin.lund.arm.com>

On Mon, Feb 18, 2019 at 11:00:19PM +0100, Christoffer Dall wrote:
> On Mon, Jan 14, 2019 at 04:11:48PM +0000, Andrew Murray wrote:
> > Enable/disable event counters as appropriate when entering and exiting
> > the guest to enable support for guest or host only event counting.
> > 
> > For both VHE and non-VHE we switch the counters between host/guest at
> > EL2. EL2 is filtered out by the PMU when we are using the :G modifier.
> 
> I don't think the last part is strictly true as per the former patch on
> a non-vhe system if you have the :h modifier, so maybe just leave that
> out of the commit message.

OK I'll remove that.

> 
> > 
> > The PMU may be on when we change which counters are enabled however
> > we avoid adding an isb as we instead rely on existing context
> > synchronisation events: the isb in kvm_arm_vhe_guest_exit for VHE and
> > the eret from the hvc in kvm_call_hyp.
> > 
> > Signed-off-by: Andrew Murray <andrew.murray@arm.com>
> > Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  arch/arm64/kvm/hyp/switch.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 60 insertions(+)
> > 
> > diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
> > index b0b1478..9018fb3 100644
> > --- a/arch/arm64/kvm/hyp/switch.c
> > +++ b/arch/arm64/kvm/hyp/switch.c
> > @@ -357,6 +357,54 @@ static bool __hyp_text __hyp_switch_fpsimd(struct kvm_vcpu *vcpu)
> >  	return true;
> >  }
> >  
> > +static bool __hyp_text __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt)
> > +{
> > +	struct kvm_host_data *host;
> > +	struct kvm_pmu_events *pmu;
> > +	u32 clr, set;
> > +
> > +	host = container_of(host_ctxt, struct kvm_host_data, host_ctxt);
> > +	pmu = &host->pmu_events;
> > +
> > +	/* We can potentially avoid a sysreg write by only changing bits that
> > +	 * differ between the guest/host. E.g. where events are enabled in
> > +	 * both guest and host
> > +	 */
> 
> super nit: kernel coding style requires 'wings' on both side of a
> multi-line comment.  Only if you respin anyhow.

Ah I didn't notice that, I'll fix this up.

Thanks for the review.

Andrew Murray

> 
> > +	clr = pmu->events_host & ~pmu->events_guest;
> > +	set = pmu->events_guest & ~pmu->events_host;
> > +
> > +	if (clr)
> > +		write_sysreg(clr, pmcntenclr_el0);
> > +
> > +	if (set)
> > +		write_sysreg(set, pmcntenset_el0);
> > +
> > +	return (clr || set);
> > +}
> > +
> > +static void __hyp_text __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt)
> > +{
> > +	struct kvm_host_data *host;
> > +	struct kvm_pmu_events *pmu;
> > +	u32 clr, set;
> > +
> > +	host = container_of(host_ctxt, struct kvm_host_data, host_ctxt);
> > +	pmu = &host->pmu_events;
> > +
> > +	/* We can potentially avoid a sysreg write by only changing bits that
> > +	 * differ between the guest/host. E.g. where events are enabled in
> > +	 * both guest and host
> > +	 */
> 
> ditto
> 
> > +	clr = pmu->events_guest & ~pmu->events_host;
> > +	set = pmu->events_host & ~pmu->events_guest;
> > +
> > +	if (clr)
> > +		write_sysreg(clr, pmcntenclr_el0);
> > +
> > +	if (set)
> > +		write_sysreg(set, pmcntenset_el0);
> > +}
> > +
> >  /*
> >   * Return true when we were able to fixup the guest exit and should return to
> >   * the guest, false when we should restore the host state and return to the
> > @@ -464,12 +512,15 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
> >  {
> >  	struct kvm_cpu_context *host_ctxt;
> >  	struct kvm_cpu_context *guest_ctxt;
> > +	bool pmu_switch_needed;
> >  	u64 exit_code;
> >  
> >  	host_ctxt = vcpu->arch.host_cpu_context;
> >  	host_ctxt->__hyp_running_vcpu = vcpu;
> >  	guest_ctxt = &vcpu->arch.ctxt;
> >  
> > +	pmu_switch_needed = __pmu_switch_to_guest(host_ctxt);
> > +
> >  	sysreg_save_host_state_vhe(host_ctxt);
> >  
> >  	/*
> > @@ -511,6 +562,9 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu)
> >  
> >  	__debug_switch_to_host(vcpu);
> >  
> > +	if (pmu_switch_needed)
> > +		__pmu_switch_to_host(host_ctxt);
> > +
> >  	return exit_code;
> >  }
> >  
> > @@ -519,6 +573,7 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu)
> >  {
> >  	struct kvm_cpu_context *host_ctxt;
> >  	struct kvm_cpu_context *guest_ctxt;
> > +	bool pmu_switch_needed;
> >  	u64 exit_code;
> >  
> >  	vcpu = kern_hyp_va(vcpu);
> > @@ -527,6 +582,8 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu)
> >  	host_ctxt->__hyp_running_vcpu = vcpu;
> >  	guest_ctxt = &vcpu->arch.ctxt;
> >  
> > +	pmu_switch_needed = __pmu_switch_to_guest(host_ctxt);
> > +
> >  	__sysreg_save_state_nvhe(host_ctxt);
> >  
> >  	__activate_vm(kern_hyp_va(vcpu->kvm));
> > @@ -573,6 +630,9 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu)
> >  	 */
> >  	__debug_switch_to_host(vcpu);
> >  
> > +	if (pmu_switch_needed)
> > +		__pmu_switch_to_host(host_ctxt);
> > +
> >  	return exit_code;
> >  }
> >  
> > -- 
> > 2.7.4
> > 
> 
> Thanks,
> 
>     Christoffer

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2019-03-04  9:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-14 16:11 [PATCH v10 0/5] arm64: Support perf event modifiers :G and :H Andrew Murray
2019-01-14 16:11 ` [PATCH v10 1/5] arm64: arm_pmu: remove unnecessary isb instruction Andrew Murray
2019-01-14 16:11 ` [PATCH v10 2/5] arm64: KVM: encapsulate kvm_cpu_context in kvm_host_data Andrew Murray
2019-01-14 16:11 ` [PATCH v10 3/5] arm64: KVM: add accessors to track guest/host only counters Andrew Murray
2019-01-14 16:11 ` [PATCH v10 4/5] arm64: arm_pmu: Add support for exclude_host/exclude_guest attributes Andrew Murray
2019-02-11 11:26   ` Will Deacon
2019-02-18 21:53   ` Christoffer Dall
2019-02-20 16:15     ` Andrew Murray
2019-02-26 12:44       ` Christoffer Dall
2019-03-04 11:14         ` Andrew Murray
2019-03-05 11:45           ` Andrew Murray
2019-03-06  8:42             ` Christoffer Dall
2019-01-14 16:11 ` [PATCH v10 5/5] arm64: KVM: Enable support for :G/:H perf event modifiers Andrew Murray
2019-02-18 22:00   ` Christoffer Dall
2019-03-04  9:40     ` Andrew Murray [this message]

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=20190301105410.GB40984@e119886-lin.cambridge.arm.com \
    --to=andrew.murray@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=julien.thierry@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will.deacon@arm.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).