All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Andrew Jones <drjones@redhat.com>,
	linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org,
	kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v2 11/17] arm64: KVM: vgic-v2: Only wipe LRs on vcpu exit
Date: Thu, 3 Mar 2016 15:58:08 +0000	[thread overview]
Message-ID: <56D85F10.1030602@arm.com> (raw)
In-Reply-To: <20160302230819.GE9634@cbox>

On 02/03/16 23:08, Christoffer Dall wrote:
> On Wed, Feb 17, 2016 at 04:40:43PM +0000, Marc Zyngier wrote:
>> So far, we're always writing all possible LRs, setting the empty
>> ones with a zero value. This is obvious doing a low of work for
> 
> s/low/lot/
> 
>> nothing, and we're better off clearing those we've actually
>> dirtied on the exit path (it is very rare to inject more than one
>> interrupt at a time anyway).
>>
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>>  arch/arm64/kvm/hyp/vgic-v2-sr.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp/vgic-v2-sr.c b/arch/arm64/kvm/hyp/vgic-v2-sr.c
>> index 3dbbc6b..e53f131 100644
>> --- a/arch/arm64/kvm/hyp/vgic-v2-sr.c
>> +++ b/arch/arm64/kvm/hyp/vgic-v2-sr.c
>> @@ -101,6 +101,7 @@ static void __hyp_text save_lrs(struct kvm_vcpu *vcpu, void __iomem *base)
>>  		}
>>  
>>  		cpu_if->vgic_lr[i] = readl_relaxed(base + GICH_LR0 + (i * 4));
>> +		writel_relaxed(0, base + GICH_LR0 + (i * 4));
>>  	}
>>  }
>>  
>> @@ -158,12 +159,11 @@ void __hyp_text __vgic_v2_restore_state(struct kvm_vcpu *vcpu)
>>  		writel_relaxed(cpu_if->vgic_hcr, base + GICH_HCR);
>>  		writel_relaxed(cpu_if->vgic_apr, base + GICH_APR);
>>  		for (i = 0; i < nr_lr; i++) {
>> -			u32 val = 0;
>> -
>> -			if (live_lrs & (1UL << i))
>> -				val = cpu_if->vgic_lr[i];
>> +			if (!(live_lrs & (1UL << i)))
>> +				continue;
> 
> how can we be sure that the LRs are clear when we launch our first VM on
> a given physical CPU?  Don't we need to flush the LRs during VGIC init
> time?
> 
>>  
>> -			writel_relaxed(val, base + GICH_LR0 + (i * 4));
>> +			writel_relaxed(cpu_if->vgic_lr[i],
>> +				       base + GICH_LR0 + (i * 4));
>>  		}
>>  	}
>>  
>> -- 
>> 2.1.4
>>
> 
> otherwie LGTM.

So how about this, just before this patch (I'll obviously do something similar for GICv3):

>From d9a80c4c406450190a68abee302c7d9a0034c62a Mon Sep 17 00:00:00 2001
From: Marc Zyngier <marc.zyngier@arm.com>
Date: Thu, 3 Mar 2016 15:43:58 +0000
Subject: [PATCH] KVM: arm/arm64: vgic-v2: Reset LRs at boot time

In order to let make the GICv2 code more lazy in the way it
accesses the LRs, it is necessary to start with a clean slate.

Let's reset the LRs on each CPU when the vgic is probed.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 virt/kvm/arm/vgic-v2.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/virt/kvm/arm/vgic-v2.c b/virt/kvm/arm/vgic-v2.c
index ff02f08..67ec334 100644
--- a/virt/kvm/arm/vgic-v2.c
+++ b/virt/kvm/arm/vgic-v2.c
@@ -176,6 +176,15 @@ static const struct vgic_ops vgic_v2_ops = {
 
 static struct vgic_params vgic_v2_params;
 
+static void vgic_cpu_init_lrs(void *params)
+{
+	struct vgic_params *vgic = params;
+	int i;
+
+	for (i = 0; i < vgic->nr_lr; i++)
+		writel_relaxed(0, vgic->vctrl_base + GICH_LR0 + (i * 4));
+}
+
 /**
  * vgic_v2_probe - probe for a GICv2 compatible interrupt controller in DT
  * @node:	pointer to the DT node
@@ -257,6 +266,9 @@ int vgic_v2_probe(struct device_node *vgic_node,
 
 	vgic->type = VGIC_V2;
 	vgic->max_gic_vcpus = VGIC_V2_MAX_CPUS;
+
+	on_each_cpu(vgic_cpu_init_lrs, vgic, 1);
+
 	*ops = &vgic_v2_ops;
 	*params = vgic;
 	goto out;


Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

WARNING: multiple messages have this Message-ID (diff)
From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 11/17] arm64: KVM: vgic-v2: Only wipe LRs on vcpu exit
Date: Thu, 3 Mar 2016 15:58:08 +0000	[thread overview]
Message-ID: <56D85F10.1030602@arm.com> (raw)
In-Reply-To: <20160302230819.GE9634@cbox>

On 02/03/16 23:08, Christoffer Dall wrote:
> On Wed, Feb 17, 2016 at 04:40:43PM +0000, Marc Zyngier wrote:
>> So far, we're always writing all possible LRs, setting the empty
>> ones with a zero value. This is obvious doing a low of work for
> 
> s/low/lot/
> 
>> nothing, and we're better off clearing those we've actually
>> dirtied on the exit path (it is very rare to inject more than one
>> interrupt at a time anyway).
>>
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>>  arch/arm64/kvm/hyp/vgic-v2-sr.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp/vgic-v2-sr.c b/arch/arm64/kvm/hyp/vgic-v2-sr.c
>> index 3dbbc6b..e53f131 100644
>> --- a/arch/arm64/kvm/hyp/vgic-v2-sr.c
>> +++ b/arch/arm64/kvm/hyp/vgic-v2-sr.c
>> @@ -101,6 +101,7 @@ static void __hyp_text save_lrs(struct kvm_vcpu *vcpu, void __iomem *base)
>>  		}
>>  
>>  		cpu_if->vgic_lr[i] = readl_relaxed(base + GICH_LR0 + (i * 4));
>> +		writel_relaxed(0, base + GICH_LR0 + (i * 4));
>>  	}
>>  }
>>  
>> @@ -158,12 +159,11 @@ void __hyp_text __vgic_v2_restore_state(struct kvm_vcpu *vcpu)
>>  		writel_relaxed(cpu_if->vgic_hcr, base + GICH_HCR);
>>  		writel_relaxed(cpu_if->vgic_apr, base + GICH_APR);
>>  		for (i = 0; i < nr_lr; i++) {
>> -			u32 val = 0;
>> -
>> -			if (live_lrs & (1UL << i))
>> -				val = cpu_if->vgic_lr[i];
>> +			if (!(live_lrs & (1UL << i)))
>> +				continue;
> 
> how can we be sure that the LRs are clear when we launch our first VM on
> a given physical CPU?  Don't we need to flush the LRs during VGIC init
> time?
> 
>>  
>> -			writel_relaxed(val, base + GICH_LR0 + (i * 4));
>> +			writel_relaxed(cpu_if->vgic_lr[i],
>> +				       base + GICH_LR0 + (i * 4));
>>  		}
>>  	}
>>  
>> -- 
>> 2.1.4
>>
> 
> otherwie LGTM.

So how about this, just before this patch (I'll obviously do something similar for GICv3):

>From d9a80c4c406450190a68abee302c7d9a0034c62a Mon Sep 17 00:00:00 2001
From: Marc Zyngier <marc.zyngier@arm.com>
Date: Thu, 3 Mar 2016 15:43:58 +0000
Subject: [PATCH] KVM: arm/arm64: vgic-v2: Reset LRs at boot time

In order to let make the GICv2 code more lazy in the way it
accesses the LRs, it is necessary to start with a clean slate.

Let's reset the LRs on each CPU when the vgic is probed.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 virt/kvm/arm/vgic-v2.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/virt/kvm/arm/vgic-v2.c b/virt/kvm/arm/vgic-v2.c
index ff02f08..67ec334 100644
--- a/virt/kvm/arm/vgic-v2.c
+++ b/virt/kvm/arm/vgic-v2.c
@@ -176,6 +176,15 @@ static const struct vgic_ops vgic_v2_ops = {
 
 static struct vgic_params vgic_v2_params;
 
+static void vgic_cpu_init_lrs(void *params)
+{
+	struct vgic_params *vgic = params;
+	int i;
+
+	for (i = 0; i < vgic->nr_lr; i++)
+		writel_relaxed(0, vgic->vctrl_base + GICH_LR0 + (i * 4));
+}
+
 /**
  * vgic_v2_probe - probe for a GICv2 compatible interrupt controller in DT
  * @node:	pointer to the DT node
@@ -257,6 +266,9 @@ int vgic_v2_probe(struct device_node *vgic_node,
 
 	vgic->type = VGIC_V2;
 	vgic->max_gic_vcpus = VGIC_V2_MAX_CPUS;
+
+	on_each_cpu(vgic_cpu_init_lrs, vgic, 1);
+
 	*ops = &vgic_v2_ops;
 	*params = vgic;
 	goto out;


Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

  parent reply	other threads:[~2016-03-03 15:58 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 16:40 [PATCH v2 00/17] KVM/ARM: Guest Entry/Exit optimizations Marc Zyngier
2016-02-17 16:40 ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 01/17] arm64: KVM: Switch the sys_reg search to be a binary search Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 02/17] ARM: KVM: Properly sort the invariant table Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 03/17] ARM: KVM: Enforce sorting of all CP tables Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 04/17] ARM: KVM: Rename struct coproc_reg::is_64 to is_64bit Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 05/17] ARM: KVM: Switch the CP reg search to be a binary search Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 06/17] KVM: arm/arm64: timer: Add active state caching Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 07/17] arm64: KVM: vgic-v2: Avoid accessing GICH registers Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-02 23:08   ` Christoffer Dall
2016-03-02 23:08     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 08/17] arm64: KVM: vgic-v2: Save maintenance interrupt state only if required Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-02 23:08   ` Christoffer Dall
2016-03-02 23:08     ` Christoffer Dall
2016-03-03  8:28     ` Marc Zyngier
2016-03-03  8:28       ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 09/17] arm64: KVM: vgic-v2: Move GICH_ELRSR saving to its own function Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-02 23:08   ` Christoffer Dall
2016-03-02 23:08     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 10/17] arm64: KVM: vgic-v2: Do not save an LR known to be empty Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-02 23:08   ` Christoffer Dall
2016-03-02 23:08     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 11/17] arm64: KVM: vgic-v2: Only wipe LRs on vcpu exit Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-02 23:08   ` Christoffer Dall
2016-03-02 23:08     ` Christoffer Dall
2016-03-03  8:14     ` Marc Zyngier
2016-03-03  8:14       ` Marc Zyngier
2016-03-03 15:58     ` Marc Zyngier [this message]
2016-03-03 15:58       ` Marc Zyngier
2016-03-04 11:36       ` Christoffer Dall
2016-03-04 11:36         ` Christoffer Dall
2016-03-04 11:45         ` Marc Zyngier
2016-03-04 11:45           ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 12/17] arm64: KVM: vgic-v2: Make GICD_SGIR quicker to hit Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-02 23:08   ` Christoffer Dall
2016-03-02 23:08     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 13/17] arm64: KVM: vgic-v3: Avoid accessing ICH registers Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-02-17 16:40 ` [PATCH v2 14/17] arm64: KVM: vgic-v3: Save maintenance interrupt state only if required Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-03 19:21   ` Christoffer Dall
2016-03-03 19:21     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 15/17] arm64: KVM: vgic-v3: Do not save an LR known to be empty Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-03 19:21   ` Christoffer Dall
2016-03-03 19:21     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 16/17] arm64: KVM: vgic-v3: Only wipe LRs on vcpu exit Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-03 19:21   ` Christoffer Dall
2016-03-03 19:21     ` Christoffer Dall
2016-02-17 16:40 ` [PATCH v2 17/17] arm64: KVM: vgic-v3: Do not save ICH_AP0Rn_EL2 for GICv2 emulation Marc Zyngier
2016-02-17 16:40   ` Marc Zyngier
2016-03-03 19:21   ` Christoffer Dall
2016-03-03 19:21     ` Christoffer Dall
2016-03-04  8:54     ` Marc Zyngier
2016-03-04  8:54       ` Marc Zyngier
2016-02-29  0:57 ` [PATCH v2 00/17] KVM/ARM: Guest Entry/Exit optimizations Mihai Claudiu Caraman
2016-02-29  0:57   ` Mihai Claudiu Caraman
2016-02-29  8:26   ` Marc Zyngier
2016-02-29  8:26     ` Marc Zyngier
2016-02-29 10:43     ` Mihai Claudiu Caraman
2016-02-29 10:43       ` Mihai Claudiu Caraman

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=56D85F10.1030602@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.