From patchwork Mon Aug 19 14:44:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 19311 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 08C45246F8 for ; Mon, 19 Aug 2013 14:46:20 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id ht10sf5638713vcb.1 for ; Mon, 19 Aug 2013 07:46:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=/glBP8qzfiIJNNxUrSSTeUEsIIZdJp5xFaHyJvtDDnk=; b=d/jQ+T35ajp8dfIF3OhzA7p2JUVb7cBNzFXE4WZjPH+xRJ7wPCIMIMeu8iDrAghaPR 96G75qzLzlW4d/mfGOH9Ar7K879LAykpRnPTP6EyPtH1XHvwHzlQybTMuZyYmrQNYrae H9N8T9zkvNxSZwwp1leU04Q21Hg+BbvFJJfTyq23YXGgM4Pmj8GpiKj4eRcuEcLNht7S VckZDIwO2xDkT0BXxVaPjeJSo42aJW2luOcjcsqcfCJfQGTtr5aZ7eRcLK+DxhWuQ+yX lesbhBF+lMO9jbq8LeIBtwrH8oMInowh986TyrIUU9pm43fHN5SkAattIJndrH/X2HZg kP0Q== X-Received: by 10.236.108.233 with SMTP id q69mr564055yhg.11.1376923579814; Mon, 19 Aug 2013 07:46:19 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.70.228 with SMTP id p4ls1655997qeu.43.gmail; Mon, 19 Aug 2013 07:46:19 -0700 (PDT) X-Received: by 10.52.119.139 with SMTP id ku11mr84733vdb.42.1376923579688; Mon, 19 Aug 2013 07:46:19 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id fa1si2432003veb.44.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 07:46:19 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ia10so3094275vcb.34 for ; Mon, 19 Aug 2013 07:46:19 -0700 (PDT) X-Gm-Message-State: ALoCoQkpqDR/lLDmuDwesUjk5wDhD9MU8uW+rptlZuk4sd3hRn598tMAWr3JXl/Ysp3TWDYCkpt0 X-Received: by 10.52.119.139 with SMTP id ku11mr84727vdb.42.1376923579603; Mon, 19 Aug 2013 07:46:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp100175vcz; Mon, 19 Aug 2013 07:46:18 -0700 (PDT) X-Received: by 10.68.130.71 with SMTP id oc7mr13791895pbb.10.1376923578565; Mon, 19 Aug 2013 07:46:18 -0700 (PDT) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by mx.google.com with ESMTPS id co1si8618518pbc.288.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 07:46:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.51 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.220.51; Received: by mail-pa0-f51.google.com with SMTP id lf1so4641418pab.24 for ; Mon, 19 Aug 2013 07:46:18 -0700 (PDT) X-Received: by 10.66.27.43 with SMTP id q11mr13519223pag.97.1376923578136; Mon, 19 Aug 2013 07:46:18 -0700 (PDT) Received: from localhost ([122.172.193.46]) by mx.google.com with ESMTPSA id wr9sm15595652pbc.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 19 Aug 2013 07:46:17 -0700 (PDT) From: Viresh Kumar To: gregkh@linuxfoundation.org, jslaby@suse.cz Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, linux-serial@vger.kernel.org, Viresh Kumar Subject: [PATCH V2 14/25] tty: serial: mfd: drop uart_port->lock before calling tty_flip_buffer_push() Date: Mon, 19 Aug 2013 20:14:18 +0530 Message-Id: <2cabe7e222cb0b322face31767ed0f4321697862.1376923198.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The current driver triggers a lockdep warning for if tty_flip_buffer_push() is called with uart_port->lock locked. This never shows up on UP kernels and comes up only on SMP kernels. Crash looks like this (produced with samsung.c driver): ----- [] (unwind_backtrace+0x0/0xf8) from [] (show_stack+0x10/0x14) [] (show_stack+0x10/0x14) from [] (dump_stack+0x6c/0xac) [] (dump_stack+0x6c/0xac) from [] (do_raw_spin_unlock+0xc4/0xd8) [] (do_raw_spin_unlock+0xc4/0xd8) from [] (_raw_spin_unlock_irqrestore+0xc/0) [] (_raw_spin_unlock_irqrestore+0xc/0x38) from [] (s3c24xx_serial_rx_chars+0) [] (s3c24xx_serial_rx_chars+0x12c/0x260) from [] (s3c64xx_serial_handle_irq+) [] (s3c64xx_serial_handle_irq+0x48/0x60) from [] (handle_irq_event_percpu+0x) [] (handle_irq_event_percpu+0x50/0x194) from [] (handle_irq_event+0x3c/0x5c) [] (handle_irq_event+0x3c/0x5c) from [] (handle_fasteoi_irq+0x80/0x13c) [] (handle_fasteoi_irq+0x80/0x13c) from [] (generic_handle_irq+0x20/0x30) [] (generic_handle_irq+0x20/0x30) from [] (handle_IRQ+0x38/0x94) [] (handle_IRQ+0x38/0x94) from [] (gic_handle_irq+0x34/0x68) [] (gic_handle_irq+0x34/0x68) from [] (__irq_svc+0x40/0x70) Exception stack(0xc04cdf70 to 0xc04cdfb8) df60: 00000000 00000000 0000166e 00000000 df80: c04cc000 c050278f c050278f 00000001 c04d444c 410fc0f4 c03649b0 00000000 dfa0: 00000001 c04cdfb8 c000f758 c000f75c 60070013 ffffffff [] (__irq_svc+0x40/0x70) from [] (arch_cpu_idle+0x28/0x30) [] (arch_cpu_idle+0x28/0x30) from [] (cpu_startup_entry+0x5c/0x148) [] (cpu_startup_entry+0x5c/0x148) from [] (start_kernel+0x334/0x38c) BUG: spinlock lockup suspected on CPU#0, kworker/0:1/360 lock: s3c24xx_serial_ports+0x1d8/0x370, .magic: dead4ead, .owner: /-1, .owner_cpu: -1 CPU: 0 PID: 360 Comm: kworker/0:1 Not tainted 3.11.0-rc6-next-20130819-00003-g75485f1 #2 Workqueue: events flush_to_ldisc [] (unwind_backtrace+0x0/0xf8) from [] (show_stack+0x10/0x14) [] (show_stack+0x10/0x14) from [] (dump_stack+0x6c/0xac) [] (dump_stack+0x6c/0xac) from [] (do_raw_spin_lock+0x100/0x17c) [] (do_raw_spin_lock+0x100/0x17c) from [] (_raw_spin_lock_irqsave+0x20/0x28) [] (_raw_spin_lock_irqsave+0x20/0x28) from [] (uart_start+0x18/0x34) [] (uart_start+0x18/0x34) from [] (__receive_buf+0x4b4/0x738) [] (__receive_buf+0x4b4/0x738) from [] (n_tty_receive_buf2+0x30/0x98) [] (n_tty_receive_buf2+0x30/0x98) from [] (flush_to_ldisc+0xec/0x138) [] (flush_to_ldisc+0xec/0x138) from [] (process_one_work+0xfc/0x348) [] (process_one_work+0xfc/0x348) from [] (worker_thread+0x138/0x37c) [] (worker_thread+0x138/0x37c) from [] (kthread+0xa4/0xb0) [] (kthread+0xa4/0xb0) from [] (ret_from_fork+0x14/0x3c) ----- Release the port lock before calling tty_flip_buffer_push() and reacquire it after the call. Similar stuff was already done for few other drivers in the past, like: commit 2389b272168ceec056ca1d8a870a97fa9c26e11a Author: Thomas Gleixner Date: Tue May 29 21:53:50 2007 +0100 [ARM] 4417/1: Serial: Fix AMBA drivers locking Signed-off-by: Viresh Kumar --- drivers/tty/serial/mfd.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c index 4a82267..d3db042 100644 --- a/drivers/tty/serial/mfd.c +++ b/drivers/tty/serial/mfd.c @@ -386,7 +386,7 @@ static void serial_hsu_stop_tx(struct uart_port *port) /* This is always called in spinlock protected mode, so * modify timeout timer is safe here */ -void hsu_dma_rx(struct uart_hsu_port *up, u32 int_sts) +void hsu_dma_rx(struct uart_hsu_port *up, u32 int_sts, unsigned long *flags) { struct hsu_dma_buffer *dbuf = &up->rxbuf; struct hsu_dma_chan *chan = up->rxc; @@ -438,7 +438,9 @@ void hsu_dma_rx(struct uart_hsu_port *up, u32 int_sts) | (0x1 << 16) | (0x1 << 24) /* timeout bit, see HSU Errata 1 */ ); + spin_unlock_irqrestore(&up->port.lock, *flags); tty_flip_buffer_push(tport); + spin_lock_irqsave(&up->port.lock, *flags); chan_writel(chan, HSU_CH_CR, 0x3); @@ -459,7 +461,8 @@ static void serial_hsu_stop_rx(struct uart_port *port) } } -static inline void receive_chars(struct uart_hsu_port *up, int *status) +static inline void receive_chars(struct uart_hsu_port *up, int *status, + unsigned long *flags) { unsigned int ch, flag; unsigned int max_count = 256; @@ -519,7 +522,10 @@ static inline void receive_chars(struct uart_hsu_port *up, int *status) ignore_char: *status = serial_in(up, UART_LSR); } while ((*status & UART_LSR_DR) && max_count--); + + spin_unlock_irqrestore(&up->port.lock, *flags); tty_flip_buffer_push(&up->port.state->port); + spin_lock_irqsave(&up->port.lock, *flags); } static void transmit_chars(struct uart_hsu_port *up) @@ -613,7 +619,7 @@ static irqreturn_t port_irq(int irq, void *dev_id) lsr = serial_in(up, UART_LSR); if (lsr & UART_LSR_DR) - receive_chars(up, &lsr); + receive_chars(up, &lsr, &flags); check_modem_status(up); /* lsr will be renewed during the receive_chars */ @@ -643,7 +649,7 @@ static inline void dma_chan_irq(struct hsu_dma_chan *chan) /* Rx channel */ if (chan->dirt == DMA_FROM_DEVICE) - hsu_dma_rx(up, int_sts); + hsu_dma_rx(up, int_sts, &flags); /* Tx channel */ if (chan->dirt == DMA_TO_DEVICE) {