From patchwork Wed Jun 5 23:19:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687651 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07E821667D6 for ; Wed, 5 Jun 2024 23:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629566; cv=none; b=OH+eWrNJv8VL2IgZZu48q4Qqfl/7oCB/m4PM0GuJ1ZZNaNKNtbj5MQwuHvjG0plqvGoF3+QwEjgNomNmQeLcd7kYiHXyG7cmEUB0RHTVBaKaS7xOTSPCmji2VS1yUEP99thHOyB3v7x54O69Tag1d3KF0e73jaZRZE9jOwqcTNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629566; c=relaxed/simple; bh=KZVWBgVm+CoCy+mG92mANe4J3jeidmvuMbYAybvIczw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qYCaSwAWOGAOSjOwo15dq3Qq+gV+DT3/RP9Fodc7dRXfZR+UkA/r5ClaeA895QXq5tVkDuJx7SpTYe2xRro+q/vMQM/B0jcvVmbHsV3D437oD662D7Y2F9AKki8Lo5/+StvZzZ1Vn1vcG+3+vYEr8dw+EuYevERMOjkZArWEvG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=y/5Qh6xN; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="y/5Qh6xN" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-627e7f0ca54so5423417b3.3 for ; Wed, 05 Jun 2024 16:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629564; x=1718234364; darn=vger.kernel.org; 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=vvPc1pSLCjHLrclONtENlA0BfdAfFhbhl4BmiE6e03E=; b=y/5Qh6xNCCnYjOh6iKqtxY8Fvl1LjNpzqV/BIG/T+mRlRvJu1+VP0a0dF53qClgGf6 fpWD7L4NnDrWmES+mx6JDis9TTPBm27xQVlUc2vx5iCE2E6Feh5oJLItZs8aP5b3IECl xoNH/w90llIqVDISb+DegBRvUz8NTuFoGQKXL6bT5C/FeF6rG9SUSgCuOnue2iVCWocr g6iGbRE/KQbDUP2nE/MgVXG+0akVMTOOvETZVRWSE3DT2nFS3zOU/prQK9IJTvODoI7Z haA64dYzzhBZUL86zgVbjI8rwCOYR7jzIMZZPvR6ERl3CZD+L2HLuW3zmeh2iiK3Dv1R 49Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629564; x=1718234364; 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=vvPc1pSLCjHLrclONtENlA0BfdAfFhbhl4BmiE6e03E=; b=hCsq60HB6Pum2m7oSfc8yyCNn6aZqm8GBMLQSlfD2GzrlYjgl7I/ZESzB7IbrAq4oX rdUB6MhZQjcvF+bJa/s48ohhJ/AkwI42dVkwBZY/BxrJSH1eSiPNAJKsw7RBr31l+oDx 0Qm4R9yqHxjFe3ZXYulLw9xbILDWGY5XbgpebixDROs4SbIjl2CUqDBNwAIU2YujewbL GXS6ryfmZDmZTuHXPOj3tt3RKGf38XoTVuEW1cJdI2L6o+6EFVy9u7T8eDQ3z5B6yknk K6SDlPf5LGQrcAOZa8lYa/C0fk6cFXSvxubPfMEEXV4HPrlgSEdSC+gpD+uuCYNomGKW XY5g== X-Forwarded-Encrypted: i=1; AJvYcCVo8Fk+orMxKdtlUCyy8reJvQd7chCZ+sl+sIF7c0U5Hr4p93fWRZptUS1lIypNjGX4BUTfGL25HHFb/8L8g3TetcOF X-Gm-Message-State: AOJu0YzU8bQmRpCBnv2Ts1ZyEafP75a5x50a6czg0eYfZUc/CR13tm6F AEHW4C1LGDOSFNBtk4UM9qQ2RKg+hJhfpHq8uTIH0zrCI+vWKG+u/IbiSBoDglVJdtpYEsCVH0g VAA== X-Google-Smtp-Source: AGHT+IGrUaoiWnAsMmJQulI1tZsuHcHEgbkRQ0IFiQ5e3Jr9zXTeKx2KPl9xfXoVkzW4PpCZhjlQYQ8r3sw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:6808:b0:61a:bda3:a78c with SMTP id 00721157ae682-62cbb3004camr9862417b3.0.1717629563976; Wed, 05 Jun 2024 16:19:23 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:09 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-2-seanjc@google.com> Subject: [PATCH v8 01/10] x86/cpu: KVM: Add common defines for architectural memory types (PAT, MTRRs, etc.) From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu Add defines for the architectural memory types that can be shoved into various MSRs and registers, e.g. MTRRs, PAT, VMX capabilities MSRs, EPTPs, etc. While most MSRs/registers support only a subset of all memory types, the values themselves are architectural and identical across all users. Leave the goofy MTRR_TYPE_* definitions as-is since they are in a uapi header, but add compile-time assertions to connect the dots (and sanity check that the msr-index.h values didn't get fat-fingered). Keep the VMX_EPTP_MT_* defines so that it's slightly more obvious that the EPTP holds a single memory type in 3 of its 64 bits; those bits just happen to be 2:0, i.e. don't need to be shifted. Opportunistically use X86_MEMTYPE_WB instead of an open coded '6' in setup_vmcs_config(). No functional change intended. Signed-off-by: Sean Christopherson Acked-by: Kai Huang Reviewed-by: Thomas Gleixner --- arch/x86/include/asm/msr-index.h | 15 ++++++++++++++- arch/x86/include/asm/vmx.h | 5 +++-- arch/x86/kernel/cpu/mtrr/mtrr.c | 6 ++++++ arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/mm/pat/memtype.c | 33 ++++++++++++-------------------- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index e022e6eb766c..1978ba0adb49 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -36,6 +36,20 @@ #define EFER_FFXSR (1<<_EFER_FFXSR) #define EFER_AUTOIBRS (1<<_EFER_AUTOIBRS) +/* + * Architectural memory types that are common to MTRRs, PAT, VMX MSRs, etc. + * Most MSRs support/allow only a subset of memory types, but the values + * themselves are common across all relevant MSRs. + */ +#define X86_MEMTYPE_UC 0ull /* Uncacheable, a.k.a. Strong Uncacheable */ +#define X86_MEMTYPE_WC 1ull /* Write Combining */ +/* RESERVED 2 */ +/* RESERVED 3 */ +#define X86_MEMTYPE_WT 4ull /* Write Through */ +#define X86_MEMTYPE_WP 5ull /* Write Protected */ +#define X86_MEMTYPE_WB 6ull /* Write Back */ +#define X86_MEMTYPE_UC_MINUS 7ull /* Weak Uncacheabled (PAT only) */ + /* FRED MSRs */ #define MSR_IA32_FRED_RSP0 0x1cc /* Level 0 stack pointer */ #define MSR_IA32_FRED_RSP1 0x1cd /* Level 1 stack pointer */ @@ -1153,7 +1167,6 @@ #define VMX_BASIC_64 0x0001000000000000LLU #define VMX_BASIC_MEM_TYPE_SHIFT 50 #define VMX_BASIC_MEM_TYPE_MASK 0x003c000000000000LLU -#define VMX_BASIC_MEM_TYPE_WB 6LLU #define VMX_BASIC_INOUT 0x0040000000000000LLU /* Resctrl MSRs: */ diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index d77a31039f24..e531d8d80a11 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -508,9 +508,10 @@ enum vmcs_field { #define VMX_EPTP_PWL_4 0x18ull #define VMX_EPTP_PWL_5 0x20ull #define VMX_EPTP_AD_ENABLE_BIT (1ull << 6) +/* The EPTP memtype is encoded in bits 2:0, i.e. doesn't need to be shifted. */ #define VMX_EPTP_MT_MASK 0x7ull -#define VMX_EPTP_MT_WB 0x6ull -#define VMX_EPTP_MT_UC 0x0ull +#define VMX_EPTP_MT_WB X86_MEMTYPE_WB +#define VMX_EPTP_MT_UC X86_MEMTYPE_UC #define VMX_EPT_READABLE_MASK 0x1ull #define VMX_EPT_WRITABLE_MASK 0x2ull #define VMX_EPT_EXECUTABLE_MASK 0x4ull diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtrr.c index 767bf1c71aad..125e36010b82 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.c +++ b/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -55,6 +55,12 @@ #include "mtrr.h" +static_assert(X86_MEMTYPE_UC == MTRR_TYPE_UNCACHABLE); +static_assert(X86_MEMTYPE_WC == MTRR_TYPE_WRCOMB); +static_assert(X86_MEMTYPE_WT == MTRR_TYPE_WRTHROUGH); +static_assert(X86_MEMTYPE_WP == MTRR_TYPE_WRPROT); +static_assert(X86_MEMTYPE_WB == MTRR_TYPE_WRBACK); + /* arch_phys_wc_add returns an MTRR register index plus this offset. */ #define MTRR_TO_PHYS_WC_OFFSET 1000 diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 75b4f41d9926..3bd6c026f192 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -7033,7 +7033,7 @@ static void nested_vmx_setup_basic(struct nested_vmx_msrs *msrs) VMCS12_REVISION | VMX_BASIC_TRUE_CTLS | ((u64)VMCS12_SIZE << VMX_BASIC_VMCS_SIZE_SHIFT) | - (VMX_BASIC_MEM_TYPE_WB << VMX_BASIC_MEM_TYPE_SHIFT); + (X86_MEMTYPE_WB << VMX_BASIC_MEM_TYPE_SHIFT); if (cpu_has_vmx_basic_inout()) msrs->basic |= VMX_BASIC_INOUT; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0e3aaf520db2..e495a8b28314 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2711,7 +2711,7 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf, #endif /* Require Write-Back (WB) memory type for VMCS accesses. */ - if (((vmx_msr_high >> 18) & 15) != 6) + if (((vmx_msr_high >> 18) & 15) != X86_MEMTYPE_WB) return -EIO; rdmsrl(MSR_IA32_VMX_MISC, misc_msr); diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index bdc2a240c2aa..15b888ebaf17 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -176,15 +176,6 @@ static inline void set_page_memtype(struct page *pg, } #endif -enum { - PAT_UC = 0, /* uncached */ - PAT_WC = 1, /* Write combining */ - PAT_WT = 4, /* Write Through */ - PAT_WP = 5, /* Write Protected */ - PAT_WB = 6, /* Write Back (default) */ - PAT_UC_MINUS = 7, /* UC, but can be overridden by MTRR */ -}; - #define CM(c) (_PAGE_CACHE_MODE_ ## c) static enum page_cache_mode __init pat_get_cache_mode(unsigned int pat_val, @@ -194,13 +185,13 @@ static enum page_cache_mode __init pat_get_cache_mode(unsigned int pat_val, char *cache_mode; switch (pat_val) { - case PAT_UC: cache = CM(UC); cache_mode = "UC "; break; - case PAT_WC: cache = CM(WC); cache_mode = "WC "; break; - case PAT_WT: cache = CM(WT); cache_mode = "WT "; break; - case PAT_WP: cache = CM(WP); cache_mode = "WP "; break; - case PAT_WB: cache = CM(WB); cache_mode = "WB "; break; - case PAT_UC_MINUS: cache = CM(UC_MINUS); cache_mode = "UC- "; break; - default: cache = CM(WB); cache_mode = "WB "; break; + case X86_MEMTYPE_UC: cache = CM(UC); cache_mode = "UC "; break; + case X86_MEMTYPE_WC: cache = CM(WC); cache_mode = "WC "; break; + case X86_MEMTYPE_WT: cache = CM(WT); cache_mode = "WT "; break; + case X86_MEMTYPE_WP: cache = CM(WP); cache_mode = "WP "; break; + case X86_MEMTYPE_WB: cache = CM(WB); cache_mode = "WB "; break; + case X86_MEMTYPE_UC_MINUS: cache = CM(UC_MINUS); cache_mode = "UC- "; break; + default: cache = CM(WB); cache_mode = "WB "; break; } memcpy(msg, cache_mode, 4); @@ -257,11 +248,11 @@ void pat_cpu_init(void) void __init pat_bp_init(void) { struct cpuinfo_x86 *c = &boot_cpu_data; -#define PAT(p0, p1, p2, p3, p4, p5, p6, p7) \ - (((u64)PAT_ ## p0) | ((u64)PAT_ ## p1 << 8) | \ - ((u64)PAT_ ## p2 << 16) | ((u64)PAT_ ## p3 << 24) | \ - ((u64)PAT_ ## p4 << 32) | ((u64)PAT_ ## p5 << 40) | \ - ((u64)PAT_ ## p6 << 48) | ((u64)PAT_ ## p7 << 56)) +#define PAT(p0, p1, p2, p3, p4, p5, p6, p7) \ + ((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \ + (X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \ + (X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \ + (X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56)) if (!IS_ENABLED(CONFIG_X86_PAT)) From patchwork Wed Jun 5 23:19:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687652 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCF18167DBF for ; Wed, 5 Jun 2024 23:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629568; cv=none; b=ViSe7oMQGWhGCDCtkrGGdT1YmwOzQLuMD1fuJFnMadjcEA2YMODS7PF7yNHnt6w+1s5u81fnay3Q6EJE9f8hsS2WLcTp2qVRmdoVJIhhsCpt+xZeLNHujcL8GJ9nvX4z8kL0WzUxz3RB+rXCQfyVaMMa7vtkg9L/b3ZHbfw4zpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629568; c=relaxed/simple; bh=OT9vjFDhZJe+JrrZnAEYUNwBDJu9CJaj1NqYkfGoeo8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lvAfamaMJSyIGGeR9q+p8s1RmEMLcSUvw9B2gFaf6BEp5HXEWzIoHzhnuXXBn5COCbnR5XOdWf4CmnsKSU7MEyx1zlT0ZPOPobvdOHk/TqPrxjD8saa9jvhbVG2QUYxLVrj2D5if9bPv7wJgABikDiXNJzvZSz6mKkhv79F/4UA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eOWx6Wky; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eOWx6Wky" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2c1ad1ee431so328253a91.0 for ; Wed, 05 Jun 2024 16:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629566; x=1718234366; darn=vger.kernel.org; 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=ARgGaSqi8KoE1rzp74nNuwJdH1oic2zBLvAnQFTt+74=; b=eOWx6WkyZB64F2yv50KrVKWPQvvZnN0dBJ5ZFInZ1FCho1RMgsYnShdf9aW0nZE3uM TZWP/QNw+/19J2nQuhYrtoK/Wkqr7USxQhVx5p9pAA+ue5d90agnTSj+lvpzqCHJVgaM Wlkhvu/5HEIinP4DqQz5mM0F8tu46i0mz55lfoTzUzsB66mU+8hjmN9R7Jk17B1SXT8K +jv92+tEjUlLcc3KjncSkXCWfdFzwcmfpoWjAFC0c8AbVakzH8f8enyaoH3GS3DYa+d1 wOET/Dt5ycFfbo9SqKlkMI1QWbpojzZk3C6pHVkQP1dpKv3vn+XDNlmzSIN2Wa0gV+P4 9W2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629566; x=1718234366; 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=ARgGaSqi8KoE1rzp74nNuwJdH1oic2zBLvAnQFTt+74=; b=X6YuVNzwKfXLYmpdPfUGF/tWhGXT3NrNFbB+pQTkz79OAM2J01HL4bWCxGbPKIecx9 xXgnC7/cdV8QdJPzhsyO7cRHMP1cqovGj++dJxcEK9FvskRqchNVvptREPJxRtJjsqNT Mq9qweN4gTIzqHACiL4Bq6L1o2Kbn9S5NZWTIOkc7W6jFGXP9U1B6qGVYcfHOiR8RG/j aCaX+LCVI0+Q+cgEUAbsiu/407nlaGa1QSQIy4ueER3dOmBwia1Qz2DCYCZMqyi2PWtZ htpTOXJG4XqRZ8INk7Rtoy69zs7JJZ7gxp4naO5DAB8j+aE//3tBbNq/fdIf2idcdQUY PCNA== X-Forwarded-Encrypted: i=1; AJvYcCU209g01vkNF7SGlnJ96/0wCcj4trqtxD+EayzKUelpNVSlwH5sds8DLUPz2ytI6h+R24Ik/wNIsXx/r1g2sCbZWEtV X-Gm-Message-State: AOJu0Yz9lyZQnsg0XwjE7x80FaMTo2PGRWSiaLNLJCsFFXP4RRJ0z+3r jLcyYNU4ztIpeh+Va9QttzMfYBFvbCuahDTibiJnV7XIgbSqyyJVanKISrwdv3TUFSkyyY9AG5k WKw== X-Google-Smtp-Source: AGHT+IEUS/On3FFj7eNLgO/pl33ogfTV3slv6hjA3hktSVZ/uIH5U0G8J1CqwLnY4uPln+tauIKBhcln4jg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:347:b0:2c2:128:47af with SMTP id 98e67ed59e1d1-2c27db6810cmr14869a91.7.1717629565921; Wed, 05 Jun 2024 16:19:25 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:10 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-3-seanjc@google.com> Subject: [PATCH v8 02/10] x86/cpu: KVM: Move macro to encode PAT value to common header From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu Move pat/memtype.c's PAT() macro to msr-index.h as PAT_VALUE(), and use it in KVM to define the default (Power-On / RESET) PAT value instead of open coding an inscrutable magic number. No functional change intended. Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson Reviewed-by: Thomas Gleixner --- arch/x86/include/asm/msr-index.h | 6 ++++++ arch/x86/kvm/x86.h | 3 ++- arch/x86/mm/pat/memtype.c | 13 +++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 1978ba0adb49..d93b73476583 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -377,6 +377,12 @@ #define MSR_IA32_CR_PAT 0x00000277 +#define PAT_VALUE(p0, p1, p2, p3, p4, p5, p6, p7) \ + ((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \ + (X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \ + (X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \ + (X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56)) + #define MSR_IA32_DEBUGCTLMSR 0x000001d9 #define MSR_IA32_LASTBRANCHFROMIP 0x000001db #define MSR_IA32_LASTBRANCHTOIP 0x000001dc diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 5da5b869a991..056cc4a12e56 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -103,7 +103,8 @@ static inline unsigned int __shrink_ple_window(unsigned int val, return max(val, min); } -#define MSR_IA32_CR_PAT_DEFAULT 0x0007040600070406ULL +#define MSR_IA32_CR_PAT_DEFAULT \ + PAT_VALUE(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC) void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu); int kvm_check_nested_events(struct kvm_vcpu *vcpu); diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 15b888ebaf17..6c4e29457c10 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -248,12 +248,6 @@ void pat_cpu_init(void) void __init pat_bp_init(void) { struct cpuinfo_x86 *c = &boot_cpu_data; -#define PAT(p0, p1, p2, p3, p4, p5, p6, p7) \ - ((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \ - (X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \ - (X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \ - (X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56)) - if (!IS_ENABLED(CONFIG_X86_PAT)) pr_info_once("x86/PAT: PAT support disabled because CONFIG_X86_PAT is disabled in the kernel.\n"); @@ -284,7 +278,7 @@ void __init pat_bp_init(void) * NOTE: When WC or WP is used, it is redirected to UC- per * the default setup in __cachemode2pte_tbl[]. */ - pat_msr_val = PAT(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC); + pat_msr_val = PAT_VALUE(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC); } /* @@ -319,7 +313,7 @@ void __init pat_bp_init(void) * NOTE: When WT or WP is used, it is redirected to UC- per * the default setup in __cachemode2pte_tbl[]. */ - pat_msr_val = PAT(WB, WC, UC_MINUS, UC, WB, WC, UC_MINUS, UC); + pat_msr_val = PAT_VALUE(WB, WC, UC_MINUS, UC, WB, WC, UC_MINUS, UC); } else { /* * Full PAT support. We put WT in slot 7 to improve @@ -347,13 +341,12 @@ void __init pat_bp_init(void) * The reserved slots are unused, but mapped to their * corresponding types in the presence of PAT errata. */ - pat_msr_val = PAT(WB, WC, UC_MINUS, UC, WB, WP, UC_MINUS, WT); + pat_msr_val = PAT_VALUE(WB, WC, UC_MINUS, UC, WB, WP, UC_MINUS, WT); } memory_caching_control |= CACHE_PAT; init_cache_modes(pat_msr_val); -#undef PAT } static DEFINE_SPINLOCK(memtype_lock); /* protects memtype accesses */ From patchwork Wed Jun 5 23:19:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687653 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B90A716938D for ; Wed, 5 Jun 2024 23:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629570; cv=none; b=eIupASkCIeTShwyXnC6kwUEIt+D6J1ablSu3/CPg8ytZnbKgw7PfNNp+QBf6JrpMwjtHh9Wz1x9ldGoCUG26b31c+5MSQNr1qTeHPsqxojr5rz3ymSFXayTXcRMMyTbdtYlDu6H2mwnTRG8/6CT/3spLlx6v0LVLAiSqOJTOTX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629570; c=relaxed/simple; bh=vtWhHR8rCipCyVzNAFOmF7RFYT1AytVFYLp9pofdaVo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xx3PKUliKCFB4ZQh1f+5GrKL1je+YAZm+/dIECCrgPi9AncbdPLtEEJSLDl54BvHTKpZole9yu7N4iu+OuAQtDptKkIhbjeKH72MUQ9ANo32cL4fKIJHiQgxR7hk+0yFnYXi3NsrMVEefXqgSSyQyW89TJ48k80wD9NYrT3cP5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=phFCmQi0; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="phFCmQi0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62c823393a4so3790227b3.2 for ; Wed, 05 Jun 2024 16:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629568; x=1718234368; darn=vger.kernel.org; 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=JbnJv6vDpUrRyVZhMkImU0pEXY4NZDKxZhfl/r6eM3A=; b=phFCmQi0I2fG8dYIxhSk0AHuYzfInmJ7fL0WE6PpVzInR8vPnRggesC1fbk2YnOEKx yGDorjR4+5LZn54eeXMqwTTzazXMCj55T1RScmcGSG+cJVFPHL+5eLMoOJMs7WgoLAV6 P+Uqp2ejQpu6yIzuQJcOgQH0ilj61FiNBSIkyw3zBJ1HSfVF9HU7fFesVjFjSwOOFOzV EbXv3okpj3yuct4C+fiQRIkDfYkwiuDi8NFl6y6dWghVnHK5d2aRSoUiX8fBaNICp2IN JnQq3fABiLI882wlWACKY3tOvC6GIQ7h+aI344P5a02nTLY7jzGAvAHkch6HuYgrX4kW 5GZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629568; x=1718234368; 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=JbnJv6vDpUrRyVZhMkImU0pEXY4NZDKxZhfl/r6eM3A=; b=ANLBUfAwlxJ0MzxTJ3vTT1InO5nWblk3B2HJEnA+hsEpnYs5OGoDGRt2ACD2cBtav1 Iz87t4h0JkCvseGf5c4h+dKL/PyubvsfO8rnAghj1myvAFAbYZBZ8CLZY4H/CQXu6YA4 dU+GJkJSfdIgm0ncol4vAH2zC6MVBu/xzecnD8rqfARHMFcBKFh92IS8wSVvQFL/1Hak GuL2lxjLVhbgGwpS2BSlZtOmKlZmE63ZrETTgvLjWR7CxP1eXti9jly1s4Qhs20kjpHl Sd0dg9Rjjhkcp6IF8yCKFkuwiLm6jwAKmZ6IfrFeWa/7AwZ6/w5rjUUkIb7fmGxTMJvb OfcQ== X-Forwarded-Encrypted: i=1; AJvYcCWqA/01a3kkAimGt4eiR7MVCGZv4UkUHUrHU6yOpISugZRsARSKkaPonISJzGarXafUPpk86POtlKAX7GeBPuyCdYKK X-Gm-Message-State: AOJu0YyTCKgkjR/jLwnDuTL7oMcJTr3aLcPcq9Sh1ZMP50Sagis1nC/0 cq4bjGqwGj2opkTTieu33ItH3z9ONAcKqgyj+Z+et3ygiQEAcWEPdec6ryCh/cj0BmCdAbHcsPn qPA== X-Google-Smtp-Source: AGHT+IGT3X5M7VkVP46RRq6pl4m8P42cLEg9GfqDkINN+MTO1zovJ38lv62i90wYIsCXK1EryfZOAVoe7p4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:10:b0:627:a671:8805 with SMTP id 00721157ae682-62cbb4d8986mr12338967b3.3.1717629567792; Wed, 05 Jun 2024 16:19:27 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:11 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-4-seanjc@google.com> Subject: [PATCH v8 03/10] KVM: x86: Stuff vCPU's PAT with default value at RESET, not creation From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu Move the stuffing of the vCPU's PAT to the architectural "default" value from kvm_arch_vcpu_create() to kvm_vcpu_reset(), guarded by !init_event, to better capture that the default value is the value "Following Power-up or Reset". E.g. setting PAT only during creation would break if KVM were to expose a RESET ioctl() to userspace (which is unlikely, but that's not a good reason to have unintuitive code). No functional change. Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Reviewed-by: Jim Mattson Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4157602c964e..887d29db0e05 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12226,8 +12226,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu); - vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT; - kvm_async_pf_hash_reset(vcpu); vcpu->arch.perf_capabilities = kvm_caps.supported_perf_cap; @@ -12393,6 +12391,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) if (!init_event) { vcpu->arch.smbase = 0x30000; + vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT; + vcpu->arch.msr_misc_features_enables = 0; vcpu->arch.ia32_misc_enable_msr = MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL | MSR_IA32_MISC_ENABLE_BTS_UNAVAIL; From patchwork Wed Jun 5 23:19:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687654 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B8D016D4D2 for ; Wed, 5 Jun 2024 23:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629573; cv=none; b=FX0N01Gd15yP7olDa3CSiS1pHrR8nleKX7G4jGgEVPqDBzJfxQ/78eot162qrVHFb50mIv6Eypr5NkGnsjQuXj0EtrAIIZCttbPwNSLk2l9IE9m/Nr27O3aiPdNLuBsbtx8y6r87e7JUH9xo+GeYgkvMId3BgsCIZiidJ+GzoeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629573; c=relaxed/simple; bh=dO25VgHPABsHY2fEB1vc850vQbsSZc7TVlAn3AUTs0s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QZO10ThlyBR1U9QiKYfnRWS+VJuUpK1EDlf/Uvgpdj/iGQQJ5v523cZEWtae8Wntsjg9OmwQM0i+9L0SzQi5fF1j/kWAcNOiU3IvuIaCLIAfukUpqN+dAfrNyMtDfUPqVZlvo49zBOrxZuFOFt+5XP3HOBHDCY83N3pJJ8QHJTo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EGlIrM7a; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EGlIrM7a" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dfa73db88dcso616763276.0 for ; Wed, 05 Jun 2024 16:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629570; x=1718234370; darn=vger.kernel.org; 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=EXdA077yWpI6eczOdgTucO+pfSrwF4gU1Jrgqc+2K/k=; b=EGlIrM7apFsKkOtraFd9l3xurhcgrWIqRYqyAJNVqDJBLSNJXuz0R4lDJNUMBKHLLj POG2mxNeFowfCw4sGG1wU/RrutdtmU+Vsc2JLCbad5kT84ZJG1vZVTRcCirKnvQVXXBm L04XY8F2Zdt3pIxlBHCfyjKk4C5zjdC1euKqkIF+j588O7uZ0KGQbYVMRc8dc6pCDu1M cPW56OrUE7NaECbRMohaN3T+nfjP4mLZViak1A3FJdNpX7lEeAmyitkfjrax1uT7lzVP 5iX1xU5K11vbWI/h9LMO+7lBlMI4rFqESVHu/oxSzFQ+nFC2MzKTO+ZNnBU0zEHjjwAM fZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629570; x=1718234370; 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=EXdA077yWpI6eczOdgTucO+pfSrwF4gU1Jrgqc+2K/k=; b=U3QG0NtJN17cuBodsdq1ldY10Vyggm1yeufKYkDCCc+lwwStHdPtnK61h1g/tNd/1y E47gxz80E2h/+ewYm89BozPLJqaKHa3/bXUG9I59u8pZWV0GZCL2PZUiMu/0wRT0Fu5M McayhypoPloAsWDvzY7jp0KJQ0CRCEhqqwbjPgwlvpiX3bBd0WiO/zDJ5Y+4o+dkF7SD 0DnJTNaqdlcDucZKi7joCsmULgVKlxzLfqkZ4UFgsGwg+ctS05N48STIyNe8F5xKXaJg lw7Lm0YUPgilQ+wweMDGFUt3V4i+ZCvbM//6YeY5T8FiH4AgsOLTrN3uvweKrO4Ep+Se cmRw== X-Forwarded-Encrypted: i=1; AJvYcCUJXX93LrLY0cfI1wSLcrGsUbgcwifk4h6N2XFS/ZeDVKk2PeGid0AgYt9Kir/dRvpVStfA9IgjdAp/v1gGePTyfs4/ X-Gm-Message-State: AOJu0YwLnQFE8pbmKd4vDoXiwEWmEka2pSO/j5ME+qtJewquDRypBxyk Jw+oA8oGYFEueyKFSpy5daajuZoBq9NElgnDUEjKtnIaD9Mhi4DYB8HYEGVb3CiuvxWztbS3zom x2w== X-Google-Smtp-Source: AGHT+IGwHwc7adeQ7Fa0nF/PuQjXMtSIZpJWHdiU+6eoX6gflpLW5j8n1F+4W20UZwZOpHoho/kpjm6DKT8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:c09:b0:dfa:59a1:e8f4 with SMTP id 3f1490d57ef6-dfacace3345mr463340276.10.1717629569624; Wed, 05 Jun 2024 16:19:29 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:12 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-5-seanjc@google.com> Subject: [PATCH v8 04/10] KVM: VMX: Move MSR_IA32_VMX_BASIC bit defines to asm/vmx.h From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu From: Xin Li Move the bit defines for MSR_IA32_VMX_BASIC from msr-index.h to vmx.h so that they are colocated with other VMX MSR bit defines, and with the helpers that extract specific information from an MSR_IA32_VMX_BASIC value. Opportunistically use BIT_ULL() instead of open coding hex values. Opportunistically rename VMX_BASIC_64 to VMX_BASIC_32BIT_PHYS_ADDR_ONLY, as "VMX_BASIC_64" is widly misleading. The flag enumerates that addresses are limited to 32 bits, not that 64-bit addresses are allowed. Last but not least, opportunistically #define DUAL_MONITOR_TREATMENT so that all known single-bit feature flags are defined (this will allow replacing open-coded literals in the future). Cc: Shan Kang Cc: Kai Huang Signed-off-by: Xin Li [sean: split to separate patch, write changelog] Reviewed-by: Zhao Liu Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson Reviewed-by: Xiaoyao Li --- arch/x86/include/asm/msr-index.h | 8 -------- arch/x86/include/asm/vmx.h | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index d93b73476583..b25c1c62b77c 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1167,14 +1167,6 @@ #define MSR_IA32_VMX_VMFUNC 0x00000491 #define MSR_IA32_VMX_PROCBASED_CTLS3 0x00000492 -/* VMX_BASIC bits and bitmasks */ -#define VMX_BASIC_VMCS_SIZE_SHIFT 32 -#define VMX_BASIC_TRUE_CTLS (1ULL << 55) -#define VMX_BASIC_64 0x0001000000000000LLU -#define VMX_BASIC_MEM_TYPE_SHIFT 50 -#define VMX_BASIC_MEM_TYPE_MASK 0x003c000000000000LLU -#define VMX_BASIC_INOUT 0x0040000000000000LLU - /* Resctrl MSRs: */ /* - Intel: */ #define MSR_IA32_L3_QOS_CFG 0xc81 diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index e531d8d80a11..81b986e501a9 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -135,6 +135,13 @@ #define VMX_VMFUNC_EPTP_SWITCHING VMFUNC_CONTROL_BIT(EPTP_SWITCHING) #define VMFUNC_EPTP_ENTRIES 512 +#define VMX_BASIC_VMCS_SIZE_SHIFT 32 +#define VMX_BASIC_32BIT_PHYS_ADDR_ONLY BIT_ULL(48) +#define VMX_BASIC_DUAL_MONITOR_TREATMENT BIT_ULL(49) +#define VMX_BASIC_MEM_TYPE_SHIFT 50 +#define VMX_BASIC_INOUT BIT_ULL(54) +#define VMX_BASIC_TRUE_CTLS BIT_ULL(55) + static inline u32 vmx_basic_vmcs_revision_id(u64 vmx_basic) { return vmx_basic & GENMASK_ULL(30, 0); From patchwork Wed Jun 5 23:19:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687655 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D4CA16D9AB for ; Wed, 5 Jun 2024 23:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629575; cv=none; b=X8F6HLblwjHbAkrgHpDot2YxurtgYujimZuPUzgNCbg1weSoeKPTWWIi3wqfmAeM2JNMM3wzBIPINvXblji4tUiwfr0xL1lm/IBh8kdwdcvGdkJnPWhT9hhq+9p6yahUurkbZRe+MkMPCivSqdosfxJvRZ21oE0HwoXHTMyAiOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629575; c=relaxed/simple; bh=o4TU5aSMsDtgX9oPElesHgr1ttHkW1FxVkZR5HkFqdA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EeSxpMnH2P8Pzydd6+unGrJnG7JheRO38ItPI0elAXlFfP8QeauIP2yrxr9kqMV67CrFNMk6VcvIF3JI6qhS1Kn80JDFysoucyVwWvJymEr+frQCcPs5+IUKeWj3EoRASr/F3ECZpDlEMvvLd1KeJCVWrARlSruVWLCKyHAC5TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JWuOum8U; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JWuOum8U" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-627ee6339d6so4705967b3.3 for ; Wed, 05 Jun 2024 16:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629571; x=1718234371; darn=vger.kernel.org; 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=x0ovJhNxRk771BF46FJnhH05FDemF9LzKryIAxmt7ys=; b=JWuOum8U1N72zdNtBmcAye3osLDDntMf8e7IgACJNu9eSyTvPLvsw0qoCk5txyTD1w URhCBkyqmfhp7ie6QBSAdCvXRC/o1ptivaOl41KjYpu5vac9FEtGo5wxMRr7t19uQawb 778sA6I4GB8k/bzEf2NadAID1PA+p0pDLx9OEK+KiQ5RuH+/Q8AuDuzMfYZ3lPjw07zz z/OMae+UmPVHoVbQOMZPh8QqjHNxMooKU8tylGOYu6CubdRHSwtyQabUg+0bfMCXLXeJ wbRUhW76PpB4Oi0/RmtRgBRmIhaVW6KlK5rYTfTWmBZ/+GzES4kwD1LVmhptC8WqBdCb h+xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629571; x=1718234371; 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=x0ovJhNxRk771BF46FJnhH05FDemF9LzKryIAxmt7ys=; b=Uei0ExafBpOC4fwQdFDd2SmrLR1pWM5OlHQ3tT2Ex/x7huxCOaod+ifDvv5E6Ak7o7 HVS/F4aa3/zH8uYYQqt/lREX7LTd2WWgja0A96ezhzagpYRpppmnwwrShNFVqZ0dH2ov M7IkBHCf5UPAxOVNnjqdBdS7i22nCEuiDaxMOjW5+QXOlNIgph8xMNqeTnlC45gqJPTQ hkn9FQ5f1PJkhJip5UIEPGQUZseO5dG2dVWPqHLb4AHsmnpsknuIOnQJKt7YosZfj1c+ UDPl0sgJYuu8Gf2l/M54tRWc4NAfqKmpEloS0C7+276gR/5W3kWcU18mVPeMnrA6ps5n loyw== X-Forwarded-Encrypted: i=1; AJvYcCVI24x33uRiJDowQ+R/kFc3XzLrnTvwfNSwZYWZrnflwOp8eTPDfpfQmfNEDQGLcSSTvcg4NLQsIyI99LqgkQTcHwVG X-Gm-Message-State: AOJu0YxzfWAws96hM730oRr8yEC5mvbepDvcP7cvuRcRrGq/Cri0LQjO 7UTLq5YSrax9NnNvpXOJIvLYkufTlpFBB5ivuOhIB249VtptbWgBHSDirmoPtEAeHJiZp6Qz2ZP VeA== X-Google-Smtp-Source: AGHT+IHepOEEIycwfROwgwHXcMOucIQZybnv3dylhX3B+i0r0x9Gwt1yiflyLOPSGdHk1wMWKBMD31XgaMU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:95:b0:61b:e73d:bea2 with SMTP id 00721157ae682-62cbb5923bfmr12052037b3.5.1717629571505; Wed, 05 Jun 2024 16:19:31 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:13 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-6-seanjc@google.com> Subject: [PATCH v8 05/10] KVM: VMX: Track CPU's MSR_IA32_VMX_BASIC as a single 64-bit value From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu From: Xin Li Track the "basic" capabilities VMX MSR as a single u64 in vmcs_config instead of splitting it across three fields, that obviously don't combine into a single 64-bit value, so that KVM can use the macros that define MSR bits using their absolute position. Replace all open coded shifts and masks, many of which are relative to the "high" half, with the appropriate macro. Opportunistically use VMX_BASIC_32BIT_PHYS_ADDR_ONLY instead of an open coded equivalent, and clean up the related comment to not reference a specific SDM section (to the surprise of no one, the comment is stale). No functional change intended (though obviously the code generation will be quite different). Cc: Shan Kang Cc: Kai Huang Signed-off-by: Xin Li [sean: split to separate patch, write changelog] Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/include/asm/vmx.h | 5 +++++ arch/x86/kvm/vmx/capabilities.h | 6 ++---- arch/x86/kvm/vmx/vmx.c | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 81b986e501a9..90963b14afaa 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -152,6 +152,11 @@ static inline u32 vmx_basic_vmcs_size(u64 vmx_basic) return (vmx_basic & GENMASK_ULL(44, 32)) >> 32; } +static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic) +{ + return (vmx_basic & GENMASK_ULL(53, 50)) >> 50; +} + static inline int vmx_misc_preemption_timer_rate(u64 vmx_misc) { return vmx_misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 41a4533f9989..86ce8bb96bed 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -54,9 +54,7 @@ struct nested_vmx_msrs { }; struct vmcs_config { - int size; - u32 basic_cap; - u32 revision_id; + u64 basic; u32 pin_based_exec_ctrl; u32 cpu_based_exec_ctrl; u32 cpu_based_2nd_exec_ctrl; @@ -76,7 +74,7 @@ extern struct vmx_capability vmx_capability __ro_after_init; static inline bool cpu_has_vmx_basic_inout(void) { - return (((u64)vmcs_config.basic_cap << 32) & VMX_BASIC_INOUT); + return vmcs_config.basic & VMX_BASIC_INOUT; } static inline bool cpu_has_virtual_nmis(void) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e495a8b28314..3141ef8679e2 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2569,13 +2569,13 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr) static int setup_vmcs_config(struct vmcs_config *vmcs_conf, struct vmx_capability *vmx_cap) { - u32 vmx_msr_low, vmx_msr_high; u32 _pin_based_exec_control = 0; u32 _cpu_based_exec_control = 0; u32 _cpu_based_2nd_exec_control = 0; u64 _cpu_based_3rd_exec_control = 0; u32 _vmexit_control = 0; u32 _vmentry_control = 0; + u64 basic_msr; u64 misc_msr; int i; @@ -2698,29 +2698,29 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf, _vmexit_control &= ~x_ctrl; } - rdmsr(MSR_IA32_VMX_BASIC, vmx_msr_low, vmx_msr_high); + rdmsrl(MSR_IA32_VMX_BASIC, basic_msr); /* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */ - if ((vmx_msr_high & 0x1fff) > PAGE_SIZE) + if (vmx_basic_vmcs_size(basic_msr) > PAGE_SIZE) return -EIO; #ifdef CONFIG_X86_64 - /* IA-32 SDM Vol 3B: 64-bit CPUs always have VMX_BASIC_MSR[48]==0. */ - if (vmx_msr_high & (1u<<16)) + /* + * KVM expects to be able to shove all legal physical addresses into + * VMCS fields for 64-bit kernels, and per the SDM, "This bit is always + * 0 for processors that support Intel 64 architecture". + */ + if (basic_msr & VMX_BASIC_32BIT_PHYS_ADDR_ONLY) return -EIO; #endif /* Require Write-Back (WB) memory type for VMCS accesses. */ - if (((vmx_msr_high >> 18) & 15) != X86_MEMTYPE_WB) + if (vmx_basic_vmcs_mem_type(basic_msr) != X86_MEMTYPE_WB) return -EIO; rdmsrl(MSR_IA32_VMX_MISC, misc_msr); - vmcs_conf->size = vmx_msr_high & 0x1fff; - vmcs_conf->basic_cap = vmx_msr_high & ~0x1fff; - - vmcs_conf->revision_id = vmx_msr_low; - + vmcs_conf->basic = basic_msr; vmcs_conf->pin_based_exec_ctrl = _pin_based_exec_control; vmcs_conf->cpu_based_exec_ctrl = _cpu_based_exec_control; vmcs_conf->cpu_based_2nd_exec_ctrl = _cpu_based_2nd_exec_control; @@ -2870,13 +2870,13 @@ struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu, gfp_t flags) if (!pages) return NULL; vmcs = page_address(pages); - memset(vmcs, 0, vmcs_config.size); + memset(vmcs, 0, vmx_basic_vmcs_size(vmcs_config.basic)); /* KVM supports Enlightened VMCS v1 only */ if (kvm_is_using_evmcs()) vmcs->hdr.revision_id = KVM_EVMCS_VERSION; else - vmcs->hdr.revision_id = vmcs_config.revision_id; + vmcs->hdr.revision_id = vmx_basic_vmcs_revision_id(vmcs_config.basic); if (shadow) vmcs->hdr.shadow_vmcs = 1; @@ -2969,7 +2969,7 @@ static __init int alloc_kvm_area(void) * physical CPU. */ if (kvm_is_using_evmcs()) - vmcs->hdr.revision_id = vmcs_config.revision_id; + vmcs->hdr.revision_id = vmx_basic_vmcs_revision_id(vmcs_config.basic); per_cpu(vmxarea, cpu) = vmcs; } From patchwork Wed Jun 5 23:19:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687656 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0730016E879 for ; Wed, 5 Jun 2024 23:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629575; cv=none; b=l2Z1l8o8K2KkQUg1rkC8xpRsOm8n2xKZ3dEW+NqHS3aGKy3L05X9vHjVozPGgQ71t8lHLCI0ck5Xq9+TCZS8rbbjxQQWTrAPqe46D0f4qqjZXREXqhXtvuhklcK3ZRZDzfzulIwAynPXEoo5yVUNNE4kbc7vvfv9Z+tsrORh97Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629575; c=relaxed/simple; bh=FRu/kZatnQdr9XzHy/g1OUjfeBWGEavtPQGcyQPsq5Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=e+9GWROayai0pZNa12KX1eXjpX2bSysScF7/HKkHclo6yiByQCbntZbQqcJ+fv5QrFEeJYejk1c3ldcvNBDNkKHs9uFomYctfd0ZGYcyBpNZ4vw/JosSU2y9fcEZXfmtj9QJqctwGhsVrX49W1OxMpBY/bUaMFOiGfMktUeuFJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iMGJWMAT; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iMGJWMAT" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-68196e85d64so223286a12.3 for ; Wed, 05 Jun 2024 16:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629573; x=1718234373; darn=vger.kernel.org; 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=pvvZ8DaNbDzOA56vK/6BLcIWihuQnHvhNAp4+dw9cQU=; b=iMGJWMATggWfHjoOT9DVXxedxK6LCc4djxkDQmeSaBE2j0hnR3XLQ3HJdhxYzjUVwE iHLllx1JZcMZpjJFGSjbzO4pgadCMFeR1iipCDJ/xcuQEQdUXl23oVF19S+q9SqdUjwc A8uOTDqeMsXnGJnXQISU1klzpqkY7A4Ds65o1Tvju5Uv1E2t3ONOOMsG4dgaxq75Ms8o e8TithXEA1WLywI8HbDDheBUtMV/P6Fi194QrXMu9jjAP957MXUE6dFcc+cPOOHyQLVG Q3n62eqnbhrwsE9T6L1isWNdkSdIXjLdFvz5irilZ8UP93ZvKtaZ1k15t129qkULcok9 azcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629573; x=1718234373; 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=pvvZ8DaNbDzOA56vK/6BLcIWihuQnHvhNAp4+dw9cQU=; b=Sn4Sp/0hmVm1gQ4W+yJpc3HR2TFhc2CSbWkr79Lh7jswLURFujZxawtsBzp5RhRYa8 2sT7LHYf6ermJMeVafFLkg6+BGwfqWUint9jgJ8YLLWLD7NWZppXDfL866N+mJpY0TfV OYA5ohB3nWlzYDx2h7fHaOTfYYPjZF1vxBoUXDFzLozlxIRJML8k4bJLD7S/8gnke2Q4 5R1uVLOrRjRAEJ3Evq8pscxp6lDlVHJZpFoLXOCosVZb19wt7SiVhgiyusprvzE7yFNN +09NMU1k76tC0mIImcTq64DXUH4PU7GeWCypMId6gj/nJArG7EfFR2uWZ+CF2XxbmVGh 3+Sw== X-Forwarded-Encrypted: i=1; AJvYcCUWQzIQBOpbIH2A/N4xOuY/e8yq3MlMqlGhxO8g69rs5uSpTTPfjQvx/TpE/PAHo69PLZpLTIjZTlYa9wq+UevtpW5n X-Gm-Message-State: AOJu0YyqeYwDyykPhT8DxhAJLhEmxDbWDh/pl/KVsd5mbv7/tvGoyrcp yrijuvfmV/Wx74vEH+2A//E/vgZGclEnpCNQDrghwxkhJ7101ODu0SjDJX2dih8Ck9OHIHLu//S 2GA== X-Google-Smtp-Source: AGHT+IHOil81jTTKEkgMi93RtvAaNFM2ic8gL0rWPxlBlpOJz0HjG3ROR/xU+gQkDYAzR5CBOZFKc/dmHMM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:ec81:b0:1f6:8033:f361 with SMTP id d9443c01a7336-1f6a5a12dcbmr362625ad.6.1717629573132; Wed, 05 Jun 2024 16:19:33 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:14 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-7-seanjc@google.com> Subject: [PATCH v8 06/10] KVM: nVMX: Use macros and #defines in vmx_restore_vmx_basic() From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu From: Xin Li Use macros in vmx_restore_vmx_basic() instead of open coding everything using BIT_ULL() and GENMASK_ULL(). Opportunistically split feature bits and reserved bits into separate variables, and add a comment explaining the subset logic (it's not immediately obvious that the set of feature bits is NOT the set of _supported_ feature bits). Cc: Shan Kang Cc: Kai Huang Signed-off-by: Xin Li [sean: split to separate patch, write changelog, drop #defines] Reviewed-by: Zhao Liu Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 3bd6c026f192..6402def985af 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -1250,21 +1250,32 @@ static bool is_bitwise_subset(u64 superset, u64 subset, u64 mask) static int vmx_restore_vmx_basic(struct vcpu_vmx *vmx, u64 data) { - const u64 feature_and_reserved = - /* feature (except bit 48; see below) */ - BIT_ULL(49) | BIT_ULL(54) | BIT_ULL(55) | - /* reserved */ - BIT_ULL(31) | GENMASK_ULL(47, 45) | GENMASK_ULL(63, 56); + const u64 feature_bits = VMX_BASIC_DUAL_MONITOR_TREATMENT | + VMX_BASIC_INOUT | + VMX_BASIC_TRUE_CTLS; + + const u64 reserved_bits = GENMASK_ULL(63, 56) | + GENMASK_ULL(47, 45) | + BIT_ULL(31); + u64 vmx_basic = vmcs_config.nested.basic; - if (!is_bitwise_subset(vmx_basic, data, feature_and_reserved)) + BUILD_BUG_ON(feature_bits & reserved_bits); + + /* + * Except for 32BIT_PHYS_ADDR_ONLY, which is an anti-feature bit (has + * inverted polarity), the incoming value must not set feature bits or + * reserved bits that aren't allowed/supported by KVM. Fields, i.e. + * multi-bit values, are explicitly checked below. + */ + if (!is_bitwise_subset(vmx_basic, data, feature_bits | reserved_bits)) return -EINVAL; /* * KVM does not emulate a version of VMX that constrains physical * addresses of VMX structures (e.g. VMCS) to 32-bits. */ - if (data & BIT_ULL(48)) + if (data & VMX_BASIC_32BIT_PHYS_ADDR_ONLY) return -EINVAL; if (vmx_basic_vmcs_revision_id(vmx_basic) != From patchwork Wed Jun 5 23:19:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687657 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFE5416FF49 for ; Wed, 5 Jun 2024 23:19:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629577; cv=none; b=Wf9VhHFDmIeMYgws8hO3CMsjmUKmNNuVZLohgRFEN6C5ZETHdVFE8mlQAui5SYcZ0HKooxSd7INp2G27sey/ZlYHDiGUoz0Xjt2Ye10fgMWlTV11PDOjn+3iVEzISUggNgE7IJwjni5g8PhXstppPXhorcYw4j40EY7NMB8LaBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629577; c=relaxed/simple; bh=5h1ApSWgEGpbWSOqPNdtnEs42lVvLBVakXdDFBScEX8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TZJ6bM/fAmhPYAecBFEkry9nWK6bVzq1pnUkAiIvyABMz7F6CkUS/si2rFRI9GpQ3tZftiFMLiLiapnCZbjWtv6n4m2eLQx89pieJcsCcq8xi3kDT8g3ml1VYsFfLGHFcLfgqSlyN9/GMRwMijaF2tR2o6+DCutJwY9BC64+uKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UYsFw4Ac; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UYsFw4Ac" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1f63b8ab0b8so3413725ad.0 for ; Wed, 05 Jun 2024 16:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629575; x=1718234375; darn=vger.kernel.org; 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=VV/Sjw//EJQTvIeLY5r8Wz3KZdB7TmofauSTUG8W0HE=; b=UYsFw4Acv9K2vm8W9h7xpiWGG2+YfoXwP8Nl9I4vY70CUs3F/VjzvuJDt0n6i95aDw xGHgnXChzZOTy91fX4cVYwLO2oIG+OwqG9r1ndt6NOKW5n60zxwAJFPDecu6i5/kxfvE tTABU5r2gktzFBNOWTrJyB+SZhZbV4jJlvAw6aWJJ4ViS3GHNOMyNB/5B4ZySUnV7cAD sSKQsFf1DWNBVFgVRYi4FHZNy7D+tQeLIOsHFfZrkgb6AQTOuuqeUvmZnvWULA/MGj7M klMc9F2cZ9GEoczYowXXL3pP8v8j2M2lGAtcDVO01mkLt13s156bDTo2f6RVfriGhoVd IA6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629575; x=1718234375; 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=VV/Sjw//EJQTvIeLY5r8Wz3KZdB7TmofauSTUG8W0HE=; b=NA4Oqeay/aXtKIKezr9Jx0GwSy/8ycsXDpnPoRGHWXHHfFm5txWKmfgDoI2ufp1laX RgkyJDFZApNpH+d+62a3iGwJMPvGklYiDG2H+B9zBA5gZH8tgG4xfpggYfCKa2miDLQq 6ZIMh6w/hnB8XINyzgItiZliWMxHcI3vZ5QuIAu40a0kwrEPr+CCqQVqMesE+GXISoSo fSuYGK0963FUK7HDXulgnNtHHFYf6mNRkO5q0lIqxNPC1BA9HBC+RMiTcCbfWtIibmUg XhfxH+MActB3oJI8j2JDG+rPiSwP1AvOJQZFeiK34e9+DJ4tGpWdFv4fNlpzdBwrdeLE p43Q== X-Forwarded-Encrypted: i=1; AJvYcCVraLbODGA2B5ko6zWLRF1Lncvvo63eep2N/yTUwl+/v38AxS5+tjRg4MEYq7WZULMQ6vAoWX2h5vr1Vd7H/Y3hNbP4 X-Gm-Message-State: AOJu0YwuRyoiLKVxNMPCPAHGuscIknpm0zrk+V+02BUsAHkFz8G0QaL+ UGWTjAMvN6C8QbLVobKpjSaDsq02CcDJPcqDCl7uWAzbbWyWGGMXAItx/YaqL0eD8FaTwAwIbMz UPw== X-Google-Smtp-Source: AGHT+IFl57quie19EWiUZk1dy0ky6k61IH/ZRAZo8VKLwCcyublpQmT60sT7YGd4MrPH91mTdL/TzVr+UXk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e80d:b0:1f6:d4b:34ff with SMTP id d9443c01a7336-1f6a5901ce9mr1373775ad.3.1717629575068; Wed, 05 Jun 2024 16:19:35 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:15 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-8-seanjc@google.com> Subject: [PATCH v8 07/10] KVM: nVMX: Add a helper to encode VMCS info in MSR_IA32_VMX_BASIC From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu Add a helper to encode the VMCS revision, size, and supported memory types in MSR_IA32_VMX_BASIC, i.e. when synthesizing KVM's supported BASIC MSR value, and delete the now unused VMCS size and memtype shift macros. For a variety of reasons, KVM has shifted (pun intended) to using helpers to *get* information from the VMX MSRs, as opposed to defined MASK and SHIFT macros for direct use. Provide a similar helper for the nested VMX code, which needs to *set* information, so that KVM isn't left with a mix of SHIFT macros and dedicated helpers. Reported-by: Xiaoyao Li Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/include/asm/vmx.h | 7 +++++-- arch/x86/kvm/vmx/nested.c | 8 +++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 90963b14afaa..65aaf0577265 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -135,10 +135,8 @@ #define VMX_VMFUNC_EPTP_SWITCHING VMFUNC_CONTROL_BIT(EPTP_SWITCHING) #define VMFUNC_EPTP_ENTRIES 512 -#define VMX_BASIC_VMCS_SIZE_SHIFT 32 #define VMX_BASIC_32BIT_PHYS_ADDR_ONLY BIT_ULL(48) #define VMX_BASIC_DUAL_MONITOR_TREATMENT BIT_ULL(49) -#define VMX_BASIC_MEM_TYPE_SHIFT 50 #define VMX_BASIC_INOUT BIT_ULL(54) #define VMX_BASIC_TRUE_CTLS BIT_ULL(55) @@ -157,6 +155,11 @@ static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic) return (vmx_basic & GENMASK_ULL(53, 50)) >> 50; } +static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype) +{ + return revision | ((u64)size << 32) | ((u64)memtype << 50); +} + static inline int vmx_misc_preemption_timer_rate(u64 vmx_misc) { return vmx_misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 6402def985af..bb346ca5b5a0 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -7040,12 +7040,10 @@ static void nested_vmx_setup_basic(struct nested_vmx_msrs *msrs) * guest, and the VMCS structure we give it - not about the * VMX support of the underlying hardware. */ - msrs->basic = - VMCS12_REVISION | - VMX_BASIC_TRUE_CTLS | - ((u64)VMCS12_SIZE << VMX_BASIC_VMCS_SIZE_SHIFT) | - (X86_MEMTYPE_WB << VMX_BASIC_MEM_TYPE_SHIFT); + msrs->basic = vmx_basic_encode_vmcs_info(VMCS12_REVISION, VMCS12_SIZE, + X86_MEMTYPE_WB); + msrs->basic |= VMX_BASIC_TRUE_CTLS; if (cpu_has_vmx_basic_inout()) msrs->basic |= VMX_BASIC_INOUT; } From patchwork Wed Jun 5 23:19:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687658 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B023017837D for ; Wed, 5 Jun 2024 23:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629579; cv=none; b=lcECGkJrs8lwzhsA19Wmsq72zsdzc+PBF7xpSlJY1inSR7Rh5FKzvZG/5+bkWZ/QNTDN6IDWyl8zwGKuu4lFHaspHxwCYhhclfiQQnebpaPjv5lhpJiKKzU85kqBhDaN66RDoOZjad/j7yUmeD5bhxJ7TzlR/xkBA1c+lyBDzi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629579; c=relaxed/simple; bh=87CcEc+zxPN+LUcT1TZmaWJwe+boX6+2JKqKtef8L4M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pIid0mn+JG0JE++74AotpejAR267HXWKn4oYayv+bcWKsw2fTbE7KvPndEinLqnasRjFNy1blTcxXDabB4klO7dTLaPGnEzuP2KQfx1D2o6VR8swwnm461qUWURLj5gRN+wpQCX7hGl3vfrp2J74nElItppIJbh4qll/6Ieam8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=p8Fcv0/e; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p8Fcv0/e" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-6cdc904ae4aso265109a12.2 for ; Wed, 05 Jun 2024 16:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629577; x=1718234377; darn=vger.kernel.org; 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=302dzMWNj5Ex/9NtJVlzr9zLleFN3tuSFPHtjrOFLS8=; b=p8Fcv0/eXf6KcofpitmExYXRtutLx2dovc9zVngsJtAHVnF9bqFNHzNswj6c0cX0Gs FETx2xtOt5+USNNEWo4H2V8HWF+InHEGeimXZQeoFYgHHG5NJRkMm8kC9//Ww3RmztSw d1834mXVdie6N9TJMahMovVpoQp6hUuZRY8z6RW6RhV4VEu4VWTiFiBdfN1cIYkZ6ziD YjN2ys2e7pwrvMkZf9P875YzB3FTD1/k2/A9Dulvt8Us19hLR9XmjwGLNHV0Wn6bbufh iHTk9CjJiUP4ldi+ckyuWqbYhvVtikKp1VGBnGBFkNbgqZ2fKEHvoep55XJkYzjoW0IY ZaRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629577; x=1718234377; 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=302dzMWNj5Ex/9NtJVlzr9zLleFN3tuSFPHtjrOFLS8=; b=iETAv/AFa1fPje38RPE4XAPoijpO7bg8S0qoRVmIBhGYbKTz8Bguyve4j08nz+PUuV DMawo84nJZj2mm/SW5+u5kSLyFhdbBkZY3hgeDMjYE0/6bAXzxjXnv7iVK0wStBZP+t1 tpBdT2y3+8CsnvOrvs5WlhovlqLybZGqdNU6u84cKvQrZhHCnIO5GNZNcLGqFtnSHiy8 Zr/F7PlZbQ184FkEk/oxuODpmNck/fTLPpGGSf3laRMeYBX322gVQ2eFfFx4Q7wyKIV3 PHPhDBuEsP1C9SIQhuxDy/SLfW+BcL+lrqvu2EY/GtXR9DVne4ubVc0gmQj+scCKB7gc cl0w== X-Forwarded-Encrypted: i=1; AJvYcCVfewrr9VbJSxPJ95o6B7uz24R5UPg7gD/6D6NoTxkMtFmyqCaYAmAoQzhq/TLQHPze9nOkPS1FZB+JXzxR9FB3T9R4 X-Gm-Message-State: AOJu0YyJn73vXCAVcM27d8T1QgOXrUTb+kiti7N0TvGFambDiI1VA+OE nZ7QNGGB+srDo51Pg9XyVyJOBtk+IcZOdyTu0AK3uP9VGo4zqGS3ZfrkO5+UDG/5sbpR7CKUSJh Knw== X-Google-Smtp-Source: AGHT+IFZG0gjnPIoheoZaQzTgYaDgtvAbqcQepguHlUv9mMXAXcFplkdkQbvtGLhtBD+50XSX8Artyn94ZM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:9555:0:b0:69e:b64d:bbff with SMTP id 41be03b00d2f7-6d94d0b372bmr9920a12.5.1717629576850; Wed, 05 Jun 2024 16:19:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:16 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-9-seanjc@google.com> Subject: [PATCH v8 08/10] KVM VMX: Move MSR_IA32_VMX_MISC bit defines to asm/vmx.h From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu Move the handful of MSR_IA32_VMX_MISC bit defines that are currently in msr-indx.h to vmx.h so that all of the VMX_MISC defines and wrappers can be found in a single location. Opportunistically use BIT_ULL() instead of open coding hex values, add defines for feature bits that are architecturally defined, and move the defines down in the file so that they are colocated with the helpers for getting fields from VMX_MISC. No functional change intended. Cc: Shan Kang Cc: Kai Huang Signed-off-by: Xin Li [sean: split to separate patch, write changelog] Reviewed-by: Zhao Liu Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson Reviewed-by: Xiaoyao Li --- arch/x86/include/asm/msr-index.h | 5 ----- arch/x86/include/asm/vmx.h | 19 ++++++++++++------- arch/x86/kvm/vmx/capabilities.h | 4 ++-- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/nested.h | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index b25c1c62b77c..8fecfa0bfff4 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1183,11 +1183,6 @@ #define MSR_IA32_SMBA_BW_BASE 0xc0000280 #define MSR_IA32_EVT_CFG_BASE 0xc0000400 -/* MSR_IA32_VMX_MISC bits */ -#define MSR_IA32_VMX_MISC_INTEL_PT (1ULL << 14) -#define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29) -#define MSR_IA32_VMX_MISC_PREEMPTION_TIMER_SCALE 0x1F - /* AMD-V MSRs */ #define MSR_VM_CR 0xc0010114 #define MSR_VM_IGNNE 0xc0010115 diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 65aaf0577265..400819ccb42c 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -122,13 +122,6 @@ #define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff -#define VMX_MISC_PREEMPTION_TIMER_RATE_MASK 0x0000001f -#define VMX_MISC_SAVE_EFER_LMA 0x00000020 -#define VMX_MISC_ACTIVITY_HLT 0x00000040 -#define VMX_MISC_ACTIVITY_WAIT_SIPI 0x00000100 -#define VMX_MISC_ZERO_LEN_INS 0x40000000 -#define VMX_MISC_MSR_LIST_MULTIPLIER 512 - /* VMFUNC functions */ #define VMFUNC_CONTROL_BIT(x) BIT((VMX_FEATURE_##x & 0x1f) - 28) @@ -160,6 +153,18 @@ static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype) return revision | ((u64)size << 32) | ((u64)memtype << 50); } +#define VMX_MISC_PREEMPTION_TIMER_RATE_MASK GENMASK_ULL(4, 0) +#define VMX_MISC_SAVE_EFER_LMA BIT_ULL(5) +#define VMX_MISC_ACTIVITY_HLT BIT_ULL(6) +#define VMX_MISC_ACTIVITY_SHUTDOWN BIT_ULL(7) +#define VMX_MISC_ACTIVITY_WAIT_SIPI BIT_ULL(8) +#define VMX_MISC_INTEL_PT BIT_ULL(14) +#define VMX_MISC_RDMSR_IN_SMM BIT_ULL(15) +#define VMX_MISC_VMXOFF_BLOCK_SMI BIT_ULL(28) +#define VMX_MISC_VMWRITE_SHADOW_RO_FIELDS BIT_ULL(29) +#define VMX_MISC_ZERO_LEN_INS BIT_ULL(30) +#define VMX_MISC_MSR_LIST_MULTIPLIER 512 + static inline int vmx_misc_preemption_timer_rate(u64 vmx_misc) { return vmx_misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 86ce8bb96bed..cb6588238f46 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -223,7 +223,7 @@ static inline bool cpu_has_vmx_vmfunc(void) static inline bool cpu_has_vmx_shadow_vmcs(void) { /* check if the cpu supports writing r/o exit information fields */ - if (!(vmcs_config.misc & MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS)) + if (!(vmcs_config.misc & VMX_MISC_VMWRITE_SHADOW_RO_FIELDS)) return false; return vmcs_config.cpu_based_2nd_exec_ctrl & @@ -365,7 +365,7 @@ static inline bool cpu_has_vmx_invvpid_global(void) static inline bool cpu_has_vmx_intel_pt(void) { - return (vmcs_config.misc & MSR_IA32_VMX_MISC_INTEL_PT) && + return (vmcs_config.misc & VMX_MISC_INTEL_PT) && (vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA) && (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL); } diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index bb346ca5b5a0..623e8fcbf427 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -7025,7 +7025,7 @@ static void nested_vmx_setup_misc_data(struct vmcs_config *vmcs_conf, { msrs->misc_low = (u32)vmcs_conf->misc & VMX_MISC_SAVE_EFER_LMA; msrs->misc_low |= - MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS | + VMX_MISC_VMWRITE_SHADOW_RO_FIELDS | VMX_MISC_EMULATED_PREEMPTION_TIMER_RATE | VMX_MISC_ACTIVITY_HLT | VMX_MISC_ACTIVITY_WAIT_SIPI; diff --git a/arch/x86/kvm/vmx/nested.h b/arch/x86/kvm/vmx/nested.h index cce4e2aa30fb..0782fe599757 100644 --- a/arch/x86/kvm/vmx/nested.h +++ b/arch/x86/kvm/vmx/nested.h @@ -109,7 +109,7 @@ static inline unsigned nested_cpu_vmx_misc_cr3_count(struct kvm_vcpu *vcpu) static inline bool nested_cpu_has_vmwrite_any_field(struct kvm_vcpu *vcpu) { return to_vmx(vcpu)->nested.msrs.misc_low & - MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS; + VMX_MISC_VMWRITE_SHADOW_RO_FIELDS; } static inline bool nested_cpu_has_zero_length_injection(struct kvm_vcpu *vcpu) From patchwork Wed Jun 5 23:19:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687659 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BD7117CA1A for ; Wed, 5 Jun 2024 23:19:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629580; cv=none; b=LAeX+IhivWME8HgnkpeWfbKaOP9tkvYPM/lxQBcCgjvK+seOL+JjeeaVURPdA/IUBs0uaEalTTPIJ24+fcYvl8Lcdqr5wpeg3/UbsrF1vvuozomLYUMAfMho8j3Rqdjqf53nNKfmFwbB1bW3RO+55wLRj4RovNg1TdwgQqjZedo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629580; c=relaxed/simple; bh=qT1Q/A+sxSRLAa1UnNv1bglzkpgKWm1lRFUyoxPlGMo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dhB6HI9i7rB35567J6znSW6NNe35ur/W4vR3b12MiPUQ9/PhWfQB9AfUq/sgZXUJC/QBCtY9Al3yTAIxQUTXmlYTvPkZVTacDvIiCoonp9q/8qDdgXCGX/7s8iIYTQJ+218NNo//CQvB/NaBnGsBT6Ig1+bqzciaur7oOuiFZbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=U54ffGPR; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U54ffGPR" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5e4df21f22dso204407a12.0 for ; Wed, 05 Jun 2024 16:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629579; x=1718234379; darn=vger.kernel.org; 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=b5iJECmbxc8XjWct41Unl4ZkHLR82FVwTmxy1PWdoMc=; b=U54ffGPRtNhKFuAIeShBUkYV2Qx89/WK6bD8QY1aK2+k2aU4q/Cvgi6Oew1f0seU9j /UB316vsgVBH04glf6HT4CEZSxX+1Xyt6cwNUKKfe1cp7uedlYYjjtu4ssQompALnwy0 Clc7R41IipHdGHVllp2UNPaHYsdi/goIXVdjirUgVFvxp+Y/iLr2fLNPsQ5/+w4/X2od 0tlkI8ys+kP/Bh7F7QqSzs4L5+ukSje54nR7TnkTzCHb1Q9d4gtlrNfGFTjHEtpz5M0X /YHHKiRpKVJ9HOEDLWKSHA456rgYIzBOt31z6P/ZBpuNrnVhhIkxepbqdF24WHfENoTN r95g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629579; x=1718234379; 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=b5iJECmbxc8XjWct41Unl4ZkHLR82FVwTmxy1PWdoMc=; b=QeK2evkk7Dh3jMXQ5kHeeKLbkcVVcaUt0+sorjGsr6c8OCQw1OI/Jinqd/+XY8jZS5 OlvrAm9g2IBjJiAnQV9kOmpWeO2+EDd4ncwoz5MZm0aDpUzuZq1UXzSlhGbYvA4XU7/Z 4rtzpSm8vpDXU79ZLv5FKGE+5hNQMM6ikFotO7LJKQ/y7HpCeuSp8smhYvBjcr+tJyV5 ti6JfCgLMhPP1v2kJgPuGlUW2loFlU1MlQltvkjfK+9jGTFnsxxAblLrL9uKKc2oG3lG 6F1P7x/fj+6ucBKmShFpscaG0aj00krE9E11qj4ad/IOLVaenyOEdIGQxhPYQEdVJuO3 1bbw== X-Forwarded-Encrypted: i=1; AJvYcCXkqBYg4V4j/6sF3cx2ehPdwZhWai5e36tiBAp7YTPj9wDxnk9ujyUTZnz5hgi0yf89t304Tl1d/S+SWW5zD0OVHdfJ X-Gm-Message-State: AOJu0YyUR3c1lBRGlt9vta91NGrq08il08H6wqhjIl7+OgvV0qjEaC5t QlpIpOrwEJX/ReR1YgrbxqtA/6jmdK7ssIVOjC/pXNBe1xd2JYf93K/0p6MEF9PGm8wy1cHc6DB sSg== X-Google-Smtp-Source: AGHT+IHzGCqGspsUE3KdeJLxZDTEgUfeVZbxWBer++QVBA+iCIe2uO3AyPkz7j5TguAF+TXpdDlYwNQkPxA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a02:6a0:b0:6be:f8bf:6a64 with SMTP id 41be03b00d2f7-6dd1d952bcbmr3813a12.1.1717629578555; Wed, 05 Jun 2024 16:19:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:17 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-10-seanjc@google.com> Subject: [PATCH v8 09/10] KVM: VMX: Open code VMX preemption timer rate mask in its accessor From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu From: Xin Li Use vmx_misc_preemption_timer_rate() to get the rate in hardware_setup(), and open code the rate's bitmask in vmx_misc_preemption_timer_rate() so that the function looks like all the helpers that grab values from VMX_BASIC and VMX_MISC MSR values. No functional change intended. Cc: Shan Kang Cc: Kai Huang Signed-off-by: Xin Li [sean: split to separate patch, write changelog] Reviewed-by: Kai Huang Signed-off-by: Sean Christopherson Reviewed-by: Xiaoyao Li --- arch/x86/include/asm/vmx.h | 3 +-- arch/x86/kvm/vmx/vmx.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 400819ccb42c..f7fd4369b821 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -153,7 +153,6 @@ static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype) return revision | ((u64)size << 32) | ((u64)memtype << 50); } -#define VMX_MISC_PREEMPTION_TIMER_RATE_MASK GENMASK_ULL(4, 0) #define VMX_MISC_SAVE_EFER_LMA BIT_ULL(5) #define VMX_MISC_ACTIVITY_HLT BIT_ULL(6) #define VMX_MISC_ACTIVITY_SHUTDOWN BIT_ULL(7) @@ -167,7 +166,7 @@ static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype) static inline int vmx_misc_preemption_timer_rate(u64 vmx_misc) { - return vmx_misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; + return vmx_misc & GENMASK_ULL(4, 0); } static inline int vmx_misc_cr3_count(u64 vmx_misc) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 3141ef8679e2..69865e7a3506 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8536,7 +8536,7 @@ __init int vmx_hardware_setup(void) u64 use_timer_freq = 5000ULL * 1000 * 1000; cpu_preemption_timer_multi = - vmcs_config.misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; + vmx_misc_preemption_timer_rate(vmcs_config.misc); if (tsc_khz) use_timer_freq = (u64)tsc_khz * 1000; From patchwork Wed Jun 5 23:19:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13687660 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6727417E900 for ; Wed, 5 Jun 2024 23:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629583; cv=none; b=dmDyCse/SsdkReYsttgUvlSu46VwyseXxxdU6rOBg1iKMlDMrDPiL54RIK4dk5enffsM9w1YuoLzl6FmIveGZ+QWQNFZ+Biv+8AzW3BawGJy/hQm7dibnYBNuFT4UK/w+ur8ZIgQVtNh6CvJE5e9sctCjrAnRC9AMi2ARYVE1hE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629583; c=relaxed/simple; bh=m+g0SZx3U4yfgg2ZJiCqAqn/IhUW6hBzAmPzCOMr/Nk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AZeB5+s9Q6R5RA0TIp0jvepMfVKZMwv0UsCY53DGKaAi2JQvrjagwD20wGT0cUkZ33KS1J9YawrB4iJ/Awso1V1ECPQPYbsd0MwXoTN28oZjaAA/DOI19MzazVSErOhePZD1Kg1qO5HWPGkbuca3G584ZOFfd5DUClJTc6+mqI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B4QS+F4v; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B4QS+F4v" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfa8ab88a8cso690534276.0 for ; Wed, 05 Jun 2024 16:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717629580; x=1718234380; darn=vger.kernel.org; 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=fogQWPs5nieObQ0xgx1BEa2/fnrhPHybbu4f2xGt2Gw=; b=B4QS+F4vYzLi9qjNVcKG3/1odMbcmjRvnB037IAIYJ2QZGrr3Mkyhew0mKft15xpV8 u05DyZQFlf/QbrSr0OBcwnbJ03/ujFrlqAcQU0altn804zmmYyZP5+7YlkfAi21can/+ 5TeY1M8+R5N90yOhLcXBNANOgw+2cq4kLFwrzKDOsEiF8nj2OpuwuSWYRc8sCAVAW34d 6FecIvc9fV9HerD+7iB58ROxPKKhmEhe5UZ17CroTl8Esv4W9wkIj28MIuIA44xtejrc XiX7J7GcLLzvCexlPn+V3LmWlvYfPAz+vcnzH/q1mAdG7tThTDJHV4odTdvq0qSQsaxj EcYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717629580; x=1718234380; 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=fogQWPs5nieObQ0xgx1BEa2/fnrhPHybbu4f2xGt2Gw=; b=jJvb9waaraRd3T2foPct4AC5cBB43FX3YSHPV9XxbK58PPsYf6HvGAo4fVIYjTJcEX 7tpkHreG1IyUCK/FIizoE4o8BbShqhZ7jhe7pUGH1AewJg9QL0++hUqBPHjNvmRpQRMk L68ynYuwUxrfUhvg5Wm3MzwfRO1LGPxd+wRSc75IzaGp8nu38GIHgxhk7J0QEjitelWm pzoGGk+2NIlDe3t5jNqbjYrPWqNb7V3nNOIImbQNcwz8YJ+eJTWQSjx//HrIeOMcu6B4 bl3mEi7l9MaSwYu+k7G4MmUnNWTDWeh3ZSfeIZ9ZW8JomuQJl3PLeldPumL5lpL4iUZ+ bibQ== X-Forwarded-Encrypted: i=1; AJvYcCXbwrh0MUK9E0fYK+rjk7t6frakWIbqWkLJhBqju9zcg9Zieej+w0PuyDeIbzMJPDgFdIsCRU+Gr8VRzEYs457/GTiA X-Gm-Message-State: AOJu0YwvDqHM60fH0RRiiSENDM3jpeQheTJgJhbk6klZOFh0SsSjBvWG s38z52ZYVMBedzbIFHkvUlp/tnGok1/o2i5c/f8gD5CYnpYAd3g+kckNtj2bacJCUjuXzgZe/qj 1pg== X-Google-Smtp-Source: AGHT+IGaGsziZpt9w1pgEZdTBlz3ttQUJRstsickABcDEPtPL4e6DcRmnD/S+IdpyACJCnyiutt0q3ZKhKk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:2b93:b0:dfa:b352:824c with SMTP id 3f1490d57ef6-dfacac6e1a6mr1150612276.7.1717629580377; Wed, 05 Jun 2024 16:19:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 5 Jun 2024 16:19:18 -0700 In-Reply-To: <20240605231918.2915961-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240605231918.2915961-1-seanjc@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240605231918.2915961-11-seanjc@google.com> Subject: [PATCH v8 10/10] KVM: nVMX: Use macros and #defines in vmx_restore_vmx_misc() From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Kai Huang , Jim Mattson , Shan Kang , Xin Li , Zhao Liu From: Xin Li Use macros in vmx_restore_vmx_misc() instead of open coding everything using BIT_ULL() and GENMASK_ULL(). Opportunistically split feature bits and reserved bits into separate variables, and add a comment explaining the subset logic (it's not immediately obvious that the set of feature bits is NOT the set of _supported_ feature bits). Cc: Shan Kang Cc: Kai Huang Signed-off-by: Xin Li [sean: split to separate patch, write changelog, drop #defines] Reviewed-by: Xiaoyao Li Reviewed-by: Kai Huang Reviewed-by: Zhao Liu Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 623e8fcbf427..4e3a2303fd9c 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -1344,16 +1344,29 @@ vmx_restore_control_msr(struct vcpu_vmx *vmx, u32 msr_index, u64 data) static int vmx_restore_vmx_misc(struct vcpu_vmx *vmx, u64 data) { - const u64 feature_and_reserved_bits = - /* feature */ - BIT_ULL(5) | GENMASK_ULL(8, 6) | BIT_ULL(14) | BIT_ULL(15) | - BIT_ULL(28) | BIT_ULL(29) | BIT_ULL(30) | - /* reserved */ - GENMASK_ULL(13, 9) | BIT_ULL(31); + const u64 feature_bits = VMX_MISC_SAVE_EFER_LMA | + VMX_MISC_ACTIVITY_HLT | + VMX_MISC_ACTIVITY_SHUTDOWN | + VMX_MISC_ACTIVITY_WAIT_SIPI | + VMX_MISC_INTEL_PT | + VMX_MISC_RDMSR_IN_SMM | + VMX_MISC_VMWRITE_SHADOW_RO_FIELDS | + VMX_MISC_VMXOFF_BLOCK_SMI | + VMX_MISC_ZERO_LEN_INS; + + const u64 reserved_bits = BIT_ULL(31) | GENMASK_ULL(13, 9); + u64 vmx_misc = vmx_control_msr(vmcs_config.nested.misc_low, vmcs_config.nested.misc_high); - if (!is_bitwise_subset(vmx_misc, data, feature_and_reserved_bits)) + BUILD_BUG_ON(feature_bits & reserved_bits); + + /* + * The incoming value must not set feature bits or reserved bits that + * aren't allowed/supported by KVM. Fields, i.e. multi-bit values, are + * explicitly checked below. + */ + if (!is_bitwise_subset(vmx_misc, data, feature_bits | reserved_bits)) return -EINVAL; if ((vmx->nested.msrs.pinbased_ctls_high &