Re: i386: Why putting __USER_DS in kernel threads stack (%esp) ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



------------------------------

Date: Sat, 17 Mar 2007 16:29:15 +0200
Subject: Re: i386: Why putting __USER_DS in kernel threads stack (%esp) ?
From: "Ahmed S. Darwish" <darwish.07@xxxxxxxxx>

On Fri, Mar 16, 2007 at 03:38:27AM +0700, Mulyadi Santosa wrote:
> Hi ...
> >Hi list,
> >
> >Reading the kernel threads initialization code I see:
> >
> >int kernel_thread(...) {
> >
> >     struct pt_regs regs;
> >     memset(&regs, 0, sizeof(regs));
> >     [...]
> >**   regs.xds = __USER_DS;
> >**   regs.xes = __USER_DS;
> >
>
> I was checking those codes too and I think that is just for satisfying
> the requirement of filling struct regs. I guess it is filled with
> USER_DS just to pretend the way do_fork is usually called via clone/fork
> syscall, that is to create normal user thread.
>

Commenting those two lines out don't even start init. While using __KERNEL_DS
instead of __USER_DS starts init then causes a
`Panic: Segment violation at 0x8049798 - Sleeping for 30 seconds'.
It may then have an important role than just mimicing user processes, right ?

What makes me wonder is that as said in Understanding Linux Kernel (v3):

  When CPL (Current Privelege level) is equal to 3, the ds register must
  contain the segment selector of the user data segment. When it's equal to
  zero, the ds register must contain the segment selector of the kernel data
  segment.

IMHO selector is different from segment descriptor right?
descriptor's privilige level is checked ,as i make out of it. Selector
comes after checking the CPL with the DPL in the GDT or LDT.

Somebody can explain this better and correct me if i am wrong somewhere.


So how come running a kernel thread with DS = __USER_DS ?
AFAIK __USER_DS and __KERNEL_DS have exactly the same values.
This simplifies the task for the kernel. Kernel does not uses
segmentation extensively(moreover it cannot escape segmentation also
IIRC) . All the mm operations actually rely on paging in Linux. Since
segmentation is the first inevitable step ,the kernel while
initialising just initialises the segment registers for whole kernel
address space to values between 0 - 4GB and also initialises the
segment registers for user address space from 0 - 4GB.This greatly
simplifies the kernel code.

Please correct me if i am wrong.

Good luck
--psr

Thanks,

--
Ahmed S. Darwish
http://darwish.07.googlepages.com



------------------------------

End of kernelnewbies Digest V7 #67
**********************************




--
play the game

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux