| 1 | Subject: [PATCH] WHPX: use QEMU interrupt controller emulation for the Cage Linux guest |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | @@ -587,7 +587,7 @@ |
| 8 | args = append(args, "-global", "ICH9-LPC.disable_s3=1") |
| 9 | args = append(args, "-global", "ICH9-LPC.disable_s4=1") |
| 10 | default: |
| 11 | - args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel) |
| 12 | + args = appendQ35Machine(args, accel) |
| 13 | } |
| 14 | case limatype.AARCH64: |
| 15 | machine := "virt,accel=" + accel |
| 16 | |
| 17 | new file mode 100644 |
| 18 | |
| 19 | |
| 20 | @@ -0,0 +1,15 @@ |
| 21 | +// SPDX-FileCopyrightText: Copyright The Lima Authors |
| 22 | +// SPDX-License-Identifier: Apache-2.0 |
| 23 | + |
| 24 | +package qemu |
| 25 | + |
| 26 | +func appendQ35Machine(args []string, accel string) []string { |
| 27 | + machine := "q35,accel=" + accel |
| 28 | + if accel == "whpx" { |
| 29 | + // QEMU 11 can fail to enable nested virtualization on WHPX even |
| 30 | + // when Windows reports it as supported (HRESULT 80370302). Use |
| 31 | + // QEMU's interrupt controller emulation for the Cage Linux guest. |
| 32 | + machine += ",kernel-irqchip=off" |
| 33 | + } |
| 34 | + return appendArgsIfNoConflict(args, "-machine", machine) |
| 35 | +} |
| 36 | |
| 37 | new file mode 100644 |
| 38 | |
| 39 | |
| 40 | @@ -0,0 +1,24 @@ |
| 41 | +// SPDX-FileCopyrightText: Copyright The Lima Authors |
| 42 | +// SPDX-License-Identifier: Apache-2.0 |
| 43 | + |
| 44 | +package qemu |
| 45 | + |
| 46 | +import "testing" |
| 47 | + |
| 48 | +func TestWHPXMachineCompatibility(t *testing.T) { |
| 49 | + for _, accel := range []string{"whpx", "kvm", "hvf", "nvmm"} { |
| 50 | + want := "q35,accel=" + accel |
| 51 | + if accel == "whpx" { |
| 52 | + want += ",kernel-irqchip=off" |
| 53 | + } |
| 54 | + args := appendQ35Machine(nil, accel) |
| 55 | + if got, _ := argValue(args, "-machine"); got != want { |
| 56 | + t.Fatalf("%s: got %q, want %q", accel, got, want) |
| 57 | + } |
| 58 | + } |
| 59 | + // Retain Lima's explicit override contract for custom QEMU arguments. |
| 60 | + args := appendQ35Machine([]string{"-machine", "q35,accel=whpx,kernel-irqchip=on"}, "whpx") |
| 61 | + if len(args) != 2 || args[1] != "q35,accel=whpx,kernel-irqchip=on" { |
| 62 | + t.Fatalf("overrode explicit machine: %v", args) |
| 63 | + } |
| 64 | +} |