Skip to content

Commit 9c7260b

Browse files
Claudio Imbrendahcahca
authored andcommitted
s390/vfio-ap: Remove gmap_convert_to_secure() from vfio_ap_ops
If the page has been exported, do not re-import it. Imports should only be triggered by the guest. The guest will import the page automatically when it will need it again, there is no advantage in importing it manually. Moreover, vfio_pin_pages() will take an extra reference on the page and thus will cause the import to always fail. The extra reference would be dropped only after pointlessly trying to import the page. Fixes: f88fb13 ("s390/vfio-ap: make sure nib is shared") Signed-off-by: Claudio Imbrenda <[email protected]> Reviewed-by: Halil Pasic <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]>
1 parent 588a983 commit 9c7260b

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,26 @@ static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib)
360360
return 0;
361361
}
362362

363-
static int ensure_nib_shared(unsigned long addr, struct gmap *gmap)
363+
/**
364+
* ensure_nib_shared() - Ensure the address of the NIB is secure and shared
365+
* @addr: the physical (absolute) address of the NIB
366+
*
367+
* This function checks whether the NIB page, which has been pinned with
368+
* vfio_pin_pages(), is a shared page belonging to a secure guest.
369+
*
370+
* It will call uv_pin_shared() on it; if the page was already pinned shared
371+
* (i.e. if the NIB belongs to a secure guest and is shared), then 0
372+
* (success) is returned. If the NIB was not shared, vfio_pin_pages() had
373+
* exported it and now it does not belong to the secure guest anymore. In
374+
* that case, an error is returned.
375+
*
376+
* Context: the NIB (at physical address @addr) has to be pinned with
377+
* vfio_pin_pages() before calling this function.
378+
*
379+
* Return: 0 in case of success, otherwise an error < 0.
380+
*/
381+
static int ensure_nib_shared(unsigned long addr)
364382
{
365-
int ret;
366-
367383
/*
368384
* The nib has to be located in shared storage since guest and
369385
* host access it. vfio_pin_pages() will do a pin shared and
@@ -374,12 +390,7 @@ static int ensure_nib_shared(unsigned long addr, struct gmap *gmap)
374390
*
375391
* If the page is already pinned shared the UV will return a success.
376392
*/
377-
ret = uv_pin_shared(addr);
378-
if (ret) {
379-
/* vfio_pin_pages() likely exported the page so let's re-import */
380-
gmap_convert_to_secure(gmap, addr);
381-
}
382-
return ret;
393+
return uv_pin_shared(addr);
383394
}
384395

385396
/**
@@ -425,6 +436,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
425436
return status;
426437
}
427438

439+
/* The pin will probably be successful even if the NIB was not shared */
428440
ret = vfio_pin_pages(&q->matrix_mdev->vdev, nib, 1,
429441
IOMMU_READ | IOMMU_WRITE, &h_page);
430442
switch (ret) {
@@ -447,7 +459,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
447459

448460
/* NIB in non-shared storage is a rc 6 for PV guests */
449461
if (kvm_s390_pv_cpu_is_protected(vcpu) &&
450-
ensure_nib_shared(h_nib & PAGE_MASK, kvm->arch.gmap)) {
462+
ensure_nib_shared(h_nib & PAGE_MASK)) {
451463
vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
452464
status.response_code = AP_RESPONSE_INVALID_ADDRESS;
453465
return status;

0 commit comments

Comments
 (0)