public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Joe Damato <ice799@gmail.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com,
	hpa@zytor.com, akpm@linux-foundation.org
Subject: Re: [PATCH] x86: Reduce duplicated code in the x86_64 context switch path.
Date: Mon, 13 May 2013 19:30:50 +0200	[thread overview]
Message-ID: <20130513173050.GA30118@gmail.com> (raw)
In-Reply-To: <20130513163108.GA9827@roeck-us.net>


* Guenter Roeck <linux@roeck-us.net> wrote:

> On Sun, May 12, 2013 at 10:14:51PM -0700, Joe Damato wrote:
> > Signed-off-by: Joe Damato <ice799@gmail.com>
> > ---
> >  arch/x86/include/asm/switch_to.h |   30 ++++++++++++++++++++++++++++++
> >  arch/x86/kernel/process_64.c     |   29 ++---------------------------
> >  2 files changed, 32 insertions(+), 27 deletions(-)
> > 
> > diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
> > index 4ec45b3..a322cc6 100644
> > --- a/arch/x86/include/asm/switch_to.h
> > +++ b/arch/x86/include/asm/switch_to.h
> > @@ -124,6 +124,36 @@ do {									\
> >  	       __switch_canary_iparam					  \
> >  	     : "memory", "cc" __EXTRA_CLOBBER)
> >  
> > +#define loadsegment_fs(fs, index)					  \
> > +	loadsegment(fs, index)
> > +
> > +#define loadsegment_gs(gs, index)					  \
> > +	load_gs_index(index)
> > +
> > +#define switch_segment(prev, next, index, seg, msr)			       \
> > +	do {								       \
> > +		/*							       \
> > +		 * Segment register != 0 always requires a reload.  Also       \
> > +		 * reload when it has changed.  When prev process used 64bit   \
> > +		 * base always reload to avoid an information leak.	       \
> > +		 */							       \
> > +		if (unlikely(index | next->index | prev->seg)) {	       \
> > +			loadsegment_##seg(seg, next->index);		       \
> > +			/*						       \
> > +			 * Check if the user used a selector != 0; if yes      \
> > +			 *  clear 64bit base, since overloaded base is always  \
> > +			 *  mapped to the Null selector			       \
> > +			 */						       \
> > +			if (index)					       \
> > +			  prev->seg = 0;				       \
> > +		}							       \
> > +									       \
> > +		/* when next process has a 64bit base use it */		       \
> > +		if (next->seg)						       \
> > +		  wrmsrl(msr, next->seg);				       \
> > +		prev->index = index;					       \
> > +	} while (0)
> > +
> >  #endif /* CONFIG_X86_32 */
> >  
> For my part I'll never understand how code written as macros is supposed to
> improve anything. I always find it confusing and risky, as it is very easy
> to introduce side effects. Also, while it may reduce the source code size,
> it often results in increased object size.
> 
> My take: If you can not write it as inline function(s), don't bother.

Indeed.

Thanks,

	Ingo

      reply	other threads:[~2013-05-13 17:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-13  5:14 [PATCH] x86: Reduce duplicated code in the x86_64 context switch path Joe Damato
2013-05-13  6:03 ` H. Peter Anvin
2013-05-13  7:26   ` Joe Damato
2013-05-13  7:20 ` [PATCH v2] " Joe Damato
2013-05-13 16:31 ` [PATCH] " Guenter Roeck
2013-05-13 17:30   ` Ingo Molnar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130513173050.GA30118@gmail.com \
    --to=mingo@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=ice799@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mingo@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox