Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp431662ybe; Wed, 4 Sep 2019 01:58:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWIJ4LAMp+9XUMM6SZn0BwS1tAFYlncyyJrBvobl9/4VXkuSUrAYMqJshss98/NaAUbD0n X-Received: by 2002:a62:cec4:: with SMTP id y187mr12424233pfg.84.1567587499037; Wed, 04 Sep 2019 01:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567587499; cv=none; d=google.com; s=arc-20160816; b=zhROhDRbPIwR88AJ0vac+q9lfC8Zlm8xTwCkmVbKgGOVphU/ml5xiiTo+uH41K/cXL wyiUSMSJmGNJfdE1J3xncKcy+cKJLNkwYlcggEKpqvEc494MFjcmu1U2m4MkddjAaQOP RANbYZ2gFr3nZSDjo1VQrHyrQT5pdTpY4RE0yAwBDyW1+T7Sv9e1XIxxhQr5THMOdmLz 7zn/SG5YM3H2cH8k0S4FE5cGZa1te4X57sCkepXDI2TtlY0duUra2/H0M12Ij+mEf8LR HrrjVpH10Rmjcpj2c44RES+mUifLKu779zqZ37ZGXP5JgQOK7OT8gqAhPy5kLpE/VKVg 3y1Q== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=av0xNin3GnWBDpQnDBFzOq7X/ikQpOh4gJWMBe2zEKk=; b=M5qI7nNxQwwxpLIgslcyA8Wb3VKqjdqxMpYzpz9+23cgJ91Fw765q94MBIyLS2BYKQ p94ojQ3V/23+dsfq2YOPk6aM4jIeoRNw/Gg0G70aJh/7N9lcAHqC+209bzcGlxYzniec bzvrmAQm+RQVGIhWlN6ZNBqiEm1HggvIdbV2DoNXZGFQc+NgPqthVbZxZ+t05AOgYSZF tMl6eTdBy4XSoiRcXXIKzAyeO710hZAlZDT/HQlj7CIpDOdoQKbwlRNIVHwa22NiVjwg yDNxnzdLDxBGO9EYZUvOytL8XOWM0L2mtCADq2dZnb+xNFc9Sg3O5Opl5aUA2LgZmJxw Awmw== 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 m5si1848441pjv.91.2019.09.04.01.58.03; Wed, 04 Sep 2019 01:58: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 S1729045AbfIDI5G (ORCPT + 99 others); Wed, 4 Sep 2019 04:57:06 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57506 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726358AbfIDI5G (ORCPT ); Wed, 4 Sep 2019 04:57:06 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CDB8C341603829889F06; Wed, 4 Sep 2019 16:57:04 +0800 (CST) Received: from [127.0.0.1] (10.202.227.238) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Wed, 4 Sep 2019 16:56:56 +0800 Subject: Re: PCI/kernel msi code vs GIC ITS driver conflict? To: Marc Zyngier , Thomas Gleixner , "Bjorn Helgaas" References: <5fd4c1cf-76c1-4054-3754-549317509310@kernel.org> CC: Linux PCI , Linuxarm , "luojiaxing@huawei.com" , "linux-kernel@vger.kernel.org" From: John Garry Message-ID: Date: Wed, 4 Sep 2019 09:56:51 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <5fd4c1cf-76c1-4054-3754-549317509310@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.238] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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. >