Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3125706ybi; Thu, 18 Jul 2019 21:31:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0lGvrohVHIhzfPQSfYPkyyxDgLZEFVUQiWMEGv1/1yprXtCzV0AnJJx/+xCD11VDaTjBr X-Received: by 2002:a65:6294:: with SMTP id f20mr53133955pgv.349.1563510719673; Thu, 18 Jul 2019 21:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563510719; cv=none; d=google.com; s=arc-20160816; b=EQK8gHX3ghInmgR4Uy8C1+tSuvP7Y07qnwjo6JBAlV7sPXa7p04INRuaChDPZ/1i0Q kmxDhUdhnlGtjl95WUS8shv3HpS7QOsivmEFNufEp262D8XXmhMEigxyVcxujDigsv6q /SiRpwmD3t9hlLYjaUuOy5hV+2coeZmdcN4IaY+Rf50eYWzXCrhspziOpPsor7MeLPrZ kJCxEreebRngqgQDRwsDqJnoP6ftxXBDwONUugR/XnBri6r3Evc+Msb4LvvuVarCdVuj biqx5yZfa31CJm3RQkYqihG/PEdPcfb4uWNay2b4DGoVBpe/04/4zwDYNuCEee4vGZsR RdMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bQaRU15f2EaGQe4phwjJyzcBvw9VwOCkj6E3MAfHxkQ=; b=YGaxJDFE6InMv/uFRD3PTIWNXR7tJ5kWke1+s53mjXfS0JpDUL3d+MOss7lG+lhyNv gQUo5Gc7gk/6HCEUppg8QuUileQUUUNinqJm2S8RU1yVsq6R8TLAWCE69VYICnULoceF rjPVfc5Ud0ihhTDzMqUo2pWkwD+/gnC5bPfYCvZkIvxLT8iMjEi9wE20bpRLgJl2YnNF QCJayNyFuzpPpljGBFeVaFRXjqB/V+wrvRon6fVGt8zrEtE/V6NT+8KD6GzYpoAtqPu/ 8/gZn12OLgdqFmUHnQKXtW+bhl/6juJs/qLwvSSkPjAg1EbuL11RboPF9Ux+s3ozKpG8 dWJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nJN1hLAC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si21520844pgk.187.2019.07.18.21.31.44; Thu, 18 Jul 2019 21:31:59 -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; dkim=pass header.i=@kernel.org header.s=default header.b=nJN1hLAC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732235AbfGSEaf (ORCPT + 99 others); Fri, 19 Jul 2019 00:30:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:37194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729995AbfGSEE7 (ORCPT ); Fri, 19 Jul 2019 00:04:59 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 00322218A3; Fri, 19 Jul 2019 04:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509098; bh=GIVjHN4Ipw1JFaURwKMXoUGR6EIG9Z9SPWtxHcXoxBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJN1hLACcT7Y/BBMj8cTvWiT7H+qcYP1T0vCOkTzEM2+STg9MAtHp2sFrWeRQh/OZ s/zbIjd3hIEPEO+KM9EurCAChP0tg3rOBT+etYX7ffnqdGC94pigbj+nGoR/VmUjgR /gqBHKWBSD7Uc2xKP2RUE4mT1Lxo3WJ05bpyAKtI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bharat Kumar Gogada , Marc Zyngier , Lorenzo Pieralisi , Sasha Levin , linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 5.1 067/141] PCI: xilinx-nwl: Fix Multi MSI data programming Date: Fri, 19 Jul 2019 00:01:32 -0400 Message-Id: <20190719040246.15945-67-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719040246.15945-1-sashal@kernel.org> References: <20190719040246.15945-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bharat Kumar Gogada [ Upstream commit 181fa434d0514e40ebf6e9721f2b72700287b6e2 ] According to the PCI Local Bus specification Revision 3.0, section 6.8.1.3 (Message Control for MSI), endpoints that are Multiple Message Capable as defined by bits [3:1] in the Message Control for MSI can request a number of vectors that is power of two aligned. As specified in section 6.8.1.6 "Message data for MSI", the Multiple Message Enable field (bits [6:4] of the Message Control register) defines the number of low order message data bits the function is permitted to modify to generate its system software allocated vectors. The MSI controller in the Xilinx NWL PCIe controller supports a number of MSI vectors specified through a bitmap and the hwirq number for an MSI, that is the value written in the MSI data TLP is determined by the bitmap allocation. For instance, in a situation where two endpoints sitting on the PCI bus request the following MSI configuration, with the current PCI Xilinx bitmap allocation code (that does not align MSI vector allocation on a power of two boundary): Endpoint #1: Requesting 1 MSI vector - allocated bitmap bits 0 Endpoint #2: Requesting 2 MSI vectors - allocated bitmap bits [1,2] The bitmap value(s) corresponds to the hwirq number that is programmed into the Message Data for MSI field in the endpoint MSI capability and is detected by the root complex to fire the corresponding MSI irqs. The value written in Message Data for MSI field corresponds to the first bit allocated in the bitmap for Multi MSI vectors. The current Xilinx NWL MSI allocation code allows a bitmap allocation that is not a power of two boundaries, so endpoint #2, is allowed to toggle Message Data bit[0] to differentiate between its two vectors (meaning that the MSI data will be respectively 0x0 and 0x1 for the two vectors allocated to endpoint #2). This clearly aliases with the Endpoint #1 vector allocation, resulting in a broken Multi MSI implementation. Update the code to allocate MSI bitmap ranges with a power of two alignment, fixing the bug. Fixes: ab597d35ef11 ("PCI: xilinx-nwl: Add support for Xilinx NWL PCIe Host Controller") Suggested-by: Marc Zyngier Signed-off-by: Bharat Kumar Gogada [lorenzo.pieralisi@arm.com: updated commit log] Signed-off-by: Lorenzo Pieralisi Acked-by: Marc Zyngier Signed-off-by: Sasha Levin --- drivers/pci/controller/pcie-xilinx-nwl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c index 81538d77f790..a9e07b8a45b1 100644 --- a/drivers/pci/controller/pcie-xilinx-nwl.c +++ b/drivers/pci/controller/pcie-xilinx-nwl.c @@ -483,15 +483,13 @@ static int nwl_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, int i; mutex_lock(&msi->lock); - bit = bitmap_find_next_zero_area(msi->bitmap, INT_PCI_MSI_NR, 0, - nr_irqs, 0); - if (bit >= INT_PCI_MSI_NR) { + bit = bitmap_find_free_region(msi->bitmap, INT_PCI_MSI_NR, + get_count_order(nr_irqs)); + if (bit < 0) { mutex_unlock(&msi->lock); return -ENOSPC; } - bitmap_set(msi->bitmap, bit, nr_irqs); - for (i = 0; i < nr_irqs; i++) { irq_domain_set_info(domain, virq + i, bit + i, &nwl_irq_chip, domain->host_data, handle_simple_irq, @@ -509,7 +507,8 @@ static void nwl_irq_domain_free(struct irq_domain *domain, unsigned int virq, struct nwl_msi *msi = &pcie->msi; mutex_lock(&msi->lock); - bitmap_clear(msi->bitmap, data->hwirq, nr_irqs); + bitmap_release_region(msi->bitmap, data->hwirq, + get_count_order(nr_irqs)); mutex_unlock(&msi->lock); } -- 2.20.1