Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934033Ab2EYAdl (ORCPT ); Thu, 24 May 2012 20:33:41 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:37984 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758913Ab2EYAdj convert rfc822-to-8bit (ORCPT ); Thu, 24 May 2012 20:33:39 -0400 MIME-Version: 1.0 In-Reply-To: References: <20120524021429.GB12557@kroah.com> Date: Fri, 25 May 2012 08:33:35 +0800 Message-ID: Subject: =?UTF-8?Q?Re=3A_Race_condition_between_driver=5Fprobe=5Fdevice_and_d?= =?UTF-8?Q?evice=5Fshutdown=E2=80=8F?= From: Ming Lei To: Alan Stern Cc: Greg KH , "Eric W. Biederman" , Wedson Almeida Filho , Andrew Morton , linux-kernel@vger.kernel.org, Linux PM List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1386 Lines: 43 On Thu, May 24, 2012 at 10:37 PM, Alan Stern wrote: > > The code there is racy already. ?It does: > > ? ? ? ? ? ? ? ?} else if (dev->driver && dev->driver->shutdown) { > > without any locking protection. ?If the driver is unbound while this > statement runs then dev->driver could be non-NULL for the first test > and NULL for the second. Yes, I missed this one, :-) > >> > to fix the race by prevent driver core from probing or releasing once >> > shutdown is started. >> > >> > How about the below patch? >> >> How about waiting for the original poster to respond as to exactly how >> they are hitting this race before doing anything? > > In addition, the patch is too complicated. ?For this type of > synchronization you should use SRCU. ?See > Documentation/RCU/whatisRCU.txt and related files. Yes, the synchronization should be a many reader vs. one writer problem, RCU should be suitable. Looks we think alike, :-) I have studied RCU yesterday, but was afraid that may introduce much more code, so not applied it in the patch. Will study it further to figure out a new version. Thanks, -- Ming Lei -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/