Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp862851rdb; Tue, 23 Jan 2024 18:45:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdcOGcsxrWtUhZv0quOBJua2+et+i6LLNvBsL9uLfspuoGQxlcLDviNf4sp3wgSSX+Pnh2 X-Received: by 2002:ae9:f805:0:b0:783:80e6:1c00 with SMTP id x5-20020ae9f805000000b0078380e61c00mr7161290qkh.123.1706064338446; Tue, 23 Jan 2024 18:45:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706064338; cv=pass; d=google.com; s=arc-20160816; b=fkdrIKbiFO7ga02GfmA4DJcjBbYEECqQ8UboRqU7Em/tzs9YTqS/xYhyk749UTSo9c n9JmKFJujrKAtx+sUETNz+HfvLaLLoXPelC2y5Geaq2liT+pD1of2GoqPNg5id55uTQq F2Tmgs+nqBcIdkBHuNULFKMk2p3yFuFWN9WUHA1OFUeMVUf9Mr+wVTVgRzsOE1RM3SUP fhR33Dhg9YQBX68g36sykBbkik4uPiPGE6oi0GW4KVFky1Fldm5+nJ1VZvhh/xZqt9r5 rwVX4ogR4JWecD6NTnuRLa87/Ida8dakyYtyP84ZE1VAN9uEFg6UfpoYy2aKzbUths/o ygkw== 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=mDBqpA55jOCh2X/zPZmsYDiDgX9MEgCXf9cIQNLvjME=; fh=D+u40KSnYgjUYLGDRdXdD62xsMHg3nFDmpf3sEnyojA=; b=LZSPoknMn+Qo3MtGky5hfUASjqgo2q/8HU1+IlPIQCVIU6m44cam0B0Q8lzPhb4B5J cF/VAQVKNKpqQX3fRSCyUHxsf8B5tK4TylL16NKG8zxhkGRM7TgGuFhpnyNW5c9NesGE cKl7erv066WVq92D4A8juvfEuqP2haMM9bU/wn/jbAouUdk+WTqFhugHTDrupZg6MpzF 32+Nfdnq7L7zSrSifuZZo5kW0oRs95qOsFg4O7RsV8o7RzRSahiUuItEE2i5HELdJyYj 0oDWsugHuZTEL5unwgqjYonllk+TsuCn/bnIt0/GC0bFGt+8S32irAC4H4rolvEiAJoU SIwQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ve+5k0Cm; 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-36330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e5-20020a37ac05000000b007777245a946si8956633qkm.41.2024.01.23.18.45.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 18:45:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ve+5k0Cm; 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-36330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36330-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3838B1C2119B for ; Wed, 24 Jan 2024 02:45:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83F5B17591; Wed, 24 Jan 2024 02:42:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ve+5k0Cm" 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 A96EBF9E6; Wed, 24 Jan 2024 02:42:37 +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=1706064160; cv=none; b=U8KesVja0I9ENV5BX3LQe+/yHVDmG92RawTpmfCPpRaLj9ysQTCmaq2OazLAfGOzfZMdZPVa0aPxKd8nv37gIrfQ1Gczv4mlaTADIQR/FC+d+5DMlOWpg0gzyZRn/J8HKPbBigu3W67M7gQEwIQKLD1danLp5jeVX/7OKyT5SN0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064160; c=relaxed/simple; bh=HiRiDRBJgwGeewv2BjjbZoB+AZJ6Z19DaJ2CBVn/WYI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bBcT5MQDUpTUW6pkijBjR9st6deiHfZyPIv/rgNt9qmrP12Dsr4stb1f8ECey83W1QC971qsrLiF7uQvCkjhlmcrPsbovFd5LHxcuBsQ/mnlrElxDDDm9cBChRNI4g3HBU3vBvjlYaWkQb8//QwaWXbumqCWLNgDftf2usHZo2o= 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=Ve+5k0Cm; 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=1706064157; x=1737600157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HiRiDRBJgwGeewv2BjjbZoB+AZJ6Z19DaJ2CBVn/WYI=; b=Ve+5k0Cm2k/fU5ade3DeiTkvWOsTwWLj3qfneI6ZCV5eS8LG9OMM4Dgp ZkgGFti9OEarAzhMFsHm97xZWpVowaSUpgcpsidXrLYdz+1OQSZzCH0l0 3bFEKYkN40UJQwxzhZUBCQP/xCJVBUXIMpvcnhvh+t9ezmaQVTXSqWkJG 1ZPChaYXwCyDa0u13Y6L9Y8NhUdIwb9HvySF1PRVvflP9a7170QmMJzme 6t6tS0Cegju1VKbjSSa+zi0GA8rQud3EroRkGRhxhdv3/WvOG6o2Z4vP/ TK4iFPPxNCBmrrVqLhDNvxUaIex+Wc3Xtn+O2vVQSHD6zNO+OZ6qDV1d+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400586458" X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="400586458" 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:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="1825846" 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:33 -0800 From: Yang Weijiang 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 07/27] x86/fpu/xstate: Warn if kernel dynamic xfeatures detected in normal fpstate Date: Tue, 23 Jan 2024 18:41:40 -0800 Message-Id: <20240124024200.102792-8-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Kernel dynamic xfeatures now are __ONLY__ enabled for guest fpstate, i.e., never for normal kernel fpstate. The bits are added when guest FPU config is initialized. Guest fpstate is allocated with fpstate->is_guest set to %true. For normal fpstate, the bits should have been removed when initializes kernel FPU config settings, WARN_ONCE() if kernel detects normal fpstate xfeatures contains kernel dynamic xfeatures before executes xsaves. Signed-off-by: Yang Weijiang Reviewed-by: Rick Edgecombe Reviewed-by: Maxim Levitsky --- arch/x86/kernel/fpu/xstate.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 3518fb26d06b..83ebf1e1cbb4 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -185,6 +185,9 @@ static inline void os_xsave(struct fpstate *fpstate) WARN_ON_FPU(!alternatives_patched); xfd_validate_state(fpstate, mask, false); + WARN_ON_FPU(!fpstate->is_guest && + (mask & XFEATURE_MASK_KERNEL_DYNAMIC)); + XSTATE_XSAVE(&fpstate->regs.xsave, lmask, hmask, err); /* We should never fault when copying to a kernel buffer: */ -- 2.39.3