Re: [RFC][PATCH 18/22] x86,kvm: Remove .fixup usage

Paolo Bonzini
2021-11-04T18:54:00Z

On 11/4/21 17:47, Peter Zijlstra wrote:
> KVM instruction emulation has a gnarly hack where the .fixup does a
> return, luckily exceptions can easily emulate a return so create a new
> extable type to fully do the FASTOP magic.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> arch/x86/include/asm/extable_fixup_types.h | 1 +
> arch/x86/kvm/emulate.c | 14 +++-----------
> arch/x86/mm/extable.c | 11 +++++++++++
> 3 files changed, 15 insertions(+), 11 deletions(-)
>
> --- a/arch/x86/include/asm/extable_fixup_types.h
> +++ b/arch/x86/include/asm/extable_fixup_types.h
> @@ -40,5 +40,6 @@
> #define EX_TYPE_ONE_REG (EX_TYPE_IMM_REG | EX_TYPE_IMM(1))
>
> #define EX_TYPE_FAULT_SGX 18
> +#define EX_TYPE_KVM_FASTOP 19
>
> #endif
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -344,7 +344,7 @@ static int fastop(struct x86_emulate_ctx
> __FOP_RET(#op "_" #dst)
>
> #define FOP1EEX(op, dst) \
> - FOP1E(op, dst) _ASM_EXTABLE(10b, kvm_fastop_exception)
> + FOP1E(op, dst) _ASM_EXTABLE_TYPE(10b, 10b, EX_TYPE_KVM_FASTOP)

There's a ret right after the 10b label, so I think you can just use this:

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 493511efa3dc..f382c03c5954 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -315,7 +315,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
__FOP_FUNC(#name)

#define __FOP_RET(name) \
- "ret \n\t" \
+ "11: ret \n\t" \
".size " name ", .-" name "\n\t"

#define FOP_RET(name) \
@@ -344,7 +344,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
__FOP_RET(#op "_" #dst)

#define FOP1EEX(op, dst) \
- FOP1E(op, dst) _ASM_EXTABLE(10b, kvm_fastop_exception)
+ FOP1E(op, dst) _ASM_EXTABLE_TYPE_REG(10b, 11b, EX_TYPE_ZERO_REG, %esi)

#define FASTOP1(op) \
FOP_START(op) \

Paolo