Introduce a fence over enabling or disabling FMB via debugfs when the zPCI device is associated with a KVM. This will prevent processes on the host from tampering with the FMB while the guest is still using it, which may cause partial counter resets and inconsistent reads which have no parallel in the architecture. For VFIO devices that are not associated with a KVM (i.e., for userspace drivers other than QEMU), this fence does not take effect. Signed-off-by: Omar Elghoul Reviewed-by: Matthew Rosato Reviewed-by: Niklas Schnelle --- arch/s390/pci/pci_debug.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/s390/pci/pci_debug.c b/arch/s390/pci/pci_debug.c index 454121bc274c..02da077b5170 100644 --- a/arch/s390/pci/pci_debug.c +++ b/arch/s390/pci/pci_debug.c @@ -153,6 +153,12 @@ static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf, if (rc) return rc; + mutex_lock(&zdev->kzdev_lock); + if (zdev->kzdev) { + rc = -EPERM; + goto out_unlock_kzdev; + } + mutex_lock(&zdev->fmb_lock); switch (val) { case 0: @@ -163,6 +169,9 @@ static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf, break; } mutex_unlock(&zdev->fmb_lock); + +out_unlock_kzdev: + mutex_unlock(&zdev->kzdev_lock); return rc ? rc : count; } -- 2.56.0