Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751937AbdGSFRL convert rfc822-to-8bit (ORCPT ); Wed, 19 Jul 2017 01:17:11 -0400 Received: from mga02.intel.com ([134.134.136.20]:11940 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751123AbdGSFRJ (ORCPT ); Wed, 19 Jul 2017 01:17:09 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,379,1496127600"; d="scan'208";a="109510297" From: "He, Bo" To: Felipe Balbi , "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" CC: "gregkh@linuxfoundation.org" , "peter.chen@nxp.com" , "k.opasiak@samsung.com" , "stefan@agner.ch" , "felixhaedicke@web.de" , "colin.king@canonical.com" , "rogerq@ti.com" , "f.fainelli@gmail.com" , "Zhang, Yanmin" Subject: RE: [PATCH] usb: gadget: udc: fix the kernel NULL pointer in composite_setup Thread-Topic: [PATCH] usb: gadget: udc: fix the kernel NULL pointer in composite_setup Thread-Index: AdL/pu3/TyZUFijXS92FGqU2rslGe///kaGA//5G3KA= Date: Wed, 19 Jul 2017 05:16:51 +0000 Message-ID: References: <87pocy81og.fsf@linux.intel.com> In-Reply-To: <87pocy81og.fsf@linux.intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3500 Lines: 72 Hi, Balbi: 1. the issue reproduced very rarely, we run reboot test reproduce the issue, it reproduced two times on two board after more than 1500 cycles reboot. 2. the kernel version is 4.4, the test case is cold reboot, I think it's not android patches cause it, it's the interrupt thread run after the udc->driver->unbind. 3. I check more drivers, like amd5536_udc_stop, at91_stop, atmel_usba_stop, bcm63xx_udc_stop, s3c_hsudc_stop, all the interrupt disable will be in the udc_stop(), so we need guarantee to stop the interrupt then release the resource. -----Original Message----- From: Felipe Balbi [mailto:balbi@kernel.org] Sent: Tuesday, July 18, 2017 6:44 PM To: He, Bo ; linux-kernel@vger.kernel.org; linux-usb@vger.kernel.org Cc: gregkh@linuxfoundation.org; peter.chen@nxp.com; k.opasiak@samsung.com; stefan@agner.ch; felixhaedicke@web.de; colin.king@canonical.com; rogerq@ti.com; f.fainelli@gmail.com; He, Bo ; Zhang, Yanmin Subject: Re: [PATCH] usb: gadget: udc: fix the kernel NULL pointer in composite_setup Hi, "He, Bo" writes: > the patch is for fix the below kernel panic: > BUG: unable to handle kernel NULL pointer dereference at > 000000000000002a > IP: [] composite_setup+0x3d/0x1830 PGD 27525b067 PUD > 27525a067 PMD 0 > Oops: 0002 [#1] PREEMPT SMP > Call Trace: > [] ? dwc3_trace+0x52/0x60 [] ? > get_parent_ip+0xd/0x50 [] android_setup+0xbc/0x140 > [] ? irq_finalize_oneshot+0xe0/0xe0 > [] dwc3_ep0_delegate_req+0x37/0x50 > [] dwc3_ep0_interrupt+0xaf9/0xc10 > [] ? get_parent_ip+0xd/0x50 [] ? > irq_finalize_oneshot+0xe0/0xe0 [] > dwc3_thread_interrupt+0x931/0xbf0 [] ? > irq_finalize_oneshot+0xe0/0xe0 [] > irq_thread_fn+0x1e/0x40 [] irq_thread+0x134/0x1b0 > [] ? wake_threads_waitq+0x30/0x30 > [] kthread+0xed/0x110 [] > ret_from_fork+0x3f/0x70 RIP [] > composite_setup+0x3d/0x1830 > > the root cause is dwc interrupt comes after usb_gadget_remove_driver. > the fix is stop udc to have the dwc3 disable the interrupt, then > release the resource in udc->driver->unbind. > usb_gadget_udc_stop--> > udc->gadget->ops->udc_stop(udc->gadget)--> > dwc3_gadget_stop > > Signed-off-by: he, bo > --- > drivers/usb/gadget/udc/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/usb/gadget/udc/core.c > b/drivers/usb/gadget/udc/core.c index e6f04ee..67e9aa5 100644 > --- a/drivers/usb/gadget/udc/core.c > +++ b/drivers/usb/gadget/udc/core.c > @@ -1258,8 +1258,8 @@ static void usb_gadget_remove_driver(struct > usb_udc *udc) > > usb_gadget_disconnect(udc->gadget); > udc->driver->disconnect(udc->gadget); > - udc->driver->unbind(udc->gadget); > usb_gadget_udc_stop(udc); > + udc->driver->unbind(udc->gadget); unbind must be called before udc_stop. This seems to be a bug *only* in dwc3. I can't see how this would happen, actually. On dwc3_gadget_stop() we mask dwc3's interrupts, so the handler should be executed anymore. Can you tell me how to reproduce this? I could try this out tomorrow. Which kernel are you using? I wonder if this is something caused by the Android patches. -- balbi