x86: adjust reserved bit page fault handling
PATCH 1/1 x86: adjust reserved bit page fault handling
One could even debate whether reserved bit faults are always fatal (and should never be propagated to the guest)...
xen/arch/x86/traps.c +19 -2
@@ -823,6 +823,17 @@ asmlinkage void do_machine_check(structmachine_check_vector (regs, regs->error_code); } +static inline void reserved_bit_page_fault (int guest,unsigned long addr, +struct cpu_user_regs *regs) +{ +if ( guest ) +gdprintk (XENLOG_ERR ,"reserved bit in page table entry: " ); +else +dprintk (XENLOG_ERR ,"reserved bit in page table entry: " ); +show_page_walk (addr); +show_execution_state (regs); +} +void propagate_page_fault (unsigned long addr,u16 error_code) {struct trap_info *ti;
@@ -852,6 +863,8 @@ void propagate_page_fault(unsigned long v->domain->domain_id, v->vcpu_id, error_code);show_page_walk (addr); } +else if (unlikely (error_code & PFEC_reserved_bit) ) +reserved_bit_page_fault (1 , addr,guest_cpu_user_regs ()); } static int handle_gdt_ldt_mapping_fault(
@@ -1034,8 +1047,10 @@ static int fixup_page_fault(unsigned lonstruct vcpu *v = current;struct domain *d = v->domain; -/* No fixups in interrupt context or when interrupts are disabled. */ -if (in_irq () || !(regs->eflags &X86_EFLAGS_IF ) ) +/* No fixups in interrupt context, when interrupts are disabled, or +* when a reserved bit was found to be set. */ +if (in_irq () || !(regs->eflags &X86_EFLAGS_IF ) || + (regs->error_code & PFEC_reserved_bit) )return 0 ;if (unlikely (IN_HYPERVISOR_RANGE (addr)) )
@@ -1101,6 +1116,8 @@ asmlinkage void do_page_fault(struct cpuif (likely ((fixup =search_exception_table (regs->eip)) !=0 ) ) {perfc_incr (copy_user_faults); +if (unlikely (regs->error_code & PFEC_reserved_bit) ) +reserved_bit_page_fault (0 , addr, regs); regs->eip = fixup;return ; }
xen/arch/x86/traps.c static int fixup_page_fault(unsigned lon · line 1056
Quoted 13 lines · Jan Beulich
xen/arch/x86/traps.c +4
-2@@ -1034,8 +1047,10 @@ static int fixup_page_fault(unsigned lonstruct vcpu *v = current;struct domain *d = v->domain; -/* No fixups in interrupt context or when interrupts are disabled. */ -if (in_irq () || !(regs->eflags &X86_EFLAGS_IF ) ) +/* No fixups in interrupt context, when interrupts are disabled, or +* when a reserved bit was found to be set. */ +if (in_irq () || !(regs->eflags &X86_EFLAGS_IF ) || + (regs->error_code & PFEC_reserved_bit) )return 0 ;if (unlikely (IN_HYPERVISOR_RANGE (addr)) )
The shadow pagetable code deliberately introduces invalid pagetable entries as part of its fast-path treatment of MMIO and not-present entries in the guest tables, so paging_fault needs to be called for PFEC_reserved_bit faults.
Cheers,
Tim.
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]
Quoted 14 lines
Quoted 1 line
Quoted 1 line
Tim Deegan <[email protected]> 01.02.08 10:28 >>>
Quoted 12 lines · Jan Beulich
(quoted diff) +4
-2@@ -1034,8 +1047,10 @@ static int fixup_page_fault(unsigned lon struct vcpu *v = current; struct domain *d = v->domain; - /* No fixups in interrupt context or when interrupts are disabled. */ - if ( in_irq() || !(regs->eflags & X86_EFLAGS_IF) ) + /* No fixups in interrupt context, when interrupts are disabled, or + * when a reserved bit was found to be set. */ + if ( in_irq() || !(regs->eflags & X86_EFLAGS_IF) || + (regs->error_code & PFEC_reserved_bit) ) return 0;
Quoted 6 lines
Review static int fixup_page_fault(unsigned lon · line 1056
Quoted 1 line
(quoted diff) +0
-0if ( unlikely(IN_HYPERVISOR_RANGE(addr)) )The shadow pagetable code deliberately introduces invalid pagetable entries as part of its fast-path treatment of MMIO and not-present entries in the guest tables, so
paging_faultneeds to be called forPFEC_reserved_bitfaults.
Here's a replacement patch then, it would still be questionable whether reserved bit faults should ever be propagated to a guest...
xen/arch/x86/traps.c +20 -2
@@ -823,6 +823,18 @@ asmlinkage void do_machine_check(structmachine_check_vector (regs, regs->error_code); } +static inline void reserved_bit_page_fault (int guest,unsigned long addr, +struct cpu_user_regs *regs) +{ +if ( guest ) +gdprintk (XENLOG_ERR ,"" ); +else +dprintk (XENLOG_ERR ,"" ); +printk ("reserved bit in page table (ec=%04X): " , regs->error_code); +show_page_walk (addr); +show_execution_state (regs); +} +void propagate_page_fault (unsigned long addr,u16 error_code) {struct trap_info *ti;
@@ -852,6 +864,8 @@ void propagate_page_fault(unsigned long v->domain->domain_id, v->vcpu_id, error_code);show_page_walk (addr); } +else if (unlikely (error_code & PFEC_reserved_bit) ) +reserved_bit_page_fault (1 , addr,guest_cpu_user_regs ()); } static int handle_gdt_ldt_mapping_fault(
@@ -1047,7 +1061,8 @@ static int fixup_page_fault(unsigned lontrace_trap_two_addr (TRC_PV_PAGING_FIXUP , regs->eip, addr);return ret; } -if ( (addr >=GDT_LDT_VIRT_START ) && (addr <GDT_LDT_VIRT_END ) ) +if ( !(regs->error_code & PFEC_reserved_bit) && + (addr >=GDT_LDT_VIRT_START ) && (addr <GDT_LDT_VIRT_END ) )return handle_gdt_ldt_mapping_fault ( addr -GDT_LDT_VIRT_START , regs);return 0 ;
@@ -1057,7 +1072,8 @@ static int fixup_page_fault(unsigned longuest_kernel_mode (v, regs) &&/* Do not check if access-protection fault since the page may legitimately be not present in shadow page tables */ - ((regs->error_code & PFEC_write_access) == PFEC_write_access) && + ((regs->error_code & (PFEC_write_access|PFEC_reserved_bit)) == + PFEC_write_access) && ptwr_do_page_fault(v, addr, regs) ) return EXCRET_fault_fixed;
@@ -1101,6 +1117,8 @@ asmlinkage void do_page_fault(struct cpuif (likely ((fixup =search_exception_table (regs->eip)) !=0 ) ) {perfc_incr (copy_user_faults); +if (unlikely (regs->error_code & PFEC_reserved_bit) ) +reserved_bit_page_fault (0 , addr, regs); regs->eip = fixup;return ; }
Quoted 9 lines · Jan Beulich
Quoted 4 lines
The shadow pagetable code deliberately introduces invalid pagetable entries as part of its fast-path treatment of MMIO and not-present entries in the guest tables, so
paging_faultneeds to be called forPFEC_reserved_bitfaults.Here's a replacement patch then, it would still be questionable whether reserved bit faults should ever be propagated to a guest...
Signed-off-by Jan Beulich <[email protected]>
What problem does this patch solve?
-- Keir
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 01.02.08 11:54 >>>
Quoted 5 lines · Jan Beulich
Quoted 4 lines
The shadow pagetable code deliberately introduces invalid pagetable entries as part of its fast-path treatment of MMIO and not-present entries in the guest tables, so
paging_faultneeds to be called forPFEC_reserved_bitfaults.
Quoted 6 lines
Quoted 4 lines
Here's a replacement patch then, it would still be questionable whether reserved bit faults should ever be propagated to a guest...
Signed-off-by Jan Beulich <[email protected]>What problem does this patch solve?
When debugging the xen_change_pte_range() problem I mistakenly interpreted a page fault error code 15 as being decimal (it really was hex) and looked at the reserved bit fault handling. The patch is the outcome of this; despite it turned out to not be a fault of this kind I thought that tightening the handling (and adding the printing, since reserved bit faults are [except in the case mentioned by Tim] always bad) wouldn't be a bad idea.
Jan