Re: [PATCH 4/4] Use kmem cache for allocating vcpus, simplify FPU ops

Avi Kivity
2007-07-30T09:12:07Z

Rusty Russell wrote:
> If we use a kmem cache for allocating vcpus, we can get the 16-byte
> alignment required by fxsave & fxrstor instructions, and avoid
> manually aligning the buffer.
>
>

Please separate the slabification from the fpu cleanups into separate
patches.

> Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
>
> diff -r 39421cbc0486 drivers/kvm/kvm.h
> --- a/drivers/kvm/kvm.h Mon Jul 30 15:01:44 2007 +1000
> +++ b/drivers/kvm/kvm.h Mon Jul 30 15:09:54 2007 +1000
> @@ -43,10 +43,6 @@
> #define KVM_MIN_FREE_MMU_PAGES 5
> #define KVM_REFILL_PAGES 25
> #define KVM_MAX_CPUID_ENTRIES 40
> -
> -#define FX_IMAGE_SIZE 512
> -#define FX_IMAGE_ALIGN 16
> -#define FX_BUF_SIZE (2 * FX_IMAGE_SIZE + FX_IMAGE_ALIGN)
>
> #define DE_VECTOR 0
> #define NM_VECTOR 7
> @@ -339,9 +335,8 @@ struct kvm_vcpu {
>
> struct kvm_guest_debug guest_debug;
>
> - char fx_buf[FX_BUF_SIZE];
> - char *host_fx_image;
> - char *guest_fx_image;
> + struct i387_fxsave_struct host_fx_image;
> + struct i387_fxsave_struct guest_fx_image;
>

So gcc is smart enough to propagate the alignment of i386_fxsave_struct
to its container? Nice.

>
> static int __init svm_init(void)
> {
> - return kvm_init_arch(&svm_arch_ops, THIS_MODULE);
> + int err;
> +
> + /* A kmem cache lets us meet the alignment requirements of fx_save. */
> + svm_kmem_cache = KMEM_CACHE(vcpu_svm, 0);
>

kvm slab caches are prefixed with kvm_; this makes it easy to 'grep kvm
/proc/slabinfo' to see kvm leaks. Please preserve that.

Also, the allocation and destruction can be in common code, reducing the
amount of rarely-executed error paths.

--
error compiling committee.c: too many arguments to function