Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752181AbbEGP6U (ORCPT ); Thu, 7 May 2015 11:58:20 -0400 Received: from mga02.intel.com ([134.134.136.20]:50394 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbbEGP6S (ORCPT ); Thu, 7 May 2015 11:58:18 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,384,1427785200"; d="scan'208";a="567858293" Message-ID: <554B8B99.8070602@linux.intel.com> Date: Thu, 07 May 2015 08:58:17 -0700 From: Dave Hansen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Ingo Molnar CC: Ingo Molnar , linux-kernel@vger.kernel.org, Andy Lutomirski , Borislav Petkov , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Thomas Gleixner Subject: Re: [PATCH 084/208] x86/fpu: Rename xsave.header::xstate_bv to 'xfeatures' References: <1430848300-27877-1-git-send-email-mingo@kernel.org> <1430848300-27877-6-git-send-email-mingo@kernel.org> <554904A6.8040503@linux.intel.com> <20150505181613.GA28562@gmail.com> <55490B1F.3080409@linux.intel.com> <20150506061603.GA13720@gmail.com> <554A5D23.2030405@linux.intel.com> <20150507122209.GB15656@gmail.com> <554B7DAA.3040606@linux.intel.com> <20150507153302.GA20993@gmail.com> In-Reply-To: <20150507153302.GA20993@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3404 Lines: 82 On 05/07/2015 08:33 AM, Ingo Molnar wrote: > * Dave Hansen wrote: >>> Btw., regarding XCR0.PKRU: that enables 'Protection Keys' in the >>> PTE format. What's the main purpose of these keys? They seem to >>> duplicate the read/write bits in the PTE, with the exception that >>> they don't impact instruction fetches. So is this used to allow >>> user-space to execute but otherwise not read instructions? >>> >>> Or some other purpose I missed? >> >> You can change the permissions of a given key with writes to the >> register without changing the PTE. No TLB shootdown, plus the >> permission changes are local to the CPU thread. > > interesting ... where are we doing that? kmap_atomic() is the only > place I can think of in the kernel, but there we are already skipping > the TLB shootdown by doing an INVLPG. Userspace. :) It's for userspace-only. >>>> We'd need to determine which fields are in the init state before we >>>> do an xsaves. >>> >>> Why? I don't think that's necessary. >> >> "If RFBM[i] = 0, XSTATE_BV[i] is written as 0." > > Yes, that's natural: RFBM is the combination of XCR0 (constant) and > the 'instruction mask' (constant as well) - i.e. it's a wide bitmask > including all our xfeatures - essentially 'xfeatures_mask' (in > tmp.fpu). > >> We need to pull XSTATE_BV in to the instruction mask when doing an >> XSAVE* if our RFBM has bits unset that *are* set in XSTATE_BV. >> Otherwise, we'll destroy the bits at XSAVE* time. > > But why would our RFBM be narrower than any possible XSTATE_BV we > handle? Our XCR0 is at the max. > > Also, the XSTATE_BV value of the save area is immaterial when we do an > XSAVES: all the state is in CPU registers, we want to save it to the > save area. XSAVES will write it for us. > >> It's not a problem today because the instruction mask is always -1, >> so it always has every bit set that *MIGHT* be set in XSTATE_BV. > > Yes. And why would we ever want to narrow it? Because it actually allows us to take advantage of the compaction. Think of the layout of a task using protection keys and MPX. MPX = 8*4 + 8*2 = 48 bytes. PKEYs = 4 bytes They'll be spread out in the standard form *OR* the compacted form with a RFBM=-1. But, with the compacted form with RFBM=PK|MPX_BITS, they'll fit in a cacheline. >> As for the whole bit 63 thing... It's possible and valid to have a >> XCOMP_BV[62:0]=0 because the instruction mask only contained bits >> that were unset in XCR0|IA32_XSS. You need bit 63 to tell you which >> format you are using. > > So basically if you request an XSAVES to ... write nothing (XCR0 AND > instruction mask is 0), then it will represent this as 0|1<<63 in > XCOMP_BV? > > In that case it does not matter whether the area is compacted or > standard: nothing was saved and nothing will have to be restored, only > the xsave header area will be accessed. Am I missing something? Take a look at the SDM. There are differences in the behavior when restoring the compacted vs. standard format. I don't know the deep reasons for *WHY*, just that there are some deltas clearly spelled out there. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/