Received: by 10.223.185.116 with SMTP id b49csp2755240wrg; Mon, 5 Mar 2018 08:11:57 -0800 (PST) X-Google-Smtp-Source: AG47ELuuPvE5nQbek+KllGbwqIakvWM4ZBFz0XxCxS3U+zs7Rw22vEycea8Wb+4y5qlQjdAVY4LX X-Received: by 10.99.163.1 with SMTP id s1mr12846267pge.47.1520266317559; Mon, 05 Mar 2018 08:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266317; cv=none; d=google.com; s=arc-20160816; b=HhqXX3XUCp+uueVOdI2Q+HyKLGoM7GniV95ZdkXhUPO4ZWySMoeoTR/FSZugEC9tf/ jfs3rGgpSjusQiVaK0RPAGy+woGydKfsY6K43Rpx9PexkB/JdaqzZOtXQi/pAlr/GAar 8/u7ZdhO5Juva19Ut7AiM9fcd7EalIOa5Xntq0bYvB2TX25k85moOK5bAjsO/4Y0eWdc x/fa1QDsP461w3hzzDxJE/ztQcyQSsWiKbVEc+qSM+/bQjrEmod65jJNu0P60DTkM2xQ XsZXqUHkw0zCKmmvbxFpeF6Y3IHtRnjpTi58kekW+7YeRYyfS3dGvqU9t5Yl2aucwNKL c/lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=tEeu/A0hsJ8QeWXDTm47x704mAdBEufp+sv+6Lkumo0=; b=puURRnxQhQ3b7ZBKKkLDzzTUKHOJApKs1KLuxvaMPJQatUu7RKqughSImrO4SkD4eb d5qUanP95473ZhdxrSjDuCGimAc6jhXNwZbaEVIZI3AlXo4B4tfV4wbFQY8JAQuQIOC7 Us2SYSAuIeXOqnI5FGbEMstHA31zcRJJ15ESRsAYHuiAeOK4fPFStjVEaDy4Nw3ONMqi djEdVBnRXvyzgJUvws5VSKY2h081Xw0VPlCkEemhe160Qzjfh4KTnX5pp3sqo8SAHSZU yUnDqolJ7OlwFuuouN0ZJxme/ldj2J+f8vWMcjyWeOvTUzJEek+KaSX+0LLey11EB+AZ 9sPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c14si8468495pgu.341.2018.03.05.08.11.42; Mon, 05 Mar 2018 08:11:57 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932093AbeCEQKJ (ORCPT + 99 others); Mon, 5 Mar 2018 11:10:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:45380 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751490AbeCEQKH (ORCPT ); Mon, 5 Mar 2018 11:10:07 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2DD4DAE24; Mon, 5 Mar 2018 16:10:06 +0000 (UTC) Message-ID: <1520265871.6256.15.camel@suse.com> Subject: Re: [RFC PATCH] cdc-acm: do not drop data from fast devices From: Oliver Neukum To: Romain Izard , johan@kernel.org Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org Date: Mon, 05 Mar 2018 17:04:31 +0100 In-Reply-To: <20180305095539.13698-1-romain.izard.pro@gmail.com> References: <20180305095539.13698-1-romain.izard.pro@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.11 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-03-05 at 10:55 +0100, Romain Izard wrote: > The TTY buffer is 4096 bytes large, throttling when there are only 128 > free bytes left, and unthrottling when there are only 128 bytes available. > But the TTY buffer is filled from an intermediate flip buffer that > contains up to 64 KiB of data, and each time unthrottle() is called 16 > URBs are scheduled by the driver, sending up to 16 KiB to the flip buffer. > As the result of tty_insert_flip_string() is not checked in the URB > reception callback, data can be lost when the flip buffer is filled faster > than the TTY is emptied. It seems to me that the problem is in the concept here. If you cannot take all data, you should tell the lower layer how much data you can take. > Moreover, as the URB callbacks are called from a tasklet context, whereas > throttling is called from the system workqueue, it is possible for the > throttling to be delayed by high traffic in the tasklet. As a result, > completed URBs can be resubmitted even if the flip buffer is full, and we > request more data from the device only to drop it immediately. That points to a deficiency with how we throttle. Maybe we should poison URBs upon throttle() being called? > To prevent this problem, the URBs whose data did not reach the flip buffer > are placed in a waiting list, which is only processed when the serial port > is unthrottled. So we introduce yet another buffer? That does look like we are papering over a design problem. > This is working when using the normal line discipline on ttyACM. But > there is a big hole in this: other line disciplines do not use throttling > and thus unthrottle is never called. The URBs will never get resubmitted, Now that is a real problem. This introduces a regression. > and the port is dead. Unfortunately, there is no notification when the > flip buffer is ready to receive new data, so the only alternative would > be to schedule a timer polling the flip buffer. But with an additional > asynchronous process in the mix, the code starts to be very brittle. Well, no. This tells us something is broken in the tty layer. > I believe this issue is not limited to ttyACM. As the TTY layer is not > performance-oriented, it can be easy to overwhelm devices with a low > available processing power. In my case, a modem sending a sustained 2 MB/s > on a debug port (exported as a CDC-ACM port) was enough to trigger the > issue. The code handling the CDC-ACM class and the generic USB serial port > is very similar when it comes to URB handling, so all drivers that rely on > that code have the same issue. > > But in general, it seems to me that there is no code in the kernel that > checks the return value of tty_insert_flip_string(). This means that we > are working with the assumption that the kernel will consume the data > faster than the source can send it, or that the upper layer will be > able or willing to throttle it fast enough to avoid losing data. Yes. And if the assumption is false, you need to go for the tty layer. I am sorry, but NACK. Regards Oliver