Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2DB7C433FE for ; Tue, 14 Dec 2021 02:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244848AbhLNCul (ORCPT ); Mon, 13 Dec 2021 21:50:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244799AbhLNCu0 (ORCPT ); Mon, 13 Dec 2021 21:50:26 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 325F2C061756; Mon, 13 Dec 2021 18:50:26 -0800 (PST) Message-ID: <20211214024947.935581464@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1639450224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=iLKtbFbkcvbY13Oep2yqrRjp8gb+L60IaMXOjILVTMQ=; b=JtUdEGit4Q8/P/pxsCdqjXbmTg6AcU2S3DXeadSa3xrfq3FLhWv3Jry4AJu/1tRQOOPrbN kHVPddQfqHJsbloFcH3ymbxWZ4/LE3+UDFv32guIG+lXZ/FOJjzvegJ6GWUdLGe9fUp5Dr c07+6iU2JX8rXvN1eCVjNh84ERQcSfevxpMy35z5pGrnAEfvu3wwqXl8Zfz9VPxtF6P80O qix9E/0VR7wQgvqnAGlEtmuZCHSwXUvPAADuGqrhkxTEpP6Npphib76JZiTCQsB1Mkrd+N v6kx7IL7rvewAFWvDmTCp/1c7ftAUaAro8p8yTT8kCzX+f7b4cIhHt+KEzHnug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1639450224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=iLKtbFbkcvbY13Oep2yqrRjp8gb+L60IaMXOjILVTMQ=; b=TJHWMkyVmY/iosFZWKqHLw5FULGGjhkNZqBQ2XcnODnPtXi3ekQ/ORKoDs3J7QgqzJrGFJ 3Px70toez4sIvNBg== From: Thomas Gleixner To: LKML Cc: Jing Liu , Yang Zhong , Paolo Bonzini , x86@kernel.org, kvm@vger.kernel.org, Sean Christoperson , Jin Nakajima , Kevin Tian , Jing Liu Subject: [patch 3/6] x86/fpu: Make XFD initialization in __fpstate_reset() a function argument References: <20211214022825.563892248@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 14 Dec 2021 03:50:24 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jing Liu vCPU threads are different from native tasks regarding to the initial XFD value. While all native tasks follow a fixed value (init_fpstate::xfd) established by the FPU core at boot, vCPU threads need to obey the reset value (i.e. ZERO) defined by the specification, to meet the expectation of the guest. Let the caller supply an argument and adjust the host and guest related invocations accordingly. [ tglx: Make it explicit via function argument ] Signed-off-by: Jing Liu Signed-off-by: Yang Zhong Signed-off-by: Thomas Gleixner --- --- arch/x86/kernel/fpu/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -199,7 +199,7 @@ void fpu_reset_from_exception_fixup(void } #if IS_ENABLED(CONFIG_KVM) -static void __fpstate_reset(struct fpstate *fpstate); +static void __fpstate_reset(struct fpstate *fpstate, u64 xfd); static void fpu_init_guest_permissions(struct fpu_guest *gfpu) { @@ -231,7 +231,8 @@ bool fpu_alloc_guest_fpstate(struct fpu_ if (!fpstate) return false; - __fpstate_reset(fpstate); + /* Leave xfd to 0 (the reset value defined by spec) */ + __fpstate_reset(fpstate, 0); fpstate_init_user(fpstate); fpstate->is_valloc = true; fpstate->is_guest = true; @@ -454,21 +455,21 @@ void fpstate_init_user(struct fpstate *f fpstate_init_fstate(fpstate); } -static void __fpstate_reset(struct fpstate *fpstate) +static void __fpstate_reset(struct fpstate *fpstate, u64 xfd) { /* Initialize sizes and feature masks */ fpstate->size = fpu_kernel_cfg.default_size; fpstate->user_size = fpu_user_cfg.default_size; fpstate->xfeatures = fpu_kernel_cfg.default_features; fpstate->user_xfeatures = fpu_user_cfg.default_features; - fpstate->xfd = init_fpstate.xfd; + fpstate->xfd = xfd; } void fpstate_reset(struct fpu *fpu) { /* Set the fpstate pointer to the default fpstate */ fpu->fpstate = &fpu->__fpstate; - __fpstate_reset(fpu->fpstate); + __fpstate_reset(fpu->fpstate, init_fpstate.xfd); /* Initialize the permission related info in fpu */ fpu->perm.__state_perm = fpu_kernel_cfg.default_features;