Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp18129rdb; Thu, 21 Dec 2023 01:13:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVf71iynpwZFRhM0Z09pVB3tqW6ZFGtgEhOJW6ifOnbHX3VVk8EA6O9ger3BhQq3XDF3NE X-Received: by 2002:a17:906:140f:b0:a23:6d5a:7dcb with SMTP id p15-20020a170906140f00b00a236d5a7dcbmr2759113ejc.75.1703149986718; Thu, 21 Dec 2023 01:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703149986; cv=none; d=google.com; s=arc-20160816; b=sc5PVhAIxiL0aphDIy1FKh1j1ISp7SSZwSehxVTrY5XcuQDzgcP0TVrcYu4Z18yWT4 TNqOY4Tc69jRP6qmAIL7vsCO4ij6NyJmmwILBNRnWZ+pFHh8qYXiivLQC11nGKIo6Cau dcu3LF+YSQzuAlhaTnOCRKb3QZ4nRy6Rje9c8U5P0qqRaLAcpL2zZHP+ED0dsDRI6p73 yqmSDRx4aTABP7xP+RaCrDwTwIeKICJxzICnPRKiffYb5Wi0QJUi2zSdhz8aIhaE7K1N eBjm2/ceoPS7iCj4sSmMlB4zEDdF3uwYT3fLkzwaUXTH10JBEGCxlAhsQuBhb2Qd2u7D im0w== ARC-Message-Signature: i=1; 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=Vywl8Unj2mhX4UP2DwGw99j6x9g/03rqeqRsNYcumUI=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=KxPpbpk8nBHQRJflvGXtJoFckTPd142PqvF7nevvLfy9YoXnfS9b1JC0rUeSHdV2sp /FcXOZHKRWR3n/ruAyoOxh25iSGHEX3hUVT/oZgRUiuONrAUgrxS4ajz0e7lB9EC+fSp +0Y6GKVDUv8OfqAvlay+VRrCmtOWE0/2YphhscaVjVgKs/I65E9lM+pnZLt39LUfj3Gg /bZ+vax3jzsLP+JY77Xyxq8PG/m/s2xEKU0BPGjCsBnErFfIgvjdB0WJhObcl8LkO9Qd bo8V6LacSO3VuWtU4Y01cAjSJRyQrMTGbK/LYlvkNQLONKHDgzbI8eswPoSzrONQtUzK tO9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dpanSWS6; spf=pass (google.com: domain of linux-kernel+bounces-8064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8064-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p24-20020a170906b21800b00a235ebeef93si671683ejz.797.2023.12.21.01.13.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:13:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8064-linux.lists.archive=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=dpanSWS6; spf=pass (google.com: domain of linux-kernel+bounces-8064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8064-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 74F2B1F24C97 for ; Thu, 21 Dec 2023 09:13:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2B7652F8F; Thu, 21 Dec 2023 09:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dpanSWS6" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (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 BF6134D109; Thu, 21 Dec 2023 09:03:48 +0000 (UTC) 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=1703149428; x=1734685428; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rs0sLmUkvny/jzDhJajlhzctZKCGIsR8BlL5L8UWwmc=; b=dpanSWS6x8TEKO6PNf7ceqBT1ofOnd6cnKOrM7XA8QrrYkvpdFwaIUI6 QLxnRtyS3HEE5yPa3bcHLlLXb3fgDrkNpSuX2kE2ikDNMvEx6JDc6eXUt BnH000FYd4n9d/QVGuXBfvqCIKldc8xJpKnyPxgXVAhsI/5PKcQ8Mhshd A/oZlDhXa44XUX3NnO9GKKG8lVbgHf+BOC615cz1HvhO6KLPriWIRsTJu LIGdrpKmtz3XAEUr2/r6Tya5tvcyxnH67BORMzXpZ9v4PmdyfvIFN1705 zWfH1peBHias62cPKDSG8T2OVdVTE27LwK5Z66MIerYjcrhZZHnzTy5cD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="398729630" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="398729630" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="900028583" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="900028583" Received: from 984fee00a5ca.jf.intel.com (HELO embargo.jf.intel.com) ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:10 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, 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 v8 07/26] x86/fpu/xstate: Warn if kernel dynamic xfeatures detected in normal fpstate Date: Thu, 21 Dec 2023 09:02:20 -0500 Message-Id: <20231221140239.4349-8-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231221140239.4349-1-weijiang.yang@intel.com> References: <20231221140239.4349-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 --- 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