From patchwork Thu Jun 20 10:31:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167319 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1665110ock; Thu, 20 Jun 2019 03:33:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWyHamKtxssgq3xopzGjcaZfQtcdbuVFwXvFj5pW7dsbN38r25L7JRu7y+VLVrBw90kd+B X-Received: by 2002:a17:902:2ac1:: with SMTP id j59mr51608455plb.156.1561026830881; Thu, 20 Jun 2019 03:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026830; cv=none; d=google.com; s=arc-20160816; b=fymf1J4BXCxgILlqEK3gqiJmHJVA3QKDZHBhkWtuJf7sE4MZr8OubMOC7rNnmIf/bJ fJvOUCQ+2zcv2Awzijkz7U1sGoNDmi3AL2jqNe+HH+YvynhjsVahozCSlfxqMEx2C9El pjh1XiYo4vdFCLV5tVrEJg0FaPj2kXLAQZMFCy3PwjRdElH1wVqIPtPxd9NmD5wtr1L0 7Gdb0Tic1ua84sD5YzlM5tzgLJw8em4FkWQQOCeWvSF7IoL1fE5tjnZmVCFdRvjI84tJ iWq0mCJasKFT1nNrrkgmzC4Y4ugHgtzPIjtALgncEJR9FoJw77VSzYL8jZQ6iQ+tFfqZ JFAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=UMZBBxhCxyq/H17OTQJCxe8hzLSN635qoo/+Hf+lFPw=; b=JS4Pc9q59FgoxMwIHeujDacGY/apv2Ses3+U0UlPjsjgOdGCiAxaipwbSWkhU87LMq pmOeRQSXjfu0frIeqqJsxeTowzSkzBp5k0AUOXonm3O8S7DcGKqggjTn9eA0UVJ4oJMV 8u4PNoQ9q4hVeWema9oxnDvBPoWWrPLPBUNadWfP7O8EvlXG7EjF4eeHCtxE/nBU6nsn lf4bDzeVmDHgBhB4sd1amAtGIU2TwOaUbyOznco7yh7MDuDc5YkpOl4lPxSD0QMsCwyQ C0HyzAoQOTfCL9CJ+fOAzV8yCLQEmv/LQSCwueHhFw1RCLo0TMR0N4xe7SokDpGaMkQ2 64vg== 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 h2si19445599plh.380.2019.06.20.03.33.50; Thu, 20 Jun 2019 03:33:50 -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 S1731380AbfFTKdg (ORCPT + 30 others); Thu, 20 Jun 2019 06:33:36 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18648 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726345AbfFTKdf (ORCPT ); Thu, 20 Jun 2019 06:33:35 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id EC3BFE25D40905185C3B; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:25 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 1/5] lib: logic_pio: Fix RCU usage Date: Thu, 20 Jun 2019 18:31:52 +0800 Message-ID: <1561026716-140537-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The traversing of io_range_list with list_for_each_entry_rcu() is not properly protected by rcu_read_lock(), so add it. In addition, the list traversing used in logic_pio_register_range() does not need to use the rcu variant. Fixes: 031e3601869c ("lib: Add generic PIO mapping method") Signed-off-by: John Garry --- lib/logic_pio.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/lib/logic_pio.c b/lib/logic_pio.c index feea48fd1a0d..761296376fbc 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -46,7 +46,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) end = new_range->hw_start + new_range->size; mutex_lock(&io_range_mutex); - list_for_each_entry_rcu(range, &io_range_list, list) { + list_for_each_entry(range, &io_range_list, list) { if (range->fwnode == new_range->fwnode) { /* range already there */ goto end_register; @@ -108,26 +108,38 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) */ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode) { - struct logic_pio_hwaddr *range; + struct logic_pio_hwaddr *range, *found_range = NULL; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { - if (range->fwnode == fwnode) - return range; + if (range->fwnode == fwnode) { + found_range = range; + break; + } } - return NULL; + rcu_read_unlock(); + + return found_range; } /* Return a registered range given an input PIO token */ static struct logic_pio_hwaddr *find_io_range(unsigned long pio) { - struct logic_pio_hwaddr *range; + struct logic_pio_hwaddr *range, *found_range = NULL; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { - if (in_range(pio, range->io_start, range->size)) - return range; + if (in_range(pio, range->io_start, range->size)) { + found_range = range; + break; + } } - pr_err("PIO entry token %lx invalid\n", pio); - return NULL; + rcu_read_unlock(); + + if (!found_range) + pr_err("PIO entry token 0x%lx invalid\n", pio); + + return found_range; } /** @@ -180,14 +192,23 @@ unsigned long logic_pio_trans_cpuaddr(resource_size_t addr) { struct logic_pio_hwaddr *range; + rcu_read_lock(); list_for_each_entry_rcu(range, &io_range_list, list) { if (range->flags != LOGIC_PIO_CPU_MMIO) continue; - if (in_range(addr, range->hw_start, range->size)) - return addr - range->hw_start + range->io_start; + if (in_range(addr, range->hw_start, range->size)) { + unsigned long cpuaddr; + + cpuaddr = addr - range->hw_start + range->io_start; + + rcu_read_unlock(); + return cpuaddr; + } } - pr_err("addr %llx not registered in io_range_list\n", - (unsigned long long) addr); + rcu_read_unlock(); + + pr_err("addr %pa not registered in io_range_list\n", &addr); + return ~0UL; } From patchwork Thu Jun 20 10:31:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167320 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1665157ock; Thu, 20 Jun 2019 03:33:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKjuPW3Y2NfST522ekIY7kCLUHGsWNMAnt1DzHs/BRDUX1dEFH8PTjVwjUIMBQfX9OXC48 X-Received: by 2002:a17:902:b18f:: with SMTP id s15mr127886821plr.44.1561026834379; Thu, 20 Jun 2019 03:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026834; cv=none; d=google.com; s=arc-20160816; b=FxpMSmlkcRoiQFYDgG3RU8duJWrVqoClmg+WeL3GzjdKkzUKqyObPoCI4d/QFjJh2y xo6/AQ0B9QgEJBKDETZbZ/gX9ZgX98ttulsnKQF0Thq+YVa38P1bVdc9YalkaydvyBk5 8//M52OTvsttuWXi7Tkii1CJERTFLa48cQ+s36tdmd3C8CCrGXve+MBbGQJmyaUG+qTU EBSC1F7EduoDfTIxN5Dn+5/p30RdeyldDcXYczy9QFVTHvgBtwPwjyvIJJjFwmpsS3pu 1qAHB1U3sImNTSvY+pKKISII5o+jtt+7Tf5KTj+I84iZyV9KViQXEwnFmw1vOfre+H/7 vqGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=t7bnCQfvAaHuKMaLWXxi2TlfK6/J6DxUM2Yfv6Bfz4M=; b=A7tWUjrPXK3a1AkehQe84OtTffjg8vkV3/uTQzQesJoaKCjDcvqeKKE3s4ppks1biy SF3nzW3xG4iIvHnG3OPpUWZSCIqZftsK9Y8HXGmNqwmcei+v+ia80PQUNQz9HPf3qaXb FCq1rePKKjBOYEONImqMhpBnES5sTHriv77sJNx7jgvsBeMlQ0f1Vmgy5JuMkwUTN4RN t2JsdivPE7NXa7jLZDHdhWt1LkPq+ytQQAQWI0gLQ/Fkjyifv77sEBz6f8OiXrJQZmd/ T4NtMNmB0B4ZmbYprzyOECYOL4HEoINy1xqkWIYxDJmG53/ff6rJLA0NSTraqQu3Go/A PC4A== 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 a10si5338276pgq.194.2019.06.20.03.33.54; Thu, 20 Jun 2019 03:33:54 -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 S1731164AbfFTKdf (ORCPT + 30 others); Thu, 20 Jun 2019 06:33:35 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18647 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726222AbfFTKdf (ORCPT ); Thu, 20 Jun 2019 06:33:35 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D286968E86C6D27CF9A1; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:25 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 2/5] lib: logic_pio: Add logic_pio_unregister_range() Date: Thu, 20 Jun 2019 18:31:53 +0800 Message-ID: <1561026716-140537-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function to unregister a logical PIO range. The method used to allocate LOGIC_PIO_CPU_MMIO regions during registration is slightly modified to ensure that we get no overlap when regions are unregistered. This is needed because the allocation scheme assumed that no regions are ever unregistered. Logical PIO space can still be leaked when unregistering certain LOGIC_PIO_CPU_MMIO regions, but this acceptable for now since there are no callers to unregister LOGIC_PIO_CPU_MMIO regions, and the logical PIO region allocation scheme would need significant work to improve this. Signed-off-by: John Garry --- include/linux/logic_pio.h | 1 + lib/logic_pio.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h index cbd9d8495690..88e1e6304a71 100644 --- a/include/linux/logic_pio.h +++ b/include/linux/logic_pio.h @@ -117,6 +117,7 @@ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode); unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode, resource_size_t hw_addr, resource_size_t size); int logic_pio_register_range(struct logic_pio_hwaddr *newrange); +void logic_pio_unregister_range(struct logic_pio_hwaddr *range); resource_size_t logic_pio_to_hwaddr(unsigned long pio); unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr); diff --git a/lib/logic_pio.c b/lib/logic_pio.c index 761296376fbc..45eb57af2574 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -56,7 +56,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) /* 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_sz = range->io_start + range->size; } else { ret = -EFAULT; goto end_register; @@ -98,6 +98,20 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) return ret; } +/** + * logic_pio_unregister_range - unregister logical PIO range for a host + * @range: pointer to the IO range which has been already registered. + * + * Unregister a previously-registered IO range node. + */ +void logic_pio_unregister_range(struct logic_pio_hwaddr *range) +{ + mutex_lock(&io_range_mutex); + list_del_rcu(&range->list); + mutex_unlock(&io_range_mutex); + synchronize_rcu(); +} + /** * find_io_range_by_fwnode - find logical PIO range for given FW node * @fwnode: FW node handle associated with logical PIO range From patchwork Thu Jun 20 10:31:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167321 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1665202ock; Thu, 20 Jun 2019 03:33:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7UZbzG+m0j7zVeTaygTRnxhFDXIxFoQinogAojHa+lYCs9egbts/F8D+WsTDlQxufetWm X-Received: by 2002:a17:90a:b903:: with SMTP id p3mr2318320pjr.79.1561026837107; Thu, 20 Jun 2019 03:33:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026837; cv=none; d=google.com; s=arc-20160816; b=Rz/7AhptebzY+qINJNG7Lj31FQrNV0bw935FJ58P8lKfz4FY2hnbG8jnAgxyG+i5sL xRm09KlszVfB4D2PXQ4a5HcdYF8GciTBMYtG9hf7wVsFQ/T5nqrKIO5e+g6my68d6cHi Jpnp7G3OAOfoh6dN0gpT+k92ZZZg/Wc6v5+Y9yzzy7cPGPSeMQNGo1ypWgCX0hWgpVBB MwlCwrO76CXKBejWgfQFM37X1TRww3ijd97HNPuqq+YeIQ/zeBN1evZmin2KFVmDEcKr mYXZag7Ku9KN9GUQ2TKd20BQPFh1dTmKNzTUKUc2HEv2k9ZBoNVynBZQhr5B9YZxrmOq Nekw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=/V1IWL280c+6QECD0i6Sq1jjHPccUq/RMQJVBUUXt8M=; b=zzuWCyqGyBMYm2SieNaQm89XO7O+kSBKpgJc05aOka5TdapKRUEWZ5CXZKyOYI6aQ4 hUyI/+PULT3u8pdFpV8PHlnPFisOTM+H2Hg2nuFF6WaYC9Zm0O0TOXzaZUkl9aLkPcCq G65eLY1vyZokmtwwxyos8g48P1L4lNoC95Lr55Ryn+5zCVfsMCtockYr57kXitbqDqXT DDXgsAt13GHcCAdI+5AdcN7UUnQ1/EYRx3K8IzD2blJqqxhpNmvCQ6hmu+Qz7oZEhdk2 0FaW0eOCNDWblt9F3FmTCE89zwj8kaUQm93H8DfoFjvJNhEeRT0B9IWTlN9kK6MiD4bW 0btw== 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 t4si18949064pfh.261.2019.06.20.03.33.56; Thu, 20 Jun 2019 03:33:57 -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 S1731617AbfFTKdz (ORCPT + 30 others); Thu, 20 Jun 2019 06:33:55 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18649 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726620AbfFTKdg (ORCPT ); Thu, 20 Jun 2019 06:33:36 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E24B49282C1C1A264A80; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:26 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 3/5] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Thu, 20 Jun 2019 18:31:54 +0800 Message-ID: <1561026716-140537-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If, after registering a logical PIO range, the driver probe later fails, the logical PIO range memory will be released automatically. This causes an issue, in that the logical PIO range is not unregistered and the released range memory may be later referenced. Fix by unregistering the logical PIO range. And since we now unregister the logical PIO range for probe failure, avoid the special ordering of setting logical PIO range ops, which was a previous (poor) attempt at a safeguard against this. Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 19d7b6ff2f17..6d301aafcad2 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -606,24 +606,25 @@ static int hisi_lpc_probe(struct platform_device *pdev) range->fwnode = dev->fwnode; range->flags = LOGIC_PIO_INDIRECT; range->size = PIO_INDIRECT_SIZE; + range->hostdata = lpcdev; + range->ops = &hisi_lpc_ops; + lpcdev->io_host = range; ret = logic_pio_register_range(range); if (ret) { dev_err(dev, "register IO range failed (%d)!\n", ret); return ret; } - lpcdev->io_host = range; /* register the LPC host PIO resources */ if (acpi_device) ret = hisi_lpc_acpi_probe(dev); else ret = of_platform_populate(dev->of_node, NULL, NULL, dev); - if (ret) + if (ret) { + logic_pio_unregister_range(range); return ret; - - lpcdev->io_host->hostdata = lpcdev; - lpcdev->io_host->ops = &hisi_lpc_ops; + } io_end = lpcdev->io_host->io_start + lpcdev->io_host->size; dev_info(dev, "registered range [%pa - %pa]\n", From patchwork Thu Jun 20 10:31:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167317 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1665004ock; Thu, 20 Jun 2019 03:33:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDQRxroGe+f8lpkMnhnLnK/r9QQk2jbgSIiZtkunynT6qCAjdAvwQKOTLqhO4RP/LmlP9z X-Received: by 2002:a62:e910:: with SMTP id j16mr28335669pfh.123.1561026822649; Thu, 20 Jun 2019 03:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026822; cv=none; d=google.com; s=arc-20160816; b=JwiVwf8MYMnON7buZmNqu96f4LlJNU8vEjt+J/8alS2F45SlQey4H1ZKHgE9TzfHvq yqkmwqLY1K7MuPBXJKo+09iNEYG/bsezT0Ic/xxeBFhQDF3ZEiWJc3zD7zxC2dOzqWC/ iPoVdq7c5xUKfUYRCCqKpXwrTyBFOsw8AdPoSuaTWHaE16BBsFkwj3Ir5s4vXk468Ef6 PmEbjlkxvDlx1a+EnB7M+7T9rt3AIfbtAif/n6l0EQ0XUCzyJRhXPHgwKmpZddc7/OWz i/gvk9Q+WTBNlYTBsA61xTvi2o75XtiCFwgpiv0zGVKMaWYlAcFTtRt1ichpR8TnU/cP HYgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ta+NRQcA1wumpPFE5rSDQql9RlIhpY74xnzbHacfSJo=; b=x6H0RqbFwDn85+bIrz8OKhp7+aq+1p/yMUEtXhPkDdIPlhvNJHSrFiP+xBhp1pL0or 44y6uvb41uKjI4OcGfCWSch6hxwihdCj0brD+tkMszr1FlyFGPYvXBcW2Evkija5PYQH sWRwmuoQRH70/UpuTHHTxKlDrbFN0uJmECXHaF5kPk7WnSUp1QtyMtdOQdF1Agdl4+AV A/R0ku97Y2KlqkLeK6JipMNJNJmA7V9GnWb7wNTIhj8+B/ioYi9C9zN367/P6hfDxaVL 2jYnzAhnBlp486uEQuOohkKKEoq3KE/5LIQMW7/Rcq+lq0stguQHI8h7zOvFlYed+aIr KyEw== 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 f17si5513824pgv.338.2019.06.20.03.33.42; Thu, 20 Jun 2019 03:33:42 -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 S1731563AbfFTKdk (ORCPT + 30 others); Thu, 20 Jun 2019 06:33:40 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18646 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726081AbfFTKdf (ORCPT ); Thu, 20 Jun 2019 06:33:35 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DCC7BD826ACA1CC4E4BC; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:26 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 4/5] bus: hisi_lpc: Add .remove method to avoid driver unbind crash Date: Thu, 20 Jun 2019 18:31:55 +0800 Message-ID: <1561026716-140537-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 child devices. Fix by adding a .remove method to tidy-up by removing the child devices and unregistering the logical PIO region. Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 6d301aafcad2..0e9f1f141c93 100644 --- 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 @@ -555,8 +566,7 @@ static int hisi_lpc_acpi_probe(struct device *hostdev) return 0; fail: - device_for_each_child(hostdev, NULL, - hisi_lpc_acpi_remove_subdev); + hisi_lpc_acpi_remove(hostdev); return ret; } @@ -626,6 +636,8 @@ static int hisi_lpc_probe(struct platform_device *pdev) 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); @@ -633,6 +645,23 @@ static int hisi_lpc_probe(struct platform_device *pdev) 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", }, @@ -646,5 +675,6 @@ static struct platform_driver hisi_lpc_driver = { .acpi_match_table = ACPI_PTR(hisi_lpc_acpi_match), }, .probe = hisi_lpc_probe, + .remove = hisi_lpc_remove, }; builtin_platform_driver(hisi_lpc_driver); From patchwork Thu Jun 20 10:31:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167316 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1664951ock; Thu, 20 Jun 2019 03:33:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1DyT9DT6V1wHISxwm3CgOkdkEbSupFzM7N5lQTahVFEfbCpsA0Pj/6raa+1t96wfFNqaB X-Received: by 2002:a17:90a:2023:: with SMTP id n32mr2285091pjc.3.1561026819458; Thu, 20 Jun 2019 03:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026819; cv=none; d=google.com; s=arc-20160816; b=JWE7iTMvMjpdQhpLYMLWr+W1vIoE6W0Ykf6oOnOsNM0RMisnX+BvIEvIExWAHLvCf6 PPVIM+7aAjA0q/J4347XleydtKaclWQsY0NCbZIMNzIp6ndibgv8PMLbGyKFTeuE53jL sihQMSvwAj0qNjGLqdPxjpvH8iMmbJZwCywo+dBUwyUUZvfp6pQT2D265+U3y8FfZBrT SY4jqNcfLd1eeVy4YiEdW5F2zZbdcsQ6kLWkVo7vILTj3bVZzN0OgKHiAOBi/4rEqMoc WZwR5wqm5LNOEyuh7xozlEPIopFrXkxqmpTW4PtAb/a5/bLQsJuAPKwxKs3k6l7/sSC8 G2sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=FKjysQ5JpqHo9RBQhtCAp8hsC/rFtm3k7cf+r9rYrng=; b=fApkgL0j8xJQuPxY04zRG3tBIaM4Pz9hqmv9opD+rhqLHYiB90bTFS5O5s0uvmyAlb B54BQE8nkOe1ypwREooN9528v1iazUp+j2XyOJPPY1dOgb/8Vp7Ye2W2DOKft3+h6J1i tJ28qLw0EZvRX3dwUyGOf69e9OWN8QsRJvDgaTrCWkES2Ntf/uBACwsjCVmRdGixf1nc msDC5aVcpMW/ucqphelFSAM8YLwUIvpJ+CnTU55Wo6MiQJbRQUdzb2Btx3809bJBuigU cYARCFHx/2VMSGx21czC5M+5aH30WHImBe+MN+KsNOTLn0h0OQfD9D4lH20zUqoYGQX1 iSow== 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 e30si5293774pfm.78.2019.06.20.03.33.39; Thu, 20 Jun 2019 03:33:39 -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 S1731528AbfFTKdh (ORCPT + 30 others); Thu, 20 Jun 2019 06:33:37 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18645 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726318AbfFTKdf (ORCPT ); Thu, 20 Jun 2019 06:33:35 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E76CD590D75BBE78D99E; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:26 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 5/5] lib: logic_pio: Enforce LOGIC_PIO_INDIRECT region ops are set at registration Date: Thu, 20 Jun 2019 18:31:56 +0800 Message-ID: <1561026716-140537-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the only LOGIC_PIO_INDIRECT host (hisi-lpc) now sets the ops prior to registration, enforce this check at registration instead of in the IO port accessors to simplify and marginally optimise the code. A slight misalignment is also tidied. Suggested-by: Bjorn Helgaas Signed-off-by: John Garry --- lib/logic_pio.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/lib/logic_pio.c b/lib/logic_pio.c index 45eb57af2574..126593ed9049 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -39,7 +39,8 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) resource_size_t iio_sz = MMIO_UPPER_LIMIT; int ret = 0; - if (!new_range || !new_range->fwnode || !new_range->size) + if (!new_range || !new_range->fwnode || !new_range->size || + (new_range->flags == LOGIC_PIO_INDIRECT && !new_range->ops)) return -EINVAL; start = new_range->hw_start; @@ -237,7 +238,7 @@ type logic_in##bw(unsigned long addr) \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ ret = entry->ops->in(entry->hostdata, \ addr, sizeof(type)); \ else \ @@ -253,7 +254,7 @@ void logic_out##bw(type value, unsigned long addr) \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ entry->ops->out(entry->hostdata, \ addr, value, sizeof(type)); \ else \ @@ -261,7 +262,7 @@ void logic_out##bw(type value, unsigned long addr) \ } \ } \ \ -void logic_ins##bw(unsigned long addr, void *buffer, \ +void logic_ins##bw(unsigned long addr, void *buffer, \ unsigned int count) \ { \ if (addr < MMIO_UPPER_LIMIT) { \ @@ -269,7 +270,7 @@ void logic_ins##bw(unsigned long addr, void *buffer, \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ entry->ops->ins(entry->hostdata, \ addr, buffer, sizeof(type), count); \ else \ @@ -286,7 +287,7 @@ void logic_outs##bw(unsigned long addr, const void *buffer, \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ - if (entry && entry->ops) \ + if (entry) \ entry->ops->outs(entry->hostdata, \ addr, buffer, sizeof(type), count); \ else \