Skip to content

Commit d3436a1

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio/qemu fixes from Michael S Tsirkin: "A couple of fixes for virtio and for the new QEMU fw cfg driver" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio: add VIRTIO_CONFIG_S_NEEDS_RESET device status bit MAINTAINERS: add entry for QEMU firmware: qemu_fw_cfg.c: hold ACPI global lock during device access virtio: virtio 1.0 cs04 spec compliance for reset qemu_fw_cfg: don't leak kobj on init error
2 parents 741f37b + c00bbcf commit d3436a1

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9142,6 +9142,13 @@ T: git git://github.com/KrasnikovEugene/wcn36xx.git
91429142
S: Supported
91439143
F: drivers/net/wireless/ath/wcn36xx/
91449144

9145+
QEMU MACHINE EMULATOR AND VIRTUALIZER SUPPORT
9146+
M: Gabriel Somlo <somlo@cmu.edu>
9147+
M: "Michael S. Tsirkin" <mst@redhat.com>
9148+
L: qemu-devel@nongnu.org
9149+
S: Maintained
9150+
F: drivers/firmware/qemu_fw_cfg.c
9151+
91459152
RADOS BLOCK DEVICE (RBD)
91469153
M: Ilya Dryomov <idryomov@gmail.com>
91479154
M: Sage Weil <sage@redhat.com>

drivers/firmware/qemu_fw_cfg.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,28 @@ static inline u16 fw_cfg_sel_endianness(u16 key)
7777
static inline void fw_cfg_read_blob(u16 key,
7878
void *buf, loff_t pos, size_t count)
7979
{
80+
u32 glk;
81+
acpi_status status;
82+
83+
/* If we have ACPI, ensure mutual exclusion against any potential
84+
* device access by the firmware, e.g. via AML methods:
85+
*/
86+
status = acpi_acquire_global_lock(ACPI_WAIT_FOREVER, &glk);
87+
if (ACPI_FAILURE(status) && status != AE_NOT_CONFIGURED) {
88+
/* Should never get here */
89+
WARN(1, "fw_cfg_read_blob: Failed to lock ACPI!\n");
90+
memset(buf, 0, count);
91+
return;
92+
}
93+
8094
mutex_lock(&fw_cfg_dev_lock);
8195
iowrite16(fw_cfg_sel_endianness(key), fw_cfg_reg_ctrl);
8296
while (pos-- > 0)
8397
ioread8(fw_cfg_reg_data);
8498
ioread8_rep(fw_cfg_reg_data, buf, count);
8599
mutex_unlock(&fw_cfg_dev_lock);
100+
101+
acpi_release_global_lock(glk);
86102
}
87103

88104
/* clean up fw_cfg device i/o */
@@ -727,12 +743,18 @@ device_param_cb(mmio, &fw_cfg_cmdline_param_ops, NULL, S_IRUSR);
727743

728744
static int __init fw_cfg_sysfs_init(void)
729745
{
746+
int ret;
747+
730748
/* create /sys/firmware/qemu_fw_cfg/ top level directory */
731749
fw_cfg_top_ko = kobject_create_and_add("qemu_fw_cfg", firmware_kobj);
732750
if (!fw_cfg_top_ko)
733751
return -ENOMEM;
734752

735-
return platform_driver_register(&fw_cfg_sysfs_driver);
753+
ret = platform_driver_register(&fw_cfg_sysfs_driver);
754+
if (ret)
755+
fw_cfg_kobj_cleanup(fw_cfg_top_ko);
756+
757+
return ret;
736758
}
737759

738760
static void __exit fw_cfg_sysfs_exit(void)

drivers/virtio/virtio_pci_modern.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
*/
1919

20+
#include <linux/delay.h>
2021
#define VIRTIO_PCI_NO_LEGACY
2122
#include "virtio_pci_common.h"
2223

@@ -271,9 +272,13 @@ static void vp_reset(struct virtio_device *vdev)
271272
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
272273
/* 0 status means a reset. */
273274
vp_iowrite8(0, &vp_dev->common->device_status);
274-
/* Flush out the status write, and flush in device writes,
275-
* including MSI-X interrupts, if any. */
276-
vp_ioread8(&vp_dev->common->device_status);
275+
/* After writing 0 to device_status, the driver MUST wait for a read of
276+
* device_status to return 0 before reinitializing the device.
277+
* This will flush out the status write, and flush in device writes,
278+
* including MSI-X interrupts, if any.
279+
*/
280+
while (vp_ioread8(&vp_dev->common->device_status))
281+
msleep(1);
277282
/* Flush pending VQ/configuration callbacks. */
278283
vp_synchronize_vectors(vdev);
279284
}

include/uapi/linux/virtio_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define VIRTIO_CONFIG_S_DRIVER_OK 4
4141
/* Driver has finished configuring features */
4242
#define VIRTIO_CONFIG_S_FEATURES_OK 8
43+
/* Device entered invalid state, driver must reset it */
44+
#define VIRTIO_CONFIG_S_NEEDS_RESET 0x40
4345
/* We've given up on this device. */
4446
#define VIRTIO_CONFIG_S_FAILED 0x80
4547

0 commit comments

Comments
 (0)