Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1186578

Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu'

From Ingo Molnar <mingo@kernel.org>
Newsgroups linux.kernel
Subject Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu'
Date 2015-07-17 10:50 +0200
Message-ID <pN9vd-kw-37@gated-at.bofh.it> (permalink)
References <pMWRk-7rm-29@gated-at.bofh.it> <pMZYS-3oO-29@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


* Peter Zijlstra <peterz@infradead.org> 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
--
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/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Dave Hansen <dave@sr71.net> - 2015-07-16 21:20 +0200
  Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Andy Lutomirski <luto@amacapital.net> - 2015-07-16 21:30 +0200
    Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Dave Hansen <dave@sr71.net> - 2015-07-16 23:30 +0200
      Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Ingo Molnar <mingo@kernel.org> - 2015-07-17 10:50 +0200
        [PATCH] x86/fpu, sched: Introduce  CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT and use it on x86 Ingo Molnar <mingo@kernel.org> - 2015-07-17 11:40 +0200
  Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Peter Zijlstra <peterz@infradead.org> - 2015-07-17 00:40 +0200
    [PATCH] x86/fpu, bug.h: Move CHECK_MEMBER_AT_END_OF() to a generic  header and use it in generic code Ingo Molnar <mingo@kernel.org> - 2015-07-17 10:50 +0200
    Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Ingo Molnar <mingo@kernel.org> - 2015-07-17 10:50 +0200
  Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' "H. Peter Anvin" <hpa@zytor.com> - 2015-07-17 00:50 +0200
    Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Andy Lutomirski <luto@amacapital.net> - 2015-07-17 01:00 +0200
  Re: [RFC][PATCH] x86, fpu: dynamically allocate 'struct fpu' Ingo Molnar <mingo@kernel.org> - 2015-07-17 10:30 +0200

csiph-web