Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18373415ybl; Fri, 3 Jan 2020 00:44:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwoM28lJF6siPSC3IHCX821IqLeodlS1qhhKAEtaz729QmVnzrcIDz3I9lNSuV4kF3Cebjp X-Received: by 2002:a05:6830:2116:: with SMTP id i22mr101511173otc.0.1578041097590; Fri, 03 Jan 2020 00:44:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578041097; cv=none; d=google.com; s=arc-20160816; b=PlkoOmbHPQ8FphA/0QlnHEY3chBP2NZ85DHonCdd4bUJ7iNDfacNLivwxkQPVAykcB so/npfMRZe0I/XhGAxurBSuj/ur4aVzfine6xITOTWkYOc4CKRvDmII1IcPbc4W2uTyT WCognnDZY9ScnRYjLLq5Ix24Q0TCAHyn9jP+ls2nvPvQiihNt+iTDnbtyaoS0c/jZLY5 idHzaiUm4n4RfDFowOWwic0ut5Zt5DVKGuWw/a3ZMqRv/Rchkrz1nnuHQZSqN8B6+8Us PwLYRGpuwBIyKWLuPWLcF1VrI5biilrHx/H/rfRK/3/NMlrkG29utU3U1Rj2IG5GoU7P HxbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Chyl7Mv3/5Q4XdzmvhpdRrpPjd66HwVmu8DgxTnljdU=; b=SqQgBvGTKpKQsDuWXI6rX1Fg6JjGdaCNXJ15LRhjVKrqrX/PGgVWdjdQUKhPF02ydL fPXSQ2d7ak+4kliydkl1WpJLTzWhds9nMIEeeD/PoBRTufzAtrJNszDSNC8S4Dc7epDM Pf4ygcj3TIsmZJETYM3SQpwXry9gsvR8wBTSbLoMr6xoQysEhm5jCX5rhwUF8SXUyYAY rRqY1fP16keCC5CeiG/lKIjSnlyZepWlmlZJZsGLVyZ5i4H/fiOlrBO8gzGgDbDtDSsE UX0Rm1LG3OKrnDU17gOM0Wy+3p3E6N9t8iqNOCSH9PUoEKxycKPz/cL4MdaQbfISwUI/ ethg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PtkbFfUr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si29652866oif.211.2020.01.03.00.44.45; Fri, 03 Jan 2020 00:44:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PtkbFfUr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbgACInm (ORCPT + 99 others); Fri, 3 Jan 2020 03:43:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:55196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbgACInm (ORCPT ); Fri, 3 Jan 2020 03:43:42 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A21521D7D; Fri, 3 Jan 2020 08:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578041021; bh=Hp7q2TTE4pvo/bziqGh+GKRop6IHs7H6cervwPFzkuY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PtkbFfUrPBMQXP7+xp+mnWGYj/IoYh1ECZ6Km+/UVIBv/1zE3bPF0b7SE6iHKMmMu 8uQ6F+AMFhsEh/kkK/RgUW4+fwPnR0Nne64F4G7rFAsV/RJJNWt4NE93WQM/M/r4yg 4zlqGEMUmNKr9e145NVxfSSpjdp06rEKmY7TW/dI= Date: Fri, 3 Jan 2020 09:43:39 +0100 From: Greg Kroah-Hartman To: Zhenzhong Duan Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Arnd Bergmann Subject: Re: [PATCH RESEND] ttyprintk: fix a potential sleeping in interrupt context issue Message-ID: <20200103084339.GA855576@kroah.com> References: <20200103034541.5302-1-zhenzhong.duan@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200103034541.5302-1-zhenzhong.duan@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 03, 2020 at 11:45:41AM +0800, Zhenzhong Duan wrote: > Google syzbot reports: > BUG: sleeping function called from invalid context at > kernel/locking/mutex.c:938 > in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 0, name: swapper/1 > 1 lock held by swapper/1/0: > ... > Call Trace: > > dump_stack+0x197/0x210 > ___might_sleep.cold+0x1fb/0x23e > __might_sleep+0x95/0x190 > __mutex_lock+0xc5/0x13c0 > mutex_lock_nested+0x16/0x20 > tpk_write+0x5d/0x340 > resync_tnc+0x1b6/0x320 > call_timer_fn+0x1ac/0x780 > run_timer_softirq+0x6c3/0x1790 > __do_softirq+0x262/0x98c > irq_exit+0x19b/0x1e0 > smp_apic_timer_interrupt+0x1a3/0x610 > apic_timer_interrupt+0xf/0x20 > > > Fix it by using spinlock in process context instead of mutex and having > interrupt disabled in critical section. > > Signed-off-by: Zhenzhong Duan > Cc: Arnd Bergmann > Cc: Greg Kroah-Hartman > --- > drivers/char/ttyprintk.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) Why was this resent? What differs from the first version that required it to be resent? Always give us a clue here please :) > > diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c > index 4f24e46ebe7c..56db949a7b70 100644 > --- a/drivers/char/ttyprintk.c > +++ b/drivers/char/ttyprintk.c > @@ -15,10 +15,11 @@ > #include > #include > #include > +#include > > struct ttyprintk_port { > struct tty_port port; > - struct mutex port_write_mutex; > + spinlock_t spinlock; > }; > > static struct ttyprintk_port tpk_port; > @@ -99,11 +100,12 @@ static int tpk_open(struct tty_struct *tty, struct file *filp) > static void tpk_close(struct tty_struct *tty, struct file *filp) > { > struct ttyprintk_port *tpkp = tty->driver_data; > + unsigned long flags; > > - mutex_lock(&tpkp->port_write_mutex); > + spin_lock_irqsave(&tpkp->spinlock, flags); > /* flush tpk_printk buffer */ > tpk_printk(NULL, 0); Are you sure you can call this with a spinlock held? Doesn't your trace above show the opposite? What is wrong with sleeping during the mutex you currently have? How is syzbot reporting this error, is there a reproducer somewhere? thanks, greg k-h