From patchwork Thu Mar 20 18:11:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 26753 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33D30202E0 for ; Thu, 20 Mar 2014 18:13:43 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id i17sf2906473qcy.7 for ; Thu, 20 Mar 2014 11:13:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :reply-to:references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=hUdPBf2aAAFPApFEVEZje5TOgjXcznweGc8FVjqpGuQ=; b=Qgti9hI2slOR2Zraz7+z05TjCSn0I6WtvXlmWJ4TZrtvWrwfLyJEZk9zR3eriGNpDy dY7zGAOqFjbYqgFoXynbxut1VdClWH/MUrI3J7MBq8ndjmVt7v2vZ4sQpr/Usdj/Ndy3 Ywn6ux2cxtargdgf9uhpkQaqA0Cg2S9jIqUMWGpBAtdAqoTzRLXk/Ovxug+PZdyMkv3p ePtOrwx5xa72IhS0ZmYqWHjGEbYUKLLQSm/W7IN2n1lxms1xrx9rDn1b54Xlh2JNDD8k OR/OE2imphr23pBmys/vXkkGJp3SrfMHRbcuEHf1Ox7EtSElchDQAgqkyGii6jdvSm3L KzOQ== X-Gm-Message-State: ALoCoQnakTsf2+CBuCoNR0n8W+BUlV8aTEvdLmx58tmwRAy9FjCzZmZTl+1FKtYIG9wtJHB0N1pE X-Received: by 10.58.195.202 with SMTP id ig10mr8491087vec.38.1395339223610; Thu, 20 Mar 2014 11:13:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.7 with SMTP id g7ls358763qgf.53.gmail; Thu, 20 Mar 2014 11:13:43 -0700 (PDT) X-Received: by 10.58.133.15 with SMTP id oy15mr33503742veb.19.1395339223515; Thu, 20 Mar 2014 11:13:43 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id cb3si607914vdc.131.2014.03.20.11.13.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 11:13:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 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.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so1424191vcb.11 for ; Thu, 20 Mar 2014 11:13:43 -0700 (PDT) X-Received: by 10.52.65.165 with SMTP id y5mr1232121vds.51.1395339223409; Thu, 20 Mar 2014 11:13:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp409170vck; Thu, 20 Mar 2014 11:13:41 -0700 (PDT) X-Received: by 10.68.245.162 with SMTP id xp2mr48444158pbc.69.1395339220963; Thu, 20 Mar 2014 11:13:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pa10si1965325pbc.194.2014.03.20.11.13.40; Thu, 20 Mar 2014 11:13:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756651AbaCTSNk (ORCPT ); Thu, 20 Mar 2014 14:13:40 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:48443 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754731AbaCTSNj (ORCPT ); Thu, 20 Mar 2014 14:13:39 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s2KIDX08030929; Thu, 20 Mar 2014 13:13:33 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2KIDWwl026804; Thu, 20 Mar 2014 13:13:32 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 20 Mar 2014 13:13:32 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2KIDV8C018365; Thu, 20 Mar 2014 13:13:32 -0500 Date: Thu, 20 Mar 2014 13:11:45 -0500 From: Felipe Balbi To: Peter Hurley CC: , Marcel Holtmann , Alan Cox , Greg KH , Muralidharan Karicheri , , , Linux Kernel Mailing List , Huang Shijie Subject: Re: hci_ldsic nested locking problem Message-ID: <20140320181145.GC3959@saruman.home> Reply-To: References: <20140320163435.GH32692@saruman.home> <1395333736.22077.32.camel@acox1-desk.ger.corp.intel.com> <20140320171621.GA2827@saruman.home> <532B25FC.3070408@hurleysoftware.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <532B25FC.3070408@hurleysoftware.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.180 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Thu, Mar 20, 2014 at 01:31:40PM -0400, Peter Hurley wrote: > [ +cc Huang Shijie ] > > On 03/20/2014 01:16 PM, Felipe Balbi wrote: > >On Thu, Mar 20, 2014 at 04:42:16PM +0000, Alan Cox wrote: > >>On Thu, 2014-03-20 at 11:34 -0500, Felipe Balbi wrote: > >>>Hi, > >>> > >>>when 8250 driver calls uart_write_wakeup(), the tty port lock is already > >>>taken. hci_ldisc.c's implementation of ->write_wakeup() calls > >>>tty->ops->write() to actually send the characters, but that call will > >>>try to acquire the same port lock again. > >>> > >>>Looking at other line disciplines that looks like a bug in hci_ldisc.c. > >>>Am I correct to assume that ->write_wakeup() is supposed to *just* > >>>wakeup the bottom half so we handle ->write() in another context ? > >>> > >>>Is it legal to call tty->ops->write() from within ->write_wakeup() ? > >> > >>It isn't because you might send all the bytes and go > >> > >> write > >> write_wakeup > >> write > >> write wakeup > >> ... > >> > >>and recurse > > > >cool, so there really is a bug in hci_ldisc. Marcel, any tips on how do > >you want this to be sorted out ? > > hci_uart_tx_wakeup() should perform the I/O as work. > FWIW, this was reported by Huang Shijie back on Dec 6. > > I'd fix it but I have no way to test it. here's a build-tested only patch which is waiting for testing from other colleagues who've got a platform to reproduce the problem: diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index bc68a44..789000d 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -118,10 +118,6 @@ static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) int hci_uart_tx_wakeup(struct hci_uart *hu) { - struct tty_struct *tty = hu->tty; - struct hci_dev *hdev = hu->hdev; - struct sk_buff *skb; - if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); return 0; @@ -129,6 +125,18 @@ int hci_uart_tx_wakeup(struct hci_uart *hu) BT_DBG(""); + schedule_work(&hu->write_work); + + return 0; +} + +static void hci_uart_write_work(struct work_struct *work) +{ + struct hci_uart *hu = container_of(work, struct hci_uart, init_ready); + struct tty_struct *tty = hu->tty; + struct hci_dev *hdev = hu->hdev; + struct sk_buff *skb; + restart: clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); @@ -153,7 +161,6 @@ restart: goto restart; clear_bit(HCI_UART_SENDING, &hu->tx_state); - return 0; } static void hci_uart_init_work(struct work_struct *work) @@ -289,6 +296,7 @@ static int hci_uart_tty_open(struct tty_struct *tty) tty->receive_room = 65536; INIT_WORK(&hu->init_ready, hci_uart_init_work); + INIT_WORK(&hu->write_work, hci_uart_write_work); spin_lock_init(&hu->rx_lock); diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index fffa61f..12df101 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h @@ -68,6 +68,7 @@ struct hci_uart { unsigned long hdev_flags; struct work_struct init_ready; + struct work_struct write_work; struct hci_uart_proto *proto; void *priv;