Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10546135rwp; Fri, 21 Jul 2023 00:30:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlHzsq+2BZvWG+UQ6LPZibwhhM6d+eOYGgI29lH9v80o4KqrINyACpwuwasvnMEGEuHcv++P X-Received: by 2002:a17:907:75f7:b0:95e:d3f5:3d47 with SMTP id jz23-20020a17090775f700b0095ed3f53d47mr973748ejc.48.1689924608860; Fri, 21 Jul 2023 00:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689924608; cv=none; d=google.com; s=arc-20160816; b=fgay42AIN2eviI55a7z+AbrDfRdL4LxtbmkLJV+cERgIHDpUdVAGbHPC4rPrvMphkE gDGreM9StWjRQIs1/6KvRy+7so7RTOgz0dff16SKDOpvYh3iFOEfcgWYLCi8PUPE+UMu 5K6xq7v9TBMwtB0wJDECNys1nmcGwrhkoXRj1KL+R4pgX8ogcmJJOvnR6hx5Y04bG3YD /nWdhK140XMG9KwVEZeOF97F3I9JGhIeL83SIaj+BnX8uWJHff9e6ylPlR5Og/TwBFdO dbwpgDJL2uLO/LEgn6A4cGyFI4dM8OkZINqXel1ZhliqGkaxdx4OmmpYlDnkVFvBSog3 ohIA== 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=0uE9aXf0NJAOKQRkbmWpe4lytE5Grmah0ZzRdmsCOQ8=; fh=Opje+PjCQx5n1tZXLBqSYGCQ4Th9+H4dl5HcyP+qSnE=; b=c3uGgbr3xNMrOdNaPZKsjyQd5FhKSD3J7AVn3suJR/NR1zRkOTgHrC9TJPDMZbJwXz yv/Z/Weo5lEPztF3hKFdZDfKUiaakkWi3jpZ8wq5WFL5mzENTwIxzEdKhZhMYkGLfVAu Bamw6TBcxkXyVzImUsts4Igb3u+qg+AtYQP4CTDzfHWzUb80e4Y2hwfMDfYuHLzwbwZg tb5hrzv5qHRLARRR1uWbZX4gQ/twvwuuGa3PsUBWa8XTEOOuzJupPw5TXdZroFfUmV/M y6sflFzdzZsWTdl/2QXru0NWoXx1SHur+/Ut5BJJTLb3NYqVHhPa9PVzOiV111qOcQ2T FlCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D9GPpHcS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020aa7c3d2000000b0051dd1d7fbeasi1898644edr.683.2023.07.21.00.29.43; Fri, 21 Jul 2023 00:30:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D9GPpHcS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbjGUGKK (ORCPT + 99 others); Fri, 21 Jul 2023 02:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230178AbjGUGJD (ORCPT ); Fri, 21 Jul 2023 02:09:03 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6247E19A6; Thu, 20 Jul 2023 23:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689919741; x=1721455741; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z1qCzT0ZMxvYsf0S3vJ/qE/swqLkzSDdT/v3wrwsFro=; b=D9GPpHcSK/ixBg5X4yqRAN6Otgh1mlOd5XXnKJC4rE8dtt05vyH27TaU 0JOAPnCURdKjyEdPUJnlKS/5OOKAvG0whkc/2tsPFFFKjQtqqQU/sWCe1 iVGf9Vl3Z/pO9V6N9k/ZKvJDgtIheuytvke+pO+w2va66HNgGS8muZ7+x G/btLIo7C8VS/kG2L6tPDQhKappD3pP6qFh2Z2pjP1YCJUXJGVVTKVFoA HTO8Sy0FOMwaosvRE4ydhkGCVfahS7vr2IjrssIbU1HMXfWWS7f4C5Prf AjJgroiCTmJQaNgChZ8zetbo/tFC2nr2Ykg/b94tIvNdf0X4ByiK27Bul g==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="370547628" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="370547628" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 23:08:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="848721990" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="848721990" Received: from embargo.jf.intel.com ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 23:08:41 -0700 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, john.allen@amd.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: rick.p.edgecombe@intel.com, chao.gao@intel.com, binbin.wu@linux.intel.com, weijiang.yang@intel.com Subject: [PATCH v4 18/20] KVM:x86: Enable guest CET supervisor xstate bit support Date: Thu, 20 Jul 2023 23:03:50 -0400 Message-Id: <20230721030352.72414-19-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230721030352.72414-1-weijiang.yang@intel.com> References: <20230721030352.72414-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add S_CET bit in kvm_caps.supported_xss so that guest can enumerate the feature in CPUID(0xd,1).ECX. Guest S_CET xstate bit is specially handled, i.e., it can be exposed without related enabling on host side, because KVM manually saves/reloads guest supervisor SHSTK SSPs and current XSS swap logic for host/guest aslo supports doing so, thus it's safe to enable the bit without host support. Signed-off-by: Yang Weijiang --- arch/x86/kvm/x86.c | 4 +++- arch/x86/kvm/x86.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 665593d75251..f68e36ef34b9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -228,7 +228,8 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE) -#define KVM_SUPPORTED_XSS (XFEATURE_MASK_CET_USER) +#define KVM_SUPPORTED_XSS (XFEATURE_MASK_CET_USER | \ + XFEATURE_MASK_CET_KERNEL) u64 __read_mostly host_efer; EXPORT_SYMBOL_GPL(host_efer); @@ -9638,6 +9639,7 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) if (boot_cpu_has(X86_FEATURE_XSAVES)) { rdmsrl(MSR_IA32_XSS, host_xss); kvm_caps.supported_xss = host_xss & KVM_SUPPORTED_XSS; + kvm_caps.supported_xss |= XFEATURE_MASK_CET_KERNEL; } kvm_init_pmu_capability(ops->pmu_ops); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 9c88ddfb3e97..66733e01b0ce 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -362,7 +362,7 @@ static inline bool kvm_mpx_supported(void) == (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR); } -#define CET_XSTATE_MASK (XFEATURE_MASK_CET_USER) +#define CET_XSTATE_MASK (XFEATURE_MASK_CET_USER | XFEATURE_MASK_CET_KERNEL) /* * Shadow Stack and Indirect Branch Tracking feature enabling depends on * whether host side CET user xstate bit is supported or not. -- 2.27.0