Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4564353imu; Tue, 29 Jan 2019 03:53:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN5QwJlsWGSpMxBy9p/i5LdYoMyIu5zESrozOup5e2Qnu4/a0bEgu2Tmxtv9fgwHYCr6zxIl X-Received: by 2002:a63:f615:: with SMTP id m21mr23817705pgh.428.1548762839821; Tue, 29 Jan 2019 03:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762839; cv=none; d=google.com; s=arc-20160816; b=PXD3/PsZ724b6Fvxf+D3bWeydswlYVGPRjzMzI/HK/YrXishDDF5VrqXyQMbgEA0Ug R2pOMrSf+VDWKGHTpNaJV237XDBTaUlX2w65QgCqw1jEuGBDRnv0zMAETuKgGaittg5i Xtusu7zvO75XQTg7vTOysxwVgpT4rCpzdeXDHIlgKs1Rmy0oqCfYE0Iq82KoXzR31CRz azDW8dujE/n7qba55+xJ1O+MFOGS5vEMQBCmR4S9Lwo2PKFnm534J6fIfrC6hP6Qgn/A N2+NuSM112DXj+ZAfLZIKyHVKfwUEcbzH/PrFEW+we4M4HpI7npghhmGLwNMV5tDqb01 XWFQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rUEHvTxiLN84VagAfcL/HlOt1NWtXHcQhRaHzmDaOOA=; b=NCO+U3VGHx3UIoyZatB6ch8zEJ3KH5ZacDT2vDIVxE4DMz0Jloet/LwrNU4kQ3PGiT zrOkVIPJunSJ7jsZbYN04GHd8O82vsyXoDleEghg1Y9mDyDMhYwyhpSLZtbPip6/WK07 gdgi7PInI7wfbFsHNvtp152nRnEFFC7ncp/SKTllsWkdY1fSQi6VLq/kkPo8hgEfc/xU xR3Kh+K7IUzlgMOCEvhTwrniFahSNBe0x3GRhVvz35IIsZ/UhDib2mkGjyvugTmYEj9H eQ1nVxEaDluCLDJoE2C61UF+8SpXmgRU7JkDYv6NyJdD1kksqAVyitOdiv70YsH6BWpF 6LOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YkoVpUoD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si4322973pls.437.2019.01.29.03.53.44; Tue, 29 Jan 2019 03:53:59 -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=YkoVpUoD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731765AbfA2Lxh (ORCPT + 99 others); Tue, 29 Jan 2019 06:53:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:43862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732014AbfA2LwK (ORCPT ); Tue, 29 Jan 2019 06:52:10 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BCF932083B; Tue, 29 Jan 2019 11:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762729; bh=tXmPTtHm5SrKhJvgK9PbWQF4qxXBfq1CQzXKtEEqAmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YkoVpUoD6ExNHLkz9JRcED+5FqJCsYtxY3Br5CM+Tb1L2J1L8uW+agHh7Z5eLNYcq cdv3ft8dQHKtL6fe9+rBEnwcs7mZ9M8O63muu+ZKyGk+jqvjZrcmtTCF+p4KQ8rjNT ixo++MGNeO5S2hMID6K41V5Kg2ocOyktUmTWRaCM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Marc Zyngier Subject: [PATCH 4.9 38/44] irqchip/gic-v3-its: Align PCI Multi-MSI allocation on their size Date: Tue, 29 Jan 2019 12:36:33 +0100 Message-Id: <20190129113143.037142661@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113139.826927690@linuxfoundation.org> References: <20190129113139.826927690@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marc Zyngier commit 8208d1708b88b412ca97f50a6d951242c88cbbac upstream. The way we allocate events works fine in most cases, except when multiple PCI devices share an ITS-visible DevID, and that one of them is trying to use MultiMSI allocation. In that case, our allocation is not guaranteed to be zero-based anymore, and we have to make sure we allocate it on a boundary that is compatible with the PCI Multi-MSI constraints. Fix this by allocating the full region upfront instead of iterating over the number of MSIs. MSI-X are always allocated one by one, so this shouldn't change anything on that front. Fixes: b48ac83d6bbc2 ("irqchip: GICv3: ITS: MSI support") Cc: stable@vger.kernel.org Reported-by: Ard Biesheuvel Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier [ardb: rebased onto v4.9.153, should apply cleanly onto v4.4.y as well] Signed-off-by: Ard Biesheuvel --- drivers/irqchip/irq-gic-v3-its.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1372,13 +1372,14 @@ static void its_free_device(struct its_d kfree(its_dev); } -static int its_alloc_device_irq(struct its_device *dev, irq_hw_number_t *hwirq) +static int its_alloc_device_irq(struct its_device *dev, int nvecs, irq_hw_number_t *hwirq) { int idx; - idx = find_first_zero_bit(dev->event_map.lpi_map, - dev->event_map.nr_lpis); - if (idx == dev->event_map.nr_lpis) + idx = bitmap_find_free_region(dev->event_map.lpi_map, + dev->event_map.nr_lpis, + get_count_order(nvecs)); + if (idx < 0) return -ENOSPC; *hwirq = dev->event_map.lpi_base + idx; @@ -1464,20 +1465,20 @@ static int its_irq_domain_alloc(struct i int err; int i; - for (i = 0; i < nr_irqs; i++) { - err = its_alloc_device_irq(its_dev, &hwirq); - if (err) - return err; + err = its_alloc_device_irq(its_dev, nr_irqs, &hwirq); + if (err) + return err; - err = its_irq_gic_domain_alloc(domain, virq + i, hwirq); + for (i = 0; i < nr_irqs; i++) { + err = its_irq_gic_domain_alloc(domain, virq + i, hwirq + i); if (err) return err; irq_domain_set_hwirq_and_chip(domain, virq + i, - hwirq, &its_irq_chip, its_dev); + hwirq + i, &its_irq_chip, its_dev); pr_debug("ID:%d pID:%d vID:%d\n", - (int)(hwirq - its_dev->event_map.lpi_base), - (int) hwirq, virq + i); + (int)(hwirq + i - its_dev->event_map.lpi_base), + (int)(hwirq + i), virq + i); } return 0;