Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp511833ybe; Wed, 4 Sep 2019 03:27:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzshe0nmjOy9o1Po4S9me/I3QYG1sqXaZd5BINpF5zQT4yed2p+/vMaRBpAjg9K+Y7bsR5m X-Received: by 2002:aa7:8498:: with SMTP id u24mr46092446pfn.61.1567592839848; Wed, 04 Sep 2019 03:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567592839; cv=none; d=google.com; s=arc-20160816; b=p5sflZXa+1yBN/Q+YoyKVYE5kSjfCr+paGcHofxtKVcrtCbAh4g4Lhn7kkDyK7J1Yg PxMvgtdyas4ujMkGXr2tyK8NBEmWp647knTDjd3PpsD1/q6mhznWLvzK9whyxPCtmNRD 5nS0bTu8AHsRcMtLeZ4+sd4A4UThrtvIk7nZQiI+4Zta+zCc2CIi6T+UcaHgtOZRXjUc ZINiIJ+Q24CVkaMIYTKn3wfUGZcB7nvmxHiQD/URqhplHplho3A4JXb63CLDpKvyJSX0 7RBDyJNlNtf/NGeFi5AGZfyJirnIDTSz/FB9jiSP7JGUjK62xLiJioTKUljePi8iXlu3 HLhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=SSfgiMUMj4UtHWKyCsLAOU7XYlq7H3kW42eDWgVTzos=; b=Yh1C4bPopjx9CrHplyo61uAyTVjc7bY9bNZ3bvVri9arImQ5aNQril+nCUwIMdhJP5 OKTpN2Aob57FympveymIUdo/GwfKNg9dSVnxI0VhmVgcsf0GHb6bKsc3z0aLeFGwHdid nuvQ/7lnvxIfbnEREyX2D8y5QNdtWwTRYxxoQy23SKi9+tcfV4SA06kRR367UHgu/2cK Rl9HBt1n+dtqjs/fkELCqzSElXm4ShGCvaBAMZoZpFpcOUNztKV9fkxBOEGeK7VzoJL/ zW5PHpL+QtaQLBUkbaQGPyH4TcFsJa83jyteKmhugayXDkFo6hOldY2d5xpRLbELvwab sIkw== 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 n123si16991434pgn.151.2019.09.04.03.27.03; Wed, 04 Sep 2019 03:27:19 -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 S1729523AbfIDKZl (ORCPT + 99 others); Wed, 4 Sep 2019 06:25:41 -0400 Received: from foss.arm.com ([217.140.110.172]:51304 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725966AbfIDKZk (ORCPT ); Wed, 4 Sep 2019 06:25:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BAED2337; Wed, 4 Sep 2019 03:25:39 -0700 (PDT) Received: from localhost (unknown [10.37.6.20]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 338313F246; Wed, 4 Sep 2019 03:25:39 -0700 (PDT) Date: Wed, 4 Sep 2019 11:25:37 +0100 From: Andrew Murray To: John Garry Cc: Marc Zyngier , Thomas Gleixner , Bjorn Helgaas , Linux PCI , Linuxarm , "luojiaxing@huawei.com" , "linux-kernel@vger.kernel.org" Subject: Re: PCI/kernel msi code vs GIC ITS driver conflict? Message-ID: <20190904102537.GV9720@e119886-lin.cambridge.arm.com> References: <5fd4c1cf-76c1-4054-3754-549317509310@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1+81 (426a6c1) (2018-08-26) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 04, 2019 at 09:56:51AM +0100, John Garry wrote: > On 03/09/2019 17:16, Marc Zyngier wrote: > > Hi John, > > > > On 03/09/2019 15:09, John Garry wrote: > > > Hi Marc, Bjorn, Thomas, > > Hi Marc, > > > > > > > We've come across a conflict with the kernel/pci msi code and GIC ITS > > > driver on our arm64 system, whereby we can't unbind and re-bind a PCI > > > device driver under special conditions. I'll explain... > > > > > > Our PCI device support 32 MSIs. The driver attempts to allocate msi > > > vectors with min msi=17, max msi = 32, and affd.pre vectors = 16. For > > > our test we make nr_cpus = 1 (just anything less than 16). > > > > Just to confirm: this PCI device is requiring Multi-MSI, right? As > > opposed to MSI-X? > > Right, Multi-MSI. > > > > > > We find that the pci/kernel msi code gives us 17 vectors, but the GIC > > > ITS code reserves 32 lpi maps in its_irq_domain_alloc(). The problem > > > then occurs when unbinding the driver in its_irq_domain_free() call, > > > where we only clear bits for 17 vectors. So if we unbind the driver and > > > then attempt to bind again, it fails. > > > > Is this device, by any chance, sharing its requested-id with another > > device? By being behind a bridge of some sort?There is some code to > > deal with it, but I'm not sure it has ever been verified in anger... > > It's a RC iEP and there should be no requested-id sharing: > > root@ubuntu:/home/john# lspci -s 74:02.0 -v > 74:02.0 Serial Attached SCSI controller: Huawei Technologies Co., Ltd. > HiSilicon SAS 3.0 HBA (rev 20) > Flags: bus master, fast devsel, latency 0, IRQ 23, NUMA node 0 > Memory at a2000000 (32-bit, non-prefetchable) [size=32K] > Capabilities: [40] Express Root Complex Integrated Endpoint, MSI 00 > Capabilities: [80] MSI: Enable+ Count=32/32 Maskable+ 64bit+ > Capabilities: [b0] Power Management version 3 > Kernel driver in use: hisi_sas_v3_hw > > > > > > Where the fault lies, I can't say. Maybe the kernel msi code should > > > always give power of 2 vectors - as I understand, the PCI spec mandates > > > this. Or maybe the GIC ITS driver has a problem in the free path, as > > > above. Or maybe the PCI driver should not be allowed to request !power > > > of 2 min/max vectors. > > > > > > Opinion? > > > > My hunch is that it is an ITS driver bug: the PCI layer is allowed to > > give any number of MSIs to an endpoint driver, as long as they match the > > requirements of the allocation for Multi-MSI. > > I would tend to say that, but isn't the requirement to allocate power of 2 > msi vectors, which doesn't seem to be enforced in the kernel msi layer? For a PCI device that supports MSI but not MSI-X - my understanding is that pci_alloc_irq_vectors_affinity and pci_alloc_irq_vectors will request *from the device* a power of 2 msi vectors between the min and max given by the driver - msi_setup_entry rounds up to nearest power of 2. However this doesn't guarantee that pci_alloc_irq_vectors will return a power of 2. For example if you set maxvec to 17, then it will request 32 from the device and pci_alloc_irq_vectors will return 17 (i.e. it satisfies your request by over allocating, but still gives you what you asked for). I'm not yet familiar with ITS, however if it is reserving 32 yet you only clear 17, then there is mismatch between the number actually reserved from the hardware, and the value returned from pci_alloc_irq_vectors. (It looks like its_alloc_device_irq rounds up to the nearest power of 2). Thanks, Andrew Murray > > That's the responsibility > > of the ITS driver. If unbind/bind fails, it means that somehow we've > > missed the freeing of the LPIs, which isn't good. > > > > Is the device common enough that I can try and reproduce the issue? > > No, it's integrated into the hi1620 SoC found in the D06 dev board only, but > I don't think that there is anything special about this HW. > > If > > there's a Linux driver somewhere, I can always hack something in > > emulation and find out... > > Ok, the interrupt allocation for this particular driver in this test is in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c#n2393 > > Cheers, > John > > > > > Thanks, > > > > M. > > > >