Skip to contentSkip to conversation

WP flag in CR0, setting

DISCUSSION Simon Kagstrom 2 participants 6 messages Jun 14, 2006 – Jul 3, 2006

lore
Share & tools
lore
#0 lore raw

Hello!

I have a slight problem in my guest port with the WP bit in CR0. The original kernel maps certain kernel pages to user-mode read-only and relies on the kernel being able to modify these despite the read-only bit being set in the pages. This in turn requires that the WP bit is unset in CR0.

Unfortunately, Xen doesn't allow the WP bit to be zeroed because Xen wants to share pages read-only with the guest OS. I'm taking this up because

a) I would like to know if I've understood the reason for this limitation

b) I'd like to discuss if the restriction could be lifted

First, from browsing the Xen code, it seems that the only pages being shared read-only with the guest is the phys-to-machine translation table. Is this true, or is it needed for something else as well?

To allow WP being unset, maybe something like the following could be done. As long as WP is unchanged everything works as it does now. When the WP bit is set,

- A copy is made of the pages mapped read-only and one of the copies is kept in the Xen-protected area

- On updates to the phys-to-machine pages, Xen updates both copies but only uses the "private" for it's own use

- If the guest overwrites something in the "public" area, it will only suffer by itself.

The problem I see with this approach is that the space needed for the phys-to-machine pages doubles if WP is set. Comments?

// Simon

#1 lore raw
Quoted 5 lines · Simon Kagstrom

I have a slight problem in my guest port with the WP bit in CR0. The original kernel maps certain kernel pages to user-mode read-only and relies on the kernel being able to modify these despite the read-only bit being set in the pages. This in turn requires that the WP bit is unset in CR0.

We can't support this. We rely on write protection for all sorts of things (e.g., prevent guest write access to page tables). You'll have to temporarily make the mapping writable, or make a kernel-private writable mapping.

-- Keir

#2 lore raw

At Wed, 14 Jun 2006 14:00:16 +0100,

Quoted 8 lines · Keir Fraser
Quoted 5 lines · Simon Kagstrom

I have a slight problem in my guest port with the WP bit in CR0. The original kernel maps certain kernel pages to user-mode read-only and relies on the kernel being able to modify these despite the read-only bit being set in the pages. This in turn requires that the WP bit is unset in CR0.

Quoted 4 lines

We can't support this. We rely on write protection for all sorts of things (e.g., prevent guest write access to page tables). You'll have to temporarily make the mapping writable, or make a kernel-private writable mapping.

Thanks for the explanation. Would the WP flag work in a HVM setting?

// Simon

#3 lore raw
Quoted 6 lines · Simon Kagstrom
Quoted 4 lines

We can't support this. We rely on write protection for all sorts of things (e.g., prevent guest write access to page tables). You'll have to temporarily make the mapping writable, or make a kernel-private writable mapping.

Thanks for the explanation. Would the WP flag work in a HVM setting?

It may not be supported right now, but it would be easy to do so if not.

-- Keir

#4 lore raw

At Thu, 15 Jun 2006 09:08:37 +0100,

Quoted 4 lines · Keir Fraser
Quoted 1 line · Simon Kagstrom

Thanks for the explanation. Would the WP flag work in a HVM setting?

It may not be supported right now, but it would be easy to do so if not.

Does Xen itself rely on running with the WP flag set? I'll go with the HVM supported WP-bit later, but as I don't have the hardware yet, I wanted to try to just clear the bit in Xen, and that seems to cause problems. Changing

xen/arch/x86/boot/x86_32.S +1 -1
diff -r 17fbffb737d9 xen/arch/x86/boot/x86_32.S
@@ -150,7 +150,7 @@ no_execute_disable:
 #endif
         mov     $idle_pg_table-__PAGE_OFFSET,%eax
         mov     %eax,%cr3
-        mov     $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */
+        mov     $0x80040033,%eax /* hi-to-lo: PG,AM,NE,ET,MP,PE */
         mov     %eax,%cr0
         jmp     1f
 1:      /* Install relocated selectors (FS/GS unused). */

Causes an assertion to trigger when booting the Linux dom0:

(XEN) Assertion '(x & PGT_count_mask) != 0' failed, line 1430, file mm.c

Is this due to how Xen works or is it because Linux uses writable page tables (I have not checked the Linux sources other than the __xen_guest_section).

// Simon

#5 lore raw
Quoted 7 lines · Simon Kagstrom

Causes an assertion to trigger when booting the Linux dom0:

(XEN) Assertion '(x & PGT_count_mask) != 0' failed, line 1430, file mm.c

Is this due to how Xen works or is it because Linux uses writable page tables (I have not checked the Linux sources other than the __xen_guest_section).

This occurs because the pagetable protection no longer works. When Linux writes directly to a pagetable it succeeds rather than trapping into Xen where appropriate reference counting and validation would occur.

-- Keir