Commit 0ee75bead83da4791e5cbf659806c54d8ee40f12
1 parent
884a0ff0b6
Exists in
master
and in
7 other branches
KVM: Let vcpu structure alignment be determined at runtime
vmx and svm vcpus have different contents and therefore may have different alignmment requirements. Let each specify its required alignment. Signed-off-by: Avi Kivity <avi@redhat.com>
Showing 9 changed files with 14 additions and 11 deletions Side-by-side Diff
arch/ia64/kvm/vmm.c
arch/powerpc/kvm/44x.c
arch/powerpc/kvm/book3s.c
| ... | ... | @@ -1385,7 +1385,8 @@ |
| 1385 | 1385 | |
| 1386 | 1386 | static int kvmppc_book3s_init(void) |
| 1387 | 1387 | { |
| 1388 | - return kvm_init(NULL, sizeof(struct kvmppc_vcpu_book3s), THIS_MODULE); | |
| 1388 | + return kvm_init(NULL, sizeof(struct kvmppc_vcpu_book3s), 0, | |
| 1389 | + THIS_MODULE); | |
| 1389 | 1390 | } |
| 1390 | 1391 | |
| 1391 | 1392 | static void kvmppc_book3s_exit(void) |
arch/powerpc/kvm/e500.c
| ... | ... | @@ -161,7 +161,7 @@ |
| 161 | 161 | flush_icache_range(kvmppc_booke_handlers, |
| 162 | 162 | kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); |
| 163 | 163 | |
| 164 | - return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), THIS_MODULE); | |
| 164 | + return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), 0, THIS_MODULE); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | static void __init kvmppc_e500_exit(void) |
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
| ... | ... | @@ -4245,7 +4245,8 @@ |
| 4245 | 4245 | |
| 4246 | 4246 | set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */ |
| 4247 | 4247 | |
| 4248 | - r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE); | |
| 4248 | + r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), | |
| 4249 | + __alignof__(struct vcpu_vmx), THIS_MODULE); | |
| 4249 | 4250 | if (r) |
| 4250 | 4251 | goto out3; |
| 4251 | 4252 |
include/linux/kvm_host.h
| ... | ... | @@ -243,7 +243,7 @@ |
| 243 | 243 | void vcpu_load(struct kvm_vcpu *vcpu); |
| 244 | 244 | void vcpu_put(struct kvm_vcpu *vcpu); |
| 245 | 245 | |
| 246 | -int kvm_init(void *opaque, unsigned int vcpu_size, | |
| 246 | +int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, | |
| 247 | 247 | struct module *module); |
| 248 | 248 | void kvm_exit(void); |
| 249 | 249 |
virt/kvm/kvm_main.c
| ... | ... | @@ -2178,7 +2178,7 @@ |
| 2178 | 2178 | kvm_arch_vcpu_put(vcpu); |
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | -int kvm_init(void *opaque, unsigned int vcpu_size, | |
| 2181 | +int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, | |
| 2182 | 2182 | struct module *module) |
| 2183 | 2183 | { |
| 2184 | 2184 | int r; |
| ... | ... | @@ -2228,8 +2228,9 @@ |
| 2228 | 2228 | goto out_free_4; |
| 2229 | 2229 | |
| 2230 | 2230 | /* A kmem cache lets us meet the alignment requirements of fx_save. */ |
| 2231 | - kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, | |
| 2232 | - __alignof__(struct kvm_vcpu), | |
| 2231 | + if (!vcpu_align) | |
| 2232 | + vcpu_align = __alignof__(struct kvm_vcpu); | |
| 2233 | + kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align, | |
| 2233 | 2234 | 0, NULL); |
| 2234 | 2235 | if (!kvm_vcpu_cache) { |
| 2235 | 2236 | r = -ENOMEM; |