From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751902AbdAXAPQ (ORCPT ); Mon, 23 Jan 2017 19:15:16 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34216 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750860AbdAXAPN (ORCPT ); Mon, 23 Jan 2017 19:15:13 -0500 Date: Tue, 24 Jan 2017 08:14:47 +0800 From: Kevin Hao To: Yu-cheng Yu Cc: Dave Hansen , fenghua.yu@intel.com, dvlasenk@redhat.com, peterz@infradead.org, oleg@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, brgerst@gmail.com, luto@kernel.org, bp@alien8.de, jpoimboe@redhat.com, hpa@zytor.com, quentin.casasnovas@oracle.com, tglx@linutronix.de, torvalds@linux-foundation.org, riel@redhat.com, linux-tip-commits@vger.kernel.org Subject: Re: [tip:x86/urgent] x86/fpu: Set the xcomp_bv when we fake up a XSAVES area Message-ID: <20170124001447.GD15017@pek-khao-d1> References: <1485075023-30161-1-git-send-email-haokexin@gmail.com> <20170123165529.GA4996@test-lenovo> <2be814b7-9fd6-7955-b4e3-6ecb4ef76052@linux.intel.com> <20170123205725.GA3920@test-lenovo> <90b0fbee-273b-31c2-6fe9-228f00c0a205@linux.intel.com> <20170123211640.GA3976@test-lenovo> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0IvGJv3f9h+YhkrH" Content-Disposition: inline In-Reply-To: <20170123211640.GA3976@test-lenovo> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0IvGJv3f9h+YhkrH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 23, 2017 at 01:16:40PM -0800, Yu-cheng Yu wrote: > On Mon, Jan 23, 2017 at 01:10:20PM -0800, Dave Hansen wrote: > > The code is: > >=20 > > > void fpstate_init(union fpregs_state *state) > > > { > > > if (!static_cpu_has(X86_FEATURE_FPU)) { > > > fpstate_init_soft(&state->soft); > > > return; > > > } > > >=20 > > > memset(state, 0, fpu_kernel_xstate_size); > > >=20 > > > /* > > > * XRSTORS requires that this bit is set in xcomp_bv, or > > > * it will #GP. Make sure it is replaced after the memset(). > > > */ > > > if (static_cpu_has(X86_FEATURE_XSAVES)) > > > state->xsave.header.xcomp_bv =3D XCOMP_BV_COMPACTED_F= ORMAT; > >=20 > > That seems to set it unconditionally. What am I missing? >=20 > The fix I am proposing is... >=20 > state->xsave.header.xcomp_bv =3D XCOMP_BV_COMPACTED_FORMAT | > xfeatures_mask; Actually I thought about this change before I made this patch, but I don't = this is the right fix. It is always error prone to init the xcomp_bv to all the supported feature. In case like copyin_to_xsaves(), it is possible that the features which should be set in xcomp_bv do not equal to all the supported features. Please see the following codes in copyin_to_xsaves(): /* * The state that came in from userspace was user-state only. * Mask all the user states out of 'xfeatures': */ xsave->header.xfeatures &=3D XFEATURE_MASK_SUPERVISOR; /* * Add back in the features that came in from userspace: */ xsave->header.xfeatures |=3D xfeatures; Thanks, Kevin --0IvGJv3f9h+YhkrH Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYhpx3AAoJEJNY7TDerrFxkbkH/3GAe6Ipsx/nCw9eC7UCeVfm 9zUS9xXLtj3uH0aDUZH1+gFT9rJiVgKAnJW5qoahE0QjpRLW53wuLGxJVuS2yfHT a+BlbXtitvysoKDFMaM0At7heJkcfE76BQTEJ6cJ5dPBjmr6q3UTBAzJptVubSKH dvFIePwzuOV2oE0R/4Kc2sq1jo9lvsMErxbneYkzZF7bt9yNZH59O56NxVavCRdo fgNI/klWCdtz8TfzRppUCL4XvRE6afOA2bDRK3l4fBkw8f2N97HKMyG/CTtgbS+C pCWEG3MkEu2QUwDHntdLqBq8WrnmQc/hCSEhJWWmPf+FxIJ+pqqs3lR4/Cd36Vw= =+2kx -----END PGP SIGNATURE----- --0IvGJv3f9h+YhkrH--