Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2562802pxb; Sun, 8 Nov 2020 05:20:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKkiFr+IrhU9OZ+CnwiTUbEl5JLHrBm6Tdst5a8yIZZT4IEDJz3xtq4+WfXpx+K7auwbxr X-Received: by 2002:a05:6402:559:: with SMTP id i25mr11163010edx.128.1604841610008; Sun, 08 Nov 2020 05:20:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604841610; cv=none; d=google.com; s=arc-20160816; b=BlmrIX5P9XczwH5lALf0K2lZWVa0dbBlSt/4dpWxGURxsy0iD+IzNA4hM7KUPlrODg y4p29omtGcY/JStuQCPblldKVsPDmdfXP+qNlqUsIcHw54+i5t3tYD2RF1V8PJ0hgbWm jF8FdSPCdDnLm6pBWWViNq9cpIETUNb9Wk0HafnWsToEdbVZlMR0tKHxjyCvU9Yd4edw b06hjyRVBlWRYRwyQIdAGg8ZiRCAbeIe9/w0BFKV9NOccwMaZmQMFC5I/kNCNBcFLlmL ZUJIH6fOoGDj+G2gVr3DGteSH07ssfDiq07qE0UhbyRnH0NutTG7+wZYzg91lXWmBtvr +pxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:organization:content-disposition :mime-version:mail-followup-to:message-id:subject:cc:to:from:date; bh=N59kM+Z3SGESq+q5So44hA8owjP3NkuydkvAsabr6bc=; b=eCjdTF+8VY2MMwkD+NcmFp3eUGSPx2m/Z28PSm3ZZ64gHPPUsDlI/Xisf3tMt30fgY Ourahwb51Gj9Fs5tX5d/nmTaTY+V/3krjdGBOrKyT75iqw8YDI/ZVOE/QJUJ/sVxb/Eg p2brD8sdZQ0+ouH3wehkkPvYBZP4/adntCF5bjroCyKSjfuC2qvNP/eOq+6PmFdguMoH xxrgK/86RJoMsr/nvSbfjQc35b61R34Vmk7/WYisHymsbEhsvhSt/5miysJGXYOj1Y09 nImgJDb2bKW+R9ZVbFSqzQ18Si2Yru28/J9FKnkQseecNBvXnrenE5ahyVFsH9Wm/ZhX 1hHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u27si4863613edi.588.2020.11.08.05.19.46; Sun, 08 Nov 2020 05:20:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728516AbgKHNOz (ORCPT + 99 others); Sun, 8 Nov 2020 08:14:55 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:38360 "EHLO hera.aquilenet.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728425AbgKHNOv (ORCPT ); Sun, 8 Nov 2020 08:14:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id EFCFCCF8; Sun, 8 Nov 2020 14:14:45 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m1gaJec65rC8; Sun, 8 Nov 2020 14:14:45 +0100 (CET) Received: from function.youpi.perso.aquilenet.fr (lfbn-bor-1-56-204.w90-50.abo.wanadoo.fr [90.50.148.204]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 11869CF7; Sun, 8 Nov 2020 14:14:44 +0100 (CET) Received: from samy by function.youpi.perso.aquilenet.fr with local (Exim 4.94) (envelope-from ) id 1kbkUj-009KMT-Vb; Sun, 08 Nov 2020 14:12:33 +0100 Date: Sun, 8 Nov 2020 14:12:33 +0100 From: Samuel Thibault To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, speakup@linux-speakup.org Subject: [PATCH] speakup ttyio: Do not schedule() in ttyio_in_nowait Message-ID: <20201108131233.tadycr73sxlvodgo@function> Mail-Followup-To: Samuel Thibault , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, speakup@linux-speakup.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the ltlk and spkout drivers, the index read function, i.e. in_nowait, is getting called from the read_all_doc mechanism, from the timer softirq: Call Trace: dump_stack+0x71/0x98 dequeue_task_idle+0x1f/0x28 __schedule+0x167/0x5d6 ? trace_hardirqs_on+0x2e/0x3a ? usleep_range+0x7f/0x7f schedule+0x8a/0xae schedule_timeout+0xb1/0xea ? del_timer_sync+0x31/0x31 do_wait_for_common+0xba/0x12b ? wake_up_q+0x45/0x45 wait_for_common+0x37/0x50 ttyio_in+0x2a/0x6b spk_ttyio_in_nowait+0xc/0x13 spk_get_index_count+0x20/0x93 cursor_done+0x1c6/0x4c6 ? read_all_doc+0xb1/0xb1 call_timer_fn+0x89/0x140 run_timer_softirq+0x164/0x1a5 ? read_all_doc+0xb1/0xb1 ? hrtimer_forward+0x7b/0x87 ? timerqueue_add+0x62/0x68 ? enqueue_hrtimer+0x95/0x9f __do_softirq+0x181/0x31f irq_exit+0x6a/0x86 smp_apic_timer_interrupt+0x15e/0x183 apic_timer_interrupt+0xf/0x20 We thus should not schedule() at all, even with timeout == 0, this crashes the kernel. We can however use try_wait_for_completion() instead of wait_for_completion_timeout(0). Cc: stable@vger.kernel.org Signed-off-by: Samuel Thibault Reported-by: John Covici Tested-by: John Covici --- drivers/accessibility/speakup/spk_ttyio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/drivers/accessibility/speakup/spk_ttyio.c +++ b/drivers/accessibility/speakup/spk_ttyio.c @@ -298,11 +298,13 @@ static unsigned char ttyio_in(int timeou struct spk_ldisc_data *ldisc_data = speakup_tty->disc_data; char rv; - if (wait_for_completion_timeout(&ldisc_data->completion, + if (!timeout) { + if (!try_wait_for_completion(&ldisc_data->completion)) + return 0xff; + } else if (wait_for_completion_timeout(&ldisc_data->completion, usecs_to_jiffies(timeout)) == 0) { - if (timeout) - pr_warn("spk_ttyio: timeout (%d) while waiting for input\n", - timeout); + pr_warn("spk_ttyio: timeout (%d) while waiting for input\n", + timeout); return 0xff; }