Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17939958ybl; Thu, 2 Jan 2020 15:12:51 -0800 (PST) X-Google-Smtp-Source: APXvYqy4JrCUrn8Uxc2X7Rd1+sBwV72vEL5kR1TKKtxiJMKOFAQZoRz1QA2okLS7ispeKdJBbv+W X-Received: by 2002:aca:2210:: with SMTP id b16mr3103220oic.32.1578006770985; Thu, 02 Jan 2020 15:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006770; cv=none; d=google.com; s=arc-20160816; b=wACneRijK1slou7BNn73w7pyKPCLEtK7l+XatD0xwsG+gPhU5D8I6n5IVosdRPXdqk 3gwMPZV8+AnnKUfESqRM/Nh3uLv0dM3bjNeai+MheiCAPkeLOh5RtfhTkW2nqWPpOLOs 8bYTeig2cUZvgDZNuByeV3N2OnP5x7aqtPhYF6o+fWRtsH6LuwpnfSFkcKpGqIQEuoX6 EOz07t6Xy/BN+NZiO7NoxOxYFxGuxn21rWdxqJ3sPqB9DGxNRw3OlCdKiJDs0r6StRph Yo3kTWsxX8gAgHTY4jzF3nHR6BVN521rF3ej4CO/U2ilnUjy7hMevB51dkrdq4XIlP27 CxBg== 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=r6/lPNf3FOM+IV01Obp3kQHeWzwdPQNF7iAeA5ddAvA=; b=Iy6PHEsNxQpe6wtydmcDHem9k8OAVLwURQLG1Trkz9Mnsi4VVf7uaUA4bVU8uGPF42 ipQzCeZQ1bPMgRMmhVRzbdH50aoMWtqYdyUhYnyKTfEvlOpPiOftWHgKmfY/sDaPXnk1 NlY5ZDJzr8w3tAXBPWJ4brceGEl1vKFhuQYpOk1+FxtTLIqxKJ4ytkDsYLD0OGuyHK8I o6oQ65D/jDp8eDzinN9Gc3JZQZSAKYZuYbXgW+IsojQGrBShOgZyqZnDZNbxTkS0kiFa FEe7uTZnGkz8n8xhEt5Zs+y0s5ascU11a/vYO7tO9SSvEH28JhKw3VjLfzYQNnGLTqco PG0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=elPd0c7Y; 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 i140si27808500oib.90.2020.01.02.15.12.39; Thu, 02 Jan 2020 15:12:50 -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; dkim=pass header.i=@kernel.org header.s=default header.b=elPd0c7Y; 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 S1729970AbgABWqA (ORCPT + 99 others); Thu, 2 Jan 2020 17:46:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:36464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730276AbgABWbW (ORCPT ); Thu, 2 Jan 2020 17:31:22 -0500 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 D2D13222C3; Thu, 2 Jan 2020 22:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004282; bh=aynnZg1Zp9sJfa60R+Dxa0s0biQO2MN521u2guWaLWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=elPd0c7Y1C42A2BxAIJTIhAuTGWmeWFqy5qG/9PAmor7yt0phheWfS9jwre0T1Q3M 0S35nGtu0fhAnYaH/Al0wNjURu8YU4jHxpwD5ccOLLMdgHMBmrivutFL3tsDa2cOdS X9p5nrgKFAeDbIW97zxoWg/fa01xNOAa7Tj6Y8Cs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thierry Reding , Joerg Roedel , Sasha Levin Subject: [PATCH 4.9 114/171] iommu/tegra-smmu: Fix page tables in > 4 GiB memory Date: Thu, 2 Jan 2020 23:07:25 +0100 Message-Id: <20200102220602.935641330@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thierry Reding [ Upstream commit 96d3ab802e4930a29a33934373157d6dff1b2c7e ] Page tables that reside in physical memory beyond the 4 GiB boundary are currently not working properly. The reason is that when the physical address for page directory entries is read, it gets truncated at 32 bits and can cause crashes when passing that address to the DMA API. Fix this by first casting the PDE value to a dma_addr_t and then using the page frame number mask for the SMMU instance to mask out the invalid bits, which are typically used for mapping attributes, etc. Signed-off-by: Thierry Reding Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/tegra-smmu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index c4eb293b1524..04cec050e42b 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -153,9 +153,9 @@ static bool smmu_dma_addr_valid(struct tegra_smmu *smmu, dma_addr_t addr) return (addr & smmu->pfn_mask) == addr; } -static dma_addr_t smmu_pde_to_dma(u32 pde) +static dma_addr_t smmu_pde_to_dma(struct tegra_smmu *smmu, u32 pde) { - return pde << 12; + return (dma_addr_t)(pde & smmu->pfn_mask) << 12; } static void smmu_flush_ptc_all(struct tegra_smmu *smmu) @@ -540,6 +540,7 @@ static u32 *tegra_smmu_pte_lookup(struct tegra_smmu_as *as, unsigned long iova, dma_addr_t *dmap) { unsigned int pd_index = iova_pd_index(iova); + struct tegra_smmu *smmu = as->smmu; struct page *pt_page; u32 *pd; @@ -548,7 +549,7 @@ static u32 *tegra_smmu_pte_lookup(struct tegra_smmu_as *as, unsigned long iova, return NULL; pd = page_address(as->pd); - *dmap = smmu_pde_to_dma(pd[pd_index]); + *dmap = smmu_pde_to_dma(smmu, pd[pd_index]); return tegra_smmu_pte_offset(pt_page, iova); } @@ -590,7 +591,7 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova, } else { u32 *pd = page_address(as->pd); - *dmap = smmu_pde_to_dma(pd[pde]); + *dmap = smmu_pde_to_dma(smmu, pd[pde]); } return tegra_smmu_pte_offset(as->pts[pde], iova); @@ -615,7 +616,7 @@ static void tegra_smmu_pte_put_use(struct tegra_smmu_as *as, unsigned long iova) if (--as->count[pde] == 0) { struct tegra_smmu *smmu = as->smmu; u32 *pd = page_address(as->pd); - dma_addr_t pte_dma = smmu_pde_to_dma(pd[pde]); + dma_addr_t pte_dma = smmu_pde_to_dma(smmu, pd[pde]); tegra_smmu_set_pde(as, iova, 0); -- 2.20.1