Skip to content

cxl-tool.py should not assume the host has KVM support or that it's enabled #2

@sscargal

Description

@sscargal

When running the cxl-tool.py --run for the first time on an AWS EC2 instance, I encountered the following error

$ ./cxl-tool.py --run
env[qemu_extra_opt] undefined, return empty
mkdir /tmp/cxl-logs/

Starting VM...
sudo chmod 666 /dev/kvm
chmod: cannot access '/dev/kvm': No such file or directory
Start Qemu failed, check /tmp/cxl-logs//qemu0.log for more information
$ ls /dev/kvm
ls: cannot access '/dev/kvm': No such file or directory

The m5.2xlarge instance has the kvm module loaded, but not the kvm_intel CPU driver

$ lsmod | grep -i kvm 
kvm                  1404928  0
irqbypass              12288  1 kvm
$ lscpu 
Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          46 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   4
  On-line CPU(s) list:    0-3
Vendor ID:                GenuineIntel
  Model name:             Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
    CPU family:           6
    Model:                85
    Thread(s) per core:   2
    Core(s) per socket:   2
    Socket(s):            1
    Stepping:             7
    BogoMIPS:             5000.00
    Flags:                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq sss
                          e3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch pti fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap clfl
                          ushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke

It appears that this instance doesn't permit me to load the KVM driver manually. It is more likely that this m5 instance doesn't support nested virtualization.

$ sudo modprobe kvm_intel 
modprobe: ERROR: could not insert 'kvm_intel': Operation not supported

$ egrep -c '(vmx|svm)' /proc/cpuinfo
0

From cxl-tool.py:

parser.add_argument('-A','--accel', help='accel mode: kvm/tcg', required=False, default="kvm")

A proposed fix idea is to handle this gracefully could look like this to utils/tools.py

if accel_mode == "kvm":
    if os.path.exists("/dev/kvm"):
        if not os.access("/dev/kvm", os.R_OK) or not os.access("/dev/kvm", os.W_OK):
            cmd = "sudo chmod 666 /dev/kvm"
            sh_cmd(cmd, echo=True)
    else:
        """ Handle the situation where /dev/kvm does not exist """
        print("Warning: /dev/kvm does not exist. KVM acceleration cannot be used.")
        accel_mode = "tcg"  # Switch to TCG (Tiny Code Generator) as a fallback

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions