Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: x86: Add a #define for the architectural max instruction length

Add a #define to capture x86's architecturally defined max instruction
length instead of open coding the literal in a variety of places.

No functional change intended.

Link: https://lore.kernel.org/r/20250201015518.689704-9-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+11 -9
+3 -1
arch/x86/kvm/kvm_emulate.h
··· 275 275 }; 276 276 }; 277 277 278 + #define X86_MAX_INSTRUCTION_LENGTH 15 279 + 278 280 struct fetch_cache { 279 - u8 data[15]; 281 + u8 data[X86_MAX_INSTRUCTION_LENGTH]; 280 282 u8 *ptr; 281 283 u8 *end; 282 284 };
+7 -7
arch/x86/kvm/trace.h
··· 830 830 TP_ARGS(vcpu, failed), 831 831 832 832 TP_STRUCT__entry( 833 - __field( __u64, rip ) 834 - __field( __u32, csbase ) 835 - __field( __u8, len ) 836 - __array( __u8, insn, 15 ) 837 - __field( __u8, flags ) 838 - __field( __u8, failed ) 833 + __field( __u64, rip ) 834 + __field( __u32, csbase ) 835 + __field( __u8, len ) 836 + __array( __u8, insn, X86_MAX_INSTRUCTION_LENGTH ) 837 + __field( __u8, flags ) 838 + __field( __u8, failed ) 839 839 ), 840 840 841 841 TP_fast_assign( ··· 846 846 __entry->rip = vcpu->arch.emulate_ctxt->_eip - __entry->len; 847 847 memcpy(__entry->insn, 848 848 vcpu->arch.emulate_ctxt->fetch.data, 849 - 15); 849 + X86_MAX_INSTRUCTION_LENGTH); 850 850 __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt->mode); 851 851 __entry->failed = failed; 852 852 ),
+1 -1
arch/x86/kvm/vmx/nested.c
··· 2970 2970 case INTR_TYPE_SOFT_EXCEPTION: 2971 2971 case INTR_TYPE_SOFT_INTR: 2972 2972 case INTR_TYPE_PRIV_SW_EXCEPTION: 2973 - if (CC(vmcs12->vm_entry_instruction_len > 15) || 2973 + if (CC(vmcs12->vm_entry_instruction_len > X86_MAX_INSTRUCTION_LENGTH) || 2974 2974 CC(vmcs12->vm_entry_instruction_len == 0 && 2975 2975 CC(!nested_cpu_has_zero_length_injection(vcpu)))) 2976 2976 return -EINVAL;