Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 172314
b: refs/heads/master
c: afbcf7a
h: refs/heads/master
v: v3
  • Loading branch information
Glauber Costa authored and Avi Kivity committed Dec 3, 2009
1 parent 50dab41 commit e88f6a4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cd5a2685de4a642fd0bd763e8c19711ef08dbe27
refs/heads/master: afbcf7ab8d1bc8c2d04792f6d9e786e0adeb328d
36 changes: 36 additions & 0 deletions trunk/Documentation/kvm/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,42 @@ struct kvm_xen_hvm_config {
__u8 pad2[30];
};

4.27 KVM_GET_CLOCK

Capability: KVM_CAP_ADJUST_CLOCK
Architectures: x86
Type: vm ioctl
Parameters: struct kvm_clock_data (out)
Returns: 0 on success, -1 on error

Gets the current timestamp of kvmclock as seen by the current guest. In
conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
such as migration.

struct kvm_clock_data {
__u64 clock; /* kvmclock current value */
__u32 flags;
__u32 pad[9];
};

4.28 KVM_SET_CLOCK

Capability: KVM_CAP_ADJUST_CLOCK
Architectures: x86
Type: vm ioctl
Parameters: struct kvm_clock_data (in)
Returns: 0 on success, -1 on error

Sets the current timestamp of kvmclock to the valued specific in its parameter.
In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
such as migration.

struct kvm_clock_data {
__u64 clock; /* kvmclock current value */
__u32 flags;
__u32 pad[9];
};

5. The kvm_run structure

Application code obtains a pointer to the kvm_run structure by
Expand Down
1 change: 1 addition & 0 deletions trunk/arch/x86/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ struct kvm_arch{

unsigned long irq_sources_bitmap;
u64 vm_init_tsc;
s64 kvmclock_offset;

struct kvm_xen_hvm_config xen_hvm_config;
};
Expand Down
42 changes: 41 additions & 1 deletion trunk/arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ static void kvm_write_guest_time(struct kvm_vcpu *v)
/* With all the info we got, fill in the values */

vcpu->hv_clock.system_time = ts.tv_nsec +
(NSEC_PER_SEC * (u64)ts.tv_sec);
(NSEC_PER_SEC * (u64)ts.tv_sec) + v->kvm->arch.kvmclock_offset;

/*
* The interface expects us to write an even number signaling that the
* update is finished. Since the guest won't see the intermediate
Expand Down Expand Up @@ -1262,6 +1263,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_PIT_STATE2:
case KVM_CAP_SET_IDENTITY_MAP_ADDR:
case KVM_CAP_XEN_HVM:
case KVM_CAP_ADJUST_CLOCK:
r = 1;
break;
case KVM_CAP_COALESCED_MMIO:
Expand Down Expand Up @@ -2468,6 +2470,44 @@ long kvm_arch_vm_ioctl(struct file *filp,
r = 0;
break;
}
case KVM_SET_CLOCK: {
struct timespec now;
struct kvm_clock_data user_ns;
u64 now_ns;
s64 delta;

r = -EFAULT;
if (copy_from_user(&user_ns, argp, sizeof(user_ns)))
goto out;

r = -EINVAL;
if (user_ns.flags)
goto out;

r = 0;
ktime_get_ts(&now);
now_ns = timespec_to_ns(&now);
delta = user_ns.clock - now_ns;
kvm->arch.kvmclock_offset = delta;
break;
}
case KVM_GET_CLOCK: {
struct timespec now;
struct kvm_clock_data user_ns;
u64 now_ns;

ktime_get_ts(&now);
now_ns = timespec_to_ns(&now);
user_ns.clock = kvm->arch.kvmclock_offset + now_ns;
user_ns.flags = 0;

r = -EFAULT;
if (copy_to_user(argp, &user_ns, sizeof(user_ns)))
goto out;
r = 0;
break;
}

default:
;
}
Expand Down
10 changes: 10 additions & 0 deletions trunk/include/linux/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ struct kvm_ioeventfd {
#ifdef __KVM_HAVE_XEN_HVM
#define KVM_CAP_XEN_HVM 38
#endif
#define KVM_CAP_ADJUST_CLOCK 39

#ifdef KVM_CAP_IRQ_ROUTING

Expand Down Expand Up @@ -512,6 +513,12 @@ struct kvm_irqfd {
__u8 pad[20];
};

struct kvm_clock_data {
__u64 clock;
__u32 flags;
__u32 pad[9];
};

/*
* ioctls for VM fds
*/
Expand Down Expand Up @@ -562,6 +569,9 @@ struct kvm_irqfd {
#define KVM_SET_BOOT_CPU_ID _IO(KVMIO, 0x78)
#define KVM_IOEVENTFD _IOW(KVMIO, 0x79, struct kvm_ioeventfd)
#define KVM_XEN_HVM_CONFIG _IOW(KVMIO, 0x7a, struct kvm_xen_hvm_config)
#define KVM_SET_CLOCK _IOW(KVMIO, 0x7b, struct kvm_clock_data)
#define KVM_GET_CLOCK _IOR(KVMIO, 0x7c, struct kvm_clock_data)


/*
* ioctls for vcpu fds
Expand Down

0 comments on commit e88f6a4

Please sign in to comment.