From patchwork Tue Oct 25 16:39:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 618136 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3521848pvb; Tue, 25 Oct 2022 09:52:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FzKvJ+0OITqDdSYexZrUBIzjUwAAxIDVYnScAHoaZLevNbdg9WPVddtJKFfZAOWnu+6As X-Received: by 2002:a05:620a:24c9:b0:6ee:d791:9f84 with SMTP id m9-20020a05620a24c900b006eed7919f84mr28225224qkn.490.1666716748801; Tue, 25 Oct 2022 09:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666716748; cv=none; d=google.com; s=arc-20160816; b=e9umt09J92gAwCG98+0Pnt4kH1Ti/qYkM+XPUu3saJkvOPILipQYW2nd+NLCUz3dxa +ubpZpwYLrqg9x3ZbfJAdNMvd+Z5pFcARB4pwWJ7f5Yrx5Hvoa2uu1xE5Wa3f+gxFisu SCGJ7xytbo5cWFup9BPTra3jsMTIfhsKhFAxSDbUFr1WJCQxVS8Cl/ePo34W5+Pvhvp9 6aacwwPjGEX3sZlS/1lOf10kksAQ6XCUbX6G8Hysh1SrNAuugcyn9hNcJMfQASiaVm4S 58dwCMH+NKImz2YRW5okBuzM48dNrcgrIJt/VCQNukovo9EFIT5svQqtmU/gmEclJ7A+ V4hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender: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:to:from :dkim-signature; bh=2ZLMGmvdBh5UWAIoQyzMmECFb98GcnB/juq4BvMu3x4=; b=vyelC1XrvPEmSIMckQ21jWeHQB45v05ar9Rq0bNy8hHXMnucKrEmEZy9d3Wb2VyvNz shkJJtXyXOA1OlpCuhK29vQrxGB25RnHsbZKLyCeelAMaGMVAwHyCjdele80P2YsriHE gdUysFNyREj563AvYlnlKiOMmvGOErZV/oPgnCYJRJlSlxfUSsLiQe3nYvrVFBqBq3jT RrVMGJb1GjAtRkDT6Gje+yc8kR2Ati5U1ei02poXsOClCk1c/adAnD7iGdwakZt8vUOx i87NjRch1j5F4QTZr7CLIJZjA+BFT9tAeyBHqM7S1+E98rp0n3ODfj0HBTKtyW+gb6i4 9LSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OE8gAHnu; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kk4-20020a056214508400b004b196120342si2084692qvb.337.2022.10.25.09.52.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Oct 2022 09:52:28 -0700 (PDT) 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=OE8gAHnu; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onMyQ-0005if-Jv; Tue, 25 Oct 2022 12:40:18 -0400 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 1onMyI-0005Oe-AQ for qemu-devel@nongnu.org; Tue, 25 Oct 2022 12:40:13 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onMyA-0001Od-HD for qemu-devel@nongnu.org; Tue, 25 Oct 2022 12:40:10 -0400 Received: by mail-wm1-x32a.google.com with SMTP id l32so8489501wms.2 for ; Tue, 25 Oct 2022 09:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2ZLMGmvdBh5UWAIoQyzMmECFb98GcnB/juq4BvMu3x4=; b=OE8gAHnuWmScYcgLtsW5t1HAlN0BuIM+rd1R5fnSZgsivUL8TbgPhzUc+y91JWG0Lz NFSn1hvEARGX57Jrawq/VBh4G4qILWL4eKOcquKeLRv2yU0rX7bD5gsqYl2MoVUs9Pli +TPa5vJSL+v9PJH4rFvxCf48ECKop0hUh2dpOUSvQPIN+Y4zcr+W7lf0oE4OivBRJ6uo GF1hsbN4ffGBV9kKibWzXJChpk0SgbYXDE2T3dInNw+QDL30EvmnMnsMQ0iFAROjg7In QCovxmim006iaNtHvY3A0XGh/aQ+fb6+iLUF1uh88u+uiUM5et6LGx3S0oAxqt6zbSfo IQaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ZLMGmvdBh5UWAIoQyzMmECFb98GcnB/juq4BvMu3x4=; b=7yqMgBcTy3qgGflbwrAGqXYJKvKilEBNQbKRomu/lzLFMKu1hjVdvBuMm5c6H785Fr LGzmzdTGm143Du9vSLOt6n0yXZrZB4hAbGWcmorpBfrAnPWRcnOsM6VdBYnsK8mKjmIw rpYJ4pZm4ojjcnI+L8Yau/wzMPLUei9wsHbO7NzIUqf+x+pQFvtS7SiwJ7gPxEyfJT3r wIMvAYRafJUTjH/DZQcdde7eBFu4cTro0Nwp1QBNksmNnC8L1rGOiKQIB9bJNZIMWx96 3QObXYRQ2T2VvMyKwP2L1KRPxc7za/iMmKAvlvJplfraH/64V0Dq8hg2ZoAUckRqz+Eh PjpQ== X-Gm-Message-State: ACrzQf02qUxbkccEgn+TcvBvqVY5lbdYKdRFH4j/KtkICrFAovgOUBKY SdBazPA+1iUVAQQ7lyp2WzzWtWnF/SNsEQ== X-Received: by 2002:a05:600c:230d:b0:3c4:2975:321a with SMTP id 13-20020a05600c230d00b003c42975321amr47466204wmo.155.1666715999460; Tue, 25 Oct 2022 09:39:59 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id z12-20020a05600c220c00b003cd9c26a0basm2971084wml.40.2022.10.25.09.39.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:39:58 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 04/30] hw/core/resettable: fix reset level counting Date: Tue, 25 Oct 2022 17:39:26 +0100 Message-Id: <20221025163952.4131046-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025163952.4131046-1-peter.maydell@linaro.org> References: <20221025163952.4131046-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Damien Hedde The code for handling the reset level count in the Resettable code has two issues: The reset count is only decremented for the 1->0 case. This means that if there's ever a nested reset that takes the count to 2 then it will never again be decremented. Eventually the count will exceed the '50' limit in resettable_phase_enter() and QEMU will trip over the assertion failure. The repro case in issue 1266 is an example of this that happens now the SCSI subsystem uses three-phase reset. Secondly, the count is decremented only after the exit phase handler is called. Moving the reset count decrement from "just after" to "just before" calling the exit phase handler allows resettable_is_in_reset() to return false during the handler execution. This simplifies reset handling in resettable devices. Typically, a function that updates the device state will just need to read the current reset state and not anymore treat the "in a reset-exit transition" as a special case. Note that the semantics change to the *_is_in_reset() functions will have no effect on the current codebase, because only two devices (hw/char/cadence_uart.c and hw/misc/zynq_sclr.c) currently call those functions, and in neither case do they do it from the device's exit phase methed. Fixes: 4a5fc890 ("scsi: Use device_cold_reset() and bus_cold_reset()") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1266 Signed-off-by: Damien Hedde Signed-off-by: Peter Maydell Reported-by: Michael Peter Reviewed-by: Philippe Mathieu-Daudé Message-id: 20221020142749.3357951-1-peter.maydell@linaro.org Buglink: https://bugs.launchpad.net/qemu/+bug/1905297 Reported-by: Michael Peter [PMM: adjust the docs paragraph changed to get the name of the 'enter' phase right and to clarify exactly when the count is adjusted; rewrite the commit message] Signed-off-by: Peter Maydell --- docs/devel/reset.rst | 8 +++++--- hw/core/resettable.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst index abea1102dc4..7cc6a6b3140 100644 --- a/docs/devel/reset.rst +++ b/docs/devel/reset.rst @@ -210,9 +210,11 @@ Polling the reset state Resettable interface provides the ``resettable_is_in_reset()`` function. This function returns true if the object parameter is currently under reset. -An object is under reset from the beginning of the *init* phase to the end of -the *exit* phase. During all three phases, the function will return that the -object is in reset. +An object is under reset from the beginning of the *enter* phase (before +either its children or its own enter method is called) to the *exit* +phase. During *enter* and *hold* phase only, the function will return that the +object is in reset. The state is changed after the *exit* is propagated to +its children and just before calling the object's own *exit* method. This function may be used if the object behavior has to be adapted while in reset state. For example if a device has an irq input, diff --git a/hw/core/resettable.c b/hw/core/resettable.c index 96a99ce39ea..c3df75c6ba8 100644 --- a/hw/core/resettable.c +++ b/hw/core/resettable.c @@ -201,12 +201,11 @@ static void resettable_phase_exit(Object *obj, void *opaque, ResetType type) resettable_child_foreach(rc, obj, resettable_phase_exit, NULL, type); assert(s->count > 0); - if (s->count == 1) { + if (--s->count == 0) { trace_resettable_phase_exit_exec(obj, obj_typename, !!rc->phases.exit); if (rc->phases.exit && !resettable_get_tr_func(rc, obj)) { rc->phases.exit(obj); } - s->count = 0; } s->exit_phase_in_progress = false; trace_resettable_phase_exit_end(obj, obj_typename, s->count);