From patchwork Thu Jan 23 13:28:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1228176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=greensocs.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=2bYxY1K1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483RLd3933z9sSP for ; Fri, 24 Jan 2020 02:40:41 +1100 (AEDT) Received: from localhost ([::1]:59598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iueb0-0001RX-LV for incoming@patchwork.ozlabs.org; Thu, 23 Jan 2020 10:40:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46961) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucXL-00057m-W0 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iucXK-0003iM-JD for qemu-devel@nongnu.org; Thu, 23 Jan 2020 08:28:43 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:56764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iucXK-0003hW-AE; Thu, 23 Jan 2020 08:28:42 -0500 Received: from crumble.bar.greensocs.com (crumble.bar.greensocs.com [172.16.11.102]) by beetle.greensocs.com (Postfix) with ESMTPS id 6D77696F56; Thu, 23 Jan 2020 13:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1579786121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dzvKbyxikkccILCxuKcmdnhT6iGxt2vyARq+Np6UnOc=; b=2bYxY1K1dG5Sh3ldZKJQN8SP8BibRI6cE3QXyH6YQPdGQgUpM/hlv/Uwbs5+gkZNt/oDwZ 3JM8eBsUlUKdBwwmImcAUvUkF0ZoKhXxBpGWWwac3TwUb+zVNT+dH8kXNygwH9urDGTJ/V dre1I3Lz9C0SKb5uooV1ycE3Lv5C7Vs= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [PATCH v8 07/11] hw/core/qdev: update hotplug reset regarding resettable Date: Thu, 23 Jan 2020 14:28:19 +0100 Message-Id: <20200123132823.1117486-8-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200123132823.1117486-1-damien.hedde@greensocs.com> References: <20200123132823.1117486-1-damien.hedde@greensocs.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1579786121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dzvKbyxikkccILCxuKcmdnhT6iGxt2vyARq+Np6UnOc=; b=uEHF7HbOQLZ4xns06KRXrcke7EW0X/fBoJK7Ctoohlh5K0/xndLW+Ly0Z3PO46AGm9L5Zi JzakeRBqcgZizjP8jkw1F+db49rz+mBw4pQ+wCQ2pXgLapLzrmWwbCB2qIOQHEsALxTsyS LM2AObxJU5/cumGFEPpBvTzAr6hXvEg= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1579786121; a=rsa-sha256; cv=none; b=1uXaVinekaoULMrbQDZzxWm41fRV0hV+Am8JbGIBJAYi1PcbvJ4G9NUXo9sm2qaFG8JPHh zPCp70GtVhtUEKkwQGjkO7aqF4hzhhPGXGsn//32Gw7pQTmKKNBjKKo0JwOqpoUocHY8AR 5GBrKAiZh1/LAx5sU6L0x9rj7xtLl1c= ARC-Authentication-Results: i=1; beetle.greensocs.com; none X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 5.135.226.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Damien Hedde , peter.maydell@linaro.org, berrange@redhat.com, ehabkost@redhat.com, Richard Henderson , cohuck@redhat.com, mark.burton@greensocs.com, qemu-s390x@nongnu.org, edgari@xilinx.com, pbonzini@redhat.com, philmd@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This commit make use of the resettable API to reset the device being hotplugged when it is realized. Also it ensures it is put in a reset state coherent with the parent it is plugged into. Note that there is a difference in the reset. Instead of resetting only the hotplugged device, we reset also its subtree (switch to resettable API). This is not expected to be a problem because sub-buses are just realized too. If a hotplugged device has any sub-buses it is logical to reset them too at this point. The recently added should_be_hidden and PCI's partially_hotplugged mechanisms do not interfere with realize operation: + In the should_be_hidden use case, device creation is delayed. + The partially_hotplugged mechanism prevents a device to be unplugged and unrealized from qdev POV and unrealized. Signed-off-by: Damien Hedde Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- v7 update: inline resettable_state_clear() v6 update: clear the reset state before doing any reset. Although it is apparently highly improbable that a device be realized again after being unrealized. See here for a discussion about this point and the partially_hotplugged/shoud_be_hidden cases. https://lists.nongnu.org/archive/html/qemu-devel/2019-11/msg04897.html --- include/hw/resettable.h | 11 +++++++++++ hw/core/qdev.c | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/hw/resettable.h b/include/hw/resettable.h index 96073354fd..5e215d94e4 100644 --- a/include/hw/resettable.h +++ b/include/hw/resettable.h @@ -153,6 +153,17 @@ struct ResettableState { bool exit_phase_in_progress; }; +/** + * resettable_state_clear: + * Clear the state. It puts the state to the initial (zeroed) state required + * to reuse an object. Typically used in realize step of base classes + * implementing the interface. + */ +static inline void resettable_state_clear(ResettableState *state) +{ + memset(state, 0, sizeof(ResettableState)); +} + /** * resettable_reset: * Trigger a reset on an object @obj of type @type. @obj must implement diff --git a/hw/core/qdev.c b/hw/core/qdev.c index ce23b35383..36bfcbc697 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -938,6 +938,12 @@ static void device_set_realized(Object *obj, bool value, Error **errp) } } + /* + * Clear the reset state, in case the object was previously unrealized + * with a dirty state. + */ + resettable_state_clear(&dev->reset); + QLIST_FOREACH(bus, &dev->child_bus, sibling) { object_property_set_bool(OBJECT(bus), true, "realized", &local_err); @@ -946,7 +952,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp) } } if (dev->hotplugged) { - device_legacy_reset(dev); + /* + * Reset the device, as well as its subtree which, at this point, + * should be realized too. + */ + resettable_assert_reset(OBJECT(dev), RESET_TYPE_COLD); + resettable_change_parent(OBJECT(dev), OBJECT(dev->parent_bus), + NULL); + resettable_release_reset(OBJECT(dev), RESET_TYPE_COLD); } dev->pending_deleted_event = false;