Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp173145pxj; Tue, 18 May 2021 00:16:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuBw/csscPPVAHsUjA/oJzMV9AszxUzWfzWF0lvuKIKUZdePuMXzkg6hewka1U6lUmI/tF X-Received: by 2002:a05:6e02:1302:: with SMTP id g2mr2949933ilr.259.1621322189846; Tue, 18 May 2021 00:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621322189; cv=none; d=google.com; s=arc-20160816; b=uR8DYUEHlcT/NR+OC2umBoOXJ4lHMP4SJZncdOQPgWMHw7UBUiPNq/HibAcbb8G76K 921B215uAPAg8OyINlT0n/k96ShRLgTxScdm2+Ho44RDW75zLzSDTo1UsQEO6mEQMZ3K bcYogr3ES9kyBp67q35b57zXOm42WyYMBzFJyAyemDLS/kF91jPOeozVwBOgyP9MN/N9 EkI0uqeQFdhqhp+VzNos6Hr2age0lwgv2nOKMWCGF8x3nbTRtfaSg57ZUX2wLau3ijqJ HeEbdVP//V8ti4kB9xGYQRn5uk2P6DRG12QVDo7x7+AumvD2qEFOii4X65Nem/FUJErK aGug== 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=eIwpH0UekjoqJGjGZbaf8SB6fawUXUuAjjUQ/iwye4iyx9KIBDGmDVYZv301QCCLCm rQ92jYpMjuWZbF2fVeuVTP8uaXYxsciCU+Q0LNnoVrbBeeQdKQb+nFBlqYgZllXCTP5v aHST/xYzRsYk5VVeEhl/JTEKKWBOGS+fskzfKr210GyHJ7AoppC9k9S3GXu5MKgfVBzZ TQ3i9sjNWQkIciPdle1XO0ID00uhKwUumhPZW3kYMhZoFM2LQpSKn1lg56EUL3Ly7HdL IWEGE9rGYx7pO5L2l2ArJYsfhPytC9wwCRgj7PihGbr8i71a8RP/g5uDFCMU/uTkA4wI wKzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KaD3ENl1; 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 l22si3421517jad.10.2021.05.18.00.16.16; Tue, 18 May 2021 00:16:29 -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=KaD3ENl1; 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 S241600AbhEQOxX (ORCPT + 99 others); Mon, 17 May 2021 10:53:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:54230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241529AbhEQOpJ (ORCPT ); Mon, 17 May 2021 10:45:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B903161951; Mon, 17 May 2021 14:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261258; bh=w1dN5sX4ZZCG3Slp7G3V4sFe3WQRgF+QCwDfjW+QruQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KaD3ENl1RZT5demG2xEVIWsvA4SYaV/SZyn4fLOjbDiOK1ND8kH+mgim3iMQXsPgI C5PqaCOSDv7JfsynMsi8Lp8pD+DE0vik/FM3Z6IuqKmR0g74pFWUeLU9LTpl44FeNO 9Me6i9xdhV23P42JKSgp5Vx4YhLrg6HrIYNXv7Ps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Neukum Subject: [PATCH 5.12 326/363] cdc-wdm: untangle a circular dependency between callback and softint Date: Mon, 17 May 2021 16:03:12 +0200 Message-Id: <20210517140313.627551546@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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);