Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1476589 > unrolled thread

[RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions

Started byPunit Agrawal <punit.agrawal@arm.com>
First post2016-09-05 18:40 +0200
Last post2016-09-06 13:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions Punit Agrawal <punit.agrawal@arm.com> - 2016-09-05 18:40 +0200
    Re: [RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB  instructions Christoffer Dall <christoffer.dall@linaro.org> - 2016-09-06 12:30 +0200
      Re: [RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions Punit Agrawal <punit.agrawal@arm.com> - 2016-09-06 13:40 +0200

#1476589 — [RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions

FromPunit Agrawal <punit.agrawal@arm.com>
Date2016-09-05 18:40 +0200
Subject[RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions
Message-ID<se569-6cw-15@gated-at.bofh.it>
The TTLB bit of Hypervisor Control Register (HCR_EL2) controls the
trapping of guest TLB maintenance instructions. Taking the trap requires
a switch to the hypervisor and is an expensive operation.

Enable selective trapping of guest TLB instructions when the associated
perf trace event is enabled for a specific virtual machine.

Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/arm64/kvm/perf_trace.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/arch/arm64/kvm/perf_trace.c b/arch/arm64/kvm/perf_trace.c
index 8bacd18..f26da1d 100644
--- a/arch/arm64/kvm/perf_trace.c
+++ b/arch/arm64/kvm/perf_trace.c
@@ -17,6 +17,8 @@
 #include <linux/kvm_host.h>
 #include <linux/trace_events.h>
 
+#include <asm/kvm_emulate.h>
+
 typedef int (*perf_trace_callback_fn)(struct kvm *kvm, bool enable);
 
 struct kvm_trace_hook {
@@ -24,7 +26,37 @@ struct kvm_trace_hook {
 	perf_trace_callback_fn setup_fn;
 };
 
+static int tlb_invalidate_trap(struct kvm *kvm, bool enable)
+{
+	int i;
+	struct kvm_vcpu *vcpu;
+
+	/*
+	 * Halt the VM to ensure atomic update across all vcpus (this
+	 * avoids racy behaviour against other modifications of
+	 * HCR_EL2 such as kvm_toggle_cache/kvm_set_way_flush).
+	 */
+	kvm_arm_halt_guest(kvm);
+	kvm_for_each_vcpu(i, vcpu, kvm) {
+		unsigned long hcr = vcpu_get_hcr(vcpu);
+
+		if (enable)
+			hcr |= HCR_TTLB;
+		else
+			hcr &= ~HCR_TTLB;
+
+		vcpu_set_hcr(vcpu, hcr);
+	}
+	kvm_arm_resume_guest(kvm);
+
+	return 0;
+}
+
 static struct kvm_trace_hook trace_hook[] = {
+	{
+		.key = "kvm_tlb_invalidate",
+		.setup_fn = tlb_invalidate_trap,
+	},
 	{ },
 };
 
-- 
2.8.1

[toc] | [next] | [standalone]


#1477257 — Re: [RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions

FromChristoffer Dall <christoffer.dall@linaro.org>
Date2016-09-06 12:30 +0200
SubjectRe: [RFC v2 PATCH 7/7] arm64: KVM: Enable selective trapping of TLB instructions
Message-ID<selNE-MN-15@gated-at.bofh.it>
In reply to#1476589
On Mon, Sep 05, 2016 at 05:31:37PM +0100, Punit Agrawal wrote:
> The TTLB bit of Hypervisor Control Register (HCR_EL2) controls the
> trapping of guest TLB maintenance instructions. Taking the trap requires
> a switch to the hypervisor and is an expensive operation.
> 
> Enable selective trapping of guest TLB instructions when the associated
> perf trace event is enabled for a specific virtual machine.
> 
> Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
> Cc: Christoffer Dall <christoffer.dall@linaro.org>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> ---
>  arch/arm64/kvm/perf_trace.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/arch/arm64/kvm/perf_trace.c b/arch/arm64/kvm/perf_trace.c
> index 8bacd18..f26da1d 100644
> --- a/arch/arm64/kvm/perf_trace.c
> +++ b/arch/arm64/kvm/perf_trace.c
> @@ -17,6 +17,8 @@
>  #include <linux/kvm_host.h>
>  #include <linux/trace_events.h>
>  
> +#include <asm/kvm_emulate.h>
> +
>  typedef int (*perf_trace_callback_fn)(struct kvm *kvm, bool enable);
>  
>  struct kvm_trace_hook {
> @@ -24,7 +26,37 @@ struct kvm_trace_hook {
>  	perf_trace_callback_fn setup_fn;
>  };
>  
> +static int tlb_invalidate_trap(struct kvm *kvm, bool enable)
> +{
> +	int i;
> +	struct kvm_vcpu *vcpu;
> +
> +	/*
> +	 * Halt the VM to ensure atomic update across all vcpus (this
> +	 * avoids racy behaviour against other modifications of
> +	 * HCR_EL2 such as kvm_toggle_cache/kvm_set_way_flush).
> +	 */
> +	kvm_arm_halt_guest(kvm);
> +	kvm_for_each_vcpu(i, vcpu, kvm) {
> +		unsigned long hcr = vcpu_get_hcr(vcpu);
> +
> +		if (enable)
> +			hcr |= HCR_TTLB;
> +		else
> +			hcr &= ~HCR_TTLB;
> +
> +		vcpu_set_hcr(vcpu, hcr);
> +	}
> +	kvm_arm_resume_guest(kvm);
> +
> +	return 0;
> +}
> +
>  static struct kvm_trace_hook trace_hook[] = {
> +	{
> +		.key = "kvm_tlb_invalidate",

is this key defined elsewhere?  If not, I think the name is ambiguous,
because it's unclear if this means 'kvm the subsystem' or 'a kvm guest',
by looking purely at the string.

> +		.setup_fn = tlb_invalidate_trap,
> +	},
>  	{ },
>  };
>  
> -- 
> 2.8.1
> 

Otherwise looks ok to me.

-Christoffer

[toc] | [prev] | [next] | [standalone]


#1477292

FromPunit Agrawal <punit.agrawal@arm.com>
Date2016-09-06 13:40 +0200
Message-ID<semTn-1nX-13@gated-at.bofh.it>
In reply to#1477257
Christoffer Dall <christoffer.dall@linaro.org> writes:

> On Mon, Sep 05, 2016 at 05:31:37PM +0100, Punit Agrawal wrote:
>> The TTLB bit of Hypervisor Control Register (HCR_EL2) controls the
>> trapping of guest TLB maintenance instructions. Taking the trap requires
>> a switch to the hypervisor and is an expensive operation.
>> 
>> Enable selective trapping of guest TLB instructions when the associated
>> perf trace event is enabled for a specific virtual machine.
>> 
>> Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
>> Cc: Christoffer Dall <christoffer.dall@linaro.org>
>> Cc: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>>  arch/arm64/kvm/perf_trace.c | 32 ++++++++++++++++++++++++++++++++
>>  1 file changed, 32 insertions(+)
>> 
>> diff --git a/arch/arm64/kvm/perf_trace.c b/arch/arm64/kvm/perf_trace.c
>> index 8bacd18..f26da1d 100644
>> --- a/arch/arm64/kvm/perf_trace.c
>> +++ b/arch/arm64/kvm/perf_trace.c
>> @@ -17,6 +17,8 @@
>>  #include <linux/kvm_host.h>
>>  #include <linux/trace_events.h>
>>  
>> +#include <asm/kvm_emulate.h>
>> +
>>  typedef int (*perf_trace_callback_fn)(struct kvm *kvm, bool enable);
>>  
>>  struct kvm_trace_hook {
>> @@ -24,7 +26,37 @@ struct kvm_trace_hook {
>>  	perf_trace_callback_fn setup_fn;
>>  };
>>  
>> +static int tlb_invalidate_trap(struct kvm *kvm, bool enable)
>> +{
>> +	int i;
>> +	struct kvm_vcpu *vcpu;
>> +
>> +	/*
>> +	 * Halt the VM to ensure atomic update across all vcpus (this
>> +	 * avoids racy behaviour against other modifications of
>> +	 * HCR_EL2 such as kvm_toggle_cache/kvm_set_way_flush).
>> +	 */
>> +	kvm_arm_halt_guest(kvm);
>> +	kvm_for_each_vcpu(i, vcpu, kvm) {
>> +		unsigned long hcr = vcpu_get_hcr(vcpu);
>> +
>> +		if (enable)
>> +			hcr |= HCR_TTLB;
>> +		else
>> +			hcr &= ~HCR_TTLB;
>> +
>> +		vcpu_set_hcr(vcpu, hcr);
>> +	}
>> +	kvm_arm_resume_guest(kvm);
>> +
>> +	return 0;
>> +}
>> +
>>  static struct kvm_trace_hook trace_hook[] = {
>> +	{
>> +		.key = "kvm_tlb_invalidate",
>
> is this key defined elsewhere?  If not, I think the name is ambiguous,
> because it's unclear if this means 'kvm the subsystem' or 'a kvm guest',
> by looking purely at the string.

The key is the name of the tracepoint that the callback is executed
against. Here it is the tracepoint defined in Patch 6/7.

I've now added a comment to the definition of "struct kvm_trace_hook" to
explain what the key is.

>
>> +		.setup_fn = tlb_invalidate_trap,
>> +	},
>>  	{ },
>>  };
>>  
>> -- 
>> 2.8.1
>> 
>
> Otherwise looks ok to me.
>
> -Christoffer
> _______________________________________________
> kvmarm mailing list
> kvmarm@lists.cs.columbia.edu
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web