Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2840370pxj; Sun, 23 May 2021 12:40:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdncGEdMbceuaQQDGaDorYS0AUAlCGh4kY73UW7qKyFbORiTYoTABHmd1+sYMDa9eiaPdT X-Received: by 2002:a05:6638:118c:: with SMTP id f12mr4837058jas.143.1621798831781; Sun, 23 May 2021 12:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621798831; cv=none; d=google.com; s=arc-20160816; b=cruPaFPxOuvEpamqkNTAfQTvHNouFZ4WpHfmh0h8SkMpeW23fLjyFmtCvpHrEmw5fD zWP6+AC9AfF28DWbUo2XuEUirjtO/3hMP5B3/xo4VYpQR/xr8eZzLz169P0g8HM2ihxe Korb6/NHj07dLkqfJxrVOBau7/l2hKj8bKkUg4WR/fy4XkY/lb+beaSkpbH39OiSIOVT WkTO6BbYfKSVtHn06P4OmnW8F79q0jAJO4mqhCRBrt2zeDlKD8hEeQdieNZc5245DZO5 h96ht2yyTUlK4OFjxg09SW/lbHmdn1PHTr5eDNmrPZgtjqeqpbOsqVHy5/okBy8oxa2l 6LaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=quEbSUkDHh8ijMSVn6F0QvNIvFtezEX23rUDpJDt5YY=; b=VHU3+nAf3KGjNvfJWHdjyQdJkCYWxkkCch44BrW8J2yvfV0avpjp/dyjBPgZdAFdrs 6flJLoMlU8z6CaIibbVgr/5ko6exTHzxgoyc7qO7zLj6ypqgp7VmJhxelZ2RvhUYgMc7 rcQ434r+A9Aed4B83w5Ml2+M0dfQZG+8U/And2LYGUDvTHfkeRghc9ahJzVxXjXIw4hG YAnPAOe7IbSk5Ha1Bs35CgKupIq5098/yiYRX/ZFBf0UYiDebELMwKFU4cDLqXxU5o6M AorRWkmubH9NEaiu54owLT8LWz4eYkABMvLfWqTNWLaRhYB6Ql3llFWTNpsv4wKnUmH0 d64A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a11si13284729jat.23.2021.05.23.12.40.19; Sun, 23 May 2021 12:40:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbhEWTk2 (ORCPT + 99 others); Sun, 23 May 2021 15:40:28 -0400 Received: from mga11.intel.com ([192.55.52.93]:31998 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231985AbhEWTj5 (ORCPT ); Sun, 23 May 2021 15:39:57 -0400 IronPort-SDR: xE8eSJ8Z60Jab38CwDUARQvrhsgfNGSxAUkuBc0TXLMDSKMsm6Bp9C7eRdYxPZKbP34cnUO2mB IwiWjUOzXJww== X-IronPort-AV: E=McAfee;i="6200,9189,9993"; a="198740681" X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="198740681" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2021 12:38:28 -0700 IronPort-SDR: Y9l1+Y+2rIutDXk7Hj+i1ZxfDWtTBfVVb/AJshyMNC1S0vj6RMPupGgqRu/de83Wkn5KK9wLWE qDyhxxovYN3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="407467093" Received: from chang-linux-3.sc.intel.com ([172.25.66.175]) by fmsmga007.fm.intel.com with ESMTP; 23 May 2021 12:38:28 -0700 From: "Chang S. Bae" To: bp@suse.de, luto@kernel.org, tglx@linutronix.de, mingo@kernel.org, x86@kernel.org Cc: len.brown@intel.com, dave.hansen@intel.com, jing2.liu@intel.com, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, chang.seok.bae@intel.com, kvm@vger.kernel.org Subject: [PATCH v5 11/28] x86/fpu/xstate: Update the xstate save function to support dynamic states Date: Sun, 23 May 2021 12:32:42 -0700 Message-Id: <20210523193259.26200-12-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210523193259.26200-1-chang.seok.bae@intel.com> References: <20210523193259.26200-1-chang.seok.bae@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extend copy_xregs_to_kernel() to receive a mask argument of which states to save, in preparation for dynamic user state handling. Update KVM to set a valid fpu->state_mask, so it can continue to share with the core code. Signed-off-by: Chang S. Bae Reviewed-by: Len Brown Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org --- Changes from v3: * Updated the changelog. (Borislav Petkov) * Made the code change more reviewable. Changes from v2: * Updated the changelog to clarify the KVM code changes. --- arch/x86/include/asm/fpu/internal.h | 3 +-- arch/x86/kernel/fpu/core.c | 2 +- arch/x86/kvm/x86.c | 9 +++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index e4afc1831e29..f964f3efc92e 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -317,9 +317,8 @@ static inline void copy_kernel_to_xregs_booting(struct xregs_state *xstate) /* * Save processor xstate to xsave area. */ -static inline void copy_xregs_to_kernel(struct xregs_state *xstate) +static inline void copy_xregs_to_kernel(struct xregs_state *xstate, u64 mask) { - u64 mask = xfeatures_mask_all; u32 lmask = mask; u32 hmask = mask >> 32; int err; diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 2584a2922fea..25c9c7dad3f9 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -98,7 +98,7 @@ EXPORT_SYMBOL(irq_fpu_usable); int copy_fpregs_to_fpstate(struct fpu *fpu) { if (likely(use_xsave())) { - copy_xregs_to_kernel(&fpu->state->xsave); + copy_xregs_to_kernel(&fpu->state->xsave, fpu->state_mask); /* * AVX512 state is tracked here because its use is diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4323ee191504..c60c92806883 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9611,11 +9611,16 @@ static void kvm_save_current_fpu(struct fpu *fpu) * KVM does not support dynamic user states yet. Assume the buffer * always has the minimum size. */ - if (test_thread_flag(TIF_NEED_FPU_LOAD)) + if (test_thread_flag(TIF_NEED_FPU_LOAD)) { memcpy(fpu->state, current->thread.fpu.state, get_xstate_config(XSTATE_MIN_SIZE)); - else + } else { + struct fpu *src_fpu = ¤t->thread.fpu; + + if (fpu->state_mask != src_fpu->state_mask) + fpu->state_mask = src_fpu->state_mask; copy_fpregs_to_fpstate(fpu); + } } /* Swap (qemu) user FPU context for the guest FPU context. */ -- 2.17.1