Skip to content

Commit 15463ee

Browse files
sean-jcbonzini
authored andcommitted
KVM: s390/vfio-ap: Use kvm_is_gpa_in_memslot() instead of open coded equivalent
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 <[email protected]> Reviewed-by: Christian Borntraeger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 12abeb8 commit 15463ee

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@ extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
722722
extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
723723
extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
724724

725+
bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa);
726+
725727
static inline void kvm_arch_free_memslot(struct kvm *kvm,
726728
struct kvm_memory_slot *slot) {}
727729
static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}

arch/s390/kvm/priv.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,14 @@ static int handle_io_inst(struct kvm_vcpu *vcpu)
605605
}
606606
}
607607

608+
#if IS_ENABLED(CONFIG_VFIO_AP)
609+
bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa)
610+
{
611+
return kvm_is_gpa_in_memslot(kvm, gpa);
612+
}
613+
EXPORT_SYMBOL_FOR_MODULES(kvm_s390_is_gpa_in_memslot, "vfio_ap");
614+
#endif
615+
608616
/*
609617
* handle_pqap: Handling pqap interception
610618
* @vcpu: the vcpu having issue the pqap instruction

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib)
354354

355355
if (!*nib)
356356
return -EINVAL;
357-
if (kvm_is_error_hva(gfn_to_hva(vcpu->kvm, *nib >> PAGE_SHIFT)))
357+
if (!kvm_s390_is_gpa_in_memslot(vcpu->kvm, *nib))
358358
return -EINVAL;
359359

360360
return 0;

0 commit comments

Comments
 (0)