<div dir="ltr">Hi Baoquan:<div>Thank you for your answer.<br><div style>That is to say the designer use __USER_DS here deliberately to improve the efficiency jump from kernel space to user space? </div><div style>BTW,how can you find this email? I write this email <span style="font-family:arial,sans-serif;font-size:14px">On 10/24/2012.</span></div>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/6/20 Baoquan He <span dir="ltr"><<a href="mailto:baoquan.he@gmail.com" target="_blank">baoquan.he@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 10/24/2012 08:04 PM, Fan Yang wrote:<br>
<br>
> Hi all: I print the cs ds and ss register in the user space, and it<br>
> is same as the __USER_CS and __USER_DS which defined in kernel as 73<br>
> and 7b. In the kernel __KERNEL_CS and __KERNEL_DS defined as 60 and<br>
> 68, but when I print this two value in my kernel module, I get 60<br>
> and 7b. Why ? It should be 60 and 68, shouldn't it?<br>
><br>
<br>
<br>
<br>
<br>
Hi Fan,<br>
<br>
I just talked to you and very impressed. By checking source code, I<br>
found what you mentioned is normal.<br>
<br>
You can check arch/x86/kernel/entry_32.S, and go to the page_fault<br>
definition, in error_code, you can<br>
see the CS and DS assignment.<br>
<br>
error_code:<br>
/* the function address is in %gs's slot on the stack */<br>
pushl_cfi %fs<br>
/*CFI_REL_OFFSET fs, 0*/<br>
pushl_cfi %es<br>
/*CFI_REL_OFFSET es, 0*/<br>
pushl_cfi %ds<br>
/*CFI_REL_OFFSET ds, 0*/<br>
pushl_cfi %eax<br>
CFI_REL_OFFSET eax, 0<br>
pushl_cfi %ebp<br>
CFI_REL_OFFSET ebp, 0<br>
pushl_cfi %edi<br>
CFI_REL_OFFSET edi, 0<br>
pushl_cfi %esi<br>
CFI_REL_OFFSET esi, 0<br>
pushl_cfi %edx<br>
CFI_REL_OFFSET edx, 0<br>
pushl_cfi %ecx<br>
CFI_REL_OFFSET ecx, 0<br>
pushl_cfi %ebx<br>
CFI_REL_OFFSET ebx, 0<br>
cld<br>
movl $(__KERNEL_PERCPU), %ecx<br>
movl %ecx, %fs<br>
UNWIND_ESPFIX_STACK<br>
GS_TO_REG %ecx<br>
movl PT_GS(%esp), %edi # get the function address<br>
movl PT_ORIG_EAX(%esp), %edx # get the error code<br>
movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart<br>
REG_TO_PTGS %ecx<br>
SET_KERNEL_GS %ecx<br>
<br>
Below is the assignment. This is changed in 2.6, the reason is that in<br>
kernel the CPL is 0 and it's<br>
safe to operate __USER_DS with DPL is 3. Here if use __KERNEL_DS, even<br>
though they have the<br>
same content, it need change back when return to user space.<br>
<br>
So in your original post, you mentioned the cs:ds is 60, 7b, it's normal<br>
and correct value. Hope<br>
this can help.<br>
<br>
movl $(__USER_DS), %ecx<br>
movl %ecx, %ds<br>
movl %ecx, %es<br>
TRACE_IRQS_OFF<br>
movl %esp,%eax # pt_regs pointer<br>
call *%edi<br>
<br>
</blockquote></div><br></div>