Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4614541pja; Thu, 21 Nov 2019 22:53:05 -0800 (PST) X-Google-Smtp-Source: APXvYqzDA5nPjFleXdwS7qPI4uF8k6yUuDXLAQBaRHGrNX6zQIqOqjYYrPYUf+1XDjwGak+Y7rMv X-Received: by 2002:a17:906:1e16:: with SMTP id g22mr5915187ejj.78.1574405585340; Thu, 21 Nov 2019 22:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574405585; cv=none; d=google.com; s=arc-20160816; b=ka91778lWZa1SUMTAFAeDP8XFKlZ8iSrrMzFlBz9PXggNIy5zWay139r4CNG7fvRdy 687GSer2t+2r3V0nZVLiZGnyrbX/yx3VGEmt0nr2V58/v526DS0ybVCMydnuy8iSEK/6 xI46ylTWvyQPm4wtfwphOeRHLzeOOcHKKcLcTcq3x8PkMnQg1fkdUeCP/x0r3XZFdGNY 8FSeQ3q+28wqGauiur6/jSV71O4v5gVsKK1Z+emumFFnhIubiQeHvpGO+VHIzUx2PtCO brRd2BErCY942FyDefWtPxgkNnbxtRu02q/0/Ul5mTaHjJX3HoFMnO+Es3OZyhCXM9u0 AeIQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rkhBlMNVCAoBANU9IMSotfIPNKgW1NhElOHd0Sk9KFM=; b=BRXM+5A8gxGZbCfAt8JvH5QRRe8yy1hWa8lNd/BQrL3WxzZ/272XwAIFEjok578YQp KLDqGViAjv9QK69/QkZ7DxfU/FuchsfiSDEveyyRtHSJEiOtGY5K0YZn7hp0CLwWsj+s TrMTX4Bwiid4TE547sgTDnsfmPj/nS161Ron29BV723VGyat+evL8/+WBuYhlf0viext Q0pYB4+qw1STLrkUwLPlrhLVmGC/qSBiElcvM+CT7pGRs066ck8iC9pCyPLgJp1Fd8Zg l8D5dFlTM3tbdCGDYgycL8FbTMwqcu3CLzEaDJxCh+1shpT5RAFlaoyanIpBV63p59KQ GMOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XKYhhS34; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19si3416901ejr.411.2019.11.21.22.52.41; Thu, 21 Nov 2019 22:53:05 -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=XKYhhS34; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728581AbfKVGYM (ORCPT + 99 others); Fri, 22 Nov 2019 01:24:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:56644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728157AbfKVFvb (ORCPT ); Fri, 22 Nov 2019 00:51:31 -0500 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 46BF420731; Fri, 22 Nov 2019 05:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401890; bh=1lcF54AcbRONjDESSOA+6p0jhMgKCR+p52kcc7fQZc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XKYhhS34Iyh7W7x47gFw4rfU1nPJXR2RZxIHk48GxGL7R9TSGxdQx0qIz7GbJdxEZ UCWVlcQAU1pAM/MFQysC0F8uxaJEVyNNtkSoBo9k/NYOiaBTUT4uzaHKceuwBaCDLj GPJVz9XkcV7Frdr/dxcwjFfkkVDMZrS7S7l5x5U0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexey Kardashevskiy , David Gibson , Alex Williamson , Michael Ellerman , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 123/219] vfio/spapr_tce: Get rid of possible infinite loop Date: Fri, 22 Nov 2019 00:47:35 -0500 Message-Id: <20191122054911.1750-116-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-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: Alexey Kardashevskiy [ Upstream commit 517ad4ae8aa93dccdb9a88c27257ecb421c9e848 ] As a part of cleanup, the SPAPR TCE IOMMU subdriver releases preregistered memory. If there is a bug in memory release, the loop in tce_iommu_release() becomes infinite; this actually happened to me. This makes the loop finite and prints a warning on every failure to make the code more bug prone. Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson Acked-by: Alex Williamson Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c index 96721b154454f..ec53310f16136 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -371,6 +371,7 @@ static void tce_iommu_release(void *iommu_data) { struct tce_container *container = iommu_data; struct tce_iommu_group *tcegrp; + struct tce_iommu_prereg *tcemem, *tmtmp; long i; while (tce_groups_attached(container)) { @@ -393,13 +394,8 @@ static void tce_iommu_release(void *iommu_data) tce_iommu_free_table(container, tbl); } - while (!list_empty(&container->prereg_list)) { - struct tce_iommu_prereg *tcemem; - - tcemem = list_first_entry(&container->prereg_list, - struct tce_iommu_prereg, next); - WARN_ON_ONCE(tce_iommu_prereg_free(container, tcemem)); - } + list_for_each_entry_safe(tcemem, tmtmp, &container->prereg_list, next) + WARN_ON(tce_iommu_prereg_free(container, tcemem)); tce_iommu_disable(container); if (container->mm) -- 2.20.1