* [Qemu-devel] [PATCH v3 1/2] qapi: Create DEFINE_PROP_STRING_LEN
2015-10-16 18:53 [Qemu-devel] [PATCH v3 0/2] Enable specifying a non-default Hyper-V vendor ID Alex Williamson
@ 2015-10-16 18:54 ` Alex Williamson
2015-10-16 18:54 ` [Qemu-devel] [PATCH v3 2/2] kvm: Allow the Hyper-V vendor ID to be specified Alex Williamson
2015-10-16 23:06 ` [Qemu-devel] [PATCH v3 0/2] Enable specifying a non-default Hyper-V vendor ID Amos Jianjun Kong
2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2015-10-16 18:54 UTC (permalink / raw)
To: qemu-devel, kvm; +Cc: pbonzini, imammedo
A slight addition to set_string(), which optionally tests that the
string length is within the bounds specified.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/core/qdev-properties.c | 7 +++++++
include/hw/qdev-core.h | 1 +
include/hw/qdev-properties.h | 16 ++++++++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 33e245e..51a05c7 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -422,6 +422,13 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
error_propagate(errp, local_err);
return;
}
+
+ if (prop->strlen >= 0 && strlen(str) > prop->strlen) {
+ error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+ g_free(str);
+ return;
+ }
+
g_free(*ptr);
*ptr = str;
}
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 8057aed..12e3031 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -244,6 +244,7 @@ struct Property {
int arrayoffset;
PropertyInfo *arrayinfo;
int arrayfieldsize;
+ int strlen;
};
struct PropertyInfo {
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 77538a8..2a46640 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -69,6 +69,20 @@ extern PropertyInfo qdev_prop_arraylen;
.qtype = QTYPE_QBOOL, \
.defval = (bool)_defval, \
}
+#define DEFINE_PROP_STRING(_name, _state, _field) { \
+ .name = (_name), \
+ .info = &(qdev_prop_string), \
+ .strlen = -1, \
+ .offset = offsetof(_state, _field) \
+ + type_check(char*, typeof_field(_state, _field)), \
+ }
+#define DEFINE_PROP_STRING_LEN(_name, _state, _field, _strlen) { \
+ .name = (_name), \
+ .info = &(qdev_prop_string), \
+ .strlen = (_strlen), \
+ .offset = offsetof(_state, _field) \
+ + type_check(char*, typeof_field(_state, _field)), \
+ }
#define PROP_ARRAY_LEN_PREFIX "len-"
@@ -144,8 +158,6 @@ extern PropertyInfo qdev_prop_arraylen;
#define DEFINE_PROP_CHR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
-#define DEFINE_PROP_STRING(_n, _s, _f) \
- DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
#define DEFINE_PROP_NETDEV(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
#define DEFINE_PROP_VLAN(_n, _s, _f) \
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v3 2/2] kvm: Allow the Hyper-V vendor ID to be specified
2015-10-16 18:53 [Qemu-devel] [PATCH v3 0/2] Enable specifying a non-default Hyper-V vendor ID Alex Williamson
2015-10-16 18:54 ` [Qemu-devel] [PATCH v3 1/2] qapi: Create DEFINE_PROP_STRING_LEN Alex Williamson
@ 2015-10-16 18:54 ` Alex Williamson
2015-10-16 23:06 ` [Qemu-devel] [PATCH v3 0/2] Enable specifying a non-default Hyper-V vendor ID Amos Jianjun Kong
2 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2015-10-16 18:54 UTC (permalink / raw)
To: qemu-devel, kvm; +Cc: pbonzini, imammedo
According to Microsoft documentation, the signature in the standard
hypervisor CPUID leaf at 0x40000000 identifies the Vendor ID and is
for reporting and diagnostic purposes only. We can therefore allow
the user to change it to whatever they want, within the 12 character
limit. Add a new hyperv-vendor-id option to the -cpu flag to allow
for this, ex:
-cpu host,hv_time,hv_vendor_id=KeenlyKVM
Link: http://msdn.microsoft.com/library/windows/hardware/hh975392
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
target-i386/cpu-qom.h | 1 +
target-i386/cpu.c | 1 +
target-i386/kvm.c | 8 +++++++-
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index c35b624..6c1eaaa 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -88,6 +88,7 @@ typedef struct X86CPU {
bool hyperv_vapic;
bool hyperv_relaxed_timing;
int hyperv_spinlock_attempts;
+ char *hyperv_vendor_id;
bool hyperv_time;
bool hyperv_crash;
bool check_cpuid;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 05d7f26..f9304ea 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3146,6 +3146,7 @@ static Property x86_cpu_properties[] = {
DEFINE_PROP_UINT32("level", X86CPU, env.cpuid_level, 0),
DEFINE_PROP_UINT32("xlevel", X86CPU, env.cpuid_xlevel, 0),
DEFINE_PROP_UINT32("xlevel2", X86CPU, env.cpuid_xlevel2, 0),
+ DEFINE_PROP_STRING_LEN("hv-vendor-id", X86CPU, hyperv_vendor_id, 12),
DEFINE_PROP_END_OF_LIST()
};
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 80d1a7e..c4108ab 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -490,7 +490,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
if (hyperv_enabled(cpu)) {
c = &cpuid_data.entries[cpuid_i++];
c->function = HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
- memcpy(signature, "Microsoft Hv", 12);
+ if (!cpu->hyperv_vendor_id) {
+ memcpy(signature, "Microsoft Hv", 12);
+ } else {
+ memset(signature, 0, 12);
+ memcpy(signature, cpu->hyperv_vendor_id,
+ strlen(cpu->hyperv_vendor_id));
+ }
c->eax = HYPERV_CPUID_MIN;
c->ebx = signature[0];
c->ecx = signature[1];
^ permalink raw reply related [flat|nested] 4+ messages in thread