From patchwork Fri Mar 22 15:53:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 10866165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3FB9139A for ; Fri, 22 Mar 2019 15:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAC702A8BE for ; Fri, 22 Mar 2019 15:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AED7A2A8C5; Fri, 22 Mar 2019 15:53:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58FA92A8BE for ; Fri, 22 Mar 2019 15:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727877AbfCVPxM (ORCPT ); Fri, 22 Mar 2019 11:53:12 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37752 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726022AbfCVPxM (ORCPT ); Fri, 22 Mar 2019 11:53:12 -0400 Received: by mail-wr1-f66.google.com with SMTP id w10so2919531wrm.4; Fri, 22 Mar 2019 08:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=18PmN9KQr/H1F84Tkb4n95xe4xVl12w2H+KQLyY4pKY=; b=nkcHtWpjjPrRTsbTuB3iZf17kZBwzEM6Zn2+iiz3HbHJNffUOfSq5iq1FiAMNSr7HX XPGwIwzZM4T753eB/qFuZA3wf7qm8gnqMDH/FKCZlLDBCM0bgx+i/PeHboe1VxcH6CWv n8wy1fMfV8crw+14LMSR9QQlU9I4q5sjXT24mzMxDzECn/OKVqB7s5wFxb5Es42glCVl R+xjuulBaC2D73TqS0BVA5clwZyeZ2yNmR1k8BRgJnP0cIat6/P/b0KcZyLJf7yQO5DP W/YgpT+fibxa6PbHWsaEew74IdbLsVpMiJp1mqSO9I1IMBfjvz4YTfC89q5QAJQ2t+Z1 a5Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=18PmN9KQr/H1F84Tkb4n95xe4xVl12w2H+KQLyY4pKY=; b=Lp1ytW1ZHfYDU+d19wzl6JIlPy+Gzd46LKwqCq3Hg3gmqWEAYpkjEenkuB9iHQM63V +mJignkL7hz/jedZRNqltYV7wYGU7HcG95z0rKuk5ipB+5cAPSf7miHdEq+7iv50as+K tdygWcfVBLvHXL0F9w5d2x4ME9XciJoCliuekfAScsv+x9xhPbsUv+HMMlYYrxzByATP C5QOg/7GopdwwExyiyI2B1MMwwhkL5uUA2fVyXqCgjk1J6/67xPKq/QRKbQWi+SIA1Ng SHYkjjp9Hf7OekYmKcll69/Jrpc/jRqgfKnk3RVZ3lMReG+797Kl+QPigm/LU6ENjhZL neNw== X-Gm-Message-State: APjAAAXoQiPVBBERJS9zHbzI5KylpdanHPtBt9+WXmmeJAJm59td/igq T2TmOYcfi7QQ5H+n6jMkW90= X-Google-Smtp-Source: APXvYqwTs+S8BZOeD1dgGTDmID8ir3CB4oX59/jDsDTNb81sGE/a7G3vLFpKpdCvdO/VbFIinOQI9Q== X-Received: by 2002:a5d:52ca:: with SMTP id r10mr7261493wrv.187.1553269990086; Fri, 22 Mar 2019 08:53:10 -0700 (PDT) Received: from 5WDYG62.mdi (static-css-cqn-143221.business.bouyguestelecom.com. [176.149.143.221]) by smtp.gmail.com with ESMTPSA id w16sm8136833wrt.84.2019.03.22.08.53.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 08:53:09 -0700 (PDT) From: Romain Izard To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Romain Izard Subject: [PATCH] usb: cdc-acm: fix race during wakeup blocking TX traffic Date: Fri, 22 Mar 2019 16:53:02 +0100 Message-Id: <20190322155302.28414-1-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the kernel is compiled with preemption enabled, the URB completion handler can run in parallel with the work responsible for waking up the tty layer. If the URB handler sets the EVENT_TTY_WAKEUP bit during the call to tty_port_tty_wakeup() to signal that there is room for additional input, it will be cleared at the end of this call. As a result, TX traffic on the upper layer will be blocked. This can be seen with a kernel configured with CONFIG_PREEMPT, and a fast modem connected with PPP running over a USB CDC-ACM port. Use test_and_clear_bit() instead, which ensures that each wakeup requested by the URB completion code will trigger a call to tty_port_tty_wakeup(). Fixes: 1aba579f3cf5 cdc-acm: handle read pipe errors Signed-off-by: Romain Izard Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 739f8960811a..ec666eb4b7b4 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -558,10 +558,8 @@ static void acm_softint(struct work_struct *work) clear_bit(EVENT_RX_STALL, &acm->flags); } - if (test_bit(EVENT_TTY_WAKEUP, &acm->flags)) { + if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) tty_port_tty_wakeup(&acm->port); - clear_bit(EVENT_TTY_WAKEUP, &acm->flags); - } } /*