Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp383883pxj; Thu, 20 May 2021 11:32:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7FamZe5V573bW91WAB3irmLWcwAc/JnTFAzdbFAGC7PCNAR5bSV0CUw7F2PDfDyLUqc6u X-Received: by 2002:a17:906:b2c1:: with SMTP id cf1mr5901637ejb.544.1621535538741; Thu, 20 May 2021 11:32:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535538; cv=none; d=google.com; s=arc-20160816; b=N6H0gqaCwILF9pdc0ccDdnmDz2Rqfjc5GMz0xAFTthQ3j4EG0btdMzf0ZlQ2vrMvUb x8LNvBuYBmDlvzmMAVYWbNX8pNNF5kNMMfnbDBIR6Sj0MLUCDFXwMPR2gJc/2ptsvD9P wRrMwrGLD9APPFcStKnTN4j2UvvpBTqdeqWtMoYY0ztUETC3/IRIwWbre160Zb/ahwIn 0u9jIJdDBPFH1dWRylOWaWaxanYouxGwoH6CCyMWAv9Jdib+wVypvtFpSXcc6kdfjMRY McKnqIxd0MNTgQlqefH0jq1palK3bgM6urUVu1MsNz9pX5iLI9J+haG/HB5UuKWWR/J6 B6eQ== 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=kUb6ZNYGt8FSpgxaureyR6fvlC36B+tvZDPJ0DBvKs4=; b=XcpSil6W7Xb0HgexhmN/E9/KIyusnjXk/6ePYpZCm8+07UDIaJRSVFqDlAmIMAcJ9F n8RUi680SHxjFVzr0inHpvfQFIsMF4/hrU5amHP+4JvI2WcaIwY+0DJxZp8uC/PrZBhZ 4y0x/eYZ0GgHmR8ek01KHh6ZoObNMcVZguaYbb7u1iYunScbvH65rfdtTzQK6zeWYkDz ViB1TZvNaWqSRSBMU82mBtWu47B+VMZAXO4UlWdwsDXPN7hejoKU3rF5gTVDDf8UgaEH 5k9zSUI+pbWSvEymZ42lxv3G67scbDtr1oqux6SyjBrzhCZVJrvwnws170JkxQVAdI83 hYHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PmtYeXpn; 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 b8si3129390edd.8.2021.05.20.11.31.54; Thu, 20 May 2021 11:32:18 -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=PmtYeXpn; 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 S235391AbhETKVa (ORCPT + 99 others); Thu, 20 May 2021 06:21:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:42276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235339AbhETKKx (ORCPT ); Thu, 20 May 2021 06:10:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9895761962; Thu, 20 May 2021 09:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503796; bh=o2ClhNsihdFHp/MeCscPR0OLjzqGCZLrRloaQQd2m6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PmtYeXpnN4WQKT1hOOjB7Yj7kjCa4kQ54rWDQvqlMvvDAUltxpocESNjauQWRaPAC 6e7eBDihLdxusQ/R8xhZCqHS7nlzBQrWirlhMribJph9SRpR/cahzQS2Ts2bWWh6Ta X8L8yAbAvbalSjgc9L9n+oyFTyk7M83SlTN1LIcE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Neukum Subject: [PATCH 4.19 383/425] cdc-wdm: untangle a circular dependency between callback and softint Date: Thu, 20 May 2021 11:22:32 +0200 Message-Id: <20210520092143.988407738@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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__); @@ -1036,9 +1048,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); @@ -1079,9 +1091,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); @@ -1139,7 +1152,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; @@ -1150,6 +1163,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);