Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp178827rdb; Tue, 5 Dec 2023 02:14:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnW9EW2c0S1kq2F2XKiYcvb57rhGvTcZYMkHt4eqmp6ocWb6xqclRgbosVaMEqMWgqzCwM X-Received: by 2002:a17:902:6908:b0:1d0:6ffe:9ef with SMTP id j8-20020a170902690800b001d06ffe09efmr5317865plk.77.1701771245769; Tue, 05 Dec 2023 02:14:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701771245; cv=none; d=google.com; s=arc-20160816; b=SotxqavQAKC6ipdZnS69T1JXkNVSYWFNPdpSe4/hcmz9NsbfXv6mqkKoLAEa4dBRk5 z+tRSS9KvHJ5Rlt+sVzINEicmgn6KrIWdW/J0QVq7PP5Xppj1IDpAgaRXSEswknO5m+w YTbY9A9YnIYdNskwXxmIsY4v6PNcjmhwPYAdpJi4RUVezot4Xyj/ZwrZFPZu/Hu552gp Fu9W6bbVwKBC3eGDumccJCBfbrWGke0sF+MbvjRltbaj6nzrL6imsOiELQm910wO7QSX vILADQBQRlm+u1AwZSHY6hrs/gPUyOVZBVZ8G7H8VY15vMS6vMWL4X2/0CPZ5hwmV/CY 3M2A== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=grTJ7yip744IhaQrVqj6sS9YQufy0rAAz+sVkwOzAuM=; fh=Uybu0da0EIeQ5z+WCl6HYC4k4sHIVTmCUfaqg+mUfcc=; b=OFaDr0TiXOuNxwg6J9atrrFzMBJFrhn/p4L9PVOBWd0VhVRDbfLVqJ2SCnEujeAV1U Wjfje749Zu7yB3xa2TRCDgVOpmN8xcBo4/OGFwkT0vMCTIDC+3jZEqiRV9HdMEJO+FhC Zw+G/zJybdiJuXOIPy6a0oB17YsL+lKZNGMVCQgfnJda70IDoEsOzAzR7bsa8y9RR59/ WoW7cRtiQ6oly19C2DwExmoO3wPH9pFdLLGC/tYOPr008tSjnEYQL8yd9HLCIdkeMwZ8 MCwEnWHlHvT0+bHmg9MDwroyGHqKI8bRT2L4DFBir+0UJJyfwc4TSFe1Sv+8CygiEv6o FUHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YEWCbMNP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w3-20020a170902a70300b001cbe9b9f160si9178077plq.5.2023.12.05.02.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 02:14:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YEWCbMNP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 887C180417DB; Tue, 5 Dec 2023 02:13:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346686AbjLEKNX (ORCPT + 99 others); Tue, 5 Dec 2023 05:13:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376795AbjLEJz5 (ORCPT ); Tue, 5 Dec 2023 04:55:57 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D056A1A4 for ; Tue, 5 Dec 2023 01:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701770161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=grTJ7yip744IhaQrVqj6sS9YQufy0rAAz+sVkwOzAuM=; b=YEWCbMNP25xxxOSvu6/dI30+6A8pLlHMpyyy8SrRWRgXAjImqdVFK7KgjHy/KftOzKp8Wn JmZzlV0TUa2MffnDPFMhbJMzCzpQp57GF++AnK3xs3OPFaHBkVJbGZ6c6Sj4dDFhK+Xw6p m5OZVAPyNN3Lq/j1vrMtY9qY3+OCk3I= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-5AxjZjf1O_uMss01wNfd2g-1; Tue, 05 Dec 2023 04:55:59 -0500 X-MC-Unique: 5AxjZjf1O_uMss01wNfd2g-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40b32faeb7eso41618495e9.1 for ; Tue, 05 Dec 2023 01:55:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701770159; x=1702374959; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=grTJ7yip744IhaQrVqj6sS9YQufy0rAAz+sVkwOzAuM=; b=LvoZXu+RiJRub+wSjlPM1K0AZROjqm99k1ZFdgpFIOT9Pr7jMWmllEsiAZETQgR9wU Q+W0c5JgH0hS6aiG6EYCFFBOMHO0vayErAvHyN6LSnzZ63muYEwcGMqO6DNVup2vzZMg oJmixLI0ql5nfQFPgHRTfdt5OyoIRZBeoP0h+a3/+RuqiV/VLpBiBUDPd+BHDkmv8lgX 3y7kbpVOa8xVjOKzat+2j6k95vMKCSWTZKbSm/EgzYp4pLU2+v1aBXO2VAMkhjP4CvD0 ckjPw94iTNOEGFQs/98VnEhJOXOtBJjpL10aKWy7j+J3mYnx4QpxDtVCIySXWCCSqVCQ 9Nfw== X-Gm-Message-State: AOJu0Yz1Y+8Ec02PyVeUJiCqAfCDyDYVQs1P+iaYdcFvf/F2jIX3wIRw ha0edYs4BEoOhNKm1I0gRsLbIukaOYpslJDKp3DXR13AJECE3IeOZWnXglcbJDznmDGaC2cYzFd 1uAno165C0wOy5F5OgFfIx0Wu X-Received: by 2002:a05:600c:190a:b0:40b:5e21:c5cc with SMTP id j10-20020a05600c190a00b0040b5e21c5ccmr219161wmq.154.1701770158746; Tue, 05 Dec 2023 01:55:58 -0800 (PST) X-Received: by 2002:a05:600c:190a:b0:40b:5e21:c5cc with SMTP id j10-20020a05600c190a00b0040b5e21c5ccmr219149wmq.154.1701770158440; Tue, 05 Dec 2023 01:55:58 -0800 (PST) Received: from starship ([89.237.98.20]) by smtp.gmail.com with ESMTPSA id fc9-20020a05600c524900b0040b34720206sm18116954wmb.12.2023.12.05.01.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 01:55:58 -0800 (PST) Message-ID: <5a8c870875acc5c7e72eb3e885c12d6362f45243.camel@redhat.com> Subject: Re: [PATCH v7 04/26] x86/fpu/xstate: Introduce XFEATURE_MASK_KERNEL_DYNAMIC xfeature set From: Maxim Levitsky To: "Yang, Weijiang" Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, dave.hansen@intel.com, pbonzini@redhat.com, seanjc@google.com, peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, john.allen@amd.com Date: Tue, 05 Dec 2023 11:55:56 +0200 In-Reply-To: <9a7052ca-9c67-45b5-ba23-dbd23e69722c@intel.com> References: <20231124055330.138870-1-weijiang.yang@intel.com> <20231124055330.138870-5-weijiang.yang@intel.com> <3c16bb90532fbd2ec95b5a3d42a93bbbf77c4d37.camel@redhat.com> <9a7052ca-9c67-45b5-ba23-dbd23e69722c@intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 05 Dec 2023 02:13:59 -0800 (PST) On Fri, 2023-12-01 at 15:49 +0800, Yang, Weijiang wrote: > On 12/1/2023 1:33 AM, Maxim Levitsky wrote: > > On Fri, 2023-11-24 at 00:53 -0500, Yang Weijiang wrote: > > > Define new XFEATURE_MASK_KERNEL_DYNAMIC set including the features can be > > I am not sure though that this name is correct, but I don't know if I can > > suggest a better name. > > It's a symmetry of XFEATURE_MASK_USER_DYNAMIC ;-) > > > 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 */ > > I suggest to explain this a bit better. How about something like that: > > > > "Kernel features that are not enabled by default for all processes, but can > > be still used by some processes, for example to support guest virtualization" > > It looks good to me, will apply it in next version, thanks! > > > But feel free to keep it as is or propose something else. IMHO this will > > be confusing this way or another. > > > > > > Another question: kernel already has a notion of 'independent features' > > which are currently kernel features that are enabled in IA32_XSS but not present in 'fpu_kernel_cfg.max_features' > > > > Currently only 'XFEATURE_LBR' is in this set. These features are saved/restored manually > > from independent buffer (in case of LBRs, perf code cares for this). > > > > Does it make sense to add CET_S to there as well instead of having XFEATURE_MASK_KERNEL_DYNAMIC, > > CET_S here refers to PL{0,1,2}_SSP, right? > > IMHO, perf relies on dedicated code to switch LBR MSRs for various reason, e.g., overhead, the feature > owns dozens of MSRs, remove xfeature bit will offload the burden of common FPU/xsave framework. This is true, but the question that begs to be asked, is what is the true purpose of the 'independent features' is from the POV of the kernel FPU framework. IMHO these are features that the framework is not aware of, except that it enables it in IA32_XSS (and in XCR0 in the future). For the guest only features, like CET_S, it is also kind of the same thing (xsave but to guest state area only). I don't insist that we add CET_S to independent features, but I just gave an idea that maybe that is better from complexity point of view to add CET there. It's up to you to decide. Sean what do you think? Best regards, Maxim Levitsky > > But CET only has 3 supervisor MSRs and they need to be managed together with user mode MSRs. > Enabling it in common FPU framework would make the switch/swap much easier without additional > support code. > > > and maybe rename the > > 'XFEATURE_MASK_INDEPENDENT' to something like 'XFEATURES_THE_KERNEL_DOESNT_CARE_ABOUT' > > (terrible name, but you might think of a better name) > > > > > > > +#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; > > > > Best regards, > > Maxim Levitsky > > > > > > > >