From patchwork Fri May 26 12:56:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9750587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8522760249 for ; Fri, 26 May 2017 12:59:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 717F126212 for ; Fri, 26 May 2017 12:59:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66485283B9; Fri, 26 May 2017 12:59:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED4E926212 for ; Fri, 26 May 2017 12:59:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dEEni-0005jQ-RH; Fri, 26 May 2017 12:57:06 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dEEnh-0005jH-6D for xen-devel@lists.xenproject.org; Fri, 26 May 2017 12:57:05 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 27/46-03557-02628295; Fri, 26 May 2017 12:57:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrILMWRWlGSWpSXmKPExsVyuP0Ov668mka kQfdJS4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNePntgPsBd9MKx4e/8TawLhLt4uRk0NCwEji 7cR/TF2MXBxCAgsZJa5c+sYEkmATUJXYcP0UK4gtIuAosbptKZjNLBArsf/OLHYQW1jASmLe5 NeMIDYLUP3nzmY2EJtXwETi3YOfLBAL5CUWbZoBZHNwcAqYSnS2G4KEhYBKdp94yTKBkXsBI8 MqRo3i1KKy1CJdQyO9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK95PzcTYxA7zIAwQ7Gyxs DDjFKcjApifJOX6ceKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCN0JFI1JIsCg1PbUiLTMHGGYw aQkOHiUR3hUgad7igsTc4sx0iNQpRl2ODavXf2ESYsnLz0uVEuflUQUqEgApyijNgxsBC/lLj LJSwryMQEcJ8RSkFuVmlqDKv2IU52BUEub9ALKKJzOvBG7TK6AjmICO8D2nDnJESSJCSqqBkd vu1cvZaxX7vk0Wzp2jtD+9Mlnz9Kfrc9mq5xT8DTm/VO+4TdE8xpzXErtiI3NV8jecXxKlWVn lXzu79fOWjqi/scceqjvznd7Z3LOa3+HSlKcl+fqW/Lt+HDwrNLO/Zc2qBV+yr0ReDszUMnJc Gm93yE80IeGVXLCvbviazZ6G9RtXLZbNVmIpzkg01GIuKk4EAOsvZdF0AgAA X-Env-Sender: jgross@suse.com X-Msg-Ref: server-16.tower-27.messagelabs.com!1495803423!104247789!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32795 invoked from network); 26 May 2017 12:57:03 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-16.tower-27.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 26 May 2017 12:57:03 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8B23AACBD; Fri, 26 May 2017 12:57:03 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Date: Fri, 26 May 2017 14:56:57 +0200 Message-Id: <20170526125657.24505-3-jgross@suse.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170526125657.24505-1-jgross@suse.com> References: <20170526125657.24505-1-jgross@suse.com> Cc: Juergen Gross , gregkh@linuxfoundation.org, boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH v2 2/2] xen: add sysfs node for guest type X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently there is no reliable user interface inside a Xen guest to determine its type (e.g. HVM, PV or PVH). Instead of letting user mode try to determine this by various rather hacky mechanisms (parsing of boot messages before they are gone, trying to make use of known subtle differences in behavior of some instructions), add a sysfs node /sys/hypervisor/guest_type to explicitly deliver this information as it is known to the kernel. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- V2: - remove PVHVM guest type (Andrew Cooper) - move description to Documentation/ABI/testing/sysfs-hypervisor-xen (Boris Ostrovsky) - make xen_guest_type const char * (Jan Beulich) - modify standard ARM guest type to "Xen" --- .../{sysfs-hypervisor-pmu => sysfs-hypervisor-xen} | 15 +++++++++++++-- MAINTAINERS | 2 +- arch/arm/xen/enlighten.c | 3 +++ arch/x86/xen/enlighten.c | 3 +++ arch/x86/xen/enlighten_hvm.c | 5 +++-- arch/x86/xen/enlighten_pv.c | 1 + drivers/xen/sys-hypervisor.c | 17 +++++++++++++++++ include/xen/xen.h | 2 ++ 8 files changed, 43 insertions(+), 5 deletions(-) rename Documentation/ABI/testing/{sysfs-hypervisor-pmu => sysfs-hypervisor-xen} (67%) diff --git a/Documentation/ABI/testing/sysfs-hypervisor-pmu b/Documentation/ABI/testing/sysfs-hypervisor-xen similarity index 67% rename from Documentation/ABI/testing/sysfs-hypervisor-pmu rename to Documentation/ABI/testing/sysfs-hypervisor-xen index 224faa105e18..c0edb3fdd6eb 100644 --- a/Documentation/ABI/testing/sysfs-hypervisor-pmu +++ b/Documentation/ABI/testing/sysfs-hypervisor-xen @@ -1,8 +1,19 @@ +What: /sys/hypervisor/guest_type +Date: May 2017 +KernelVersion: 4.13 +Contact: xen-devel@lists.xenproject.org +Description: If running under Xen: + Type of guest: + "Xen": standard guest type on arm + "HVM": fully virtualized guest (x86) + "PV": paravirtualized guest (x86) + "PVH": fully virtualized guest without legacy emulation (x86) + What: /sys/hypervisor/pmu/pmu_mode Date: August 2015 KernelVersion: 4.3 Contact: Boris Ostrovsky -Description: +Description: If running under Xen: Describes mode that Xen's performance-monitoring unit (PMU) uses. Accepted values are "off" -- PMU is disabled @@ -17,7 +28,7 @@ What: /sys/hypervisor/pmu/pmu_features Date: August 2015 KernelVersion: 4.3 Contact: Boris Ostrovsky -Description: +Description: If running under Xen: Describes Xen PMU features (as an integer). A set bit indicates that the corresponding feature is enabled. See include/xen/interface/xenpmu.h for available features diff --git a/MAINTAINERS b/MAINTAINERS index 5d10cc33fc41..76a0fecfca51 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13984,7 +13984,7 @@ F: arch/x86/include/asm/xen/ F: include/xen/ F: include/uapi/xen/ F: Documentation/ABI/stable/sysfs-hypervisor-xen -F: Documentation/ABI/testing/sysfs-hypervisor-pmu +F: Documentation/ABI/testing/sysfs-hypervisor-xen XEN HYPERVISOR ARM M: Stefano Stabellini diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index ba7f4c8f5c3e..7429af623379 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -43,6 +43,9 @@ EXPORT_SYMBOL(xen_start_info); enum xen_domain_type xen_domain_type = XEN_NATIVE; EXPORT_SYMBOL(xen_domain_type); +const char *xen_guest_type = "Xen"; +EXPORT_SYMBOL_GPL(xen_guest_type); + struct shared_info xen_dummy_shared_info; struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info; diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index a5ffcbb20cc0..17b6503df291 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -47,6 +47,9 @@ EXPORT_PER_CPU_SYMBOL(xen_vcpu_id); enum xen_domain_type xen_domain_type = XEN_NATIVE; EXPORT_SYMBOL_GPL(xen_domain_type); +const char *xen_guest_type = "HVM"; +EXPORT_SYMBOL_GPL(xen_guest_type); + unsigned long *machine_to_phys_mapping = (void *)MACH2PHYS_VIRT_START; EXPORT_SYMBOL(machine_to_phys_mapping); unsigned long machine_to_phys_nr; diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index a6d014f47e52..bda98726d139 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -68,9 +68,10 @@ static void __init init_hvm_pv_info(void) xen_domain_type = XEN_HVM_DOMAIN; /* PVH set up hypercall page in xen_prepare_pvh(). */ - if (xen_pvh_domain()) + if (xen_pvh_domain()) { pv_info.name = "Xen PVH"; - else { + xen_guest_type = "PVH"; + } else { u64 pfn; uint32_t msr; diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index f33eef4ebd12..7ac5e93d96f3 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1255,6 +1255,7 @@ asmlinkage __visible void __init xen_start_kernel(void) return; xen_domain_type = XEN_PV_DOMAIN; + xen_guest_type = "PV"; xen_setup_features(); diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c index 84106f9c456c..d641e9970d5d 100644 --- a/drivers/xen/sys-hypervisor.c +++ b/drivers/xen/sys-hypervisor.c @@ -50,6 +50,18 @@ static int __init xen_sysfs_type_init(void) return sysfs_create_file(hypervisor_kobj, &type_attr.attr); } +static ssize_t guest_type_show(struct hyp_sysfs_attr *attr, char *buffer) +{ + return sprintf(buffer, "%s\n", xen_guest_type); +} + +HYPERVISOR_ATTR_RO(guest_type); + +static int __init xen_sysfs_guest_type_init(void) +{ + return sysfs_create_file(hypervisor_kobj, &guest_type_attr.attr); +} + /* xen version attributes */ static ssize_t major_show(struct hyp_sysfs_attr *attr, char *buffer) { @@ -471,6 +483,9 @@ static int __init hyper_sysfs_init(void) ret = xen_sysfs_type_init(); if (ret) goto out; + ret = xen_sysfs_guest_type_init(); + if (ret) + goto guest_type_out; ret = xen_sysfs_version_init(); if (ret) goto version_out; @@ -502,6 +517,8 @@ static int __init hyper_sysfs_init(void) comp_out: sysfs_remove_group(hypervisor_kobj, &version_group); version_out: + sysfs_remove_file(hypervisor_kobj, &guest_type_attr.attr); +guest_type_out: sysfs_remove_file(hypervisor_kobj, &type_attr.attr); out: return ret; diff --git a/include/xen/xen.h b/include/xen/xen.h index 6e8b7fc79801..f02d1732d7a6 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -9,8 +9,10 @@ enum xen_domain_type { #ifdef CONFIG_XEN extern enum xen_domain_type xen_domain_type; +extern const char *xen_guest_type; #else #define xen_domain_type XEN_NATIVE +#define xen_guest_type "native" #endif #define xen_domain() (xen_domain_type != XEN_NATIVE)