From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754248AbbHFO4O (ORCPT ); Thu, 6 Aug 2015 10:56:14 -0400 Received: from www.sr71.net ([198.145.64.142]:52930 "EHLO blackbird.sr71.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753082AbbHFO4N (ORCPT ); Thu, 6 Aug 2015 10:56:13 -0400 Message-ID: <55C3758A.50005@sr71.net> Date: Thu, 06 Aug 2015 07:56:10 -0700 From: Dave Hansen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Ingo Molnar , Linus Torvalds CC: Peter Anvin , Denys Vlasenko , Thomas Gleixner , linux-kernel@vger.kernel.org, Andy Lutomirski , bp@alien8.de, Peter Zijlstra , fenghua.yu@intel.com, x86@kernel.org, dave.hansen@linux.intel.com Subject: Re: [PATCH] x86, fpu: correct XSAVE xstate size calculation References: <20150728172143.6DDFECA7@viggo.jf.intel.com> <20150805103227.GA3233@gmail.com> <55C21EFC.3060802@sr71.net> <20150806071545.GB2194@gmail.com> <20150806082746.GA10974@gmail.com> In-Reply-To: <20150806082746.GA10974@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 I think we have three options. Here's some rough pseudo-ish-code to sketch them out. /* Option 1, what we have today */ /* * This breaks if offset[i]+size[i] != offset[i+1] * or if alignment is in play. Silly hardware breaks * this today. */ for (i = 0; i < nr_xstates; i++) { if (!enabled_xstate(i)) continue; total_blob_size += xstate_sizes[i]; } /* Option 2: search for the end of the last state, probably works, Ingo likes? */ for (i = 0; i < nr_xstates; i++) { if (cpu_has_xsaves && !enabled_xstate(i)) continue; end_of_state = xstate_offsets[i] + xstate_sizes[i]; if (xstate_is_aligned[i]) /* currently not implemented */ end_of_state = ALIGN(end_of_state, 64); if (end_of_state > total_blob_size) total_blob_size = end_of_state; } /* align unconditionally, maybe??? */ total_blob_size = ALIGN(total_blob_size, 64); /* Double check our obviously bug-free math with what the CPU says */ if (!cpu_has_xsaves) cpuid(0xD0, 0, &check_total_blob_size, ...); else cpuid(0xD0, 1, &check_total_blob_size, ...); WARN_ON(check_total_blob_size != total_blob_size); /* Option 3, trust the CPU (what Dave's patch does) */ if (!cpu_has_xsaves) cpuid(0xD0, 0, &total_blob_size, ...); else cpuid(0xD0, 1, &total_blob_size, ...);