From patchwork Fri Jan 10 13:28:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934639 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 C66A2E77188 for ; Fri, 10 Jan 2025 13:29:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869508.1280940 (Exim 4.92) (envelope-from ) id 1tWF4T-0000zG-5G; Fri, 10 Jan 2025 13:29:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869508.1280940; Fri, 10 Jan 2025 13:29:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4S-0000yP-UJ; Fri, 10 Jan 2025 13:29:04 +0000 Received: by outflank-mailman (input) for mailman id 869508; Fri, 10 Jan 2025 13:29:04 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4S-0000vX-1b for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:04 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id db40feb3-cf56-11ef-99a4-01e77a169b0f; Fri, 10 Jan 2025 14:29:02 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5d3d2a30afcso3398579a12.3 for ; Fri, 10 Jan 2025 05:29:02 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:01 -0800 (PST) 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" X-Inumbo-ID: db40feb3-cf56-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515742; x=1737120542; 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=bRQNfKsuvZw+nxO+9fRaGgM5v8xaStyagtWnmxEhbWE=; b=M94DQGGKuHNJfq3/ovUirZDCRE6qK/dMMVbdXWjbWclr6RUFwJI3/HKN+s5zNAHMCR e/1zisUbrIjspv0DrWEEbHSfFOHwvE4c1TokIHYE71v8kC+H9Pu5H93fQ9sYKzRizSL1 yhldldxeJVkuBUU70rm3zBVQILnb4Q7SXDuII= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515742; x=1737120542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bRQNfKsuvZw+nxO+9fRaGgM5v8xaStyagtWnmxEhbWE=; b=Xxc15VoanBE0k5fWLZ0KoRgz45HMKDiMOvwzOLgMnIM4RoaOkusKnZr4xCXXbYhXwL 0WpZU9J6vW88nPrEQb4FtLaLUQxfAcsfBST2ZW4ga+Uqg6LJrxPh4XJxd5SNbhYBpTs4 yOa08K0RzWtmeSdJmpgjyW6RVuf5fr2SJSEAcyvXIYrvcjW5N3RQRt9Eyy1PRZQclFw6 qAWVFD5R62L6JmKHut/Orlo8sMpYnR43TD7i/bviGZXs32h5EpBqZU1cvEN5HmOEKHqv acNTyRX7eG6SJLcCimgUSUsQXVUkXlsFCXhxOLG8aHntUdp7Zd5C8swN4pBBJImvA3WE YCFg== X-Gm-Message-State: AOJu0YwwguwnBoS4XOG+l+hDB1MUayoMkNbkfjB5cxtGRkWTHi2KLTNK CnIk3kC/NAwnQ+ULVSOKqpD3YF9PAxjhQsc0tVJPvG2P9B4raRqzE0XZtymYkf6QMkpIMU79zUV fGUkVKA== X-Gm-Gg: ASbGncvsFVJcDrNUg1rtIh4Lwwy9M4+oXEZfc6mjPp8ji+yoVCQ1K9Fn/ZWySkEFlyZ c0ew44Fu+x0mSikaDZGlY9PmkHhvPP6Nn6tfB3/F8a56lXsJ+bCE1VJJk1sEUFe8wS04lK3/FU6 9ibmJrgcaSn/gUjedFPdjbPXUP6dY4tQNe8iMw0V7FST6D6Vv/MeGuLKFJ5IvJNaITAZbm6Lwzw y5UreXJVQgqMk3ztovtt47u08vAsWp4UBMpeNTanXWibfQ8DVeUO18N2I6CIetYH0FUWB0aDWOa WPA= X-Google-Smtp-Source: AGHT+IGyXX40MA98jKr2GDP3/U+a3JZgqNiBAzNjjB3AtjN0x38sMjEg0t46Ben6q3KxCJNyi6FbXg== X-Received: by 2002:a05:6402:50c9:b0:5d9:a61:e7c9 with SMTP id 4fb4d7f45d1cf-5d972e1bf6fmr9811622a12.20.1736515741680; Fri, 10 Jan 2025 05:29:01 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 01/12] x86/xstate: Create map/unmap primitives for xsave areas Date: Fri, 10 Jan 2025 13:28:12 +0000 Message-ID: <20250110132823.24348-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Add infrastructure to simplify ASI handling. With ASI in the picture we'll have several different means of accessing the XSAVE area of a given vCPU, depending on whether a domain is covered by ASI or not and whether the vCPU is question is scheduled on the current pCPU or not. Having these complexities exposed at the call sites becomes unwieldy very fast. These wrappers are intended to be used in a similar way to map_domain_page() and unmap_domain_page(); The map operation will dispatch the appropriate pointer for each case in a future patch, while unmap will remain a no-op where no unmap is required (e.g: when there's no ASI) and remove the transient maping if one was required. Follow-up patches replace all uses of raw v->arch.xsave_area by this mechanism in preparation to add the beforementioned dispatch logic to be added at a later time. Signed-off-by: Alejandro Vallejo --- v2->v3: * Evaluate `v` in UNMAP (casted to void) v1->v2: * Comment macros more heavily to show their performance characteristics. * Addressed various nits in the macro comments. * Macro names to uppercase. --- xen/arch/x86/include/asm/xstate.h | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/xstate.h index 07017cc4edfd..ab81a4c8527e 100644 --- a/xen/arch/x86/include/asm/xstate.h +++ b/xen/arch/x86/include/asm/xstate.h @@ -143,4 +143,46 @@ static inline bool xstate_all(const struct vcpu *v) (v->arch.xcr0_accum & XSTATE_LAZY & ~XSTATE_FP_SSE); } +/* + * Fetch a pointer to a vCPU's XSAVE area + * + * TL;DR: If v == current, the mapping is guaranteed to already exist. + * + * Despite the name, this macro might not actually map anything. The only case + * in which a mutation of page tables is strictly required is when ASI==on && + * v!=current. For everything else the mapping already exists and needs not + * be created nor destroyed. + * + * +-----------------+--------------+ + * | v == current | v != current | + * +--------------+-----------------+--------------+ + * | ASI enabled | per-vCPU fixmap | actual map | + * +--------------+-----------------+--------------+ + * | ASI disabled | directmap | + * +--------------+--------------------------------+ + * + * There MUST NOT be outstanding maps of XSAVE areas of the non-current vCPU + * at the point of context switch. Otherwise, the unmap operation will + * misbehave. + * + * TODO: Expand the macro to the ASI cases after infra to do so is in place. + * + * @param v Owner of the XSAVE area + */ +#define VCPU_MAP_XSAVE_AREA(v) ((v)->arch.xsave_area) + +/* + * Drops the mapping of a vCPU's XSAVE area and nullifies its pointer on exit + * + * See VCPU_MAP_XSAVE_AREA() for additional information on the persistence of + * these mappings. This macro only tears down the mappings in the ASI=on && + * v!=current case. + * + * TODO: Expand the macro to the ASI cases after infra to do so is in place. + * + * @param v Owner of the XSAVE area + * @param x XSAVE blob of v + */ +#define VCPU_UNMAP_XSAVE_AREA(v, x) do { (void)(v); (x) = NULL; } while(0) + #endif /* __ASM_XSTATE_H */ From patchwork Fri Jan 10 13:28:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934641 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 0ADF3E7719C for ; Fri, 10 Jan 2025 13:29:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869509.1280952 (Exim 4.92) (envelope-from ) id 1tWF4Y-0001Rq-Dc; Fri, 10 Jan 2025 13:29:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869509.1280952; Fri, 10 Jan 2025 13:29:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4Y-0001Rj-AM; Fri, 10 Jan 2025 13:29:10 +0000 Received: by outflank-mailman (input) for mailman id 869509; Fri, 10 Jan 2025 13:29:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4X-0001QR-3K for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:09 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id de97cd0e-cf56-11ef-a0df-8be0dac302b0; Fri, 10 Jan 2025 14:29:08 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5d4e2aa7ea9so3927428a12.2 for ; Fri, 10 Jan 2025 05:29:08 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:05 -0800 (PST) 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" X-Inumbo-ID: de97cd0e-cf56-11ef-a0df-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515747; x=1737120547; 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=S28ujRidgdqsUo8KctrJ2mFUS3eNRL5DEkXV5XiQbS4=; b=QKaeRnlOYPQCiNTgTugLWYvK8SKLLF7nOu+ApIO6eKY1hjVV7CxmMTGOV8rmT/4RQg VAhoeK/uM94PIIsw8XxTCiH6t/bxmCmqjP3Bifxe3EdoR1pUFf3wTrH8GGjCAMkb2m+r U2NdnL3G2YzvaCQBiqiohu7oBB417DmTNzCxI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515747; x=1737120547; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S28ujRidgdqsUo8KctrJ2mFUS3eNRL5DEkXV5XiQbS4=; b=mVNFu+M0063MCVDYq5IsIVsPP5TLqPOBD+m2+5sMBYXMQRprr7NOLIzXwQ9hPFXfW8 ZdunpgESmgyit53PhK68dQ4dvJFPvfdHrxK9Z6MzhVdhAA+clerCnHrEJq/I6SGOmjZc BItYaITYhOy4vnntvSevM13cGRUa8IJhOu3CBZ5/8rxwHkRkrfCRNqLK3d9my1A+ZOCa 11pUROiEOceU6r38iON2cbaDC5pghB7AIdQx3PUA+QVAqWQT31KlQClGd9GVUGrjPZYy o5aGXFt05/2y7sGjyHD8+b5nV523CIvFvstwh3Zim30r9zz7ar6ZWSdeJel7zW0ML/as 3Tmg== X-Gm-Message-State: AOJu0YyZw/WL4CxeGZTPcqx+RFq5Wksc76ck7kgbIEayA55YU3hydaeV 4RXdAXNd5k3IoOOjxK4kYiRr5T+xn98JTlOF1OtB4co1k0Hq+nxKiMgmm/L8093WHD+omJZNpPd 2uH66jA== X-Gm-Gg: ASbGncvm7lks88ic0Ku5iC+j3+XC/5Kfx0cwPGsJn/u09glFAh1tS3L26gQGK4KO6HR YIvI2mjoSuDH3p4yBikhMDAIRTmmBXMUlos2t+9eyVN+yyxFUnqewAEAzDerLjCyAPk4OsThybv NqIKpVhE5FAPcKgwvhqmNSrc20BlkaxeKE+5bpb0NMKOST+I9yuwzmjvR8U05CrQrigm7K7UMfK RVYORzMEQkbUDPWfPTbqddvEtPqKYr9Lf1v+G3TRHT7K+UAp6o8P6GOkLd3ZxRQjFiGRMKPkdHa gy4= X-Google-Smtp-Source: AGHT+IHo0flgxzQJnpbc2JNOLtTwppT7VEX9vUmyga15KAzYVXXS0m2eQk3iDaRnwtsq76u6Qp3rQw== X-Received: by 2002:a05:6402:194e:b0:5d8:211a:4d59 with SMTP id 4fb4d7f45d1cf-5d972e178e1mr10632908a12.19.1736515745814; Fri, 10 Jan 2025 05:29:05 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 02/12] x86/hvm: Map/unmap xsave area in hvm_save_cpu_ctxt() Date: Fri, 10 Jan 2025 13:28:13 +0000 Message-ID: <20250110132823.24348-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v2->v3: * Added A-by v1->v2: * No change --- xen/arch/x86/hvm/hvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 922c9b3af64d..884b2b9d32cd 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -914,11 +914,11 @@ static int cf_check hvm_save_cpu_ctxt(struct vcpu *v, hvm_domain_context_t *h) if ( v->fpu_initialised ) { - BUILD_BUG_ON(sizeof(ctxt.fpu_regs) != - sizeof(v->arch.xsave_area->fpu_sse)); - memcpy(ctxt.fpu_regs, &v->arch.xsave_area->fpu_sse, - sizeof(ctxt.fpu_regs)); + const struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(v); + BUILD_BUG_ON(sizeof(ctxt.fpu_regs) != sizeof(xsave_area->fpu_sse)); + memcpy(ctxt.fpu_regs, &xsave_area->fpu_sse, sizeof(ctxt.fpu_regs)); + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); ctxt.flags = XEN_X86_FPU_INITIALISED; } From patchwork Fri Jan 10 13:28:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934642 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 CE587E77188 for ; Fri, 10 Jan 2025 13:29:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869511.1280963 (Exim 4.92) (envelope-from ) id 1tWF4a-0001it-Ly; Fri, 10 Jan 2025 13:29:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869511.1280963; Fri, 10 Jan 2025 13:29:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4a-0001ii-If; Fri, 10 Jan 2025 13:29:12 +0000 Received: by outflank-mailman (input) for mailman id 869511; Fri, 10 Jan 2025 13:29:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4Y-0001QR-RH for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:10 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dfe7a059-cf56-11ef-a0df-8be0dac302b0; Fri, 10 Jan 2025 14:29:10 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5d0ac27b412so2537670a12.1 for ; Fri, 10 Jan 2025 05:29:10 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:09 -0800 (PST) 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" X-Inumbo-ID: dfe7a059-cf56-11ef-a0df-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515749; x=1737120549; 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=5O7gLemGUf6JN5FF2lKFWWHjDWg3G1VdwWkZcZUgbRo=; b=H+3rDaSRoJ9qfFjKCevTO9Db2au3aLeL3PSMeJGGENCB2svThvFz6H77i906SZF1tj flMU2CvdS1XcpQb0sWnu5TQSZDXblQRMMdb1Cn650KEGkda9GsuoPGqVdYQx6ZRRb0mp Eck0ivjrA9CJRFAOIC9LpKYtX+PIEmGw/eY8g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515749; x=1737120549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5O7gLemGUf6JN5FF2lKFWWHjDWg3G1VdwWkZcZUgbRo=; b=DOLvvUVE7w+qJa2HJCgrHnB7PchQ8003xmaU93EZeOD6ydJCIO6SCVBana7n9BRvaY 9uFnZ/Bolisb0G+aIDXdNfY+1faJH645xLx43+GyIv36fhTyAXqNfL/rOoKlQTAlaw5B AD5dmREDpLZP1t0P9LHWjT1J6VN6eWij7hM9nfzsOJTqYW+UH4b52T6jfxPWmZ/vzElQ K3JDyiRGgieUtFtIkpxV+5PMbnMf5SoN51fu/KTvY8063t/ilsRfoWOacIwqM5m5aV6R UCdv4FCknliuNcxNEjMwa9W3n1gxbFYtb6517Rp4j99/XnZ3aqvf6tXnDcYaChtifJ7C UTBw== X-Gm-Message-State: AOJu0Yyadct4GtAKXBF/i66+vxI5pvgo2UVdfkYvjTiqTb0cCzOAKTTl NCLinBwqFdBrvlczabjY0NkuVbu0BYHy7fwYSiWU06AD4r2mkH/R1VDqCMV9iT/zJN+aUbw72+l qaCaVEA== X-Gm-Gg: ASbGncupgDhCzJvAWLqJ7oPTlBL5bk4hMHGnb9KHRwkylvdq49+ZlFhnEK8rn0Wzu3k srl7GRwowqQfuyLGUK+XId3j9dZB5NL6dcDJIUjvCQEA1cR6lLGWpviExqIv9tALQQyHvUporEj hC0ybO9MURVDZLPtFvfY5OPxMBCS+3x8/mHHlDQLhVMhkPSSea0iJuYZnxoMyiw1k4XjQhFUUis ZVU22YlOBdezuvYnXpWeC5Z0/MVsMzQyBTa6Vxf8oe7QaS9QlyRHAyJELA3Oz60cVK271Y6FdM7 aew= X-Google-Smtp-Source: AGHT+IFDwVTKHs3K2kJcgyqa3q8O7JLMmDZootiHiSvxM+9IOV5nU8oJOp9UKXOkmTk4hp/wvl9+qw== X-Received: by 2002:a05:6402:5243:b0:5d9:b84:a01f with SMTP id 4fb4d7f45d1cf-5d972e169a3mr10438762a12.18.1736515749503; Fri, 10 Jan 2025 05:29:09 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 03/12] x86/fpu: Map/umap xsave area in vcpu_{reset,setup}_fpu() Date: Fri, 10 Jan 2025 13:28:14 +0000 Message-ID: <20250110132823.24348-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v2->v3: * Added A-by v1->v2: * No change --- xen/arch/x86/i387.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 8fba0aef4284..5429531ddd5f 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -304,24 +304,32 @@ int vcpu_init_fpu(struct vcpu *v) void vcpu_reset_fpu(struct vcpu *v) { + struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(v); + v->fpu_initialised = false; - *v->arch.xsave_area = (struct xsave_struct) { + *xsave_area = (struct xsave_struct) { .xsave_hdr.xstate_bv = X86_XCR0_X87, }; /* Old gcc doesn't permit these to be part of the initializer. */ - v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT; - v->arch.xsave_area->fpu_sse.fcw = FCW_RESET; - v->arch.xsave_area->fpu_sse.ftw = FXSAVE_FTW_RESET; + xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT; + xsave_area->fpu_sse.fcw = FCW_RESET; + xsave_area->fpu_sse.ftw = FXSAVE_FTW_RESET; + + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); } void vcpu_setup_fpu(struct vcpu *v, const void *data) { + struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(v); + v->fpu_initialised = true; - *v->arch.xsave_area = (struct xsave_struct) { + *xsave_area = (struct xsave_struct) { .fpu_sse = *(const fpusse_t*)data, .xsave_hdr.xstate_bv = XSTATE_FP_SSE, }; + + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); } /* Free FPU's context save area */ From patchwork Fri Jan 10 13:28:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934644 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 008F1E7719C for ; Fri, 10 Jan 2025 13:29:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869512.1280973 (Exim 4.92) (envelope-from ) id 1tWF4d-00020i-0f; Fri, 10 Jan 2025 13:29:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869512.1280973; Fri, 10 Jan 2025 13:29:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4c-00020W-Qs; Fri, 10 Jan 2025 13:29:14 +0000 Received: by outflank-mailman (input) for mailman id 869512; Fri, 10 Jan 2025 13:29:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4a-0000vX-RM for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:12 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e0812746-cf56-11ef-99a4-01e77a169b0f; Fri, 10 Jan 2025 14:29:11 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5d4e2aa7ea9so3927504a12.2 for ; Fri, 10 Jan 2025 05:29:11 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:10 -0800 (PST) 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" X-Inumbo-ID: e0812746-cf56-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515750; x=1737120550; 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=Pulx2rJf+eVHBhVEkVLX9BFreaZxFXyF8Is/s9m9sX8=; b=L9dv5+jwFLfSlTaXGdnHHqRHWnGd3jiAk6zju2d3S5GCRblIWX6ac+w38Gcj+/kZ62 EcJy/citFUjUzgVOONMRoljKPJvuyO3aizYfKJPHqkUo1wca7LZKS0pk+O3qG59NNtfI Mj0h28MA41aYqJFw4/tQmqEOjwEQZ4HvfPPxE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515750; x=1737120550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pulx2rJf+eVHBhVEkVLX9BFreaZxFXyF8Is/s9m9sX8=; b=GkepZzWOopzUomAy3R5v0JQ4H8tDOk7ZExvPDVFtXQFX0yNot8vQUJvGsWKVGVPvgc ktgMiuXDq4pI11k62xRS9W+0LMv7dajqV/D6TryfGXRaSXM6oFSVZMvv8h4kiBDo9EKo qU02jtv7cLpHDkKk1rlJeR9dM+jIfs1bmX3bHR2VQE/p8vp5XGUO+TtjVmjLYTwL1oIe 2jy0M5CkO9PqmyaSUxqb9Mbx0+NpdKYJG6KmFpEtPyRWOLO3zsLlKvxbldDZjxczJSoz HWEXhL1SlnKTMS24KWgsvODZoZGXn+aIninBTddIyLVQFskQ89kAfSuJMFvtCTr6clQg q7jA== X-Gm-Message-State: AOJu0Yyrl7TL+64/VjY10KI9NabR/vLp6VxSNDUVCzzrJoyPKBKFLV2k 9T9ivMo8QXgq5fZ8nOxU+CBauBG47SK2hnEiQz96Yd8RRaF//x6CpM3yOx3bKwLUEppQkfNYOIp W4ghZZg== X-Gm-Gg: ASbGncuNpCs6tce9ELJ8eYuhct55+oJCg0Wcqw8ajQo/FobBZc+KmnfrEioRgSb/j18 oK2nHqQ/847vM5s3oJjWBluUoxgiugb133DCe7aIlUSS/qF7fuvAZdy4dsRpFc6KJje11eHJO0l p2uUzcMJvrjg9naRsWCppF8g7DyuPpnU6bo2lriVluZQShrL8ZWw18jXb+515pxqTFwwXd/4B0Y u1f2m581gsC9Etru8kaXjR76fJvtdoY/WCR9BBeL5ltsQ/4TA53j++xNepj2aI0rrO4e0eO6te4 YTo= X-Google-Smtp-Source: AGHT+IH/zIJhlFB//h5vV6Zg10dAMqVvYLHKKDAVfZ79wH6CqKU5mgDtC7kYIG7zl3p84Kdgmv0bnA== X-Received: by 2002:a05:6402:5244:b0:5d0:8197:7ab3 with SMTP id 4fb4d7f45d1cf-5d972dfb878mr10087008a12.3.1736515750544; Fri, 10 Jan 2025 05:29:10 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 04/12] x86/xstate: Map/unmap xsave area in xstate_set_init() and handle_setbv() Date: Fri, 10 Jan 2025 13:28:15 +0000 Message-ID: <20250110132823.24348-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v2->v3: * style: Capitalized first letter of the comment. * Added A-by v1->v2: * Added comment highlighting fastpath for current --- xen/arch/x86/xstate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index af9e345a7ace..12004d7db24b 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -993,7 +993,13 @@ int handle_xsetbv(u32 index, u64 new_bv) clts(); if ( curr->fpu_dirtied ) - asm ( "stmxcsr %0" : "=m" (curr->arch.xsave_area->fpu_sse.mxcsr) ); + { + /* Has a fastpath for `current`, so there's no actual map */ + struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(curr); + + asm ( "stmxcsr %0" : "=m" (xsave_area->fpu_sse.mxcsr) ); + VCPU_UNMAP_XSAVE_AREA(curr, xsave_area); + } else if ( xstate_all(curr) ) { /* See the comment in i387.c:vcpu_restore_fpu_eager(). */ @@ -1048,7 +1054,7 @@ void xstate_set_init(uint64_t mask) unsigned long cr0 = read_cr0(); unsigned long xcr0 = this_cpu(xcr0); struct vcpu *v = idle_vcpu[smp_processor_id()]; - struct xsave_struct *xstate = v->arch.xsave_area; + struct xsave_struct *xstate; if ( ~xfeature_mask & mask ) { @@ -1061,8 +1067,10 @@ void xstate_set_init(uint64_t mask) clts(); + xstate = VCPU_MAP_XSAVE_AREA(v); memset(&xstate->xsave_hdr, 0, sizeof(xstate->xsave_hdr)); xrstor(v, mask); + VCPU_UNMAP_XSAVE_AREA(v, xstate); if ( cr0 & X86_CR0_TS ) write_cr0(cr0); From patchwork Fri Jan 10 13:28:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934643 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 E2CD9E7719D for ; Fri, 10 Jan 2025 13:29:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869513.1280978 (Exim 4.92) (envelope-from ) id 1tWF4d-000243-Aw; Fri, 10 Jan 2025 13:29:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869513.1280978; Fri, 10 Jan 2025 13:29:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4d-00023B-5R; Fri, 10 Jan 2025 13:29:15 +0000 Received: by outflank-mailman (input) for mailman id 869513; Fri, 10 Jan 2025 13:29:13 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4b-0000vX-Te for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:13 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e125b8e4-cf56-11ef-99a4-01e77a169b0f; Fri, 10 Jan 2025 14:29:12 +0100 (CET) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5d41848901bso3788211a12.0 for ; Fri, 10 Jan 2025 05:29:12 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:11 -0800 (PST) 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" X-Inumbo-ID: e125b8e4-cf56-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515751; x=1737120551; 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=zUEO9205Bbujlvio/njapuGkmXsktum9lbTR3dku2CE=; b=hZO6ExnZGiX60aGYwqM1OiTBkheEI5vkDcgkTdmjcz2FHxsxCcbxIneG7x+hpcb/jE 7kL0lqhfU+rXmG3HZWcR/2bPZeGGLv2NsKRt/ijloECBwZ2Ypaq2JjR129ULDQCSFko2 cHuE7Qn6Ni5B/lHknoi5GpsrEWarlUozyBvKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515751; x=1737120551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zUEO9205Bbujlvio/njapuGkmXsktum9lbTR3dku2CE=; b=XgIOfn98hPLq0Mpy/AZJILxpzQLsnCCJk3e1UlCgjKFfR8/d/xADfswc5yUwmLKQue HsZVS0LiYl8JFUpmVyH0uwp+00HrH7YGNOS47Cuoiaih8yMM8xWDBagVbUjDtwlo1qlu LG7HOKW8l/kngoxAfUJyub2kVO7WRH4bJ8a0XLdLQkHqN315FLcSMjV+wtzR6msoM0V3 TPwhKZQXZ1PH3TlP+wCm5YN9blHkQcBpKtfdx0pN0JzH2zRDlr0SiBZrk+/oD2OOp4PW Eluqmw8HBP4VQU7FqqN3MoTL5mHYIuOOkMyjTivVyt1nwD75QZ//8B1Lb99Qj0pXx38K mvdg== X-Gm-Message-State: AOJu0YxbHpuORyiPtSe9zs1NrCoF9bG0gsoR0h0ZyaP/lL0yUF2Uay8z F8iLInB2OvlMLdB927lklV6SvZXwqAC9GwCkfMjXkdUPhL/TXSWOuT+mQYau/QlOW0g+NSGqhsI +VUq6mg== X-Gm-Gg: ASbGnctkcKa1r5ZNBqgXBeHEkijfuVgLzuLqYA8rATILSvxpPl/foqDCNvJyDLSKC+p ybbLj5HVmeE3+HDktJDNKh7vrTTvns4v94J0hb+2BvhBWIDH9KjT+4RVeqdyha6oVBSIsdLBkRL 9T2AzDBqpjmcn3T7GfBDO1fsRRaNunB04PKaByG2dRwD2XIAktZDKRwWT4Uc3xkjfZy3b1FR7zx iGxYAzXruuk018D+e6DYFrECNKmu+2BRaXmFrlD/GcySShlbXq2jR0cOAj0ygXXEMwFZPlIAaFX njg= X-Google-Smtp-Source: AGHT+IEoX1iZirm/9+11R/yAmKqYvTojFGbSSLXDzqpQe8R8iEbKo+oGFbWvaPWpr8T4NrAFe7KVoQ== X-Received: by 2002:a05:6402:3506:b0:5d9:3118:d0b8 with SMTP id 4fb4d7f45d1cf-5d98a27dc65mr5164910a12.8.1736515751604; Fri, 10 Jan 2025 05:29:11 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 05/12] x86/hvm: Map/unmap xsave area in hvmemul_{get,put}_fpu() Date: Fri, 10 Jan 2025 13:28:16 +0000 Message-ID: <20250110132823.24348-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v2->v3: * style: Capitalized first letter of the fastpath comment * Added A-by v1->v2: * Added comments highlighting fastpath for current --- xen/arch/x86/hvm/emulate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index a1935a174830..d5011612aff0 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -2371,7 +2371,9 @@ static int cf_check hvmemul_get_fpu( alternative_vcall(hvm_funcs.fpu_dirty_intercept); else if ( type == X86EMUL_FPU_fpu ) { - const fpusse_t *fpu_ctxt = &curr->arch.xsave_area->fpu_sse; + /* Has a fastpath for `current`, so there's no actual map */ + const struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(curr); + const fpusse_t *fpu_ctxt = &xsave_area->fpu_sse; /* * Latch current register state so that we can back out changes @@ -2397,6 +2399,8 @@ static int cf_check hvmemul_get_fpu( else ASSERT(fcw == fpu_ctxt->fcw); } + + VCPU_UNMAP_XSAVE_AREA(curr, xsave_area); } return X86EMUL_OKAY; @@ -2411,7 +2415,9 @@ static void cf_check hvmemul_put_fpu( if ( aux ) { - fpusse_t *fpu_ctxt = &curr->arch.xsave_area->fpu_sse; + /* Has a fastpath for `current`, so there's no actual map */ + struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(curr); + fpusse_t *fpu_ctxt = &xsave_area->fpu_sse; bool dval = aux->dval; int mode = hvm_guest_x86_mode(curr); @@ -2467,6 +2473,8 @@ static void cf_check hvmemul_put_fpu( fpu_ctxt->fop = aux->op; + VCPU_UNMAP_XSAVE_AREA(curr, xsave_area); + /* Re-use backout code below. */ backout = X86EMUL_FPU_fpu; } From patchwork Fri Jan 10 13:28:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934646 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 8E4C2E77188 for ; Fri, 10 Jan 2025 13:29:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869515.1280993 (Exim 4.92) (envelope-from ) id 1tWF4e-0002V4-OC; Fri, 10 Jan 2025 13:29:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869515.1280993; Fri, 10 Jan 2025 13:29:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4e-0002UF-Gm; Fri, 10 Jan 2025 13:29:16 +0000 Received: by outflank-mailman (input) for mailman id 869515; Fri, 10 Jan 2025 13:29:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4c-0000vX-TU for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:14 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e1b0135c-cf56-11ef-99a4-01e77a169b0f; Fri, 10 Jan 2025 14:29:13 +0100 (CET) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5d7e3f1fdafso4034677a12.0 for ; Fri, 10 Jan 2025 05:29:13 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:12 -0800 (PST) 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" X-Inumbo-ID: e1b0135c-cf56-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515752; x=1737120552; 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=CCX/yh7HycpxvmfWA8KKNWXNQA4qbA28JEl6dZ92/5k=; b=eMgrfm00v/DfijO/Z7ZyU+vZPe5C3+0kl6btixzaSIiW5+8/Epbji/YTx9Lrg3UmvV M/DEqs/xw3X7deL6pUAoKQaYLtXzSRX7+aAAxeiGXTxbQ2CL5HjgccXj7WbAVy9LZHCh MvMoJlR8MMnmcrFDIpDaWAJleqjm3Dg2fvQI8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515752; x=1737120552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CCX/yh7HycpxvmfWA8KKNWXNQA4qbA28JEl6dZ92/5k=; b=kqUIAPayeKjloHG4QXbKVYcAmFBtxeKJqdlc5Ma2fMhDleEVPmdLErLrQom1RJtC/b sOwkvcAjeZmxfGBm/YqHJjRvuroOzXsemw9miC4vJSawL+tRC9yf7GMbiyFIhRsPPLp2 Akus6zCuHD93niO6obq0/xgD+I2Xml6pWEJSCzc5BTSqCjdbCQQKooTPB4eYTEuNjoCK XnCpC7d1lVjlcpMHd8bm45qRoxDD9MSWSceNVLaxzjYJH+NU0sNM04bPjEM01v5jhyBP Rsr8QNae4mbvjqwaGfrJry46+pKNzq7HfX9J+83TP2WekNNEvPXJOmoJxU5rZ0xF9pcC fO7A== X-Gm-Message-State: AOJu0YykiBBpPCzMmBIyTzgHmdv2f0n1WmsVMJEo1Tl3Zh6w1fnXIxCQ CcUvfzE1X4gfXOo/QTOArJvXEhFRRyG8OA1gzD6aZdmLpsZNZ7F2KsXOczPg91+zVAJi/36B/+w gaFMwRg== X-Gm-Gg: ASbGncu2/7ccdC/3V7MYmiO671v+GGjOTTox6Y2FQP3MiC7flBk3hh67sobrVQHS9ZL I0TGJ5a3idQEX4zruPt8OS4R0tKMQTCz+/bnq0ZUSCstZ6gTShukYNZHmoD1qikZrHZbdf5No2Q M8FlfIHDWRDFUWDSG0WYYEf2zz4BLEfIZXNUftqFWwZw3x/V+0jdP+vTeBVxTlqDoIMsZYaF4Aa midWl+Prq5JXmyEjvGxubWcEAn/rs5VbfE4y5yX1CH+yzQtI2k8CJu0RS9Kac58Vrc3/kAYnmiN JKQ= X-Google-Smtp-Source: AGHT+IFt0+J+MzwzmdDfbFOmSHL+99J1n+bWPWq8Lzmmx0aBwjpOqjzKgIrvM+hZK/x8jYYJOdfbsA== X-Received: by 2002:a05:6402:430c:b0:5d4:75b:8ced with SMTP id 4fb4d7f45d1cf-5d972e6bdf5mr9861162a12.32.1736515752585; Fri, 10 Jan 2025 05:29:12 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 06/12] x86/domctl: Map/unmap xsave area in arch_get_info_guest() Date: Fri, 10 Jan 2025 13:28:17 +0000 Message-ID: <20250110132823.24348-7-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v1->v2: * Added A-by v1->v2: * No change --- xen/arch/x86/domctl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 5f01111619da..3044f706de1c 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1377,16 +1377,17 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) unsigned int i; const struct domain *d = v->domain; bool compat = is_pv_32bit_domain(d); + const struct xsave_struct *xsave_area; #ifdef CONFIG_COMPAT #define c(fld) (!compat ? (c.nat->fld) : (c.cmp->fld)) #else #define c(fld) (c.nat->fld) #endif - BUILD_BUG_ON(sizeof(c.nat->fpu_ctxt) != - sizeof(v->arch.xsave_area->fpu_sse)); - memcpy(&c.nat->fpu_ctxt, &v->arch.xsave_area->fpu_sse, - sizeof(c.nat->fpu_ctxt)); + xsave_area = VCPU_MAP_XSAVE_AREA(v); + BUILD_BUG_ON(sizeof(c.nat->fpu_ctxt) != sizeof(xsave_area->fpu_sse)); + memcpy(&c.nat->fpu_ctxt, &xsave_area->fpu_sse, sizeof(c.nat->fpu_ctxt)); + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); if ( is_pv_domain(d) ) c(flags = v->arch.pv.vgc_flags & ~(VGCF_i387_valid|VGCF_in_kernel)); From patchwork Fri Jan 10 13:28:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934645 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 74539E7719F for ; Fri, 10 Jan 2025 13:29:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869518.1281007 (Exim 4.92) (envelope-from ) id 1tWF4g-0002un-Hl; Fri, 10 Jan 2025 13:29:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869518.1281007; Fri, 10 Jan 2025 13:29:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4g-0002sI-As; Fri, 10 Jan 2025 13:29:18 +0000 Received: by outflank-mailman (input) for mailman id 869518; Fri, 10 Jan 2025 13:29:16 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4e-0000vX-SH for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:16 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e26119b5-cf56-11ef-99a4-01e77a169b0f; Fri, 10 Jan 2025 14:29:14 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5d3f65844deso3159909a12.0 for ; Fri, 10 Jan 2025 05:29:14 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:13 -0800 (PST) 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" X-Inumbo-ID: e26119b5-cf56-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515754; x=1737120554; 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=NpsXCde4rHvHOBhrjr2xt+9hIK3kXIA7STQqezCkmas=; b=QQDe33ZF/gpuVeJpaMcRSdfCHezA0E+kBQRmyfp7wbgJHu8ukOFClTJjRzD5sYyQOn KhC+7dEQbQjIFYDaWUZOpKRlHzuhEh/QHFa2vfPp4wvvvto6Jqjej4vu3jDScOx0p6lb 2aVfMF3z9+fC5x1S3As3Bp0tng03kpWaw6TQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515754; x=1737120554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NpsXCde4rHvHOBhrjr2xt+9hIK3kXIA7STQqezCkmas=; b=AYILJ5lX0CGvMjrp0c8qdbZOx3ewceHQUwx0kEgd4fXVIgED/S4oYWWQHpbkxeO9Qg IV0M/7AZstbgxb1d4126rgVhV9ts7P7kQpPjhxDqn8acqjx3junNaK343f1Ebh5CwINM ARou/Tpm7gi1Q6lBrGInXJGCCUhvljSGQtiCY4RGcg2YOUxhMm9j+AHYPfnUnmTGU/uU OEzKtLtxSIuKjdgjeAuKYxa2pSZ2H1TquibakwInkFjS1hAgKNKvAG/DqAXhyxvaENkw aIMJccfmViRK2U04YSrWCYKFImEWtSRh8YaVSdY2Gy4Bmtrm21AnJXnzB53WaN310E0a Ocmw== X-Gm-Message-State: AOJu0Yx5o7Zn1wsj6PzPpfO5U0A9aBdr43aqlYIgMOpldE3Lm6kFTF/A TTUFEAIAE/7lvTSL/b73MWtwhcJWGW7vbXGGylM2VnG/AQryXq75Co0Q4nXMShH04nq/Yee5ttw d1ftZcA== X-Gm-Gg: ASbGncvcRTsaAUPU7cDyYALnit5gE6WwUM3yQSu5RHwP41y831tFni8vHBNIQpydi2G OPbhQdkfqRJY7GDiha3W1C891RT+TLkc/SCxxq1Rn7hYSW6nyII9BeAUpeit9iATYfYTw4xkLUv StVgl8zMhKpzp62xXa8I7RyLUKJfrESPAPglh6/xgms7YnDkmWRh+ncScqOLze7q5v8xXgWfs+h vGpotUPxcFIt8dnZ0TPgjkyq//ti3/TLmb5rY0CJ9G+m3UY3I5peBBo9FjgieVk6FQeqw09LtZg bRQ= X-Google-Smtp-Source: AGHT+IHLwTsFfF0iue5H/nDszzLlRu5rCiVcELAIDfNI3h8oJ83PoDm2hkMI53TMpPky9oTecF3DMQ== X-Received: by 2002:a05:6402:5244:b0:5d0:8197:7ab3 with SMTP id 4fb4d7f45d1cf-5d972dfb878mr10087233a12.3.1736515753650; Fri, 10 Jan 2025 05:29:13 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 07/12] x86/xstate: Map/unmap xsave area in {compress,expand}_xsave_states() Date: Fri, 10 Jan 2025 13:28:18 +0000 Message-ID: <20250110132823.24348-8-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2->v3: * Unmap xsave area also before the early return. v1->v2: * No change --- xen/arch/x86/xstate.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 12004d7db24b..3d249518a1b7 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -177,7 +177,7 @@ static void setup_xstate_comp(uint16_t *comp_offsets, */ void expand_xsave_states(const struct vcpu *v, void *dest, unsigned int size) { - const struct xsave_struct *xstate = v->arch.xsave_area; + const struct xsave_struct *xstate = VCPU_MAP_XSAVE_AREA(v); const void *src; uint16_t comp_offsets[sizeof(xfeature_mask)*8]; u64 xstate_bv = xstate->xsave_hdr.xstate_bv; @@ -191,7 +191,7 @@ void expand_xsave_states(const struct vcpu *v, void *dest, unsigned int size) if ( !(xstate->xsave_hdr.xcomp_bv & XSTATE_COMPACTION_ENABLED) ) { memcpy(dest, xstate, size); - return; + goto out; } ASSERT(xsave_area_compressed(xstate)); @@ -228,6 +228,9 @@ void expand_xsave_states(const struct vcpu *v, void *dest, unsigned int size) valid &= ~feature; } + + out: + VCPU_UNMAP_XSAVE_AREA(v, xstate); } /* @@ -242,7 +245,7 @@ void expand_xsave_states(const struct vcpu *v, void *dest, unsigned int size) */ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size) { - struct xsave_struct *xstate = v->arch.xsave_area; + struct xsave_struct *xstate = VCPU_MAP_XSAVE_AREA(v); void *dest; uint16_t comp_offsets[sizeof(xfeature_mask)*8]; u64 xstate_bv, valid; @@ -256,7 +259,7 @@ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size) if ( !(v->arch.xcr0_accum & XSTATE_XSAVES_ONLY) ) { memcpy(xstate, src, size); - return; + goto out; } /* @@ -294,6 +297,9 @@ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size) valid &= ~feature; } + + out: + VCPU_UNMAP_XSAVE_AREA(v, xstate); } void xsave(struct vcpu *v, uint64_t mask) From patchwork Fri Jan 10 13:28:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934647 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 5FBEBE7719E for ; Fri, 10 Jan 2025 13:29:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869517.1281002 (Exim 4.92) (envelope-from ) id 1tWF4f-0002lq-V1; Fri, 10 Jan 2025 13:29:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869517.1281002; Fri, 10 Jan 2025 13:29:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4f-0002l8-Qf; Fri, 10 Jan 2025 13:29:17 +0000 Received: by outflank-mailman (input) for mailman id 869517; Fri, 10 Jan 2025 13:29:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4e-0001QR-GE for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:16 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e33d4457-cf56-11ef-a0df-8be0dac302b0; Fri, 10 Jan 2025 14:29:15 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5d3dce16a3dso3707488a12.1 for ; Fri, 10 Jan 2025 05:29:16 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:14 -0800 (PST) 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" X-Inumbo-ID: e33d4457-cf56-11ef-a0df-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515755; x=1737120555; 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=RqLvtnGygQhpjVsvp9h9as+dqMu10ap3I0KwRn4gBrU=; b=jRGTW/Pc7/13lWxrUuXVe145yOiFaChY8Lq/aS57KiSuX8T0FQsjEzHN9jmMInvum/ uSa4zbMULN517N0MrAeaa8NR9Y1h1aeHV/Man9Px0hSFtRLkzW6BZM5toyxJaibT4HEN qbUDlKvppe/BsZj1dEyWAHQU6gVIiUIfWbi/0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515755; x=1737120555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RqLvtnGygQhpjVsvp9h9as+dqMu10ap3I0KwRn4gBrU=; b=t0DdO4mQIVZ7wcuoeeG8BOoSaFgaRr25UmqBL/uHBZMap5iN6e/WNUHYhX+R1t6Xaq vi9y+eLdoCAWci+6jmEKhMf1sB+u2LnhTpA6iirR3dQPtOYAOlQd8sYbLAIku6o/rYx4 JQAxj/MkReZwBMZaohrGBcDxiWOgusFBp+IGMsxc+SWbBN+oHQhQDzxeBm1FQqaP3Qnh IAm8mQ/25oAat2gjCvlQRQOKoGHVDqEsilkvx7hBcq9+Cp/9pUyWy/PDNTLxKyyemqhX ThPk4781aFg7j6EVe2vRVd72Bw6+iQqLBcUq8QeyzPF50PClDMhzJMeYgZALtsIIBokY wUEw== X-Gm-Message-State: AOJu0Yw6+e2XcQ4oG5QsMTOIHO7PAlXMYn2mvZEXUCCFpGUZt13Mhxic Xzsfcf/BDfj8bztvWHqQw324tM0XoXtphGzSaAxpZeVUzOS+WU/c2sT0DC16WmdkOrEUN2LmlPT SwiY8VQ== X-Gm-Gg: ASbGnctFfibL85alxTTccO4PG4f03t3EB5yNovyDBhtQ/Hydp9xF68ifpPMLUkMncXH jvYmL2rsXgEha0lqhWJVTKVqIca/ZTjFXKB4P1KDbstdMZ+Kv5vYv1ZpSpfTdZ1kI+YxZOskU4H R6N94Qf+Z3k9bWn6lPSqjGpy0JwX7Idk6twIQvHT7/wSgNiXz7qa/MsiBbjygYJ2BdpzwWEFo2v /K3aJ7ORxFPg7FJHlmXwk1+9vl0SCDNr/ErZXxjN6j8UbIMUqUo87EUnnM935VEbzYl49zUKUQP y3w= X-Google-Smtp-Source: AGHT+IEUzU/9TuxG5IxaDVVK7OZ7dMFL9qCGMhFZl/jaqgzNc7UBjeNpP97oNPvy+m/qQtqKPk4Isw== X-Received: by 2002:a05:6402:4408:b0:5d3:eb50:4e33 with SMTP id 4fb4d7f45d1cf-5d9861d1511mr6241934a12.5.1736515755264; Fri, 10 Jan 2025 05:29:15 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 08/12] x86/emulator: Refactor FXSAVE_AREA to use wrappers Date: Fri, 10 Jan 2025 13:28:19 +0000 Message-ID: <20250110132823.24348-9-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Adds an UNMAP primitive to make use of vcpu_unmap_xsave_area() when linked into xen. unmap is a no-op during tests. Signed-off-by: Alejandro Vallejo --- v2->v3: * Fixed typo in first parameter of UNMAP_FXSAVE_AREA. * Added Parenthesis around "x" in #else's UNMAP_FXSAVE_AREA(x) v1->v2: * Added comments highlighting fastpath on `current` --- xen/arch/x86/x86_emulate/blk.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/x86_emulate/blk.c b/xen/arch/x86/x86_emulate/blk.c index 08a05f8453f7..11b16aeaec39 100644 --- a/xen/arch/x86/x86_emulate/blk.c +++ b/xen/arch/x86/x86_emulate/blk.c @@ -11,9 +11,12 @@ !defined(X86EMUL_NO_SIMD) # ifdef __XEN__ # include -# define FXSAVE_AREA ((void *)¤t->arch.xsave_area->fpu_sse) +/* Has a fastpath for `current`, so there's no actual map */ +# define FXSAVE_AREA ((void *)VCPU_MAP_XSAVE_AREA(current)) +# define UNMAP_FXSAVE_AREA(x) VCPU_UNMAP_XSAVE_AREA(current, x) # else # define FXSAVE_AREA get_fpu_save_area() +# define UNMAP_FXSAVE_AREA(x) ((void)(x)) # endif #endif @@ -292,6 +295,9 @@ int x86_emul_blk( } else asm volatile ( "fxrstor %0" :: "m" (*fxsr) ); + + UNMAP_FXSAVE_AREA(fxsr); + break; } @@ -320,6 +326,9 @@ int x86_emul_blk( if ( fxsr != ptr ) /* i.e. s->op_bytes < sizeof(*fxsr) */ memcpy(ptr, fxsr, s->op_bytes); + + UNMAP_FXSAVE_AREA(fxsr); + break; } From patchwork Fri Jan 10 13:28:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934648 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 72128E7719C for ; Fri, 10 Jan 2025 13:29:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869519.1281021 (Exim 4.92) (envelope-from ) id 1tWF4i-0003Ja-50; Fri, 10 Jan 2025 13:29:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869519.1281021; Fri, 10 Jan 2025 13:29:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4h-0003Hn-Rz; Fri, 10 Jan 2025 13:29:19 +0000 Received: by outflank-mailman (input) for mailman id 869519; Fri, 10 Jan 2025 13:29:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4g-0001QR-Lh for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:18 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e4913f05-cf56-11ef-a0df-8be0dac302b0; Fri, 10 Jan 2025 14:29:18 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5d982de9547so3863734a12.2 for ; Fri, 10 Jan 2025 05:29:18 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:16 -0800 (PST) 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" X-Inumbo-ID: e4913f05-cf56-11ef-a0df-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515757; x=1737120557; 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=NBkiVpHM8v5vp8P31Jsr5IhRd2sJbMgPGREzQchfE+0=; b=USmORQwaLa7l5xaHIvGC5nila+X+hoOxASxsLKn7L1ZzwocqC5d+8F80QxrpbTp2le Zbs6QCyN4RpdTy6fgB42x7rWe02U29rXpvg3pH01/z09ZTQwOWYMVNqv66v9bllHgLst 5mFTdptrcOmG5jVz3mlq2M6tiZamiAYJbQ42A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515757; x=1737120557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NBkiVpHM8v5vp8P31Jsr5IhRd2sJbMgPGREzQchfE+0=; b=bjUS2f7QDqSzaVBIwud6AUXRM8+UYvKT7HYjRuf23KCXLfB3pd2usA0h73jtAk0FTg W0EstrFc/1FEe4DWqjhSWOFlKgp0EBODzWPp1piKlqIzii0BvRIR2862AJRwcl5ogogD u2I2yqhXKY7Eq06TWj9OJyCFDjxQJ1dZAsJZK9WVXrvRcAtQWiMTU2vicUCuWNxJDXY5 Uaot6SWlgMRz/NBFrWdgvQu/7gdXY39z5HyQroygyPd2h442AwFy9grHxYYC6Uiv8ZFX 3vRfpbLSANvkIf1gnTWBa8wXS4eMT4jV4ftWEZGWK3Z+C5A5/3AR4Xgl4nnvoDmNiLN8 34UQ== X-Gm-Message-State: AOJu0YwtZdliDxWsPBTmRo0jLWZuuzTFv6gEpACffOFCp7Dt5DXStL4z wM0yPhzh/mAgZFOQ7SQOCnlzXXgYSR43wvdocKJiXp5qXIxjLRkGqdt+Lkos5m/fmMUKPiM3HER dlgP65w== X-Gm-Gg: ASbGncs8tROJZQpTq/OZ3X4r8xjS1ATha8gtOMMz3PSJ8QJ/JkDu+Zin8aAJlit8MSF aNtBDWFZchdupHldistHS7vgKOkRbgrI2sDIEPTLKT4hOjZUej7u578mXUG+KU2dnzlNIx+Q2X9 w8hunko0lWlOcA4DmIJZfbHXWdJKtuIMoWdty/8EOn4009r7HUHQA/aeNNwgCJyNo3r3uFumqJe b+L0YK/d0u/jgy+xRr1ipUs4vlsCMY6O3Gb2eQhRJVm0HWuSqL/b2l7Gb5eL4AmovdTWAte9f9x /M4= X-Google-Smtp-Source: AGHT+IF2kUi1l15Plt8UytnrHFbBfLL+/GMd8KtcoOhar7B79Utam/Ngh0jJKQmV4Jh1Dkwci5S5XA== X-Received: by 2002:a05:6402:2746:b0:5d9:a85:1a59 with SMTP id 4fb4d7f45d1cf-5d972e4769bmr9812304a12.27.1736515757431; Fri, 10 Jan 2025 05:29:17 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 09/12] x86/mpx: Map/unmap xsave area in in read_bndcfgu() Date: Fri, 10 Jan 2025 13:28:20 +0000 Message-ID: <20250110132823.24348-10-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2->v3: * No change v1->v2: * s/ret/bndcfgu --- xen/arch/x86/xstate.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 3d249518a1b7..2003ba664594 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1024,9 +1024,10 @@ int handle_xsetbv(u32 index, u64 new_bv) uint64_t read_bndcfgu(void) { + uint64_t bndcfgu = 0; unsigned long cr0 = read_cr0(); - struct xsave_struct *xstate - = idle_vcpu[smp_processor_id()]->arch.xsave_area; + struct vcpu *v = idle_vcpu[smp_processor_id()]; + struct xsave_struct *xstate = VCPU_MAP_XSAVE_AREA(v); const struct xstate_bndcsr *bndcsr; ASSERT(cpu_has_mpx); @@ -1052,7 +1053,12 @@ uint64_t read_bndcfgu(void) if ( cr0 & X86_CR0_TS ) write_cr0(cr0); - return xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ? bndcsr->bndcfgu : 0; + if ( xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ) + bndcfgu = bndcsr->bndcfgu; + + VCPU_UNMAP_XSAVE_AREA(v, xstate); + + return bndcfgu; } void xstate_set_init(uint64_t mask) From patchwork Fri Jan 10 13:28:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934649 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 93AA9E77188 for ; Fri, 10 Jan 2025 13:29:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869521.1281030 (Exim 4.92) (envelope-from ) id 1tWF4j-0003fx-HJ; Fri, 10 Jan 2025 13:29:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869521.1281030; Fri, 10 Jan 2025 13:29:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4j-0003dN-B3; Fri, 10 Jan 2025 13:29:21 +0000 Received: by outflank-mailman (input) for mailman id 869521; Fri, 10 Jan 2025 13:29:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4i-0001QR-CU for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:20 +0000 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [2a00:1450:4864:20::542]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e58aad29-cf56-11ef-a0df-8be0dac302b0; Fri, 10 Jan 2025 14:29:19 +0100 (CET) Received: by mail-ed1-x542.google.com with SMTP id 4fb4d7f45d1cf-5d414b8af7bso3534644a12.0 for ; Fri, 10 Jan 2025 05:29:19 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:18 -0800 (PST) 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" X-Inumbo-ID: e58aad29-cf56-11ef-a0df-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515759; x=1737120559; 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=f2RsoCzP1jEEvrkQ7ie+7psyxTtmQ+XSlhDRoNh8Ta4=; b=GXLxss7JQtIMQ5qxRdi32eG7uMDxBFRlL20VpnyOPep68jhkhOG0Y5jorcTKoRnaW2 Ho6aREBD+KaGTQuAE+Qzf6uBbYVguACNXEOV0Qn+aMX2zaaIQsg6k1ftBeM7/RB2hWSa udW3OIHQXiKAwQh3dOPwL4yzUgpRdFzpD97Xg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515759; x=1737120559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f2RsoCzP1jEEvrkQ7ie+7psyxTtmQ+XSlhDRoNh8Ta4=; b=MeZ8Oku6qLy93J8cMN3br67vLbasrUScHjHOmDnmsboK0VBXAfFykrGMrC1HFGztmm hf64XCsDjoaHNYmE69Ub7VYR0Sgnp7rFwvry0KW8oAAG3ix5tziBm0XQAjnLPUkSQ2EN oBxAqD6CDavR8rrW5CCP1sByaWAm3yMPaPZFg2SJ3XZxwEI3FmK0mUbU8e/CnhBUaZ6r ctzCkMD7hF+ioL3vErXCpNfDFDN1iS+aeDXdjYbhbC7+tm07FcB6336y+54tJG7rpuQt LynyHdztZY3F4bKaM2rvB08XToVlY4DmZ4/bLNb1+3RWbPNkVI7tICsth5Uqe52IYy8Q k8bw== X-Gm-Message-State: AOJu0YwTJa3Fp6QIvBvpGbNguUNP0FJgi1lFDRVZAbxerobips9Y74Ds H6kDYH5d5nRHgLf+K0ubUurxREvw7140QdhutRPwiMCWqRNpuJNtF1c9nHnSTQfgdate8O1LbHA ATQ734uYa X-Gm-Gg: ASbGncuJMLzX+Og7uTAeAoRMhLoBSL2vxvFxz3e7oGJRdJ96VHOKFd0OTvdCX9MoiFZ pDKMajGtBT1XP29h/QjSV9gD/38bbLzaC/wImPCzR0iTWLT5pGqsvqWrj4S0AisWc/had/mLtov wfZ62EbLyADHOvotrLIvW203E8/EPlQfoLyklIbQ/c8rRdVSClzcravwmqow1w2Pu18jgwaKpWL x+fOOgzMrBTUGG/6/zWWA4IYyW1LkHrgLeE7kvoqVVGrhpbIry+hrmE5j0DtF4qhjky/HkuuHAk 7jY= X-Google-Smtp-Source: AGHT+IF15swdBXE1MFaI32h7Atni7TCGXHlE4Tor2dd8F/fqqD6BOl5NrTMZmikGKgmrRfGNYInbLg== X-Received: by 2002:a05:6402:448e:b0:5d0:c67e:e263 with SMTP id 4fb4d7f45d1cf-5d972e08663mr9043770a12.8.1736515759088; Fri, 10 Jan 2025 05:29:19 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 10/12] x86/fpu: Pass explicit xsave areas to fpu_(f)xsave() Date: Fri, 10 Jan 2025 13:28:21 +0000 Message-ID: <20250110132823.24348-11-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2->v3: * const-ified v in fpu_fxsave() (missing in v2) v1->v2: * const-ified v --- xen/arch/x86/i387.c | 16 ++++++++++------ xen/arch/x86/include/asm/xstate.h | 2 +- xen/arch/x86/xstate.c | 3 +-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 5429531ddd5f..11d06f921269 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -129,7 +129,7 @@ static inline uint64_t vcpu_xsave_mask(const struct vcpu *v) } /* Save x87 extended state */ -static inline void fpu_xsave(struct vcpu *v) +static inline void fpu_xsave(const struct vcpu *v, struct xsave_struct *xsave_area) { bool ok; uint64_t mask = vcpu_xsave_mask(v); @@ -141,15 +141,14 @@ static inline void fpu_xsave(struct vcpu *v) */ ok = set_xcr0(v->arch.xcr0_accum | XSTATE_FP_SSE); ASSERT(ok); - xsave(v, mask); + xsave(v, xsave_area, mask); ok = set_xcr0(v->arch.xcr0 ?: XSTATE_FP_SSE); ASSERT(ok); } /* Save x87 FPU, MMX, SSE and SSE2 state */ -static inline void fpu_fxsave(struct vcpu *v) +static inline void fpu_fxsave(const struct vcpu *v, fpusse_t *fpu_ctxt) { - fpusse_t *fpu_ctxt = &v->arch.xsave_area->fpu_sse; unsigned int fip_width = v->domain->arch.x87_fip_width; if ( fip_width != 4 ) @@ -264,6 +263,8 @@ void vcpu_restore_fpu_lazy(struct vcpu *v) */ static bool _vcpu_save_fpu(struct vcpu *v) { + struct xsave_struct *xsave_area; + if ( !v->fpu_dirtied && !v->arch.nonlazy_xstate_used ) return false; @@ -272,11 +273,14 @@ static bool _vcpu_save_fpu(struct vcpu *v) /* This can happen, if a paravirtualised guest OS has set its CR0.TS. */ clts(); + xsave_area = VCPU_MAP_XSAVE_AREA(v); + if ( cpu_has_xsave ) - fpu_xsave(v); + fpu_xsave(v, xsave_area); else - fpu_fxsave(v); + fpu_fxsave(v, &xsave_area->fpu_sse); + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); v->fpu_dirtied = 0; return true; diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/xstate.h index ab81a4c8527e..87f05dbca6f4 100644 --- a/xen/arch/x86/include/asm/xstate.h +++ b/xen/arch/x86/include/asm/xstate.h @@ -97,7 +97,7 @@ uint64_t get_xcr0(void); void set_msr_xss(u64 xss); uint64_t get_msr_xss(void); uint64_t read_bndcfgu(void); -void xsave(struct vcpu *v, uint64_t mask); +void xsave(const struct vcpu *v, struct xsave_struct *ptr, uint64_t mask); void xrstor(struct vcpu *v, uint64_t mask); void xstate_set_init(uint64_t mask); bool xsave_enabled(const struct vcpu *v); diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 2003ba664594..24053b394200 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -302,9 +302,8 @@ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size) VCPU_UNMAP_XSAVE_AREA(v, xstate); } -void xsave(struct vcpu *v, uint64_t mask) +void xsave(const struct vcpu *v, struct xsave_struct *ptr, uint64_t mask) { - struct xsave_struct *ptr = v->arch.xsave_area; uint32_t hmask = mask >> 32; uint32_t lmask = mask; unsigned int fip_width = v->domain->arch.x87_fip_width; From patchwork Fri Jan 10 13:28:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934651 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 9BD0EE77188 for ; Fri, 10 Jan 2025 13:29:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869527.1281046 (Exim 4.92) (envelope-from ) id 1tWF4n-0004MG-8v; Fri, 10 Jan 2025 13:29:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869527.1281046; Fri, 10 Jan 2025 13:29:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4n-0004Lh-0Z; Fri, 10 Jan 2025 13:29:25 +0000 Received: by outflank-mailman (input) for mailman id 869527; Fri, 10 Jan 2025 13:29:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4l-0000vX-32 for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:23 +0000 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [2a00:1450:4864:20::531]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e695ffc9-cf56-11ef-99a4-01e77a169b0f; Fri, 10 Jan 2025 14:29:21 +0100 (CET) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5d3bbb0f09dso3438940a12.2 for ; Fri, 10 Jan 2025 05:29:21 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:19 -0800 (PST) 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" X-Inumbo-ID: e695ffc9-cf56-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515761; x=1737120561; 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=GI//zXjGi7gOKfBwz6cTp3sciH/k2uuKEBMoWxpEBrQ=; b=IVpQF2uNpYLUNdDE8CeswGFQI3fv/YRCcOrUp0gOtsVDJWDzJTTmIVn1xXOcljxreB UbML3L8cgBDo+9omI6ZtMV++j9iil/FFy/A8sPAxhmV9zdXL22CWGt1+rLqVVxJp1q9E PNGsClpKL0md/7WQLzjcyMv2xi5sA8I8sLPuc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515761; x=1737120561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GI//zXjGi7gOKfBwz6cTp3sciH/k2uuKEBMoWxpEBrQ=; b=ogTiPP+Ww64VbJgQj3U1ThZmeUu5A2zqO5MvUTWu/eVbUfy/CG+WqjP/ZGVphd/ZbX Misnqzk6GiAYKOyqh8kuyNK88OJwTSZWU7NtO1HPdM9yw462x8MW1m8iUk3R9Lb+g0Zl lkFouE5bhQ+sVlN1VWR2b8QBdZIt58CezFpnepujR6u1hFYD6kg9qyj+KiHNTxHw/0mu ozqFYOt7MATXretl32Ah3rzDBoVTF3sKXq7FkfxLsOSibpoxjLtjNGx9O59ROmto0Z08 RX7E380JcHnEYRY1vvz6L2aN00SfTGN64HZFJzV3mKSzxuyrLN1YcTbE35YbjmwGP0++ uYPQ== X-Gm-Message-State: AOJu0Yw+A3Gh2+A4ThGnxqzxXRuAl6j11rJpL1ccQmI5RoKl07iwLpEw 3oQ3Stai7VwJUxBeCUy6KBWMHAOlmfPImByXhYcs0DwOezcN3xeFiFBIvSqdYOqNsaN9yY00SAR 7DPOnMQ== X-Gm-Gg: ASbGncuG7F/rODQe5BoQ2lOOqvsZ5P9TIjlpgE7KQpsjjCDqEK0qXgQGu0VpwRfX+bJ qgils5DhbX76IEUO9rmhg7CZgv3iMii78nLpoqydvcXg92FTf2N25vEesMKL9VBylwTT5CtUjBV h0xcuULFEGl2Aih+87R3dsoxTJYgLoFD/09juj8ZgBG1uM32pVDmxwqLBsfk0bNQkwzK/as0EwF 8K4o5Ih0Z1Q/UCis1rQKfXFVudYq4LTY6FOHVDhhrtULx08UwlHZi+FKwpQAGag6Xp/6Fv16FpB xvE= X-Google-Smtp-Source: AGHT+IHl+QVKSzvBQaSukQzB8NUKHv3g4BYe4c8rMerq7z2zRKYMYXHuIotBpbj7sN26MOkPWBfcVg== X-Received: by 2002:a05:6402:4414:b0:5d9:a84:d4b6 with SMTP id 4fb4d7f45d1cf-5d972d26ac2mr8691628a12.0.1736515760631; Fri, 10 Jan 2025 05:29:20 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 11/12] x86/fpu: Pass explicit xsave areas to fpu_(f)xrstor() Date: Fri, 10 Jan 2025 13:28:22 +0000 Message-ID: <20250110132823.24348-12-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2->v3: * const-ified v in fpu_xrstor() * Removed v in fpu_fxrstor() v1->v2: * const-ified v in xrstor() ( it was incorrectly reported in v2 as it being fpu_xrstor() ) --- xen/arch/x86/i387.c | 26 ++++++++++++++++---------- xen/arch/x86/include/asm/xstate.h | 2 +- xen/arch/x86/xstate.c | 10 ++++++---- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 11d06f921269..943ae668606f 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -20,7 +20,8 @@ /* FPU Restore Functions */ /*******************************/ /* Restore x87 extended state */ -static inline void fpu_xrstor(struct vcpu *v, uint64_t mask) +static inline void fpu_xrstor(const struct vcpu *v, + struct xsave_struct *xsave_area, uint64_t mask) { bool ok; @@ -30,16 +31,14 @@ static inline void fpu_xrstor(struct vcpu *v, uint64_t mask) */ ok = set_xcr0(v->arch.xcr0_accum | XSTATE_FP_SSE); ASSERT(ok); - xrstor(v, mask); + xrstor(v, xsave_area, mask); ok = set_xcr0(v->arch.xcr0 ?: XSTATE_FP_SSE); ASSERT(ok); } /* Restore x87 FPU, MMX, SSE and SSE2 state */ -static inline void fpu_fxrstor(struct vcpu *v) +static inline void fpu_fxrstor(const fpusse_t *fpu_ctxt) { - const fpusse_t *fpu_ctxt = &v->arch.xsave_area->fpu_sse; - /* * Some CPUs don't save/restore FDP/FIP/FOP unless an exception * is pending. Clear the x87 state here by setting it to fixed @@ -195,6 +194,8 @@ static inline void fpu_fxsave(const struct vcpu *v, fpusse_t *fpu_ctxt) /* Restore FPU state whenever VCPU is schduled in. */ void vcpu_restore_fpu_nonlazy(struct vcpu *v, bool need_stts) { + struct xsave_struct *xsave_area; + /* Restore nonlazy extended state (i.e. parts not tracked by CR0.TS). */ if ( !v->arch.fully_eager_fpu && !v->arch.nonlazy_xstate_used ) goto maybe_stts; @@ -209,12 +210,13 @@ void vcpu_restore_fpu_nonlazy(struct vcpu *v, bool need_stts) * above) we also need to restore full state, to prevent subsequently * saving state belonging to another vCPU. */ + xsave_area = VCPU_MAP_XSAVE_AREA(v); if ( v->arch.fully_eager_fpu || xstate_all(v) ) { if ( cpu_has_xsave ) - fpu_xrstor(v, XSTATE_ALL); + fpu_xrstor(v, xsave_area, XSTATE_ALL); else - fpu_fxrstor(v); + fpu_fxrstor(&xsave_area->fpu_sse); v->fpu_initialised = 1; v->fpu_dirtied = 1; @@ -224,9 +226,10 @@ void vcpu_restore_fpu_nonlazy(struct vcpu *v, bool need_stts) } else { - fpu_xrstor(v, XSTATE_NONLAZY); + fpu_xrstor(v, xsave_area, XSTATE_NONLAZY); need_stts = true; } + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); maybe_stts: if ( need_stts ) @@ -238,6 +241,7 @@ void vcpu_restore_fpu_nonlazy(struct vcpu *v, bool need_stts) */ void vcpu_restore_fpu_lazy(struct vcpu *v) { + struct xsave_struct *xsave_area; ASSERT(!is_idle_vcpu(v)); /* Avoid recursion. */ @@ -248,10 +252,12 @@ void vcpu_restore_fpu_lazy(struct vcpu *v) ASSERT(!v->arch.fully_eager_fpu); + xsave_area = VCPU_MAP_XSAVE_AREA(v); if ( cpu_has_xsave ) - fpu_xrstor(v, XSTATE_LAZY); + fpu_xrstor(v, xsave_area, XSTATE_LAZY); else - fpu_fxrstor(v); + fpu_fxrstor(&xsave_area->fpu_sse); + VCPU_UNMAP_XSAVE_AREA(v, xsave_area); v->fpu_initialised = 1; v->fpu_dirtied = 1; diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/xstate.h index 87f05dbca6f4..7d160d2b54be 100644 --- a/xen/arch/x86/include/asm/xstate.h +++ b/xen/arch/x86/include/asm/xstate.h @@ -98,7 +98,7 @@ void set_msr_xss(u64 xss); uint64_t get_msr_xss(void); uint64_t read_bndcfgu(void); void xsave(const struct vcpu *v, struct xsave_struct *ptr, uint64_t mask); -void xrstor(struct vcpu *v, uint64_t mask); +void xrstor(const struct vcpu *v, struct xsave_struct *ptr, uint64_t mask); void xstate_set_init(uint64_t mask); bool xsave_enabled(const struct vcpu *v); int __must_check validate_xstate(const struct domain *d, diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 24053b394200..3d4fb7664c5f 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -376,11 +376,10 @@ void xsave(const struct vcpu *v, struct xsave_struct *ptr, uint64_t mask) ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET] = fip_width; } -void xrstor(struct vcpu *v, uint64_t mask) +void xrstor(const struct vcpu *v, struct xsave_struct *ptr, uint64_t mask) { uint32_t hmask = mask >> 32; uint32_t lmask = mask; - struct xsave_struct *ptr = v->arch.xsave_area; unsigned int faults, prev_faults; /* @@ -994,6 +993,7 @@ int handle_xsetbv(u32 index, u64 new_bv) mask &= curr->fpu_dirtied ? ~XSTATE_FP_SSE : XSTATE_NONLAZY; if ( mask ) { + struct xsave_struct *xsave_area = VCPU_MAP_XSAVE_AREA(curr); unsigned long cr0 = read_cr0(); clts(); @@ -1013,7 +1013,9 @@ int handle_xsetbv(u32 index, u64 new_bv) curr->fpu_dirtied = 1; cr0 &= ~X86_CR0_TS; } - xrstor(curr, mask); + xrstor(curr, xsave_area, mask); + VCPU_UNMAP_XSAVE_AREA(curr, xsave_area); + if ( cr0 & X86_CR0_TS ) write_cr0(cr0); } @@ -1080,7 +1082,7 @@ void xstate_set_init(uint64_t mask) xstate = VCPU_MAP_XSAVE_AREA(v); memset(&xstate->xsave_hdr, 0, sizeof(xstate->xsave_hdr)); - xrstor(v, mask); + xrstor(v, xstate, mask); VCPU_UNMAP_XSAVE_AREA(v, xstate); if ( cr0 & X86_CR0_TS ) From patchwork Fri Jan 10 13:28:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13934650 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 AFA67E7719C for ; Fri, 10 Jan 2025 13:29:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.869526.1281043 (Exim 4.92) (envelope-from ) id 1tWF4m-0004IM-Ps; Fri, 10 Jan 2025 13:29:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 869526.1281043; Fri, 10 Jan 2025 13:29:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4m-0004I0-Kl; Fri, 10 Jan 2025 13:29:24 +0000 Received: by outflank-mailman (input) for mailman id 869526; Fri, 10 Jan 2025 13:29:23 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tWF4l-0001QR-5I for xen-devel@lists.xenproject.org; Fri, 10 Jan 2025 13:29:23 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e723c13e-cf56-11ef-a0df-8be0dac302b0; Fri, 10 Jan 2025 14:29:22 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5d7e3f1fc01so4018560a12.2 for ; Fri, 10 Jan 2025 05:29:22 -0800 (PST) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c98d6sm1589297a12.35.2025.01.10.05.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:29:21 -0800 (PST) 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" X-Inumbo-ID: e723c13e-cf56-11ef-a0df-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1736515762; x=1737120562; 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=TGYGQF82WrUmaE3ckte9a2eG993H0v3sPPUj77Kpcmw=; b=Cr83ioQvAcp9FvPphkT8iLQsf2VpYo10ZezFRZ9EPAHxub3qbLyUoi1uxGy72TTRvp to9aDP776+EKGZn6WzPCxNkn4FBg/EpFFeCr8199osQZBFPoIeXyticOMBtnZFlh3Qzb f/2ci0586FJ7pPcmy4+bz+iRP8C8yn45wnwjI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515762; x=1737120562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TGYGQF82WrUmaE3ckte9a2eG993H0v3sPPUj77Kpcmw=; b=I4EJYEBukDpM4TAOTZlL3sdR01BVTK5ZvMTgD5VKEvm3aTwHFhkkp9oP+otEs3o1Kl t5u3ZdXWkI+VBrtOUxjjLNc88kzqsEZM1zXyGLTjKSV6tz7Hf8QdJvCBGJYF/VK1Dv2r fmhUn80kC/1PxMtJOgnMno5VqUJ6iZ9oGBLQjEwm0CSwotIMoOT6nszsddsd6ZiQAel6 lSv/sbkGNBQYjgbs00d7X7Cm7sJhzDW52k8IxFL7UWNL7S7Mmw4d5kobP55QXAuNWVZh hVCv+rQFzA0vmNAt7k3dx0qMAck8OkpmXV4y9JdWWzdWHAadjT+ydkV9gZSn9XDKdV1I 4xdg== X-Gm-Message-State: AOJu0YzfBkjExomFQVAElE1J2aJQ7cOdn60Zpyco7E9eQXVNwbNbkHdf DOr1bbJhrL/gxJMsC2KHjcI4sJKeQnumGFUaXg0rnC1Xj31UkauZjEv9pvNmaCQmklsFyDPyCHn lcsOsTA== X-Gm-Gg: ASbGncsN5s72xdY77DUsQW+uE6sAURCK8zm6qrQNGq67qAfxdOpPjtCecRTNpV7ARyd 5iW+KzbuxOTep/2w7LAOA2TGgZdMJu5IirLiZM+sQO5QouKgzGCKSyfxZzYt0hKJBhu+L4+le5C b1+HA6qBUXWxVWErfS2ZF7dqh6Jo0rYdchoVBihewFvRSe/hJrBU+hHi3PNVA1//KRxPGEzowv9 NiDekHw3Pm9zmTgGjoJSEVxuFPmDiqpyNXl4OqLRhXn8E0qRYT2ZlT4UCcWRtkpAIofW4sM8qNa xG4= X-Google-Smtp-Source: AGHT+IHm6oaJ8YwWbN8mvMBsk0Ry+E2PKI9C0KwkXDe5NuUIwFuRQ4O/29eudYZew7AzQZ2WhbARTA== X-Received: by 2002:a17:907:c815:b0:ab2:c78f:e4ae with SMTP id a640c23a62f3a-ab2c78fe63dmr536582966b.20.1736515761703; Fri, 10 Jan 2025 05:29:21 -0800 (PST) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v3 12/12] x86/xstate: Make xstate_all() and vcpu_xsave_mask() take explicit xstate Date: Fri, 10 Jan 2025 13:28:23 +0000 Message-ID: <20250110132823.24348-13-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110132823.24348-1-alejandro.vallejo@cloud.com> References: <20250110132823.24348-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v2->v3: * Added A-by --- xen/arch/x86/i387.c | 9 +++++---- xen/arch/x86/include/asm/xstate.h | 5 +++-- xen/arch/x86/xstate.c | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 943ae668606f..8120a6a4afc0 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -107,7 +107,8 @@ static inline void fpu_fxrstor(const fpusse_t *fpu_ctxt) /* FPU Save Functions */ /*******************************/ -static inline uint64_t vcpu_xsave_mask(const struct vcpu *v) +static inline uint64_t vcpu_xsave_mask(const struct vcpu *v, + const struct xsave_struct *xsave_area) { if ( v->fpu_dirtied ) return v->arch.nonlazy_xstate_used ? XSTATE_ALL : XSTATE_LAZY; @@ -124,14 +125,14 @@ static inline uint64_t vcpu_xsave_mask(const struct vcpu *v) * XSTATE_FP_SSE), vcpu_xsave_mask will return XSTATE_ALL. Otherwise * return XSTATE_NONLAZY. */ - return xstate_all(v) ? XSTATE_ALL : XSTATE_NONLAZY; + return xstate_all(v, xsave_area) ? XSTATE_ALL : XSTATE_NONLAZY; } /* Save x87 extended state */ static inline void fpu_xsave(const struct vcpu *v, struct xsave_struct *xsave_area) { bool ok; - uint64_t mask = vcpu_xsave_mask(v); + uint64_t mask = vcpu_xsave_mask(v, xsave_area); ASSERT(mask); /* @@ -211,7 +212,7 @@ void vcpu_restore_fpu_nonlazy(struct vcpu *v, bool need_stts) * saving state belonging to another vCPU. */ xsave_area = VCPU_MAP_XSAVE_AREA(v); - if ( v->arch.fully_eager_fpu || xstate_all(v) ) + if ( v->arch.fully_eager_fpu || xstate_all(v, xsave_area) ) { if ( cpu_has_xsave ) fpu_xrstor(v, xsave_area, XSTATE_ALL); diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/xstate.h index 7d160d2b54be..a1b188537c15 100644 --- a/xen/arch/x86/include/asm/xstate.h +++ b/xen/arch/x86/include/asm/xstate.h @@ -132,14 +132,15 @@ xsave_area_compressed(const struct xsave_struct *xsave_area) return xsave_area->xsave_hdr.xcomp_bv & XSTATE_COMPACTION_ENABLED; } -static inline bool xstate_all(const struct vcpu *v) +static inline bool xstate_all(const struct vcpu *v, + const struct xsave_struct *xsave_area) { /* * XSTATE_FP_SSE may be excluded, because the offsets of XSTATE_FP_SSE * (in the legacy region of xsave area) are fixed, so saving * XSTATE_FP_SSE will not cause overwriting problem with XSAVES/XSAVEC. */ - return xsave_area_compressed(v->arch.xsave_area) && + return xsave_area_compressed(xsave_area) && (v->arch.xcr0_accum & XSTATE_LAZY & ~XSTATE_FP_SSE); } diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 3d4fb7664c5f..b204147815c3 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1005,7 +1005,7 @@ int handle_xsetbv(u32 index, u64 new_bv) asm ( "stmxcsr %0" : "=m" (xsave_area->fpu_sse.mxcsr) ); VCPU_UNMAP_XSAVE_AREA(curr, xsave_area); } - else if ( xstate_all(curr) ) + else if ( xstate_all(curr, xsave_area) ) { /* See the comment in i387.c:vcpu_restore_fpu_eager(). */ mask |= XSTATE_LAZY;