From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756629AbbGQIj4 (ORCPT ); Fri, 17 Jul 2015 04:39:56 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:37173 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755962AbbGQIjx (ORCPT ); Fri, 17 Jul 2015 04:39:53 -0400 Date: Fri, 17 Jul 2015 10:39:48 +0200 From: Ingo Molnar To: Peter Zijlstra Cc: Dave Hansen , tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, bp@alien8.de, luto@amacapital.net, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Message-ID: <20150717083947.GA16130@gmail.com> References: <20150716191437.A334FF2E@viggo.jf.intel.com> <20150716223534.GQ3644@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150716223534.GQ3644@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Peter Zijlstra wrote: > On Thu, Jul 16, 2015 at 12:14:37PM -0700, Dave Hansen wrote: > > +++ b/arch/x86/kernel/fpu/init.c 2015-07-16 12:02:15.284280976 -0700 > > @@ -136,6 +136,45 @@ static void __init fpu__init_system_gene > > unsigned int xstate_size; > > EXPORT_SYMBOL_GPL(xstate_size); > > > > +#define CHECK_MEMBER_AT_END_OF(TYPE, MEMBER) \ > > + BUILD_BUG_ON((sizeof(TYPE) - \ > > + offsetof(TYPE, MEMBER) - \ > > + sizeof(((TYPE *)0)->MEMBER)) > \ > > + 0) \ > > + > > +/* > > + * We append the 'struct fpu' to the task_struct. > > + */ > > +int __weak arch_task_struct_size(void) > > +{ > > + int task_size = sizeof(struct task_struct); > > + > > + /* > > + * Subtract off the static size of the register state. > > + * It potentially has a bunch of padding. > > + */ > > + task_size -= sizeof(((struct task_struct *)0)->thread.fpu.state); > > + > > + /* > > + * Add back the dynamically-calculated register state > > + * size. > > + */ > > + task_size += xstate_size; > > + > > + /* > > + * We dynamically size 'struct fpu', so we require that > > + * it be at the end of 'thread_struct' and that > > + * 'thread_struct' be at the end of 'task_struct'. If > > + * you hit a compile error here, check the structure to > > + * see if something got added to the end. > > + */ > > + CHECK_MEMBER_AT_END_OF(struct fpu, state); > > + CHECK_MEMBER_AT_END_OF(struct thread_struct, fpu); > > + CHECK_MEMBER_AT_END_OF(struct task_struct, thread); > > + > > + return task_size; > > +} > > Since you want these invariants true at all times, maybe put the > BUILD_BUG_ON() in generic code instead of x86 specific? That way people > poking at other archs are less likely to accidentally break your stuff. Yeah. Thanks, Ingo