spapr: add uuid/host details to device tree
PATCH v4 1/1 spapr: add uuid/host details to device tree
Useful for identifying the guest/host uniquely within the guest. Adding following properties to the guest root node.
vm,uuid - uuid of the guest
host-model - Host model number
host-serial - Host machine serial number
hypervisor type - Tells its "kvm"
---
v4: make uuid as human readable
v3: rebase to ppcnext
v2: indentation fixes
--- hw/ppc/spapr.c | 25 +++++++++++++++++++++++++ target-ppc/kvm.c | 44 +++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +25 -0
@@ -318,6 +318,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,QemuOpts *opts =qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL );unsigned sockets = opts ?qemu_opt_get_number (opts,"sockets" ,0 ) :0 ;uint32_t cpus_per_socket = sockets ? (smp_cpus / sockets) :1 ; +char char_buf[512 ];add_str (hypertas,"hcall-pft" );add_str (hypertas,"hcall-term" );
@@ -347,6 +348,30 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,_FDT ((fdt_property_string (fdt,"model" ,"IBM pSeries (emulated by qemu)" )));_FDT ((fdt_property_string (fdt,"compatible" ,"qemu,pseries" ))); +if (kvm_enabled ()) { +_FDT ((fdt_property_string (fdt,"hypervisor" ,"kvm" ))); + } + +/* +* Add info to guest to indentify which host is it being run on +* and what is the uuid of the guest +*/ +memset (char_buf,0 ,sizeof (char_buf)); +if (!kvmppc_get_host_model (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-model" , char_buf))); +memset (char_buf,0 ,sizeof (char_buf)); + } +if (!kvmppc_get_host_serial (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-serial" , char_buf))); + } + +snprintf (char_buf,37 ,UUID_FMT , qemu_uuid[0 ], qemu_uuid[1 ], + qemu_uuid[2 ], qemu_uuid[3 ], qemu_uuid[4 ], qemu_uuid[5 ], + qemu_uuid[6 ], qemu_uuid[7 ], qemu_uuid[8 ], qemu_uuid[9 ], + qemu_uuid[10 ], qemu_uuid[11 ], qemu_uuid[12 ], qemu_uuid[13 ], + qemu_uuid[14 ], qemu_uuid[15 ]); +_FDT ((fdt_property_string (fdt,"vm,uuid" , char_buf))); +_FDT ((fdt_property_cell (fdt,"#address-cells" ,0x2 )));_FDT ((fdt_property_cell (fdt,"#size-cells" ,0x2 )));
target-ppc/kvm.c +43 -1
56 lines not on this page · raw message
target-ppc/kvm_ppc.h +12 -0
@@ -19,6 +19,8 @@ uint32_t kvmppc_get_tbfreq(void);uint64_t kvmppc_get_clockfreq (void );uint32_t kvmppc_get_vmx (void );uint32_t kvmppc_get_dfp (void ); +int32_t kvmppc_get_host_model (char *buf,int buf_len); +int32_t kvmppc_get_host_serial (char *buf,int buf_len);int kvmppc_get_hasidle (CPUPPCState *env);int kvmppc_get_hypercall (CPUPPCState *env,uint8_t *buf,int buf_len);int kvmppc_set_interrupt (PowerPCCPU *cpu,int irq,int level);
@@ -60,6 +62,16 @@ static inline uint32_t kvmppc_get_tbfreq(void)return 0 ; } +static inline int32_t kvmppc_get_host_model (char *buf,int buf_len) +{ +return 0 ; +} + +static inline int32_t kvmppc_get_host_serial (char *buf,int buf_len) +{ +return 0 ; +} +static inline uint64_t kvmppc_get_clockfreq (void ) {return 0 ;
Signature · 1 line
1.8.3.1
Quoted 25 lines · Nikunj A Dadhania
Useful for identifying the guest/host uniquely within the guest. Adding following properties to the guest root node.
vm,uuid - uuid of the guest
host-model - Host model number
host-serial - Host machine serial number
hypervisor type - Tells its "kvm"Signed-off-by Nikunj A Dadhania <[email protected]>---
v4: make uuid as human readable
v3: rebase to ppcnext
v2: indentation fixes--- hw/ppc/spapr.c | 25 +++++++++++++++++++++++++ target-ppc/kvm.c | 44 +++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 321
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -318,6 +318,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,QemuOpts *opts =qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL );unsigned sockets = opts ?qemu_opt_get_number (opts,"sockets" ,0 ) :0 ;uint32_t cpus_per_socket = sockets ? (smp_cpus / sockets) :1 ; +char char_buf[512 ];
Can't you just return callee allocated, caller free'd memory?
Quoted 13 lines
hw/ppc/spapr.c +6
-0add_str (hypertas,"hcall-pft" );add_str (hypertas,"hcall-term" );@@ -347,6 +348,30 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,_FDT ((fdt_property_string (fdt,"model" ,"IBM pSeries (emulated by qemu)" )));_FDT ((fdt_property_string (fdt,"compatible" ,"qemu,pseries" ))); +if (kvm_enabled ()) { +_FDT ((fdt_property_string (fdt,"hypervisor" ,"kvm" ))); + } + +/* +* Add info to guest to indentify which host is it being run on
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 366
Quoted 10 lines
hw/ppc/spapr.c +10
-0+* and what is the uuid of the guest +*/ +memset (char_buf,0 ,sizeof (char_buf)); +if (!kvmppc_get_host_model (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-model" , char_buf))); +memset (char_buf,0 ,sizeof (char_buf)); + } +if (!kvmppc_get_host_serial (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-serial" , char_buf))); + }
Please be aware that all of the above is bogus when you start thinking about live migration.
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 368
Quoted 2 lines
hw/ppc/spapr.c +2
-0+ + snprintf(char_buf, 37, UUID_FMT, qemu_uuid[0], qemu_uuid[1],
g_strdup_printf()
Quoted 30 lines
hw/ppc/spapr.c +6
-0+ qemu_uuid[2 ], qemu_uuid[3 ], qemu_uuid[4 ], qemu_uuid[5 ], + qemu_uuid[6 ], qemu_uuid[7 ], qemu_uuid[8 ], qemu_uuid[9 ], + qemu_uuid[10 ], qemu_uuid[11 ], qemu_uuid[12 ], qemu_uuid[13 ], + qemu_uuid[14], qemu_uuid[15]); +_FDT ((fdt_property_string (fdt,"vm,uuid" , char_buf))); +_FDT ((fdt_property_cell (fdt,"#address-cells" ,0x2 )));_FDT ((fdt_property_cell (fdt,"#size-cells" ,0x2 )));target-ppc/kvm.c +5
-1@@ -1369,7 +1369,7 @@ static int read_cpuinfo(const char *field, char *value, int len) } do { - if(!fgets(line, sizeof(line), f)) { + if (!fgets(line, sizeof(line), f)) { break; } if (!strncmp(line, field, field_len)) {@@ -1404,6 +1404,48 @@ uint32_t kvmppc_get_tbfreq(void)return retval; } +int32_t kvmppc_get_host_serial (char *value,int len) +{ +FILE *f; +int ret =-1 ;
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1420
Quoted 10 lines
target-ppc/kvm.c +10
-0+char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/system-id" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);
Why IBM,<system-id>?
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1425
Quoted 5 lines
target-ppc/kvm.c +5
-0+ ret =0 ; + } +fclose (f); + +return ret;
I think it makes sense to extract the "read a full file into a buffer" logic into a separate function. For bonus points, find a glib function that already does it and use that ;).
Quoted 6 lines
target-ppc/kvm.c +6
-0+} + +int32_t kvmppc_get_host_model (char *value,int len) +{ +FILE *f; +int ret =-1 ;
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1441
Quoted 10 lines
target-ppc/kvm.c +10
-0+char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/model" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);
Same here - wouldn't this be IBM,IBM,foo?
Alex
Quoted 40 lines
target-ppc/kvm.c +7
-0+ ret =0 ; + } +fclose (f); + +return ret; +} +/* Try to find a device tree node for a CPU with clock-frequency property */ static int kvmppc_find_cpu_dt (char *buf,int buf_len) {target-ppc/kvm_ppc.h +12
-0@@ -19,6 +19,8 @@ uint32_t kvmppc_get_tbfreq(void);uint64_t kvmppc_get_clockfreq (void );uint32_t kvmppc_get_vmx (void );uint32_t kvmppc_get_dfp (void ); +int32_t kvmppc_get_host_model (char *buf,int buf_len); +int32_t kvmppc_get_host_serial (char *buf,int buf_len);int kvmppc_get_hasidle (CPUPPCState *env);int kvmppc_get_hypercall (CPUPPCState *env,uint8_t *buf,int buf_len);int kvmppc_set_interrupt (PowerPCCPU *cpu,int irq,int level);@@ -60,6 +62,16 @@ static inline uint32_t kvmppc_get_tbfreq(void)return 0 ; } +static inline int32_t kvmppc_get_host_model (char *buf,int buf_len) +{ +return 0 ; +} + +static inline int32_t kvmppc_get_host_serial (char *buf,int buf_len) +{ +return 0 ; +} +static inline uint64_t kvmppc_get_clockfreq (void ) {return 0 ;
Quoted 3 lines · Alexander Graf
Please be aware that all of the above is bogus when you start thinking
about live migration.
What's probably where we need to start thinking about implementing migration according to PAPR :-)
IE. With pre and post-migration notifications to the guest including device-tree updates.
Cheers,
Ben.
Quoted 21 lines · Alexander Graf
Quoted 20 lines · Nikunj A Dadhania
Useful for identifying the guest/host uniquely within the guest. Adding following properties to the guest root node.
vm,uuid - uuid of the guest
host-model - Host model number
host-serial - Host machine serial number
hypervisor type - Tells its "kvm"Signed-off-by Nikunj A Dadhania <[email protected]>---
v4: make uuid as human readable
v3: rebase to ppcnext
v2: indentation fixes--- hw/ppc/spapr.c | 25 +++++++++++++++++++++++++ target-ppc/kvm.c | 44 +++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)
Quoted 11 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 321
Quoted 9 lines
hw/ppc/spapr.c +1
-0@@ -318,6 +318,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,QemuOpts *opts =qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL );unsigned sockets = opts ?qemu_opt_get_number (opts,"sockets" ,0 ) :0 ;uint32_t cpus_per_socket = sockets ? (smp_cpus / sockets) :1 ; +char char_buf[512 ];Can't you just return callee allocated, caller free'd memory?
Tried doing it more in line of read_cpuinfo in target-ppc/kvm.c I could do it either ways.
Quoted 19 lines
Quoted 19 lines
hw/ppc/spapr.c +11
-0add_str (hypertas,"hcall-pft" );add_str (hypertas,"hcall-term" );@@ -347,6 +348,30 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,_FDT ((fdt_property_string (fdt,"model" ,"IBM pSeries (emulated by qemu)" )));_FDT ((fdt_property_string (fdt,"compatible" ,"qemu,pseries" ))); +if (kvm_enabled ()) { +_FDT ((fdt_property_string (fdt,"hypervisor" ,"kvm" ))); + } + +/* +* Add info to guest to indentify which host is it being run on +* and what is the uuid of the guest +*/ +memset (char_buf,0 ,sizeof (char_buf)); +if (!kvmppc_get_host_model (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-model" , char_buf)));
Quoted 8 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 366
Quoted 5 lines
hw/ppc/spapr.c +5
-0+memset (char_buf,0 ,sizeof (char_buf)); + } +if (!kvmppc_get_host_serial (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-serial" , char_buf))); + }Please be aware that all of the above is bogus when you start thinking about live migration.
Yes, there are tools that look at these. Is there a way to update these on migration?
Quoted 5 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 368
Quoted 3 lines
hw/ppc/spapr.c +2
-0+ + snprintf(char_buf, 37, UUID_FMT, qemu_uuid[0], qemu_uuid[1],
g_strdup_printf()
Ok.
Quoted 27 lines
Quoted 27 lines
hw/ppc/spapr.c +6
-0+ qemu_uuid[2 ], qemu_uuid[3 ], qemu_uuid[4 ], qemu_uuid[5 ], + qemu_uuid[6 ], qemu_uuid[7 ], qemu_uuid[8 ], qemu_uuid[9 ], + qemu_uuid[10 ], qemu_uuid[11 ], qemu_uuid[12 ], qemu_uuid[13 ], + qemu_uuid[14], qemu_uuid[15]); +_FDT ((fdt_property_string (fdt,"vm,uuid" , char_buf))); +_FDT ((fdt_property_cell (fdt,"#address-cells" ,0x2 )));_FDT ((fdt_property_cell (fdt,"#size-cells" ,0x2 )));target-ppc/kvm.c +1
-1@@ -1369,7 +1369,7 @@ static int read_cpuinfo(const char *field, char *value, int len) } do { - if(!fgets(line, sizeof(line), f)) { + if (!fgets(line, sizeof(line), f)) { break; } if (!strncmp(line, field, field_len)) {@@ -1404,6 +1404,48 @@ uint32_t kvmppc_get_tbfreq(void)return retval; }
Quoted 16 lines
Quoted 4 lines
target-ppc/kvm.c +4
-0+int32_t kvmppc_get_host_serial (char *value,int len) +{ +FILE *f; +int ret =-1 ;target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1420
Quoted 10 lines
target-ppc/kvm.c +10
-0+char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/system-id" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);Why IBM,<system-id>?
There were userspace tools that looking at lparcfg, and were encoded similarly.
Quoted 10 lines
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1425
Quoted 6 lines
target-ppc/kvm.c +5
-0+ ret =0 ; + } +fclose (f); + +return ret;I think it makes sense to extract the "read a full file into a buffer" logic into a separate function. For bonus points, find a glib function that already does it and use that ;).
Let me search.
Quoted 11 lines
Quoted 11 lines
target-ppc/kvm.c +10
-0+} + +int32_t kvmppc_get_host_model (char *value,int len) +{ +FILE *f; +int ret =-1 ; +char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/model" ,"r" );
Quoted 8 lines
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1420
Quoted 6 lines
target-ppc/kvm.c +6
-0+if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);Same here - wouldn't this be IBM,IBM,foo?
No, it will be IBM,<model>
Regards
Nikunj
Quoted 33 lines · Nikunj A Dadhania
Quoted 21 lines · Alexander Graf
Quoted 20 lines · Nikunj A Dadhania
Useful for identifying the guest/host uniquely within the guest. Adding following properties to the guest root node.
vm,uuid - uuid of the guest
host-model - Host model number
host-serial - Host machine serial number
hypervisor type - Tells its "kvm"Signed-off-by Nikunj A Dadhania <[email protected]>---
v4: make uuid as human readable
v3: rebase to ppcnext
v2: indentation fixes--- hw/ppc/spapr.c | 25 +++++++++++++++++++++++++ target-ppc/kvm.c | 44 +++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)Quoted 10 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 321
Quoted 9 lines
hw/ppc/spapr.c +1
-0@@ -318,6 +318,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,QemuOpts *opts =qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL );unsigned sockets = opts ?qemu_opt_get_number (opts,"sockets" ,0 ) :0 ;uint32_t cpus_per_socket = sockets ? (smp_cpus / sockets) :1 ; +char char_buf[512 ];Can't you just return callee allocated, caller free'd memory?
Quoted 2 lines
Tried doing it more in line of
read_cpuinfointarget-ppc/kvm.cI could do it either ways.
Yeah, feel free to convert that one too if you like ;).
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
hw/ppc/spapr.c +10
-0add_str (hypertas,"hcall-pft" );add_str (hypertas,"hcall-term" );@@ -347,6 +348,30 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,_FDT ((fdt_property_string (fdt,"model" ,"IBM pSeries (emulated by qemu)" )));_FDT ((fdt_property_string (fdt,"compatible" ,"qemu,pseries" ))); +if (kvm_enabled ()) { +_FDT ((fdt_property_string (fdt,"hypervisor" ,"kvm" ))); + } + +/* +* Add info to guest to indentify which host is it being run on +* and what is the uuid of the guest +*/ +memset (char_buf,0 ,sizeof (char_buf)); +if (!kvmppc_get_host_model (char_buf,sizeof (char_buf))) {Quoted 8 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 366
Quoted 6 lines
hw/ppc/spapr.c +6
-0+_FDT ((fdt_property_string (fdt,"host-model" , char_buf))); +memset (char_buf,0 ,sizeof (char_buf)); + } +if (!kvmppc_get_host_serial (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-serial" , char_buf))); + }Please be aware that all of the above is bogus when you start thinking about live migration.
Quoted 2 lines
Yes, there are tools that look at these. Is there a way to update these on migration?
As Ben already mentioned ;).
Quoted 47 lines
Quoted 4 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 368
Quoted 3 lines
hw/ppc/spapr.c +2
-0+ + snprintf(char_buf, 37, UUID_FMT, qemu_uuid[0], qemu_uuid[1],
g_strdup_printf()Ok.
Quoted 26 lines
Quoted 26 lines
hw/ppc/spapr.c +6
-0+ qemu_uuid[2 ], qemu_uuid[3 ], qemu_uuid[4 ], qemu_uuid[5 ], + qemu_uuid[6 ], qemu_uuid[7 ], qemu_uuid[8 ], qemu_uuid[9 ], + qemu_uuid[10 ], qemu_uuid[11 ], qemu_uuid[12 ], qemu_uuid[13 ], + qemu_uuid[14], qemu_uuid[15]); +_FDT ((fdt_property_string (fdt,"vm,uuid" , char_buf))); +_FDT ((fdt_property_cell (fdt,"#address-cells" ,0x2 )));_FDT ((fdt_property_cell (fdt,"#size-cells" ,0x2 )));target-ppc/kvm.c +1
-1@@ -1369,7 +1369,7 @@ static int read_cpuinfo(const char *field, char *value, int len) } do { - if(!fgets(line, sizeof(line), f)) { + if (!fgets(line, sizeof(line), f)) { break; } if (!strncmp(line, field, field_len)) {@@ -1404,6 +1404,48 @@ uint32_t kvmppc_get_tbfreq(void)return retval; }Quoted 15 lines
Quoted 4 lines
target-ppc/kvm.c +4
-0+int32_t kvmppc_get_host_serial (char *value,int len) +{ +FILE *f; +int ret =-1 ;target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1420
Quoted 10 lines
target-ppc/kvm.c +10
-0+char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/system-id" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);Why IBM,<system-id>?
Quoted 2 lines
There were userspace tools that looking at lparcfg, and were encoded similarly.
I don't think we own the IBM namespace, so I find this slightly bogus. Also why would a host machine have to be made by IBM?
Quoted 28 lines
Quoted 9 lines
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1425
Quoted 6 lines
target-ppc/kvm.c +5
-0+ ret =0 ; + } +fclose (f); + +return ret;I think it makes sense to extract the "read a full file into a buffer" logic into a separate function. For bonus points, find a glib function that already does it and use that ;).
Let me search.
Quoted 9 lines
Quoted 9 lines
target-ppc/kvm.c +9
-0+} + +int32_t kvmppc_get_host_model (char *value,int len) +{ +FILE *f; +int ret =-1 ; +char line[512 ]; + +memset (line,0 ,sizeof (line));Quoted 8 lines
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1441
Quoted 7 lines
target-ppc/kvm.c +7
-0+ f =fopen ("/proc/device-tree/model" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);Same here - wouldn't this be IBM,IBM,foo?
Quoted 1 line
No, it will be IBM,<model>
Hrm, I just tried to compare this with a pHyp system and can't seem to find any /proc/device-tree/host* files. What am I missing?
Alex
Quoted 117 lines · Alexander Graf
Quoted 33 lines · Nikunj A Dadhania
Quoted 21 lines · Alexander Graf
Quoted 20 lines · Nikunj A Dadhania
Useful for identifying the guest/host uniquely within the guest. Adding following properties to the guest root node.
vm,uuid - uuid of the guest
host-model - Host model number
host-serial - Host machine serial number
hypervisor type - Tells its "kvm"Signed-off-by Nikunj A Dadhania <[email protected]>---
v4: make uuid as human readable
v3: rebase to ppcnext
v2: indentation fixes--- hw/ppc/spapr.c | 25 +++++++++++++++++++++++++ target-ppc/kvm.c | 44 +++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-)Quoted 10 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 321
Quoted 9 lines
hw/ppc/spapr.c +1
-0@@ -318,6 +318,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,QemuOpts *opts =qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL );unsigned sockets = opts ?qemu_opt_get_number (opts,"sockets" ,0 ) :0 ;uint32_t cpus_per_socket = sockets ? (smp_cpus / sockets) :1 ; +char char_buf[512 ];Can't you just return callee allocated, caller free'd memory?
Quoted 2 lines
Tried doing it more in line of
read_cpuinfointarget-ppc/kvm.cI could do it either ways.Yeah, feel free to convert that one too if you like ;).
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
hw/ppc/spapr.c +10
-0add_str (hypertas,"hcall-pft" );add_str (hypertas,"hcall-term" );@@ -347,6 +348,30 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,_FDT ((fdt_property_string (fdt,"model" ,"IBM pSeries (emulated by qemu)" )));_FDT ((fdt_property_string (fdt,"compatible" ,"qemu,pseries" ))); +if (kvm_enabled ()) { +_FDT ((fdt_property_string (fdt,"hypervisor" ,"kvm" ))); + } + +/* +* Add info to guest to indentify which host is it being run on +* and what is the uuid of the guest +*/ +memset (char_buf,0 ,sizeof (char_buf)); +if (!kvmppc_get_host_model (char_buf,sizeof (char_buf))) {Quoted 8 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 366
Quoted 6 lines
hw/ppc/spapr.c +6
-0+_FDT ((fdt_property_string (fdt,"host-model" , char_buf))); +memset (char_buf,0 ,sizeof (char_buf)); + } +if (!kvmppc_get_host_serial (char_buf,sizeof (char_buf))) { +_FDT ((fdt_property_string (fdt,"host-serial" , char_buf))); + }Please be aware that all of the above is bogus when you start thinking about live migration.
Quoted 2 lines
Yes, there are tools that look at these. Is there a way to update these on migration?
As Ben already mentioned ;).
Quoted 47 lines
Quoted 4 lines
hw/ppc/spapr.c static void *spapr_create_fdt_skel(hwaddr initrd_base, · line 368
Quoted 3 lines
hw/ppc/spapr.c +2
-0+ + snprintf(char_buf, 37, UUID_FMT, qemu_uuid[0], qemu_uuid[1],
g_strdup_printf()Ok.
Quoted 41 lines
Quoted 30 lines
hw/ppc/spapr.c +6
-0+ qemu_uuid[2 ], qemu_uuid[3 ], qemu_uuid[4 ], qemu_uuid[5 ], + qemu_uuid[6 ], qemu_uuid[7 ], qemu_uuid[8 ], qemu_uuid[9 ], + qemu_uuid[10 ], qemu_uuid[11 ], qemu_uuid[12 ], qemu_uuid[13 ], + qemu_uuid[14], qemu_uuid[15]); +_FDT ((fdt_property_string (fdt,"vm,uuid" , char_buf))); +_FDT ((fdt_property_cell (fdt,"#address-cells" ,0x2 )));_FDT ((fdt_property_cell (fdt,"#size-cells" ,0x2 )));target-ppc/kvm.c +5
-1@@ -1369,7 +1369,7 @@ static int read_cpuinfo(const char *field, char *value, int len) } do { - if(!fgets(line, sizeof(line), f)) { + if (!fgets(line, sizeof(line), f)) { break; } if (!strncmp(line, field, field_len)) {@@ -1404,6 +1404,48 @@ uint32_t kvmppc_get_tbfreq(void)return retval; } +int32_t kvmppc_get_host_serial (char *value,int len) +{ +FILE *f; +int ret =-1 ;target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1420
Quoted 10 lines
target-ppc/kvm.c +10
-0+char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/system-id" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);Why IBM,<system-id>?
Quoted 5 lines
Quoted 2 lines
There were userspace tools that looking at lparcfg, and were encoded similarly.
I don't think we own the IBM namespace, so I find this slightly bogus. Also why would a host machine have to be made by IBM?
You have a valid point, i will remove the "IBM" prefix :-)
Quoted 29 lines
Quoted 29 lines
Quoted 10 lines
target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1425
Quoted 7 lines
target-ppc/kvm.c +5
-0+ ret =0 ; + } +fclose (f); + +return ret;I think it makes sense to extract the "read a full file into a buffer" logic into a separate function. For bonus points, find a glib function that already does it and use that ;).
Let me search.
Quoted 17 lines
Quoted 6 lines
target-ppc/kvm.c +6
-0+} + +int32_t kvmppc_get_host_model (char *value,int len) +{ +FILE *f; +int ret =-1 ;target-ppc/kvm.c uint32_t kvmppc_get_tbfreq(void) · line 1441
Quoted 10 lines
target-ppc/kvm.c +10
-0+char line[512 ]; + +memset (line,0 ,sizeof (line)); + f =fopen ("/proc/device-tree/model" ,"r" ); +if (!f) { +return ret; + } + +if (fgets (line,sizeof (line), f)) { +snprintf (value, len,"IBM,%s" , line);Same here - wouldn't this be IBM,IBM,foo?
Quoted 4 lines
Quoted 1 line
No, it will be IBM,<model>
Hrm, I just tried to compare this with a pHyp system and can't seem to find any
/proc/device-tree/host*files. What am I missing?
You wont, they arent there in pHyp. It was being populated in /proc/ppc64/lparcfg. For example /model which we encode as :
_FDT((fdt_property_string(fdt, "model", "IBM pSeries (emulated by qemu)")));
pHyp would have put it as host machine model. From above we digressed.
I thought of having a mechanism that is more generic to get these from device tree directly.
Regards,
Nikunj