From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130627; cv=none; d=zohomail.com; s=zohoarc; b=fi/z5uV/Jzjk4TLeZlR6okexUWLX5YAUr3rnUax7I8tLY1bQkFnlVK7fZNAnnYbEItcOW9KVrgiX1HKtTyvftsabt9YSEBeVt1MCr1LnmuwxWm2EUPVU/9fUPwPyBrN/PIrJXbpQLwoKPRG6CrAHB1BuEu6CyWt5BggKfL5vE4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130627; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DPLr0d8FwquAzKliN25Vvro3xH1NV3dTjQJhxaKuYlk=; b=NhOD2RnlnHwARHAU+jBpwAqfJ7b5C4re9dUCtSM6XKIaPj2Bxg3xXDA0/4OMOcak9EySqyA+vl86xLEXLPZDtRZObH7/el4zP1FInnkVZj+7gyOhy4tP/f08B0mFxxCTdXoMktCGfmgoy+Df70P1XBlLbdwgIcYroidjuRSzcB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130627557503.4261446231802; Mon, 28 Oct 2024 08:50:27 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130629215116600 Content-Type: text/plain; charset="utf-8" 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 ma= sk) { bool ok; =20 - 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 =3D vcpu_xsave_mask(v); =20 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. --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130627; cv=none; d=zohomail.com; s=zohoarc; b=Shcv4WpZ0BqyRfTXH6JOxivgiZEKm02VV4CZWvWHLKl3T04YU2Iuo8vZtUDtEhM950LPXNGZy/JlwT9ieu+Feu3jTj8Eo89JFkEHw6qMCWflEdIpKxAXnvbYjnBUzTkU3mJqKfzJh/iCy8gH7qSYLZg8h8BfOYUorIjtTqmfrPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130627; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=W4k/sSFYh0TQGRGsfutUPLlHi3zFXSiHFIADoMp0Wgc=; b=TFWNkyxmp+7sQTtZBqQ3wAYZ8+xyRMsNTBMPbQ4GyJCX9co4xLhE0uwPUDTiws7ofQNYRLIAc2f6uLHJH2y4RpabPCsdK2oDiwAq9uh07Inje/JRI4CYH8HQUXUoHZ8MmJKpQ6UUDvoWbc5X/iVF0+gqTbckaGov4nRRZd0SUnk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130627438647.711826560901; Mon, 28 Oct 2024 08:50:27 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130629222116600 Content-Type: text/plain; charset="utf-8" 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/x= state.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); } =20 +/* + * 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) =3D NULL; }) + #endif /* __ASM_XSTATE_H */ --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130625; cv=none; d=zohomail.com; s=zohoarc; b=CiIib3shUQELq2Y8/OyDGiDerfrfxsZQU90Yc+CJR5E/YpAhseVMKDw0o4yOhJVfRPI5lBP3CBqjAcsDsH2yh83WdHBfJwEEJ0Nop6x6A5VWf+QiTaorc0LPaC7+Xl1qb2p+FNk39RYwGGKCKFttM8XhrbvKK95iFWPdzLEe+qU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130625; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M5K6Nspj7vj9C6pOy10gyRqgpDSP036JKIQJVf2EbyY=; b=m2Y8UuyDguiBsUCc/MOzORgKJU1xaxffVPo+wuhqh/ywnS/6/uJvkaIb+KF83j04UJeMBDVNW3QdqLPbeWLugetl9ulqojtBdf5KcEIGuKI88iPCAs9YyxppQoUpc4XSdvG8iSSPpFBiNHe/pJyUKMGrL5b/lSIriNTxyaxOKg8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130625709230.34807393780625; Mon, 28 Oct 2024 08:50:25 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130627367116600 Content-Type: text/plain; charset="utf-8" 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) =20 if ( v->fpu_initialised ) { - BUILD_BUG_ON(sizeof(ctxt.fpu_regs) !=3D - 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 =3D vcpu_map_xsave_area(v); =20 + BUILD_BUG_ON(sizeof(ctxt.fpu_regs) !=3D 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 =3D XEN_X86_FPU_INITIALISED; } =20 --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130624; cv=none; d=zohomail.com; s=zohoarc; b=ZOyRM+mKNjywht0mt4hUkWKoRFZ/nFbnPsIUoFPnuwYE+OpQZ8W/dt/UlroRODu0ihBrHYUDfvu5bMadBNMiF8tsbhKgXKPSovUBYOS4GN+IU27eLBDkUPeMbNMvXeQ9K2g5s7xPlntod3iuByI5UwvVTT32txHqWMrBcJxqki0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130624; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hY/UrTCQ/vWU0sbBxlJ8N5ALQVl83VMvY6/kdegt+f8=; b=G15X4HJj302Gv/SwDTkP4Wkjkeka4qHjRektXIKjuLdLA9O6hXlNcvVq9domFBy4hIA2cVzqhRVKFg4xCa6RqgRs273bvEEdaDkAP9OJ3ofX3gXSSUtEGms361u1g3OSsC9RS6SDJnRIfmgkacWnp3uQJCDpAaLWmZu3GhFPPL8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17301306239971009.9076293489536; Mon, 28 Oct 2024 08:50:23 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130625231116600 Content-Type: text/plain; charset="utf-8" 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) =20 void vcpu_reset_fpu(struct vcpu *v) { + struct xsave_struct *xsave_area =3D vcpu_map_xsave_area(v); + v->fpu_initialised =3D false; - *v->arch.xsave_area =3D (struct xsave_struct) { + *xsave_area =3D (struct xsave_struct) { .fpu_sse =3D { .mxcsr =3D MXCSR_DEFAULT, .fcw =3D FCW_RESET, @@ -315,15 +317,21 @@ void vcpu_reset_fpu(struct vcpu *v) }, .xsave_hdr.xstate_bv =3D X86_XCR0_X87, }; + + vcpu_unmap_xsave_area(v, xsave_area); } =20 void vcpu_setup_fpu(struct vcpu *v, const void *data) { + struct xsave_struct *xsave_area =3D vcpu_map_xsave_area(v); + v->fpu_initialised =3D true; - *v->arch.xsave_area =3D (struct xsave_struct) { + *xsave_area =3D (struct xsave_struct) { .fpu_sse =3D *(const fpusse_t*)data, .xsave_hdr.xstate_bv =3D XSTATE_FP_SSE, }; + + vcpu_unmap_xsave_area(v, xsave_area); } =20 /* Free FPU's context save area */ --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130626; cv=none; d=zohomail.com; s=zohoarc; b=BK0s6sry1nXih/tqaXUNoKnBDaYmSufWpbqHEwqmm3V2JnoDW+iEB35VifDG1QEEGSJ6qunUsBarCfwmXLl/6fQQ63GrN7Ih4nxEjAEncPryOTsT+V5XDCr4+QFBscrsjUHP+tdW+HZdrElH85ZbzRvehnRUL29AJc9UQlhkAw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130626; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=k5/TXen51hB68I6BFGT+jmFtlRjBnBfjDOpUJmu9hDE=; b=gx+m9MJgc7G/gCaAb3tivUEenNZEAXnfFvXEjgeipG0H1o800SIzFBB7XZd/u2QSoc2yHs5Thxhfr6WHeaVXQMDMX/W3LLSbS2IYohzu8cCXiEzoRyq7yCOjzSZk4k6MrjZ3dZ1OJURIIc7pb1dcD1PHEzscnBLXGnk6jMXMfU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130626696627.3325252790013; Mon, 28 Oct 2024 08:50:26 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130627234116600 Content-Type: text/plain; charset="utf-8" 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) =20 clts(); if ( curr->fpu_dirtied ) - asm ( "stmxcsr %0" : "=3Dm" (curr->arch.xsave_area->fpu_sse.mx= csr) ); + { + struct xsave_struct *xsave_area =3D vcpu_map_xsave_area(curr); + + asm ( "stmxcsr %0" : "=3Dm" (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 =3D read_cr0(); unsigned long xcr0 =3D this_cpu(xcr0); struct vcpu *v =3D idle_vcpu[smp_processor_id()]; - struct xsave_struct *xstate =3D v->arch.xsave_area; + struct xsave_struct *xstate; =20 if ( ~xfeature_mask & mask ) { @@ -1061,8 +1066,10 @@ void xstate_set_init(uint64_t mask) =20 clts(); =20 + xstate =3D vcpu_map_xsave_area(v); memset(&xstate->xsave_hdr, 0, sizeof(xstate->xsave_hdr)); xrstor(v, mask); + vcpu_unmap_xsave_area(v, xstate); =20 if ( cr0 & X86_CR0_TS ) write_cr0(cr0); --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130627; cv=none; d=zohomail.com; s=zohoarc; b=ALFj1APAmsXz+JiTZMei8hS/S/Ts7+crNAbxiOyhXTR2bcNGGAYtiJEuU312hvMtDbCW0GAHRENTpnLAEIgOGybTvNvR0Zp88y6VN8xZaWfcPtEk+/JK2A/6ZzWijnpXuN+NQ2ezJyfAfu7boKyI6EF1Wp5iUEHypsqngf24HAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130627; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vCUIaO5AAUJAl3VVRobAf52t1sH+3QDwfli/NHe1tzs=; b=htj08GOwgiTf7bX3TibJf32SY3mZw1e5lbMgwdB7XbxkMhuAa9LHmWDJLNvValDU5xfi/NPoay3fWXByOxNfQiT2oZ20eggCACYh96BO/ONoZRkjtkAQL3o0KPUNexdoEa2NGPnYT8MFeD1XMfvREeksC2sGn8+qiv9Y+c2o11I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130627785620.3318003783028; Mon, 28 Oct 2024 08:50:27 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130629184116600 Content-Type: text/plain; charset="utf-8" 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 =3D=3D X86EMUL_FPU_fpu ) { - const fpusse_t *fpu_ctxt =3D &curr->arch.xsave_area->fpu_sse; + const struct xsave_struct *xsave_area =3D vcpu_map_xsave_area(curr= ); + const fpusse_t *fpu_ctxt =3D &xsave_area->fpu_sse; =20 /* * 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 =3D=3D fpu_ctxt->fcw); } + + vcpu_unmap_xsave_area(curr, xsave_area); } =20 return X86EMUL_OKAY; @@ -2411,7 +2414,8 @@ static void cf_check hvmemul_put_fpu( =20 if ( aux ) { - fpusse_t *fpu_ctxt =3D &curr->arch.xsave_area->fpu_sse; + struct xsave_struct *xsave_area =3D vcpu_map_xsave_area(curr); + fpusse_t *fpu_ctxt =3D &xsave_area->fpu_sse; bool dval =3D aux->dval; int mode =3D hvm_guest_x86_mode(curr); =20 @@ -2465,6 +2469,8 @@ static void cf_check hvmemul_put_fpu( =20 fpu_ctxt->fop =3D aux->op; =20 + vcpu_unmap_xsave_area(curr, xsave_area); + /* Re-use backout code below. */ backout =3D X86EMUL_FPU_fpu; } --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130629; cv=none; d=zohomail.com; s=zohoarc; b=haOveanUiAXVtM/Pp+PAaLe4wAusIKU/2M1+T1Cg10TcUfP+PQnZSHDPxNij1oA065iNxzkRNdPPHyLKVzPtZauLGcU3cEReO1bLkkGIBL7VcL/ntbZsrYt1LRF5TuefRRywQeGpIUt/RHCDh6cfCtgvKJEdWyGolr3eaJG42lY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JVXYPJCZuoH2OyHtUDCKgOdo7as5qgDULzyHGXZW2OE=; b=HQxoqTcUGbLMHbdTA/z8Ve4WkoR76xR74VzFsWRO5rTFdhsNIzaqtphvC7FdBji5OGaqWJc72b+3XB2j0/4lC3xNaD9B3TykRuCir1IC9MPWaP6wqHnnnjUqzW9h+RIwQdHeJ8CMfuar1f9AClFE/iDRLVjn0TTA3tBmpY3BzOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130629552476.0444376928408; Mon, 28 Oct 2024 08:50:29 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130631261116600 Content-Type: text/plain; charset="utf-8" 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 =3D v->domain; bool compat =3D 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 =20 - BUILD_BUG_ON(sizeof(c.nat->fpu_ctxt) !=3D - 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 =3D vcpu_map_xsave_area(v); + BUILD_BUG_ON(sizeof(c.nat->fpu_ctxt) !=3D 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); =20 if ( is_pv_domain(d) ) c(flags =3D v->arch.pv.vgc_flags & ~(VGCF_i387_valid|VGCF_in_kerne= l)); --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130630; cv=none; d=zohomail.com; s=zohoarc; b=S7z4+mijzXi2Dz2ZpuA2jwyIje0zMHSKd5jB+ChH/OI+RtidLF5WepgvCvXVYwWWS4i/nDQ3MqlTImxyG1KIZWz/4MUYR9lbqz3DJr3/51FRR0VXW+LKwyeCX5ceuTbOSbVVCg6BZ/lC96lWxF4+Lbln3cWb2Yix83mLtfKqiR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130630; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U/RnzlnP3G9CO4SusiLr8zIyIe7394ke2U9MPNKtXhg=; b=dMDGAwAQTq1pwV3pgKFNSf+sift/hZfTIJyqi8s78FhI1AqzLoJWWrrLqCwe1D+kbW2YU4dMqz4nM38gMU2MxqZZIQHXtnbHorrKSOTvcyRO/8OLMa8xjVWXCV0dIWKGBo3bP+yqDQFFzprv2bTAxraVhlMV5CBYgxs6vS9yWN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130630019855.8735892333835; Mon, 28 Oct 2024 08:50:30 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130631233116600 Content-Type: text/plain; charset="utf-8" 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 si= ze) { - const struct xsave_struct *xstate =3D v->arch.xsave_area; + const struct xsave_struct *xstate =3D vcpu_map_xsave_area(v); const void *src; uint16_t comp_offsets[sizeof(xfeature_mask)*8]; u64 xstate_bv =3D xstate->xsave_hdr.xstate_bv; @@ -228,6 +228,8 @@ void expand_xsave_states(const struct vcpu *v, void *de= st, unsigned int size) =20 valid &=3D ~feature; } + + vcpu_unmap_xsave_area(v, xstate); } =20 /* @@ -242,7 +244,7 @@ void expand_xsave_states(const struct vcpu *v, void *de= st, unsigned int size) */ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int s= ize) { - struct xsave_struct *xstate =3D v->arch.xsave_area; + struct xsave_struct *xstate =3D 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) =20 valid &=3D ~feature; } + + vcpu_unmap_xsave_area(v, xstate); } =20 void xsave(struct vcpu *v, uint64_t mask) --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130629; cv=none; d=zohomail.com; s=zohoarc; b=OhJYhVnORAj4FRrgrSngnQAJPLRKy8CtXoOIu3SRSkHodfO9GXDTU2aZG4BQATGqAniFvmdIHu5b3D0280ZO4hE2x2+U4vL0rd40qBm6E3Xm+pQUP+a+7t8B+RxS58vWQXx1YbZFAF9qOxJ7vZc77VQ/WggVmWAhubQ3xySjeKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BVQr91XZlcFHKTZl1uI+zUZ3+gisoPjkP7pJQrXj6Go=; b=WbJaStBiGKWOhD65UeTz9UTyF/8S1JdvlxYcA/nTHDd+HkLVdn7+EqiIOliI2Dzf9pcFmzV5W0yLd2whPaaMC9DYBe5CS6eEEr4bIdyaMn2hrDo5T46e2KRrRrIxwltSmoKOgim2FPLgZ9g6J+Ls5f5r3m24MmRYKRKQUtv/pfI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130629434926.6360961189745; Mon, 28 Oct 2024 08:50:29 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130631265116600 Content-Type: text/plain; charset="utf-8" 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 =20 @@ -292,6 +294,9 @@ int x86_emul_blk( } else asm volatile ( "fxrstor %0" :: "m" (*fxsr) ); + + UNMAP_FXSAVE_AREA(fxsr); + break; } =20 @@ -320,6 +325,9 @@ int x86_emul_blk( =20 if ( fxsr !=3D ptr ) /* i.e. s->op_bytes < sizeof(*fxsr) */ memcpy(ptr, fxsr, s->op_bytes); + + UNMAP_FXSAVE_AREA(fxsr); + break; } =20 --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130629; cv=none; d=zohomail.com; s=zohoarc; b=ilH72V3PPSjX8fT+U1srcVgPYfHDHiUoryYmluOkvjqqS6ymZ8qy2tOt+JiJH6xWTHHL0YiEZ1YxZj8oAYhQDXecksGH/srdey3zEUK0X7PAgv66PfvmI7G7SzX8FP0xnab6ogZHMrgWl4TkXYhEZvOR66SKueSY9txgW3FRAj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Avz5HmUUjPMBeZFfQQx+SO7GKCNtStFnZFq73+xyyr8=; b=oHNw8ORZlH4DSfnIcK/s9cfXqXDPXAhKyCXkcE8GFwwwk6Eu00bbYE9BP3UV221KkdQkhX9MpmRhLwZcnwY7DyAQ29U7lbJKhsThNFD+KLfMJTV/9hUxfSM/XRbrPOjARfDfh8FcvC42CwyAPSjzrvrU24zsOguAaGjMUjMVlSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17301306299151023.7394655159686; Mon, 28 Oct 2024 08:50:29 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130631260116600 Content-Type: text/plain; charset="utf-8" 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) =20 uint64_t read_bndcfgu(void) { + uint64_t ret =3D 0; unsigned long cr0 =3D read_cr0(); - struct xsave_struct *xstate - =3D idle_vcpu[smp_processor_id()]->arch.xsave_area; + struct vcpu *v =3D idle_vcpu[smp_processor_id()]; + struct xsave_struct *xstate =3D vcpu_map_xsave_area(v); const struct xstate_bndcsr *bndcsr; =20 ASSERT(cpu_has_mpx); @@ -1049,7 +1050,12 @@ uint64_t read_bndcfgu(void) if ( cr0 & X86_CR0_TS ) write_cr0(cr0); =20 - return xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ? bndcsr->bndcfgu= : 0; + if ( xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ) + ret =3D bndcsr->bndcfgu; + + vcpu_unmap_xsave_area(v, xstate); + + return ret; } =20 void xstate_set_init(uint64_t mask) --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130637; cv=none; d=zohomail.com; s=zohoarc; b=e0TbH7XYkfDHddYrG1mH46cFsFys6RVUrE5geO0fhEH2G/1b8WiRApEO77MCzU1y6hY6WisyesTXinlRnuYJnIGTJdB7HKcbynzHArnTx5jI5IIX7QGNU9daoXQqBYdzrrgbqbQHyNmJvUQqK/wo9ECFLOrzdjTskvJsndvFBvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130637; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NrpqNXgaGWCogi9sNhxEA3iqIJalu/4gAkUE90pvCh0=; b=M63gQun562r2x0osWLD4ceS0exZWyGIKKv5Gflf4fpmK4kYYj74YPDz+luAXa+ON6YzeQuLLkoBHU2mdP/BeMLncBau+FQzJbVeP6IvGutVDJDY61mvt3U37EG3NkFGp6q8R0Y2ZprBmbsIWanGNHzvSDloiUhMGgYgqHvZMSg0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130637893265.93743726551713; Mon, 28 Oct 2024 08:50:37 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130639308116600 Content-Type: text/plain; charset="utf-8" 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 =3D read_cr0(); struct vcpu *v =3D idle_vcpu[smp_processor_id()]; struct xsave_struct *xstate =3D vcpu_map_xsave_area(v); - const struct xstate_bndcsr *bndcsr; + struct xstate_bndcsr *bndcsr; =20 ASSERT(cpu_has_mpx); clts(); @@ -1051,7 +1051,10 @@ uint64_t read_bndcfgu(void) write_cr0(cr0); =20 if ( xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ) + { ret =3D bndcsr->bndcfgu; + *bndcsr =3D (struct xstate_bndcsr){}; + } =20 vcpu_unmap_xsave_area(v, xstate); =20 --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130631; cv=none; d=zohomail.com; s=zohoarc; b=YA30KE18me+rBADVgvhVoFJrrcNGlEsJfjccQW+2JE4I2uCzHB3xe7NC0LPHwLHFl88IhTZyFNyg0CMb9Xu5vy4T4cyOPSxGB+37FADPeynbDer3Y6C3bblOs5UNMqgRgZstt1t6bjax3oMp8FkcHUNcNGU+ZinhOxipY1vxivs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130631; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jNA4CkiYLhWj5GrlTVNs4LHtyrIqkd6cYmJb5XAmLwY=; b=IfMa/AY/NqxttqzZMOgDZbgV7lBRdqFlmhhYQu1a7uo92stKSQI6T/qbuaE380+3COTfE1q5jhkxx/CM07/85DohDdVFvUEuE+iuP7EObu+0hNRx5CoYblLlT4M/KQX6R8s1y8fKw63TqiIMulElhmGucKRsiZPrQLSmsmfWJfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 173013063121952.36980943151127; Mon, 28 Oct 2024 08:50:31 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130633406116600 Content-Type: text/plain; charset="utf-8" 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 vcp= u *v) } =20 /* Save x87 extended state */ -static inline void fpu_xsave(struct vcpu *v) +static inline void fpu_xsave(struct vcpu *v, struct xsave_struct *xsave_ar= ea) { bool ok; uint64_t mask =3D vcpu_xsave_mask(v); @@ -143,15 +143,14 @@ static inline void fpu_xsave(struct vcpu *v) */ ok =3D set_xcr0(v->arch.xcr0_accum | XSTATE_FP_SSE); ASSERT(ok); - xsave(v, mask); + xsave(v, xsave_area, mask); ok =3D set_xcr0(v->arch.xcr0 ?: XSTATE_FP_SSE); ASSERT(ok); } =20 /* 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 =3D &v->arch.xsave_area->fpu_sse; unsigned int fip_width =3D v->domain->arch.x87_fip_width; =20 if ( fip_width !=3D 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; =20 @@ -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(); =20 + xsave_area =3D 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); =20 + vcpu_unmap_xsave_area(v, xsave_area); v->fpu_dirtied =3D 0; =20 return true; diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/x= state.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); } =20 -void xsave(struct vcpu *v, uint64_t mask) +void xsave(struct vcpu *v, struct xsave_struct *ptr, uint64_t mask) { - struct xsave_struct *ptr =3D v->arch.xsave_area; uint32_t hmask =3D mask >> 32; uint32_t lmask =3D mask; unsigned int fip_width =3D v->domain->arch.x87_fip_width; --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130646; cv=none; d=zohomail.com; s=zohoarc; b=ikBVYT3V73flx72lu9AdUDHs2zSwtjBwyYFwOMIUL9A3h6aeKT8lCK7a8ms0nkY1qNLp0Xyp4cWmDwgGb7/IvUxwT8F6fsLsQp/NdxrlZwDATE1Siv1B3Ls1+xhlKY/c+lJY/2YsVhYJoQP6dcKpyD9mlgCcgOA/juq3xHUk9RM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130646; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oF/zafBR21s51XQ55xrj7f7wP/qB8eTuRfs/webK9Bc=; b=V22V/1ETDBJj1uS1xxh2yvkg+TWN7XRls6nedRPvjYuGZm1PfUoYrSO1PcXRJNx4+nIGlS63HOrs3jCmByXyYF9UOplI+B2VIX7UgzPr3Y99rJskZ43LxgUbCaz+YvcIX5t5iY9fmMjVJ3n7SLF/TxDzMKs8rebqTDY2k4CffBI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130646503693.5061671285532; Mon, 28 Oct 2024 08:50:46 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130647453116600 Content-Type: text/plain; charset="utf-8" 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_a= rea, + uint64_t mask) { bool ok; =20 @@ -31,16 +32,14 @@ static inline void fpu_xrstor(struct vcpu *v, uint64_t = mask) */ ok =3D set_xcr0(v->arch.xcr0_accum | XSTATE_FP_SSE); ASSERT(ok); - xrstor(v, mask); + xrstor(v, xsave_area, mask); ok =3D set_xcr0(v->arch.xcr0 ?: XSTATE_FP_SSE); ASSERT(ok); } =20 /* 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 =3D &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 ne= ed_stts) * above) we also need to restore full state, to prevent subsequently * saving state belonging to another vCPU. */ + xsave_area =3D 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); =20 v->fpu_initialised =3D 1; v->fpu_dirtied =3D 1; @@ -226,9 +228,10 @@ void vcpu_restore_fpu_nonlazy(struct vcpu *v, bool nee= d_stts) } else { - fpu_xrstor(v, XSTATE_NONLAZY); + fpu_xrstor(v, xsave_area, XSTATE_NONLAZY); need_stts =3D true; } + vcpu_unmap_xsave_area(v, xsave_area); =20 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)); =20 /* Avoid recursion. */ @@ -250,10 +254,12 @@ void vcpu_restore_fpu_lazy(struct vcpu *v) =20 ASSERT(!v->arch.fully_eager_fpu); =20 + xsave_area =3D 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); =20 v->fpu_initialised =3D 1; v->fpu_dirtied =3D 1; diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/x= state.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] =3D fip_width; } =20 -void xrstor(struct vcpu *v, uint64_t mask) +void xrstor(struct vcpu *v, struct xsave_struct *ptr, uint64_t mask) { uint32_t hmask =3D mask >> 32; uint32_t lmask =3D mask; - struct xsave_struct *ptr =3D v->arch.xsave_area; unsigned int faults, prev_faults; =20 /* @@ -992,6 +991,7 @@ int handle_xsetbv(u32 index, u64 new_bv) mask &=3D curr->fpu_dirtied ? ~XSTATE_FP_SSE : XSTATE_NONLAZY; if ( mask ) { + struct xsave_struct *xsave_area =3D vcpu_map_xsave_area(curr); unsigned long cr0 =3D read_cr0(); =20 clts(); @@ -1010,7 +1010,9 @@ int handle_xsetbv(u32 index, u64 new_bv) curr->fpu_dirtied =3D 1; cr0 &=3D ~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) =20 xstate =3D 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); =20 if ( cr0 & X86_CR0_TS ) --=20 2.47.0 From nobody Thu Nov 21 16:04:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1730130639; cv=none; d=zohomail.com; s=zohoarc; b=GI7K0ErHPKrZJyUNP5X7Nu0Ky9aDJ7mcECmKObZLAQ4VwLV9iDsbKHv4O6km3AMyf370vtz9WN3EeTaJhmvB96DO98vcSyte1wBxFCclTBkEM/3K/XujieCQKF3qCgoPLL2g0yfw6OrkyLfGcqQEAXGNTyuJRXURX3K4stL2Nxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730130639; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HwNJgVlmgOrKpINGfBXiXo/pOeaz7GckymMD2iqzF3A=; b=hZDAUw12K32ho5jxI9faZ3mL8jmh17ze7OsFjO2FEgV555hbTitfv7BrNfPosj3k8so0ERrKtGGDD3QFUQywq+3CdYDMVqCuFkwdr2FE69Xu4yN6j3r7086czfGJ1oBtF29394V1k3ihemxyj/5ySyX+Z+NRiqEvbvu2EdrMBoI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1730130639824366.8562377941986; Mon, 28 Oct 2024 08:50:39 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1730130641446116600 Content-Type: text/plain; charset="utf-8" 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 fp= usse_t *fpu_ctxt) /* FPU Save Functions */ /*******************************/ =20 -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_ar= ea) { 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 v= cpu *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; } =20 /* Save x87 extended state */ static inline void fpu_xsave(struct vcpu *v, struct xsave_struct *xsave_ar= ea) { bool ok; - uint64_t mask =3D vcpu_xsave_mask(v); + uint64_t mask =3D vcpu_xsave_mask(v, xsave_area); =20 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 =3D 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/x= state.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 *xsav= e_area) return xsave_area->xsave_hdr.xcomp_bv & XSTATE_COMPACTION_ENABLED; } =20 -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); } =20 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" : "=3Dm" (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 |=3D XSTATE_LAZY; --=20 2.47.0