From zaitcev@redhat.com  Fri Jun 21 00:23:21 2002
Return-Path: <zaitcev@redhat.com>
Date: Fri, 21 Jun 2002 00:23:19 -0400
From: Pete Zaitcev <zaitcev@redhat.com>
To: linux390@de.ibm.com
Cc: linux-390@vm.marist.edu, zaitcev@redhat.com
Subject: Putting current in register
Message-ID: <20020621002319.A16389@devserv.devel.redhat.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5.1i
Content-Length: 558
Lines: 12

Since interrupt stacks were split, current sits in the prefix page.
Did anyone think about returning it into a register? I am not
sufficiently familiar with the architecture to figure it out.
Candidates include control 10 (PER start), control 15 (Linkage),
and GPR 12. Possibly I missed something.

I was thinking about abusing X15, but it seems that applications
may do some mischief trying "extract saved registers" instructions.
PER appears to be used, I am not sure if that's actually the case.
So, I am zooming on R12. Anyone wants to comment?

-- Pete

From Ulrich.Weigand@de.ibm.com  Fri Jun 21 07:42:46 2002
From: "BOEBLINGEN LINUX390" <LINUX390@de.ibm.com>
Subject: Re: Putting current in register
To: Pete Zaitcev <zaitcev@redhat.com>
Cc: linux-390@vm.marist.edu, zaitcev@redhat.com
X-Mailer: Lotus Notes Release 5.0.3 (Intl) 21 March 2000
Message-ID: <OFAC021867.0C7B6659-ONC1256BDF.003F2296@de.ibm.com>
Sender: "Ulrich Weigand" <Ulrich.Weigand@de.ibm.com>
Date: Fri, 21 Jun 2002 13:42:33 +0200
MIME-Version: 1.0
Content-type: text/plain; charset=us-ascii
Content-Length: 1735
Lines: 40


Pete Zaitcev wrote:

>Since interrupt stacks were split, current sits in the prefix page.
>Did anyone think about returning it into a register? I am not
>sufficiently familiar with the architecture to figure it out.
>Candidates include control 10 (PER start), control 15 (Linkage),
>and GPR 12. Possibly I missed something.
>
>I was thinking about abusing X15, but it seems that applications
>may do some mischief trying "extract saved registers" instructions.
>PER appears to be used, I am not sure if that's actually the case.
>So, I am zooming on R12. Anyone wants to comment?

Using control registers is not a good idea: they might have some
unintended effect on user space, and also setting/accessing them
is slow (they can only be copied from/to memory; also, changing a
CR will often cause a SIE intercept in VM).

You could use R12 (or any other GPR), but at the cost of increasing
register pressure throughout the kernel; currently R12 is used just
as any available register (because kernel code is not -fPIC).  I
don't think this trade-off would be worthwhile.

If you want a register that is unused, and fast to access, you
could use an access register; preferably AR3.  (It is not used,
but it is already saved/restored on kernel entry/exit because
AR2 and AR4 are used by the kernel.)  This would be similar to
linuxthreads using AR0 as thread pointer register.  (Of course,
access regs only have 32-bit even in 64-bit mode which is
annoying when you want them to hold a pointer.)

However, what's the point?  Loading current from the prefix page
costs one cycle (assuming it is in L1 cache); on our platform
register->register operations and memory->register operations
from L1 usually take the same time.

Bye,
Ulrich


From zaitcev@redhat.com  Fri Jun 21 12:28:09 2002
Date: Fri, 21 Jun 2002 12:28:06 -0400
From: Pete Zaitcev <zaitcev@redhat.com>
To: BOEBLINGEN LINUX390 <LINUX390@de.ibm.com>
Cc: Pete Zaitcev <zaitcev@redhat.com>, linux-390@vm.marist.edu
Subject: Re: Putting current in register
Message-ID: <20020621122806.A26211@devserv.devel.redhat.com>
References: <OFAC021867.0C7B6659-ONC1256BDF.003F2296@de.ibm.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5.1i
In-Reply-To: <OFAC021867.0C7B6659-ONC1256BDF.003F2296@de.ibm.com>; from LINUX390@de.ibm.com on Fri, Jun 21, 2002 at 01:42:33PM +0200
Content-Length: 854
Lines: 19

>[...]
> However, what's the point?  Loading current from the prefix page
> costs one cycle (assuming it is in L1 cache); on our platform
> register->register operations and memory->register operations
> from L1 usually take the same time.

I am trying to unmap the prefix page, if I do so the get_current
has to be modified. Obvious option is to store current in a global;
then an access to it would require some cycles to load the pointer
from a global table then reference said pointer. Actually, a global
may be advantageous because it does not need to be preloaded on
every kernel entry. It's not that significant probably, but still.
Just thought I'd explore.

I did not notice that control registers cannot be loaded from
memory. Also, some people think that access registers are 16
bits wide (my copy of PoO lists them as 32 bits wide).

-- Pete

From weigand@faui11.informatik.uni-erlangen.de  Fri Jun 21 16:56:34 2002
From: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
Message-Id: <200206212056.WAA06507@faui11.informatik.uni-erlangen.de>
Subject: Re: Putting current in register
To: zaitcev@redhat.com
Date: Fri, 21 Jun 2002 22:56:29 +0200 (MET DST)
Cc: LINUX-390@VM.MARIST.EDU
X-Mailer: ELM [version 2.5 PL2]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Length: 1238
Lines: 39

Pete Zaitcev wrote:

>I am trying to unmap the prefix page, if I do so the get_current
>has to be modified. 

Er, it would seem that if you unmap the prefix page, get_current
would be the least of your problems ;-(  What about all the other
uses of the lowcore (including those demanded by the architecture
like retrieving the program-interruption condition etc.)?

Again, I fail to see what benefit this is supposed to bring ...

>Obvious option is to store current in a global;
>then an access to it would require some cycles to load the pointer
>from a global table then reference said pointer. Actually, a global
>may be advantageous because it does not need to be preloaded on
>every kernel entry. It's not that significant probably, but still.
>Just thought I'd explore.

And how do you indend to make this per-cpu?
 
>I did not notice that control registers cannot be loaded from
>memory. 

They can be loaded from memory, in fact they can be loaded
*only* from memory.

>Also, some people think that access registers are 16
>bits wide (my copy of PoO lists them as 32 bits wide).

Then it would appear that some people are wrong and the
PoP is right ;-)

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de

From zaitcev  Fri Jun 21 17:44:49 2002
Date: Fri, 21 Jun 2002 17:43:16 -0400
From: Pete Zaitcev <zaitcev@redhat.com>
To: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
Cc: Pete Zaitcev <zaitcev@redhat.com>
Subject: Re: Putting current in register
Message-ID: <20020621174316.A13134@devserv.devel.redhat.com>
References: <200206212056.WAA06507@faui11.informatik.uni-erlangen.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <200206212056.WAA06507@faui11.informatik.uni-erlangen.de>; from weigand@immd1.informatik.uni-erlangen.de on Fri, Jun 21, 2002 at 10:56:29PM +0200
Content-Length: 994
Lines: 28

> From: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
> Date: Fri, 21 Jun 2002 22:56:29 +0200 (MET DST)

> >I am trying to unmap the prefix page, if I do so the get_current
> >has to be modified. 
> 
> Er, it would seem that if you unmap the prefix page, get_current
> would be the least of your problems ;-(  What about all the other
> uses of the lowcore (including those demanded by the architecture
> like retrieving the program-interruption condition etc.)?

My reading is that none of them uses virtual storage addressing.
The real page zero must be mapped somewhere, just not at
virtual address zero. Fortunately, you are not using big
pages, so kernel can unmap one page after IPL.

> Again, I fail to see what benefit this is supposed to bring ...

This is supposed to catch NULL pointers. You just wait, I am
going to enable SLAB poisoning too :)

> >Obvious option is to store current in a global;

> And how do you indend to make this per-cpu?

Duh. AR3 then.
 
-- Pete

From weigand@faui11.informatik.uni-erlangen.de  Fri Jun 21 17:55:58 2002
From: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
Message-Id: <200206212155.XAA07392@faui11.informatik.uni-erlangen.de>
Subject: Re: Putting current in register
To: zaitcev@redhat.com (Pete Zaitcev)
Date: Fri, 21 Jun 2002 23:55:54 +0200 (MET DST)
In-Reply-To: <20020621174316.A13134@devserv.devel.redhat.com> from "Pete Zaitcev" at Jun 21, 2002 05:43:16 PM
X-Mailer: ELM [version 2.5 PL2]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Length: 926
Lines: 29


> My reading is that none of them uses virtual storage addressing.
> The real page zero must be mapped somewhere, just not at
> virtual address zero. Fortunately, you are not using big
> pages, so kernel can unmap one page after IPL.

OK, I guess that should work ...

> > Again, I fail to see what benefit this is supposed to bring ...
> 
> This is supposed to catch NULL pointers. You just wait, I am
> going to enable SLAB poisoning too :)

You are aware that we have low-address protection switched on
for the kernel address space?  Every write access to the low
512 bytes will trap; this should get most NULL pointer write 
accesses.

So your scheme would help only with NULL pointer read accesses.
Might still be useful as debugging option, but I don't think it's
worthwhile in a production kernel (too much overhead for too
little gain IMO).

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de

From weigand@faui11.informatik.uni-erlangen.de  Fri Jun 21 18:18:59 2002
From: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
Message-Id: <200206212218.AAA07760@faui11.informatik.uni-erlangen.de>
Subject: Re: Putting current in register
To: zaitcev@redhat.com (Pete Zaitcev)
Date: Sat, 22 Jun 2002 00:18:55 +0200 (MET DST)
In-Reply-To: <20020621174316.A13134@devserv.devel.redhat.com> from "Pete Zaitcev" at Jun 21, 2002 05:43:16 PM
X-Mailer: ELM [version 2.5 PL2]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Status: RO
X-Status: A
Content-Length: 895
Lines: 25

> My reading is that none of them uses virtual storage addressing.
> The real page zero must be mapped somewhere, just not at
> virtual address zero.

Ah, it's more difficult.  If you don't have the lowcore, I don't
see how user<->kernel space transitions can be made to work.

The problem is that you need to save all registers on kernel
entry.  The only thing the hardware saves for you is the PSW,
everything else must be done manually.  Now, just *where* can
you save registers?  Loading any address into a register 
clobbers it, and the only addresses that can be used as
immediate addresses without registers are those below 4096.
So you *need* the page at virtual address 0 to be present.

Check out the SAVE_ALL_BASE macro in entry.S how it is 
currently done; I don't believe this can be done without
lowcore.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de

From zaitcev@redhat.com  Fri Jun 21 18:47:13 2002
Return-Path: <zaitcev@redhat.com>
Date: Fri, 21 Jun 2002 18:45:40 -0400
From: Pete Zaitcev <zaitcev@redhat.com>
To: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
Cc: Pete Zaitcev <zaitcev@redhat.com>
Subject: Re: Putting current in register
Message-ID: <20020621184540.A925@devserv.devel.redhat.com>
References: <20020621174316.A13134@devserv.devel.redhat.com> <200206212218.AAA07760@faui11.informatik.uni-erlangen.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5.1i
In-Reply-To: <200206212218.AAA07760@faui11.informatik.uni-erlangen.de>; from weigand@immd1.informatik.uni-erlangen.de on Sat, Jun 22, 2002 at 12:18:55AM +0200
Content-Length: 604
Lines: 15

> From: Ulrich Weigand <weigand@immd1.informatik.uni-erlangen.de>
> Date: Sat, 22 Jun 2002 00:18:55 +0200 (MET DST)

>[...]
> The problem is that you need to save all registers on kernel
> entry.  The only thing the hardware saves for you is the PSW,
> everything else must be done manually.  Now, just *where* can
> you save registers?  Loading any address into a register 
> clobbers it, and the only addresses that can be used as
> immediate addresses without registers are those below 4096.
> So you *need* the page at virtual address 0 to be present.

I guess I have give up the idea then.

-- Pete

