From patchwork Mon Aug 28 01:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Niethe X-Patchwork-Id: 1826589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=ds16qOxl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RYtVM0dpBz1yfX for ; Mon, 28 Aug 2023 11:38:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=ds16qOxl; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RYtVL6jmBz30NN for ; Mon, 28 Aug 2023 11:38:02 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=ds16qOxl; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::531; helo=mail-pg1-x531.google.com; envelope-from=jniethe5@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RYtVB4Nfhz2yW7 for ; Mon, 28 Aug 2023 11:37:54 +1000 (AEST) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-563f8e8a53dso1144970a12.3 for ; Sun, 27 Aug 2023 18:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693186671; x=1693791471; 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=wMX1vtbY0tg3XjzUzEvo8Xt/Pgu0+SOyiQjOHZZLNX0=; b=ds16qOxlQ9V+Ax9BqcK+QSV6DObaNL1nycEYzHNnJB9ndlVNPDB4T7gzsoxkHbnQgs JjySWJIQfFZsKev4TQhVfFQzsMvPaLYSmRAeOzXcqf+duRBd6IqoLr5zjh9YhjddZ8Z3 s7krXbT940FmZ+uuJwLyjXxBpsQI+3w7g6UZaMGA2KIVTf5f5r+7uz/NDL3mYMeN9uX6 DHT98m2t+6HkLExgyMqIzdaM1VHxyTW1UEFJQ95JowBrI+6TxAgbgOZGSmEsRK/Awdlh tfyxO5PUiwp8zgRpgxr/+JIwMAs+EO5Xa9qW309cf1HDqwqFU1G0eVdU9mXrDbt9INUA nanQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693186671; x=1693791471; 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=wMX1vtbY0tg3XjzUzEvo8Xt/Pgu0+SOyiQjOHZZLNX0=; b=WyrfqSZuP3ppSTA93uG+iJaXfsETf9f7W+u9eq7KVZ+ard9mnoE3vMx4s73qqwQ+TF 18PgSQ/v+DEuqOCcQHrhfJrAc8vW7gqEk1+46hzGlJ1WtW9IdIgbrMDO95GCUz56AC0R vakhkDfrdv7Xljp/ykOLQ25G0VALsZPyS+8PUBsOocj6zsn+wTT+RFSJvwJ/yh4O7vva PLAVXVdA7Q+Q+C39qXGwZavVcbSCUaCrbJytiYYe3+BRizHPclK5rMkPTztM3jkKDgjb x57jvLkVjds+oW5SfRQwwx955lp4m3fQr8UHwq7RD6OgVEW63t2DxAcOv4s3z7K5SjW7 I1jg== X-Gm-Message-State: AOJu0YyHYYauSJKYi5rfLdzcQ26rPNd3rbQis7Pr+FuZIH6ikS39mcdv 5wfbBy32080elc03P+OiGgDLwLmUKsgV0w== X-Google-Smtp-Source: AGHT+IETGMQ0IRJ7Y5hFk3FIHLCKznHQFU+2EJH8NxodvMdhQa0ER5wbs++a4ULFbk2xMbzG8Q+wmg== X-Received: by 2002:a17:902:ced1:b0:1be:1fc:8ce0 with SMTP id d17-20020a170902ced100b001be01fc8ce0mr22421978plg.12.1693186671296; Sun, 27 Aug 2023 18:37:51 -0700 (PDT) Received: from pwon.ibmuc.com (159-196-117-139.9fc475.syd.nbn.aussiebb.net. [159.196.117.139]) by smtp.gmail.com with ESMTPSA id 21-20020a170902c25500b001b89536974bsm5934364plg.202.2023.08.27.18.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 18:37:50 -0700 (PDT) From: Jordan Niethe To: slof@lists.ozlabs.org Date: Mon, 28 Aug 2023 11:37:36 +1000 Message-Id: <20230828013736.18414-3-jniethe5@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230828013736.18414-1-jniethe5@gmail.com> References: <20230828013736.18414-1-jniethe5@gmail.com> MIME-Version: 1.0 Subject: [SLOF] [PATCH 3/3] virtio-serial: Do not close stdout on quiesce X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kconsul@linux.vnet.ibm.com, groug@kaod.org Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" Commit 76fee95 ("slof: Only close stdout for virtio-serial devices") says that commit cf28264 ("virtio-serial: Rework shutdown sequence") fixed a hang. The problem was believed to be that it was necessary to close stdout to shutdown the underlying virtio device. Commit cf28264 ("virtio-serial: Rework shutdown sequence") closed stdout on quiesce. This meant when prom_init() called write on stdout after quiesce, there is a use after free so this is unreliable, and can also hang (especially after reboots). Quiescing is intended to put hardware into a safe state for the client to take over. It is incorrect for SLOF to close ihandles that the client could still be using, even after a quiesce. Rather than closing the stdout device, all that needs to happen is to ensure virtio-serial-shutdown gets called. On quiesce, close the virtio device, but leave the stdout device itself open. Commit 8174acd ("virtio-serial: Close device completely") handles reads and writes as no-ops if the underlying virtio device is closed so there is no problem with the client calling "write" on stdout after this, but no output will be displayed. Fixes: cf28264 ("virtio-serial: Rework shutdown sequence") Debugged-by: Kautuk Consul Co-developed-by: Kautuk Consul Signed-off-by: Kautuk Consul Signed-off-by: Jordan Niethe --- board-qemu/slof/virtio-serial.fs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/board-qemu/slof/virtio-serial.fs b/board-qemu/slof/virtio-serial.fs index 41e2e04..54dacff 100644 --- a/board-qemu/slof/virtio-serial.fs +++ b/board-qemu/slof/virtio-serial.fs @@ -33,8 +33,6 @@ virtio-setup-vd VALUE virtiodev : virtio-serial-term-key? virtiodev virtio-serial-haschar ; : virtio-serial-term-key BEGIN virtio-serial-term-key? UNTIL virtiodev virtio-serial-getchar ; -: virtio-serial-close-stdout s" stdout" get-chosen IF decode-int nip nip close-dev THEN ; - \ Basic device initialization - which has only to be done once : init ( -- ) virtiodev virtio-serial-init drop @@ -42,7 +40,7 @@ virtiodev virtio-serial-init drop \ Linux closes stdin at some point in prom_init(). This internally triggers a \ quiesce in SLOF. We must ensure stdout gets closed as well otherwise the \ device cannot be reset properly and the boot will hang. - ['] virtio-serial-close-stdout add-quiesce-xt + ['] shutdown add-quiesce-xt ; 0 VALUE open-count @@ -62,8 +60,8 @@ virtiodev virtio-serial-init drop open-count 0> IF open-count 1 - dup to open-count 0= IF shutdown THEN + close THEN - close ; : write ( addr len -- actual )