Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1266774lqp; Mon, 15 Apr 2024 00:26:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUXS6wXWasjCFJyLOz37l96uR3O4Lvw6QNcedDysRkSTJEHUlhIdvjRURoikyOPW7oF5+n2T/C9gDcPngZfVaGP81z8qtv/osChJTIEXA== X-Google-Smtp-Source: AGHT+IE4MV+ApqRDLjbvL5pdrrbRRMTm7WRXYnqgGCkJdsty4TvYEHWDaqDPrq6OrDIvo7n8E3fo X-Received: by 2002:a05:620a:12e1:b0:78d:4424:b286 with SMTP id f1-20020a05620a12e100b0078d4424b286mr9954160qkl.39.1713165992617; Mon, 15 Apr 2024 00:26:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713165992; cv=pass; d=google.com; s=arc-20160816; b=Zr3xtVKEqzUXdlCrn9NmKZXhAEgqOu9jqdSbYEHct00LOzUydDAGVUsLw4jY9yjfl0 iFNuITcuL9OR/61OGqQs+71xBfqqSbEXvU4Sp0tMgcB8APeLeY7xjByc3VKWybgPRli+ vlpmP1HzTEOW9tUwhOszVlp19QL46xTT3S4wPp2YuvowMKMLscBj1ucmAjsZOCVLyvft lj6/RDokbgidYAebrpqIDCbHWrc2wcbCkJ+SJxRU4yofD6MvJzuxI9Ay5LR03KXk8PzB QMeDQshxuv8yKwt6tAoX/MjFDHG0M9mlJ2G3xJZzjaKOzcwiHbsn2sxCSU2XFB7zbkk1 IcoQ== 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=v7BjPhAlFBhTEGFMWvftnzDqFaf2G+EAKw4fXvo/KUY=; fh=30IucGZHj4fAzK0mmdw2blDDdXas7wVuHYEEp7uFAIw=; b=tTeuZ7ccu0b5CvCaiIuPzHEBeUWZ2emroTwpHEVtQwV38riyr4FdpdaaowwI/TVMnK MgoqEwLLoHl3HZ4kvtAQw2VuUw8+wyTCLdW0l0rtbOjoYFD0lsj2WE59yI5M4Ve32DzU YIzku+cq/JnOhcqhOn41asI4aGgxIDcWiCqEl9z32s2qp2kfevFUeo9Vlucts1FmjpTU 4r3VOJIK8uJRF4N+DYKsYblrv2U0hRSuRw/TvyyfQ1fhDOxbNyZDFbXmx8gjRR3458Po ZeFGWlDa93ewiiFOwGRpJaJHk4JLpqnkQCq8UpBLytiggevpQBEMHi8WDzdompvAeJb/ tgKw==; 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-144668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144668-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x6-20020ae9e646000000b0078ec3f3d80esi8695653qkl.94.2024.04.15.00.26.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 00:26:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-144668-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144668-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 574441C23119 for ; Mon, 15 Apr 2024 07:26:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C40522C6B9; Mon, 15 Apr 2024 07:26:25 +0000 (UTC) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) (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 A00E42C69D for ; Mon, 15 Apr 2024 07:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.216.63.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713165985; cv=none; b=kJo3kKoPwGpnkF6sKgzAGVhs1IbUyvdC6cCD+zR3mkJTcbk5ItcAwnnEPFaTDyZSHwGZGqLpziz5PyUs9Cf/oASSw1WlsEeXdoS+B3ItN8YaNNx+2ygNx5kWBbeaHc2JUSanu2wjoWY494jtvr33HEprfnIAaw7qihtahpg+DTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713165985; c=relaxed/simple; bh=lHmk46j5smgQwNJBTICXjkHQdeSTlHjk8tSCGkyRRHg=; h=Date:Message-ID:Mime-Version:From:To:Cc:Subject:Content-Type; b=Zh8ejrV+mTMInmAWhk3veiu9USbreSXrr2Lse9A22bfqi2rS3r9pz2qdjZqlkhU2WN49UY13oAEUZIDSnJIPyDLg78mW6xUHWGFZBITx22pyXw733RiaEFK8Dno/Gir3LjfSLyA98OSOlPD+pwdWrhrhN5PmaY/DVAodc40WPRI= 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=63.216.63.35 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 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 4VHzHc2DRbz6FK2S; Mon, 15 Apr 2024 15:26:20 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.99.176]) by mse-fl1.zte.com.cn with SMTP id 43F7QFGx087387; Mon, 15 Apr 2024 15:26:15 +0800 (+08) (envelope-from li.hao40@zte.com.cn) Received: from mapi (xaxapp01[null]) by mapi (Zmail) with MAPI id mid31; Mon, 15 Apr 2024 15:26:17 +0800 (CST) Date: Mon, 15 Apr 2024 15:26:17 +0800 (CST) X-Zmail-TransId: 2af9661cd6996c9-22440 X-Mailer: Zmail v1.0 Message-ID: <20240415152617552rmRLJBUV8aJ4lLJILh6-Z@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?W1BBVENIIHYyXSB0dHk6IGh2Yzogd2FrZXVwIGh2YyBjb25zb2xlIGltbWVkaWF0ZWx5IHdoZW4gbmVlZGVk?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 43F7QFGx087387 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 661CD69C.000/4VHzHc2DRbz6FK2S 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. v1->v2: Some fixes according to: https://lore.kernel.org/all/75dff5cd-7b0e-4039-9157-8bf10cf7ba29@kernel.org/ use tty_port_tty_wakeup() instead of tty_wakeup() to wake up tty Signed-off-by: Li Hao --- drivers/tty/hvc/hvc_console.c | 10 +++------- drivers/tty/hvc/hvc_console.h | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index cd1f657f7..cbd234847 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -480,7 +480,7 @@ static int hvc_push(struct hvc_struct *hp) n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); if (n <= 0) { if (n == 0 || n == -EAGAIN) { - hp->do_wakeup = 1; + tty_port_tty_wakeup(&hp->port); return 0; } /* throw away output on error; this happens when @@ -491,7 +491,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_port_tty_wakeup(&hp->port); return n; } @@ -739,11 +739,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 cf4c1af08..6622f71ba 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; int outbuf_size; int n_outbuf; uint32_t vtermno; -- 2.25.1