Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp648608pxj; Tue, 18 May 2021 11:00:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyomxXje2kDUmRMC2qyNCHwYVOjmAkVtL++yAArIyq/NkJDAJ3xxDU3O3msYFMCwyAReY+D X-Received: by 2002:a05:6e02:13d3:: with SMTP id v19mr5683652ilj.168.1621360836926; Tue, 18 May 2021 11:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621360836; cv=none; d=google.com; s=arc-20160816; b=KjH7u8nN65S46L0lQzHUY3caosmNSqOymKgANv1JmJXsN5VFYn/fWBPvbYveLXQ+0D +swozf9xnoh4dS/BEGMQyMvkG4y1Q5FB/dJ2glkVgDuWwp4jxnr/3QSSckrTyMTiJ1F6 HKBDJ/ikOzbQmz/4+dVkOyXJof9FCEGBKhfDPzwMp9Dgbw497zPxuViF24MbWdZD1Q5Q mWq7MRdnoW1001zOSbrUaZfhE+GWM7NJHPF5asCRimfEjo7ZrqCGCtKSggk/p6HOgLMH iXBK3cuidVoyEbrXk5uDhjt/NSNvDXdSorL2Jq5UdO4gUreUxrx6yB84IeszvqHi5z9p F8vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6ndncZQOylEWIhdV1XdT9fP9NlogXYPwcijUC09fu74=; b=wM3VN+ei7aAQ/69k0Ia9cbAq/WXcxr/VCiyB25ntzA2FcM4++Lz3OM9as/dSAx9dF0 xVzJtKftUV303IICXC+oNMb6o7MR0CB0IBoxM/V3I0ZeOBvsNROadpKAL3BdXp0cXwFh BGL+T0I1+ZMn9iYyQOwJ2sqLU+PhOs5Oty1kc5Yv64J7+wy1y8Ja2ppMCiBqjJemw1nk Af6q/7mAFHxZFqO7+36gLwy4b4DC7eOIy6XVmQYOx4k/ouGd1zMGL7y/ilQK+IMjLxDg nEyASfA4uqXRdiabdMMablE3NfYcnUdZ9LqTew1AFVt4jOlPFr0DrvOWejrI9Ocmc2WX zm+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QrgBI18d; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si21568197iol.93.2021.05.18.11.00.03; Tue, 18 May 2021 11:00:36 -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=@linuxfoundation.org header.s=korg header.b=QrgBI18d; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346894AbhEQQKT (ORCPT + 99 others); Mon, 17 May 2021 12:10:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:36456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245623AbhEQPqg (ORCPT ); Mon, 17 May 2021 11:46:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CDE3761D38; Mon, 17 May 2021 14:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262670; bh=w1dN5sX4ZZCG3Slp7G3V4sFe3WQRgF+QCwDfjW+QruQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QrgBI18dSlykgiXb19aqIw0zW+dUJ4uaBzucBiD6lVd6Pdon3DVFdCH7ZjhzZPevD QREo7X5uk1yDYd4V4g5iBPTTCSLcQERWtyKWZG4Sq90Hx5n1eRlhDT9pskUjZjyBAw E07FV7GqMZZWze4icuH+WbaSBSzW8hw7KfbgZqkY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Neukum Subject: [PATCH 5.10 254/289] cdc-wdm: untangle a circular dependency between callback and softint Date: Mon, 17 May 2021 16:02:59 +0200 Message-Id: <20210517140313.694965267@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver Neukum commit 18abf874367456540846319574864e6ff32752e2 upstream. We have a cycle of callbacks scheduling works which submit URBs with those callbacks. This needs to be blocked, stopped and unblocked to untangle the circle. Signed-off-by: Oliver Neukum Link: https://lore.kernel.org/r/20210426092622.20433-1-oneukum@suse.com Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/cdc-wdm.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -321,12 +321,23 @@ exit: } -static void kill_urbs(struct wdm_device *desc) +static void poison_urbs(struct wdm_device *desc) { /* the order here is essential */ - usb_kill_urb(desc->command); - usb_kill_urb(desc->validity); - usb_kill_urb(desc->response); + usb_poison_urb(desc->command); + usb_poison_urb(desc->validity); + usb_poison_urb(desc->response); +} + +static void unpoison_urbs(struct wdm_device *desc) +{ + /* + * the order here is not essential + * it is symmetrical just to be nice + */ + usb_unpoison_urb(desc->response); + usb_unpoison_urb(desc->validity); + usb_unpoison_urb(desc->command); } static void free_urbs(struct wdm_device *desc) @@ -741,11 +752,12 @@ static int wdm_release(struct inode *ino if (!desc->count) { if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { dev_dbg(&desc->intf->dev, "wdm_release: cleanup\n"); - kill_urbs(desc); + poison_urbs(desc); spin_lock_irq(&desc->iuspin); desc->resp_count = 0; spin_unlock_irq(&desc->iuspin); desc->manage_power(desc->intf, 0); + unpoison_urbs(desc); } else { /* must avoid dev_printk here as desc->intf is invalid */ pr_debug(KBUILD_MODNAME " %s: device gone - cleaning up\n", __func__); @@ -1037,9 +1049,9 @@ static void wdm_disconnect(struct usb_in wake_up_all(&desc->wait); mutex_lock(&desc->rlock); mutex_lock(&desc->wlock); + poison_urbs(desc); cancel_work_sync(&desc->rxwork); cancel_work_sync(&desc->service_outs_intr); - kill_urbs(desc); mutex_unlock(&desc->wlock); mutex_unlock(&desc->rlock); @@ -1080,9 +1092,10 @@ static int wdm_suspend(struct usb_interf set_bit(WDM_SUSPENDING, &desc->flags); spin_unlock_irq(&desc->iuspin); /* callback submits work - order is essential */ - kill_urbs(desc); + poison_urbs(desc); cancel_work_sync(&desc->rxwork); cancel_work_sync(&desc->service_outs_intr); + unpoison_urbs(desc); } if (!PMSG_IS_AUTO(message)) { mutex_unlock(&desc->wlock); @@ -1140,7 +1153,7 @@ static int wdm_pre_reset(struct usb_inte wake_up_all(&desc->wait); mutex_lock(&desc->rlock); mutex_lock(&desc->wlock); - kill_urbs(desc); + poison_urbs(desc); cancel_work_sync(&desc->rxwork); cancel_work_sync(&desc->service_outs_intr); return 0; @@ -1151,6 +1164,7 @@ static int wdm_post_reset(struct usb_int struct wdm_device *desc = wdm_find_device(intf); int rv; + unpoison_urbs(desc); clear_bit(WDM_OVERFLOW, &desc->flags); clear_bit(WDM_RESETTING, &desc->flags); rv = recover_from_urb_loss(desc);