[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 6/6] hw/qdev: Check machine_hotplug_handler in hotplug_unplug_
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v5 6/6] hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common |
Date: |
Fri, 10 Jan 2025 10:19:08 +0100 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
Commit 03fcbd9dc508 ("qdev: Check for the availability of a hotplug
controller before adding a device") says:
> The qdev_unplug() function contains a g_assert(hotplug_ctrl)
> statement, so QEMU crashes when the user tries to device_add +
> device_del a device that does not have a corresponding hotplug
> controller.
> The code in qdev_device_add() already checks whether the bus has a
> proper hotplug controller, but for devices that do not have a
> corresponding bus, here is no appropriate check available yet. In that
> case we should check whether the machine itself provides a suitable
> hotplug controller and refuse to plug the device if none is available.
However, it forgot to add the corresponding check to qdev_unplug().
Check the machine hotplug handler once in the common
qdev_hotplug_unplug_allowed_common() helper so both hotplug
and hot-unplug path are covered.
Fixes: 7716b8ca74 ("qdev: HotplugHandler: Add support for unplugging BUS-less
devices")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/core/qdev-hotplug.c | 7 +++++++
system/qdev-monitor.c | 14 +++-----------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/hw/core/qdev-hotplug.c b/hw/core/qdev-hotplug.c
index f6422cd0e4e..e11597acd1f 100644
--- a/hw/core/qdev-hotplug.c
+++ b/hw/core/qdev-hotplug.c
@@ -48,6 +48,13 @@ static bool qdev_hotplug_unplug_allowed_common(DeviceState
*dev, BusState *bus,
bus->name);
return false;
}
+ } else {
+ if (!qdev_get_machine_hotplug_handler(dev)) {
+ /* No bus, no machine hotplug handler --> device is not
hotpluggable */
+ error_setg(errp, "Device '%s' can not be hotplugged on this
machine",
+ object_get_typename(OBJECT(dev)));
+ return false;
+ }
}
return true;
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index 99b638c0aca..30f28eb8e4a 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -683,17 +683,9 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
dev = qdev_new(driver);
/* Check whether the hotplug is allowed by the machine */
- if (phase_check(PHASE_MACHINE_READY)) {
- if (!qdev_hotplug_allowed(dev, bus, errp)) {
- goto err_del_dev;
- }
-
- if (!bus && !qdev_get_machine_hotplug_handler(dev)) {
- /* No bus, no machine hotplug handler --> device is not
hotpluggable */
- error_setg(errp, "Device '%s' can not be hotplugged on this
machine",
- driver);
- goto err_del_dev;
- }
+ if (phase_check(PHASE_MACHINE_READY) &&
+ !qdev_hotplug_allowed(dev, bus, errp)) {
+ goto err_del_dev;
}
/*
--
2.47.1
- [PATCH v5 0/6] hw/core: Unify hotplug decision logic, Philippe Mathieu-Daudé, 2025/01/10
- [PATCH v5 1/6] hw/qdev: Pass bus argument to qdev_hotplug_allowed(), Philippe Mathieu-Daudé, 2025/01/10
- [PATCH v5 2/6] hw/qdev: Factor qdev_hotunplug_allowed() out, Philippe Mathieu-Daudé, 2025/01/10
- [PATCH v5 3/6] hw/qdev: Introduce qdev_hotplug_unplug_allowed_common(), Philippe Mathieu-Daudé, 2025/01/10
- [PATCH v5 4/6] hw/qdev: Check DevClass::hotpluggable in hotplug_unplug_allowed_common, Philippe Mathieu-Daudé, 2025/01/10
- [PATCH v5 5/6] hw/qdev: Check qbus_is_hotpluggable in hotplug_unplug_allowed_common, Philippe Mathieu-Daudé, 2025/01/10
- [PATCH v5 6/6] hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common,
Philippe Mathieu-Daudé <=
- Re: [PATCH v5 0/6] hw/core: Unify hotplug decision logic, Philippe Mathieu-Daudé, 2025/01/10