Opened 7 years ago

Closed 7 months ago

#8530 closed bug (fixed)

USB bus manager does not support unaligned read/writes

Reported by: pulkomandy Owned by: mmlr
Priority: normal Milestone: R1
Component: Drivers/USB Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

I'm trying to perform some simple sector read/write operations on an usb mass storage device (SD card reader).

The following code works fine :

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
	char* buffer = malloc(512);
	int fd = open("/dev/disk/usb/0/3/raw", O_RDONLY);
	
	lseek(fd, 8192, SEEK_SET);
	
	if (fd < 0)
		perror("open error");
	if (read(fd, buffer, 1) == -1)
		perror("read error");

	close(fd);
	free(buffer);
}

But this one doesn't :

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
	char buffer[512];
	int fd = open("/dev/disk/usb/0/3/raw", O_RDONLY);
	
	lseek(fd, 8192, SEEK_SET);
	
	if (fd < 0)
		perror("open error");
	if (read(fd, buffer, 1) == -1)
		perror("read error");

	close(fd);
}

The only difference is the way buffer is allocated. Our malloc happens to align memory to pages, while allocating on the stack obviously doesn't.

Following message is seen in error log :

KERN: usb error transfer 0: data buffer spans across multiple areas!
KERN: usb error ehci -1: failed to add pending transfer

From then on, the device is not accessible anymore by any means and needs to be unplugged/replugged.

Change History (3)

comment:1 Changed 7 years ago by phoudoin

Well, three remarks:

  1. it's not limited to EHCI, as it's an USB bus manager issue, not a controler one.
  2. it's not a page alignment issue, but lack of multiple pages support
  3. the fact that it makes the device not accessible anymore is a definitive extra bug, that should be tracking down: an explicitly handled error in the stack should not let the device access in a broken state

comment:2 Changed 4 years ago by waddlesplash

Summary: EHCI usb driver does not support unaligned read/writesUSB bus manager does not support unaligned read/writes

Changing summary as per comment.

comment:3 Changed 7 months ago by pulkomandy

Resolution: fixed
Status: newclosed

Not reproductible anymore.

Note: See TracTickets for help on using tickets.