From patchwork Thu Nov 10 01:30:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 17889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp664026wru; Wed, 9 Nov 2022 17:34:47 -0800 (PST) X-Google-Smtp-Source: AMsMyM4mySZr5qUhI5mldvBT2cJDc7O7NYMTWjjUnPq62CCeCUQninAZ39ZnrOiuMks8zgRchPaU X-Received: by 2002:a63:5219:0:b0:459:16e5:9dd9 with SMTP id g25-20020a635219000000b0045916e59dd9mr1481613pgb.362.1668044087595; Wed, 09 Nov 2022 17:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668044087; cv=none; d=google.com; s=arc-20160816; b=XStdMETyVVSUBwtmAhQj7pyEZf03WivFNgQFA/VmLhwD3qlfidiDIh1fnW/AXVhGdY dfP/zM1OTL8sJ0WOnrUt1keKZ8XgRn5z30KUs2mkNwL3scU8yR675azQ/NEeK0av/t3r djNa+WU0aZkLTkDOwub3acvYj+/4Ph58inYMLrcQ7eflDxIBJ4c1t+JiU0AwEXY+9owz U657KKrOUUoAkE/aAzgfQ+Q0PpDZiaTBBW+mj/fCfkUD1TYeb1ImWJTS17UuT2BTflBl mNIzPEQCVVJyGh70M7fJh6xeZX6Uwx+jLy/6XpBDsd/4KQuuA6pxhWjcP06b8CLke2hk tK6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=8CUr/OIWb5uA6RYsOSzZ05CCdXKaCyDdB9TR+zmvZr8=; b=xFYY0E29pglUMuJhS6xi0G0FUtRt4s6ZczpwQJ/Z/VI2T1NNGxy4RwJRt0923lTk5d eY7jChZasI7oUh6li0fNdWsGTX5JD0DcTvSo9lNKOVL5FHdes1vL2qxbCs5JPf8B3r/p DF4S+SynckeoY2xyML6ME/1ycfl/ieCHwtI6L0bGcJt9T2y+tKZg3v1eSnN5Aouts2G+ oLg0j0QRnPOUTjEkQMrJhnwOrt38exwXX8A5nTn6mvtM1BiIXYAvB+Kz45NwPyBDcuUN 04TzkGSNkShp8mjce65jk4KGeqQia4cbn9tlfCK+dNYM0xFLYy3iYI9kx3vw3F/Kh4+S LNkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IY4Hnp9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f132-20020a636a8a000000b004622caf9ac4si17656052pgc.805.2022.11.09.17.34.33; Wed, 09 Nov 2022 17:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IY4Hnp9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbiKJBaQ (ORCPT + 99 others); Wed, 9 Nov 2022 20:30:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbiKJBaJ (ORCPT ); Wed, 9 Nov 2022 20:30:09 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D4AB22B19 for ; Wed, 9 Nov 2022 17:30:08 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id e8-20020a5b0cc8000000b006bca0fa3ab6so576516ybr.0 for ; Wed, 09 Nov 2022 17:30:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=8CUr/OIWb5uA6RYsOSzZ05CCdXKaCyDdB9TR+zmvZr8=; b=IY4Hnp9nEnEWHOuWMXN4OSnd8wrZeOFxLo/VhaYoC1w456+3TkOHkZQi3KGTexqOlH Wlza3rSXhvcTGaSu1ke2JOG5He/C2la4fpKvU6a4r96II3nfgG8NFyq2bZfez24vcwR5 MMp4mv+xBL9FqzPVI6wZ/8zhspUXr+L0ZJcZAzk4dLDngAXinRZVhqexSTvf6IQ1P2sI C/JkLgKbxt7DhD6m0DRwPI+sPWJw3aQSpGn+589BQKLSa5hsWVsV80XRTSpUp7NzTaAX wkq3uOupa/TaJCuoKTr0ROikLx1i3bOUErGnsde6DLbIYqIYyVIJDNxTCcxhzDNO17+7 bvJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8CUr/OIWb5uA6RYsOSzZ05CCdXKaCyDdB9TR+zmvZr8=; b=eg604qkUvK720UhEheJc3+xwjngpIZGiV6isQiijybUdnKXQnPBCA1Ej2G9Dy7mTD8 bfDbYdlK2DCftSTwB58DBALmei+FpoMjceX9u/TxrPp5N9fJlabU+Jn5NC5pnlAKekc+ qkRqHSgjqe3pksLep2AP8ZCBulZXngwf52fOlg8nqEJWypzwvDHCqyJ2MKYVDaCnf+C5 LiDfCdSGQltNU+n1LrHaQcXyo2wbZ1LpGHqzIxdzVzTifmqGEXe6jE1aLgz+XiPKiThp u5QxxbdedvtUo6TjrcFY+gC2lUBbjIaRsfGLyIdrqqMlBG6bwUeycioE2x+dQf/GkzVj iDuQ== X-Gm-Message-State: ACrzQf3ma6ud/OnVbZWbwLYEcIyjTOLKivjpgo1pVyoAJLbwj3nTU6+G 3gkSr+wgZwW3bst1j7qi6ptqecdrIVI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:2455:0:b0:6d0:465:e186 with SMTP id k82-20020a252455000000b006d00465e186mr1047003ybk.278.1668043807310; Wed, 09 Nov 2022 17:30:07 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 10 Nov 2022 01:30:01 +0000 In-Reply-To: <20221110013003.1421895-1-seanjc@google.com> Mime-Version: 1.0 References: <20221110013003.1421895-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221110013003.1421895-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: VMX: Make module params and other variables read-only after init From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749070996881249118?= X-GMAIL-MSGID: =?utf-8?q?1749070996881249118?= 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. Signed-off-by: Sean Christopherson --- 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(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index cd2ac9536c99..1339634ead07 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -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 diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 61a2e551640a..bae81a50cbd7 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -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 diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c index 8f95c7c01433..ca66e6ce7e5d 100644 --- a/arch/x86/kvm/vmx/sgx.c +++ b/arch/x86/kvm/vmx/sgx.c @@ -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 */ diff --git a/arch/x86/kvm/vmx/sgx.h b/arch/x86/kvm/vmx/sgx.h index a400888b376d..1e7fb11eabcf 100644 --- a/arch/x86/kvm/vmx/sgx.h +++ b/arch/x86/kvm/vmx/sgx.h @@ -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); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index aca88524fd1e..c36d29416d52 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -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) From patchwork Thu Nov 10 01:30:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 17891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp664375wru; Wed, 9 Nov 2022 17:35:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf6k85RshkFSQEYvQY2p4Sh+Oj2a6BObAmrlV1uoq9ZtmeFxDZiUP4KQMIQHhUN6z9YD4J4g X-Received: by 2002:a63:ba49:0:b0:470:63e5:5c59 with SMTP id l9-20020a63ba49000000b0047063e55c59mr956113pgu.172.1668044148272; Wed, 09 Nov 2022 17:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668044148; cv=none; d=google.com; s=arc-20160816; b=aqZ3CBWydPUzNRwYvNVLxsnyLZnXSEkN0fKU9kGWWyeD4Gk7W+PQijuGpyr/424K8e glX4x0QgzaiO9RTLBA28BQsRhy1TCpHoByVcozTJBNfpbRZCbUkKO+9yQOfNncvJFxEz L6P+WzuSFcs91XH+os1I+bRfKg/eyAhQ0AQTGWzlRSWF2xc2n6x6G94SgUrO4OrsVRdg ezlaU3k68uxCwznvZnZrE4Nmc2NDYVV4nt/I22EnrW8NvsTWmp0nLfk0kLDGslwAfSYl IN3tSfpa1dQoy80Cv/e2Y2iL/FYHJ0BK//xqwHj9Q9JInE3GnWmXo471cYEGarbfgNet HVnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=/4bwbP2JIl1w6WCsdAS3m6C3yOQnsuV5KJ06kvZbaP0=; b=Ma3K+zvGwITOtnQUgBmQklS6aWdzH2o6hedqfUKgmMLNG/jue3ux4UPREUh+K7hn9s 7GPY5aCsUunJO3ifoQmfZKDs1VpCAmcXGhKl1M1jqNisCHt7HKw+LLyQF8On12n+0Atx 7DrV1XHFFOHLlS9hAF6tC+aJbwUIrUkTRvcQ0fL0e9mRv4C0PhHv5Ng61dEWi9452WLc IoBg3BDjjf40S3cRKP7mahuTAx1dISjtb8g1j3IXzzPjjxbWUw6N96bfAbKAKWgzZtkg OHUKFSU7DUYTXq61IE7iBETQ7Rm5JN2zA/mECqqqr/kuAuF0shpUEudp0U0wZ/AoPwHD dzCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=l0p8172m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020a63d016000000b00450b99448b0si19315957pgf.341.2022.11.09.17.35.34; Wed, 09 Nov 2022 17:35:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=l0p8172m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232296AbiKJBaT (ORCPT + 99 others); Wed, 9 Nov 2022 20:30:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232282AbiKJBaJ (ORCPT ); Wed, 9 Nov 2022 20:30:09 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8882529C for ; Wed, 9 Nov 2022 17:30:09 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id v10-20020a17090a7c0a00b00215deac75b4so251201pjf.3 for ; Wed, 09 Nov 2022 17:30:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=/4bwbP2JIl1w6WCsdAS3m6C3yOQnsuV5KJ06kvZbaP0=; b=l0p8172mRh+A5kK8Bj1NUUAho95PhZ6VdTXUfqMRp+FyO9t9EcrGarYer6gc6AW8i+ 6t6+PCG6D2K79fF/x0m9K11xFPRSBPoSS/eB3QE/Rzt9DwrDWPlyrCUTBE/VQP2eYjs8 EoBvVC0v/E6QTdAlVCD9+9M4FMh5phWFz3D2bGnCo7JmgHsdzYZvKty9fm9FWr/D8l8C Tc0BMS+tizJb1lu8fOY1oVWVDFZzfW4sbI/BCILHRzND+SdUDgLmg+pY5Sc87Wgr6IMr FwutmXDItzc0icn40EUIFlQOPrGVUMsbPNKWsKO7PMLo+mPVu/ovy7eZB9iA3feo071S +dSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/4bwbP2JIl1w6WCsdAS3m6C3yOQnsuV5KJ06kvZbaP0=; b=a7fZV8tdUu082zghGuap1QIkPEWlW0GEhxEaqQDXxDDAsZsT8g7o5TuRJltrHvuP8e 5TlXRr3bruTvaDTOA3f0HMH83/+xoBltiljTjhEfnfyHKizAaU6UoCJ0zRoKskB7HfSM X+8HEdt9p0aPv3tCpIYffU1DvRtEB5Z0t3voIvctWDM98Rsyim0THphfCVLkXJ123Lib Yk+HOL3Psj357eaVP390lpYzc8ZSoax6pVx+NRsI7D9dDhwhaIWfphWLbzduBZtBzPu+ /V8J1AL/2VsXlptF/Ro+wN1iPDlFdvCtFMRS9WFKhB/3OJswlb5JSExTX1LaRHFGmdER v4sQ== X-Gm-Message-State: ACrzQf1WlWyqmbaO4PwCJB7wTw74CEYMF2rHuqOReem82y44h+hOJykm nnHNlwGvLTnVNriN5Vv2C/CINwilNak= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:e86:b0:56b:9ae8:ca05 with SMTP id bo6-20020a056a000e8600b0056b9ae8ca05mr1506767pfb.59.1668043808753; Wed, 09 Nov 2022 17:30:08 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 10 Nov 2022 01:30:02 +0000 In-Reply-To: <20221110013003.1421895-1-seanjc@google.com> Mime-Version: 1.0 References: <20221110013003.1421895-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221110013003.1421895-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: SVM: Make MSR permission bitmap offsets read-only after init From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749071060887051831?= X-GMAIL-MSGID: =?utf-8?q?1749071060887051831?= Tag 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. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 6 +++--- arch/x86/kvm/svm/svm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 527f18d8cc44..e96c808fa8d3 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -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; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 199a2ecef1ce..ca348e016729 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -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; From patchwork Thu Nov 10 01:30:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 17890 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp664111wru; Wed, 9 Nov 2022 17:35:01 -0800 (PST) X-Google-Smtp-Source: AMsMyM4+tVtZKiywIcTg+mw5tJweaGLrfLwKUkvo+wkaL//NmxbwuTxLd8QMLM9zFwK1rKcmuzQr X-Received: by 2002:aa7:c914:0:b0:461:e3e1:bc3b with SMTP id b20-20020aa7c914000000b00461e3e1bc3bmr1412045edt.145.1668044101776; Wed, 09 Nov 2022 17:35:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668044101; cv=none; d=google.com; s=arc-20160816; b=PotlSLnNPPscae5sqWMDYaSD1p9kUBKrx5hpG3Lrn0PUdWoC8gf05hWqOwsg0omCzH PkkGXZWdfvJReAoMs9X1XwelaCQxLCrRQUlTzLBqFnoS55pJ2LPFEHyXnTq36lnuNijx zWzO2FovazSqkD6psrDVQp6IAmMGP4Zu+sIsDNTVNFWswpaizWoHfn/adI6hJVFWnuaF syoRBq8u1uTbwaxbhsNyRQR6D3ehUu9XBB5e9NEj+MIIa00obH7nZpN3RejqpR6qtrzF 6vHe9pVcv3FRbS/XLHj3f3et+xNhhjPifqCF6A2T+PhvKO/lC4qVj3Q6j/lfwG+Z+c55 UWjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=MwcsabIB4BaNJTZXLskYlIE6OYIcO08VWcBRJDU6GBY=; b=Dy2nLNWpA+d9r+3hTVp+UZep0Q/IeQ4COMjnBF/ksFuF20H1ojFBhIn8HCYNkVulX4 TDLXJh2ih+2bXZ+dcMMkP/wajM1oopG5qCDA91am+RQPMgTMLTzaC6xOAMB4XWLnA2BD lY7fAjZIc9YFiytMMNyJpF+BwkI54R8CEXFm4qaX5nISfAJIICHUfM0q909AFkql01Wv +fXjoGcPmLly7vayOe8kCeNdpMxvMpNIV2HpIdPAijCF2o+ieKrohsyFl7SRhJJ9zS6e GjfKkRkwh/cUeh5Gr8MPBHTjUAQGpR06DqoApwXPrxNCsTC6yJvhZ8Lb8NP0WCLbAefg /u9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hqcslbD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg19-20020a170907a41300b0078db71898f2si17898119ejc.851.2022.11.09.17.34.38; Wed, 09 Nov 2022 17:35:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hqcslbD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232314AbiKJBaZ (ORCPT + 99 others); Wed, 9 Nov 2022 20:30:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbiKJBaL (ORCPT ); Wed, 9 Nov 2022 20:30:11 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF5A25EB9 for ; Wed, 9 Nov 2022 17:30:10 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id z125-20020a25c983000000b006dc905e6ccfso553703ybf.1 for ; Wed, 09 Nov 2022 17:30:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=MwcsabIB4BaNJTZXLskYlIE6OYIcO08VWcBRJDU6GBY=; b=hqcslbD7QX+04riaiUMb4oE5H0KGB0y2jsZBE+cI1SYe90LgB1Jnz4F7RxzZkT7/j/ uUwMwVt5PMLKMbBUOfNSNcG4tpMoCPsucflKBJIT2+dpMWYuTmZaK3I0wlt/j/9jJ768 ONZSyzM1wPgVeNiHFxoECj4DLH/GkIcQte9f6qNio5JxpxR7zhwXMMb8Jz8FLp11xLJJ 1Ryb4YabWzDpFSqFqB2jmx7ylbSDDartSDSXuq2cAsMP6pJ72Zh1bwN3jfIP7QSsEdcF q2wArMCyFhhHuM4ZApu0I/4ltv6p4EQt/XAqdDxrbOj2oJXSjsrTxN9l26PCrX/PivEs RiHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MwcsabIB4BaNJTZXLskYlIE6OYIcO08VWcBRJDU6GBY=; b=zUtZKI3C3gxFjC5nVR0G/xm7rvIgshI98toC9VK0DhhmWBAcJtion1tzd4k4TbViOG uVNeuluRbobY++rDt5KQtd9xMeY/tsrYiIpTxpKfaBpIjUFb9vhuJXQliLVODJtODgZS y+oeZM70z9Xbc2R0Yt9eyRyPywZNfG3k7lBryFOdCQFNur7gxRxDTL5gDIt4bPhhGQ8k FQXEJKzMRldmrXeJcRZlCPEZy8aaQS0tz3djRR9MpoPy8nKQRmsDRcFd4X7OjOcW6B7e Oyw26pKKuQwZmyYFgxaUzcgWyUpt1iJz77l9hx/hin8j5uKc0e7ifPTP+qk4y8pkTAsi 1HLQ== X-Gm-Message-State: ACrzQf0rb6UKZE/ML6nhcUI/xPT24wecsltLC1rUiFZ4LJBtWm1YE0/O 6sGxpdVeM/PDIs08TwqJ7OdXgW9u92k= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:5b82:0:b0:36b:c476:c27e with SMTP id p124-20020a815b82000000b0036bc476c27emr1150133ywb.320.1668043810152; Wed, 09 Nov 2022 17:30:10 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 10 Nov 2022 01:30:03 +0000 In-Reply-To: <20221110013003.1421895-1-seanjc@google.com> Mime-Version: 1.0 References: <20221110013003.1421895-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221110013003.1421895-4-seanjc@google.com> Subject: [PATCH 3/3] KVM: SVM: Make module params and other variables read-only after init From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749071012097456900?= X-GMAIL-MSGID: =?utf-8?q?1749071012097456900?= Tag 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. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index e96c808fa8d3..f13d96e1dd0c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -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};