* 85xx Address space query
@ 2009-06-24 9:44 kernel mailz
2009-06-24 13:15 ` Kumar Gala
0 siblings, 1 reply; 11+ messages in thread
From: kernel mailz @ 2009-06-24 9:44 UTC (permalink / raw)
To: linuxppc-dev
[-- Attachment #1: Type: text/plain, Size: 768 bytes --]
Hi,
I am a newbie, trying to learn but have a few queries, nice if you could
respond
For linux on 85xx systems...
(a) Kernel code runs in PR=0 AS=0 and PID=0, which user space application
run in PR=1 AS=0 and PID 1-255.
Is this correct.
(b) I am writing a small program where the application code opens invokes a
ioctl call and passes a buffer pointer ( say 0x10000 in user space)
Now the driver code is using copy_from_user.
How this works internally ?
1. User code executes ioctl
2. interrupt goes to the kernel
3. ioctl handler in driver gets invoked
The buffer pointer still contains 0x10000.
How kernel code running in PR=0 accesses it and does the copy. I am not able
to see a address space switch in the asm code of copy_tofrom_user.
Please respond
-TRX
[-- Attachment #2: Type: text/html, Size: 855 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-24 9:44 85xx Address space query kernel mailz
@ 2009-06-24 13:15 ` Kumar Gala
2009-06-24 17:46 ` kernel mailz
2009-06-25 11:32 ` Benjamin Herrenschmidt
0 siblings, 2 replies; 11+ messages in thread
From: Kumar Gala @ 2009-06-24 13:15 UTC (permalink / raw)
To: kernel mailz; +Cc: linuxppc-dev
On Jun 24, 2009, at 4:44 AM, kernel mailz wrote:
> Hi,
>
> I am a newbie, trying to learn but have a few queries, nice if you
> could respond
> For linux on 85xx systems...
>
> (a) Kernel code runs in PR=0 AS=0 and PID=0, which user space
> application run in PR=1 AS=0 and PID 1-255.
> Is this correct.
correct.
> (b) I am writing a small program where the application code opens
> invokes a ioctl call and passes a buffer pointer ( say 0x10000 in
> user space)
> Now the driver code is using copy_from_user.
> How this works internally ?
>
> 1. User code executes ioctl
> 2. interrupt goes to the kernel
On the interrupt the PR changes from 0 -> 1
> 3. ioctl handler in driver gets invoked
> The buffer pointer still contains 0x10000.
>
> How kernel code running in PR=0 accesses it and does the copy. I am
> not able to see a address space switch in the asm code of
> copy_tofrom_user.
There isn't a address space switch. But address spaces exist at the
same time. The user app is given 0..0xc000_0000 and the kernel uses
0xc000_0000..0xffff_ffff.
- k
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-24 13:15 ` Kumar Gala
@ 2009-06-24 17:46 ` kernel mailz
2009-06-24 22:52 ` Scott Wood
2009-06-25 11:33 ` Benjamin Herrenschmidt
2009-06-25 11:32 ` Benjamin Herrenschmidt
1 sibling, 2 replies; 11+ messages in thread
From: kernel mailz @ 2009-06-24 17:46 UTC (permalink / raw)
To: linuxppc-dev
On Wed, Jun 24, 2009 at 6:45 PM, Kumar Gala<galak@kernel.crashing.org> wrot=
e:
>
> On Jun 24, 2009, at 4:44 AM, kernel mailz wrote:
>
>> Hi,
>>
>> I am a newbie, trying to learn but have a few queries, nice if you could
>> respond
>> For linux on 85xx systems...
>>
>> (a) Kernel code runs in PR=3D0 AS=3D0 and PID=3D0, which user space appl=
ication
>> run in PR=3D1 AS=3D0 and PID 1-255.
>> Is this correct.
>
> correct.
>
>> (b) I am writing a small program where the application code opens invoke=
s
>> a ioctl call and passes a buffer pointer ( say 0x10000 in user space)
>> Now the driver code is using copy_from_user.
>> How this works internally ?
>>
>> 1. User code executes ioctl
>> 2. interrupt goes to the kernel
>
> On the interrupt the PR changes from 0 -> 1
>
>> 3. ioctl handler in driver gets invoked
>> The buffer pointer still contains 0x10000.
>>
>> How kernel code running in PR=3D0 accesses it and does the copy. I am no=
t
>> able to see a address space switch in the asm code of copy_tofrom_user.
>
> There isn't a address space switch. =A0But address spaces exist at the sa=
me
> time. =A0The user app is given 0..0xc000_0000 and the kernel uses
> 0xc000_0000..0xffff_ffff.
>
Ah Ok, I get it Thanks Kumar
But If the app was running with PID=3D1, interrupt occurs, kernel code
gets executed in PID=3D1, how does the kernel handle this ? and goes
back to PID=3D0, since its translations are all in PID=3D0
> - k
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-24 17:46 ` kernel mailz
@ 2009-06-24 22:52 ` Scott Wood
2009-06-25 10:51 ` kernel mailz
2009-06-25 11:33 ` Benjamin Herrenschmidt
1 sibling, 1 reply; 11+ messages in thread
From: Scott Wood @ 2009-06-24 22:52 UTC (permalink / raw)
To: kernel mailz; +Cc: linuxppc-dev
kernel mailz wrote:
> But If the app was running with PID=1, interrupt occurs, kernel code
> gets executed in PID=1, how does the kernel handle this ? and goes
> back to PID=0, since its translations are all in PID=0
PID 0 is special, it's mappings are present regardless of the value of
the PID register.
-Scott
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-24 22:52 ` Scott Wood
@ 2009-06-25 10:51 ` kernel mailz
2009-06-25 17:32 ` Kumar Gala
2009-06-25 19:34 ` Scott Wood
0 siblings, 2 replies; 11+ messages in thread
From: kernel mailz @ 2009-06-25 10:51 UTC (permalink / raw)
To: Scott Wood; +Cc: linuxppc-dev
So this means
when kernel gets interrupted by app which may be in PID=5 (say)
kernel translations for PID=0 remain valid ?
I am not able to follow Scott
-TZ
On Thu, Jun 25, 2009 at 4:22 AM, Scott Wood<scottwood@freescale.com> wrote:
> kernel mailz wrote:
>>
>> But If the app was running with PID=1, interrupt occurs, kernel code
>> gets executed in PID=1, how does the kernel handle this ? and goes
>> back to PID=0, since its translations are all in PID=0
>
> PID 0 is special, it's mappings are present regardless of the value of the
> PID register.
>
> -Scott
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-25 10:51 ` kernel mailz
@ 2009-06-25 17:32 ` Kumar Gala
2009-06-25 17:52 ` kernel mailz
2009-06-25 19:34 ` Scott Wood
1 sibling, 1 reply; 11+ messages in thread
From: Kumar Gala @ 2009-06-25 17:32 UTC (permalink / raw)
To: kernel mailz; +Cc: Scott Wood, linuxppc-dev
That is correct. The PID = 0 translations are always valid.
- k
On Jun 25, 2009, at 5:51 AM, kernel mailz wrote:
> So this means
> when kernel gets interrupted by app which may be in PID=5 (say)
> kernel translations for PID=0 remain valid ?
> I am not able to follow Scott
>
> -TZ
>
> On Thu, Jun 25, 2009 at 4:22 AM, Scott Wood<scottwood@freescale.com>
> wrote:
>> kernel mailz wrote:
>>>
>>> But If the app was running with PID=1, interrupt occurs, kernel code
>>> gets executed in PID=1, how does the kernel handle this ? and goes
>>> back to PID=0, since its translations are all in PID=0
>>
>> PID 0 is special, it's mappings are present regardless of the value
>> of the
>> PID register.
>>
>> -Scott
>>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-25 17:32 ` Kumar Gala
@ 2009-06-25 17:52 ` kernel mailz
2009-06-25 17:58 ` Kumar Gala
0 siblings, 1 reply; 11+ messages in thread
From: kernel mailz @ 2009-06-25 17:52 UTC (permalink / raw)
To: Kumar Gala; +Cc: Scott Wood, linuxppc-dev
If an aap has to be placed in AS=1 and it issues an ioctl, kernel
needs to be modified ?
I guess the PID=0 trick will work when AS is same
right ?
On 6/25/09, Kumar Gala <galak@kernel.crashing.org> wrote:
> That is correct. The PID = 0 translations are always valid.
>
> - k
>
> On Jun 25, 2009, at 5:51 AM, kernel mailz wrote:
>
>> So this means
>> when kernel gets interrupted by app which may be in PID=5 (say)
>> kernel translations for PID=0 remain valid ?
>> I am not able to follow Scott
>>
>> -TZ
>>
>> On Thu, Jun 25, 2009 at 4:22 AM, Scott Wood<scottwood@freescale.com>
>> wrote:
>>> kernel mailz wrote:
>>>>
>>>> But If the app was running with PID=1, interrupt occurs, kernel code
>>>> gets executed in PID=1, how does the kernel handle this ? and goes
>>>> back to PID=0, since its translations are all in PID=0
>>>
>>> PID 0 is special, it's mappings are present regardless of the value
>>> of the
>>> PID register.
>>>
>>> -Scott
>>>
>> _______________________________________________
>> Linuxppc-dev mailing list
>> Linuxppc-dev@lists.ozlabs.org
>> https://lists.ozlabs.org/listinfo/linuxppc-dev
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-25 17:52 ` kernel mailz
@ 2009-06-25 17:58 ` Kumar Gala
0 siblings, 0 replies; 11+ messages in thread
From: Kumar Gala @ 2009-06-25 17:58 UTC (permalink / raw)
To: kernel mailz; +Cc: Scott Wood, linuxppc-dev
On Jun 25, 2009, at 12:52 PM, kernel mailz wrote:
> If an aap has to be placed in AS=1 and it issues an ioctl, kernel
> needs to be modified ?
Correct, this would be a significant change to the kernel.
> I guess the PID=0 trick will work when AS is same
>
> right ?
correct.
- k
>
> On 6/25/09, Kumar Gala <galak@kernel.crashing.org> wrote:
>> That is correct. The PID = 0 translations are always valid.
>>
>> - k
>>
>> On Jun 25, 2009, at 5:51 AM, kernel mailz wrote:
>>
>>> So this means
>>> when kernel gets interrupted by app which may be in PID=5 (say)
>>> kernel translations for PID=0 remain valid ?
>>> I am not able to follow Scott
>>>
>>> -TZ
>>>
>>> On Thu, Jun 25, 2009 at 4:22 AM, Scott Wood<scottwood@freescale.com>
>>> wrote:
>>>> kernel mailz wrote:
>>>>>
>>>>> But If the app was running with PID=1, interrupt occurs, kernel
>>>>> code
>>>>> gets executed in PID=1, how does the kernel handle this ? and goes
>>>>> back to PID=0, since its translations are all in PID=0
>>>>
>>>> PID 0 is special, it's mappings are present regardless of the value
>>>> of the
>>>> PID register.
>>>>
>>>> -Scott
>>>>
>>> _______________________________________________
>>> Linuxppc-dev mailing list
>>> Linuxppc-dev@lists.ozlabs.org
>>> https://lists.ozlabs.org/listinfo/linuxppc-dev
>>
>>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-25 10:51 ` kernel mailz
2009-06-25 17:32 ` Kumar Gala
@ 2009-06-25 19:34 ` Scott Wood
1 sibling, 0 replies; 11+ messages in thread
From: Scott Wood @ 2009-06-25 19:34 UTC (permalink / raw)
To: kernel mailz; +Cc: linuxppc-dev
kernel mailz wrote:
> So this means
> when kernel gets interrupted by app which may be in PID=5 (say)
> kernel translations for PID=0 remain valid ?
> I am not able to follow Scott
Yes, exactly. They're valid even in userspace, except to the extent that the
kernel marks them supervisor-only.
-Scott
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-24 17:46 ` kernel mailz
2009-06-24 22:52 ` Scott Wood
@ 2009-06-25 11:33 ` Benjamin Herrenschmidt
1 sibling, 0 replies; 11+ messages in thread
From: Benjamin Herrenschmidt @ 2009-06-25 11:33 UTC (permalink / raw)
To: kernel mailz; +Cc: linuxppc-dev
On Wed, 2009-06-24 at 23:16 +0530, kernel mailz wrote:
> But If the app was running with PID=1, interrupt occurs, kernel code
> gets executed in PID=1, how does the kernel handle this ? and goes
> back to PID=0, since its translations are all in PID=0
PID 0 is a special case in HW. TLB entries with TID=0 will match any PID
value.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: 85xx Address space query
2009-06-24 13:15 ` Kumar Gala
2009-06-24 17:46 ` kernel mailz
@ 2009-06-25 11:32 ` Benjamin Herrenschmidt
1 sibling, 0 replies; 11+ messages in thread
From: Benjamin Herrenschmidt @ 2009-06-25 11:32 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, kernel mailz
> > 1. User code executes ioctl
> > 2. interrupt goes to the kernel
>
> On the interrupt the PR changes from 0 -> 1
The other way around actually :-)
> > 3. ioctl handler in driver gets invoked
> > The buffer pointer still contains 0x10000.
> >
> > How kernel code running in PR=0 accesses it and does the copy. I am
> > not able to see a address space switch in the asm code of
> > copy_tofrom_user.
>
> There isn't a address space switch. But address spaces exist at the
> same time. The user app is given 0..0xc000_0000 and the kernel uses
> 0xc000_0000..0xffff_ffff.
You may want to add, to make things clearer, that the HW treats PID 0
specially. Translations in the TLB that have PID (we call it TID in the
TLB entry) 0 match any value of the PID register.
So kernel pages all have TID = 0, which means they are visible to all
processes, but have permissions set such that only the supervisor (ie.
PR = 0) can actually access them. MSR:PR is automatically switched to 0
by the processor when taking an interrupt, allowing the kernel thus to
access both its own pages and the pages of the current process.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-06-25 19:35 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-24 9:44 85xx Address space query kernel mailz
2009-06-24 13:15 ` Kumar Gala
2009-06-24 17:46 ` kernel mailz
2009-06-24 22:52 ` Scott Wood
2009-06-25 10:51 ` kernel mailz
2009-06-25 17:32 ` Kumar Gala
2009-06-25 17:52 ` kernel mailz
2009-06-25 17:58 ` Kumar Gala
2009-06-25 19:34 ` Scott Wood
2009-06-25 11:33 ` Benjamin Herrenschmidt
2009-06-25 11:32 ` Benjamin Herrenschmidt
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).