Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4956206ybv; Tue, 11 Feb 2020 06:31:52 -0800 (PST) X-Google-Smtp-Source: APXvYqw7n1nEqW+Y9MNd5cxBLpaueBcXGIP7yMWLJP+2QUsxH/UIlYhwa6VroxjhECSi8dCIgMYS X-Received: by 2002:a9d:806:: with SMTP id 6mr5200890oty.90.1581431512006; Tue, 11 Feb 2020 06:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581431511; cv=none; d=google.com; s=arc-20160816; b=QC8hInTEUk9tMEbNutvIq5YtyOIuQP8zBehxQHGUQvaGJLPLea0mJRwW/QFqvkKm6w I7DRGzT2jOWgioghRf2NrV9kJNM6YXIDwGU6RXo1dTyIS/xaIa3QY+eJSj5vcalyvcwM cG41GrrP0tR9vWrhqvqLK56iSddSRVBu5ROcnXKhv82JUwegWCFx4TxGqidYtrzmQKfM ZV3GxizmFW1Tot0prZahBOF+SXOpGq5AJmkLwGAP2EXvDZg3GcXyyK5W1mSIms+P5aCW p/8Lmg6H0C0fH3ZivBIej3eaCgXKWwyLIvlEGcQnbxbqWFe580tix17XjzJ+a+HuPMBs DaJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:references:cc:to:from:subject; bh=NZZps3Vci34MGzssDM2d4jqgdBru2yOBF8K5x838ouI=; b=iq2EIQH/OEuF3LHW2l/QdXYpyoLia/h2NmYlSuvOd7UzOBVVqWrzGGXrmBzd++yR0n xArNAEtSjuXJveko5MZf6kc+S4V+WxpMplkbLvBJcomkhVTvVJlLEl0PUArgvjd1qkdi 8+R1Ph0tn4ykSJMhTZ64gEn61NlTMvDwIYe92rfH8iIS3bLRq/DEJlCH6C0for+CDOF9 5ap+F6kH3sz/YI4L0V73HJZ5zqsY3YHz0wQvbu1QTF9HI51w0ZPsUK78RFFb9DCGYUJ/ 8xZHpADo36lSwrHIlsmh0eVyHaqEwfbUQ5QLGqRn+Cxnhpt/a8/8ly6qlw1Ha7denDdq 5U5g== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si1660270oiz.237.2020.02.11.06.31.38; Tue, 11 Feb 2020 06:31:51 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730023AbgBKOF5 (ORCPT + 99 others); Tue, 11 Feb 2020 09:05:57 -0500 Received: from mga09.intel.com ([134.134.136.24]:1887 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbgBKOF4 (ORCPT ); Tue, 11 Feb 2020 09:05:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2020 06:05:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,428,1574150400"; d="scan'208";a="405945809" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.170]) ([10.237.72.170]) by orsmga005.jf.intel.com with ESMTP; 11 Feb 2020 06:05:52 -0800 Subject: Re: [RFT PATCH] xhci: Fix memory leak when caching protocol extended capability PSI tables From: Mathias Nyman To: Greg KH , Marek Szyprowski Cc: pmenzel@molgen.mpg.de, mika.westerberg@linux.intel.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, 'Linux Samsung SOC' , Krzysztof Kozlowski References: <572bea6f-06d4-938a-802e-93386acf59d9@linux.intel.com> <20200108151730.21022-1-mathias.nyman@linux.intel.com> <089285ab-7041-49bb-54ea-c73b25f96f48@samsung.com> <20200211122316.GG1856500@kroah.com> <9d314940-086e-d9a7-88e2-88447cd1c67d@linux.intel.com> Openpgp: preference=signencrypt Autocrypt: addr=mathias.nyman@linux.intel.com; prefer-encrypt=mutual; keydata= mQINBFMB0ccBEADd+nZnZrFDsIjQtclVz6OsqFOQ6k0nQdveiDNeBuwyFYykkBpaGekoHZ6f lH4ogPZzQ+pzoJEMlRGXc881BIggKMCMH86fYJGfZKWdfpg9O6mqSxyEuvBHKe9eZCBKPvoC L2iwygtO8TcXXSCynvXSeZrOwqAlwnxWNRm4J2ikDck5S5R+Qie0ZLJIfaId1hELofWfuhy+ tOK0plFR0HgVVp8O7zWYT2ewNcgAzQrRbzidA3LNRfkL7jrzyAxDapuejuK8TMrFQT/wW53e uegnXcRJaibJD84RUJt+mJrn5BvZ0MYfyDSc1yHVO+aZcpNr+71yZBQVgVEI/AuEQ0+p9wpt O9Wt4zO2KT/R5lq2lSz1MYMJrtfFRKkqC6PsDSB4lGSgl91XbibK5poxrIouVO2g9Jabg04T MIPpVUlPme3mkYHLZUsboemRQp5/pxV4HTFR0xNBCmsidBICHOYAepCzNmfLhfo1EW2Uf+t4 L8IowAaoURKdgcR2ydUXjhACVEA/Ldtp3ftF4hTQ46Qhba/p4MUFtDAQ5yeA5vQVuspiwsqB BoL/298+V119JzM998d70Z1clqTc8fiGMXyVnFv92QKShDKyXpiisQn2rrJVWeXEIVoldh6+ J8M3vTwzetnvIKpoQdSFJ2qxOdQ8iYRtz36WYl7hhT3/hwkHuQARAQABtCdNYXRoaWFz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XID6GmjwFQR5Wh/RE IJtkiDAsk37cfZ9d1kZ2gCQryTV9lmflSOB6AFZkOLuEVSC5qW8M/s6IGDfYXN12YJaZPptJ fiD/ Message-ID: <20d0559f-8d0f-42f5-5ebf-7f658a172161@linux.intel.com> Date: Tue, 11 Feb 2020 16:08:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <9d314940-086e-d9a7-88e2-88447cd1c67d@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11.2.2020 14.29, Mathias Nyman wrote: > On 11.2.2020 14.23, Greg KH wrote: >> On Tue, Feb 11, 2020 at 11:56:12AM +0100, Marek Szyprowski wrote: >>> Hi >>> >>> On 08.01.2020 16:17, Mathias Nyman wrote: >>>> xhci driver assumed that xHC controllers have at most one custom >>>> supported speed table (PSI) for all usb 3.x ports. >>>> Memory was allocated for one PSI table under the xhci hub structure. >>>> >>>> Turns out this is not the case, some controllers have a separate >>>> "supported protocol capability" entry with a PSI table for each port. >>>> This means each usb3 port can in theory support different custom speeds. >>>> >>>> To solve this cache all supported protocol capabilities with their PSI >>>> tables in an array, and add pointers to the xhci port structure so that >>>> every port points to its capability entry in the array. >>>> >>>> When creating the SuperSpeedPlus USB Device Capability BOS descriptor >>>> for the xhci USB 3.1 roothub we for now will use only data from the >>>> first USB 3.1 capable protocol capability entry in the array. >>>> This could be improved later, this patch focuses resolving >>>> the memory leak. >>>> >>>> Reported-by: Paul Menzel >>>> Reported-by: Sajja Venkateswara Rao >>>> Signed-off-by: Mathias Nyman >>> >>> This patch landed in today's linux-next (20200211) and causes NULL >>> pointer dereference during second suspend/resume cycle on Samsung >>> Exynos5422-based (arm 32bit) Odroid XU3lite board: >>> >>> # time rtcwake -s10 -mmem >>> rtcwake: wakeup from "mem" using /dev/rtc0 at Tue Feb 11 10:51:43 2020 >>> PM: suspend entry (deep) >>> Filesystems sync: 0.012 seconds >>> Freezing user space processes ... (elapsed 0.010 seconds) done. >>> OOM killer disabled. >>> Freezing remaining freezable tasks ... (elapsed 0.002 seconds) done. >>> smsc95xx 1-1.1:1.0 eth0: entering SUSPEND2 mode >>> wake enabled for irq 153 >>> wake enabled for irq 158 >>> samsung-pinctrl 13400000.pinctrl: Setting external wakeup interrupt >>> mask: 0xffffffe7 >>> Disabling non-boot CPUs ... >>> IRQ 51: no longer affine to CPU1 >>> IRQ 52: no longer affine to CPU2 >>> s3c2410-wdt 101d0000.watchdog: watchdog disabled >>> wake disabled for irq 158 >>> usb usb1: root hub lost power or was reset >>> usb usb2: root hub lost power or was reset >>> wake disabled for irq 153 >>> exynos-tmu 10060000.tmu: More trip points than supported by this TMU. >>> exynos-tmu 10060000.tmu: 2 trip points should be configured in polling mode. >>> exynos-tmu 10064000.tmu: More trip points than supported by this TMU. >>> exynos-tmu 10064000.tmu: 2 trip points should be configured in polling mode. >>> exynos-tmu 10068000.tmu: More trip points than supported by this TMU. >>> exynos-tmu 10068000.tmu: 2 trip points should be configured in polling mode. >>> exynos-tmu 1006c000.tmu: More trip points than supported by this TMU. >>> exynos-tmu 1006c000.tmu: 2 trip points should be configured in polling mode. >>> exynos-tmu 100a0000.tmu: More trip points than supported by this TMU. >>> exynos-tmu 100a0000.tmu: 6 trip points should be configured in polling mode. >>> usb usb3: root hub lost power or was reset >>> s3c-rtc 101e0000.rtc: rtc disabled, re-enabling >>> usb usb4: root hub lost power or was reset >>> xhci-hcd xhci-hcd.8.auto: No ports on the roothubs? >>> PM: dpm_run_callback(): platform_pm_resume+0x0/0x44 returns -12 >>> PM: Device xhci-hcd.8.auto failed to resume async: error -12 >>> hub 3-0:1.0: hub_ext_port_status failed (err = -32) >>> hub 4-0:1.0: hub_ext_port_status failed (err = -32) >>> usb 1-1: reset high-speed USB device number 2 using exynos-ehci >>> usb 1-1.1: reset high-speed USB device number 3 using exynos-ehci >>> OOM killer enabled. >>> Restarting tasks ... done. >>> >>> real    0m11.890s >>> user    0m0.001s >>> sys     0m0.679s >>> root@target:~# PM: suspend exit >>> mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 400000Hz, >>> actual 396825HZ div = 63) >>> mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 200000000Hz, >>> actual 200000000HZ div = 0) >>> mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot req 52000000Hz, >>> actual 50000000HZ div = 0) >>> mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot req 200000000Hz, >>> actual 200000000HZ div = 1) >>> smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC1E1 >>> >>> root@target:~# >>> root@target:~# time rtcwake -s10 -mmem[   35.451572] vdd_ldo12: disabling >>> >>> rtcwake: wakeup from "mem" using /dev/rtc0 at Tue Feb 11 10:52:02 2020 >>> PM: suspend entry (deep) >>> Filesystems sync: 0.004 seconds >>> Freezing user space processes ... (elapsed 0.006 seconds) done. >>> OOM killer disabled. >>> Freezing remaining freezable tasks ... (elapsed 0.070 seconds) done. >>> hub 4-0:1.0: hub_ext_port_status failed (err = -32) >>> hub 3-0:1.0: hub_ext_port_status failed (err = -32) >>> 8<--- cut here --- >>> Unable to handle kernel NULL pointer dereference at virtual address 00000014 >>> pgd = 4c26b54b >>> [00000014] *pgd=00000000 >>> Internal error: Oops: 17 [#1] PREEMPT SMP ARM >>> Modules linked in: >>> CPU: 3 PID: 1468 Comm: kworker/u16:23 Not tainted >>> 5.6.0-rc1-next-20200211 #268 >>> Hardware name: Samsung Exynos (Flattened Device Tree) >>> Workqueue: events_unbound async_run_entry_fn >>> PC is at xhci_suspend+0x12c/0x520 >>> LR is at 0xa6aa9898 >>> pc : []    lr : []    psr: 60000093 >>> sp : ec401df8  ip : 0000001a  fp : c12e7864 >>> r10: 00000000  r9 : ecfb87b0  r8 : ecfb8220 >>> r7 : 00000000  r6 : 00000000  r5 : 00000004  r4 : ecfb81f0 >>> r3 : 00007d00  r2 : 00000001  r1 : 00000001  r0 : 00000000 >>> Flags: nZCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none >>> Control: 10c5387d  Table: 6bd4006a  DAC: 00000051 >>> Process kworker/u16:23 (pid: 1468, stack limit = 0x6e4b6fba) >>> Stack: (0xec401df8 to 0xec402000) >>> ... >>> [] (xhci_suspend) from [] (dpm_run_callback+0xb4/0x3fc) >>> [] (dpm_run_callback) from [] >>> (__device_suspend+0x134/0x7e8) >>> [] (__device_suspend) from [] (async_suspend+0x1c/0x94) >>> [] (async_suspend) from [] >>> (async_run_entry_fn+0x48/0x1b8) >>> [] (async_run_entry_fn) from [] >>> (process_one_work+0x230/0x7bc) >>> [] (process_one_work) from [] (worker_thread+0x44/0x524) >>> [] (worker_thread) from [] (kthread+0x130/0x164) >>> [] (kthread) from [] (ret_from_fork+0x14/0x20) >>> Exception stack(0xec401fb0 to 0xec401ff8) >>> ... >>> ---[ end trace c72caf6487666442 ]--- >>> note: kworker/u16:23[1468] exited with preempt_count 1 >>> >>> Reverting it fixes the NULL pointer issue. I can provide more >>> information or do some other tests. Just let me know what will help to >>> fix it. >>> >>> > ... >> >> Ugh. Mathias, should I just revert this for now? >> > > Yes, revert it. > > This looks very odd, after second resume, and losing power driver > can't find any port at all. > > Marek, do you still get the "xhci-hcd xhci-hcd.8.auto: No ports on the roothubs?" > message on second resume after reverting the patch? > Ok, I think I got it. Patch doesn't set xhci->num_port_caps to 0 in xhci_mem_cleanup(). Adding new ports will fail when we reinitialize xhci manually, like in this exynos case where xhci loses power in suspend/resume cycle. I'll post a new version soon -Mathias