From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796516331; b=fUw7jYX1MLDg0xUnCSa6+LpUxzUwtOrB7nIiOaFv0o3Y02NlADHggMtSrY3LCFiLCvzz ymST2uecH6TiUV5ykLln5LKlu3cFIiaFG303tCXXjLWkPyiDtvT7o8sluVz2PiNQJb1AN ADCNbAO2cVaMP3vEqPV844nKcck99g935IwAjZRk1Fy9nCxv/xiWfpOL1b8NflKCNLnS4 E1PQ1pfenpir5OE+inkVk7qetzIgqv63j/D2HMhdiep0Z1N+3WT+UH1nO8o4nl0zLU5Kb mtKQ8E6Vlfvj/LXpDmoTbEqJnbjmVWs+/zugm9jVtDp7l8Uo+0TCIaYXf3haS4TMzkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796516331; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=f0YpdeySVzAbOjsNvdUCdtMg7ntREpwlH8CidKJD3ag=; b=ZPOomU6JhcZ3g3YEH3bmuLeeio6OKIZy3dW7GcWJ/floHWY6tg2NC+RHVycFsfjiI+KW O+gTR7BDYpKsHCgU3r9MDV0V3icIY8bG6nOSbD53v7ZMzDP7S+POFWw19gH2aVmy80yv5 kH2iW2HE2f0cHmG3BmWChRRu0W0by+41KR+oRbfvyvYwp/Re4gkgVzW5Kc3J8m7/vZHsO lnspHj/NN6sWDMVc4aXfSZAzGoiS2LUTXm6+teo0LUG+m/0TLgDGRk1FZHccDHH4ojs7p J/0r9KRCH4JW8zhOR84igFCg0YYAwVn/hdpvfPE2d8Fy0rnpCt40vSM9If1J4KP5dqA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Xbya9uuw; arc=none smtp.remote-ip=209.85.218.52 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D296606A689 for ; Sun, 6 Dec 2026 00:18:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3D296606A689 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Xbya9uuw Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-c516a574bffso350171966b.3 for ; Sat, 05 Dec 2026 16:18:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796516330; x=1797121130; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f0YpdeySVzAbOjsNvdUCdtMg7ntREpwlH8CidKJD3ag=; b=Xbya9uuwupwd7DQhOsq7Q0edHKG057VM7uKqwi012M+z8mPM2uKrLF9xfCF53JOL8a mVSKIdVb1b+R0dDwwfl0jEHt91FTxzgSIK/jgmn7wgxy/wITdR7o9+LDx2wjFpQUrOAa trFjSCEr7mTTHd+2P3nV3MO7dBnTagUOgs7elsVTcgogDrGMd6Qk9o1ecUmnZcptf8E7 tLRA5kPVfb4fITrhP6yAgh13MVEkcjUVMKTSF6k+HRlf2/vse6rQ6SzluiMyy7acSpNQ ZDkxGJjlhNBqg/34LAiG1DpGlZKAFl/5sOskIDy8w+EED0rxVHavohEsgvgt6PGnHu/0 AjcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796516330; x=1797121130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=f0YpdeySVzAbOjsNvdUCdtMg7ntREpwlH8CidKJD3ag=; b=YdZBzo9w0qc1lHvuyxVte98xeY8a7zkON7p/1aSaonvMTSTTinqlRrMqzhvQ1c/LaZ f+QYUs3OF8Pjko/1re0M5rM81spk+VrH0QUst3EENthQwLEWV2f543pfAvpAVtaxP7CT wI/iCEJ6mFOfsiJmA2ObY1MumYV2cQYDbomuU+Sh5ycFm7uC9jhX/v+464SLjeyGy5QE ynGIYghgWDjl9IMnLakcONQBWPZ6D1vVAeE6R8Y2m57JpuMBbFn7xyBtRzXKM3rm12SG +rnncILw407e6Hn0hOqMhoHBIT69gFhf3LE0K0oz60VfeWXyQzl0jpk8a5uEtyipPehr miJw== X-Forwarded-Encrypted: i=1; AL+hErGjv2QEZfMiv0Ko/oDfbkNGCsrR++vJBzBs8kduAvTJ1voZ/Wm9jTKE6OojaRBGuZPfYH+xnLP2oJfXIwo=@vger.kernel.org X-Gm-Message-State: APuU4Z8frp/4u/KBQkuwkquvMYVCROUo/BQUWwSKcuISMN11F22TGMZc WmwjzSQQC1cBLq+KULbaDns/nYSSed1mch0Tx/lM9t6goZ9a8bOKZlFi X-Gm-Gg: AZFdTZeNUPU8+DkVLdxgIPVD58JYw9d2EGN1wjZAxsb+ZsFMwNdyX76SNrYe4WHK75m u/TjsUnQnbZi+QJ0P66cEHW8GL8J2gejNTrCkPT3fJBEc6GWN74HPp/t43IErmTapVihgcsHJY8 PQZG1CMZBflQU0fZtBlvqnrnPDeXRBH2vhcjmhKPEOR6Vwk4WEjUrMu0RnL2sJPmbzv/iQMgG6r ZzBtcQHGvcs7NnIZ2eQ5bb4nL139koiOhI+SXg/uH6EeymMeb2aWaQF6GkrF0HNUKTdrXPA35ml nxgQQCwFXYvPyA3Gy9S5C2V33wbGea/tT9rxGAwccmx32bKyVUlfJf7qavhEE/HugHXDji42UXt 0mkB7Sk3cwybXo8r8cz0PrCDe9eZfI5VF+iXd55XPryuY9TBi/eGWBcRZbttvubzGhT2To1Trdc xfC/C1huqlSscrqBdCIs8bkYi+JEy7KHzDmMoPNgBvYNvJ3EoV69WcV3ejVgmKa3FkYOurTdQMz CHvAJU9LlR41BZ6OPUYLODbItj2NojyMQbr92/yrpa6ki2dBLpCe4144gQIpBEYUimhgVIV5RTb pFVNJd4fHXVLUUeDmVF5Zu46GCNZ1l9Q8/3lMBCbwxvM1/7Zlqn7DTLkIk2w80mQKiMq3sZedMu ikOPHselfXw3AXBtribRwd9bPsxw5281UdpRZ/MW6iJ7bV42zKssu8NK/rKXEutlAfg6qOE046W a5me8bklp7eumN0Wxc1nCJcK0OMriUbeIclOkhcpUiCWA= X-Received: by 2002:a17:907:3e15:b0:c2e:4fa2:f3f7 with SMTP id a640c23a62f3a-c5262207190mr394436766b.22.1796516329698; Sat, 05 Dec 2026 16:18:49 -0800 (PST) Received: from Mac.localdomain ([188.146.22.246]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b3b724esm290077766b.42.2026.12.05.16.18.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 05 Dec 2026 16:18:49 -0800 (PST) From: Mateusz Sikora To: Johan Hovold Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Mateusz Sikora , Willy Tarreau Subject: [PATCH 2/2] USB: serial: ch341: use more read urbs Date: Sun, 6 Dec 2026 01:18:44 +0100 Message-ID: <20261206001844.14858-3-ms1qaz@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261206001844.14858-1-ms1qaz@gmail.com> References: <20261206001844.14858-1-ms1qaz@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The CH340 has 32-byte bulk endpoints so with two read urbs only 64 bytes can be in flight, which is less than 0.7 ms worth of data at 921600 baud. Characters are lost whenever the completion of a read urb is delayed for longer than that. This was first observed on a Raspberry Pi 4 where heavy network traffic through a Docker bridge delayed the softirq that gives back completed bulk-in urbs, on the CPU handling the xHCI interrupt, by up to 1.1 ms. With six devices receiving at 921600 baud while Docker networks and containers were created and removed in a loop for 150 seconds, the two CH340 devices lost 392 and 398 lines of output in about 220 seconds of recording, while a CH343 (cdc-acm) and three USB-Serial/JTAG devices on the same hub lost nothing. It can also be reproduced on x86 (Intel Sunrise Point xHCI) with the same kind of load during 135 seconds of a 180 second recording. A CH340 receiving 24-byte lines then lost 335 to 436 lines per run at 921600 baud, and 681 to 703 lines at 1500000 baud. The largest gaps there correspond to about 7 ms of data. Using 512-byte buffers instead also avoids the loss but had to be reverted as these devices do not send a zero-length packet when a transfer is a multiple of the endpoint size, which could leave received data stuck until more data arrived. See commit df7b16d1c00e ("Revert "USB: serial: ch341: fix character loss at high transfer rates""). Use 32 endpoint-sized read urbs instead, which gives 1 KiB of buffering (about 11 ms at 921600 baud and 7 ms at 1500000 baud) without waiting for short packets. This is the same amount as cdc-acm, which uses 16 urbs of twice the endpoint size. With bursts of 32 to 128 bytes followed by a pause, 512-byte buffers held the data back for 200 to 800 ms, until a burst ended with a short packet, while endpoint-sized urbs delivered every burst as quickly as the stock driver. With this, nothing was lost in the setups above, in two runs on the Raspberry Pi and in five runs on x86 (two at 921600 baud and three at 1500000 baud), nor in three x86 runs with continuous traffic through the bridge at 1500000 baud. With 16 urbs the x86 setup still lost 6 to 13 lines at 921600 baud and 237 to 279 lines at 1500000 baud. Note that at 1500000 baud the buffering is about the same as the largest gaps seen, so there is little margin left at that rate. This patch and its description were drafted with an AI assistant (Claude) and reviewed and tested by me. Cc: Willy Tarreau Signed-off-by: Mateusz Sikora --- drivers/usb/serial/ch341.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index 569f4aede..c9ac114b8 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c @@ -868,6 +868,7 @@ static struct usb_serial_driver ch341_device = { }, .id_table = id_table, .num_ports = 1, + .num_read_urbs = 32, .open = ch341_open, .dtr_rts = ch341_dtr_rts, .carrier_raised = ch341_carrier_raised, -- 2.54.0 (Apple Git-157)