From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CD20C433E1 for ; Fri, 21 Aug 2020 16:45:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58A4D20732 for ; Fri, 21 Aug 2020 16:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598028351; bh=EC0gZpwbVWyRCJJFNNRf8jvNqjXRs7By//WD6ow1/qg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=cdfvwbfRcf5+yyGkB87VwYHshzTi2ze9TNc66wrfrfDhrKEMAzgSAtwImKgwLzMkQ HS4sRWaNlGBMZiJlU5b38YKJbNiAco0/q+AtSefZrIRdvj8tmUsBBpwGeAE3eFNMhR LaplCJicO6dwkEy6IaJvnm+NrqLdkUJHNgLq0xQo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728630AbgHUQpr (ORCPT ); Fri, 21 Aug 2020 12:45:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:49958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728387AbgHUQUl (ORCPT ); Fri, 21 Aug 2020 12:20:41 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E249B22CAD; Fri, 21 Aug 2020 16:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598026786; bh=EC0gZpwbVWyRCJJFNNRf8jvNqjXRs7By//WD6ow1/qg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kwLaDLrbj1pgGwCbTrhoI8Db6AzNG5w4ikQKlP32Iez32JcEyaCz2pjHjrCVFW2pT gSjl85WVgPWq03o89T/XDBtC01IUMcY32IbD8JhL7j5+vpBIpdmg7VdFOWi6YhgxrE 58AnSKtLc9BM55yKf8J4T+P1hSBk4gRhduOqtv00= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Robin Murphy , Prakash Gupta , Joerg Roedel , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.9 06/26] iommu/iova: Don't BUG on invalid PFNs Date: Fri, 21 Aug 2020 12:19:17 -0400 Message-Id: <20200821161938.349246-6-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821161938.349246-1-sashal@kernel.org> References: <20200821161938.349246-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy [ Upstream commit d3e3d2be688b4b5864538de61e750721a311e4fc ] Unlike the other instances which represent a complete loss of consistency within the rcache mechanism itself, or a fundamental and obvious misconfiguration by an IOMMU driver, the BUG_ON() in iova_magazine_free_pfns() can be provoked at more or less any time in a "spooky action-at-a-distance" manner by any old device driver passing nonsense to dma_unmap_*() which then propagates through to queue_iova(). Not only is this well outside the IOVA layer's control, it's also nowhere near fatal enough to justify panicking anyway - all that really achieves is to make debugging the offending driver more difficult. Let's simply WARN and otherwise ignore bogus PFNs. Reported-by: Prakash Gupta Signed-off-by: Robin Murphy Reviewed-by: Prakash Gupta Link: https://lore.kernel.org/r/acbd2d092b42738a03a21b417ce64e27f8c91c86.1591103298.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/iova.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index f106fd9782bfb..99c36a5438a75 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -676,7 +676,9 @@ iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad) for (i = 0 ; i < mag->size; ++i) { struct iova *iova = private_find_iova(iovad, mag->pfns[i]); - BUG_ON(!iova); + if (WARN_ON(!iova)) + continue; + private_free_iova(iovad, iova); } -- 2.25.1