Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2936902imm; Thu, 24 May 2018 19:25:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpYdehnU5R+OvmPr//5gdNx5/I9a2c0jwGNuRv0pV4uHFbWfoAWZILydr81VhZYtnQu98d6 X-Received: by 2002:a63:7a07:: with SMTP id v7-v6mr434104pgc.444.1527215152861; Thu, 24 May 2018 19:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527215152; cv=none; d=google.com; s=arc-20160816; b=WowQvAgnhesE2shK6hMMTiYHfA8Ekmi7sBgIZAmmiMbNtIUNplk8DtTt0RLjtTy0KH OXbowx6rW0XkI2E9ikYUOdH8hJMK035wg8h6WVv8g2BwreraIdCzEi5TuzSkGfFAIxHr dczj+xsONmTkGDE3JxZoj10xVf4mcTwxlvMLkk+EB9PbDliPFsZGAib5EQE4ZFpL2sor /Xb2ctdh24h/Dy1YiMCd+CGvj9eFkh10E6r7/CvBIomKTKVBke8g8zC8khxvjkaai+87 xYHcX6VtoApKwFmLXY2+jSeWdjfA5+WASKUZLH0mr6xPwp0UryICSJjT1JnP3BTnW3Fk aIhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=QLk4eWDfeg5+FEUC7wOYD4lEnYIgv9BIcOemMasWkDI=; b=WFkFIrl82AvACmTUXs9frrSJ/9bE1lVfJuFcm0ALEbAx8ruJOTO4u5W4/cs2eGxHMy JpOWuOKHeZByyJunnFgLmc4aIkLSSVX6fWGPkvqPqIKOTWuxo+sBmqAqo5aHCpx8125o 8NvXwG2guvf1xo2yL6sbFmVJ92u5aZlvQDZ3pwe1PYNO46rrYZohtFZblB60Ifa28U58 RfTxZxJySge9ptoimPkCaaImFZMxdWVAbmz+3QfloojwJ7KySZiGd91cTvKUDS+8Ip9C fhaoQKV53L0mrGMu8LcgtSUacxeEBcpBy38fnlsne6bfag/TJ9dVEvnbCohz0pex7JSP FEBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EdNDSyB9; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 34-v6si22873801plz.66.2018.05.24.19.25.38; Thu, 24 May 2018 19:25:52 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=EdNDSyB9; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031036AbeEXQFl (ORCPT + 99 others); Thu, 24 May 2018 12:05:41 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:39308 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030546AbeEXQFg (ORCPT ); Thu, 24 May 2018 12:05:36 -0400 Received: by mail-pg0-f66.google.com with SMTP id e1-v6so996588pga.6 for ; Thu, 24 May 2018 09:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QLk4eWDfeg5+FEUC7wOYD4lEnYIgv9BIcOemMasWkDI=; b=EdNDSyB9/QAfyHtLfZ+cZbDtyGMzN6rPz4yUQKoviMoNI/6yNAErEt+antZMDGFm+j L/a5x+DXDdvYkg5wEKISwxuQnqqbKewRpF/TqSeFGXeY1tJXbqapN0Q+7508hbv+eKSZ oPlo5E3vErUSL8yVJxgCHQE8qkHLCmI6g9Bduqe9FVSGiBwHGxhlMW1E5QjjRDW0maCQ 8PXitPNrs25UUug8X7HPGCaiqk7/KhKIfGC7ht5gMsx048aeSMKiVMM7i9w1zj7dYqf4 g3D6OV4pijRWCzkEcRJA8Pu1y17Wy3PUDg6MiOq+ll9MJMb6I0hJZTrS6Ph3TC3LtydP cWQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QLk4eWDfeg5+FEUC7wOYD4lEnYIgv9BIcOemMasWkDI=; b=l5NAuKMLmM0juVbKB15Y/cpPjyL1OpfBFIbyzWYMzWqdGLLvuQOrjghPjo0yUSRpjQ Oo5m77QSHYDaAwJQuoOaRZ0/NPMp+isPigKmY+jwKcrlaFV8TC3mACefFhCviosT6y6t 1miWM0C0n0WMhAv7Pgx6Rvfi9BZFLR1qmhG+UhisFMTortGQ6ZIoFraRERD6dBtI/6in abtrPW+soQ2CjePhbyLFg5LFSMCrLEwMnJ7lKta1LcPQq+8Rlw6jtS62hrSjzeGR9UPZ O/64N+GehMM4lpX8O8NoE0h/oKjq7F/vgQf3r+S+KdrNhQCfHNJVnmkWqkWg8SauBXaA nlxQ== X-Gm-Message-State: ALKqPwdwvLGA1HEvtWQ+gkWbHAvoWpD1U+fsC9cIn7Pp2HL5mqda8pyH 3ZdVVWXwrbwhGl1xL7LGp5bDstyhr94= X-Received: by 2002:a63:7b15:: with SMTP id w21-v6mr6437120pgc.268.1527177935964; Thu, 24 May 2018 09:05:35 -0700 (PDT) Received: from google.com ([2401:fa00:fc:202:ac57:d0e0:7094:5]) by smtp.gmail.com with ESMTPSA id r22-v6sm33019240pfh.61.2018.05.24.09.05.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 May 2018 09:05:35 -0700 (PDT) Date: Fri, 25 May 2018 00:05:32 +0800 From: Martin Liu To: Alan Stern Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, jenhaochen@google.com Subject: Re: [RFC] driver core: don't hold dev's parent lock when using async probe Message-ID: <20180524160532.GA4803@google.com> References: <20180524140021.GA214888@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 24, 2018 at 11:02:57AM -0400, Alan Stern wrote: > On Thu, 24 May 2018, Martin Liu wrote: > > > On Tue, May 22, 2018 at 01:09:44PM -0400, Alan Stern wrote: > > > On Tue, 22 May 2018, martin_liu wrote: > > > > > > > not sure if we still need 'bf74ad5bc417 ("[PATCH] Hold the > > > > device's parent's lock during probe and remove")' since it has > > > > been there over 10 years. If we still need it and hard to fix it > > > > , the simple way is to find a place not to allow USB subsystem > > > > drivers to have async probe capability. Any suggestion is welcome. > > > > > > I don't think the "allows_async_probing" attribute is the best way to > > > attack this. Some other approach, like a special-purpose flag, might > > > be better. > > > > > > Yes, USB still needs to have parent's locks held during probing. > > > Here's the reason. A USB device can have multiple interfaces, each > > > bound to its own driver. A driver may sometimes need to issue a reset, > > > but in USB there's no way to reset a single interface. Only the entire > > > device can be reset, and of course this affects all the interfaces. > > > Therefore a driver needs to acquire the device lock before it can issue > > > a reset. > > > > > > The problem is that the driver's thread may already hold the device > > > lock. During a normal probe sequence, for example, the interfaces get > > > probed by the hub driver while it owns the device lock. But for probes > > > under other circumstances (for example, if the user writes to the > > > driver's "bind" attribute in sysfs), the device lock might not be held. > > > > > > A driver cannot tell these two cases apart. The only way to make it > > > work all the time is to have the caller _always_ hold the device lock > > > while the driver is probed (or the removed, for that matter). > > > > > > Alan Stern > > > > Thanks for the reply and more detail about the backgroud. I'd like to > > have a conclusion about it. Please kindly correct me if my understanding > > is wrong. Regarding to the "special-purpose flag", do you mean we could > > find a place in USB subsystem to have the flag set (not sure if it's > > easy to find it). Driver core would be base on the flag to decide if we > > need to hold the device's parent's lock. > > Yes, except that the flag would not be in the USB subsystem. It would > be in the device, device_type, or bus_type structure, so that the > driver core could access it. > > Alan Stern Thanks for the quick feedback and the suggestion. will try to figure out how it works. Martin