KVM: xen: update shared_info and vcpu_info handling
Subsystems (6)
Paul Durrant
maintainerv3 cover KVM: xen: update shared_info and vcpu_info handling
From: Paul Durrant <[email protected]>
Currently we treat the shared_info page as guest memory and the VMM informs KVM of its location using a GFN. However it is not guest memory as such; it's an overlay page. So we pointlessly invalidate and re-cache a mapping to the *same page* of memory every time the guest requests that shared_info be mapped into its address space. Let's avoid doing that by modifying the pfncache code to allow activation using a fixed userspace HVA as well as a GPA.
Also, if the guest does not hypercall to explicitly set a pointer to a vcpu_info in its own memory, the default vcpu_info embedded in the shared_info page should be used. At the moment the VMM has to set up a pointer to the structure explicitly (again treating it like it's in guest memory, despite being in an overlay page). Let's also avoid the need for that. We already have a cached mapping for the shared_info page so just use that directly by default.
Paul Durrant (13):
KVM: pfncache: add a map helper function
KVM: pfncache: add a mark-dirty helper
KVM: pfncache: add a helper to get the gpa
KVM: pfncache: base offset check on khva rather than gpa
KVM: pfncache: allow a cache to be activated with a fixed (userspace)
HVA
KVM: xen: allow shared_info to be mapped by fixed HVA
KVM: xen: prepare for using 'default' vcpu_info
KVM: xen: prevent vcpu_id from changing whilst shared_info is valid
KVM: xen: automatically use the vcpu_info embedded in shared_info
KVM: selftests / xen: set KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID
KVM: selftests / xen: map shared_info using HVA rather than GFN
KVM: selftests / xen: don't explicitly set the vcpu_info address
KVM: xen: advertize the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA capability
Documentation/virt/kvm/api.rst | 49 ++++-- arch/x86/include/asm/kvm_host.h | 4 + arch/x86/kvm/x86.c | 17 +-- arch/x86/kvm/xen.c | 139 +++++++++++++----- arch/x86/kvm/xen.h | 6 +- include/linux/kvm_host.h | 43 ++++++ include/linux/kvm_types.h | 3 +- include/uapi/linux/kvm.h | 6 +- .../selftests/kvm/x86_64/xen_shinfo_test.c | 75 ++++++++-- virt/kvm/pfncache.c | 129 +++++++++++----- 10 files changed, 360 insertions(+), 111 deletions(-)
---
Cc: "H. Peter Anvin" <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 1/13 KVM: pfncache: add a map helper function
From: Paul Durrant <[email protected]>
We have an unmap helper but mapping is open-coded. Arguably this is fine because mapping is done in only one place, hva_to_pfn_retry(), but adding the helper does make that function more readable.
No functional change intended.
---
Cc: David Woodhouse <[email protected]>
Cc: Paolo Bonzini <[email protected]>
--- virt/kvm/pfncache.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-)
virt/kvm/pfncache.c +25 -18
@@ -96,17 +96,28 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len) }EXPORT_SYMBOL_GPL (kvm_gpc_check); -static void gpc_unmap_khva (kvm_pfn_t pfn,void *khva) +static void *gpc_map (kvm_pfn_t pfn) +{ +if (pfn_valid (pfn)) +return kmap (pfn_to_page (pfn)); +#ifdef CONFIG_HAS_IOMEM + else + return memremap(pfn_to_hpa(pfn), PAGE_SIZE, MEMREMAP_WB); +#endif +} + +static void gpc_unmap (kvm_pfn_t pfn,void *khva) {/* Unmap the old pfn/page if it was mapped before. */ -if (!is_error_noslot_pfn (pfn) && khva) { -if (pfn_valid (pfn)) -kunmap (pfn_to_page (pfn)); +if (is_error_noslot_pfn (pfn) || !khva) +return ; + +if (pfn_valid (pfn)) +kunmap (pfn_to_page (pfn));#ifdef CONFIG_HAS_IOMEM - else -memunmap (khva ); + else +memunmap (khva );#endif - } }static inline bool mmu_notifier_retry_cache (struct kvm *kvm,unsigned long mmu_seq)
@@ -175,7 +186,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)* the existing mapping and didn't create a new one. */ if (new_khva != old_khva) -gpc_unmap_khva (new_pfn, new_khva); +gpc_unmap (new_pfn, new_khva);kvm_release_pfn_clean (new_pfn);
@@ -193,15 +204,11 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)* too must be done outside of gpc->lock! */ if (gpc->usage &KVM_HOST_USES_PFN ) { -if (new_pfn == gpc->pfn) { +if (new_pfn == gpc->pfn) new_khva = old_khva; - }else if (pfn_valid (new_pfn)) { - new_khva =kmap (pfn_to_page (new_pfn)); -#ifdef CONFIG_HAS_IOMEM - }else { - new_khva =memremap (pfn_to_hpa (new_pfn),PAGE_SIZE ,MEMREMAP_WB ); -#endif - } +else + new_khva =gpc_map (new_pfn); +if (!new_khva) {kvm_release_pfn_clean (new_pfn); goto out_error;
@@ -326,7 +333,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa,mutex_unlock (&gpc->refresh_lock);if (unmap_old) -gpc_unmap_khva (old_pfn, old_khva); +gpc_unmap (old_pfn, old_khva);return ret; }
@@ -412,7 +419,7 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc)list_del (&gpc->list);spin_unlock (&kvm->gpc_lock); -gpc_unmap_khva (old_pfn, old_khva); +gpc_unmap (old_pfn, old_khva); } }EXPORT_SYMBOL_GPL (kvm_gpc_deactivate);
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 2/13 KVM: pfncache: add a mark-dirty helper
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
At the moment pages are marked dirty by open-coded calls to mark_page_dirty_in_slot(), directly deferefencing the gpa and memslot from the cache. After a subsequent patch these may not always be set so add a helper now so that caller will protected from the need to know about this detail.
NOTE: Pages are now marked dirty while the cache lock is held. This is
to ensure that gpa and memslot are mutually consistent.
---
Cc: David Woodhouse <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
--- arch/x86/kvm/x86.c | 2 +- arch/x86/kvm/xen.c | 13 ++++++------- include/linux/kvm_host.h | 7 +++++++ virt/kvm/pfncache.c | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-)
arch/x86/kvm/x86.c +1 -1
@@ -3137,7 +3137,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, guest_hv_clock->version = ++vcpu->hv_clock.version; -mark_page_dirty_in_slot (v->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT ); +kvm_gpc_mark_dirty (gpc);read_unlock_irqrestore (&gpc->lock, flags);trace_kvm_pvclock_update (v->vcpu_id, &vcpu->hv_clock);
arch/x86/kvm/xen.c +6 -7
@@ -430,14 +430,13 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)smp_wmb (); } -if (user_len2) +if (user_len2) { +kvm_gpc_mark_dirty (gpc2);read_unlock (&gpc2->lock); + } +kvm_gpc_mark_dirty (gpc1);read_unlock_irqrestore (&gpc1->lock, flags); - -mark_page_dirty_in_slot (v->kvm, gpc1->memslot, gpc1->gpa >>PAGE_SHIFT ); -if (user_len2) -mark_page_dirty_in_slot (v->kvm, gpc2->memslot, gpc2->gpa >>PAGE_SHIFT ); }void kvm_xen_update_runstate (struct kvm_vcpu *v,int state)
@@ -543,13 +542,13 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) : "0" (evtchn_pending_sel32));WRITE_ONCE (vi->evtchn_upcall_pending,1 ); } + +kvm_gpc_mark_dirty (gpc);read_unlock_irqrestore (&gpc->lock, flags);/* For the per-vCPU lapic vector, deliver it as MSI. */ if (v->arch.xen.upcall_vector)kvm_xen_inject_vcpu_vector (v); - -mark_page_dirty_in_slot (v->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT ); }int __kvm_xen_has_interrupt (struct kvm_vcpu *v)
include/linux/kvm_host.h +7 -0
@@ -1367,6 +1367,13 @@ int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len);*/ void kvm_gpc_deactivate (struct gfn_to_pfn_cache *gpc); +/** +* kvm_gpc_mark_dirty - mark a cached page as dirty. +* +* @gpc: struct gfn_to_pfn_cache object. +*/ +void kvm_gpc_mark_dirty (struct gfn_to_pfn_cache *gpc); +void kvm_sigset_activate (struct kvm_vcpu *vcpu);void kvm_sigset_deactivate (struct kvm_vcpu *vcpu);
virt/kvm/pfncache.c +6 -0
@@ -386,6 +386,12 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) }EXPORT_SYMBOL_GPL (kvm_gpc_activate); +void kvm_gpc_mark_dirty (struct gfn_to_pfn_cache *gpc) +{ +mark_page_dirty_in_slot (gpc->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT ); +} +EXPORT_SYMBOL_GPL (kvm_gpc_mark_dirty); +void kvm_gpc_deactivate (struct gfn_to_pfn_cache *gpc) {struct kvm *kvm = gpc->kvm;
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 3/13 KVM: pfncache: add a helper to get the gpa
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
A subsequent patch will rename this field since it will become overloaded. To avoid churn in places that currently retrieve the gpa, add a helper for that purpose now.
No functional change intended.
---
Cc: David Woodhouse <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
--- arch/x86/kvm/xen.c | 15 ++++++++------- include/linux/kvm_host.h | 7 +++++++ virt/kvm/pfncache.c | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-)
arch/x86/kvm/xen.c +8 -7
@@ -261,8 +261,8 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)* alignment (and the 32-bit ABI doesn't align the 64-bit integers * anyway, even if the overall struct had been 64-bit aligned). */ -if ((gpc1->gpa & ~PAGE_MASK ) + user_len >=PAGE_SIZE ) { - user_len1 =PAGE_SIZE - (gpc1->gpa & ~PAGE_MASK ); +if ((kvm_gpc_gpa (gpc1) & ~PAGE_MASK ) + user_len >=PAGE_SIZE ) { + user_len1 =PAGE_SIZE - (kvm_gpc_gpa (gpc1) & ~PAGE_MASK ); user_len2 = user_len - user_len1; }else { user_len1 = user_len;
@@ -343,7 +343,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)* to the second page now because the guest changed to * 64-bit mode, the second GPC won't have been set up. */ -if (kvm_gpc_activate (gpc2, gpc1->gpa + user_len1, +if (kvm_gpc_activate (gpc2,kvm_gpc_gpa (gpc1) + user_len1, user_len2))return ;
@@ -677,7 +677,8 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)case KVM_XEN_ATTR_TYPE_SHARED_INFO :if (kvm->arch.xen.shinfo_cache.active) - data->u.shared_info.gfn =gpa_to_gfn (kvm->arch.xen.shinfo_cache.gpa); + data->u.shared_info.gfn = +gpa_to_gfn (kvm_gpc_gpa (&kvm->arch.xen.shinfo_cache));else data->u.shared_info.gfn =KVM_XEN_INVALID_GFN ; r =0 ;
@@ -955,7 +956,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)switch (data->type) {case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO :if (vcpu->arch.xen.vcpu_info_cache.active) - data->u.gpa = vcpu->arch.xen.vcpu_info_cache.gpa; + data->u.gpa =kvm_gpc_gpa (&vcpu->arch.xen.vcpu_info_cache);else data->u.gpa =KVM_XEN_INVALID_GPA ; r =0 ;
@@ -963,7 +964,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO :if (vcpu->arch.xen.vcpu_time_info_cache.active) - data->u.gpa = vcpu->arch.xen.vcpu_time_info_cache.gpa; + data->u.gpa =kvm_gpc_gpa (&vcpu->arch.xen.vcpu_time_info_cache);else data->u.gpa =KVM_XEN_INVALID_GPA ; r =0 ;
@@ -975,7 +976,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)break ; }if (vcpu->arch.xen.runstate_cache.active) { - data->u.gpa = vcpu->arch.xen.runstate_cache.gpa; + data->u.gpa =kvm_gpc_gpa (&vcpu->arch.xen.runstate_cache); r =0 ; }break ;
include/linux/kvm_host.h +7 -0
@@ -1374,6 +1374,13 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc);*/ void kvm_gpc_mark_dirty (struct gfn_to_pfn_cache *gpc); +/** +* kvm_gpc_gpa - retrieve the guest physical address of a cached mapping +* +* @gpc: struct gfn_to_pfn_cache object. +*/ +gpa_t kvm_gpc_gpa (struct gfn_to_pfn_cache *gpc); +void kvm_sigset_activate (struct kvm_vcpu *vcpu);void kvm_sigset_deactivate (struct kvm_vcpu *vcpu);
virt/kvm/pfncache.c +6 -0
@@ -386,6 +386,12 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) }EXPORT_SYMBOL_GPL (kvm_gpc_activate); +gpa_t kvm_gpc_gpa (struct gfn_to_pfn_cache *gpc) +{ +return gpc->gpa; +} +EXPORT_SYMBOL_GPL (kvm_gpc_gpa); +void kvm_gpc_mark_dirty (struct gfn_to_pfn_cache *gpc) {mark_page_dirty_in_slot (gpc->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT );
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 4/13 KVM: pfncache: base offset check on khva rather than gpa
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
After a subsequent patch, the gpa may not always be set whereas khva will (as long as the cache valid flag is also set).
No functional change intended.
---
Cc: David Woodhouse <[email protected]>
Cc: Paolo Bonzini <[email protected]>
--- virt/kvm/pfncache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
virt/kvm/pfncache.c +5 -2
@@ -83,15 +83,18 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)if (!gpc->active)return false; -if ((gpc->gpa & ~PAGE_MASK ) + len >PAGE_SIZE ) +if (gpc->generation != slots->generation)return false; -if (gpc->generation != slots->generation ||kvm_is_error_hva (gpc->uhva)) +if (kvm_is_error_hva (gpc->uhva))return false;if (!gpc->valid)return false; +if (offset_in_page (gpc->khva) + len >PAGE_SIZE ) +return false; +return true; }EXPORT_SYMBOL_GPL (kvm_gpc_check);
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 5/13 KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
Some cached pages may actually be overlays on guest memory that have a fixed HVA within the VMM. It's pointless to invalidate such cached mappings if the overlay is moved so allow a cache to be activated directly with the HVA to cater for such cases. A subsequent patch will make use of this facility.
---
Cc: Paolo Bonzini <[email protected]>
Cc: David Woodhouse <[email protected]>
--- include/linux/kvm_host.h | 29 ++++++++++++++++ include/linux/kvm_types.h | 3 +- virt/kvm/pfncache.c | 73 ++++++++++++++++++++++++++++----------- 3 files changed, 84 insertions(+), 21 deletions(-)
include/linux/kvm_host.h +29 -0
@@ -1321,6 +1321,22 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,*/ int kvm_gpc_activate (struct gfn_to_pfn_cache *gpc,gpa_t gpa,unsigned long len); +/** +* kvm_gpc_activate_hva - prepare a cached kernel mapping and HPA for a given HVA. +* +* @gpc: struct gfn_to_pfn_cache object. +* @hva: userspace virtual address to map. +* @len: sanity check; the range being access must fit a single page. +* +* @return: 0 for success. +* -EINVAL for a mapping which would cross a page boundary. +* -EFAULT for an untranslatable guest physical address. +* +* The semantics of this function are the same as those of kvm_gpc_activate(). It +* merely bypasses a layer of address translation. +*/ +int kvm_gpc_activate_hva (struct gfn_to_pfn_cache *gpc,unsigned long hva,unsigned long len); +/** * kvm_gpc_check - check validity of a gfn_to_pfn_cache. *
@@ -1378,9 +1394,22 @@ void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc);* kvm_gpc_gpa - retrieve the guest physical address of a cached mapping * * @gpc: struct gfn_to_pfn_cache object. +* +* @return: If the cache was activated with a fixed HVA then INVALID_GPA +* will be returned. */ gpa_t kvm_gpc_gpa (struct gfn_to_pfn_cache *gpc); +/** +* kvm_gpc_hva - retrieve the fixed host physical address of a cached mapping +* +* @gpc: struct gfn_to_pfn_cache object. +* +* @return: If the cache was activated with a guest physical address then +* 0 will be returned. +*/ +unsigned long kvm_gpc_hva (struct gfn_to_pfn_cache *gpc); +void kvm_sigset_activate (struct kvm_vcpu *vcpu);void kvm_sigset_deactivate (struct kvm_vcpu *vcpu);
include/linux/kvm_types.h +2 -1
@@ -64,7 +64,7 @@ struct gfn_to_hva_cache {struct gfn_to_pfn_cache {u64 generation; -gpa_t gpa; +u64 addr;unsigned long uhva;struct kvm_memory_slot *memslot;struct kvm *kvm;
@@ -77,6 +77,7 @@ struct gfn_to_pfn_cache {enum pfn_cache_usage usage;bool active;bool valid; +bool addr_is_gpa; };#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
virt/kvm/pfncache.c +53 -20
133 lines not on this page · raw message
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 6/13 KVM: xen: allow shared_info to be mapped by fixed HVA
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
The shared_info page is not guest memory as such. It is a dedicated page allocated by the VMM and overlaid onto guest memory in a GFN chosen by the guest. The guest may even request that shared_info be moved from one GFN to another, but the HVA is never going to change. Thus it makes much more sense to map the shared_info page in kernel once using this fixed HVA. Hence add a new KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA attribute type for this purpose and a KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag to advertize its availability. Don't actually advertize it yet though. That will be done in a subsequent patch, which will also add tests for the new attribute type.
Also update the KVM API documentation with the new attribute and also fix it up to consistently refer to 'shared_info' (with the underscore).
NOTE: The change of the kvm_xen_hvm_attr shared_info from struct to union
is technically an ABI change but it's entirely compatible with existing users.
---
Cc: David Woodhouse <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
v2:
- Define the new attribute and capability but don't advertize the capability yet.
- Add API documentation.
--- Documentation/virt/kvm/api.rst | 25 +++++++++++++++++++------ arch/x86/kvm/xen.c | 28 ++++++++++++++++++++++------ include/uapi/linux/kvm.h | 6 +++++- 3 files changed, 46 insertions(+), 13 deletions(-)
Documentation/virt/kvm/api.rst +19 -6
@@ -353,7 +353,7 @@ The bits in the dirty bitmap are cleared before the ioctl returns, unless KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information, see the description of the capability. -Note that the Xen shared info page, if configured, shall always be assumed +Note that the Xen shared_info page, if configured, shall always be assumed to be dirty. KVM will not explicitly mark it such.
@@ -5408,8 +5408,9 @@ KVM_PV_ASYNC_CLEANUP_PERFORM __u8 long_mode; __u8 vector; __u8 runstate_update_flag; - struct { + union { __u64 gfn; + __u64 hva; } shared_info; struct { __u32 send_port;
@@ -5437,10 +5438,10 @@ type values: KVM_XEN_ATTR_TYPE_LONG_MODE Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This - determines the layout of the shared info pages exposed to the VM. + determines the layout of the shared_info page exposed to the VM. KVM_XEN_ATTR_TYPE_SHARED_INFO - Sets the guest physical frame number at which the Xen "shared info" + Sets the guest physical frame number at which the Xen shared_info page resides. Note that although Xen places vcpu_info for the first 32 vCPUs in the shared_info page, KVM does not automatically do so and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
@@ -5449,7 +5450,7 @@ KVM_XEN_ATTR_TYPE_SHARED_INFO not be aware of the Xen CPU id which is used as the index into the vcpu_info[] array, so may know the correct default location. - Note that the shared info page may be constantly written to by KVM; + Note that the shared_info page may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts to a Xen guest, amongst other things. It is exempt from dirty tracking mechanisms — KVM will not explicitly mark the page as dirty each
@@ -5458,9 +5459,21 @@ KVM_XEN_ATTR_TYPE_SHARED_INFO any vCPU has been running or any event channel interrupts can be routed to the guest. - Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared info + Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared_info page. +KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA + If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the + Xen capabilities, then this attribute may be used to set the + userspace address at which the shared_info page resides, which + will always be fixed in the VMM regardless of where it is mapped + in guest physical address space. This attribute should be used in + preference to KVM_XEN_ATTR_TYPE_SHARED_INFO as it avoids + unnecessary invalidation of an internal cache when the page is + re-mapped in guest physcial address space. + + Setting the hva to zero will disable the shared_info page. + KVM_XEN_ATTR_TYPE_UPCALL_VECTOR Sets the exception vector used to deliver Xen event channel upcalls. This is the HVM-wide vector injected directly by the hypervisor
arch/x86/kvm/xen.c +22 -6
@@ -34,24 +34,27 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r);DEFINE_STATIC_KEY_DEFERRED_FALSE (kvm_xen_enabled,HZ ); -static int kvm_xen_shared_info_init (struct kvm *kvm,gfn_t gfn) +static int kvm_xen_shared_info_init (struct kvm *kvm,u64 addr,bool addr_is_gfn) {struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache;struct pvclock_wall_clock *wc; -gpa_t gpa =gfn_to_gpa (gfn);u32 *wc_sec_hi;u32 wc_version;u64 wall_nsec;int ret =0 ;int idx =srcu_read_lock (&kvm->srcu); -if (gfn ==KVM_XEN_INVALID_GFN ) { +if ((addr_is_gfn && addr ==KVM_XEN_INVALID_GFN ) || + (!addr_is_gfn && addr ==0 )) {kvm_gpc_deactivate (gpc); goto out; } do { - ret = kvm_gpc_activate(gpc, gpa, PAGE_SIZE); + if (addr_is_gfn) + ret = kvm_gpc_activate(gpc, gfn_to_gpa(addr), PAGE_SIZE); + else + ret = kvm_gpc_activate_hva(gpc, addr, PAGE_SIZE); if (ret) goto out;
@@ -604,7 +607,6 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) {int r = -ENOENT ; -switch (data->type) {case KVM_XEN_ATTR_TYPE_LONG_MODE :if (!IS_ENABLED (CONFIG_64BIT ) && data->u.long_mode) {
@@ -619,7 +621,13 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)case KVM_XEN_ATTR_TYPE_SHARED_INFO :mutex_lock (&kvm->arch.xen.xen_lock); - r =kvm_xen_shared_info_init (kvm, data->u.shared_info.gfn); + r =kvm_xen_shared_info_init (kvm, data->u.shared_info.gfn, true); +mutex_unlock (&kvm->arch.xen.xen_lock); +break ; + +case KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA : +mutex_lock (&kvm->arch.xen.xen_lock); + r =kvm_xen_shared_info_init (kvm, data->u.shared_info.hva, false);mutex_unlock (&kvm->arch.xen.xen_lock);break ;
@@ -684,6 +692,14 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) r =0 ;break ; +case KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA : +if (kvm->arch.xen.shinfo_cache.active) + data->u.shared_info.hva =kvm_gpc_hva (&kvm->arch.xen.shinfo_cache); +else + data->u.shared_info.hva =0 ; + r =0 ; +break ; +case KVM_XEN_ATTR_TYPE_UPCALL_VECTOR : data->u.vector = kvm->arch.xen.upcall_vector; r =0 ;
include/uapi/linux/kvm.h +5 -1
@@ -1282,6 +1282,7 @@ struct kvm_x86_mce {#define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)#define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5)#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6) +#define KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA (1 << 7)struct kvm_xen_hvm_config {__u32 flags;
@@ -1793,9 +1794,10 @@ struct kvm_xen_hvm_attr {__u8 long_mode;__u8 vector;__u8 runstate_update_flag; -struct { +union {__u64 gfn;#define KVM_XEN_INVALID_GFN ((__u64)-1) +__u64 hva; } shared_info;struct {__u32 send_port;
@@ -1837,6 +1839,8 @@ struct kvm_xen_hvm_attr {#define KVM_XEN_ATTR_TYPE_XEN_VERSION 0x4/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */ #define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG 0x5 +/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA */ +#define KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA 0x6/* Per-vCPU Xen attributes */ #define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr)
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 7/13 KVM: xen: prepare for using 'default' vcpu_info
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
The shared_info page contains an array of 32 vcpu_info structures which may be used by guests (with fewer than 32 vCPUs) if they don't explicitly register vcpu_info structures in their own memory, using a VCPUOP_register_vcpu_info hypercall.
Currently we rely on the VMM always registering vcpu_info structures, even if the guest doesn't make that hypercall, which is somewhat bogus as (as has been stated in the comment of a previous commit) the shared_info page is not guest memory.
Prepare to automatically use the vcpu_info info embedded in shared_info by default, by adding a get_vcpu_info_cache() helper function. This function also passes back an offset to be added to the cached khva. This is currently always zero since we're still relying on the current VMM behaviour. A subsequent patch will make proper use of it.
No functional change intended.
NOTE: To avoid leaking detail of the vcpu_info duality into the main
x86 code, a kvm_xen_guest_time_update() has also been added and use of this requires that kvm_setup_guest_pvclock() ceases to be a static function.
---
Cc: David Woodhouse <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
v2:
- Fix build warning.
--- arch/x86/include/asm/kvm_host.h | 4 +++ arch/x86/kvm/x86.c | 12 +++----- arch/x86/kvm/xen.c | 50 ++++++++++++++++++++++++++------- arch/x86/kvm/xen.h | 6 +++- 4 files changed, 53 insertions(+), 19 deletions(-)
arch/x86/include/asm/kvm_host.h +4 -0
@@ -2238,4 +2238,8 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages);*/ #define KVM_EXIT_HYPERCALL_MBZ GENMASK_ULL(31, 1) +void kvm_setup_guest_pvclock (struct kvm_vcpu *v, +struct gfn_to_pfn_cache *gpc, +unsigned int offset); +#endif /* _ASM_X86_KVM_HOST_H */
arch/x86/kvm/x86.c +4 -8
@@ -3094,9 +3094,9 @@ u64 get_kvmclock_ns(struct kvm *kvm)return data.clock; } -static void kvm_setup_guest_pvclock (struct kvm_vcpu *v, -struct gfn_to_pfn_cache *gpc, -unsigned int offset) +void kvm_setup_guest_pvclock (struct kvm_vcpu *v, +struct gfn_to_pfn_cache *gpc, +unsigned int offset) {struct kvm_vcpu_arch *vcpu = &v->arch;struct pvclock_vcpu_time_info *guest_hv_clock;
@@ -3232,11 +3232,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)if (vcpu->pv_time.active)kvm_setup_guest_pvclock (v, &vcpu->pv_time,0 ); -if (vcpu->xen.vcpu_info_cache.active) -kvm_setup_guest_pvclock (v, &vcpu->xen.vcpu_info_cache, - offsetof(struct compat_vcpu_info , time)); -if (vcpu->xen.vcpu_time_info_cache.active) -kvm_setup_guest_pvclock (v, &vcpu->xen.vcpu_time_info_cache,0 ); +kvm_xen_guest_time_update (v);kvm_hv_setup_tsc_page (v->kvm, &vcpu->hv_clock);return 0 ; }
arch/x86/kvm/xen.c +40 -10
124 lines not on this page · raw message
arch/x86/kvm/xen.h +5 -1
@@ -16,6 +16,7 @@extern struct static_key_false_deferred kvm_xen_enabled; +void kvm_xen_guest_time_update (struct kvm_vcpu *vcpu);int __kvm_xen_has_interrupt (struct kvm_vcpu *vcpu);void kvm_xen_inject_pending_events (struct kvm_vcpu *vcpu);int kvm_xen_vcpu_set_attr (struct kvm_vcpu *vcpu,struct kvm_xen_vcpu_attr *data);
@@ -52,7 +53,6 @@ static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm)static inline int kvm_xen_has_interrupt (struct kvm_vcpu *vcpu) {if (static_branch_unlikely (&kvm_xen_enabled.key) && - vcpu->arch.xen.vcpu_info_cache.active && vcpu->kvm->arch.xen.upcall_vector)return __kvm_xen_has_interrupt (vcpu);
@@ -80,6 +80,10 @@ static inline int kvm_xen_has_pending_timer(struct kvm_vcpu *vcpu)void kvm_xen_inject_timer_irqs (struct kvm_vcpu *vcpu);#else +static inline void kvm_xen_guest_time_update (struct kvm_vcpu *vcpu) +{ +} +static inline int kvm_xen_write_hypercall_page (struct kvm_vcpu *vcpu,u64 data) {return 1 ;
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 8/13 KVM: xen: prevent vcpu_id from changing whilst shared_info is valid
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
To further prepare for automatically using the vcpu_info structures embedded in the shared_info page, we need to ensure that the Xen vcpu_id cannot change under our feet. We can do this by simply returning -EBUSY to any attempt to modify the attribute while the shinfo_cache is active.
---
Cc: David Woodhouse <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]
v3:
- New in this version.
--- arch/x86/kvm/xen.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/xen.c +14 -4
@@ -752,6 +752,18 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)return r; } +static int kvm_xen_set_vcpu_id (struct kvm_vcpu *vcpu,unsigned int vcpu_id) +{ +struct kvm *kvm = vcpu->kvm; +struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache; + +if (gpc->active) +return -EBUSY ; + + vcpu->arch.xen.vcpu_id = vcpu_id; +return 0 ; +} +int kvm_xen_vcpu_set_attr (struct kvm_vcpu *vcpu,struct kvm_xen_vcpu_attr *data) {int idx, r = -ENOENT ;
@@ -941,10 +953,8 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)case KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID :if (data->u.vcpu_id >=KVM_MAX_VCPUS ) r = -EINVAL ; -else { - vcpu->arch.xen.vcpu_id = data->u.vcpu_id; - r =0 ; - } +else + r =kvm_xen_set_vcpu_id (vcpu, data->u.vcpu_id);break ;case KVM_XEN_VCPU_ATTR_TYPE_TIMER :
Signature · 1 line
2.39.2
Re: [PATCH v3 08/13] KVM: xen: prevent vcpu_id from changing whilst shared_info is valid
Quoted 8 lines · Paul Durrant
From: Paul Durrant <[email protected]>
To further prepare for automatically using the
vcpu_infostructures embedded in theshared_infopage, we need to ensure that the Xenvcpu_idcannot change under our feet. We can do this by simply returning-EBUSYto any attempt to modify the attribute while theshinfo_cacheis active.Signed-off-by Paul Durrant <[email protected]>
Makes sense. Wants explicitly mentioning in the documentation for KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID. If/when you did that,
Paul Durrant
maintainerPATCH v3 9/13 KVM: xen: automatically use the vcpu_info embedded in shared_info
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
The VMM should only need to set the KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO attribute in response to a VCPUOP_register_vcpu_info hypercall. We can handle the default case internally since we already know where the shared_info page is. Modify get_vcpu_info_cache() to pass back a pointer to the shared info pfn cache (and appropriate offset) for any of the first 32 vCPUs if the attribute has not been set.
A VMM will be able to determine whether it needs to set up default vcpu_info using the previously defined KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA Xen capability flag, which will be advertized in a subsequent patch.
Also update the KVM API documentation to describe the new behaviour.
---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: [email protected]
v3:
- Add a note to the API documentation discussing vcpu_info copying.
v2:
- Dispense with the KVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFO capability.
- Add API documentation.
--- Documentation/virt/kvm/api.rst | 22 +++++++++++++++------- arch/x86/kvm/xen.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-)
Documentation/virt/kvm/api.rst +15 -7
@@ -5442,13 +5442,7 @@ KVM_XEN_ATTR_TYPE_LONG_MODE KVM_XEN_ATTR_TYPE_SHARED_INFO Sets the guest physical frame number at which the Xen shared_info - page resides. Note that although Xen places vcpu_info for the first - 32 vCPUs in the shared_info page, KVM does not automatically do so - and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used - explicitly even when the vcpu_info for a given vCPU resides at the - "default" location in the shared_info page. This is because KVM may - not be aware of the Xen CPU id which is used as the index into the - vcpu_info[] array, so may know the correct default location. + page resides. Note that the shared_info page may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts to
@@ -5564,12 +5558,26 @@ type values: KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO Sets the guest physical address of the vcpu_info for a given vCPU. + The vcpu_info for the first 32 vCPUs defaults to the structures + embedded in the shared_info page. + + If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the + Xen capabilities then the VMM is not required to set this default + location; KVM will handle that internally. Otherwise this attribute + must be set for all vCPUs. + As with the shared_info page for the VM, the corresponding page may be dirtied at any time if event channel interrupt delivery is enabled, so userspace should always assume that the page is dirty without relying on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable the vcpu_info. + Note that, if the guest sets an explicit vcpu_info location in guest + memory then the VMM is expected to copy the content of the structure + embedded in the shared_info page to the new location. It is therefore + important that no event delivery is in progress at this time, otherwise + events may be missed. + KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO Sets the guest physical address of an additional pvclock structure for a given vCPU. This is typically used for guest vsyscall support.
arch/x86/kvm/xen.c +15 -0
@@ -491,6 +491,21 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v)static struct gfn_to_pfn_cache *get_vcpu_info_cache (struct kvm_vcpu *v,unsigned long *offset) { +if (!v->arch.xen.vcpu_info_cache.active && v->arch.xen.vcpu_id <MAX_VIRT_CPUS ) { +struct kvm *kvm = v->kvm; + +if (offset) { +if (IS_ENABLED (CONFIG_64BIT ) && kvm->arch.xen.long_mode) + *offset = offsetof(struct shared_info , + vcpu_info[v->arch.xen.vcpu_id]); +else + *offset = offsetof(struct compat_shared_info , + vcpu_info[v->arch.xen.vcpu_id]); + } + +return &kvm->arch.xen.shinfo_cache; + } +if (offset) *offset =0 ;
Signature · 1 line
2.39.2
David Woodhouse
maintainerRe: [PATCH v3 09/13] KVM: xen: automatically use the vcpu_info embedded in shared_info
Quoted 58 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The VMM should only need to set the
KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFOattribute in response to aVCPUOP_register_vcpu_infohypercall. We can handle the default case internally since we already know where theshared_infopage is. Modifyget_vcpu_info_cache()to pass back a pointer to the shared info pfn cache (and appropriate offset) for any of the first 32 vCPUs if the attribute has not been set.A VMM will be able to determine whether it needs to set up default
vcpu_infousing the previously definedKVM_XEN_HVM_CONFIG_SHARED_INFO_HVAXen capability flag, which will be advertized in a subsequent patch.Also update the KVM API documentation to describe the new behaviour.
Signed-off-by Paul Durrant <[email protected]>---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: [email protected]v3:
- Add a note to the API documentation discussingvcpu_infocopying.v2:
- Dispense with theKVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFOcapability.
- Add API documentation.
---
Documentation/virt/kvm/api.rst | 22 +++++++++++++++------- arch/x86/kvm/xen.c | 15 +++++++++++++++2 files changed, 30 insertions(+), 7 deletions(-)Documentation/virt/kvm/api.rst +0
-0@@ -5442,13 +5442,7 @@ KVM_XEN_ATTR_TYPE_LONG_MODE
KVM_XEN_ATTR_TYPE_SHARED_INFO
Sets the guest physical frame number at which the Xenshared_info- page resides. Note that although Xen placesvcpu_infofor the first - 32 vCPUs in theshared_infopage, KVM does not automatically do so - and instead requires thatKVM_XEN_VCPU_ATTR_TYPE_VCPU_INFObe used - explicitly even when thevcpu_infofor a given vCPU resides at the - "default" location in theshared_infopage. This is because KVM may - not be aware of the Xen CPU id which is used as the index into the - vcpu_info[] array, so may know the correct default location. + page resides.
Note that theshared_infopage may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts toDocumentation/virt/kvm/api.rst +0
-0@@ -5564,12 +5558,26 @@ type values:
Quoted 5 lines
KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
Sets the guest physical address of thevcpu_infofor a given vCPU. + Thevcpu_infofor the first 32 vCPUs defaults to the structures + embedded in theshared_infopage.
The above is true only if KVM has KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA. You kind of touch on that next, but perhaps the 'if the KVM_...' condition should be moved up?
Quoted 8 lines
+ If the
KVM_XEN_HVM_CONFIG_SHARED_INFO_HVAflag is also set in the + Xen capabilities then the VMM is not required to set this default + location; KVM will handle that internally. Otherwise this attribute + must be set for all vCPUs.
+
As with theshared_infopage for the VM, the corresponding page may be dirtied at any time if event channel interrupt delivery is enabled, so userspace should always assume that the page is dirty without relying
Quoted 9 lines
on dirty logging. Setting the gpa to
KVM_XEN_INVALID_GPAwill disable thevcpu_info.
+ Note that, if the guest sets an explicitvcpu_infolocation in guest + memory then the VMM is expected to copy the content of the structure + embedded in theshared_infopage to the new location. It is therefore + important that no event delivery is in progress at this time, otherwise + events may be missed.
That's difficult. It means tearing down all interrupts from passthrough devices which are mapped via PIRQs, and also all IPIs.
The IPI code *should* be able to fall back to just letting the VMM handle the hypercall in userspace. But PIRQs are harder. I'd be happier if our plan — handwavy though it may be — led to being able to use the existing slow path for delivering interrupts by just *invalidating* the cache. Maybe we *should* move the memcpy into the kernel, and let it lock *both* the shinfo and new vcpu_info caches while it's doing the copy? Given that that's the only valid transition, that shouldn't be so hard, should it?
Quoted 29 lines
KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
Sets the guest physical address of an additional pvclock structure for a given vCPU. This is typically used for guest vsyscall support.arch/x86/kvm/xen.c +0
-0@@ -491,6 +491,21 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v)
static structgfn_to_pfn_cache*get_vcpu_info_cache(structkvm_vcpu*v, unsigned long *offset) {
+ if (!v->arch.xen.vcpu_info_cache.active &&v->arch.xen.vcpu_id<MAX_VIRT_CPUS) { + struct kvm *kvm =v->kvm;arch/x86/kvm/xen.c +13
-0+ + if (offset) { + if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) + *offset = offsetof(struct shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + else + *offset = offsetof(struct compat_shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + } + + return &kvm->arch.xen.shinfo_cache; + } +if (offset)
*offset = 0;
Re: [PATCH v3 09/13] KVM: xen: automatically use the vcpu_info embedded in shared_info
Quoted 87 lines · David Woodhouse
Quoted 58 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The VMM should only need to set the
KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFOattribute in response to aVCPUOP_register_vcpu_infohypercall. We can handle the default case internally since we already know where theshared_infopage is. Modifyget_vcpu_info_cache()to pass back a pointer to the shared info pfn cache (and appropriate offset) for any of the first 32 vCPUs if the attribute has not been set.A VMM will be able to determine whether it needs to set up default
vcpu_infousing the previously definedKVM_XEN_HVM_CONFIG_SHARED_INFO_HVAXen capability flag, which will be advertized in a subsequent patch.Also update the KVM API documentation to describe the new behaviour.
Signed-off-by Paul Durrant <[email protected]>---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: [email protected]v3:
- Add a note to the API documentation discussingvcpu_infocopying.v2:
- Dispense with theKVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFOcapability.
- Add API documentation.--- Documentation/virt/kvm/api.rst | 22 +++++++++++++++------- arch/x86/kvm/xen.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-)Documentation/virt/kvm/api.rst +1
-7@@ -5442,13 +5442,7 @@ KVM_XEN_ATTR_TYPE_LONG_MODE KVM_XEN_ATTR_TYPE_SHARED_INFO Sets the guest physical frame number at which the Xen shared_info - page resides. Note that although Xen places vcpu_info for the first - 32 vCPUs in the shared_info page, KVM does not automatically do so - and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used - explicitly even when the vcpu_info for a given vCPU resides at the - "default" location in the shared_info page. This is because KVM may - not be aware of the Xen CPU id which is used as the index into the - vcpu_info[] array, so may know the correct default location. + page resides. Note that the shared_info page may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts toDocumentation/virt/kvm/api.rst type values: · line 5562
Quoted 5 lines
Documentation/virt/kvm/api.rst +2
-0@@ -5564,12 +5558,26 @@ type values: KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO Sets the guest physical address of the vcpu_info for a given vCPU. + The vcpu_info for the first 32 vCPUs defaults to the structures + embedded in the shared_info page.The above is true only if KVM has
KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA. You kind of touch on that next, but perhaps the 'if theKVM_...' condition should be moved up?Quoted 7 lines
Documentation/virt/kvm/api.rst +5
-0+ If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the + Xen capabilities then the VMM is not required to set this default + location; KVM will handle that internally. Otherwise this attribute + must be set for all vCPUs. + As with the shared_info page for the VM, the corresponding page may be dirtied at any time if event channel interrupt delivery is enabled, soDocumentation/virt/kvm/api.rst type values:
Quoted 10 lines
Documentation/virt/kvm/api.rst +5
-0userspace should always assume that the page is dirty without relying on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable the vcpu_info. + Note that, if the guest sets an explicit vcpu_info location in guest + memory then the VMM is expected to copy the content of the structure + embedded in the shared_info page to the new location. It is therefore + important that no event delivery is in progress at this time, otherwise + events may be missed.
Quoted 2 lines
That's difficult. It means tearing down all interrupts from passthrough devices which are mapped via PIRQs, and also all IPIs.
So those don't honour event channel masking? That seems like a problem.
Quoted 10 lines
The IPI code *should* be able to fall back to just letting the VMM handle the hypercall in userspace. But PIRQs are harder. I'd be happier if our plan — handwavy though it may be — led to being able to use the existing slow path for delivering interrupts by just *invalidating* the cache. Maybe we *should* move the memcpy into the kernel, and let it lock *both* the shinfo and new
vcpu_infocaches while it's doing the copy? Given that that's the only valid transition, that shouldn't be so hard, should it?
No, it just kind of oversteps the remit of the attribute... but I'll try adding it and see how messy it gets.
Paul
Quoted 30 lines
Quoted 29 lines
Documentation/virt/kvm/api.rst +0
-0KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO Sets the guest physical address of an additional pvclock structure for a given vCPU. This is typically used for guest vsyscall support.arch/x86/kvm/xen.c +15
-0@@ -491,6 +491,21 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v) static struct gfn_to_pfn_cache *get_vcpu_info_cache(struct kvm_vcpu *v, unsigned long *offset) { + if (!v->arch.xen.vcpu_info_cache.active && v->arch.xen.vcpu_id < MAX_VIRT_CPUS) { + struct kvm *kvm = v->kvm; + + if (offset) { + if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) + *offset = offsetof(struct shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + else + *offset = offsetof(struct compat_shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + } + + return &kvm->arch.xen.shinfo_cache; + } + if (offset) *offset = 0;
David Woodhouse
maintainerRe: [PATCH v3 09/13] KVM: xen: automatically use the vcpu_info embedded in shared_info
Quoted 11 lines · Paul Durrant
Quoted 9 lines
Quoted 6 lines
+ Note that, if the guest sets an explicit
vcpu_infolocation in guest + memory then the VMM is expected to copy the content of the structure + embedded in theshared_infopage to the new location. It is therefore + important that no event delivery is in progress at this time, otherwise + events may be missed.That's difficult. It means tearing down all interrupts from passthrough devices which are mapped via PIRQs, and also all IPIs.
So those don't honour event channel masking? That seems like a problem.
Oh, *mask*. Sure, it does honour masking. But... that would mean the VMM has to keep track of which ports were *really* masked by the guest, and which ones were just masked for the switchover. Including if the guest does some mask/unmask activity *while* the switchover is happening (or locking to prevent such). I still don't think that's a kind thing to be telling the VMMs they need to do.
Quoted 11 lines
Quoted 10 lines
The IPI code *should* be able to fall back to just letting the VMM handle the hypercall in userspace. But PIRQs are harder. I'd be happier if our plan — handwavy though it may be — led to being able to use the existing slow path for delivering interrupts by just *invalidating* the cache. Maybe we *should* move the memcpy into the kernel, and let it lock *both* the shinfo and new
vcpu_infocaches while it's doing the copy? Given that that's the only valid transition, that shouldn't be so hard, should it?
Quoted 2 lines
No, it just kind of oversteps the remit of the attribute... but I'll try adding it and see how messy it gets.
Well, there's a reason I left all the vcpu_info address magic in userspace in the first place. It was there in João's original patches and I ripped it all out.
But I see your logic for wanting to put it back; I suspect moving the memcpy too is part of the cost of that? Should work out OK, I think.
Paul Durrant
maintainerPATCH v3 10/13 KVM: selftests / xen: set KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
If the capability (KVM_XEN_HVM_CONFIG_EVTCHN_SEND) is present then set the guest's vCPU id to match the chosen vcpu_info offset.
Also make some cosmetic fixes to the code for clarity.
---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: David Woodhouse <[email protected]>
v3:
- Remame VCPU_ID to XEN_VCPU_ID.
- Set vcpu_id before the shared_info page is set.
v2:
- New in this version.
--- .../selftests/kvm/x86_64/xen_shinfo_test.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +15 -4
@@ -38,6 +38,8 @@#define VCPU_INFO_VADDR (SHINFO_REGION_GVA + 0x40)#define RUNSTATE_VADDR (SHINFO_REGION_GVA + PAGE_SIZE + PAGE_SIZE - 15) +#define XEN_VCPU_ID 1/* Must correspond to offset of VCPU_INFO_[V]ADDR */ +#define EVTCHN_VECTOR 0x10#define EVTCHN_TEST1 15
@@ -410,7 +412,7 @@ static void *juggle_shinfo_state(void *arg)struct kvm_xen_hvm_attr cache_activate = { .type =KVM_XEN_ATTR_TYPE_SHARED_INFO , - .u.shared_info.gfn =SHINFO_REGION_GPA /PAGE_SIZE + .u.shared_info.gfn =SHINFO_ADDR /PAGE_SIZE };struct kvm_xen_hvm_attr cache_deactivate = {
@@ -446,6 +448,7 @@ int main(int argc, char *argv[])bool do_runstate_flag = !!(xen_caps &KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG );bool do_eventfd_tests = !!(xen_caps &KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL );bool do_evtchn_tests = do_eventfd_tests && !!(xen_caps &KVM_XEN_HVM_CONFIG_EVTCHN_SEND ); +bool has_vcpu_id = !!(xen_caps &KVM_XEN_HVM_CONFIG_EVTCHN_SEND );clock_gettime (CLOCK_REALTIME , &min_ts);
@@ -492,9 +495,17 @@ int main(int argc, char *argv[]) "Failed to read back RUNSTATE_UPDATE_FLAG attr"); } +if (has_vcpu_id) { +struct kvm_xen_vcpu_attr vid = { + .type =KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID , + .u.vcpu_id =XEN_VCPU_ID , + }; +vcpu_ioctl (vcpu,KVM_XEN_VCPU_SET_ATTR , &vid); + } +struct kvm_xen_hvm_attr ha = { .type =KVM_XEN_ATTR_TYPE_SHARED_INFO , - .u.shared_info.gfn =SHINFO_REGION_GPA /PAGE_SIZE , + .u.shared_info.gfn =SHINFO_ADDR /PAGE_SIZE , };vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &ha);
@@ -983,8 +994,8 @@ int main(int argc, char *argv[])struct pvclock_wall_clock *wc;struct pvclock_vcpu_time_info *ti, *ti2; - wc =addr_gpa2hva (vm,SHINFO_REGION_GPA +0xc00 ); - ti =addr_gpa2hva (vm,SHINFO_REGION_GPA +0x40 +0x20 ); + wc =addr_gpa2hva (vm,SHINFO_ADDR +0xc00 ); + ti =addr_gpa2hva (vm,VCPU_INFO_ADDR +0x20 ); ti2 =addr_gpa2hva (vm,PVTIME_ADDR );if (verbose) {
Signature · 1 line
2.39.2
Paul Durrant
maintainerPATCH v3 11/13 KVM: selftests / xen: map shared_info using HVA rather than GFN
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
Using the HVA of the shared_info page is more efficient, so if the capability (KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) is present use that method to do the mapping.
NOTE: Have the juggle_shinfo_state() thread map and unmap using both
GFN and HVA, to make sure the older mechanism is not broken.
---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: David Woodhouse <[email protected]>
v3:
- Re-work the juggle_shinfo_state() thread
v2:
- New in this version.
--- .../selftests/kvm/x86_64/xen_shinfo_test.c | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-)
tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +35 -9
@@ -395,6 +395,7 @@ static int cmp_timespec(struct timespec *a, struct timespec *b)return 0 ; } +static struct shared_info *shinfo;static struct vcpu_info *vinfo;static struct kvm_vcpu *vcpu;
@@ -410,20 +411,38 @@ static void *juggle_shinfo_state(void *arg) {struct kvm_vm *vm = (struct kvm_vm *)arg; -struct kvm_xen_hvm_attr cache_activate = { +struct kvm_xen_hvm_attr cache_activate_gfn = { .type =KVM_XEN_ATTR_TYPE_SHARED_INFO , .u.shared_info.gfn =SHINFO_ADDR /PAGE_SIZE }; -struct kvm_xen_hvm_attr cache_deactivate = { +struct kvm_xen_hvm_attr cache_deactivate_gfn = { .type =KVM_XEN_ATTR_TYPE_SHARED_INFO , .u.shared_info.gfn =KVM_XEN_INVALID_GFN }; +struct kvm_xen_hvm_attr cache_activate_hva = { + .type =KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA , + .u.shared_info.hva = (unsigned long )shinfo + }; + +struct kvm_xen_hvm_attr cache_deactivate_hva = { + .type =KVM_XEN_ATTR_TYPE_SHARED_INFO , + .u.shared_info.hva =0 + }; + +int xen_caps =kvm_check_cap (KVM_CAP_XEN_HVM ); +for (;;) { -__vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &cache_activate); -__vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &cache_deactivate); +__vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &cache_activate_gfn);pthread_testcancel (); +__vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &cache_deactivate_gfn); + +if (xen_caps &KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA ) { +__vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &cache_activate_hva); +pthread_testcancel (); +__vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &cache_deactivate_hva); + } }return NULL ;
@@ -449,6 +468,7 @@ int main(int argc, char *argv[])bool do_eventfd_tests = !!(xen_caps &KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL );bool do_evtchn_tests = do_eventfd_tests && !!(xen_caps &KVM_XEN_HVM_CONFIG_EVTCHN_SEND );bool has_vcpu_id = !!(xen_caps &KVM_XEN_HVM_CONFIG_EVTCHN_SEND ); +bool has_shinfo_hva = !!(xen_caps &KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA );clock_gettime (CLOCK_REALTIME , &min_ts);
@@ -459,7 +479,7 @@ int main(int argc, char *argv[]) SHINFO_REGION_GPA, SHINFO_REGION_SLOT, 3, 0);virt_map (vm,SHINFO_REGION_GVA ,SHINFO_REGION_GPA ,3 ); -struct shared_info *shinfo =addr_gpa2hva (vm,SHINFO_VADDR ); + shinfo =addr_gpa2hva (vm,SHINFO_VADDR );int zero_fd =open ("/dev/zero" ,O_RDONLY );TEST_ASSERT (zero_fd !=-1 ,"Failed to open /dev/zero" );
@@ -503,10 +523,16 @@ int main(int argc, char *argv[])vcpu_ioctl (vcpu,KVM_XEN_VCPU_SET_ATTR , &vid); } -struct kvm_xen_hvm_attr ha = { - .type =KVM_XEN_ATTR_TYPE_SHARED_INFO , - .u.shared_info.gfn =SHINFO_ADDR /PAGE_SIZE , - }; +struct kvm_xen_hvm_attr ha = {}; + +if (has_shinfo_hva) { + ha.type =KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA ; + ha.u.shared_info.hva = (unsigned long )shinfo; + }else { + ha.type =KVM_XEN_ATTR_TYPE_SHARED_INFO ; + ha.u.shared_info.gfn =SHINFO_ADDR /PAGE_SIZE ; + } +vm_ioctl (vm,KVM_XEN_HVM_SET_ATTR , &ha);/*
Signature · 1 line
2.39.2
Re: [PATCH v3 11/13] KVM: selftests / xen: map shared_info using HVA rather than GFN
Quoted 15 lines · Paul Durrant
for (;;) {
- __vm_ioctl(vm,KVM_XEN_HVM_SET_ATTR,&cache_activate); - __vm_ioctl(vm,KVM_XEN_HVM_SET_ATTR,&cache_deactivate); + __vm_ioctl(vm,KVM_XEN_HVM_SET_ATTR,&cache_activate_gfn);pthread_testcancel();
+ __vm_ioctl(vm,KVM_XEN_HVM_SET_ATTR,&cache_deactivate_gfn); +
+ if (xen_caps&KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) {
+ __vm_ioctl(vm,KVM_XEN_HVM_SET_ATTR,&cache_activate_hva); + pthread_testcancel();
+ __vm_ioctl(vm,KVM_XEN_HVM_SET_ATTR,&cache_deactivate_hva); + }
}
So now the loop starts by activating it in GFN mode even if it was already activated in HVA mode. Is that something we should even allow? I suppose it doesn't hurt.
And it *may* leave it activated in either HVA or GFN mode.
Are both deactivate modes equivalent? I think they are, aren't they?
So it could be...
for (;;) {
__vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_deactivate); __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_activate);
if (xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) {
__vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_deactivate_hva);
__vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_activate_hva);
}
pthread_testcancel();}
But that's just nitpicking, I suppose.
Paul Durrant
maintainerPATCH v3 12/13 KVM: selftests / xen: don't explicitly set the vcpu_info address
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
If the vCPU id is set and the shared_info is mapped using HVA then we can infer that KVM has the ability to use a default vcpu_info mapping. Hence we can stop setting the address of the vcpu_info structure.
NOTE: We still explicitly set vcpu_info half way through testing (to point
at exactly the place it already is) to make sure that setting the attribute does not fail.
---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: David Woodhouse <[email protected]>
v3:
- Add a guest sync point to set the vcpu_info attribute
v2:
- New in this version.
--- .../testing/selftests/kvm/x86_64/xen_shinfo_test.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +13 -1
@@ -68,6 +68,7 @@ enum {TEST_POLL_TIMEOUT ,TEST_POLL_MASKED ,TEST_POLL_WAKE , +SET_VCPU_INFO ,TEST_TIMER_PAST ,TEST_LOCKING_SEND_RACE , TEST_LOCKING_POLL_RACE,
@@ -327,6 +328,10 @@ static void guest_code(void)GUEST_SYNC (TEST_POLL_WAKE ); +/* Set the vcpu_info to point at exactly the place it already is to +* make sure the attribute is functional. */ +GUEST_SYNC (SET_VCPU_INFO ); +/* A timer wake an *unmasked* port which should wake us with an * actual interrupt, while we're polling on a different port. */ ports[0 ]++;
@@ -549,7 +554,10 @@ int main(int argc, char *argv[]) .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO, .u.gpa = VCPU_INFO_ADDR, }; -vcpu_ioctl (vcpu,KVM_XEN_VCPU_SET_ATTR , &vi); + +if (!has_vcpu_id || !has_shinfo_hva) { +vcpu_ioctl (vcpu,KVM_XEN_VCPU_SET_ATTR , &vi); + }struct kvm_xen_vcpu_attr pvclock = { .type =KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO ,
@@ -903,6 +911,10 @@ int main(int argc, char *argv[])alarm (1 );break ; +case SET_VCPU_INFO : +vcpu_ioctl (vcpu,KVM_XEN_VCPU_SET_ATTR , &vi); +break ; +case TEST_TIMER_PAST :TEST_ASSERT (!evtchn_irq_expected,"Expected event channel IRQ but it didn't happen" );
Signature · 1 line
2.39.2
Re: [PATCH v3 12/13] KVM: selftests / xen: don't explicitly set the vcpu_info address
Quoted 11 lines · Paul Durrant
From: Paul Durrant <[email protected]>
If the vCPU id is set and the
shared_infois mapped using HVA then we can infer that KVM has the ability to use a defaultvcpu_infomapping. Hence we can stop setting the address of thevcpu_infostructure.NOTE: We still explicitly set
vcpu_infohalf way through testing (to point at exactly the place it already is) to make sure that setting the attribute does not fail.Signed-off-by Paul Durrant <[email protected]>
Sean Christopherson
maintainerQuoted 10 lines · Paul Durrant
From: Paul Durrant <[email protected]>
Currently we treat the
shared_infopage as guest memory and the VMM informs KVM of its location using a GFN. However it is not guest memory as such; it's an overlay page. So we pointlessly invalidate and re-cache a mapping to the *same page* of memory every time the guest requests thatshared_infobe mapped into its address space. Let's avoid doing that by modifying the pfncache code to allow activation using a fixed userspace HVA as well as a GPA.
Quoted 7 lines
Also, if the guest does not hypercall to explicitly set a pointer to a
vcpu_infoin its own memory, the defaultvcpu_infoembedded in theshared_infopage should be used. At the moment the VMM has to set up a pointer to the structure explicitly (again treating it like it's in guest memory, despite being in an overlay page). Let's also avoid the need for that. We already have a cached mapping for theshared_infopage so just use that directly by default.
1. Please Cc me on *all* patches if you Cc me on one patch. I belive this is the preference of the vast majority of maintainers/reviewers/contributors. Having to go spelunking to find the rest of a series is annoying.
2. Wait a reasonable amount of time between posting versions. 1 hour is not reasonable. At an *absolute minimum*, wait 1 business day.
3. In the cover letter, summarize what's changed between versions. Lack of a summary exacerbates the problems from #1 and #2, e.g. I have a big pile of mails scattered across my mailboxes, and I am effectively forced to find and read them all if I want to have any clue as to why I have a 12 patch series on version 3 in less than two business days.
P.S. I very much appreciate that y'all are doing review publicly, thank you!
David Woodhouse
maintainerQuoted 23 lines · Sean Christopherson
Quoted 10 lines · Paul Durrant
From: Paul Durrant <[email protected]>
Currently we treat the
shared_infopage as guest memory and the VMM informs KVM of its location using a GFN. However it is not guest memory as such; it's an overlay page. So we pointlessly invalidate and re-cache a mapping to the *same page* of memory every time the guest requests thatshared_infobe mapped into its address space. Let's avoid doing that by modifying the pfncache code to allow activation using a fixed userspace HVA as well as a GPA.Quoted 7 lines
Also, if the guest does not hypercall to explicitly set a pointer to a
vcpu_infoin its own memory, the defaultvcpu_infoembedded in theshared_infopage should be used. At the moment the VMM has to set up a pointer to the structure explicitly (again treating it like it's in guest memory, despite being in an overlay page). Let's also avoid the need for that. We already have a cached mapping for theshared_infopage so just use that directly by default.1. Please Cc me on *all* patches if you Cc me on one patch. I belive this is the preference of the vast majority of maintainers/reviewers/contributors. Having to go spelunking to find the rest of a series is annoying.
Quoted 8 lines
2. Wait a reasonable amount of time between posting versions. 1 hour is not reasonable. At an *absolute minimum*, wait 1 business day.
3. In the cover letter, summarize what's changed between versions. Lack of a summary exacerbates the problems from #1 and #2, e.g. I have a big pile of mails scattered across my mailboxes, and I am effectively forced to find and read them all if I want to have any clue as to why I have a 12 patch series on version 3 in less than two business days.
I meant to mention that too.
Quoted 1 line
P.S. I very much appreciate that y'all are doing review publicly, thank you!
Well, to a certain extent you can't have both #2 and the P.S. Or at least doesn't work very well if we try.
Paul and I were literally sitting in the same room last Friday talking about this, and of course you saw the very first iteration of it on the mailing list rather than it being done in private and then presented as a fait accompli. We try to set that example for those around us.
(Just as you saw the very first attempt at the exit-on-hlt thing, and the lore.kernel.org link was what I gave to my engineers to tell them to see what happens if they try that.)
And there *are* going to be a couple of rounds of rapid review and adjustment as we start from scratch in the open, as I firmly believe that we should. I *want* to do it in public and I *want* you to be able to see it, but I don't necessarily think it works for us to *wait* for you. Maybe it makes more sense for you to dive deep into the details only after the rapid fire round has finished?
Unless you don't *want* those first rounds to be in public? But I don't think that's the right approach.
Suggestions welcome.
Maybe in this particular case given that I said something along the lines of "knock something up and let's see how I feel about it when I see it", it should be using an 'RFC' tag until I actually approve it? Not sure how to extrapolate that to the general case, mind you.
Sean Christopherson
maintainerQuoted 59 lines · David Woodhouse
Quoted 23 lines · Sean Christopherson
Quoted 10 lines · Paul Durrant
From: Paul Durrant <[email protected]>
Currently we treat the
shared_infopage as guest memory and the VMM informs KVM of its location using a GFN. However it is not guest memory as such; it's an overlay page. So we pointlessly invalidate and re-cache a mapping to the *same page* of memory every time the guest requests thatshared_infobe mapped into its address space. Let's avoid doing that by modifying the pfncache code to allow activation using a fixed userspace HVA as well as a GPA.Quoted 7 lines
Also, if the guest does not hypercall to explicitly set a pointer to a
vcpu_infoin its own memory, the defaultvcpu_infoembedded in theshared_infopage should be used. At the moment the VMM has to set up a pointer to the structure explicitly (again treating it like it's in guest memory, despite being in an overlay page). Let's also avoid the need for that. We already have a cached mapping for theshared_infopage so just use that directly by default.1. Please Cc me on *all* patches if you Cc me on one patch. I belive this is the preference of the vast majority of maintainers/reviewers/contributors. Having to go spelunking to find the rest of a series is annoying.
Quoted 8 lines
2. Wait a reasonable amount of time between posting versions. 1 hour is not reasonable. At an *absolute minimum*, wait 1 business day.
3. In the cover letter, summarize what's changed between versions. Lack of a summary exacerbates the problems from #1 and #2, e.g. I have a big pile of mails scattered across my mailboxes, and I am effectively forced to find and read them all if I want to have any clue as to why I have a 12 patch series on version 3 in less than two business days.
I meant to mention that too.
Quoted 1 line
P.S. I very much appreciate that y'all are doing review publicly, thank you!Well, to a certain extent you can't have both #2 and the
P.S. Or at least doesn't work very well if we try.Paul and I were literally sitting in the same room last Friday talking about this, and of course you saw the very first iteration of it on the mailing list rather than it being done in private and then presented as a fait accompli. We try to set that example for those around us.
(Just as you saw the very first attempt at the exit-on-hlt thing, and the lore.kernel.org link was what I gave to my engineers to tell them to see what happens if they try that.)
And there *are* going to be a couple of rounds of rapid review and adjustment as we start from scratch in the open, as I firmly believe that we should. I *want* to do it in public and I *want* you to be able to see it, but I don't necessarily think it works for us to *wait* for you. Maybe it makes more sense for you to dive deep into the details only after the rapid fire round has finished?
Unless you don't *want* those first rounds to be in public? But I don't think that's the right approach.
Quoted 6 lines
Suggestions welcome.
Maybe in this particular case given that I said something along the lines of "knock something up and let's see how I feel about it when I see it", it should be using an 'RFC' tag until I actually approve it? Not sure how to extrapolate that to the general case, mind you.
Tag them RFC, explain your expectations, goals, and intent in the cover letter, don't copy+paste cover letters verbatim between versions, and summarize the RFC(s) when you get to a point where you're ready for others to jump in. The cover letter is *identical* from v1=>v2=>v3, how is anyone supposed to understand what on earth is going on unless they happened to be in the same room as ya'll on Friday?
Doing rapid-fire, early review on beta-quality patches is totally fine, so long as it's clear that others can effectively ignore the early versions unless they are deeply interested or whatever.
A disclaimer at the top of the cover letter, e.g.
This series is a first attempt at an idea David had to improve performance of the pfncache when KVM is emulating Xen. David and I are still working out the details, it's probably not necessary for other folks to review this right now.
along with a summary of previous version and a transition from RFC => non-RFC makes it clear when I and others are expected to get involved.
In other words, use tags and the cover letter to communicate, don't just view the cover letter as a necessary evil to get people to care about your patches.
On 18/09/2023 18:12, Sean Christopherson wrote:
[snip]
Quoted 7 lines
Tag them RFC, explain your expectations, goals, and intent in the cover letter, don't copy+paste cover letters verbatim between versions, and summarize the RFC(s) when you get to a point where you're ready for others to jump in. The cover letter is *identical* from v1=>v2=>v3, how is anyone supposed to understand what on earth is going on unless they happened to be in the same room as ya'll on Friday?
The cover letter is indeed identical because the purpose of the series has not changed. Each individual patch has a commit comment summarizing what changed from version to version or whether it is new in a perticular version. I thought this would be enough for any reviewer to be able to see what is going on. In future I will also roll these up into the cover letter.
Quoted 12 lines
Doing rapid-fire, early review on beta-quality patches is totally fine, so long as it's clear that others can effectively ignore the early versions unless they are deeply interested or whatever.
A disclaimer at the top of the cover letter, e.g.
This series is a first attempt at an idea David had to improve performance of the pfncache when KVM is emulating Xen. David and I are still working out the details, it's probably not necessary for other folks to review this right now.
Quoted 5 lines
along with a summary of previous version and a transition from RFC => non-RFC makes it clear when I and others are expected to get involved.
In other words, use tags and the cover letter to communicate, don't just view the cover letter as a necessary evil to get people to care about your patches.
That was not the intention at all; I put all the detailed explanation in the commit comments because I thought that would make review *easier*.
Paul
Sean Christopherson
maintainerQuoted 10 lines · Paul Durrant
On 18/09/2023 18:12, Sean Christopherson wrote:
[snip]Quoted 7 lines
Tag them RFC, explain your expectations, goals, and intent in the cover letter, don't copy+paste cover letters verbatim between versions, and summarize the RFC(s) when you get to a point where you're ready for others to jump in. The cover letter is *identical* from v1=>v2=>v3, how is anyone supposed to understand what on earth is going on unless they happened to be in the same room as ya'll on Friday?
Quoted 2 lines
The cover letter is indeed identical because the purpose of the series has not changed.
For anything out of the ordinary, e.g. posting v3 just a few hours after v2 is definitely not normal, use the cover letter to call out why you're posting a particular version of the series, not just the purpose of the series.
Quoted 5 lines
Quoted 2 lines
In other words, use tags and the cover letter to communicate, don't just view the cover letter as a necessary evil to get people to care about your patches.
That was not the intention at all; I put all the detailed explanation in the commit comments because I thought that would make review *easier*.
Per-patch comments *might* make individual patches easier to review, but (for me at least) they are waaay less helpful for reviewing series as a whole, and all but usless for initial triage. E.g. for a situation like this where a series has reached v4 before I've so much as glanced at the patches, having the history in the cover letter allows me to catch up and get a feel for how the series got to v4 in ~20 seconds. With per-patch comments, I have to go find each comment and then piece together the bigger picture.
Per-patch comments also don't work well if a version makes minor changes to a large series (hunting through a 10+ patch series to figure out that only one patch changed is not exactly efficient), if a patch is dropped, if there are changes to the overall approach, etc.
Paul Durrant
maintainerPATCH v3 13/13 KVM: xen: advertize the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA capability
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
Now that all relevant kernel changes and selftests are in place, enable the new capability.
---
Cc: Sean Christopherson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: [email protected]
v2:
- New in this version.
--- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +2 -1
@@ -4527,7 +4527,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL |KVM_XEN_HVM_CONFIG_SHARED_INFO |KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL | -KVM_XEN_HVM_CONFIG_EVTCHN_SEND ; +KVM_XEN_HVM_CONFIG_EVTCHN_SEND | +KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA ;if (sched_info_on ()) r |=KVM_XEN_HVM_CONFIG_RUNSTATE |KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG ;
Signature · 1 line
2.39.2