]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: s390/vfio-ap: Use kvm_is_gpa_in_memslot() instead of open coded equivalent
authorSean Christopherson <seanjc@google.com>
Fri, 19 Sep 2025 00:32:59 +0000 (17:32 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 30 Sep 2025 17:38:06 +0000 (13:38 -0400)
Use kvm_is_gpa_in_memslot() to check the validity of the notification
indicator byte address instead of open coding equivalent logic in the VFIO
AP driver.

Opportunistically use a dedicated wrapper that exists and is exported
expressly for the VFIO AP module.  kvm_is_gpa_in_memslot() is generally
unsuitable for use outside of KVM; other drivers typically shouldn't rely
on KVM's memslots, and using the API requires kvm->srcu (or slots_lock) to
be held for the entire duration of the usage, e.g. to avoid TOCTOU bugs.
handle_pqap() is a bit of a special case, as it's explicitly invoked from
KVM with kvm->srcu already held, and the VFIO AP driver is in many ways an
extension of KVM that happens to live in a separate module.

Providing a dedicated API for the VFIO AP driver will allow restricting
the vast majority of generic KVM's exports to KVM submodules (e.g. to x86's
kvm-{amd,intel}.ko vendor mdoules).

No functional change intended.

Acked-by: Anthony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Link: https://lore.kernel.org/r/20250919003303.1355064-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/s390/include/asm/kvm_host.h
arch/s390/kvm/priv.c
drivers/s390/crypto/vfio_ap_ops.c

index 95d15416c39d2e1fecce09bb9abfd06aae05008a..c2ba3d4398c5371526ddfd53b43607c00abc35a1 100644 (file)
@@ -722,6 +722,8 @@ extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
 extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
 extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
 
+bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa);
+
 static inline void kvm_arch_free_memslot(struct kvm *kvm,
                                         struct kvm_memory_slot *slot) {}
 static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
index 9253c70897a8d4f16c2c21e2aa684febc562ecaa..9a71b6e00948ffba3c17f74ac0bd4a5a27d4f34a 100644 (file)
@@ -605,6 +605,14 @@ static int handle_io_inst(struct kvm_vcpu *vcpu)
        }
 }
 
+#if IS_ENABLED(CONFIG_VFIO_AP)
+bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa)
+{
+       return kvm_is_gpa_in_memslot(kvm, gpa);
+}
+EXPORT_SYMBOL_FOR_MODULES(kvm_s390_is_gpa_in_memslot, "vfio_ap");
+#endif
+
 /*
  * handle_pqap: Handling pqap interception
  * @vcpu: the vcpu having issue the pqap instruction
index 766557547f83fa3bc13ee0aa97e78fb37be70a93..eb5ff49f6fe7de1d301a2d4740ce0f346579f610 100644 (file)
@@ -354,7 +354,7 @@ static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib)
 
        if (!*nib)
                return -EINVAL;
-       if (kvm_is_error_hva(gfn_to_hva(vcpu->kvm, *nib >> PAGE_SHIFT)))
+       if (!kvm_s390_is_gpa_in_memslot(vcpu->kvm, *nib))
                return -EINVAL;
 
        return 0;