# CPU Baseline

This page explains how go-pve-qemu picks the `--cpu` type for new VMs so they can migrate between any nodes in the cluster.

## Why a Baseline

Proxmox's `host` CPU type exposes the current node's full instruction set to the VM; after migrating to a node with an older instruction set the VM fails to boot. Using the lowest level every node supports trades a little performance for unrestricted migration.

## Detection Flow

1. Read the cache file `.go_qemu_cpu_type`; use it when present
2. `pvesh get /nodes --output-format json` to list every node
3. Run `pvesh get /nodes/<node>/status` per node and parse `cpuinfo.flags`
4. Classify each node with the table below and take the cluster-wide minimum
5. Write `.go_qemu_cpu_type`

If any node query fails, detection fails as a whole and `qm create` falls back to `kvm64`.

## Level Classification

| Level | Required flags |
|---|---|
| `x86-64-v1` | Default when v2 is not met |
| `x86-64-v2` | `cx16` `lahf_lm` `popcnt` `sse4_1` `sse4_2` `ssse3` |
| `x86-64-v2-AES` | v2 + `aes` `pclmulqdq` (and v3 not met) |
| `x86-64-v3` | v2 + `avx` `avx2` `bmi1` `bmi2` `f16c` `fma` `movbe` `lzcnt` `xsaveopt` |
| `x86-64-v4` | v3 + `avx512f` `avx512bw` `avx512cd` `avx512dq` `avx512vl` |

## Known Behavior

- The cluster-wide minimum only recognizes `x86-64-v1` through `v4`; a node classified as `x86-64-v2-AES` counts as v1 and drops the whole cluster baseline to `x86-64-v1`
- The cache never expires on its own; delete `.go_qemu_cpu_type` after adding or replacing nodes
- Existing VMs are unaffected; only VMs created afterwards use the new baseline
