From patchwork Thu Mar 20 19:30:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 26759 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 507A420143 for ; Thu, 20 Mar 2014 19:34:53 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rp16sf3321606pbb.9 for ; Thu, 20 Mar 2014 12:34:52 -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:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=OegrxSQSlU2xJIfEiFYnjT69Ea8mASrOhl3AXewsd0E=; b=foh1tzYN9L6lUWzW4qUjXKoHnhmTQR4nBA/uEOynE/27CfL8lALZl8SzkTtqgGwPVB v1sxqaIuh6wt0hUQT8aUGBxS9h3P6X1/UwomtBJ1XBN6xhMeDWlWs/3Vtq0cC2B+Xp+j RqlV4ECctBCsDWL+4F57tLZEVpjKEwD+GbzWb66e/4m2COU708QcH25i2e3F7ptVmnXa teDX3l6boYbYuHRaHbNZvggWLQso9ArLSlNQWjpeLReCcekDDKC4dsYwyaDnjD6FapwD i6uMRuR33LeAJ0tvnJm7ge7j/4SL85oyhAONpwHIDk9+ZYjZZ7F/1mutdfhTw6Ti59DK 1bDw== X-Gm-Message-State: ALoCoQkj1HmcY0WGd7UooUEs+0tNQmHv7Wmecd3FikgrNE9kgITAL9OBSNa4uU7OfHXdzBmumfQ8 X-Received: by 10.66.159.36 with SMTP id wz4mr17865269pab.14.1395344092528; Thu, 20 Mar 2014 12:34:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.194 with SMTP id d60ls354463qge.22.gmail; Thu, 20 Mar 2014 12:34:52 -0700 (PDT) X-Received: by 10.58.248.5 with SMTP id yi5mr1917099vec.42.1395344092407; Thu, 20 Mar 2014 12:34:52 -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 xo2si643103vec.116.2014.03.20.12.34.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Mar 2014 12:34:52 -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 oy12so1489622veb.4 for ; Thu, 20 Mar 2014 12:34:52 -0700 (PDT) X-Received: by 10.220.147.16 with SMTP id j16mr7516546vcv.14.1395344092193; Thu, 20 Mar 2014 12:34:52 -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 i9csp414042vck; Thu, 20 Mar 2014 12:34:51 -0700 (PDT) X-Received: by 10.68.113.194 with SMTP id ja2mr49132339pbb.30.1395344091159; Thu, 20 Mar 2014 12:34:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wt1si2100340pbc.32.2014.03.20.12.34.50; Thu, 20 Mar 2014 12:34:50 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965189AbaCTTcO (ORCPT + 26 others); Thu, 20 Mar 2014 15:32:14 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:57366 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965088AbaCTTcG (ORCPT ); Thu, 20 Mar 2014 15:32:06 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s2KJW4sl012251; Thu, 20 Mar 2014 14:32:04 -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 s2KJW3O7018057; Thu, 20 Mar 2014 14:32:03 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 20 Mar 2014 14:32:03 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2KJW3LA031085; Thu, 20 Mar 2014 14:32:03 -0500 From: Felipe Balbi To: Greg KH CC: , , , , , Linux OMAP Mailing List , Linux Kernel Mailing List , Felipe Balbi Subject: [PATCH 09/11] bluetooth: hci_ldisc: fix deadlock condition Date: Thu, 20 Mar 2014 14:30:05 -0500 Message-ID: <1395343807-21618-9-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.9.1.286.g5172cb3 In-Reply-To: <1395343807-21618-1-git-send-email-balbi@ti.com> References: <1395343807-21618-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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: , 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. Reviewed-by: Peter Hurley Reported-by: Huang Shijie Signed-off-by: Felipe Balbi Acked-by: Marcel Holtmann --- drivers/bluetooth/hci_ldisc.c | 24 +++++++++++++++++++----- drivers/bluetooth/hci_uart.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 6e06f6f..77af52f 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,22 @@ 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, write_work); + struct tty_struct *tty = hu->tty; + struct hci_dev *hdev = hu->hdev; + struct sk_buff *skb; + + /* REVISIT: should we cope with bad skbs or ->write() returning + * and error value ? + */ + restart: clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); @@ -153,7 +165,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 +292,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 +330,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;