From patchwork Tue Nov 5 14:32:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863035 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 8F9ACD2B931 for ; Tue, 5 Nov 2024 14:34:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830258.1245210 (Exim 4.92) (envelope-from ) id 1t8Kd0-0002ff-Qt; Tue, 05 Nov 2024 14:33:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830258.1245210; Tue, 05 Nov 2024 14:33:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd0-0002eV-No; Tue, 05 Nov 2024 14:33:54 +0000 Received: by outflank-mailman (input) for mailman id 830258; Tue, 05 Nov 2024 14:33:53 +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 1t8Kcz-0002Lm-KR for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:53 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f8fc86c5-9b82-11ef-99a3-01e77a169b0f; Tue, 05 Nov 2024 15:33:49 +0100 (CET) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c937b5169cso600769a12.1 for ; Tue, 05 Nov 2024 06:33:49 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:48 -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: f8fc86c5-9b82-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MjkiLCJoZWxvIjoibWFpbC1lZDEteDUyOS5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImY4ZmM4NmM1LTliODItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODE3MjI5LjkxNDQ3MSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817229; x=1731422029; 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=lm70mwHIeRKoNhCCFejzjDU9gu+VjbCXPS3BQfLbce0=; b=Jbq9NOlxXEKCEAVMutHvn3NY6gBcL3xu8E0LACqzgbFFn7NJ6XQJwmmS/Wc2UEG5Q2 XqoNUPVGHZ8LNnwA39RKjnXJheVvKMmpy3WZBHoR6W0juYBWV2HHMIRI0FRmK4Ld1jIu kuDd87x620yko9ktevApdRkVk2S9y18QyHzew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817229; x=1731422029; 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=lm70mwHIeRKoNhCCFejzjDU9gu+VjbCXPS3BQfLbce0=; b=OZcdzPBYWWNblG8dBSaBhSnMbR8qBqD9UklS1N/sZoAJ22qyK3vpzOjB+fiSMQ4d+l DBvvfm0z5QWtRJtQLHnO6tCZ6Nn4IjsW9LgQClMu0wUbnijQBlFcXorYN/4suo1Xeh/J p64rv9ekxPU5f4T16aar+8DdpQyCU8f7xh6x7KkupzwdmK/qDlKDxFm2xq/+2mKgXnOq mMIe7EQMUMu/cveQx1faV33Rfc4O4I2pS55tZYF7xrrgatPuLbiS0vWm6f38hRX3rXUW tZDSRz5PrTqPiQr5BlBr+RR+FsDC5aAnFobQ6043/FBEbG6y4cYLWYDfOtIXutI+O39b sudQ== X-Gm-Message-State: AOJu0Yx4cWR4QdHhqN7eJ5nYIj5rPWDPfGQwpyOCv7YmfxFW73b/3GrX PWcZ/ffbkEwjt68MN9iIe/UhIfKDGpGG8MDI+TYId/a26vPVhz/6LPuc6zQMqOSs1/BzSq+IMKu 6 X-Google-Smtp-Source: AGHT+IEhWx2RuS/BYIBWDBc6maT4rwV0tb/DwlYlZRoeFkV4ZYnjAKsX+HD1obBYMGsMYslSbg1VMw== X-Received: by 2002:a05:6402:2748:b0:5ce:c7ce:145e with SMTP id 4fb4d7f45d1cf-5cec7ce17ccmr12100578a12.14.1730817228923; Tue, 05 Nov 2024 06:33:48 -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 v2 01/13] x86/xstate: Remove stale assertions in fpu_x{rstor,save}() Date: Tue, 5 Nov 2024 14:32:58 +0000 Message-ID: <20241105143310.28301-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 After edb48e76458b("x86/fpu: Combine fpu_ctxt and xsave_area in arch_vcpu"), v->arch.xsave_area is always present and we can just remove these asserts. Fixes: edb48e76458b("x86/fpu: Combine fpu_ctxt and xsave_area in arch_vcpu") Signed-off-by: Alejandro Vallejo Acked-by: Jan Beulich --- v2: * Remove asserts rather than refactor them. * Trimmed and adjusted commit message --- xen/arch/x86/i387.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 83f9b2502bff..3add0025e495 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -24,7 +24,6 @@ static inline void fpu_xrstor(struct vcpu *v, uint64_t mask) { bool ok; - ASSERT(v->arch.xsave_area); /* * XCR0 normally represents what guest OS set. In case of Xen itself, * we set the accumulated feature mask before doing save/restore. @@ -136,7 +135,6 @@ static inline void fpu_xsave(struct vcpu *v) uint64_t mask = vcpu_xsave_mask(v); ASSERT(mask); - ASSERT(v->arch.xsave_area); /* * XCR0 normally represents what guest OS set. In case of Xen itself, * we set the accumulated feature mask before doing save/restore. From patchwork Tue Nov 5 14:32:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863040 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 87589D2B92E for ; Tue, 5 Nov 2024 14:34:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830257.1245205 (Exim 4.92) (envelope-from ) id 1t8Kd0-0002YW-EE; Tue, 05 Nov 2024 14:33:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830257.1245205; Tue, 05 Nov 2024 14:33:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd0-0002YP-BF; Tue, 05 Nov 2024 14:33:54 +0000 Received: by outflank-mailman (input) for mailman id 830257; Tue, 05 Nov 2024 14:33:53 +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 1t8Kcz-0002K5-4A for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:53 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f998a050-9b82-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:33:50 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c941623a5aso11544248a12.0 for ; Tue, 05 Nov 2024 06:33:50 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:49 -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: f998a050-9b82-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzQiLCJoZWxvIjoibWFpbC1lZDEteDUzNC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImY5OThhMDUwLTliODItMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjMwLjg5NTk1NSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817230; x=1731422030; 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=B5MI75e4+hOjaOxFZKHpo9oTq8hdhATr+ZHahTSCs6U=; b=PKYz8U1znWxozUwaYYMfdTV77Kp4otFElDwOVHx9mhAklzIW8t3iYXuGIFFlUauKvZ icbQFsQYFxCqjYNi8BZ90e/JEtJtW0EfsjGp71yoAyWp67/baPa8GamEs9UdQaWoDl2y Zstprrl5ANbXnZBF3lL6Ply/DVTmdKjMCiRl4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817230; x=1731422030; 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=B5MI75e4+hOjaOxFZKHpo9oTq8hdhATr+ZHahTSCs6U=; b=EenDw7AmIkEWo7D7xbVtQjFsouzGpB85c4nWAjjQiD0ilcUJ9teNdfwQ+I0Q6NKeyO abhp8TTS+mYEHKI01XjS3sBSjWHNnuF9BuPK3HJjQumtAHUjd+iqP3zFLOUl+dkuP3Iu 5W9uKsJr5Ar0vmExlHWmHy6EV3qsQvzDauS98a/8P3TMhGqknx+9avUnutvqkt+L4Znx W/0aXPe5/4WxCA/16ma4XsmTUOAi6SrlwjZy9LQRXX9jQAkOuOuG/oEX2NvpJvRzUGAF IiYPCCO489oXyJWfbJ8vX/hjw88emR7cXZfwLl/2NbsdZg39J4iH2OWdurDVoQv1Y6I2 eOWA== X-Gm-Message-State: AOJu0Yz8+VZ9p0dB0/+4AH4lh5k0u3g0002DMfL0txvyQnp1xKjq18UI SzccX8VY2U/mngwmNzisKX6DLepYkkcKyFc0ahxKCkg/5XuhGmc6yp03hgZCNA40EX/9e8LcOUk q X-Google-Smtp-Source: AGHT+IElpRYa2awz+b5ZiTEQCetsqe4Q4xDPQIeYnAy0JSjDCDL+J66ma0sNHWP3O0Gl53xOoGT0Pg== X-Received: by 2002:a05:6402:51c7:b0:5ce:df98:ea7d with SMTP id 4fb4d7f45d1cf-5cedf98eb22mr4487574a12.8.1730817229985; Tue, 05 Nov 2024 06:33:49 -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 v2 02/13] x86/xstate: Create map/unmap primitives for xsave areas Date: Tue, 5 Nov 2024 14:32:59 +0000 Message-ID: <20241105143310.28301-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-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: * 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..6b0daff0aeec 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) ({ (x) = NULL; }) + #endif /* __ASM_XSTATE_H */ From patchwork Tue Nov 5 14:33:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863036 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 2131FD2B933 for ; Tue, 5 Nov 2024 14:34:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830260.1245235 (Exim 4.92) (envelope-from ) id 1t8Kd3-0003Hp-Bz; Tue, 05 Nov 2024 14:33:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830260.1245235; Tue, 05 Nov 2024 14:33:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd3-0003HX-7B; Tue, 05 Nov 2024 14:33:57 +0000 Received: by outflank-mailman (input) for mailman id 830260; Tue, 05 Nov 2024 14:33:55 +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 1t8Kd1-0002K5-Ig for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:55 +0000 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [2a00:1450:4864:20::530]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id faffc597-9b82-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:33:53 +0100 (CET) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5c94861ee25so2968683a12.0 for ; Tue, 05 Nov 2024 06:33:53 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:50 -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: faffc597-9b82-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzAiLCJoZWxvIjoibWFpbC1lZDEteDUzMC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZhZmZjNTk3LTliODItMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjMzLjI0NjU3MSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817232; x=1731422032; 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=yyqgbdCyqz7WQBq4sAipK7yHeendz1D8ul3qjvP/+g8=; b=HAITGYMUSd1lNIcdGPsrzp1k+itdrcqUkACAJWneEGU2TFJZBU/CMnfTOiJ/cJrrij JTSRqURZUSRTzNfRmXFlsYf8gecxKBze1d8KTMtIpm8X37lReZbBp3r5xHYgcHl1GCHu xFT8R1nxgrwS94imrr8uV/6Vynih48E8iSh0c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817232; x=1731422032; 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=yyqgbdCyqz7WQBq4sAipK7yHeendz1D8ul3qjvP/+g8=; b=eUMdeZcUnqDNUHV/nLZd3jLloNFxCh6OGY5LYiv6lp8MSBOR0gYydVcVtLMLiUScQM NUI0fUr0J9SJd+cnrLzeeQbcWt9LKw4HL86tglxTq8vL6v67vBiYDFgKGmtKoFaTythc pM6t4Te//0WqvkWtWPQtLFocSk2Ayu0h69Tt2XvB45X2VVbzfpNDAL6gSRQvKG3lJAEW iCieZr21ikDaLuB2fbBNA4SWj4KVeSjLCBzq5pm2xrgkOHiT/Dj3DwU/LeGj83A+kZxY YAQw4DNPqqx6RgVd3kwEhjzSps4wYvnmHQ22n8O7X85HDhswsNJRr1TRZqCcIrcuxMvW eHXg== X-Gm-Message-State: AOJu0YxZWv8zIUp/CrVWZa9S+pPd5nB0mJBMlsqwDWlP5AkL38H6n43C mUSfEAw1Q0BOwzn/9cq9WKToljU3r94Cq/JEUAr93gahGrA4iajLspprgGruWLCuwz1IenhlGNs P X-Google-Smtp-Source: AGHT+IF1jV35urzB96D/9HqoIOs+dpJXaGQ8XIKeUjyC6ubT8ayqoooLczkbqx7hS4HjBq+ce64o4w== X-Received: by 2002:a05:6402:5c9:b0:5ca:efe:10de with SMTP id 4fb4d7f45d1cf-5ceb9382a40mr18273172a12.30.1730817230969; Tue, 05 Nov 2024 06:33:50 -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 v2 03/13] x86/hvm: Map/unmap xsave area in hvm_save_cpu_ctxt() Date: Tue, 5 Nov 2024 14:33:00 +0000 Message-ID: <20241105143310.28301-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 018d44a08b6b..c90654697cb1 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 Tue Nov 5 14:33:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863038 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 02207D2B931 for ; Tue, 5 Nov 2024 14:34:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830259.1245225 (Exim 4.92) (envelope-from ) id 1t8Kd2-00031b-2P; Tue, 05 Nov 2024 14:33:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830259.1245225; Tue, 05 Nov 2024 14:33:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd1-00031U-VS; Tue, 05 Nov 2024 14:33:55 +0000 Received: by outflank-mailman (input) for mailman id 830259; Tue, 05 Nov 2024 14:33:55 +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 1t8Kd1-0002K5-BR for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:55 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fac9d3cc-9b82-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:33:53 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c9454f3bfaso7202689a12.2 for ; Tue, 05 Nov 2024 06:33:53 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:51 -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: fac9d3cc-9b82-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmMiLCJoZWxvIjoibWFpbC1lZDEteDUyYy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZhYzlkM2NjLTliODItMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjMzLjE3MDk3NSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817232; x=1731422032; 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=uaCt1R4em9pfxDQHOMV7fnt5XQRHenhzTeTJnqdZ8nU=; b=U+6rm4YdBHLDfOu0p9aWuoNvXtPwm5fOGfBLvI5eRG9b5Wibfu36JvITuwWi514VZM Oes2x8qGRCKxbi6s6Puc4o8U+j4xZjgJoixfdkZUnOW23S4lmDhBMid3F8Y4ptfWGOF7 8Ph11yIpZgNRhqlpzGTv81BfPOSNVvROF2r34= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817232; x=1731422032; 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=uaCt1R4em9pfxDQHOMV7fnt5XQRHenhzTeTJnqdZ8nU=; b=trbXY5QIb6gHQvGZhrLCWp0EqV7AlemqGTtYxUxU9B+mewAVKiF2AzFg/TdjHdg9LS 78+pqrQjKIuoZ4meprlCRn8s/liZ2LS4QwDMARChMeHSKFu4y6r8gyCi9H9MmkWD9PRZ bWdpizA0WnH14dAcuyuHSaZTim5sfmvv2vfWvIcFYdHfEE67smy20g6nMWGk8tPnqQ+S gXgEwvH4K1JlbZhXyY5Ts3X0KhHYjzlelWZ/StW5GHAVY1Fkw3uNoMCMqVPMP5Cjp76T o4uzMsmIe86FnAmtZpe1em08Px2LXwc59KWxbfd9FDznK9ZIFDpWZuz+foYB1+USYuW+ U1Aw== X-Gm-Message-State: AOJu0Yyl6A8QYfjLTRgsvzwShDIr5fvYUv45KU4EKHxSQY3gVdeSGHfw zrLqZFKXkRg62kqQ2BmHSQfo0Mx/EK4ZQWAqUxZ0HmLZTk0iA9VAcHinOxo3oqR55ul2i3fBDZO o X-Google-Smtp-Source: AGHT+IHkwmMqPA6QHCDQwMcBPOeKV84ETVsWV5zBo30jGJZIha1WDr3qXV57i1sevxjjrvQV5bhAwQ== X-Received: by 2002:a05:6402:4405:b0:5ce:dfab:e2f5 with SMTP id 4fb4d7f45d1cf-5cedfabe3f0mr2954851a12.13.1730817231901; Tue, 05 Nov 2024 06:33:51 -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 v2 04/13] x86/fpu: Map/umap xsave area in vcpu_{reset,setup}_fpu() Date: Tue, 5 Nov 2024 14:33:01 +0000 Message-ID: <20241105143310.28301-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2: * No change --- xen/arch/x86/i387.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 3add0025e495..a6ae323fa95f 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -304,8 +304,10 @@ 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) { .fpu_sse = { .mxcsr = MXCSR_DEFAULT, .fcw = FCW_RESET, @@ -313,15 +315,21 @@ void vcpu_reset_fpu(struct vcpu *v) }, .xsave_hdr.xstate_bv = X86_XCR0_X87, }; + + 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 Tue Nov 5 14:33:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863034 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 999BCD2B932 for ; Tue, 5 Nov 2024 14:34:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830261.1245244 (Exim 4.92) (envelope-from ) id 1t8Kd5-0003al-JS; Tue, 05 Nov 2024 14:33:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830261.1245244; Tue, 05 Nov 2024 14:33:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd5-0003aa-GB; Tue, 05 Nov 2024 14:33:59 +0000 Received: by outflank-mailman (input) for mailman id 830261; Tue, 05 Nov 2024 14:33:57 +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 1t8Kd3-0002Lm-Ji for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:57 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fbcc7573-9b82-11ef-99a3-01e77a169b0f; Tue, 05 Nov 2024 15:33:54 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-539e13375d3so5709834e87.3 for ; Tue, 05 Nov 2024 06:33:54 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:52 -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: fbcc7573-9b82-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMzMiLCJoZWxvIjoibWFpbC1sZjEteDEzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZiY2M3NTczLTliODItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODE3MjM0LjU0NDQyMywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817234; x=1731422034; 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=cccZT2nNkS7HwSnMjpqOOO6Pj9Rt1hTJOtUGj8Io0EM=; b=cqvAj5hq1PfOP4NTs3I5y/dVM5hYvU49CVm5dH1egJD2yUuL2ZuCN9fhnf3nPU8eV0 YKacFgYt1lZ4wcLHvUpKPH3lAGAs9OkC2ceMbLkUVBKUcksFYuEFbEU8WNbmG5UnFCZT ylHMnciva4isyDxkzHyfBGsh/L3+OjqCWBWj4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817234; x=1731422034; 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=cccZT2nNkS7HwSnMjpqOOO6Pj9Rt1hTJOtUGj8Io0EM=; b=oJmpnsvGqWa6PrpxuY2gdYHVY7psur+QYz4ZMWDiR/q7i77HSfaQMsoroqBCV1PE/t 59DHsP1HbnphSDDYsMiXOKvAUOyp91uWJCPKsKWq+DSBcozQItJBkGmZdRJXTpcIvpLe 7F/bptu2fbFpxq2+TFEnt2vNNUDxurFveyJ/7OL58wCDT4NM/BeMrTvJ5LT8++Uxz2DZ F2tztBoCAL9x4YoXzdPyYuX+2tIFg27MuNSVEhG2zAKSBR01VzWtIatrz9iD9P4Ye+rX +dyFl2By6xHjH9rQBE4mxjippyMDrOqejE0YN9g8+9+Cm5MM4MDbIcxChtZtmwU/DLty 8VsA== X-Gm-Message-State: AOJu0YwX3SBpsV26eVykjVzf9J7LxleTWOL6fUjYMCWM9NyfLW9JTyVV 0HQF4s8nHgw+ZjM42l2J+e8i4ndKdgi9AbTF7tqrKGUEW1LGtkHF1Zs9dd8susI/EIrZQv3VAsA g X-Google-Smtp-Source: AGHT+IHrNmRZfcX4aC6aS1DeA4a59+43m9OGjtNEUC2QU5MbtRtDnUQSzXyAAjVgiUZtRovM+6xiGQ== X-Received: by 2002:a05:6512:138e:b0:536:53f0:2f8e with SMTP id 2adb3069b0e04-53c79e8ecbdmr8749128e87.37.1730817233351; Tue, 05 Nov 2024 06:33:53 -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 v2 05/13] x86/xstate: Map/unmap xsave area in xstate_set_init() and handle_setbv() Date: Tue, 5 Nov 2024 14:33:02 +0000 Message-ID: <20241105143310.28301-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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..401bdad2eb0d 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 Tue Nov 5 14:33:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863042 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 97547D2B932 for ; Tue, 5 Nov 2024 14:34:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830262.1245249 (Exim 4.92) (envelope-from ) id 1t8Kd6-0003dn-0J; Tue, 05 Nov 2024 14:34:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830262.1245249; Tue, 05 Nov 2024 14:33:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd5-0003d2-PK; Tue, 05 Nov 2024 14:33:59 +0000 Received: by outflank-mailman (input) for mailman id 830262; Tue, 05 Nov 2024 14:33:58 +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 1t8Kd3-0002K5-W3 for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:57 +0000 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [2a00:1450:4864:20::533]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fc92def0-9b82-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:33:55 +0100 (CET) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aadb1so5994362a12.0 for ; Tue, 05 Nov 2024 06:33:55 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:53 -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: fc92def0-9b82-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzMiLCJoZWxvIjoibWFpbC1lZDEteDUzMy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZjOTJkZWYwLTliODItMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjM1Ljg5NDEwMywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817235; x=1731422035; 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=mJwLbo7xtzRRC/VnQO4xXecso10EVyoDQfxpw8QvaGI=; b=Szbl2X6Sf3CZ+i/9NunmcRgJl7dOrZiIQG3VR2m9NbzB6Q9J8a9QUFK6MJqufMKKPh bgji8ssMnieAHstP/bHqP9i6eeRUDrOPjTATvAXhnxDjvZnoxZTv6KXJCTwRq+Briz67 +tAf3dWs8Boy+2Xf++QEmD4GwKpjlO/izqRXk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817235; x=1731422035; 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=mJwLbo7xtzRRC/VnQO4xXecso10EVyoDQfxpw8QvaGI=; b=QAC5disuorDut0ISeUznhscGMifL/jDVgg0gxzxhadYw9jwnDcq9s1KCuxQON8B90a 1YuiV92uI/kfRp1E6sgud1b2eSbTqzxdtK13ZprQ1mG8THu789UwOkQ9xMyKEP9jFitf FkXSlVi47yorx1Dbf+/cw67Yj4FBhAr1W/A8/vx4l56PAItFyiS8tMjo2RXFj2gc6TGG 4rO6x4GbAZlGDUu+1gM5DmE8UspZZYY5dzC55O7Mlm6Elky50lZDOuTfQAHsReZ1svos E1eQKQx9dsMBeAB5mA1lfVcPEBEJWPpsAOR1a0b9113xzJ2frbIHG9qwSCba9EChaGTA UGyA== X-Gm-Message-State: AOJu0Yxvvbyis5FHDPwZcL+XNpGY60pv1Zas5Lujphe2DlEldjPvWDIo CzkplGee8Ht65Qs+dmZb/nhdcOkzVU77I1Wl0c6TAapyFWVdgDA27ZfuoU/7/YqCKzMmuzf7z7J t X-Google-Smtp-Source: AGHT+IHTCf6ZJQX++QLf10O2tL6Cn7s9y8sERr+xKKzk+gTuFjlCqijQcrcnwHgB0hYuPj/Ra8bJzw== X-Received: by 2002:a05:6402:1d56:b0:5ce:e067:27aa with SMTP id 4fb4d7f45d1cf-5cee0672877mr3491397a12.32.1730817234883; Tue, 05 Nov 2024 06:33:54 -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 v2 06/13] x86/hvm: Map/unmap xsave area in hvmemul_{get,put}_fpu() Date: Tue, 5 Nov 2024 14:33:03 +0000 Message-ID: <20241105143310.28301-7-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 f2bc6967dfcb..04a3df420a59 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); @@ -2465,6 +2471,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 Tue Nov 5 14:33:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863043 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 9C4A4D2B92E for ; Tue, 5 Nov 2024 14:34:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830263.1245264 (Exim 4.92) (envelope-from ) id 1t8Kd7-000450-Ah; Tue, 05 Nov 2024 14:34:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830263.1245264; Tue, 05 Nov 2024 14:34:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd7-000445-3z; Tue, 05 Nov 2024 14:34:01 +0000 Received: by outflank-mailman (input) for mailman id 830263; Tue, 05 Nov 2024 14:33:59 +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 1t8Kd5-0002Lm-Na for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:33:59 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fd27942f-9b82-11ef-99a3-01e77a169b0f; Tue, 05 Nov 2024 15:33:56 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso10245858a12.3 for ; Tue, 05 Nov 2024 06:33:56 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:55 -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: fd27942f-9b82-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MzQiLCJoZWxvIjoibWFpbC1lZDEteDUzNC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZkMjc5NDJmLTliODItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODE3MjM2Ljg2NzczNywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817236; x=1731422036; 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=N6lX8wC6vemlWKb1ztmufWqxP8TDVhHXoJf9VFLSRv4=; b=kXktaJXveODNv06MYvImBltVodEW/gpD4YHFSbWOIr5/FQ0ZL1wY17TTvLyFLFt2kj 7K1L7HUuzCY2akbGZAVx/hYV/Wl6lJ2TKKjTrw0YCf/Ih1xU1VPkSZhMXjqZw9orJjwH zeuGXsJU7IoqctZJhgUfzfouoi70kpNHEdGiE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817236; x=1731422036; 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=N6lX8wC6vemlWKb1ztmufWqxP8TDVhHXoJf9VFLSRv4=; b=hxQmIs6iMOI7mT1GTmKe3MmY08Olxm58Yio+WBaSXYjHATMRVAqjlP+EyrL6KY+RyK cgp+BSBXvgnLSVDVwQuHfN9rVpTYGklNJbXjLBwKTMgt9w0Exqcmzqtw2hcnxHeEdNZx 1iErhN3BPCOCvJ8wAW2l2VeMtQs6/+SeVqKmMLpTcuta/0dFDKYUWTXYor+l6N9ddr4J senpPPC4+NXe3rFk/rEwTBKQ7HRAJQk+/v27bX/ydrEjeLCUF9JRGzUfqB6rsSZMJB/w uw9pUIZ606jvg1aFWt5hNHf9CCBZcstiX0btKKaZ8FjyswtvuDlXLY3IqW/m5FMcfnMM RA3A== X-Gm-Message-State: AOJu0YwyyhE8qfSKi8WT3weYnsqsHaEtGBYTBfJcfF1KcOa3MIRzaFX4 j9IOBm5EfLVvA25wk2BI5vpebLVY35krSaK/WJRM7zbrRpTgiOa3IqZQeViddjOb/JW2XezJrPM v X-Google-Smtp-Source: AGHT+IGVWmLvCB54DEgDhUuVvwOh11g5k5GHHLDORNT+WxCKbjVQgDKv6HikkcI8I3dUFbb80yEbnw== X-Received: by 2002:a05:6402:520b:b0:5c9:6f20:4cf1 with SMTP id 4fb4d7f45d1cf-5cea971b4b5mr17021317a12.27.1730817235911; Tue, 05 Nov 2024 06:33:55 -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 v2 07/13] x86/domctl: Map/unmap xsave area in arch_get_info_guest() Date: Tue, 5 Nov 2024 14:33:04 +0000 Message-ID: <20241105143310.28301-8-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 Tue Nov 5 14:33:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863037 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 D35ADD2B92E for ; Tue, 5 Nov 2024 14:34:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830264.1245275 (Exim 4.92) (envelope-from ) id 1t8Kd9-0004SI-LY; Tue, 05 Nov 2024 14:34:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830264.1245275; Tue, 05 Nov 2024 14:34:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8Kd9-0004S5-GH; Tue, 05 Nov 2024 14:34:03 +0000 Received: by outflank-mailman (input) for mailman id 830264; Tue, 05 Nov 2024 14:34:01 +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 1t8Kd7-0002Lm-IY for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:34:01 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fe1b1500-9b82-11ef-99a3-01e77a169b0f; Tue, 05 Nov 2024 15:33:58 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aadb1so5994427a12.0 for ; Tue, 05 Nov 2024 06:33:58 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:57 -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: fe1b1500-9b82-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmIiLCJoZWxvIjoibWFpbC1lZDEteDUyYi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZlMWIxNTAwLTliODItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODE3MjM4LjQ4OTUwOSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817237; x=1731422037; 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=BUizmB3LOGfKPH6kG1rx3VM0wuv9I8IHhRkqZT/M2eQ=; b=cJ5Uk17YC/EeN0s7Q0qiduCn0XP1QI1BdjdN7S1G4LABL/8Brkd2cO+p6wpZeQ2nwI ICp+gJycQ+wjPaDWvxLpZzagDqoV03Xd+MrAFU+PVDFQmv/uzXAprdSUfYCXQpT0AjSB 88BMFVCWaIzZ2Y0V/mtaO4qMn6SBD+b0IYiqI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817237; x=1731422037; 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=BUizmB3LOGfKPH6kG1rx3VM0wuv9I8IHhRkqZT/M2eQ=; b=lZ28g9O3392r5N1YZV6q81edJJGvurxPcci5cauHgERnD6u28Z+igdiSEdkgcbyMGh SW7NJhxamYC5UxjZV/5JJYBI7zLvzH4xXYP1yXrhN5PB/ukUwQHcm+6hT9Zg1Si+K5dz cUJn01Svh0zjOsTOUR5d+Xy30iOHzTWpgSsP8QiwqD6btMXjCl0AqllPv+iiTtHPfylo IDVqp2AAGM81/lL+RJ/Guq6NWjI+JGViHQGVtrVXiZEJCQIsfyxWc82p1Kkm0NpxF1dY z2FnwFo9Mi3yycxo1GMaFiCKuXJNpNSxNKSxui0eClVidhuDgsxYv1O+DHBBaC6IXDwh 0Bhg== X-Gm-Message-State: AOJu0YzSYsUAnTmb8caZrr4X+ezoBf/38zSHn2000n3cBAfR1o01DJSc eHUls62XsyntOJAGerI6l8UkduI15qVzmq1vRXalquNl7HoWVIjjRuW+NOxPmLfkjeeat/zjpN4 Z X-Google-Smtp-Source: AGHT+IEiUJOQD7yv0Jo69qAsBZhZGsSu6R1qeHwLDHYDgogg18wiMRIt9gk6zfpbL/A+gvmG/cfj6w== X-Received: by 2002:a05:6402:42d6:b0:5ce:d01e:bf79 with SMTP id 4fb4d7f45d1cf-5ced01ebfccmr6412282a12.2.1730817237507; Tue, 05 Nov 2024 06:33:57 -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 v2 08/13] x86/xstate: Map/unmap xsave area in {compress,expand}_xsave_states() Date: Tue, 5 Nov 2024 14:33:05 +0000 Message-ID: <20241105143310.28301-9-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2: * No change --- xen/arch/x86/xstate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 401bdad2eb0d..6db7ec2ea6a9 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; @@ -228,6 +228,8 @@ void expand_xsave_states(const struct vcpu *v, void *dest, unsigned int size) valid &= ~feature; } + + VCPU_UNMAP_XSAVE_AREA(v, xstate); } /* @@ -242,7 +244,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; @@ -294,6 +296,8 @@ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size) valid &= ~feature; } + + VCPU_UNMAP_XSAVE_AREA(v, xstate); } void xsave(struct vcpu *v, uint64_t mask) From patchwork Tue Nov 5 14:33:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863045 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 5865CD2B932 for ; Tue, 5 Nov 2024 14:34:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830265.1245284 (Exim 4.92) (envelope-from ) id 1t8KdB-0004jK-2b; Tue, 05 Nov 2024 14:34:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830265.1245284; Tue, 05 Nov 2024 14:34: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 1t8KdA-0004i0-RX; Tue, 05 Nov 2024 14:34:04 +0000 Received: by outflank-mailman (input) for mailman id 830265; Tue, 05 Nov 2024 14:34:02 +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 1t8Kd8-0002Lm-LH for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:34:02 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fef368e9-9b82-11ef-99a3-01e77a169b0f; Tue, 05 Nov 2024 15:33:59 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5ceca0ec4e7so3883220a12.0 for ; Tue, 05 Nov 2024 06:33:59 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:58 -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: fef368e9-9b82-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmIiLCJoZWxvIjoibWFpbC1lZDEteDUyYi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZlZjM2OGU5LTliODItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODE3MjM5Ljg4MzA0OCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817239; x=1731422039; 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=UKD1CllUUFP/95/tHyduaxD4gLazG9r0IgfoStz+dic=; b=S+bstDkbGu3y+qM0RnCgWta6KZk/dW2D3rVgqHa0p/+XwT4SiKSxVRn4Qp04kd4KEW NVO6Nh6L7QjaxnrjB9JCwelirpeabrUqEYYcYAElCKWLpuQnNIda1jij/orbnPLiiIXd mARJVeD8vbkB/fSmK1/gfk0hNzKLfOM4Etyfk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817239; x=1731422039; 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=UKD1CllUUFP/95/tHyduaxD4gLazG9r0IgfoStz+dic=; b=t+NEiCXvQLI6ZBRo+PaDoa2ekiRxeESia/SQL1jsgS4Z73MIeY7vmQz+upf6VDmy/3 6PwZt2eXhdWn/FSI34YpQUBCZxOEPndMy3TDnIpc7KvQnXkqNVsollbTxFQOJqAHcTVZ NB2I5bEC2FAFPxd07vmb7jj4n6LLBYpqNCiAxJI+dtIpHuxj9knGmAwtLlD9vbkkm5KB Bz5YRct30yuoVQOBKNc0cj5AmsDuCcJgi7kowHFwQpS6HBJrBF5MFWafk48gXCsXCiaP +mPf5ZVxlZwFM57e+0j5d9bVmH3vUXwx9AkMFeF2gzXX9OC9QAQmF1dM/yZ+orifw5bD tblg== X-Gm-Message-State: AOJu0Yx/eGEo1c1szvU1bcL8CPTrPyisiNs0EfU5G5cSLIyUL9cLTGT2 J0+KSQg8sBH+HLqpjz7SpsfDisZrdnQKA+GiNhDch4NM+G8oi6KUUFLVqcDeztmWlowjRLs1cNi m X-Google-Smtp-Source: AGHT+IHRZFhPefPtV7nx6c0cnFCSuUCW8livz50ATFuMJWDV1OhNGuvheVnLhO3/SW011uPiQ9tJRw== X-Received: by 2002:a05:6402:845:b0:5cb:6675:bb3b with SMTP id 4fb4d7f45d1cf-5cbbf8b23eemr24693657a12.13.1730817239003; Tue, 05 Nov 2024 06:33:59 -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 v2 09/13] x86/emulator: Refactor FXSAVE_AREA to use wrappers Date: Tue, 5 Nov 2024 14:33:06 +0000 Message-ID: <20241105143310.28301-10-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-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: * 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..76fd497ed8a3 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(currt ent, 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 Tue Nov 5 14:33:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863046 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 48AD9D2B934 for ; Tue, 5 Nov 2024 14:34:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830266.1245291 (Exim 4.92) (envelope-from ) id 1t8KdB-0004oi-OO; Tue, 05 Nov 2024 14:34:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830266.1245291; Tue, 05 Nov 2024 14:34: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 1t8KdB-0004mD-8q; Tue, 05 Nov 2024 14:34:05 +0000 Received: by outflank-mailman (input) for mailman id 830266; Tue, 05 Nov 2024 14:34:03 +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 1t8Kd9-0002K5-HU for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:34:03 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ffcd476c-9b82-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:34:01 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5ceb75f9631so5709387a12.0 for ; Tue, 05 Nov 2024 06:34:01 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:33:59 -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: ffcd476c-9b82-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmYiLCJoZWxvIjoibWFpbC1lZDEteDUyZi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6ImZmY2Q0NzZjLTliODItMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjQxLjMwOTk5MSwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817240; x=1731422040; 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=AHukccBbBpbC+k7kZ0/gZzzWfRKQINdoK6h9gGQzyg4=; b=fT8CMbkKkoEionf+10rr2ldMJYNDhX+QDFRZilivZDvqtnn8htUu1tNxDov0z0ulV0 kY1kqbe7x8SGosEnflPyAUsyB9diZAQBFvnXAgVYSWMUf9+xVqBw7/JiApz3jTlnRpmh fDS0bAvmBmRS/euKUR3Y6D4F45d5GiMAO6K5E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817240; x=1731422040; 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=AHukccBbBpbC+k7kZ0/gZzzWfRKQINdoK6h9gGQzyg4=; b=bNmiJftDzQrFvhFURlcL+gnu00nCOTGvhZWnCgYWE7eon4OEvg8EWnEUVSdDCYN5xQ zYS2+qnXLcbXVdV53+cMbBAdo0LSROdeFk23sQlgTnIBct9nFxJlKSjPlJWsy0p5JSiq Z0+wtQYBcdzOX1w0C2cB9+5P1TzHepXDntxuENLXUOirtuIPgvUfpCn2gRdH1t5ecPXR q3us5FEMYkjuTEDC1mKvkDeItqP7GXem6h49/2g3jrO6X9U7M6SC+DI8+UU9/aOKw+pm ASs8cfHD8M5xDsMjgqTTaCsw92odujX3c6jZxwzHUaC3xeqSJ8c4me/mhsmHN2kE6hZK Xsww== X-Gm-Message-State: AOJu0Yw8zLd18fdX1+TbFG9+geylQgYbz2tQrSw47YNIcvJJHwIAVZjy kVKobDZn5G/R73xHxHIkXgx/MDLdc/D/PUmEHo6+agSriiTg9wnxYz00VDHZPR95ppzNdpdyRrk Q X-Google-Smtp-Source: AGHT+IHa/ojeelBSzZGbiAyj+Hr1UbyyUgXITX9+Pi112rloiy17KwqQt0YRmn5B4ntqXT9Ez72fbg== X-Received: by 2002:a05:6402:278e:b0:5ce:de14:63ed with SMTP id 4fb4d7f45d1cf-5cede146458mr4200250a12.36.1730817240423; Tue, 05 Nov 2024 06:34:00 -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 v2 10/13] x86/mpx: Map/unmap xsave area in in read_bndcfgu() Date: Tue, 5 Nov 2024 14:33:07 +0000 Message-ID: <20241105143310.28301-11-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 6db7ec2ea6a9..9ecbef760277 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1022,9 +1022,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); @@ -1050,7 +1051,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 Tue Nov 5 14:33:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863041 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 B93B4D2B931 for ; Tue, 5 Nov 2024 14:34:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830267.1245304 (Exim 4.92) (envelope-from ) id 1t8KdD-0005Qe-Vh; Tue, 05 Nov 2024 14:34:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830267.1245304; Tue, 05 Nov 2024 14:34:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8KdD-0005PX-OF; Tue, 05 Nov 2024 14:34:07 +0000 Received: by outflank-mailman (input) for mailman id 830267; Tue, 05 Nov 2024 14:34:05 +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 1t8KdB-0002K5-OQ for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:34:05 +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 00d4b073-9b83-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:34:03 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aaddeso5938205a12.2 for ; Tue, 05 Nov 2024 06:34:03 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:34:00 -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: 00d4b073-9b83-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmQiLCJoZWxvIjoibWFpbC1lZDEteDUyZC5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjAwZDRiMDczLTliODMtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjQzLjEzMzc5NCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817242; x=1731422042; 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=Jc35G27Gr3VkDuTcKUwBetak3Ic6rCOhMXfwTHHpMdE=; b=dru1R5uas4DaJ2XypHDq0s6GgXyJkFEeLn5R0TDByDrodiM39u/T1ymHXQChZ9sVlU rSNY1bLvorCJZqrRFVCP7mSCyIA8Lqvhu205uvSSphmrZ6HUuyG3WMTndWTfQwmZ9XkO 7y2v+jGG+Vvp0yAxt5a7WpwnrN382rSC/ka/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817242; x=1731422042; 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=Jc35G27Gr3VkDuTcKUwBetak3Ic6rCOhMXfwTHHpMdE=; b=uryXotXrtvYfvCWbJYJOykz/E1Ou5YM0yWQhZ+zF6jr9wK6du3fK5F3S9/EAeYJtLA y5JJuBgyfZggoKXJupSkt+/07GYl96668WJkz0z267L2DgLpw/cuzUfprlZrwv0hCFNR r0mFXXS17Bwh7ntwT8yQXOpC3xmfy5fTARmmW9+nm6Ll3keNFFnEFQpWR+pENveLwoKf G1Ejncr6erofnRfp9jmKof3R7iW6/Udo+i+bnkIMB1brQ8BZ6AJvNn8/4iQmVwgPn5Jq euZUz6IJx2Tu4Q/oV3Epuy/EVnpGphEL7uKCg4/yVAkqg8rbzhbiMlWvXGqMI8hqauyT P1tA== X-Gm-Message-State: AOJu0Yw3JsBUU6HlR+Mau4ddThXpf9UYKgxE38jQu+xoSAO46gyiMqMv 2c29BQQzOfJFkOBWqawRm4Pp0SEV35NyLjMP5HCichIJ5/GH0tYJs7hhw6zj6RxueHDGhnhq8MX 2 X-Google-Smtp-Source: AGHT+IH7kiUbK3mBgFNVwAoXuK6Xah394QabsKMkZvp2o5saOpNY3n0VT2XUZP6qGa/L1Iq16mEZgQ== X-Received: by 2002:a05:6402:2751:b0:5ce:cfed:6c4f with SMTP id 4fb4d7f45d1cf-5cecfed6cdbmr8807224a12.23.1730817242071; Tue, 05 Nov 2024 06:34:02 -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 v2 11/13] x86/fpu: Pass explicit xsave areas to fpu_(f)xsave() Date: Tue, 5 Nov 2024 14:33:08 +0000 Message-ID: <20241105143310.28301-12-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 a6ae323fa95f..73c52ce2f577 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(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 6b0daff0aeec..bd286123c735 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 9ecbef760277..f3e41f742c3c 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -300,9 +300,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 Tue Nov 5 14:33:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863044 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 1518DD2B931 for ; Tue, 5 Nov 2024 14:34:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830272.1245321 (Exim 4.92) (envelope-from ) id 1t8KdH-0006DB-FK; Tue, 05 Nov 2024 14:34:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830272.1245321; Tue, 05 Nov 2024 14:34:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8KdH-0006Ac-6y; Tue, 05 Nov 2024 14:34:11 +0000 Received: by outflank-mailman (input) for mailman id 830272; Tue, 05 Nov 2024 14:34:09 +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 1t8KdF-0002Lm-CA for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:34:09 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 01cf7f9e-9b83-11ef-99a3-01e77a169b0f; Tue, 05 Nov 2024 15:34:04 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-539e690479cso5792053e87.3 for ; Tue, 05 Nov 2024 06:34:04 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:34:03 -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: 01cf7f9e-9b83-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjoxMmYiLCJoZWxvIjoibWFpbC1sZjEteDEyZi5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjAxY2Y3ZjllLTliODMtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMwODE3MjQ0LjYzMjIwNywic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817244; x=1731422044; 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=lvXFoZIT084RN37AsraaKxNusw6LAdGsn4eMeymG1tw=; b=SqgSx6G48UPW3y6LyOs90IXEpVz6faYIRLyYPtqK2OamyFDF1Ib8EfXnvF/xHEciOG R78qMLc4/i48a0QEKOJGnQg81xVJXlGhmJuxHPADL6PlllBLu46/+0kHk8nMfzPzROaH Je9JuoravDhkmjWaECdv8YXTUGGl6Sugf+Gfc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817244; x=1731422044; 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=lvXFoZIT084RN37AsraaKxNusw6LAdGsn4eMeymG1tw=; b=uZUDj4TU2vIYX0g+Egcxjnot2qx45MMI05pUkScgE3ATtv85J6hkDCakxXOcqG5jYz vvjFGBTcUYRjY2BT4bOSw9zTr9WOO0TXSI2Z3AWu4D6Jajptf+B6kmy2KhObvN/ZolCj 8tnDLfhe29tU+TGvEndv/vKxBfQw4qALUu5QMSukunOIMANB2BkpmLLkYJyby0P8FN37 EQxTBdFGKk6jLSRBqlZObmBJiPYk/O0HH0lLJrcoIwUkVT+/tBOOGAWcOH0Y46RHMouP sgYzydSTagAki0XGxM+5d+GofrhZDbDznAVloFQ2q4AUSykN0PEHKlHSEaA5HryZw1XM GinA== X-Gm-Message-State: AOJu0YzzEb89n9yBiQV7KtMH/nJR0voWGNx606hf8T8xo1EitDfVe+HP TO286p5kW+DF55j5eARdL6pA6xpIM9tjCToxhZU+i7TXmpml0TN+Zhw+k1h6xGm5Dzz/k+JSUlC 7 X-Google-Smtp-Source: AGHT+IEi8f1ooBIDDsZtziWzMdi1NElpo5P7/OCx24gHU/0VHdpp3Z4HwqasLJdsE3mVz4AD+p21gA== X-Received: by 2002:a05:651c:98d:b0:2f7:53b8:ca57 with SMTP id 38308e7fff4ca-2fedb790772mr81567381fa.19.1730817243635; Tue, 05 Nov 2024 06:34:03 -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 v2 12/13] x86/fpu: Pass explicit xsave areas to fpu_(f)xrstor() Date: Tue, 5 Nov 2024 14:33:09 +0000 Message-ID: <20241105143310.28301-13-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- v2: * const-ified v in 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 73c52ce2f577..c794367a3cc7 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(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(struct vcpu *v, 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(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(v, &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(v, &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 bd286123c735..d2ef4c0b25f0 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 f3e41f742c3c..b5e8d90ef600 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -374,11 +374,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; /* @@ -992,6 +991,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(); @@ -1011,7 +1011,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); } @@ -1078,7 +1080,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 Tue Nov 5 14:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13863047 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 39140D2B931 for ; Tue, 5 Nov 2024 14:34:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.830268.1245313 (Exim 4.92) (envelope-from ) id 1t8KdF-0005lT-LA; Tue, 05 Nov 2024 14:34:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 830268.1245313; Tue, 05 Nov 2024 14:34:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t8KdF-0005kb-Bk; Tue, 05 Nov 2024 14:34:09 +0000 Received: by outflank-mailman (input) for mailman id 830268; Tue, 05 Nov 2024 14:34:07 +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 1t8KdD-0002K5-OX for xen-devel@lists.xenproject.org; Tue, 05 Nov 2024 14:34:07 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0275fcd4-9b83-11ef-a0c5-8be0dac302b0; Tue, 05 Nov 2024 15:34:05 +0100 (CET) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5ceccffadfdso3553120a12.2 for ; Tue, 05 Nov 2024 06:34:05 -0800 (PST) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cee6a99ff2sm1395047a12.4.2024.11.05.06.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 06:34:04 -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: 0275fcd4-9b83-11ef-a0c5-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDA6MTQ1MDo0ODY0OjIwOjo1MmMiLCJoZWxvIjoibWFpbC1lZDEteDUyYy5nb29nbGUuY29tIn0= X-Custom-Transaction: eyJpZCI6IjAyNzVmY2Q0LTliODMtMTFlZi1hMGM1LThiZTBkYWMzMDJiMCIsInRzIjoxNzMwODE3MjQ1Ljc1ODA5NCwic2VuZGVyIjoiYWxlamFuZHJvLnZhbGxlam9AY2xvdWQuY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730817245; x=1731422045; 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=6B5omt1SedDQO6IJZRH4ErAkBbwq92KD+awlMKQ0bxI=; b=i4FMGxGpZc1jBhlMRVOTT5mcac4CED05EJi3mHEGYHY1m3+b+bfXSYHRBR6rMxlNgr 5ePLpd9NCU9CjN8mweZjiTfx3y2/FGXbO2F7pjp7fTlOuL9d8hBCpsWd7bff1rlHVp1p GfSJHcX4eV9iX3ou/oo6fZLCkVJxVcKu/c0zU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730817245; x=1731422045; 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=6B5omt1SedDQO6IJZRH4ErAkBbwq92KD+awlMKQ0bxI=; b=CYr+D4hHVMLbp61AJXknGHtfqWLPkKEtesLpHxC6PNyzYVTpNayGFQJGFyISHfyHga 6NJUUem+b/XqX55tOK9XoPWrVSB4FmLbqOi/tnyZG1Edgnns4eIclcxFCgXTQ6LWRFaO 0sOCFGl9qvrfDdnhiqSNX6KPQ9Lyg+ml4vL9vaT+TDlE8EcskjV7QVd1dKMRF7gEgs5B Kq2mkOBhNUViqEi/p/3tOHlusJKpw9B0Q7DWB8/4zNhXUeIVDtDT+DdU+E1keb+wiSZn 8zQa0X0T49Nxkq+4sM1G3zO30smcz9CFwC1O9+bjxEPdgzwZUt5MsqbT2cFH8hWIhycD QoCw== X-Gm-Message-State: AOJu0Yxo9ZMybraO0V0ti8z+nurZp3HKm3+2BangoeLXUwyUQM03XH85 3lHViGmRASmIp78iMeQ4VwQWMm7GqmCXV2ee/Wh7RXUa1Zbq2p2x61KTr/nLcmppVOB97Rxh/mp D X-Google-Smtp-Source: AGHT+IFJA6M0XBv7FRFRoMs3JuKuoqXi/nf+aCqDEMKXEkJJ1sPRGW37quCEyuWC30mb250kMwCXmw== X-Received: by 2002:a05:6402:210d:b0:5c9:74e3:acbb with SMTP id 4fb4d7f45d1cf-5cea9678020mr15569290a12.10.1730817244742; Tue, 05 Nov 2024 06:34:04 -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 v2 13/13] x86/xstate: Make xstate_all() and vcpu_xsave_mask() take explicit xstate Date: Tue, 5 Nov 2024 14:33:10 +0000 Message-ID: <20241105143310.28301-14-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105143310.28301-1-alejandro.vallejo@cloud.com> References: <20241105143310.28301-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 c794367a3cc7..36a6c8918162 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -107,7 +107,8 @@ static inline void fpu_fxrstor(struct vcpu *v, 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 d2ef4c0b25f0..e3e9c18239ed 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 b5e8d90ef600..26e460adfd79 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1003,7 +1003,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;