All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>,
	Sricharan R <sricharan@codeaurora.org>,
	"Wangzhou (B)" <wangzhou1@hisilicon.com>,
	"will.deacon@arm.com" <will.deacon@arm.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"lorenzo.pieralisi@arm.com" <lorenzo.pieralisi@arm.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
	"m.szyprowski@samsung.com" <m.szyprowski@samsung.com>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"tn@semihalf.com" <tn@semihalf.com>,
	hanjun.guo@linaro.o
Subject: Re: [PATCH V9 00/11] IOMMU probe deferral support
Date: Fri, 24 Mar 2017 18:38:39 +0000	[thread overview]
Message-ID: <db3d68f8-713c-9ae2-7df9-324bc1b375b1@arm.com> (raw)
In-Reply-To: <5FC3163CFD30C246ABAA99954A238FA81750B7CB@lhreml504-mbs>

On 24/03/17 09:27, Shameerali Kolothum Thodi wrote:
> Hi Sricharan,
> 
>> -----Original Message-----
>> From: Sricharan R [mailto:sricharan@codeaurora.org]
>> Sent: Friday, March 24, 2017 7:10 AM
>> To: Wangzhou (B); robin.murphy@arm.com; will.deacon@arm.com;
>> joro@8bytes.org; lorenzo.pieralisi@arm.com; iommu@lists.linux-
>> foundation.org; linux-arm-kernel@lists.infradead.org; linux-arm-
>> msm@vger.kernel.org; m.szyprowski@samsung.com;
>> bhelgaas@google.com; linux-pci@vger.kernel.org; linux-
>> acpi@vger.kernel.org; tn@semihalf.com; hanjun.guo@linaro.org;
>> okaya@codeaurora.org
>> Cc: Shameerali Kolothum Thodi
>> Subject: Re: [PATCH V9 00/11] IOMMU probe deferral support
>>
>> Hi Zhou,
>>
>> On 3/24/2017 9:23 AM, Zhou Wang wrote:
>>> On 2017/3/10 3:00, Sricharan R wrote:
>>>> This series calls the dma ops configuration for the devices at a
>>>> generic place so that it works for all busses.
>>>> The dma_configure_ops for a device is now called during the
>>>> device_attach callback just before the probe of the bus/driver is
>>>> called. Similarly dma_deconfigure is called during
>>>> device/driver_detach path.
>>>>
>>>> pci_bus_add_devices    (platform/amba)(_device_create/driver_register)
>>>>        |                         |
>>>> pci_bus_add_device     (device_add/driver_register)
>>>>        |                         |
>>>> device_attach           device_initial_probe
>>>>        |                         |
>>>> __device_attach_driver    __device_attach_driver
>>>>        |
>>>> driver_probe_device
>>>>        |
>>>> really_probe
>>>>        |
>>>> dma_configure
>>>>
>>>> Similarly on the device/driver_unregister path
>>>> __device_release_driver is called which inturn calls dma_deconfigure.
>>>>
>>>> Rebased the series against mainline 4.11-rc1. Applies and builds
>>>> cleanly against mainline and linux-next. There is a conflict with
>>>> patch#9 against iommu-next, but that should go away eventually as
>>>> iommu-next is rebased against 4.11-rc1.
>>>>
>>>> * Tested with platform and pci devices for probe deferral
>>>>   and reprobe on arm64 based platform.
>>>
>>> Hi Sricharan,
>>>
>>> I applied this series on v4.11-rc1 to test PCIe pass through in
>>> HiSilicon
>>> D05 board(with Intel 82599 networking card). It failed.
>>>
>>> After I used:
>>>
>>> echo vfio-pci > /sys/bus/pci/devices/0002:81:10.0/driver_override
>>> echo 0002:81:10.0 > /sys/bus/pci/drivers/ixgbevf/unbind
>>> echo 0002:81:10.0 > /sys/bus/pci/drivers_probe
>>>
>>> to bind vfio-pci driver to Intel 82599 networking card VF.
>>>
>>> I got log in host:
>>> [...]
>>> [  414.275818] ixgbevf: Intel(R) 10 Gigabit PCI Express Virtual
>>> Function Network Driver - version 3.2.2-k [  414.275824] ixgbevf: Copyright
>> (c) 2009 - 2015 Intel Corporation.
>>> [  414.276647] ixgbe 0002:81:00.0 eth12: SR-IOV enabled with 1 VFs [
>>> 414.342252] pcieport 0002:80:00.0: can't derive routing for PCI INT A
>>> [  414.342255] ixgbe 0002:81:00.0: PCI INT A: no GSI [  414.343348]
>>> ixgbe 0002:81:00.0: Multiqueue Enabled: Rx Queue count = 4, Tx Queue
>>> count = 4 [  414.448135] pci 0002:81:10.0: [8086:10ed] type 00 class
>>> 0x020000 [  414.448713] iommu: Adding device 0002:81:10.0 to group 4 [
>>> 414.449798] ixgbevf 0002:81:10.0: enabling device (0000 -> 0002) [
>>> 414.451101] ixgbevf 0002:81:10.0: PF still in reset state.  Is the PF interface
>> up?
>>> [  414.451103] ixgbevf 0002:81:10.0: Assigning random MAC address [
>>> 414.451414] ixgbevf 0002:81:10.0: be:30:8f:ed:f8:02 [  414.451417]
>>> ixgbevf 0002:81:10.0: MAC: 1 [  414.451418] ixgbevf 0002:81:10.0:
>>> Intel(R) 82599 Virtual Function [  414.464271] VFIO - User Level
>>> meta-driver version: 0.3 [  414.570074] ixgbe 0002:81:00.0: registered
>>> PHC device on eth12
>>> [  414.700493] specified DMA range outside IOMMU capability
>> <-- error here
>>> [  414.700496] Failed to set up IOMMU for device 0002:81:10.0; retaining
>> platform DMA ops        <-- error here
>>
>> Looks like this triggers the start of the bug.
>> So the below check in iommu_dma_init_domain fails,
>>
>>          if (domain->geometry.force_aperture) {
>>                  if (base > domain->geometry.aperture_end ||
>>                      base + size <= domain->geometry.aperture_start) {
>>
>> and the rest goes out of sync after that. Can you print out the base,
>> aperture_start and end values to see why the check fails ?
> 
> dev_info(dev, "0x%llx 0x%llx, 0x%llx 0x%llx, 0x%llx 0x%llx\n", base, size, domain->geometry.aperture_start, domain->geometry.aperture_end, *dev->dma_mask, dev->coherent_dma_mask);
> 
> [  183.752100] ixgbevf 0000:81:10.0: 0x0 0x100000000, 0x0 0xffffffffffff, 0xffffffff 0xffffffff
> .....
> [  319.508037] vfio-pci 0000:81:10.0: 0x0 0x0, 0x0 0xffffffffffff, 0xffffffffffffffff 0xffffffffffffffff
> 
> Yes, size seems to be the problem here. When the VF  device gets attached to vfio-pci,
> somehow the dev->coherent_dma_mask is set to 64 bits and size become zero.

AFAICS, this is either down to patch 3 (which should apply on its own
easily enough for testing), or patch 6, implying that somehow the
vfio-pci device gets its DMA mask widened to 64 bits somewhere between
very soon after after creation (where we originally called
of_dma_configure()) and immediately before probe (where we now call it).

Either way I guess this is yet more motivation to write that "change the
arch_setup_dma_ops() interface to take a mask instead of a size" patch...

> @@ -107,7 +107,7 @@ int of_dma_configure(struct device *dev, struct device_node *np)
>   	ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
>   	if (ret < 0) {
>   		dma_addr = offset = 0;
>  -		size = dev->coherent_dma_mask + 1;
>  +		size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
> 
> @@ -1386,7 +1387,8 @@ int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr)
>   	 * Assume dma valid range starts at 0 and covers the whole
>   	 * coherent_dma_mask.
>   	 */
>  -	arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu,
>  +	size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
>  +	arch_setup_dma_ops(dev, 0, size, iommu,
>   			   attr == DEV_DMA_COHERENT);
> 
> With the above fixes, DT boot works fine. But we still get the below crash on ACPI
> 
>>> [  402.581445] kernel BUG at drivers/iommu/arm-smmu-v3.c:1064!
>>> [  402.587007] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
>>> [  402.592479] Modules linked in: vfio_iommu_type1 vfio_pci irqbypass
>> vfio_virqfd vfio ixgbevf ixgb

I can't see how ACPI vs. DT would make any difference to the domain
attach/detach mechanics getting into an invalid state (if the DT case
works then unbinding the ixgbevf driver clearly does release the Stream
ID correctly in general), so I'm more inclined to believe that something
goes wrong with the fwspec in the ACPI path such that we end up touching
the wrong STE altogether.

Robin.

>> The change that this series does is trying to add the dma/iommu ops to the
>> device after the iommu is actually probed.
>> So in your working case, does the device initially gets hooked to iommu_ops
>> and the above same check passes in working case ?
> 
> I believe so. Because didn't notice the "specified DMA range outside IOMMU capability"
> in the working case.
>  
> Thanks,
> Shameer
> 


WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>,
	Sricharan R <sricharan@codeaurora.org>,
	"Wangzhou (B)" <wangzhou1@hisilicon.com>,
	"will.deacon@arm.com" <will.deacon@arm.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"lorenzo.pieralisi@arm.com" <lorenzo.pieralisi@arm.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
	"m.szyprowski@samsung.com" <m.szyprowski@samsung.com>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"tn@semihalf.com" <tn@semihalf.com>,
	"hanjun.guo@linaro.org" <hanjun.guo@linaro.org>,
	"okaya@codeaurora.org" <okaya@codeaurora.org>
Subject: Re: [PATCH V9 00/11] IOMMU probe deferral support
Date: Fri, 24 Mar 2017 18:38:39 +0000	[thread overview]
Message-ID: <db3d68f8-713c-9ae2-7df9-324bc1b375b1@arm.com> (raw)
In-Reply-To: <5FC3163CFD30C246ABAA99954A238FA81750B7CB@lhreml504-mbs>

On 24/03/17 09:27, Shameerali Kolothum Thodi wrote:
> Hi Sricharan,
> 
>> -----Original Message-----
>> From: Sricharan R [mailto:sricharan@codeaurora.org]
>> Sent: Friday, March 24, 2017 7:10 AM
>> To: Wangzhou (B); robin.murphy@arm.com; will.deacon@arm.com;
>> joro@8bytes.org; lorenzo.pieralisi@arm.com; iommu@lists.linux-
>> foundation.org; linux-arm-kernel@lists.infradead.org; linux-arm-
>> msm@vger.kernel.org; m.szyprowski@samsung.com;
>> bhelgaas@google.com; linux-pci@vger.kernel.org; linux-
>> acpi@vger.kernel.org; tn@semihalf.com; hanjun.guo@linaro.org;
>> okaya@codeaurora.org
>> Cc: Shameerali Kolothum Thodi
>> Subject: Re: [PATCH V9 00/11] IOMMU probe deferral support
>>
>> Hi Zhou,
>>
>> On 3/24/2017 9:23 AM, Zhou Wang wrote:
>>> On 2017/3/10 3:00, Sricharan R wrote:
>>>> This series calls the dma ops configuration for the devices at a
>>>> generic place so that it works for all busses.
>>>> The dma_configure_ops for a device is now called during the
>>>> device_attach callback just before the probe of the bus/driver is
>>>> called. Similarly dma_deconfigure is called during
>>>> device/driver_detach path.
>>>>
>>>> pci_bus_add_devices    (platform/amba)(_device_create/driver_register)
>>>>        |                         |
>>>> pci_bus_add_device     (device_add/driver_register)
>>>>        |                         |
>>>> device_attach           device_initial_probe
>>>>        |                         |
>>>> __device_attach_driver    __device_attach_driver
>>>>        |
>>>> driver_probe_device
>>>>        |
>>>> really_probe
>>>>        |
>>>> dma_configure
>>>>
>>>> Similarly on the device/driver_unregister path
>>>> __device_release_driver is called which inturn calls dma_deconfigure.
>>>>
>>>> Rebased the series against mainline 4.11-rc1. Applies and builds
>>>> cleanly against mainline and linux-next. There is a conflict with
>>>> patch#9 against iommu-next, but that should go away eventually as
>>>> iommu-next is rebased against 4.11-rc1.
>>>>
>>>> * Tested with platform and pci devices for probe deferral
>>>>   and reprobe on arm64 based platform.
>>>
>>> Hi Sricharan,
>>>
>>> I applied this series on v4.11-rc1 to test PCIe pass through in
>>> HiSilicon
>>> D05 board(with Intel 82599 networking card). It failed.
>>>
>>> After I used:
>>>
>>> echo vfio-pci > /sys/bus/pci/devices/0002:81:10.0/driver_override
>>> echo 0002:81:10.0 > /sys/bus/pci/drivers/ixgbevf/unbind
>>> echo 0002:81:10.0 > /sys/bus/pci/drivers_probe
>>>
>>> to bind vfio-pci driver to Intel 82599 networking card VF.
>>>
>>> I got log in host:
>>> [...]
>>> [  414.275818] ixgbevf: Intel(R) 10 Gigabit PCI Express Virtual
>>> Function Network Driver - version 3.2.2-k [  414.275824] ixgbevf: Copyright
>> (c) 2009 - 2015 Intel Corporation.
>>> [  414.276647] ixgbe 0002:81:00.0 eth12: SR-IOV enabled with 1 VFs [
>>> 414.342252] pcieport 0002:80:00.0: can't derive routing for PCI INT A
>>> [  414.342255] ixgbe 0002:81:00.0: PCI INT A: no GSI [  414.343348]
>>> ixgbe 0002:81:00.0: Multiqueue Enabled: Rx Queue count = 4, Tx Queue
>>> count = 4 [  414.448135] pci 0002:81:10.0: [8086:10ed] type 00 class
>>> 0x020000 [  414.448713] iommu: Adding device 0002:81:10.0 to group 4 [
>>> 414.449798] ixgbevf 0002:81:10.0: enabling device (0000 -> 0002) [
>>> 414.451101] ixgbevf 0002:81:10.0: PF still in reset state.  Is the PF interface
>> up?
>>> [  414.451103] ixgbevf 0002:81:10.0: Assigning random MAC address [
>>> 414.451414] ixgbevf 0002:81:10.0: be:30:8f:ed:f8:02 [  414.451417]
>>> ixgbevf 0002:81:10.0: MAC: 1 [  414.451418] ixgbevf 0002:81:10.0:
>>> Intel(R) 82599 Virtual Function [  414.464271] VFIO - User Level
>>> meta-driver version: 0.3 [  414.570074] ixgbe 0002:81:00.0: registered
>>> PHC device on eth12
>>> [  414.700493] specified DMA range outside IOMMU capability
>> <-- error here
>>> [  414.700496] Failed to set up IOMMU for device 0002:81:10.0; retaining
>> platform DMA ops        <-- error here
>>
>> Looks like this triggers the start of the bug.
>> So the below check in iommu_dma_init_domain fails,
>>
>>          if (domain->geometry.force_aperture) {
>>                  if (base > domain->geometry.aperture_end ||
>>                      base + size <= domain->geometry.aperture_start) {
>>
>> and the rest goes out of sync after that. Can you print out the base,
>> aperture_start and end values to see why the check fails ?
> 
> dev_info(dev, "0x%llx 0x%llx, 0x%llx 0x%llx, 0x%llx 0x%llx\n", base, size, domain->geometry.aperture_start, domain->geometry.aperture_end, *dev->dma_mask, dev->coherent_dma_mask);
> 
> [  183.752100] ixgbevf 0000:81:10.0: 0x0 0x100000000, 0x0 0xffffffffffff, 0xffffffff 0xffffffff
> .....
> [  319.508037] vfio-pci 0000:81:10.0: 0x0 0x0, 0x0 0xffffffffffff, 0xffffffffffffffff 0xffffffffffffffff
> 
> Yes, size seems to be the problem here. When the VF  device gets attached to vfio-pci,
> somehow the dev->coherent_dma_mask is set to 64 bits and size become zero.

AFAICS, this is either down to patch 3 (which should apply on its own
easily enough for testing), or patch 6, implying that somehow the
vfio-pci device gets its DMA mask widened to 64 bits somewhere between
very soon after after creation (where we originally called
of_dma_configure()) and immediately before probe (where we now call it).

Either way I guess this is yet more motivation to write that "change the
arch_setup_dma_ops() interface to take a mask instead of a size" patch...

> @@ -107,7 +107,7 @@ int of_dma_configure(struct device *dev, struct device_node *np)
>   	ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
>   	if (ret < 0) {
>   		dma_addr = offset = 0;
>  -		size = dev->coherent_dma_mask + 1;
>  +		size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
> 
> @@ -1386,7 +1387,8 @@ int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr)
>   	 * Assume dma valid range starts at 0 and covers the whole
>   	 * coherent_dma_mask.
>   	 */
>  -	arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu,
>  +	size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
>  +	arch_setup_dma_ops(dev, 0, size, iommu,
>   			   attr == DEV_DMA_COHERENT);
> 
> With the above fixes, DT boot works fine. But we still get the below crash on ACPI
> 
>>> [  402.581445] kernel BUG at drivers/iommu/arm-smmu-v3.c:1064!
>>> [  402.587007] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
>>> [  402.592479] Modules linked in: vfio_iommu_type1 vfio_pci irqbypass
>> vfio_virqfd vfio ixgbevf ixgb

I can't see how ACPI vs. DT would make any difference to the domain
attach/detach mechanics getting into an invalid state (if the DT case
works then unbinding the ixgbevf driver clearly does release the Stream
ID correctly in general), so I'm more inclined to believe that something
goes wrong with the fwspec in the ACPI path such that we end up touching
the wrong STE altogether.

Robin.

>> The change that this series does is trying to add the dma/iommu ops to the
>> device after the iommu is actually probed.
>> So in your working case, does the device initially gets hooked to iommu_ops
>> and the above same check passes in working case ?
> 
> I believe so. Because didn't notice the "specified DMA range outside IOMMU capability"
> in the working case.
>  
> Thanks,
> Shameer
> 


WARNING: multiple messages have this Message-ID (diff)
From: robin.murphy@arm.com (Robin Murphy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V9 00/11] IOMMU probe deferral support
Date: Fri, 24 Mar 2017 18:38:39 +0000	[thread overview]
Message-ID: <db3d68f8-713c-9ae2-7df9-324bc1b375b1@arm.com> (raw)
In-Reply-To: <5FC3163CFD30C246ABAA99954A238FA81750B7CB@lhreml504-mbs>

On 24/03/17 09:27, Shameerali Kolothum Thodi wrote:
> Hi Sricharan,
> 
>> -----Original Message-----
>> From: Sricharan R [mailto:sricharan at codeaurora.org]
>> Sent: Friday, March 24, 2017 7:10 AM
>> To: Wangzhou (B); robin.murphy at arm.com; will.deacon at arm.com;
>> joro at 8bytes.org; lorenzo.pieralisi at arm.com; iommu at lists.linux-
>> foundation.org; linux-arm-kernel at lists.infradead.org; linux-arm-
>> msm at vger.kernel.org; m.szyprowski at samsung.com;
>> bhelgaas at google.com; linux-pci at vger.kernel.org; linux-
>> acpi at vger.kernel.org; tn at semihalf.com; hanjun.guo at linaro.org;
>> okaya at codeaurora.org
>> Cc: Shameerali Kolothum Thodi
>> Subject: Re: [PATCH V9 00/11] IOMMU probe deferral support
>>
>> Hi Zhou,
>>
>> On 3/24/2017 9:23 AM, Zhou Wang wrote:
>>> On 2017/3/10 3:00, Sricharan R wrote:
>>>> This series calls the dma ops configuration for the devices at a
>>>> generic place so that it works for all busses.
>>>> The dma_configure_ops for a device is now called during the
>>>> device_attach callback just before the probe of the bus/driver is
>>>> called. Similarly dma_deconfigure is called during
>>>> device/driver_detach path.
>>>>
>>>> pci_bus_add_devices    (platform/amba)(_device_create/driver_register)
>>>>        |                         |
>>>> pci_bus_add_device     (device_add/driver_register)
>>>>        |                         |
>>>> device_attach           device_initial_probe
>>>>        |                         |
>>>> __device_attach_driver    __device_attach_driver
>>>>        |
>>>> driver_probe_device
>>>>        |
>>>> really_probe
>>>>        |
>>>> dma_configure
>>>>
>>>> Similarly on the device/driver_unregister path
>>>> __device_release_driver is called which inturn calls dma_deconfigure.
>>>>
>>>> Rebased the series against mainline 4.11-rc1. Applies and builds
>>>> cleanly against mainline and linux-next. There is a conflict with
>>>> patch#9 against iommu-next, but that should go away eventually as
>>>> iommu-next is rebased against 4.11-rc1.
>>>>
>>>> * Tested with platform and pci devices for probe deferral
>>>>   and reprobe on arm64 based platform.
>>>
>>> Hi Sricharan,
>>>
>>> I applied this series on v4.11-rc1 to test PCIe pass through in
>>> HiSilicon
>>> D05 board(with Intel 82599 networking card). It failed.
>>>
>>> After I used:
>>>
>>> echo vfio-pci > /sys/bus/pci/devices/0002:81:10.0/driver_override
>>> echo 0002:81:10.0 > /sys/bus/pci/drivers/ixgbevf/unbind
>>> echo 0002:81:10.0 > /sys/bus/pci/drivers_probe
>>>
>>> to bind vfio-pci driver to Intel 82599 networking card VF.
>>>
>>> I got log in host:
>>> [...]
>>> [  414.275818] ixgbevf: Intel(R) 10 Gigabit PCI Express Virtual
>>> Function Network Driver - version 3.2.2-k [  414.275824] ixgbevf: Copyright
>> (c) 2009 - 2015 Intel Corporation.
>>> [  414.276647] ixgbe 0002:81:00.0 eth12: SR-IOV enabled with 1 VFs [
>>> 414.342252] pcieport 0002:80:00.0: can't derive routing for PCI INT A
>>> [  414.342255] ixgbe 0002:81:00.0: PCI INT A: no GSI [  414.343348]
>>> ixgbe 0002:81:00.0: Multiqueue Enabled: Rx Queue count = 4, Tx Queue
>>> count = 4 [  414.448135] pci 0002:81:10.0: [8086:10ed] type 00 class
>>> 0x020000 [  414.448713] iommu: Adding device 0002:81:10.0 to group 4 [
>>> 414.449798] ixgbevf 0002:81:10.0: enabling device (0000 -> 0002) [
>>> 414.451101] ixgbevf 0002:81:10.0: PF still in reset state.  Is the PF interface
>> up?
>>> [  414.451103] ixgbevf 0002:81:10.0: Assigning random MAC address [
>>> 414.451414] ixgbevf 0002:81:10.0: be:30:8f:ed:f8:02 [  414.451417]
>>> ixgbevf 0002:81:10.0: MAC: 1 [  414.451418] ixgbevf 0002:81:10.0:
>>> Intel(R) 82599 Virtual Function [  414.464271] VFIO - User Level
>>> meta-driver version: 0.3 [  414.570074] ixgbe 0002:81:00.0: registered
>>> PHC device on eth12
>>> [  414.700493] specified DMA range outside IOMMU capability
>> <-- error here
>>> [  414.700496] Failed to set up IOMMU for device 0002:81:10.0; retaining
>> platform DMA ops        <-- error here
>>
>> Looks like this triggers the start of the bug.
>> So the below check in iommu_dma_init_domain fails,
>>
>>          if (domain->geometry.force_aperture) {
>>                  if (base > domain->geometry.aperture_end ||
>>                      base + size <= domain->geometry.aperture_start) {
>>
>> and the rest goes out of sync after that. Can you print out the base,
>> aperture_start and end values to see why the check fails ?
> 
> dev_info(dev, "0x%llx 0x%llx, 0x%llx 0x%llx, 0x%llx 0x%llx\n", base, size, domain->geometry.aperture_start, domain->geometry.aperture_end, *dev->dma_mask, dev->coherent_dma_mask);
> 
> [  183.752100] ixgbevf 0000:81:10.0: 0x0 0x100000000, 0x0 0xffffffffffff, 0xffffffff 0xffffffff
> .....
> [  319.508037] vfio-pci 0000:81:10.0: 0x0 0x0, 0x0 0xffffffffffff, 0xffffffffffffffff 0xffffffffffffffff
> 
> Yes, size seems to be the problem here. When the VF  device gets attached to vfio-pci,
> somehow the dev->coherent_dma_mask is set to 64 bits and size become zero.

AFAICS, this is either down to patch 3 (which should apply on its own
easily enough for testing), or patch 6, implying that somehow the
vfio-pci device gets its DMA mask widened to 64 bits somewhere between
very soon after after creation (where we originally called
of_dma_configure()) and immediately before probe (where we now call it).

Either way I guess this is yet more motivation to write that "change the
arch_setup_dma_ops() interface to take a mask instead of a size" patch...

> @@ -107,7 +107,7 @@ int of_dma_configure(struct device *dev, struct device_node *np)
>   	ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
>   	if (ret < 0) {
>   		dma_addr = offset = 0;
>  -		size = dev->coherent_dma_mask + 1;
>  +		size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
> 
> @@ -1386,7 +1387,8 @@ int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr)
>   	 * Assume dma valid range starts at 0 and covers the whole
>   	 * coherent_dma_mask.
>   	 */
>  -	arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu,
>  +	size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
>  +	arch_setup_dma_ops(dev, 0, size, iommu,
>   			   attr == DEV_DMA_COHERENT);
> 
> With the above fixes, DT boot works fine. But we still get the below crash on ACPI
> 
>>> [  402.581445] kernel BUG at drivers/iommu/arm-smmu-v3.c:1064!
>>> [  402.587007] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
>>> [  402.592479] Modules linked in: vfio_iommu_type1 vfio_pci irqbypass
>> vfio_virqfd vfio ixgbevf ixgb

I can't see how ACPI vs. DT would make any difference to the domain
attach/detach mechanics getting into an invalid state (if the DT case
works then unbinding the ixgbevf driver clearly does release the Stream
ID correctly in general), so I'm more inclined to believe that something
goes wrong with the fwspec in the ACPI path such that we end up touching
the wrong STE altogether.

Robin.

>> The change that this series does is trying to add the dma/iommu ops to the
>> device after the iommu is actually probed.
>> So in your working case, does the device initially gets hooked to iommu_ops
>> and the above same check passes in working case ?
> 
> I believe so. Because didn't notice the "specified DMA range outside IOMMU capability"
> in the working case.
>  
> Thanks,
> Shameer
> 

  parent reply	other threads:[~2017-03-24 18:38 UTC|newest]

Thread overview: 217+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-09 19:00 [PATCH V9 00/11] IOMMU probe deferral support Sricharan R
2017-03-09 19:00 ` Sricharan R
2017-03-09 19:00 ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 02/11] iommu/of: Prepare for deferred IOMMU configuration Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 03/11] of: dma: Move range size workaround to of_dma_get_range() Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 04/11] of: dma: Make of_dma_deconfigure() public Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 05/11] ACPI/IORT: Add function to check SMMUs drivers presence Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 06/11] of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 08/11] drivers: acpi: Handle IOMMU lookup failure with deferred probing or error Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:00 ` [PATCH V9 09/11] arm64: dma-mapping: Remove the notifier trick to handle early setting of dma_ops Sricharan R
2017-03-09 19:00   ` Sricharan R
2017-03-09 19:01 ` [PATCH V9 10/11] iommu/arm-smmu: Clean up early-probing workarounds Sricharan R
2017-03-09 19:01   ` Sricharan R
2017-03-09 19:01 ` [PATCH V9 11/11] ACPI/IORT: Remove linker section for IORT entries probing Sricharan R
2017-03-09 19:01   ` Sricharan R
2017-03-24  3:53 ` [PATCH V9 00/11] IOMMU probe deferral support Zhou Wang
2017-03-24  3:53   ` Zhou Wang
2017-03-24  3:53   ` Zhou Wang
     [not found]   ` <58D49845.9060407-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
2017-03-24  7:09     ` Sricharan R
2017-03-24  7:09       ` Sricharan R
2017-03-24  7:09       ` Sricharan R
     [not found]       ` <0ea8022b-a19b-335d-6cc6-81510196f891-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-24  9:27         ` Shameerali Kolothum Thodi
2017-03-24  9:27           ` Shameerali Kolothum Thodi
2017-03-24  9:27           ` Shameerali Kolothum Thodi
2017-03-24 12:50           ` Sricharan R
2017-03-24 12:50             ` Sricharan R
2017-03-24 12:50             ` Sricharan R
2017-03-24 14:43           ` Lorenzo Pieralisi
2017-03-24 14:43             ` Lorenzo Pieralisi
2017-03-24 14:43             ` Lorenzo Pieralisi
2017-03-24 15:09             ` Shameerali Kolothum Thodi
2017-03-24 15:09               ` Shameerali Kolothum Thodi
2017-03-24 15:09               ` Shameerali Kolothum Thodi
2017-03-24 18:38           ` Robin Murphy [this message]
2017-03-24 18:38             ` Robin Murphy
2017-03-24 18:38             ` Robin Murphy
     [not found]             ` <db3d68f8-713c-9ae2-7df9-324bc1b375b1-5wv7dgnIgG8@public.gmane.org>
2017-03-27 14:53               ` Shameerali Kolothum Thodi
2017-03-27 15:58             ` Shameerali Kolothum Thodi
2017-03-27 15:58               ` Shameerali Kolothum Thodi
2017-03-27 15:58               ` Shameerali Kolothum Thodi
2017-03-27 16:18               ` Robin Murphy
2017-03-27 16:18                 ` Robin Murphy
2017-03-27 16:18                 ` Robin Murphy
     [not found]                 ` <f67fb561-4238-6933-04f3-0f910f9232d1-5wv7dgnIgG8@public.gmane.org>
2017-03-27 17:33                   ` Lorenzo Pieralisi
2017-03-27 17:33                     ` Lorenzo Pieralisi
2017-03-27 17:33                     ` Lorenzo Pieralisi
2017-03-28  4:53                   ` Sricharan R
2017-03-28  4:53                     ` Sricharan R
2017-03-28  4:53                     ` Sricharan R
     [not found]                     ` <8d7ba471-84d4-b9f3-9d2a-de166f6839d4-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-28 14:15                       ` Shameerali Kolothum Thodi
2017-03-28 14:15                         ` Shameerali Kolothum Thodi
2017-03-28 14:15                         ` Shameerali Kolothum Thodi
2017-03-28 16:07                         ` Sricharan R
2017-03-28 16:07                           ` Sricharan R
2017-03-28 16:07                           ` Sricharan R
     [not found] ` <1489086061-9356-1-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-09 19:00   ` [PATCH V9 01/11] iommu/of: Refactor of_iommu_configure() for error handling Sricharan R
2017-03-09 19:00     ` Sricharan R
2017-03-09 19:00     ` Sricharan R
2017-03-09 19:00   ` [PATCH V9 07/11] iommu: of: Handle IOMMU lookup failure with deferred probing or error Sricharan R
2017-03-09 19:00     ` Sricharan R
2017-03-09 19:00     ` Sricharan R
     [not found]     ` <1489086061-9356-8-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-28 15:00       ` [V9, " Rob Herring
2017-03-28 15:00         ` Rob Herring
2017-03-28 15:00         ` Rob Herring
2017-03-28 15:11         ` Robin Murphy
2017-03-28 15:11           ` Robin Murphy
2017-03-28 15:11           ` Robin Murphy
2017-03-28 16:06         ` Sricharan R
2017-03-28 16:06           ` Sricharan R
2017-03-28 16:06           ` Sricharan R
2017-04-04 10:18   ` [PATCH V10 00/12] IOMMU probe deferral support Sricharan R
2017-04-04 10:18     ` Sricharan R
2017-04-04 10:18     ` Sricharan R
2017-04-04 10:18     ` Sricharan R
     [not found]     ` <1491301105-5274-1-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-04 10:18       ` [PATCH V10 01/12] iommu/of: Refactor of_iommu_configure() for error handling Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18       ` [PATCH V10 02/12] iommu/of: Prepare for deferred IOMMU configuration Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18       ` [PATCH V10 03/12] of: dma: Move range size workaround to of_dma_get_range() Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
     [not found]         ` <1491301105-5274-4-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-04 10:46           ` Robin Murphy
2017-04-04 10:46             ` Robin Murphy
2017-04-04 10:46             ` Robin Murphy
2017-04-04 10:46             ` Robin Murphy
2017-04-06  6:24         ` Frank Rowand
2017-04-06  6:24           ` Frank Rowand
2017-04-06  6:24           ` Frank Rowand
     [not found]           ` <58E5DF13.2020700-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-06  9:35             ` Sricharan R
2017-04-06  9:35               ` Sricharan R
2017-04-06  9:35               ` Sricharan R
2017-04-06  9:35               ` Sricharan R
2017-04-06 10:03             ` Robin Murphy
2017-04-06 10:03               ` Robin Murphy
2017-04-06 10:03               ` Robin Murphy
2017-04-06 10:03               ` Robin Murphy
2017-04-04 10:18       ` [PATCH V10 04/12] of: dma: Make of_dma_deconfigure() public Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
     [not found]         ` <1491301105-5274-5-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-04 10:47           ` Robin Murphy
2017-04-04 10:47             ` Robin Murphy
2017-04-04 10:47             ` Robin Murphy
2017-04-04 10:47             ` Robin Murphy
2017-04-04 10:18       ` [PATCH V10 05/12] ACPI/IORT: Add function to check SMMUs drivers presence Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
     [not found]         ` <1491301105-5274-6-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-04 11:04           ` Robin Murphy
2017-04-04 11:04             ` Robin Murphy
2017-04-04 11:04             ` Robin Murphy
2017-04-04 11:04             ` Robin Murphy
2017-04-04 10:18       ` [PATCH V10 06/12] of: device: Fix overflow of coherent_dma_mask Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
     [not found]         ` <1491301105-5274-7-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-04 11:10           ` Robin Murphy
2017-04-04 11:10             ` Robin Murphy
2017-04-04 11:10             ` Robin Murphy
2017-04-04 11:10             ` Robin Murphy
2017-04-06  7:01         ` Frank Rowand
2017-04-06  7:01           ` Frank Rowand
     [not found]           ` <58E5E7B7.1050400-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-06 10:24             ` Robin Murphy
2017-04-06 10:24               ` Robin Murphy
2017-04-06 10:24               ` Robin Murphy
2017-04-06 10:24               ` Robin Murphy
     [not found]               ` <b081f333-084d-ffa5-635f-f7f1c0232ac3-5wv7dgnIgG8@public.gmane.org>
2017-04-06 13:56                 ` Rob Herring
2017-04-06 13:56                   ` Rob Herring
2017-04-06 13:56                   ` Rob Herring
2017-04-06 13:56                   ` Rob Herring
2017-04-06 13:56                   ` Rob Herring
     [not found]                   ` <CAL_JsqLsE378hfs=xNvSdPV2r+7H81cAFzOwtda2W+mFVoohuA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-06 14:45                     ` Robin Murphy
2017-04-06 14:45                       ` Robin Murphy
2017-04-06 14:45                       ` Robin Murphy
2017-04-06 14:45                       ` Robin Murphy
2017-04-06 19:24               ` Frank Rowand
2017-04-06 19:24                 ` Frank Rowand
2017-04-06 19:24                 ` Frank Rowand
2017-04-06 11:01           ` Sricharan R
2017-04-06 11:01             ` Sricharan R
2017-04-06 11:01             ` Sricharan R
     [not found]             ` <b77e3405-f060-bcd5-99f6-7d76f9edf08a-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-06 19:34               ` Frank Rowand
2017-04-06 19:34                 ` Frank Rowand
2017-04-06 19:34                 ` Frank Rowand
2017-04-06 19:34                 ` Frank Rowand
2017-04-07  4:12                 ` Sricharan R
2017-04-07  4:12                   ` Sricharan R
2017-04-07  4:12                   ` Sricharan R
2017-04-07 14:46                 ` Robin Murphy
2017-04-07 14:46                   ` Robin Murphy
2017-04-07 23:13                   ` Frank Rowand
2017-04-07 23:13                     ` Frank Rowand
     [not found]                     ` <58E81D01.8030606-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-04-10 13:25                       ` Robin Murphy
2017-04-10 13:25                         ` Robin Murphy
2017-04-10 13:25                         ` Robin Murphy
2017-04-10 13:25                         ` Robin Murphy
2017-04-07 23:10           ` Frank Rowand
2017-04-07 23:10             ` Frank Rowand
2017-04-04 10:18       ` [PATCH V10 07/12] of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
     [not found]         ` <1491301105-5274-8-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-04 12:17           ` Robin Murphy
2017-04-04 12:17             ` Robin Murphy
2017-04-04 12:17             ` Robin Murphy
2017-04-04 12:17             ` Robin Murphy
2017-04-04 12:30             ` Sricharan R
2017-04-04 12:30               ` Sricharan R
2017-04-04 12:30               ` Sricharan R
2017-04-04 10:18       ` [PATCH V10 08/12] iommu: of: Handle IOMMU lookup failure with deferred probing or error Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 11:24         ` Robin Murphy
2017-04-04 11:24           ` Robin Murphy
2017-04-04 10:18       ` [PATCH V10 09/12] drivers: acpi: " Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 11:31         ` Robin Murphy
2017-04-04 11:31           ` Robin Murphy
2017-04-04 11:31           ` Robin Murphy
2017-04-04 10:18       ` [PATCH V10 10/12] arm64: dma-mapping: Remove the notifier trick to handle early setting of dma_ops Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18       ` [PATCH V10 11/12] iommu/arm-smmu: Clean up early-probing workarounds Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18       ` [PATCH V10 12/12] ACPI/IORT: Remove linker section for IORT entries probing Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 10:18         ` Sricharan R
2017-04-04 11:33         ` Robin Murphy
2017-04-04 11:33           ` Robin Murphy
2017-04-04 11:33           ` Robin Murphy
2017-04-04 12:49     ` [PATCH V10 00/12] IOMMU probe deferral support Robin Murphy
2017-04-04 12:49       ` Robin Murphy
2017-04-04 12:49       ` Robin Murphy
     [not found]       ` <b0f3a1ec-ea13-7465-1d44-9191e3e803ef-5wv7dgnIgG8@public.gmane.org>
2017-04-05 10:04         ` Lorenzo Pieralisi
2017-04-05 10:04           ` Lorenzo Pieralisi
2017-04-05 10:04           ` Lorenzo Pieralisi
2017-04-05 10:04           ` Lorenzo Pieralisi
2017-04-05  1:23     ` Rob Herring
2017-04-05  1:23       ` Rob Herring
2017-04-05  1:23       ` Rob Herring
2017-04-05  1:23       ` Rob Herring
2017-04-06 18:46       ` Frank Rowand
2017-04-06 18:46         ` Frank Rowand
2017-04-06 18:46         ` Frank Rowand
2017-04-06 18:46         ` Frank Rowand
2017-04-06 18:46         ` Frank Rowand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db3d68f8-713c-9ae2-7df9-324bc1b375b1@arm.com \
    --to=robin.murphy@arm.com \
    --cc=bhelgaas@google.com \
    --cc=hanjun.guo@linaro.o \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=m.szyprowski@samsung.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=sricharan@codeaurora.org \
    --cc=tn@semihalf.com \
    --cc=wangzhou1@hisilicon.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.