Skip to content

Commit

Permalink
s390: ap: implement PAPQ AQIC interception in kernel
Browse files Browse the repository at this point in the history
We register a AP PQAP instruction hook during the open
of the mediated device. And unregister it on release.

During the probe of the AP device, we allocate a vfio_ap_queue
structure to keep track of the information we need for the
PQAP/AQIC instruction interception.

In the AP PQAP instruction hook, if we receive a demand to
enable IRQs,
- we retrieve the vfio_ap_queue based on the APQN we receive
  in REG1,
- we retrieve the page of the guest address, (NIB), from
  register REG2
- we retrieve the mediated device to use the VFIO pinning
  infrastructure to pin the page of the guest address,
- we retrieve the pointer to KVM to register the guest ISC
  and retrieve the host ISC
- finaly we activate GISA

If we receive a demand to disable IRQs,
- we deactivate GISA
- unregister from the GIB
- unpin the NIB

When removing the AP device from the driver the device is
reseted and this process unregisters the GISA from the GIB,
and unpins the NIB address then we free the vfio_ap_queue
structure.

Signed-off-by: Pierre Morel <[email protected]>
Acked-by: Tony Krowiak <[email protected]>
Acked-by: Harald Freudenberger <[email protected]>
Signed-off-by: Halil Pasic <[email protected]>
Signed-off-by: Vasily Gorbik <[email protected]>
  • Loading branch information
Pierre Morel authored and Vasily Gorbik committed Jul 2, 2019
1 parent 62e358c commit ec89b55
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 7 deletions.
34 changes: 33 additions & 1 deletion drivers/s390/crypto/vfio_ap_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright IBM Corp. 2018
*
* Author(s): Tony Krowiak <[email protected]>
* Pierre Morel <[email protected]>
*/

#include <linux/module.h>
Expand Down Expand Up @@ -40,14 +41,45 @@ static struct ap_device_id ap_queue_ids[] = {

MODULE_DEVICE_TABLE(vfio_ap, ap_queue_ids);

/**
* vfio_ap_queue_dev_probe:
*
* Allocate a vfio_ap_queue structure and associate it
* with the device as driver_data.
*/
static int vfio_ap_queue_dev_probe(struct ap_device *apdev)
{
struct vfio_ap_queue *q;

q = kzalloc(sizeof(*q), GFP_KERNEL);
if (!q)
return -ENOMEM;
dev_set_drvdata(&apdev->device, q);
q->apqn = to_ap_queue(&apdev->device)->qid;
q->saved_isc = VFIO_AP_ISC_INVALID;
return 0;
}

/**
* vfio_ap_queue_dev_remove:
*
* Takes the matrix lock to avoid actions on this device while removing
* Free the associated vfio_ap_queue structure
*/
static void vfio_ap_queue_dev_remove(struct ap_device *apdev)
{
/* Nothing to do yet */
struct vfio_ap_queue *q;
int apid, apqi;

mutex_lock(&matrix_dev->lock);
q = dev_get_drvdata(&apdev->device);
dev_set_drvdata(&apdev->device, NULL);
apid = AP_QID_CARD(q->apqn);
apqi = AP_QID_QUEUE(q->apqn);
vfio_ap_mdev_reset_queue(apid, apqi, 1);
vfio_ap_irq_disable(q);
kfree(q);
mutex_unlock(&matrix_dev->lock);
}

static void vfio_ap_matrix_dev_release(struct device *dev)
Expand Down
Loading

0 comments on commit ec89b55

Please sign in to comment.