Skip to content

Commit debc5a1

Browse files
committed
KVM: x86: use a separate asm-offsets.c file
This already removes an ugly #include "" from asm-offsets.c, but especially it avoids a future error when trying to define asm-offsets for KVM's svm/svm.h header. This would not work for kernel/asm-offsets.c, because svm/svm.h includes kvm_cache_regs.h which is not in the include path when compiling asm-offsets.c. The problem is not there if the .c file is in arch/x86/kvm. Suggested-by: Sean Christopherson <seanjc@google.com> Cc: stable@vger.kernel.org Fixes: a149180 ("x86: Add magic AMD return-thunk") Reviewed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f4298ca commit debc5a1

5 files changed

Lines changed: 30 additions & 7 deletions

File tree

arch/x86/kernel/asm-offsets.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <asm/suspend.h>
2020
#include <asm/tlbflush.h>
2121
#include <asm/tdx.h>
22-
#include "../kvm/vmx/vmx.h"
2322

2423
#ifdef CONFIG_XEN
2524
#include <xen/interface/xen.h>
@@ -108,9 +107,4 @@ static void __used common(void)
108107
OFFSET(TSS_sp0, tss_struct, x86_tss.sp0);
109108
OFFSET(TSS_sp1, tss_struct, x86_tss.sp1);
110109
OFFSET(TSS_sp2, tss_struct, x86_tss.sp2);
111-
112-
if (IS_ENABLED(CONFIG_KVM_INTEL)) {
113-
BLANK();
114-
OFFSET(VMX_spec_ctrl, vcpu_vmx, spec_ctrl);
115-
}
116110
}

arch/x86/kvm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/kvm-asm-offsets.s
2+
/kvm-asm-offsets.h

arch/x86/kvm/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ endif
3434
obj-$(CONFIG_KVM) += kvm.o
3535
obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
3636
obj-$(CONFIG_KVM_AMD) += kvm-amd.o
37+
38+
AFLAGS_vmx/vmenter.o := -iquote $(obj)
39+
$(obj)/vmx/vmenter.o: $(obj)/kvm-asm-offsets.h
40+
41+
$(obj)/kvm-asm-offsets.h: $(obj)/kvm-asm-offsets.s FORCE
42+
$(call filechk,offsets,__KVM_ASM_OFFSETS_H__)
43+
44+
targets += kvm-asm-offsets.s
45+
clean-files += kvm-asm-offsets.h

arch/x86/kvm/kvm-asm-offsets.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Generate definitions needed by assembly language modules.
4+
* This code generates raw asm output which is post-processed to extract
5+
* and format the required data.
6+
*/
7+
#define COMPILE_OFFSETS
8+
9+
#include <linux/kbuild.h>
10+
#include "vmx/vmx.h"
11+
12+
static void __used common(void)
13+
{
14+
if (IS_ENABLED(CONFIG_KVM_INTEL)) {
15+
BLANK();
16+
OFFSET(VMX_spec_ctrl, vcpu_vmx, spec_ctrl);
17+
}
18+
}

arch/x86/kvm/vmx/vmenter.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <linux/linkage.h>
33
#include <asm/asm.h>
4-
#include <asm/asm-offsets.h>
54
#include <asm/bitsperlong.h>
65
#include <asm/kvm_vcpu_regs.h>
76
#include <asm/nospec-branch.h>
87
#include <asm/percpu.h>
98
#include <asm/segment.h>
9+
#include "kvm-asm-offsets.h"
1010
#include "run_flags.h"
1111

1212
#define WORD_SIZE (BITS_PER_LONG / 8)

0 commit comments

Comments
 (0)