Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp36522lqt; Wed, 5 Jun 2024 16:21:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxsw3dTtvEFmPytRCbRzv4Z1Tf6xISDjsSWI1b68cm0agO/q6/U2J3620lIST7o/rZMP+WEo6Cx5ln7nqQbWD1r5OkSx8qa25e7Fnc1g== X-Google-Smtp-Source: AGHT+IE4vm94B0l0GQ8S7cy+H+Z6AruzuieZ3sxFSm8P1D+bXvA02Yog2xy3wsSZs/LLdDMC8Csa X-Received: by 2002:a17:903:4053:b0:1f6:3720:ce56 with SMTP id d9443c01a7336-1f6a5a12094mr32429045ad.27.1717629705566; Wed, 05 Jun 2024 16:21:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717629705; cv=pass; d=google.com; s=arc-20160816; b=kJ9MZXJjdYrXukWHG0Phxjhsqv9IwHdBXlYxw+mEztNfYhy1bvyVN/6D5lmd4HTdfO XZ/uEo6tJJt4mvKppvzcWeaoR6T/xxG3IUa6bsCzebrfS4HqfwEWrtJVTjreUW7c95Kw EUY6KwzxVn1rvAJ6ImBZjZeCYvT9+62ZeEKml7ffmZkkxCsliP5eTHkjj6t+by2Lx+4k BJ8aZWiLclVn6WrkFK8DwXKOrRZg6iDoTSmpl31Qxhs0QOgoPQ+G9aNZDIaLV6S/F79s KkhiANImHXjJKM9OHDL9HXajOJ4+GT7pbhavLXH6ba67z/T4Q4+722w8P9mWXqAh2QvR 24BA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=VV/Sjw//EJQTvIeLY5r8Wz3KZdB7TmofauSTUG8W0HE=; fh=d96ppYB8SsPLuH840kRFC0enwv1ssUoG6fdO1ztsAHE=; b=rfYKyLKGz0lDLkyzAaCNSNKC5MLiBCcYk0xes72BAfQQicr5nrUbl6GDz6oBgwDWcs aImRMBMc/b1eaEJRZDAGP+s7Wn0FwYV36HCLVC5Qfini1QYC1xOBPZIr6z7ho3fdKfrQ Spge/3TYLY1BYakPMs9VTSyqAmXEi6iC/RGym/1hRDffPQ9BGeoMtHyUEExBNuqGof4Z xhoKI+jBChp+tjsrAyfNWXNqAuWWukhdO79XNph55Qn1yW8n5eDAhlzGPtWQ3X2IQdN3 6w2u2q1OYO9jRJPCiPAAV3QoRMHnBCe1vMgU3nqJtxWTsd7CwIosqhQTjQMMxmuv2aiH nmVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UYsFw4Ac; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-203399-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7d64b9si1293235ad.214.2024.06.05.16.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 16:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203399-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UYsFw4Ac; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-203399-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 30A1B280D5F for ; Wed, 5 Jun 2024 23:21:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2F6117B401; Wed, 5 Jun 2024 23:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UYsFw4Ac" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 C7CB616FF23 for ; Wed, 5 Jun 2024 23:19:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629577; cv=none; b=q3WXM20UdFcRvmAsy3IwbDFPAeIIssgGyq7vLiXg6NDX7PzSlaP02Tc27ld22OeBDyjAAjDQ8cB8AYyt/kShXvvbMHpczd3xLWVm4NHMOvKP91IxSj7jMyVYNmou9LOu1o1edKv0hdlbgnNFLqo8WsrG50oZP6EPH7EV/4Lg0kU= 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.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 Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1f624b473e3so3242855ad.3 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=BVzkrVdU+XaxPp9Ee5SRMnQXWiSna+zA6uZ4hq0XRyXX0v9IVu/ZxYc72+0UafsAzv 0Us+0aB83XHdN4P4w2VMFPIT8t5O4H6s5HL686xoBHfOpN9wA6TJdSm5VzqJo/QQRDvE sV8i1glY1Z0zPF3ahvbzLDBHDLFLnoKWKGvPTRN7yx2KlijBwygB6XEmsF+SZB6VgLY0 m2aW/ve7PkqcedBkKQayqcTtHswJoLquuuzvKQNvAEUwjFJ/AU4cWoKaDXgccWjYy5DH 0ceqO9Xvnw+ucEMgk0xmgY7gVQCsG3NWD3aTE05/P6JuedlaiOsDbOQBvwP3FpMHDaUA hgFA== X-Gm-Message-State: AOJu0YzZCzVooyq7ljiIZFkCi1C4Lphzyg+NHgyOlUy3J9k40QyoOKYy fg7ELeFG92gBA5k1EQbhDNEBBnOy7xa2A2pp/W0oENKFCifEOpGOcnYqgsaVGwWR6k+uWx+sQac A/Q== 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: linux-kernel@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 Content-Type: text/plain; charset="UTF-8" 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; } -- 2.45.1.467.gbab1589fc0-goog