Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp18732rdb; Thu, 21 Dec 2023 01:14:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjDorBd+48RNMaDbB7b1XpSxGhXGJhdNX6uv3mj7Z37Afnkh+IPTfNw5627LxXcNAxMXL+ X-Received: by 2002:a05:6a20:bca5:b0:195:e8f:66ab with SMTP id fx37-20020a056a20bca500b001950e8f66abmr359596pzb.36.1703150074498; Thu, 21 Dec 2023 01:14:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703150074; cv=none; d=google.com; s=arc-20160816; b=owXeG9EHpB72dD2mHgKEU68/0pG5UMnaphCOy4wELwP/ax6qZnzmNJNGa6xBsftWAu C3PkogqfgZLj2/uQ5focu2OAkC47ZPYPPa1IWGahJ+AdULEte0hkrWkHmp2o4M/0xuRh n5eFtcFDybjpFiJRrIFQboXJL0haMX6pHquH2aXT1Ukkf6AQmRFXtgWncJ7D7RMnBB1p F34sgwAvkvfYSBAJkJgpDRwqJ00kSTTeAbx2v7FzhiOQsHOQ1GaoAfJPglvX5/7F3S0Z CCIcxw6MEjmEjHbaohSnMwlCaAiB53QPAxTPx/MxjzVAhHAq03JE3KnTDlIevbkPLyNo vaBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NcDENkm2zmS8KmC2+RYVL3E73gGw5nUgtjFWSHp3UIU=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=c/6PLn+x5Qh7k4VtaCEG5O0gYIgLRVsFvL9GMynglS7ecmSM3c2Z9hLC7jwWAt2kUJ ariw0rULEwxVgPUsYt2PLrSruB5JSxQFkmxL1kbqeCiupTPS12xWycU1YdjFCYxIxSNk H+LI8CeRegNxvgv4hS18k+g+O7du/DlrHxfBTAlKeXDyg7itqo7cDx3XC+9zTvsdAZpf bsmR4Av8CG/xWyuxSvUY6mQzieOZGp2khP/0DzhClogMhx4jW+h6BcB+eCLiYkhhitPR 2xTnWESE0fOsDLsxJTaq/6DBc+jj43alQ8adXDpfq2mjYSnm8dL0iSFHQsXgl2io3kPN yQXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dRAUm9s9; spf=pass (google.com: domain of linux-kernel+bounces-8069-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8069-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y63-20020a638a42000000b00565f0e91894si1257360pgd.394.2023.12.21.01.14.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:14:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8069-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dRAUm9s9; spf=pass (google.com: domain of linux-kernel+bounces-8069-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8069-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 2E3F9281C30 for ; Thu, 21 Dec 2023 09:14:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BDDC54FA9; Thu, 21 Dec 2023 09:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dRAUm9s9" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 476234E1AF; Thu, 21 Dec 2023 09:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703149430; x=1734685430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cxpPX3Wn0VREKtBeuHc/MZkj33xyM0sqH6UvdE/wBRo=; b=dRAUm9s9l+HdfkPkw6Ny/09VX8iYFOFRjA6Jm6Mhz/xAiryCSGgVvN4F 2hPWVA2xre0Qplv9A/PVpemPM8HDJXqrYeKVN0x5Vzs1t7vBisyP4h3u/ eGxl6NRJFXdVZmYEAEmY7flK8XlkaqbMnOFZdvdpOJt3MTjyZaMhSDxZL QEeUDCMgMK03gjmSIIDmELiIWb/mf6BcdFpFLa4RBDOSXtX7KGD1teRuX wPibCDDVgIEJwjXH/KZm6QexLFhpPxhZZWAQ7+y8n8vEPDhv6VLCWf/ET Dvcvbmf2CgNmgy0FjWVC6e3PO1E/AEgZB+2jfzBXEFpkp05v/J1/0qk6h Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="398729646" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="398729646" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="900028589" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="900028589" Received: from 984fee00a5ca.jf.intel.com (HELO embargo.jf.intel.com) ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:10 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v8 10/26] KVM: x86: Refine xsave-managed guest register/MSR reset handling Date: Thu, 21 Dec 2023 09:02:23 -0500 Message-Id: <20231221140239.4349-11-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231221140239.4349-1-weijiang.yang@intel.com> References: <20231221140239.4349-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Tweak the code a bit to facilitate resetting more xstate components in the future, e.g., adding CET's xstate-managed MSRs. No functional change intended. Signed-off-by: Yang Weijiang Reviewed-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0e7dc3398293..3671f4868d1b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12205,6 +12205,11 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) static_branch_dec(&kvm_has_noapic_vcpu); } +static inline bool is_xstate_reset_needed(void) +{ + return kvm_cpu_cap_has(X86_FEATURE_MPX); +} + void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) { struct kvm_cpuid_entry2 *cpuid_0x1; @@ -12262,7 +12267,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) kvm_async_pf_hash_reset(vcpu); vcpu->arch.apf.halted = false; - if (vcpu->arch.guest_fpu.fpstate && kvm_mpx_supported()) { + if (vcpu->arch.guest_fpu.fpstate && is_xstate_reset_needed()) { struct fpstate *fpstate = vcpu->arch.guest_fpu.fpstate; /* @@ -12272,8 +12277,12 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) if (init_event) kvm_put_guest_fpu(vcpu); - fpstate_clear_xstate_component(fpstate, XFEATURE_BNDREGS); - fpstate_clear_xstate_component(fpstate, XFEATURE_BNDCSR); + if (kvm_cpu_cap_has(X86_FEATURE_MPX)) { + fpstate_clear_xstate_component(fpstate, + XFEATURE_BNDREGS); + fpstate_clear_xstate_component(fpstate, + XFEATURE_BNDCSR); + } if (init_event) kvm_load_guest_fpu(vcpu); -- 2.39.3