From patchwork Wed Sep 4 17:53:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172953 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp271480ilq; Wed, 4 Sep 2019 11:13:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5IlzN5JgHejqdAYrVoJt4VLuV/B36431yg7ntcul7o0+wy+PhZlvESrfSNly2OnbS9cOQ X-Received: by 2002:a62:86cf:: with SMTP id x198mr24951130pfd.234.1567620791195; Wed, 04 Sep 2019 11:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620791; cv=none; d=google.com; s=arc-20160816; b=Oz6myx+UC9c6WFBRP/T2fUTbaocpzdPNcczpetNdz3JWHGfgbOvM1DAvfldAaXjWrN 1NSDVHbF3XMeWVXV9yD2zLlPSfxnZMcdFkQMB3lEDdNCz3Bpu2YxcJnrU6v390NZP91X hvu85oAucADddTACREo4Tm5X5MrKVwxg6j0sVRSJ4hp5O9smT2iloIc89P3MLY1E0Xoc 5KMJustB1oWfRTBA5a4UnUWcBFs/Mu5LkNuqlKj9Yoflyyowm1+HIUdExpFpRHhYIsJs cw9OQmDKgKm5qGpx3BvSo23CnkkA/+4MsZHL0L91fmsdXtWnhui06+2xf9j2w+/X4GSi sVDg== 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=6P2FIiNl/1xVTTVcqe8WPbHwGKIPlyHc4WtOUj3ytqM=; b=WXPrBH72jR8uKe16Cz98wjQr7tQp+juWJAsh1hUWiKK5qWkVA/YC2f8BFiuTdqUrP7 mXBWLDroy6V23qo13YUmvfPE5+Hm1gRUL/l/sNcwvlpq7zy536KhLiicA5PFMlPvAFo8 8PFKtbUZXGEKBarweOXTwKiZtFfiokuJmoAncCn//PTpgQ4iSmZfoYfHSCNe1iUjY21G +Qk4oxeQ1/zCzQKqDx5iNiz2O9FtRbS/ngMOK/kE7TRXd/whB/AlUZXZ0UW2CTFdsoWp omw/f0tARE/+0unLJpgCLrhL2jmYdU3KGGyHWSZ8J4rYOHjt+BWnGrSLK2UEGAKmy4dC IFNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=losMKIiG; 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 y8si16806726pfq.15.2019.09.04.11.13.10; Wed, 04 Sep 2019 11:13:11 -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; dkim=pass header.i=@kernel.org header.s=default header.b=losMKIiG; 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 S2390631AbfIDSNK (ORCPT + 28 others); Wed, 4 Sep 2019 14:13:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:57782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389432AbfIDSNI (ORCPT ); Wed, 4 Sep 2019 14:13:08 -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 2064B208E4; Wed, 4 Sep 2019 18:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620787; bh=QfaEHryzVEL2hXwWkCzJ3WcurmZFn+JfnVJi9dnQP8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=losMKIiGeaIrMhlVfgZgve3+KoQZde7uAtUrG1a6N9Xs+L3LkFFvBgasvtl2hqO0l wwt9wXKBE0DyhBfK6Y2UqSwNc3uuz/j/WXNTWQ5QENHoYGlNe1SRH1F2kWZ22CYmWO 2NrCnM7E4ygh9MGLqCphHyvN7i28Y53lxaoMw4XU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Ulf Hansson Subject: [PATCH 5.2 094/143] mmc: sdhci-cadence: enable v4_mode to fix ADMA 64-bit addressing Date: Wed, 4 Sep 2019 19:53:57 +0200 Message-Id: <20190904175317.813874728@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Yamada commit e73a3896eaca95ea5fc895720502a3f040eb4b39 upstream. The IP datasheet says this controller is compatible with SD Host Specification Version v4.00. As it turned out, the ADMA of this IP does not work with 64-bit mode when it is in the Version 3.00 compatible mode; it understands the old 64-bit descriptor table (as defined in SDHCI v2), but the ADMA System Address Register (SDHCI_ADMA_ADDRESS) cannot point to the 64-bit address. I noticed this issue only after commit bd2e75633c80 ("dma-contiguous: use fallback alloc_pages for single pages"). Prior to that commit, dma_set_mask_and_coherent() returned the dma address that fits in 32-bit range, at least for the default arm64 configuration (arch/arm64/configs/defconfig). Now the host->adma_addr exceeds the 32-bit limit, causing the real problem for the Socionext SoCs. (As a side-note, I was also able to reproduce the issue for older kernels by turning off CONFIG_DMA_CMA.) Call sdhci_enable_v4_mode() to fix this. Cc: # v4.20+ Signed-off-by: Masahiro Yamada Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/sdhci-cadence.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/mmc/host/sdhci-cadence.c +++ b/drivers/mmc/host/sdhci-cadence.c @@ -369,6 +369,7 @@ static int sdhci_cdns_probe(struct platf host->mmc_host_ops.execute_tuning = sdhci_cdns_execute_tuning; host->mmc_host_ops.hs400_enhanced_strobe = sdhci_cdns_hs400_enhanced_strobe; + sdhci_enable_v4_mode(host); sdhci_get_of_property(pdev); From patchwork Wed Sep 4 17:54:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172958 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp274521ilq; Wed, 4 Sep 2019 11:15:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpoC5AgGjzcQglop08h9Q/ZjC+tgScbWUPR4S7uhIvoM40mNrEYewfp5Ml/MrUHEh98kZH X-Received: by 2002:a17:902:8492:: with SMTP id c18mr42891380plo.279.1567620942077; Wed, 04 Sep 2019 11:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620942; cv=none; d=google.com; s=arc-20160816; b=P+aouUqwvur7zkX5hPOAfZiuqYC8VI1lpz/LeqrDI/KGqB1YvFjBMDINezjG+XWe7K CL8l7zz6knKjzXgtjl8/b0B4ID5+s66mIaV2okkQnq+GL1x4ZFLqq+OwMODEDPMfFt7F EPFzljB1y4pZzXVrljiOMn/VCUhHqGfJlgVRsLkDM5d5fAvLsrDR9eY4jHajx4yJtiWj Cqo3WMIb4aidhsDrthWrpNCRjPIHUkMNyCr5qoAmqt/g3hPVIlmjGty5zg6RJ6vL2GT9 Hhh4qd9O2aPGHanixzSez+3Sy3D72yd1djSSHvcs17PhYcBaGikyWuYzVDTKSYjju2NP tzhg== 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=dSglE/DDokgdMKJ1GMdt6siYkdDUnpLEvwTlrPGy7QA=; b=N7+Q9+6rG+GN/HsVFBaKjNd2jkxp+5BAPAr0E59vC41Akll6V8U056R1UBaRPtAJZ+ kdcb1zCPkPC/n5hguShouQEbibxN7JCRes45VqEdqQvvNMRY3kfz48ZLXmS+Prm4DfI1 vuWYJtV2tbZGfabjWO04VvIp6q3k1dcr7gsgHuzMiJRBEmMd/3KbCmkCVOHXDcLTWTS+ EwRil/bCjg9XOO0IdHouWCcNfaghaXdlGSZBE6Zt7eLiuv9sxie/bbza3uWEnsQ8rVsi GVQCV2i5tU/VczSel4lzStu/XgaEG44kzpehgAVfV+O4i/l4DSW/lrdy5EjY7GPVp622 Tqng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MweqImoE; 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 i6si2874654pjs.13.2019.09.04.11.15.37; Wed, 04 Sep 2019 11:15: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; dkim=pass header.i=@kernel.org header.s=default header.b=MweqImoE; 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 S2390694AbfIDSP3 (ORCPT + 28 others); Wed, 4 Sep 2019 14:15:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:32774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390393AbfIDSP1 (ORCPT ); Wed, 4 Sep 2019 14:15:27 -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 E9501206BA; Wed, 4 Sep 2019 18:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620926; bh=0JTnuWsTelDkywrJ0M1VQsfCLhs1bVpfAngi0Bt8z9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MweqImoEPg3YsLtcDbAnV4A1kEfK7sFk6vBSMBPQXEZLJLFwPfTXi/nPYFaeMatAE JAsS66t2n26Oq8kTYj8mKgWJWFF8IKm/Npc48ECqs9Hf7COCa/t/HBnFSIho6saMhU aoGPUHQW8ekCw2TGTjUfCTutPiCtdVimkvr9SfPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 5.2 107/143] lib: logic_pio: Fix RCU usage Date: Wed, 4 Sep 2019 19:54:10 +0200 Message-Id: <20190904175318.588086429@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit 06709e81c668f5f56c65b806895b278517bd44e0 upstream. The traversing of io_range_list with list_for_each_entry_rcu() is not properly protected by rcu_read_lock() and rcu_read_unlock(), so add them. These functions mark the critical section scope where the list is protected for the reader, it cannot be "reclaimed". Any updater - in this case, the logical PIO registration functions - cannot update the list until the reader exits this critical section. In addition, the list traversing used in logic_pio_register_range() does not need to use the rcu variant. This is because we are already using io_range_mutex to guarantee mutual exclusion from mutating the list. Cc: stable@vger.kernel.org Fixes: 031e3601869c ("lib: Add generic PIO mapping method") Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- lib/logic_pio.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -46,7 +46,7 @@ int logic_pio_register_range(struct logi 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 @@ end_register: */ 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(re { 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 Wed Sep 4 17:54:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172959 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp274990ilq; Wed, 4 Sep 2019 11:16:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxN0k8iVK+dXMS62yyc6sAv1FZjVgP/d9Ild4YKxe0Ef2c+3TclY1fSf1Tm77Y4Mn4WsVj X-Received: by 2002:a17:90a:9907:: with SMTP id b7mr6481441pjp.101.1567620969133; Wed, 04 Sep 2019 11:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620969; cv=none; d=google.com; s=arc-20160816; b=csy+Exd9YEki3FKf+ipQ6ACWCTspjmBBJ9mFHeiYjCdcjLnU+3SKzT7l8Udr88UH+I hTLFMH9zRXUG4KJktqrLMnopp6AHKBCHzEa74ofi9Yw4eVHJtsc1cG4Q52hr5KKyZXcD kaHObl6tdqcLeEeoTT23FgIjbKAp2srb4Hh7zAhCl5eUtacoDOCixGrC59zZyUj0YY4Q Tc31ykObDuis21k2Vx6hBLhYm3M7H240peD5CUnphQ6uo9t+3qtLYiRdRdsj8+AJdboE 4NIqBeKGlY8+MeaoVCSN1QOE4vHBABQLtafLhXw8G07i9IAE+NodEBmHuv/LKWaRDBy2 64EQ== 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=CqNa40uLsrLsUj5QgcRYWprZvvnzXCV/bC5HHjMu8Zsk1cMeQhNwtoqEGjeCx9YZMZ AZxfsdSK0IU6pWmdUR4ZGfjB/b2yrIejvL0PwYvO6s3/wwQ/hIjfuARsw/5treqcRl9H N+FoRaTKKK0cBai8nrpkqSmykm83Hw2Fp9nWbXezOFPlKJ727ET8+7hs5x6HOHcGtPUA oZhiPVby/EKP/oKq1CNSi41zOJcWyWARWk5xw4m7QIDPRmihLEsxvvlRxA4gsCQQmhiG 9oe/BcmluWxE/Rjauo5ajv8GRfDDP0Ywf+TJPn6OutM3dlTVCvyHd1p31jNPjT6I4Z9K gHeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LJATrdsI; 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 i6si2874654pjs.13.2019.09.04.11.16.05; Wed, 04 Sep 2019 11:16:09 -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; dkim=pass header.i=@kernel.org header.s=default header.b=LJATrdsI; 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 S2391012AbfIDSPs (ORCPT + 28 others); Wed, 4 Sep 2019 14:15:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:32824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390393AbfIDSP3 (ORCPT ); Wed, 4 Sep 2019 14:15:29 -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 9E44F2087E; Wed, 4 Sep 2019 18:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620929; bh=UbwxphCkJgqkkmqkEGI327ZtsTfNouQD7+qWRvtcpI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LJATrdsI1qtyD4e0xUfQIx7wwktQ+SgtFjUUKeEQv+hGmdLcIyL7zmhzjIgHQ0oPv XfLqRclFriEhK0NbzqydTIW92eADE5dhR1vlZa6fHXKNqYhkT6Er/3BgD3nwuNsk3f QzY87z+Rl2R2j2MJdQDCCqAcxp9xTdhQJs9zf6cM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 5.2 108/143] lib: logic_pio: Avoid possible overlap for unregistering regions Date: Wed, 4 Sep 2019 19:54:11 +0200 Message-Id: <20190904175318.625979109@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 172955 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp272214ilq; Wed, 4 Sep 2019 11:13:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOm8LS3je4hiHTUgnsIzzbufakXMVaTDiSHiHA2DzRQeqSXNq9UfDHd6yKk9ggvInyeZaq X-Received: by 2002:aa7:998f:: with SMTP id k15mr34122137pfh.203.1567620828546; Wed, 04 Sep 2019 11:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620828; cv=none; d=google.com; s=arc-20160816; b=HDnXn1YBvlrFc58Chw1+sPnzVq2zjFMDmGzhwK5tNT+4chRcotJglN9tbwMfv4ZXp2 6qo6EjzzKMWzBDIsrQ5I0OUFPKYFng+zZvEqcPSXvLjdDM9Uu52TzUoRqHYK+J+WguxQ G7JfbifTZsx0D2/kuEmjTMqOs7jbcA5spnzdHZPTfaspe8EdNIH9UCare0SPEqCVA4UQ MZLChSUwNAgMCRMiID+s3reVADeZoZT46e29UEsgnSH2ACvHxWlBa3GMpEA+4dysLJNG hXfElMAkJnTmP+r2vd0l2LiyqgO1uBUWQZ2NsSPSGzZIUYBOE70K/bolukCQnI2AyLzE nuuw== 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=KrV8T0HaWbpbELilfw7x90MNqYHtZaqDNT2nMNqDKmg=; b=ZYHaDqK9TDBo7xr3nsi9pelkwtGio28DYEVz0JRk5bPCRjifji5O4/gYMKDxLvOdQj JXmaAea2BL/Kh33FnqEY18kWmtzwKNJIpmd8thaDJdzQRMYYIjY0gJe0jf0HYReV8l2z WwBXjK1WoD2gQEy+hk4XBui1xgqkUU6yIOgtm/bxq7Lik5e1L0xVdqwyXxJAjDAfHyTL mCfpYs55F+BJb3ubsLiXopcJ/vmvRL1fGOH4qNgpXBs9fgpqCeJJQMXwC0vgVUZDox// aAyo5QI3wIUj59SvQasxiZS1NVmwDTX96ptwBX9ZGDvuJJWrWb/tVC552Sb1a2+NRfbs SWgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g53H2+Yv; 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 e3si17464131pgv.153.2019.09.04.11.13.48; Wed, 04 Sep 2019 11:13:48 -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; dkim=pass header.i=@kernel.org header.s=default header.b=g53H2+Yv; 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 S2390341AbfIDSNq (ORCPT + 28 others); Wed, 4 Sep 2019 14:13:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:58644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389972AbfIDSNn (ORCPT ); Wed, 4 Sep 2019 14:13:43 -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 DC79D208E4; Wed, 4 Sep 2019 18:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620822; bh=izBRRnXiw9mOfutHNB06OnVP5gsPFMTfZ8E+HUYKFVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g53H2+YvJ7V0o1HGulFNEvw7tbfyLiR0ZHtfNKayhX74uZud4ELH1mJM5EtaEGhJN xW1zRsn1BRi2nIOv2t1qYReK3SPFWtx9LcAKI8hATFnE4AKIMItTvvSLtnbbAsc0W9 uGni6C+5Jz4XFwhdpotxQhyn3ble3uxF4vSc8OHs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 5.2 109/143] lib: logic_pio: Add logic_pio_unregister_range() Date: Wed, 4 Sep 2019 19:54:12 +0200 Message-Id: <20190904175318.668350121@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit b884e2de2afc68ce30f7093747378ef972dde253 upstream. Add a function to unregister a logical PIO range. 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. Cc: stable@vger.kernel.org Signed-off-by: John Garry Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- include/linux/logic_pio.h | 1 + lib/logic_pio.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) --- a/include/linux/logic_pio.h +++ b/include/linux/logic_pio.h @@ -117,6 +117,7 @@ struct logic_pio_hwaddr *find_io_range_b 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); --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -99,6 +99,20 @@ end_register: } /** + * logic_pio_unregister_range - unregister a 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 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: 172957 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp272543ilq; Wed, 4 Sep 2019 11:14:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7HQUMmCx3E/nNoEow8yJljxHsps8MxLj2md9ZBmlGrJXysXw1OUJSRkcHUaC2tGHsMn3/ X-Received: by 2002:a17:90a:f48f:: with SMTP id bx15mr1347056pjb.75.1567620845473; Wed, 04 Sep 2019 11:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620845; cv=none; d=google.com; s=arc-20160816; b=rAS65HVz0ICAQJAleZfWXcWvMOv+JvaVbmiXNhz7nQECZXjvQZtMBKXqhr22O3T87g gXVdyLJJHOHv5bE6qxwnKxOIBD/U8bP1Qu0DSpYB4HBsLse7fKDDqbrOby/unGtfVTeZ SBQzmQtQTwd44CTts0Zh46ibjPtNSZFTxQBcD3kJNu63vW5fObR1hv82ZRr6cbw7kmGd /JbRSF/q8nEu8Ho5oInLJ4zWYaWDSeOrdKOMFHfaSd4ZVMjjO87YXgiEdSTu1Ivv9Myp PbDH8nqcDsAQFU/uoRXaEI1teQNzm4LY3fEYywOL5FGxTFZMAuzBUWmWPYvu2m6LAGJ6 hUTg== 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=OQXGGo3qlOieK4g5gxbHQ9lkBibyRV5HAJswVXzk+Ps=; b=JuJX/z1g6Ttcq9eoAv12GCr9oOs/WxwsnLMw4awXso8NwWlu/SVDofP38oC8y5k/Kf PZ3MtHW4Kyo0YUF52796zcUn4v2G2sK4JqWSnduTtpPzCgvfKJFBaZhorl1X2VaFzJKr ShrWU4VfG6JYxEAOOUDW7pugCCQwMIlCHcBb43E251erlUsdm4FbnNp55Rmop3J5Ht/D 89rQV1jRvrFN+rlUdx5ba82BDQXM8BE0ayoFVcIRVrOKnnophnPSXvrF1BecTNLY9sKr uqTu0Ll1kjQjS3YqkA2MjzpDMkhcLLVgqMCB+hsMm4wenT6ZuT1KZqAZ6yjPus/kfcOa y6Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y1YjtPeh; 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 u2si17527046pgr.284.2019.09.04.11.14.05; Wed, 04 Sep 2019 11:14:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Y1YjtPeh; 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 S2390724AbfIDSOE (ORCPT + 28 others); Wed, 4 Sep 2019 14:14:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:59024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390680AbfIDSOC (ORCPT ); Wed, 4 Sep 2019 14:14:02 -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 B43A52087E; Wed, 4 Sep 2019 18:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620841; bh=8nwAokFfIT1by3nyndFKb0KCCuuMpr3W2dZs8lyiYzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y1YjtPehk01KdNfQLdZE9PomsY1sR/40Kmj9OPfeI6jp/NcQqDyWoDQN4O8WvuTNo AA8FM1mB9nZPAy6pvFo/z9hIQd2ByZ+rb6u0YfMl2N8mGHAz8XEXNnjpOYJ4mV5t5B 7QA/qQcbfpXec5RVYOrlDQZGwkp3zn78GLZUzhM0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 5.2 116/143] bus: hisi_lpc: Add .remove method to avoid driver unbind crash Date: Wed, 4 Sep 2019 19:54:19 +0200 Message-Id: <20190904175318.935451583@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -555,8 +566,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; } @@ -569,6 +579,10 @@ static int hisi_lpc_acpi_probe(struct de { return -ENODEV; } + +static void hisi_lpc_acpi_remove(struct device *hostdev) +{ +} #endif // CONFIG_ACPI /* @@ -626,6 +640,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); @@ -633,6 +649,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", }, @@ -646,5 +679,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);