Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp891750imm; Fri, 29 Jun 2018 08:03:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIysdumPGsoTnw2RXIL0GAHeCtqokCoDvOucQ/PwJxplvXW40mV605TMzYe5438cQiu9SaD X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr15642415plb.26.1530284596831; Fri, 29 Jun 2018 08:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530284596; cv=none; d=google.com; s=arc-20160816; b=qPzk4nTK/uEHbuAOLGsnaLATJUAubth3oLiPOwFY+epnvh/32zoRAfP9r4m7NpE+e/ 596JGrGdo08YQffzaI4Xt8WwlbeTMFzLERllYDF7iRHXeeAnagvi2mXOyJVb+qRXgbhE Iud193e0LntEiSZn6FhuPxyKrk1ZJncjGxuqZLfkmaiG/hVz3+D1WxaBTabKKSCv+ST7 N2IKzNI03alOSyUf3ZLmQGdYpYgZUpngtJG1RkEg8pDwv7aTqTAJcAZbfYFoaWV1sOOR jgbDOCztEYk7PyMEhZ8JUBzYAGAeBKs+LPFmwj3XnCGKX+uUcgwO9y9qpigTs6U073qF zdDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=Ft8Da1dBhGpgvOy2rTHMD3PLOovGB71rDrnA0y01D4A=; b=TFW3rt3L/qwDB7mbVP9bLA+5swY1ETTGWfwnDjTjs3c+Cbe3wvuekfuS3YmP1EG5Kb BaihNCyiGclSf7u9og84Cw8N/dGS7x5lu0Gq5KE11d22SX/YEB4CePri3gDNFFwmC39p 68po975PUs9gBfgM+Or87ZgX4P2VDRtbAMp2fF6it9kQT8p9BKlwEgVzC6HqXzgNoNi3 f3dIr7Ej74qtaw27ockWCecRVJMTka+xueCp4kxoE+SlUbjxNCGo6tNZjBaVrKd3zN4Y /a0iLi7man5upuT4yHen0LOxkEiK7Sic2KyLf93d/rm1l6zFjNQsxrt9sjSP5SmokQhP HL/w== 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 z2-v6si9310504pln.395.2018.06.29.08.02.59; Fri, 29 Jun 2018 08:03:16 -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; 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 S934967AbeF2LFD (ORCPT + 99 others); Fri, 29 Jun 2018 07:05:03 -0400 Received: from smtp08.smtpout.orange.fr ([80.12.242.130]:50551 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934510AbeF2LFB (ORCPT ); Fri, 29 Jun 2018 07:05:01 -0400 Received: from belgarion ([90.55.203.186]) by mwinf5d15 with ME id 4b4y1y00941oiFu03b4y1t; Fri, 29 Jun 2018 13:05:00 +0200 X-ME-Helo: belgarion X-ME-Auth: amFyem1pay5yb2JlcnRAb3JhbmdlLmZy X-ME-Date: Fri, 29 Jun 2018 13:05:00 +0200 X-ME-IP: 90.55.203.186 From: Robert Jarzmik To: Felipe Balbi Cc: Jia-Ju Bai , gregkh@linuxfoundation.org, nicolas.ferre@microchip.com, keescook@chromium.org, allen.lkml@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] usb: gadget: r8a66597: Fix two possible sleep-in-atomic-context bugs in init_controller() References: <20180620035453.7721-1-baijiaju1990@gmail.com> <87efh0o6f9.fsf@belgarion.home> <87y3eydrs1.fsf@linux.intel.com> <87efgqkrzl.fsf@belgarion.home> <87k1qhevpd.fsf@linux.intel.com> X-URL: http://belgarath.falguerolles.org/ Date: Fri, 29 Jun 2018 13:04:58 +0200 In-Reply-To: <87k1qhevpd.fsf@linux.intel.com> (Felipe Balbi's message of "Fri, 29 Jun 2018 13:25:02 +0300") Message-ID: <87a7rdlup1.fsf@belgarion.home> User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Felipe Balbi writes: > Hi, > > Robert Jarzmik writes: >>>>> The driver may sleep with holding a spinlock. >>>>> The function call paths (from bottom to top) in Linux-4.16.7 are: >>>>> >>>>> [FUNC] msleep >>>>> drivers/usb/gadget/udc/r8a66597-udc.c, 839: >>>>> msleep in init_controller >>>>> drivers/usb/gadget/udc/r8a66597-udc.c, 96: >>>>> init_controller in r8a66597_usb_disconnect >>>>> drivers/usb/gadget/udc/r8a66597-udc.c, 93: >>>>> spin_lock in r8a66597_usb_disconnect >>>> >>>> That should not happen... >>>> >>>> If think the issue you have is that your usb_connect() and usb_disconnect() are >>>> called from interrupt context. I think the proper fix, as what is done in most >>>> udc phys, is to schedule a workqueue, see drivers/usb/phy/phy-gpio-vbus-usb.c, >>>> gpio_vbus_data.vbus. >>> >>> argh, no. No workqueues needed here. Sorry >> Technically why ? > > well, strictly technically there's nothing wrong. But it opens a can of > worms. We've seen time and time again drivers growing into > unmaintainable mess because of workqueues being fired in several places. I see. >> >> And as bonus question, why is it better to have mdelay() calls in the driver ? > > As a bugfix, it's the smallest fix possible, right? Ideally, we wouldn't > need either of them. Perhaps there's a bit which can be polled instead? Ideally yes. Do you remember if a "threaded interrupt" might use msleep() ? I seem to remember that they can, so won't that be another alternative ? Cheers. -- Robert