Update to 3.19-rc1
Paolo Bonzini
maintainercover Update to 3.19-rc1
The largest changes are in the XSAVE support. Recent kernels added a separate feature word for XSAVE features, and KVM's CPUID code is relying on the new definition. Except for cpu_has_xsaves, it's never accessing the feature itself: wrap cpu_has_xsaves with kvm_cpu_has_xsaves, and then there is no problem with out-of-bounds accesses.
Paolo Bonzini (4):
stubs for xsavec support
fixes for changes in the iommu and PCI APIs
fixes for changes in the percpu counter API
add trace_seq_buffer_ptr
external-module-compat-comm.h | 32 ++++++++++++++++++++++++++++++++ external-module-compat.c | 11 +++++++++++ linux | 2 +- sync | 14 ++++++++++++-- x86/external-module-compat.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1
Paolo Bonzini
maintainerPATCH 1/4 stubs for xsavec support
These are needed for KVM changes in 3.18.
Recent kernels added a separate feature word for XSAVE features, and KVM's CPUID code is relying on the new definition. Except for cpu_has_xsaves, it's never accessing the feature itself: wrap cpu_has_xsaves with kvm_cpu_has_xsaves, and then there is no problem with out-of-bounds accesses.
--- external-module-compat-comm.h | 4 ++++ external-module-compat.c | 11 +++++++++++ sync | 14 ++++++++++++-- x86/external-module-compat.h | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-)
external-module-compat-comm.h +4 -0
@@ -1424,3 +1424,7 @@ extern u64 kvm_get_boot_base_ns(struct timekeeper *tk);#undef is_zero_pfn#define is_zero_pfn (pfn) ((pfn) == page_to_pfn(ZERO_PAGE(0))) + +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,17 ,0 ) +void *get_xsave_addr (struct xsave_struct *xsave,int feature); +#endif
external-module-compat.c +11 -0
@@ -362,3 +362,14 @@ u64 kvm_get_boot_base_ns(struct timekeeper *tk) }#endif #endif + +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,17 ,0 ) +void *get_xsave_addr (struct xsave_struct *xsave,int feature) +{ +int index =fls64 (feature) -1 ; +u32 size, offset, ecx, edx; + +cpuid_count (0xd , index, &size, &offset, &ecx, &edx); +return (u8 *)xsave + offset; +} +#endif
sync +12 -2
@@ -44,8 +44,8 @@ def hack_content(fname, data): 'set_desc_base set_desc_limit pvclock_vcpu_time_info tboot_enabled ' 'i387_fxsave_struct native_write_msr_safe xsave_struct ' 'fpu_alloc fpu_free fpu_restore_checking fpu_save_init fpu_finit ' - 'load_gdt store_gdt xstate_size cpu_has_xsave __get_user_pages_fast ' - 'set_64bit siginfo_t use_mm ' + 'load_gdt store_gdt xstate_size cpu_has_xsave cpu_has_xsaves ' + '__get_user_pages_fast set_64bit siginfo_t use_mm ' 'unuse_mm request_threaded_irq init_fpu __this_cpu_read ' '__this_cpu_write sigset_from_compat ' 'sched_info_on x86_pmu_capability perf_get_x86_pmu_capability '
@@ -299,6 +299,16 @@ def hack_content(fname, data): if line == '#endif' and finish_endif: w('#endif') finish_endif = False + if match(r'xcomp_bv'): + w('#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)') + w(line) + w('#else') + # Will be under if (cpu_has_xsaves), which is always 0. Just + # replace with something that compiles, the C statement might + # span more than one line. + w('WARN(1, "this should never happen"),') + w(sub(r'xcomp_bv', 'xstate_bv', line)) + line = '#endif' if match(r'tkr\.'): w('#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)') w(line)
x86/external-module-compat.h +37 -0
@@ -428,6 +428,23 @@ static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)#define X86_FEATURE_MPX (9*32+14)/* Memory Protection Extension */ #endif +#if X86_FEATURE_XSAVEOPT <10 *32 +#undef X86_FEATURE_XSAVEOPT +#endif +#define X86_FEATURE_XSAVEOPT (10*32+0)/* XSAVEOPT instruction */ + +#ifndef X86_FEATURE_XSAVEC +#define X86_FEATURE_XSAVEC (10*32+1)/* XSAVEC instruction */ +#endif + +#ifndef X86_FEATURE_XGETBV1 +#define X86_FEATURE_XGETBV1 (10*32+2)/* "XCR1" register */ +#endif + +#ifndef X86_FEATURE_XSAVES +#define X86_FEATURE_XSAVES (10*32+3)/* XSAVES instruction */ +#endif +#ifndef MSR_AMD64_PATCH_LOADER #define MSR_AMD64_PATCH_LOADER 0xc0010020#endif
@@ -586,6 +603,10 @@ static inline void preempt_notifier_sys_exit(void) {}#define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)#endif +#ifndef cpu_has_xsaves +#define cpu_has_xsaves boot_cpu_has(X86_FEATURE_XSAVES) +#endif +/* EFER_LMA and EFER_LME are missing in pre 2.6.24 i386 kernels */ #ifndef EFER_LME #define _EFER_LME 8/* Long mode enable */
@@ -1141,6 +1162,16 @@ static inline int kvm_init_fpu(struct task_struct *tsk)#define XSTATE_EAGER (XSTATE_BNDREGS | XSTATE_BNDCSR)#endif +#ifndef XSTATE_OPMASK +#define XSTATE_OPMASK 0x20 +#define XSTATE_ZMM_Hi256 0x40 +#define XSTATE_Hi16_ZMM 0x80 +#endif + +#ifndef XSTATE_AVX512 +#define XSTATE_AVX512 (XSTATE_OPMASK | XSTATE_ZMM_Hi256 | XSTATE_Hi16_ZMM) +#endif +#ifndef XSTATE_EXTEND_MASK #define XSTATE_EXTEND_MASK (~(XSTATE_FPSSE | (1ULL << 63)))#endif
@@ -1496,6 +1527,12 @@ static inline int __register_hotcpu_notifier(struct notifier_block *nb) }#endif +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,17 ,0 ) +#define kvm_cpu_has_xsaves 0 +#else /* >= 3.17 */ +#define kvm_cpu_has_xsaves cpu_has_xsaves +#endif /* >= 3.17 */ +#ifndef MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS #define MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS (1ULL << 29)#endif
Signature · 1 line
1.8.3.1
Re: [PATCH 1/4] stubs for xsavec support
Quoted 16 lines · Paolo Bonzini
These are needed for KVM changes in 3.18.
Recent kernels added a separate feature word for XSAVE features, and KVM's CPUID code is relying on the new definition. Except for
cpu_has_xsaves, it's never accessing the feature itself: wrapcpu_has_xsaveswithkvm_cpu_has_xsaves, and then there is no problem with out-of-bounds accesses.Signed-off-by Paolo Bonzini <[email protected]>--- external-module-compat-comm.h | 4 ++++ external-module-compat.c | 11 +++++++++++ sync | 14 ++++++++++++-- x86/external-module-compat.h | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-)
...
x86/external-module-compat.h static inline int rdmsrl_safe(unsigned msr, unsigned long long *p) · line 434
Quoted 12 lines
x86/external-module-compat.h +4
-0@@ -428,6 +428,23 @@ static inline int rdmsrl_safe(unsigned msr, unsigned long long *p)#define X86_FEATURE_MPX (9*32+14)/* Memory Protection Extension */ #endif +#if X86_FEATURE_XSAVEOPT <10 *32 +#undef X86_FEATURE_XSAVEOPT +#endif +#define X86_FEATURE_XSAVEOPT (10*32+0)/* XSAVEOPT instruction */
This causes redefinition warnings if the condition is not met. Was the plan to put the define before the #endif?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Paolo Bonzini
maintainerRe: [PATCH 1/4] stubs for xsavec support
Quoted 6 lines · Jan Kiszka
Quoted 4 lines
x86/external-module-compat.h static inline int rdmsrl_safe(unsigned msr, unsigned long long *p) · line 434
Quoted 4 lines
x86/external-module-compat.h +4
-0+#if X86_FEATURE_XSAVEOPT <10 *32 +#undef X86_FEATURE_XSAVEOPT +#endif +#define X86_FEATURE_XSAVEOPT (10*32+0)/* XSAVEOPT instruction */ This causes redefinition warnings if the condition is not met. Was the plan to put the define before the #endif?
The plan was to match the kernel's definition, which however has a space:
#define X86_FEATURE_XSAVEOPT (10*32+ 0)
But putting the define before the #endif also works.
Paolo
Re: [PATCH 1/4] stubs for xsavec support
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Jan Kiszka
Quoted 4 lines
x86/external-module-compat.h static inline int rdmsrl_safe(unsigned msr, unsigned long long *p) · line 434
Quoted 4 lines
x86/external-module-compat.h +4
-0+#if X86_FEATURE_XSAVEOPT <10 *32 +#undef X86_FEATURE_XSAVEOPT +#endif +#define X86_FEATURE_XSAVEOPT (10*32+0)/* XSAVEOPT instruction */ This causes redefinition warnings if the condition is not met. Was the plan to put the define before the #endif?
Quoted 5 lines
The plan was to match the kernel's definition, which however has a space:
#define
X86_FEATURE_XSAVEOPT(10*32+ 0)But putting the define before the #endif also works.
Finally got my buildbot working again: There are some open issues, maybe you can have a look at http://buildbot.kiszka.org/kvm-kmod/waterfall,
next branch. At least the 3.17 thing requires fixing but may require more than a #define.
Thanks,
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Paolo Bonzini
maintainerRe: [PATCH 1/4] stubs for xsavec support
Quoted 13 lines · Jan Kiszka
Quoted 12 lines · Paolo Bonzini
Quoted 6 lines · Jan Kiszka
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+#if X86_FEATURE_XSAVEOPT < 10 * 32 +#undef X86_FEATURE_XSAVEOPT +#endif +#define X86_FEATURE_XSAVEOPT (10*32+0) /* XSAVEOPT instruction */This causes redefinition warnings if the condition is not met. Was the plan to put the define before the #endif?
The plan was to match the kernel's definition, which however has a space:
Quoted 8 lines
Quoted 3 lines
#define
X86_FEATURE_XSAVEOPT(10*32+ 0)But putting the define before the #endif also works.
Finally got my buildbot working again: There are some open issues, maybe you can have a look at http://buildbot.kiszka.org/kvm-kmod/waterfall,
next branch. At least the 3.17 thing requires fixing but may require more than a #define.
Why is APICv crippled in kvm-kmod even for newer kernels?
If all that's needed is "make it compile with 3.9 and earlier", you can do something like this:
sync +9 -4
@@ -341,13 +341,18 @@ def hack_content(fname, data): if line == '\tif (!cpu_has_vmx_apicv())': w('#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)') w(line) + w('#else') + w('if (1)') line = '#endif' if line == '#if IS_ENABLED(CONFIG_KVM)': line = '#if 1' - if line == '\t\tapic->send_IPI_mask(get_cpu_mask(vcpu->cpu),': - line = '\t\t;' - if line == '\t\t\t\tPOSTED_INTR_VECTOR);': - line = '' + if match(r'^\t+apic->send_IPI_mask\(get_cpu_mask\(vcpu->cpu\),$'): + w('#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)') + w('\t\t;') + w('#else') + if match(r'^\t+POSTED_INTR_VECTOR\);$'): + w(line) + line = '#endif' if line == '\tif (!static_cpu_has_bug(X86_BUG_AMD_TLB_MMATCH))': w('#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)') w(line)
Paolo
Re: [PATCH 1/4] stubs for xsavec support
Quoted 18 lines · Paolo Bonzini
Quoted 15 lines · Jan Kiszka
Quoted 14 lines · Paolo Bonzini
Quoted 6 lines · Jan Kiszka
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+#if X86_FEATURE_XSAVEOPT < 10 * 32 +#undef X86_FEATURE_XSAVEOPT +#endif +#define X86_FEATURE_XSAVEOPT (10*32+0) /* XSAVEOPT instruction */This causes redefinition warnings if the condition is not met. Was the plan to put the define before the #endif?
The plan was to match the kernel's definition, which however has a space:
#define
X86_FEATURE_XSAVEOPT(10*32+ 0)
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
But putting the define before the #endif also works.
Finally got my buildbot working again: There are some open issues, maybe you can have a look at http://buildbot.kiszka.org/kvm-kmod/waterfall,
next branch. At least the 3.17 thing requires fixing but may require more than a #define.Why is APICv crippled in kvm-kmod even for newer kernels?
No idea. Maybe the patcher runs amok? I didn't look into details yet.
Quoted 21 lines
If all that's needed is "make it compile with 3.9 and earlier", you can do something like this:
sync +2
-4@@ -341,13 +341,18 @@ def hack_content(fname, data): if line == '\tif (!cpu_has_vmx_apicv())': w('#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)') w(line) + w('#else') + w('if (1)') line = '#endif' if line == '#if IS_ENABLED(CONFIG_KVM)': line = '#if 1' - if line == '\t\tapic->send_IPI_mask(get_cpu_mask(vcpu->cpu),': - line = '\t\t;' - if line == '\t\t\t\tPOSTED_INTR_VECTOR);': - line = ''
sync def hack_content(fname, data): · line 358
Quoted 10 lines
sync +7
-0+ if match(r'^\t+apic->send_IPI_mask\(get_cpu_mask\(vcpu->cpu\),$'): + w('#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)') + w('\t\t;') + w('#else') + if match(r'^\t+POSTED_INTR_VECTOR\);$'): + w(line) + line = '#endif' if line == '\tif (!static_cpu_has_bug(X86_BUG_AMD_TLB_MMATCH))': w('#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)') w(line)
Tested already? If so, please provide it as patch. If not: I can run it later through buildbot here.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Paolo Bonzini
maintainerRe: [PATCH 1/4] stubs for xsavec support
Quoted 1 line · Jan Kiszka
Tested already? If so, please provide it as patch.
Tested but not with APICv, so it's not really worthy except as a compile check.
Paolo
Quoted 1 line
If not: I can run it later through buildbot here.
Paolo Bonzini
maintainerPATCH 2/4 fixes for changes in the iommu and PCI APIs
In reply to Paolo BonziniThese API changes were introduced in 3.18.
--- external-module-compat-comm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
external-module-compat-comm.h +15 -0
@@ -14,6 +14,7 @@#include <linux/kvm_para.h> #include <linux/kconfig.h> #include <linux/cpu.h> +#include <linux/pci.h> #include <linux/time.h> #include <linux/kernel.h> #include <asm/processor.h>
@@ -1425,6 +1426,20 @@ extern u64 kvm_get_boot_base_ns(struct timekeeper *tk);#undef is_zero_pfn#define is_zero_pfn (pfn) ((pfn) == page_to_pfn(ZERO_PAGE(0))) +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,18 ,0 ) +#define iommu_capable (dummy, cap) \ + iommu_domain_has_cap(kvm->arch.iommu_domain, cap) + +static inline void pci_clear_dev_assigned (struct pci_dev *pdev) +{ + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED ; +} + +static inline void pci_set_dev_assigned (struct pci_dev *pdev) +{ + pdev->dev_flags |=PCI_DEV_FLAGS_ASSIGNED ; +} +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,17 ,0 )void *get_xsave_addr (struct xsave_struct *xsave,int feature);#endif
Signature · 1 line
1.8.3.1
Paolo Bonzini
maintainerPATCH 3/4 fixes for changes in the percpu counter API
In reply to Paolo BonziniThese API changes were introduced in 3.18. Update source pointer since 3.18 now compiles.
--- external-module-compat-comm.h | 9 +++++++++ linux | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-)
external-module-compat-comm.h +9 -0
@@ -1440,6 +1440,15 @@ static inline void pci_set_dev_assigned(struct pci_dev *pdev) pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED; } +#undef percpu_counter_init +#define percpu_counter_init (fbc, value, gfp) \ + ({ \ + static struct lock_class_key __key; \ + \ + __percpu_counter_init(fbc, value, &__key); \ + }) +#endif +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,17 ,0 )void *get_xsave_addr (struct xsave_struct *xsave,int feature);#endif
linux +1 -1
@@ -1 +1 @@ -Subproject commit da01e61428aa2b5c424fddc11178498462d8c77f +Subproject commit b2776bf7149bddd1f4161f14f79520f17fc1d71d
Signature · 1 line
1.8.3.1
Paolo Bonzini
maintainerPATCH 4/4 add trace_seq_buffer_ptr
In reply to Paolo BonziniThese API changes were introduced in 3.19-rc1. Update source pointer since this is the only required change for 3.19-rc1.
--- external-module-compat-comm.h | 4 ++++ linux | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
external-module-compat-comm.h +4 -0
@@ -1452,3 +1452,7 @@ static inline void pci_set_dev_assigned(struct pci_dev *pdev)#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,17 ,0 )void *get_xsave_addr (struct xsave_struct *xsave,int feature);#endif + +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,19 ,0 ) +#define trace_seq_buffer_ptr (p) ((p)->buffer + (p)->len) +#endif
linux +1 -1
@@ -1 +1 @@ -Subproject commit b2776bf7149bddd1f4161f14f79520f17fc1d71d +Subproject commit 97bf6af1f928216fd6c5a66e8a57bfa95a659672
Signature · 1 line
1.8.3.1