Skip to contentSkip to conversation

Cubietruck: cannot create KVM guests: "kvm_init_vcpu failed: Invalid argument"

Qemu-devel Kashyap Chamarthy 4 participants 9 messages Dec 9, 2014

lore
Share & tools
lore
#0 lore raw

Booting a minimal KVM guest throws the below error on Cubietruck:

"kvm_init_vcpu failed: Invalid argument"

More context and an easy reproducer in this QEMU bug[1] for Fedora.

Context quoting Rich Jones from comment #2:

    "For some reason I thought this had been fixed upstream, but
    now that I've finally got my CT working again, I see that I
    am still carrying that patch in my custom qemu.
    
    diff --git a/target-arm/cpu.c b/target-arm/cpu.c
    index 5ce7350..04d69d1 100644
    --- a/target-arm/cpu.c
    +++ b/target-arm/cpu.c
    @@ -858,7 +858,7 @@ static void cortex_a15_initfn(Object *obj)
         set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
         set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
         set_feature(&cpu->env, ARM_FEATURE_LPAE);
    -    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
    +    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
         cpu->midr = 0x412fc0f1;
         cpu->reset_fpsid = 0x410430f0;
         cpu->mvfr0 = 0x10110222;
    
    So that's the answer really, it's a qemu bug.  Actually it looks as
    if qemu contains some code to try to get the host CPU type, but it
    doesn't work, or maybe we need to pass a -cpu option ..."

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1171501 -- Cubietruck:
cannot create KVM guests: "kvm_init_vcpu failed: Invalid argument"

Signature · 1 line
/kashyap
#1 lore raw
Quoted 17 lines · Kashyap Chamarthy

Booting a minimal KVM guest throws the below error on Cubietruck:

"kvm_init_vcpu failed: Invalid argument"

More context and an easy reproducer in this QEMU bug[1] for Fedora.

Context quoting Rich Jones from comment #2:

    "For some reason I thought this had been fixed upstream, but
    now that I've finally got my CT working again, I see that I
    am still carrying that patch in my custom qemu.

    diff --git a/target-arm/cpu.c b/target-arm/cpu.c
    index 5ce7350..04d69d1 100644
    --- a/target-arm/cpu.c
    +++ b/target-arm/cpu.c
    @@ -858,7 +858,7 @@ static void cortex_a15_initfn(Object *obj)
Quoted 8 lines
         set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
         set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
         set_feature(&cpu->env, ARM_FEATURE_LPAE);
    -    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
    +    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
         cpu->midr = 0x412fc0f1;
         cpu->reset_fpsid = 0x410430f0;
         cpu->mvfr0 = 0x10110222;

This is obviously a bogus patch -- this is the initfn for Cortex-A15 so telling it to be a Cortex-A7 is wrong (and would break working setups on A15 hosts).

Quoted 3 lines

So that's the answer really, it's a qemu bug. Actually it looks as if qemu contains some code to try to get the host CPU type, but it doesn't work, or maybe we need to pass a -cpu option ..."

Yes, you need to pass a -cpu option. For KVM on ARM, you always need to either:
* pass a -cpu option matching the host CPU
* pass "-cpu host"

The CubieTruck is a Cortex-A7, which we don't have specific support for in QEMU, so you will need "-cpu host".

thanks
-- PMM

#2 lore raw
Quoted 27 lines · Peter Maydell
Quoted 17 lines · Kashyap Chamarthy

Booting a minimal KVM guest throws the below error on Cubietruck:

"kvm_init_vcpu failed: Invalid argument"

More context and an easy reproducer in this QEMU bug[1] for Fedora.

Context quoting Rich Jones from comment #2:

    "For some reason I thought this had been fixed upstream, but
    now that I've finally got my CT working again, I see that I
    am still carrying that patch in my custom qemu.

    diff --git a/target-arm/cpu.c b/target-arm/cpu.c
    index 5ce7350..04d69d1 100644
    --- a/target-arm/cpu.c
    +++ b/target-arm/cpu.c
    @@ -858,7 +858,7 @@ static void cortex_a15_initfn(Object *obj)
Quoted 8 lines
         set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
         set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
         set_feature(&cpu->env, ARM_FEATURE_LPAE);
    -    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
    +    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
         cpu->midr = 0x412fc0f1;
         cpu->reset_fpsid = 0x410430f0;
         cpu->mvfr0 = 0x10110222;
Quoted 3 lines

This is obviously a bogus patch -- this is the initfn for Cortex-A15 so telling it to be a Cortex-A7 is wrong (and would break working setups on A15 hosts).

Yes, I definitely was not proposing this as a serious patch! In my copy of qemu it has "HACK" in all capital letters in the summary ...

Quoted 11 lines
Quoted 3 lines

So that's the answer really, it's a qemu bug. Actually it looks as if qemu contains some code to try to get the host CPU type, but it doesn't work, or maybe we need to pass a -cpu option ..."

Yes, you need to pass a -cpu option. For KVM on ARM, you always need to either:
* pass a -cpu option matching the host CPU
* pass "-cpu host"

The CubieTruck is a Cortex-A7, which we don't have specific support for in QEMU, so you will need "-cpu host".

Kashyap ^^ can you try this? Should be a trivial one-liner change in src/launch-direct.c.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
#3 lore raw
Quoted 44 lines · Richard W.M. Jones
Quoted 27 lines · Peter Maydell
Quoted 17 lines · Kashyap Chamarthy

Booting a minimal KVM guest throws the below error on Cubietruck:

"kvm_init_vcpu failed: Invalid argument"

More context and an easy reproducer in this QEMU bug[1] for Fedora.

Context quoting Rich Jones from comment #2:

    "For some reason I thought this had been fixed upstream, but
    now that I've finally got my CT working again, I see that I
    am still carrying that patch in my custom qemu.

    diff --git a/target-arm/cpu.c b/target-arm/cpu.c
    index 5ce7350..04d69d1 100644
    --- a/target-arm/cpu.c
    +++ b/target-arm/cpu.c
    @@ -858,7 +858,7 @@ static void cortex_a15_initfn(Object *obj)
Quoted 8 lines
         set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
         set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
         set_feature(&cpu->env, ARM_FEATURE_LPAE);
    -    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
    +    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
         cpu->midr = 0x412fc0f1;
         cpu->reset_fpsid = 0x410430f0;
         cpu->mvfr0 = 0x10110222;
Quoted 3 lines

This is obviously a bogus patch -- this is the initfn for Cortex-A15 so telling it to be a Cortex-A7 is wrong (and would break working setups on A15 hosts).

Yes, I definitely was not proposing this as a serious patch! In my copy of qemu it has "HACK" in all capital letters in the summary ...

Quoted 9 lines
Quoted 3 lines

So that's the answer really, it's a qemu bug. Actually it looks as if qemu contains some code to try to get the host CPU type, but it doesn't work, or maybe we need to pass a -cpu option ..."

Yes, you need to pass a -cpu option. For KVM on ARM, you always need to either:
* pass a -cpu option matching the host CPU
* pass "-cpu host"

Quoted 5 lines
Quoted 2 lines

The CubieTruck is a Cortex-A7, which we don't have specific support for in QEMU, so you will need "-cpu host".

Kashyap ^^ can you try this? Should be a trivial one-liner change in src/launch-direct.c.

Yeah, libguestfs build in progress on Cubietruck (it's slow), will test.

Signature · 1 line
/kashyap
#4 lore raw
In reply to Richard W.M. Jones
Quoted 5 lines · Richard W.M. Jones
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Kashyap Chamarthy

Booting a minimal KVM guest throws the below error on Cubietruck:

"kvm_init_vcpu failed: Invalid argument"

[. . .]

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

So that's the answer really, it's a qemu bug. Actually it looks as if qemu contains some code to try to get the host CPU type, but it doesn't work, or maybe we need to pass a -cpu option ..."

Yes, you need to pass a -cpu option. For KVM on ARM, you always need to either:
* pass a -cpu option matching the host CPU
* pass "-cpu host"

Quoted 5 lines
Quoted 2 lines

The CubieTruck is a Cortex-A7, which we don't have specific support for in QEMU, so you will need "-cpu host".

Kashyap ^^ can you try this? Should be a trivial one-liner change in src/launch-direct.c.

Yes it works with it :-)

With the below diff in libguestfs:

    $ git diff src/launch.c
    diff --git a/src/launch.c b/src/launch.c
    index 9fadce8..ce71a8e 100644
    --- a/src/launch.c
    +++ b/src/launch.c
    @@ -400,7 +400,7 @@ const char *
     guestfs___get_cpu_model (int kvm)
     {
     #if defined(__arm__)            /* 32 bit ARM. */
    -  return NULL;
    +  return "host";
     #elif defined(__aarch64__)
       /* With -M virt, the default -cpu is cortex-a15.  Stupid. */

I can boot a KVM guest successfully on Cubietruck, invoked via libguestfs appliance:

. . .

[01433ms] /bin/qemu-system-arm \
    -global virtio-blk-device.scsi=off \
    -nodefconfig \
    -enable-fips \
    -nodefaults \
    -display none \
    -M vexpress-a15 \
    -cpu host \
    -machine accel=kvm:tcg \
    -m 500 \
    -no-reboot \
    -rtc driftfix=slew \
    -global kvm-pit.lost_tick_policy=discard \
    -kernel /home/kashyapc/src/libguestfs/tmp/.guestfs-1000/appliance.d/kernel \
    -dtb /home/kashyapc/src/libguestfs/tmp/.guestfs-1000/appliance.d/dtb \
    -initrd /home/kashyapc/src/libguestfs/tmp/.guestfs-1000/appliance.d/initrd \
    -device virtio-scsi-device,id=scsi \
    -drive file=/home/kashyapc/src/libguestfs/tmp/libguestfsRMfHzO/scratch.1,cache=unsafe,format=raw,id=hd0,if=none \
    -device scsi-hd,drive=hd0 \
    -drive file=/home/kashyapc/src/libguestfs/tmp/.guestfs-1000/appliance.d/root,snapshot=on,id=appliance,cache=unsafe,if=none \
    -device scsi-hd,drive=appliance \
    -device virtio-serial-device \
    -serial stdio \
    -chardev socket,path=/home/kashyapc/src/libguestfs/tmp/libguestfsRMfHzO/guestfsd.sock,id=channel0 \
    -device virtserialport,chardev=channel0,name=org.libguestfs.channel.0 \
    -append 'panic=1 mem=500M console=ttyAMA0 udevtimeout=6000 udev.event-timeout=6000 no_timer_check acpi=off printk.time=1 cgroup_disable=memory root=/dev/sdb selinux=0 guestfs_verbose=1 TERM=vt102'

. . .

Thanks, Rich & Peter.

Signature · 1 line
/kashyap
#5 lore raw
In reply to Kashyap Chamarthy
Quoted 21 lines · Kashyap Chamarthy

Booting a minimal KVM guest throws the below error on Cubietruck:

"kvm_init_vcpu failed: Invalid argument"

More context and an easy reproducer in this QEMU bug[1] for Fedora.

Context quoting Rich Jones from comment #2:

    "For some reason I thought this had been fixed upstream, but
    now that I've finally got my CT working again, I see that I
    am still carrying that patch in my custom qemu.
    
    diff --git a/target-arm/cpu.c b/target-arm/cpu.c
    index 5ce7350..04d69d1 100644
    --- a/target-arm/cpu.c
    +++ b/target-arm/cpu.c
    @@ -858,7 +858,7 @@ static void cortex_a15_initfn(Object *obj)
         set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS);
         set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
         set_feature(&cpu->env, ARM_FEATURE_LPAE);
    -    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15;
Quoted 8 lines
    +    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7;
         cpu->midr = 0x412fc0f1;
         cpu->reset_fpsid = 0x410430f0;
         cpu->mvfr0 = 0x10110222;
    
    So that's the answer really, it's a qemu bug.  Actually it looks as
    if qemu contains some code to try to get the host CPU type, but it
    doesn't work, or maybe we need to pass a -cpu option ..."

Kashyap,

Can you try modifying src/launch-direct.c to see if we can pass

-cpu cortex-a7

and if that fixes the problem?

If that does solve the problem, the question becomes how to detect the right CPU (either cortex-a7, cortex-a15, cortex-a57, ...) This information isn't easily available to libguestfs AFAIK.

I really think that qemu should just "do the right thing" though.

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
#6 lore raw
Quoted 1 line · Richard W.M. Jones

I really think that qemu should just "do the right thing" though.

Tricky, because you have to use the same CPU as the host if you want to use KVM, and that conflicts with wanting to do the same thing on all host platforms for a given set of command line options. If you have some concrete suggestions for improving things that don't break backwards-compatibility I'm happy to hear them, though.

-- PMM

#7 lore raw
Quoted 5 lines · * Peter Maydell ([email protected]) wrote:
Quoted 1 line · Richard W.M. Jones

I really think that qemu should just "do the right thing" though.

Tricky, because you have to use the same CPU as the host if you want to use KVM

That's an unusally strict requirement; is there no concept of a common subset that will work on multiple CPUs?

Is that still true for v8? I can see it making it tricky for users with piles of newer/older hosts.

Dave

Quoted 8 lines

and that conflicts with wanting to do the
same thing on all host platforms for a given set of command line options. If you have some concrete suggestions for improving things that don't break backwards-compatibility I'm happy to hear them, though.

-- PMM

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#8 lore raw
Quoted 4 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Peter Maydell ([email protected]) wrote:
Quoted 1 line · Richard W.M. Jones

I really think that qemu should just "do the right thing" though.

Quoted 8 lines
Quoted 2 lines

Tricky, because you have to use the same CPU as the host if you want to use KVM

That's an unusally strict requirement; is there no concept of a common subset that will work on multiple CPUs?

Is that still true for v8? I can see it making it tricky for users with piles of newer/older hosts.

It's a limitation of the kernel implementation -- we don't attempt to trap things like ID registers, so what the guest sees is just the host CPU. The architecture provides the means to trap these and the KVM API allows userspace to ask the kernel to provide an emulation specifically of a particular CPU. But the kernel will currently always refuse to emulate anything other than the host CPU type it's running on.

thanks
-- PMM