anomaly in irq check in fixup_page_fault()
Subsystems (8)
Hi,
This is a bit confusing. This for PVOPs kernel, I've not looked at older PV kernels to see what they do yet. But, the VCPU starts with evtchn_upcall_mask set and eflags.IF enabled. However, during kernel boot memory mapping lot of faults are getting fixed up by xen in:
fixup_page_fault():
/* No fixups in interrupt context or when interrupts are disabled. */
if ( in_irq() || !(regs->eflags & X86_EFLAGS_IF) ) <------
return 0;The guest is running under the assumption of INTs disabled during init_memory_mapping, and the first enable happens much later. So this check seems redundant at least for PVOPs kernel.
Now for my hybrid, the guest during initial boot is running with IF disabled, so fixup doesn't like that. Not sure if permanently disabling the (eflags & X86_EFLAGS_IF) check for hybrid would be a good idea for me.
thanks,
Mukesh
Quoted 11 lines · Mukesh Rathor
Hi,
This is a bit confusing. This for PVOPs kernel, I've not looked at older PV kernels to see what they do yet. But, the VCPU starts with
evtchn_upcall_maskset and eflags.IF enabled. However, during kernel boot memory mapping lot of faults are getting fixed up by xen in:
fixup_page_fault():/* No fixups in interrupt context or when interrupts are disabled. */ if ( in_irq() || !(regs->eflags & X86_EFLAGS_IF) ) <------ return 0;
A PV guest never has EF.IF=0, so the early exit should never be triggered by a guest fault.
Your best bet is to fake this out in your HVM container wrapper. Just write an EFLAGS into the saved regs that has EF.IF=1, as would always be the case for a normal PV guest. Rather that than fragile eis_hvm_pv() checks scattered around.
The setting of EF.IF shouldn't matter much for your guest as you'll be doing PV event delivery anyway, but I wonder how it ends up with EF.IF=0 -- is that deliberate?
-- Keir
Quoted 17 lines
The guest is running under the assumption of INTs disabled during
init_memory_mapping, and the first enable happens much later. So this check seems redundant at least for PVOPs kernel.Now for my hybrid, the guest during initial boot is running with IF disabled, so fixup doesn't like that. Not sure if permanently disabling the (eflags &
X86_EFLAGS_IF) check for hybrid would be a good idea for me.thanks,
Mukesh_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 14 lines · On Thu, 21 Jul 2011 07:35:00 +0100 Keir Fraser <[email protected]> wrote:
Quoted 11 lines · Mukesh Rathor
Hi,
This is a bit confusing. This for PVOPs kernel, I've not looked at older PV kernels to see what they do yet. But, the VCPU starts with
evtchn_upcall_maskset and eflags.IF enabled. However, during kernel boot memory mapping lot of faults are getting fixed up by xen in:
fixup_page_fault():/* No fixups in interrupt context or when interrupts aredisabled. */ if (
in_irq()|| !(regs->eflags &X86_EFLAGS_IF) ) <------ return 0;
Quoted 7 lines
A PV guest never has EF.IF=0, so the early exit should never be triggered by a guest fault.
Your best bet is to fake this out in your HVM container wrapper. Just write an EFLAGS into the saved regs that has EF.IF=1, as would always be the case for a normal PV guest. Rather that than fragile
eis_hvm_pv()checks scattered around.
Ok. In my prototype, i've the check, but I'll do the wrapper. I realize now the above check is more for hyp not taking fault disabled than the guest doing so.
Quoted 3 lines
The setting of EF.IF shouldn't matter much for your guest as you'll be doing PV event delivery anyway, but I wonder how it ends up with EF.IF=0 -- is that deliberate?
Yeah, I change IF=0 initially to make sure events are not delivered until the guest is ready and does irq enable. For PV, the vcpu-mask=1 assures this. Unlike PV, the hybrid changes IF in enable/disable to make "interrupt window exiting" work, BTW.
thanks,
Mukesh
Quoted 18 lines · Mukesh Rathor
Quoted 10 lines · On Thu, 21 Jul 2011 07:35:00 +0100 Keir Fraser <[email protected]> wrote:
On 21/07/2011 02:30, "Mukesh Rathor" <[email protected]> wrote:
A PV guest never has EF.IF=0, so the early exit should never be triggered by a guest fault.
Your best bet is to fake this out in your HVM container wrapper. Just write an EFLAGS into the saved regs that has EF.IF=1, as would always be the case for a normal PV guest. Rather that than fragile
eis_hvm_pv()checks scattered around.Ok. In my prototype, i've the check, but I'll do the wrapper. I realize now the above check is more for hyp not taking fault disabled than the guest doing so.
Quoted 8 lines
Quoted 3 lines
The setting of EF.IF shouldn't matter much for your guest as you'll be doing PV event delivery anyway, but I wonder how it ends up with EF.IF=0 -- is that deliberate?
Yeah, I change IF=0 initially to make sure events are not delivered until the guest is ready and does irq enable. For PV, the vcpu-mask=1 assures this. Unlike PV, the hybrid changes IF in enable/disable to make "interrupt window exiting" work, BTW.
I hope this can be an optional extension in the final version.
-- Keir
Quoted 3 lines
thanks,
Mukesh
Quoted 9 lines · Keir Fraser
Quoted 7 lines · Mukesh Rathor
Hi,
This is a bit confusing. This for PVOPs kernel, I've not looked at older PV kernels to see what they do yet. But, the VCPU starts with
evtchn_upcall_maskset and eflags.IF enabled. However, during kernel boot memory mapping lot of faults are getting fixed up by xen in:
Quoted 7 lines
Quoted 4 lines
fixup_page_fault():/* No fixups in interrupt context or when interrupts are disabled. */ if ( in_irq() || !(regs->eflags & X86_EFLAGS_IF) ) <------ return 0;A PV guest never has EF.IF=0, so the early exit should never be triggered by a guest fault.
When I was playing with PV in HVM prototypes way back I noticed that, for a pvops kernel at least, we seem to accidentally rely on the fact that trying to clear EFLAGS.IF from RING>0 silently ignores the change (as it does for any privileged bits in EFLAGS). This meant that on vmexit I would sometimes discover that IF was cleared. Originally I made this shoot the guest (it must be misbehaving, right!) but in the end I decided to be pragmatic and always |=EFLAGS_IF on the vmexit path.
I _think_ this was the original reason I discovered the issue that I fixed with the short series I reposted at
http://marc.info/?l=linux-kernel&m=130987084009107 (IOW I think kernel_eflags ended up with IF incorrect under pvops Xen, but it was a long time ago so perhaps I'm misremembering).
I also vaguely recall that the optimisation used in Xen's implementation of the xen_save_fl or xen_save_fl_direct, which basically only guarantees that the bit at EFLAGS_IF is valid in the value it returns (compared with native_save_fl which returns a full set of EFLAGS), was also something I suspected being implicated in IF getting turned off -- but you can pretty easily (at the expense of the optimisation) make those hooks return the real eflags with the ~evtchn_upcall_mask in the EFLAGS_IF bit.
At the time I sprinkled assertions around the guest kernel to help debug the issue, patch (against 2.6.32, so ancient) attached FWIW.
Ian.
Quoted 31 lines
Your best bet is to fake this out in your HVM container wrapper. Just write an EFLAGS into the saved regs that has EF.IF=1, as would always be the case for a normal PV guest. Rather that than fragile
eis_hvm_pv()checks scattered around.The setting of EF.IF shouldn't matter much for your guest as you'll be doing PV event delivery anyway, but I wonder how it ends up with EF.IF=0 -- is that deliberate?
-- Keir
Quoted 9 lines
The guest is running under the assumption of INTs disabled during
init_memory_mapping, and the first enable happens much later. So this check seems redundant at least for PVOPs kernel.Now for my hybrid, the guest during initial boot is running with IF disabled, so fixup doesn't like that. Not sure if permanently disabling the (eflags &
X86_EFLAGS_IF) check for hybrid would be a good idea for me.Quoted 8 lines
thanks,
Mukesh_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
arch/x86/boot/compressed/head_64.S +1 -0
@@ -245,6 +245,7 @@ ENTRY(startup_64) /* Zero EFLAGS */ pushq $0 + ud2 popfq /*
arch/x86/boot/cpucheck.c +2 -0
@@ -96,9 +96,11 @@ static int has_eflag(u32 mask)"movl %0,%1 ; " "xorl %2,%1 ; " "pushl %1 ; " +"ud2; " "popfl ; " "pushfl ; " "popl %1 ; " +"ud2; " "popfl" : "=&r" (f0), "=&r" (f1) : "ri" (mask));
arch/x86/ia32/ia32entry.S +1 -0
@@ -176,6 +176,7 @@ sysexit_from_sys_call: xorq %r9,%r9 xorq %r10,%r10 xorq %r11,%r11 + ud2 popfq CFI_ADJUST_CFA_OFFSET -8 /*CFI_RESTORE rflags*/
arch/x86/include/asm/irqflags.h +4 -4
@@ -28,7 +28,7 @@ static inline unsigned long native_save_fl(void)static inline void native_restore_fl (unsigned long flags) { - asmvolatile ("push %0 ; popf" + asmvolatile ("push %0 ; ud2; popf" :/* no output */ :"g" (flags) :"memory" ,"cc" );
@@ -36,7 +36,7 @@ static inline void native_restore_fl(unsigned long flags)static inline void native_irq_disable (void ) { - asmvolatile ("cli" : : :"memory" ); + asmvolatile ("ud2; cli" : : :"memory" ); }static inline void native_irq_enable (void )
@@ -113,7 +113,7 @@ static inline unsigned long __raw_local_irq_save(void)#else #define ENABLE_INTERRUPTS (x) sti -#define DISABLE_INTERRUPTS (x) cli +#define DISABLE_INTERRUPTS (x) ud2; cli#ifdef CONFIG_X86_64 #define SWAPGS swapgs
@@ -181,7 +181,7 @@ static inline int raw_irqs_disabled(void)SAVE_REST ; \LOCKDEP_SYS_EXIT ; \RESTORE_REST ; \ - cli; \ + ud2; cli; \TRACE_IRQS_OFF ;#else
arch/x86/include/asm/processor.h +2 -1
@@ -545,6 +545,7 @@ static inline void native_set_iopl_mask(unsigned mask)"andl %1, %0;" "orl %2, %0;" "pushl %0;" +"ud2; " "popfl" : "=&r" (reg) : "i" (~X86_EFLAGS_IOPL), "r" (mask));
@@ -782,7 +783,7 @@ static inline void wbinvd_halt(void)mb ();/* check for clflush to determine if wbinvd is legal */ if (cpu_has_clflush) - asmvolatile ("cli; wbinvd; 1: hlt; jmp 1b" : : :"memory" ); + asmvolatile ("ud2; cli; wbinvd; 1: hlt; jmp 1b" : : :"memory" );else while (1 )halt ();
arch/x86/include/asm/system.h +2 -1
@@ -65,6 +65,7 @@ do { \"jmp __switch_to\n" /* regparm call */ \"1:\t" \"popl %%ebp\n\t" /* restore EBP */ \ +"ud2\n\t" "popfl\n" /* restore flags */ \ \/* output parameters */ \
@@ -102,7 +103,7 @@ do { \/* frame pointer must be last for get_wchan */ #define SAVE_CONTEXT "pushf ; pushq %%rbp ; movq %%rsi,%%rbp\n\t" -#define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popf\t" +#define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; testl $0x200,(%%rsp) ; jnz 1f ; ud2 ; 1: popf\t"#define __EXTRA_CLOBBER \ , "rcx", "rbx", "rdx", "r8", "r9", "r10", "r11", \
arch/x86/kernel/acpi/wakeup_64.S +1 -0
@@ -90,6 +90,7 @@ resume_point: movq saved_context_cr0(%rax), %rbx movq %rbx, %cr0 pushq pt_regs_flags(%rax) + ud2 popfq movq pt_regs_sp(%rax), %rsp movq pt_regs_bp(%rax), %rbp
arch/x86/kernel/cpu/common.c +11 -0
@@ -188,9 +188,11 @@ static inline int flag_is_changeable_p(u32 flag)"movl %0, %1 \n\t" "xorl %2, %0 \n\t" "pushl %0 \n\t" +"ud2 \n\t" "popfl \n\t" "pushfl \n\t" "popl %0 \n\t" +"ud2 \n\t" "popfl \n\t" : "=&r" (f1), "=&r" (f2)
@@ -1089,6 +1091,13 @@ static void clear_all_debug_regs(void)*/ #ifdef CONFIG_X86_64 +void assert_EFLAGS_IF (void ) +{ +unsigned long eflags =native_save_fl (); +BUG_ON (!(eflags &X86_EFLAGS_IF )); +} + +extern int debug_save_fl;void __cpuinit cpu_init (void ) {struct orig_ist *orig_ist;
@@ -1187,6 +1196,8 @@ void __cpuinit cpu_init(void)if (is_uv_system ())uv_cpu_init (); + + assert_EFLAGS_IF(); }#else
arch/x86/kernel/entry_64.S +6 -0
@@ -400,6 +400,10 @@ ENTRY(ret_from_fork) push $0x0202 CFI_ADJUST_CFA_OFFSET 8 + testq $0x200,(%rsp) + jnz 1f + ud2 +1: popf # reset kernel eflags CFI_ADJUST_CFA_OFFSET -8
@@ -866,6 +870,7 @@ irq_return: #ifdef CONFIG_PARAVIRT ENTRY(native_iret) + ud2 iretq .section __ex_table,"a"
@@ -1139,6 +1144,7 @@ gs_change: movl %edi,%gs 2: mfence /* workaround */ SWAPGS + ud2 popf CFI_ADJUST_CFA_OFFSET -8 ret
arch/x86/kernel/head_64.S +1 -0
@@ -202,6 +202,7 @@ ENTRY(secondary_startup_64) /* zero EFLAGS after setting rsp */ pushq $0 + ud2 popfq /*
arch/x86/kernel/kprobes.c +1 -0
@@ -634,6 +634,7 @@ static void __used __kprobes kretprobe_trampoline_holder(void)" popq %rdi\n" /* Skip orig_ax, ip, cs */ " addq $24, %rsp\n" +" ud2\n" " popfq\n"#else " pushf\n"
arch/x86/kernel/paravirt_patch_64.c +3 -3
@@ -2,11 +2,11 @@#include <asm/asm-offsets.h> #include <linux/stringify.h> -DEF_NATIVE (pv_irq_ops, irq_disable,"cli" ); +DEF_NATIVE (pv_irq_ops, irq_disable,"ud2; cli" );DEF_NATIVE (pv_irq_ops, irq_enable,"sti" ); -DEF_NATIVE (pv_irq_ops, restore_fl,"pushq %rdi; popfq" ); +DEF_NATIVE (pv_irq_ops, restore_fl,"pushq %rdi; ud2; popfq" );DEF_NATIVE (pv_irq_ops, save_fl,"pushfq; popq %rax" ); -DEF_NATIVE (pv_cpu_ops, iret,"iretq" ); +DEF_NATIVE (pv_cpu_ops, iret,"ud2; iretq" );DEF_NATIVE (pv_mmu_ops, read_cr2,"movq %cr2, %rax" );DEF_NATIVE (pv_mmu_ops, read_cr3,"movq %cr3, %rax" );DEF_NATIVE (pv_mmu_ops, write_cr3,"movq %rdi, %cr3" );
arch/x86/kernel/process_64.c +1 -0
@@ -198,6 +198,7 @@ void __show_regs(struct pt_regs *regs, int all)rdmsrl (MSR_FS_BASE , fs);rdmsrl (MSR_GS_BASE , gs);rdmsrl (MSR_KERNEL_GS_BASE , shadowgs); +//shadowgs = gs = fs = 0xdeadbeef; if (!all)return ;
arch/x86/kernel/relocate_kernel_64.S +2 -0
@@ -69,6 +69,7 @@ relocate_kernel: /* zero out flags, and disable interrupts */ pushq $0 + ud2 popfq /*
@@ -198,6 +199,7 @@ virtual_mapped: movq %r8, %cr0 movq %rbp, %rax + ud2 popf popq %r15 popq %r14
arch/x86/kernel/smpboot.c +3 -0
@@ -266,6 +266,7 @@ static void __cpuinit smp_callin(void)/* * Activate a secondary processor. */ +extern void assert_EFLAGS_IF (void ); notrace static void __cpuinit start_secondary(void *unused) {/*
@@ -274,7 +275,9 @@ notrace static void __cpuinit start_secondary(void *unused)* most necessary things. */ vmi_bringup (); +assert_EFLAGS_IF ();cpu_init (); +assert_EFLAGS_IF ();preempt_disable ();smp_callin ();
arch/x86/kernel/traps.c +4 -0
@@ -897,6 +897,8 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) }#endif +extern void assert_EFLAGS_IF (void ); +void __init trap_init (void ) {int i;
@@ -967,7 +969,9 @@ void __init trap_init(void)/* * Should be a barrier for any external CPU state: */ +assert_EFLAGS_IF ();cpu_init (); x86_init.irqs.trap_init (); +assert_EFLAGS_IF (); }
arch/x86/kernel/verify_cpu_64.S +4 -0
@@ -35,6 +35,7 @@ verify_cpu: pushfl # Save caller passed flags pushl $0 # Kill any dangerous flags + ud2 popfl pushfl # standard way to check for cpuid
@@ -42,6 +43,7 @@ verify_cpu: movl %eax,%ebx xorl $0x200000,%eax pushl %eax + ud2 popfl pushfl popl %eax
@@ -96,10 +98,12 @@ verify_cpu_sse_test: jmp verify_cpu_sse_test # try again verify_cpu_no_longmode: + ud2 popfl # Restore caller passed flags movl $1,%eax ret verify_cpu_sse_ok: + ud2 popfl # Restore caller passed flags xorl %eax, %eax ret
arch/x86/lib/cmpxchg8b_emu.S +2 -0
@@ -42,6 +42,7 @@ cmpxchg8b_emu: movl %ebx, (%esi) movl %ecx, 4(%esi) + ud2 popfl ret
@@ -50,6 +51,7 @@ cmpxchg8b_emu: half_same: movl 4(%esi), %edx + ud2 popfl ret
arch/x86/mm/fault.c +20 -6
@@ -16,6 +16,8 @@#include <asm/pgalloc.h> /* pgd_*(), ... */ #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */ +#include <asm/xen/page.h> +/* * Page fault error code bits: *
@@ -444,7 +446,7 @@ static int bad_address(void *p)return probe_kernel_address ((unsigned long *)p, dummy); } -static void dump_pagetable (unsigned long address) +/*static*/ void dump_pagetable (unsigned long address) {pgd_t *base =__va (read_cr3 () &PHYSICAL_PAGE_MASK );pgd_t *pgd = base +pgd_index (address);
@@ -455,7 +457,9 @@ static void dump_pagetable(unsigned long address)if (bad_address (pgd)) goto bad; -printk ("PGD %lx " ,pgd_val (*pgd)); +printk ("%#lx -> " , address); +printk ("CR3 %p/%lx/%lx " , base,read_cr3 (),pfn_to_mfn (read_cr3 () >>PAGE_SHIFT )); +printk ("PGD %lx/%lx " ,pgd_val (*pgd), pgd->pgd);if (!pgd_present (*pgd)) goto out;
@@ -464,7 +468,7 @@ static void dump_pagetable(unsigned long address)if (bad_address (pud)) goto bad; -printk ("PUD %lx " ,pud_val (*pud)); +printk ("PUD %lx/%lx " ,pud_val (*pud), pud->pud);if (!pud_present (*pud) ||pud_large (*pud)) goto out;
@@ -472,7 +476,7 @@ static void dump_pagetable(unsigned long address)if (bad_address (pmd)) goto bad; -printk ("PMD %lx " ,pmd_val (*pmd)); +printk ("PMD %lx/%lx " ,pmd_val (*pmd), pmd->pmd);if (!pmd_present (*pmd) ||pmd_large (*pmd)) goto out;
@@ -480,7 +484,7 @@ static void dump_pagetable(unsigned long address)if (bad_address (pte)) goto bad; -printk ("PTE %lx" ,pte_val (*pte)); +printk ("PTE %lx/%lx" ,pte_val (*pte), pte->pte); out:printk ("\n" );return ;
@@ -683,6 +687,8 @@ static inline void show_signal_msg(struct pt_regs *regs, unsigned long error_code, unsigned long address, struct task_struct *tsk) { + extern void check_hypercall_page(void); +if (!unhandled_signal (tsk,SIGSEGV ))return ;
@@ -693,10 +699,18 @@ show_signal_msg(struct pt_regs *regs, unsigned long error_code,task_pid_nr (tsk) >1 ?KERN_INFO :KERN_EMERG , tsk->comm,task_pid_nr (tsk), address, (void *)regs->ip, (void *)regs->sp, error_code); - +printk (KERN_CONT " cs %04lx\n" , regs->cs);print_vma_addr (KERN_CONT " in " , regs->ip);printk (KERN_CONT "\n" ); +dump_pagetable (address); +dump_stack (); + +check_hypercall_page (); + +die ("SEGFAULT" , regs, error_code); + +//BUG(); } static void
arch/x86/mm/init.c +8 -0
@@ -14,6 +14,8 @@#include <asm/tlb.h> #include <asm/proto.h> +#include <asm/xen/hypercall.h> + DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);unsigned long __initdata e820_table_start;
@@ -379,9 +381,15 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)void free_initmem (void ) { +extern void check_hypercall_page (void ); + +check_hypercall_page (); +free_init_pages ("unused kernel memory" , (unsigned long )(&__init_begin), (unsigned long )(&__init_end)); + +check_hypercall_page (); }#ifdef CONFIG_BLK_DEV_INITRD
arch/x86/mm/setup_nx.c +1 -1
@@ -7,7 +7,7 @@int nx_enabled;#if defined(CONFIG_X86_64 ) || defined(CONFIG_X86_PAE ) -static int disable_nx__cpuinitdata ; +static int disable_nx__cpuinitdata =1 ;/* * noexec = on|off
arch/x86/xen/enlighten.c +20 -0
@@ -113,6 +113,8 @@ static void xen_vcpu_setup(int cpu)printk (KERN_DEBUG "trying to map vcpu_info %d at %p, mfn %llx, offset %d\n" , cpu, vcpup, info.mfn, info.offset); +printk (KERN_CRIT "%s: time before change is %#llx\n" , __func__,xen_clocksource_read ()); +/* Check to see if the hypervisor will put the vcpu_info structure where we want it, which allows direct access via a percpu-variable. */
@@ -128,7 +130,12 @@ static void xen_vcpu_setup(int cpu)printk (KERN_DEBUG "cpu %d using vcpu_info at %p\n" , cpu, vcpup); +printk (KERN_CRIT "time pad is 0x%02x%02x\n" , + vcpup->time.pad[0 ], + vcpup->time.pad[1 ]); + } +printk (KERN_CRIT "%s: time after change is %#llx\n" , __func__,xen_clocksource_read ()); }/*
@@ -857,6 +864,7 @@ void xen_setup_vcpu_info_placement(void) pv_irq_ops.irq_enable =__PV_IS_CALLEE_SAVE (xen_irq_enable_direct); pv_mmu_ops.read_cr2 = xen_read_cr2_direct; } +printk (KERN_CRIT "%s: time after change is %#llx\n" , __func__,xen_clocksource_read ()); } static unsigned xen_patch(u8 type, u16 clobbers, void *insnbuf,
@@ -1189,3 +1197,15 @@ asmlinkage void __init xen_start_kernel(void)x86_64_start_reservations ((char *)__pa_symbol (&boot_params));#endif } + +void check_hypercall_page (void ) +{ +extern void dump_pagetable (unsigned long address); +//extern unsigned char *hypercall_page; +int i; +printk ("SUPPORTED PTE MASK %#lx\n" , __supported_pte_mask); +dump_pagetable ((unsigned long )&hypercall_page); +for (i=0 ; i<32 ; i++) +printk (" %02x" , hypercall_page[127 ]._entry[i] &0xff ); +printk ("\n" ); +}
arch/x86/xen/irq.c +28 -0
@@ -11,6 +11,8 @@#include "xen-ops.h" +#include <xen/hvc-console.h> +/* * Force a proper event-channel callback from Xen after clearing the * callback mask. We do this in a very simple manner, by making a call
@@ -21,8 +23,11 @@ void xen_force_evtchn_callback(void) (void )HYPERVISOR_xen_version (0 ,NULL ); } +int debug_save_fl =0 ; +static unsigned long xen_save_fl (void ) { +static int once =10 ;struct vcpu_info *vcpu;unsigned long flags;
@@ -35,6 +40,11 @@ static unsigned long xen_save_fl(void)-0 -> 0x00000000 -1 -> 0xffffffff */ +if (debug_save_fl && once) { +xen_raw_printk (KERN_CRIT "%s: returning %#lx\n" , __func__, + (unsigned long )((-flags) &X86_EFLAGS_IF )); + once--; + }return (-flags) &X86_EFLAGS_IF ; }PV_CALLEE_SAVE_REGS_THUNK (xen_save_fl);
@@ -77,6 +87,23 @@ static void xen_irq_disable(void) }PV_CALLEE_SAVE_REGS_THUNK (xen_irq_disable); +struct tty_struct ; +void sysrq_handle_xen (int key,struct tty_struct *tty) +{ +extern s64 xen_last_timeout; +struct vcpu_info *vcpu; + vcpu =percpu_read (xen_vcpu); +printk (KERN_CRIT "DEBUG\n" ); +printk (KERN_CRIT "evtchn_upcall_mask %d\n" , vcpu->evtchn_upcall_mask =0 ); +printk (KERN_CRIT "last timeout %#llx now %#llx\n" , xen_last_timeout,xen_clocksource_read ()); +if ( xen_last_timeout <xen_clocksource_read ()) +printk (KERN_CRIT "missed an event?\n" ); +//printk(KERN_CRIT "tsc is %llx hypervisor says %#lx reread %#llx\n", +// native_read_tsc(), +// (unsigned long)HYPERVISOR_vcpu_op(VCPUOP_read_tsc, 0, NULL), +// native_read_tsc()); +} +static void xen_irq_enable (void ) {struct vcpu_info *vcpu;
@@ -128,6 +155,7 @@ static const struct pv_irq_ops xen_irq_ops __initdata = {void __init xen_init_irq_ops () { +xen_raw_printk (KERN_CRIT "Register Xen IRQ OPS\n" ); pv_irq_ops = xen_irq_ops; x86_init.irqs.intr_init = xen_init_IRQ; }
arch/x86/xen/smp.c +4 -0
@@ -55,10 +55,12 @@ static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } +extern void assert_EFLAGS_IF (void );static __cpuinit void cpu_bringup (void ) {int cpu =smp_processor_id (); +assert_EFLAGS_IF ();cpu_init ();touch_softlockup_watchdog ();preempt_disable ();
@@ -81,11 +83,13 @@ static __cpuinit void cpu_bringup(void)local_irq_enable ();wmb ();/* make sure everything is out */ +assert_EFLAGS_IF (); }static __cpuinit void cpu_bringup_and_idle (void ) {cpu_bringup (); +assert_EFLAGS_IF ();cpu_idle (); }
arch/x86/xen/time.c +16 -2
@@ -314,6 +314,8 @@ static int xen_timerop_set_next_event(unsigned long delta, {WARN_ON (evt->mode !=CLOCK_EVT_MODE_ONESHOT ); +printk (KERN_CRIT "%s\n" , __func__); +if (HYPERVISOR_set_timer_op (get_abs_timeout (delta)) <0 )BUG ();
@@ -367,6 +369,8 @@ static void xen_vcpuop_set_mode(enum clock_event_mode mode, } } +s64 xen_last_timeout; +static int xen_vcpuop_set_next_event (unsigned long delta,struct clock_event_device *evt) {
@@ -376,9 +380,17 @@ static int xen_vcpuop_set_next_event(unsigned long delta,WARN_ON (evt->mode !=CLOCK_EVT_MODE_ONESHOT ); - single.timeout_abs_ns =get_abs_timeout (delta); + xen_last_timeout = single.timeout_abs_ns =get_abs_timeout (delta); single.flags = VCPU_SSHOTTMR_future; +if (0 ) { +printk (KERN_CRIT "%s singleshot at %#llx (%#llx + %#lx)\n" , __func__, + single.timeout_abs_ns,xen_clocksource_read (), delta); +printk (KERN_CRIT "%s xen_vcpu->time %#llx\n" , __func__, +pvclock_clocksource_read (&per_cpu (xen_vcpu, cpu)->time)); +printk (KERN_CRIT "%s xen_vcpu_info->time %#llx\n" , __func__, +pvclock_clocksource_read (&per_cpu (xen_vcpu_info, cpu).time)); + } ret =HYPERVISOR_vcpu_op (VCPUOP_set_singleshot_timer, cpu, &single);BUG_ON (ret !=0 && ret != -ETIME );
@@ -410,6 +422,8 @@ static irqreturn_t xen_timer_interrupt(int irq, void *dev_id)struct clock_event_device *evt = &__get_cpu_var (xen_clock_events);irqreturn_t ret; +//printk(KERN_CRIT "TIMER INTERRUPT\n"); + ret =IRQ_NONE ;if (evt->event_handler) { evt->event_handler (evt);
@@ -480,7 +494,7 @@ __init void xen_time_init(void)clocksource_register (&xen_clocksource); -if (HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer, cpu,NULL ) ==0 ) { +if (/*0 && */ HYPERVISOR_vcpu_op (VCPUOP_stop_periodic_timer, cpu,NULL ) ==0 ) {/* Successfully turned off 100Hz tick, so we have the vcpuop-based timer interface */ printk (KERN_DEBUG "Xen: using vcpuop timer interface\n" );
drivers/char/sysrq.c +9 -1
@@ -391,6 +391,14 @@ static struct sysrq_key_op sysrq_unrt_op = { .enable_mask = SYSRQ_ENABLE_RTNICE, }; +extern void sysrq_handle_xen (int key,struct tty_struct *tty); + +static struct sysrq_key_op sysrq_xen_op = { + .handler = sysrq_handle_xen, + .help_msg ="Xen(D)" , + .action_msg ="Xen debug sysrq" , +}; +/* Key Operations table and lock */ static DEFINE_SPINLOCK (sysrq_key_table_lock);
@@ -410,7 +418,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = {* a: Don't use for system provided sysrqs, it is handled specially on * sparc and will never arrive. */ -NULL ,/* a */ + &sysrq_xen_op,/* a */ &sysrq_reboot_op,/* b */ &sysrq_crash_op,/* c & ibm_emac driver debug */ &sysrq_showlocks_op, /* d */
drivers/xen/events.c +8 -1
@@ -438,6 +438,8 @@ static int bind_virq_to_irq(unsigned int virq, unsigned int cpu)per_cpu (virq_to_irq, cpu)[virq] = irq;bind_evtchn_to_cpu (evtchn, cpu); +if (virq ==0 ) +printk (KERN_CRIT "EVTCHN%d bound to VIRQ_TIMER\n" , evtchn); }spin_unlock (&irq_mapping_update_lock);
@@ -509,6 +511,8 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,int retval; irq =bind_virq_to_irq (virq, cpu); +if (virq ==0 ) +printk (KERN_CRIT "VIRQ_TIMER is IRQ%d\n" , irq); retval =request_irq (irq, handler, irqflags, devname, dev_id);if (retval !=0 ) {unbind_from_irq (irq);
@@ -621,6 +625,8 @@ void xen_evtchn_do_upcall(struct pt_regs *regs)struct vcpu_info *vcpu_info =__get_cpu_var (xen_vcpu);unsigned count; +//printk(KERN_CRIT "upcall on VCPU%d\n", cpu); +exit_idle ();irq_enter ();
@@ -646,7 +652,8 @@ void xen_evtchn_do_upcall(struct pt_regs *regs)int bit_idx =__ffs (pending_bits);int port = (word_idx *BITS_PER_LONG ) + bit_idx;int irq = evtchn_to_irq[port]; - +if (0 &&info_for_irq (irq)->type==IRQT_VIRQ &&virq_from_irq (irq) ==0 ) +printk (KERN_CRIT "upcall on EVTCHN%d, IRQ%d\n" , port, irq);if (irq !=-1 )handle_irq (irq, regs); }
drivers/xen/xenbus/xenbus_probe.c +3 -0
@@ -919,11 +919,14 @@ static void wait_for_devices(struct xenbus_driver *xendrv)return ;while (exists_disconnected_device (drv)) { +printk (KERN_CRIT "xenbus: waiting for devices (%d / %d).\n" , jiffies, timeout);if (time_after (jiffies, timeout))break ;schedule_timeout_interruptible (HZ /10 ); } +printk (KERN_CRIT "xenbus: done waiting\n" ); +bus_for_each_dev (&xenbus_frontend.bus,NULL , drv, print_device_status); }
include/xen/interface/vcpu.h +2 -0
@@ -170,4 +170,6 @@ struct vcpu_register_vcpu_info { };DEFINE_GUEST_HANDLE_STRUCT (vcpu_register_vcpu_info); +//#define VCPUOP_read_tsc 99 +#endif /* __XEN_PUBLIC_VCPU_H__ */
init/main.c +24 -0
@@ -514,11 +514,14 @@ static void __init mm_init(void)vmalloc_init (); } +extern void assert_EFLAGS_IF (void ); + asmlinkage void __init start_kernel(void) {char * command_line;extern struct kernel_param __start___param[], __stop___param[]; +assert_EFLAGS_IF ();smp_setup_processor_id ();/*
@@ -543,6 +546,7 @@ asmlinkage void __init start_kernel(void)* Interrupts are still disabled. Do necessary setups, then * enable them */ +assert_EFLAGS_IF ();lock_kernel ();tick_init ();boot_cpu_init ();
@@ -559,6 +563,7 @@ asmlinkage void __init start_kernel(void)page_alloc_init ();printk (KERN_NOTICE "Kernel command line: %s\n" , boot_command_line); +assert_EFLAGS_IF ();parse_early_param (); parse_args("Booting kernel", static_command_line, __start___param, __stop___param - __start___param,
@@ -570,7 +575,9 @@ asmlinkage void __init start_kernel(void)pidhash_init ();vfs_caches_init_early ();sort_main_extable (); +assert_EFLAGS_IF ();trap_init (); +assert_EFLAGS_IF ();mm_init ();/* * Set up the scheduler prior starting any interrupts (such as the
@@ -582,7 +589,9 @@ asmlinkage void __init start_kernel(void)* Disable preemption - early bootup scheduling is extremely * fragile until we cpu_idle() for the first time. */ +assert_EFLAGS_IF ();preempt_disable (); +assert_EFLAGS_IF ();if (!irqs_disabled ()) {printk (KERN_WARNING "start_kernel(): bug: interrupts were " "enabled *very* early, fixing it\n" );
@@ -599,9 +608,11 @@ asmlinkage void __init start_kernel(void)timekeeping_init ();time_init ();profile_init (); +assert_EFLAGS_IF ();if (!irqs_disabled ())printk (KERN_CRIT "start_kernel(): bug: interrupts were " "enabled early\n" ); +assert_EFLAGS_IF ();early_boot_irqs_on ();local_irq_enable ();
@@ -609,6 +620,7 @@ asmlinkage void __init start_kernel(void)set_gfp_allowed_mask (__GFP_BITS_MASK);kmem_cache_init_late (); +assert_EFLAGS_IF ();/* * HACK ALERT! This is early. We're enabling the console before
@@ -628,6 +640,7 @@ asmlinkage void __init start_kernel(void)*/ locking_selftest (); +assert_EFLAGS_IF ();#ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok &&page_to_pfn (virt_to_page ((void *)initrd_start)) < min_low_pfn) {
@@ -642,6 +655,7 @@ asmlinkage void __init start_kernel(void)enable_debug_pagealloc ();kmemtrace_init ();kmemleak_init (); +assert_EFLAGS_IF ();debug_objects_mem_init ();idr_init_cache ();setup_per_cpu_pageset ();
@@ -663,6 +677,7 @@ asmlinkage void __init start_kernel(void)buffer_init ();key_init ();security_init (); +assert_EFLAGS_IF ();vfs_caches_init (totalram_pages);radix_tree_init ();signals_init ();
@@ -676,6 +691,7 @@ asmlinkage void __init start_kernel(void)taskstats_init_early ();delayacct_init (); +assert_EFLAGS_IF ();check_bugs ();acpi_early_init ();/* before LAPIC and SMP init */
@@ -685,6 +701,7 @@ asmlinkage void __init start_kernel(void)/* Do the rest non-__init'ed, we're now alive */ rest_init (); +assert_EFLAGS_IF (); }/* Call all constructor functions linked into the kernel. */
@@ -804,6 +821,7 @@ static noinline int init_post(void)__releases (kernel_lock) {/* need to finish all async __init code before freeing the memory */ +assert_EFLAGS_IF ();async_synchronize_full ();free_initmem ();unlock_kernel ();
@@ -811,6 +829,7 @@ static noinline int init_post(void) system_state =SYSTEM_RUNNING ;numa_default_policy (); +assert_EFLAGS_IF ();if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 )printk (KERN_WARNING "Warning: unable to open an initial console.\n" );
@@ -846,6 +865,7 @@ static noinline int init_post(void)static int __init kernel_init (void * unused) { +assert_EFLAGS_IF ();lock_kernel ();/*
@@ -868,11 +888,13 @@ static int __init kernel_init(void * unused) cad_pid =task_pid (current); +assert_EFLAGS_IF ();smp_prepare_cpus (setup_max_cpus);do_pre_smp_initcalls ();start_boot_trace (); +assert_EFLAGS_IF ();smp_init ();sched_init_smp ();
@@ -883,6 +905,7 @@ static int __init kernel_init(void * unused)* the work */ +assert_EFLAGS_IF ();if (!ramdisk_execute_command) ramdisk_execute_command ="/init" ;
@@ -897,6 +920,7 @@ static int __init kernel_init(void * unused)* initmem segments and start the user-mode stuff.. */ +assert_EFLAGS_IF ();init_post ();return 0 ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel