From patchwork Fri Apr 12 16:08:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 788287 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp793626wrm; Fri, 12 Apr 2024 09:09:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX3JGA1PCQvZl1VSJwGwpE0ECbhWxs/kx50egM4KXGL+WVc3XTfeoEIlRMZq+rpT8a0xHKqFLRzW7Fv5xJxn7ra X-Google-Smtp-Source: AGHT+IFmzCzX81DuA6RFBF5e/irNl1Y9IhtMwqlGqIYBRq0LUh52+h7LIQuWn4V63s4m6qIo158a X-Received: by 2002:a05:6122:1349:b0:4d4:1ec7:76e5 with SMTP id f9-20020a056122134900b004d41ec776e5mr3260003vkp.16.1712938181252; Fri, 12 Apr 2024 09:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712938181; cv=none; d=google.com; s=arc-20160816; b=RiS1Y48FAJ70CwXVfJNDvamguNwRWUxnb1TvGuuhECEjapqFfPBC88XlNEn4vsNe3z /zeQ/UiaNzHLbM/lhyv1dlTS8vcPrU8nBUwGRZ0qizXbv9hyrwvNi5F37jawM8KohMnE j6bCa14smaMZpbtP6t841CMv0ugmvrYfuo+rjR70gXCRrzdbJITk7I+mjY3nJ+HjVRko f140rRr4eS5Kp8AZBaGsiYyWrlWobq5XtblJAwpaio4xV+S4w84ZsnwzSZCmf8kPx1U9 /OC2vLXvA/3d7546qoUEUdnWvyM91EuQgNIDQRZ/X75sqTy1EUwZ1YT8BfoqaBZ4iuSv uXEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:to:from :dkim-signature; bh=e/uP53aB4q+23J2glSZ0OAwIIKnVVLxT2g0uleIPttY=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=PY+hzJ3yPDNW4iy4SlueZZKrLGnk+4qjHoSCBOHUwFbxvopMt0BmznlwXGhqfF/RYx PYADbNoHdzaL+VljVwn4gBAU4/LnAZjjH1KTY4ROWTC+ngntWMicdLLSYZzQ4vp7EMr8 uwD/nixQnQE9W3jPkzTK0d37GgGUTtZ+eKAaFkfDMk0SFcB7GYFevvpJKq4FhdTdK7FR 4z1D+IZbqA3fPC8bcb7RZX9kjrSUMLbt5E9YuTTf7V0AmarC3AsuVzQyqfn+433Pdl5y D5njPNM6FxZIfUiGt7/zM9GNXQZY7sn41b6Bkrrn6k0DDjnkJGHLIjr0/Xn6Fm8iMUXu kWsw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XWG1zu8l; 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 j1-20020ac5c301000000b004daad0f8db6si653329vkk.53.2024.04.12.09.09.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2024 09:09:41 -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=XWG1zu8l; 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 1rvJRu-0001uu-65; Fri, 12 Apr 2024 12:08:22 -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 1rvJRr-0001tW-Hm for qemu-devel@nongnu.org; Fri, 12 Apr 2024 12:08:19 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvJRo-0004a8-5O for qemu-devel@nongnu.org; Fri, 12 Apr 2024 12:08:19 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-343d7ff2350so723600f8f.0 for ; Fri, 12 Apr 2024 09:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712938094; x=1713542894; darn=nongnu.org; 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=e/uP53aB4q+23J2glSZ0OAwIIKnVVLxT2g0uleIPttY=; b=XWG1zu8ljbyJMYJ9W9FpUwi411DDItepa15utZcBeuA81L8m/aLqgTqjqV5LCZ7SWP l5a8OOJgThYPpzhgUs19zsK206/BFkGnzOLo2xcjRfzauCWOy1WgCc2cRHb/RH5Lhb09 HoZQSSU+CXX9uPaapwOKw9MLz9jhY7qc5OS9X5G8pnEjHkvUj/dB3cLMDb6JlHSU0cqi v6Nn54M5prnxx+re2YE4bkox2Fs/cIllqqLGEiAQ8Rq39ncNQSf95yoeXv0i8GLHCVun RKpU1wlOi/oRzGEIxX+HvNdlGJv1rN5VCIBzalKw6Ry2v7waBr+QhxfM1LtbZflQc0J2 bo8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712938094; x=1713542894; 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=e/uP53aB4q+23J2glSZ0OAwIIKnVVLxT2g0uleIPttY=; b=haXrsLTopVl3tMriLDGpRlnW6vz05+L1K5Zr1CeVvmBtDMax2qmg2HUdR4Y8mrJ6Dk SfWPB4aPvwlHywCkVxiTMfyspFznsbyvm5QzqYx9CCOMuwxqDCDvtTwnOD5kemM0PLtK 9CE3FTVBUtr/i3wH2R0q4tLRBGBK2J8J1HiRe58NNMrB6Ok3fIERG4NrgpJtvoPs/pag e/9xKteES2P9e1810lr1wx45/qPTC/VWQAO3rpys17DBVIp588gVMnu3B27Q/sbsRhRg W0qbdemBFWuCDv+g2ObBiqmHIeW5VX2Xxhfus+HRyXKEpIhZ3w+MUOhxz8u8CYNPOvIs PwRQ== X-Gm-Message-State: AOJu0Yzr3MHKxXbczAhXrgeq6TsrRpq9uMUe/HjPSRF7qNwlLbQG+bkL Y+fBZ0dZ/nrPUBh2wL0q/A+YPRJO1i1GDHS4PtOH4zN0oxXBrJkrWABeK+shNHd2/MCu5N7/fko e X-Received: by 2002:adf:fe07:0:b0:346:aab2:7979 with SMTP id n7-20020adffe07000000b00346aab27979mr1886852wrr.25.1712938094576; Fri, 12 Apr 2024 09:08:14 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id cr12-20020a05600004ec00b00341ce80ea66sm4582371wrb.82.2024.04.12.09.08.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 09:08:14 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 6/6] reset: Add RESET_TYPE_SNAPSHOT_LOAD Date: Fri, 12 Apr 2024 17:08:09 +0100 Message-Id: <20240412160809.1260625-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412160809.1260625-1-peter.maydell@linaro.org> References: <20240412160809.1260625-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.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 Some devices and machines need to handle the reset before a vmsave snapshot is loaded differently -- the main user is the handling of RNG seed information, which does not want to put a new RNG seed into a ROM blob when we are doing a snapshot load. Currently this kind of reset handling is supported only for: * TYPE_MACHINE reset methods, which take a ShutdownCause argument * reset functions registered with qemu_register_reset_nosnapshotload To allow a three-phase-reset device to also distinguish "snapshot load" reset from the normal kind, add a new ResetType RESET_TYPE_SNAPSHOT_LOAD. All our existing reset methods ignore the reset type, so we don't need to update any device code. Add the enum type, and make qemu_devices_reset() use the right reset type for the ShutdownCause it is passed. This allows us to get rid of the device_reset_reason global we were using to implement qemu_register_reset_nosnapshotload(). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel --- docs/devel/reset.rst | 17 ++++++++++++++--- include/hw/resettable.h | 1 + hw/core/reset.c | 15 ++++----------- hw/core/resettable.c | 4 ---- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst index 49baa1ea271..9746a4e8a0b 100644 --- a/docs/devel/reset.rst +++ b/docs/devel/reset.rst @@ -27,9 +27,7 @@ instantly reset an object, without keeping it in reset state, just call ``resettable_reset()``. These functions take two parameters: a pointer to the object to reset and a reset type. -Several types of reset will be supported. For now only cold reset is defined; -others may be added later. The Resettable interface handles reset types with an -enum: +The Resettable interface handles reset types with an enum ``ResetType``: ``RESET_TYPE_COLD`` Cold reset is supported by every resettable object. In QEMU, it means we reset @@ -37,6 +35,19 @@ enum: from what is a real hardware cold reset. It differs from other resets (like warm or bus resets) which may keep certain parts untouched. +``RESET_TYPE_SNAPSHOT_LOAD`` + This is called for a reset which is being done to put the system into a + clean state prior to loading a snapshot. (This corresponds to a reset + with ``SHUTDOWN_CAUSE_SNAPSHOT_LOAD``.) Almost all devices should treat + this the same as ``RESET_TYPE_COLD``. The main exception is devices which + have some non-deterministic state they want to reinitialize to a different + value on each cold reset, such as RNG seed information, and which they + must not reinitialize on a snapshot-load reset. + +Devices which implement reset methods must treat any unknown ``ResetType`` +as equivalent to ``RESET_TYPE_COLD``; this will reduce the amount of +existing code we need to change if we add more types in future. + Calling ``resettable_reset()`` is equivalent to calling ``resettable_assert_reset()`` then ``resettable_release_reset()``. It is possible to interleave multiple calls to these three functions. There may diff --git a/include/hw/resettable.h b/include/hw/resettable.h index 3161e471c9b..7e249deb8b5 100644 --- a/include/hw/resettable.h +++ b/include/hw/resettable.h @@ -35,6 +35,7 @@ typedef struct ResettableState ResettableState; */ typedef enum ResetType { RESET_TYPE_COLD, + RESET_TYPE_SNAPSHOT_LOAD, } ResetType; /* diff --git a/hw/core/reset.c b/hw/core/reset.c index f9fef45e050..58dfc8db3dc 100644 --- a/hw/core/reset.c +++ b/hw/core/reset.c @@ -43,13 +43,6 @@ static ResettableContainer *get_root_reset_container(void) return root_reset_container; } -/* - * Reason why the currently in-progress qemu_devices_reset() was called. - * If we made at least SHUTDOWN_CAUSE_SNAPSHOT_LOAD have a corresponding - * ResetType we could perhaps avoid the need for this global. - */ -static ShutdownCause device_reset_reason; - /* * This is an Object which implements Resettable simply to call the * callback function in the hold phase. @@ -77,8 +70,7 @@ static void legacy_reset_hold(Object *obj, ResetType type) { LegacyReset *lr = LEGACY_RESET(obj); - if (device_reset_reason == SHUTDOWN_CAUSE_SNAPSHOT_LOAD && - lr->skip_on_snapshot_load) { + if (type == RESET_TYPE_SNAPSHOT_LOAD && lr->skip_on_snapshot_load) { return; } lr->func(lr->opaque); @@ -180,8 +172,9 @@ void qemu_unregister_resettable(Object *obj) void qemu_devices_reset(ShutdownCause reason) { - device_reset_reason = reason; + ResetType type = (reason == SHUTDOWN_CAUSE_SNAPSHOT_LOAD) ? + RESET_TYPE_SNAPSHOT_LOAD : RESET_TYPE_COLD; /* Reset the simulation */ - resettable_reset(OBJECT(get_root_reset_container()), RESET_TYPE_COLD); + resettable_reset(OBJECT(get_root_reset_container()), type); } diff --git a/hw/core/resettable.c b/hw/core/resettable.c index bebf7f10b26..6dd3e3dc487 100644 --- a/hw/core/resettable.c +++ b/hw/core/resettable.c @@ -48,8 +48,6 @@ void resettable_reset(Object *obj, ResetType type) void resettable_assert_reset(Object *obj, ResetType type) { - /* TODO: change this assert when adding support for other reset types */ - assert(type == RESET_TYPE_COLD); trace_resettable_reset_assert_begin(obj, type); assert(!enter_phase_in_progress); @@ -64,8 +62,6 @@ void resettable_assert_reset(Object *obj, ResetType type) void resettable_release_reset(Object *obj, ResetType type) { - /* TODO: change this assert when adding support for other reset types */ - assert(type == RESET_TYPE_COLD); trace_resettable_reset_release_begin(obj, type); assert(!enter_phase_in_progress);