From patchwork Tue Feb 20 16:06:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 774273 Delivered-To: patch@linaro.org Received: by 2002:a5d:4943:0:b0:33b:4db1:f5b3 with SMTP id r3csp1730178wrs; Tue, 20 Feb 2024 08:07:56 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV6A615vrRH/CvpdRxnfiXusCKBebPYDCBv1AIwy0EJJa+ZvXQzAeykorxw00s5IgYSpcgeXL321vh8U2JAhujb X-Google-Smtp-Source: AGHT+IHh0SgnvGTlz1FQgyeao8sIVLVChZgsnYqoyxQTnr0pUvIgFw+zBdQ1lAaEsGf35sNUOcjs X-Received: by 2002:ac8:7f05:0:b0:42c:7aef:615c with SMTP id f5-20020ac87f05000000b0042c7aef615cmr18769999qtk.21.1708445276352; Tue, 20 Feb 2024 08:07:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708445276; cv=none; d=google.com; s=arc-20160816; b=liLw2jX5uJJNNloFo7T2qVe5xEHxE48Ox32Gr+Y6W0e2HuPfjuhSaaC18IiYyI6E86 0687r5YTP7O0O77JVSDROYpNRssvFPtOze4h++nZBaSzL9vONLy/K8bFDd8TcnhBBlxs ydXmXnuLxIsYA1lNjmvAyxbH9XiVBelCz/+eBD8NRG526RNSGR0YhOYV1llt/6iUQXf0 HGw4p7Y4lPyEGomCjDPpgy1CPa5R8rq2lve2hisnj2D+b2IXLB5Nk2a8zrLF3FZk6Hue y9yeFE2nA3DeBmHzWdEzyEK1O9afC6CFMezw5+UYpowHHjDRFmX1ENb0e7JAskilfdK4 5dvA== 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:cc:to :from:dkim-signature; bh=FJNxNHiqA9T4HKtvdwd+S2EJnh6+yff9KeawpRzL/Bw=; fh=dm0WNFmBzWrd+9ibIS2DbEOUrG4x0hquFjik6cek7jE=; b=r6rcY7xmDEIdiLugyXiGGAod9n9BYpD1YMErgB3DaSGaDb3KDYs97KznlxO6jfSx0A XwOztOkyKyerKtg9RcybD7Jwi1hdICc83qDmLcXnVAjW+kSiHQFBI1q0YV5p9WhnBuyY WX75w/D9xVHPn51QwqiHpL9Y2ygh5qmmz9N4F7wgd5F9StJBH5Siq/0C4fUp/JTPP7Xm SB6gJPfkGTB+wUjTl/p6FQrNprYDV1rTtuoBSlV61YLDskJcEyIPJETrJnous2+B6Fhw +fI3vcdDE2XsQHUee6e0cztX8qbhPcZi2RVDgF5lFuSehPAkCcWV4IgaAeWxp3F3slS9 N4vA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oI7uj454; 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 u8-20020a05622a14c800b0042da946f329si9542071qtx.738.2024.02.20.08.07.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Feb 2024 08:07:56 -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=oI7uj454; 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 1rcSdc-00026n-IK; Tue, 20 Feb 2024 11:06:32 -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 1rcSdZ-00023G-Qh for qemu-devel@nongnu.org; Tue, 20 Feb 2024 11:06:29 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcSdX-0005Er-Q5 for qemu-devel@nongnu.org; Tue, 20 Feb 2024 11:06:29 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-41272d92b8dso778065e9.1 for ; Tue, 20 Feb 2024 08:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708445186; x=1709049986; 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=FJNxNHiqA9T4HKtvdwd+S2EJnh6+yff9KeawpRzL/Bw=; b=oI7uj454n/km6OvPtvr90DbHlQ2SSeULVG46ZJayK4s2tAX9N1vFSF7HgFt87qId1q jHuGRNvIxqv5pbbUITDNm1WpmHAo3vBLSaW7hzji91bGn+JKOOJDmVd1E0eHJIAF2JTp Vi67ty5vvp7bFijenLF4WZ4lUuTOamx2Z5taWq12ShWtZKMoMlgkII2MD+tl0MycXL4j jPWyRWy8N/JbSgrQx/iUrpH1MXSkL+CCjwfggsDprVL5PknrFl8cJYIdhH5jYOSyVCeq TVy0vpAuyvC2xzFJK+v4uFtadT4kaPCK6WIMAT8JSDPhZ2N8nE89bNzSAHwXwLXLMtzf yh0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708445186; x=1709049986; 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=FJNxNHiqA9T4HKtvdwd+S2EJnh6+yff9KeawpRzL/Bw=; b=bzeOKFgcUIY/pvizF45MeTLVzChVzsg1qoI5/mi18JLl+vd6iSO/8LmY8yX7ekYgPb GTVzjno2+bg6fYqGwtkietiWqK1UPuVizKpdzY7wtKgoNDqif3t6+OBMJWcYSeBQhDhH g24DbAyH7CmG0rAWRB7QH0Iw2iSEle878y39ZByfiu6MjHNjmfvE7crMq2Uezw92pdro IXqAMUZI+/TxCuA81hMackiLcrixHoqr7LWMy39zQhDAGVMzyZCzDw2i38jIwAF6ZNu+ UATLIP2TxueExzSUsx3DM466xsJ8MN3OKckyP2UFdxoHR7VP3/i2j5UggrMzrrKDZipC 6jmw== X-Gm-Message-State: AOJu0YywDHyo2CHoefGPe5zgTBjHTbLJMUm09Xuot3B9NPcoZ/lz7zDB 7WAIhcVnw+iL5/Bo0MEQwA71T0cxNoNgLipwvNAvk9WHsKMQT8m8zcL4XZaV0+itbES+9Rkn5a3 K X-Received: by 2002:a05:600c:3111:b0:412:71d2:9c17 with SMTP id g17-20020a05600c311100b0041271d29c17mr742858wmo.6.1708445186459; Tue, 20 Feb 2024 08:06:26 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b0040f0219c371sm15299927wmq.19.2024.02.20.08.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 08:06:26 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , "Michael S. Tsirkin" , "Gonglei (Arei)" Subject: [PATCH 03/10] system/bootdevice: Don't unregister reset handler in restore_boot_order() Date: Tue, 20 Feb 2024 16:06:15 +0000 Message-Id: <20240220160622.114437-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220160622.114437-1-peter.maydell@linaro.org> References: <20240220160622.114437-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Currently the qemu_register_reset() API permits the reset handler functions registered with it to remove themselves from within the callback function. This is fine with our current implementation, but is a bit odd, because generally reset is supposed to be idempotent, and doesn't fit well in a three-phase-reset world where a resettable object will get multiple callbacks as the system is reset. We now have only one user of qemu_register_reset() which makes use of the ability to unregister itself within the callback: restore_boot_order(). We want to change our implementation of qemu_register_reset() to something where it would be awkward to maintain the "can self-unregister" feature. Rather than making that reimplementation complicated, change restore_boot_order() so that it doesn't unregister itself but instead returns doing nothing for any calls after it has done the "restore the boot order" work. Signed-off-by: Peter Maydell Acked-by: Richard Henderson Reviewed-by: Zhao Liu --- It would be nicer not to use reset at all, especially since I'm not a fan of conflating "system is reset" with "system boots", but I didn't have a good idea for how to do that. --- system/bootdevice.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/system/bootdevice.c b/system/bootdevice.c index 2106f1026ff..2c55c9bd90c 100644 --- a/system/bootdevice.c +++ b/system/bootdevice.c @@ -101,20 +101,23 @@ void validate_bootdevices(const char *devices, Error **errp) void restore_boot_order(void *opaque) { char *normal_boot_order = opaque; - static int first = 1; + static int bootcount = 0; - /* Restore boot order and remove ourselves after the first boot */ - if (first) { - first = 0; + switch (bootcount++) { + case 0: + /* First boot: use the one-time config */ + return; + case 1: + /* Second boot: restore normal boot order */ + if (boot_set_handler) { + qemu_boot_set(normal_boot_order, &error_abort); + } + g_free(normal_boot_order); + return; + default: + /* Subsequent boots: keep using normal boot order */ return; } - - if (boot_set_handler) { - qemu_boot_set(normal_boot_order, &error_abort); - } - - qemu_unregister_reset(restore_boot_order, normal_boot_order); - g_free(normal_boot_order); } void check_boot_index(int32_t bootindex, Error **errp)