From patchwork Thu Mar 20 19:03:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 26755 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 805E1202E0 for ; Thu, 20 Mar 2014 19:05:58 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id x10sf3026684pdj.6 for ; Thu, 20 Mar 2014 12:05:57 -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=xOkH5r28FfSYRb2r7oUHfN6xI3YfjqTo/BGZJNA6QjU=; b=XVE3NT/LRUZmVDJj/LajAOW2drH4m1UZN2v7TSpmpnVKbRH/5YSiJeL3Hs5hfZitkU xYQwYM/6nB8i92NKnpZOIzsyGIW7i1sj1q5I0cDE3Uxsy1CCkxj/6/qSWIc+GQZkJEUO sfjAgzH/1bez9/FWAp13VRI9uX8CGvQN1PyVpxsjjenzgNJRd/PR++M9BALfzLUPAN0H b7pQH+n+LlCctQjaht3zKKYRtG5TDA7URQJffO29x675Cj+DLKPDDnKn0IpErKfQmb6p yFyUNYgnX+85T1j0iYEW0Zgt+d8MQ+SuTlUpHeFQ86NgtqttfW0twFoGEmOD0bNsxdiU pXMA== X-Gm-Message-State: ALoCoQkrJSm9EpNaMHEJ8cWzg9wx3XsaRFlo1dVNkvQ5pSJH/42mMm5gscX3vQF8Y+u0Y5HARsqr X-Received: by 10.68.201.134 with SMTP id ka6mr18116668pbc.4.1395342357794; Thu, 20 Mar 2014 12:05:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.73 with SMTP id 67ls332491qga.18.gmail; Thu, 20 Mar 2014 12:05:57 -0700 (PDT) X-Received: by 10.58.212.200 with SMTP id nm8mr34498626vec.11.1395342357674; Thu, 20 Mar 2014 12:05:57 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id p8si622485vef.176.2014.03.20.12.05.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 12:05:57 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id oy12so1450882veb.18 for ; Thu, 20 Mar 2014 12:05:57 -0700 (PDT) X-Received: by 10.58.37.232 with SMTP id b8mr6083046vek.27.1395342357445; Thu, 20 Mar 2014 12:05:57 -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 i9csp412302vck; Thu, 20 Mar 2014 12:05:56 -0700 (PDT) X-Received: by 10.66.192.133 with SMTP id hg5mr31873113pac.122.1395342355881; Thu, 20 Mar 2014 12:05:55 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ys6si1355889pab.418.2014.03.20.12.05.52; Thu, 20 Mar 2014 12:05:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-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 S933559AbaCTTFv (ORCPT + 2 others); Thu, 20 Mar 2014 15:05:51 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:55970 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933548AbaCTTFu (ORCPT ); Thu, 20 Mar 2014 15:05:50 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s2KJ5jgQ009743; Thu, 20 Mar 2014 14:05:45 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2KJ5iiC031970; Thu, 20 Mar 2014 14:05:44 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 20 Mar 2014 14:05:44 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2KJ5hNq019119; Thu, 20 Mar 2014 14:05:44 -0500 Date: Thu, 20 Mar 2014 14:03:57 -0500 From: Felipe Balbi To: Felipe Balbi CC: Peter Hurley , Marcel Holtmann , Alan Cox , Greg KH , Muralidharan Karicheri , , , Linux Kernel Mailing List , Huang Shijie Subject: Re: hci_ldsic nested locking problem Message-ID: <20140320190357.GG3959@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> <20140320181145.GC3959@saruman.home> <532B319D.4090208@hurleysoftware.com> <20140320182528.GE3959@saruman.home> <20140320190154.GF3959@saruman.home> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140320190154.GF3959@saruman.home> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-serial-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-serial@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.128.173 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: , Hi, On Thu, Mar 20, 2014 at 02:01:54PM -0500, Felipe Balbi wrote: > > @@ -318,6 +326,8 @@ static void hci_uart_tty_close(struct tty_struct *tty) > > if (hdev) > > hci_uart_close(hdev); > > > > + cancel_work_sync(&hy->write_work); > > forgot to commit, darn it here it is: >From eaf7ff6f2d224f202369e4820b76a03fa664fab0 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 20 Mar 2014 13:20:10 -0500 Subject: [PATCH] bluetooth: hci_ldisc: fix deadlock condition LDISCs shouldn't call tty->ops->write() from within ->write_wakeup(). ->write_wakeup() is called with port lock taken and IRQs disabled, tty->ops->write() will try to acquire the same port lock and we will deadlock. Signed-off-by: Felipe Balbi --- drivers/bluetooth/hci_ldisc.c | 20 +++++++++++++++----- drivers/bluetooth/hci_uart.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 6e06f6f..5a53e50 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) @@ -281,6 +288,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); @@ -318,6 +326,8 @@ static void hci_uart_tty_close(struct tty_struct *tty) if (hdev) hci_uart_close(hdev); + cancel_work_sync(&hu->write_work); + if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) { if (hdev) { if (test_bit(HCI_UART_REGISTERED, &hu->flags)) 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;