From patchwork Mon Oct 28 15:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853701 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 8FF11D3399E for ; Mon, 28 Oct 2024 15:50:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826683.1241028 (Exim 4.92) (envelope-from ) id 1t5S0K-0008R3-7d; Mon, 28 Oct 2024 15:50:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826683.1241028; Mon, 28 Oct 2024 15:50:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5S0K-0008Qw-4m; Mon, 28 Oct 2024 15:50:04 +0000 Received: by outflank-mailman (input) for mailman id 826683; Mon, 28 Oct 2024 15:50:02 +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 1t5S0I-000874-IH for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:02 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4aa7bcf2-9544-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 16:50:01 +0100 (CET) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2fb51e00c05so64668321fa.0 for ; Mon, 28 Oct 2024 08:50:01 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:00 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4aa7bcf2-9544-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130601; x=1730735401; 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=DPLr0d8FwquAzKliN25Vvro3xH1NV3dTjQJhxaKuYlk=; b=gg2fIKTVONMRK8myfgOs7owVeKPQ27ZCGdE91TUesEJtkiR1SiIKRuhiA6JvGwCC+t oG1tHdzrwSwXGNeiI7HQ9Xx/V9PGL3VM86T7Aq4VFG4znGP51Kj8fLLnn5Ojtn4BZbam jUfawQoVqsmEVCBMrTP6bmYQtr1TvEjtfTZBs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130601; x=1730735401; 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=DPLr0d8FwquAzKliN25Vvro3xH1NV3dTjQJhxaKuYlk=; b=hsCU2tBbStOk+vT0f9ivOVa4bNY0aMh1HlkQ18zxVLs2sZvty+1jmisAMxidXOel68 VaRSx1yzkWn2EGJR0+sPYgdY6aLJWcKdmx/vLIHbze3Q/YlYPcfRZrkg9JciJTC/KReb h2H8rjAs9sb14eKEFOkvCl0H4m/qfbYgNGVF3Wv1nteB1aJNYmAKl3SgY5Pvw8KFeO0a 8yE1DeWLj3rRqK9LXJKssJbuvN6bZ4uvB9LWyf/hafIEcz+1GuMhTUzZaWq26hSMErOm r6xZqdKby+l93wgcPRCRpPGzIk4GjGZgFWMzAxD4GwwYnyn8o3OtiCfjlvoQgWajE9Aa aGRw== X-Gm-Message-State: AOJu0Yxff1ThNwvqEzoTzNtaYmyelF5LEGvEchkJrxkAXVTzLJxycIYS wX2mbYN49qKYd0aWJJiJ4nC0udcb90AmeJFEmEpJyS31QmHTWoGlGSU/P9Ahjc+aIhsJKEDdRsa Z X-Google-Smtp-Source: AGHT+IFtmzmZV5fwObpGT1d2ilRoYu6/BvAiUMHd9PeBKgHP0k7Y5B9lU5THnhultSOFDHtQezy2ng== X-Received: by 2002:a2e:2403:0:b0:2fb:357a:be4d with SMTP id 38308e7fff4ca-2fcbe0a35aemr45594251fa.43.1730130600675; Mon, 28 Oct 2024 08:50:00 -0700 (PDT) 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 01/14] x86/xstate: Update stale assertions in fpu_x{rstor,save}() Date: Mon, 28 Oct 2024 15:49:19 +0000 Message-ID: <20241028154932.6797-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 The asserts' intent was to establish whether the xsave instruction was usable or not, which at the time was strictly given by the presence of the xsave area. After edb48e76458b("x86/fpu: Combine fpu_ctxt and xsave_area in arch_vcpu"), that area is always present a more relevant assert is that the host supports XSAVE. Fixes: edb48e76458b("x86/fpu: Combine fpu_ctxt and xsave_area in arch_vcpu") Signed-off-by: Alejandro Vallejo --- I'd also be ok with removing the assertions altogether. They serve very little purpose there after the merge of xsave and fpu_ctxt. --- xen/arch/x86/i387.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c index 83f9b2502bff..375a8274f632 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -24,7 +24,7 @@ static inline void fpu_xrstor(struct vcpu *v, uint64_t mask) { bool ok; - ASSERT(v->arch.xsave_area); + ASSERT(cpu_has_xsave); /* * XCR0 normally represents what guest OS set. In case of Xen itself, * we set the accumulated feature mask before doing save/restore. @@ -136,7 +136,7 @@ static inline void fpu_xsave(struct vcpu *v) uint64_t mask = vcpu_xsave_mask(v); ASSERT(mask); - ASSERT(v->arch.xsave_area); + ASSERT(cpu_has_xsave); /* * XCR0 normally represents what guest OS set. In case of Xen itself, * we set the accumulated feature mask before doing save/restore. From patchwork Mon Oct 28 15:49:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853702 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 9B303D3399D for ; Mon, 28 Oct 2024 15:50:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826684.1241034 (Exim 4.92) (envelope-from ) id 1t5S0K-0008Tb-Ia; Mon, 28 Oct 2024 15:50:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826684.1241034; Mon, 28 Oct 2024 15:50:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5S0K-0008SS-CG; Mon, 28 Oct 2024 15:50:04 +0000 Received: by outflank-mailman (input) for mailman id 826684; Mon, 28 Oct 2024 15:50: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 1t5S0J-000874-CJ for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:03 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4b65b92e-9544-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 16:50:02 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a9a0ec0a94fso626989766b.1 for ; Mon, 28 Oct 2024 08:50:02 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:01 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4b65b92e-9544-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130602; x=1730735402; 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=W4k/sSFYh0TQGRGsfutUPLlHi3zFXSiHFIADoMp0Wgc=; b=BxWtNzFoQZNttH0ufX5ixSCfo0bNSsdzdMNnnPbFIpaX3Y6eHjsQ/cKNWZIEb/Zn1f jponcH4WEeTDUrk07DJlbr7JP5l15KSgkJU322j4NpBqQ5PshEQWGWVmMO2unOjlKxro q4P+10Q+vp16Lqxs/rKh7cELfOlvt8neUAJCc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130602; x=1730735402; 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=W4k/sSFYh0TQGRGsfutUPLlHi3zFXSiHFIADoMp0Wgc=; b=klddmtkyWV0aKfxl62CM1t9UP4SQQ7dGEGslf5AiFPHxVByXwPtdL2cXSb0w97tnTm IoQbT3JDsUWlNzXgLtiP7i62z/kswLmnjTfA3o4o2nwX2bl0ofb3H2rRGLYZBns6Xk8h hJsKk2vv/NwTZk1J4ePTBlYOBHR2WHriDHRw/T9hGxWgUJ/q7M1jSiXgJx/lx5TFBv3X kfiXWiAU9uMbnl9B4LKXhMiPIE3Gtgxv1r5CzCcZtYiZnQLvpXmAyWp2Y6qpFdT6q/1o WcsL/7/VxNv5GLblatE1dVIItDLgnOq6YwuqcXTkubTdAl80KH0skOmyh/bUxNCgY1mv w0WA== X-Gm-Message-State: AOJu0YyJFAno/gd+8XkRqqwlwvEgT2F7iWLQYjBcJhhJToVywNdesZU+ huKbyctdDv9js675akeLjL+uVQtHI6KVs34YLz4ijtOpJbSdaYLdEOfXYS9/BZfZ7SemX878K4e K X-Google-Smtp-Source: AGHT+IHjJ9oGe3akrkidsj5uCSXKoT5jpDGsKnM6W6RXB7stLEvw/7zR2nEMIrzcFYIyPwxWLJL/dw== X-Received: by 2002:a17:907:7b93:b0:a9a:b70:2a7c with SMTP id a640c23a62f3a-a9de5f3f87cmr634499366b.25.1730130601572; Mon, 28 Oct 2024 08:50:01 -0700 (PDT) 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 02/14] x86/xstate: Create map/unmap primitives for xsave areas Date: Mon, 28 Oct 2024 15:49:20 +0000 Message-ID: <20241028154932.6797-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-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 --- xen/arch/x86/include/asm/xstate.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/xstate.h index 07017cc4edfd..36260459667c 100644 --- a/xen/arch/x86/include/asm/xstate.h +++ b/xen/arch/x86/include/asm/xstate.h @@ -143,4 +143,24 @@ static inline bool xstate_all(const struct vcpu *v) (v->arch.xcr0_accum & XSTATE_LAZY & ~XSTATE_FP_SSE); } +/* + * Fetch a pointer to the XSAVE area of a vCPU + * + * If ASI is enabled for the domain, this mapping is pCPU-local. + * + * @param v Owner of the XSAVE area + */ +#define vcpu_map_xsave_area(v) ((v)->arch.xsave_area) + +/* + * Drops the XSAVE area of a vCPU and nullifies its pointer on exit. + * + * If ASI is enabled and v is not the currently scheduled vCPU then the + * per-pCPU mapping is removed from the address space. + * + * @param v vCPU logically owning xsave_area + * @param xsave_area XSAVE blob of v + */ +#define vcpu_unmap_xsave_area(v, x) ({ (x) = NULL; }) + #endif /* __ASM_XSTATE_H */ From patchwork Mon Oct 28 15:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853703 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 8FF53D3399F for ; Mon, 28 Oct 2024 15:50:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826686.1241058 (Exim 4.92) (envelope-from ) id 1t5S0M-0000oN-7A; Mon, 28 Oct 2024 15:50:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826686.1241058; Mon, 28 Oct 2024 15:50:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5S0M-0000nN-2P; Mon, 28 Oct 2024 15:50:06 +0000 Received: by outflank-mailman (input) for mailman id 826686; Mon, 28 Oct 2024 15:50:04 +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 1t5S0K-000874-7I for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:04 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4b9450bb-9544-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 16:50:03 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a86e9db75b9so669318766b.1 for ; Mon, 28 Oct 2024 08:50:03 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:01 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4b9450bb-9544-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130602; x=1730735402; 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=M5K6Nspj7vj9C6pOy10gyRqgpDSP036JKIQJVf2EbyY=; b=H9iNfog2o4W3yH7pweobUggwnKMC3cbeaU/vJ9G/Fe1nsRBc331R8tjNFKjQnlLDAc vAtoc9SC66bTH5stZNyqi/6zLf91VqIGe4jBpksI3v8OyJUDC2jKenFgxCyE5AlaCa/o 964JPEf2Ij/rbwQRDMNMaubdlLhrXA3hYFteg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130602; x=1730735402; 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=M5K6Nspj7vj9C6pOy10gyRqgpDSP036JKIQJVf2EbyY=; b=Kysb1+TmLtv7qSUYl4zW06MdyVlMNlDH5dTTFEJhY/8gcRX8OFT2uMHZqqI3UuuVlu zII4nG8KcW0EQkT7uEYQFHAG14ZDUTufv022b0gDNhjlpB2yjIONWoLAE8sZ/6UOVDqN vRLecuSUPAcSmhjx2Hhst4KxlH4c86jGIX8pVPcWBkfgK4YkQia5GaCYF4PrR8o+IR3F 0s9rJTDZdPJWaukHfic0i+wKG0n2Ylp3yI8ER2iHywakqvP+AYSmokMrZSaZ/jqHMgdC 7QfaLt8pYbAeWWnm+IFEDnsLUpnSniqy7836YqW2EQprNSNkx79wf/x1y68zTyiN1oxF M/Ew== X-Gm-Message-State: AOJu0YwOHe7f0lny7dM4DZmDE952IYoZGjCFSIwKst0+iIKQzn7YnC1a uevUB3tMgm8dnjm4Np5KbrLqstuKu5krjq577aiHZKmMp+pQ3b0RtbXiPQGeJlHZhIRcabaDV86 v X-Google-Smtp-Source: AGHT+IENOkisnUIp/1ZDjvE3uVJQj41jLy+2PM5YAn3FaDRjW+hclm6tDVlVyAKvEArohDjyyFFtSg== X-Received: by 2002:a17:907:2da2:b0:a9a:a5c:e23b with SMTP id a640c23a62f3a-a9de619c1camr773093266b.58.1730130602288; Mon, 28 Oct 2024 08:50:02 -0700 (PDT) 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 03/14] x86/hvm: Map/unmap xsave area in hvm_save_cpu_ctxt() Date: Mon, 28 Oct 2024 15:49:21 +0000 Message-ID: <20241028154932.6797-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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..77b975f07f32 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 Mon Oct 28 15:49:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853705 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 9F0B2D339A2 for ; Mon, 28 Oct 2024 15:50:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826688.1241074 (Exim 4.92) (envelope-from ) id 1t5S0N-0001FH-SF; Mon, 28 Oct 2024 15:50:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826688.1241074; Mon, 28 Oct 2024 15:50: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 1t5S0N-0001DL-Li; Mon, 28 Oct 2024 15:50:07 +0000 Received: by outflank-mailman (input) for mailman id 826688; Mon, 28 Oct 2024 15:50:05 +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 1t5S0L-0008FV-Ho for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:05 +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 4c1752b5-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:04 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c95a962c2bso5541659a12.2 for ; Mon, 28 Oct 2024 08:50:04 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:02 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4c1752b5-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130603; x=1730735403; 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=hY/UrTCQ/vWU0sbBxlJ8N5ALQVl83VMvY6/kdegt+f8=; b=FJek+/D7mp0vn/T9HA2IbH50c731yiPg9/cjRpNDHKVx86eIvfLiQCvPG6ahNtbUR+ LV7oC4/RKRTUDyAy5j7XOQWW2/x5xlP4qma3T/3g1QZmlsJoWf7ltftn2eChnOZ7KCRs MqYziWqu8Jj3YWUyg7HFH6gYg339cTt96FkkU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130603; x=1730735403; 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=hY/UrTCQ/vWU0sbBxlJ8N5ALQVl83VMvY6/kdegt+f8=; b=Gly7dzCclPefjZNsd5+p9WUx8CvJxkN8DiUEr2eJGUEJt7iJUosNzK4tOs8t9SSWX4 FVzZn86SbHWOAsdjVnHQnsT8VnkWgD4CeazcBLqmVkgozhoxhU5UsWnEHTug0R2r6pJb hOkUz7N3zQnNHm7FdN/7sembCbiKxNhlfa/zxRbbG+/k/MYOxNX0iQsaXTc5YzDpOKj5 QAvDszfa8bbB/a9xg9hJgkejWY5Fh7h4PdB+2ugmt2JXUku210uXfVja7XtOpA0Ye2z1 PoXtiPJp0Rrkhc44bYMX67tr9y8hd9KlKpfkTIAu1aJ7l9mpNlwML0HCX9bkYeAlYSDS 2YbQ== X-Gm-Message-State: AOJu0Yw5CAF7kEtNNwPRUTikoCYELzfx9gBKc61yed043r8CmPbM01TS 5fAKIKLMjvwHTAWkZacqqwDD+6viRlVyXQpB189EHrOV2WU2YKWl9/XAYfp/mg9LCkGNHky2Ca3 r X-Google-Smtp-Source: AGHT+IG6StWqjpAO8DYedOrCCnEILK72ffLHyWgeM9Uz/5/G68jTWsMGvKh3D3LSCUH1wOiNDrZUFg== X-Received: by 2002:a17:906:6a1d:b0:a9a:4f78:b8 with SMTP id a640c23a62f3a-a9de5c922c6mr748802166b.2.1730130603202; Mon, 28 Oct 2024 08:50:03 -0700 (PDT) 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 04/14] x86/fpu: Map/umap xsave area in vcpu_{reset,setup}_fpu() Date: Mon, 28 Oct 2024 15:49:22 +0000 Message-ID: <20241028154932.6797-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 375a8274f632..a571bcb23c91 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -306,8 +306,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, @@ -315,15 +317,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 Mon Oct 28 15:49:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853699 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 B853CD33998 for ; Mon, 28 Oct 2024 15:50:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826687.1241070 (Exim 4.92) (envelope-from ) id 1t5S0N-0001A0-Jk; Mon, 28 Oct 2024 15:50:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826687.1241070; Mon, 28 Oct 2024 15:50: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 1t5S0N-00019a-Bb; Mon, 28 Oct 2024 15:50:07 +0000 Received: by outflank-mailman (input) for mailman id 826687; Mon, 28 Oct 2024 15:50: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 1t5S0L-000874-BW for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:05 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4ca4ce99-9544-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 16:50:04 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a9a68480164so620241766b.3 for ; Mon, 28 Oct 2024 08:50:04 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:03 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4ca4ce99-9544-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130604; x=1730735404; 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=k5/TXen51hB68I6BFGT+jmFtlRjBnBfjDOpUJmu9hDE=; b=TY/fIWVJd9hNosxSg3y3L6TwxGcyw7Z3XrbpVDP6KAO8hoYT8IWuoWN7fhgQSh5JGG +bBsdgJR4MDfiAdoYrWFTpEMiT1TOo7spC056dsdxpo+U0KpKG/fhZU79WPIiYqJ99bY ViUYA3oq4eJvH4rpmRy6UPRfPG6XgaiLJSg+M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130604; x=1730735404; 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=k5/TXen51hB68I6BFGT+jmFtlRjBnBfjDOpUJmu9hDE=; b=RNZV0/86H4+vsjKM0IYys36ILFAR9wTFeMPYBecQYl3eO8tljREINku+2EVhzV6dl6 fO2XhsxpHP9Pap1KENTjjcpzrZohtZlSkkR6xTjRNR3RVTStK6orPJcvNjYjqZFgVIkp hfVhha+VXhw43FknpHKCOOXBxDsmLRajY8GjZzcel0iJFsAznIfJtiltF7yHB7VKKU5a 4tEBBLEFukgvYVQo/atFGN2hu0W8nXZax18exmHaT26sz2xfJECjnFT26gHqTCscTMGi WS93vG7fzaNYdU/tL9KZxVfeb5xhiaJHZXZOmDR3AIqCPGpLiXPPgvIUh1x5VN2GkJuZ zRig== X-Gm-Message-State: AOJu0Yxprcl01SzgNs+btBwc1R8S25lC6HwdnhEuwZj0vjwd/5jz/WwO ztY4WCGg845vZx/vtnjhtCiO1xgUxsAzXvuJ4sTt2KeYxYtMQpvl9Bho7Wygh0BcXK5LIT/vNfI G X-Google-Smtp-Source: AGHT+IEuqJAcG2GYWLVnnngxRLpaSRDV3BwBCu+v1OexXNCj5m10aMlavT0wiEaUKGuKYvkiTGsvTg== X-Received: by 2002:a17:906:6a1d:b0:a9a:18ee:5106 with SMTP id a640c23a62f3a-a9de61e95a5mr760804266b.65.1730130604050; Mon, 28 Oct 2024 08:50:04 -0700 (PDT) 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 05/14] x86/xstate: Map/unmap xsave area in xstate_set_init() and handle_setbv() Date: Mon, 28 Oct 2024 15:49:23 +0000 Message-ID: <20241028154932.6797-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- xen/arch/x86/xstate.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index af9e345a7ace..60e752a245ca 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -993,7 +993,12 @@ int handle_xsetbv(u32 index, u64 new_bv) clts(); if ( curr->fpu_dirtied ) - asm ( "stmxcsr %0" : "=m" (curr->arch.xsave_area->fpu_sse.mxcsr) ); + { + 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 +1053,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 +1066,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 Mon Oct 28 15:49:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853704 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 9D806D339A1 for ; Mon, 28 Oct 2024 15:50:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826689.1241080 (Exim 4.92) (envelope-from ) id 1t5S0O-0001Mn-Di; Mon, 28 Oct 2024 15:50:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826689.1241080; Mon, 28 Oct 2024 15:50:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5S0O-0001LM-1s; Mon, 28 Oct 2024 15:50:08 +0000 Received: by outflank-mailman (input) for mailman id 826689; Mon, 28 Oct 2024 15:50:07 +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 1t5S0N-0008FV-8j for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:07 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4d1cebc9-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:05 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9a0c40849cso731818966b.3 for ; Mon, 28 Oct 2024 08:50:05 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:04 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4d1cebc9-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130605; x=1730735405; 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=vCUIaO5AAUJAl3VVRobAf52t1sH+3QDwfli/NHe1tzs=; b=cPAtnkReW2GjHosOwvGsYwTAOkydWbo96UeTiSRlrVpqo0ohTY7mlvtyCtkOmsJBQ3 fArpT3883r5gOsdxp8WGro8N70BJm/WjoPY00+e7QqHo6Pv+/lEugBsO5yeW+rDqM7yn EPbZz0GQVoKc0MtE8UOZ5gDe+0PH9RT+WTscI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130605; x=1730735405; 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=vCUIaO5AAUJAl3VVRobAf52t1sH+3QDwfli/NHe1tzs=; b=N4hcVtIKytbjnAVWOvodSrxKqnO4wiuJwBoE62VGnbUPUtihz171+ZEZoZFZSpGdNS HDwV5sF/6ovR8he9Y5KDbqCKhfACwnsbPT58EQS/97OTGk4LR/YezEA3iu6ic2aeUF3A BbBVhY8HZl7XoR3UE4kahX1CGgjH8k5h7Jl7ieMftzTa6mtjDwPm4+l7OebeQPxHvPHi Nr9ApgCJ1+zM8srdR+x7iGq/Tcg3jOzYoaTPn5JGoVSCxvIS7lQrJ4k6HQONpZ6s1o7w I8A/NK62uznZa7f7IVAdDGVpxhMx7Gv3LuzdLygnPdiTfiQX+oH5WjR4hEgtY7qJnLVX eCEg== X-Gm-Message-State: AOJu0YyP4/foT71RTzdS+VPqXxhcAdyGmVoIb0gGzM9yg/Hr5H2td4Om LD6Qpm5/5Bg8PJdBVdSX377vKwqXCxkexWjZaGAG7g1GXV4Pa1ZyU56YoDUmAAL/Q8jDQcfgw8c f X-Google-Smtp-Source: AGHT+IE5VF1LUnql9xYflHwCakwiEC09wAgohLGgcWNnxyhKcGI4YZSpn8NZ2zgcm3u36Kdyu5zrtg== X-Received: by 2002:a17:906:794f:b0:a9a:4597:a7f3 with SMTP id a640c23a62f3a-a9de619876amr890640466b.62.1730130604948; Mon, 28 Oct 2024 08:50:04 -0700 (PDT) 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 06/14] x86/hvm: Map/unmap xsave area in hvmemul_{get,put}_fpu() Date: Mon, 28 Oct 2024 15:49:24 +0000 Message-ID: <20241028154932.6797-7-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- xen/arch/x86/hvm/emulate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index f2bc6967dfcb..a6ddc9928f16 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -2371,7 +2371,8 @@ 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; + 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 +2398,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 +2414,8 @@ static void cf_check hvmemul_put_fpu( if ( aux ) { - fpusse_t *fpu_ctxt = &curr->arch.xsave_area->fpu_sse; + 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 +2469,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 Mon Oct 28 15:49:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853707 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 BE48AD339A3 for ; Mon, 28 Oct 2024 15:50:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826690.1241099 (Exim 4.92) (envelope-from ) id 1t5S0Q-00024d-OI; Mon, 28 Oct 2024 15:50:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826690.1241099; Mon, 28 Oct 2024 15:50: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 1t5S0Q-00024G-H7; Mon, 28 Oct 2024 15:50:10 +0000 Received: by outflank-mailman (input) for mailman id 826690; Mon, 28 Oct 2024 15:50:08 +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 1t5S0O-0008FV-4H for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:08 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4d9fdbdc-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:06 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a9a0ef5179dso650080766b.1 for ; Mon, 28 Oct 2024 08:50:06 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:05 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4d9fdbdc-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130606; x=1730735406; 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=JVXYPJCZuoH2OyHtUDCKgOdo7as5qgDULzyHGXZW2OE=; b=KoA5DhtSDYIPAB10JQZX7D80uvfd8+uvgt/7MlWoNTJfqFS/K2fzpWOa7u9eDyrymC 0M7w38WkzG2xoxquTQ8Torm1TG2WNdOgAVNgS7TFSmcSztZrajMnmMsjEO+TEw7Q5ptv wN6y1Vrp6bTDpHKXdA9UPZ6IhAO2NQg2ic9jI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130606; x=1730735406; 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=JVXYPJCZuoH2OyHtUDCKgOdo7as5qgDULzyHGXZW2OE=; b=g6tEpy0boAdqpfs6G9s3xHEpR3IsYVUdWuPQDQaskkqRLHjc4kyQqsnBgz5zhnkCyd 6PBHFpwlwJ/k6duzYcBInVcGa0tKzGWBMkN/UY9SiYvEcGy1n4p0LS1JoZk0z7/ZYBdp fhNwYbJgNF6bhLgIfFYKnmiJaKdJ94MJo7v3ePP0jvfT9qADMvzM+bb8OFaePczcw2HM hf0hjb2bYBqBc+eY9ITVtaHvVSfukDlnslrZLqTdpVqFan9DvdMJmErLUmWX3qoGTtu8 iVCiB7bVzMPQSB7zz6vwYjhYtov5kXewaKWokHQND4txDgW3pFUEWwsIHPfauU5JsFY9 Y92A== X-Gm-Message-State: AOJu0Ywds2uNAI+x90MVtOW+PlPo1XnbZZR5drY8nbdpcBjgZ9FEs5L0 A9cGSwDbkA41sVVsW22c/7x3IM2Shd94bTYTMuQ0Y/gFdg5mytFTtttknJkmQwqstJVYlMpYikn V X-Google-Smtp-Source: AGHT+IGx8bTDgJ193xI9eWu9eQdCHqvY2+04eGQudCrPjMKopwDOW6yd3cRVje2O0p1v6XvFRnf9/Q== X-Received: by 2002:a17:907:728d:b0:a86:8e3d:86e2 with SMTP id a640c23a62f3a-a9de5d6e1f2mr935295266b.11.1730130605742; Mon, 28 Oct 2024 08:50:05 -0700 (PDT) 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 07/14] x86/domctl: Map/unmap xsave area in arch_get_info_guest() Date: Mon, 28 Oct 2024 15:49:25 +0000 Message-ID: <20241028154932.6797-8-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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..8f6075bc84b8 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 Mon Oct 28 15:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853706 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 EF65AD339A0 for ; Mon, 28 Oct 2024 15:50:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826691.1241104 (Exim 4.92) (envelope-from ) id 1t5S0R-00028F-BJ; Mon, 28 Oct 2024 15:50:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826691.1241104; Mon, 28 Oct 2024 15:50: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 1t5S0Q-000275-UF; Mon, 28 Oct 2024 15:50:10 +0000 Received: by outflank-mailman (input) for mailman id 826691; Mon, 28 Oct 2024 15:50: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 1t5S0O-0008FV-VJ for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:08 +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 4e1db68c-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:07 +0100 (CET) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5c94c4ad9d8so5620233a12.2 for ; Mon, 28 Oct 2024 08:50:07 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:06 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4e1db68c-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130606; x=1730735406; 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=U/RnzlnP3G9CO4SusiLr8zIyIe7394ke2U9MPNKtXhg=; b=O6XncR+HGoONTeR42svBZ0ktT0A85b789pK57ek5U/GAixGKJXujbWwjw9nkBW7atJ E+8QGGRa59byB6cRLD+bfnrFDnyErhV2KEtNk4ZtLc1jJvvLbkWTXUQ4lg69M0FHh+8H fbpHHfJAz6J2QTucGCIaS99WJSFJwmdpLafws= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130606; x=1730735406; 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=U/RnzlnP3G9CO4SusiLr8zIyIe7394ke2U9MPNKtXhg=; b=fjOaHjEDKc5WZbpGqFBKawuhqLonz1biXHN6jA1fQu7GzXBgLovfxS+6Wd7vQZak09 C2f1FjP3GNp8uuDKMbJZke2iOhQmK9e/fPPQi9kus1tyGoyweLQGNAnaXgaIN3DgGm6+ VBvf7VHvwCdXRxd6aX2NxHWy3onbzIp9UMAlnHqjfLJHu94AztgAyL0Xz5et11dt2haG dAXpq6nBwVCILDLf+ncOSduCpFEuAIIU2qCvJ/LJR/iFZAxYAan+/dElVaHWe+/w6F+D LtQZS2FXEiK7KROOaxVxsS7mlJH90vn9un0f94IEU8CCJ8Xu5M1juZyXrBsCnzRw4hHs eQKQ== X-Gm-Message-State: AOJu0YyxCj21mw8JApE8W75wUXKKiPtZ9kqdelPpmNW4FKUNoylk6Ulw akJ0FP8FKbXbcKPE0uC8dQPK9w+wz6TgzovP69QkAqnayF6I+tOAU8hRGgjDhjuMzc5DDt6shgt L X-Google-Smtp-Source: AGHT+IEKmbjye0E8XCJyiovjf17ficSIKt+h3itpmbWhUSPk51uXP6fJi6EvzMuZ6L65ZsGREr72qw== X-Received: by 2002:a17:907:31cb:b0:a9a:3cf:cdb8 with SMTP id a640c23a62f3a-a9de5f72a86mr852630566b.36.1730130606628; Mon, 28 Oct 2024 08:50:06 -0700 (PDT) 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 08/14] x86/xstate: Map/unmap xsave area in {compress,expand}_xsave_states() Date: Mon, 28 Oct 2024 15:49:26 +0000 Message-ID: <20241028154932.6797-9-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 60e752a245ca..4019ca4aae83 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 Mon Oct 28 15:49:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853708 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 B7C87D33998 for ; Mon, 28 Oct 2024 15:50:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826692.1241109 (Exim 4.92) (envelope-from ) id 1t5S0S-0002GO-7b; Mon, 28 Oct 2024 15:50:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826692.1241109; Mon, 28 Oct 2024 15:50: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 1t5S0R-0002D9-Ju; Mon, 28 Oct 2024 15:50:11 +0000 Received: by outflank-mailman (input) for mailman id 826692; Mon, 28 Oct 2024 15:50: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 1t5S0P-0008FV-QF for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:09 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4e98f673-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:08 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a86e9db75b9so669331866b.1 for ; Mon, 28 Oct 2024 08:50:08 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:07 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4e98f673-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130607; x=1730735407; 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=BVQr91XZlcFHKTZl1uI+zUZ3+gisoPjkP7pJQrXj6Go=; b=MfUNumKTljT6wgPlIt4UNi9ZUHNwx1vhLw7gMn085JDV8UNVsrwSrX0gj5+wstiwu/ mP/SE7tJQRYMxLonKrfqlnXiyN9EtudWe5Z847+ml74LkFUEUaYCa0utvUeHi6ZMvShy 6Jsya90FcYEkhBdMbRHaKLf74XfarQxRmk1hk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130607; x=1730735407; 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=BVQr91XZlcFHKTZl1uI+zUZ3+gisoPjkP7pJQrXj6Go=; b=CTjod5ch/PrC5Uf1C7o6jOGRL/D07GYQjU0CIu9wtUe1oVDa/jhIp2qhbdoReRxD2f TDv7/bp+Aa6aKzev7B/alXJhV0ObnzYCCdiTVz7kOsHEtZTExdpGiZJdQvPXoHs51p7b a7mgKO8hC59S4i2YwPW7utTkqdlvLpkjh83rT96uxXIw05oczZ7BFEXtoHxyVTvpcZCH 1M3358w9sybvfp6Uwo2jVJhTWLuOFcv2OQINx/URp58mk97AGz8UeIzq5UpUjZS29vuO aRa+AonMHCRKv/Q4BYeDmR8QdK3Z0aNFtA4d7D9Ns/FDNGC+AB7Hto4aV/BmNClblNpw OG7Q== X-Gm-Message-State: AOJu0YycqrhH9E8bvTIi8y1ESat1PLdBlKXiectz8x2WUKeAoM4UwZzs 70Cn93Lip5afnjVnJ5iRcDT1DnkyHR3RQtxWm3N1g6UbJj/CZHvGzEv6MYCgCe4HF31lq+5nVfS q X-Google-Smtp-Source: AGHT+IE9C6AE9q4nMjRt1C+VfW2rH9XoLb9J6ZQJla+EMe54GmyWuVpV1KfcGJcfCKDpZX5aG3UOew== X-Received: by 2002:a17:907:1c9d:b0:a99:ed2e:3875 with SMTP id a640c23a62f3a-a9de615ece4mr713802766b.42.1730130607479; Mon, 28 Oct 2024 08:50:07 -0700 (PDT) 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 09/14] x86/emulator: Refactor FXSAVE_AREA to use wrappers Date: Mon, 28 Oct 2024 15:49:27 +0000 Message-ID: <20241028154932.6797-10-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-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 --- xen/arch/x86/x86_emulate/blk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/x86_emulate/blk.c b/xen/arch/x86/x86_emulate/blk.c index 08a05f8453f7..d5b59333823f 100644 --- a/xen/arch/x86/x86_emulate/blk.c +++ b/xen/arch/x86/x86_emulate/blk.c @@ -11,9 +11,11 @@ !defined(X86EMUL_NO_SIMD) # ifdef __XEN__ # include -# define FXSAVE_AREA ((void *)¤t->arch.xsave_area->fpu_sse) +# 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 +294,9 @@ int x86_emul_blk( } else asm volatile ( "fxrstor %0" :: "m" (*fxsr) ); + + UNMAP_FXSAVE_AREA(fxsr); + break; } @@ -320,6 +325,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 Mon Oct 28 15:49:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853709 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 7DFE1D339A4 for ; Mon, 28 Oct 2024 15:50:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826693.1241115 (Exim 4.92) (envelope-from ) id 1t5S0S-0002Pa-NN; Mon, 28 Oct 2024 15:50:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826693.1241115; Mon, 28 Oct 2024 15:50: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 1t5S0S-0002Lh-F0; Mon, 28 Oct 2024 15:50:12 +0000 Received: by outflank-mailman (input) for mailman id 826693; Mon, 28 Oct 2024 15:50:11 +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 1t5S0Q-0008FV-TX for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:10 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4f3340e9-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:09 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a9a156513a1so696754166b.0 for ; Mon, 28 Oct 2024 08:50:09 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:07 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4f3340e9-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130608; x=1730735408; 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=Avz5HmUUjPMBeZFfQQx+SO7GKCNtStFnZFq73+xyyr8=; b=fGBlgYXj4aQ4LFrwVgbw+qOOp7iTsL3BI/zt8K1okiw4iXpEd8PN2i5JVyRPXy1Pdd dKtik0MWxssAdblNUvu+RGlKMDFLr6kcnYrPou2m6NQSa9bprIwfy0mJjgVXmFXvyekA TvQKrRuwXoJDKTZ6tos1qFRgJesa0/6R78JoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130608; x=1730735408; 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=Avz5HmUUjPMBeZFfQQx+SO7GKCNtStFnZFq73+xyyr8=; b=XlNoRR0On38H49KC0KvBpWVLZ2hnjqw9a+4h4gFRwFmuxVkOdS1Gzhu1gTKIM4relk G6l6JOqtWc3DRwuHlj36zR8B77ynoxnVKrOqXDgq26Yh5ZqnA78ShmZtEzHF2q3hnPuU VeLqwlbdu+0De3wTG/9vu0Y2JxIZNM64urz7co3h/wKhpldhi4AUG9AHnOLp5H7vdtzg xjT9aIub4xoKSNvDNNo5s17rDKkNFwnMKe/w3+4rzIBlJ9xwTkR1R9CLMjs/2LBm4TVL 7paTVs+9n9YDfEIhFMI8nR66F+fmx2RtvbMGKGDDLQyxENVFBs2obleA4ZzzsR/Pn9Qi Zu2g== X-Gm-Message-State: AOJu0YxLU+bt6FxNKQ9D543WUE6uPYhYIsOV9j0vcsqBeG/7VIriL0eA 5dt8qyB6fapeifQ9K9egEJdmji0BbgPUp8+SJZ8xeUTkaUFJ7XFzcp+gx/FsDlNZcimtTrEITCF H X-Google-Smtp-Source: AGHT+IFYkudP6zAU62spG2PVUAK8m0Vhgf6c+oKiNEtCmUOgIOvJL7/w8NXyEKEp5JICHhs/Va6zEg== X-Received: by 2002:a17:907:9281:b0:a99:d3f4:ff3b with SMTP id a640c23a62f3a-a9de5f65689mr830166466b.27.1730130608439; Mon, 28 Oct 2024 08:50:08 -0700 (PDT) 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 10/14] x86/mpx: Map/unmap xsave area in in read_bndcfgu() Date: Mon, 28 Oct 2024 15:49:28 +0000 Message-ID: <20241028154932.6797-11-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 4019ca4aae83..2a54da2823cf 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1021,9 +1021,10 @@ int handle_xsetbv(u32 index, u64 new_bv) uint64_t read_bndcfgu(void) { + uint64_t ret = 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); @@ -1049,7 +1050,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 ) + ret = bndcsr->bndcfgu; + + vcpu_unmap_xsave_area(v, xstate); + + return ret; } void xstate_set_init(uint64_t mask) From patchwork Mon Oct 28 15:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853711 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 192C0D3399D for ; Mon, 28 Oct 2024 15:50:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826695.1241133 (Exim 4.92) (envelope-from ) id 1t5S0U-00031j-LS; Mon, 28 Oct 2024 15:50:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826695.1241133; Mon, 28 Oct 2024 15:50: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 1t5S0U-0002yd-BR; Mon, 28 Oct 2024 15:50:14 +0000 Received: by outflank-mailman (input) for mailman id 826695; Mon, 28 Oct 2024 15:50: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 1t5S0R-0008FV-J1 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:11 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4fb99d1a-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:10 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5cb72918bddso5920168a12.3 for ; Mon, 28 Oct 2024 08:50:10 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:08 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4fb99d1a-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130609; x=1730735409; 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=NrpqNXgaGWCogi9sNhxEA3iqIJalu/4gAkUE90pvCh0=; b=WTQFFIPbAb2KLFsUVTOrCZKvWnKHHvlawjDT53CJHT+qK5N9P1JZKaUnjKZe7iRCxy Xbnt7hAQpzd+818uNA58gI/suqfubtYY0zqw5TbPnOPNz+oho+kCeIMe+nG/L0NWjbxz 40gBDn07QNb1x9KsCPuYxyVvgJvJMMz9C2ITE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130609; x=1730735409; 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=NrpqNXgaGWCogi9sNhxEA3iqIJalu/4gAkUE90pvCh0=; b=VaRtSC2ZF63o1HIIW1W5qMrGLxQ+fvZHBo19C7pm/yBAEGFyJ+l3agMD2LXny26BWn 5hncuTz6J0ut2WP4oi/KZPQMnP/FapmZccaRrv10kGV/Js9jUrcj1R4s1Z+eGtzObyVM UFoTzdnGnsQ1NEGiY7q+wR/kvSqFfBxu74uBF95OX1DcwBBXm8l8IyXh84ovdKmi+VNT A+EXM/HCW0Sjdovi4UUeHvIk7ZIZPQKNR8x2KXi31TwqH5IFSIZa2JSfNvex49bEpzT4 DeOHV883xHJwZA4NMI8EaPgDQuM6zh+LnUzP2Qzlao3F7isLdiWIQwKJ6pPUoL1zRRCv Ggyw== X-Gm-Message-State: AOJu0Yxob9B1201OGCp0rZYT6HeESk977Ikfk/SHR6rCd0+nPacm2fer PHAaCW7wgTIAszy/v6deYzF0WkF6PK0cruMo9M5Th5zv9c09h7a5obKIA6wjUVoxrzhp13LrjEv F X-Google-Smtp-Source: AGHT+IF+QfFAUVZf3RFIYO1/1CSUdBaGD9aUJf2nTNYdCWZjxveXstimaXqORZSmU3y6L7iziuZUNg== X-Received: by 2002:a17:907:7282:b0:a9a:294:cb30 with SMTP id a640c23a62f3a-a9de5d985e9mr805426666b.16.1730130609298; Mon, 28 Oct 2024 08:50:09 -0700 (PDT) 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 11/14] x86/mpx: Adjust read_bndcfgu() to clean after itself Date: Mon, 28 Oct 2024 15:49:29 +0000 Message-ID: <20241028154932.6797-12-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Overwrite the MPX data dumped in the idle XSAVE area to avoid leaking it. While it's not very sensitive, better to err on the side of caution. Signed-off-by: Alejandro Vallejo --- Depending on whether the idle domain is considered ASI or non-ASI this might or might not be enough. If the idle domain is not ASI the XSAVE area would be in the directmap, which would render the zap ineffective because it would still be transiently readable from another pCPU. --- xen/arch/x86/xstate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 2a54da2823cf..a9a7ee2cd1e6 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1025,7 +1025,7 @@ uint64_t read_bndcfgu(void) unsigned long cr0 = read_cr0(); struct vcpu *v = idle_vcpu[smp_processor_id()]; struct xsave_struct *xstate = vcpu_map_xsave_area(v); - const struct xstate_bndcsr *bndcsr; + struct xstate_bndcsr *bndcsr; ASSERT(cpu_has_mpx); clts(); @@ -1051,7 +1051,10 @@ uint64_t read_bndcfgu(void) write_cr0(cr0); if ( xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ) + { ret = bndcsr->bndcfgu; + *bndcsr = (struct xstate_bndcsr){}; + } vcpu_unmap_xsave_area(v, xstate); From patchwork Mon Oct 28 15:49:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853710 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 614A6D339A5 for ; Mon, 28 Oct 2024 15:50:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826694.1241124 (Exim 4.92) (envelope-from ) id 1t5S0T-0002ay-Bo; Mon, 28 Oct 2024 15:50:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826694.1241124; Mon, 28 Oct 2024 15:50:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5S0T-0002Yu-1h; Mon, 28 Oct 2024 15:50:13 +0000 Received: by outflank-mailman (input) for mailman id 826694; Mon, 28 Oct 2024 15:50:11 +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 1t5S0R-000874-Gh for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:11 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 504a4b77-9544-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 16:50:11 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a99e3b3a411so884982166b.0 for ; Mon, 28 Oct 2024 08:50:11 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:09 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 504a4b77-9544-11ef-a0c2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130610; x=1730735410; 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=jNA4CkiYLhWj5GrlTVNs4LHtyrIqkd6cYmJb5XAmLwY=; b=bRW7UQpLL5dW7iovCtabjxKn8dtNie9TzyWueM+mL47ZagHnWnQcrruC9krFVi3Ij6 S5Y2Wy2vLZmjoM1/joecst3tXfvvVb1o2hl6Z0CMQaAjgSAoAaYBVTVoffut7mKvtKab VA62XIwN6uW+V8Uy9OetwrWFpGcgNBhbKrAqI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130610; x=1730735410; 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=jNA4CkiYLhWj5GrlTVNs4LHtyrIqkd6cYmJb5XAmLwY=; b=r4sSCwoIxNwu2a6Inix3IHzSNI/cqbS8WsJw9saYnGiD0OcjVmSuYJJHEUEhsh3Mff tIgFGCtkcgIM2Q3LfXXxLMNnUawu+Is+gS7x8tOFfq+heIEAhKACHG/JWSdWG01RiIx7 OCTc3JU+tjC2IMxVB1dmt8nXVZRcEJUzefO+Y74XHOc/VaqcWOLRx4pweRc+aAOsXTeK Eg+OUHVT/+w5j2GYUBYsrOn6iLaZgBHHjszxB2T8sPWjdzjiE/kfaAGiIWObzJu/6gUg rNQTNjbthzRDRKmeW43olt1/HHKisxOUPaDlAU+IVI0Xbx2xtuqa1kf678LpssCBQ90u A3MQ== X-Gm-Message-State: AOJu0Ywa4j4kenT+1pvnRbOKOijSGLQbI1swH1W5qxnAh7XXGJF2RGgt RSqknPPvClyvh8LZKVQw/zFBYfjkbS6R0wgHtHqjOtxH/vQy7OWPAvyJVRBZa43gE4VbJ5lTnkc L X-Google-Smtp-Source: AGHT+IFurN0UhPHZ+j0cvRqeJ5wZHyxfY+2OmUVsvN5Qor4ojhql7E6XWaaLOyUGpDr2fxUAzaiO0A== X-Received: by 2002:a17:907:9815:b0:a9a:a666:4c7 with SMTP id a640c23a62f3a-a9e22ac6eecmr4045866b.24.1730130610198; Mon, 28 Oct 2024 08:50:10 -0700 (PDT) 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 12/14] x86/fpu: Pass explicit xsave areas to fpu_(f)xsave() Date: Mon, 28 Oct 2024 15:49:30 +0000 Message-ID: <20241028154932.6797-13-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 a571bcb23c91..5950fbcf272e 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -130,7 +130,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(struct vcpu *v, struct xsave_struct *xsave_area) { bool ok; uint64_t mask = vcpu_xsave_mask(v); @@ -143,15 +143,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 ) @@ -266,6 +265,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; @@ -274,11 +275,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 36260459667c..104fe0d44173 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(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 a9a7ee2cd1e6..518388e6e272 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(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 Mon Oct 28 15:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853713 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 807D6D3399B for ; Mon, 28 Oct 2024 15:50:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826697.1241158 (Exim 4.92) (envelope-from ) id 1t5S0Y-0003pu-1P; Mon, 28 Oct 2024 15:50:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826697.1241158; Mon, 28 Oct 2024 15:50: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 1t5S0X-0003nf-LI; Mon, 28 Oct 2024 15:50:17 +0000 Received: by outflank-mailman (input) for mailman id 826697; Mon, 28 Oct 2024 15:50: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 1t5S0W-0008FV-42 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:16 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 50c7b84f-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:11 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a9a850270e2so737391466b.0 for ; Mon, 28 Oct 2024 08:50:11 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:10 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 50c7b84f-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130611; x=1730735411; 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=oF/zafBR21s51XQ55xrj7f7wP/qB8eTuRfs/webK9Bc=; b=f1cDNAWcjJX4J37+CTPWbXlYgvwX/Jz5sjH2B7yHzmXkRJgU3ENIiLy+se7hD4X/5f t9zzo//623V/MD3zrgzOxkWBokb/ivVlcZh6YRNNOppxpM3jNzlNR3N17YI2Ge+ksIut nFLh2yig6t4c+KXcsQDmuGECIrIOdvL85Qi3k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130611; x=1730735411; 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=oF/zafBR21s51XQ55xrj7f7wP/qB8eTuRfs/webK9Bc=; b=Zhfx38xO15hlv9imHY7hnIx1hzHQ3c2F052vKj6E4NiRsyNm+dSzNm3j+0yAF7gW5G EJcqZPGl/WdA3V7FiCBSthw92ZzpwM0lC8fINJdV3MmkhTCb3pv+BGxMcq71+97pS//S /iV7ilzkVp9oRS186o0mr2XJFcHKUy9QpLpmFweP5ZVM3G4vW+mQSZp7+TRqPlIx58Il 5LHPrhO5oHuc5LQt7jD+WnHDcprog85N9BVo/Ki0nOa5tumZQrg1P8GVXxLPKNWKTwsh wQAYMdoF1kyzuDZuV2GS8mBRGJKDR8VrD/9lFgeSw+4i9PrUbp+VMYIl1m9mNUjKtaUJ lGUg== X-Gm-Message-State: AOJu0YxTLAf+7xwjjeSJ6gE8lTThIfWiFDN4DQ8oma0mBFUK3xvddnLC WtvNvVI2QDwiOcajB4ApCTf/mlcmRwpSMmgMK/dW+GnIuKStS+k7vVbuYImcHjslb2/VYZ9HyRS H X-Google-Smtp-Source: AGHT+IF3/bhrLgSOziE7SwxQmzzMAg6HWwkCFCduzdTekcWhgq6v2MAPrFNTaOqxjidfqXp1wB6P8Q== X-Received: by 2002:a17:906:f591:b0:a9a:9df:5581 with SMTP id a640c23a62f3a-a9de5ee8bacmr837394266b.38.1730130611065; Mon, 28 Oct 2024 08:50:11 -0700 (PDT) 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 13/14] x86/fpu: Pass explicit xsave areas to fpu_(f)xrstor() Date: Mon, 28 Oct 2024 15:49:31 +0000 Message-ID: <20241028154932.6797-14-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 No functional change. Signed-off-by: Alejandro Vallejo --- 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 5950fbcf272e..7e1fb8ad8779 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; @@ -31,16 +32,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 @@ -197,6 +196,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; @@ -211,12 +212,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; @@ -226,9 +228,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 ) @@ -240,6 +243,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. */ @@ -250,10 +254,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 104fe0d44173..43f7731c2b17 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(struct vcpu *v, struct xsave_struct *ptr, uint64_t mask); -void xrstor(struct vcpu *v, uint64_t mask); +void xrstor(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 518388e6e272..aa5c062f7e51 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -374,11 +374,10 @@ void xsave(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(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(); @@ -1010,7 +1010,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 Mon Oct 28 15:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 13853712 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 EA3DCD33998 for ; Mon, 28 Oct 2024 15:50:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826696.1241154 (Exim 4.92) (envelope-from ) id 1t5S0X-0003j4-Dj; Mon, 28 Oct 2024 15:50:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826696.1241154; Mon, 28 Oct 2024 15:50: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 1t5S0X-0003hF-0R; Mon, 28 Oct 2024 15:50:17 +0000 Received: by outflank-mailman (input) for mailman id 826696; Mon, 28 Oct 2024 15:50: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 1t5S0V-0008FV-44 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 15:50:15 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5144c1cb-9544-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 16:50:12 +0100 (CET) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a9a2cdc6f0cso603068166b.2 for ; Mon, 28 Oct 2024 08:50:12 -0700 (PDT) Received: from localhost.localdomain ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b3a0834a6sm387674066b.191.2024.10.28.08.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:50:11 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5144c1cb-9544-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1730130612; x=1730735412; 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=HwNJgVlmgOrKpINGfBXiXo/pOeaz7GckymMD2iqzF3A=; b=Duuih0KxloKm6sWNfEyA3X8M8+QqdQBFfStVqYKNepZMoDGZ4GgrU/L3nbIDlpkcIR Myv9lnFxGJi9oPLOGO9zcTQPANVGlnKp0GyPFPDqIgQlRmmf9twubJSexKwhr7pkb6Lh nJFfBKpdDvM8xntw5V1pnJgPDVORJsZHx7X/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730130612; x=1730735412; 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=HwNJgVlmgOrKpINGfBXiXo/pOeaz7GckymMD2iqzF3A=; b=kVluQsc3kD8D/uZAppkHV2Mi/L2VntPoBw/b3jT9Fc8LdPM4PoQHenK65uCq07PG3F gsRKRBubQDAqrc/TwbodAFb76kpaDqHUVkmW6zFJkQz2KTpM43+N8fLJUPXS1Lo0d07Y a6RKFCXNUVBJ2vuQd5jbzl11v+O6WOtc+HAWfqzrgYwHL5Uza5aRQrEBqr+LazgfS3B0 Ri+djPBzavRK0SwMbdqtZcEDvHITXGUqSfqbbAsRB0KFHMBWAVY9ovAn9uPaGbzeNCS0 cFHgCY5tcK/j0dwgG3962U0QegvwdUll2ENbkCJfVeIOhKGOnMC8ofZhPxambsEbfmhW bVug== X-Gm-Message-State: AOJu0Yx3BjKFw4X6/WGQZjLabr0QIimiUYkTow3VXtpYXBnqZWV+zgTb PEQyIV3weq75Yv2u4VK4d/1IotKKuSys/6eMD1norR9pDIlTo8Krh5HuQ5ehXoTH61qdTWnwrHV E X-Google-Smtp-Source: AGHT+IHEY1nVRqaVDFBcRPDXXekAHbeOYazAPOBV9yuB9+xZ37aBGYXnmRkAxgllujT4PRIvJffbng== X-Received: by 2002:a17:906:c14a:b0:a9a:80bd:2920 with SMTP id a640c23a62f3a-a9de61990b1mr811601166b.53.1730130611929; Mon, 28 Oct 2024 08:50:11 -0700 (PDT) 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 14/14] x86/xstate: Make xstate_all() and vcpu_xsave_mask() take explicit xstate Date: Mon, 28 Oct 2024 15:49:32 +0000 Message-ID: <20241028154932.6797-15-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028154932.6797-1-alejandro.vallejo@cloud.com> References: <20241028154932.6797-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 7e1fb8ad8779..87b44dc11b55 100644 --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -108,7 +108,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; @@ -125,14 +126,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(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); ASSERT(cpu_has_xsave); @@ -213,7 +214,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 43f7731c2b17..81350d0105bb 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 aa5c062f7e51..cbe56eba89eb 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -1002,7 +1002,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;