Skip to content

Commit 89b6b8c

Browse files
committed
Merge tag 'vfio-v5.15-rc1' of git://github.com/awilliam/linux-vfio
Pull VFIO updates from Alex Williamson: - Fix dma-valid return WAITED implementation (Anthony Yznaga) - SPDX license cleanups (Cai Huoqing) - Split vfio-pci-core from vfio-pci and enhance PCI driver matching to support future vendor provided vfio-pci variants (Yishai Hadas, Max Gurtovoy, Jason Gunthorpe) - Replace duplicated reflck with core support for managing first open, last close, and device sets (Jason Gunthorpe, Max Gurtovoy, Yishai Hadas) - Fix non-modular mdev support and don't nag about request callback support (Christoph Hellwig) - Add semaphore to protect instruction intercept handler and replace open-coded locks in vfio-ap driver (Tony Krowiak) - Convert vfio-ap to vfio_register_group_dev() API (Jason Gunthorpe) * tag 'vfio-v5.15-rc1' of git://github.com/awilliam/linux-vfio: (37 commits) vfio/pci: Introduce vfio_pci_core.ko vfio: Use kconfig if XX/endif blocks instead of repeating 'depends on' vfio: Use select for eventfd PCI / VFIO: Add 'override_only' support for VFIO PCI sub system PCI: Add 'override_only' field to struct pci_device_id vfio/pci: Move module parameters to vfio_pci.c vfio/pci: Move igd initialization to vfio_pci.c vfio/pci: Split the pci_driver code out of vfio_pci_core.c vfio/pci: Include vfio header in vfio_pci_core.h vfio/pci: Rename ops functions to fit core namings vfio/pci: Rename vfio_pci_device to vfio_pci_core_device vfio/pci: Rename vfio_pci_private.h to vfio_pci_core.h vfio/pci: Rename vfio_pci.c to vfio_pci_core.c vfio/ap_ops: Convert to use vfio_register_group_dev() s390/vfio-ap: replace open coded locks for VFIO_GROUP_NOTIFY_SET_KVM notification s390/vfio-ap: r/w lock for PQAP interception handler function pointer vfio/type1: Fix vfio_find_dma_valid return vfio-pci/zdev: Remove repeated verbose license text vfio: platform: reset: Convert to SPDX identifier vfio: Remove struct vfio_device_ops open/release ...
2 parents 9ae5fce + ea87073 commit 89b6b8c

45 files changed

Lines changed: 3004 additions & 2963 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Documentation/driver-api/vfio.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,13 @@ vfio_unregister_group_dev() respectively::
255255
void vfio_init_group_dev(struct vfio_device *device,
256256
struct device *dev,
257257
const struct vfio_device_ops *ops);
258+
void vfio_uninit_group_dev(struct vfio_device *device);
258259
int vfio_register_group_dev(struct vfio_device *device);
259260
void vfio_unregister_group_dev(struct vfio_device *device);
260261

261262
The driver should embed the vfio_device in its own structure and call
262-
vfio_init_group_dev() to pre-configure it before going to registration.
263+
vfio_init_group_dev() to pre-configure it before going to registration
264+
and call vfio_uninit_group_dev() after completing the un-registration.
263265
vfio_register_group_dev() indicates to the core to begin tracking the
264266
iommu_group of the specified dev and register the dev as owned by a VFIO bus
265267
driver. Once vfio_register_group_dev() returns it is possible for userspace to

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19607,6 +19607,7 @@ T: git git://github.com/awilliam/linux-vfio.git
1960719607
F: Documentation/driver-api/vfio.rst
1960819608
F: drivers/vfio/
1960919609
F: include/linux/vfio.h
19610+
F: include/linux/vfio_pci_core.h
1961019611
F: include/uapi/linux/vfio.h
1961119612

1961219613
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/gpu/drm/i915/gvt/kvmgt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ static int intel_vgpu_group_notifier(struct notifier_block *nb,
885885
return NOTIFY_OK;
886886
}
887887

888-
static int intel_vgpu_open(struct mdev_device *mdev)
888+
static int intel_vgpu_open_device(struct mdev_device *mdev)
889889
{
890890
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
891891
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
@@ -1004,7 +1004,7 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu)
10041004
vgpu->handle = 0;
10051005
}
10061006

1007-
static void intel_vgpu_release(struct mdev_device *mdev)
1007+
static void intel_vgpu_close_device(struct mdev_device *mdev)
10081008
{
10091009
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
10101010

@@ -1753,8 +1753,8 @@ static struct mdev_parent_ops intel_vgpu_ops = {
17531753
.create = intel_vgpu_create,
17541754
.remove = intel_vgpu_remove,
17551755

1756-
.open = intel_vgpu_open,
1757-
.release = intel_vgpu_release,
1756+
.open_device = intel_vgpu_open_device,
1757+
.close_device = intel_vgpu_close_device,
17581758

17591759
.read = intel_vgpu_read,
17601760
.write = intel_vgpu_write,

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
/**

drivers/s390/cio/vfio_ccw_ops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
159159
return 0;
160160
}
161161

162-
static int vfio_ccw_mdev_open(struct mdev_device *mdev)
162+
static int vfio_ccw_mdev_open_device(struct mdev_device *mdev)
163163
{
164164
struct vfio_ccw_private *private =
165165
dev_get_drvdata(mdev_parent_dev(mdev));
@@ -194,7 +194,7 @@ static int vfio_ccw_mdev_open(struct mdev_device *mdev)
194194
return ret;
195195
}
196196

197-
static void vfio_ccw_mdev_release(struct mdev_device *mdev)
197+
static void vfio_ccw_mdev_close_device(struct mdev_device *mdev)
198198
{
199199
struct vfio_ccw_private *private =
200200
dev_get_drvdata(mdev_parent_dev(mdev));
@@ -638,8 +638,8 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
638638
.supported_type_groups = mdev_type_groups,
639639
.create = vfio_ccw_mdev_create,
640640
.remove = vfio_ccw_mdev_remove,
641-
.open = vfio_ccw_mdev_open,
642-
.release = vfio_ccw_mdev_release,
641+
.open_device = vfio_ccw_mdev_open_device,
642+
.close_device = vfio_ccw_mdev_close_device,
643643
.read = vfio_ccw_mdev_read,
644644
.write = vfio_ccw_mdev_write,
645645
.ioctl = vfio_ccw_mdev_ioctl,

0 commit comments

Comments
 (0)