[PATCH v2 0/3] Usb gadget ncm code cleanup
This patchset consists of some code cleanup in usb gadget ncm code. Note: Testing has only been done on an ARM i.MX6 based platform. --- Change from v1 to v2 Subject line changed on Patch 2. Torsten Polle (3): usb: gadget: NCM: link socket buffers to the device for tx packets usb: gadget: u_ether: link socket buffers to the device for received packets usb: gadget: NCM: differentiate consumed packets from dropped packets drivers/usb/gadget/function/f_ncm.c | 11 +++ drivers/usb/gadget/function/u_ether.c |5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) -- 1.7.9.5 -- 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
[PATCH v2 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets
From: Torsten Polle <tpo...@de.adit-jv.com> dev_kfree_skb_any() is used to free packets that are dropped by the network stack. Therefore the function should not be used for packets that have been successfully processed by the network stack. Instead dev_consume_skb_any() has to be used for such consumed packets. This separation helps to identify dropped packets. Signed-off-by: Torsten Polle <tpo...@de.adit-jv.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/f_ncm.c |8 drivers/usb/gadget/function/u_ether.c |3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index b6771ad..e8008fa 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -998,7 +998,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm) /* Merge the skbs */ swap(skb2, ncm->skb_tx_data); if (ncm->skb_tx_data) { - dev_kfree_skb_any(ncm->skb_tx_data); + dev_consume_skb_any(ncm->skb_tx_data); ncm->skb_tx_data = NULL; } @@ -1009,7 +1009,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm) /* Copy NTB across. */ ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len); memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); - dev_kfree_skb_any(ncm->skb_tx_ndp); + dev_consume_skb_any(ncm->skb_tx_ndp); ncm->skb_tx_ndp = NULL; /* Insert zero'd datagram. */ @@ -1136,7 +1136,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, memset(ntb_data, 0, dgram_pad); ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len); memcpy(ntb_data, skb->data, skb->len); - dev_kfree_skb_any(skb); + dev_consume_skb_any(skb); skb = NULL; } else if (ncm->skb_tx_data && ncm->timer_force_tx) { @@ -1332,7 +1332,7 @@ static int ncm_unwrap_ntb(struct gether *port, } while (ndp_len > 2 * (opts->dgram_item_len * 2)); } while (ndp_index); - dev_kfree_skb_any(skb); + dev_consume_skb_any(skb); VDBG(port->func.config->cdev, "Parsed NTB with %d frames\n", dgram_counter); diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index d8593c7..8a6be06 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -455,16 +455,17 @@ static void tx_complete(struct usb_ep *ep, struct usb_request *req) /* FALLTHROUGH */ case -ECONNRESET: /* unlink */ case -ESHUTDOWN:/* disconnect etc */ + dev_kfree_skb_any(skb); break; case 0: dev->net->stats.tx_bytes += skb->len; + dev_consume_skb_any(skb); } dev->net->stats.tx_packets++; spin_lock(>req_lock); list_add(>list, >tx_reqs); spin_unlock(>req_lock); - dev_kfree_skb_any(skb); atomic_dec(>tx_qlen); if (netif_carrier_ok(dev->net)) -- 1.7.9.5 -- 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
[PATCH v2 2/3] usb: gadget: u_ether: link socket buffers to the device for received packets
From: Torsten Polle <tpo...@de.adit-jv.com> Socket buffers should be linked to the (network) device that allocated the buffers. __netdev_alloc_skb performs this task. Signed-off-by: Torsten Polle <tpo...@de.adit-jv.com> Signed-off-by: Jim Baxter <jim_bax...@mentor.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- Change from v1 to v2 Subject line changed drivers/usb/gadget/function/u_ether.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 8cb0803..d8593c7 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -224,7 +224,7 @@ static void defer_kevent(struct eth_dev *dev, int flag) if (dev->port_usb->is_fixed) size = max_t(size_t, size, dev->port_usb->fixed_out_len); - skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); + skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags); if (skb == NULL) { DBG(dev, "no rx skb\n"); goto enomem; -- 1.7.9.5 -- 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
[PATCH v2 1/3] usb: gadget: NCM: link socket buffers to the device for tx packets
From: Torsten Polle <tpo...@de.adit-jv.com> Socket buffers should be linked to the (network) device that allocated the buffers. Signed-off-by: Torsten Polle <tpo...@de.adit-jv.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/f_ncm.c |3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 6396037..b6771ad 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1078,6 +1078,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, if (!ncm->skb_tx_data) goto err; + ncm->skb_tx_data->dev = ncm->netdev; ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len); memset(ntb_data, 0, ncb_len); /* dwSignature */ @@ -1096,6 +1097,8 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, GFP_ATOMIC); if (!ncm->skb_tx_ndp) goto err; + + ncm->skb_tx_ndp->dev = ncm->netdev; ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, opts->ndp_size); memset(ntb_ndp, 0, ncb_len); -- 1.7.9.5 -- 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: Gadget regression with u_ether in Linux next
> On Saturday 17 September 2016 12:03 AM, Tony Lindgren wrote: > Hi, > > Looks like commit c9ffc78745f8 ("usb: gadget: NCM: Protect dev->port_usb > using dev->lock") causes hangs for me with Linux next. > > Reverting c9ffc78745f8 makes the issues go away, some more info below. > > Regards, > > Tony Sorry. There was a mistake with the commit. spinlock not acquired in if (dev->wrap) condition was also being tried to get unlocked. Please revert/remove the commit. Thanks, Harish -- 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 v1 2/3] usb: gadget: NCM: link socket buffers to the device for received packets
>>>>> On Thursday 15 September 2016 08:35 PM, Yauheni Kaliuta wrote: >Is subject a bit misleading, it's more generic, then NCM? Agreed. I will submit v2 patchset. WBR, Harish Jenny K N -- 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
[PATCH v1 2/3] usb: gadget: NCM: link socket buffers to the device for received packets
From: Torsten Polle <tpo...@de.adit-jv.com> Socket buffers should be linked to the (network) device that allocated the buffers. __netdev_alloc_skb performs this task. Signed-off-by: Torsten Polle <tpo...@de.adit-jv.com> Signed-off-by: Jim Baxter <jim_bax...@mentor.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/u_ether.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 8cb0803..d8593c7 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -224,7 +224,7 @@ static void defer_kevent(struct eth_dev *dev, int flag) if (dev->port_usb->is_fixed) size = max_t(size_t, size, dev->port_usb->fixed_out_len); - skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); + skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags); if (skb == NULL) { DBG(dev, "no rx skb\n"); goto enomem; -- 1.7.9.5 -- 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
[PATCH v1 3/3] usb: gadget: NCM: differentiate consumed packets from dropped packets
From: Torsten Polle <tpo...@de.adit-jv.com> dev_kfree_skb_any() is used to free packets that are dropped by the network stack. Therefore the function should not be used for packets that have been successfully processed by the network stack. Instead dev_consume_skb_any() has to be used for such consumed packets. This separation helps to identify dropped packets. Signed-off-by: Torsten Polle <tpo...@de.adit-jv.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/f_ncm.c |8 drivers/usb/gadget/function/u_ether.c |3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index b6771ad..e8008fa 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -998,7 +998,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm) /* Merge the skbs */ swap(skb2, ncm->skb_tx_data); if (ncm->skb_tx_data) { - dev_kfree_skb_any(ncm->skb_tx_data); + dev_consume_skb_any(ncm->skb_tx_data); ncm->skb_tx_data = NULL; } @@ -1009,7 +1009,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm) /* Copy NTB across. */ ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len); memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len); - dev_kfree_skb_any(ncm->skb_tx_ndp); + dev_consume_skb_any(ncm->skb_tx_ndp); ncm->skb_tx_ndp = NULL; /* Insert zero'd datagram. */ @@ -1136,7 +1136,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, memset(ntb_data, 0, dgram_pad); ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len); memcpy(ntb_data, skb->data, skb->len); - dev_kfree_skb_any(skb); + dev_consume_skb_any(skb); skb = NULL; } else if (ncm->skb_tx_data && ncm->timer_force_tx) { @@ -1332,7 +1332,7 @@ static int ncm_unwrap_ntb(struct gether *port, } while (ndp_len > 2 * (opts->dgram_item_len * 2)); } while (ndp_index); - dev_kfree_skb_any(skb); + dev_consume_skb_any(skb); VDBG(port->func.config->cdev, "Parsed NTB with %d frames\n", dgram_counter); diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index d8593c7..8a6be06 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -455,16 +455,17 @@ static void tx_complete(struct usb_ep *ep, struct usb_request *req) /* FALLTHROUGH */ case -ECONNRESET: /* unlink */ case -ESHUTDOWN:/* disconnect etc */ + dev_kfree_skb_any(skb); break; case 0: dev->net->stats.tx_bytes += skb->len; + dev_consume_skb_any(skb); } dev->net->stats.tx_packets++; spin_lock(>req_lock); list_add(>list, >tx_reqs); spin_unlock(>req_lock); - dev_kfree_skb_any(skb); atomic_dec(>tx_qlen); if (netif_carrier_ok(dev->net)) -- 1.7.9.5 -- 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
[PATCH v1 1/3] usb: gadget: NCM: link socket buffers to the device for tx packets
From: Torsten Polle <tpo...@de.adit-jv.com> Socket buffers should be linked to the (network) device that allocated the buffers. Signed-off-by: Torsten Polle <tpo...@de.adit-jv.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/f_ncm.c |3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 6396037..b6771ad 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1078,6 +1078,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, if (!ncm->skb_tx_data) goto err; + ncm->skb_tx_data->dev = ncm->netdev; ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len); memset(ntb_data, 0, ncb_len); /* dwSignature */ @@ -1096,6 +1097,8 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, GFP_ATOMIC); if (!ncm->skb_tx_ndp) goto err; + + ncm->skb_tx_ndp->dev = ncm->netdev; ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, opts->ndp_size); memset(ntb_ndp, 0, ncb_len); -- 1.7.9.5 -- 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
[PATCH v1 0/3] Usb gadget ncm code cleanup
This patchset consists of some code cleanup in usb gadget ncm code. Note: Testing has only been done on an ARM i.MX6 based platform. Torsten Polle (3): usb: gadget: NCM: link socket buffers to the device for tx packets usb: gadget: NCM: link socket buffers to the device for received packets usb: gadget: NCM: differentiate consumed packets from dropped packets drivers/usb/gadget/function/f_ncm.c | 11 +++ drivers/usb/gadget/function/u_ether.c |5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) -- 1.7.9.5 -- 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
[PATCH v1 2/2] usb: gadget: NCM: Protect dev->port_usb using dev->lock
This commit incorporates findings from https://lkml.org/lkml/2016/4/25/594 The function has been modified to make sure we hold the dev lock when accessing the net device pointer. Acked-by: Jim Baxter <jim_bax...@mentor.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/u_ether.c |7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 9c8c9ed..8cb0803 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -553,14 +553,16 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, spin_lock_irqsave(>lock, flags); if (dev->port_usb) skb = dev->wrap(dev->port_usb, skb); - spin_unlock_irqrestore(>lock, flags); if (!skb) { /* Multi frame CDC protocols may store the frame for * later which is not a dropped frame. */ if (dev->port_usb && - dev->port_usb->supports_multi_frame) + dev->port_usb->supports_multi_frame) { + spin_unlock_irqrestore(>lock, flags); goto multiframe; + } + spin_unlock_irqrestore(>lock, flags); goto drop; } } @@ -578,6 +580,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, req->zero = 0; else req->zero = 1; + spin_unlock_irqrestore(>lock, flags); /* use zlp framing on tx for strict CDC-Ether conformance, * though any robust network rx path ignores extra padding. -- 1.7.9.5 -- 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
[PATCH v1 0/2] usb: gadget: NCM: NULL pointer dereference in eth_start_xmit
This patchset incorporates findings from https://lkml.org/lkml/2016/4/25/690 When submitting patch https://lkml.org/lkml/2016/4/25/594, few observations from Alan from https://lkml.org/lkml/2016/4/25/690 needed to be incorporated. We find that the changes are already taken to linux-next repo by another commit 88c09eacf560c3303d0ee8cf91b8b7ff7f000350. Hence this patchset only adds the remaining findings. Harish Jenny K N (2): usb: gadget: u_ether: fix another dereference after null check usb: gadget: NCM: Protect dev->port_usb using dev->lock drivers/usb/gadget/function/u_ether.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 1.7.9.5 -- 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
[PATCH v1 1/2] usb: gadget: u_ether: fix another dereference after null check
dev->port_usb is checked for null pointer previously, so dev->port_usb might be null during no zlp check, fix it by adding null pointer check. Acked-by: Jim Baxter <jim_bax...@mentor.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/u_ether.c |3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 3be4b93..9c8c9ed 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -571,7 +571,8 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, req->complete = tx_complete; /* NCM requires no zlp if transfer is dwNtbInMaxSize */ - if (dev->port_usb->is_fixed && + if (dev->port_usb && + dev->port_usb->is_fixed && length == dev->port_usb->fixed_in_len && (length % in->maxpacket) == 0) req->zero = 0; -- 1.7.9.5 -- 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
[PATCH v1 0/1] usb: gadget: f_fs: Stop ffs_closed NULL pointers
This patchset fixes the crash in ffs_closed during a disconnect of a USB composite FFS session. The issue was caused by the use of an outdated pointer in ffs_closed which had been deleted and not Nulled. Note: Testing has only been done on an ARM i.MX6 based platform. Jim Baxter (1): usb: gadget: f_fs: Stop ffs_closed NULL pointers. drivers/usb/gadget/function/f_fs.c |5 + 1 file changed, 5 insertions(+) -- 1.7.9.5 -- 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
[PATCH v1 1/1] usb: gadget: f_fs: Stop ffs_closed NULL pointers.
From: Jim Baxter <jim_bax...@mentor.com> The struct ffs_data::private_data has a pointer to ffs_dev stored in it during the ffs_fs_mount() function however it is not cleared when the ffs_dev is freed later which causes the ffs_closed function to crash with "Unable to handle kernel NULL pointer dereference" error when using the data in ffs_data::private_data. This clears this pointer during the ffs_free_dev clean up function. Signed-off-by: Jim Baxter <jim_bax...@mentor.com> Signed-off-by: Jiada Wang <jiada_w...@mentor.com> Signed-off-by: Harish Jenny K N <harish_kand...@mentor.com> --- drivers/usb/gadget/function/f_fs.c |5 + 1 file changed, 5 insertions(+) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 5c8429f..b309650 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3470,6 +3470,11 @@ static void _ffs_free_dev(struct ffs_dev *dev) list_del(>entry); if (dev->name_allocated) kfree(dev->name); + + /* Clear the private_data pointer to stop incorrect dev access */ + if (dev->ffs_data) + dev->ffs_data->private_data = NULL; + kfree(dev); if (list_empty(_devices)) functionfs_cleanup(); -- 1.7.9.5 -- 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