drivers/s390/crypto/vfio_ap_ops.c
Source file repositories/reference/linux-study-clean/drivers/s390/crypto/vfio_ap_ops.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/s390/crypto/vfio_ap_ops.c- Extension
.c- Size
- 83539 bytes
- Lines
- 2870
- Domain
- Driver Families
- Bucket
- drivers/s390
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/string.hlinux/vfio.hlinux/device.hlinux/list.hlinux/ctype.hlinux/bitops.hlinux/kvm_host.hlinux/module.hlinux/uuid.hasm/kvm.hasm/zcrypt.hvfio_ap_private.hvfio_ap_debug.h
Detected Declarations
function get_update_locks_for_kvmfunction release_update_locks_for_kvmfunction get_update_locks_for_mdevfunction release_update_locks_for_mdevfunction list_for_each_entryfunction get_update_locks_for_queuefunction hash_for_each_possiblefunction vfio_ap_wait_for_irqclearfunction vfio_ap_free_aqic_resourcesfunction vfio_ap_wait_for_irqclearfunction vfio_ap_validate_nibfunction vfio_pin_pagesfunction PQAPfunction ensure_nib_sharedfunction Featurefunction vfio_ap_setirqfunction vfio_ap_matrix_initfunction signal_guest_ap_cfg_changedfunction vfio_ap_mdev_update_guest_apcbfunction vfio_ap_mdev_filter_cdomsfunction _queue_passablefunction vfio_ap_mdev_filter_matrixfunction for_each_set_bit_invfunction vfio_ap_mdev_init_devfunction vfio_ap_mdev_probefunction vfio_ap_mdev_link_queuefunction vfio_ap_mdev_link_apqnfunction vfio_ap_unlink_queue_fr_mdevfunction vfio_ap_unlink_mdev_fr_queuefunction vfio_ap_mdev_unlink_fr_queuesfunction for_each_set_bit_invfunction vfio_ap_mdev_removefunction vfio_ap_mdev_log_sharing_errfunction for_each_set_bit_invfunction vfio_ap_mdev_log_in_use_errfunction for_each_set_bit_invfunction vfio_ap_mdev_verify_no_sharingfunction list_for_each_entryfunction ap_apqn_in_matrix_owned_by_def_drvfunction vfio_ap_mdev_link_adapterfunction collect_queues_to_resetfunction for_each_set_bit_invfunction reset_queues_for_apidfunction reset_queues_for_apidsfunction assign_adapter_storefunction vfio_ap_mdev_unlink_adapterfunction for_each_set_bit_invfunction vfio_ap_mdev_hot_unplug_adapters
Annotated Snippet
test_bit_inv(AP_QID_QUEUE(apqn), matrix_mdev->matrix.aqm)) {
if (matrix_mdev->kvm)
mutex_lock(&matrix_mdev->kvm->lock);
mutex_lock(&matrix_dev->mdevs_lock);
return matrix_mdev;
}
}
mutex_lock(&matrix_dev->mdevs_lock);
return NULL;
}
/**
* get_update_locks_for_queue: get the locks required to update the APCB of the
* KVM guest to which the matrix mdev linked to a
* vfio_ap_queue object is attached.
*
* @q: a pointer to a vfio_ap_queue object.
*
* The proper locking order is:
* 1. q->matrix_dev->guests_lock: required to use the KVM pointer to update a
* KVM guest's APCB.
* 2. q->matrix_mdev->kvm->lock: required to update a guest's APCB
* 3. matrix_dev->mdevs_lock: required to access data stored in matrix_mdev
*
* Note: if @queue is not linked to an ap_matrix_mdev object, the KVM lock
* will not be taken.
*/
static inline void get_update_locks_for_queue(struct vfio_ap_queue *q)
{
mutex_lock(&matrix_dev->guests_lock);
if (q->matrix_mdev && q->matrix_mdev->kvm)
mutex_lock(&q->matrix_mdev->kvm->lock);
mutex_lock(&matrix_dev->mdevs_lock);
}
/**
* vfio_ap_mdev_get_queue - retrieve a queue with a specific APQN from a
* hash table of queues assigned to a matrix mdev
* @matrix_mdev: the matrix mdev
* @apqn: The APQN of a queue device
*
* Return: the pointer to the vfio_ap_queue struct representing the queue or
* NULL if the queue is not assigned to @matrix_mdev
*/
static struct vfio_ap_queue *vfio_ap_mdev_get_queue(
struct ap_matrix_mdev *matrix_mdev,
int apqn)
{
struct vfio_ap_queue *q;
hash_for_each_possible(matrix_mdev->qtable.queues, q, mdev_qnode,
apqn) {
if (q && q->apqn == apqn)
return q;
}
return NULL;
}
/**
* vfio_ap_wait_for_irqclear - clears the IR bit or gives up after 5 tries
* @apqn: The AP Queue number
*
* Checks the IRQ bit for the status of this APQN using ap_tapq.
* Returns if the ap_tapq function succeeded and the bit is clear.
* Returns if ap_tapq function failed with invalid, deconfigured or
* checkstopped AP.
* Otherwise retries up to 5 times after waiting 20ms.
*/
static void vfio_ap_wait_for_irqclear(int apqn)
{
struct ap_queue_status status;
int retry = 5;
do {
status = ap_tapq(apqn, NULL);
switch (status.response_code) {
case AP_RESPONSE_NORMAL:
case AP_RESPONSE_RESET_IN_PROGRESS:
if (!status.irq_enabled)
return;
fallthrough;
case AP_RESPONSE_BUSY:
msleep(20);
break;
case AP_RESPONSE_Q_NOT_AVAIL:
Annotation
- Immediate include surface: `linux/string.h`, `linux/vfio.h`, `linux/device.h`, `linux/list.h`, `linux/ctype.h`, `linux/bitops.h`, `linux/kvm_host.h`, `linux/module.h`.
- Detected declarations: `function get_update_locks_for_kvm`, `function release_update_locks_for_kvm`, `function get_update_locks_for_mdev`, `function release_update_locks_for_mdev`, `function list_for_each_entry`, `function get_update_locks_for_queue`, `function hash_for_each_possible`, `function vfio_ap_wait_for_irqclear`, `function vfio_ap_free_aqic_resources`, `function vfio_ap_wait_for_irqclear`.
- Atlas domain: Driver Families / drivers/s390.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.