Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp158796lqo; Tue, 7 May 2024 16:01:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjcR/gTIZKmo4hPuVPcVAygEzSxPrGhlE1o/bGr0q8CeP1nd3vjuyTWBIYAXs3QArPDqpTZdw+78rloMZYx8pYGj8w56GqqAFbAaOGJg== X-Google-Smtp-Source: AGHT+IFRjnKRkO1y0MPsdlhMNhmHRT8cfR7BwOWgZl0G1LcJVo2leA3+OjGRitt2nhVPSSqe2Wbe X-Received: by 2002:a05:6358:418e:b0:186:32b2:c0cb with SMTP id e5c5f4694b2df-192d356c046mr137288455d.25.1715122905723; Tue, 07 May 2024 16:01:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715122905; cv=pass; d=google.com; s=arc-20160816; b=SzqYArJq19/cpsconskecWLhGaDzwrPl611QVz9VJVAQRloDCg0kCTP0+hlz3CSs5w RV1G8knS7W0FSDMMaTNuxiOARcI/34oti3KswXM4MErZIyi+YfbkeA6v4BMFG6mJ0Ejd VV9KlI+O+G9vCpeyCw1Bj5JVf+nOgatLxpSz9QIDUgRcpeKHuzGEsi6TnyeLA4tapiYB 9f9gYq0kPxLOOj2s9+Magp5qErqfmYpSuvZNLOLZSRGxpBOiC39b0a2n1JrpQslnGiIg zVY4MJqqOncMrhOxHKshU12ASYWTMxdCkQk5BpZiaY0SKPkE117fgslChAfMCqRvlx2H C4Sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=If9Q7YXcI0jaMPx5yFMsDYt2AC8Km9g14o178fmmDSQ=; fh=nC/COdARzWDjeJfJU3WzVRKEbYVxPlsoN70xexa3yeg=; b=B+r6PclsL/clVIDurQh1ual/nbiOiUkeoG6ZDGg/fDLK2tReqygKLJRAhCDUcPc/gP YFd7YP8dvFTa+fZzpQi1dZH9lfCb0IMJiMMb7ed1OBQnyvTNlZrwF6jDY63rns5+AY1J 9Ztkyk7Ec85L5thi7rXR8t+xBnoxX/wYwzefHI+CCgjJROnNgc21V4zheXWazlwN5xqn bDqJfpEolbSVTXCLVwbQq6e+lMiuwlGbtE2/cXnWCx6NIuuKjEXCg+vck1R3mKYzQJBS 4q8624X9EaJ1FXdrR/YNl0YB+watofBKMsgopYFE+gY94qyyP3nHkWNrLfTnmwLqNOHw v4dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uwhzibAd; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-172273-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q137-20020a632a8f000000b0060a08962dcfsi11064627pgq.86.2024.05.07.16.01.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172273-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uwhzibAd; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-172273-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 683862832FA for ; Tue, 7 May 2024 23:01:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46ADB127E37; Tue, 7 May 2024 22:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uwhzibAd" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E736786AF4 for ; Tue, 7 May 2024 22:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715122679; cv=none; b=fwOdnO7zw3m02DdYiHvuFzX6ZO2sDJ7tsBhAoGzDS3RALnahsWZlZnoLMn0aR63O+oEQvgFEDPsey00rbCZMmgq35V5Qfd83l+LJwExJKSVGWkBpaTFuaL0GU1lgfphRyd6YD2bmcHB6rQ5OtaeTYGUYYxGxqQVCRtiXWqtsMJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715122679; c=relaxed/simple; bh=XyBcZnJlWUppCuQIMinKz47R/Vd3bwL8FhNo2NLewFs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Pxc0ZNiXCOuUGMgBbTCt91U1JWyEc62xPtf9LGXKaH8QPRbt5ny3QpLUbzGoF4vYnqExMWBbfpKSWL0spLZoTwAlfyrSLV0A1PJ2iEh5m4sh0tMkcjTql/NO4R2sw2rjYoW3IW23ToEGig2kkkCeJedAi+wJ8uHEDLRxXC7K6LQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uwhzibAd; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de57643041bso6237839276.0 for ; Tue, 07 May 2024 15:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715122677; x=1715727477; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=If9Q7YXcI0jaMPx5yFMsDYt2AC8Km9g14o178fmmDSQ=; b=uwhzibAdk7SJF5PiZr80OlUUfdpQ2nyF8AQn4b1e5BjyH468Th+vQZKHdagrj83BWz weXeFRd5HFBXawGUiblHto7z1KcwSRQE0G3aWX6OJcFPrQMAgtifLfWtH9W4bIBA+9AP RMNd0OLclTwa10ulL+uXASm/jHT/i3vhfGSWT/uada+mqE15RpEIklE0HkYI/RWm+urK zroDzds6xwEueMtNwR+lbBO+8r4FtFOeq9W15V5MQronb3xg4P7eAFJWR1ckCGNV8x1Y mQvVX5DOtCsEtiwtWDT9POcGD8ULvTuypv5fNspbXoWJPLpqwoyzxhmmuywu2wKiz4UU CXKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715122677; x=1715727477; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=If9Q7YXcI0jaMPx5yFMsDYt2AC8Km9g14o178fmmDSQ=; b=LllCALq0GmnYb3NGot+3RmGwMkflIclNyU9Lq3RdxllZWe+gPzJlUdFLGErpdVcmCt CqXd+8VnKJ4/TWRqPO/hIWRCzjWgTN9WVDcUlvkoVMtZu9roCqMOvLjmQoBF998LinMC JYUwIaMFvoocQ8+Y2402X9kFlh6w42qH8zchen2Xp/WQuFC0fumwhm7eONJSDgMFn7W9 AN5PDHh7iPqulup2x0OKpMNBU7ukTcsGqZfxBxNQBfOBCJLCUhMCJuWBXcxdvEkF2hpg P6/HeiWkSoU7z3d7NIOiwl51A3Q8bgrfd8nn7I6n3U2kXpoifqgg6Sl0iT6+ZJdB1fZY WDpQ== X-Forwarded-Encrypted: i=1; AJvYcCWRdjpMVGzIXC+IMQ4jO8w1K5EGlxLo1xcdY2undYXSW4f6PFFpN4Fz5weCNGQHV13DLiCL13gXixb1dOticKbUH/CV9xPixa6W4yzc X-Gm-Message-State: AOJu0YzOx8j/SAp1MfE60gobmqBtYyJkzsIC08MLUYhVOhVc/9fYLnws 30e4QdNv/mLGOCrgZhVC6O8sSKAmGlqekN6vwfceY4BPBJRpKFduUkyikuIZcLjlNleKo1OZiX5 Luw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:110e:b0:dc7:7ce9:fb4d with SMTP id 3f1490d57ef6-debb9e6d93bmr281205276.12.1715122677033; Tue, 07 May 2024 15:57:57 -0700 (PDT) Date: Tue, 7 May 2024 15:57:55 -0700 In-Reply-To: <893ac578-baaf-4f4f-96ee-e012dfc073a8@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240219074733.122080-1-weijiang.yang@intel.com> <20240219074733.122080-5-weijiang.yang@intel.com> <893ac578-baaf-4f4f-96ee-e012dfc073a8@intel.com> Message-ID: Subject: Re: [PATCH v10 04/27] x86/fpu/xstate: Introduce XFEATURE_MASK_KERNEL_DYNAMIC xfeature set From: Sean Christopherson To: Dave Hansen Cc: Yang Weijiang , pbonzini@redhat.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com Content-Type: text/plain; charset="us-ascii" On Thu, May 02, 2024, Dave Hansen wrote: > On 5/1/24 11:45, Sean Christopherson wrote: > > On Sun, Feb 18, 2024, Yang Weijiang wrote: > >> Define a new XFEATURE_MASK_KERNEL_DYNAMIC mask to specify the features > > I still don't understand why this is being called DYNAMIC. CET_SS isn't dynamic, > > as KVM is _always_ allowed to save/restore CET_SS, i.e. whether or not KVM can > > expose CET_SS to a guest is a static, boot-time decision. Whether or not a guest > > XSS actually enables CET_SS is "dynamic", but that's true of literally every > > xfeature in XCR0 and XSS. > > > > XFEATURE_MASK_XTILE_DATA is labeled as dynamic because userspace has to explicitly > > request that XTILE_DATA be enabled, and thus whether or not KVM is allowed to > > expose XTILE_DATA to the guest is a dynamic, runtime decision. > > > > So IMO, the umbrella macro should be XFEATURE_MASK_KERNEL_GUEST_ONLY. > > Here's how I got that naming. First, "static" features are always > there. "Dynamic" features might or might not be there. I was also much > more focused on what's in the XSAVE buffer than on the enabling itself, > which are _slightly_ different. Ah, and CET_KERNEL will be '0' in XSTATE_BV for non-guest buffers, but '1' for guest buffers. > Then, it's a matter of whether the feature is user or supervisor. The > kernel might need new state for multiple reasons. Think of LBR state as > an example. The kernel might want LBR state around for perf _or_ so it > can be exposed to a guest. > > I just didn't want to tie it to "GUEST" too much in case we have more of > these things come along that get used for things unrelated to KVM. > Obviously, at this point, we've only got one and KVM is the only user so > the delta that I was worried about doesn't actually exist. > > So I still prefer calling it "KERNEL" over "GUEST". But I also don't > feel strongly about it and I've said my peace. I won't NAK it one way > or the other. I assume you mean "DYNAMIC" over "GUEST"? I'm ok with DYNAMIC, reflecting the impact on each buffer makes sense. My one request would be to change the WARN in os_xsave() to fire on CET_KERNEL, not KERNEL_DYNAMIC, because it's specifically CET_KERNEL that is guest-only. Future dynamic xfeatures could be guest-only, but they could also be dynamic for some completely different reason. That was my other hang-up with "DYNAMIC"; as-is, os_xsave() implies that it really truly is GUEST_ONLY. diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 83ebf1e1cbb4..2a1ff49ccfd5 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -185,8 +185,7 @@ 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)); + WARN_ON_FPU(!fpstate->is_guest && (mask & XFEATURE_MASK_CET_KERNEL)); XSTATE_XSAVE(&fpstate->regs.xsave, lmask, hmask, err);