From patchwork Wed Sep 4 17:54:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172950 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1046848ocp; Wed, 4 Sep 2019 11:09:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwem2Fc21x9knrbtuIYUUz0kGA4m4wddDj91A+cF2ds6lm0dF0X1nHYwffi4Y6FAW4p6xvb X-Received: by 2002:a62:37c5:: with SMTP id e188mr48891222pfa.207.1567620478213; Wed, 04 Sep 2019 11:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620478; cv=none; d=google.com; s=arc-20160816; b=Mg1Tha8bNrdEv2gxQaOAYvD36MrCU4K6kGTkZ9LaPywGqJKbS8cI4AnrUAF1wAAaSk mwlcmna5nnXbi5j5hxMAAy1XIFQHaJSpk3SWRE2bmLuJajeNa9fQzT6rqGUxFD+aSEmW VLb1h9nJ5caB2HgX61j5rHNPDeiHFrZPnSwbrxkLsB2qsZCew1BS4aj0PUnnaiH2WeYh hBdojzHKNfqCiiTaU1dVQoiEuHgWbJUvFjUKY3DY2Lsygpo+7A1shZtwklM3D9mHgtND ziEDGlAWRKA7/+lvUP/3OiHDTWkFlqinFBxcwcveM94aEM8PUVge3ctsBrDHB1Cc643e 35aw== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s5hrPziqRfZjLWZJOvxvO5X66NcgwH29zvM09VrJcTs=; b=Mrl9Z3YWGN9E6BMSYvPwbcaVkjeTTTJkFF3dmGZH3H2esNRUbBcszNjLvTMlrfWrQe TZMAeXwxel4WAGzAq4n+vzY9rpQyWeYIsDSu93/pZCdAm1LA2xf0K7jTgHFtHf58KuXI VuzPBSm9CAoFu3mdXbSAfckWerwnu3r6xEAU1atqPM1SfiAuCluTHzYPUoD7vfTD/EyN ASfOAKEDMH0eOA4RWG3vzFyenN/w0CcL7WKlw9H1GvLoecJEaMKBiwgVsr8A/Odp5Da8 joaapRhp12J+Exuc3B2n5ckMMqmsGDKweHs8Af876CKHdpYWQLPL9FY//hTCEbLjDdzw VOvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=stARnLWN; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 v186si16946265pgd.358.2019.09.04.11.07.57; Wed, 04 Sep 2019 11:07:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@kernel.org header.s=default header.b=stARnLWN; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389119AbfIDSH5 (ORCPT + 14 others); Wed, 4 Sep 2019 14:07:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:50554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389302AbfIDSH4 (ORCPT ); Wed, 4 Sep 2019 14:07:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D8BA520870; Wed, 4 Sep 2019 18:07:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620475; bh=UbwxphCkJgqkkmqkEGI327ZtsTfNouQD7+qWRvtcpI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=stARnLWN+RtRq81hHYa2OulY7q8ZKiMxoo3ABQxJRfDDRAdTgFduGi5WKCs4D0yY0 wBdiW/2W7hTfpofjgBFhmZbensHnq+aGr7q+iws+c5ByfNiaK5WeIf4ebfTlMLHbi+ ftnEcKLDIAZ9vw+LpycL16+7cciiPGrzalWOtC0o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 4.19 71/93] lib: logic_pio: Avoid possible overlap for unregistering regions Date: Wed, 4 Sep 2019 19:54:13 +0200 Message-Id: <20190904175309.207549490@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: John Garry commit 0a27142bd1ee259e24a0be2b0133e5ca5df8da91 upstream. The code was originally written to not support unregistering logical PIO regions. To accommodate supporting unregistering logical PIO regions, subtly modify LOGIC_PIO_CPU_MMIO region registration code, such that the "end" of the registered regions is the "end" of the last region, and not the sum of the sizes of all the registered regions. Cc: stable@vger.kernel.org Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- lib/logic_pio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -35,7 +35,7 @@ int logic_pio_register_range(struct logi struct logic_pio_hwaddr *range; resource_size_t start; resource_size_t end; - resource_size_t mmio_sz = 0; + resource_size_t mmio_end = 0; resource_size_t iio_sz = MMIO_UPPER_LIMIT; int ret = 0; @@ -56,7 +56,7 @@ int logic_pio_register_range(struct logi /* for MMIO ranges we need to check for overlap */ if (start >= range->hw_start + range->size || end < range->hw_start) { - mmio_sz += range->size; + mmio_end = range->io_start + range->size; } else { ret = -EFAULT; goto end_register; @@ -69,16 +69,16 @@ int logic_pio_register_range(struct logi /* range not registered yet, check for available space */ if (new_range->flags == LOGIC_PIO_CPU_MMIO) { - if (mmio_sz + new_range->size - 1 > MMIO_UPPER_LIMIT) { + if (mmio_end + new_range->size - 1 > MMIO_UPPER_LIMIT) { /* if it's too big check if 64K space can be reserved */ - if (mmio_sz + SZ_64K - 1 > MMIO_UPPER_LIMIT) { + if (mmio_end + SZ_64K - 1 > MMIO_UPPER_LIMIT) { ret = -E2BIG; goto end_register; } new_range->size = SZ_64K; pr_warn("Requested IO range too big, new size set to 64K\n"); } - new_range->io_start = mmio_sz; + new_range->io_start = mmio_end; } else if (new_range->flags == LOGIC_PIO_INDIRECT) { if (iio_sz + new_range->size - 1 > IO_SPACE_LIMIT) { ret = -E2BIG; From patchwork Wed Sep 4 17:54:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172948 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp1045114ocp; Wed, 4 Sep 2019 11:08:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0HLvCD3r9geQfbhFlDTlyN/bhSpVvtpOVfoDRQjnLbWgsCwOzuxAj8zyeIEBny35C+Ph0 X-Received: by 2002:a17:90a:890c:: with SMTP id u12mr6282018pjn.124.1567620494795; Wed, 04 Sep 2019 11:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620494; cv=none; d=google.com; s=arc-20160816; b=Gs2HgtA7xFtoOPbgsifq/GTRZ7GpuZDyR8PGyPOTXIz+Sv6n7reASvIXs1bLIT0qtq vOCSR+jnQZ8x9nVYS/HtpPvVySRDTp4HHK3WiYbQz3htA+YfAE1VFpbnbpMS0hEp+dV7 nzfY0Q6SIiu5/bPWDBSw1NxWEr+30duADKP2QhV5aAonX9SAaneFSuO9RceWQCTYZ6JS HrDbbJ8BlMvHZBq4r3CqAEAwhcOXQ1P9FvAG2Msg6G14+XFof0F7u06WdsFCSx1ik+bg jEYhGSfrXlTtIqYA8eayWDwEd5e/Izk0fHUnvC2t7RT0wYkodAiLCJN9V1lf90O7MdQH t9ng== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XdXUDPO7PBdPU/JWNleo80P/EVIa9FNIOwNZKATB/vA=; b=igLPdLL2IyRwwGG9KvGK3rRreOqqUP7pcT1yx3fOG1OmnQ6BSOSejrO3bCmLoN6uqv H44qGlCJQm5FNcOLNFVRQ+RClMQ2d9M+lXuCo/IWiskdYaO8z32PBMXyZc/qmCh/Hq+4 VfpmIDjALyuTVC7Sw/uDcRnJ/61frBsuwxR2MVCoVbP/dUTHDPJ/IlctL/obEmRSx4AQ 8FWjSCFDiSbupHtFpVo7JOcsRDDeolOHvUuzI7/UA6P5BiY8W1e+u8aFkkj2wOsU9aN1 2TWmPNw8p05XJBQwe54jTypcOISvymTXJ3Uycws9HuXs8c0Mv6iLcaLxDgnkq6p3xG4H tYtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AmXz9VW6; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 d13si18568571pgu.268.2019.09.04.11.08.14; Wed, 04 Sep 2019 11:08:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@kernel.org header.s=default header.b=AmXz9VW6; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389128AbfIDSIN (ORCPT + 14 others); Wed, 4 Sep 2019 14:08:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:50952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389734AbfIDSIM (ORCPT ); Wed, 4 Sep 2019 14:08:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E89942087E; Wed, 4 Sep 2019 18:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620491; bh=FCQ49UyAnellf/2lRQYhfrCi+V/oPwiaJ/v5oINvU/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmXz9VW6FatDNjkrZPMIJUq5/X6yMrsAAL7bKeCmxR/pVAsb2yr/sCOetwkV/fJdS E6VqBH4gvA6g8yyObg+MoCZ7jbLmjXrrNY6Yj8x+UMKZeL9rZ8CxTpBN7r7g2NKPOd riYXkU3sV+ZGVa3jLZ+k+8YQl8TMIaMK+uwSCJek= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 4.19 77/93] bus: hisi_lpc: Add .remove method to avoid driver unbind crash Date: Wed, 4 Sep 2019 19:54:19 +0200 Message-Id: <20190904175309.744840990@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: John Garry commit 10e62b47973b0b0ceda076255bcb147b83e20517 upstream. The original driver author seemed to be under the impression that a driver cannot be removed if it does not have a .remove method. Or maybe if it is a built-in platform driver. This is not true. This crash can be created: root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1 Unable to handle kernel paging request at virtual address ffff000010035010 Mem abort info: ESR = 0x96000047 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000047 CM = 0, WnR = 1 swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000 [ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000 Internal error: Oops: 96000047 [#1] PREEMPT SMP Modules linked in: CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198 Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018 pstate: 20000085 (nzCv daIf -PAN -UAO) pc : hisi_lpc_target_in+0x7c/0x120 lr : hisi_lpc_target_in+0x70/0x120 sp : ffff00001efe3930 x29: ffff00001efe3930 x28: ffff841f9f599200 x27: 0000000000000002 x26: 0000000000000000 x25: 0000000000000080 x24: 00000000000000e4 x23: 0000000000000000 x22: 0000000000000064 x21: ffff801fb667d280 x20: 0000000000000001 x19: ffff00001efe39ac x18: 0000000000000000 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 x8 : ffff841febe60340 x7 : ffff801fb55c52e8 x6 : 0000000000000000 x5 : 0000000000ffc0e3 x4 : 0000000000000001 x3 : ffff801fb667d280 x2 : 0000000000000001 x1 : ffff000010035010 x0 : ffff000010035000 Call trace: hisi_lpc_target_in+0x7c/0x120 hisi_lpc_comm_in+0x88/0x98 logic_inb+0x5c/0xb8 port_inb+0x18/0x20 bt_event+0x38/0x808 smi_event_handler+0x4c/0x5a0 check_start_timer_thread.part.4+0x40/0x58 sender+0x78/0x88 smi_send.isra.6+0x94/0x108 i_ipmi_request+0x2c4/0x8f8 ipmi_request_settime+0x124/0x160 handle_send_req+0x19c/0x208 ipmi_ioctl+0x2c0/0x990 do_vfs_ioctl+0xb8/0x8f8 ksys_ioctl+0x80/0xb8 __arm64_sys_ioctl+0x1c/0x28 el0_svc_common.constprop.0+0x64/0x160 el0_svc_handler+0x28/0x78 el0_svc+0x8/0xc Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034) ---[ end trace aa842b86af7069e4 ]--- The problem here is that the host goes away but the associated logical PIO region remains registered, as do the children devices. Fix by adding a .remove method to tidy-up by removing the child devices and unregistering the logical PIO region. Cc: stable@vger.kernel.org Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- drivers/bus/hisi_lpc.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -456,6 +456,17 @@ struct hisi_lpc_acpi_cell { size_t pdata_size; }; +static void hisi_lpc_acpi_remove(struct device *hostdev) +{ + struct acpi_device *adev = ACPI_COMPANION(hostdev); + struct acpi_device *child; + + device_for_each_child(hostdev, NULL, hisi_lpc_acpi_remove_subdev); + + list_for_each_entry(child, &adev->children, node) + acpi_device_clear_enumerated(child); +} + /* * hisi_lpc_acpi_probe - probe children for ACPI FW * @hostdev: LPC host device pointer @@ -556,8 +567,7 @@ static int hisi_lpc_acpi_probe(struct de return 0; fail: - device_for_each_child(hostdev, NULL, - hisi_lpc_acpi_remove_subdev); + hisi_lpc_acpi_remove(hostdev); return ret; } @@ -570,6 +580,10 @@ static int hisi_lpc_acpi_probe(struct de { return -ENODEV; } + +static void hisi_lpc_acpi_remove(struct device *hostdev) +{ +} #endif // CONFIG_ACPI /* @@ -627,6 +641,8 @@ static int hisi_lpc_probe(struct platfor return ret; } + dev_set_drvdata(dev, lpcdev); + io_end = lpcdev->io_host->io_start + lpcdev->io_host->size; dev_info(dev, "registered range [%pa - %pa]\n", &lpcdev->io_host->io_start, &io_end); @@ -634,6 +650,23 @@ static int hisi_lpc_probe(struct platfor return ret; } +static int hisi_lpc_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct acpi_device *acpi_device = ACPI_COMPANION(dev); + struct hisi_lpc_dev *lpcdev = dev_get_drvdata(dev); + struct logic_pio_hwaddr *range = lpcdev->io_host; + + if (acpi_device) + hisi_lpc_acpi_remove(dev); + else + of_platform_depopulate(dev); + + logic_pio_unregister_range(range); + + return 0; +} + static const struct of_device_id hisi_lpc_of_match[] = { { .compatible = "hisilicon,hip06-lpc", }, { .compatible = "hisilicon,hip07-lpc", }, @@ -647,5 +680,6 @@ static struct platform_driver hisi_lpc_d .acpi_match_table = ACPI_PTR(hisi_lpc_acpi_match), }, .probe = hisi_lpc_probe, + .remove = hisi_lpc_remove, }; builtin_platform_driver(hisi_lpc_driver);