Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp290296rdb; Mon, 15 Jan 2024 23:26:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbN08kVBJZsRoq8SnJPDxRQc6/5Y8VdMhky7mUiQgmAyTaTLAgWF31yhmA5KvTqWXfQtFZ X-Received: by 2002:a54:4390:0:b0:3bd:61ee:db9c with SMTP id u16-20020a544390000000b003bd61eedb9cmr6174206oiv.115.1705389970555; Mon, 15 Jan 2024 23:26:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705389970; cv=none; d=google.com; s=arc-20160816; b=ukSq3JCoONgpstdX2zdTuviL9XrEOsAEz9YuSWAMKwAex8+GIYNljaYt7nvv9srP1R 5kcj+4T40SUISJ1DsKDq3Eco7aFUOsDLXWMvfZJ86M08PbMN1FGiPhMfBUh4bUNYOncP cDFiyEwkU4HEFmJjDRAoh7hDtwbEiG04hEEXg8/KR6dgctbvx/wqLoQJwhs+NwKDPPJe YNcOmdMxJxzLxuu9EKgEVSB8metPzQmUiJu5FIwoqqLIPFZObU62ePO5cWIAHuSkHeul G/VUusQjkEk8j8xITHPSHOChPYG1sXsXpBHK1JM/KIU4WWuiwrN01Kp9hI2vO+gqNPO2 sqOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=us8HQzFqTWjbAJhCa2H9K05g6sgNudZVHMzzeeyluSc=; fh=WxyeAmcgt4ZpeSEccAwkTziCZy9zE1PEl9pTwDG9q+U=; b=I/zXGCKfL6YmtV8kW2aQ5pCooSyAEG2hAmpCGVnQLIRvVso++e1510W/POv/arVT7L oF0bfMBq+biQS4GaDslmNb70wHgFlz0/g8YI86tG8VqAn2LDymu22nAga/qFVKbWe2Sh k5z3X5kQKH71AtsP5ABKuMmCiS+AhrRWDw+yzuuwf+NX12wlDqELosDsFB81Gb2syC+O HbD7CTUhIyzDTJsd95loPLT05usGGwVPa9/1kKfIjhK45kSrIkn6lHhkz4QLcxNZnA3L irY12xCzGU0erY7UzembFjmWJO5/g1ChTZ9kpopNrDdBB5OwLK2hQpSl6j3+TCJOYpuQ hUmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=aNfwW6vk; spf=pass (google.com: domain of linux-kernel+bounces-27073-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27073-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l70-20020a638849000000b005cee028d0b7si9880201pgd.358.2024.01.15.23.26.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 23:26:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27073-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=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=aNfwW6vk; spf=pass (google.com: domain of linux-kernel+bounces-27073-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27073-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (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 181C72835B0 for ; Tue, 16 Jan 2024 07:26:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8869D1119E; Tue, 16 Jan 2024 07:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aNfwW6vk" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 2FD9D11184; Tue, 16 Jan 2024 07:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705389960; x=1736925960; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=0VYlJARRAU2puU6RAyuMiQBsYdqfLxIjxrmkwXJqv10=; b=aNfwW6vkQiBAfchG7HnPN7RJTN3zhABoHp2sSrPdh/YKsJ86JzA8MgKX 53o903s9HDbO5DRcssZLnGEFEpYunqPVfBwOQLOaytiBIe9mY3YDsW5NP kMhmeAlbQgmiJFmEHZkqxkqwkQUiXzl18xs6NWtrXBh13btadeMviMQTV mS/SbxGMpsyFAyNus4VbI0EZ/zCUmUMcebv2BmVJjnLpT4GY6hDi2bGF7 vVddCkUmmVvQ77Sqi1S8g9prQRRAjN3dmj76Gt0mbGYtdEWUJMoLpJyvZ VdmTnMQ4mkAL5TOd/0ivdeqKWVfyPQslULMZgHHehZ2yQpnshSi3hj890 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="7156741" X-IronPort-AV: E=Sophos;i="6.04,198,1695711600"; d="scan'208";a="7156741" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2024 23:25:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="1030892839" X-IronPort-AV: E=Sophos;i="6.04,198,1695711600"; d="scan'208";a="1030892839" Received: from yy-desk-7060.sh.intel.com (HELO localhost) ([10.239.159.76]) by fmsmga006.fm.intel.com with ESMTP; 15 Jan 2024 23:25:56 -0800 Date: Tue, 16 Jan 2024 15:25:55 +0800 From: Yuan Yao To: Yang Weijiang Cc: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com Subject: Re: [PATCH v8 24/26] KVM: x86: Enable CET virtualization for VMX and advertise to userspace Message-ID: <20240116072555.jnj74yairx7add6i@yy-desk-7060> References: <20231221140239.4349-1-weijiang.yang@intel.com> <20231221140239.4349-25-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231221140239.4349-25-weijiang.yang@intel.com> User-Agent: NeoMutt/20171215 On Thu, Dec 21, 2023 at 09:02:37AM -0500, Yang Weijiang wrote: > Expose CET features to guest if KVM/host can support them, clear CPUID > feature bits if KVM/host cannot support. > > Set CPUID feature bits so that CET features are available in guest CPUID. > Add CR4.CET bit support in order to allow guest set CET master control > bit. > > Disable KVM CET feature if unrestricted_guest is unsupported/disabled as > KVM does not support emulating CET. > > The CET load-bits in VM_ENTRY/VM_EXIT control fields should be set to make > guest CET xstates isolated from host's. > > On platforms with VMX_BASIC[bit56] == 0, inject #CP at VMX entry with error > code will fail, and if VMX_BASIC[bit56] == 1, #CP injection with or without > error code is allowed. Disable CET feature bits if the MSR bit is cleared > so that nested VMM can inject #CP if and only if VMX_BASIC[bit56] == 1. > > Don't expose CET feature if either of {U,S}_CET xstate bits is cleared > in host XSS or if XSAVES isn't supported. > > CET MSR contents after reset, power-up and INIT are set to 0s, clears the > guest fpstate fields so that the guest MSRs are reset to 0s after the events. > > Signed-off-by: Yang Weijiang > --- > arch/x86/include/asm/kvm_host.h | 2 +- > arch/x86/include/asm/msr-index.h | 1 + > arch/x86/kvm/cpuid.c | 19 +++++++++++++++++-- > arch/x86/kvm/vmx/capabilities.h | 6 ++++++ > arch/x86/kvm/vmx/vmx.c | 29 ++++++++++++++++++++++++++++- > arch/x86/kvm/vmx/vmx.h | 6 ++++-- > arch/x86/kvm/x86.c | 31 +++++++++++++++++++++++++++++-- > arch/x86/kvm/x86.h | 3 +++ > 8 files changed, 89 insertions(+), 8 deletions(-) .. > -#define KVM_SUPPORTED_XSS 0 > +#define KVM_SUPPORTED_XSS (XFEATURE_MASK_CET_USER | \ > + XFEATURE_MASK_CET_KERNEL) > > u64 __read_mostly host_efer; > EXPORT_SYMBOL_GPL(host_efer); > @@ -9921,6 +9922,20 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) > if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES)) > kvm_caps.supported_xss = 0; > > + if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) && > + !kvm_cpu_cap_has(X86_FEATURE_IBT)) > + kvm_caps.supported_xss &= ~(XFEATURE_CET_USER | > + XFEATURE_CET_KERNEL); Looks should be XFEATURE_MASK_xxx. > + > + if ((kvm_caps.supported_xss & (XFEATURE_MASK_CET_USER | > + XFEATURE_MASK_CET_KERNEL)) != > + (XFEATURE_MASK_CET_USER | XFEATURE_MASK_CET_KERNEL)) { > + kvm_cpu_cap_clear(X86_FEATURE_SHSTK); > + kvm_cpu_cap_clear(X86_FEATURE_IBT); > + kvm_caps.supported_xss &= ~(XFEATURE_CET_USER | > + XFEATURE_CET_KERNEL); Ditto. > + } > + > #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f) > cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_); > #undef __kvm_cpu_cap_has > @@ -12392,7 +12407,9 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) > > static inline bool is_xstate_reset_needed(void) > { > - return kvm_cpu_cap_has(X86_FEATURE_MPX); > + return kvm_cpu_cap_has(X86_FEATURE_MPX) || > + kvm_cpu_cap_has(X86_FEATURE_SHSTK) || > + kvm_cpu_cap_has(X86_FEATURE_IBT); > } > > void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > @@ -12469,6 +12486,16 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > XFEATURE_BNDCSR); > } > > + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) { > + fpstate_clear_xstate_component(fpstate, > + XFEATURE_CET_USER); > + fpstate_clear_xstate_component(fpstate, > + XFEATURE_CET_KERNEL); > + } else if (kvm_cpu_cap_has(X86_FEATURE_IBT)) { > + fpstate_clear_xstate_component(fpstate, > + XFEATURE_CET_USER); > + } > + > if (init_event) > kvm_load_guest_fpu(vcpu); > } > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 656107e64c93..cc585051d24b 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -533,6 +533,9 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type); > __reserved_bits |= X86_CR4_PCIDE; \ > if (!__cpu_has(__c, X86_FEATURE_LAM)) \ > __reserved_bits |= X86_CR4_LAM_SUP; \ > + if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \ > + !__cpu_has(__c, X86_FEATURE_IBT)) \ > + __reserved_bits |= X86_CR4_CET; \ > __reserved_bits; \ > }) > > -- > 2.39.3 > >