Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939457AbcJGQYJ (ORCPT ); Fri, 7 Oct 2016 12:24:09 -0400 Received: from mga04.intel.com ([192.55.52.120]:20566 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938902AbcJGQYA (ORCPT ); Fri, 7 Oct 2016 12:24:00 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,456,1473145200"; d="scan'208";a="887762489" Subject: [PATCH] x86/pkeys: make protection keys an "eager" feature To: linux-kernel@vger.kernel.org Cc: Dave Hansen , dave.hansen@intel.com, stable@vger.kernel.org, x86@kernel.org From: Dave Hansen Date: Fri, 07 Oct 2016 09:23:42 -0700 Message-Id: <20161007162342.28A49813@viggo.jf.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2035 Lines: 49 From: Dave Hansen Our XSAVE features are divided into two categories: those that generate FPU exceptions, and those that do not. MPX and pkeys do not generate FPU exceptions and thus can not be used lazily. We disable them when lazy mode is forced on. We have a pair of masks to collect these two sets of features, but XFEATURE_MASK_PKRU was added to the wrong mask: XFEATURE_MASK_LAZY. Fix it by moving the feature to XFEATURE_MASK_EAGER. Note: this only causes problem if you boot with lazy FPU mode (eagerfpu=off) which is *not* the default. It also only affects hardware which is not currently publicly available. It looks like eager mode is going away, but we still need this patch applied to any kernel that has protection keys and lazy mode, which is 4.6 through 4.8 at this point, and 4.9 if the lazy removal isn't sent to Linus for 4.9. Signed-off-by: Dave Hansen Fixes: c8df40098451 ("x86/fpu, x86/mm/pkeys: Add PKRU xsave fields and data structures") Cc: # v4.6+ Cc: x86@kernel.org --- b/arch/x86/include/asm/fpu/xstate.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff -puN arch/x86/include/asm/fpu/xstate.h~x86-pkeys-add-as-eager-feature arch/x86/include/asm/fpu/xstate.h --- a/arch/x86/include/asm/fpu/xstate.h~x86-pkeys-add-as-eager-feature 2016-10-07 08:54:17.363165294 -0700 +++ b/arch/x86/include/asm/fpu/xstate.h 2016-10-07 08:54:17.366165429 -0700 @@ -27,11 +27,12 @@ XFEATURE_MASK_YMM | \ XFEATURE_MASK_OPMASK | \ XFEATURE_MASK_ZMM_Hi256 | \ - XFEATURE_MASK_Hi16_ZMM | \ - XFEATURE_MASK_PKRU) + XFEATURE_MASK_Hi16_ZMM) /* Supported features which require eager state saving */ -#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR) +#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | \ + XFEATURE_MASK_BNDCSR | \ + XFEATURE_MASK_PKRU) /* All currently supported features */ #define XCNTXT_MASK (XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER) _