Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1283072ybg; Tue, 2 Jun 2020 06:11:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD4hu1hVSPzUJ++EaJetozwC213z5NN4KQSuudtB4OHM0lmhNbMN2MwGQTH/42fVZdHlEF X-Received: by 2002:aa7:c541:: with SMTP id s1mr14137935edr.167.1591103496201; Tue, 02 Jun 2020 06:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591103496; cv=none; d=google.com; s=arc-20160816; b=rt061bGhRYoD3p49dX5zqneYavVCz84PM3ru2bb+dubZv/es9TXLhZGFeIt9mx5QbU 8GQJt6WV9keF0YZTycRJF1Ssu1jarmJctBfgOEg2RiAe2bx+172MFy4K2n7wnV1gPYiM nAIjuF52m+ghUwDDhDz0iPpvItXvDA/etGL7quqk0RhqgjDJY80CaproEiG+ow5Gd9ir kHReSr0lVEM6owFnEacVgFK3TL0jJBxxnAsmi1YJTzrIYukTKJq6uC1s+vOOm6kjDlAd opO/s5pfprvijhvAAnk3X84GUtpX+epnUtBW3TmH1zFrW+7iyWBQCvBCqJm64UQB+DqB f9aQ== 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 :message-id:date:subject:cc:to:from; bh=nEWOKqb1Y46MOUiw10fzrN+lVeX+F+sRIprOB6ot/nQ=; b=UPJ6DZ/PuwjvXRpkphYNLAAe2ru1tJNBI7LllfBp+PpeEUMImiqDBibkhA2g7Wpcwd ZGHr2sPwPOo8UJT8vmFvSeHpdaKstzkTl0EE8K04/LJArTkKXUXIPBDH86KnY3yMv6ov upD9NbB8WUyut4U/LSahYpM7Y6bG+2g+M/cOiiMpURt4KkklCRMNBAHz7bPGHvxaw78y 9OS+F/U/2Gsma0g4UklK214l74HS7oFa2trEYa5CcsTQ/FgTpSffoWaXQVHm4762/Tx7 Wd3jzGK03D2eUW4c8q0Uo/59sUMD6vqq4TSvI5FMfgESr6GNcsNUol30cpDOpYgzSsv0 T8pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do13si246669ejc.328.2020.06.02.06.11.12; Tue, 02 Jun 2020 06:11:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728648AbgFBNIc (ORCPT + 99 others); Tue, 2 Jun 2020 09:08:32 -0400 Received: from foss.arm.com ([217.140.110.172]:50730 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727769AbgFBNI1 (ORCPT ); Tue, 2 Jun 2020 09:08:27 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8A1991FB; Tue, 2 Jun 2020 06:08:26 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C373F3F305; Tue, 2 Jun 2020 06:08:25 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Prakash Gupta Subject: [PATCH] iommu/iova: Don't BUG on invalid PFNs Date: Tue, 2 Jun 2020 14:08:18 +0100 Message-Id: X-Mailer: git-send-email 2.23.0.dirty MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 0e6a9536eca6..612cbf668adf 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); } -- 2.23.0.dirty