Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp36353lqt; Wed, 5 Jun 2024 16:21:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3VpEJSuT5giDNqpTcmLL7aVm0wCLywx2PA5nyufsZwm6DKpjaH7mN/SFIGIiS+bVw7pAD+mzCpClIaP6JGPZvTdPBgScqGQ3QYpOrXQ== X-Google-Smtp-Source: AGHT+IGOH6s/eQsJECUM2r1KY5z8BsozmE2yUkRdQYq8+TzS6NBRBHXhhYe6c4VmvQ/el1NUYX6m X-Received: by 2002:a25:8012:0:b0:df7:887b:abfb with SMTP id 3f1490d57ef6-dfaca9ba7demr4040668276.15.1717629678786; Wed, 05 Jun 2024 16:21:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717629678; cv=pass; d=google.com; s=arc-20160816; b=0xMCwk43Wqz1+8LoZxtqT77nHQVjbcPcVUp7VoqEbIYUzLdAh9Qcn/JknkY3vE3su/ R1pTo8BmjeD96Aq4SQubE7aMN2/gdAJUaBf7s3bvVIZUzcKn/oC5Yk5aHogwFesRvjgx snsBj0baoX898EBpOshM40+BNdliEJuhQBCNUcdZ65lg4CDZ5kaERLofzrdgUhUosmh1 dilo2G73TKEdV7J5r14zznW6W39gw8/8Dth/yQ5HvQ8EIn0yV7wNLvb39Z57nSFfjGca iolxcO82sV27V+yiGqJwtOl6txqcqRsJp5UbnXeu3qqtb7CQWsgWtxi7YERxI7P49I08 ZsJQ== 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=pvvZ8DaNbDzOA56vK/6BLcIWihuQnHvhNAp4+dw9cQU=; fh=d96ppYB8SsPLuH840kRFC0enwv1ssUoG6fdO1ztsAHE=; b=uoE9H/R8CvWemBsIGwy9/T2lFswL3SGMGVhiJmFO1kCp4IxjY57/meszXTGqlTb1nP qXT7bmBNrsPKSgaGl3zDvVMMuv36RRK0IKkHIN+1xfvMqFBfob11tA0DwAtN98OBTrex 37ySlwDXZCWvxoAlkb9CpcvP+QE8b4CjGaDiRSmljkog7e67vDQIFtsGh4KChla69qjK TncSX5hBqZ4/AkIb85V/aKYACxraKQwFcrYCsVpXpVzW3rvMKkhARz4Ru/6uUGvlkKn2 jsDPaUYumvnu5rHXbBVwDM4j6ngOaN1PSg8fJ8wJ3HNhrOg4iIdphqO6Gayxby9jkkeA hHFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iMGJWMAT; 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-203398-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203398-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b04f63c7c8si1757796d6.36.2024.06.05.16.21.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 16:21:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203398-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iMGJWMAT; 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-203398-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203398-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7DF311C2238B for ; Wed, 5 Jun 2024 23:21:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C6F1167299; Wed, 5 Jun 2024 23:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iMGJWMAT" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 026F816E878 for ; Wed, 5 Jun 2024 23:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717629575; cv=none; b=FhU9sr+hMXuglpcxQeFSPQmFy5XnFhTLJrcRZ1ewW8ZabOWUCSw8WdGcrXPQnJk39kHgDfd8U8x+wI7vP+T8MsaGtxM1zCkUtOXLkwlH0li9BPx+2XuMRqfnxZni3tZcXp4NjX0ojty+jk/7zcZ66F0NbQGxHZp7WWIujQY7JHw= 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.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-pg1-f202.google.com with SMTP id 41be03b00d2f7-68196e85d64so223287a12.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=ubjuArhCgD5zDR89FMTCXNPM7u1xfG09PIZozAza5rYMlIZKeSAEHV4v4sVVZ81qau sO5UdCNTr3DYLwfSU5It6qW7lhovpBrvKNlxOzGWTw8Kf5S818gaceYK7wq4b4zA9EdC GZb/JILGF5FEObUEf2xCBlCPybitndTW51JF7CsBwv1emFTZxYkFunuT+A1JaCq8+MDe wHbpPrTapbTiy4vjBG+m/JfRDykjBI/r59fw5ngUs3mHrJKfRMjbNL62aeVKZ2ZZjDsf wJa2Ixy1ZvwyxESZOk5NlVuG63tNK/ju1NoP9900FnvLfm93Su7boJicapoK5TZirJdd dDbQ== X-Gm-Message-State: AOJu0Ywr5imKZB/oOIqtZBT1MyItjx/yWzo54LZbK3cJiz1d1lrlcr9N l15FfG2HEkH+OEkEFD9QXW/LjjUyU8dLw3ufBl6MKqDslle1S/x30eacB6bvB53eESPkU+4LJ8u C/w== 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: 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-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 Content-Type: text/plain; charset="UTF-8" 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) != -- 2.45.1.467.gbab1589fc0-goog