From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753740AbcEIXyY (ORCPT ); Mon, 9 May 2016 19:54:24 -0400 Received: from mga03.intel.com ([134.134.136.65]:46653 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753522AbcEIXyX (ORCPT ); Mon, 9 May 2016 19:54:23 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,602,1455004800"; d="scan'208";a="972143657" Subject: Re: [PATCH v5 11/13] x86/xsaves: Add WARN_ON_FPU() when a disabled xstate component offset is requested for a compacted format To: Yu-cheng Yu References: <57311DC6.5000503@linux.intel.com> <20160509234416.GA28442@test-lenovo> Cc: linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Andy Lutomirski , Borislav Petkov , Sai Praneeth Prakhya , "Ravi V. Shankar" , Fenghua Yu From: Dave Hansen Message-ID: <5731232D.8060406@linux.intel.com> Date: Mon, 9 May 2016 16:54:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20160509234416.GA28442@test-lenovo> 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 On 05/09/2016 04:44 PM, Yu-cheng Yu wrote: > On Mon, May 09, 2016 at 04:31:18PM -0700, Dave Hansen wrote: >> On 05/09/2016 01:46 PM, Yu-cheng Yu wrote: >>> Add a warning in case a disabled (not existing) xstate component offset >>> is requested. >> ... >>> diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c >>> index 350814c..2e6dbfe 100644 >>> --- a/arch/x86/kernel/fpu/xstate.c >>> +++ b/arch/x86/kernel/fpu/xstate.c >>> @@ -756,6 +756,7 @@ void *__raw_xsave_addr(struct xregs_state *xsave, int xstate_feature_mask) >>> { >>> int feature_nr = fls64(xstate_feature_mask) - 1; >>> >>> + WARN_ON_FPU(using_compacted_format() && !xfeature_enabled(feature_nr)); >>> return (void *)xsave + xstate_comp_offsets[feature_nr]; >>> } >> >> Why the using_compacted_format()? Shouldn't this be an error, regardless. > > If the kernel is not using compacted format, I can get a component offset, no? You can get it, but why would you? Let's say you were trying to get the MPX contents. You'd either be guaranteed to be getting 0's or uninitialized garbage (if we didn't zero it carefully). The garbage could be kernel data (if we didn't zero carefully). So it just seems dangerous to allow this for no apparent benefit.