Skip to content

Commit f007ea2

Browse files
Masami HiramatsuIngo Molnar
authored andcommitted
kprobes/x86: Cleanup save/restore registers
Introduce SAVE/RESOTRE_REGS_STRING for cleanup kretprobe-trampoline asm code. These macros will be used for emulating interruption. Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com> Cc: systemtap <systemtap@sources.redhat.com> Cc: DLE <dle-develop@lists.sourceforge.net> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Cc: Jim Keniston <jkenisto@us.ibm.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Anders Kaseorg <andersk@ksplice.com> Cc: Tim Abbott <tabbott@ksplice.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Jason Baron <jbaron@redhat.com> Cc: Mathieu Desnoyers <compudj@krystal.dyndns.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com> LKML-Reference: <20100225133430.6725.83342.stgit@localhost6.localdomain6> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 0f94eb6 commit f007ea2

1 file changed

Lines changed: 67 additions & 61 deletions

File tree

‎arch/x86/kernel/kprobes.c‎

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,69 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
554554
return 0;
555555
}
556556

557+
#ifdef CONFIG_X86_64
558+
#define SAVE_REGS_STRING \
559+
/* Skip cs, ip, orig_ax. */ \
560+
" subq $24, %rsp\n" \
561+
" pushq %rdi\n" \
562+
" pushq %rsi\n" \
563+
" pushq %rdx\n" \
564+
" pushq %rcx\n" \
565+
" pushq %rax\n" \
566+
" pushq %r8\n" \
567+
" pushq %r9\n" \
568+
" pushq %r10\n" \
569+
" pushq %r11\n" \
570+
" pushq %rbx\n" \
571+
" pushq %rbp\n" \
572+
" pushq %r12\n" \
573+
" pushq %r13\n" \
574+
" pushq %r14\n" \
575+
" pushq %r15\n"
576+
#define RESTORE_REGS_STRING \
577+
" popq %r15\n" \
578+
" popq %r14\n" \
579+
" popq %r13\n" \
580+
" popq %r12\n" \
581+
" popq %rbp\n" \
582+
" popq %rbx\n" \
583+
" popq %r11\n" \
584+
" popq %r10\n" \
585+
" popq %r9\n" \
586+
" popq %r8\n" \
587+
" popq %rax\n" \
588+
" popq %rcx\n" \
589+
" popq %rdx\n" \
590+
" popq %rsi\n" \
591+
" popq %rdi\n" \
592+
/* Skip orig_ax, ip, cs */ \
593+
" addq $24, %rsp\n"
594+
#else
595+
#define SAVE_REGS_STRING \
596+
/* Skip cs, ip, orig_ax and gs. */ \
597+
" subl $16, %esp\n" \
598+
" pushl %fs\n" \
599+
" pushl %ds\n" \
600+
" pushl %es\n" \
601+
" pushl %eax\n" \
602+
" pushl %ebp\n" \
603+
" pushl %edi\n" \
604+
" pushl %esi\n" \
605+
" pushl %edx\n" \
606+
" pushl %ecx\n" \
607+
" pushl %ebx\n"
608+
#define RESTORE_REGS_STRING \
609+
" popl %ebx\n" \
610+
" popl %ecx\n" \
611+
" popl %edx\n" \
612+
" popl %esi\n" \
613+
" popl %edi\n" \
614+
" popl %ebp\n" \
615+
" popl %eax\n" \
616+
/* Skip ds, es, fs, gs, orig_ax, and ip. Note: don't pop cs here*/\
617+
" addl $24, %esp\n"
618+
#endif
619+
557620
/*
558621
* When a retprobed function returns, this code saves registers and
559622
* calls trampoline_handler() runs, which calls the kretprobe's handler.
@@ -567,81 +630,24 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
567630
/* We don't bother saving the ss register */
568631
" pushq %rsp\n"
569632
" pushfq\n"
570-
/*
571-
* Skip cs, ip, orig_ax.
572-
* trampoline_handler() will plug in these values
573-
*/
574-
" subq $24, %rsp\n"
575-
" pushq %rdi\n"
576-
" pushq %rsi\n"
577-
" pushq %rdx\n"
578-
" pushq %rcx\n"
579-
" pushq %rax\n"
580-
" pushq %r8\n"
581-
" pushq %r9\n"
582-
" pushq %r10\n"
583-
" pushq %r11\n"
584-
" pushq %rbx\n"
585-
" pushq %rbp\n"
586-
" pushq %r12\n"
587-
" pushq %r13\n"
588-
" pushq %r14\n"
589-
" pushq %r15\n"
633+
SAVE_REGS_STRING
590634
" movq %rsp, %rdi\n"
591635
" call trampoline_handler\n"
592636
/* Replace saved sp with true return address. */
593637
" movq %rax, 152(%rsp)\n"
594-
" popq %r15\n"
595-
" popq %r14\n"
596-
" popq %r13\n"
597-
" popq %r12\n"
598-
" popq %rbp\n"
599-
" popq %rbx\n"
600-
" popq %r11\n"
601-
" popq %r10\n"
602-
" popq %r9\n"
603-
" popq %r8\n"
604-
" popq %rax\n"
605-
" popq %rcx\n"
606-
" popq %rdx\n"
607-
" popq %rsi\n"
608-
" popq %rdi\n"
609-
/* Skip orig_ax, ip, cs */
610-
" addq $24, %rsp\n"
638+
RESTORE_REGS_STRING
611639
" popfq\n"
612640
#else
613641
" pushf\n"
614-
/*
615-
* Skip cs, ip, orig_ax and gs.
616-
* trampoline_handler() will plug in these values
617-
*/
618-
" subl $16, %esp\n"
619-
" pushl %fs\n"
620-
" pushl %es\n"
621-
" pushl %ds\n"
622-
" pushl %eax\n"
623-
" pushl %ebp\n"
624-
" pushl %edi\n"
625-
" pushl %esi\n"
626-
" pushl %edx\n"
627-
" pushl %ecx\n"
628-
" pushl %ebx\n"
642+
SAVE_REGS_STRING
629643
" movl %esp, %eax\n"
630644
" call trampoline_handler\n"
631645
/* Move flags to cs */
632646
" movl 56(%esp), %edx\n"
633647
" movl %edx, 52(%esp)\n"
634648
/* Replace saved flags with true return address. */
635649
" movl %eax, 56(%esp)\n"
636-
" popl %ebx\n"
637-
" popl %ecx\n"
638-
" popl %edx\n"
639-
" popl %esi\n"
640-
" popl %edi\n"
641-
" popl %ebp\n"
642-
" popl %eax\n"
643-
/* Skip ds, es, fs, gs, orig_ax and ip */
644-
" addl $24, %esp\n"
650+
RESTORE_REGS_STRING
645651
" popf\n"
646652
#endif
647653
" ret\n");

0 commit comments

Comments
 (0)