From patchwork Mon Aug 28 01:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Niethe X-Patchwork-Id: 1826587 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=sgmTE5Xx; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RYtVH3hZYz1yfX for ; Mon, 28 Aug 2023 11:37:59 +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=sgmTE5Xx; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RYtVG1P2Tz30dt for ; Mon, 28 Aug 2023 11:37:58 +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=sgmTE5Xx; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=jniethe5@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 4RYtV674wcz2yW7 for ; Mon, 28 Aug 2023 11:37:49 +1000 (AEST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bee82fad0fso13838175ad.2 for ; Sun, 27 Aug 2023 18:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693186665; x=1693791465; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/MQIwQoIlx3352PpdiiIpCvo2bs6/8iItxanBx0sjg8=; b=sgmTE5Xxumg/iDYet1rBNB7UNRg1SJgLrllh4Y7fd6wwAbS3z8RE1+LfnOTlvWgKse GAYc5/L16gosqvJ6K20KutTxchcNEcf6nhoZuOJ5UaCmSH4YkZytxvXsvSvvFvHcaGul iPxTtsc7FalwhW3aEBvu7/o6WBRKyj/yHyA7K67wGKpXDFPAR5/t8p/vZWCTlmQidwlW 3Eh7qOzwfrE2ijLzdfWDwlutTQWvn9BTMEnbbjiQgfJWmKvqTBlJqTJfyrI09r1tcSXH 0ccSKuiOvlN9BkviBJJ2r2tbFKtj0Z1NLBP2hWD5NG9/qQC+KL8cOEQCHalkujwdePeL ic3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693186665; x=1693791465; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/MQIwQoIlx3352PpdiiIpCvo2bs6/8iItxanBx0sjg8=; b=M9qr49Jqs0o0Z52/m9QhO/3sXhbBSbnax8ZKm+NXCyAlDXRXCqdChneV4Olw7eK5Rm bMOISHRhx0yvItqK3JlsVZwqD6FrxbL2lQZp8pcbvsM97BjwULhs/USR6URbpdyzcfhW L0YHj35p59SqNfE9GhXZEqSbyhp5UhRq48H945m0zx4HOCHnOwFN5w2B8jNbrbm09NXM Q8F6ybg2MMRhSZv8GlM/4BUUVJARjW2VM5cojh1D/Gv0U7GerjAN37wLaXB4BsJtZzVk G81VRsCr33LoolpHLXMNJ66GsT0TfDZ2u8txDiDso7BvgxeEeOcOL8fkoQxbT3C2HBMH atVA== X-Gm-Message-State: AOJu0YwMxmDFtwOag83g8tkoDnmnEmtQTjUXhoQA+I8jyH4nhVeNBWqH sQDBcIqNPg38JMyvDXrSLVBRzdtuQnuIAQ== X-Google-Smtp-Source: AGHT+IF841vwN6xvQjkz05nOT4XsxoPo8hAR2mI69zeDHNrEWb65KLfYgk+v374taedalPvjq2vNfw== X-Received: by 2002:a17:902:c412:b0:1bf:25a0:f870 with SMTP id k18-20020a170902c41200b001bf25a0f870mr27912407plk.27.1693186664662; Sun, 27 Aug 2023 18:37:44 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 18:37:44 -0700 (PDT) From: Jordan Niethe To: slof@lists.ozlabs.org Date: Mon, 28 Aug 2023 11:37:34 +1000 Message-Id: <20230828013736.18414-1-jniethe5@gmail.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Subject: [SLOF] [PATCH 1/3] virtio-serial: Fix invalid stack access with closed virtio device 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" When virtiodev is 0, its read method accesses beyond the end of the stack with nip. Instead finish with 1 on the stack to mirror the virtio-serial-getchar case and the behavior of the write method to return successfully even with the virtio device closed. Fixes: 8174acd ("virtio-serial: Close device completely") Co-developed-by: Kautuk Consul Signed-off-by: Kautuk Consul Signed-off-by: Jordan Niethe --- board-qemu/slof/virtio-serial.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board-qemu/slof/virtio-serial.fs b/board-qemu/slof/virtio-serial.fs index 82868e2..a67a310 100644 --- a/board-qemu/slof/virtio-serial.fs +++ b/board-qemu/slof/virtio-serial.fs @@ -78,7 +78,7 @@ virtiodev virtio-serial-init drop : read ( addr len -- actual ) 0= IF drop 0 EXIT THEN - virtiodev 0= IF nip EXIT THEN + virtiodev 0= IF drop 1 EXIT THEN virtiodev virtio-serial-haschar 0= IF 0 swap c! -2 EXIT THEN virtiodev virtio-serial-getchar swap c! 1 ; From patchwork Mon Aug 28 01:37:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Niethe X-Patchwork-Id: 1826588 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=CW1HhHJD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; 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 [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RYtVJ4trnz1yfX for ; Mon, 28 Aug 2023 11:38:00 +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=CW1HhHJD; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RYtVJ3zJdz30P3 for ; Mon, 28 Aug 2023 11:38:00 +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=CW1HhHJD; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::633; helo=mail-pl1-x633.google.com; envelope-from=jniethe5@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 4RYtV70rpgz2yw0 for ; Mon, 28 Aug 2023 11:37:50 +1000 (AEST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bdbf10333bso21177295ad.1 for ; Sun, 27 Aug 2023 18:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693186668; x=1693791468; 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=85qEiz75H8B8yGxcydz+sE/gsYwW1LM7p9acc1uppFU=; b=CW1HhHJD7q70sMjAOF19ET/WA5NNtFBBpUnsKKU5cnfFCebnL7R7m00ybvZXSd/a4l 29put2vzNkjud73dwXRN7EBl2kQRwuigKfqgfwmgEMj1byqYZ7AK7lA6ddzTp/dJIdYL DZBttYUbtleKOuRWKn06KSWuWQC1VnBULOg5NsPuO43CP5OLVACDN4KZjpnOhu1yGjB0 MmbqUCrMjOPHvlmhC1LT3uD9slWrUXcyHbgZRw4ka4+mNl/kIKTYlPuHkK23xW1A+NTP YewUOHMyPVL5Wdw1cuzXGqD+eH1vpfuf8zpAUfMKPb/8ln5LcXnzw6oNW9+On+ufkgtF bnrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693186668; x=1693791468; 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=85qEiz75H8B8yGxcydz+sE/gsYwW1LM7p9acc1uppFU=; b=lJFq6u03yVmVE/7M+iJV/bCA/KUtPb0Gt9VsmY2ycJKRKm1yPPoDtU5k1ZfPeWEGYA juJOUyoK2zO6OGyCb4xLkXYQJUaMpn1E0A8HsgJN+S24K0U1yQwpq657HdGm9y90jJoL CqC0u3jpfACD148Us1kVZ9JNFh+jw8v8gcRL0OgUMiXrtLiRX0uR0b5y8lXdYeQ18B6E 6UBnd4YScAM++MpK3i6Qw3MyFgu1MenvzQ/o9E4LFJCEvljx5lBUrFa/mXwiBB3PJzTP D9JCuDdpaYsTVuw1V/CB3BA4mTe+pUxVmu53LMHKS4baRW5DyKEs+4zlY0AyKPO4ruVQ Dw9Q== X-Gm-Message-State: AOJu0YzVreb5Aw5B98fsSRdfZ8bDiqcYHSDFDenLbVpLdtKwkn7L/eBX WU+khoZF5OUp06FqSPvOJDC59SoEUwbL+g== X-Google-Smtp-Source: AGHT+IG3vHBexTKDsChBINOc4gDc9uq0fG0JSLMP+hl0S7SERJlWMMT9Rk73TEdtDj9+prOSbvbZ4w== X-Received: by 2002:a17:903:230e:b0:1bf:6a06:7b60 with SMTP id d14-20020a170903230e00b001bf6a067b60mr26206865plh.66.1693186668066; Sun, 27 Aug 2023 18:37:48 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 18:37:47 -0700 (PDT) From: Jordan Niethe To: slof@lists.ozlabs.org Date: Mon, 28 Aug 2023 11:37:35 +1000 Message-Id: <20230828013736.18414-2-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 2/3] virtio-serial: Make read and write methods report failure 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" From: Kautuk Consul The read and write methods return as though they were successfully even if the virtio device is closed (virtiodev is 0) and it is not able to send or receive any characters. Make the read and write methods return 0 to indicate they did not succeed in this case. Signed-off-by: Kautuk Consul Signed-off-by: Jordan Niethe --- board-qemu/slof/virtio-serial.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/board-qemu/slof/virtio-serial.fs b/board-qemu/slof/virtio-serial.fs index a67a310..41e2e04 100644 --- a/board-qemu/slof/virtio-serial.fs +++ b/board-qemu/slof/virtio-serial.fs @@ -67,7 +67,7 @@ virtiodev virtio-serial-init drop ; : write ( addr len -- actual ) - virtiodev 0= IF nip EXIT THEN + virtiodev 0= IF 2drop 0 EXIT THEN tuck 0 ?DO dup c@ virtiodev SWAP virtio-serial-putchar @@ -78,7 +78,7 @@ virtiodev virtio-serial-init drop : read ( addr len -- actual ) 0= IF drop 0 EXIT THEN - virtiodev 0= IF drop 1 EXIT THEN + virtiodev 0= IF drop 0 EXIT THEN virtiodev virtio-serial-haschar 0= IF 0 swap c! -2 EXIT THEN virtiodev virtio-serial-getchar swap c! 1 ; 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 )