Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp990887rdb; Sun, 18 Feb 2024 23:56:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/DBTHLwFH5uQCuZ6uTNxbiFDv9YYJZC2iziTnQMu83EEev2+JkSSgiONzueG7SsQ+WEbkHso4dL5N2eBaD3ZQhtRX6tbiARC3QjiLJA== X-Google-Smtp-Source: AGHT+IHDPsSt+XQizUX4oFFeZPdoWTi+5cBgEXM4bKzUfb8TlH+870yOVuJ1WlnWlCcCcruNRd1u X-Received: by 2002:a17:90b:3a8d:b0:299:3c2e:64ca with SMTP id om13-20020a17090b3a8d00b002993c2e64camr4742068pjb.14.1708329398910; Sun, 18 Feb 2024 23:56:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708329398; cv=pass; d=google.com; s=arc-20160816; b=GbKWgzL0fQ0Vb90k1Bxj8GCPy5CAF9VH/dZO+jKk3uJLajGcQevLl2ZWFHvIkFuD22 J1BJ6wmOAUWqVK4CyDpfT4jKo/O6OrBXTfHUetMMCEnFGCVLtXcUL34r/nRtzdmZh6qj Vcy67hutRUKuQAYjrwRuYGEaNf0GfyENf4nttptiqrM4nbY8F++TYCGTJ7JysJVHdCQ5 a6BY2lfLCrABLgzwTweSGjv4pAuddcNz33j5+vTpEY/JI00xsmuO/Ek4J9mNaUs7UnCx Hhw42WXPUrK/PjNhQF/geoGfyDkFtVS9KZYiN/w1vgBO4faBJXO1S5DWkQwG9zxffbbV XBzQ== 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=mqN4MQIoa669ks5GmqxUjxvQlQ6un4JEg/rZKQk6Mc4=; fh=6bYtQoKQxNJSYrJA1a9vseXH6qHZpRYO7L/7krtpXA0=; b=QNq1ekKjLiNtS46Vj2QZMiOrqK+v6SL3Mp43GuUWPTJ7SBx6av4I7cx6lIBrAvf14L 5FawdiLO6C5HXTYbUSBlg9jW8asttIQm/+kda5gvsvZzKB8qR++G40Ir3iwwUISisPA3 Dvny7xQ8pr3Yt/yc0qes0UlY7u4O1aB3qQPYHjmQBnI9jSkwuqlcyjZc1lysay2066rB 75Rlfg8fgZtt+LLumlvtVeLkvR0Q6l8IoWo/Dx5r1Gsu0GPlH4BwATSUjeH/p1dG2+CP OsS3mII0Bp9CwUwhxtUW4FVjmmWpU8J4tJUuOM5VtAdd87ELdjj67UGjyx/1B9YpZtMK 7ksA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nYILxYVy; 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-70867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70867-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fz14-20020a17090b024e00b0029689cd7463si4082521pjb.186.2024.02.18.23.56.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:56:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nYILxYVy; 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-70867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70867-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A72C6B23332 for ; Mon, 19 Feb 2024 07:50:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DE102376C; Mon, 19 Feb 2024 07:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nYILxYVy" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 90F8A20DEA; Mon, 19 Feb 2024 07:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328867; cv=none; b=L2aM9XUvk8/A9MKk8GQN1h1xOhqm6LOf56rvRP6e0TQuVJYtd9L/LzNdgrWSVE0Nb+JkUXVq+zGPTKT6f9AoXS+i9eiHt3/JcxMXldLXOo27jhY1PegNfmKbEp2P7T+rEOv+lztGxguQ26j5LcheVD1lmygoiqLZjLYjgn5FLrc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328867; c=relaxed/simple; bh=Qcjmmmende+5tsFshQjIf5GC3RiO8JOjs03Rr6rpZfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PRYLwhTEaIwAun1bpxZ6yQCfOROFVhQIt9ux4iu/D8Z5yAVgLPBA3x5sqEwZ2p0WK2KaGcsiIlUrscHGdP71D2R/1g+lFcz7NIuduoPnpOl3XTxUNxQjSQgR7tBaeQZp2Ps4RqQEhnkcSO2ZAkxXVp28tUxYVMrNo45iKZMnvCw= 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=nYILxYVy; arc=none smtp.client-ip=198.175.65.16 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=1708328865; x=1739864865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qcjmmmende+5tsFshQjIf5GC3RiO8JOjs03Rr6rpZfY=; b=nYILxYVyhhZHgnRO8bR6J+F3oinEOlE3BuQKlWqWnvmVoldB+KxHEbvG KOS0sh5rYs3WUC5aGZsxC1kIZ1TCo8gLuRUeE4b4tg2RMHe+z/UHu717T TyBGa2F3nxMAeexfr1VtswWeW51POq+/jAfuk3pQVOKrVWsVuEYC1DgMv S1flUq4QfMlsJQbIFiFOo3bVnvMa7DrjwybwbUQAE/Sir6+IfhD9nZsPx bbcWEt7tNyswIeNMYaAx36U9BI6eT62FbMw1OV+WKN82fqXRC+MV3rRvE XSxqj3gdq6KPAprLBQYhGL+cw74/KP/8sBDWpbDgugjCfqkD/gtkP3yuV A==; X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="2535011" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="2535011" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:47:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10988"; a="826966063" X-IronPort-AV: E=Sophos;i="6.06,170,1705392000"; d="scan'208";a="826966063" Received: from jf.jf.intel.com (HELO jf.intel.com) ([10.165.9.183]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2024 23:47:43 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, x86@kernel.org, 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 v10 02/27] x86/fpu/xstate: Refine CET user xstate bit enabling Date: Sun, 18 Feb 2024 23:47:08 -0800 Message-ID: <20240219074733.122080-3-weijiang.yang@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219074733.122080-1-weijiang.yang@intel.com> References: <20240219074733.122080-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 Remove XFEATURE_CET_USER entry from dependency array as the entry doesn't reflect true dependency between CET features and the user xstate bit. Enable the bit in fpu_kernel_cfg.max_features when either SHSTK or IBT is available. Both user mode shadow stack and indirect branch tracking features depend on XFEATURE_CET_USER bit in XSS to automatically save/restore user mode xstate registers, i.e., IA32_U_CET and IA32_PL3_SSP whenever necessary. Note, the issue, i.e., CPUID only enumerates IBT but no SHSTK is resulted from CET KVM series which synthesizes guest CPUIDs based on userspace settings,in real world the case is rare. In other words, the existing dependency check is correct when only user mode SHSTK is available. Signed-off-by: Yang Weijiang Reviewed-by: Rick Edgecombe Tested-by: Rick Edgecombe --- arch/x86/kernel/fpu/xstate.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 07911532b108..f6b98693da59 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -73,7 +73,6 @@ static unsigned short xsave_cpuid_features[] __initdata = { [XFEATURE_PT_UNIMPLEMENTED_SO_FAR] = X86_FEATURE_INTEL_PT, [XFEATURE_PKRU] = X86_FEATURE_OSPKE, [XFEATURE_PASID] = X86_FEATURE_ENQCMD, - [XFEATURE_CET_USER] = X86_FEATURE_SHSTK, [XFEATURE_XTILE_CFG] = X86_FEATURE_AMX_TILE, [XFEATURE_XTILE_DATA] = X86_FEATURE_AMX_TILE, }; @@ -798,6 +797,14 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) fpu_kernel_cfg.max_features &= ~BIT_ULL(i); } + /* + * CET user mode xstate bit has been cleared by above sanity check. + * Now pick it up if either SHSTK or IBT is available. Either feature + * depends on the xstate bit to save/restore user mode states. + */ + if (boot_cpu_has(X86_FEATURE_SHSTK) || boot_cpu_has(X86_FEATURE_IBT)) + fpu_kernel_cfg.max_features |= BIT_ULL(XFEATURE_CET_USER); + if (!cpu_feature_enabled(X86_FEATURE_XFD)) fpu_kernel_cfg.max_features &= ~XFEATURE_MASK_USER_DYNAMIC; -- 2.43.0