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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1F9C10F284F for ; Fri, 27 Mar 2026 17:16:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1266057.1556678 (Exim 4.92) (envelope-from ) id 1w6Anb-0006mz-I4; Fri, 27 Mar 2026 17:16:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1266057.1556678; Fri, 27 Mar 2026 17:16:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w6Anb-0006ms-Ee; Fri, 27 Mar 2026 17:16:43 +0000 Received: by outflank-mailman (input) for mailman id 1266057; Fri, 27 Mar 2026 17:16:42 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w6AnZ-0006mm-Ut for xen-devel@lists.xenproject.org; Fri, 27 Mar 2026 17:16:42 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w6AnY-00E3WY-RE for xen-devel@lists.xenproject.org; Fri, 27 Mar 2026 18:16:40 +0100 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c6bb5d-2eae-0a2a0a5409dd-0a2a4504af5c-38 for ; Fri, 27 Mar 2026 18:16:40 +0100 Received: from [209.85.128.49] (helo=mail-wm1-f49.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c6bb78-c823-0a2a45040019-d1558031cd85-3 for ; Fri, 27 Mar 2026 18:16:40 +0100 Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-486fda2a389so19183475e9.1 for ; Fri, 27 Mar 2026 10:16:40 -0700 (PDT) Received: from localhost.localdomain (host-78-146-242-105.as13285.net. [78.146.242.105]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722d2366dsm98991055e9.10.2026.03.27.10.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 10:16:38 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=citrix.com header.i="@citrix.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1774631800; x=1775236600; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0VEaJHVlFf1RyDf4mFUIyI/gmCJzqHaIWFNIxE0++FM=; b=qcX3BxREjvW1Xd4H8AdvNkvVo1k+FQ3UBgD1coSDdGtIUr3sgY3fvVp2tYlp8nWkBr vj2JJnB6cDN3TRJaMxegby6BPeU850/JUbbNdE7evCI5NAZGf7D6r8fY7i9DZWqB7IPZ NXzLzFkA5270LYK2kyLlKYUVCEejgSm9JZfh4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774631800; x=1775236600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0VEaJHVlFf1RyDf4mFUIyI/gmCJzqHaIWFNIxE0++FM=; b=Ceek3SERmPjUrGYI3YM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e9.15.1774631798963; Fri, 27 Mar 2026 10:16:38 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Ross Lagerwall Subject: [PATCH v2 2/2] x86/fpu: Initialise FTW in xstate_alloc_save_area() Date: Fri, 27 Mar 2026 17:16:36 +0000 Message-Id: <20260327171636.1182604-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260326190429.1156367-3-andrew.cooper3@citrix.com> References: <20260326190429.1156367-3-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-ebf023/1774631800-B8A8E9D1-81B5EAC6/0/0 X-purgate-type: clean X-purgate-size: 1964 Right now, xstate_alloc_save_area() leaves both XSTATE_BV and FTW clear. This causes a difference in behaviour between FXRSTOR and XRSTOR. Switch to using using XSTATE's idea of initial configuration which will behave the same even on pre-XSAVE hardware. Expand the comment to explain why. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: Ross Lagerwall v2: * Rewrite the commmit message and comment. --- xen/arch/x86/xstate.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index e990abc9d18c..defe9b3f0cbe 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -550,11 +550,22 @@ int xstate_alloc_save_area(struct vcpu *v) return -ENOMEM; /* - * Set the memory image to default values, but don't force the context - * to be loaded from memory (i.e. keep save_area->xsave_hdr.xstate_bv - * clear). + * We're creating a vCPU, so conceptually we should be choosing the + * architectural #RESET values. + * + * However for historical reasons of configuring the external + * co-processor, FCW's #RESET state is different to what F(N)INIT and + * XSTATE consider the "initial configuration". + * + * Guests won't care about the difference; all software tends to executes + * FNINIT very early during setup. + * + * Use XSTATE's idea of initial configuration. This allows XSTATE_BV to + * remain clear and for CPUs to use the INIT optimisation where + * applicable. */ save_area->fpu_sse.fcw = FCW_DEFAULT; + save_area->fpu_sse.ftw = FXSAVE_FTW_RESET; save_area->fpu_sse.mxcsr = MXCSR_DEFAULT; v->arch.xsave_area = save_area; -- 2.39.5