From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4709BC07545 for ; Tue, 24 Oct 2023 16:32:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343923AbjJXQc2 (ORCPT ); Tue, 24 Oct 2023 12:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343878AbjJXQc0 (ORCPT ); Tue, 24 Oct 2023 12:32:26 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FEA593 for ; Tue, 24 Oct 2023 09:32:25 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c9c83b656fso39212395ad.1 for ; Tue, 24 Oct 2023 09:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698165144; x=1698769944; 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=5GzmymUe1pax62z1VC7ZEkV0i3+BeKVhxznyxpe6Bzc=; b=ICjE6g+cydha7Wn6DtkNeViEFuDtY8z9DIibvhF5DWf1ht+ZhFaFPzj54lNUJTPP6t NlxJAeGvAtPHAcrAgeQvDysSfmMAXi/izvDYadu330sV7BO7b4xRjTUC+944dCbp20Gd aiL4E6TQZsebG/VCupYh95QQKum43s+FnGJNmjjtkRnEAWC4iMGE7UHV44VQAEktU6ya rwQ/go4kjUkws5z969DI3WIyKwrp/GtqVBLyl1qgd5spIQe2L+tqOIsd6dFUJMXjIyHi mEiVuJsWC7hr/iw5qKA3KWCc+Pg9EIODTurZ621o8Amvh6OriIrj8VZb1bzPn9FSYNkb Zrwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698165144; x=1698769944; 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=5GzmymUe1pax62z1VC7ZEkV0i3+BeKVhxznyxpe6Bzc=; b=I4aenZAwIT7RLbeHqyN7Sa0D46OOjS0fB3VdqbTaESC95goHGumkE546bTLhIh43XJ Ssjr+zc8ta9WKgq+K4vSkc7v414XHj0DTKH0RSPmz6M+fo9sMlopzQr6OLNMObGazF4G ufPwFtZOaW8Z59Jqvh7bKirwPdA/ZSxYZpWAqz2TTAL6+p7xiSksgqOp7e8dBS2m9ahP K3bFyLKeUCBePeDfNyHl9Am3ptbSQBVSWPDNZA6j8FWS7V6bWyjYAjnDzgNfvcG0/eUP oB7x+flHQnbN8lK4mRAIW0fU4PIgp1tGCenXJJfK4M1nizuCCJ/REyP+uJxpDqoJn4ba ZFCw== X-Gm-Message-State: AOJu0YzzFoXM67+Fnmxtw18HQ53r1DXrxN0PgjrT7uaRhqxQzQo/GB2L XN/k4SaXIOUeFsDyoN+6fsHShL50jsw= X-Google-Smtp-Source: AGHT+IHUwMUUKgwcg7lcFhCFzNYrNwiZ0J6zbrV6w6arrJF03RiDB9jgs8HGglnlW9P4SA4gsj6eGHjRmrY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d04b:b0:1ca:2285:3757 with SMTP id l11-20020a170902d04b00b001ca22853757mr177379pll.2.1698165144606; Tue, 24 Oct 2023 09:32:24 -0700 (PDT) Date: Tue, 24 Oct 2023 09:32:23 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230914063325.85503-1-weijiang.yang@intel.com> <20230914063325.85503-3-weijiang.yang@intel.com> Message-ID: Subject: Re: [PATCH v6 02/25] x86/fpu/xstate: Fix guest fpstate allocation size calculation From: Sean Christopherson To: Weijiang Yang Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, john.allen@amd.com Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 24, 2023, Weijiang Yang wrote: > On 10/21/2023 8:39 AM, Sean Christopherson wrote: > > On Thu, Sep 14, 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. > > > > > > Signed-off-by: Yang Weijiang > > > --- > > > 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); > > Shouldn't all the other calculations in this function also switch to fpu_kernel_cfg? > > At the very least, this looks wrong when paired with the above: > > > > 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; > > Hi, Sean, > Not sure what's your concerns. > From my understanding fpu_kernel_cfg.default_size should include all enabled > xfeatures in host (XCR0 | XSS), this is also expected for supporting all > guest enabled xfeatures. gfpu->uabi_size only includes enabled user xfeatures > which are operated via KVM uABIs(KVM_GET_XSAVE/KVM_SET_XSAVE/KVM_GET_XSAVE2), > so the two sizes are relatively independent since guest supervisor xfeatures > are saved/restored via GET/SET_MSRS interfaces. Ah, right, I keep forgetting that KVM's ABI can't use XRSTOR because it forces the compacted format. This part still looks odd to me: gfpu->xfeatures = fpu_user_cfg.default_features; gfpu->perm = fpu_user_cfg.default_features; but I'm probably just not understanding something in the other patches changes yet.