From patchwork Fri Aug 13 18:25:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anirudh Rayabharam X-Patchwork-Id: 12436005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C45E7C4320A for ; Fri, 13 Aug 2021 18:26:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 884C160EE5 for ; Fri, 13 Aug 2021 18:26:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233222AbhHMS0f (ORCPT ); Fri, 13 Aug 2021 14:26:35 -0400 Received: from sender4-of-o53.zoho.com ([136.143.188.53]:21389 "EHLO sender4-of-o53.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233041AbhHMS0e (ORCPT ); Fri, 13 Aug 2021 14:26:34 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1628879164; cv=none; d=zohomail.com; s=zohoarc; b=VtledMqoj4buK1l6XqV9NZhWH8bpS6vX6CinaxKBwtphmi7DzvQjKFvPWZEvmboTfa+N8nPxpJnZkzZkYhJHWdiZWtuCZW3aYiiMRU1Gd6hWSeXh8LmqUqmWUbLMiDotAu2T+T45CMo2aqSpFX6/KHRpnaKKY6KEDC7DJVE3kJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628879164; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=b2I2aydOcN7RGQlpbBtHwZwGygVFKfRrP8IbdWl2eSI=; b=fc/MLx5Ath7BdGAM6yOrkbrNJehYGNxkofKJ808fpLqNETdmT6PZxynZx8qJFshhEY/uhFlNuI4sFFzgKDcHcmCFsvvq8UTXI3r/eWncjsVW+cfsoUCM7uh8HwNZUSneEvodZP2AX1O104iyGnEWVGT+psSNOTscR8b+dpOvOqE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anirudhrb.com; spf=pass smtp.mailfrom=mail@anirudhrb.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1628879164; s=zoho; d=anirudhrb.com; i=mail@anirudhrb.com; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=b2I2aydOcN7RGQlpbBtHwZwGygVFKfRrP8IbdWl2eSI=; b=guLIaS4cPL3vl+m/qKiUyZO3EWdIlgK3j67X/CpLAJe1Vb72EkHd6Dj/KiuHC6Un xDyFaRuT2fVNS6jOKFdraq9p5XdeEOUJGqFkI7kqLQaacariFqU4xG4gPtC5ou4v7LO SMYSr4ze76NGiIIVRu2pYDTf0MwfgnqxLy30VUHg= Received: from localhost.localdomain (49.207.58.140 [49.207.58.140]) by mx.zohomail.com with SMTPS id 1628879163555621.7556704124663; Fri, 13 Aug 2021 11:26:03 -0700 (PDT) From: Anirudh Rayabharam To: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org Cc: Anirudh Rayabharam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, syzbot+74d6ef051d3d2eacf428@syzkaller.appspotmail.com Subject: [PATCH v3 1/2] usbip: give back URBs for unsent unlink requests during cleanup Date: Fri, 13 Aug 2021 23:55:07 +0530 Message-Id: <20210813182508.28127-2-mail@anirudhrb.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210813182508.28127-1-mail@anirudhrb.com> References: <20210813182508.28127-1-mail@anirudhrb.com> MIME-Version: 1.0 X-ZohoMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In vhci_device_unlink_cleanup(), the URBs for unsent unlink requests are not given back. This sometimes causes usb_kill_urb to wait indefinitely for that urb to be given back. syzbot has reported a hung task issue [1] for this. To fix this, give back the urbs corresponding to unsent unlink requests (unlink_tx list) similar to how urbs corresponding to unanswered unlink requests (unlink_rx list) are given back. [1]: https://syzkaller.appspot.com/bug?id=08f12df95ae7da69814e64eb5515d5a85ed06b76 Reported-by: syzbot+74d6ef051d3d2eacf428@syzkaller.appspotmail.com Tested-by: syzbot+74d6ef051d3d2eacf428@syzkaller.appspotmail.com Signed-off-by: Anirudh Rayabharam --- drivers/usb/usbip/vhci_hcd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 4ba6bcdaa8e9..6f3f374d4bbc 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -957,8 +957,34 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev) spin_lock(&vdev->priv_lock); list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { + struct urb *urb; + + /* give back URB of unsent unlink request */ pr_info("unlink cleanup tx %lu\n", unlink->unlink_seqnum); + + urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum); + if (!urb) { + pr_info("the urb (seqnum %lu) was already given back\n", + unlink->unlink_seqnum); + list_del(&unlink->list); + kfree(unlink); + continue; + } + + urb->status = -ENODEV; + + usb_hcd_unlink_urb_from_ep(hcd, urb); + list_del(&unlink->list); + + spin_unlock(&vdev->priv_lock); + spin_unlock_irqrestore(&vhci->lock, flags); + + usb_hcd_giveback_urb(hcd, urb, urb->status); + + spin_lock_irqsave(&vhci->lock, flags); + spin_lock(&vdev->priv_lock); + kfree(unlink); } From patchwork Fri Aug 13 18:25:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anirudh Rayabharam X-Patchwork-Id: 12436007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EAC4C4338F for ; Fri, 13 Aug 2021 18:26:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83DB9610CF for ; Fri, 13 Aug 2021 18:26:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233041AbhHMS0y (ORCPT ); Fri, 13 Aug 2021 14:26:54 -0400 Received: from sender4-of-o53.zoho.com ([136.143.188.53]:21395 "EHLO sender4-of-o53.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233276AbhHMS0m (ORCPT ); Fri, 13 Aug 2021 14:26:42 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1628879172; cv=none; d=zohomail.com; s=zohoarc; b=U6IBDmJ5WLEkTyWX8Cwz67YvkIgzhQkYtyObb9so/FhTiwe5a/JL28dvOYQlaO0a+Qrerpv+a7Qiy2Ygxu2xI2otwyQdpFvGr0ObBK1urn2RD88LeGEdMdgLaU6hgR+1yb2NwtFOEVmy7Qc1pP9r+E3c973L5/OiU6VY0DZdxVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628879172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=VT9prQakObj76qkfJx3PmUtiBqU9r7m5dMmTl99Pvzk=; b=LXG6x8dq+6B2uktz0UEVXDAZoSfZpVT6LxyPLCvL8Nx9mD4vsMpNkGpWlDsBEVy1f5TwjJYmVx5zsxKa7dOwhEwvRzP3ypSsEzF5lTiL3HwoT7oUMG7nZ8m6R/PHw54vwwwSgaAvbiUb97HZf3MeJfi/RQxJylj6haqeNxa+AjA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anirudhrb.com; spf=pass smtp.mailfrom=mail@anirudhrb.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1628879172; s=zoho; d=anirudhrb.com; i=mail@anirudhrb.com; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=VT9prQakObj76qkfJx3PmUtiBqU9r7m5dMmTl99Pvzk=; b=nvVhmZ+GdWG9ee6GBX51mJsdCYfDSgVdR/EiuwCqImJILqbbEE/pET3tQ3RjV/0m C9EgdqMaPYr8gkp41Pbk26qVGsgLx5IeyYGEGA88r/IPgTpBb/RUYYpC2qDnYXztaAA d2tNEZmI1nTx+WCD/JIAE+BOjqAg0s/r7JAzd//c= Received: from localhost.localdomain (49.207.58.140 [49.207.58.140]) by mx.zohomail.com with SMTPS id 1628879170666216.37574659773452; Fri, 13 Aug 2021 11:26:10 -0700 (PDT) From: Anirudh Rayabharam To: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org Cc: Anirudh Rayabharam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH v3 2/2] usbip: eliminate duplicate code in vhci_device_unlink_cleanup Date: Fri, 13 Aug 2021 23:55:08 +0530 Message-Id: <20210813182508.28127-3-mail@anirudhrb.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210813182508.28127-1-mail@anirudhrb.com> References: <20210813182508.28127-1-mail@anirudhrb.com> MIME-Version: 1.0 X-ZohoMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The cleanup code for unlink_tx and unlink_rx lists is almost the same. So, extract it into a new function and call it for both unlink_rx and unlink_tx. Signed-off-by: Anirudh Rayabharam --- drivers/usb/usbip/vhci_hcd.c | 57 ++++++++++++------------------------ 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 6f3f374d4bbc..b142508b46ce 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -945,7 +945,8 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) return 0; } -static void vhci_device_unlink_cleanup(struct vhci_device *vdev) +static void vhci_cleanup_unlink_list(struct vhci_device *vdev, + struct list_head *unlink_list) { struct vhci_hcd *vhci_hcd = vdev_to_vhci_hcd(vdev); struct usb_hcd *hcd = vhci_hcd_to_hcd(vhci_hcd); @@ -956,46 +957,15 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev) spin_lock_irqsave(&vhci->lock, flags); spin_lock(&vdev->priv_lock); - list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { + list_for_each_entry_safe(unlink, tmp, unlink_list, list) { struct urb *urb; - /* give back urb of unsent unlink request */ - pr_info("unlink cleanup tx %lu\n", unlink->unlink_seqnum); - - urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum); - if (!urb) { - pr_info("the urb (seqnum %lu) was already given back\n", - unlink->unlink_seqnum); - list_del(&unlink->list); - kfree(unlink); - continue; - } - - urb->status = -ENODEV; - - usb_hcd_unlink_urb_from_ep(hcd, urb); - - list_del(&unlink->list); - - spin_unlock(&vdev->priv_lock); - spin_unlock_irqrestore(&vhci->lock, flags); - - usb_hcd_giveback_urb(hcd, urb, urb->status); - - spin_lock_irqsave(&vhci->lock, flags); - spin_lock(&vdev->priv_lock); - - kfree(unlink); - } - - while (!list_empty(&vdev->unlink_rx)) { - struct urb *urb; - - unlink = list_first_entry(&vdev->unlink_rx, struct vhci_unlink, - list); - - /* give back URB of unanswered unlink request */ - pr_info("unlink cleanup rx %lu\n", unlink->unlink_seqnum); + if (unlink_list == &vdev->unlink_tx) + pr_info("unlink cleanup tx %lu\n", + unlink->unlink_seqnum); + else + pr_info("unlink_cleanup rx %lu\n", + unlink->unlink_seqnum); urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum); if (!urb) { @@ -1027,6 +997,15 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev) spin_unlock_irqrestore(&vhci->lock, flags); } +static void vhci_device_unlink_cleanup(struct vhci_device *vdev) +{ + /* give back URB of unsent unlink request */ + vhci_cleanup_unlink_list(vdev, &vdev->unlink_tx); + + /* give back URB of unanswered unlink request */ + vhci_cleanup_unlink_list(vdev, &vdev->unlink_rx); +} + /* * The important thing is that only one context begins cleanup. * This is why error handling and cleanup become simple.