@@ -276,15 +276,11 @@ extern struct paravirt_patch_template pv_ops;
276276#define NATIVE_LABEL (a ,x ,b ) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t"
277277
278278unsigned int paravirt_patch (u8 type , void * insn_buff , unsigned long addr , unsigned int len );
279+ #define paravirt_ptr (op ) [paravirt_opptr] "m" (pv_ops.op)
279280
280281int paravirt_disable_iospace (void );
281282
282- /*
283- * This generates an indirect call based on the operation type number.
284- * The type number, computed in PARAVIRT_PATCH, is derived from the
285- * offset into the paravirt_patch_template structure, and can therefore be
286- * freely converted back into a structure offset.
287- */
283+ /* This generates an indirect call based on the operation type number. */
288284#define PARAVIRT_CALL \
289285 ANNOTATE_RETPOLINE_SAFE \
290286 "call *%[paravirt_opptr];"
@@ -317,12 +313,6 @@ int paravirt_disable_iospace(void);
317313 * However, x86_64 also has to clobber all caller saved registers, which
318314 * unfortunately, are quite a bit (r8 - r11)
319315 *
320- * The call instruction itself is marked by placing its start address
321- * and size into the .parainstructions section, so that
322- * apply_paravirt() in arch/i386/kernel/alternative.c can do the
323- * appropriate patching under the control of the backend pv_init_ops
324- * implementation.
325- *
326316 * Unfortunately there's no way to get gcc to generate the args setup
327317 * for the call, and then allow the call itself to be generated by an
328318 * inline asm. Because of this, we must do the complete arg setup and
@@ -421,14 +411,27 @@ int paravirt_disable_iospace(void);
421411 __mask & __eax; \
422412 })
423413
424-
414+ /*
415+ * Use alternative patching for paravirt calls:
416+ * - For replacing an indirect call with a direct one, use the "normal"
417+ * ALTERNATIVE() macro with the indirect call as the initial code sequence,
418+ * which will be replaced with the related direct call by using the
419+ * ALT_FLAG_DIRECT_CALL special case and the "always on" feature.
420+ * - In case the replacement is either a direct call or a short code sequence
421+ * depending on a feature bit, the ALTERNATIVE_2() macro is being used.
422+ * The indirect call is the initial code sequence again, while the special
423+ * code sequence is selected with the specified feature bit. In case the
424+ * feature is not active, the direct call is used as above via the
425+ * ALT_FLAG_DIRECT_CALL special case and the "always on" feature.
426+ */
425427#define ____PVOP_CALL (ret , op , call_clbr , extra_clbr , ...) \
426428 ({ \
427429 PVOP_CALL_ARGS; \
428430 PVOP_TEST_NULL(op); \
429- asm volatile(paravirt_alt(PARAVIRT_CALL) \
431+ asm volatile(ALTERNATIVE(PARAVIRT_CALL, ALT_CALL_INSTR, \
432+ ALT_CALL_ALWAYS) \
430433 : call_clbr, ASM_CALL_CONSTRAINT \
431- : paravirt_type (op), \
434+ : paravirt_ptr (op), \
432435 ##__VA_ARGS__ \
433436 : "memory", "cc" extra_clbr); \
434437 ret; \
@@ -439,10 +442,11 @@ int paravirt_disable_iospace(void);
439442 ({ \
440443 PVOP_CALL_ARGS; \
441444 PVOP_TEST_NULL(op); \
442- asm volatile(ALTERNATIVE(paravirt_alt(PARAVIRT_CALL), \
443- alt, cond) \
445+ asm volatile(ALTERNATIVE_2(PARAVIRT_CALL, \
446+ ALT_CALL_INSTR, ALT_CALL_ALWAYS, \
447+ alt, cond) \
444448 : call_clbr, ASM_CALL_CONSTRAINT \
445- : paravirt_type (op), \
449+ : paravirt_ptr (op), \
446450 ##__VA_ARGS__ \
447451 : "memory", "cc" extra_clbr); \
448452 ret; \
0 commit comments