Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp893728rdh; Thu, 23 Nov 2023 23:59:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoH4XPwZTUpBeIt+MW/9TAMV8eJfmVo9F+TPIO00Vo+RaH/D2txuQjchkIZNaAxfpW6MGJ X-Received: by 2002:a05:6a20:d396:b0:18b:d31f:7d25 with SMTP id iq22-20020a056a20d39600b0018bd31f7d25mr2483761pzb.38.1700812785037; Thu, 23 Nov 2023 23:59:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700812785; cv=none; d=google.com; s=arc-20160816; b=clr5dLlc3shN0dcW7UcJCaXrO96m2QmrToy2QJk/j7knfHZrxT8ka5Ws7e0ZQ+mWcs yaTEmsbf1R6VO252t1FIRWO9JuKOX69KiIn+qx1agej6Fr8dNvn4jlhx1J7bnmCh4miy Dj0vzHCXAvnfEVDJBc3LoMXgW2q3PXs+Mzqzj/SW0rOf/G/HR9REuUcuCS434Nu2jbX7 q2Po6RqSpvE4QIYVNhkIfavcgg1Gi0qP1u5UXeVCucZuyoz96DENu9c3nhoBRVnnsE1d s7a9oOhjOmSFlX4mG/Ccs6Ooctwv0TCZtTLz16I8vWV3vtGOQLCOrtDoMgJIA3vKPumv SuvA== 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=VDutRh151I2Rj9GWXl40WG5oKOVTJ1+4FA+twdQJ4q4=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=AgZK1YQ+AXwNU7CyQgvQ34lJXue5r8hc7LRudojFK7BUb7+jABAGcSlhMQQLpB1xV+ 0RtajF2ydyIFx+ypKaqbB8P2EVs5rL19q5OAtVMVeplgNtRKoFZk7GCUhnFjSFeYuDML bAHi7QirS5KbEMe/cbb0eXNzak64D2OtlGc82aTn6wAGSNIndIifcA/Df9nDYj/d2n6J GLpGyguPUjzm6qs+f2iXMSOAdCUjK36U9WZH4MeY1harYyE8DI+h9zi37Pk4ZnmMvQOi Ox6rcHbx96++G2Yp0r8ix2pU5biwILyJSiEk6Jx7b4QZ/MQgIF5oaJg5WGzZpoBagKR6 Cavg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mm0QiHiz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d19-20020a63d653000000b00573f885c4easi2938471pgj.753.2023.11.23.23.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 23:59:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mm0QiHiz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 3524F81E020F; Thu, 23 Nov 2023 23:59:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345146AbjKXH72 (ORCPT + 99 others); Fri, 24 Nov 2023 02:59:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234713AbjKXH6g (ORCPT ); Fri, 24 Nov 2023 02:58:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 426061719; Thu, 23 Nov 2023 23:58:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700812721; x=1732348721; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ri6Un4b+Ug+q4iHhsNMvjaggwXQxRjHXcUUIj5tdoAM=; b=Mm0QiHiz7Jw2x4YIvxGrZs3dbJv5rNjJVxMWUm1I75RsGCsxDqCITWqs 8HMTe7CF3YpHZph50BRnQ5hBKLK4YScWwl73irWQB5YDsVDqndxqIAh1R nVnfn7EfdPmIG0UXND6T7Rzrr3jKe0PD6+lbGG29/DR624GnSqcuwEoDZ 8MgdacGLPf5CfHAHNDJZz6RfDm0yPd1vHyWiDbJy75hsRTMOpsAe6pVQv BNoSgtY2GiAKopSl63Evi2QbZz1jTEExDv5Ml/KuM+s/ozgmNmRvQQXEq IPHk+Gf7zMnF90DkqwMyRLpFO8ks98x7F2IeimvxvJLru83VKt+penb+R g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="458872286" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="458872286" 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:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="833629801" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="833629801" 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:35 -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 04/26] x86/fpu/xstate: Introduce XFEATURE_MASK_KERNEL_DYNAMIC xfeature set Date: Fri, 24 Nov 2023 00:53:08 -0500 Message-Id: <20231124055330.138870-5-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=-4.5 required=5.0 tests=BAYES_00,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 23 Nov 2023 23:59:43 -0800 (PST) Define new XFEATURE_MASK_KERNEL_DYNAMIC set including the features can be optionally enabled by kernel components, i.e., the features are required by specific kernel components. Currently it's used by KVM to configure guest dedicated fpstate for calculating the xfeature and fpstate storage size etc. The kernel dynamic xfeatures now only contain XFEATURE_CET_KERNEL, which is supported by host as they're enabled in xsaves/xrstors operating xfeature set (XCR0 | XSS), but the relevant CPU feature, i.e., supervisor shadow stack, is not enabled in host kernel so it can be omitted for normal fpstate by default. Remove the kernel dynamic feature from fpu_kernel_cfg.default_features so that the bits in xstate_bv and xcomp_bv are cleared and xsaves/xrstors can be optimized by HW for normal fpstate. Suggested-by: Dave Hansen Signed-off-by: Yang Weijiang --- arch/x86/include/asm/fpu/xstate.h | 5 ++++- arch/x86/kernel/fpu/xstate.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h index 3b4a038d3c57..a212d3851429 100644 --- a/arch/x86/include/asm/fpu/xstate.h +++ b/arch/x86/include/asm/fpu/xstate.h @@ -46,9 +46,12 @@ #define XFEATURE_MASK_USER_RESTORE \ (XFEATURE_MASK_USER_SUPPORTED & ~XFEATURE_MASK_PKRU) -/* Features which are dynamically enabled for a process on request */ +/* Features which are dynamically enabled per userspace request */ #define XFEATURE_MASK_USER_DYNAMIC XFEATURE_MASK_XTILE_DATA +/* Features which are dynamically enabled per kernel side request */ +#define XFEATURE_MASK_KERNEL_DYNAMIC XFEATURE_MASK_CET_KERNEL + /* All currently supported supervisor features */ #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \ XFEATURE_MASK_CET_USER | \ diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index b57d909facca..ba4172172afd 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -824,6 +824,7 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) /* Clean out dynamic features from default */ fpu_kernel_cfg.default_features = fpu_kernel_cfg.max_features; fpu_kernel_cfg.default_features &= ~XFEATURE_MASK_USER_DYNAMIC; + fpu_kernel_cfg.default_features &= ~XFEATURE_MASK_KERNEL_DYNAMIC; fpu_user_cfg.default_features = fpu_user_cfg.max_features; fpu_user_cfg.default_features &= ~XFEATURE_MASK_USER_DYNAMIC; -- 2.27.0