From nobody Tue Dec 16 23:09:27 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46EA02749F0; Tue, 6 May 2025 09:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746524005; cv=none; b=FOAY9ZBHN/RYlwSHayBM8lhkSGCB81cJgq3b4URQSRfaBHPsVSszf+MaK4ampJ/EtmxvaIcE4pQv6pNsbuZc77UyhGc7oKI420nJ8s+EnWSmg18Asg0SUSTEdU7zkhUeVBIOkgfqe8VUcginASzE1wwR6v1SxOKliKmHwTGBWGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746524005; c=relaxed/simple; bh=BPrGGwjOrkImv/qMfv3zpJkzr5Dwg04/sd+pRnWHH68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CkybRA0XPeRAVuATzGNRwfKRJ4RuEc7hG4IxESauXYBjB3BwdU8RHeIidPLa/H03n/tFYgseyIDKCVuuldvPzdxi5H+dr8BmJ+dv/jjUbU5Rv/38EyVj9Trk6pHWM6W7gxL/S014TXpxxVOuCx3jKUyoTi8J8FRQJftcFs3PAFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=N/0jsDJc; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N/0jsDJc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1746524004; x=1778060004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BPrGGwjOrkImv/qMfv3zpJkzr5Dwg04/sd+pRnWHH68=; b=N/0jsDJcujhml9cLue6fAoo3HJ0RyZZUXwkiI+PIJ2/9H51YzRUSN6bq WXIXnGu/o04pzAEwrWoKxiNf6qsQPAleWiR7tt4STUIvXu6jlLr2X+mWv CbmkK3rSQ/YQtGUPWhbyhis4qjgb0hROxNYCmZnOOKwl54Q07h72CnZ32 n3aOmoPD8wjloSi6rsxukGUV+HaBb1SSmac9K78rW7XfXAamzk0qOip1b f4awAIJv0FdoeRIoOgpoZIzbIw6kTevrxbcPadoN3gRZZ0dkxEpCHRNAQ ttmNiXI2l23ZaEpXvXv/EPEVxNpkVT70Yyfp2s864N8TQsDX96UQEaQi7 A==; X-CSE-ConnectionGUID: lQPjCVDeQHWbyHXnFC1RkQ== X-CSE-MsgGUID: SSzA7qj9T2ebFQ8a1kQalw== X-IronPort-AV: E=McAfee;i="6700,10204,11424"; a="35800425" X-IronPort-AV: E=Sophos;i="6.15,266,1739865600"; d="scan'208";a="35800425" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2025 02:33:23 -0700 X-CSE-ConnectionGUID: FGUguBdnRWegKEMUuTANVg== X-CSE-MsgGUID: /uhV684KSCaVMHWGkV3uiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,266,1739865600"; d="scan'208";a="135446957" Received: from spr.sh.intel.com ([10.239.53.19]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2025 02:33:19 -0700 From: Chao Gao To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, tglx@linutronix.de, dave.hansen@intel.com, seanjc@google.com, pbonzini@redhat.com Cc: peterz@infradead.org, rick.p.edgecombe@intel.com, weijiang.yang@intel.com, john.allen@amd.com, bp@alien8.de, chang.seok.bae@intel.com, xin3.li@intel.com, Chao Gao , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Oleg Nesterov , Eric Biggers , Stanislav Spassov , Kees Cook Subject: [PATCH v6 5/7] x86/fpu: Initialize guest fpstate and FPU pseudo container from guest defaults Date: Tue, 6 May 2025 17:36:10 +0800 Message-ID: <20250506093740.2864458-6-chao.gao@intel.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20250506093740.2864458-1-chao.gao@intel.com> References: <20250506093740.2864458-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" fpu_alloc_guest_fpstate() currently uses host defaults to initialize guest fpstate and pseudo containers. Guest defaults were introduced to differentiate the features and sizes of host and guest FPUs. Switch to using guest defaults instead. Additionally, incorporate the initialization of indicators (is_valloc and is_guest) into the newly added guest-specific reset function to centralize the resetting of guest fpstate. Suggested-by: Chang S. Bae Signed-off-by: Chao Gao --- v6: Drop vcpu_fpu_config.user_* (Rick) v5: init is_valloc/is_guest in the guest-specific reset function (Chang) --- arch/x86/kernel/fpu/core.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 444e517a8648..78a9c809dfad 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -211,7 +211,24 @@ void fpu_reset_from_exception_fixup(void) } =20 #if IS_ENABLED(CONFIG_KVM) -static void __fpstate_reset(struct fpstate *fpstate, u64 xfd); +static void __guest_fpstate_reset(struct fpstate *fpstate, u64 xfd) +{ + /* + * Initialize sizes and feature masks. Supervisor features and + * sizes may diverge between guest FPUs and host FPUs, whereas + * user features and sizes remain the same. + */ + fpstate->size =3D guest_default_cfg.size; + fpstate->xfeatures =3D guest_default_cfg.features; + fpstate->user_size =3D fpu_user_cfg.default_size; + fpstate->user_xfeatures =3D fpu_user_cfg.default_features; + fpstate->xfd =3D xfd; + + /* Initialize indicators to reflect properties of the fpstate */ + fpstate->is_valloc =3D true; + fpstate->is_guest =3D true; +} + =20 static void fpu_lock_guest_permissions(void) { @@ -236,19 +253,18 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu) struct fpstate *fpstate; unsigned int size; =20 - size =3D fpu_kernel_cfg.default_size + ALIGN(offsetof(struct fpstate, reg= s), 64); + size =3D guest_default_cfg.size + ALIGN(offsetof(struct fpstate, regs), 6= 4); + fpstate =3D vzalloc(size); if (!fpstate) return false; =20 /* Leave xfd to 0 (the reset value defined by spec) */ - __fpstate_reset(fpstate, 0); + __guest_fpstate_reset(fpstate, 0); fpstate_init_user(fpstate); - fpstate->is_valloc =3D true; - fpstate->is_guest =3D true; =20 gfpu->fpstate =3D fpstate; - gfpu->xfeatures =3D fpu_kernel_cfg.default_features; + gfpu->xfeatures =3D guest_default_cfg.features; =20 /* * KVM sets the FP+SSE bits in the XSAVE header when copying FPU state --=20 2.47.1