All of lore.kernel.org
 help / color / mirror / Atom feed
From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 03/13] ARM: KVM: Initial VGIC infrastructure support
Date: Wed, 28 Nov 2012 13:09:37 +0000	[thread overview]
Message-ID: <50B60D11.7000904@arm.com> (raw)
In-Reply-To: <20121128124955.GE21671@mudshark.cambridge.arm.com>

On 28/11/12 12:49, Will Deacon wrote:
> On Sat, Nov 10, 2012 at 03:44:37PM +0000, Christoffer Dall wrote:
>> From: Marc Zyngier <marc.zyngier@arm.com>
>>
>> Wire the basic framework code for VGIC support. Nothing to enable
>> yet.
> 
> Again, not sure how useful this patch is. Might as well merge it with code
> that actually does something. Couple of comments inline anyway...
>  
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
>> ---
>>  arch/arm/include/asm/kvm_host.h |    7 ++++
>>  arch/arm/include/asm/kvm_vgic.h |   70 +++++++++++++++++++++++++++++++++++++++
>>  arch/arm/kvm/arm.c              |   21 +++++++++++-
>>  arch/arm/kvm/interrupts.S       |    4 ++
>>  arch/arm/kvm/mmio.c             |    3 ++
>>  virt/kvm/kvm_main.c             |    5 ++-
>>  6 files changed, 107 insertions(+), 3 deletions(-)
>>  create mode 100644 arch/arm/include/asm/kvm_vgic.h
> 
> [...]
> 
>> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
>> index 60b119a..426828a 100644
>> --- a/arch/arm/kvm/arm.c
>> +++ b/arch/arm/kvm/arm.c
>> @@ -183,6 +183,9 @@ int kvm_dev_ioctl_check_extension(long ext)
>>  {
>>  	int r;
>>  	switch (ext) {
>> +#ifdef CONFIG_KVM_ARM_VGIC
>> +	case KVM_CAP_IRQCHIP:
>> +#endif
>>  	case KVM_CAP_USER_MEMORY:
>>  	case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
>>  	case KVM_CAP_ONE_REG:
>> @@ -304,6 +307,10 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
>>  {
>>  	/* Force users to call KVM_ARM_VCPU_INIT */
>>  	vcpu->arch.target = -1;
>> +
>> +	/* Set up VGIC */
>> +	kvm_vgic_vcpu_init(vcpu);
>> +
>>  	return 0;
>>  }
>>  
>> @@ -363,7 +370,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
>>   */
>>  int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
>>  {
>> -	return !!v->arch.irq_lines;
>> +	return !!v->arch.irq_lines || kvm_vgic_vcpu_pending_irq(v);
>>  }
> 
> So interrupt injection without the in-kernel GIC updates irq_lines, but the
> in-kernel GIC has its own separate data structures? Why can't the in-kernel GIC
> just use irq_lines instead of irq_pending_on_cpu?

They serve very different purposes:
- irq_lines directly controls the IRQ and FIQ lines (it is or-ed into
the HCR register before entering the guest)
- irq_pending_on_cpu deals with the CPU interface, and only that. Plus,
it is a kernel only thing. What triggers the interrupt on the guest is
the presence of list registers with a pending state.

You signal interrupts one way or the other.

> 
>>  
>>  int kvm_arch_vcpu_in_guest_mode(struct kvm_vcpu *v)
>> @@ -633,6 +640,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  
>>  		update_vttbr(vcpu->kvm);
>>  
>> +		kvm_vgic_sync_to_cpu(vcpu);
>> +
>>  		local_irq_disable();
>>  
>>  		/*
>> @@ -645,6 +654,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  
>>  		if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) {
>>  			local_irq_enable();
>> +			kvm_vgic_sync_from_cpu(vcpu);
>>  			continue;
>>  		}
> 
> For VFP, we use different terminology (sync and flush). I don't think they're
> any clearer than what you have, but the consistency would be nice.

Which one maps to which?

> Given that both these functions are run with interrupts enabled, why doesn't
> the second require a lock for updating dist->irq_pending_on_cpu? I notice
> there's a random smp_mb() over there...

Updating *only* irq_pending_on_cpu doesn't require the lock (set_bit()
should be safe, and I think the smp_mb() is a leftover of some debugging
hack). kvm_vgic_to_cpu() does a lot more (it picks interrupt from the
distributor, hence requires the lock to be taken).

>>  
>> @@ -683,6 +693,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  		 * Back from guest
>>  		 *************************************************************/
>>  
>> +		kvm_vgic_sync_from_cpu(vcpu);
> 
> Likewise.
> 
>>  		ret = handle_exit(vcpu, run, ret);
>>  	}
>>  
>> @@ -965,6 +977,13 @@ static int init_hyp_mode(void)
>>  		}
>>  	}
>>  
>> +	/*
>> +	 * Init HYP view of VGIC
>> +	 */
>> +	err = kvm_vgic_hyp_init();
>> +	if (err)
>> +		goto out_free_mappings;
>> +
>>  	return 0;
>>  out_free_vfp:
>>  	free_percpu(kvm_host_vfp_state);
> 
> [...]
> 
>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> index 2fb7319..665af96 100644
>> --- a/virt/kvm/kvm_main.c
>> +++ b/virt/kvm/kvm_main.c
>> @@ -1880,12 +1880,13 @@ static long kvm_vcpu_ioctl(struct file *filp,
>>  	if (vcpu->kvm->mm != current->mm)
>>  		return -EIO;
>>  
>> -#if defined(CONFIG_S390) || defined(CONFIG_PPC)
>> +#if defined(CONFIG_S390) || defined(CONFIG_PPC) || defined(CONFIG_ARM)
>>  	/*
>>  	 * Special cases: vcpu ioctls that are asynchronous to vcpu execution,
>>  	 * so vcpu_load() would break it.
>>  	 */
>> -	if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_INTERRUPT)
>> +	if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_INTERRUPT ||
>> +	    ioctl == KVM_IRQ_LINE)
>>  		return kvm_arch_vcpu_ioctl(filp, ioctl, arg);
>>  #endif
> 
> Separate patch?

Probably, yes.

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

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <marc.zyngier@arm.com>
To: Will Deacon <will.deacon@arm.com>
Cc: Christoffer Dall <c.dall@virtualopensystems.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>
Subject: Re: [PATCH v4 03/13] ARM: KVM: Initial VGIC infrastructure support
Date: Wed, 28 Nov 2012 13:09:37 +0000	[thread overview]
Message-ID: <50B60D11.7000904@arm.com> (raw)
In-Reply-To: <20121128124955.GE21671@mudshark.cambridge.arm.com>

On 28/11/12 12:49, Will Deacon wrote:
> On Sat, Nov 10, 2012 at 03:44:37PM +0000, Christoffer Dall wrote:
>> From: Marc Zyngier <marc.zyngier@arm.com>
>>
>> Wire the basic framework code for VGIC support. Nothing to enable
>> yet.
> 
> Again, not sure how useful this patch is. Might as well merge it with code
> that actually does something. Couple of comments inline anyway...
>  
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
>> ---
>>  arch/arm/include/asm/kvm_host.h |    7 ++++
>>  arch/arm/include/asm/kvm_vgic.h |   70 +++++++++++++++++++++++++++++++++++++++
>>  arch/arm/kvm/arm.c              |   21 +++++++++++-
>>  arch/arm/kvm/interrupts.S       |    4 ++
>>  arch/arm/kvm/mmio.c             |    3 ++
>>  virt/kvm/kvm_main.c             |    5 ++-
>>  6 files changed, 107 insertions(+), 3 deletions(-)
>>  create mode 100644 arch/arm/include/asm/kvm_vgic.h
> 
> [...]
> 
>> diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
>> index 60b119a..426828a 100644
>> --- a/arch/arm/kvm/arm.c
>> +++ b/arch/arm/kvm/arm.c
>> @@ -183,6 +183,9 @@ int kvm_dev_ioctl_check_extension(long ext)
>>  {
>>  	int r;
>>  	switch (ext) {
>> +#ifdef CONFIG_KVM_ARM_VGIC
>> +	case KVM_CAP_IRQCHIP:
>> +#endif
>>  	case KVM_CAP_USER_MEMORY:
>>  	case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
>>  	case KVM_CAP_ONE_REG:
>> @@ -304,6 +307,10 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
>>  {
>>  	/* Force users to call KVM_ARM_VCPU_INIT */
>>  	vcpu->arch.target = -1;
>> +
>> +	/* Set up VGIC */
>> +	kvm_vgic_vcpu_init(vcpu);
>> +
>>  	return 0;
>>  }
>>  
>> @@ -363,7 +370,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
>>   */
>>  int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
>>  {
>> -	return !!v->arch.irq_lines;
>> +	return !!v->arch.irq_lines || kvm_vgic_vcpu_pending_irq(v);
>>  }
> 
> So interrupt injection without the in-kernel GIC updates irq_lines, but the
> in-kernel GIC has its own separate data structures? Why can't the in-kernel GIC
> just use irq_lines instead of irq_pending_on_cpu?

They serve very different purposes:
- irq_lines directly controls the IRQ and FIQ lines (it is or-ed into
the HCR register before entering the guest)
- irq_pending_on_cpu deals with the CPU interface, and only that. Plus,
it is a kernel only thing. What triggers the interrupt on the guest is
the presence of list registers with a pending state.

You signal interrupts one way or the other.

> 
>>  
>>  int kvm_arch_vcpu_in_guest_mode(struct kvm_vcpu *v)
>> @@ -633,6 +640,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  
>>  		update_vttbr(vcpu->kvm);
>>  
>> +		kvm_vgic_sync_to_cpu(vcpu);
>> +
>>  		local_irq_disable();
>>  
>>  		/*
>> @@ -645,6 +654,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  
>>  		if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) {
>>  			local_irq_enable();
>> +			kvm_vgic_sync_from_cpu(vcpu);
>>  			continue;
>>  		}
> 
> For VFP, we use different terminology (sync and flush). I don't think they're
> any clearer than what you have, but the consistency would be nice.

Which one maps to which?

> Given that both these functions are run with interrupts enabled, why doesn't
> the second require a lock for updating dist->irq_pending_on_cpu? I notice
> there's a random smp_mb() over there...

Updating *only* irq_pending_on_cpu doesn't require the lock (set_bit()
should be safe, and I think the smp_mb() is a leftover of some debugging
hack). kvm_vgic_to_cpu() does a lot more (it picks interrupt from the
distributor, hence requires the lock to be taken).

>>  
>> @@ -683,6 +693,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
>>  		 * Back from guest
>>  		 *************************************************************/
>>  
>> +		kvm_vgic_sync_from_cpu(vcpu);
> 
> Likewise.
> 
>>  		ret = handle_exit(vcpu, run, ret);
>>  	}
>>  
>> @@ -965,6 +977,13 @@ static int init_hyp_mode(void)
>>  		}
>>  	}
>>  
>> +	/*
>> +	 * Init HYP view of VGIC
>> +	 */
>> +	err = kvm_vgic_hyp_init();
>> +	if (err)
>> +		goto out_free_mappings;
>> +
>>  	return 0;
>>  out_free_vfp:
>>  	free_percpu(kvm_host_vfp_state);
> 
> [...]
> 
>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> index 2fb7319..665af96 100644
>> --- a/virt/kvm/kvm_main.c
>> +++ b/virt/kvm/kvm_main.c
>> @@ -1880,12 +1880,13 @@ static long kvm_vcpu_ioctl(struct file *filp,
>>  	if (vcpu->kvm->mm != current->mm)
>>  		return -EIO;
>>  
>> -#if defined(CONFIG_S390) || defined(CONFIG_PPC)
>> +#if defined(CONFIG_S390) || defined(CONFIG_PPC) || defined(CONFIG_ARM)
>>  	/*
>>  	 * Special cases: vcpu ioctls that are asynchronous to vcpu execution,
>>  	 * so vcpu_load() would break it.
>>  	 */
>> -	if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_INTERRUPT)
>> +	if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_INTERRUPT ||
>> +	    ioctl == KVM_IRQ_LINE)
>>  		return kvm_arch_vcpu_ioctl(filp, ioctl, arg);
>>  #endif
> 
> Separate patch?

Probably, yes.

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


  reply	other threads:[~2012-11-28 13:09 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-10 15:44 [PATCH v4 00/13] KVM/ARM vGIC support Christoffer Dall
2012-11-10 15:44 ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 01/13] KVM: ARM: Introduce KVM_SET_DEVICE_ADDRESS ioctl Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 02/13] ARM: KVM: Keep track of currently running vcpus Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-28 12:47   ` Will Deacon
2012-11-28 12:47     ` Will Deacon
2012-11-28 13:15     ` Marc Zyngier
2012-11-28 13:15       ` Marc Zyngier
2012-11-30 22:39     ` Christoffer Dall
2012-11-30 22:39       ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 03/13] ARM: KVM: Initial VGIC infrastructure support Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-28 12:49   ` Will Deacon
2012-11-28 12:49     ` Will Deacon
2012-11-28 13:09     ` Marc Zyngier [this message]
2012-11-28 13:09       ` Marc Zyngier
2012-11-28 14:13       ` Will Deacon
2012-11-28 14:13         ` Will Deacon
2012-12-01  2:19     ` Christoffer Dall
2012-12-01  2:19       ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 04/13] ARM: KVM: Initial VGIC MMIO support code Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  8:54   ` Dong Aisheng
2012-11-12  8:54     ` Dong Aisheng
2012-11-13 13:32     ` Christoffer Dall
2012-11-13 13:32       ` Christoffer Dall
2012-11-28 13:09   ` Will Deacon
2012-11-28 13:09     ` Will Deacon
2012-11-28 13:44     ` Marc Zyngier
2012-11-28 13:44       ` Marc Zyngier
2012-11-10 15:44 ` [PATCH v4 05/13] ARM: KVM: VGIC accept vcpu and dist base addresses from user space Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  8:56   ` Dong Aisheng
2012-11-12  8:56     ` Dong Aisheng
2012-11-13 13:35     ` Christoffer Dall
2012-11-13 13:35       ` Christoffer Dall
2012-11-28 13:11   ` Will Deacon
2012-11-28 13:11     ` Will Deacon
2012-11-28 13:22     ` [kvmarm] " Marc Zyngier
2012-11-28 13:22       ` Marc Zyngier
2012-12-01  2:52     ` Christoffer Dall
2012-12-01  2:52       ` Christoffer Dall
2012-12-01 15:57       ` Christoffer Dall
2012-12-01 15:57         ` Christoffer Dall
2012-12-03 10:40       ` Will Deacon
2012-12-03 10:40         ` Will Deacon
2012-11-10 15:44 ` [PATCH v4 06/13] ARM: KVM: VGIC distributor handling Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  9:29   ` Dong Aisheng
2012-11-12  9:29     ` Dong Aisheng
2012-11-13 13:38     ` Christoffer Dall
2012-11-13 13:38       ` Christoffer Dall
2012-11-28 13:21   ` Will Deacon
2012-11-28 13:21     ` Will Deacon
2012-11-28 14:35     ` Marc Zyngier
2012-11-28 14:35       ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 07/13] ARM: KVM: VGIC virtual CPU interface management Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:23   ` Will Deacon
2012-12-03 13:23     ` Will Deacon
2012-12-03 14:11     ` Marc Zyngier
2012-12-03 14:11       ` Marc Zyngier
2012-12-03 14:34       ` Will Deacon
2012-12-03 14:34         ` Will Deacon
2012-12-03 15:24         ` Marc Zyngier
2012-12-03 15:24           ` Marc Zyngier
2012-12-03 14:54       ` Christoffer Dall
2012-12-03 14:54         ` Christoffer Dall
2012-11-10 15:45 ` [PATCH v4 08/13] ARM: KVM: vgic: retire queued, disabled interrupts Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:24   ` Will Deacon
2012-12-03 13:24     ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 09/13] ARM: KVM: VGIC interrupt injection Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:25   ` Will Deacon
2012-12-03 13:25     ` Will Deacon
2012-12-03 14:21     ` Marc Zyngier
2012-12-03 14:21       ` Marc Zyngier
2012-12-03 14:58       ` Christoffer Dall
2012-12-03 14:58         ` Christoffer Dall
2012-12-03 19:13       ` Christoffer Dall
2012-12-03 19:13         ` Christoffer Dall
2012-12-03 19:22         ` Marc Zyngier
2012-12-03 19:22           ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 10/13] ARM: KVM: VGIC control interface world switch Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:31   ` Will Deacon
2012-12-03 13:31     ` Will Deacon
2012-12-03 14:26     ` Marc Zyngier
2012-12-03 14:26       ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 11/13] ARM: KVM: VGIC initialisation code Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-05 10:43   ` Will Deacon
2012-12-05 10:43     ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 12/13] ARM: KVM: vgic: reduce the number of vcpu kick Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-05 10:43   ` Will Deacon
2012-12-05 10:43     ` Will Deacon
2012-12-05 10:58     ` Russell King - ARM Linux
2012-12-05 10:58       ` Russell King - ARM Linux
2012-12-05 12:17       ` Marc Zyngier
2012-12-05 12:17         ` Marc Zyngier
2012-12-05 12:29         ` Russell King - ARM Linux
2012-12-05 12:29           ` Russell King - ARM Linux
2012-12-05 13:40           ` Marc Zyngier
2012-12-05 13:40             ` Marc Zyngier
2012-12-05 15:55             ` Russell King - ARM Linux
2012-12-05 15:55               ` Russell King - ARM Linux
2012-12-05 11:16   ` Russell King - ARM Linux
2012-12-05 11:16     ` Russell King - ARM Linux
2012-11-10 15:45 ` [PATCH v4 13/13] ARM: KVM: Add VGIC configuration option Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-11-10 19:52   ` Sergei Shtylyov
2012-11-10 19:52     ` Sergei Shtylyov

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=50B60D11.7000904@arm.com \
    --to=marc.zyngier@arm.com \
    --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.