Message ID | 20230914032334.75212-3-weijiang.yang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp176807vqi; Thu, 14 Sep 2023 00:42:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsiN9ofWK7Vt9uiCvou2JIhs46xfaBp7oMv/5Obis55zmTQ9JkCeQi0H/urNG+zmaiHpsn X-Received: by 2002:a17:90a:f009:b0:263:9e9b:5586 with SMTP id bt9-20020a17090af00900b002639e9b5586mr4544497pjb.44.1694677335373; Thu, 14 Sep 2023 00:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694677335; cv=none; d=google.com; s=arc-20160816; b=W/VFapHJ8/qt/48m5eLG1m0cecYq6B/6ZO2qXikz7eda0OQRfw71/uYd8QmEqYoogL /KjY0HldTNcVV5fUEa/Gv0AhZV/HKAPpSaQbDTonxBnfMD+k6tgLmRHEuh7K05iwgZeM 4JmmQZfvIgzW/cbp1clPSd+Hoc/WUVIQJS2IwgQJy8LheSv+0d/8CvR5nzOnhKcyQZfu NhvSNU8gzd6QD3vnJNccnND7LZ2XlwTTiR9NHfW+q3US+I55FRnHZFntqJp464yxllnX Kg1jkQ4bkarjHl4f2RnPkIKQOan9loghZ29OkAPeMY9QzNhkyBCxoPB56HwafTnER0xR DcmQ== 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=nYxuvNshQMN9deYRRgEOiv1auCQcrolT6NBytTZvMoY=; fh=VKDky7JI6Mwho+jW2kjyYjgneGFqVaPlgJX6sIBNvQM=; b=h0IxK79/2LsX0NgNNFnTwwqBvM6dSGCgxH/wefPW8OMHONPAVFePaPeycIT6w25yoC N8GwknQKDDs1nPTwTYzl97iPjbdwCYd88R7JzE6VrgWLKY2rTQ5LrKuodCrq+1VeXUX9 vD9VjKXLYpW2+byZqeNpKV80SXe3CTMLT645QFvn8Tf/FfeynJ1dynSq97mQpukAndiZ Qk7ZjnBelKHxO9DE3tlXpinTBpy8WxYVaxExuSe+tqRE7+8gaLM8cRWjoy0RRliqgD09 pa+izXhZF3r2EUrx2TKm93g4iFd1sqcpJ3OiRy5MnThVU7/zza08bHfKeTxfwwcAjFKW cX8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SnhbiDqR; 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id rm9-20020a17090b3ec900b00267b910cb37si1203455pjb.52.2023.09.14.00.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:42:15 -0700 (PDT) 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=SnhbiDqR; 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 7D499832821F; Wed, 13 Sep 2023 23:29:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235410AbjING2w (ORCPT <rfc822;chrisfriedt@gmail.com> + 35 others); Thu, 14 Sep 2023 02:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232446AbjING2q (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 14 Sep 2023 02:28:46 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A74C7F7; Wed, 13 Sep 2023 23:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694672922; x=1726208922; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FKJfPu7lwKGVQbgKOQaw0mIzmXpCo4IrXnEnhDUCXZg=; b=SnhbiDqRJSU+wg4VUdWeFQ0GwHBkJkSPlcZQRNdR43uCZRXrwU2YzmaA a9Ul2fYwpXN3jxbys3VEVcE9NkHZtJObmlY/Z/h16Ugl5jn9naTvWbEBy P7y3IpNmThZMgXh8gymZNB79iqY6kty/cOAzlBI+RQEyxGRrPmVxJDi3B KJMeOXGFiTzL+LEBzLrlks2bRa3uRruxyOTbr6CV9sjIPe2aC5hmFj6ez 3TrI46/Fu0/Ca/mbo7e8Pzf8Dyckpp+J56Hw/87Qj/OTlZWsRssUV61ao NHq7xh6Kj3z/wW3iPK7RYKAiv8Z6C6NLeB0j9Hugo3MCs519Z5uosQHFo w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="382672443" X-IronPort-AV: E=Sophos;i="6.02,145,1688454000"; d="scan'208";a="382672443" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 23:28:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="809937981" X-IronPort-AV: E=Sophos;i="6.02,145,1688454000"; d="scan'208";a="809937981" Received: from embargo.jf.intel.com ([10.165.9.183]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 23:28:41 -0700 From: Yang Weijiang <weijiang.yang@intel.com> To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@intel.com, tglx@linutronix.de, peterz@infradead.org, seanjc@google.com, pbonzini@redhat.com, rick.p.edgecombe@intel.com, kvm@vger.kernel.org, yang.zhong@intel.com, jing2.liu@intel.com, chao.gao@intel.com, Yang Weijiang <weijiang.yang@intel.com> Subject: [RFC PATCH 2/8] x86/fpu/xstate: Fix guest fpstate allocation size calculation Date: Wed, 13 Sep 2023 23:23:28 -0400 Message-Id: <20230914032334.75212-3-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230914032334.75212-1-weijiang.yang@intel.com> References: <20230914032334.75212-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> 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]); Wed, 13 Sep 2023 23:29:10 -0700 (PDT) X-Spam-Status: No, score=0.2 required=5.0 tests=DATE_IN_PAST_03_06, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997981648389809 X-GMAIL-MSGID: 1776997981648389809 |
Series |
Introduce CET supervisor xstate support
|
|
Commit Message
Yang, Weijiang
Sept. 14, 2023, 3:23 a.m. UTC
Fix guest xsave area allocation size from fpu_user_cfg.default_size to
fpu_kernel_cfg.default_size so that the xsave area size is consistent
with fpstate->size set in __fpstate_reset().
With the fix, guest fpstate size is sufficient for KVM supported guest
xfeatures.
Fixes: 69f6ed1d14c6 ("x86/fpu: Provide infrastructure for KVM FPU cleanup");
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
arch/x86/kernel/fpu/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
On Wed, Sep 13, 2023, Yang Weijiang wrote: > Fix guest xsave area allocation size from fpu_user_cfg.default_size to > fpu_kernel_cfg.default_size so that the xsave area size is consistent > with fpstate->size set in __fpstate_reset(). > > With the fix, guest fpstate size is sufficient for KVM supported guest > xfeatures. > > Fixes: 69f6ed1d14c6 ("x86/fpu: Provide infrastructure for KVM FPU cleanup"); > Cc: Thomas Gleixner <tglx@linutronix.de> > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> > --- > arch/x86/kernel/fpu/core.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c > index a86d37052a64..a42d8ad26ce6 100644 > --- a/arch/x86/kernel/fpu/core.c > +++ b/arch/x86/kernel/fpu/core.c > @@ -220,7 +220,9 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu) > struct fpstate *fpstate; > unsigned int size; > > - size = fpu_user_cfg.default_size + ALIGN(offsetof(struct fpstate, regs), 64); > + size = fpu_kernel_cfg.default_size + > + ALIGN(offsetof(struct fpstate, regs), 64); This looks sketchy and incomplete. I haven't looked at the gory details of fpu_user_cfg vs. fpu_kernel_cfg, but the rest of this function uses fpu_user_cfg, including a check on fpu_user_cfg.default_size. That makes me think that changing just the allocation size isn't quite right. /* Leave xfd to 0 (the reset value defined by spec) */ __fpstate_reset(fpstate, 0); fpstate_init_user(fpstate); fpstate->is_valloc = true; fpstate->is_guest = true; gfpu->fpstate = fpstate; gfpu->xfeatures = fpu_user_cfg.default_features; gfpu->perm = fpu_user_cfg.default_features; /* * KVM sets the FP+SSE bits in the XSAVE header when copying FPU state * to userspace, even when XSAVE is unsupported, so that restoring FPU * state on a different CPU that does support XSAVE can cleanly load * the incoming state using its natural XSAVE. In other words, KVM's * uABI size may be larger than this host's default size. Conversely, * the default size should never be larger than KVM's base uABI size; * all features that can expand the uABI size must be opt-in. */ gfpu->uabi_size = sizeof(struct kvm_xsave); if (WARN_ON_ONCE(fpu_user_cfg.default_size > gfpu->uabi_size)) gfpu->uabi_size = fpu_user_cfg.default_size;
On Fri, Oct 20, 2023, Sean Christopherson wrote: > On Wed, Sep 13, 2023, Yang Weijiang wrote: > > Fix guest xsave area allocation size from fpu_user_cfg.default_size to > > fpu_kernel_cfg.default_size so that the xsave area size is consistent > > with fpstate->size set in __fpstate_reset(). > > > > With the fix, guest fpstate size is sufficient for KVM supported guest > > xfeatures. > > > > Fixes: 69f6ed1d14c6 ("x86/fpu: Provide infrastructure for KVM FPU cleanup"); > > Cc: Thomas Gleixner <tglx@linutronix.de> > > Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> > > --- > > arch/x86/kernel/fpu/core.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c > > index a86d37052a64..a42d8ad26ce6 100644 > > --- a/arch/x86/kernel/fpu/core.c > > +++ b/arch/x86/kernel/fpu/core.c > > @@ -220,7 +220,9 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu) > > struct fpstate *fpstate; > > unsigned int size; > > > > - size = fpu_user_cfg.default_size + ALIGN(offsetof(struct fpstate, regs), 64); > > + size = fpu_kernel_cfg.default_size + > > + ALIGN(offsetof(struct fpstate, regs), 64); > > This looks sketchy and incomplete. I haven't looked at the gory details of > fpu_user_cfg vs. fpu_kernel_cfg, but the rest of this function uses fpu_user_cfg, > including a check on fpu_user_cfg.default_size. That makes me think that changing > just the allocation size isn't quite right. Shoot, I didn't realize the CET virtualization series included this a day later. I'll respond there.
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index a86d37052a64..a42d8ad26ce6 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -220,7 +220,9 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu) struct fpstate *fpstate; unsigned int size; - size = fpu_user_cfg.default_size + ALIGN(offsetof(struct fpstate, regs), 64); + size = fpu_kernel_cfg.default_size + + ALIGN(offsetof(struct fpstate, regs), 64); + fpstate = vzalloc(size); if (!fpstate) return false;