All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/1] lscpu: correct the Virtualization type on Xen DomU PV guest
@ 2016-03-19 12:03 Dongli Zhang
  2016-03-21  9:16 ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Dongli Zhang @ 2016-03-19 12:03 UTC (permalink / raw)
  To: kzak; +Cc: util-linux, qcai


> + Is the file always available (including old XEN versions)?=20

This file (/sys/hypervisor/properties/features) has been available since Li=
nux 2.6.31=20
(drivers/xen/sys-hypervisor.c)

> + There is also path_read_u64() to avoid path_fopen() & fscanf().

I will change to path_read_u64.


I also made a new flow to detect the Xen virtualization type according to
the features on this path to maximize the number of versions of existing
Xen and Linux to support. Xen versions from Xen 3.3.0 to the current Xen
unstable would be able to help detect PV based on
XENFEAT_mmu_pt_update_preserve_ad. Xen versions from Xen 4.4.0 to the
newest would be able to help detect PVH (which has been introduced since
Xen 4.4.0).

if cpuid returns XenVMMXenVMM
=09virtype =3D full
=09if _PATH_SYS_HYP_FEATURES (the file) exists
=09=09if XENFEAT_mmu_pt_update_preserve_ad is set (supported since Xen 3.3.=
0)
=09=09=09virtype =3D para
=09=09else if XENFEAT_supervisor_mode_kernel is set and
=09=09=09=09XENFEAT_hvm_callback_vector is set (supported since Xen 4.4.0)
=09=09=09virtype =3D para
=09=09end if
=09end if
end if

Please let me know your feedback and suggestion so that I would send the
new patch soon.

Dongli Zhang

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] lscpu: correct the Virtualization type on Xen DomU PV guest
  2016-03-19 12:03 [PATCH 1/1] lscpu: correct the Virtualization type on Xen DomU PV guest Dongli Zhang
@ 2016-03-21  9:16 ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2016-03-21  9:16 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: util-linux, qcai

On Sat, Mar 19, 2016 at 05:03:41AM -0700, Dongli Zhang wrote:
> 
> > + Is the file always available (including old XEN versions)? 
> 
> This file (/sys/hypervisor/properties/features) has been available since Linux 2.6.31 
> (drivers/xen/sys-hypervisor.c)
> 
> > + There is also path_read_u64() to avoid path_fopen() & fscanf().
> 
> I will change to path_read_u64.
> 
> 
> I also made a new flow to detect the Xen virtualization type according to
> the features on this path to maximize the number of versions of existing
> Xen and Linux to support. Xen versions from Xen 3.3.0 to the current Xen
> unstable would be able to help detect PV based on
> XENFEAT_mmu_pt_update_preserve_ad. Xen versions from Xen 4.4.0 to the
> newest would be able to help detect PVH (which has been introduced since
> Xen 4.4.0).
> 
> if cpuid returns XenVMMXenVMM
> 	virtype = full
> 	if _PATH_SYS_HYP_FEATURES (the file) exists
> 		if XENFEAT_mmu_pt_update_preserve_ad is set (supported since Xen 3.3.0)
> 			virtype = para
> 		else if XENFEAT_supervisor_mode_kernel is set and
> 				XENFEAT_hvm_callback_vector is set (supported since Xen 4.4.0)
> 			virtype = para
> 		end if
> 	end if
> end if
> 
> Please let me know your feedback and suggestion so that I would send the
> new patch soon.

Looks good, go ahead ;-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] lscpu: correct the Virtualization type on Xen DomU PV guest
  2016-03-18  6:53 Dongli Zhang
@ 2016-03-18 10:48 ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2016-03-18 10:48 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: util-linux, qcai

On Fri, Mar 18, 2016 at 02:53:24PM +0800, Dongli Zhang wrote:
> +			fd = path_fopen("r", 0, _PATH_SYS_HYP_FEATURES);

 Is the file always available (including old XEN versions)? This
 function exit on error, maybe we need path_exist() before open.

 There is also path_read_u64() to avoid path_fopen() & fscanf().

    Karel

> +			if (fd && fscanf(fd, "%x", &features) == 1) {
> +				/* Xen para-virt (or pvh) */
> +				if (!(features & (1U << XENFEAT_hvm_pirqs)))
> +					desc->virtype = VIRT_PARA;
> +				fclose(fd);
> +			}
> +		}
> +	} else if (read_hypervisor_powerpc(desc) > 0) {}
>  
>  	/* Xen para-virt or dom0 */
>  	else if (path_exist(_PATH_PROC_XEN)) {

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] lscpu: correct the Virtualization type on Xen DomU PV guest
@ 2016-03-18  6:53 Dongli Zhang
  2016-03-18 10:48 ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Dongli Zhang @ 2016-03-18  6:53 UTC (permalink / raw)
  To: util-linux, qcai; +Cc: dongli.zhang

Nowadays, most Intel CPUs have "cpuid faulting" available which could trap
the execution of "cpuid" instruction when CPL>0  with GP fault. Thus,
"cpuid" instruction could trap to Xen hypervisor on the paravirtualized PV
guest on most servers today, except on old CPUs prior to 2011. On CPU after
2011, Xen will put "XenVMMXenVMM" on both HVM and PV guests, which could
have lscpu command erroneously classify the guest as type "full".  The
current lscpu command, which is based on "cpuid" instruction, still assumes
that it will not cause the trap to Xen hypervisor on Xen PV guest and uses
/proc/xen to identify whether it's running on PV DomU or not.  To identify
this kind of information under the help of
/sys/hypervisor/properties/features would be more accurate for the CPU
nowadays.  The bit 10 (XENFEAT_hvm_pirqs) of
/sys/hypervisor/properties/features will be set only when it's running on
Xen HVM domain.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
 sys-utils/lscpu.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 36e36c9..faa86bc 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -73,6 +73,7 @@
 
 /* /sys paths */
 #define _PATH_SYS_SYSTEM	"/sys/devices/system"
+#define _PATH_SYS_HYP_FEATURES "/sys/hypervisor/properties/features"
 #define _PATH_SYS_CPU		_PATH_SYS_SYSTEM "/cpu"
 #define _PATH_SYS_NODE		_PATH_SYS_SYSTEM "/node"
 #define _PATH_PROC_XEN		"/proc/xen"
@@ -86,6 +87,9 @@
 #define _PATH_PROC_DEVICETREE	"/proc/device-tree"
 #define _PATH_DEV_MEM 		"/dev/mem"
 
+/* Xen Domain feature flag used for /sys/hypervisor/properties/features */
+#define XENFEAT_hvm_pirqs	10
+
 /* virtualization types */
 enum {
 	VIRT_NONE	= 0,
@@ -811,10 +815,20 @@ read_hypervisor(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 			desc->hyper = HYPER_VMWARE;
 	}
 
-	if (desc->hyper)
+	if (desc->hyper) {
 		desc->virtype = VIRT_FULL;
-
-	else if (read_hypervisor_powerpc(desc) > 0) {}
+		if (desc->hyper == HYPER_XEN) {
+			unsigned int features;
+
+			fd = path_fopen("r", 0, _PATH_SYS_HYP_FEATURES);
+			if (fd && fscanf(fd, "%x", &features) == 1) {
+				/* Xen para-virt (or pvh) */
+				if (!(features & (1U << XENFEAT_hvm_pirqs)))
+					desc->virtype = VIRT_PARA;
+				fclose(fd);
+			}
+		}
+	} else if (read_hypervisor_powerpc(desc) > 0) {}
 
 	/* Xen para-virt or dom0 */
 	else if (path_exist(_PATH_PROC_XEN)) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-21  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-19 12:03 [PATCH 1/1] lscpu: correct the Virtualization type on Xen DomU PV guest Dongli Zhang
2016-03-21  9:16 ` Karel Zak
  -- strict thread matches above, loose matches on Subject: below --
2016-03-18  6:53 Dongli Zhang
2016-03-18 10:48 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.