Skip to content

Commit ea87073

Browse files
author
Alex Williamson
committed
Merge branches 'v5.15/vfio/spdx-license-cleanups', 'v5.15/vfio/dma-valid-waited-v3', 'v5.15/vfio/vfio-pci-core-v5' and 'v5.15/vfio/vfio-ap' into v5.15/vfio/next
4 parents 29848a0 + ffc95d1 + 7fa005c + eb0feef commit ea87073

28 files changed

Lines changed: 2704 additions & 2483 deletions

Documentation/PCI/pci.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ need pass only as many optional fields as necessary:
103103
- subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF)
104104
- class and classmask fields default to 0
105105
- driver_data defaults to 0UL.
106+
- override_only field defaults to 0.
106107

107108
Note that driver_data must match the value used by any of the pci_device_id
108109
entries defined in the driver. This makes the driver_data field mandatory

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19466,6 +19466,7 @@ T: git git://github.com/awilliam/linux-vfio.git
1946619466
F: Documentation/driver-api/vfio.rst
1946719467
F: drivers/vfio/
1946819468
F: include/linux/vfio.h
19469+
F: include/linux/vfio_pci_core.h
1946919470
F: include/uapi/linux/vfio.h
1947019471

1947119472
VFIO FSL-MC DRIVER

arch/s390/include/asm/kvm_host.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,12 @@ struct kvm_s390_cpu_model {
798798
unsigned short ibc;
799799
};
800800

801-
struct kvm_s390_module_hook {
802-
int (*hook)(struct kvm_vcpu *vcpu);
803-
struct module *owner;
804-
};
801+
typedef int (*crypto_hook)(struct kvm_vcpu *vcpu);
805802

806803
struct kvm_s390_crypto {
807804
struct kvm_s390_crypto_cb *crycb;
808-
struct kvm_s390_module_hook *pqap_hook;
805+
struct rw_semaphore pqap_hook_rwsem;
806+
crypto_hook *pqap_hook;
809807
__u32 crycbd;
810808
__u8 aes_kw;
811809
__u8 dea_kw;

arch/s390/kvm/kvm-s390.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,12 +2559,26 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
25592559
kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
25602560
}
25612561

2562+
/*
2563+
* kvm_arch_crypto_set_masks
2564+
*
2565+
* @kvm: pointer to the target guest's KVM struct containing the crypto masks
2566+
* to be set.
2567+
* @apm: the mask identifying the accessible AP adapters
2568+
* @aqm: the mask identifying the accessible AP domains
2569+
* @adm: the mask identifying the accessible AP control domains
2570+
*
2571+
* Set the masks that identify the adapters, domains and control domains to
2572+
* which the KVM guest is granted access.
2573+
*
2574+
* Note: The kvm->lock mutex must be locked by the caller before invoking this
2575+
* function.
2576+
*/
25622577
void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
25632578
unsigned long *aqm, unsigned long *adm)
25642579
{
25652580
struct kvm_s390_crypto_cb *crycb = kvm->arch.crypto.crycb;
25662581

2567-
mutex_lock(&kvm->lock);
25682582
kvm_s390_vcpu_block_all(kvm);
25692583

25702584
switch (kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
@@ -2595,13 +2609,23 @@ void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
25952609
/* recreate the shadow crycb for each vcpu */
25962610
kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART);
25972611
kvm_s390_vcpu_unblock_all(kvm);
2598-
mutex_unlock(&kvm->lock);
25992612
}
26002613
EXPORT_SYMBOL_GPL(kvm_arch_crypto_set_masks);
26012614

2615+
/*
2616+
* kvm_arch_crypto_clear_masks
2617+
*
2618+
* @kvm: pointer to the target guest's KVM struct containing the crypto masks
2619+
* to be cleared.
2620+
*
2621+
* Clear the masks that identify the adapters, domains and control domains to
2622+
* which the KVM guest is granted access.
2623+
*
2624+
* Note: The kvm->lock mutex must be locked by the caller before invoking this
2625+
* function.
2626+
*/
26022627
void kvm_arch_crypto_clear_masks(struct kvm *kvm)
26032628
{
2604-
mutex_lock(&kvm->lock);
26052629
kvm_s390_vcpu_block_all(kvm);
26062630

26072631
memset(&kvm->arch.crypto.crycb->apcb0, 0,
@@ -2613,7 +2637,6 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm)
26132637
/* recreate the shadow crycb for each vcpu */
26142638
kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART);
26152639
kvm_s390_vcpu_unblock_all(kvm);
2616-
mutex_unlock(&kvm->lock);
26172640
}
26182641
EXPORT_SYMBOL_GPL(kvm_arch_crypto_clear_masks);
26192642

@@ -2630,6 +2653,7 @@ static void kvm_s390_crypto_init(struct kvm *kvm)
26302653
{
26312654
kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb;
26322655
kvm_s390_set_crycb_format(kvm);
2656+
init_rwsem(&kvm->arch.crypto.pqap_hook_rwsem);
26332657

26342658
if (!test_kvm_facility(kvm, 76))
26352659
return;

arch/s390/kvm/priv.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ static int handle_io_inst(struct kvm_vcpu *vcpu)
610610
static int handle_pqap(struct kvm_vcpu *vcpu)
611611
{
612612
struct ap_queue_status status = {};
613+
crypto_hook pqap_hook;
613614
unsigned long reg0;
614615
int ret;
615616
uint8_t fc;
@@ -654,18 +655,20 @@ static int handle_pqap(struct kvm_vcpu *vcpu)
654655
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
655656

656657
/*
657-
* Verify that the hook callback is registered, lock the owner
658-
* and call the hook.
658+
* If the hook callback is registered, there will be a pointer to the
659+
* hook function pointer in the kvm_s390_crypto structure. Lock the
660+
* owner, retrieve the hook function pointer and call the hook.
659661
*/
662+
down_read(&vcpu->kvm->arch.crypto.pqap_hook_rwsem);
660663
if (vcpu->kvm->arch.crypto.pqap_hook) {
661-
if (!try_module_get(vcpu->kvm->arch.crypto.pqap_hook->owner))
662-
return -EOPNOTSUPP;
663-
ret = vcpu->kvm->arch.crypto.pqap_hook->hook(vcpu);
664-
module_put(vcpu->kvm->arch.crypto.pqap_hook->owner);
664+
pqap_hook = *vcpu->kvm->arch.crypto.pqap_hook;
665+
ret = pqap_hook(vcpu);
665666
if (!ret && vcpu->run->s.regs.gprs[1] & 0x00ff0000)
666667
kvm_s390_set_psw_cc(vcpu, 3);
668+
up_read(&vcpu->kvm->arch.crypto.pqap_hook_rwsem);
667669
return ret;
668670
}
671+
up_read(&vcpu->kvm->arch.crypto.pqap_hook_rwsem);
669672
/*
670673
* A vfio_driver must register a hook.
671674
* No hook means no driver to enable the SIE CRYCB and no queues.

drivers/pci/pci-driver.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
136136
struct pci_dev *dev)
137137
{
138138
struct pci_dynid *dynid;
139-
const struct pci_device_id *found_id = NULL;
139+
const struct pci_device_id *found_id = NULL, *ids;
140140

141141
/* When driver_override is set, only bind to the matching driver */
142142
if (dev->driver_override && strcmp(dev->driver_override, drv->name))
@@ -152,14 +152,28 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
152152
}
153153
spin_unlock(&drv->dynids.lock);
154154

155-
if (!found_id)
156-
found_id = pci_match_id(drv->id_table, dev);
155+
if (found_id)
156+
return found_id;
157157

158-
/* driver_override will always match, send a dummy id */
159-
if (!found_id && dev->driver_override)
160-
found_id = &pci_device_id_any;
158+
for (ids = drv->id_table; (found_id = pci_match_id(ids, dev));
159+
ids = found_id + 1) {
160+
/*
161+
* The match table is split based on driver_override.
162+
* In case override_only was set, enforce driver_override
163+
* matching.
164+
*/
165+
if (found_id->override_only) {
166+
if (dev->driver_override)
167+
return found_id;
168+
} else {
169+
return found_id;
170+
}
171+
}
161172

162-
return found_id;
173+
/* driver_override will always match, send a dummy id */
174+
if (dev->driver_override)
175+
return &pci_device_id_any;
176+
return NULL;
163177
}
164178

165179
/**

0 commit comments

Comments
 (0)