[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/41] char: forbid direct chardevice access for hots
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 11/41] char: forbid direct chardevice access for hotswap devices |
Date: |
Thu, 13 Jul 2017 16:24:04 +0200 |
From: Anton Nefedov <address@hidden>
qemu_chr_fe_get_driver() is unsafe, frontends with hotswap support
should not access CharDriver ptr directly as CharDriver might change.
Signed-off-by: Anton Nefedov <address@hidden>
Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
chardev/char-fe.c | 7 +++++++
include/chardev/char-fe.h | 10 ++++++++++
2 files changed, 17 insertions(+)
diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index 7054863..de5ba3c 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -179,9 +179,16 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt,
...)
Chardev *qemu_chr_fe_get_driver(CharBackend *be)
{
+ /* this is unsafe for the users that support chardev hotswap */
+ assert(be->chr_be_change == NULL);
return be->chr;
}
+bool qemu_chr_fe_backend_connected(CharBackend *be)
+{
+ return !!be->chr;
+}
+
bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
{
int tag = 0;
diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h
index 9f38060..588abed 100644
--- a/include/chardev/char-fe.h
+++ b/include/chardev/char-fe.h
@@ -46,10 +46,20 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del);
*
* Returns the driver associated with a CharBackend or NULL if no
* associated Chardev.
+ * Note: avoid this function as the driver should never be accessed directly,
+ * especially by the frontends that support chardevice hotswap.
+ * Consider qemu_chr_fe_backend_connected() to check for driver existence
*/
Chardev *qemu_chr_fe_get_driver(CharBackend *be);
/**
+ * @qemu_chr_fe_backend_connected:
+ *
+ * Returns true if there is a chardevice associated with @be.
+ */
+bool qemu_chr_fe_backend_connected(CharBackend *be);
+
+/**
* @qemu_chr_fe_set_handlers:
* @b: a CharBackend
* @fd_can_read: callback to get the amount of data the frontend may
--
1.8.3.1
- [Qemu-devel] [PULL 21/41] exec: use qemu_ram_ptr_length to access guest ram, (continued)
- [Qemu-devel] [PULL 21/41] exec: use qemu_ram_ptr_length to access guest ram, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 23/41] mttcg/i386: Patch instruction using async_safe_* framework, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 27/41] gdbstub: don't fail on vCont; C04:0; c packets, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 25/41] gdbstub: rename cpu_index -> cpu_gdb_index, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 28/41] chardev: fix parallel device can't be reconnect, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 34/41] nbd: Simplify trace of client flags in negotiation, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 35/41] nbd: Refactor reply to NBD_OPT_EXPORT_NAME, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 36/41] nbd: Implement NBD_OPT_GO on server, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 41/41] translate-all: remove redundant !tcg_enabled check in dump_exec_info, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 09/41] char: add backend hotswap handler, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 11/41] char: forbid direct chardevice access for hotswap devices,
Paolo Bonzini <=
- [Qemu-devel] [PULL 18/41] virtio-console: chardev hotswap support, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 20/41] serial: chardev hotswap support, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 22/41] Revert "exec.c: Fix breakpoint invalidation race", Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 24/41] gdbstub: modernise DEBUG_GDB, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 26/41] qom/cpu: remove host_tid field, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 29/41] memory/iommu: QOM'fy IOMMU MemoryRegion, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 30/41] memory/iommu: introduce IOMMUMemoryRegionClass, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 31/41] nbd: Create struct for tracking export info, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 32/41] nbd: Don't bother tracing an NBD_OPT_ABORT response failure, Paolo Bonzini, 2017/07/13
- [Qemu-devel] [PULL 33/41] nbd: Expose and debug more NBD constants, Paolo Bonzini, 2017/07/13