RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-19 Thread Du, Changbin
Hi, > > I'd prefer fail the request at all, and it is better done in HW. > > Because per the USB Spec that device can return NAK if a function was > > unable to accept data From the host. The DWC3 has not been design as > > this, if software fail the transfer, it is a little weird for host. > > >

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-19 Thread Michal Nazarewicz
On Thu, May 19 2016, Changbin Du wrote: >> On Wed, May 18 2016, Felipe Balbi wrote: >> > we've been through this before. This needs to be done at the gadget >> > layer. Gadget driver can over-allocate ahead of time if >> > gadget->quirk_ep_out_aligned_size is true, then we avoid memcpy() at >> > th

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-18 Thread Du, Changbin
> On Wed, May 18 2016, Felipe Balbi wrote: > > we've been through this before. This needs to be done at the gadget > > layer. Gadget driver can over-allocate ahead of time if > > gadget->quirk_ep_out_aligned_size is true, then we avoid memcpy() at > > the UDC driver level. > > Right, all right, so

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-18 Thread Du, Changbin
> >> thanks Alan Stern and Michal. > >> Here just have a comment - the buffered data need be dropped when > the > >> epfile is closed, because it means the session is terminated. > > > > I blame that on sleep deprivation. Another issue is what to do when > > endpoint is disabled. Should the buffe

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-18 Thread Michal Nazarewicz
On Wed, May 18 2016, Felipe Balbi wrote: > we've been through this before. This needs to be done at the gadget > layer. Gadget driver can over-allocate ahead of time if > gadget->quirk_ep_out_aligned_size is true, then we avoid memcpy() at > the UDC driver level. Right, all right, so let’s look at

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-18 Thread Felipe Balbi
Hi, Michal Nazarewicz writes: > On Tue, May 17 2016, Changbin Du wrote: >>> There appears to be no kfifo support for iov_iter though, so I just went >>> with a simple buffer. >>> >>> I haven’t looked at the patch too carefully so this is an RFC rather >>> than an actual patch at this point. It

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-18 Thread Michal Nazarewicz
On Tue, May 17 2016, Changbin Du wrote: >> There appears to be no kfifo support for iov_iter though, so I just went >> with a simple buffer. >> >> I haven’t looked at the patch too carefully so this is an RFC rather >> than an actual patch at this point. It does compile at least. >> >> Regardles

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Du, Changbin
> There appears to be no kfifo support for iov_iter though, so I just went > with a simple buffer. > > I haven’t looked at the patch too carefully so this is an RFC rather > than an actual patch at this point. It does compile at least. > > Regardless, the more I thin about it, the more I’m under

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Michal Nazarewicz
On Mon, May 16 2016, Felipe Balbi wrote: > Michal Nazarewicz writes: > >>> Alan Stern writes: The point is that you don't know whether the host sent more data than expected. All you know is that the host sent more data than the user asked the kernel for -- but maybe the user didn'

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Michal Nazarewicz
> On 05/16/2016 06:05 PM, Michal Nazarewicz wrote: >> So I’ve been looking at AIO handling in f_fs and either I’m stupid or >> the code is broken. On Mon, May 16 2016, Lars-Peter Clausen wrote: > The code was broken. Fixed in commit 332a5b446b791 ("usb: gadget: > f_fs: Fix EFAULT generation for as

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Krzysztof Opasiak
Hi Michal, On 05/16/2016 06:05 PM, Michal Nazarewicz wrote: > So I’ve been looking at AIO handling in f_fs and either I’m stupid or > the code is broken. Here’s part of ffs_user_copy_worker: > > int ret = io_data->req->status ? io_data->req->status : >

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Lars-Peter Clausen
On 05/16/2016 06:05 PM, Michal Nazarewicz wrote: > So I’ve been looking at AIO handling in f_fs and either I’m stupid or > the code is broken. The code was broken. Fixed in commit 332a5b446b791 ("usb: gadget: f_fs: Fix EFAULT generation for async read operations:). -- To unsubscribe from this list

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Michal Nazarewicz
So I’ve been looking at AIO handling in f_fs and either I’m stupid or the code is broken. Here’s part of ffs_user_copy_worker: int ret = io_data->req->status ? io_data->req->status : io_data->req->actual; if (io_data->read && ret > 0) {

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Felipe Balbi
Michal Nazarewicz writes: >> Alan Stern writes: >>> The point is that you don't know whether the host sent more data than >>> expected. All you know is that the host sent more data than the user >>> asked the kernel for -- but maybe the user didn't ask for all the >>> data that he expected. Ma

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Michal Nazarewicz
> Alan Stern writes: >> The point is that you don't know whether the host sent more data than >> expected. All you know is that the host sent more data than the user >> asked the kernel for -- but maybe the user didn't ask for all the >> data that he expected. Maybe the user wanted to retrieve t

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-16 Thread Felipe Balbi
Hi, Alan Stern writes: > On Fri, 13 May 2016, Felipe Balbi wrote: > >> We deliver to userspace the part userspace requested, right? So that's >> okay. The USB details WRT e.g. babble or host trying to send more data >> than expected, needs to be handled within the kernel. > > The point is that y

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-14 Thread Michal Nazarewicz
On Fri, May 13 2016, Alan Stern wrote: > The point is that you don't know whether the host sent more data than > expected. All you know is that the host sent more data than the user > asked the kernel for -- but maybe the user didn't ask for all the data > that he expected. Maybe the user wanted

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-13 Thread Alan Stern
On Fri, 13 May 2016, Felipe Balbi wrote: > We deliver to userspace the part userspace requested, right? So that's > okay. The USB details WRT e.g. babble or host trying to send more data > than expected, needs to be handled within the kernel. The point is that you don't know whether the host sent

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-13 Thread Du, Changbin
Hi, > >> Yeah, it probably deserves a pr_err() or pr_debug(), but host sending > >> more data than it should, is another problem altogether which needs to > >> be addressed at the host. > >> > >> Adding a print to aid debugging is a good idea, but bailing out on the > >> peripheral side is not :-s

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi, "Du, Changbin" writes: >> "Du, Changbin" writes: >> >> right, and that was my point: if we copy more to userspace, then we have >> >> a real big problem. >> >> >> > Yes, we drop the data because we userspace buffer is not enough this time. >> > The problem here is that really can we just dr

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Du, Changbin
> Hi, > > "Du, Changbin" writes: > >> right, and that was my point: if we copy more to userspace, then we have > >> a real big problem. > >> > > Yes, we drop the data because we userspace buffer is not enough this time. > > The problem here is that really can we just drop it silently? Maybe not.

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi, "Du, Changbin" writes: >> right, and that was my point: if we copy more to userspace, then we have >> a real big problem. >> > Yes, we drop the data because we userspace buffer is not enough this time. > The problem here is that really can we just drop it silently? Maybe not. Yeah, it prob

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Du, Changbin
> Hi, > > "Du, Changbin" writes: > >> >> > These all can lead host send more than device wanted bytes. For > sure > >> >> > it wrong at host side, but device side don't know. > >> >> > >> >> but none of this means we have a bug at device side. In fact, by > >> >> allowing these extra bytes to rea

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi, "Du, Changbin" writes: >> >> > These all can lead host send more than device wanted bytes. For sure >> >> > it wrong at host side, but device side don't know. >> >> >> >> but none of this means we have a bug at device side. In fact, by >> >> allowing these extra bytes to reach userspace, we

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi, "Du, Changbin" writes: >> >> > These all can lead host send more than device wanted bytes. For sure >> >> > it wrong at host side, but device side don't know. >> >> >> >> but none of this means we have a bug at device side. In fact, by >> >> allowing these extra bytes to reach userspace, we

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Du, Changbin
Hi, > > we need a min() here. Better version below: No need. copy_to_iter will do it for us. Best Regards, Du, Changbin > > diff --git a/drivers/usb/gadget/function/f_fs.c > b/drivers/usb/gadget/function/f_fs.c > index 73515d54e1cc..6c49b152f46e 100644 > --- a/drivers/usb/gadget/function/f_fs.c

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Du, Changbin
> >> > These all can lead host send more than device wanted bytes. For sure > >> > it wrong at host side, but device side don't know. > >> > >> but none of this means we have a bug at device side. In fact, by > >> allowing these extra bytes to reach userspace, we could be creating a > >> possible a

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi again, Felipe Balbi writes: > @@ -811,7 +815,12 @@ static ssize_t ffs_epfile_io(struct file *file, struct > ffs_io_data *io_data) >*/ > ret = interrupted ? -EINTR : ep->status; > if (io_data->read && ret > 0) { > - ret = copy_to

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi, "Du, Changbin" writes: >> >> > The problem is device side app sometimes received incorrect data >> caused >> >> > by the dropping. Most times the error can be detected by APP itself, but >> >> >> >> why ? app did e.g. read(5), that caused driver to queue a usb_request >> >> with length set t

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Du, Changbin
> > The extra bytes can be anything(random), they just data from APP layer. > > It doesn't make sense for you to check. So I will not dump them, sorry. > > interesting, so you claim to have found a bug, but when asked to provide > more information your answer is "no" ? Thanks :-) > Do you really

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Felipe Balbi
Hi, "Du, Changbin" writes: > Hi, > >> >> and when has this actually happened ? Host should not send more data in >> >> this case, if it does, it's an error on the host side. Also, returning >> >> -EOVERFLOW is not exactly correct here, because you'd violate POSIX >> >> specification of read(), r

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-12 Thread Du, Changbin
Hi, > >> and when has this actually happened ? Host should not send more data in > >> this case, if it does, it's an error on the host side. Also, returning > >> -EOVERFLOW is not exactly correct here, because you'd violate POSIX > >> specification of read(), right ? > >> > > This can happen if th

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-11 Thread Felipe Balbi
Hi, "Du, Changbin" writes: >> > If it happen, we can keep the excess data for next i/o, or >> > report an error. But we cannot silently drop data, because >> > USB layer should ensure the data integrality it has transferred, >> > otherwise applications may get corrupt data if it doesn't >> > det

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-11 Thread Du, Changbin
> On Wed, May 11 2016, Felipe Balbi wrote: > > Also, returning -EOVERFLOW is not exactly correct here, because you'd > > violate POSIX specification of read(), right ? > > Maybe we could piggyback on: > >EINVAL fd was created via a call to timerfd_create(2) and the > wrong s

RE: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-11 Thread Du, Changbin
> Hi, > > changbin...@intel.com writes: > > From: "Du, Changbin" > > > > Since the buffer size for req is rounded up to maxpacketsize, > > then we may end up with more data then user space has space > > for. > > only for OUT direction with the controller you're using ;-) For sure. > > > If it

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-11 Thread Michal Nazarewicz
On Wed, May 11 2016, Felipe Balbi wrote: > Also, returning -EOVERFLOW is not exactly correct here, because you'd > violate POSIX specification of read(), right ? Maybe we could piggyback on: EINVAL fd was created via a call to timerfd_create(2) and the wrong size buffer was g

Re: [PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-11 Thread Felipe Balbi
Hi, changbin...@intel.com writes: > From: "Du, Changbin" > > Since the buffer size for req is rounded up to maxpacketsize, > then we may end up with more data then user space has space > for. only for OUT direction with the controller you're using ;-) > If it happen, we can keep the excess dat

[PATCH] usb: gadget: f_fs: report error if excess data received

2016-05-11 Thread changbin . du
From: "Du, Changbin" Since the buffer size for req is rounded up to maxpacketsize, then we may end up with more data then user space has space for. If it happen, we can keep the excess data for next i/o, or report an error. But we cannot silently drop data, because USB layer should ensure the da