Skip to content

Commit 3010a06

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/paravirt, objtool: Annotate indirect calls
Paravirt emits indirect calls which get flagged by objtool retpoline checks, annotate it away because all these indirect calls will be patched out before we start userspace. This patching happens through alternative_instructions() -> apply_paravirt() -> pv_init_ops.patch() which will eventually end up in paravirt_patch_default(). This function _will_ write direct alternatives. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Acked-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 9e0e3c5 commit 3010a06

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

arch/x86/include/asm/paravirt.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifdef CONFIG_PARAVIRT
88
#include <asm/pgtable_types.h>
99
#include <asm/asm.h>
10+
#include <asm/nospec-branch.h>
1011

1112
#include <asm/paravirt_types.h>
1213

@@ -879,23 +880,27 @@ extern void default_banner(void);
879880

880881
#define INTERRUPT_RETURN \
881882
PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
882-
jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
883+
ANNOTATE_RETPOLINE_SAFE; \
884+
jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret);)
883885

884886
#define DISABLE_INTERRUPTS(clobbers) \
885887
PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
886888
PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
889+
ANNOTATE_RETPOLINE_SAFE; \
887890
call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable); \
888891
PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
889892

890893
#define ENABLE_INTERRUPTS(clobbers) \
891894
PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
892895
PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
896+
ANNOTATE_RETPOLINE_SAFE; \
893897
call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable); \
894898
PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
895899

896900
#ifdef CONFIG_X86_32
897901
#define GET_CR0_INTO_EAX \
898902
push %ecx; push %edx; \
903+
ANNOTATE_RETPOLINE_SAFE; \
899904
call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
900905
pop %edx; pop %ecx
901906
#else /* !CONFIG_X86_32 */
@@ -917,21 +922,25 @@ extern void default_banner(void);
917922
*/
918923
#define SWAPGS \
919924
PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
920-
call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs) \
925+
ANNOTATE_RETPOLINE_SAFE; \
926+
call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs); \
921927
)
922928

923929
#define GET_CR2_INTO_RAX \
924-
call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2)
930+
ANNOTATE_RETPOLINE_SAFE; \
931+
call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2);
925932

926933
#define USERGS_SYSRET64 \
927934
PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64), \
928935
CLBR_NONE, \
929-
jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
936+
ANNOTATE_RETPOLINE_SAFE; \
937+
jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64);)
930938

931939
#ifdef CONFIG_DEBUG_ENTRY
932940
#define SAVE_FLAGS(clobbers) \
933941
PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_save_fl), clobbers, \
934942
PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \
943+
ANNOTATE_RETPOLINE_SAFE; \
935944
call PARA_INDIRECT(pv_irq_ops+PV_IRQ_save_fl); \
936945
PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
937946
#endif

arch/x86/include/asm/paravirt_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <asm/desc_defs.h>
4444
#include <asm/kmap_types.h>
4545
#include <asm/pgtable_types.h>
46+
#include <asm/nospec-branch.h>
4647

4748
struct page;
4849
struct thread_struct;
@@ -392,7 +393,9 @@ int paravirt_disable_iospace(void);
392393
* offset into the paravirt_patch_template structure, and can therefore be
393394
* freely converted back into a structure offset.
394395
*/
395-
#define PARAVIRT_CALL "call *%c[paravirt_opptr];"
396+
#define PARAVIRT_CALL \
397+
ANNOTATE_RETPOLINE_SAFE \
398+
"call *%c[paravirt_opptr];"
396399

397400
/*
398401
* These macros are intended to wrap calls through one of the paravirt

0 commit comments

Comments
 (0)