Message ID | 20240124024200.102792-11-weijiang.yang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-36331-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp739110dyi; Tue, 23 Jan 2024 18:47:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkXcejdUcQFT7WYqZX3c9Jt5TTj8ldPmYUn/yqPD5574Siv1OC7Kmze7vWGDPx9xU/1a4X X-Received: by 2002:a05:651c:386:b0:2cc:a61b:46df with SMTP id e6-20020a05651c038600b002cca61b46dfmr268603ljp.55.1706064434823; Tue, 23 Jan 2024 18:47:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706064434; cv=pass; d=google.com; s=arc-20160816; b=cJARsbevrdaK+ONeSpbQlsrOowknHVWsRSAHvokhu+zLdP+vP1F62yAxc8z94KlvBu pYnxarbLlGTCAcmYXPDB/oSxlhws5jHpGGT7g8f5i29/QbxJOCvUk7WELi71E6GXwfFv iud15Qmph2eBM0CsRnFS68bmbI578cEFicsdAAyfwnP/E5+IUaQ5utG0q8K7TIWNutuD UfwsX/vNvzzgRSNJMCdX4WqVBUmiDdEr7HrIdFWcE0aAnyJaCYFRtfCTX9CQQwOhhkZA SwRBPUH+ps7GWiCRquVj+zRVg7Dmla1ieCJrohuoA/Bk/wwU3gfcpkDW38Hw7i9CX4Bd f68w== ARC-Message-Signature: i=2; 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=D+u40KSnYgjUYLGDRdXdD62xsMHg3nFDmpf3sEnyojA=; b=ETHRwJZ7ezEXy2ZuWfVrCgoj3ryIWXNofdTFUhqVWB4voyyjAM3ulvmemJrsmpWJXL 8nourQM7f078egNhxqKrc8ZV3bGbFixBcAb/r8IF3s0J2luFtEC054ZCrJYrFCu3O7+o PTMUkHlnJO+7+A0sCI1RlLwUlZVr3ig8+XD1dbRqorhF25+qRxfvbGX8owwF2AwSACFB GB3JgaXm9xoncL+2PEC2M7ULt3TOjJ6+jcgHNCcfoIII1jI61SsrLFBBhudL2Nyej+4E 6k7Ah0v7Bj21Q3PYgwD/1ltcGR5xX+ep9dr3t7FnC+E8I2wuaE6L6s7/QxCCjQDkXSmj BrHQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="jzIb/tY7"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36331-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36331-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i34-20020a0564020f2200b0055bff9ade42si3919845eda.170.2024.01.23.18.47.14 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 18:47:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36331-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="jzIb/tY7"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36331-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36331-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6CE8C1F218BE for <ouuuleilei@gmail.com>; Wed, 24 Jan 2024 02:47:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D3C75C98; Wed, 24 Jan 2024 02:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jzIb/tY7" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 CAC46171BC; Wed, 24 Jan 2024 02:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064161; cv=none; b=AhAZ8YpcKlUrH8BU8kq4v7E01JpX10M8otlCPOTYD1UsiKH6ixnXFgWJ4riH9UgOHtlqIKe32Ffxn1Ed5jBJ0alY0m7NvLkhNSDeQTG34ybRwyrdC6iY2VGTr6BicxtKMcIQU+ed5K/HROCJ0NiXkFEl5wVPDY2QyIgge4qC/hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064161; c=relaxed/simple; bh=cxpPX3Wn0VREKtBeuHc/MZkj33xyM0sqH6UvdE/wBRo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T/bpQ2Oq51itYJDTgjul5LlKMC08SDBTmFcf9CWE1eJ02yX6DerK18H1yKipuwvIWoeFHhkudW2cmJ1nIvOflsvO6Xb0DpeOm3E6RspZZ3pyo6OapaERN2IuXJBPaKN73LOrCdrlhjbHfqX4nrKxBIAaFy1EWWYeIKkkJKMUjus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jzIb/tY7; arc=none smtp.client-ip=192.55.52.120 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=1706064159; x=1737600159; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cxpPX3Wn0VREKtBeuHc/MZkj33xyM0sqH6UvdE/wBRo=; b=jzIb/tY7JY9v72xklDRzq6stw171yM3YJ5nXSAYV9G0enQNgUIvFBKtP AyOtGxxbqekdBKOtVoxU4auKKNWpi/616w404wtiwnkaFanvy9I17BqGN yBgHnRRUY4dwGDGcTuBIr55A2x8jRzNUZ01NtoRfN2206o9x4rhDJdtv5 fKfhjK5F+ir3wm/OgoGzwK1fdTyR9N6tQVwaTLinq2aPCc4+Aqvs6x00e +uYeEhYiBPBVjWNd2H1ZNHCP66T8BBWF13ZEycWjJDHiU5mH0ScRepCWr KCSpmqplOj6PzcDzFXcI5KJYbTm1FXYgsPLemNj8dilsPiayaNFTkRX8/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400586478" X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="400586478" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="1825855" Received: from 984fee00a5ca.jf.intel.com ([10.165.9.183]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:35 -0800 From: Yang Weijiang <weijiang.yang@intel.com> To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, yuan.yao@linux.intel.com 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 v9 10/27] KVM: x86: Refine xsave-managed guest register/MSR reset handling Date: Tue, 23 Jan 2024 18:41:43 -0800 Message-Id: <20240124024200.102792-11-weijiang.yang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240124024200.102792-1-weijiang.yang@intel.com> References: <20240124024200.102792-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788938220842434757 X-GMAIL-MSGID: 1788938220842434757 |
Series |
Enable CET Virtualization
|
|
Commit Message
Yang, Weijiang
Jan. 24, 2024, 2:41 a.m. UTC
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 <weijiang.yang@intel.com> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> --- arch/x86/kvm/x86.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
Comments
On Tue, Jan 23, 2024 at 06:41:43PM -0800, Yang Weijiang wrote: >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 <weijiang.yang@intel.com> >Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> >--- > 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); >+ } Checking whether KVM supports MPX is indirect and adds complexity. how about something like: #define XSTATE_NEED_RESET_MASK (XFEATURE_MASK_BNDREGS | \ XFEATURE_MASK_BNDCSR) u64 reset_mask; ... reset_mask = (kvm_caps.supported_xcr0 | kvm_caps.supported_xss) & XSTATE_NEED_RESET_MASK; if (vcpu->arch.guest_fpu.fpstate && reset_mask) { ... for_each_set_bit(i, &reset_mask, XFEATURE_MAX) fpstate_clear_xstate_component(fpstate, i); ... } then in patch 24, you can simply add CET_U/S into XSTATE_NEED_RESET_MASK.
On 1/25/2024 6:17 PM, Chao Gao wrote: > On Tue, Jan 23, 2024 at 06:41:43PM -0800, Yang Weijiang wrote: >> 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 <weijiang.yang@intel.com> >> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> >> --- >> 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); >> + } > Checking whether KVM supports MPX is indirect and adds complexity. > > how about something like: > > #define XSTATE_NEED_RESET_MASK (XFEATURE_MASK_BNDREGS | \ > XFEATURE_MASK_BNDCSR) > > u64 reset_mask; > ... > > reset_mask = (kvm_caps.supported_xcr0 | kvm_caps.supported_xss) & > XSTATE_NEED_RESET_MASK; > if (vcpu->arch.guest_fpu.fpstate && reset_mask) { > ... > for_each_set_bit(i, &reset_mask, XFEATURE_MAX) > fpstate_clear_xstate_component(fpstate, i); > ... > } > > then in patch 24, you can simply add CET_U/S into XSTATE_NEED_RESET_MASK. Yes, the proposal looks good to me, will apply it in next version, thanks!
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);