Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3858448pxv; Mon, 19 Jul 2021 10:25:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5de8nrA7v4Ssfi/O4GIf55AyblgP8B+qYuPGHztahVmIPy9h/q5NUCMa3fc66CNIPK964 X-Received: by 2002:a50:ee15:: with SMTP id g21mr35448362eds.334.1626715533072; Mon, 19 Jul 2021 10:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715533; cv=none; d=google.com; s=arc-20160816; b=t2VXlh6fM/nq2pDU7piNJGvrSE9kvrcMR0DUldrqwFZZZS6hn7Q8RdJtiiBIqAVXhl IW1tXLUGKscW7Q+O2tfZ1ATrfAIVfxBAVooACAffO7PeC8AQto+IXMs0m9PQugSTOEfc 6UrW7RdXeHyn7MHb+OgrMjm8apnUgU1qAqrO2N35aZaMl+JTacKpFB+P+sGT/bdRADWo TNvc5P2DHM9MY2fXFPeB+1TBERFzaZ9sp9ZazFjNtljho3hxkZ34YXzXqA2AJx4hQkns nPCxbzFCe7A6Reg4QO3N56gXRQjATTjkEpNCCoRN8J4ZpN0lbgckACNzx/YU+MUS7A8F rMNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BIKMfbSOT22F81+j44dRArJHL1TSN9vlyjsGT95SMu0=; b=qSJbo3T68mjSN1njGbDWPz/Xdc5GHTW/eqIHH47LsVacFrS3ukZz1VAFF2D7pHf8H0 1zczifbS8F8I9EqsfClFteMohSY07LSgUdDekXX6wQ8b//9jvwDnPUkVPhCnDluRyoB9 St7pMd7Fl4oUjdwSfwAzDlHiVLA4aS2JzjLMwZzD+WgcM0UuW+LdPIQ24ETX2m8M8EU3 /n1lb7QgYdFMcrHi8r5laXexRkNMJdNb/wXJQPd80Ltcsxec1E7tVwGpflGsWT3FqGky kXKun0PlV8IesHlP6qpgNkNNfwOFbKFE1CYOb/R6RBFalQJS9Q1ICv4i42HpVICTSxen oNEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VtBkEAjd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si6632031ejg.350.2021.07.19.10.25.11; Mon, 19 Jul 2021 10:25:33 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VtBkEAjd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356199AbhGSQkw (ORCPT + 99 others); Mon, 19 Jul 2021 12:40:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:58072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347582AbhGSPTv (ORCPT ); Mon, 19 Jul 2021 11:19:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 19DA161249; Mon, 19 Jul 2021 15:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710319; bh=PsM/oEeLeFVpxT9DvqvZk4ztkjZyublkQYANPYhPMQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VtBkEAjdjcgoZRnxxkQ16yEgXBdC/hAuZhN1MPzRdKdoHkS6CS7qNDgMS+b4eQbN+ JGrFUVqkncYkvtRmf0g/FWd90+Owe2+Dwoyv6R2kppDjfIV+tnuZJ7R2d0skoj4QNY TOrOCoLZpi4SzRz2MS6lQiRYFHTsu9Xx055LsmO4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= , Sandor Bodo-Merle , Lorenzo Pieralisi , Marc Zyngier , Ray Jui , Sasha Levin Subject: [PATCH 5.10 166/243] PCI: iproc: Fix multi-MSI base vector number allocation Date: Mon, 19 Jul 2021 16:53:15 +0200 Message-Id: <20210719144946.252833606@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sandor Bodo-Merle [ Upstream commit e673d697b9a234fc3544ac240e173cef8c82b349 ] Commit fc54bae28818 ("PCI: iproc: Allow allocation of multiple MSIs") introduced multi-MSI support with a broken allocation mechanism (it failed to reserve the proper number of bits from the inner domain). Natural alignment of the base vector number was also not guaranteed. Link: https://lore.kernel.org/r/20210622152630.40842-1-sbodomerle@gmail.com Fixes: fc54bae28818 ("PCI: iproc: Allow allocation of multiple MSIs") Reported-by: Pali Rohár Signed-off-by: Sandor Bodo-Merle Signed-off-by: Lorenzo Pieralisi Acked-by: Marc Zyngier Acked-by: Pali Rohár Acked-by: Ray Jui Signed-off-by: Sasha Levin --- drivers/pci/controller/pcie-iproc-msi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/pcie-iproc-msi.c b/drivers/pci/controller/pcie-iproc-msi.c index eede4e8f3f75..557d93dcb3bc 100644 --- a/drivers/pci/controller/pcie-iproc-msi.c +++ b/drivers/pci/controller/pcie-iproc-msi.c @@ -252,18 +252,18 @@ static int iproc_msi_irq_domain_alloc(struct irq_domain *domain, mutex_lock(&msi->bitmap_lock); - /* Allocate 'nr_cpus' number of MSI vectors each time */ - hwirq = bitmap_find_next_zero_area(msi->bitmap, msi->nr_msi_vecs, 0, - msi->nr_cpus, 0); - if (hwirq < msi->nr_msi_vecs) { - bitmap_set(msi->bitmap, hwirq, msi->nr_cpus); - } else { - mutex_unlock(&msi->bitmap_lock); - return -ENOSPC; - } + /* + * Allocate 'nr_irqs' multiplied by 'nr_cpus' number of MSI vectors + * each time + */ + hwirq = bitmap_find_free_region(msi->bitmap, msi->nr_msi_vecs, + order_base_2(msi->nr_cpus * nr_irqs)); mutex_unlock(&msi->bitmap_lock); + if (hwirq < 0) + return -ENOSPC; + for (i = 0; i < nr_irqs; i++) { irq_domain_set_info(domain, virq + i, hwirq + i, &iproc_msi_bottom_irq_chip, @@ -284,7 +284,8 @@ static void iproc_msi_irq_domain_free(struct irq_domain *domain, mutex_lock(&msi->bitmap_lock); hwirq = hwirq_to_canonical_hwirq(msi, data->hwirq); - bitmap_clear(msi->bitmap, hwirq, msi->nr_cpus); + bitmap_release_region(msi->bitmap, hwirq, + order_base_2(msi->nr_cpus * nr_irqs)); mutex_unlock(&msi->bitmap_lock); -- 2.30.2