On 3/19/07, Ahmed S. Darwish <darwish.07@xxxxxxxxx> wrote:
On Mon, Mar 19, 2007 at 06:17:10PM +0530, pradeep singh wrote: > >------------------------------ > > > >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(®s, 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. I think the logical sequence is Selector [in segment registers ] -> GDT -> Descriptor
oops... got me :) Sorry jumbled offset and selector :(. thank you for correcting me.
> 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. Yes they have the same _start_ values to make segmentation transparent, but they differ in other fields, espicifically the DPL (Descriptor privilege level).
Let me know the answer when you find one. thanks --psr
-- Ahmed S. Darwish http://darwish.07.googlepages.com
-- 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