Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4451222imu; Sat, 19 Jan 2019 09:39:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN58vQ7GJi4ZeqJ9JuhEJBywIH7pLZdMEutTleAYY9HWesgEr+00EaejNyz0Thk20S2dAFEI X-Received: by 2002:a63:78cd:: with SMTP id t196mr22358410pgc.62.1547919573856; Sat, 19 Jan 2019 09:39:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547919573; cv=none; d=google.com; s=arc-20160816; b=wkuGJbtrZmktra4dh9B9xLRnwBh6MfsGcV0ZVRjU5lYKjNEvQIoiIDuPRdfarl2BvQ saeqftKOWNsg5nzNydtpD6cRjJZ4OHpCsZkKPWqh27dmN6WnurbMjSUZo/V+Djt/7Ask wkxcR+a2Clce3p/hipXbZkJuQDIF8oAO6nCWkkYe7+aZ/MuoG/4Y347Rp3WTFWjaKuLa 3yFZnz4i1lSCxTOmeCxBvCmtvXXVhMs/AkL7RRpjNeMS7zsQNk2c8CyS7mXdTejZrapE /15CHB9zmIXsXazmYQ88rB6wP12dtoe8idKQZBT7pQOk254P6zQ2VW9yZTgs1XdWdzyl sZIg== 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=jhddLAyAIhQQYUv8UZf1G4S6PZHEDm077f3HD6GIv9g=; b=KmtGgQVLzpJw/Ql5WR0kt2S0n2XGJTIryRfcO0i1O+XQehmMImDTMBWkO6J7b+Zd51 5RKmOj7FYmIPVajfU7MJN5fdnRldVaHa9MC0tW5HPbNLk45CDHYEg0z5hCQ+wNQWPI1D v/6CBgRgnZqFUeqSiFKo+vU6AT0NciELMBhrvtUwHkOCyfkuZma857fYLyRow19S9lsu ymElgzEIlk1nFwmjeVFBITcEwd8DKutl8xlnYiFnZIS2yi/D1HqlEWjBOp+o437DyQjJ rpYSgV+O7fv5G4Bk7nxMA/+wrpixMSce+y/MMPaZVuOT5if6AmjGwgEfJ6LUJII9Fvwe ergg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si7928489pgn.365.2019.01.19.09.39.17; Sat, 19 Jan 2019 09:39:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728746AbfASRiI (ORCPT + 99 others); Sat, 19 Jan 2019 12:38:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57564 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728423AbfASRiI (ORCPT ); Sat, 19 Jan 2019 12:38:08 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67F0989AE6; Sat, 19 Jan 2019 17:38:08 +0000 (UTC) Received: from cantor.redhat.com (ovpn-116-12.phx2.redhat.com [10.3.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id F26F7100190B; Sat, 19 Jan 2019 17:38:07 +0000 (UTC) From: Jerry Snitselaar To: iommu@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH] iommu/amd: unmap all mapped pages in error path of map_sg Date: Sat, 19 Jan 2019 10:38:05 -0700 Message-Id: <20190119173805.1753-1-jsnitsel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 19 Jan 2019 17:38:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the error path of map_sg there is an incorrect if condition for breaking out of the loop that searches the scatterlist for mapped pages to unmap. Instead of breaking out of the loop once all the pages that were mapped have been unmapped, it will break out of the loop after it has unmapped 1 page. Fix the condition, so it breaks out of the loop only after all the mapped pages have been unmapped. Fixes: 80187fd39dcb ("iommu/amd: Optimize map_sg and unmap_sg") Cc: Joerg Roedel Signed-off-by: Jerry Snitselaar --- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 1167ff0416cf..aeeca479f914 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2548,7 +2548,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, bus_addr = address + s->dma_address + (j << PAGE_SHIFT); iommu_unmap_page(domain, bus_addr, PAGE_SIZE); - if (--mapped_pages) + if (--mapped_pages == 0) goto out_free_iova; } } -- 2.20.1.98.gecbdaf0899