From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796516331; b=ceU4ACheOqzQxYBUBus04X9ztAQeEdheYiNTzuLnV200t844LJXq4sCj9chLFa77sqxg 1db4vf+zHSbpA0HW8EBYmc4YTFdJRypcWmnwPJs9t2qgPtWcK/7czfRdVraOdpMum3Cdg jM+P2guATFUUZO3hK9S0NgIR1BpBke0iYF0EqW4bpshvSFB1Uw403rlOsar2ziJyehYt4 vqGUVCd+T8k0VMVYM3c+jZhu6SUQOPFGo2c0oopk/RwFzPK4vF1BnliruXRhnJto0l3S/ xyfibwL4swJxF03nT/S9S3p1y1bxJNJJ71zJj0b8lZHN572EKmSYfy5uxpnNscqRv3A== 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=le38HF28XSUzwUbA9YLU6BMZ6gKxp4DnB3tFsbAbequrEUww915qt+8eIWUn4xlQHx5k fIiQB929UL/47+zyLg/c11Mvta8icSgfZgr/Xn9A8hKB2WpWk4971TSGumQU5nYeVmul3 pzpVqP62UtPlfeQkRLfIOS+EUtmiTPGTebM1Y3j/HPX4fjNNnUY8VqkVVYfFzs/te6T7b 9Gv8qZMp1D73lNsnfLcdX/KCgn02MBg2DM5qAf5Q89hmoBcApr1Ch5EV+mDXGna+YaBmd 8vaTRDvgW7R4t2kZmquZLZCULaJE0VqzRuOqobvDsayU/BEGWyynno8IrhPSJUv+XVQ== 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.53 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 45E03606A335 for ; Sun, 6 Dec 2026 00:18:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 45E03606A335 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-f53.google.com with SMTP id a640c23a62f3a-c553eed3da8so67874666b.1 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=A4z9wQzs1P8dighqlEEDPNU+ZszTab82OXF1OHxhUiAUef4AIPqcehzde9Eqvq3pIU vPueiWOhscC3kishfNgbzzBs08Q3ZtAIfHUhI4nrmd1a0x0Rp++X/zE8bGeFsmPOGTsF /W/DLTV1/cM9WZbAXysJhdiy6fKZ1TuSvpalAadD2RAOal/OY1n3wpxxFMRHmTUtads1 SCZbs3G85kTco/MlZ2P3HzyvYfEvag8ee9wEzM6ZtaigCqw+bhHg70i7Tq/3VKRQ1uQ+ QJ50UmbFzGQ82BJzHEpsdskLzH59uznZeKGVlokJe7vkK2DrLMC3t0TtNJ3xDqpmPXV5 fXRQ== X-Forwarded-Encrypted: i=1; AL+hErGPXMUZ4mytvdfcRxc1bOxP2R/dqtQ58QnyV/4iKDiy3lCWqtDVjy2Dcm/XnZcj47wMahGzvckapOg=@vger.kernel.org X-Gm-Message-State: APuU4Z+pX32gE5k6wEdBYQOskauLbuX0ljHwZeYuJkR3tDiQ5zP8Uu4G iSAjJXGe6pLuMnwDyVLsUJ1dLMNsuNJl74SY5o/AlkBfOT+76IHkjHVn X-Gm-Gg: AZFdTZfMNZ1ZRnE5h2W1F7tjwR6UxqLeVivDLTbxwLVuR50tOuBJydCpoyF9jkNUXNm wNdlciQcC1MxhGwTALFY5vFTueIEhi+aB2fwMXBO2EvF42CqQuFJZfzcq2Elk+1wwnJJgMictpU WmYfzdV7nWEHDvq9Cy3PNS6JZQGcNEpkVPhEdSswqUAwRYKVSjMXsJA/Rr3eRUSG2U9O+4X3bxV z9ktXCSREPKueNivPAOLgEGmIbPhASJDiapz2WgtK6MweBvCMplsV06UtnPTEiBE4ySY7sFbSH0 Sekyf8S99Akp4GA4VHzRz9wSFjh9640M1ob/GAWBhV7GMr57yPIbYo0DJ44JKQlXx71LdKeUSr4 VJuvLadsQF6+pB095iNuCzf0u7UomEz4Brd6726b2klAyeYuGpOrnsiTOnFizohjxwOIHxvU7GX nH92V1stTFcO+anB0XPv/M41gGXOGPx6btu7Hhm/LI8wNghe362I5JpFJ33yyMYg0njmyPfsW6F ci+VHiyqosqeBxGpDvd8QYZACsYTn7ezFkTGGJ0Redz82dzQ0pL2GNH19s2dwWMAjf2An69PTh5 FWI+/R3oiBbgtM5uCAhCsoFxvLJdBjp/08Dkp9oJsUc3oXKNEUMc81RP41Dochk+giBJoeKiZN/ oFvLPg0KDculRlqpWWoFqA1eO7/z6Dpnxwc2m6ZhjMcyDLOYgZBS55vLmVYn/UMoY7OLidAqL0S LLAGgE0aevXVl2ReNkYYfAEBDqoQE1aFU4/60dWNxGPes= 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-usb@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)