All of lore.kernel.org
 help / color / mirror / Atom feed
* [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-10 12:33 ` Pankaj Bansal
  0 siblings, 0 replies; 14+ messages in thread
From: Pankaj Bansal @ 2019-05-10 12:33 UTC (permalink / raw)
  To: Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

Hi Will/Robin/Joerg,

I am s/w engineer from NXP India Pvt. Ltd.
We are using SMMU-V3 in one of NXP SOC.
I have a question about the SMMU Stream ID allocation in linux.

Right now the Stream IDs allocated to a device are mapped via device tree to the device.
https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iommu/arm,smmu-v3.txt#L39

As the device tree is passed from bootloader to linux, we detect all the stream IDs needed by a device in bootloader and add their IDs in respective device nodes.
For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we are assigning a unique Stream ID in bootloader.

However, this poses an issue with PCIE hot plug.
If we plug in a pcie device while linux is running, a unique BDF is assigned to the device, for which there is no stream ID in device tree.

How can this problem be solved in linux?

Is there a way to assign (and revoke) stream IDs at run time?

Regards,
Pankaj Bansal

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-10 12:33 ` Pankaj Bansal
  0 siblings, 0 replies; 14+ messages in thread
From: Pankaj Bansal @ 2019-05-10 12:33 UTC (permalink / raw)
  To: Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel, Nipun Gupta

Hi Will/Robin/Joerg,

I am s/w engineer from NXP India Pvt. Ltd.
We are using SMMU-V3 in one of NXP SOC.
I have a question about the SMMU Stream ID allocation in linux.

Right now the Stream IDs allocated to a device are mapped via device tree to the device.
https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iommu/arm,smmu-v3.txt#L39

As the device tree is passed from bootloader to linux, we detect all the stream IDs needed by a device in bootloader and add their IDs in respective device nodes.
For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we are assigning a unique Stream ID in bootloader.

However, this poses an issue with PCIE hot plug.
If we plug in a pcie device while linux is running, a unique BDF is assigned to the device, for which there is no stream ID in device tree.

How can this problem be solved in linux?

Is there a way to assign (and revoke) stream IDs at run time?

Regards,
Pankaj Bansal


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [ARM SMMU] Dynamic StreamID allocation
  2019-05-10 12:33 ` Pankaj Bansal
@ 2019-05-10 13:19   ` Pankaj Bansal
  -1 siblings, 0 replies; 14+ messages in thread
From: Pankaj Bansal @ 2019-05-10 13:19 UTC (permalink / raw)
  To: Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

Correction: we use ARM SMMU-500.
Corresponding bindings are : https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iommu/arm,smmu.txt#L49

The #iommu-cells is 1 in our SOC: https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi#L693

Regards,
Pankaj Bansal

> -----Original Message-----
> From: Pankaj Bansal
> Sent: Friday, 10 May, 2019 06:04 PM
> To: Will Deacon <will.deacon@arm.com>; Robin Murphy
> <robin.murphy@arm.com>; Joerg Roedel <joro@8bytes.org>
> Cc: linux-arm-kernel@lists.infradead.org; iommu@lists.linux-foundation.org;
> Varun Sethi <V.Sethi@nxp.com>; Nipun Gupta <nipun.gupta@nxp.com>
> Subject: [ARM SMMU] Dynamic StreamID allocation
> 
> Hi Will/Robin/Joerg,
> 
> I am s/w engineer from NXP India Pvt. Ltd.
> We are using SMMU-V3 in one of NXP SOC.
> I have a question about the SMMU Stream ID allocation in linux.
> 
> Right now the Stream IDs allocated to a device are mapped via device tree to
> the device.
> https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindin
> gs/iommu/arm,smmu-v3.txt#L39
> 
> As the device tree is passed from bootloader to linux, we detect all the stream
> IDs needed by a device in bootloader and add their IDs in respective device
> nodes.
> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we are
> assigning a unique Stream ID in bootloader.
> 
> However, this poses an issue with PCIE hot plug.
> If we plug in a pcie device while linux is running, a unique BDF is assigned to the
> device, for which there is no stream ID in device tree.
> 
> How can this problem be solved in linux?
> 
> Is there a way to assign (and revoke) stream IDs at run time?
> 
> Regards,
> Pankaj Bansal

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-10 13:19   ` Pankaj Bansal
  0 siblings, 0 replies; 14+ messages in thread
From: Pankaj Bansal @ 2019-05-10 13:19 UTC (permalink / raw)
  To: Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel, Nipun Gupta

Correction: we use ARM SMMU-500.
Corresponding bindings are : https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iommu/arm,smmu.txt#L49

The #iommu-cells is 1 in our SOC: https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi#L693

Regards,
Pankaj Bansal

> -----Original Message-----
> From: Pankaj Bansal
> Sent: Friday, 10 May, 2019 06:04 PM
> To: Will Deacon <will.deacon@arm.com>; Robin Murphy
> <robin.murphy@arm.com>; Joerg Roedel <joro@8bytes.org>
> Cc: linux-arm-kernel@lists.infradead.org; iommu@lists.linux-foundation.org;
> Varun Sethi <V.Sethi@nxp.com>; Nipun Gupta <nipun.gupta@nxp.com>
> Subject: [ARM SMMU] Dynamic StreamID allocation
> 
> Hi Will/Robin/Joerg,
> 
> I am s/w engineer from NXP India Pvt. Ltd.
> We are using SMMU-V3 in one of NXP SOC.
> I have a question about the SMMU Stream ID allocation in linux.
> 
> Right now the Stream IDs allocated to a device are mapped via device tree to
> the device.
> https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindin
> gs/iommu/arm,smmu-v3.txt#L39
> 
> As the device tree is passed from bootloader to linux, we detect all the stream
> IDs needed by a device in bootloader and add their IDs in respective device
> nodes.
> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we are
> assigning a unique Stream ID in bootloader.
> 
> However, this poses an issue with PCIE hot plug.
> If we plug in a pcie device while linux is running, a unique BDF is assigned to the
> device, for which there is no stream ID in device tree.
> 
> How can this problem be solved in linux?
> 
> Is there a way to assign (and revoke) stream IDs at run time?
> 
> Regards,
> Pankaj Bansal


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [ARM SMMU] Dynamic StreamID allocation
  2019-05-10 12:33 ` Pankaj Bansal
@ 2019-05-10 13:36   ` Jean-Philippe Brucker
  -1 siblings, 0 replies; 14+ messages in thread
From: Jean-Philippe Brucker @ 2019-05-10 13:36 UTC (permalink / raw)
  To: Pankaj Bansal, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

On 10/05/2019 13:33, Pankaj Bansal wrote:
> Hi Will/Robin/Joerg,
> 
> I am s/w engineer from NXP India Pvt. Ltd.
> We are using SMMU-V3 in one of NXP SOC.
> I have a question about the SMMU Stream ID allocation in linux.
> 
> Right now the Stream IDs allocated to a device are mapped via device tree to the device.
> https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iommu/arm,smmu-v3.txt#L39
> 
> As the device tree is passed from bootloader to linux, we detect all the stream IDs needed by a device in bootloader and add their IDs in respective device nodes.
> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we are assigning a unique Stream ID in bootloader.
> 
> However, this poses an issue with PCIE hot plug.
> If we plug in a pcie device while linux is running, a unique BDF is assigned to the device, for which there is no stream ID in device tree.
> 
> How can this problem be solved in linux?

Assuming the streamID associated to a BDF is predictable (streamID = BDF
+ constant), using the iommu-map property should just work:

https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/pci/pci-iommu.txt

It describes the streamIDs of all possible BDFs, including hotplugged
functions.

Thanks,
Jean

> 
> Is there a way to assign (and revoke) stream IDs at run time?
> 
> Regards,
> Pankaj Bansal
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-10 13:36   ` Jean-Philippe Brucker
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Philippe Brucker @ 2019-05-10 13:36 UTC (permalink / raw)
  To: Pankaj Bansal, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel, Nipun Gupta

On 10/05/2019 13:33, Pankaj Bansal wrote:
> Hi Will/Robin/Joerg,
> 
> I am s/w engineer from NXP India Pvt. Ltd.
> We are using SMMU-V3 in one of NXP SOC.
> I have a question about the SMMU Stream ID allocation in linux.
> 
> Right now the Stream IDs allocated to a device are mapped via device tree to the device.
> https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/iommu/arm,smmu-v3.txt#L39
> 
> As the device tree is passed from bootloader to linux, we detect all the stream IDs needed by a device in bootloader and add their IDs in respective device nodes.
> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we are assigning a unique Stream ID in bootloader.
> 
> However, this poses an issue with PCIE hot plug.
> If we plug in a pcie device while linux is running, a unique BDF is assigned to the device, for which there is no stream ID in device tree.
> 
> How can this problem be solved in linux?

Assuming the streamID associated to a BDF is predictable (streamID = BDF
+ constant), using the iommu-map property should just work:

https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/pci/pci-iommu.txt

It describes the streamIDs of all possible BDFs, including hotplugged
functions.

Thanks,
Jean

> 
> Is there a way to assign (and revoke) stream IDs at run time?
> 
> Regards,
> Pankaj Bansal
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [ARM SMMU] Dynamic StreamID allocation
  2019-05-10 13:36   ` Jean-Philippe Brucker
@ 2019-05-13  7:09     ` Pankaj Bansal
  -1 siblings, 0 replies; 14+ messages in thread
From: Pankaj Bansal @ 2019-05-13  7:09 UTC (permalink / raw)
  To: Jean-Philippe Brucker, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

Hi Jean,

> -----Original Message-----
> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
> Sent: Friday, 10 May, 2019 07:07 PM
> To: Pankaj Bansal <pankaj.bansal@nxp.com>; Will Deacon
> <will.deacon@arm.com>; Robin Murphy <robin.murphy@arm.com>; Joerg
> Roedel <joro@8bytes.org>
> Cc: iommu@lists.linux-foundation.org; Varun Sethi <V.Sethi@nxp.com>; linux-
> arm-kernel@lists.infradead.org; Nipun Gupta <nipun.gupta@nxp.com>
> Subject: Re: [ARM SMMU] Dynamic StreamID allocation
> 
> On 10/05/2019 13:33, Pankaj Bansal wrote:
> > Hi Will/Robin/Joerg,
> >
> > I am s/w engineer from NXP India Pvt. Ltd.
> > We are using SMMU-V3 in one of NXP SOC.
> > I have a question about the SMMU Stream ID allocation in linux.
> >
> > Right now the Stream IDs allocated to a device are mapped via device tree to
> the device.
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
> > ir.bootlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%
> > 2Fbindings%2Fiommu%2Farm%2Csmmu-
> v3.txt%23L39&amp;data=02%7C01%7Cpankaj
> > .bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C686ea1d3b
> c2b4c6
> >
> fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sdata=vIG5u5n
> XR5iRp
> > uuuGjeFxKBtA5f5ohf91znXX0QWm1c%3D&amp;reserved=0
> >
> > As the device tree is passed from bootloader to linux, we detect all the stream
> IDs needed by a device in bootloader and add their IDs in respective device
> nodes.
> > For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we
> are assigning a unique Stream ID in bootloader.
> >
> > However, this poses an issue with PCIE hot plug.
> > If we plug in a pcie device while linux is running, a unique BDF is assigned to
> the device, for which there is no stream ID in device tree.
> >
> > How can this problem be solved in linux?
> 
> Assuming the streamID associated to a BDF is predictable (streamID = BDF
> + constant), using the iommu-map property should just work:
> 
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo
> tlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%2Fbind
> ings%2Fpci%2Fpci-
> iommu.txt&amp;data=02%7C01%7Cpankaj.bansal%40nxp.com%7C3cbe8bd482
> 7e425afd0f08d6d54c925e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C636930922220665343&amp;sdata=GkkovEnvhd5dN%2BGdh%2FnKCyW5Cd
> EnLDP3cWTrk%2B%2FO7EQ%3D&amp;reserved=0
> 
> It describes the streamIDs of all possible BDFs, including hotplugged functions.

You mean that we should increase the "length" parameter (in (rid-base,iommu,iommu-base,length) touple) ?
This would cater to any *new* Bus Device Function being detected on PCIE bus?
Is that right ?
Right now when we make iommu-map in bootloader, we are giving one RID per BDF:
https://elixir.bootlin.com/u-boot/latest/source/drivers/pci/pcie_layerscape_fixup.c#L168

But isn't the better approach to make it dynamic in linux?
i.e. as soon as a new device is detected "requester id" is allocated to it from available pool.
When device is removed, return the "requester id" to pool.
is there any h/w limitation which prevents it?

Regards,
Pankaj Bansal
> 
> Thanks,
> Jean
> 
> >
> > Is there a way to assign (and revoke) stream IDs at run time?
> >
> > Regards,
> > Pankaj Bansal
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists
> > .infradead.org%2Fmailman%2Flistinfo%2Flinux-arm-
> kernel&amp;data=02%7C0
> >
> 1%7Cpankaj.bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C6
> 86ea
> >
> 1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sda
> ta=2La
> > GBHO2%2Bbqk519uJvCatlHyRCtAPPjKO8Gxu1bQHBM%3D&amp;reserved=0
> >

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-13  7:09     ` Pankaj Bansal
  0 siblings, 0 replies; 14+ messages in thread
From: Pankaj Bansal @ 2019-05-13  7:09 UTC (permalink / raw)
  To: Jean-Philippe Brucker, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel, Nipun Gupta

Hi Jean,

> -----Original Message-----
> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
> Sent: Friday, 10 May, 2019 07:07 PM
> To: Pankaj Bansal <pankaj.bansal@nxp.com>; Will Deacon
> <will.deacon@arm.com>; Robin Murphy <robin.murphy@arm.com>; Joerg
> Roedel <joro@8bytes.org>
> Cc: iommu@lists.linux-foundation.org; Varun Sethi <V.Sethi@nxp.com>; linux-
> arm-kernel@lists.infradead.org; Nipun Gupta <nipun.gupta@nxp.com>
> Subject: Re: [ARM SMMU] Dynamic StreamID allocation
> 
> On 10/05/2019 13:33, Pankaj Bansal wrote:
> > Hi Will/Robin/Joerg,
> >
> > I am s/w engineer from NXP India Pvt. Ltd.
> > We are using SMMU-V3 in one of NXP SOC.
> > I have a question about the SMMU Stream ID allocation in linux.
> >
> > Right now the Stream IDs allocated to a device are mapped via device tree to
> the device.
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
> > ir.bootlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%
> > 2Fbindings%2Fiommu%2Farm%2Csmmu-
> v3.txt%23L39&amp;data=02%7C01%7Cpankaj
> > .bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C686ea1d3b
> c2b4c6
> >
> fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sdata=vIG5u5n
> XR5iRp
> > uuuGjeFxKBtA5f5ohf91znXX0QWm1c%3D&amp;reserved=0
> >
> > As the device tree is passed from bootloader to linux, we detect all the stream
> IDs needed by a device in bootloader and add their IDs in respective device
> nodes.
> > For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we
> are assigning a unique Stream ID in bootloader.
> >
> > However, this poses an issue with PCIE hot plug.
> > If we plug in a pcie device while linux is running, a unique BDF is assigned to
> the device, for which there is no stream ID in device tree.
> >
> > How can this problem be solved in linux?
> 
> Assuming the streamID associated to a BDF is predictable (streamID = BDF
> + constant), using the iommu-map property should just work:
> 
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo
> tlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%2Fbind
> ings%2Fpci%2Fpci-
> iommu.txt&amp;data=02%7C01%7Cpankaj.bansal%40nxp.com%7C3cbe8bd482
> 7e425afd0f08d6d54c925e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C636930922220665343&amp;sdata=GkkovEnvhd5dN%2BGdh%2FnKCyW5Cd
> EnLDP3cWTrk%2B%2FO7EQ%3D&amp;reserved=0
> 
> It describes the streamIDs of all possible BDFs, including hotplugged functions.

You mean that we should increase the "length" parameter (in (rid-base,iommu,iommu-base,length) touple) ?
This would cater to any *new* Bus Device Function being detected on PCIE bus?
Is that right ?
Right now when we make iommu-map in bootloader, we are giving one RID per BDF:
https://elixir.bootlin.com/u-boot/latest/source/drivers/pci/pcie_layerscape_fixup.c#L168

But isn't the better approach to make it dynamic in linux?
i.e. as soon as a new device is detected "requester id" is allocated to it from available pool.
When device is removed, return the "requester id" to pool.
is there any h/w limitation which prevents it?

Regards,
Pankaj Bansal
> 
> Thanks,
> Jean
> 
> >
> > Is there a way to assign (and revoke) stream IDs at run time?
> >
> > Regards,
> > Pankaj Bansal
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists
> > .infradead.org%2Fmailman%2Flistinfo%2Flinux-arm-
> kernel&amp;data=02%7C0
> >
> 1%7Cpankaj.bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C6
> 86ea
> >
> 1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sda
> ta=2La
> > GBHO2%2Bbqk519uJvCatlHyRCtAPPjKO8Gxu1bQHBM%3D&amp;reserved=0
> >

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [ARM SMMU] Dynamic StreamID allocation
  2019-05-13  7:09     ` Pankaj Bansal
@ 2019-05-13 12:42       ` Jean-Philippe Brucker
  -1 siblings, 0 replies; 14+ messages in thread
From: Jean-Philippe Brucker @ 2019-05-13 12:42 UTC (permalink / raw)
  To: Pankaj Bansal, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

On 13/05/2019 08:09, Pankaj Bansal wrote:
> Hi Jean,
> 
>> -----Original Message-----
>> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
>> Sent: Friday, 10 May, 2019 07:07 PM
>> To: Pankaj Bansal <pankaj.bansal@nxp.com>; Will Deacon
>> <will.deacon@arm.com>; Robin Murphy <robin.murphy@arm.com>; Joerg
>> Roedel <joro@8bytes.org>
>> Cc: iommu@lists.linux-foundation.org; Varun Sethi <V.Sethi@nxp.com>; linux-
>> arm-kernel@lists.infradead.org; Nipun Gupta <nipun.gupta@nxp.com>
>> Subject: Re: [ARM SMMU] Dynamic StreamID allocation
>>
>> On 10/05/2019 13:33, Pankaj Bansal wrote:
>>> Hi Will/Robin/Joerg,
>>>
>>> I am s/w engineer from NXP India Pvt. Ltd.
>>> We are using SMMU-V3 in one of NXP SOC.
>>> I have a question about the SMMU Stream ID allocation in linux.
>>>
>>> Right now the Stream IDs allocated to a device are mapped via device tree to
>> the device.
>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
>>> ir.bootlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%
>>> 2Fbindings%2Fiommu%2Farm%2Csmmu-
>> v3.txt%23L39&amp;data=02%7C01%7Cpankaj
>>> .bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C686ea1d3b
>> c2b4c6
>>>
>> fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sdata=vIG5u5n
>> XR5iRp
>>> uuuGjeFxKBtA5f5ohf91znXX0QWm1c%3D&amp;reserved=0
>>>
>>> As the device tree is passed from bootloader to linux, we detect all the stream
>> IDs needed by a device in bootloader and add their IDs in respective device
>> nodes.
>>> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we
>> are assigning a unique Stream ID in bootloader.
>>>
>>> However, this poses an issue with PCIE hot plug.
>>> If we plug in a pcie device while linux is running, a unique BDF is assigned to
>> the device, for which there is no stream ID in device tree.
>>>
>>> How can this problem be solved in linux?
>>
>> Assuming the streamID associated to a BDF is predictable (streamID = BDF
>> + constant), using the iommu-map property should just work:
>>
>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo
>> tlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%2Fbind
>> ings%2Fpci%2Fpci-
>> iommu.txt&amp;data=02%7C01%7Cpankaj.bansal%40nxp.com%7C3cbe8bd482
>> 7e425afd0f08d6d54c925e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
>> %7C636930922220665343&amp;sdata=GkkovEnvhd5dN%2BGdh%2FnKCyW5Cd
>> EnLDP3cWTrk%2B%2FO7EQ%3D&amp;reserved=0
>>
>> It describes the streamIDs of all possible BDFs, including hotplugged functions.
> 
> You mean that we should increase the "length" parameter (in (rid-base,iommu,iommu-base,length) touple) ?
> This would cater to any *new* Bus Device Function being detected on PCIE bus?
> Is that right ?

No, the iommu-map solution only works when you can predict at boot time
which streamID will correspond to any BDF, for example if the PCIe
controller or firmware automatically assigns streamID = BDF.

> Right now when we make iommu-map in bootloader, we are giving one RID per BDF:
> https://elixir.bootlin.com/u-boot/latest/source/drivers/pci/pcie_layerscape_fixup.c#L168

Right, that won't work with hotplug. You can't derive a unique streamID
from any BDF at boot, if the streamID range is limited to 16 values on
this hardware.

Maybe you could move this allocator to the Linux Layerscape driver, and
call iommu_fwspec_add_ids() from there, rather than using iommu-map? Not
sure how feasible that is, but it might still be the simplest.

Thanks,
Jean

> 
> But isn't the better approach to make it dynamic in linux?
> i.e. as soon as a new device is detected "requester id" is allocated to it from available pool.
> When device is removed, return the "requester id" to pool.
> is there any h/w limitation which prevents it?
> 
> Regards,
> Pankaj Bansal
>>
>> Thanks,
>> Jean
>>
>>>
>>> Is there a way to assign (and revoke) stream IDs at run time?
>>>
>>> Regards,
>>> Pankaj Bansal
>>>
>>>
>>> _______________________________________________
>>> linux-arm-kernel mailing list
>>> linux-arm-kernel@lists.infradead.org
>>> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists
>>> .infradead.org%2Fmailman%2Flistinfo%2Flinux-arm-
>> kernel&amp;data=02%7C0
>>>
>> 1%7Cpankaj.bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C6
>> 86ea
>>>
>> 1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sda
>> ta=2La
>>> GBHO2%2Bbqk519uJvCatlHyRCtAPPjKO8Gxu1bQHBM%3D&amp;reserved=0
>>>
> 
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
> 

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-13 12:42       ` Jean-Philippe Brucker
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Philippe Brucker @ 2019-05-13 12:42 UTC (permalink / raw)
  To: Pankaj Bansal, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

On 13/05/2019 08:09, Pankaj Bansal wrote:
> Hi Jean,
> 
>> -----Original Message-----
>> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
>> Sent: Friday, 10 May, 2019 07:07 PM
>> To: Pankaj Bansal <pankaj.bansal@nxp.com>; Will Deacon
>> <will.deacon@arm.com>; Robin Murphy <robin.murphy@arm.com>; Joerg
>> Roedel <joro@8bytes.org>
>> Cc: iommu@lists.linux-foundation.org; Varun Sethi <V.Sethi@nxp.com>; linux-
>> arm-kernel@lists.infradead.org; Nipun Gupta <nipun.gupta@nxp.com>
>> Subject: Re: [ARM SMMU] Dynamic StreamID allocation
>>
>> On 10/05/2019 13:33, Pankaj Bansal wrote:
>>> Hi Will/Robin/Joerg,
>>>
>>> I am s/w engineer from NXP India Pvt. Ltd.
>>> We are using SMMU-V3 in one of NXP SOC.
>>> I have a question about the SMMU Stream ID allocation in linux.
>>>
>>> Right now the Stream IDs allocated to a device are mapped via device tree to
>> the device.
>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
>>> ir.bootlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%
>>> 2Fbindings%2Fiommu%2Farm%2Csmmu-
>> v3.txt%23L39&amp;data=02%7C01%7Cpankaj
>>> .bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C686ea1d3b
>> c2b4c6
>>>
>> fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sdata=vIG5u5n
>> XR5iRp
>>> uuuGjeFxKBtA5f5ohf91znXX0QWm1c%3D&amp;reserved=0
>>>
>>> As the device tree is passed from bootloader to linux, we detect all the stream
>> IDs needed by a device in bootloader and add their IDs in respective device
>> nodes.
>>> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we
>> are assigning a unique Stream ID in bootloader.
>>>
>>> However, this poses an issue with PCIE hot plug.
>>> If we plug in a pcie device while linux is running, a unique BDF is assigned to
>> the device, for which there is no stream ID in device tree.
>>>
>>> How can this problem be solved in linux?
>>
>> Assuming the streamID associated to a BDF is predictable (streamID = BDF
>> + constant), using the iommu-map property should just work:
>>
>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo
>> tlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%2Fbind
>> ings%2Fpci%2Fpci-
>> iommu.txt&amp;data=02%7C01%7Cpankaj.bansal%40nxp.com%7C3cbe8bd482
>> 7e425afd0f08d6d54c925e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
>> %7C636930922220665343&amp;sdata=GkkovEnvhd5dN%2BGdh%2FnKCyW5Cd
>> EnLDP3cWTrk%2B%2FO7EQ%3D&amp;reserved=0
>>
>> It describes the streamIDs of all possible BDFs, including hotplugged functions.
> 
> You mean that we should increase the "length" parameter (in (rid-base,iommu,iommu-base,length) touple) ?
> This would cater to any *new* Bus Device Function being detected on PCIE bus?
> Is that right ?

No, the iommu-map solution only works when you can predict at boot time
which streamID will correspond to any BDF, for example if the PCIe
controller or firmware automatically assigns streamID = BDF.

> Right now when we make iommu-map in bootloader, we are giving one RID per BDF:
> https://elixir.bootlin.com/u-boot/latest/source/drivers/pci/pcie_layerscape_fixup.c#L168

Right, that won't work with hotplug. You can't derive a unique streamID
from any BDF at boot, if the streamID range is limited to 16 values on
this hardware.

Maybe you could move this allocator to the Linux Layerscape driver, and
call iommu_fwspec_add_ids() from there, rather than using iommu-map? Not
sure how feasible that is, but it might still be the simplest.

Thanks,
Jean

> 
> But isn't the better approach to make it dynamic in linux?
> i.e. as soon as a new device is detected "requester id" is allocated to it from available pool.
> When device is removed, return the "requester id" to pool.
> is there any h/w limitation which prevents it?
> 
> Regards,
> Pankaj Bansal
>>
>> Thanks,
>> Jean
>>
>>>
>>> Is there a way to assign (and revoke) stream IDs at run time?
>>>
>>> Regards,
>>> Pankaj Bansal
>>>
>>>
>>> _______________________________________________
>>> linux-arm-kernel mailing list
>>> linux-arm-kernel@lists.infradead.org
>>> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists
>>> .infradead.org%2Fmailman%2Flistinfo%2Flinux-arm-
>> kernel&amp;data=02%7C0
>>>
>> 1%7Cpankaj.bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C6
>> 86ea
>>>
>> 1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sda
>> ta=2La
>>> GBHO2%2Bbqk519uJvCatlHyRCtAPPjKO8Gxu1bQHBM%3D&amp;reserved=0
>>>
> 
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [ARM SMMU] Dynamic StreamID allocation
  2019-05-10 12:33 ` Pankaj Bansal
@ 2019-05-13 13:34   ` Laurentiu Tudor
  -1 siblings, 0 replies; 14+ messages in thread
From: Laurentiu Tudor @ 2019-05-13 13:34 UTC (permalink / raw)
  To: Pankaj Bansal, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

Hi Pankaj,

> -----Original Message-----
> From: linux-arm-kernel <linux-arm-kernel-bounces@lists.infradead.org> On
> Behalf Of Pankaj Bansal
> Sent: Friday, May 10, 2019 3:34 PM
> 
> Hi Will/Robin/Joerg,
> 
> I am s/w engineer from NXP India Pvt. Ltd.
> We are using SMMU-V3 in one of NXP SOC.
> I have a question about the SMMU Stream ID allocation in linux.
> 
> Right now the Stream IDs allocated to a device are mapped via device tree
> to the device.

[snip]

> 
> As the device tree is passed from bootloader to linux, we detect all the
> stream IDs needed by a device in bootloader and add their IDs in
> respective device nodes.
> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus,
> we are assigning a unique Stream ID in bootloader.
> 
> However, this poses an issue with PCIE hot plug.
> If we plug in a pcie device while linux is running, a unique BDF is
> assigned to the device, for which there is no stream ID in device tree.
> 
> How can this problem be solved in linux?
> 
> Is there a way to assign (and revoke) stream IDs at run time?

I think that our main problem is that we enumerate the PCI EPs in the bootloader (u-boot) and allocate StreamIDs just for them, completely disregarding hotplug scenarios. One simple fix would be to not do this and simply allocate a decently sized, fixed range of StreamIDs per PCI controller.

---
Best Regards, Laurentiu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-13 13:34   ` Laurentiu Tudor
  0 siblings, 0 replies; 14+ messages in thread
From: Laurentiu Tudor @ 2019-05-13 13:34 UTC (permalink / raw)
  To: Pankaj Bansal, Will Deacon, Robin Murphy, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel, Nipun Gupta

Hi Pankaj,

> -----Original Message-----
> From: linux-arm-kernel <linux-arm-kernel-bounces@lists.infradead.org> On
> Behalf Of Pankaj Bansal
> Sent: Friday, May 10, 2019 3:34 PM
> 
> Hi Will/Robin/Joerg,
> 
> I am s/w engineer from NXP India Pvt. Ltd.
> We are using SMMU-V3 in one of NXP SOC.
> I have a question about the SMMU Stream ID allocation in linux.
> 
> Right now the Stream IDs allocated to a device are mapped via device tree
> to the device.

[snip]

> 
> As the device tree is passed from bootloader to linux, we detect all the
> stream IDs needed by a device in bootloader and add their IDs in
> respective device nodes.
> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus,
> we are assigning a unique Stream ID in bootloader.
> 
> However, this poses an issue with PCIE hot plug.
> If we plug in a pcie device while linux is running, a unique BDF is
> assigned to the device, for which there is no stream ID in device tree.
> 
> How can this problem be solved in linux?
> 
> Is there a way to assign (and revoke) stream IDs at run time?

I think that our main problem is that we enumerate the PCI EPs in the bootloader (u-boot) and allocate StreamIDs just for them, completely disregarding hotplug scenarios. One simple fix would be to not do this and simply allocate a decently sized, fixed range of StreamIDs per PCI controller.

---
Best Regards, Laurentiu

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [ARM SMMU] Dynamic StreamID allocation
  2019-05-13 12:42       ` Jean-Philippe Brucker
@ 2019-05-13 13:36         ` Robin Murphy
  -1 siblings, 0 replies; 14+ messages in thread
From: Robin Murphy @ 2019-05-13 13:36 UTC (permalink / raw)
  To: Jean-Philippe Brucker, Pankaj Bansal, Will Deacon, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

On 13/05/2019 13:42, Jean-Philippe Brucker wrote:
> On 13/05/2019 08:09, Pankaj Bansal wrote:
>> Hi Jean,
>>
>>> -----Original Message-----
>>> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
>>> Sent: Friday, 10 May, 2019 07:07 PM
>>> To: Pankaj Bansal <pankaj.bansal@nxp.com>; Will Deacon
>>> <will.deacon@arm.com>; Robin Murphy <robin.murphy@arm.com>; Joerg
>>> Roedel <joro@8bytes.org>
>>> Cc: iommu@lists.linux-foundation.org; Varun Sethi <V.Sethi@nxp.com>; linux-
>>> arm-kernel@lists.infradead.org; Nipun Gupta <nipun.gupta@nxp.com>
>>> Subject: Re: [ARM SMMU] Dynamic StreamID allocation
>>>
>>> On 10/05/2019 13:33, Pankaj Bansal wrote:
>>>> Hi Will/Robin/Joerg,
>>>>
>>>> I am s/w engineer from NXP India Pvt. Ltd.
>>>> We are using SMMU-V3 in one of NXP SOC.
>>>> I have a question about the SMMU Stream ID allocation in linux.
>>>>
>>>> Right now the Stream IDs allocated to a device are mapped via device tree to
>>> the device.
>>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
>>>> ir.bootlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%
>>>> 2Fbindings%2Fiommu%2Farm%2Csmmu-
>>> v3.txt%23L39&amp;data=02%7C01%7Cpankaj
>>>> .bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C686ea1d3b
>>> c2b4c6
>>>>
>>> fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sdata=vIG5u5n
>>> XR5iRp
>>>> uuuGjeFxKBtA5f5ohf91znXX0QWm1c%3D&amp;reserved=0
>>>>
>>>> As the device tree is passed from bootloader to linux, we detect all the stream
>>> IDs needed by a device in bootloader and add their IDs in respective device
>>> nodes.
>>>> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we
>>> are assigning a unique Stream ID in bootloader.
>>>>
>>>> However, this poses an issue with PCIE hot plug.
>>>> If we plug in a pcie device while linux is running, a unique BDF is assigned to
>>> the device, for which there is no stream ID in device tree.
>>>>
>>>> How can this problem be solved in linux?
>>>
>>> Assuming the streamID associated to a BDF is predictable (streamID = BDF
>>> + constant), using the iommu-map property should just work:
>>>
>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo
>>> tlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%2Fbind
>>> ings%2Fpci%2Fpci-
>>> iommu.txt&amp;data=02%7C01%7Cpankaj.bansal%40nxp.com%7C3cbe8bd482
>>> 7e425afd0f08d6d54c925e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
>>> %7C636930922220665343&amp;sdata=GkkovEnvhd5dN%2BGdh%2FnKCyW5Cd
>>> EnLDP3cWTrk%2B%2FO7EQ%3D&amp;reserved=0
>>>
>>> It describes the streamIDs of all possible BDFs, including hotplugged functions.
>>
>> You mean that we should increase the "length" parameter (in (rid-base,iommu,iommu-base,length) touple) ?
>> This would cater to any *new* Bus Device Function being detected on PCIE bus?
>> Is that right ?
> 
> No, the iommu-map solution only works when you can predict at boot time
> which streamID will correspond to any BDF, for example if the PCIe
> controller or firmware automatically assigns streamID = BDF.
> 
>> Right now when we make iommu-map in bootloader, we are giving one RID per BDF:
>> https://elixir.bootlin.com/u-boot/latest/source/drivers/pci/pcie_layerscape_fixup.c#L168
> 
> Right, that won't work with hotplug. You can't derive a unique streamID
> from any BDF at boot, if the streamID range is limited to 16 values on
> this hardware.

Furthermore, does U-Boot enumerate all possible SR-IOV capabilities, or 
is this already broken regardless of hotplug?

> Maybe you could move this allocator to the Linux Layerscape driver, and
> call iommu_fwspec_add_ids() from there, rather than using iommu-map? Not
> sure how feasible that is, but it might still be the simplest.

Assuming there's still the same silly 7-bit limitation as LS2085, you 
could in theory carve out that entire space of ICIDs to allow a static 
mapping like this:

	iommu-map-mask = <0x0f07>;
	iommu-map = <0x000 &smmu 0x00 0x8>,
		    <0x100 &smmu 0x08 0x8>,
		    <0x200 &smmu 0x10 0x8>,
		    <0x300 &smmu 0x18 0x8>,
		    <0x400 &smmu 0x20 0x8>,
		    <0x500 &smmu 0x28 0x8>,
		    <0x600 &smmu 0x30 0x8>,
		    <0x700 &smmu 0x38 0x8>,
		    <0x800 &smmu 0x40 0x8>,
		    <0x900 &smmu 0x48 0x8>,
		    <0xa00 &smmu 0x50 0x8>,
		    <0xb00 &smmu 0x58 0x8>,
		    <0xc00 &smmu 0x60 0x8>,
		    <0xd00 &smmu 0x68 0x8>,
		    <0xe00 &smmu 0x70 0x8>,
		    <0xf00 &smmu 0x78 0x8>;

That gives you 16 buses before IDs start aliasing awkwardly (any devices 
sharing a bus will alias per-function, but that's probably acceptable 
since they'd likely get grouped together anyway).

Either way the IOMMU layer itself is actually relatively easy-going 
these days. Even with the existing approach, if you could just update 
Linux's internal idea of the firmware data before the bus_add_device() 
call happens for the hotplugged device, then things should just work. 
You're also going to face the exact same problem for ITS Device IDs, 
though, and things may be less forgiving there.

Robin.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [ARM SMMU] Dynamic StreamID allocation
@ 2019-05-13 13:36         ` Robin Murphy
  0 siblings, 0 replies; 14+ messages in thread
From: Robin Murphy @ 2019-05-13 13:36 UTC (permalink / raw)
  To: Jean-Philippe Brucker, Pankaj Bansal, Will Deacon, Joerg Roedel
  Cc: iommu, Varun Sethi, linux-arm-kernel

On 13/05/2019 13:42, Jean-Philippe Brucker wrote:
> On 13/05/2019 08:09, Pankaj Bansal wrote:
>> Hi Jean,
>>
>>> -----Original Message-----
>>> From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
>>> Sent: Friday, 10 May, 2019 07:07 PM
>>> To: Pankaj Bansal <pankaj.bansal@nxp.com>; Will Deacon
>>> <will.deacon@arm.com>; Robin Murphy <robin.murphy@arm.com>; Joerg
>>> Roedel <joro@8bytes.org>
>>> Cc: iommu@lists.linux-foundation.org; Varun Sethi <V.Sethi@nxp.com>; linux-
>>> arm-kernel@lists.infradead.org; Nipun Gupta <nipun.gupta@nxp.com>
>>> Subject: Re: [ARM SMMU] Dynamic StreamID allocation
>>>
>>> On 10/05/2019 13:33, Pankaj Bansal wrote:
>>>> Hi Will/Robin/Joerg,
>>>>
>>>> I am s/w engineer from NXP India Pvt. Ltd.
>>>> We are using SMMU-V3 in one of NXP SOC.
>>>> I have a question about the SMMU Stream ID allocation in linux.
>>>>
>>>> Right now the Stream IDs allocated to a device are mapped via device tree to
>>> the device.
>>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felix
>>>> ir.bootlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%
>>>> 2Fbindings%2Fiommu%2Farm%2Csmmu-
>>> v3.txt%23L39&amp;data=02%7C01%7Cpankaj
>>>> .bansal%40nxp.com%7C3cbe8bd4827e425afd0f08d6d54c925e%7C686ea1d3b
>>> c2b4c6
>>>>
>>> fa92cd99c5c301635%7C0%7C0%7C636930922220665343&amp;sdata=vIG5u5n
>>> XR5iRp
>>>> uuuGjeFxKBtA5f5ohf91znXX0QWm1c%3D&amp;reserved=0
>>>>
>>>> As the device tree is passed from bootloader to linux, we detect all the stream
>>> IDs needed by a device in bootloader and add their IDs in respective device
>>> nodes.
>>>> For each PCIE Endpoint (a unique BDF (Bus Device Function)) on PCIE bus, we
>>> are assigning a unique Stream ID in bootloader.
>>>>
>>>> However, this poses an issue with PCIE hot plug.
>>>> If we plug in a pcie device while linux is running, a unique BDF is assigned to
>>> the device, for which there is no stream ID in device tree.
>>>>
>>>> How can this problem be solved in linux?
>>>
>>> Assuming the streamID associated to a BDF is predictable (streamID = BDF
>>> + constant), using the iommu-map property should just work:
>>>
>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo
>>> tlin.com%2Flinux%2Flatest%2Fsource%2FDocumentation%2Fdevicetree%2Fbind
>>> ings%2Fpci%2Fpci-
>>> iommu.txt&amp;data=02%7C01%7Cpankaj.bansal%40nxp.com%7C3cbe8bd482
>>> 7e425afd0f08d6d54c925e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
>>> %7C636930922220665343&amp;sdata=GkkovEnvhd5dN%2BGdh%2FnKCyW5Cd
>>> EnLDP3cWTrk%2B%2FO7EQ%3D&amp;reserved=0
>>>
>>> It describes the streamIDs of all possible BDFs, including hotplugged functions.
>>
>> You mean that we should increase the "length" parameter (in (rid-base,iommu,iommu-base,length) touple) ?
>> This would cater to any *new* Bus Device Function being detected on PCIE bus?
>> Is that right ?
> 
> No, the iommu-map solution only works when you can predict at boot time
> which streamID will correspond to any BDF, for example if the PCIe
> controller or firmware automatically assigns streamID = BDF.
> 
>> Right now when we make iommu-map in bootloader, we are giving one RID per BDF:
>> https://elixir.bootlin.com/u-boot/latest/source/drivers/pci/pcie_layerscape_fixup.c#L168
> 
> Right, that won't work with hotplug. You can't derive a unique streamID
> from any BDF at boot, if the streamID range is limited to 16 values on
> this hardware.

Furthermore, does U-Boot enumerate all possible SR-IOV capabilities, or 
is this already broken regardless of hotplug?

> Maybe you could move this allocator to the Linux Layerscape driver, and
> call iommu_fwspec_add_ids() from there, rather than using iommu-map? Not
> sure how feasible that is, but it might still be the simplest.

Assuming there's still the same silly 7-bit limitation as LS2085, you 
could in theory carve out that entire space of ICIDs to allow a static 
mapping like this:

	iommu-map-mask = <0x0f07>;
	iommu-map = <0x000 &smmu 0x00 0x8>,
		    <0x100 &smmu 0x08 0x8>,
		    <0x200 &smmu 0x10 0x8>,
		    <0x300 &smmu 0x18 0x8>,
		    <0x400 &smmu 0x20 0x8>,
		    <0x500 &smmu 0x28 0x8>,
		    <0x600 &smmu 0x30 0x8>,
		    <0x700 &smmu 0x38 0x8>,
		    <0x800 &smmu 0x40 0x8>,
		    <0x900 &smmu 0x48 0x8>,
		    <0xa00 &smmu 0x50 0x8>,
		    <0xb00 &smmu 0x58 0x8>,
		    <0xc00 &smmu 0x60 0x8>,
		    <0xd00 &smmu 0x68 0x8>,
		    <0xe00 &smmu 0x70 0x8>,
		    <0xf00 &smmu 0x78 0x8>;

That gives you 16 buses before IDs start aliasing awkwardly (any devices 
sharing a bus will alias per-function, but that's probably acceptable 
since they'd likely get grouped together anyway).

Either way the IOMMU layer itself is actually relatively easy-going 
these days. Even with the existing approach, if you could just update 
Linux's internal idea of the firmware data before the bus_add_device() 
call happens for the hotplugged device, then things should just work. 
You're also going to face the exact same problem for ITS Device IDs, 
though, and things may be less forgiving there.

Robin.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-05-13 13:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10 12:33 [ARM SMMU] Dynamic StreamID allocation Pankaj Bansal
2019-05-10 12:33 ` Pankaj Bansal
2019-05-10 13:19 ` Pankaj Bansal
2019-05-10 13:19   ` Pankaj Bansal
2019-05-10 13:36 ` Jean-Philippe Brucker
2019-05-10 13:36   ` Jean-Philippe Brucker
2019-05-13  7:09   ` Pankaj Bansal
2019-05-13  7:09     ` Pankaj Bansal
2019-05-13 12:42     ` Jean-Philippe Brucker
2019-05-13 12:42       ` Jean-Philippe Brucker
2019-05-13 13:36       ` Robin Murphy
2019-05-13 13:36         ` Robin Murphy
2019-05-13 13:34 ` Laurentiu Tudor
2019-05-13 13:34   ` Laurentiu Tudor

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.