···1020102010211021.macro paranoidzeroentry_ist sym do_sym ist10221022ENTRY(\sym)10231023- INTR_FRAME10231023+ INTR_FRAME10241024 PARAVIRT_ADJUST_EXCEPTION_FRAME10251025 pushq $-1 /* ORIG_RAX: no syscall to restart */10261026 CFI_ADJUST_CFA_OFFSET 8···10881088errorentry alignment_check do_alignment_check10891089zeroentry simd_coprocessor_error do_simd_coprocessor_error1090109010911091- /* Reload gs selector with exception handling */10921092- /* edi: new selector */10911091+ /* Reload gs selector with exception handling */10921092+ /* edi: new selector */10931093ENTRY(native_load_gs_index)10941094 CFI_STARTPROC10951095 pushf10961096 CFI_ADJUST_CFA_OFFSET 810971097 DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))10981098- SWAPGS10981098+ SWAPGS10991099gs_change:11001100- movl %edi,%gs11001100+ movl %edi,%gs110111012: mfence /* workaround */11021102 SWAPGS11031103- popf11031103+ popf11041104 CFI_ADJUST_CFA_OFFSET -811051105- ret11051105+ ret11061106 CFI_ENDPROC11071107END(native_load_gs_index)1108110811091109- .section __ex_table,"a"11101110- .align 811111111- .quad gs_change,bad_gs11121112- .previous11131113- .section .fixup,"ax"11091109+ .section __ex_table,"a"11101110+ .align 811111111+ .quad gs_change,bad_gs11121112+ .previous11131113+ .section .fixup,"ax"11141114 /* running with kernelgs */11151115bad_gs:11161116 SWAPGS /* switch back to user gs */11171117 xorl %eax,%eax11181118- movl %eax,%gs11191119- jmp 2b11201120- .previous11181118+ movl %eax,%gs11191119+ jmp 2b11201120+ .previous1121112111221122/*11231123 * Create a kernel thread.···11521152 * so internally to the x86_64 port you can rely on kernel_thread()11531153 * not to reschedule the child before returning, this avoids the need11541154 * of hacks for example to fork off the per-CPU idle tasks.11551155- * [Hopefully no generic code relies on the reschedule -AK]11551155+ * [Hopefully no generic code relies on the reschedule -AK]11561156 */11571157 RESTORE_ALL11581158 UNFAKE_STACK_FRAME···12311231zeroentry xen_hypervisor_callback xen_do_hypervisor_callback1232123212331233/*12341234-# A note on the "critical region" in our callback handler.12351235-# We want to avoid stacking callback handlers due to events occurring12361236-# during handling of the last event. To do this, we keep events disabled12371237-# until we've done all processing. HOWEVER, we must enable events before12381238-# popping the stack frame (can't be done atomically) and so it would still12391239-# be possible to get enough handler activations to overflow the stack.12401240-# Although unlikely, bugs of that kind are hard to track down, so we'd12411241-# like to avoid the possibility.12421242-# So, on entry to the handler we detect whether we interrupted an12431243-# existing activation in its critical region -- if so, we pop the current12441244-# activation and restart the handler using the previous one.12451245-*/12341234+ * A note on the "critical region" in our callback handler.12351235+ * We want to avoid stacking callback handlers due to events occurring12361236+ * during handling of the last event. To do this, we keep events disabled12371237+ * until we've done all processing. HOWEVER, we must enable events before12381238+ * popping the stack frame (can't be done atomically) and so it would still12391239+ * be possible to get enough handler activations to overflow the stack.12401240+ * Although unlikely, bugs of that kind are hard to track down, so we'd12411241+ * like to avoid the possibility.12421242+ * So, on entry to the handler we detect whether we interrupted an12431243+ * existing activation in its critical region -- if so, we pop the current12441244+ * activation and restart the handler using the previous one.12451245+ */12461246ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)12471247 CFI_STARTPROC12481248-/* Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will12491249- see the correct pointer to the pt_regs */12481248+/*12491249+ * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will12501250+ * see the correct pointer to the pt_regs12511251+ */12501252 movq %rdi, %rsp # we don't return, adjust the stack frame12511253 CFI_ENDPROC12521254 DEFAULT_FRAME···12661264END(do_hypervisor_callback)1267126512681266/*12691269-# Hypervisor uses this for application faults while it executes.12701270-# We get here for two reasons:12711271-# 1. Fault while reloading DS, ES, FS or GS12721272-# 2. Fault while executing IRET12731273-# Category 1 we do not need to fix up as Xen has already reloaded all segment12741274-# registers that could be reloaded and zeroed the others.12751275-# Category 2 we fix up by killing the current process. We cannot use the12761276-# normal Linux return path in this case because if we use the IRET hypercall12771277-# to pop the stack frame we end up in an infinite loop of failsafe callbacks.12781278-# We distinguish between categories by comparing each saved segment register12791279-# with its current contents: any discrepancy means we in category 1.12801280-*/12671267+ * Hypervisor uses this for application faults while it executes.12681268+ * We get here for two reasons:12691269+ * 1. Fault while reloading DS, ES, FS or GS12701270+ * 2. Fault while executing IRET12711271+ * Category 1 we do not need to fix up as Xen has already reloaded all segment12721272+ * registers that could be reloaded and zeroed the others.12731273+ * Category 2 we fix up by killing the current process. We cannot use the12741274+ * normal Linux return path in this case because if we use the IRET hypercall12751275+ * to pop the stack frame we end up in an infinite loop of failsafe callbacks.12761276+ * We distinguish between categories by comparing each saved segment register12771277+ * with its current contents: any discrepancy means we in category 1.12781278+ */12811279ENTRY(xen_failsafe_callback)12821280 INTR_FRAME 1 (6*8)12831281 /*CFI_REL_OFFSET gs,GS*/···13411339#endif1342134013431341 /*13441344- * "Paranoid" exit path from exception stack.13451345- * Paranoid because this is used by NMIs and cannot take13421342+ * "Paranoid" exit path from exception stack.13431343+ * Paranoid because this is used by NMIs and cannot take13461344 * any kernel state for granted.13471345 * We don't do kernel preemption checks here, because only13481346 * NMI should be common and it does not enable IRQs and···14471445 cmpq %rcx,RIP+8(%rsp)14481446 je error_swapgs14491447 cmpq $gs_change,RIP+8(%rsp)14501450- je error_swapgs14481448+ je error_swapgs14511449 jmp error_sti14521450END(error_entry)14531451···15231521 CFI_ENDPROC15241522#else15251523 jmp paranoid_exit15261526- CFI_ENDPROC15241524+ CFI_ENDPROC15271525#endif15281526END(nmi)15291527