virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>,
	lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>,
	virtualization <virtualization@lists.osdl.org>
Subject: Re: [PATCH 5/7] Use %gs for per-cpu sections in kernel
Date: Mon, 25 Sep 2006 11:16:14 +1000	[thread overview]
Message-ID: <1159146974.26986.30.camel@localhost.localdomain> (raw)
In-Reply-To: <45172AC8.2070701@goop.org>

On Sun, 2006-09-24 at 18:03 -0700, Jeremy Fitzhardinge wrote:
> Rusty Russell wrote:
> >> So are symbols referencing the .data.percpu section 0-based?  Wouldn't 
> >> you need to subtract __per_cpu_start from the symbols to get a 0-based 
> >> segment offset?
> >>     
> >
> > I don't think I understand the question.
> >
> > The .data.percpu section is the "template" per-cpu section, freed along
> > with other initdata: after setup_percpu_areas() is called, it is not
> > supposed to be used.  Around that time, the gs segment is set up based
> > at __per_cpu_offset[cpu], so "%gs:<varname>" accesses the local version.
> >   
> 
> If you do
> 
>     DEFINE_PER_CPU(int, foo);
> 
> then this ends up defining per_cpu__foo in .data.percpu.  Since 
> .data.percpu is part of the init data section, it starts at some address 
> X (not 0), so the real offset into the actual per-cpu memory is actually 
> (per_cpu__foo - __per_cpu_start).  setup_per_cpu_areas() builds this 
> delta into the __per_cpu_offset[], and so it means that the base of your 
> %gs segment is at -__per_cpu_start from the actual start of the CPU's 
> per-cpu memory, and the limit has to be correspondingly larger.  Which 
> is a bit ugly.

Hi Jeremy!

	You're thinking of it in a convoluted way, by converting to offsets
from the per-cpu section, then converting it back.  How about this
explanation: the local cpu's versions are offset from where the compiler
thinks they are by __per_cpu_offset[cpu].  We set the segment base to
__per_cpu_offset[cpu], so "%gs:per_cpu__foo" gets us straight to the
local cpu version.  __per_cpu_offset[cpu] is always positive (kernel
image sits at bottom of kernel address space).

>   Especially since "__per_cpu_start" is actually very 
> large, and so this scheme pretty much relies on being able to wrap 
> around the segment limit, and will be very bad for Xen.

__per_cpu_start is large, yes.  But there's no reason to use it in
address calculation.  The second half of your statement is not correct.

> An alternative is to put the "-__per_cpu_start" into the addressing mode 
> when constructing the address of the per-cpu variable.

I think you're thinking of TLS relocations?  I don't use them...

Rusty.
-- 
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law

  reply	other threads:[~2006-09-25  1:16 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-22 11:51 [PATCH 0/7] Using %gs for per-cpu areas on x86 Rusty Russell
2006-09-22 11:53 ` [PATCH 1/7] Use per-cpu GDT tables from early in boot Rusty Russell
2006-09-22 11:55   ` [PATCH 2/7] Rusty Russell
2006-09-22 11:56     ` [PATCH 3/7] Update sys_vm86 to cope with changed pt_regs and %gs usage Rusty Russell
2006-09-22 11:58       ` [PATCH 4/7] Fix places where using %gs changes the usermode ABI Rusty Russell
2006-09-22 11:59         ` [PATCH 5/7] Use %gs for per-cpu sections in kernel Rusty Russell
2006-09-22 12:00           ` [PATCH 6/7] (Optional) implement smp_processor_id() as a per-cpu var Rusty Russell
2006-09-22 12:01             ` [PATCH 7/7] (Optional) implement current " Rusty Russell
2006-09-25  5:29               ` Rusty Russell
2006-09-25  5:27             ` [PATCH 6/7] (Optional) implement smp_processor_id() " Rusty Russell
2006-09-22 12:32           ` [PATCH 5/7] Use %gs for per-cpu sections in kernel Andi Kleen
2006-09-22 22:43             ` Jeremy Fitzhardinge
2006-09-22 23:52               ` Andi Kleen
2006-09-23  4:51             ` Rusty Russell
2006-09-23  8:17               ` Andi Kleen
2006-09-23  8:55                 ` Rusty Russell
2006-09-22 22:39           ` Jeremy Fitzhardinge
2006-09-23  4:31             ` Rusty Russell
2006-09-25  1:03               ` Jeremy Fitzhardinge
2006-09-25  1:16                 ` Rusty Russell [this message]
2006-09-25  1:36                   ` Jeremy Fitzhardinge
2006-09-25  2:51                     ` Rusty Russell
2006-09-25  5:25                       ` Jeremy Fitzhardinge
2006-09-25  6:03                         ` Rusty Russell
2006-09-25  6:25                           ` Jeremy Fitzhardinge
2006-09-25 23:33                             ` Rusty Russell
2006-09-23  8:13             ` Andi Kleen
2006-09-25  1:07               ` Jeremy Fitzhardinge
2006-09-25  1:20                 ` Rusty Russell
2006-09-25  5:26                   ` Rusty Russell
2006-09-22 22:24     ` [PATCH 2/7] Jeremy Fitzhardinge
2006-09-23  4:36       ` Rusty Russell

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=1159146974.26986.30.camel@localhost.localdomain \
    --to=rusty@rustcorp.com.au \
    --cc=ak@muc.de \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.osdl.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;
as well as URLs for NNTP newsgroup(s).