Skip to content

Commit ec89b55

Browse files
Pierre MorelVasily Gorbik
authored andcommitted
s390: ap: implement PAPQ AQIC interception in kernel
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]>
1 parent 62e358c commit ec89b55

File tree

3 files changed

+375
-7
lines changed

3 files changed

+375
-7
lines changed

drivers/s390/crypto/vfio_ap_drv.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright IBM Corp. 2018
66
*
77
* Author(s): Tony Krowiak <[email protected]>
8+
* Pierre Morel <[email protected]>
89
*/
910

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

4142
MODULE_DEVICE_TABLE(vfio_ap, ap_queue_ids);
4243

44+
/**
45+
* vfio_ap_queue_dev_probe:
46+
*
47+
* Allocate a vfio_ap_queue structure and associate it
48+
* with the device as driver_data.
49+
*/
4350
static int vfio_ap_queue_dev_probe(struct ap_device *apdev)
4451
{
52+
struct vfio_ap_queue *q;
53+
54+
q = kzalloc(sizeof(*q), GFP_KERNEL);
55+
if (!q)
56+
return -ENOMEM;
57+
dev_set_drvdata(&apdev->device, q);
58+
q->apqn = to_ap_queue(&apdev->device)->qid;
59+
q->saved_isc = VFIO_AP_ISC_INVALID;
4560
return 0;
4661
}
4762

63+
/**
64+
* vfio_ap_queue_dev_remove:
65+
*
66+
* Takes the matrix lock to avoid actions on this device while removing
67+
* Free the associated vfio_ap_queue structure
68+
*/
4869
static void vfio_ap_queue_dev_remove(struct ap_device *apdev)
4970
{
50-
/* Nothing to do yet */
71+
struct vfio_ap_queue *q;
72+
int apid, apqi;
73+
74+
mutex_lock(&matrix_dev->lock);
75+
q = dev_get_drvdata(&apdev->device);
76+
dev_set_drvdata(&apdev->device, NULL);
77+
apid = AP_QID_CARD(q->apqn);
78+
apqi = AP_QID_QUEUE(q->apqn);
79+
vfio_ap_mdev_reset_queue(apid, apqi, 1);
80+
vfio_ap_irq_disable(q);
81+
kfree(q);
82+
mutex_unlock(&matrix_dev->lock);
5183
}
5284

5385
static void vfio_ap_matrix_dev_release(struct device *dev)

0 commit comments

Comments
 (0)