From patchwork Fri Jun 27 06:47:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikunj A Dadhania X-Patchwork-Id: 364788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 26978140087 for ; Fri, 27 Jun 2014 16:48:59 +1000 (EST) Received: from localhost ([::1]:48276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Pxx-0000AN-Cu for incoming@patchwork.ozlabs.org; Fri, 27 Jun 2014 02:48:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0PxK-0007ek-KE for qemu-devel@nongnu.org; Fri, 27 Jun 2014 02:48:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0PxB-00024P-7R for qemu-devel@nongnu.org; Fri, 27 Jun 2014 02:48:18 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:48061) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0PxA-0001xY-AB for qemu-devel@nongnu.org; Fri, 27 Jun 2014 02:48:09 -0400 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 27 Jun 2014 12:18:04 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 27 Jun 2014 12:18:02 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id AA950E0045; Fri, 27 Jun 2014 12:19:16 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5R6nG2Y17432746; Fri, 27 Jun 2014 12:19:16 +0530 Received: from d28av03.in.ibm.com (localhost [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5R6m0I8028831; Fri, 27 Jun 2014 12:18:01 +0530 Received: from abhimanyu.in.ibm.com ([9.79.243.110]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5R6lqLi028392; Fri, 27 Jun 2014 12:17:59 +0530 From: Nikunj A Dadhania To: qemu-devel@nongnu.org, agraf@suse.de Date: Fri, 27 Jun 2014 12:17:37 +0530 Message-Id: <1403851658-13128-2-git-send-email-nikunj@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.1 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14062706-2674-0000-0000-000000989CA7 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 122.248.162.9 Cc: aik@au1.ibm.com, qemu-ppc@nongnu.org, nikunj@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 2/3] spapr: add uuid/host details to device tree X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/ppc/spapr.c | 19 +++++++++++++++++++ target-ppc/kvm.c | 44 +++++++++++++++++++++++++++++++++++++++++++- target-ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a8ba916..33f77d2 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -319,6 +319,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"); @@ -348,6 +349,24 @@ 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))); + } + _FDT((fdt_property(fdt, "vm,uuid", qemu_uuid, 16))); + _FDT((fdt_property_cell(fdt, "#address-cells", 0x2))); _FDT((fdt_property_cell(fdt, "#size-cells", 0x2))); diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 2d87108..25091f8 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -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; + 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); + ret = 0; + } + fclose(f); + + return ret; +} + +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"); + if (!f) { + return ret; + } + + if (fgets(line, sizeof(line), f)) { + snprintf(value, len, "IBM,%s", line); + 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) { diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index 1118122..6fa3314 100644 --- a/target-ppc/kvm_ppc.h +++ b/target-ppc/kvm_ppc.h @@ -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;