Re: [PATCH v3 1/2] usb: gadget: loopback: fix: Don't share qlen and buflen between instances
On Thu, Sep 24, 2015 at 07:10:53PM +0200, Krzysztof Opasiak wrote: > > > On 09/24/2015 06:51 PM, Felipe Balbi wrote: > >On Thu, Sep 24, 2015 at 05:19:12PM +0200, Robert Baldyga wrote: > >>On 09/22/2015 08:40 PM, Krzysztof Opasiak wrote: > >>>Each instance of loopback function may have different qlen > >>>and buflen attributes values. When linking function to > >>>configuration those values had been assigned to global > >>>variables. Linking other instance to config overwrites those > >>>values. > >>> > >>>This commit moves those values to f_loopback structure > >>>to avoid overwriting. Now each function has its own instance > >>>of those values. > >>> > >>>Cc:# 3.10+ > >>>Signed-off-by: Krzysztof Opasiak > >> > >>Reviewed-by: Robert Baldyga > > > >doesn't seem to fit stable IMO. Care to explain why you think we need > >to backport this to v3.10+ ? > > > > Let's consider following set of commands: > > cd $CFS_ROOT/usb_gadget > mkdir g1 > cd g1 > mkdir functions/SourceSink.1 > mkdir functions/SourceSink.2 > echo 1024 > functions/SourceSink.1/buflen > echo 512 > functions/SourceSink.2/buflen > mkdir configs/c.1 > ln -s functions/SourceSink.1 configs/c.1/ > ln -s functions/SourceSink.2 configs/c.1/ > echo $UDC > UDC > > You assume that after executing this script you will get two instances of > SourceSink functions and one of them will alloc requests buffers which has > 1024 and second one which has only 512. > > Unfortunately due to using global variables both of them are going to alloc > only 512 bytes for each request. The same situation is with qlen. All > instances are going to use attributes values from the last one in the > system, even if they are in multiple gadgets. that's all fine and dandy, but it's still a new requirement. It fits easily into "has never worked before" category. If it was something which really regressed, IOW we used to support it but some other commit broke it, then I'd agree. > In my opinion second patch in this series is much more important as it makes > loopback function working again after almost year of being only /dev/null > and /dev/zero. But that one should to go only to 3.18. ok -- balbi signature.asc Description: PGP signature
Re: [PATCH v3 1/2] usb: gadget: loopback: fix: Don't share qlen and buflen between instances
On 09/22/2015 08:40 PM, Krzysztof Opasiak wrote: > Each instance of loopback function may have different qlen > and buflen attributes values. When linking function to > configuration those values had been assigned to global > variables. Linking other instance to config overwrites those > values. > > This commit moves those values to f_loopback structure > to avoid overwriting. Now each function has its own instance > of those values. > > Cc:# 3.10+ > Signed-off-by: Krzysztof Opasiak Reviewed-by: Robert Baldyga > --- > drivers/usb/gadget/function/f_loopback.c | 24 +--- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/usb/gadget/function/f_loopback.c > b/drivers/usb/gadget/function/f_loopback.c > index 6e2fe63..e4bfed4 100644 > --- a/drivers/usb/gadget/function/f_loopback.c > +++ b/drivers/usb/gadget/function/f_loopback.c > @@ -34,6 +34,9 @@ struct f_loopback { > > struct usb_ep *in_ep; > struct usb_ep *out_ep; > + > + unsignedqlen; > + unsignedbuflen; > }; > > static inline struct f_loopback *func_to_loop(struct usb_function *f) > @@ -41,13 +44,10 @@ static inline struct f_loopback *func_to_loop(struct > usb_function *f) > return container_of(f, struct f_loopback, function); > } > > -static unsigned qlen; > -static unsigned buflen; > - > /*-*/ > > static struct usb_interface_descriptor loopback_intf = { > - .bLength = sizeof loopback_intf, > + .bLength = sizeof(loopback_intf), > .bDescriptorType = USB_DT_INTERFACE, > > .bNumEndpoints =2, > @@ -253,7 +253,7 @@ static void loopback_complete(struct usb_ep *ep, struct > usb_request *req) > } > > /* queue the buffer for some later OUT packet */ > - req->length = buflen; > + req->length = loop->buflen; > status = usb_ep_queue(ep, req, GFP_ATOMIC); > if (status == 0) > return; > @@ -290,7 +290,9 @@ static void disable_loopback(struct f_loopback *loop) > > static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len) > { > - return alloc_ep_req(ep, len, buflen); > + struct f_loopback *loop = ep->driver_data; > + > + return alloc_ep_req(ep, len, loop->buflen); > } > > static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback > *loop, > @@ -317,7 +319,7 @@ static int enable_endpoint(struct usb_composite_dev > *cdev, struct f_loopback *lo >* we buffer at most 'qlen' transfers; fewer if any need more >* than 'buflen' bytes each. >*/ > - for (i = 0; i < qlen && result == 0; i++) { > + for (i = 0; i < loop->qlen && result == 0; i++) { > req = lb_alloc_ep_req(ep, 0); > if (!req) > goto fail1; > @@ -391,10 +393,10 @@ static struct usb_function *loopback_alloc(struct > usb_function_instance *fi) > lb_opts->refcnt++; > mutex_unlock(_opts->lock); > > - buflen = lb_opts->bulk_buflen; > - qlen = lb_opts->qlen; > - if (!qlen) > - qlen = 32; > + loop->buflen = lb_opts->bulk_buflen; > + loop->qlen = lb_opts->qlen; > + if (!loop->qlen) > + loop->qlen = 32; > > loop->function.name = "loopback"; > loop->function.bind = loopback_bind; > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 1/2] usb: gadget: loopback: fix: Don't share qlen and buflen between instances
On Thu, Sep 24, 2015 at 05:19:12PM +0200, Robert Baldyga wrote: > On 09/22/2015 08:40 PM, Krzysztof Opasiak wrote: > > Each instance of loopback function may have different qlen > > and buflen attributes values. When linking function to > > configuration those values had been assigned to global > > variables. Linking other instance to config overwrites those > > values. > > > > This commit moves those values to f_loopback structure > > to avoid overwriting. Now each function has its own instance > > of those values. > > > > Cc:# 3.10+ > > Signed-off-by: Krzysztof Opasiak > > Reviewed-by: Robert Baldyga doesn't seem to fit stable IMO. Care to explain why you think we need to backport this to v3.10+ ? > > > --- > > drivers/usb/gadget/function/f_loopback.c | 24 +--- > > 1 file changed, 13 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/usb/gadget/function/f_loopback.c > > b/drivers/usb/gadget/function/f_loopback.c > > index 6e2fe63..e4bfed4 100644 > > --- a/drivers/usb/gadget/function/f_loopback.c > > +++ b/drivers/usb/gadget/function/f_loopback.c > > @@ -34,6 +34,9 @@ struct f_loopback { > > > > struct usb_ep *in_ep; > > struct usb_ep *out_ep; > > + > > + unsignedqlen; > > + unsignedbuflen; > > }; > > > > static inline struct f_loopback *func_to_loop(struct usb_function *f) > > @@ -41,13 +44,10 @@ static inline struct f_loopback *func_to_loop(struct > > usb_function *f) > > return container_of(f, struct f_loopback, function); > > } > > > > -static unsigned qlen; > > -static unsigned buflen; > > - > > > > /*-*/ > > > > static struct usb_interface_descriptor loopback_intf = { > > - .bLength = sizeof loopback_intf, > > + .bLength = sizeof(loopback_intf), > > .bDescriptorType = USB_DT_INTERFACE, > > > > .bNumEndpoints =2, > > @@ -253,7 +253,7 @@ static void loopback_complete(struct usb_ep *ep, struct > > usb_request *req) > > } > > > > /* queue the buffer for some later OUT packet */ > > - req->length = buflen; > > + req->length = loop->buflen; > > status = usb_ep_queue(ep, req, GFP_ATOMIC); > > if (status == 0) > > return; > > @@ -290,7 +290,9 @@ static void disable_loopback(struct f_loopback *loop) > > > > static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int > > len) > > { > > - return alloc_ep_req(ep, len, buflen); > > + struct f_loopback *loop = ep->driver_data; > > + > > + return alloc_ep_req(ep, len, loop->buflen); > > } > > > > static int enable_endpoint(struct usb_composite_dev *cdev, struct > > f_loopback *loop, > > @@ -317,7 +319,7 @@ static int enable_endpoint(struct usb_composite_dev > > *cdev, struct f_loopback *lo > > * we buffer at most 'qlen' transfers; fewer if any need more > > * than 'buflen' bytes each. > > */ > > - for (i = 0; i < qlen && result == 0; i++) { > > + for (i = 0; i < loop->qlen && result == 0; i++) { > > req = lb_alloc_ep_req(ep, 0); > > if (!req) > > goto fail1; > > @@ -391,10 +393,10 @@ static struct usb_function *loopback_alloc(struct > > usb_function_instance *fi) > > lb_opts->refcnt++; > > mutex_unlock(_opts->lock); > > > > - buflen = lb_opts->bulk_buflen; > > - qlen = lb_opts->qlen; > > - if (!qlen) > > - qlen = 32; > > + loop->buflen = lb_opts->bulk_buflen; > > + loop->qlen = lb_opts->qlen; > > + if (!loop->qlen) > > + loop->qlen = 32; > > > > loop->function.name = "loopback"; > > loop->function.bind = loopback_bind; > > > -- balbi signature.asc Description: PGP signature
Re: [PATCH v3 1/2] usb: gadget: loopback: fix: Don't share qlen and buflen between instances
On 09/24/2015 06:51 PM, Felipe Balbi wrote: On Thu, Sep 24, 2015 at 05:19:12PM +0200, Robert Baldyga wrote: On 09/22/2015 08:40 PM, Krzysztof Opasiak wrote: Each instance of loopback function may have different qlen and buflen attributes values. When linking function to configuration those values had been assigned to global variables. Linking other instance to config overwrites those values. This commit moves those values to f_loopback structure to avoid overwriting. Now each function has its own instance of those values. Cc:# 3.10+ Signed-off-by: Krzysztof Opasiak Reviewed-by: Robert Baldyga doesn't seem to fit stable IMO. Care to explain why you think we need to backport this to v3.10+ ? Let's consider following set of commands: cd $CFS_ROOT/usb_gadget mkdir g1 cd g1 mkdir functions/SourceSink.1 mkdir functions/SourceSink.2 echo 1024 > functions/SourceSink.1/buflen echo 512 > functions/SourceSink.2/buflen mkdir configs/c.1 ln -s functions/SourceSink.1 configs/c.1/ ln -s functions/SourceSink.2 configs/c.1/ echo $UDC > UDC You assume that after executing this script you will get two instances of SourceSink functions and one of them will alloc requests buffers which has 1024 and second one which has only 512. Unfortunately due to using global variables both of them are going to alloc only 512 bytes for each request. The same situation is with qlen. All instances are going to use attributes values from the last one in the system, even if they are in multiple gadgets. In my opinion second patch in this series is much more important as it makes loopback function working again after almost year of being only /dev/null and /dev/zero. But that one should to go only to 3.18. Best regards, -- Krzysztof Opasiak Samsung R Institute Poland Samsung Electronics -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html