From patchwork Wed Jun 14 18:52:16 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: 9787249 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 270E4602D9 for ; Wed, 14 Jun 2017 18:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18AE226E16 for ; Wed, 14 Jun 2017 18:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D43A28539; Wed, 14 Jun 2017 18:54:31 +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=unavailable 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 9B03C26E16 for ; Wed, 14 Jun 2017 18:54:29 +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 1dLDOy-0006KJ-Gd; Wed, 14 Jun 2017 18:52:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLDOw-0006Jv-Rm for xen-devel@lists.xenproject.org; Wed, 14 Jun 2017 18:52:22 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 62/C9-03613-6E581495; Wed, 14 Jun 2017 18:52:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRWlGSWpSXmKPExsVyuP0Ov+7jVsd Ig7d3mCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxnf7vYCh4bVqw/dJ+9gXG+VhcjJ4eEgJHE 24n/mLoYuTiEBBYySuya9YYdJCEsYCfx6fRfMFtEIF/i3M17rCA2s4CcROfkHcwQDRMZJeZt3 QpWxCagKrHh+imwIl4Ba4nrN38ygdgsQPGzcy+ygdiiAuESvQf62SBqBCVOznzCAmJzAi1rej oTaoG/xNqmBiYIW1xi07PvrBMY+WYhaZmFpGwWkjIIW09ix/VfULa8xPa3c5gh7GCJ8x9uYBG Pkfh+8TnjAkaOVYwaxalFZalFusZGeklFmekZJbmJmTm6hgZmermpxcWJ6ak5iUnFesn5uZsY gYHOAAQ7GE+vCzzEKMnBpCTKO1XQMVKILyk/pTIjsTgjvqg0J7X4EKMMB4eSBK8KMHKEBItS0 1Mr0jJzgDEHk5bg4FES4c0ESfMWFyTmFmemQ6ROMepybFi9/guTEEtefl6qlDgvC0iRAEhRRm ke3AhY/F9ilJUS5mUEOkqIpyC1KDezBFX+FaM4B6OSMK8vyBSezLwSuE2vgI5gAjoi6IIDyBE liQgpqQbGTSK7aiwLlnOdFfzqwjWPZ/Fy757tme1bD7btPNQpsnlp6RSXR3c1EoNEK2y3rt3J KpjA2JW28sriCyd5X380Ps78NjyT3exp6aKTYob3Js1fsyOkebmVdepb38OuPaHpllIn7+/Oq ZrFW+Lwttg26sW1LXeWMk8V7/C1TnWK2Z5wKV7tf5WlEktxRqKhFnNRcSIA3A10yfoCAAA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1497466338!73953453!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 58921 invoked from network); 14 Jun 2017 18:52:19 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-7.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 14 Jun 2017 18:52:19 -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 5F8A4AB9D; Wed, 14 Jun 2017 18:52:18 +0000 (UTC) To: Boris Ostrovsky , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org References: <20170614172352.27557-1-jgross@suse.com> <20170614172352.27557-3-jgross@suse.com> From: Juergen Gross Message-ID: Date: Wed, 14 Jun 2017 20:52:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Language: de-DE Cc: gregkh@linuxfoundation.org Subject: Re: [Xen-devel] [PATCH v4 2/4] 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 14/06/17 19:43, Boris Ostrovsky wrote: > >> --- 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) >> + >> > > > >> >> +static ssize_t guest_type_show(struct hyp_sysfs_attr *attr, char *buffer) >> +{ >> + const char *type = "???"; >> + >> + switch (xen_domain_type) { >> + case XEN_NATIVE: >> + /* ARM only. */ >> + type = "Xen"; >> + break; >> + case XEN_PV_DOMAIN: >> + type = "PV"; >> + break; >> + case XEN_HVM_DOMAIN: >> + type = xen_pvh_domain() ? "PVH" : "HVM"; >> + break; >> + } > > I think we should return -EINVAL for unknown type. Or document "???" in > the ABI document. Hmm, okay. Are you fine with the attached patch? Juergen Reviewed-by: Boris Ostrovsky From b8661036e7465eab99f988cec3fe37e35536eb40 Mon Sep 17 00:00:00 2001 From: Juergen Gross Date: Wed, 14 Jun 2017 17:12:45 +0200 Subject: [PATCH v5] xen: add sysfs node for guest type 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 --- V4: - use xen_domain_type instead of introducing xen_guest_type (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 +- drivers/xen/sys-hypervisor.c | 34 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 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 68c31aebb79c..5630439429e6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13983,7 +13983,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/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c index 84106f9c456c..2f78f84a31e9 100644 --- a/drivers/xen/sys-hypervisor.c +++ b/drivers/xen/sys-hypervisor.c @@ -50,6 +50,35 @@ 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) +{ + const char *type; + + switch (xen_domain_type) { + case XEN_NATIVE: + /* ARM only. */ + type = "Xen"; + break; + case XEN_PV_DOMAIN: + type = "PV"; + break; + case XEN_HVM_DOMAIN: + type = xen_pvh_domain() ? "PVH" : "HVM"; + break; + default: + return -EINVAL; + } + + return sprintf(buffer, "%s\n", 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 +500,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 +534,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; -- 2.12.3