Skip to content

Commit f2340cd

Browse files
jpemartinsdwmw2
authored andcommitted
KVM: x86/xen: register vcpu time info region
Allow the Xen emulated guest the ability to register secondary vcpu time information. On Xen guests this is used in order to be mapped to userspace and hence allow vdso gettimeofday to work. Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
1 parent aa096aa commit f2340cd

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎arch/x86/include/asm/kvm_host.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ struct kvm_vcpu_hv {
535535
struct kvm_vcpu_xen {
536536
u64 hypercall_rip;
537537
bool vcpu_info_set;
538+
bool vcpu_time_info_set;
538539
struct gfn_to_hva_cache vcpu_info_cache;
540+
struct gfn_to_hva_cache vcpu_time_info_cache;
539541
};
540542

541543
struct kvm_vcpu_arch {

‎arch/x86/kvm/x86.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,8 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
27572757
if (vcpu->xen.vcpu_info_set)
27582758
kvm_setup_pvclock_page(v, &vcpu->xen.vcpu_info_cache,
27592759
offsetof(struct compat_vcpu_info, time));
2760+
if (vcpu->xen.vcpu_time_info_set)
2761+
kvm_setup_pvclock_page(v, &vcpu->xen.vcpu_time_info_cache, 0);
27602762
if (v == kvm_get_vcpu(v->kvm, 0))
27612763
kvm_hv_setup_tsc_page(v->kvm, &vcpu->hv_clock);
27622764
return 0;

‎arch/x86/kvm/xen.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)
141141
}
142142
break;
143143

144+
case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO:
145+
r = kvm_gfn_to_hva_cache_init(vcpu->kvm,
146+
&vcpu->arch.xen.vcpu_time_info_cache,
147+
data->u.gpa,
148+
sizeof(struct pvclock_vcpu_time_info));
149+
if (!r) {
150+
vcpu->arch.xen.vcpu_time_info_set = true;
151+
kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
152+
}
153+
break;
154+
144155
default:
145156
break;
146157
}
@@ -164,6 +175,13 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)
164175
}
165176
break;
166177

178+
case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO:
179+
if (vcpu->arch.xen.vcpu_time_info_set) {
180+
data->u.gpa = vcpu->arch.xen.vcpu_time_info_cache.gpa;
181+
r = 0;
182+
}
183+
break;
184+
167185
default:
168186
break;
169187
}

‎include/uapi/linux/kvm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ struct kvm_xen_vcpu_attr {
16201620
};
16211621

16221622
#define KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO 0x0
1623+
#define KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO 0x1
16231624

16241625
/* Secure Encrypted Virtualization command */
16251626
enum sev_cmd_id {

0 commit comments

Comments
 (0)