|
64 | 64 |
|
65 | 65 | static_assert(__AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_IDX_MASK) == -1u); |
66 | 66 |
|
| 67 | +#define AVIC_AUTO_MODE -1 |
| 68 | + |
| 69 | +static int avic_param_set(const char *val, const struct kernel_param *kp) |
| 70 | +{ |
| 71 | + if (val && sysfs_streq(val, "auto")) { |
| 72 | + *(int *)kp->arg = AVIC_AUTO_MODE; |
| 73 | + return 0; |
| 74 | + } |
| 75 | + |
| 76 | + return param_set_bint(val, kp); |
| 77 | +} |
| 78 | + |
| 79 | +static const struct kernel_param_ops avic_ops = { |
| 80 | + .flags = KERNEL_PARAM_OPS_FL_NOARG, |
| 81 | + .set = avic_param_set, |
| 82 | + .get = param_get_bool, |
| 83 | +}; |
| 84 | + |
67 | 85 | /* |
68 | | - * enable / disable AVIC. Because the defaults differ for APICv |
69 | | - * support between VMX and SVM we cannot use module_param_named. |
| 86 | + * Enable / disable AVIC. In "auto" mode (default behavior), AVIC is enabled |
| 87 | + * for Zen4+ CPUs with x2AVIC (and all other criteria for enablement are met). |
70 | 88 | */ |
71 | | -static bool avic; |
72 | | -module_param(avic, bool, 0444); |
| 89 | +static int avic = AVIC_AUTO_MODE; |
| 90 | +module_param_cb(avic, &avic_ops, &avic, 0444); |
| 91 | +__MODULE_PARM_TYPE(avic, "bool"); |
| 92 | + |
73 | 93 | module_param(enable_ipiv, bool, 0444); |
74 | 94 |
|
75 | 95 | static bool force_avic; |
@@ -1151,6 +1171,18 @@ void avic_vcpu_unblocking(struct kvm_vcpu *vcpu) |
1151 | 1171 |
|
1152 | 1172 | static bool __init avic_want_avic_enabled(void) |
1153 | 1173 | { |
| 1174 | + /* |
| 1175 | + * In "auto" mode, enable AVIC by default for Zen4+ if x2AVIC is |
| 1176 | + * supported (to avoid enabling partial support by default, and because |
| 1177 | + * x2AVIC should be supported by all Zen4+ CPUs). Explicitly check for |
| 1178 | + * family 0x19 and later (Zen5+), as the kernel's synthetic ZenX flags |
| 1179 | + * aren't inclusive of previous generations, i.e. the kernel will set |
| 1180 | + * at most one ZenX feature flag. |
| 1181 | + */ |
| 1182 | + if (avic == AVIC_AUTO_MODE) |
| 1183 | + avic = boot_cpu_has(X86_FEATURE_X2AVIC) && |
| 1184 | + (boot_cpu_data.x86 > 0x19 || cpu_feature_enabled(X86_FEATURE_ZEN4)); |
| 1185 | + |
1154 | 1186 | if (!avic || !npt_enabled) |
1155 | 1187 | return false; |
1156 | 1188 |
|
|
0 commit comments