public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls
@ 2014-11-07 14:55 Jason J. Herne
  2014-11-07 14:55 ` Jason J. Herne
  0 siblings, 1 reply; 5+ messages in thread
From: Jason J. Herne @ 2014-11-07 14:55 UTC (permalink / raw)
  To: kvm, borntraeger, cornelia.huck, aik, agraf, pbonzini; +Cc: Jason J. Herne

From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>

As discussed, v2 moves TOD set/get functions to the setone/getone interface.
A high byte is also provided to account for future expansion.

Jason J. Herne (1):
  kvm-s390: Provide guest TOD Clock Get/Set Controls

 arch/s390/include/uapi/asm/kvm.h |  2 ++
 arch/s390/kvm/kvm-s390.c         | 63 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)

-- 
1.8.3.2


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

* [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls
  2014-11-07 14:55 [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls Jason J. Herne
@ 2014-11-07 14:55 ` Jason J. Herne
  2014-11-07 15:06   ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Jason J. Herne @ 2014-11-07 14:55 UTC (permalink / raw)
  To: kvm, borntraeger, cornelia.huck, aik, agraf, pbonzini; +Cc: Jason J. Herne

From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>

Provide KVM_REG_S390_TOD and KVM_REG_S390_TOD_HIGH registers on s390 for
managing guest Time Of Day clock value.

KVM_REG_S390_TOD_HIGH is presently always set to 0. In the future it will
contain a high order expansion of the tod clock value after it overflows
the 64-bits of KVM_REG_S390_TOD.

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
---
 arch/s390/include/uapi/asm/kvm.h |  2 ++
 arch/s390/kvm/kvm-s390.c         | 63 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index 48eda3a..5578832 100644
--- a/arch/s390/include/uapi/asm/kvm.h
+++ b/arch/s390/include/uapi/asm/kvm.h
@@ -138,4 +138,6 @@ struct kvm_sync_regs {
 #define KVM_REG_S390_PFSELECT	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x7)
 #define KVM_REG_S390_PP		(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x8)
 #define KVM_REG_S390_GBEA	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x9)
+#define KVM_REG_S390_TOD	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0xA)
+#define KVM_REG_S390_TOD_HIGH	(KVM_REG_S390 | KVM_REG_SIZE_U8 | 0xB)
 #endif
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 55aade4..17e3d61 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -31,6 +31,7 @@
 #include <asm/switch_to.h>
 #include <asm/facility.h>
 #include <asm/sclp.h>
+#include<asm/timex.h>
 #include "kvm-s390.h"
 #include "gaccess.h"
 
@@ -788,10 +789,48 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
 	return 0;
 }
 
+static int kvm_s390_get_guest_tod(struct kvm_vcpu *vcpu, u64 *guest_tod)
+{
+	u64 host_tod;
+	int r;
+
+	r = store_tod_clock(&host_tod);
+	if (r)
+		return r;
+
+	*guest_tod = host_tod + vcpu->arch.sie_block->epoch;
+	return 0;
+}
+
+/*
+Set the guest's effective TOD clock to the given value. The guest's
+TOD clock is determined by the following formula: gtod = host_tod + epoch.
+NOTE: Even though the epoch value is associated with a vcpu, there is only
+one TOD clock and epoch value per guest.  All vcpu's epoch values must be kept
+synchronized.
+*/
+static int kvm_s390_set_guest_tod(struct kvm_vcpu *vcpu, u64 guest_tod)
+{
+	struct kvm_vcpu *cur_vcpu;
+	unsigned int vcpu_idx;
+	u64 host_tod;
+	int r;
+
+	r = store_tod_clock(&host_tod);
+	if (r)
+		return r;
+
+	kvm_for_each_vcpu(vcpu_idx, cur_vcpu, vcpu->kvm) {
+		cur_vcpu->arch.sie_block->epoch = guest_tod - host_tod;
+	}
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,
 					   struct kvm_one_reg *reg)
 {
 	int r = -EINVAL;
+	u64 gtod;
 
 	switch (reg->id) {
 	case KVM_REG_S390_TODPR:
@@ -830,6 +869,15 @@ static int kvm_arch_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,
 		r = put_user(vcpu->arch.sie_block->gbea,
 			     (u64 __user *)reg->addr);
 		break;
+	case KVM_REG_S390_TOD:
+		r = kvm_s390_get_guest_tod(vcpu, &gtod);
+		if (r)
+			break;
+		r = put_user(gtod, (u64 __user *)reg->addr);
+		break;
+	case KVM_REG_S390_TOD_HIGH:
+		r = put_user(0, (u8 __user *)reg->addr);
+		break;
 	default:
 		break;
 	}
@@ -841,6 +889,8 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 					   struct kvm_one_reg *reg)
 {
 	int r = -EINVAL;
+	u64 gtod;
+	u8 gtod_high;
 
 	switch (reg->id) {
 	case KVM_REG_S390_TODPR:
@@ -879,6 +929,19 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 		r = get_user(vcpu->arch.sie_block->gbea,
 			     (u64 __user *)reg->addr);
 		break;
+	case KVM_REG_S390_TOD:
+		r = get_user(gtod, (u64 __user *)reg->addr);
+		if (r)
+			break;
+		r = kvm_s390_set_guest_tod(vcpu, gtod);
+		break;
+	case KVM_REG_S390_TOD_HIGH:
+		r = get_user(gtod_high, (u8 __user *)reg->addr);
+		if (r)
+			break;
+		if (gtod_high != 0)
+			r = -EINVAL;
+		break;
 	default:
 		break;
 	}
-- 
1.8.3.2


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

* Re: [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls
  2014-11-07 14:55 ` Jason J. Herne
@ 2014-11-07 15:06   ` Paolo Bonzini
  2014-11-07 15:10     ` Christian Borntraeger
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2014-11-07 15:06 UTC (permalink / raw)
  To: Jason J. Herne, kvm, borntraeger, cornelia.huck, aik, agraf



On 07/11/2014 15:55, Jason J. Herne wrote:
> From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>
> 
> Provide KVM_REG_S390_TOD and KVM_REG_S390_TOD_HIGH registers on s390 for
> managing guest Time Of Day clock value.
> 
> KVM_REG_S390_TOD_HIGH is presently always set to 0. In the future it will
> contain a high order expansion of the tod clock value after it overflows
> the 64-bits of KVM_REG_S390_TOD.
> 
> Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
> ---
>  arch/s390/include/uapi/asm/kvm.h |  2 ++
>  arch/s390/kvm/kvm-s390.c         | 63 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 65 insertions(+)
> 
> diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
> index 48eda3a..5578832 100644
> --- a/arch/s390/include/uapi/asm/kvm.h
> +++ b/arch/s390/include/uapi/asm/kvm.h
> @@ -138,4 +138,6 @@ struct kvm_sync_regs {
>  #define KVM_REG_S390_PFSELECT	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x7)
>  #define KVM_REG_S390_PP		(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x8)
>  #define KVM_REG_S390_GBEA	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x9)
> +#define KVM_REG_S390_TOD	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0xA)
> +#define KVM_REG_S390_TOD_HIGH	(KVM_REG_S390 | KVM_REG_SIZE_U8 | 0xB)
>  #endif
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index 55aade4..17e3d61 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -31,6 +31,7 @@
>  #include <asm/switch_to.h>
>  #include <asm/facility.h>
>  #include <asm/sclp.h>
> +#include<asm/timex.h>
>  #include "kvm-s390.h"
>  #include "gaccess.h"
>  
> @@ -788,10 +789,48 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> +static int kvm_s390_get_guest_tod(struct kvm_vcpu *vcpu, u64 *guest_tod)
> +{
> +	u64 host_tod;
> +	int r;
> +
> +	r = store_tod_clock(&host_tod);
> +	if (r)
> +		return r;
> +
> +	*guest_tod = host_tod + vcpu->arch.sie_block->epoch;
> +	return 0;
> +}
> +
> +/*
> +Set the guest's effective TOD clock to the given value. The guest's
> +TOD clock is determined by the following formula: gtod = host_tod + epoch.
> +NOTE: Even though the epoch value is associated with a vcpu, there is only
> +one TOD clock and epoch value per guest.  All vcpu's epoch values must be kept
> +synchronized.
> +*/
> +static int kvm_s390_set_guest_tod(struct kvm_vcpu *vcpu, u64 guest_tod)
> +{
> +	struct kvm_vcpu *cur_vcpu;
> +	unsigned int vcpu_idx;
> +	u64 host_tod;
> +	int r;
> +
> +	r = store_tod_clock(&host_tod);
> +	if (r)
> +		return r;
> +
> +	kvm_for_each_vcpu(vcpu_idx, cur_vcpu, vcpu->kvm) {
> +		cur_vcpu->arch.sie_block->epoch = guest_tod - host_tod;
> +	}
> +	return 0;
> +}
> +
>  static int kvm_arch_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,
>  					   struct kvm_one_reg *reg)
>  {
>  	int r = -EINVAL;
> +	u64 gtod;
>  
>  	switch (reg->id) {
>  	case KVM_REG_S390_TODPR:
> @@ -830,6 +869,15 @@ static int kvm_arch_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,
>  		r = put_user(vcpu->arch.sie_block->gbea,
>  			     (u64 __user *)reg->addr);
>  		break;
> +	case KVM_REG_S390_TOD:
> +		r = kvm_s390_get_guest_tod(vcpu, &gtod);
> +		if (r)
> +			break;
> +		r = put_user(gtod, (u64 __user *)reg->addr);
> +		break;
> +	case KVM_REG_S390_TOD_HIGH:
> +		r = put_user(0, (u8 __user *)reg->addr);
> +		break;
>  	default:
>  		break;
>  	}
> @@ -841,6 +889,8 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>  					   struct kvm_one_reg *reg)
>  {
>  	int r = -EINVAL;
> +	u64 gtod;
> +	u8 gtod_high;
>  
>  	switch (reg->id) {
>  	case KVM_REG_S390_TODPR:
> @@ -879,6 +929,19 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>  		r = get_user(vcpu->arch.sie_block->gbea,
>  			     (u64 __user *)reg->addr);
>  		break;
> +	case KVM_REG_S390_TOD:
> +		r = get_user(gtod, (u64 __user *)reg->addr);
> +		if (r)
> +			break;
> +		r = kvm_s390_set_guest_tod(vcpu, gtod);
> +		break;
> +	case KVM_REG_S390_TOD_HIGH:
> +		r = get_user(gtod_high, (u8 __user *)reg->addr);
> +		if (r)
> +			break;
> +		if (gtod_high != 0)
> +			r = -EINVAL;
> +		break;
>  	default:
>  		break;
>  	}
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Thanks!

Paolo

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

* Re: [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls
  2014-11-07 15:06   ` Paolo Bonzini
@ 2014-11-07 15:10     ` Christian Borntraeger
  2014-11-07 15:19       ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Borntraeger @ 2014-11-07 15:10 UTC (permalink / raw)
  To: Paolo Bonzini, Jason J. Herne, kvm, cornelia.huck, aik, agraf

Am 07.11.2014 um 16:06 schrieb Paolo Bonzini:
> 
> 
> On 07/11/2014 15:55, Jason J. Herne wrote:
>> From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>
>>
>> Provide KVM_REG_S390_TOD and KVM_REG_S390_TOD_HIGH registers on s390 for
>> managing guest Time Of Day clock value.
>>
>> KVM_REG_S390_TOD_HIGH is presently always set to 0. In the future it will
>> contain a high order expansion of the tod clock value after it overflows
>> the 64-bits of KVM_REG_S390_TOD.
>>
>> Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
>> ---
>>  arch/s390/include/uapi/asm/kvm.h |  2 ++
>>  arch/s390/kvm/kvm-s390.c         | 63 ++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 65 insertions(+)
>>
>> diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
>> index 48eda3a..5578832 100644
>> --- a/arch/s390/include/uapi/asm/kvm.h
>> +++ b/arch/s390/include/uapi/asm/kvm.h
>> @@ -138,4 +138,6 @@ struct kvm_sync_regs {
>>  #define KVM_REG_S390_PFSELECT	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x7)
>>  #define KVM_REG_S390_PP		(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x8)
>>  #define KVM_REG_S390_GBEA	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x9)
>> +#define KVM_REG_S390_TOD	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0xA)
>> +#define KVM_REG_S390_TOD_HIGH	(KVM_REG_S390 | KVM_REG_SIZE_U8 | 0xB)
>>  #endif
>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index 55aade4..17e3d61 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -31,6 +31,7 @@
>>  #include <asm/switch_to.h>
>>  #include <asm/facility.h>
>>  #include <asm/sclp.h>
>> +#include<asm/timex.h>

Will apply with a small whitespace fix
[..]

> Acked-by: Paolo Bonzini <pbonzini@redhat.com>


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

* Re: [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls
  2014-11-07 15:10     ` Christian Borntraeger
@ 2014-11-07 15:19       ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2014-11-07 15:19 UTC (permalink / raw)
  To: Christian Borntraeger, Paolo Bonzini, Jason J. Herne, kvm,
	cornelia.huck, aik



On 07.11.14 16:10, Christian Borntraeger wrote:
> Am 07.11.2014 um 16:06 schrieb Paolo Bonzini:
>>
>>
>> On 07/11/2014 15:55, Jason J. Herne wrote:
>>> From: "Jason J. Herne" <jjherne@linux.vnet.ibm.com>
>>>
>>> Provide KVM_REG_S390_TOD and KVM_REG_S390_TOD_HIGH registers on s390 for
>>> managing guest Time Of Day clock value.
>>>
>>> KVM_REG_S390_TOD_HIGH is presently always set to 0. In the future it will
>>> contain a high order expansion of the tod clock value after it overflows
>>> the 64-bits of KVM_REG_S390_TOD.
>>>
>>> Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
>>> ---
>>>  arch/s390/include/uapi/asm/kvm.h |  2 ++
>>>  arch/s390/kvm/kvm-s390.c         | 63 ++++++++++++++++++++++++++++++++++++++++
>>>  2 files changed, 65 insertions(+)
>>>
>>> diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
>>> index 48eda3a..5578832 100644
>>> --- a/arch/s390/include/uapi/asm/kvm.h
>>> +++ b/arch/s390/include/uapi/asm/kvm.h
>>> @@ -138,4 +138,6 @@ struct kvm_sync_regs {
>>>  #define KVM_REG_S390_PFSELECT	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x7)
>>>  #define KVM_REG_S390_PP		(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x8)
>>>  #define KVM_REG_S390_GBEA	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x9)
>>> +#define KVM_REG_S390_TOD	(KVM_REG_S390 | KVM_REG_SIZE_U64 | 0xA)
>>> +#define KVM_REG_S390_TOD_HIGH	(KVM_REG_S390 | KVM_REG_SIZE_U8 | 0xB)
>>>  #endif
>>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>>> index 55aade4..17e3d61 100644
>>> --- a/arch/s390/kvm/kvm-s390.c
>>> +++ b/arch/s390/kvm/kvm-s390.c
>>> @@ -31,6 +31,7 @@
>>>  #include <asm/switch_to.h>
>>>  #include <asm/facility.h>
>>>  #include <asm/sclp.h>
>>> +#include<asm/timex.h>
> 
> Will apply with a small whitespace fix

Reviewed-by: Alexander Graf <agraf@suse.de>


Alex

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

end of thread, other threads:[~2014-11-07 15:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 14:55 [PATCH v2] kvm-s390: Provide guest TOD Clock Get/Set Controls Jason J. Herne
2014-11-07 14:55 ` Jason J. Herne
2014-11-07 15:06   ` Paolo Bonzini
2014-11-07 15:10     ` Christian Borntraeger
2014-11-07 15:19       ` Alexander Graf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox