On Tue, Feb 06, 2024, David Woodhouse wrote:
On Tue, 2024-02-06 at 20:03 -0800, Sean Christopherson wrote:
+s390 folks (question on kvm_is_error_gpa() for ya)
On Mon, Jan 15, 2024, Paul Durrant wrote:
@@ -1398,7 +1414,9 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc); static inline void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) { lockdep_assert_held(&gpc->lock); - mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);
+ if (gpc->gpa != KVM_XEN_INVALID_GPA)
KVM_XEN_INVALID_GPA absolutely doesn't belong in common code. Not to mention that it will break when Paolo (rightly) moves it to an x86 header.
https://lore.kernel.org/all/20240131233056.10845-3-pbonzini@redhat.com
We can use plain INVALID_GPA for that, I think. ISTR the reason we have a separate KVM_XEN_INVALID_GPA is because that's a userspace API.
...
But! kvm_is_error_gpa() already exists, and it very, very sneakily does a memslot lookup and checks for a valid HVA.
Hm, that doesn't sound as fast as simple comparison. We also can't do it from kvm_gpc_check(), can we?
You snipped the part where I suggested renaming the existing kvm_is_error_gpa().
I am suggesting we do the below (and obviously rename the s390 usage, too), and then the gpc code can use use kvm_is_error_gpa().
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index bbfefd7e612f..e1df988e4d57 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -148,6 +148,11 @@ static inline bool kvm_is_error_hva(unsigned long addr)
#endif
+static inline bool kvm_is_error_gpa(gpa_t gpa) +{ + return gpa == INVALID_GPA; +} + #define KVM_ERR_PTR_BAD_PAGE (ERR_PTR(-ENOENT))
static inline bool is_error_page(struct page *page) @@ -1787,7 +1792,7 @@ static inline hpa_t pfn_to_hpa(kvm_pfn_t pfn) return (hpa_t)pfn << PAGE_SHIFT; }
-static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa) +static inline bool kvm_gpa_is_in_memslot(struct kvm *kvm, gpa_t gpa) { unsigned long hva = gfn_to_hva(kvm, gpa_to_gfn(gpa));