Mapping page table pages read-only
Hello!
I'm working on porting some IA-32 memory management code where the page tables pages are read before updating to check consistency (basically to catch cases where the old mapping is lost). However, I'm not really sure how to map the page table pages read-only in Xen.
I have pages 1-1-mapped pseudo-physical to virtual for the page tables, and if I just update the page directory as-is, i.e.:
xen_flush_queue();
xen_queue_pt_update(phys_to_machine(to_phys(pageDirectoryVaddr)) + sizeof(void*)*l2_table_offset(vaddr),
phys_to_machine(value) | (value & ~(PAGE_SIZE-1)) );
xen_pt_pin((unsigned long)phys_to_machine(value));
(the code is based on the FreeBSD port and the MiniOS), I get the "Bad type" error:
(XEN) DOM220: (file=mm.c, line=1510) Bad type (saw f0000001 != exp 27ff0000) for mfn 1a6df (pfn 33da) (XEN) DOM220: (file=mm.c, line=1780) Error while pinning mfn 1a6df
this goes away if I unmap the page first (update_va_mapping to 0). However, I'd like to keep the page mapped at the same 1-1 physical<->virtual address and still place it in the page directory. I've tried
HYPERVISOR_update_va_mapping((unsigned long)page,
(pte_t){(unsigned long)phys_to_machine(page)},
PRESENT);, being careful to only set bit 0 (PRESENT), which should make the page read-only. If I do this, however, I get an access violation on access of the page table page. Can anyone tell me what I do wrong here?
// Simon
At Tue, 02 May 2006 11:10:21 +0200,
Quoted 9 lines · Simon Kagstrom
HYPERVISOR_update_va_mapping((unsigned long)page, (pte_t){(unsigned long)phys_to_machine(page)}, PRESENT);, being careful to only set bit 0 (PRESENT), which should make the page read-only. If I do this, however, I get an access violation on access of the page table page. Can anyone tell me what I do wrong here?
Oh dear. My fault.
For reference, the error was that I placed the page flags in the update_va_mapping flags field, whereas they should be in actual entry, i.e.,
HYPERVISOR_update_va_mapping((unsigned long)page,
(pte_t){(unsigned long)phys_to_machine(page) | FLAGS}, 0);
works much better. On to the next problem!
// Simon