Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3120480imu; Mon, 17 Dec 2018 13:45:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8hmYcW4Thrgg/p8h7woif8CdP/fRHGuDEAZLgMFVZr17oAYMuy47mFEulyOAEYaI/JP7u X-Received: by 2002:a62:8d4f:: with SMTP id z76mr14789950pfd.2.1545083109223; Mon, 17 Dec 2018 13:45:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545083109; cv=none; d=google.com; s=arc-20160816; b=dHBGk9pmu1VqJMzAiWJYNyi1VZxexlN89GFKjFpzk52REXIJR7S0ybG7zKzyqn4Nln jIae4YCGtoL6er1PtmKoHQgr7ReJpJMEPRz1p3xCtxkQh3sC1+XqyWvP8r5wpfiIzZQG eDdDoOcbtgJmCqGU54hgWT2jj3ISRWxwHYffkpppP0YDT1T5lAbRra/gcectGPaIQyIS o/tLsPcAR4DQPJ7DrYdU+utxkonjf9QcFbz5QIyqMrvr5nB9MQ1Cb1svWtWe9GM4HGpU fXQbGQJ8B5ucnJBqssmyu5YloWHt99GYFwSANQakByZ61MivYze5mSw0h9d5HJC0Qpcx EUPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=KyBSLq5OZTj/sREiBEGMjlq8zE03fbaCjyrbBx/LFvk=; b=y3Q6kj1Y7bj54FArx1aZ/hgXkUDPYFQ/5wmMG2cZyhqIzkKVjPEJGPjxi+JmpVnKhd A1dRUhWcnSO5939vlCo7yoKQpSIhHmRm2O0O+AArCUfoQa8Ab2ctqZTRHODzsJFJJBK3 UJh3F6d5FoW7OA8UgmN2HP7z7V7z6nT2yhhFqXQPfkcpjbk+Ae7WaNQJj+57ijNef4sD s1Mfl0EscIab+n8/ilk6iMMUN6eYUndn1qtCZrmOIuRMT0w0fbu76fyj1GkVa1gXfvYZ 06IRq8JY5MqWn+NUVSXJZ9wmY6txU/FuF7j78B1sFYI8EeT1egyxFPSk9EFj/uJDTPjb pCnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11si11831485pgd.234.2018.12.17.13.44.54; Mon, 17 Dec 2018 13:45:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388098AbeLQQV5 (ORCPT + 99 others); Mon, 17 Dec 2018 11:21:57 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:56526 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S2387944AbeLQQV4 (ORCPT ); Mon, 17 Dec 2018 11:21:56 -0500 Received: (qmail 2085 invoked by uid 2102); 17 Dec 2018 11:21:55 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 17 Dec 2018 11:21:55 -0500 Date: Mon, 17 Dec 2018 11:21:55 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Andrew Worsley cc: Greg Kroah-Hartman , Mathias Nyman , Nicolas Boichat , Jon Flatley , Kai-Heng Feng , Bin Liu , Benson Leung , "open list:USB SUBSYSTEM" , open list Subject: Re: [PATCH] Prevent race condition between USB authorisation and USB discovery events In-Reply-To: <20181217061036.24143-1-amworsley@gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Dec 2018, Andrew Worsley wrote: > A sysfs driven USB authorisation change can trigger a usb_set_configuration > while a hub_event worker thread is running. This can result in a USB device > being disabled just after it was configured and bringing down all the > devices and impacting hardware and user processes that were established on > top of this these interfaces. In some cases the USB disable never completed > and the whole system hung. Can you be more specific about this? Disabling a USB device shouldn't cause these kinds of problems, regardless of whether or not the device was just configured. > At my work I had an occasional hang due to this race condition. Roughly 1 > in 50 boots had the race occurrence and 1 in 4 of those resulted in a hang. > This patch fixed the problem and I had no problems (spurious disables > or hangs) in 750+ boots. usb_authorize_device, usb_deauthorize_device, and hub_event all acquire the device mutex. Why should adding another mutex make any difference? In fact there's an actual disadvantage: Making hub_event acquire a global mutex will prevent us from handling multiple hubs concurrently. Although we don't do this now, we might want to in the future. Alan Stern