* cdc_acm bug? read buffer bytes shifted @ 2016-08-20 3:40 Julio Guerra [not found] ` <2c59e268-9fd6-172b-1803-074aa4e11f27-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Julio Guerra @ 2016-08-20 3:40 UTC (permalink / raw) To: linux-usb-u79uwXL29TY76Z2rM5mHXA, linux-serial-u79uwXL29TY76Z2rM5mHXA Hi, I have noticed a problem using a usb device managed by the cdc_acm driver. The data received from the device and copied to userspace ends up being shifted by one byte again and again after some amount of calls to read() and most importantly with previously read data. usbmon shows the usb data payload is correct. A small shell script is enough to make it happen fastly: https://gist.github.com/Julio-Guerra/b6529994f814771c825649bdb8d927c2 It prints the buffer read with my device (a relay) and gives me things like: > 00 01 01 01 00 01 00 01 ... > 01 00 01 01 01 00 01 00 ... > 00 01 00 01 01 01 00 01 after a random number of times, while usbmon shows the usb payload "00 01 01 01 00 01 00 01" Another example: > 00 00 00 00 00 00 00 01 ... > 01 00 00 00 00 00 00 00 ... > 00 01 00 00 00 00 00 00 ... > 00 00 01 00 00 00 00 00 after a random number of times, while usbmon shows the usb payload "00 00 00 00 00 00 00 01". Any idea? I currently use versions 4.5.0 and 4.7.1 to execute this script. Thanks you -- Julio Guerra -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <2c59e268-9fd6-172b-1803-074aa4e11f27-wf23HAOg02MWenYVfaLwtA@public.gmane.org>]
* Re: cdc_acm bug? read buffer bytes shifted [not found] ` <2c59e268-9fd6-172b-1803-074aa4e11f27-wf23HAOg02MWenYVfaLwtA@public.gmane.org> @ 2016-08-20 11:32 ` Oliver Neukum [not found] ` <1471692758.29854.0.camel-IBi9RG/b67k@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Oliver Neukum @ 2016-08-20 11:32 UTC (permalink / raw) To: Julio Guerra Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA On Sat, 2016-08-20 at 05:40 +0200, Julio Guerra wrote: > Another example: > > 00 00 00 00 00 00 00 01 > ... > > 01 00 00 00 00 00 00 00 > ... > > 00 01 00 00 00 00 00 00 > ... > > 00 00 01 00 00 00 00 00 > after a random number of times, while usbmon shows the usb payload > "00 00 00 00 00 00 00 01". Hi, how many bytes does read() return? Regards Oliver -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <1471692758.29854.0.camel-IBi9RG/b67k@public.gmane.org>]
* Re: cdc_acm bug? read buffer bytes shifted [not found] ` <1471692758.29854.0.camel-IBi9RG/b67k@public.gmane.org> @ 2016-08-20 12:14 ` Julio Guerra [not found] ` <4bffb2dd-de01-8819-cf44-c4fb1357ecd4-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Julio Guerra @ 2016-08-20 12:14 UTC (permalink / raw) To: Oliver Neukum Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA >> Another example: >>> 00 00 00 00 00 00 00 01 >> ... >>> 01 00 00 00 00 00 00 00 >> ... >>> 00 01 00 00 00 00 00 00 >> ... >>> 00 00 01 00 00 00 00 00 >> after a random number of times, while usbmon shows the usb payload >> "00 00 00 00 00 00 00 01". > > Hi, how many bytes does read() return? > Exactly 8 bytes, always. I set the tty in raw non-canonical mode with vmin = 8 and vtime = 0. I also tried with vmin = 1 and did the copy of exactly 8 bytes by looping in userspace, without any improvement. I wrote a small workaround for now that detects this problem (because I exactly know what the buffer is supposed to look like) to close() and re-open() the device. The next read buffer is then correct. -- Julio Guerra -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <4bffb2dd-de01-8819-cf44-c4fb1357ecd4-wf23HAOg02MWenYVfaLwtA@public.gmane.org>]
* Re: cdc_acm bug? read buffer bytes shifted [not found] ` <4bffb2dd-de01-8819-cf44-c4fb1357ecd4-wf23HAOg02MWenYVfaLwtA@public.gmane.org> @ 2016-08-21 12:11 ` Julio Guerra 2016-08-22 14:04 ` Oliver Neukum 1 sibling, 0 replies; 7+ messages in thread From: Julio Guerra @ 2016-08-21 12:11 UTC (permalink / raw) To: Oliver Neukum Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA >>> Another example: >>>> 00 00 00 00 00 00 00 01 >>> ... >>>> 01 00 00 00 00 00 00 00 >>> ... >>>> 00 01 00 00 00 00 00 00 >>> ... >>>> 00 00 01 00 00 00 00 00 >>> after a random number of times, while usbmon shows the usb payload >>> "00 00 00 00 00 00 00 01". >> >> Hi, how many bytes does read() return? >> > > Exactly 8 bytes, always. I set the tty in raw non-canonical mode with > vmin = 8 and vtime = 0. I also tried with vmin = 1 and did the copy of > exactly 8 bytes by looping in userspace, without any improvement. > > I wrote a small workaround for now that detects this problem (because I > exactly know what the buffer is supposed to look like) to close() and > re-open() the device. The next read buffer is then correct. > Some more precisions: I just had access to the FTDI version of the device instead of the Microchip one and the bug did not appear under the ftdi_sio driver, by running the previous script approx. 5 minutes. -- Julio Guerra -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cdc_acm bug? read buffer bytes shifted [not found] ` <4bffb2dd-de01-8819-cf44-c4fb1357ecd4-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 2016-08-21 12:11 ` Julio Guerra @ 2016-08-22 14:04 ` Oliver Neukum [not found] ` <1471874667.17783.19.camel-IBi9RG/b67k@public.gmane.org> 1 sibling, 1 reply; 7+ messages in thread From: Oliver Neukum @ 2016-08-22 14:04 UTC (permalink / raw) To: Julio Guerra Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA On Sat, 2016-08-20 at 14:14 +0200, Julio Guerra wrote: > >> Another example: > >>> 00 00 00 00 00 00 00 01 > >> ... > >>> 01 00 00 00 00 00 00 00 > >> ... > >>> 00 01 00 00 00 00 00 00 > >> ... > >>> 00 00 01 00 00 00 00 00 > >> after a random number of times, while usbmon shows the usb payload > >> "00 00 00 00 00 00 00 01". > > > > Hi, how many bytes does read() return? > > > > Exactly 8 bytes, always. I set the tty in raw non-canonical mode with > vmin = 8 and vtime = 0. I also tried with vmin = 1 and did the copy of > exactly 8 bytes by looping in userspace, without any improvement. > > I wrote a small workaround for now that detects this problem (because I > exactly know what the buffer is supposed to look like) to close() and > re-open() the device. The next read buffer is then correct. > Please activate dynamic debugging for the tty and cdc_acm driver. We need to know where the corruption happens. Regards Oliver -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <1471874667.17783.19.camel-IBi9RG/b67k@public.gmane.org>]
* Re: cdc_acm bug? read buffer bytes shifted [not found] ` <1471874667.17783.19.camel-IBi9RG/b67k@public.gmane.org> @ 2016-09-16 16:24 ` Julio Guerra [not found] ` <f97a97ee-4d22-145c-5f73-472ee4f03968-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Julio Guerra @ 2016-09-16 16:24 UTC (permalink / raw) To: Oliver Neukum Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1.1: Type: text/plain, Size: 1562 bytes --] > On Sat, 2016-08-20 at 14:14 +0200, Julio Guerra wrote: >>>> Another example: >>>>> 00 00 00 00 00 00 00 01 >>>> ... >>>>> 01 00 00 00 00 00 00 00 >>>> ... >>>>> 00 01 00 00 00 00 00 00 >>>> ... >>>>> 00 00 01 00 00 00 00 00 >>>> after a random number of times, while usbmon shows the usb payload >>>> "00 00 00 00 00 00 00 01". >>> >>> Hi, how many bytes does read() return? >>> >> >> Exactly 8 bytes, always. I set the tty in raw non-canonical mode with >> vmin = 8 and vtime = 0. I also tried with vmin = 1 and did the copy of >> exactly 8 bytes by looping in userspace, without any improvement. >> >> I wrote a small workaround for now that detects this problem (because I >> exactly know what the buffer is supposed to look like) to close() and >> re-open() the device. The next read buffer is then correct. >> > > Please activate dynamic debugging for the tty and cdc_acm driver. > We need to know where the corruption happens. > I didn't find anything helpful in /sys/kernel/debug/dynamic_debug regarging the tty module (I enabled tty_io debugs and it doesn't appear in the logs), but I enabled cdc_acm debugs. Nothing is observable in the logs when the bug appears. I logged everything as a comment of the gist: https://gist.github.com/Julio-Guerra/b6529994f814771c825649bdb8d927c2#gistcomment-1875985 Note that re-running the script restarts the underlying kernel buffer correctly, it does not restart from its previous bugged state. Let me know if you want other debug traces enabled. -- Julio Guerra [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 842 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <f97a97ee-4d22-145c-5f73-472ee4f03968-wf23HAOg02MWenYVfaLwtA@public.gmane.org>]
* Re: cdc_acm bug? read buffer bytes shifted [not found] ` <f97a97ee-4d22-145c-5f73-472ee4f03968-wf23HAOg02MWenYVfaLwtA@public.gmane.org> @ 2016-09-20 8:45 ` Oliver Neukum 0 siblings, 0 replies; 7+ messages in thread From: Oliver Neukum @ 2016-09-20 8:45 UTC (permalink / raw) To: Julio Guerra Cc: linux-serial-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA On Fri, 2016-09-16 at 18:24 +0200, Julio Guerra wrote: > > On Sat, 2016-08-20 at 14:14 +0200, Julio Guerra wrote: > >>>> Another example: > >>>>> 00 00 00 00 00 00 00 01 > >>>> ... > >>>>> 01 00 00 00 00 00 00 00 > >>>> ... > >>>>> 00 01 00 00 00 00 00 00 > >>>> ... > >>>>> 00 00 01 00 00 00 00 00 > >>>> after a random number of times, while usbmon shows the usb payload > >>>> "00 00 00 00 00 00 00 01". > >>> > >>> Hi, how many bytes does read() return? > >>> > >> > >> Exactly 8 bytes, always. I set the tty in raw non-canonical mode with > >> vmin = 8 and vtime = 0. I also tried with vmin = 1 and did the copy of > >> exactly 8 bytes by looping in userspace, without any improvement. > >> > >> I wrote a small workaround for now that detects this problem (because I > >> exactly know what the buffer is supposed to look like) to close() and > >> re-open() the device. The next read buffer is then correct. > >> > > > > Please activate dynamic debugging for the tty and cdc_acm driver. > > We need to know where the corruption happens. > > > > I didn't find anything helpful in /sys/kernel/debug/dynamic_debug > regarging the tty module (I enabled tty_io debugs and it doesn't appear > in the logs), but I enabled cdc_acm debugs. Nothing is observable in the > logs when the bug appears. I logged everything as a comment of the gist: > https://gist.github.com/Julio-Guerra/b6529994f814771c825649bdb8d927c2#gistcomment-1875985 > > Note that re-running the script restarts the underlying kernel buffer > correctly, it does not restart from its previous bugged state. > > Let me know if you want other debug traces enabled. > Can you modify the tty layer to print out the buffer? It is unclear from the logs where the shift happens. Regards Oliver -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-09-20 8:45 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-08-20 3:40 cdc_acm bug? read buffer bytes shifted Julio Guerra [not found] ` <2c59e268-9fd6-172b-1803-074aa4e11f27-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 2016-08-20 11:32 ` Oliver Neukum [not found] ` <1471692758.29854.0.camel-IBi9RG/b67k@public.gmane.org> 2016-08-20 12:14 ` Julio Guerra [not found] ` <4bffb2dd-de01-8819-cf44-c4fb1357ecd4-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 2016-08-21 12:11 ` Julio Guerra 2016-08-22 14:04 ` Oliver Neukum [not found] ` <1471874667.17783.19.camel-IBi9RG/b67k@public.gmane.org> 2016-09-16 16:24 ` Julio Guerra [not found] ` <f97a97ee-4d22-145c-5f73-472ee4f03968-wf23HAOg02MWenYVfaLwtA@public.gmane.org> 2016-09-20 8:45 ` Oliver Neukum
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).