From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751640AbdJSD1C (ORCPT ); Wed, 18 Oct 2017 23:27:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52072 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751099AbdJSD1B (ORCPT ); Wed, 18 Oct 2017 23:27:01 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3EBA068B8 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=alex.williamson@redhat.com Subject: [PATCH] iommu/amd: Fix alloc_irq_index() increment From: Alex Williamson To: alex.williamson@redhat.com Cc: iommu@lists.linux-foundation.org, jroedel@suse.de, tglx@linutronix.de, linux-kernel@vger.kernel.org, joro@8bytes.org Date: Wed, 18 Oct 2017 21:26:58 -0600 Message-ID: <20171019032542.20915.96572.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 19 Oct 2017 03:27:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On an is_allocated() interrupt index, we ALIGN() the current index and then increment it via the for loop, guaranteeing that it is no longer aligned for alignments >1. We instead need to align the next index, to guarantee forward progress, moving the increment-only to the case where the index was found to be unallocated. Fixes: 37946d95fc1a ('iommu/amd: Add align parameter to alloc_irq_index()') Signed-off-by: Alex Williamson --- drivers/iommu/amd_iommu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 9dc7facfd2e5..3c1a29104f0e 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3682,13 +3682,12 @@ static int alloc_irq_index(u16 devid, int count, bool align) /* Scan table for free entries */ for (index = ALIGN(table->min_index, alignment), c = 0; - index < MAX_IRQS_PER_TABLE; - index++) { + index < MAX_IRQS_PER_TABLE;) { if (!iommu->irte_ops->is_allocated(table, index)) { c += 1; } else { c = 0; - index = ALIGN(index, alignment); + index = ALIGN(index + 1, alignment); continue; } @@ -3699,6 +3698,8 @@ static int alloc_irq_index(u16 devid, int count, bool align) index -= count - 1; goto out; } + + index++; } index = -ENOSPC;