kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip
@ 2015-08-17  9:43 Pavel Fedin
  2015-08-17  9:43 ` [PATCH v4 1/3] Fix NULL pointer dereference if KVM is used " Pavel Fedin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pavel Fedin @ 2015-08-17  9:43 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: Marc Zyngier

This patch set brings back functionality which was broken in v4.0.
Unfortunately because of restrictions of such a hardware is is impossible
to take advantage of virtual architected timer, therefore guest, running
in such restricted mode, has to use some memory-mapped timer. But it is
still better than nothing.

v3 => v4:
- Revert back to using switch on kvm_vgic_hyp_init() return code. I decided
  to leave 'vgic_present = false' statement because it helps to understand
  the code.

v2 => v3:
- Improved commit messages, added references to commits where the respective
  functionality was broken
- Explicitly specify that the solution currently affects only vGIC and has
  nothing to do with timer.
- Fixed code style according to previous notes
- Removed ARM64 save/restore patch introduced in v2 because it was already
  obsolete for linux-next
- Modify KVM_CAP_IRQFD handling in correct place

v1 => v2:
- Do not use defensive approach in patch 0001. Use correct conditions in
  callers instead
- Added ARM64-specific code, without which attempt to run a VM ends in a
  HYP crash because of unset vGIC save/restore function pointers


Pavel Fedin (3):
  Fix NULL pointer dereference if KVM is used without in-kernel irqchip
  Detect vGIC presence at runtime
  Make KVM_CAP_IRQFD dependent on KVM_CAP_IRQCHIP

 arch/arm/kvm/arm.c  | 24 +++++++++++++++++++++---
 virt/kvm/kvm_main.c |  5 +++--
 2 files changed, 24 insertions(+), 5 deletions(-)

-- 
2.4.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/3] Fix NULL pointer dereference if KVM is used without in-kernel irqchip
  2015-08-17  9:43 [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
@ 2015-08-17  9:43 ` Pavel Fedin
  2015-08-17  9:43 ` [PATCH v4 2/3] Detect vGIC presence at runtime Pavel Fedin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Fedin @ 2015-08-17  9:43 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: Marc Zyngier, Christoffer Dall

Makes qemu working again with kernel-irqchip=off option, allowing to use
GIC emulation in userspace.

Previously kvm_vgic_map_resources() used to include irqchip_in_kernel()
check, and vgic_v2_map_resources() still has it, but now vm_ops are not
initialized before kvm_vgic_create(). Therefore kvm_vgic_map_resources()
call without vGIC instantiation attempts to call
vm_ops.map_resources == NULL

The bug was introduced in b26e5fdac43c1b7c394502917e42e3b91f3aa1a3

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 arch/arm/kvm/arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 7a7b26f..fddaa2e 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -449,7 +449,7 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
 	 * Map the VGIC hardware resources before running a vcpu the first
 	 * time on this VM.
 	 */
-	if (unlikely(!vgic_ready(kvm))) {
+	if (unlikely(irqchip_in_kernel(kvm) && !vgic_ready(kvm))) {
 		ret = kvm_vgic_map_resources(kvm);
 		if (ret)
 			return ret;
-- 
2.4.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/3] Detect vGIC presence at runtime
  2015-08-17  9:43 [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
  2015-08-17  9:43 ` [PATCH v4 1/3] Fix NULL pointer dereference if KVM is used " Pavel Fedin
@ 2015-08-17  9:43 ` Pavel Fedin
  2015-08-17  9:43 ` [PATCH v4 3/3] Make KVM_CAP_IRQFD dependent on KVM_CAP_IRQCHIP Pavel Fedin
  2015-08-31 11:24 ` [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Fedin @ 2015-08-17  9:43 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: Marc Zyngier

Before commit 662d9715840aef44dcb573b0f9fab9e8319c868a is was possible to
compile the kernel without vGIC and vTimer support. Commit message says
about possibility to detect vGIC support in runtine, but this has never
been implemented.

This patch introdices runtime check, restoring the lost functionality. It
again allows to use KVM on hardware without vGIC. Interrupt controller has
to be emulated in userspace in this case.

-ENODEV return code from probe function means there's no GIC at all.
-ENXIO happens when, for example, there is GIC node in the device tree,
but it does not specify vGIC resources. Normally this means that vGIC
hardware is defunct. Any other error code is still treated as full stop
because it might mean some really serious problems.

This patch does not touch any virtual timer code, suggesting that timer
hardware is actually in place. Normally on boards in question it is true,
however since vGIC is missing, it is impossible to correctly utilize
interrupts from the virtual timer. Since virtual timer handling is in
active redevelopment now, handling in it userspace is out of scope at
the moment. The guest is currently suggested to use some memory-mapped
timer which can be emulated in userspace.

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 arch/arm/kvm/arm.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index fddaa2e..b44e53c 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -61,6 +61,8 @@ static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
 static u8 kvm_next_vmid;
 static DEFINE_SPINLOCK(kvm_vmid_lock);
 
+static bool vgic_present;
+
 static void kvm_arm_set_running_vcpu(struct kvm_vcpu *vcpu)
 {
 	BUG_ON(preemptible());
@@ -131,7 +133,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	kvm->arch.vmid_gen = 0;
 
 	/* The maximum number of VCPUs is limited by the host's GIC model */
-	kvm->arch.max_vcpus = kvm_vgic_get_max_vcpus();
+	kvm->arch.max_vcpus = vgic_present ?
+				kvm_vgic_get_max_vcpus() : KVM_MAX_VCPUS;
 
 	return ret;
 out_free_stage2_pgd:
@@ -171,6 +174,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	int r;
 	switch (ext) {
 	case KVM_CAP_IRQCHIP:
+		r = vgic_present;
+		break;
 	case KVM_CAP_IOEVENTFD:
 	case KVM_CAP_DEVICE_CTRL:
 	case KVM_CAP_USER_MEMORY:
@@ -859,6 +864,8 @@ static int kvm_vm_ioctl_set_device_addr(struct kvm *kvm,
 
 	switch (dev_id) {
 	case KVM_ARM_DEVICE_VGIC_V2:
+		if (!vgic_present)
+			return -ENXIO;
 		return kvm_vgic_addr(kvm, type, &dev_addr->addr, true);
 	default:
 		return -ENODEV;
@@ -873,6 +880,8 @@ long kvm_arch_vm_ioctl(struct file *filp,
 
 	switch (ioctl) {
 	case KVM_CREATE_IRQCHIP: {
+		if (!vgic_present)
+			return -ENXIO;
 		return kvm_vgic_create(kvm, KVM_DEV_TYPE_ARM_VGIC_V2);
 	}
 	case KVM_ARM_SET_DEVICE_ADDR: {
@@ -1055,8 +1064,17 @@ static int init_hyp_mode(void)
 	 * Init HYP view of VGIC
 	 */
 	err = kvm_vgic_hyp_init();
-	if (err)
+	switch (err) {
+	case 0:
+		vgic_present = true;
+		break;
+	case -ENODEV:
+	case -ENXIO:
+		vgic_present = false;
+		break;
+	default:
 		goto out_free_context;
+	}
 
 	/*
 	 * Init HYP architected timer support
-- 
2.4.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 3/3] Make KVM_CAP_IRQFD dependent on KVM_CAP_IRQCHIP
  2015-08-17  9:43 [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
  2015-08-17  9:43 ` [PATCH v4 1/3] Fix NULL pointer dereference if KVM is used " Pavel Fedin
  2015-08-17  9:43 ` [PATCH v4 2/3] Detect vGIC presence at runtime Pavel Fedin
@ 2015-08-17  9:43 ` Pavel Fedin
  2015-08-31 11:24 ` [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Fedin @ 2015-08-17  9:43 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: Marc Zyngier

Now at least ARM is able to determine whether the machine has
virtualization support for irqchip or not at runtime. Obviously,
irqfd requires irqchip.

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 virt/kvm/kvm_main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 9097741..7b49618 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2478,12 +2478,13 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
 #ifdef CONFIG_HAVE_KVM_MSI
 	case KVM_CAP_SIGNAL_MSI:
 #endif
+	case KVM_CAP_CHECK_EXTENSION_VM:
+		return 1;
 #ifdef CONFIG_HAVE_KVM_IRQFD
 	case KVM_CAP_IRQFD:
 	case KVM_CAP_IRQFD_RESAMPLE:
+		return kvm_vm_ioctl_check_extension(kvm, KVM_CAP_IRQCHIP);
 #endif
-	case KVM_CAP_CHECK_EXTENSION_VM:
-		return 1;
 #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING
 	case KVM_CAP_IRQ_ROUTING:
 		return KVM_MAX_IRQ_ROUTES;
-- 
2.4.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip
  2015-08-17  9:43 [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
                   ` (2 preceding siblings ...)
  2015-08-17  9:43 ` [PATCH v4 3/3] Make KVM_CAP_IRQFD dependent on KVM_CAP_IRQCHIP Pavel Fedin
@ 2015-08-31 11:24 ` Pavel Fedin
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Fedin @ 2015-08-31 11:24 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: 'Marc Zyngier', 'Christoffer Dall'

 Hello! Two weeks has passed, i have fixed up Marc's notes, so PING...

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia


> -----Original Message-----
> From: kvm-owner@vger.kernel.org [mailto:kvm-owner@vger.kernel.org] On Behalf Of Pavel Fedin
> Sent: Monday, August 17, 2015 12:44 PM
> To: kvmarm@lists.cs.columbia.edu; kvm@vger.kernel.org
> Cc: Marc Zyngier; Christoffer Dall
> Subject: [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip
> 
> This patch set brings back functionality which was broken in v4.0.
> Unfortunately because of restrictions of such a hardware is is impossible
> to take advantage of virtual architected timer, therefore guest, running
> in such restricted mode, has to use some memory-mapped timer. But it is
> still better than nothing.
> 
> v3 => v4:
> - Revert back to using switch on kvm_vgic_hyp_init() return code. I decided
>   to leave 'vgic_present = false' statement because it helps to understand
>   the code.
> 
> v2 => v3:
> - Improved commit messages, added references to commits where the respective
>   functionality was broken
> - Explicitly specify that the solution currently affects only vGIC and has
>   nothing to do with timer.
> - Fixed code style according to previous notes
> - Removed ARM64 save/restore patch introduced in v2 because it was already
>   obsolete for linux-next
> - Modify KVM_CAP_IRQFD handling in correct place
> 
> v1 => v2:
> - Do not use defensive approach in patch 0001. Use correct conditions in
>   callers instead
> - Added ARM64-specific code, without which attempt to run a VM ends in a
>   HYP crash because of unset vGIC save/restore function pointers
> 
> 
> Pavel Fedin (3):
>   Fix NULL pointer dereference if KVM is used without in-kernel irqchip
>   Detect vGIC presence at runtime
>   Make KVM_CAP_IRQFD dependent on KVM_CAP_IRQCHIP
> 
>  arch/arm/kvm/arm.c  | 24 +++++++++++++++++++++---
>  virt/kvm/kvm_main.c |  5 +++--
>  2 files changed, 24 insertions(+), 5 deletions(-)
> 
> --
> 2.4.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-31 11:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-17  9:43 [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin
2015-08-17  9:43 ` [PATCH v4 1/3] Fix NULL pointer dereference if KVM is used " Pavel Fedin
2015-08-17  9:43 ` [PATCH v4 2/3] Detect vGIC presence at runtime Pavel Fedin
2015-08-17  9:43 ` [PATCH v4 3/3] Make KVM_CAP_IRQFD dependent on KVM_CAP_IRQCHIP Pavel Fedin
2015-08-31 11:24 ` [PATCH v4 0/3] KVM: arm/arm64: Allow to use KVM without in-kernel irqchip Pavel Fedin

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).