From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965802AbbDWAGz (ORCPT ); Wed, 22 Apr 2015 20:06:55 -0400 Received: from mga11.intel.com ([192.55.52.93]:45158 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965722AbbDWAGy (ORCPT ); Wed, 22 Apr 2015 20:06:54 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,627,1422950400"; d="scan'208";a="713939059" From: "Yu, Fenghua" To: "Hansen, Dave" , "H. Peter Anvin" , Ingo Molnar , Thomas Gleixner , "Mallick, Asit K" , "Williamson, Glenn P" CC: linux-kernel , x86 Subject: RE: [PATCH Bugfix v2 2/4] x86/xsaves: Define and use user_xstate_size for xstate size in signal context Thread-Topic: [PATCH Bugfix v2 2/4] x86/xsaves: Define and use user_xstate_size for xstate size in signal context Thread-Index: AQHQfLiIAUQT0wolI0CMCliWpUsyaZ1Z1M2A//+Mf9CAAIEuAP//kJ/g Date: Thu, 23 Apr 2015 00:06:51 +0000 Message-ID: <3E5A0FA7E9CA944F9D5414FEC6C712205C8CF9CF@ORSMSX106.amr.corp.intel.com> References: <1429678319-61356-1-git-send-email-fenghua.yu@intel.com> <1429678319-61356-3-git-send-email-fenghua.yu@intel.com> <5537EC31.7080808@intel.com> <3E5A0FA7E9CA944F9D5414FEC6C712205C8CE779@ORSMSX106.amr.corp.intel.com> <5537F7AA.3010609@intel.com> In-Reply-To: <5537F7AA.3010609@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.22.254.139] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id t3N070m0024389 > From: Hansen, Dave > Sent: Wednesday, April 22, 2015 12:34 PM > To: Yu, Fenghua; H. Peter Anvin; Ingo Molnar; Thomas Gleixner; Mallick, Asit > K; Williamson, Glenn P > Cc: linux-kernel; x86 > Subject: Re: [PATCH Bugfix v2 2/4] x86/xsaves: Define and use > user_xstate_size for xstate size in signal context > > On 04/22/2015 12:05 PM, Yu, Fenghua wrote: > >> From: Hansen, Dave > >> Sent: Wednesday, April 22, 2015 11:45 AM > >> To: Yu, Fenghua; H. Peter Anvin; Ingo Molnar; Thomas Gleixner; > >> Mallick, Asit K; Williamson, Glenn P > >> Cc: linux-kernel; x86 > >> Subject: Re: [PATCH Bugfix v2 2/4] x86/xsaves: Define and use > >> user_xstate_size for xstate size in signal context > >> > >> On 04/21/2015 09:51 PM, Fenghua Yu wrote: > >>> + /* > >>> + * Copy rest of xstates in compact format to user. > >>> + */ > >>> + for (i = 2; i < xstate_features; i++) { > >>> + if (test_bit(i, (unsigned long *)&pcntxt_mask)) { > >>> + int user_offset, kernel_offset; > >>> + int size; > >>> + > >>> + user_offset = xstate_offsets[i]; > >>> + kernel_offset = xstate_comp_offsets[i]; > >>> + size = xstate_sizes[i]; > >>> + > >>> + if (__copy_to_user(buf_fx + user_offset, > >>> + xsave + kernel_offset, size)) > >>> + return -1; > >>> + } > >>> + } > >> > >> Is this checking the right bitmap? > >> > >> The 'xsaves' documentation says: "If RFBM[i] = 1, XSTATE_BV[i] is set > >> to the value of XINUSE[i]". Where "XINUSE denotes the > >> state-component bitmap corresponding to the init optimization". > >> > >> So shouldn't this be checking xsave->xsave_hdr.xstate_bv instead of > >> pcntxt_mask? The will be equal unless the "init optimization" is in play. > > > > Xsave->xsave_hdr.xstate_bv is equal to pcntxt_mask (see > setup_init_fpu_buf()). > > No. I don't think it works this way. xsaves *WRITES* to the XSTATE_BV[] > field in addition to reading it. According to the SDM: > "execution of XSAVES writes the XSTATE_BV field of the XSAVE header (see > Section 13.4.2), setting XSTATE_BV[i] (0 ≤ i ≤ 63) as follows... > Execution of XSAVES performs the init optimization to reduce the amount of > data written to memory. If XINUSE[i] = 0, state component i is not saved to > the XSAVE area (even if RFBM[i] = 1)". > > > And here XINUSE and RFBM are irrelevant because they are used in init > > or modified optimization during xsave*/xrstore*. We only copy out the > > xstates from kernel to user and XINUSE and RFBM are not in scope here. > > I think they are in use. The kernel created its buffer with 'xsaves' so when it > is reading the buffer it needs to take those optimizations in to consideration. > We need to copy ALL of supported xstates to user. Using xstate_bv only copies partial xstates that are in non-init status. Xstate_bv only has xstates that are in non-init status. The xstates that are in init status will not be copied to user if using xstate_bv. In this case, the xstates that are in init status will be all zeros in the user buffer (remember we clear the user buffer before). That's incorrect. If pcntxt_mask is used to copy xstates, all of supported xstates either in init or non-init status will be copied correctly to the user buffer. All of other parts in the user buffer will be zeros. So there should be a problem to use pcntxt_mask here. But I agree the init_xstate_buf was not initialized correctly earlier in the boot time. But that's a separate issue to be fixed in a different patch. Thanks. -Fenghua {.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I