Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp894925rdh; Fri, 24 Nov 2023 00:01:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE99Va16GrLO87JfAIeYpgZY9bGsli5bXsQquslck6Dhz0ydjoU0gN4QGCtXL35HDtopBqj X-Received: by 2002:a05:6a20:d704:b0:18b:8e3d:ed2 with SMTP id iz4-20020a056a20d70400b0018b8e3d0ed2mr2398005pzb.31.1700812880455; Fri, 24 Nov 2023 00:01:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700812880; cv=none; d=google.com; s=arc-20160816; b=dIkrsOq3bUY9LCvFPAxjG/U9mtRp2szVboJjOVd4Jz1SlCL6PFoVKUuiE6XiD++l2F wIeUaB2wMrmWe0B/e2WNok1s3SdxJuApqxGBJAaOQBIWg0KDGBFNUX6yYJ7fAQAUhv8o IouPK/tO2092r+qSl50Z7LH/T9aLX1+FHwxHzKbXEtzAREd9eELrRl/aOVOnrXwqdhTn P38NeMaxrjcGlA9TD6PipltdKhPeMhDgEzppgRjR8ua97lr5fx7l4Cm4Zvs1MiluRkbJ drKdYS/8hkHxAukAFSS+i7VCjQrWnf+4P8VxuUnY75YTX8cDV2dSZYpTpQZxmdRfJcqc t6dg== 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=ekN5WGc3PgcChCKxKpeptrI8wQYIaGhtvTKiVLrQsco=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=i1ONIq6YEyWYknv7Ajgakt12hHIgL53roAiktA/kDAWpDTv1WIIepBWayy046SbzGq McZFe0Nei8s1bI/aHAx4XEcSYXyzyBz06rjeAsZg2q/ffIyWTHkGWpsKKv7weblV5YIc cbq6ExlBHV5jnFD7A957rVgczQT/O9099etNb/odf1I7bpXjJORLPiWRgAOjW1DS924b 1Hqv4IhmvShpuJyhfYRsQWCBnhqNaR5E/OcCZ8rJC2jnvcvYO8/5mvrqVCBdk12cMTSo fha3os1k+PN7kR6vHjRmg13GuqF53J9kQMxsUsN/OPsJ6jjaG9Tg/02r4LZacN+ZX5kh EUzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k+KLlCkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fd31-20020a056a002e9f00b006be0f482c0fsi3121565pfb.63.2023.11.24.00.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:01:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k+KLlCkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3A3AD806D7E5; Fri, 24 Nov 2023 00:00:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345045AbjKXH7O (ORCPT + 99 others); Fri, 24 Nov 2023 02:59:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbjKXH6h (ORCPT ); Fri, 24 Nov 2023 02:58:37 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06CDC170B; Thu, 23 Nov 2023 23:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700812723; x=1732348723; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YrQMcIE+3fwJeUl1QCEA3wnA4x7/0zKhwJGfXTGGQIs=; b=k+KLlCkvlNLrW2KhO0POnBUiH1TB/JFFg2yq+eUoSZsgYnQIWTc/LL+t TfBwRDSE3RQVeOlkP/vcyCG8mjOdTuYiVVWEPnDC3P/8cK70SFLAIfDWi +RVjnFNI5KrgrkDVY9LBvMi9+A/XBy3gMMChe0dU8mp0UYX3U8YxpOiIT ClftX2zMRwDigJreosROd/iCRnUkMeyZe4Ui7CAYEyq/EviC+CVx1zviC 1AJnMP4+8vn95FnHjdl1XD0rgwc5+x0VCKvPBMkRsXSmrH1Op8VGathM6 um18ub8Chf8oLpqPurY0K1FcGTIckk+Be/smxu4Eh3rl0FUF6BSh8JQN3 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="458872303" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="458872303" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="833629810" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="833629810" Received: from unknown (HELO embargo.jf.intel.com) ([10.165.9.183]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:37 -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 v7 07/26] x86/fpu/xstate: Warn if kernel dynamic xfeatures detected in normal fpstate Date: Fri, 24 Nov 2023 00:53:11 -0500 Message-Id: <20231124055330.138870-8-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231124055330.138870-1-weijiang.yang@intel.com> References: <20231124055330.138870-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,LONGWORDS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 24 Nov 2023 00:00:28 -0800 (PST) Kernel dynamic xfeatures now are __ONLY__ enabled for guest fpstate, i.e., none 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 --- 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 c032acb56306..d45f3e570e69 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -186,6 +186,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.27.0