-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s390: vfio-ap: register matrix device with VFIO mdev framework
Registers the matrix device created by the VFIO AP device driver with the VFIO mediated device framework. Registering the matrix device will create the sysfs structures needed to create mediated matrix devices each of which will be used to configure the AP matrix for a guest and connect it to the VFIO AP device driver. Registering the matrix device with the VFIO mediated device framework will create the following sysfs structures: /sys/devices/vfio_ap/matrix/ ...... [mdev_supported_types] ......... [vfio_ap-passthrough] ............ create To create a mediated device for the AP matrix device, write a UUID to the create file: uuidgen > create A symbolic link to the mediated device's directory will be created in the devices subdirectory named after the generated $uuid: /sys/devices/vfio_ap/matrix/ ...... [mdev_supported_types] ......... [vfio_ap-passthrough] ............ [devices] ............... [$uuid] A symbolic link to the mediated device will also be created in the vfio_ap matrix's directory: /sys/devices/vfio_ap/matrix/[$uuid] Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Halil Pasic <pasic@linux.ibm.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Tested-by: Michael Mueller <mimu@linux.ibm.com> Tested-by: Farhan Ali <alifm@linux.ibm.com> Message-Id: <20180925231641.4954-6-akrowiak@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
- Loading branch information
Tony Krowiak
authored and
Christian Borntraeger
committed
Sep 26, 2018
1 parent
1fde573
commit 65f0671
Showing
6 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* Adjunct processor matrix VFIO device driver callbacks. | ||
* | ||
* Copyright IBM Corp. 2018 | ||
* | ||
* Author(s): Tony Krowiak <akrowiak@linux.ibm.com> | ||
* Halil Pasic <pasic@linux.ibm.com> | ||
* Pierre Morel <pmorel@linux.ibm.com> | ||
*/ | ||
#include <linux/string.h> | ||
#include <linux/vfio.h> | ||
#include <linux/device.h> | ||
#include <linux/list.h> | ||
#include <linux/ctype.h> | ||
#include <asm/zcrypt.h> | ||
|
||
#include "vfio_ap_private.h" | ||
|
||
#define VFIO_AP_MDEV_TYPE_HWVIRT "passthrough" | ||
#define VFIO_AP_MDEV_NAME_HWVIRT "VFIO AP Passthrough Device" | ||
|
||
static void vfio_ap_matrix_init(struct ap_config_info *info, | ||
struct ap_matrix *matrix) | ||
{ | ||
matrix->apm_max = info->apxa ? info->Na : 63; | ||
matrix->aqm_max = info->apxa ? info->Nd : 15; | ||
matrix->adm_max = info->apxa ? info->Nd : 15; | ||
} | ||
|
||
static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) | ||
{ | ||
struct ap_matrix_mdev *matrix_mdev; | ||
|
||
if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0)) | ||
return -EPERM; | ||
|
||
matrix_mdev = kzalloc(sizeof(*matrix_mdev), GFP_KERNEL); | ||
if (!matrix_mdev) { | ||
atomic_inc(&matrix_dev->available_instances); | ||
return -ENOMEM; | ||
} | ||
|
||
vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix); | ||
mdev_set_drvdata(mdev, matrix_mdev); | ||
mutex_lock(&matrix_dev->lock); | ||
list_add(&matrix_mdev->node, &matrix_dev->mdev_list); | ||
mutex_unlock(&matrix_dev->lock); | ||
|
||
return 0; | ||
} | ||
|
||
static int vfio_ap_mdev_remove(struct mdev_device *mdev) | ||
{ | ||
struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); | ||
|
||
mutex_lock(&matrix_dev->lock); | ||
list_del(&matrix_mdev->node); | ||
mutex_unlock(&matrix_dev->lock); | ||
|
||
kfree(matrix_mdev); | ||
mdev_set_drvdata(mdev, NULL); | ||
atomic_inc(&matrix_dev->available_instances); | ||
|
||
return 0; | ||
} | ||
|
||
static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) | ||
{ | ||
return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT); | ||
} | ||
|
||
MDEV_TYPE_ATTR_RO(name); | ||
|
||
static ssize_t available_instances_show(struct kobject *kobj, | ||
struct device *dev, char *buf) | ||
{ | ||
return sprintf(buf, "%d\n", | ||
atomic_read(&matrix_dev->available_instances)); | ||
} | ||
|
||
MDEV_TYPE_ATTR_RO(available_instances); | ||
|
||
static ssize_t device_api_show(struct kobject *kobj, struct device *dev, | ||
char *buf) | ||
{ | ||
return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING); | ||
} | ||
|
||
MDEV_TYPE_ATTR_RO(device_api); | ||
|
||
static struct attribute *vfio_ap_mdev_type_attrs[] = { | ||
&mdev_type_attr_name.attr, | ||
&mdev_type_attr_device_api.attr, | ||
&mdev_type_attr_available_instances.attr, | ||
NULL, | ||
}; | ||
|
||
static struct attribute_group vfio_ap_mdev_hwvirt_type_group = { | ||
.name = VFIO_AP_MDEV_TYPE_HWVIRT, | ||
.attrs = vfio_ap_mdev_type_attrs, | ||
}; | ||
|
||
static struct attribute_group *vfio_ap_mdev_type_groups[] = { | ||
&vfio_ap_mdev_hwvirt_type_group, | ||
NULL, | ||
}; | ||
|
||
static const struct mdev_parent_ops vfio_ap_matrix_ops = { | ||
.owner = THIS_MODULE, | ||
.supported_type_groups = vfio_ap_mdev_type_groups, | ||
.create = vfio_ap_mdev_create, | ||
.remove = vfio_ap_mdev_remove, | ||
}; | ||
|
||
int vfio_ap_mdev_register(void) | ||
{ | ||
atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT); | ||
|
||
return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops); | ||
} | ||
|
||
void vfio_ap_mdev_unregister(void) | ||
{ | ||
mdev_unregister_device(&matrix_dev->device); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters