Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4477643pxt; Wed, 11 Aug 2021 07:02:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJcl5L9S9vkRsq5gNRX0AWLHCjBaA9wX6ERoOO90n5pXh4KS1RDdrSmklaKwA8Z3NN1xRw X-Received: by 2002:a05:6e02:78d:: with SMTP id q13mr384269ils.262.1628690528407; Wed, 11 Aug 2021 07:02:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1628690528; cv=pass; d=google.com; s=arc-20160816; b=b3pKZdVW8upIJPvlx14EEIKcKFQPd+5LqW6VEexnBLeq4QF4QsDrHO90RuKCmiVirV 45Inv9otagd3AXlLRUBPKMqm72WMUK1RYQubazDusiXFU1KWdZOpBOHDkHq7Md4cY2mc 8CRR4TaaBryPW7gGJdDEYP5T+tsoNpnzQljOJKrGVwkjQdpkPF+v4zDQS6igcp+yMYNJ S7L2V0QP9Sm2vLH3hTBZsVS+VaVuj/ZRxF8BnSnl+j+mJziErxzpqjY6PKG0H4EZjbN2 kKaNXBLUBqPGRmqF2yEDnReIxmXaycoVrzPEcYwkwLE8DL9ByT7O9dG8zej0bkSVod9S fhTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ubSIKy+sSgzaqZS7QTljTFHq59xZvHdz22kUHhUcLOw=; b=CDs/6ZxZQa7VqHDX61Fz14j0bzyTrwuGUOpAr2lPw6TdThh9nQJ2rVJGo2TX5wNXFA cRAfNDgf3uJFS6TM4dRunAo5DgsfowwKXDhCm1dKlwV7gpqeTUNfSWogKS69CoQeaxGv PuYFAir1xcQRFjEmSrMQgLiPaqhLMdAtvMcrDd4QDHPuyrcwsI8JituMaLk+Lg8Boncu 0K5a9X2Zt1GmlmN8uJviPMKDhXCucDzthHOn4wVqmsvLzyyfo4yEJCJeCKc5hJ3a2ZfK Od5KKf00xsTmn0NXLEy2X+2cMqph+SyQZ1QadG2wnkCI4nfalvJkKwDnvtn1aFBFk6rJ SDvA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@anirudhrb.com header.s=zoho header.b=UkZlPPIi; arc=pass (i=1 spf=pass spfdomain=anirudhrb.com dkim=pass dkdomain=anirudhrb.com dmarc=pass fromdomain=anirudhrb.com>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n5si30611940ilk.136.2021.08.11.07.01.54; Wed, 11 Aug 2021 07:02:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@anirudhrb.com header.s=zoho header.b=UkZlPPIi; arc=pass (i=1 spf=pass spfdomain=anirudhrb.com dkim=pass dkdomain=anirudhrb.com dmarc=pass fromdomain=anirudhrb.com>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232137AbhHKN7i (ORCPT + 99 others); Wed, 11 Aug 2021 09:59:38 -0400 Received: from sender4-of-o53.zoho.com ([136.143.188.53]:21386 "EHLO sender4-of-o53.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232118AbhHKN7e (ORCPT ); Wed, 11 Aug 2021 09:59:34 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1628690347; cv=none; d=zohomail.com; s=zohoarc; b=WuCCI/rBZ8lWr4irii8zUWZ/ieQbpl22r1PPJcUhed74/0NYs6GyBwGAdIZhMcRFCEqH1t9Fqpj/zCUqDDpAyAhthzAkfwQpP7FiQ9YUhdFuaiPEWFzuUO7lbp2y72MtNczYsEY2TBh+IIv119sbv/f46i5fjZsvA0DVQKl03JY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628690347; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ubSIKy+sSgzaqZS7QTljTFHq59xZvHdz22kUHhUcLOw=; b=IaxZT30rB2Rk2y6sU6OTCz+96J1mdnVL3QFQo8B11pcMaYaCX0CaBODB2Va8gFlpfBx1nSKXm8/jJBCNbPoYZuCJ9Hh2OLvoZfVEvV6VCESVJInEyDG0TFYvwQE3owdtplqtGS+lQAfA8NSA2+fbTJY5X37xof4qLUcIrs5EYkg= 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=1628690347; s=zoho; d=anirudhrb.com; i=mail@anirudhrb.com; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:In-Reply-To; bh=ubSIKy+sSgzaqZS7QTljTFHq59xZvHdz22kUHhUcLOw=; b=UkZlPPIiSLNX9ZNTu2Ec+isPz4t+sIg8xlYMHLpbAySl1P6iBIc0JNTLOi6vvcwP lFgOY3GQS16mWlmwuIFf5R/Jp7GqpYNjpvxKPSr5D0Ck5/SRbGVVLhmJrGHAMPml0pG Q4/KvDk8BSjs3KqolW3YhLzi9jaSM0yAsE8Bh5Ts= Received: from anirudhrb.com (106.51.105.246 [106.51.105.246]) by mx.zohomail.com with SMTPS id 1628690342411673.202954929236; Wed, 11 Aug 2021 06:59:02 -0700 (PDT) Date: Wed, 11 Aug 2021 19:28:55 +0530 From: Anirudh Rayabharam To: Shuah Khan Cc: Valentina Manea , Shuah Khan , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-usb@vger.kernel.org, mail@anirudhrb.com Subject: Re: [PATCH v2] usbip: give back URBs for unsent unlink requests during cleanup Message-ID: References: <20210806181335.2078-1-mail@anirudhrb.com> <4aaf420d-e85e-212e-3bc4-a70e016de610@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4aaf420d-e85e-212e-3bc4-a70e016de610@linuxfoundation.org> X-ZohoMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 10, 2021 at 05:25:51PM -0600, Shuah Khan wrote: > On 8/6/21 12:13 PM, Anirudh Rayabharam wrote: > > 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. Since the code is almost the > > same, extract it into a new function and call it for both unlink_rx and > > unlink_tx lists. > > > > Let's not do the refactor - let's first fix the problem and then the refactor. Sure, I will make it a two patch series where the first one fixes the problem and the second one does the refactor. > > > [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 > > --- > > > > Changes in v2: > > Use WARN_ON() instead of BUG() when unlink_list is neither unlink_tx nor > > unlink_rx. > > > > v1: https://lore.kernel.org/lkml/20210806164015.25263-1-mail@anirudhrb.com/ > > > > --- > > drivers/usb/usbip/vhci_hcd.c | 45 +++++++++++++++++++++++++----------- > > 1 file changed, 32 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c > > index 4ba6bcdaa8e9..67e638f4c455 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); > > @@ -953,23 +954,23 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev) > > struct vhci_unlink *unlink, *tmp; > > unsigned long flags; > > + if (WARN(unlink_list != &vdev->unlink_tx > > + && unlink_list != &vdev->unlink_rx, > > + "Invalid list passed to __vhci_cleanup_unlink_list\n")) > > + return; > > + > > With this change, this will be only place unlink_rx is used without > vdev->priv_lock hold? Please explain why this is safe. Well, this doesn't read or modify the contents of unlink_rx and unlink_tx. So, it looks safe to me. Let me know if I'm missing something here. > > > spin_lock_irqsave(&vhci->lock, flags); > > spin_lock(&vdev->priv_lock); > > - list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { > > - pr_info("unlink cleanup tx %lu\n", unlink->unlink_seqnum); > > - list_del(&unlink->list); > > - kfree(unlink); > > - } > > - > > - while (!list_empty(&vdev->unlink_rx)) { > > + list_for_each_entry_safe(unlink, tmp, unlink_list, list) { > > 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) { > > @@ -1001,6 +1002,24 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev) > > spin_unlock_irqrestore(&vhci->lock, flags); > > } > > +static inline void vhci_cleanup_unlink_tx(struct vhci_device *vdev) > > +{ > > + __vhci_cleanup_unlink_list(vdev, &vdev->unlink_tx); > > With this change, this will be only place unlink_rx is used without > vdev->priv_lock hold? Please explain why this is safe. > > > +} > > + > > Is there a need for this layer? > > > +static inline void vhci_cleanup_unlink_rx(struct vhci_device *vdev) > > +{ > > + __vhci_cleanup_unlink_list(vdev, &vdev->unlink_rx); > > With this change, this will be only place unlink_rx is used without > vdev->priv_lock hold? Please explain why this is safe. > > > +} > > + > Is there a need for this layer? I added these wrappers purely for convenience. There is no other purpose. Would you prefer this patch without the wrappers? Thanks for the review! - Anirudh.