Received: by 10.213.65.68 with SMTP id h4csp36812imn; Mon, 19 Mar 2018 18:44:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELvWrlVwbNqI3pLQHAXjj8WtWOWiYsZIx2+zFo1COeJ2BnIrRKYFV0/j9vqT7NzxkffUTd3M X-Received: by 2002:a17:902:2cc3:: with SMTP id n61-v6mr2758437plb.148.1521510272418; Mon, 19 Mar 2018 18:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510272; cv=none; d=google.com; s=arc-20160816; b=A/6Pm/eNDIZkFmaJfi0+YJgCN+Bh5WOy8sDxaBQz1XYRx6X6R0AzcAZqcONa/jkTAU HQRXUAJ1LvninfJye1yt0OlNE0yfbMZItJszeqblvvhRmMGdSSEe7PIJKH9iZrcscIXR QiWhB7LQ2KaaMrkv9nYIp/xe8OAjyZECjNNMvl3llHe0ZvLYQq4t1j8EocH7DkDyvVE7 N0LN8Q0cKYSN1SN3r1Z1ItK7gE2LZMIczkZUlwvMWzqzRT3r8TPTws/idvkqzsBSPFEO rz4LxRVUciUZ3fbVuNYSV+rs7YIHni3Bz2lgt6E+Mo8oKfuWXM3yizZ58fxQledGtGys W8xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=lfMcxfFnbaxQQ6XQn1r8DRLU2wgB1Jz24oqWry0WEKA=; b=IPnsGe4aE49mEiFCJMhKkRxhAYsCeYFgT1k8eO9H9lLHWUfO3TTq/mLj3O49XOy4AZ i2YhX5DgYQdXPJ3l2tU8d91nSiAHSYiYfektmVG/i2trzkWd0QV0Oe2cgymdN/14zxeI nl8aFI5zrH1R7xXFjKGuFEBWtLVMqEgYXVxM7nlrJv8QNrPBDK1zny1iswefDVHyH0xu 3R0bloRZlhJaFWtDgpIJrUhS+MJfFsPTYdocsR2yN4NvkBzRcK3aPCYpAazDkqnMDEDd eFg9Jhq2Nmtwte5pQNIVBZbjwQ73ThM80P1l70EuoOgJaDItQE4eBhYJ3Q3R9+WOUueV 5GwA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si426322pfi.123.2018.03.19.18.44.18; Mon, 19 Mar 2018 18:44:32 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970267AbeCSSsq (ORCPT + 99 others); Mon, 19 Mar 2018 14:48:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53384 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032038AbeCSSbA (ORCPT ); Mon, 19 Mar 2018 14:31:00 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9F8911278; Mon, 19 Mar 2018 18:30:59 +0000 (UTC) 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.14 29/41] irqchip/gic-v3-its: Ensure nr_ites >= nr_lpis Date: Mon, 19 Mar 2018 19:08:29 +0100 Message-Id: <20180319180734.138841577@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180732.195217948@linuxfoundation.org> References: <20180319180732.195217948@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ard Biesheuvel commit 4f2c7583e33eb08dc09dd2e25574b80175ba7d93 upstream. When struct its_device instances are created, the nr_ites member will be set to a power of 2 that equals or exceeds the requested number of MSIs passed to the msi_prepare() callback. At the same time, the LPI map is allocated to be some multiple of 32 in size, where the allocated size may be less than the requested size depending on whether a contiguous range of sufficient size is available in the global LPI bitmap. This may result in the situation where the nr_ites < nr_lpis, and since nr_ites is what we program into the hardware when we map the device, the additional LPIs will be non-functional. For bog standard hardware, this does not really matter. However, in cases where ITS device IDs are shared between different PCIe devices, we may end up allocating these additional LPIs without taking into account that they don't actually work. So let's make nr_ites at least 32. This ensures that all allocated LPIs are 'live', and that its_alloc_device_irq() will fail when attempts are made to allocate MSIs beyond what was allocated in the first place. Signed-off-by: Ard Biesheuvel [maz: updated comment] Signed-off-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman --- drivers/irqchip/irq-gic-v3-its.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1310,7 +1310,7 @@ static struct irq_chip its_irq_chip = { * This gives us (((1UL << id_bits) - 8192) >> 5) possible allocations. */ #define IRQS_PER_CHUNK_SHIFT 5 -#define IRQS_PER_CHUNK (1 << IRQS_PER_CHUNK_SHIFT) +#define IRQS_PER_CHUNK (1UL << IRQS_PER_CHUNK_SHIFT) #define ITS_MAX_LPI_NRBITS 16 /* 64K LPIs */ static unsigned long *lpi_bitmap; @@ -2026,11 +2026,10 @@ static struct its_device *its_create_dev dev = kzalloc(sizeof(*dev), GFP_KERNEL); /* - * At least one bit of EventID is being used, hence a minimum - * of two entries. No, the architecture doesn't let you - * express an ITT with a single entry. + * We allocate at least one chunk worth of LPIs bet device, + * and thus that many ITEs. The device may require less though. */ - nr_ites = max(2UL, roundup_pow_of_two(nvecs)); + nr_ites = max(IRQS_PER_CHUNK, roundup_pow_of_two(nvecs)); sz = nr_ites * its->ite_size; sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; itt = kzalloc(sz, GFP_KERNEL);