Linux IOMMU Development
 help / color / mirror / Atom feed
From: <yf.wang@mediatek.com>
To: <will@kernel.org>
Cc: Guangming.Cao@mediatek.com, wsd_upstream@mediatek.com,
	linux-kernel@vger.kernel.org, Libo.Kang@mediatek.com,
	yf.wang@mediatek.com, iommu@lists.linux-foundation.org,
	linux-mediatek@lists.infradead.org, stable@vger.kernel.org,
	matthias.bgg@gmail.com, robin.murphy@arm.com,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3] iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure
Date: Tue, 7 Dec 2021 19:33:15 +0800	[thread overview]
Message-ID: <20211207113315.29109-1-yf.wang@mediatek.com> (raw)
In-Reply-To: <20211207094817.GA31382@willie-the-truck>


[-- Attachment #1.1: Type: text/html, Size: 2911 bytes --]

[-- Attachment #1.2: Type: text/plain, Size: 1925 bytes --]

From: Yunfei Wang <yf.wang@mediatek.com>

In __arm_v7s_alloc_table function:
iommu call kmem_cache_alloc to allocate page table, this function
allocate memory may fail, when kmem_cache_alloc fails to allocate
table, call virt_to_phys will be abnomal and return unexpected phys
and goto out_free, then call kmem_cache_free to release table will
trigger KE, __get_free_pages and free_pages have similar problem,
so add error handle for page table allocation failure.

Fixes: 29859aeb8a6ea ("iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE")
Signed-off-by: Yunfei Wang <yf.wang@mediatek.com>
Cc: <stable@vger.kernel.org> # 5.10.*
---
v3: Update patch
    1. Remove unnecessary log print as suggested by Will.
    2. Remove unnecessary condition check.
v2: Cc stable@vger.kernel.org
    1. This patch needs to be merged stable branch, add stable@vger.kernel.org
       in mail list.
    2. There is No new code change in v2.

---
 drivers/iommu/io-pgtable-arm-v7s.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
index bfb6acb651e5..be066c1503d3 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -246,13 +246,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
 			__GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
 	else if (lvl == 2)
 		table = kmem_cache_zalloc(data->l2_tables, gfp);
+
+	if (!table)
+		return NULL;
+
 	phys = virt_to_phys(table);
 	if (phys != (arm_v7s_iopte)phys) {
 		/* Doesn't fit in PTE */
 		dev_err(dev, "Page table does not fit in PTE: %pa", &phys);
 		goto out_free;
 	}
-	if (table && !cfg->coherent_walk) {
+	if (!cfg->coherent_walk) {
 		dma = dma_map_single(dev, table, size, DMA_TO_DEVICE);
 		if (dma_mapping_error(dev, dma))
 			goto out_free;
-- 
2.18.0

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-12-07 11:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07  2:47 [PATCH] iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure yf.wang
2021-12-07  9:48 ` Will Deacon
2021-12-07 11:33   ` yf.wang [this message]
2021-12-07 11:42     ` [PATCH v3] " Robin Murphy
2021-12-14 15:18     ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211207113315.29109-1-yf.wang@mediatek.com \
    --to=yf.wang@mediatek.com \
    --cc=Guangming.Cao@mediatek.com \
    --cc=Libo.Kang@mediatek.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=will@kernel.org \
    --cc=wsd_upstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox