Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp409739lqg; Thu, 11 Apr 2024 06:50:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMTxWev1YaWr1Ig+lJhOrlvh8yJDfFPfTjZiP70NbRoQgNPsDQQ0z7th4INnhYbcgO2zYUFvNqIE+IKhp/lzntHgY/qmKgRMj5VVuchQ== X-Google-Smtp-Source: AGHT+IFuTpUwI7MOugWbtG/8V0iyIJEKuUIAe0y7TzTzeJIZXtvFUDlkIuuIxaKEwmI6e/U289S6 X-Received: by 2002:a17:907:6d1f:b0:a52:1820:103b with SMTP id sa31-20020a1709076d1f00b00a521820103bmr2948577ejc.2.1712843455754; Thu, 11 Apr 2024 06:50:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712843455; cv=pass; d=google.com; s=arc-20160816; b=Ha5pRjHPU9e5FMkNAMFuWOVIPtjAjBT2Zg/HVUt7soUpcfmXg1XS2YMw/MAFNhLD6I 7/d+obOH66SJkXtJ5nY4r7kseuFigYAkRcdVNIj/WfNbby+o54JGoeEPELXSJHtwYM5Y r5jnvkP417S54HYn33S/Ops+I6jbdUgnuy5ldTygVYCyH0zLUh98o2IFu2OsteVQ6p0x 0WbuXXj+M4xR6+f0RKRQTDjloSelIlhd5hVtLGFN8gxiE8QLUbVqRpKppZSGXNTRpaxm 4R8pXOs6zFbLssXj8nHq+KSvfZkaXxx/hSlY7oMWeYMgABCyeUneiE2J6wGh+wv8f3Rx aTkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date; bh=gBiP73NPo0WukeeNNZCzXgnu3dwo3YbjgzkGIAgilGI=; fh=30IucGZHj4fAzK0mmdw2blDDdXas7wVuHYEEp7uFAIw=; b=CmGis65vhLwcyvgigfm3F861y+GucMDheqjdlBnNfu4ErkBzrVXN02pPhXKhqMtW6p h/RHSb0EBIk/5CCnqQnCLW5w9+o6C9DEDPil3dUPO2oqGwnM5TBXIR4gq+LWDdWiBjHk i0XiEyS9ecRQ/rQDE5B0TQf1qe472ff6H8lCVZkINewpBrJm9eAKp7Y12fmWGcnfHOj9 teSMNuUmGqoT7re7RSsEpPMPRKH4bKoLH9xgpxY2L97XluyoGFCn2RQ7L/iy7/V2Zbfl 6jRATDVtSMt5nWKrmpKxsDyxOw653HOdIyfYy5J/FCfqWJbM6c0WRYQwsOmt4ResQdq3 eTCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zte.com.cn dmarc=pass fromdomain=zte.com.cn); spf=pass (google.com: domain of linux-kernel+bounces-140568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l21-20020a1709066b9500b00a51d3658975si775919ejr.852.2024.04.11.06.50.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 06:50:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zte.com.cn dmarc=pass fromdomain=zte.com.cn); spf=pass (google.com: domain of linux-kernel+bounces-140568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7DBC01F22194 for ; Thu, 11 Apr 2024 13:50:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7991114D6E0; Thu, 11 Apr 2024 13:50:49 +0000 (UTC) Received: from mxct.zte.com.cn (mxct.zte.com.cn [58.251.27.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93FBC14BF8D for ; Thu, 11 Apr 2024 13:50:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=58.251.27.85 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712843449; cv=none; b=admJ/3D+BAkReqmZNsfF4EFbTFA7B/jYKgnUD9CJNnxUaY6pw8eHlWbR4+4TZH3B6DREzyI4Q5wpceevk9WitqjmExffX5oKME1BDBN/FtLSC9B/BQ5xiVaMO0flPrUTXG7ar49brtxQ9wv7u2FpiGmIsP+6U847frFT1wGos5o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712843449; c=relaxed/simple; bh=5tZzAQ3pT/J97nL1xvjN2jr8PRlgTWfwPZhAnSs4iTU=; h=Date:Message-ID:Mime-Version:From:To:Cc:Subject:Content-Type; b=AqsmeciHKSQ8YfbPfkO6w/SJab0Fzp4X1V8IcSy08203swdBwF+OCltMMC1pi2QYlWa2jdkXKuYx6vSGmnt+ZPbG9fHMXGe+m+luvOhCNFcBeQQuw5wVu0ObFrhRGcN31PhDUtt57y8c29tEHkfZQAIhoczBCkUnsHxMmIRkelM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=58.251.27.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mxde.zte.com.cn (unknown [10.35.20.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4VFh0r6xSZzW8G for ; Thu, 11 Apr 2024 21:50:36 +0800 (CST) Received: from mxhk.zte.com.cn (unknown [192.168.250.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxde.zte.com.cn (FangMail) with ESMTPS id 4VFh0l6RqfzBRZ5q for ; Thu, 11 Apr 2024 21:50:31 +0800 (CST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4VFh0V5pn9z8XrRB; Thu, 11 Apr 2024 21:50:18 +0800 (CST) Received: from xaxapp03.zte.com.cn ([10.88.97.17]) by mse-fl1.zte.com.cn with SMTP id 43BDoDmT006048; Thu, 11 Apr 2024 21:50:13 +0800 (+08) (envelope-from li.hao40@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid31; Thu, 11 Apr 2024 21:50:17 +0800 (CST) Date: Thu, 11 Apr 2024 21:50:17 +0800 (CST) X-Zmail-TransId: 2afa6617ea99ffffffffb9d-ff120 X-Mailer: Zmail v1.0 Message-ID: <20240411215017604oDcKsSipiLnfwd2SzAnsj@zte.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: Cc: , , Subject: =?UTF-8?B?W1BBVENIXSB0dHk6IGh2Yzogd2FrZXVwIGh2YyBjb25zb2xlIGltbWVkaWF0ZWx5IHdoZW4gbmVlZGVk?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 43BDoDmT006048 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6617EAAB.000/4VFh0r6xSZzW8G From: Li Hao Cancel the do_wakeup flag in hvc_struct, and change it to immediately wake up tty when hp->n_outbuf is 0 in hvc_push(). When we receive a key input character, the interrupt handling function hvc_handle_interrupt() will be executed, and the echo thread flush_to_ldisc() will be added to the queue. If the user is currently using tcsetattr(), a hang may occur. tcsetattr() enters kernel and waits for hp->n_outbuf to become 0 via tty_wait_until_sent(). If the echo thread finishes executing before reaching tty_wait_until_sent (for example, put_chars() takes too long), it will cause while meeting the wakeup condition (hp->do_wakeup = 1), tty_wait_until_sent() cannot be woken up (missed the tty_wakeup() of this round's tty_poll). Unless the next key input character comes, hvc_poll will be executed, and tty_wakeup() will be performed through the do_wakeup flag. Signed-off-by: Li Hao --- drivers/tty/hvc/hvc_console.c | 12 +++++------- drivers/tty/hvc/hvc_console.h | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index cdcc64ea2554..4f06aead690a 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -476,11 +476,13 @@ static void hvc_hangup(struct tty_struct *tty) static int hvc_push(struct hvc_struct *hp) { int n; + struct tty_struct *tty; n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); + tty = tty_port_tty_get(&hp->port); if (n <= 0) { if (n == 0 || n == -EAGAIN) { - hp->do_wakeup = 1; + tty_wakeup(tty); return 0; } /* throw away output on error; this happens when @@ -491,7 +493,7 @@ static int hvc_push(struct hvc_struct *hp) if (hp->n_outbuf > 0) memmove(hp->outbuf, hp->outbuf + n, hp->n_outbuf); else - hp->do_wakeup = 1; + tty_wakeup(tty); return n; } @@ -739,11 +741,7 @@ static int __hvc_poll(struct hvc_struct *hp, bool may_sleep) poll_mask |= HVC_POLL_READ; out: - /* Wakeup write queue if necessary */ - if (hp->do_wakeup) { - hp->do_wakeup = 0; - tty_wakeup(tty); - } + /* Wakeup in hvc_push */ bail: spin_unlock_irqrestore(&hp->lock, flags); diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h index 18d005814e4b..164ae2c82b98 100644 --- a/drivers/tty/hvc/hvc_console.h +++ b/drivers/tty/hvc/hvc_console.h @@ -36,7 +36,6 @@ struct hvc_struct { struct tty_port port; spinlock_t lock; int index; - int do_wakeup; char *outbuf; int outbuf_size; int n_outbuf; -- 2.25.1