Skip to contentSkip to conversation

Problem with modify CR0 of xen kernel

DISCUSSION errik 2 participants 2 messages Dec 13, 2009 – Dec 14, 2009

lore
Share & tools
lore

errik

author
#0 lore raw

Hi All,

This is a function of a kernel module, but when I calls this function, a
segment fault error happens, I don't know why because the code works well on other types of kernel such as PAE and default.
unsigned long clear_and_return_cr0(void)

{
    unsigned long cr0 = 0;
    unsigned long ret;
#ifdef X86_64
    __asm__ __volatile("movq %%cr0, %%rax" : "=a"(cr0));
    ret = cr0;
    cr0 &= 0xfffffffffffeffff;
    __asm__ __volatile__("movq %%rax, %%cr0" : : "a"(cr0));
#else
    __asm__ __volatile("mov %%cr0, %%eax" : "=a"(cr0));
    ret = cr0;
    cr0 &= 0xfffeffff;
    __asm__ __volatile__("mov %%eax, %%cr0" : : "a"(cr0));
#endif
    return ret;
}

May anyone give me some suggestions?

Thanks a lot!
Eric

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

The only bit a pv kernel may modify in CR0 is CR0.TS. If you looked at the Xen output, you also would have seen a corresponding warning.

Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

errik <[email protected]> 13.12.09 09:44 >>>

Hi All,

This is a function of a kernel module, but when I calls this function, a
segment fault error happens, I don't know why because the code works well on other types of kernel such as PAE and default.
unsigned long clear_and_return_cr0(void)

{
    unsigned long cr0 = 0;
    unsigned long ret;
#ifdef X86_64
    __asm__ __volatile("movq %%cr0, %%rax" : "=a"(cr0));
    ret = cr0;
    cr0 &= 0xfffffffffffeffff;
    __asm__ __volatile__("movq %%rax, %%cr0" : : "a"(cr0));
#else
    __asm__ __volatile("mov %%cr0, %%eax" : "=a"(cr0));
    ret = cr0;
    cr0 &= 0xfffeffff;
    __asm__ __volatile__("mov %%eax, %%cr0" : : "a"(cr0));
#endif
    return ret;
}

May anyone give me some suggestions?

Thanks a lot!
Eric