qemu-kvm: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument
kvm_arch_init_vcpu Invalid argument host-passthrough kvm
·
1. 问题描述及原因分析
在飞腾5000C的服务器环境下,通过virsh create cirros.xml命令启动虚拟机,报如下错误:
错误:从 cirros.xml 创建域失败
错误:internal error: qemu unexpectedly closed the monitor: 2024-01-25T02:23:36.085930Z qemu-kvm: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument
cirros.xml文件内容如下:
<domain type='kvm' id='1'>
<name>cirros</name>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='aarch64' machine='virt-rhel8.4.0'>hvm</type>
</os>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu'/>
<target dev='sda' bus='scsi'/>
<readonly/>
<boot order='2'/>
<alias name='scsi0-0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/cirros-0.6.0-aarch64-disk.img' index='1'/>
<backingStore/>
<target dev='sdb' bus='scsi'/>
<boot order='1'/>
<alias name='scsi0-0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
</devices>
</domain>
为了验证如上问题,我们直接通过qemu-kvm的命令
qemu-kvm --machine virt -cpu cortex-a57
发现也报
qemu-kvm: kvm_init_vcpu failed: Invalid argument
cortex-a57通过qemu-kvm --machine virt -cpu help查出来的,估计虽然在国产平台显示是支持该款CPU的,实际并不支持,不过如下CPU支持
qemu-kvm --machine virt -cpu Kunpeng-920
为了安全起见我们直接采用host模式
qemu-kvm --machine virt -cpu host
可以成功启动qemu模拟器,故我们改造xml文件,加入host模式,如下
<cpu mode='host-passthrough' check='none'/>
通过virsh create cirros.xml可以成功启动虚拟机,判断为若不指定CPU MODE,会选择到libvirt默认指定的型号,国产平台不一定能支持,故出现kvm_init_vcpu failed: Invalid argument。
2. 解决方案:
在xml里明确指定cpu mode,国产平台一般采用host-passthrough模式更为稳妥,如下,比较完整的cirros.xml如下:
<domain type='kvm' id='1'>
<name>cirros</name>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='aarch64' machine='virt-rhel8.4.0'>hvm</type>
</os>
<features>
<gic version='3'/>
</features>
<cpu mode='host-passthrough' check='none'/>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu'/>
<target dev='sda' bus='scsi'/>
<readonly/>
<boot order='2'/>
<alias name='scsi0-0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/cirros-0.6.0-aarch64-disk.img' index='1'/>
<backingStore/>
<target dev='sdb' bus='scsi'/>
<boot order='1'/>
<alias name='scsi0-0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
</devices>
</domain>
3.参考文献
https://libvirt.org/drvqemu.html
https://blog.csdn.net/avatar_2009/article/details/107666014
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献3条内容
所有评论(0)