From patchwork Tue Sep 1 15:08:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 310291 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.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 0A461C433E2 for ; Tue, 1 Sep 2020 16:42:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D00FE2078B for ; Tue, 1 Sep 2020 16:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598978552; bh=VZu/xCLM/zvS86LzuuApCHR8B0eir2DgfJaLNqhOAVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GdSmiztorHVLNAAYYHiqC6AstcG6J4a42LDidxfc2li9LBfKuDAquoeeEz9LtQJTR t1KiigU0lSS13CZNnx3SkRg16xWqvT+raXh6BlNGkK51iM5MB+xaBowdAfWxLznlI1 lopjA8LHzEyyGiHFlDFBeEsY7mzgaUnvVanEPB4U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730656AbgIAQma (ORCPT ); Tue, 1 Sep 2020 12:42:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:55696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729832AbgIAP16 (ORCPT ); Tue, 1 Sep 2020 11:27:58 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 80379206FA; Tue, 1 Sep 2020 15:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974076; bh=VZu/xCLM/zvS86LzuuApCHR8B0eir2DgfJaLNqhOAVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jnm3ZA+0qy8M2lo7zftZN5LHupWH/dvMCKMBvfi5JXL1o7mpDxoz3Wb576/861hHK uawOe8UkKTSF6lQ5u8ggznSXrOYfjvQ0jHwLEKRYYx4ux6Yox3f/KkNhV2nvq0fGnd GvKpf6SAhyffXKjj+wz/WVyfQfx1wz9inQzkYHLM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prakash Gupta , Robin Murphy , Joerg Roedel , Sasha Levin Subject: [PATCH 5.4 027/214] iommu/iova: Dont BUG on invalid PFNs Date: Tue, 1 Sep 2020 17:08:27 +0200 Message-Id: <20200901150954.270613348@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150952.963606936@linuxfoundation.org> References: <20200901150952.963606936@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 0e6a9536eca62..612cbf668adf8 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -811,7 +811,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); }