KVM: Mark vendor module param read-only after init
Sean Christopherson
maintainercover KVM: Mark vendor module param read-only after init
Mark the read-only VMX and SVM module params, and a few other global variables, read-only after init. In many cases, KVM is royally hosed if a configuration knob changes while VMs are running, e.g. toggling the TDP knob would result in spectacular fireworks.
This series is probably best queued very early in a cycle, as the result of mis-labeled variable is an unexpected kernel #PF.
Sean Christopherson (3):
KVM: VMX: Make module params and other variables read-only after init
KVM: SVM: Make MSR permission bitmap offsets read-only after init
KVM: SVM: Make module params and other variables read-only after init
arch/x86/kvm/svm/svm.c | 38 ++++++++++++++++----------------- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/kvm/vmx/capabilities.h | 16 +++++++------- arch/x86/kvm/vmx/nested.c | 4 ++-- arch/x86/kvm/vmx/sgx.c | 2 +- arch/x86/kvm/vmx/sgx.h | 2 +- arch/x86/kvm/vmx/vmx.c | 36 +++++++++++++++---------------- 7 files changed, 50 insertions(+), 50 deletions(-)
base-commit: d663b8a285986072428a6a145e5994bc275df994
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Sean Christopherson
maintainerPATCH 1/3 KVM: VMX: Make module params and other variables read-only after init
Tag VMX's module params and global variables that are configured under the vmx_init() umbrella as read-only after init. The global knobs should never change once KVM is fully loaded.
--- arch/x86/kvm/vmx/capabilities.h | 16 +++++++-------- arch/x86/kvm/vmx/nested.c | 4 ++-- arch/x86/kvm/vmx/sgx.c | 2 +- arch/x86/kvm/vmx/sgx.h | 2 +- arch/x86/kvm/vmx/vmx.c | 36 ++++++++++++++++----------------- 5 files changed, 30 insertions(+), 30 deletions(-)
arch/x86/kvm/vmx/capabilities.h +8 -8
@@ -9,14 +9,14 @@#include "../pmu.h" #include "../cpuid.h" -extern bool __read_mostly enable_vpid; -extern bool __read_mostly flexpriority_enabled; -extern bool __read_mostly enable_ept; -extern bool __read_mostly enable_unrestricted_guest; -extern bool __read_mostly enable_ept_ad_bits; -extern bool __read_mostly enable_pml; -extern bool __read_mostly enable_ipiv; -extern int __read_mostly pt_mode; +extern bool __ro_after_init enable_vpid; +extern bool __ro_after_init flexpriority_enabled; +extern bool __ro_after_init enable_ept; +extern bool __ro_after_init enable_unrestricted_guest; +extern bool __ro_after_init enable_ept_ad_bits; +extern bool __ro_after_init enable_pml; +extern bool __ro_after_init enable_ipiv; +extern int __ro_after_init pt_mode;#define PT_MODE_SYSTEM 0#define PT_MODE_HOST_GUEST 1
arch/x86/kvm/vmx/nested.c +2 -2
@@ -18,10 +18,10 @@#include "x86.h" #include "smm.h" -static bool __read_mostly enable_shadow_vmcs =1 ; +static bool __ro_after_init enable_shadow_vmcs =1 ;module_param_named (enable_shadow_vmcs, enable_shadow_vmcs, bool,S_IRUGO ); -static bool __read_mostly nested_early_check =0 ; +static bool __ro_after_init nested_early_check;module_param (nested_early_check, bool,S_IRUGO );#define CC KVM_NESTED_VMENTER_CONSISTENCY_CHECK
arch/x86/kvm/vmx/sgx.c +1 -1
@@ -10,7 +10,7 @@#include "vmx.h" #include "x86.h" -bool __read_mostly enable_sgx =1 ; +bool __ro_after_init enable_sgx =1 ;module_param_named (sgx, enable_sgx, bool,0444 );/* Initial value of guest's virtual SGX_LEPUBKEYHASHn MSRs */
arch/x86/kvm/vmx/sgx.h +1 -1
@@ -8,7 +8,7 @@#include "vmx_ops.h" #ifdef CONFIG_X86_SGX_KVM -extern bool __read_mostly enable_sgx; +extern bool __ro_after_init enable_sgx;int handle_encls (struct kvm_vcpu *vcpu);
arch/x86/kvm/vmx/vmx.c +18 -18
@@ -79,34 +79,34 @@ static const struct x86_cpu_id vmx_cpu_id[] = {MODULE_DEVICE_TABLE (x86cpu, vmx_cpu_id);#endif -bool __read_mostly enable_vpid =1 ; +bool __ro_after_init enable_vpid =1 ;module_param_named (vpid, enable_vpid, bool,0444 ); -static bool __read_mostly enable_vnmi =1 ; +static bool __ro_after_init enable_vnmi =1 ;module_param_named (vnmi, enable_vnmi, bool,S_IRUGO ); -bool __read_mostly flexpriority_enabled =1 ; +bool __ro_after_init flexpriority_enabled =1 ;module_param_named (flexpriority, flexpriority_enabled, bool,S_IRUGO ); -bool __read_mostly enable_ept =1 ; +bool __ro_after_init enable_ept =1 ;module_param_named (ept, enable_ept, bool,S_IRUGO ); -bool __read_mostly enable_unrestricted_guest =1 ; +bool __ro_after_init enable_unrestricted_guest =1 ;module_param_named (unrestricted_guest, enable_unrestricted_guest, bool,S_IRUGO ); -bool __read_mostly enable_ept_ad_bits =1 ; +bool __ro_after_init enable_ept_ad_bits =1 ;module_param_named (eptad, enable_ept_ad_bits, bool,S_IRUGO ); -static bool __read_mostly emulate_invalid_guest_state = true; +static bool __ro_after_init emulate_invalid_guest_state = true;module_param (emulate_invalid_guest_state, bool,S_IRUGO ); -static bool __read_mostly fasteoi =1 ; +static bool __ro_after_init fasteoi =1 ;module_param (fasteoi, bool,S_IRUGO );module_param (enable_apicv, bool,S_IRUGO ); -bool __read_mostly enable_ipiv = true; +bool __ro_after_init enable_ipiv = true;module_param (enable_ipiv, bool,0444 );/*
@@ -114,13 +114,13 @@ module_param(enable_ipiv, bool, 0444);* VMX and be a hypervisor for its own guests. If nested=0, guests may not * use VMX instructions. */ -static bool __read_mostly nested =1 ; +static bool __ro_after_init nested =1 ;module_param (nested, bool,S_IRUGO ); -bool __read_mostly enable_pml =1 ; +bool __ro_after_init enable_pml =1 ;module_param_named (pml, enable_pml, bool,S_IRUGO ); -static bool __read_mostly error_on_inconsistent_vmcs_config = true; +static bool __ro_after_init error_on_inconsistent_vmcs_config = true;module_param (error_on_inconsistent_vmcs_config, bool,0444 );static bool __read_mostly dump_invalid_vmcs =0 ;
@@ -132,8 +132,8 @@ module_param(dump_invalid_vmcs, bool, 0644);#define KVM_VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL/* Guest_tsc -> host_tsc conversion requires 64-bit division. */ -static int __read_mostly cpu_preemption_timer_multi; -static bool __read_mostly enable_preemption_timer =1 ; +static int __ro_after_init cpu_preemption_timer_multi; +static bool __ro_after_init enable_preemption_timer =1 ;#ifdef CONFIG_X86_64 module_param_named (preemption_timer, enable_preemption_timer, bool,S_IRUGO );#endif
@@ -211,7 +211,7 @@ static unsigned int ple_window_max = KVM_VMX_DEFAULT_PLE_WINDOW_MAX;module_param (ple_window_max, uint,0444 );/* Default is SYSTEM mode, 1 for host-guest mode */ -int __read_mostly pt_mode =PT_MODE_SYSTEM ; +int __ro_after_init pt_mode =PT_MODE_SYSTEM ;module_param (pt_mode, int,S_IRUGO );static DEFINE_STATIC_KEY_FALSE (vmx_l1d_should_flush);
@@ -237,7 +237,7 @@ static const struct {static void *vmx_l1d_flush_pages;/* Control for disabling CPU Fill buffer clear */ -static bool __read_mostly vmx_fb_clear_ctrl_available; +static bool __ro_after_init vmx_fb_clear_ctrl_available;static int vmx_setup_l1d_flush (enum vmx_l1d_flush_state l1tf) {
@@ -370,7 +370,7 @@ static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp)return sprintf (s,"%s\n" , vmentry_l1d_param[l1tf_vmx_mitigation].option); } -static void vmx_setup_fb_clear_ctrl (void ) +__init static void vmx_setup_fb_clear_ctrl (void ) {u64 msr;
@@ -524,7 +524,7 @@ static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)static unsigned long host_idt_base;#if IS_ENABLED (CONFIG_HYPERV ) -static bool __read_mostly enlightened_vmcs = true; +static bool __ro_after_init enlightened_vmcs = true;module_param (enlightened_vmcs, bool,0444 );static int hv_enable_direct_tlbflush (struct kvm_vcpu *vcpu)
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Sean Christopherson
maintainerPATCH 2/3 KVM: SVM: Make MSR permission bitmap offsets read-only after init
In reply to Sean ChristophersonTag the pre-computed offsets into the MSR permission bitmaps as read-only after init, and similarly tag add_msr_offset() and init_msrpm_offsets() as __init. The bitmaps themselves are dynamically configured, but the offsets, i.e. the set of MSRs that can be passed through to the guest, is static for a given instance of KVM.
--- arch/x86/kvm/svm/svm.c | 6 +++--- arch/x86/kvm/svm/svm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kvm/svm/svm.c +3 -3
@@ -65,7 +65,7 @@ MODULE_DEVICE_TABLE(x86cpu, svm_cpu_id);static bool erratum_383_found__read_mostly ; -u32 msrpm_offsets[MSRPM_OFFSETS ]__read_mostly ; +u32 msrpm_offsets[MSRPM_OFFSETS ]__ro_after_init ;/* * Set osvw_len to higher value when updated Revision Guides
@@ -860,7 +860,7 @@ static void svm_msr_filter_changed(struct kvm_vcpu *vcpu) } } -static void add_msr_offset (u32 offset) +__init static void add_msr_offset (u32 offset) {int i;
@@ -887,7 +887,7 @@ static void add_msr_offset(u32 offset)BUG (); } -static void init_msrpm_offsets (void ) +__init static void init_msrpm_offsets (void ) {int i;
arch/x86/kvm/svm/svm.h +1 -1
@@ -31,7 +31,7 @@#define MAX_DIRECT_ACCESS_MSRS 46#define MSRPM_OFFSETS 32 -extern u32 msrpm_offsets[MSRPM_OFFSETS ]__read_mostly ; +extern u32 msrpm_offsets[MSRPM_OFFSETS ]__ro_after_init ;extern bool npt_enabled;extern int vgif;extern bool intercept_smi;
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Sean Christopherson
maintainerPATCH 3/3 KVM: SVM: Make module params and other variables read-only after init
In reply to Sean ChristophersonTag SVM's module params and global variables that are configured under the svm_init() umbrella as read-only after init. The global knobs should never change once KVM is fully loaded.
--- arch/x86/kvm/svm/svm.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
arch/x86/kvm/svm/svm.c +16 -16
@@ -168,70 +168,70 @@ static const struct svm_direct_access_msrs {* count only mode. */ -static unsigned short pause_filter_thresh =KVM_DEFAULT_PLE_GAP ; +static unsigned short pause_filter_thresh__ro_after_init =KVM_DEFAULT_PLE_GAP ;module_param (pause_filter_thresh, ushort,0444 ); -static unsigned short pause_filter_count =KVM_SVM_DEFAULT_PLE_WINDOW ; +static unsigned short pause_filter_count__ro_after_init =KVM_SVM_DEFAULT_PLE_WINDOW ;module_param (pause_filter_count, ushort,0444 );/* Default doubles per-vcpu window every exit. */ -static unsigned short pause_filter_count_grow =KVM_DEFAULT_PLE_WINDOW_GROW ; +static unsigned short pause_filter_count_grow__ro_after_init =KVM_DEFAULT_PLE_WINDOW_GROW ;module_param (pause_filter_count_grow, ushort,0444 );/* Default resets per-vcpu window every exit to pause_filter_count. */ -static unsigned short pause_filter_count_shrink =KVM_DEFAULT_PLE_WINDOW_SHRINK ; +static unsigned short pause_filter_count_shrink__ro_after_init =KVM_DEFAULT_PLE_WINDOW_SHRINK ;module_param (pause_filter_count_shrink, ushort,0444 );/* Default is to compute the maximum so we can never overflow. */ -static unsigned short pause_filter_count_max =KVM_SVM_DEFAULT_PLE_WINDOW_MAX ; +static unsigned short pause_filter_count_max__ro_after_init =KVM_SVM_DEFAULT_PLE_WINDOW_MAX ;module_param (pause_filter_count_max, ushort,0444 );/* * Use nested page tables by default. Note, NPT may get forced off by * svm_hardware_setup() if it's unsupported by hardware or the host kernel. */ -bool npt_enabled = true; +bool npt_enabled__ro_after_init = true;module_param_named (npt, npt_enabled, bool,0444 );/* allow nested virtualization in KVM/SVM */ -static int nested = true; +static int nested__ro_after_init = true;module_param (nested, int,S_IRUGO );/* enable/disable Next RIP Save */ -static int nrips = true; +static int nrips__ro_after_init = true;module_param (nrips, int,0444 );/* enable/disable Virtual VMLOAD VMSAVE */ -static int vls = true; +static int vls__ro_after_init = true;module_param (vls, int,0444 );/* enable/disable Virtual GIF */ -int vgif = true; +int vgif__ro_after_init = true;module_param (vgif, int,0444 );/* enable/disable LBR virtualization */ -static int lbrv = true; +static int lbrv__ro_after_init = true;module_param (lbrv, int,0444 ); -static int tsc_scaling = true; +static int tsc_scaling__ro_after_init = true;module_param (tsc_scaling, int,0444 );/* * enable / disable AVIC. Because the defaults differ for APICv * support between VMX and SVM we cannot use module_param_named. */ -static bool avic; +static bool avic__ro_after_init ;module_param (avic, bool,0444 );bool __read_mostly dump_invalid_vmcb;module_param (dump_invalid_vmcb, bool,0644 ); -bool intercept_smi = true; +bool intercept_smi__ro_after_init = true;module_param (intercept_smi, bool,0444 ); -static bool svm_gp_erratum_intercept = true; +static bool svm_gp_erratum_intercept__ro_after_init = true;static u8 rsm_ins_bytes[] ="\x0f\xaa" ;
@@ -255,7 +255,7 @@ DEFINE_PER_CPU(struct svm_cpu_data, svm_data);* RDTSCP and RDPID are not used in the kernel, specifically to allow KVM to * defer the restoration of TSC_AUX until the CPU returns to userspace. */ -static int tsc_aux_uret_slot__read_mostly =-1 ; +static int tsc_aux_uret_slot__ro_after_init =-1 ;static const u32 msrpm_ranges[] = {0 ,0xc0000000 ,0xc0010000 };
Signature · 1 line
2.38.1.431.g37b22c650d-goog