From patchwork Tue Mar 6 15:51:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10262175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FA50602C8 for ; Tue, 6 Mar 2018 15:53:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 293E0290DD for ; Tue, 6 Mar 2018 15:53:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25478290A9; Tue, 6 Mar 2018 15:53:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 758EF29326 for ; Tue, 6 Mar 2018 15:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=oyG3COoWGSZsLiYQ6euLcedkVX1optFkm2e2US9U254=; b=FQy wh7sZAe+cjnYRFSi/zzRL6W3XIB+ekeL1gPo/BFbcFw2Y2XTp6+xSmWrypz9YgP1VoL7HvfRcUNXB QV8ZakW3/HwSNcv/c7dCKRMPf66yJaceMzxsMCrGEf6CXkhSXISpeaD35k3vl68lS7BRweZbhOTTC fXnP496qy07zOHOLEu/SVMZgS5b/T7gaX9vZxCL2AGGLo4e8aPoXfWhtm9V8VruqXkM8Q+cLMP4p7 9DPIeqeM2X+eqIMILugJidsV+Addi/f93lX2xP167OT2oXt3t1BULbxHyJY6nQnRA0wYUPUD0wUKW joqBE7T95N01t4T9iQDBk5ypMVchizg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1etEsd-0005ZM-Jx; Tue, 06 Mar 2018 15:51:55 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1etEsZ-0005Xg-G7 for linux-arm-kernel@lists.infradead.org; Tue, 06 Mar 2018 15:51:52 +0000 Received: by mail-wm0-x244.google.com with SMTP id t6so23210393wmt.5 for ; Tue, 06 Mar 2018 07:51:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=JlhPENJFc84qPOF+QJUTRx5RPDUd2Na/kf8ujf4KkMA=; b=W/oy/sH0emFnrY3uZ4fZ50NVLcUUrz5tVpJsaoA0O4qXxttptPRbXc7fkZt8kgKeS+ Cscsrj8b/JQ2BZWqcHAMkS1002Ir8hIIjEw+FO7s3GscQKDAQies8yBU42QpJyIXcwqQ eipnem8DLr7PAwIEgYE9IHqLGNQEq/HWihGrY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JlhPENJFc84qPOF+QJUTRx5RPDUd2Na/kf8ujf4KkMA=; b=bHXGR+z8oVjMB2GQyYCWZWtI1jhkJSDayw9elx72plcDI5o6N6mqZs1hxubXguo7IF cOpD/pXQX2YjVzPrOP7s0/2c+8ePdvVnLmghYG9Nb8KZSToD+zxJvEwQNjdxhz39xCEz c+mDjy1gNFVRVUGEpMsQKwllj9k5kzdLS6ZEFn9fqZ3UJr8Mkmmd4MgSlU0F0OvPUmms plVUTUBMDZNcAhbFan9yTOm1xTgW+D0ErTABZjBelzD1WSARpgZf21lQvRSLJsJRezUU 2GCA/a+NV46/5ZAqtTeoBHmy1aqfPFag+qJLubtf6KwZYhYShTkD6jjxmZ6sBQn2zsQL S1Xw== X-Gm-Message-State: AElRT7Hku+8mRYkZ2GWen6mF13dXcS7eC03txk8dHBHihi2UoX8BVnVq U5rGqPH0ey6aiUpThEKsl1K5Nw== X-Google-Smtp-Source: AG47ELvciE+oPPnYV03tr0msEVRqABr0aiW4ODEwJdkEJMHCRCOVi3rlq2CuJ8HKIV9OeZu0W45uew== X-Received: by 10.28.224.135 with SMTP id x129mr12685864wmg.57.1520351499304; Tue, 06 Mar 2018 07:51:39 -0800 (PST) Received: from localhost.localdomain ([160.168.113.39]) by smtp.gmail.com with ESMTPSA id v75sm36011827wrb.76.2018.03.06.07.51.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 07:51:38 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] irqchip: gic-v3-its: ensure nr_ites >= nr_lpis Date: Tue, 6 Mar 2018 15:51:32 +0000 Message-Id: <20180306155132.8757-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180306_075151_551601_3F292CB6 X-CRM114-Status: GOOD ( 16.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.zyngier@arm.com, tglx@linutronix.de, jason@lakedaemon.net, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/irqchip/irq-gic-v3-its.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 1d3056f53747..ee488c468400 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1412,7 +1412,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; @@ -2123,7 +2123,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, * of two entries. No, the architecture doesn't let you * express an ITT with a single entry. */ - 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);