Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qemu): use proper machine type and cpu model based on host arch #1627

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pkg/container/qemu_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,14 @@ func createMicroVM(ctx context.Context, cfg *Config) error {

// we need to fallback to -machine virt, if not machine has been specified
if !microvm {
baseargs = append(baseargs, "-machine", "virt")
if cfg.Arch.ToAPK() != apko_types.ParseArchitecture(runtime.GOARCH).ToAPK() {
baseargs = append(baseargs, "-machine", "virt,virtualization=true")
} else if _, err := os.Stat("/dev/kvm"); err == nil {
// aarch64 supports virt machine type, let's use that if we're on it, else
// if we're on x86 arch, but without microvm machine type, let's go to q35
if cfg.Arch.ToAPK() == "aarch64" {
baseargs = append(baseargs, "-machine", "virt")
} else if cfg.Arch.ToAPK() == "x86_64" {
baseargs = append(baseargs, "-machine", "q35")
} else {
return fmt.Errorf("unknown architecture: %s", cfg.Arch.ToAPK())
}
}

Expand Down Expand Up @@ -370,6 +373,19 @@ func createMicroVM(ctx context.Context, cfg *Config) error {
baseargs = append(baseargs, "-cpu", cfg.CPUModel)
} else {
baseargs = append(baseargs, "-cpu", "host")
// we cant use `-cpu host` when architecture does not match between host
// and guest
if cfg.Arch.ToAPK() != apko_types.ParseArchitecture(runtime.GOARCH).ToAPK() {
// let's use a recent default for those
baseargs = append(baseargs, "-cpu", "max")
89luca89 marked this conversation as resolved.
Show resolved Hide resolved
if cfg.Arch.ToAPK() == "aarch64" {
baseargs = append(baseargs, "-cpu", "cortex-a76")
} else if cfg.Arch.ToAPK() == "x86_64" {
baseargs = append(baseargs, "-cpu", "Haswell-v4")
} else {
return fmt.Errorf("unknown architecture: %s", cfg.Arch.ToAPK())
}
}
}

baseargs = append(baseargs, "-daemonize")
Expand Down
Loading