Skip to content

Commit 7962918

Browse files
committed
KVM: emulate: do not adjust size of fastop and setcc subroutines
Instead of doing complicated calculations to find the size of the subroutines (which are even more complicated because they need to be stringified into an asm statement), just hardcode to 16. It is less dense for a few combinations of IBT/SLS/retbleed, but it has the advantage of being really simple. Cc: [email protected] # 5.15.x: 84e7051: x86/kvm: fix FASTOP_SIZE when return thunks are enabled Cc: [email protected] Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 8a414f9 commit 7962918

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

arch/x86/kvm/emulate.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,6 @@
189189
#define X8(x...) X4(x), X4(x)
190190
#define X16(x...) X8(x), X8(x)
191191

192-
#define NR_FASTOP (ilog2(sizeof(ulong)) + 1)
193-
#define RET_LENGTH (1 + (4 * IS_ENABLED(CONFIG_RETHUNK)) + \
194-
IS_ENABLED(CONFIG_SLS))
195-
#define FASTOP_LENGTH (ENDBR_INSN_SIZE + 7 + RET_LENGTH)
196-
#define FASTOP_SIZE (8 << ((FASTOP_LENGTH > 8) & 1) << ((FASTOP_LENGTH > 16) & 1))
197-
static_assert(FASTOP_LENGTH <= FASTOP_SIZE);
198-
199192
struct opcode {
200193
u64 flags;
201194
u8 intercept;
@@ -310,9 +303,15 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
310303
* Moreover, they are all exactly FASTOP_SIZE bytes long, so functions for
311304
* different operand sizes can be reached by calculation, rather than a jump
312305
* table (which would be bigger than the code).
306+
*
307+
* The 16 byte alignment, considering 5 bytes for the RET thunk, 3 for ENDBR
308+
* and 1 for the straight line speculation INT3, leaves 7 bytes for the
309+
* body of the function. Currently none is larger than 4.
313310
*/
314311
static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
315312

313+
#define FASTOP_SIZE 16
314+
316315
#define __FOP_FUNC(name) \
317316
".align " __stringify(FASTOP_SIZE) " \n\t" \
318317
".type " name ", @function \n\t" \
@@ -446,9 +445,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
446445
* RET | JMP __x86_return_thunk [1,5 bytes; CONFIG_RETHUNK]
447446
* INT3 [1 byte; CONFIG_SLS]
448447
*/
449-
#define SETCC_LENGTH (ENDBR_INSN_SIZE + 3 + RET_LENGTH)
450-
#define SETCC_ALIGN (4 << ((SETCC_LENGTH > 4) & 1) << ((SETCC_LENGTH > 8) & 1))
451-
static_assert(SETCC_LENGTH <= SETCC_ALIGN);
448+
#define SETCC_ALIGN 16
452449

453450
#define FOP_SETCC(op) \
454451
".align " __stringify(SETCC_ALIGN) " \n\t" \

0 commit comments

Comments
 (0)