From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753936AbcESHek (ORCPT ); Thu, 19 May 2016 03:34:40 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:35936 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753388AbcESHei convert rfc822-to-8bit (ORCPT ); Thu, 19 May 2016 03:34:38 -0400 From: Michal Nazarewicz To: "Du\, Changbin" , Felipe Balbi , Alan Stern Cc: Al Viro , "gregkh\@linuxfoundation.org" , "rui.silva\@linaro.org" , "k.opasiak\@samsung.com" , "lars\@metafoo.de" , "linux-usb\@vger.kernel.org" , "linux-kernel\@vger.kernel.org" Subject: Re: [PATCH] usb: gadget: f_fs: report error if excess data received In-Reply-To: <0C18FE92A7765D4EB9EE5D38D86A563A05D30D7A@SHSMSX103.ccr.corp.intel.com> Organization: http://mina86.com/ References: <87eg92p3cn.fsf@linux.intel.com> <87bn46p2gk.fsf@linux.intel.com> <0C18FE92A7765D4EB9EE5D38D86A563A05D30546@SHSMSX103.ccr.corp.intel.com> <878tz7zn7y.fsf@linux.intel.com> <0C18FE92A7765D4EB9EE5D38D86A563A05D30D7A@SHSMSX103.ccr.corp.intel.com> User-Agent: Notmuch/0.19+53~g2e63a09 (http://notmuchmail.org) Emacs/25.1.50.1 (x86_64-unknown-linux-gnu) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACP0lEQVQ4T23Sv2vbQBQHcBk1xE6WyALX107VUEgmn6+ouUwpEQQ6uRjttkWP4CkBg2M0BQLBdPFZYPsyFYo7qEtKDQ7on+t7+nF2Ux8ahD587717OmNYrOvycHsZ+o2r051wHTHysAvGb8ygvgu4QWT0sCmkgZCIEnlV2X8BtyraazFGDuxhmKSQJMlwHQ7v5MHSNxmz78rfElwAa3ieVD9e+hBhjaPDDG6NgFo2f4wBMNIo5YmRtF0RyDgFjJjlMIWbnuM4x9MMfABGTlN4qgIQB4A1DEyA1BHWtfeWNUMwiVJKoqh97KrkOO+qzgluVYLvFCUKAX73nONeBr7BGMdM6Sg0kuep03VywLaIzRiVr+GAzKlpQIsAFnWAG2e6DT5WmWDiudZMIc6hYrMOmeMQK9WX0B+/RfjzL9DI7Y9/Iayn29Ci0r2i4f9gMimMSZLCDMalgQGU5hnUtqAN0OGvEmO1Wnl0C0wWSCEHnuHBqmygxdxA8oWXwbipoc1EoNR9DqOpBpOJrnr0criQab9ZT4LL+wI+K7GBQH30CrhUruilgP9DRTrhVWZCiAyILP+wiuLeCKGTD6r/nc8LOJcAwR6IBTUs+7CASw3QFZ0MdA2PI3zNziH4ZKVhXCRMBjeZ1DWMekKwDCASwExy+NQ86TaykaDAFHO4aP48y4fIcDM5yOG8GcTLbOyp8A8azjJI93JFd1EA6yN8sSxMQJWoABqniRZVykYgRXErzrdqExAoUrRb0xfRp8p2A/4XmfilTtkDZ4cAAAAASUVORK5CYII= X-Face: -TR8(rDTHy/(xl?SfWd1|3:TTgDIatE^t'vop%*gVg[kn$t{EpK(P"VQ=~T2#ysNmJKN$"yTRLB4YQs$4{[.]Fc1)*O]3+XO^oXM>Q#b^ix,O)Zbn)q[y06$`e3?C)`CwR9y5riE=fv^X@x$y?D:XO6L&x4f-}}I4=VRNwiA^t1-ZrVK^07.Pi/57c_du'& X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:160519:lars@metafoo.de::wFmh+YjuXQA/IrC0:00059C X-Hashcash: 1:20:160519:linux-kernel@vger.kernel.org::jbwpLxE2Q+U1UgU5:0000000000000000000000000000000001MiJ X-Hashcash: 1:20:160519:gregkh@linuxfoundation.org::xX67jnQjziOVm288:000000000000000000000000000000000002gXE X-Hashcash: 1:20:160519:viro@zeniv.linux.org.uk::TOfxvmWiQAufy9TR:000000000000000000000000000000000000001K7W X-Hashcash: 1:20:160519:felipe.balbi@linux.intel.com::OGuQk+Bm2Rl/94Cb:0000000000000000000000000000000001ZVi X-Hashcash: 1:20:160519:stern@rowland.harvard.edu::X2JYllhSjwQC8gOj:0000000000000000000000000000000000004iaS X-Hashcash: 1:20:160519:linux-usb@vger.kernel.org::HHrnhao/9yuPzZdS:0000000000000000000000000000000000003bfH X-Hashcash: 1:20:160519:changbin.du@intel.com::CcPP9G7xGETvUWU4:00000000000000000000000000000000000000006CXJ X-Hashcash: 1:20:160519:rui.silva@linaro.org::ElPGJGyvLG086f18:00000000000000000000000000000000000000000Da0H X-Hashcash: 1:20:160519:k.opasiak@samsung.com::JeP6doE8p6p3D172:0000000000000000000000000000000000000000C5jI Date: Thu, 19 May 2016 09:34:33 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> > the UDC driver level. >> >> Right, all right, so let’s look at it from a regular USB function point >> of view. If a USB function allocates a request which is not aligned, >> UDC will align the buffer and *drop* excess data. Seeing how ugly > Do you mean UDC driver align the buffer? I searched the code, currently > only DWC3 needs buffer size to be aligned to MaxPacketSize on ep out. > And the align is done in f_fs driver. I thought that was what was happening based on Felipe’s comment about avoiding memcpy. I looked at the code now and dunno what actually happens. >> f_fs’s code is becoming, I’m now leaning to letting to f_fs do the same >> thing: if user space makes an unaligned read, f_fs aligns the buffer and >> then drops excess data. >> >> Any arguments for f_fs to not drop the data apply to UDC, so they should >> behave identically. >> > 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. > > So, now we have 3 choices: > 1) buffer the excess data > 2) fail the transfer You mean fail when more data has been sent (i.e. drop the whole packet) or fail at entry to read() if the buffer is not aligned? > 3) drop the excess data, then print an warning message > > Which one do you prefer? I think f_fs should mimic whatever happens if unaligned request is queued on dwc3. As far as I understand, this is not 1. I’ll be travelling again on Friday so I’ll finish up the patch doing 1 so we will have a choice between 1 (my patch) and 3 (your patch). -- Best regards ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ «If at first you don’t succeed, give up skydiving»