Message ID | 1397494110-5756-3-git-send-email-cornelia.huck@de.ibm.com |
---|---|
State | New |
Headers | show |
On 14.04.14 18:48, Cornelia Huck wrote: > Provide helper functions for enabling capabilities (on a vcpu and on a vm). > > Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> > --- > include/sysemu/kvm.h | 4 ++++ > kvm-all.c | 33 ++++++++++++++++++++++++++++++++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h > index 0bee1e8..2ff5ad3 100644 > --- a/include/sysemu/kvm.h > +++ b/include/sysemu/kvm.h > @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); > > int kvm_check_extension(KVMState *s, unsigned int extension); > > +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); > + > +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); > + > uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, > uint32_t index, int reg); > > diff --git a/kvm-all.c b/kvm-all.c > index cd4111d..658e50c 100644 > --- a/kvm-all.c > +++ b/kvm-all.c > @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) > return ret; > } > > -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, > +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) > +{ > + struct kvm_enable_cap cap = {}; > + va_list ap; > + int i; > + > + cap.cap = capability; > + va_start(ap, capability); > + for (i = 0; i < 4; i++) { > + cap.args[i] = va_arg(ap, uint64_t); Is this legit? Can we just pull items off the stack without running beyond? Alex > + } > + va_end(ap); > + return kvm_vm_ioctl(s, KVM_ENABLE_CAP, &cap); > +} > + > +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...) > +{ > + struct kvm_enable_cap cap = {}; > + va_list ap; > + int i; > + > + cap.cap = capability; > + va_start(ap, capability); > + for (i = 0; i < 4; i++) { > + cap.args[i] = va_arg(ap, uint64_t); > + } > + va_end(ap); > + return kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap); > +} > + > + > +static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, > bool assign, uint32_t size, bool datamatch) > { > int ret;
On 16.04.2014, at 13:22, Alexander Graf <agraf@suse.de> wrote: > > On 14.04.14 18:48, Cornelia Huck wrote: >> Provide helper functions for enabling capabilities (on a vcpu and on a vm). >> >> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> >> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> >> --- >> include/sysemu/kvm.h | 4 ++++ >> kvm-all.c | 33 ++++++++++++++++++++++++++++++++- >> 2 files changed, 36 insertions(+), 1 deletion(-) >> >> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h >> index 0bee1e8..2ff5ad3 100644 >> --- a/include/sysemu/kvm.h >> +++ b/include/sysemu/kvm.h >> @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); >> int kvm_check_extension(KVMState *s, unsigned int extension); >> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); >> + >> +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); >> + >> uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, >> uint32_t index, int reg); >> diff --git a/kvm-all.c b/kvm-all.c >> index cd4111d..658e50c 100644 >> --- a/kvm-all.c >> +++ b/kvm-all.c >> @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) >> return ret; >> } >> -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, >> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) >> +{ >> + struct kvm_enable_cap cap = {}; >> + va_list ap; >> + int i; >> + >> + cap.cap = capability; >> + va_start(ap, capability); >> + for (i = 0; i < 4; i++) { >> + cap.args[i] = va_arg(ap, uint64_t); > > Is this legit? Can we just pull items off the stack without running beyond? For inspiration on how to know the number of arguments that got passed in, check out http://git.qemu.org/?p=qemu.git;a=blob;f=include/sysemu/device_tree.h#l40 Alex
On Wed, 16 Apr 2014 13:38:27 +0200 Alexander Graf <agraf@suse.de> wrote: > > On 16.04.2014, at 13:22, Alexander Graf <agraf@suse.de> wrote: > > > > > On 14.04.14 18:48, Cornelia Huck wrote: > >> Provide helper functions for enabling capabilities (on a vcpu and on a vm). > >> > >> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> > >> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> > >> --- > >> include/sysemu/kvm.h | 4 ++++ > >> kvm-all.c | 33 ++++++++++++++++++++++++++++++++- > >> 2 files changed, 36 insertions(+), 1 deletion(-) > >> > >> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h > >> index 0bee1e8..2ff5ad3 100644 > >> --- a/include/sysemu/kvm.h > >> +++ b/include/sysemu/kvm.h > >> @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); > >> int kvm_check_extension(KVMState *s, unsigned int extension); > >> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); > >> + > >> +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); > >> + > >> uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, > >> uint32_t index, int reg); > >> diff --git a/kvm-all.c b/kvm-all.c > >> index cd4111d..658e50c 100644 > >> --- a/kvm-all.c > >> +++ b/kvm-all.c > >> @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) > >> return ret; > >> } > >> -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, > >> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) > >> +{ > >> + struct kvm_enable_cap cap = {}; > >> + va_list ap; > >> + int i; > >> + > >> + cap.cap = capability; > >> + va_start(ap, capability); > >> + for (i = 0; i < 4; i++) { > >> + cap.args[i] = va_arg(ap, uint64_t); > > > > Is this legit? Can we just pull items off the stack without running beyond? > > For inspiration on how to know the number of arguments that got passed in, check out > > http://git.qemu.org/?p=qemu.git;a=blob;f=include/sysemu/device_tree.h#l40 Ah, that is probably better than splattering args with random stuff. Will try.
On Wed, 16 Apr 2014 13:58:31 +0200 Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > On Wed, 16 Apr 2014 13:38:27 +0200 > Alexander Graf <agraf@suse.de> wrote: > > > > > On 16.04.2014, at 13:22, Alexander Graf <agraf@suse.de> wrote: > > > > > > > > On 14.04.14 18:48, Cornelia Huck wrote: > > >> Provide helper functions for enabling capabilities (on a vcpu and on a vm). > > >> > > >> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> > > >> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> > > >> --- > > >> include/sysemu/kvm.h | 4 ++++ > > >> kvm-all.c | 33 ++++++++++++++++++++++++++++++++- > > >> 2 files changed, 36 insertions(+), 1 deletion(-) > > >> > > >> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h > > >> index 0bee1e8..2ff5ad3 100644 > > >> --- a/include/sysemu/kvm.h > > >> +++ b/include/sysemu/kvm.h > > >> @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); > > >> int kvm_check_extension(KVMState *s, unsigned int extension); > > >> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); > > >> + > > >> +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); > > >> + > > >> uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, > > >> uint32_t index, int reg); > > >> diff --git a/kvm-all.c b/kvm-all.c > > >> index cd4111d..658e50c 100644 > > >> --- a/kvm-all.c > > >> +++ b/kvm-all.c > > >> @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) > > >> return ret; > > >> } > > >> -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, > > >> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) > > >> +{ > > >> + struct kvm_enable_cap cap = {}; > > >> + va_list ap; > > >> + int i; > > >> + > > >> + cap.cap = capability; > > >> + va_start(ap, capability); > > >> + for (i = 0; i < 4; i++) { > > >> + cap.args[i] = va_arg(ap, uint64_t); > > > > > > Is this legit? Can we just pull items off the stack without running beyond? > > > > For inspiration on how to know the number of arguments that got passed in, check out > > > > http://git.qemu.org/?p=qemu.git;a=blob;f=include/sysemu/device_tree.h#l40 > > Ah, that is probably better than splattering args with random stuff. > Will try. > Huh, how does <integer type> array[] = { __VA_ARGS__ }; even compile? On both i386 and s390, I get "initialization makes integer from pointer without a cast" - is arm different?
On 16.04.14 16:25, Cornelia Huck wrote: > On Wed, 16 Apr 2014 13:58:31 +0200 > Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > >> On Wed, 16 Apr 2014 13:38:27 +0200 >> Alexander Graf <agraf@suse.de> wrote: >> >>> On 16.04.2014, at 13:22, Alexander Graf <agraf@suse.de> wrote: >>> >>>> On 14.04.14 18:48, Cornelia Huck wrote: >>>>> Provide helper functions for enabling capabilities (on a vcpu and on a vm). >>>>> >>>>> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> >>>>> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> >>>>> --- >>>>> include/sysemu/kvm.h | 4 ++++ >>>>> kvm-all.c | 33 ++++++++++++++++++++++++++++++++- >>>>> 2 files changed, 36 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h >>>>> index 0bee1e8..2ff5ad3 100644 >>>>> --- a/include/sysemu/kvm.h >>>>> +++ b/include/sysemu/kvm.h >>>>> @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); >>>>> int kvm_check_extension(KVMState *s, unsigned int extension); >>>>> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); >>>>> + >>>>> +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); >>>>> + >>>>> uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, >>>>> uint32_t index, int reg); >>>>> diff --git a/kvm-all.c b/kvm-all.c >>>>> index cd4111d..658e50c 100644 >>>>> --- a/kvm-all.c >>>>> +++ b/kvm-all.c >>>>> @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) >>>>> return ret; >>>>> } >>>>> -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, >>>>> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) >>>>> +{ >>>>> + struct kvm_enable_cap cap = {}; >>>>> + va_list ap; >>>>> + int i; >>>>> + >>>>> + cap.cap = capability; >>>>> + va_start(ap, capability); >>>>> + for (i = 0; i < 4; i++) { >>>>> + cap.args[i] = va_arg(ap, uint64_t); >>>> Is this legit? Can we just pull items off the stack without running beyond? >>> For inspiration on how to know the number of arguments that got passed in, check out >>> >>> http://git.qemu.org/?p=qemu.git;a=blob;f=include/sysemu/device_tree.h#l40 >> Ah, that is probably better than splattering args with random stuff. >> Will try. >> > Huh, how does > > <integer type> array[] = { __VA_ARGS__ }; > > even compile? On both i386 and s390, I get "initialization makes > integer from pointer without a cast" - is arm different? This only works when used inside a #define, since then the preprocessor resolves __VA_ARGS__ :). Alex
On Wed, 16 Apr 2014 16:26:30 +0200 Alexander Graf <agraf@suse.de> wrote: > > On 16.04.14 16:25, Cornelia Huck wrote: > > On Wed, 16 Apr 2014 13:58:31 +0200 > > Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > > > >> On Wed, 16 Apr 2014 13:38:27 +0200 > >> Alexander Graf <agraf@suse.de> wrote: > >> > >>> On 16.04.2014, at 13:22, Alexander Graf <agraf@suse.de> wrote: > >>> > >>>> On 14.04.14 18:48, Cornelia Huck wrote: > >>>>> Provide helper functions for enabling capabilities (on a vcpu and on a vm). > >>>>> > >>>>> Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com> > >>>>> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> > >>>>> --- > >>>>> include/sysemu/kvm.h | 4 ++++ > >>>>> kvm-all.c | 33 ++++++++++++++++++++++++++++++++- > >>>>> 2 files changed, 36 insertions(+), 1 deletion(-) > >>>>> > >>>>> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h > >>>>> index 0bee1e8..2ff5ad3 100644 > >>>>> --- a/include/sysemu/kvm.h > >>>>> +++ b/include/sysemu/kvm.h > >>>>> @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); > >>>>> int kvm_check_extension(KVMState *s, unsigned int extension); > >>>>> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); > >>>>> + > >>>>> +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); > >>>>> + > >>>>> uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, > >>>>> uint32_t index, int reg); > >>>>> diff --git a/kvm-all.c b/kvm-all.c > >>>>> index cd4111d..658e50c 100644 > >>>>> --- a/kvm-all.c > >>>>> +++ b/kvm-all.c > >>>>> @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) > >>>>> return ret; > >>>>> } > >>>>> -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, > >>>>> +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) > >>>>> +{ > >>>>> + struct kvm_enable_cap cap = {}; > >>>>> + va_list ap; > >>>>> + int i; > >>>>> + > >>>>> + cap.cap = capability; > >>>>> + va_start(ap, capability); > >>>>> + for (i = 0; i < 4; i++) { > >>>>> + cap.args[i] = va_arg(ap, uint64_t); > >>>> Is this legit? Can we just pull items off the stack without running beyond? > >>> For inspiration on how to know the number of arguments that got passed in, check out > >>> > >>> http://git.qemu.org/?p=qemu.git;a=blob;f=include/sysemu/device_tree.h#l40 > >> Ah, that is probably better than splattering args with random stuff. > >> Will try. > >> > > Huh, how does > > > > <integer type> array[] = { __VA_ARGS__ }; > > > > even compile? On both i386 and s390, I get "initialization makes > > integer from pointer without a cast" - is arm different? > > This only works when used inside a #define, since then the preprocessor > resolves __VA_ARGS__ :). Obviously. That's where I got the error :)
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 0bee1e8..2ff5ad3 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -294,6 +294,10 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu); int kvm_check_extension(KVMState *s, unsigned int extension); +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...); + +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...); + uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, uint32_t index, int reg); diff --git a/kvm-all.c b/kvm-all.c index cd4111d..658e50c 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -501,7 +501,38 @@ int kvm_check_extension(KVMState *s, unsigned int extension) return ret; } -static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val, +int kvm_enable_cap_vm(KVMState *s, unsigned int capability, ...) +{ + struct kvm_enable_cap cap = {}; + va_list ap; + int i; + + cap.cap = capability; + va_start(ap, capability); + for (i = 0; i < 4; i++) { + cap.args[i] = va_arg(ap, uint64_t); + } + va_end(ap); + return kvm_vm_ioctl(s, KVM_ENABLE_CAP, &cap); +} + +int kvm_enable_cap_vcpu(CPUState *cpu, unsigned int capability, ...) +{ + struct kvm_enable_cap cap = {}; + va_list ap; + int i; + + cap.cap = capability; + va_start(ap, capability); + for (i = 0; i < 4; i++) { + cap.args[i] = va_arg(ap, uint64_t); + } + va_end(ap); + return kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap); +} + + +static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, bool assign, uint32_t size, bool datamatch) { int ret;