From patchwork Mon Jan 13 17:36:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 856939 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp1546242wrc; Mon, 13 Jan 2025 09:38:54 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVnBdnQWcDyiAmzcariqzgsWZw1wrMaS+1sKyYRPaXkcOUobT73sLoSjFtU0IjgVv22WAG45g==@linaro.org X-Google-Smtp-Source: AGHT+IFAgWspJfs5B+UOrDfuhnCF0rsR1oM0VXfVQiYtA2m7BYMu01QvNeZFG8EEQhftGHejjnnX X-Received: by 2002:a05:620a:19a3:b0:7b6:7618:d7ce with SMTP id af79cd13be357-7bcd96e88c8mr3569204485a.10.1736789934600; Mon, 13 Jan 2025 09:38:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736789934; cv=none; d=google.com; s=arc-20240605; b=R4xgqKi3AYaup228Qsufw1uVYIVlg/kfgeAouFl9VLy3G1siBihb0ehBQduyfrWH4W nWuKy9xMxXoQnY0qG9uiycp4eoaZPSQbFEDpjMkGrrC1Xqa5euzzwsL93rWbjz2EVRbR SfQn3JdvOaqbqiR9bLmg4Ay52KGNmp9nfsTaw+esnmnwopF7/HLkl7rsJWZwd1dOK10z bLFwpx9OQQsHd3Rn5GlCFdLuWsu3i45fdm+jbMBh6ic1TcB9kgyRbrTe6ip1j9xP3t29 8pz0qNo7D/qWGjq4HN4bmsXNO9W32J3MPs4d85KawVDUIahF8KQcOU2euOD2YFIT8f+w A1hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=So15p+H+DSsGmUuH6+mgWAC3ycngOqSbmiFDKA1MmyA=; fh=Pa0Kx7VcbCaepe9+5NP9LrCZ4BMLIY/WxZiYNx05RvE=; b=O0JZc7x4SNX1JBo4HWMBKAmmojdCP0SKfCWoOOXaa71vDLUvQB/Ov6XS7Rd2O35JCy Kmx9nI+enNjfH132xG7ZkNSbNzK8LGlbX17PKJCAj9GW1+JiuDpg6Zq3oDi/3e1knA2O uS5PwodcwPL/6Owf9SFoArkQaGagCQ8JB6kX/HtJgs8nDpEtjfByT1B4NkncbNRPNkRw hVdcJIkRj253Ml1NxmrDjI/WbpG88eTgnGiTqXjNtlRY1jQIIgC1u5rm55dg3Dfl9V7a +X3XI48CiY/fGQkiOtTrx3opvzJmdyThEgjTKnyMCfRVRdj/S0kXGcQBfhO7NEpzuOBr FNig==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHjv8KqM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7bce322a4a9si1159275585a.57.2025.01.13.09.38.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Jan 2025 09:38:54 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHjv8KqM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXONL-00035Z-3A; Mon, 13 Jan 2025 12:37:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXOMg-0002En-Rp for qemu-devel@nongnu.org; Mon, 13 Jan 2025 12:36:39 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tXOMf-00072D-8L for qemu-devel@nongnu.org; Mon, 13 Jan 2025 12:36:38 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4361fe642ddso48335545e9.2 for ; Mon, 13 Jan 2025 09:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736789795; x=1737394595; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=So15p+H+DSsGmUuH6+mgWAC3ycngOqSbmiFDKA1MmyA=; b=cHjv8KqM0maYDidtTkfqeZAeZ+mxjvl9vjmigK6M8AXU0qd/b60TJCFx8sDcllCIAI 7jPz/zzxOyk6paiuea79Dufrp5ahoOSVo1vtcN6m+3MKZPQy9Bvcife75SXsjIlRxXkS 5qgJOvMSJIKSGP+RqotdT1LZVCRym6ilkCk4D+nqxmtyouFOly3js3kw2vbQhXxs9fhJ ROKyMA7EXjhFeFM4dOmex2by7YgMOk/ohi6Ui8crj6DlZ8iBWxN3ZnKEXwZjCGbtOGe8 hoye5egl+R77jp/tbPb3PFOABbW2bIlKC6e60VOP6w31RRamPv+nZNpKPFykxAIHS+PH 4dkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736789795; x=1737394595; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=So15p+H+DSsGmUuH6+mgWAC3ycngOqSbmiFDKA1MmyA=; b=jCSCHdSAKlE/Ot42G+elOHs5pNeiXI1rSac1tzQRBHGuiSkM9TYsAUMTgIfvWS67r0 ETZN9I99BceyJWoeoe5Defhbnscag1eG25glnSA6d/9y/X/LMuBN0YayrChAdnatYYlx lwNIumNjW9rrRH2ZfgT6y3IupLOYAZY9hoObVlUXirlf0Hz+2nRBB1kP8p2821jMbmtK dcnRj0Rt4kJqJXc26S5nK0lU+T2SAF2seMf6gNMUxhUnmEVh5dTSk369IUlaBa7gMVZZ af1dtPhawqFwBtVFhtE78FaOqM+eryLC8mVX28IHhCmYCeRb7WiiH5KzwN6DjQux6t3n C1qg== X-Gm-Message-State: AOJu0YxI9LGckoUNRzK+vqTyRcEJ8dfyLPEXYf/zfgSZPfZpw6NkqwuR jfRvkE3Nk4Nu7bBcEPC6BMWCGAImCH5TkfhivY+ImIsWHARFhwtumt+UAz4u/FAJsUUeBvrf5Np TOEQ= X-Gm-Gg: ASbGncv64Mrnn03w8h0fmmVfzBqLH5Cfbgc2p1RbHahco5k39bl77PkmhuTzMgjzgNr a/0/S0jf9JOvG9IR1pRYzohFyy1c2UJKNjggCrUxZInmAfjmOxKWjvRBhHXwzqU0LLCDFnKOqWp lvuHOhE0HM0W8l9OTVFOYt6H0g9t27TZmuffxztIt9Sd01ZZZmozxDBkQDjln97udIsILUjsS6i xcDDv3rd96LVQDFS4StyV31zJKcgTFlbMlcwLydGt50X252lcVClbdmzPauiGjDxmf1OaTHLZN2 Qw0pxHY6xbMVm8YlX5EEklbXmDwN9Rs= X-Received: by 2002:a05:600c:4f8e:b0:436:fb02:e90 with SMTP id 5b1f17b1804b1-436fb021066mr56367155e9.10.1736789795403; Mon, 13 Jan 2025 09:36:35 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e9d8fba4sm150936005e9.4.2025.01.13.09.36.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 09:36:34 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Igor Mammedov Subject: [PULL v2 11/55] hw/qdev: Check machine_hotplug_handler in hotplug_unplug_allowed_common Date: Mon, 13 Jan 2025 18:36:03 +0100 Message-ID: <20250113173604.46931-7-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113173604.46931-1-philmd@linaro.org> References: <20250113173604.46931-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki 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 [PMD: Split from bigger patch, part 6/6] Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Igor Mammedov Message-Id: <20250110091908.64454-7-philmd@linaro.org> --- hw/core/qdev-hotplug.c | 10 ++++++++++ system/qdev-monitor.c | 14 +++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/hw/core/qdev-hotplug.c b/hw/core/qdev-hotplug.c index f6422cd0e4e..ff176dc1bb3 100644 --- a/hw/core/qdev-hotplug.c +++ b/hw/core/qdev-hotplug.c @@ -48,6 +48,16 @@ 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 e27d25c5859..861c25c855f 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -684,17 +684,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; } /*