Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp893763rdh; Thu, 23 Nov 2023 23:59:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGe0DnU6pxtbS6cvQX2apjT2n5J6stYedpJaORqQi4Kx36/Av4S+4kMjYRZCyfGn5E43u7M X-Received: by 2002:a9d:6acd:0:b0:6d6:4cf3:d908 with SMTP id m13-20020a9d6acd000000b006d64cf3d908mr2102196otq.33.1700812788015; Thu, 23 Nov 2023 23:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700812787; cv=none; d=google.com; s=arc-20160816; b=tz21YtCtVn/jqYKXvk/YruoU1zdq0JIFmSi7ag8TWGCnPOnUG2YJOpY602IqjV71tI O/tcFyJBb05zgfnx88cs53heW++93Uvy4QhkIfllLagv894arVI1XseTRT2KCsMFLzx7 7shjGJs7pYQd2PRI/K5gMMuhlV0yXM4fESpt/94bTtINAkZL41X8n5ju5Okp2dMT/tnK wXGjn4m6+tL44lkHJEKqKfZpv7k6acZPgJ+18oEYwzkGQKoNJhNvSRdtpcIVOUKjJX9k NkXkXb1LNrX142qjSCilyOijtSShxduILxEc96ZbS7n3rqf0YHsQBYyc9IUhDsAzSQRr h0wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8zr9erBg9e1do8EQZqJOyrVFsptfkPA75bbip6SVJ5A=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=PdOWLxIIhDZDeYSg1rsNc+uhgaztciGhYijzBjZrLwgN/Cw0Exr8nrnx8vQKrJ3TI8 Gjcn4fgtvRmFgZybcMTQkBrzhAgSLAjuRDB3GoGiO+WG48fG2f65/+n8VxEANXAnLwsv w3Ne2t+bDXWoPwyTt9vZFqxL5HGD2dFl5yFHQ9OKRKlglLlKvi7yiuSIzylAZovuHGgi sYVQljj7cteXylzJj/CYswq4SigysQ7oSO3HrSD5dh23u+ULkeKclV2LCEvQfqsg6QSa 8NrBeq4xZiev1/W0Pt6+ccozkFrs5NP7WYC2EWWF1dfW9YFfofG+4Ww9t/XRiIpX8NhC ZfxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=idHEpzN5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id c4-20020a631c44000000b005789f552066si3165429pgm.335.2023.11.23.23.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 23:59:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=idHEpzN5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 44BD983303E4; Thu, 23 Nov 2023 23:59:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345068AbjKXH7R (ORCPT + 99 others); Fri, 24 Nov 2023 02:59:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235132AbjKXH6i (ORCPT ); Fri, 24 Nov 2023 02:58:38 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF1BE1710; Thu, 23 Nov 2023 23:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700812724; x=1732348724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hoo4Iwqu83bRaL99m4ilvZ+WdOV6DreLDSnH/3fxOIs=; b=idHEpzN51+O7s0Wil+apR1RyXame7o6nVIkOi8n3PvFSY8bnZVHmFZe2 bMjPK8RQlLYpGBi8aB+WIj7kygbay63JKGL3zD/fpZMzQV+KwRi0UVN4m CWTwxLRxgVuitfj0TAbVOzlSmMehReDz0A41mkjQ26sxFsOWWqpAVqnmt 8EbBkBrXs86lhSJcIPXYF+emNcrA+wnVUUR1eU1X9aQy5KdkQpgiq5Ws+ FuspsKgO6gob6k2a0tLkC1zxxkcGBSLJz5p7Areytzr5nDJ7lFPmWZrpR zGEEuZ0Ml80RvBsyjUt8j1o4KpgHpT42k9A4wkPQpW4PCiqj8e9jZFcyJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="458872319" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="458872319" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="833629820" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="833629820" Received: from unknown (HELO embargo.jf.intel.com) ([10.165.9.183]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:38 -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 v7 10/26] KVM: x86: Refine xsave-managed guest register/MSR reset handling Date: Fri, 24 Nov 2023 00:53:14 -0500 Message-Id: <20231124055330.138870-11-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231124055330.138870-1-weijiang.yang@intel.com> References: <20231124055330.138870-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 23 Nov 2023 23:59:45 -0800 (PST) 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 --- 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 b9c2c0cd4cf5..16b4f2dd138a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12132,6 +12132,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; @@ -12189,7 +12194,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; /* @@ -12199,8 +12204,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.27.0