Re: Attach kvm-clock to Linux guests on VMM

2019-05-28 Thread Renato Aguiar



On Mon, May 27 2019, Pratik Vyas wrote:


* Renato Aguiar  [2019-05-27 03:53:11 -0700]:


Hi,

The following patch makes Linux guests use kvm-clock by setting
KVM's CPUID signature on VMM:



I think the right thing is to make linux attach pvclock if it's 
on

OpenBSD vmm.  You want to send them a patch?


It makes sense. I checked Linux's source code again and it seems 
to share the same pvclock implementation with KVM and Xen already. 
It shouldn't be hard to include VMM too. I'll try that out.




Otherwise, does vmm pvclock keep good time on linux from your 
experiments?


I didn't do long term testing, but from what I could see it keeps 
the clock in sync with the host.


--
Renato Aguiar



Re: Attach kvm-clock to Linux guests on VMM

2019-05-28 Thread Renato Aguiar



On Mon, May 27 2019, Mike Larkin wrote:


On Mon, May 27, 2019 at 03:53:11AM -0700, Renato Aguiar wrote:

Hi,

The following patch makes Linux guests use kvm-clock by setting 
KVM's CPUID

signature on VMM:



By saying the hypervisor is KVM to all guests, does this cause 
the guests

to make other assumptions we don't want?


I'm not sure. Linux seems to be fine with it, but it may cause 
issues with other OSs.


I'll try implementing it on the Linux side instead.




Index: sys/arch/amd64/amd64/vmm.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/vmm.c,v
retrieving revision 1.245
diff -u -p -r1.245 vmm.c
--- sys/arch/amd64/amd64/vmm.c	17 May 2019 19:07:15 - 
1.245

+++ sys/arch/amd64/amd64/vmm.c  27 May 2019 09:44:07 -
@@ -238,6 +238,7 @@ extern uint64_t tsc_frequency;
extern int tsc_is_invariant;

const char *vmm_hv_signature = VMM_HV_SIGNATURE;
+const char *kvm_hv_signature = KVM_HV_SIGNATURE;

const struct kmem_pa_mode vmm_kp_contig = {
.kp_constraint = _constraint,
@@ -6433,7 +6434,14 @@ vmm_handle_cpuid(struct vcpu *vcpu)
*rcx = *((uint32_t *)_hv_signature[4]);
*rdx = *((uint32_t *)_hv_signature[8]);
break;
+   case 0x4100:/* KVM CPUID signature */
+   *rax = 0;
+   *rbx = *((uint32_t *)_hv_signature[0]);
+   *rcx = *((uint32_t *)_hv_signature[4]);
+   *rdx = *((uint32_t *)_hv_signature[8]);
+   break;
case 0x4001:/* KVM hypervisor features */
+   case 0x4101:
*rax = (1 << KVM_FEATURE_CLOCKSOURCE2) |
(1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT);
*rbx = 0;
Index: sys/arch/amd64/include/vmmvar.h
===
RCS file: /cvs/src/sys/arch/amd64/include/vmmvar.h,v
retrieving revision 1.66
diff -u -p -r1.66 vmmvar.h
--- sys/arch/amd64/include/vmmvar.h	17 May 2019 19:07:16 - 
1.66

+++ sys/arch/amd64/include/vmmvar.h 27 May 2019 09:44:07 -
@@ -22,6 +22,7 @@
#define _MACHINE_VMMVAR_H_

#define VMM_HV_SIGNATURE"OpenBSDVMM58"
+#define KVM_HV_SIGNATURE   "KVMKVMKVM\0\0\0"

#define VMM_MAX_MEM_RANGES  16
#define VMM_MAX_DISKS_PER_VM4
Index: sys/arch/i386/include/vmmvar.h
===
RCS file: /cvs/src/sys/arch/i386/include/vmmvar.h,v
retrieving revision 1.19
diff -u -p -r1.19 vmmvar.h
--- sys/arch/i386/include/vmmvar.h	18 Jan 2019 01:34:50 - 
1.19

+++ sys/arch/i386/include/vmmvar.h  27 May 2019 09:44:07 -
@@ -15,3 +15,4 @@
 */

#define VMM_HV_SIGNATURE"OpenBSDVMM58"
+#define KVM_HV_SIGNATURE   "KVMKVMKVM\0\0\0"
Index: sys/dev/pv/pvbus.c
===
RCS file: /cvs/src/sys/dev/pv/pvbus.c,v
retrieving revision 1.19
diff -u -p -r1.19 pvbus.c
--- sys/dev/pv/pvbus.c	13 May 2019 15:40:34 - 
1.19

+++ sys/dev/pv/pvbus.c  27 May 2019 09:44:08 -
@@ -85,7 +85,7 @@ struct pvbus_type {
void(*init)(struct pvbus_hv *);
void(*print)(struct pvbus_hv *);
} pvbus_types[PVBUS_MAX] = {
-   { "KVMKVMKVM\0\0\0",  "KVM",pvbus_kvm },
+   { KVM_HV_SIGNATURE, "KVM",pvbus_kvm },
	{ "Microsoft Hv",	"Hyper-V", pvbus_hyperv, 
pvbus_hyperv_print },

{ "VMwareVMware", "VMware" },
	{ "XenVMMXenVMM",	"Xen",	pvbus_xen, pvbus_xen_print 
},



--
Renato Aguiar




--
Renato Aguiar



Re: Attach kvm-clock to Linux guests on VMM

2019-05-27 Thread Pratik Vyas

* Renato Aguiar  [2019-05-27 03:53:11 -0700]:


Hi,

The following patch makes Linux guests use kvm-clock by setting KVM's 
CPUID signature on VMM:




I think the right thing is to make linux attach pvclock if it's on
OpenBSD vmm.  You want to send them a patch?

Otherwise, does vmm pvclock keep good time on linux from your experiments?

--
Pratik



Re: Attach kvm-clock to Linux guests on VMM

2019-05-27 Thread Mike Larkin
On Mon, May 27, 2019 at 03:53:11AM -0700, Renato Aguiar wrote:
> Hi,
> 
> The following patch makes Linux guests use kvm-clock by setting KVM's CPUID
> signature on VMM:
> 

By saying the hypervisor is KVM to all guests, does this cause the guests
to make other assumptions we don't want?

> Index: sys/arch/amd64/amd64/vmm.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/vmm.c,v
> retrieving revision 1.245
> diff -u -p -r1.245 vmm.c
> --- sys/arch/amd64/amd64/vmm.c17 May 2019 19:07:15 -1.245
> +++ sys/arch/amd64/amd64/vmm.c27 May 2019 09:44:07 -
> @@ -238,6 +238,7 @@ extern uint64_t tsc_frequency;
> extern int tsc_is_invariant;
> 
> const char *vmm_hv_signature = VMM_HV_SIGNATURE;
> +const char *kvm_hv_signature = KVM_HV_SIGNATURE;
> 
> const struct kmem_pa_mode vmm_kp_contig = {
>   .kp_constraint = _constraint,
> @@ -6433,7 +6434,14 @@ vmm_handle_cpuid(struct vcpu *vcpu)
>   *rcx = *((uint32_t *)_hv_signature[4]);
>   *rdx = *((uint32_t *)_hv_signature[8]);
>   break;
> + case 0x4100:/* KVM CPUID signature */
> + *rax = 0;
> + *rbx = *((uint32_t *)_hv_signature[0]);
> + *rcx = *((uint32_t *)_hv_signature[4]);
> + *rdx = *((uint32_t *)_hv_signature[8]);
> + break;
>   case 0x4001:/* KVM hypervisor features */
> + case 0x4101:
>   *rax = (1 << KVM_FEATURE_CLOCKSOURCE2) |
>   (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT);
>   *rbx = 0;
> Index: sys/arch/amd64/include/vmmvar.h
> ===
> RCS file: /cvs/src/sys/arch/amd64/include/vmmvar.h,v
> retrieving revision 1.66
> diff -u -p -r1.66 vmmvar.h
> --- sys/arch/amd64/include/vmmvar.h   17 May 2019 19:07:16 -1.66
> +++ sys/arch/amd64/include/vmmvar.h   27 May 2019 09:44:07 -
> @@ -22,6 +22,7 @@
> #define _MACHINE_VMMVAR_H_
> 
> #define VMM_HV_SIGNATURE  "OpenBSDVMM58"
> +#define KVM_HV_SIGNATURE "KVMKVMKVM\0\0\0"
> 
> #define VMM_MAX_MEM_RANGES16
> #define VMM_MAX_DISKS_PER_VM  4
> Index: sys/arch/i386/include/vmmvar.h
> ===
> RCS file: /cvs/src/sys/arch/i386/include/vmmvar.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 vmmvar.h
> --- sys/arch/i386/include/vmmvar.h18 Jan 2019 01:34:50 -1.19
> +++ sys/arch/i386/include/vmmvar.h27 May 2019 09:44:07 -
> @@ -15,3 +15,4 @@
>  */
> 
> #define VMM_HV_SIGNATURE  "OpenBSDVMM58"
> +#define KVM_HV_SIGNATURE "KVMKVMKVM\0\0\0"
> Index: sys/dev/pv/pvbus.c
> ===
> RCS file: /cvs/src/sys/dev/pv/pvbus.c,v
> retrieving revision 1.19
> diff -u -p -r1.19 pvbus.c
> --- sys/dev/pv/pvbus.c13 May 2019 15:40:34 -  1.19
> +++ sys/dev/pv/pvbus.c27 May 2019 09:44:08 -
> @@ -85,7 +85,7 @@ struct pvbus_type {
>   void(*init)(struct pvbus_hv *);
>   void(*print)(struct pvbus_hv *);
> } pvbus_types[PVBUS_MAX] = {
> - { "KVMKVMKVM\0\0\0","KVM",  pvbus_kvm },
> + { KVM_HV_SIGNATURE, "KVM",  pvbus_kvm },
>   { "Microsoft Hv",   "Hyper-V", pvbus_hyperv, pvbus_hyperv_print },
>   { "VMwareVMware",   "VMware" },
>   { "XenVMMXenVMM",   "Xen",  pvbus_xen, pvbus_xen_print },
> 
> 
> -- 
> Renato Aguiar
> 



Attach kvm-clock to Linux guests on VMM

2019-05-27 Thread Renato Aguiar

Hi,

The following patch makes Linux guests use kvm-clock by setting 
KVM's CPUID signature on VMM:


Index: sys/arch/amd64/amd64/vmm.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/vmm.c,v
retrieving revision 1.245
diff -u -p -r1.245 vmm.c
--- sys/arch/amd64/amd64/vmm.c	17 May 2019 19:07:15 - 
   1.245

+++ sys/arch/amd64/amd64/vmm.c  27 May 2019 09:44:07 -
@@ -238,6 +238,7 @@ extern uint64_t tsc_frequency;
extern int tsc_is_invariant;

const char *vmm_hv_signature = VMM_HV_SIGNATURE;
+const char *kvm_hv_signature = KVM_HV_SIGNATURE;

const struct kmem_pa_mode vmm_kp_contig = {
.kp_constraint = _constraint,
@@ -6433,7 +6434,14 @@ vmm_handle_cpuid(struct vcpu *vcpu)
*rcx = *((uint32_t *)_hv_signature[4]);
*rdx = *((uint32_t *)_hv_signature[8]);
break;
+   case 0x4100:/* KVM CPUID signature */
+   *rax = 0;
+   *rbx = *((uint32_t *)_hv_signature[0]);
+   *rcx = *((uint32_t *)_hv_signature[4]);
+   *rdx = *((uint32_t *)_hv_signature[8]);
+   break;
case 0x4001:/* KVM hypervisor features */
+   case 0x4101:
*rax = (1 << KVM_FEATURE_CLOCKSOURCE2) |
(1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT);
*rbx = 0;
Index: sys/arch/amd64/include/vmmvar.h
===
RCS file: /cvs/src/sys/arch/amd64/include/vmmvar.h,v
retrieving revision 1.66
diff -u -p -r1.66 vmmvar.h
--- sys/arch/amd64/include/vmmvar.h	17 May 2019 19:07:16 - 
   1.66

+++ sys/arch/amd64/include/vmmvar.h 27 May 2019 09:44:07 -
@@ -22,6 +22,7 @@
#define _MACHINE_VMMVAR_H_

#define VMM_HV_SIGNATURE"OpenBSDVMM58"
+#define KVM_HV_SIGNATURE   "KVMKVMKVM\0\0\0"

#define VMM_MAX_MEM_RANGES  16
#define VMM_MAX_DISKS_PER_VM4
Index: sys/arch/i386/include/vmmvar.h
===
RCS file: /cvs/src/sys/arch/i386/include/vmmvar.h,v
retrieving revision 1.19
diff -u -p -r1.19 vmmvar.h
--- sys/arch/i386/include/vmmvar.h	18 Jan 2019 01:34:50 - 
   1.19

+++ sys/arch/i386/include/vmmvar.h  27 May 2019 09:44:07 -
@@ -15,3 +15,4 @@
 */

#define VMM_HV_SIGNATURE"OpenBSDVMM58"
+#define KVM_HV_SIGNATURE   "KVMKVMKVM\0\0\0"
Index: sys/dev/pv/pvbus.c
===
RCS file: /cvs/src/sys/dev/pv/pvbus.c,v
retrieving revision 1.19
diff -u -p -r1.19 pvbus.c
--- sys/dev/pv/pvbus.c  13 May 2019 15:40:34 -  1.19
+++ sys/dev/pv/pvbus.c  27 May 2019 09:44:08 -
@@ -85,7 +85,7 @@ struct pvbus_type {
void(*init)(struct pvbus_hv *);
void(*print)(struct pvbus_hv *);
} pvbus_types[PVBUS_MAX] = {
-   { "KVMKVMKVM\0\0\0",  "KVM",pvbus_kvm },
+   { KVM_HV_SIGNATURE, "KVM",pvbus_kvm },
	{ "Microsoft Hv",	"Hyper-V", pvbus_hyperv, 
pvbus_hyperv_print },

{ "VMwareVMware", "VMware" },
	{ "XenVMMXenVMM",	"Xen",	pvbus_xen, pvbus_xen_print 
},



--
Renato Aguiar