Skip to content

Commit

Permalink
virtme: let user disable KVM accel easily
Browse files Browse the repository at this point in the history
Some testers run without KVM support (including x86 testers running
in nested VMs). Reproducing such conditions with vng currently requires
a bit of hacking. Support --disable-kvm to do the same thing more
cleanly.

Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Feb 1, 2024
1 parent c8086ea commit 28f0710
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 10 additions & 3 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def make_parser() -> argparse.ArgumentParser:
action="store_true",
help='Avoid using the "microvm" QEMU architecture (only on x86_64)',
)
g.add_argument(
"--disable-kvm",
action="store_true",
help='Avoid using hardware virtualization / KVM',
)
g.add_argument(
"--force-initramfs",
action="store_true",
Expand Down Expand Up @@ -720,7 +725,9 @@ def sanitize_disk_args(func: str, arg: str) -> Tuple[str, str]:
return name, fn


def can_use_kvm():
def can_use_kvm(args):
if args.disable_kvm:
return False
if not os.path.exists("/dev/kvm"):
return False
try:
Expand All @@ -733,7 +740,7 @@ def can_use_kvm():


def can_use_microvm(args):
return not args.disable_microvm and not args.numa and args.arch == "x86_64" and can_use_kvm()
return not args.disable_microvm and not args.numa and args.arch == "x86_64" and can_use_kvm(args)


def has_read_acl(username, file_path):
Expand Down Expand Up @@ -963,7 +970,7 @@ def do_it() -> int:
kernelargs.append("virtme_rw_overlay%d=%s" % (i, d))

# Turn on KVM if available
kvm_ok = can_use_kvm()
kvm_ok = can_use_kvm(args)
if is_native and kvm_ok:
qemuargs.extend(["-machine", "accel=kvm:tcg"])

Expand Down
14 changes: 14 additions & 0 deletions virtme_ng/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ def make_parser():
help='Avoid using the "microvm" QEMU architecture (only on x86_64)',
)

parser.add_argument(
"--disable-kvm",
action="store_true",
help='Avoid using hardware virtualization / KVM',
)

parser.add_argument(
"--cwd",
action="store",
Expand Down Expand Up @@ -855,6 +861,12 @@ def _get_virtme_disable_microvm(self, args):
else:
self.virtme_param["disable_microvm"] = ""

def _get_virtme_disable_kvm(self, args):
if args.disable_kvm:
self.virtme_param["disable_kvm"] = "--disable-kvm"
else:
self.virtme_param["disable_kvm"] = ""

def _get_virtme_9p(self, args):
if args.force_9p:
self.virtme_param["force_9p"] = "--force-9p"
Expand Down Expand Up @@ -965,6 +977,7 @@ def run(self, args):
self._get_virtme_disk(args)
self._get_virtme_sound(args)
self._get_virtme_disable_microvm(args)
self._get_virtme_disable_kvm(args)
self._get_virtme_9p(args)
self._get_virtme_initramfs(args)
self._get_virtme_graphics(args)
Expand Down Expand Up @@ -1000,6 +1013,7 @@ def run(self, args):
+ f'{self.virtme_param["disk"]} '
+ f'{self.virtme_param["sound"]} '
+ f'{self.virtme_param["disable_microvm"]} '
+ f'{self.virtme_param["disable_kvm"]} '
+ f'{self.virtme_param["force_9p"]} '
+ f'{self.virtme_param["force_initramfs"]} '
+ f'{self.virtme_param["graphics"]} '
Expand Down

0 comments on commit 28f0710

Please sign in to comment.