All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irqchip/gicv3-its: Decrease page size when needed
@ 2015-04-15  9:49 ` Minghuan Lian
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan Lian @ 2015-04-15  9:49 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arm-kernel, Zang Roy-R61911, Hu Mingkai-B21284, Scott Wood,
	Yoder Stuart-B08248, Arnd Bergmann, Bjorn Helgaas, Minghuan Lian

The default page size of ITS table has been changed to 64KB,
but for some platforms the real size of allocate memory which
calculated by DEVBITS of register GITS_TYPER may smaller than
default size. In this case, psz must be decreased, otherwise,
the wrong page number will cause kernel hang.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 596b0a9..d0374a6 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -844,6 +844,9 @@ static int its_alloc_tables(struct its_node *its)
 
 		its->tables[i] = base;
 
+		while (alloc_size < psz)
+			psz = psz >> 1;
+
 retry_baser:
 		val = (virt_to_phys(base) 				 |
 		       (type << GITS_BASER_TYPE_SHIFT)			 |
-- 
1.9.1


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

* [PATCH] irqchip/gicv3-its: Decrease page size when needed
@ 2015-04-15  9:49 ` Minghuan Lian
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan Lian @ 2015-04-15  9:49 UTC (permalink / raw)
  To: linux-arm-kernel

The default page size of ITS table has been changed to 64KB,
but for some platforms the real size of allocate memory which
calculated by DEVBITS of register GITS_TYPER may smaller than
default size. In this case, psz must be decreased, otherwise,
the wrong page number will cause kernel hang.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 596b0a9..d0374a6 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -844,6 +844,9 @@ static int its_alloc_tables(struct its_node *its)
 
 		its->tables[i] = base;
 
+		while (alloc_size < psz)
+			psz = psz >> 1;
+
 retry_baser:
 		val = (virt_to_phys(base) 				 |
 		       (type << GITS_BASER_TYPE_SHIFT)			 |
-- 
1.9.1

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15  9:49 ` Minghuan Lian
@ 2015-04-15  9:49   ` Minghuan Lian
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan Lian @ 2015-04-15  9:49 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arm-kernel, Zang Roy-R61911, Hu Mingkai-B21284, Scott Wood,
	Yoder Stuart-B08248, Arnd Bergmann, Bjorn Helgaas, Minghuan Lian

SMMU of some platforms can only isolate limited device ID.
This may require that all PCI devices share the same ITS
device with the fixed device ID. The patch adds function
arch_msi_share_devid_update used for these platforms to update
the fixed device ID and maximum MSI interrupts number.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index d0374a6..be78d0a 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev, u16 alias, void *data)
 	return 0;
 }
 
+void __weak
+arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32 *nvesc)
+{
+	/*
+	 * use PCI_DEVID NOT share device ID as default
+	 * so nothing need to do
+	 */
+}
+
 static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
 			   int nvec, msi_alloc_info_t *info)
 {
@@ -1185,6 +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
 	dev_alias.count = nvec;
 
 	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
+	arch_msi_share_devid_update(pdev, &dev_alias.dev_id, &dev_alias.count);
+
 	its = domain->parent->host_data;
 
 	its_dev = its_find_device(its, dev_alias.dev_id);
-- 
1.9.1


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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-15  9:49   ` Minghuan Lian
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan Lian @ 2015-04-15  9:49 UTC (permalink / raw)
  To: linux-arm-kernel

SMMU of some platforms can only isolate limited device ID.
This may require that all PCI devices share the same ITS
device with the fixed device ID. The patch adds function
arch_msi_share_devid_update used for these platforms to update
the fixed device ID and maximum MSI interrupts number.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index d0374a6..be78d0a 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev, u16 alias, void *data)
 	return 0;
 }
 
+void __weak
+arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32 *nvesc)
+{
+	/*
+	 * use PCI_DEVID NOT share device ID as default
+	 * so nothing need to do
+	 */
+}
+
 static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
 			   int nvec, msi_alloc_info_t *info)
 {
@@ -1185,6 +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
 	dev_alias.count = nvec;
 
 	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
+	arch_msi_share_devid_update(pdev, &dev_alias.dev_id, &dev_alias.count);
+
 	its = domain->parent->host_data;
 
 	its_dev = its_find_device(its, dev_alias.dev_id);
-- 
1.9.1

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

* [PATCH 2/2] pci/layerscape: Add LS2085A MSI support
  2015-04-15  9:49 ` Minghuan Lian
@ 2015-04-15  9:49   ` Minghuan Lian
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan Lian @ 2015-04-15  9:49 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-arm-kernel, Zang Roy-R61911, Hu Mingkai-B21284, Scott Wood,
	Yoder Stuart-B08248, Arnd Bergmann, Bjorn Helgaas, Minghuan Lian

Freescale LS2085A uses GICv3 ITS to provide MSI functionality,
but it only supports 64 isolation context identifiers. So, all
the PCIe devices inserted to the same PCIe controller will share
the fixed ICID.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
---
Depend on pci-layerscape-Add-LS2085A-PCIe-support.patch

 drivers/pci/host/pci-layerscape.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/pci/host/pci-layerscape.c b/drivers/pci/host/pci-layerscape.c
index 15c5e47..1f317ca 100644
--- a/drivers/pci/host/pci-layerscape.c
+++ b/drivers/pci/host/pci-layerscape.c
@@ -30,20 +30,38 @@
 
 /* PEX LUT registers */
 #define PCIE_LUT_BASE		0x80000
+#define PCIE_LUT_PEXLCR		0x024 /* PEX LUT Control Register */
+#define PCIE_LUT_UDR(n)		(0x800 + (n) * 8)
+#define PCIE_LUT_LDR(n)		(0x804 + (n) * 8)
+#define PCIE_LUT_MASK_ALL	0xffff
+#define PCIE_LUT_DR_NUM		32
+#define PCIE_LUT_ENABLE		(0x1 << 31)
 #define PCIE_LUT_DBG		0x7FC /* PEX LUT Debug register */
 
 #define PCIE_ATU_NUM		6
 
+#define PCIE_MSI_MAX_NUM	64
+#define PCIE_ICID_BASE		1
+
 struct ls_pcie {
 	struct dw_pcie_port	pp;
 	void __iomem		*regs;
 	void __iomem		*lut;
 	struct regmap		*scfg;
 	int			index;
+	int			icid;
 };
 
 #define to_ls_pcie(x)	container_of(x, struct ls_pcie, pp)
 
+void arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32 *nvesc)
+{
+	struct ls_pcie *pcie = to_ls_pcie(pdev->bus->sysdata);
+
+	*dev_id = pcie->icid;
+	*nvesc = PCIE_MSI_MAX_NUM;
+}
+
 static int ls1_pcie_link_up(struct dw_pcie_port *pp)
 {
 	struct ls_pcie *pcie = to_ls_pcie(pp);
@@ -136,6 +154,12 @@ static int ls2_pcie_host_init(struct dw_pcie_port *pp)
 	dw_pcie_dbi_write(pp, val, PCI_HEADER_TYPE & ~0x3);
 	dw_pcie_dbi_write(pp, 0, PCIE_DBI_RO_WR_EN);
 
+	/* Set LUT. All request ID will map to a static ICID */
+	iowrite32(pcie->icid, pcie->lut + PCIE_LUT_PEXLCR);
+	iowrite32(PCIE_LUT_MASK_ALL, pcie->lut + PCIE_LUT_UDR(0));
+	iowrite32(PCIE_LUT_ENABLE | pcie->icid,
+		  pcie->lut + PCIE_LUT_LDR(0));
+
 	if (!ls2_pcie_link_up(pp))
 		dev_err(pp->dev, "phy link never came up\n");
 
@@ -159,6 +183,7 @@ static int __init ls_pcie_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 	struct ls_pcie *pcie;
 	struct resource *res;
+	static int ls_pcie_num;
 	int ret;
 
 	match = of_match_device(ls_pcie_of_match, &pdev->dev);
@@ -177,6 +202,8 @@ static int __init ls_pcie_probe(struct platform_device *pdev)
 	}
 
 	pcie->lut = pcie->regs + PCIE_LUT_BASE;
+	pcie->index = ls_pcie_num++;
+	pcie->icid = PCIE_ICID_BASE + pcie->index;
 	pcie->pp.dev = &pdev->dev;
 	pcie->pp.dbi = pcie->regs;
 	pcie->pp.dw_ops = (struct dw_host_ops *)match->data;
-- 
1.9.1


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

* [PATCH 2/2] pci/layerscape: Add LS2085A MSI support
@ 2015-04-15  9:49   ` Minghuan Lian
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan Lian @ 2015-04-15  9:49 UTC (permalink / raw)
  To: linux-arm-kernel

Freescale LS2085A uses GICv3 ITS to provide MSI functionality,
but it only supports 64 isolation context identifiers. So, all
the PCIe devices inserted to the same PCIe controller will share
the fixed ICID.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
---
Depend on pci-layerscape-Add-LS2085A-PCIe-support.patch

 drivers/pci/host/pci-layerscape.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/pci/host/pci-layerscape.c b/drivers/pci/host/pci-layerscape.c
index 15c5e47..1f317ca 100644
--- a/drivers/pci/host/pci-layerscape.c
+++ b/drivers/pci/host/pci-layerscape.c
@@ -30,20 +30,38 @@
 
 /* PEX LUT registers */
 #define PCIE_LUT_BASE		0x80000
+#define PCIE_LUT_PEXLCR		0x024 /* PEX LUT Control Register */
+#define PCIE_LUT_UDR(n)		(0x800 + (n) * 8)
+#define PCIE_LUT_LDR(n)		(0x804 + (n) * 8)
+#define PCIE_LUT_MASK_ALL	0xffff
+#define PCIE_LUT_DR_NUM		32
+#define PCIE_LUT_ENABLE		(0x1 << 31)
 #define PCIE_LUT_DBG		0x7FC /* PEX LUT Debug register */
 
 #define PCIE_ATU_NUM		6
 
+#define PCIE_MSI_MAX_NUM	64
+#define PCIE_ICID_BASE		1
+
 struct ls_pcie {
 	struct dw_pcie_port	pp;
 	void __iomem		*regs;
 	void __iomem		*lut;
 	struct regmap		*scfg;
 	int			index;
+	int			icid;
 };
 
 #define to_ls_pcie(x)	container_of(x, struct ls_pcie, pp)
 
+void arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32 *nvesc)
+{
+	struct ls_pcie *pcie = to_ls_pcie(pdev->bus->sysdata);
+
+	*dev_id = pcie->icid;
+	*nvesc = PCIE_MSI_MAX_NUM;
+}
+
 static int ls1_pcie_link_up(struct dw_pcie_port *pp)
 {
 	struct ls_pcie *pcie = to_ls_pcie(pp);
@@ -136,6 +154,12 @@ static int ls2_pcie_host_init(struct dw_pcie_port *pp)
 	dw_pcie_dbi_write(pp, val, PCI_HEADER_TYPE & ~0x3);
 	dw_pcie_dbi_write(pp, 0, PCIE_DBI_RO_WR_EN);
 
+	/* Set LUT. All request ID will map to a static ICID */
+	iowrite32(pcie->icid, pcie->lut + PCIE_LUT_PEXLCR);
+	iowrite32(PCIE_LUT_MASK_ALL, pcie->lut + PCIE_LUT_UDR(0));
+	iowrite32(PCIE_LUT_ENABLE | pcie->icid,
+		  pcie->lut + PCIE_LUT_LDR(0));
+
 	if (!ls2_pcie_link_up(pp))
 		dev_err(pp->dev, "phy link never came up\n");
 
@@ -159,6 +183,7 @@ static int __init ls_pcie_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 	struct ls_pcie *pcie;
 	struct resource *res;
+	static int ls_pcie_num;
 	int ret;
 
 	match = of_match_device(ls_pcie_of_match, &pdev->dev);
@@ -177,6 +202,8 @@ static int __init ls_pcie_probe(struct platform_device *pdev)
 	}
 
 	pcie->lut = pcie->regs + PCIE_LUT_BASE;
+	pcie->index = ls_pcie_num++;
+	pcie->icid = PCIE_ICID_BASE + pcie->index;
 	pcie->pp.dev = &pdev->dev;
 	pcie->pp.dbi = pcie->regs;
 	pcie->pp.dw_ops = (struct dw_host_ops *)match->data;
-- 
1.9.1

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15  9:49   ` Minghuan Lian
@ 2015-04-15 11:08     ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-15 11:08 UTC (permalink / raw)
  To: Minghuan.Lian, linux-pci
  Cc: Arnd Bergmann, Minghuan.Lian, Mingkai.Hu, Roy Zang, Stuart Yoder,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Minghuan,
Not clear what this patch intends to do. Can you please explain the point about SMMU isolating limited device ID.

Regards
Varun

> -----Original Message-----
> From: linux-arm-kernel [mailto:linux-arm-kernel-
> bounces@lists.infradead.org] On Behalf Of Minghuan Lian
> Sent: Wednesday, April 15, 2015 3:19 PM
> To: linux-pci@vger.kernel.org
> Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-
> kernel@lists.infradead.org
> Subject: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> SMMU of some platforms can only isolate limited device ID.
> This may require that all PCI devices share the same ITS device with the fixed
> device ID. The patch adds function arch_msi_share_devid_update used for
> these platforms to update the fixed device ID and maximum MSI interrupts
> number.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index d0374a6..be78d0a 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev,
> u16 alias, void *data)
>  	return 0;
>  }
> 
> +void __weak
> +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> +*nvesc) {
> +	/*
> +	 * use PCI_DEVID NOT share device ID as default
> +	 * so nothing need to do
> +	 */
> +}
> +
>  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
>  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain, struct
> device *dev,
>  	dev_alias.count = nvec;
> 
>  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> +&dev_alias.count);
> +
>  	its = domain->parent->host_data;
> 
>  	its_dev = its_find_device(its, dev_alias.dev_id);
> --
> 1.9.1
> 
> 
> _______________________________________________
> 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] 74+ messages in thread

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-15 11:08     ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-15 11:08 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Minghuan,
Not clear what this patch intends to do. Can you please explain the point about SMMU isolating limited device ID.

Regards
Varun

> -----Original Message-----
> From: linux-arm-kernel [mailto:linux-arm-kernel-
> bounces at lists.infradead.org] On Behalf Of Minghuan Lian
> Sent: Wednesday, April 15, 2015 3:19 PM
> To: linux-pci at vger.kernel.org
> Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-
> kernel at lists.infradead.org
> Subject: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> SMMU of some platforms can only isolate limited device ID.
> This may require that all PCI devices share the same ITS device with the fixed
> device ID. The patch adds function arch_msi_share_devid_update used for
> these platforms to update the fixed device ID and maximum MSI interrupts
> number.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index d0374a6..be78d0a 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev,
> u16 alias, void *data)
>  	return 0;
>  }
> 
> +void __weak
> +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> +*nvesc) {
> +	/*
> +	 * use PCI_DEVID NOT share device ID as default
> +	 * so nothing need to do
> +	 */
> +}
> +
>  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
>  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain, struct
> device *dev,
>  	dev_alias.count = nvec;
> 
>  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> +&dev_alias.count);
> +
>  	its = domain->parent->host_data;
> 
>  	its_dev = its_find_device(its, dev_alias.dev_id);
> --
> 1.9.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15 11:08     ` Varun Sethi
@ 2015-04-15 11:38       ` Minghuan.Lian at freescale.com
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian @ 2015-04-15 11:38 UTC (permalink / raw)
  To: Varun Sethi, linux-pci
  Cc: Arnd Bergmann, Mingkai.Hu, Roy Zang, Stuart Yoder, Bjorn Helgaas,
	Scott Wood, linux-arm-kernel

Hi Varun,

Freescale LS2085A SMMU uses in hit/miss mechanism for the concatenation {tbu number,stream_id}. This concatenation is then assigned to a context bank that determines the translation type and form. The Isolation Context Identifier ICID is the main field of stream_id which will be used to hit ITS device. We may look ICID as ITS device ID and PCI device ID. But there are only 64 ICIDs  0 - 63.  If using default PCI_DEVID(bus, devfn)  ((((u16)(bus)) << 8) | (devfn)), PCI device(bus >=1) ) ID will larger than 63.  SMMU will miss this translation.
In addition, because the ICID number  is only 64, all the PCIe device will use the same ICID and share the same ITS device.

Thanks,
Minghuan

> -----Original Message-----
> From: Sethi Varun-B16395
> Sent: Wednesday, April 15, 2015 7:08 PM
> To: Lian Minghuan-B31939; linux-pci@vger.kernel.org
> Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-
> kernel@lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Minghuan,
> Not clear what this patch intends to do. Can you please explain the point
> about SMMU isolating limited device ID.
> 
> Regards
> Varun
> 
> > -----Original Message-----
> > From: linux-arm-kernel [mailto:linux-arm-kernel-
> > bounces@lists.infradead.org] On Behalf Of Minghuan Lian
> > Sent: Wednesday, April 15, 2015 3:19 PM
> > To: linux-pci@vger.kernel.org
> > Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> > R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421;
> > linux-arm- kernel@lists.infradead.org
> > Subject: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > SMMU of some platforms can only isolate limited device ID.
> > This may require that all PCI devices share the same ITS device with
> > the fixed device ID. The patch adds function
> > arch_msi_share_devid_update used for these platforms to update the
> > fixed device ID and maximum MSI interrupts number.
> >
> > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > ---
> >  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/irqchip/irq-gic-v3-its.c
> > b/drivers/irqchip/irq-gic-v3-its.c
> > index d0374a6..be78d0a 100644
> > --- a/drivers/irqchip/irq-gic-v3-its.c
> > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev
> > *pdev,
> > u16 alias, void *data)
> >  	return 0;
> >  }
> >
> > +void __weak
> > +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> > +*nvesc) {
> > +	/*
> > +	 * use PCI_DEVID NOT share device ID as default
> > +	 * so nothing need to do
> > +	 */
> > +}
> > +
> >  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> >  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> > +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain,
> > +struct
> > device *dev,
> >  	dev_alias.count = nvec;
> >
> >  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> > +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> > +&dev_alias.count);
> > +
> >  	its = domain->parent->host_data;
> >
> >  	its_dev = its_find_device(its, dev_alias.dev_id);
> > --
> > 1.9.1
> >
> >
> > _______________________________________________
> > 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] 74+ messages in thread

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-15 11:38       ` Minghuan.Lian at freescale.com
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian at freescale.com @ 2015-04-15 11:38 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Varun,

Freescale LS2085A SMMU uses in hit/miss mechanism for the concatenation {tbu number,stream_id}. This concatenation is then assigned to a context bank that determines the translation type and form. The Isolation Context Identifier ICID is the main field of stream_id which will be used to hit ITS device. We may look ICID as ITS device ID and PCI device ID. But there are only 64 ICIDs  0 - 63.  If using default PCI_DEVID(bus, devfn)  ((((u16)(bus)) << 8) | (devfn)), PCI device(bus >=1) ) ID will larger than 63.  SMMU will miss this translation.
In addition, because the ICID number  is only 64, all the PCIe device will use the same ICID and share the same ITS device.

Thanks,
Minghuan

> -----Original Message-----
> From: Sethi Varun-B16395
> Sent: Wednesday, April 15, 2015 7:08 PM
> To: Lian Minghuan-B31939; linux-pci at vger.kernel.org
> Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-
> kernel at lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Minghuan,
> Not clear what this patch intends to do. Can you please explain the point
> about SMMU isolating limited device ID.
> 
> Regards
> Varun
> 
> > -----Original Message-----
> > From: linux-arm-kernel [mailto:linux-arm-kernel-
> > bounces at lists.infradead.org] On Behalf Of Minghuan Lian
> > Sent: Wednesday, April 15, 2015 3:19 PM
> > To: linux-pci at vger.kernel.org
> > Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> > R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421;
> > linux-arm- kernel at lists.infradead.org
> > Subject: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > SMMU of some platforms can only isolate limited device ID.
> > This may require that all PCI devices share the same ITS device with
> > the fixed device ID. The patch adds function
> > arch_msi_share_devid_update used for these platforms to update the
> > fixed device ID and maximum MSI interrupts number.
> >
> > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > ---
> >  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/irqchip/irq-gic-v3-its.c
> > b/drivers/irqchip/irq-gic-v3-its.c
> > index d0374a6..be78d0a 100644
> > --- a/drivers/irqchip/irq-gic-v3-its.c
> > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev
> > *pdev,
> > u16 alias, void *data)
> >  	return 0;
> >  }
> >
> > +void __weak
> > +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> > +*nvesc) {
> > +	/*
> > +	 * use PCI_DEVID NOT share device ID as default
> > +	 * so nothing need to do
> > +	 */
> > +}
> > +
> >  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> >  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> > +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain,
> > +struct
> > device *dev,
> >  	dev_alias.count = nvec;
> >
> >  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> > +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> > +&dev_alias.count);
> > +
> >  	its = domain->parent->host_data;
> >
> >  	its_dev = its_find_device(its, dev_alias.dev_id);
> > --
> > 1.9.1
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] irqchip/gicv3-its: Decrease page size when needed
  2015-04-15  9:49 ` Minghuan Lian
@ 2015-04-15 11:51   ` Jason Cooper
  -1 siblings, 0 replies; 74+ messages in thread
From: Jason Cooper @ 2015-04-15 11:51 UTC (permalink / raw)
  To: Minghuan Lian
  Cc: linux-pci, Arnd Bergmann, Hu Mingkai-B21284, Zang Roy-R61911,
	Yoder Stuart-B08248, Bjorn Helgaas, Scott Wood, linux-arm-kernel

Minghuan Lian,

On Wed, Apr 15, 2015 at 05:49:22PM +0800, Minghuan Lian wrote:
> The default page size of ITS table has been changed to 64KB,
> but for some platforms the real size of allocate memory which
> calculated by DEVBITS of register GITS_TYPER may smaller than
> default size. In this case, psz must be decreased, otherwise,
> the wrong page number will cause kernel hang.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
>  1 file changed, 3 insertions(+)

Please run scripts/get_maintainer.pl on your patches before sending.  This
needs to be sent to myself and Thomas Gleixner for review.

The merge window just opened, so nothing new is being added to the tree
currently.  Go ahead and resend after a few days.

thx,

Jason.

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

* [PATCH] irqchip/gicv3-its: Decrease page size when needed
@ 2015-04-15 11:51   ` Jason Cooper
  0 siblings, 0 replies; 74+ messages in thread
From: Jason Cooper @ 2015-04-15 11:51 UTC (permalink / raw)
  To: linux-arm-kernel

Minghuan Lian,

On Wed, Apr 15, 2015 at 05:49:22PM +0800, Minghuan Lian wrote:
> The default page size of ITS table has been changed to 64KB,
> but for some platforms the real size of allocate memory which
> calculated by DEVBITS of register GITS_TYPER may smaller than
> default size. In this case, psz must be decreased, otherwise,
> the wrong page number will cause kernel hang.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
>  1 file changed, 3 insertions(+)

Please run scripts/get_maintainer.pl on your patches before sending.  This
needs to be sent to myself and Thomas Gleixner for review.

The merge window just opened, so nothing new is being added to the tree
currently.  Go ahead and resend after a few days.

thx,

Jason.

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15 11:38       ` Minghuan.Lian at freescale.com
@ 2015-04-15 13:18         ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-15 13:18 UTC (permalink / raw)
  To: Minghuan.Lian, linux-pci
  Cc: Arnd Bergmann, Mingkai.Hu, Roy Zang, Stuart Yoder, Bjorn Helgaas,
	Scott Wood, linux-arm-kernel, Will Deacon

Hi Minghuan,
Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID would also be forwarded as a part of stream id to GIC. My understanding is that TBU ID is forwarded (as a part of the stream ID) to the TCU in case of a TBU translation miss. In case of the LS2085 PCIe controller you would have to setup the PCIe device ID to stream ID translation table. We may have to restrict the number of entries based on the available number of contexts.

Regards
Varun


> -----Original Message-----
> From: Lian Minghuan-B31939
> Sent: Wednesday, April 15, 2015 5:08 PM
> To: Sethi Varun-B16395; linux-pci@vger.kernel.org
> Cc: Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-
> B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-
> kernel@lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Varun,
> 
> Freescale LS2085A SMMU uses in hit/miss mechanism for the concatenation
> {tbu number,stream_id}. This concatenation is then assigned to a context
> bank that determines the translation type and form. The Isolation Context
> Identifier ICID is the main field of stream_id which will be used to hit ITS
> device. We may look ICID as ITS device ID and PCI device ID. But there are
> only 64 ICIDs  0 - 63.  If using default PCI_DEVID(bus, devfn)  ((((u16)(bus)) <<
> 8) | (devfn)), PCI device(bus >=1) ) ID will larger than 63.  SMMU will miss this
> translation.
> In addition, because the ICID number  is only 64, all the PCIe device will use
> the same ICID and share the same ITS device.
> 
> Thanks,
> Minghuan
> 
> > -----Original Message-----
> > From: Sethi Varun-B16395
> > Sent: Wednesday, April 15, 2015 7:08 PM
> > To: Lian Minghuan-B31939; linux-pci@vger.kernel.org
> > Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> > R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421;
> > linux-arm- kernel@lists.infradead.org
> > Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Hi Minghuan,
> > Not clear what this patch intends to do. Can you please explain the
> > point about SMMU isolating limited device ID.
> >
> > Regards
> > Varun
> >
> > > -----Original Message-----
> > > From: linux-arm-kernel [mailto:linux-arm-kernel-
> > > bounces@lists.infradead.org] On Behalf Of Minghuan Lian
> > > Sent: Wednesday, April 15, 2015 3:19 PM
> > > To: linux-pci@vger.kernel.org
> > > Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang
> > > Roy- R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421;
> > > linux-arm- kernel@lists.infradead.org
> > > Subject: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > >
> > > SMMU of some platforms can only isolate limited device ID.
> > > This may require that all PCI devices share the same ITS device with
> > > the fixed device ID. The patch adds function
> > > arch_msi_share_devid_update used for these platforms to update the
> > > fixed device ID and maximum MSI interrupts number.
> > >
> > > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > > ---
> > >  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
> > >  1 file changed, 11 insertions(+)
> > >
> > > diff --git a/drivers/irqchip/irq-gic-v3-its.c
> > > b/drivers/irqchip/irq-gic-v3-its.c
> > > index d0374a6..be78d0a 100644
> > > --- a/drivers/irqchip/irq-gic-v3-its.c
> > > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > > @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev
> > > *pdev,
> > > u16 alias, void *data)
> > >  	return 0;
> > >  }
> > >
> > > +void __weak
> > > +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> > > +*nvesc) {
> > > +	/*
> > > +	 * use PCI_DEVID NOT share device ID as default
> > > +	 * so nothing need to do
> > > +	 */
> > > +}
> > > +
> > >  static int its_msi_prepare(struct irq_domain *domain, struct device
> *dev,
> > >  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> > > +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain,
> > > +struct
> > > device *dev,
> > >  	dev_alias.count = nvec;
> > >
> > >  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> > > +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> > > +&dev_alias.count);
> > > +
> > >  	its = domain->parent->host_data;
> > >
> > >  	its_dev = its_find_device(its, dev_alias.dev_id);
> > > --
> > > 1.9.1
> > >
> > >
> > > _______________________________________________
> > > 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] 74+ messages in thread

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-15 13:18         ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-15 13:18 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Minghuan,
Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID would also be forwarded as a part of stream id to GIC. My understanding is that TBU ID is forwarded (as a part of the stream ID) to the TCU in case of a TBU translation miss. In case of the LS2085 PCIe controller you would have to setup the PCIe device ID to stream ID translation table. We may have to restrict the number of entries based on the available number of contexts.

Regards
Varun


> -----Original Message-----
> From: Lian Minghuan-B31939
> Sent: Wednesday, April 15, 2015 5:08 PM
> To: Sethi Varun-B16395; linux-pci at vger.kernel.org
> Cc: Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-
> B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-
> kernel at lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Varun,
> 
> Freescale LS2085A SMMU uses in hit/miss mechanism for the concatenation
> {tbu number,stream_id}. This concatenation is then assigned to a context
> bank that determines the translation type and form. The Isolation Context
> Identifier ICID is the main field of stream_id which will be used to hit ITS
> device. We may look ICID as ITS device ID and PCI device ID. But there are
> only 64 ICIDs  0 - 63.  If using default PCI_DEVID(bus, devfn)  ((((u16)(bus)) <<
> 8) | (devfn)), PCI device(bus >=1) ) ID will larger than 63.  SMMU will miss this
> translation.
> In addition, because the ICID number  is only 64, all the PCIe device will use
> the same ICID and share the same ITS device.
> 
> Thanks,
> Minghuan
> 
> > -----Original Message-----
> > From: Sethi Varun-B16395
> > Sent: Wednesday, April 15, 2015 7:08 PM
> > To: Lian Minghuan-B31939; linux-pci at vger.kernel.org
> > Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang Roy-
> > R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421;
> > linux-arm- kernel at lists.infradead.org
> > Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Hi Minghuan,
> > Not clear what this patch intends to do. Can you please explain the
> > point about SMMU isolating limited device ID.
> >
> > Regards
> > Varun
> >
> > > -----Original Message-----
> > > From: linux-arm-kernel [mailto:linux-arm-kernel-
> > > bounces at lists.infradead.org] On Behalf Of Minghuan Lian
> > > Sent: Wednesday, April 15, 2015 3:19 PM
> > > To: linux-pci at vger.kernel.org
> > > Cc: Arnd Bergmann; Lian Minghuan-B31939; Hu Mingkai-B21284; Zang
> > > Roy- R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421;
> > > linux-arm- kernel at lists.infradead.org
> > > Subject: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > >
> > > SMMU of some platforms can only isolate limited device ID.
> > > This may require that all PCI devices share the same ITS device with
> > > the fixed device ID. The patch adds function
> > > arch_msi_share_devid_update used for these platforms to update the
> > > fixed device ID and maximum MSI interrupts number.
> > >
> > > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > > ---
> > >  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
> > >  1 file changed, 11 insertions(+)
> > >
> > > diff --git a/drivers/irqchip/irq-gic-v3-its.c
> > > b/drivers/irqchip/irq-gic-v3-its.c
> > > index d0374a6..be78d0a 100644
> > > --- a/drivers/irqchip/irq-gic-v3-its.c
> > > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > > @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev
> > > *pdev,
> > > u16 alias, void *data)
> > >  	return 0;
> > >  }
> > >
> > > +void __weak
> > > +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> > > +*nvesc) {
> > > +	/*
> > > +	 * use PCI_DEVID NOT share device ID as default
> > > +	 * so nothing need to do
> > > +	 */
> > > +}
> > > +
> > >  static int its_msi_prepare(struct irq_domain *domain, struct device
> *dev,
> > >  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> > > +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain,
> > > +struct
> > > device *dev,
> > >  	dev_alias.count = nvec;
> > >
> > >  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> > > +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> > > +&dev_alias.count);
> > > +
> > >  	its = domain->parent->host_data;
> > >
> > >  	its_dev = its_find_device(its, dev_alias.dev_id);
> > > --
> > > 1.9.1
> > >
> > >
> > > _______________________________________________
> > > linux-arm-kernel mailing list
> > > linux-arm-kernel at lists.infradead.org
> > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] irqchip/gicv3-its: Decrease page size when needed
  2015-04-15 11:51   ` Jason Cooper
@ 2015-04-15 14:17     ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-15 14:17 UTC (permalink / raw)
  To: Jason Cooper, Minghuan Lian
  Cc: Arnd Bergmann, linux-pci, Hu Mingkai-B21284, Zang Roy-R61911,
	Yoder Stuart-B08248, Scott Wood, Bjorn Helgaas, linux-arm-kernel

On 2015-04-15 12:51, Jason Cooper wrote:
> Minghuan Lian,
>
> On Wed, Apr 15, 2015 at 05:49:22PM +0800, Minghuan Lian wrote:
>> The default page size of ITS table has been changed to 64KB,
>> but for some platforms the real size of allocate memory which
>> calculated by DEVBITS of register GITS_TYPER may smaller than
>> default size. In this case, psz must be decreased, otherwise,
>> the wrong page number will cause kernel hang.
>>
>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
>> ---
>>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
>>  1 file changed, 3 insertions(+)
>
> Please run scripts/get_maintainer.pl on your patches before sending.  
> This
> needs to be sent to myself and Thomas Gleixner for review.

Please also CC me on anything that touches GICv3 or the ITS code.

Thanks,

         M.
-- 
Fast, cheap, reliable. Pick two.

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

* [PATCH] irqchip/gicv3-its: Decrease page size when needed
@ 2015-04-15 14:17     ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-15 14:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 2015-04-15 12:51, Jason Cooper wrote:
> Minghuan Lian,
>
> On Wed, Apr 15, 2015 at 05:49:22PM +0800, Minghuan Lian wrote:
>> The default page size of ITS table has been changed to 64KB,
>> but for some platforms the real size of allocate memory which
>> calculated by DEVBITS of register GITS_TYPER may smaller than
>> default size. In this case, psz must be decreased, otherwise,
>> the wrong page number will cause kernel hang.
>>
>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
>> ---
>>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
>>  1 file changed, 3 insertions(+)
>
> Please run scripts/get_maintainer.pl on your patches before sending.  
> This
> needs to be sent to myself and Thomas Gleixner for review.

Please also CC me on anything that touches GICv3 or the ITS code.

Thanks,

         M.
-- 
Fast, cheap, reliable. Pick two.

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

* Re: [PATCH] irqchip/gicv3-its: Decrease page size when needed
  2015-04-15  9:49 ` Minghuan Lian
@ 2015-04-15 16:31   ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-15 16:31 UTC (permalink / raw)
  To: Minghuan Lian
  Cc: linux-pci, Arnd Bergmann, Hu Mingkai-B21284, Zang Roy-R61911,
	Yoder Stuart-B08248, Bjorn Helgaas, Scott Wood, linux-arm-kernel,
	Jason Cooper, Thomas Gleixner

On Wed, 15 Apr 2015 17:49:22 +0800
Minghuan Lian <Minghuan.Lian@freescale.com> wrote:

[adding Jason and Thomas to the party, since they shoud be cc'd the
first place]

> The default page size of ITS table has been changed to 64KB,
> but for some platforms the real size of allocate memory which
> calculated by DEVBITS of register GITS_TYPER may smaller than
> default size. In this case, psz must be decreased, otherwise,
> the wrong page number will cause kernel hang.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index 596b0a9..d0374a6 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -844,6 +844,9 @@ static int its_alloc_tables(struct its_node *its)
>  
>  		its->tables[i] = base;
>  
> +		while (alloc_size < psz)
> +			psz = psz >> 1;
> +
>  retry_baser:
>  		val = (virt_to_phys(base) 				 |
>  		       (type << GITS_BASER_TYPE_SHIFT)			 |

This doesn't make sense to me. psz is the page size that your HW
supports, not necessarily something that you can actually change as you
wish (some, if not most, ITSs only support one page size). Also, you
now have to psz go via unsupported page sizes (like 32K and 8K), and
you may end up programming junk in the registers. Good job! ;-)

So making it vary to accommodate your allocation size is slightly
doomed. If your allocation is smaller than your ITS page size, it is
the allocation that has to be bumped up, not the page size that has to
be reduced.

So overall, this is a NAK. Please come up with a better fix.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

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

* [PATCH] irqchip/gicv3-its: Decrease page size when needed
@ 2015-04-15 16:31   ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-15 16:31 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 15 Apr 2015 17:49:22 +0800
Minghuan Lian <Minghuan.Lian@freescale.com> wrote:

[adding Jason and Thomas to the party, since they shoud be cc'd the
first place]

> The default page size of ITS table has been changed to 64KB,
> but for some platforms the real size of allocate memory which
> calculated by DEVBITS of register GITS_TYPER may smaller than
> default size. In this case, psz must be decreased, otherwise,
> the wrong page number will cause kernel hang.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index 596b0a9..d0374a6 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -844,6 +844,9 @@ static int its_alloc_tables(struct its_node *its)
>  
>  		its->tables[i] = base;
>  
> +		while (alloc_size < psz)
> +			psz = psz >> 1;
> +
>  retry_baser:
>  		val = (virt_to_phys(base) 				 |
>  		       (type << GITS_BASER_TYPE_SHIFT)			 |

This doesn't make sense to me. psz is the page size that your HW
supports, not necessarily something that you can actually change as you
wish (some, if not most, ITSs only support one page size). Also, you
now have to psz go via unsupported page sizes (like 32K and 8K), and
you may end up programming junk in the registers. Good job! ;-)

So making it vary to accommodate your allocation size is slightly
doomed. If your allocation is smaller than your ITS page size, it is
the allocation that has to be bumped up, not the page size that has to
be reduced.

So overall, this is a NAK. Please come up with a better fix.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15  9:49   ` Minghuan Lian
@ 2015-04-15 16:36     ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-15 16:36 UTC (permalink / raw)
  To: Minghuan Lian
  Cc: linux-pci, Arnd Bergmann, Hu Mingkai-B21284, Zang Roy-R61911,
	Yoder Stuart-B08248, Bjorn Helgaas, Scott Wood, linux-arm-kernel,
	Jason Cooper, Thomas Gleixner

On Wed, 15 Apr 2015 17:49:23 +0800
Minghuan Lian <Minghuan.Lian@freescale.com> wrote:

> SMMU of some platforms can only isolate limited device ID.
> This may require that all PCI devices share the same ITS
> device with the fixed device ID. The patch adds function
> arch_msi_share_devid_update used for these platforms to update
> the fixed device ID and maximum MSI interrupts number.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index d0374a6..be78d0a 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev, u16 alias, void *data)
>  	return 0;
>  }
>  
> +void __weak
> +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32 *nvesc)
> +{
> +	/*
> +	 * use PCI_DEVID NOT share device ID as default
> +	 * so nothing need to do
> +	 */
> +}
> +

NAK. On top of being ugly as sin, this breaks any form of multiplatform
support. No way anything like this is going in. Guys, you really should
know better.

>  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
>  			   int nvec, msi_alloc_info_t *info)
>  {
> @@ -1185,6 +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
>  	dev_alias.count = nvec;
>  
>  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id, &dev_alias.count);
> +

See the function above? That's where the aliasing should be taken care
of.

>  	its = domain->parent->host_data;
>  
>  	its_dev = its_find_device(its, dev_alias.dev_id);

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-15 16:36     ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-15 16:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 15 Apr 2015 17:49:23 +0800
Minghuan Lian <Minghuan.Lian@freescale.com> wrote:

> SMMU of some platforms can only isolate limited device ID.
> This may require that all PCI devices share the same ITS
> device with the fixed device ID. The patch adds function
> arch_msi_share_devid_update used for these platforms to update
> the fixed device ID and maximum MSI interrupts number.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index d0374a6..be78d0a 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev, u16 alias, void *data)
>  	return 0;
>  }
>  
> +void __weak
> +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32 *nvesc)
> +{
> +	/*
> +	 * use PCI_DEVID NOT share device ID as default
> +	 * so nothing need to do
> +	 */
> +}
> +

NAK. On top of being ugly as sin, this breaks any form of multiplatform
support. No way anything like this is going in. Guys, you really should
know better.

>  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
>  			   int nvec, msi_alloc_info_t *info)
>  {
> @@ -1185,6 +1194,8 @@ static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
>  	dev_alias.count = nvec;
>  
>  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id, &dev_alias.count);
> +

See the function above? That's where the aliasing should be taken care
of.

>  	its = domain->parent->host_data;
>  
>  	its_dev = its_find_device(its, dev_alias.dev_id);

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny.

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

* RE: [PATCH] irqchip/gicv3-its: Decrease page size when needed
  2015-04-15 14:17     ` Marc Zyngier
@ 2015-04-16  1:15       ` Minghuan.Lian at freescale.com
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian @ 2015-04-16  1:15 UTC (permalink / raw)
  To: Marc Zyngier, Jason Cooper
  Cc: Arnd Bergmann, linux-pci, Mingkai.Hu, Roy Zang, Stuart Yoder,
	Scott Wood, Bjorn Helgaas, linux-arm-kernel

SGkgTWFyYywNCg0KT0ssIEkgd2lsbCBmb2xsb3cgeW91ciBjb21tZW50Lg0KDQpUaGFua3MsDQpN
aW5naHVhbg0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IE1hcmMgWnlu
Z2llciBbbWFpbHRvOm1hcmMuenluZ2llckBhcm0uY29tXQ0KPiBTZW50OiBXZWRuZXNkYXksIEFw
cmlsIDE1LCAyMDE1IDEwOjE3IFBNDQo+IFRvOiBKYXNvbiBDb29wZXI7IExpYW4gTWluZ2h1YW4t
QjMxOTM5DQo+IENjOiBBcm5kIEJlcmdtYW5uOyBsaW51eC1wY2lAdmdlci5rZXJuZWwub3JnOyBI
dSBNaW5na2FpLUIyMTI4NDsgWmFuZw0KPiBSb3ktUjYxOTExOyBZb2RlciBTdHVhcnQtQjA4MjQ4
OyBXb29kIFNjb3R0LUIwNzQyMTsgQmpvcm4gSGVsZ2FhczsgbGludXgtDQo+IGFybS1rZXJuZWxA
bGlzdHMuaW5mcmFkZWFkLm9yZw0KPiBTdWJqZWN0OiBSZTogW1BBVENIXSBpcnFjaGlwL2dpY3Yz
LWl0czogRGVjcmVhc2UgcGFnZSBzaXplIHdoZW4gbmVlZGVkDQo+IA0KPiBPbiAyMDE1LTA0LTE1
IDEyOjUxLCBKYXNvbiBDb29wZXIgd3JvdGU6DQo+ID4gTWluZ2h1YW4gTGlhbiwNCj4gPg0KPiA+
IE9uIFdlZCwgQXByIDE1LCAyMDE1IGF0IDA1OjQ5OjIyUE0gKzA4MDAsIE1pbmdodWFuIExpYW4g
d3JvdGU6DQo+ID4+IFRoZSBkZWZhdWx0IHBhZ2Ugc2l6ZSBvZiBJVFMgdGFibGUgaGFzIGJlZW4g
Y2hhbmdlZCB0byA2NEtCLCBidXQgZm9yDQo+ID4+IHNvbWUgcGxhdGZvcm1zIHRoZSByZWFsIHNp
emUgb2YgYWxsb2NhdGUgbWVtb3J5IHdoaWNoIGNhbGN1bGF0ZWQgYnkNCj4gPj4gREVWQklUUyBv
ZiByZWdpc3RlciBHSVRTX1RZUEVSIG1heSBzbWFsbGVyIHRoYW4gZGVmYXVsdCBzaXplLiBJbiB0
aGlzDQo+ID4+IGNhc2UsIHBzeiBtdXN0IGJlIGRlY3JlYXNlZCwgb3RoZXJ3aXNlLCB0aGUgd3Jv
bmcgcGFnZSBudW1iZXIgd2lsbA0KPiA+PiBjYXVzZSBrZXJuZWwgaGFuZy4NCj4gPj4NCj4gPj4g
U2lnbmVkLW9mZi1ieTogTWluZ2h1YW4gTGlhbiA8TWluZ2h1YW4uTGlhbkBmcmVlc2NhbGUuY29t
Pg0KPiA+PiAtLS0NCj4gPj4gIGRyaXZlcnMvaXJxY2hpcC9pcnEtZ2ljLXYzLWl0cy5jIHwgMyAr
KysNCj4gPj4gIDEgZmlsZSBjaGFuZ2VkLCAzIGluc2VydGlvbnMoKykNCj4gPg0KPiA+IFBsZWFz
ZSBydW4gc2NyaXB0cy9nZXRfbWFpbnRhaW5lci5wbCBvbiB5b3VyIHBhdGNoZXMgYmVmb3JlIHNl
bmRpbmcuDQo+ID4gVGhpcw0KPiA+IG5lZWRzIHRvIGJlIHNlbnQgdG8gbXlzZWxmIGFuZCBUaG9t
YXMgR2xlaXhuZXIgZm9yIHJldmlldy4NCj4gDQo+IFBsZWFzZSBhbHNvIENDIG1lIG9uIGFueXRo
aW5nIHRoYXQgdG91Y2hlcyBHSUN2MyBvciB0aGUgSVRTIGNvZGUuDQo+IA0KPiBUaGFua3MsDQo+
IA0KPiAgICAgICAgICBNLg0KPiAtLQ0KPiBGYXN0LCBjaGVhcCwgcmVsaWFibGUuIFBpY2sgdHdv
Lg0K

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

* [PATCH] irqchip/gicv3-its: Decrease page size when needed
@ 2015-04-16  1:15       ` Minghuan.Lian at freescale.com
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian at freescale.com @ 2015-04-16  1:15 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc,

OK, I will follow your comment.

Thanks,
Minghuan

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> Sent: Wednesday, April 15, 2015 10:17 PM
> To: Jason Cooper; Lian Minghuan-B31939
> Cc: Arnd Bergmann; linux-pci at vger.kernel.org; Hu Mingkai-B21284; Zang
> Roy-R61911; Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; linux-
> arm-kernel at lists.infradead.org
> Subject: Re: [PATCH] irqchip/gicv3-its: Decrease page size when needed
> 
> On 2015-04-15 12:51, Jason Cooper wrote:
> > Minghuan Lian,
> >
> > On Wed, Apr 15, 2015 at 05:49:22PM +0800, Minghuan Lian wrote:
> >> The default page size of ITS table has been changed to 64KB, but for
> >> some platforms the real size of allocate memory which calculated by
> >> DEVBITS of register GITS_TYPER may smaller than default size. In this
> >> case, psz must be decreased, otherwise, the wrong page number will
> >> cause kernel hang.
> >>
> >> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> >> ---
> >>  drivers/irqchip/irq-gic-v3-its.c | 3 +++
> >>  1 file changed, 3 insertions(+)
> >
> > Please run scripts/get_maintainer.pl on your patches before sending.
> > This
> > needs to be sent to myself and Thomas Gleixner for review.
> 
> Please also CC me on anything that touches GICv3 or the ITS code.
> 
> Thanks,
> 
>          M.
> --
> Fast, cheap, reliable. Pick two.

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15 16:36     ` Marc Zyngier
@ 2015-04-16  2:57       ` Minghuan.Lian at freescale.com
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian @ 2015-04-16  2:57 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang, Stuart Yoder,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel, Jason Cooper,
	Thomas Gleixner

Hi Marc,

Please see my comments inline

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> Sent: Thursday, April 16, 2015 12:37 AM
> To: Lian Minghuan-B31939
> Cc: linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> Roy-R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-
> arm-kernel@lists.infradead.org; Jason Cooper; Thomas Gleixner
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Wed, 15 Apr 2015 17:49:23 +0800
> Minghuan Lian <Minghuan.Lian@freescale.com> wrote:
> 
> > SMMU of some platforms can only isolate limited device ID.
> > This may require that all PCI devices share the same ITS device with
> > the fixed device ID. The patch adds function
> > arch_msi_share_devid_update used for these platforms to update the
> > fixed device ID and maximum MSI interrupts number.
> >
> > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > ---
> >  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/irqchip/irq-gic-v3-its.c
> > b/drivers/irqchip/irq-gic-v3-its.c
> > index d0374a6..be78d0a 100644
> > --- a/drivers/irqchip/irq-gic-v3-its.c
> > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev,
> u16 alias, void *data)
> >  	return 0;
> >  }
> >
> > +void __weak
> > +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> > +*nvesc) {
> > +	/*
> > +	 * use PCI_DEVID NOT share device ID as default
> > +	 * so nothing need to do
> > +	 */
> > +}
> > +
> 
> NAK. On top of being ugly as sin, this breaks any form of multiplatform
> support. No way anything like this is going in. Guys, you really should know
> better.
> 
[Minghuan]  The current ITS MSI will create an individual ITS device for each PCIe device, and use PCI_DEVID as ITS dev_id
However, out platform only supports  ITS dev_id 0 -63.  A normal PCIe DEVID of 0000:01:00.0 is 256 bigger than 63.
Besides, because of the limited dev_id number, all the PCIe device will share the same ITS dev. Our platform provides a hardware module LUT to map PCI DEVID to ITS dev_id.  So, when creating ITS device, we need to update dev_id and the nvesc.
I may change pci_for_each_dma_alias to add a new flag to use alias_bus and alias_devfn. 
But I also need to update nvesc which should contains all the PCI device MSI/MSIX nvesc and PCIe PME, aerdrv interrupts.
The main difference is that we need a ITS device to service multiple PCIe devices.
Could you give me some suggestions how to implement this requirement.
     

> >  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> >  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> +1194,8 @@
> > static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> >  	dev_alias.count = nvec;
> >
> >  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> > +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> > +&dev_alias.count);
> > +
> 
> See the function above? That's where the aliasing should be taken care of.
> 
[Minghuan] The alias will use dma_alias_devfn, but it does not contains alias_bus.
I need to translate PCI_DEVID to a fixed ID.

> >  	its = domain->parent->host_data;
> >
> >  	its_dev = its_find_device(its, dev_alias.dev_id);
> 
> Thanks,
> 
> 	M.
> --
> Jazz is not dead. It just smells funny.

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-16  2:57       ` Minghuan.Lian at freescale.com
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian at freescale.com @ 2015-04-16  2:57 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc,

Please see my comments inline

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> Sent: Thursday, April 16, 2015 12:37 AM
> To: Lian Minghuan-B31939
> Cc: linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> Roy-R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-
> arm-kernel at lists.infradead.org; Jason Cooper; Thomas Gleixner
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Wed, 15 Apr 2015 17:49:23 +0800
> Minghuan Lian <Minghuan.Lian@freescale.com> wrote:
> 
> > SMMU of some platforms can only isolate limited device ID.
> > This may require that all PCI devices share the same ITS device with
> > the fixed device ID. The patch adds function
> > arch_msi_share_devid_update used for these platforms to update the
> > fixed device ID and maximum MSI interrupts number.
> >
> > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > ---
> >  drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/irqchip/irq-gic-v3-its.c
> > b/drivers/irqchip/irq-gic-v3-its.c
> > index d0374a6..be78d0a 100644
> > --- a/drivers/irqchip/irq-gic-v3-its.c
> > +++ b/drivers/irqchip/irq-gic-v3-its.c
> > @@ -1169,6 +1169,15 @@ static int its_get_pci_alias(struct pci_dev *pdev,
> u16 alias, void *data)
> >  	return 0;
> >  }
> >
> > +void __weak
> > +arch_msi_share_devid_update(struct pci_dev *pdev, u32 *dev_id, u32
> > +*nvesc) {
> > +	/*
> > +	 * use PCI_DEVID NOT share device ID as default
> > +	 * so nothing need to do
> > +	 */
> > +}
> > +
> 
> NAK. On top of being ugly as sin, this breaks any form of multiplatform
> support. No way anything like this is going in. Guys, you really should know
> better.
> 
[Minghuan]  The current ITS MSI will create an individual ITS device for each PCIe device, and use PCI_DEVID as ITS dev_id
However, out platform only supports  ITS dev_id 0 -63.  A normal PCIe DEVID of 0000:01:00.0 is 256 bigger than 63.
Besides, because of the limited dev_id number, all the PCIe device will share the same ITS dev. Our platform provides a hardware module LUT to map PCI DEVID to ITS dev_id.  So, when creating ITS device, we need to update dev_id and the nvesc.
I may change pci_for_each_dma_alias to add a new flag to use alias_bus and alias_devfn. 
But I also need to update nvesc which should contains all the PCI device MSI/MSIX nvesc and PCIe PME, aerdrv interrupts.
The main difference is that we need a ITS device to service multiple PCIe devices.
Could you give me some suggestions how to implement this requirement.
     

> >  static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> >  			   int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> +1194,8 @@
> > static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
> >  	dev_alias.count = nvec;
> >
> >  	pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
> > +	arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> > +&dev_alias.count);
> > +
> 
> See the function above? That's where the aliasing should be taken care of.
> 
[Minghuan] The alias will use dma_alias_devfn, but it does not contains alias_bus.
I need to translate PCI_DEVID to a fixed ID.

> >  	its = domain->parent->host_data;
> >
> >  	its_dev = its_find_device(its, dev_alias.dev_id);
> 
> Thanks,
> 
> 	M.
> --
> Jazz is not dead. It just smells funny.

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-16  2:57       ` Minghuan.Lian at freescale.com
@ 2015-04-16 10:04         ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-16 10:04 UTC (permalink / raw)
  To: Minghuan.Lian
  Cc: linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang, Stuart Yoder,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel, Jason Cooper,
	Thomas Gleixner

On 16/04/15 03:57, Minghuan.Lian@freescale.com wrote:
> Hi Marc,
> 
> Please see my comments inline
> 
>> -----Original Message----- From: Marc Zyngier 
>> [mailto:marc.zyngier@arm.com] Sent: Thursday, April 16, 2015 12:37
>>  AM To: Lian Minghuan-B31939 Cc: linux-pci@vger.kernel.org; Arnd 
>> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-B08248;
>>  Bjorn Helgaas; Wood Scott-B07421; linux- 
>> arm-kernel@lists.infradead.org; Jason Cooper; Thomas Gleixner 
>> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device 
>> ID
>> 
>> On Wed, 15 Apr 2015 17:49:23 +0800 Minghuan Lian 
>> <Minghuan.Lian@freescale.com> wrote:
>> 
>>> SMMU of some platforms can only isolate limited device ID. This 
>>> may require that all PCI devices share the same ITS device with 
>>> the fixed device ID. The patch adds function 
>>> arch_msi_share_devid_update used for these platforms to update 
>>> the fixed device ID and maximum MSI interrupts number.
>>> 
>>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com> --- 
>>> drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++ 1 file changed,
>>> 11 insertions(+)
>>> 
>>> diff --git a/drivers/irqchip/irq-gic-v3-its.c 
>>> b/drivers/irqchip/irq-gic-v3-its.c index d0374a6..be78d0a 100644 
>>> --- a/drivers/irqchip/irq-gic-v3-its.c +++ 
>>> b/drivers/irqchip/irq-gic-v3-its.c @@ -1169,6 +1169,15 @@ static
>>>  int its_get_pci_alias(struct pci_dev *pdev,
>> u16 alias, void *data)
>>> return 0; }
>>> 
>>> +void __weak +arch_msi_share_devid_update(struct pci_dev *pdev, 
>>> u32 *dev_id, u32 +*nvesc) { +	/* +	 * use PCI_DEVID NOT share 
>>> device ID as default +	 * so nothing need to do +	 */ +} +
>> 
>> NAK. On top of being ugly as sin, this breaks any form of 
>> multiplatform support. No way anything like this is going in. Guys,
>> you really should know better.
>> 
> [Minghuan]  The current ITS MSI will create an individual ITS device 
> for each PCIe device, and use PCI_DEVID as ITS dev_id However, out 
> platform only supports  ITS dev_id 0 -63.  A normal PCIe DEVID of 
> 0000:01:00.0 is 256 bigger than 63. Besides, because of the limited 
> dev_id number, all the PCIe device will share the same ITS dev. Our 
> platform provides a hardware module LUT to map PCI DEVID to ITS 
> dev_id.  So, when creating ITS device, we need to update dev_id and 
> the nvesc. I may change pci_for_each_dma_alias to add a new flag to 
> use alias_bus and alias_devfn.

Yes, that's where you should take care of this hack.

> But I also need to update nvesc which should contains all the PCI 
> device MSI/MSIX nvesc and PCIe PME, aerdrv interrupts. The main 
> difference is that we need a ITS device to service multiple PCIe 
> devices. Could you give me some suggestions how to implement this 
> requirement.

It you take the time to read the code in its_msi_prepare(), you'll
quickly notice that we already handle aliasing of multiple PCI devices
to a single DeviceID. Once you have the aliasing taken care of in
pci_for_each_dma_alias, the ITS code will automatically adjust the
number of vectors (using its_get_pci_alias as a callback from
pci_for_each_dma_alias).

>>> static int its_msi_prepare(struct irq_domain *domain, struct 
>>> device *dev, int nvec, msi_alloc_info_t *info)  { @@ -1185,6
>> +1194,8 @@
>>> static int its_msi_prepare(struct irq_domain *domain, struct 
>>> device *dev, dev_alias.count = nvec;
>>> 
>>> pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias); + 
>>> arch_msi_share_devid_update(pdev, &dev_alias.dev_id, 
>>> +&dev_alias.count); +
>> 
>> See the function above? That's where the aliasing should be taken 
>> care of.
>> 
> [Minghuan] The alias will use dma_alias_devfn, but it does not 
> contains alias_bus. I need to translate PCI_DEVID to a fixed ID.

Then add another flag to deal with that. Your hardware is "creative"
(some might even argue it is broken), so deal with the creativity as a
quirk, which has no business in the ITS driver (or any other driver).

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-16 10:04         ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-16 10:04 UTC (permalink / raw)
  To: linux-arm-kernel

On 16/04/15 03:57, Minghuan.Lian at freescale.com wrote:
> Hi Marc,
> 
> Please see my comments inline
> 
>> -----Original Message----- From: Marc Zyngier 
>> [mailto:marc.zyngier at arm.com] Sent: Thursday, April 16, 2015 12:37
>>  AM To: Lian Minghuan-B31939 Cc: linux-pci at vger.kernel.org; Arnd 
>> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-B08248;
>>  Bjorn Helgaas; Wood Scott-B07421; linux- 
>> arm-kernel at lists.infradead.org; Jason Cooper; Thomas Gleixner 
>> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device 
>> ID
>> 
>> On Wed, 15 Apr 2015 17:49:23 +0800 Minghuan Lian 
>> <Minghuan.Lian@freescale.com> wrote:
>> 
>>> SMMU of some platforms can only isolate limited device ID. This 
>>> may require that all PCI devices share the same ITS device with 
>>> the fixed device ID. The patch adds function 
>>> arch_msi_share_devid_update used for these platforms to update 
>>> the fixed device ID and maximum MSI interrupts number.
>>> 
>>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com> --- 
>>> drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++ 1 file changed,
>>> 11 insertions(+)
>>> 
>>> diff --git a/drivers/irqchip/irq-gic-v3-its.c 
>>> b/drivers/irqchip/irq-gic-v3-its.c index d0374a6..be78d0a 100644 
>>> --- a/drivers/irqchip/irq-gic-v3-its.c +++ 
>>> b/drivers/irqchip/irq-gic-v3-its.c @@ -1169,6 +1169,15 @@ static
>>>  int its_get_pci_alias(struct pci_dev *pdev,
>> u16 alias, void *data)
>>> return 0; }
>>> 
>>> +void __weak +arch_msi_share_devid_update(struct pci_dev *pdev, 
>>> u32 *dev_id, u32 +*nvesc) { +	/* +	 * use PCI_DEVID NOT share 
>>> device ID as default +	 * so nothing need to do +	 */ +} +
>> 
>> NAK. On top of being ugly as sin, this breaks any form of 
>> multiplatform support. No way anything like this is going in. Guys,
>> you really should know better.
>> 
> [Minghuan]  The current ITS MSI will create an individual ITS device 
> for each PCIe device, and use PCI_DEVID as ITS dev_id However, out 
> platform only supports  ITS dev_id 0 -63.  A normal PCIe DEVID of 
> 0000:01:00.0 is 256 bigger than 63. Besides, because of the limited 
> dev_id number, all the PCIe device will share the same ITS dev. Our 
> platform provides a hardware module LUT to map PCI DEVID to ITS 
> dev_id.  So, when creating ITS device, we need to update dev_id and 
> the nvesc. I may change pci_for_each_dma_alias to add a new flag to 
> use alias_bus and alias_devfn.

Yes, that's where you should take care of this hack.

> But I also need to update nvesc which should contains all the PCI 
> device MSI/MSIX nvesc and PCIe PME, aerdrv interrupts. The main 
> difference is that we need a ITS device to service multiple PCIe 
> devices. Could you give me some suggestions how to implement this 
> requirement.

It you take the time to read the code in its_msi_prepare(), you'll
quickly notice that we already handle aliasing of multiple PCI devices
to a single DeviceID. Once you have the aliasing taken care of in
pci_for_each_dma_alias, the ITS code will automatically adjust the
number of vectors (using its_get_pci_alias as a callback from
pci_for_each_dma_alias).

>>> static int its_msi_prepare(struct irq_domain *domain, struct 
>>> device *dev, int nvec, msi_alloc_info_t *info)  { @@ -1185,6
>> +1194,8 @@
>>> static int its_msi_prepare(struct irq_domain *domain, struct 
>>> device *dev, dev_alias.count = nvec;
>>> 
>>> pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias); + 
>>> arch_msi_share_devid_update(pdev, &dev_alias.dev_id, 
>>> +&dev_alias.count); +
>> 
>> See the function above? That's where the aliasing should be taken 
>> care of.
>> 
> [Minghuan] The alias will use dma_alias_devfn, but it does not 
> contains alias_bus. I need to translate PCI_DEVID to a fixed ID.

Then add another flag to deal with that. Your hardware is "creative"
(some might even argue it is broken), so deal with the creativity as a
quirk, which has no business in the ITS driver (or any other driver).

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-15 13:18         ` Varun Sethi
@ 2015-04-16 10:40           ` Will Deacon
  -1 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-16 10:40 UTC (permalink / raw)
  To: Varun Sethi
  Cc: Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang,
	Stuart Yoder, Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Varun,

Thanks for adding me to Cc.

On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> would also be forwarded as a part of stream id to GIC. My understanding is
> that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> of a TBU translation miss. In case of the LS2085 PCIe controller you would
> have to setup the PCIe device ID to stream ID translation table. We may
> have to restrict the number of entries based on the available number of
> contexts.

Unfortunately, I'm having a really hard time parsing this thread (some parts
of it simply don't make sense; others use non-architectural terms and
overall I don't get a feeling for the problem).

Please could you explain your system design step by step so that I can
understand (a) what you've built and (b) why the current design of Linux is
causing you problems?

Sorry if I'm just being thick, but it's important that we get this right.

Cheers,

Will

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-16 10:40           ` Will Deacon
  0 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-16 10:40 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Varun,

Thanks for adding me to Cc.

On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> would also be forwarded as a part of stream id to GIC. My understanding is
> that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> of a TBU translation miss. In case of the LS2085 PCIe controller you would
> have to setup the PCIe device ID to stream ID translation table. We may
> have to restrict the number of entries based on the available number of
> contexts.

Unfortunately, I'm having a really hard time parsing this thread (some parts
of it simply don't make sense; others use non-architectural terms and
overall I don't get a feeling for the problem).

Please could you explain your system design step by step so that I can
understand (a) what you've built and (b) why the current design of Linux is
causing you problems?

Sorry if I'm just being thick, but it's important that we get this right.

Cheers,

Will

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-16 10:04         ` Marc Zyngier
@ 2015-04-16 10:57           ` Minghuan.Lian at freescale.com
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian @ 2015-04-16 10:57 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang, Stuart Yoder,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel, Jason Cooper,
	Thomas Gleixner

Hi Marc,

Thanks for your comments.
I still have a couple of questions,
1. If I add a new flag and all PCI DEVID will be replaced with a fixed ID,  does SMMU can work correctly?
For example, If we insert an  Ethernet card with two ports, a port is assigned to kvm1, another port is assigned to kvm2. In this case, we should use one or two fixed ID?
2. If using PCIe device with SR-IOV, the driver will dynamically create some new PCIe devices. At this time, ITS device may has been created for PF.  So we must previously  create ITS device with a large enough nvesc.
However its_get_pci_alias: dev_alias->count += its_pci_msi_vec_count(dev_alias->pdev) only calculate with the exiting PCIe device, could not meet this requirement.
How to change dev_alias->count?  

Thanks,
Minghuan
  
> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> Sent: Thursday, April 16, 2015 6:04 PM
> To: Lian Minghuan-B31939
> Cc: linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> Roy-R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-
> arm-kernel@lists.infradead.org; Jason Cooper; Thomas Gleixner
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On 16/04/15 03:57, Minghuan.Lian@freescale.com wrote:
> > Hi Marc,
> >
> > Please see my comments inline
> >
> >> -----Original Message----- From: Marc Zyngier
> >> [mailto:marc.zyngier@arm.com] Sent: Thursday, April 16, 2015 12:37
> >> AM To: Lian Minghuan-B31939 Cc: linux-pci@vger.kernel.org; Arnd
> >> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-B08248;
> >> Bjorn Helgaas; Wood Scott-B07421; linux-
> >> arm-kernel@lists.infradead.org; Jason Cooper; Thomas Gleixner
> >> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >>
> >> On Wed, 15 Apr 2015 17:49:23 +0800 Minghuan Lian
> >> <Minghuan.Lian@freescale.com> wrote:
> >>
> >>> SMMU of some platforms can only isolate limited device ID. This may
> >>> require that all PCI devices share the same ITS device with the
> >>> fixed device ID. The patch adds function arch_msi_share_devid_update
> >>> used for these platforms to update the fixed device ID and maximum
> >>> MSI interrupts number.
> >>>
> >>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com> ---
> >>> drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++ 1 file changed,
> >>> 11 insertions(+)
> >>>
> >>> diff --git a/drivers/irqchip/irq-gic-v3-its.c
> >>> b/drivers/irqchip/irq-gic-v3-its.c index d0374a6..be78d0a 100644
> >>> --- a/drivers/irqchip/irq-gic-v3-its.c +++
> >>> b/drivers/irqchip/irq-gic-v3-its.c @@ -1169,6 +1169,15 @@ static
> >>> int its_get_pci_alias(struct pci_dev *pdev,
> >> u16 alias, void *data)
> >>> return 0; }
> >>>
> >>> +void __weak +arch_msi_share_devid_update(struct pci_dev *pdev,
> >>> u32 *dev_id, u32 +*nvesc) { +	/* +	 * use PCI_DEVID NOT share
> >>> device ID as default +	 * so nothing need to do +	 */ +} +
> >>
> >> NAK. On top of being ugly as sin, this breaks any form of
> >> multiplatform support. No way anything like this is going in. Guys,
> >> you really should know better.
> >>
> > [Minghuan]  The current ITS MSI will create an individual ITS device
> > for each PCIe device, and use PCI_DEVID as ITS dev_id However, out
> > platform only supports  ITS dev_id 0 -63.  A normal PCIe DEVID of
> > 0000:01:00.0 is 256 bigger than 63. Besides, because of the limited
> > dev_id number, all the PCIe device will share the same ITS dev. Our
> > platform provides a hardware module LUT to map PCI DEVID to ITS
> > dev_id.  So, when creating ITS device, we need to update dev_id and
> > the nvesc. I may change pci_for_each_dma_alias to add a new flag to
> > use alias_bus and alias_devfn.
> 
> Yes, that's where you should take care of this hack.
> 
> > But I also need to update nvesc which should contains all the PCI
> > device MSI/MSIX nvesc and PCIe PME, aerdrv interrupts. The main
> > difference is that we need a ITS device to service multiple PCIe
> > devices. Could you give me some suggestions how to implement this
> > requirement.
> 
> It you take the time to read the code in its_msi_prepare(), you'll quickly
> notice that we already handle aliasing of multiple PCI devices to a single
> DeviceID. Once you have the aliasing taken care of in
> pci_for_each_dma_alias, the ITS code will automatically adjust the number
> of vectors (using its_get_pci_alias as a callback from
> pci_for_each_dma_alias).
> 
> >>> static int its_msi_prepare(struct irq_domain *domain, struct device
> >>> *dev, int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> >> +1194,8 @@
> >>> static int its_msi_prepare(struct irq_domain *domain, struct device
> >>> *dev, dev_alias.count = nvec;
> >>>
> >>> pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias); +
> >>> arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> >>> +&dev_alias.count); +
> >>
> >> See the function above? That's where the aliasing should be taken
> >> care of.
> >>
> > [Minghuan] The alias will use dma_alias_devfn, but it does not
> > contains alias_bus. I need to translate PCI_DEVID to a fixed ID.
> 
> Then add another flag to deal with that. Your hardware is "creative"
> (some might even argue it is broken), so deal with the creativity as a quirk,
> which has no business in the ITS driver (or any other driver).
> 
> Thanks,
> 
> 	M.
> --
> Jazz is not dead. It just smells funny...

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-16 10:57           ` Minghuan.Lian at freescale.com
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian at freescale.com @ 2015-04-16 10:57 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc,

Thanks for your comments.
I still have a couple of questions,
1. If I add a new flag and all PCI DEVID will be replaced with a fixed ID,  does SMMU can work correctly?
For example, If we insert an  Ethernet card with two ports, a port is assigned to kvm1, another port is assigned to kvm2. In this case, we should use one or two fixed ID?
2. If using PCIe device with SR-IOV, the driver will dynamically create some new PCIe devices. At this time, ITS device may has been created for PF.  So we must previously  create ITS device with a large enough nvesc.
However its_get_pci_alias: dev_alias->count += its_pci_msi_vec_count(dev_alias->pdev) only calculate with the exiting PCIe device, could not meet this requirement.
How to change dev_alias->count?  

Thanks,
Minghuan
  
> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> Sent: Thursday, April 16, 2015 6:04 PM
> To: Lian Minghuan-B31939
> Cc: linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> Roy-R61911; Yoder Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-
> arm-kernel at lists.infradead.org; Jason Cooper; Thomas Gleixner
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On 16/04/15 03:57, Minghuan.Lian at freescale.com wrote:
> > Hi Marc,
> >
> > Please see my comments inline
> >
> >> -----Original Message----- From: Marc Zyngier
> >> [mailto:marc.zyngier at arm.com] Sent: Thursday, April 16, 2015 12:37
> >> AM To: Lian Minghuan-B31939 Cc: linux-pci at vger.kernel.org; Arnd
> >> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-B08248;
> >> Bjorn Helgaas; Wood Scott-B07421; linux-
> >> arm-kernel at lists.infradead.org; Jason Cooper; Thomas Gleixner
> >> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >>
> >> On Wed, 15 Apr 2015 17:49:23 +0800 Minghuan Lian
> >> <Minghuan.Lian@freescale.com> wrote:
> >>
> >>> SMMU of some platforms can only isolate limited device ID. This may
> >>> require that all PCI devices share the same ITS device with the
> >>> fixed device ID. The patch adds function arch_msi_share_devid_update
> >>> used for these platforms to update the fixed device ID and maximum
> >>> MSI interrupts number.
> >>>
> >>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com> ---
> >>> drivers/irqchip/irq-gic-v3-its.c | 11 +++++++++++ 1 file changed,
> >>> 11 insertions(+)
> >>>
> >>> diff --git a/drivers/irqchip/irq-gic-v3-its.c
> >>> b/drivers/irqchip/irq-gic-v3-its.c index d0374a6..be78d0a 100644
> >>> --- a/drivers/irqchip/irq-gic-v3-its.c +++
> >>> b/drivers/irqchip/irq-gic-v3-its.c @@ -1169,6 +1169,15 @@ static
> >>> int its_get_pci_alias(struct pci_dev *pdev,
> >> u16 alias, void *data)
> >>> return 0; }
> >>>
> >>> +void __weak +arch_msi_share_devid_update(struct pci_dev *pdev,
> >>> u32 *dev_id, u32 +*nvesc) { +	/* +	 * use PCI_DEVID NOT share
> >>> device ID as default +	 * so nothing need to do +	 */ +} +
> >>
> >> NAK. On top of being ugly as sin, this breaks any form of
> >> multiplatform support. No way anything like this is going in. Guys,
> >> you really should know better.
> >>
> > [Minghuan]  The current ITS MSI will create an individual ITS device
> > for each PCIe device, and use PCI_DEVID as ITS dev_id However, out
> > platform only supports  ITS dev_id 0 -63.  A normal PCIe DEVID of
> > 0000:01:00.0 is 256 bigger than 63. Besides, because of the limited
> > dev_id number, all the PCIe device will share the same ITS dev. Our
> > platform provides a hardware module LUT to map PCI DEVID to ITS
> > dev_id.  So, when creating ITS device, we need to update dev_id and
> > the nvesc. I may change pci_for_each_dma_alias to add a new flag to
> > use alias_bus and alias_devfn.
> 
> Yes, that's where you should take care of this hack.
> 
> > But I also need to update nvesc which should contains all the PCI
> > device MSI/MSIX nvesc and PCIe PME, aerdrv interrupts. The main
> > difference is that we need a ITS device to service multiple PCIe
> > devices. Could you give me some suggestions how to implement this
> > requirement.
> 
> It you take the time to read the code in its_msi_prepare(), you'll quickly
> notice that we already handle aliasing of multiple PCI devices to a single
> DeviceID. Once you have the aliasing taken care of in
> pci_for_each_dma_alias, the ITS code will automatically adjust the number
> of vectors (using its_get_pci_alias as a callback from
> pci_for_each_dma_alias).
> 
> >>> static int its_msi_prepare(struct irq_domain *domain, struct device
> >>> *dev, int nvec, msi_alloc_info_t *info)  { @@ -1185,6
> >> +1194,8 @@
> >>> static int its_msi_prepare(struct irq_domain *domain, struct device
> >>> *dev, dev_alias.count = nvec;
> >>>
> >>> pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias); +
> >>> arch_msi_share_devid_update(pdev, &dev_alias.dev_id,
> >>> +&dev_alias.count); +
> >>
> >> See the function above? That's where the aliasing should be taken
> >> care of.
> >>
> > [Minghuan] The alias will use dma_alias_devfn, but it does not
> > contains alias_bus. I need to translate PCI_DEVID to a fixed ID.
> 
> Then add another flag to deal with that. Your hardware is "creative"
> (some might even argue it is broken), so deal with the creativity as a quirk,
> which has no business in the ITS driver (or any other driver).
> 
> Thanks,
> 
> 	M.
> --
> Jazz is not dead. It just smells funny...

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-16 10:57           ` Minghuan.Lian at freescale.com
@ 2015-04-16 11:50             ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-16 11:50 UTC (permalink / raw)
  To: Minghuan.Lian
  Cc: linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang, Stuart Yoder,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel, Jason Cooper,
	Thomas Gleixner, Will Deacon

Minghuan,

On 16/04/15 11:57, Minghuan.Lian@freescale.com wrote:

Please include the relevant people (Will Deacon for questions about the
SMMU), and avoid top posting, it makes it very hard to follow a discussion.

> I still have a couple of questions,
> 1. If I add a new flag and all PCI DEVID will be replaced with a
> fixed ID,  does SMMU can work correctly? For example, If we insert an
> Ethernet card with two ports, a port is assigned to kvm1, another
> port is assigned to kvm2. In this case, we should use one or two
> fixed ID?

That completely depends on what the SMMU sees. If it sees the same ID,
you won't be able to perform any form of isolation. But I have no idea
how your hardware works, so maybe explaining in details how this is
constructed will help.

> 2. If using PCIe device with SR-IOV, the driver will dynamically
> create some new PCIe devices. At this time, ITS device may has been
> created for PF.  So we must previously  create ITS device with a
> large enough nvesc. However its_get_pci_alias: dev_alias->count +=
> its_pci_msi_vec_count(dev_alias->pdev) only calculate with the
> exiting PCIe device, could not meet this requirement. How to change
> dev_alias->count?

You cannot change this dynamically. The ITT for this DeviceID will have
been allocated, and the ITS is getting live traffic. No way you're going
to resize it.

You will probable have to add some extra quirks to force the allocation
of a much larger ITT by lying about the nvec somehow. Or forget about
SRIOV and hotplug.

	M.
-- 
Jazz is not dead. It just smells funny...

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-16 11:50             ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-16 11:50 UTC (permalink / raw)
  To: linux-arm-kernel

Minghuan,

On 16/04/15 11:57, Minghuan.Lian at freescale.com wrote:

Please include the relevant people (Will Deacon for questions about the
SMMU), and avoid top posting, it makes it very hard to follow a discussion.

> I still have a couple of questions,
> 1. If I add a new flag and all PCI DEVID will be replaced with a
> fixed ID,  does SMMU can work correctly? For example, If we insert an
> Ethernet card with two ports, a port is assigned to kvm1, another
> port is assigned to kvm2. In this case, we should use one or two
> fixed ID?

That completely depends on what the SMMU sees. If it sees the same ID,
you won't be able to perform any form of isolation. But I have no idea
how your hardware works, so maybe explaining in details how this is
constructed will help.

> 2. If using PCIe device with SR-IOV, the driver will dynamically
> create some new PCIe devices. At this time, ITS device may has been
> created for PF.  So we must previously  create ITS device with a
> large enough nvesc. However its_get_pci_alias: dev_alias->count +=
> its_pci_msi_vec_count(dev_alias->pdev) only calculate with the
> exiting PCIe device, could not meet this requirement. How to change
> dev_alias->count?

You cannot change this dynamically. The ITT for this DeviceID will have
been allocated, and the ITS is getting live traffic. No way you're going
to resize it.

You will probable have to add some extra quirks to force the allocation
of a much larger ITT by lying about the nvec somehow. Or forget about
SRIOV and hotplug.

	M.
-- 
Jazz is not dead. It just smells funny...

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-16 11:50             ` Marc Zyngier
@ 2015-04-16 18:38               ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-16 18:38 UTC (permalink / raw)
  To: Marc Zyngier, Minghuan.Lian
  Cc: Jason Cooper, Arnd Bergmann, linux-pci, Will Deacon,
	Stuart Yoder, Scott Wood, Bjorn Helgaas, Mingkai.Hu, Roy Zang,
	Thomas Gleixner, linux-arm-kernel

Hi Minghuan,

> -----Original Message-----
> From: linux-arm-kernel [mailto:linux-arm-kernel-
> bounces@lists.infradead.org] On Behalf Of Marc Zyngier
> Sent: Thursday, April 16, 2015 5:21 PM
> To: Lian Minghuan-B31939
> Cc: Jason Cooper; Arnd Bergmann; linux-pci@vger.kernel.org; Will Deacon;
> Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; Hu Mingkai-B21284;
> Zang Roy-R61911; Thomas Gleixner; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Minghuan,
> 
> On 16/04/15 11:57, Minghuan.Lian@freescale.com wrote:
> 
> Please include the relevant people (Will Deacon for questions about the
> SMMU), and avoid top posting, it makes it very hard to follow a discussion.
> 
> > I still have a couple of questions,
> > 1. If I add a new flag and all PCI DEVID will be replaced with a fixed
> > ID,  does SMMU can work correctly? For example, If we insert an
> > Ethernet card with two ports, a port is assigned to kvm1, another port
> > is assigned to kvm2. In this case, we should use one or two fixed ID?
> 
> That completely depends on what the SMMU sees. If it sees the same ID,
> you won't be able to perform any form of isolation. But I have no idea how
> your hardware works, so maybe explaining in details how this is constructed
> will help.
> 

We would need separate stream IDs and iommu groups for endpoints, to assign them to different VMs. We would have to set up the stream ID to device ID translation table during device probe, via add_device callback. While setting the device id for the interrupt translation table, you would have to get streamID corresponding to a given PCIe device ID. Again, I don't think that we should consider the TBUID, while setting the ITT device id.

-Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-16 18:38               ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-16 18:38 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Minghuan,

> -----Original Message-----
> From: linux-arm-kernel [mailto:linux-arm-kernel-
> bounces at lists.infradead.org] On Behalf Of Marc Zyngier
> Sent: Thursday, April 16, 2015 5:21 PM
> To: Lian Minghuan-B31939
> Cc: Jason Cooper; Arnd Bergmann; linux-pci at vger.kernel.org; Will Deacon;
> Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; Hu Mingkai-B21284;
> Zang Roy-R61911; Thomas Gleixner; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Minghuan,
> 
> On 16/04/15 11:57, Minghuan.Lian at freescale.com wrote:
> 
> Please include the relevant people (Will Deacon for questions about the
> SMMU), and avoid top posting, it makes it very hard to follow a discussion.
> 
> > I still have a couple of questions,
> > 1. If I add a new flag and all PCI DEVID will be replaced with a fixed
> > ID,  does SMMU can work correctly? For example, If we insert an
> > Ethernet card with two ports, a port is assigned to kvm1, another port
> > is assigned to kvm2. In this case, we should use one or two fixed ID?
> 
> That completely depends on what the SMMU sees. If it sees the same ID,
> you won't be able to perform any form of isolation. But I have no idea how
> your hardware works, so maybe explaining in details how this is constructed
> will help.
> 

We would need separate stream IDs and iommu groups for endpoints, to assign them to different VMs. We would have to set up the stream ID to device ID translation table during device probe, via add_device callback. While setting the device id for the interrupt translation table, you would have to get streamID corresponding to a given PCIe device ID. Again, I don't think that we should consider the TBUID, while setting the ITT device id.

-Varun

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-16 18:38               ` Varun Sethi
@ 2015-04-17  2:34                 ` Minghuan.Lian at freescale.com
  -1 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian @ 2015-04-17  2:34 UTC (permalink / raw)
  To: Varun Sethi, Marc Zyngier
  Cc: Jason Cooper, Arnd Bergmann, linux-pci, Will Deacon,
	Stuart Yoder, Scott Wood, Bjorn Helgaas, Mingkai.Hu, Roy Zang,
	Thomas Gleixner, linux-arm-kernel

Hi Marc and Varun,

Thank you very much for your valuable comments.
I will study further and try to find a better way to support ls2085 msi.

Thanks,
Minghuan

> -----Original Message-----
> From: Sethi Varun-B16395
> Sent: Friday, April 17, 2015 2:38 AM
> To: Marc Zyngier; Lian Minghuan-B31939
> Cc: Jason Cooper; Arnd Bergmann; linux-pci@vger.kernel.org; Will Deacon;T
> Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; Hu Mingkai-B21284;
> Zang Roy-R61911; Thomas Gleixner; linux-arm-kernel@lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Minghuan,
> 
> > -----Original Message-----
> > From: linux-arm-kernel [mailto:linux-arm-kernel-
> > bounces@lists.infradead.org] On Behalf Of Marc Zyngier
> > Sent: Thursday, April 16, 2015 5:21 PM
> > To: Lian Minghuan-B31939
> > Cc: Jason Cooper; Arnd Bergmann; linux-pci@vger.kernel.org; Will
> > Deacon; Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; Hu
> > Mingkai-B21284; Zang Roy-R61911; Thomas Gleixner;
> > linux-arm-kernel@lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Minghuan,
> >
> > On 16/04/15 11:57, Minghuan.Lian@freescale.com wrote:
> >
> > Please include the relevant people (Will Deacon for questions about
> > the SMMU), and avoid top posting, it makes it very hard to follow a
> discussion.
> >
> > > I still have a couple of questions,
> > > 1. If I add a new flag and all PCI DEVID will be replaced with a
> > > fixed ID,  does SMMU can work correctly? For example, If we insert
> > > an Ethernet card with two ports, a port is assigned to kvm1, another
> > > port is assigned to kvm2. In this case, we should use one or two fixed ID?
> >
> > That completely depends on what the SMMU sees. If it sees the same ID,
> > you won't be able to perform any form of isolation. But I have no idea
> > how your hardware works, so maybe explaining in details how this is
> > constructed will help.
> >
> 
> We would need separate stream IDs and iommu groups for endpoints, to
> assign them to different VMs. We would have to set up the stream ID to
> device ID translation table during device probe, via add_device callback.
> While setting the device id for the interrupt translation table, you would have
> to get streamID corresponding to a given PCIe device ID. Again, I don't think
> that we should consider the TBUID, while setting the ITT device id.
> 
> -Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-17  2:34                 ` Minghuan.Lian at freescale.com
  0 siblings, 0 replies; 74+ messages in thread
From: Minghuan.Lian at freescale.com @ 2015-04-17  2:34 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc and Varun,

Thank you very much for your valuable comments.
I will study further and try to find a better way to support ls2085 msi.

Thanks,
Minghuan

> -----Original Message-----
> From: Sethi Varun-B16395
> Sent: Friday, April 17, 2015 2:38 AM
> To: Marc Zyngier; Lian Minghuan-B31939
> Cc: Jason Cooper; Arnd Bergmann; linux-pci at vger.kernel.org; Will Deacon;T
> Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; Hu Mingkai-B21284;
> Zang Roy-R61911; Thomas Gleixner; linux-arm-kernel at lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Minghuan,
> 
> > -----Original Message-----
> > From: linux-arm-kernel [mailto:linux-arm-kernel-
> > bounces at lists.infradead.org] On Behalf Of Marc Zyngier
> > Sent: Thursday, April 16, 2015 5:21 PM
> > To: Lian Minghuan-B31939
> > Cc: Jason Cooper; Arnd Bergmann; linux-pci at vger.kernel.org; Will
> > Deacon; Yoder Stuart-B08248; Wood Scott-B07421; Bjorn Helgaas; Hu
> > Mingkai-B21284; Zang Roy-R61911; Thomas Gleixner;
> > linux-arm-kernel at lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Minghuan,
> >
> > On 16/04/15 11:57, Minghuan.Lian at freescale.com wrote:
> >
> > Please include the relevant people (Will Deacon for questions about
> > the SMMU), and avoid top posting, it makes it very hard to follow a
> discussion.
> >
> > > I still have a couple of questions,
> > > 1. If I add a new flag and all PCI DEVID will be replaced with a
> > > fixed ID,  does SMMU can work correctly? For example, If we insert
> > > an Ethernet card with two ports, a port is assigned to kvm1, another
> > > port is assigned to kvm2. In this case, we should use one or two fixed ID?
> >
> > That completely depends on what the SMMU sees. If it sees the same ID,
> > you won't be able to perform any form of isolation. But I have no idea
> > how your hardware works, so maybe explaining in details how this is
> > constructed will help.
> >
> 
> We would need separate stream IDs and iommu groups for endpoints, to
> assign them to different VMs. We would have to set up the stream ID to
> device ID translation table during device probe, via add_device callback.
> While setting the device id for the interrupt translation table, you would have
> to get streamID corresponding to a given PCIe device ID. Again, I don't think
> that we should consider the TBUID, while setting the ITT device id.
> 
> -Varun

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-16 10:40           ` Will Deacon
@ 2015-04-17 14:19             ` Stuart Yoder
  -1 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-17 14:19 UTC (permalink / raw)
  To: Will Deacon, Varun Sethi
  Cc: Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon@arm.com]
> Sent: Thursday, April 16, 2015 5:40 AM
> To: Sethi Varun-B16395
> Cc: Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder
> Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Varun,
> 
> Thanks for adding me to Cc.
> 
> On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> > would also be forwarded as a part of stream id to GIC. My understanding is
> > that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> > of a TBU translation miss. In case of the LS2085 PCIe controller you would
> > have to setup the PCIe device ID to stream ID translation table. We may
> > have to restrict the number of entries based on the available number of
> > contexts.
> 
> Unfortunately, I'm having a really hard time parsing this thread (some parts
> of it simply don't make sense; others use non-architectural terms and
> overall I don't get a feeling for the problem).
> 
> Please could you explain your system design step by step so that I can
> understand (a) what you've built and (b) why the current design of Linux is
> causing you problems?
> 
> Sorry if I'm just being thick, but it's important that we get this right.

I'll try to summarize some key points about the system...

System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and
fsl-mc bus generate message interrupts.

The flow a message interrupt would take is this:

    --------------
      PCI device
    --------------
          |
          | pcidevid + MSI msg
          |
          V
    --------------
    PCI controller
      pcidevid ->
      streamID
      mapping
    --------------
          |
          | streamID + MSI msg
          |
          V
    --------------
        SMMU
    --------------
          |
          | streamID + MSI msg
          |
          V
    --------------
       CCN-504 (Dickens)
    --------------
          |
          | streamID + MSI msg
          |
          V
    --------------
      GICv3 ITS    streamID == ITS deviceID
    --------------

So, the way things work (at least initially) is that each PCI device maps
to a single streamID, and thus each device has a separate ITT in 
the ITS.  So, things should be cool.

However, there is an improvement we envision as possible due to 
the limited number of SMMU contexts (i.e. 64).  If there are
64 SMMU context registers it means that there is a max of
64 software contexts where things can be isolated.  But, say I have
an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
to a KVM VM.  Those 8 PCI devices could share the same
streamID/ITS-device-ID since they all share the same isolation
context.

What would be nice is at the time the 8 VFS are being added
to the IOMMU domain is for the pcidevid -> streamID mapping
table to be updated dynamically.  It simply lets us make
more efficient use of the limited streamIDs we have.

I think it is this improvement that Minghuan had in mind
in this patch.

Thanks,
Stuart

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-17 14:19             ` Stuart Yoder
  0 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-17 14:19 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon at arm.com]
> Sent: Thursday, April 16, 2015 5:40 AM
> To: Sethi Varun-B16395
> Cc: Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Yoder
> Stuart-B08248; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Varun,
> 
> Thanks for adding me to Cc.
> 
> On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> > would also be forwarded as a part of stream id to GIC. My understanding is
> > that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> > of a TBU translation miss. In case of the LS2085 PCIe controller you would
> > have to setup the PCIe device ID to stream ID translation table. We may
> > have to restrict the number of entries based on the available number of
> > contexts.
> 
> Unfortunately, I'm having a really hard time parsing this thread (some parts
> of it simply don't make sense; others use non-architectural terms and
> overall I don't get a feeling for the problem).
> 
> Please could you explain your system design step by step so that I can
> understand (a) what you've built and (b) why the current design of Linux is
> causing you problems?
> 
> Sorry if I'm just being thick, but it's important that we get this right.

I'll try to summarize some key points about the system...

System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and
fsl-mc bus generate message interrupts.

The flow a message interrupt would take is this:

    --------------
      PCI device
    --------------
          |
          | pcidevid + MSI msg
          |
          V
    --------------
    PCI controller
      pcidevid ->
      streamID
      mapping
    --------------
          |
          | streamID + MSI msg
          |
          V
    --------------
        SMMU
    --------------
          |
          | streamID + MSI msg
          |
          V
    --------------
       CCN-504 (Dickens)
    --------------
          |
          | streamID + MSI msg
          |
          V
    --------------
      GICv3 ITS    streamID == ITS deviceID
    --------------

So, the way things work (at least initially) is that each PCI device maps
to a single streamID, and thus each device has a separate ITT in 
the ITS.  So, things should be cool.

However, there is an improvement we envision as possible due to 
the limited number of SMMU contexts (i.e. 64).  If there are
64 SMMU context registers it means that there is a max of
64 software contexts where things can be isolated.  But, say I have
an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
to a KVM VM.  Those 8 PCI devices could share the same
streamID/ITS-device-ID since they all share the same isolation
context.

What would be nice is at the time the 8 VFS are being added
to the IOMMU domain is for the pcidevid -> streamID mapping
table to be updated dynamically.  It simply lets us make
more efficient use of the limited streamIDs we have.

I think it is this improvement that Minghuan had in mind
in this patch.

Thanks,
Stuart

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-17 14:19             ` Stuart Yoder
@ 2015-04-17 17:57               ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-17 17:57 UTC (permalink / raw)
  To: Stuart Yoder, Will Deacon
  Cc: Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Stuart/Will,

> -----Original Message-----
> From: Yoder Stuart-B08248
> Sent: Friday, April 17, 2015 7:49 PM
> To: Will Deacon; Sethi Varun-B16395
> Cc: Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu
> Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-
> arm-kernel@lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> 
> 
> > -----Original Message-----
> > From: Will Deacon [mailto:will.deacon@arm.com]
> > Sent: Thursday, April 16, 2015 5:40 AM
> > To: Sethi Varun-B16395
> > Cc: Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu
> > Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-B08248; Bjorn Helgaas;
> > Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Hi Varun,
> >
> > Thanks for adding me to Cc.
> >
> > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if
> > > TBU ID would also be forwarded as a part of stream id to GIC. My
> > > understanding is that TBU ID is forwarded (as a part of the stream
> > > ID) to the TCU in case of a TBU translation miss. In case of the
> > > LS2085 PCIe controller you would have to setup the PCIe device ID to
> > > stream ID translation table. We may have to restrict the number of
> > > entries based on the available number of contexts.
> >
> > Unfortunately, I'm having a really hard time parsing this thread (some
> > parts of it simply don't make sense; others use non-architectural
> > terms and overall I don't get a feeling for the problem).
> >
> > Please could you explain your system design step by step so that I can
> > understand (a) what you've built and (b) why the current design of
> > Linux is causing you problems?
> >
> > Sorry if I'm just being thick, but it's important that we get this right.
> 
> I'll try to summarize some key points about the system...
> 
> System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
> PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and fsl-mc
> bus generate message interrupts.
> 
> The flow a message interrupt would take is this:
> 
>     --------------
>       PCI device
>     --------------
>           |
>           | pcidevid + MSI msg
>           |
>           V
>     --------------
>     PCI controller
>       pcidevid ->
>       streamID
>       mapping
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>         SMMU
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>        CCN-504 (Dickens)
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>       GICv3 ITS    streamID == ITS deviceID
>     --------------
> 
> So, the way things work (at least initially) is that each PCI device maps to a
> single streamID, and thus each device has a separate ITT in the ITS.  So, things
> should be cool.
> 
> However, there is an improvement we envision as possible due to the
> limited number of SMMU contexts (i.e. 64).  If there are
> 64 SMMU context registers it means that there is a max of
> 64 software contexts where things can be isolated.  But, say I have an SRIOV
> card with 64 VFs, and I want to assign 8 of the VFs to a KVM VM.  Those 8 PCI
> devices could share the same streamID/ITS-device-ID since they all share the
> same isolation context.
> 
> What would be nice is at the time the 8 VFS are being added to the IOMMU
> domain is for the pcidevid -> streamID mapping table to be updated
> dynamically.  It simply lets us make more efficient use of the limited
> streamIDs we have.
> 
i.e. we set up a common stream id for PCIe devices while attaching them to a domain. This would require traversal of PCIe bus topology in order to determine the dma alias during attach_device.
In case of a transparent host bridge we would have to consider the device id corresponding to the bridge.

I think it would be better if we can statically restrict number of permissible stream Ids per PCIe controller. We can setup the stream ID to device ID mapping during device probe itself (add_device or of_xlate)

For the ITS setup, we would have to translate the device id to the associated stream Id. What would happen in case of the transparent host bridge, all the devices behind the bridge would share the same stream ID?

-Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-17 17:57               ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-17 17:57 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Stuart/Will,

> -----Original Message-----
> From: Yoder Stuart-B08248
> Sent: Friday, April 17, 2015 7:49 PM
> To: Will Deacon; Sethi Varun-B16395
> Cc: Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu
> Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-
> arm-kernel at lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> 
> 
> > -----Original Message-----
> > From: Will Deacon [mailto:will.deacon at arm.com]
> > Sent: Thursday, April 16, 2015 5:40 AM
> > To: Sethi Varun-B16395
> > Cc: Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu
> > Mingkai-B21284; Zang Roy-R61911; Yoder Stuart-B08248; Bjorn Helgaas;
> > Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Hi Varun,
> >
> > Thanks for adding me to Cc.
> >
> > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if
> > > TBU ID would also be forwarded as a part of stream id to GIC. My
> > > understanding is that TBU ID is forwarded (as a part of the stream
> > > ID) to the TCU in case of a TBU translation miss. In case of the
> > > LS2085 PCIe controller you would have to setup the PCIe device ID to
> > > stream ID translation table. We may have to restrict the number of
> > > entries based on the available number of contexts.
> >
> > Unfortunately, I'm having a really hard time parsing this thread (some
> > parts of it simply don't make sense; others use non-architectural
> > terms and overall I don't get a feeling for the problem).
> >
> > Please could you explain your system design step by step so that I can
> > understand (a) what you've built and (b) why the current design of
> > Linux is causing you problems?
> >
> > Sorry if I'm just being thick, but it's important that we get this right.
> 
> I'll try to summarize some key points about the system...
> 
> System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
> PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and fsl-mc
> bus generate message interrupts.
> 
> The flow a message interrupt would take is this:
> 
>     --------------
>       PCI device
>     --------------
>           |
>           | pcidevid + MSI msg
>           |
>           V
>     --------------
>     PCI controller
>       pcidevid ->
>       streamID
>       mapping
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>         SMMU
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>        CCN-504 (Dickens)
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>       GICv3 ITS    streamID == ITS deviceID
>     --------------
> 
> So, the way things work (at least initially) is that each PCI device maps to a
> single streamID, and thus each device has a separate ITT in the ITS.  So, things
> should be cool.
> 
> However, there is an improvement we envision as possible due to the
> limited number of SMMU contexts (i.e. 64).  If there are
> 64 SMMU context registers it means that there is a max of
> 64 software contexts where things can be isolated.  But, say I have an SRIOV
> card with 64 VFs, and I want to assign 8 of the VFs to a KVM VM.  Those 8 PCI
> devices could share the same streamID/ITS-device-ID since they all share the
> same isolation context.
> 
> What would be nice is at the time the 8 VFS are being added to the IOMMU
> domain is for the pcidevid -> streamID mapping table to be updated
> dynamically.  It simply lets us make more efficient use of the limited
> streamIDs we have.
> 
i.e. we set up a common stream id for PCIe devices while attaching them to a domain. This would require traversal of PCIe bus topology in order to determine the dma alias during attach_device.
In case of a transparent host bridge we would have to consider the device id corresponding to the bridge.

I think it would be better if we can statically restrict number of permissible stream Ids per PCIe controller. We can setup the stream ID to device ID mapping during device probe itself (add_device or of_xlate)

For the ITS setup, we would have to translate the device id to the associated stream Id. What would happen in case of the transparent host bridge, all the devices behind the bridge would share the same stream ID?

-Varun

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-17 14:19             ` Stuart Yoder
@ 2015-04-22 17:07               ` Will Deacon
  -1 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-22 17:07 UTC (permalink / raw)
  To: Stuart Yoder
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Stuart,

First of, thanks for taking the time to explain this in more detail.
Comments inline.

On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> > > would also be forwarded as a part of stream id to GIC. My understanding is
> > > that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> > > of a TBU translation miss. In case of the LS2085 PCIe controller you would
> > > have to setup the PCIe device ID to stream ID translation table. We may
> > > have to restrict the number of entries based on the available number of
> > > contexts.
> > 
> > Unfortunately, I'm having a really hard time parsing this thread (some parts
> > of it simply don't make sense; others use non-architectural terms and
> > overall I don't get a feeling for the problem).
> > 
> > Please could you explain your system design step by step so that I can
> > understand (a) what you've built and (b) why the current design of Linux is
> > causing you problems?
> > 
> > Sorry if I'm just being thick, but it's important that we get this right.
> 
> I'll try to summarize some key points about the system...
> 
> System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
> PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and
> fsl-mc bus generate message interrupts.

Ah cool, so you have multiple buses sharing a single SMMU? That's going to
necessitate some ID remapping in the device-tree. Perhaps you could comment
on Mark Rutland's proposal if it does/doesn't work for you:

  http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/333199.html


> The flow a message interrupt would take is this:
> 
>     --------------
>       PCI device
>     --------------
>           |
>           | pcidevid + MSI msg
>           |
>           V
>     --------------
>     PCI controller
>       pcidevid ->
>       streamID
>       mapping
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>         SMMU
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>        CCN-504 (Dickens)
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V

The streamID here as the same as the one coming out of the SMMU, right?
(just trying to out why you have the CCN-504 in the picture).

>     --------------
>       GICv3 ITS    streamID == ITS deviceID
>     --------------
> 
> So, the way things work (at least initially) is that each PCI device maps
> to a single streamID, and thus each device has a separate ITT in 
> the ITS.  So, things should be cool.
> 
> However, there is an improvement we envision as possible due to 
> the limited number of SMMU contexts (i.e. 64).  If there are
> 64 SMMU context registers it means that there is a max of
> 64 software contexts where things can be isolated.  But, say I have
> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> to a KVM VM.  Those 8 PCI devices could share the same
> streamID/ITS-device-ID since they all share the same isolation
> context.
> 
> What would be nice is at the time the 8 VFS are being added
> to the IOMMU domain is for the pcidevid -> streamID mapping
> table to be updated dynamically.  It simply lets us make
> more efficient use of the limited streamIDs we have.
> 
> I think it is this improvement that Minghuan had in mind
> in this patch.

Ok, but in this case it should be possible to use a single context bank for
all of the VF streamIDs by configuring the appropriate SMR, no? Wouldn't
that sort of thing be preferable to dynamic StreamID assignment? It would
certainly make life easier for the MSIs.

Will

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-22 17:07               ` Will Deacon
  0 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-22 17:07 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Stuart,

First of, thanks for taking the time to explain this in more detail.
Comments inline.

On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> > > would also be forwarded as a part of stream id to GIC. My understanding is
> > > that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> > > of a TBU translation miss. In case of the LS2085 PCIe controller you would
> > > have to setup the PCIe device ID to stream ID translation table. We may
> > > have to restrict the number of entries based on the available number of
> > > contexts.
> > 
> > Unfortunately, I'm having a really hard time parsing this thread (some parts
> > of it simply don't make sense; others use non-architectural terms and
> > overall I don't get a feeling for the problem).
> > 
> > Please could you explain your system design step by step so that I can
> > understand (a) what you've built and (b) why the current design of Linux is
> > causing you problems?
> > 
> > Sorry if I'm just being thick, but it's important that we get this right.
> 
> I'll try to summarize some key points about the system...
> 
> System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
> PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and
> fsl-mc bus generate message interrupts.

Ah cool, so you have multiple buses sharing a single SMMU? That's going to
necessitate some ID remapping in the device-tree. Perhaps you could comment
on Mark Rutland's proposal if it does/doesn't work for you:

  http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/333199.html


> The flow a message interrupt would take is this:
> 
>     --------------
>       PCI device
>     --------------
>           |
>           | pcidevid + MSI msg
>           |
>           V
>     --------------
>     PCI controller
>       pcidevid ->
>       streamID
>       mapping
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>         SMMU
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V
>     --------------
>        CCN-504 (Dickens)
>     --------------
>           |
>           | streamID + MSI msg
>           |
>           V

The streamID here as the same as the one coming out of the SMMU, right?
(just trying to out why you have the CCN-504 in the picture).

>     --------------
>       GICv3 ITS    streamID == ITS deviceID
>     --------------
> 
> So, the way things work (at least initially) is that each PCI device maps
> to a single streamID, and thus each device has a separate ITT in 
> the ITS.  So, things should be cool.
> 
> However, there is an improvement we envision as possible due to 
> the limited number of SMMU contexts (i.e. 64).  If there are
> 64 SMMU context registers it means that there is a max of
> 64 software contexts where things can be isolated.  But, say I have
> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> to a KVM VM.  Those 8 PCI devices could share the same
> streamID/ITS-device-ID since they all share the same isolation
> context.
> 
> What would be nice is at the time the 8 VFS are being added
> to the IOMMU domain is for the pcidevid -> streamID mapping
> table to be updated dynamically.  It simply lets us make
> more efficient use of the limited streamIDs we have.
> 
> I think it is this improvement that Minghuan had in mind
> in this patch.

Ok, but in this case it should be possible to use a single context bank for
all of the VF streamIDs by configuring the appropriate SMR, no? Wouldn't
that sort of thing be preferable to dynamic StreamID assignment? It would
certainly make life easier for the MSIs.

Will

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-22 17:07               ` Will Deacon
@ 2015-04-22 18:40                 ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-22 18:40 UTC (permalink / raw)
  To: Will Deacon, Stuart Yoder
  Cc: Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Will,

> -----Original Message-----
> From: Will Deacon [mailto:will.deacon@arm.com]
> Sent: Wednesday, April 22, 2015 10:37 PM
> To: Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org;
> Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood
> Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Stuart,
> 
> First of, thanks for taking the time to explain this in more detail.
> Comments inline.
> 
> On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if
> > > > TBU ID would also be forwarded as a part of stream id to GIC. My
> > > > understanding is that TBU ID is forwarded (as a part of the stream
> > > > ID) to the TCU in case of a TBU translation miss. In case of the
> > > > LS2085 PCIe controller you would have to setup the PCIe device ID
> > > > to stream ID translation table. We may have to restrict the number
> > > > of entries based on the available number of contexts.
> > >
> > > Unfortunately, I'm having a really hard time parsing this thread
> > > (some parts of it simply don't make sense; others use
> > > non-architectural terms and overall I don't get a feeling for the problem).
> > >
> > > Please could you explain your system design step by step so that I
> > > can understand (a) what you've built and (b) why the current design
> > > of Linux is causing you problems?
> > >
> > > Sorry if I'm just being thick, but it's important that we get this right.
> >
> > I'll try to summarize some key points about the system...
> >
> > System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.
> > There are PCI, fsl-mc, and platform devices that do DMA.  Devices on
> > the PCI and fsl-mc bus generate message interrupts.
> 
> Ah cool, so you have multiple buses sharing a single SMMU? That's going to
> necessitate some ID remapping in the device-tree. Perhaps you could
> comment on Mark Rutland's proposal if it does/doesn't work for you:
> 
>   http://lists.infradead.org/pipermail/linux-arm-kernel/2015-
> March/333199.html
> 
> 
> > The flow a message interrupt would take is this:
> >
> >     --------------
> >       PCI device
> >     --------------
> >           |
> >           | pcidevid + MSI msg
> >           |
> >           V
> >     --------------
> >     PCI controller
> >       pcidevid ->
> >       streamID
> >       mapping
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >         SMMU
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >        CCN-504 (Dickens)
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> 
> The streamID here as the same as the one coming out of the SMMU, right?
> (just trying to out why you have the CCN-504 in the picture).
> 
> >     --------------
> >       GICv3 ITS    streamID == ITS deviceID
> >     --------------
> >
> > So, the way things work (at least initially) is that each PCI device
> > maps to a single streamID, and thus each device has a separate ITT in
> > the ITS.  So, things should be cool.
> >
> > However, there is an improvement we envision as possible due to the
> > limited number of SMMU contexts (i.e. 64).  If there are
> > 64 SMMU context registers it means that there is a max of
> > 64 software contexts where things can be isolated.  But, say I have an
> > SRIOV card with 64 VFs, and I want to assign 8 of the VFs to a KVM VM.
> > Those 8 PCI devices could share the same streamID/ITS-device-ID since
> > they all share the same isolation context.
> >
> > What would be nice is at the time the 8 VFS are being added to the
> > IOMMU domain is for the pcidevid -> streamID mapping table to be
> > updated dynamically.  It simply lets us make more efficient use of the
> > limited streamIDs we have.
> >
> > I think it is this improvement that Minghuan had in mind in this
> > patch.
> 
> Ok, but in this case it should be possible to use a single context bank for all of
> the VF streamIDs by configuring the appropriate SMR, no? Wouldn't that sort
> of thing be preferable to dynamic StreamID assignment? It would certainly
> make life easier for the MSIs.
> 
Yes, that would happen when the all the VFs are attached to the same domain. But it would be an issue if we have to attach devices to different domains.

-Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-22 18:40                 ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-22 18:40 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Will,

> -----Original Message-----
> From: Will Deacon [mailto:will.deacon at arm.com]
> Sent: Wednesday, April 22, 2015 10:37 PM
> To: Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org;
> Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood
> Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Stuart,
> 
> First of, thanks for taking the time to explain this in more detail.
> Comments inline.
> 
> On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if
> > > > TBU ID would also be forwarded as a part of stream id to GIC. My
> > > > understanding is that TBU ID is forwarded (as a part of the stream
> > > > ID) to the TCU in case of a TBU translation miss. In case of the
> > > > LS2085 PCIe controller you would have to setup the PCIe device ID
> > > > to stream ID translation table. We may have to restrict the number
> > > > of entries based on the available number of contexts.
> > >
> > > Unfortunately, I'm having a really hard time parsing this thread
> > > (some parts of it simply don't make sense; others use
> > > non-architectural terms and overall I don't get a feeling for the problem).
> > >
> > > Please could you explain your system design step by step so that I
> > > can understand (a) what you've built and (b) why the current design
> > > of Linux is causing you problems?
> > >
> > > Sorry if I'm just being thick, but it's important that we get this right.
> >
> > I'll try to summarize some key points about the system...
> >
> > System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.
> > There are PCI, fsl-mc, and platform devices that do DMA.  Devices on
> > the PCI and fsl-mc bus generate message interrupts.
> 
> Ah cool, so you have multiple buses sharing a single SMMU? That's going to
> necessitate some ID remapping in the device-tree. Perhaps you could
> comment on Mark Rutland's proposal if it does/doesn't work for you:
> 
>   http://lists.infradead.org/pipermail/linux-arm-kernel/2015-
> March/333199.html
> 
> 
> > The flow a message interrupt would take is this:
> >
> >     --------------
> >       PCI device
> >     --------------
> >           |
> >           | pcidevid + MSI msg
> >           |
> >           V
> >     --------------
> >     PCI controller
> >       pcidevid ->
> >       streamID
> >       mapping
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >         SMMU
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >        CCN-504 (Dickens)
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> 
> The streamID here as the same as the one coming out of the SMMU, right?
> (just trying to out why you have the CCN-504 in the picture).
> 
> >     --------------
> >       GICv3 ITS    streamID == ITS deviceID
> >     --------------
> >
> > So, the way things work (at least initially) is that each PCI device
> > maps to a single streamID, and thus each device has a separate ITT in
> > the ITS.  So, things should be cool.
> >
> > However, there is an improvement we envision as possible due to the
> > limited number of SMMU contexts (i.e. 64).  If there are
> > 64 SMMU context registers it means that there is a max of
> > 64 software contexts where things can be isolated.  But, say I have an
> > SRIOV card with 64 VFs, and I want to assign 8 of the VFs to a KVM VM.
> > Those 8 PCI devices could share the same streamID/ITS-device-ID since
> > they all share the same isolation context.
> >
> > What would be nice is at the time the 8 VFS are being added to the
> > IOMMU domain is for the pcidevid -> streamID mapping table to be
> > updated dynamically.  It simply lets us make more efficient use of the
> > limited streamIDs we have.
> >
> > I think it is this improvement that Minghuan had in mind in this
> > patch.
> 
> Ok, but in this case it should be possible to use a single context bank for all of
> the VF streamIDs by configuring the appropriate SMR, no? Wouldn't that sort
> of thing be preferable to dynamic StreamID assignment? It would certainly
> make life easier for the MSIs.
> 
Yes, that would happen when the all the VFs are attached to the same domain. But it would be an issue if we have to attach devices to different domains.

-Varun

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-22 17:07               ` Will Deacon
@ 2015-04-22 19:41                 ` Stuart Yoder
  -1 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-22 19:41 UTC (permalink / raw)
  To: Will Deacon
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon@arm.com]
> Sent: Wednesday, April 22, 2015 12:07 PM
> To: Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Stuart,
> 
> First of, thanks for taking the time to explain this in more detail.
> Comments inline.
> 
> On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> > > > would also be forwarded as a part of stream id to GIC. My understanding is
> > > > that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> > > > of a TBU translation miss. In case of the LS2085 PCIe controller you would
> > > > have to setup the PCIe device ID to stream ID translation table. We may
> > > > have to restrict the number of entries based on the available number of
> > > > contexts.
> > >
> > > Unfortunately, I'm having a really hard time parsing this thread (some parts
> > > of it simply don't make sense; others use non-architectural terms and
> > > overall I don't get a feeling for the problem).
> > >
> > > Please could you explain your system design step by step so that I can
> > > understand (a) what you've built and (b) why the current design of Linux is
> > > causing you problems?
> > >
> > > Sorry if I'm just being thick, but it's important that we get this right.
> >
> > I'll try to summarize some key points about the system...
> >
> > System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
> > PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and
> > fsl-mc bus generate message interrupts.
> 
> Ah cool, so you have multiple buses sharing a single SMMU? That's going to
> necessitate some ID remapping in the device-tree. Perhaps you could comment
> on Mark Rutland's proposal if it does/doesn't work for you:
> 
>   http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/333199.html

Thanks for the pointer, I had not seen that before.  Will read and
comment on it.

> > The flow a message interrupt would take is this:
> >
> >     --------------
> >       PCI device
> >     --------------
> >           |
> >           | pcidevid + MSI msg
> >           |
> >           V
> >     --------------
> >     PCI controller
> >       pcidevid ->
> >       streamID
> >       mapping
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >         SMMU
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >        CCN-504 (Dickens)
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> 
> The streamID here as the same as the one coming out of the SMMU, right?

Yes.

> (just trying to out why you have the CCN-504 in the picture).

It really isn't relevant I guess, just the picture I had in my
head.

> >     --------------
> >       GICv3 ITS    streamID == ITS deviceID
> >     --------------
> >
> > So, the way things work (at least initially) is that each PCI device maps
> > to a single streamID, and thus each device has a separate ITT in
> > the ITS.  So, things should be cool.
> >
> > However, there is an improvement we envision as possible due to
> > the limited number of SMMU contexts (i.e. 64).  If there are
> > 64 SMMU context registers it means that there is a max of
> > 64 software contexts where things can be isolated.  But, say I have
> > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > to a KVM VM.  Those 8 PCI devices could share the same
> > streamID/ITS-device-ID since they all share the same isolation
> > context.
> >
> > What would be nice is at the time the 8 VFS are being added
> > to the IOMMU domain is for the pcidevid -> streamID mapping
> > table to be updated dynamically.  It simply lets us make
> > more efficient use of the limited streamIDs we have.
> >
> > I think it is this improvement that Minghuan had in mind
> > in this patch.
> 
> Ok, but in this case it should be possible to use a single context bank for
> all of the VF streamIDs by configuring the appropriate SMR, no?

Yes, but there are limited SMRs.  In our case there are only
128 SMRs in SMMU-500 and we have potentially way more masters than
that.

> Wouldn't
> that sort of thing be preferable to dynamic StreamID assignment? It would
> certainly make life easier for the MSIs.

It would be preferable, but given only 128 total stream IDS and
64 context registers it's potentially an issue.  On our LS2085 SoC it is
PCI and the fsl-mc bus (see description here:
https://lkml.org/lkml/2015/3/5/795) that potentially have way
more masters than streamIDS. So, for those busses we would essentially
view a streamID as a "context ID"-- each SMR is associated with
1 context bank register.

For PCI we have a programmable "PCI req ID"-to-"stream ID"
mapping table in the PCI controller that is dynamically
programmable.

Looking at it like that means that we could have
any number of masters but only 64 "contexts"
and since the masters all all programmable it's
seems feasbile to envision doing some bus/vendor
specific set up when a device is added to an
IOMMU domain.   One thing that would need to be conveyed
to the SMMU driver if doing dynamic streamID setup
is what streamIDs are available to be used.

Thanks,
Stuart



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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-22 19:41                 ` Stuart Yoder
  0 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-22 19:41 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon at arm.com]
> Sent: Wednesday, April 22, 2015 12:07 PM
> To: Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Stuart,
> 
> First of, thanks for taking the time to explain this in more detail.
> Comments inline.
> 
> On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure if TBU ID
> > > > would also be forwarded as a part of stream id to GIC. My understanding is
> > > > that TBU ID is forwarded (as a part of the stream ID) to the TCU in case
> > > > of a TBU translation miss. In case of the LS2085 PCIe controller you would
> > > > have to setup the PCIe device ID to stream ID translation table. We may
> > > > have to restrict the number of entries based on the available number of
> > > > contexts.
> > >
> > > Unfortunately, I'm having a really hard time parsing this thread (some parts
> > > of it simply don't make sense; others use non-architectural terms and
> > > overall I don't get a feeling for the problem).
> > >
> > > Please could you explain your system design step by step so that I can
> > > understand (a) what you've built and (b) why the current design of Linux is
> > > causing you problems?
> > >
> > > Sorry if I'm just being thick, but it's important that we get this right.
> >
> > I'll try to summarize some key points about the system...
> >
> > System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.  There are
> > PCI, fsl-mc, and platform devices that do DMA.  Devices on the PCI and
> > fsl-mc bus generate message interrupts.
> 
> Ah cool, so you have multiple buses sharing a single SMMU? That's going to
> necessitate some ID remapping in the device-tree. Perhaps you could comment
> on Mark Rutland's proposal if it does/doesn't work for you:
> 
>   http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/333199.html

Thanks for the pointer, I had not seen that before.  Will read and
comment on it.

> > The flow a message interrupt would take is this:
> >
> >     --------------
> >       PCI device
> >     --------------
> >           |
> >           | pcidevid + MSI msg
> >           |
> >           V
> >     --------------
> >     PCI controller
> >       pcidevid ->
> >       streamID
> >       mapping
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >         SMMU
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> >     --------------
> >        CCN-504 (Dickens)
> >     --------------
> >           |
> >           | streamID + MSI msg
> >           |
> >           V
> 
> The streamID here as the same as the one coming out of the SMMU, right?

Yes.

> (just trying to out why you have the CCN-504 in the picture).

It really isn't relevant I guess, just the picture I had in my
head.

> >     --------------
> >       GICv3 ITS    streamID == ITS deviceID
> >     --------------
> >
> > So, the way things work (at least initially) is that each PCI device maps
> > to a single streamID, and thus each device has a separate ITT in
> > the ITS.  So, things should be cool.
> >
> > However, there is an improvement we envision as possible due to
> > the limited number of SMMU contexts (i.e. 64).  If there are
> > 64 SMMU context registers it means that there is a max of
> > 64 software contexts where things can be isolated.  But, say I have
> > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > to a KVM VM.  Those 8 PCI devices could share the same
> > streamID/ITS-device-ID since they all share the same isolation
> > context.
> >
> > What would be nice is at the time the 8 VFS are being added
> > to the IOMMU domain is for the pcidevid -> streamID mapping
> > table to be updated dynamically.  It simply lets us make
> > more efficient use of the limited streamIDs we have.
> >
> > I think it is this improvement that Minghuan had in mind
> > in this patch.
> 
> Ok, but in this case it should be possible to use a single context bank for
> all of the VF streamIDs by configuring the appropriate SMR, no?

Yes, but there are limited SMRs.  In our case there are only
128 SMRs in SMMU-500 and we have potentially way more masters than
that.

> Wouldn't
> that sort of thing be preferable to dynamic StreamID assignment? It would
> certainly make life easier for the MSIs.

It would be preferable, but given only 128 total stream IDS and
64 context registers it's potentially an issue.  On our LS2085 SoC it is
PCI and the fsl-mc bus (see description here:
https://lkml.org/lkml/2015/3/5/795) that potentially have way
more masters than streamIDS. So, for those busses we would essentially
view a streamID as a "context ID"-- each SMR is associated with
1 context bank register.

For PCI we have a programmable "PCI req ID"-to-"stream ID"
mapping table in the PCI controller that is dynamically
programmable.

Looking at it like that means that we could have
any number of masters but only 64 "contexts"
and since the masters all all programmable it's
seems feasbile to envision doing some bus/vendor
specific set up when a device is added to an
IOMMU domain.   One thing that would need to be conveyed
to the SMMU driver if doing dynamic streamID setup
is what streamIDs are available to be used.

Thanks,
Stuart

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-22 19:41                 ` Stuart Yoder
@ 2015-04-24 16:18                   ` Will Deacon
  -1 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-24 16:18 UTC (permalink / raw)
  To: Stuart Yoder
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel,
	marc.zyngier

On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > > However, there is an improvement we envision as possible due to
> > > the limited number of SMMU contexts (i.e. 64).  If there are
> > > 64 SMMU context registers it means that there is a max of
> > > 64 software contexts where things can be isolated.  But, say I have
> > > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > > to a KVM VM.  Those 8 PCI devices could share the same
> > > streamID/ITS-device-ID since they all share the same isolation
> > > context.
> > >
> > > What would be nice is at the time the 8 VFS are being added
> > > to the IOMMU domain is for the pcidevid -> streamID mapping
> > > table to be updated dynamically.  It simply lets us make
> > > more efficient use of the limited streamIDs we have.
> > >
> > > I think it is this improvement that Minghuan had in mind
> > > in this patch.
> > 
> > Ok, but in this case it should be possible to use a single context bank for
> > all of the VF streamIDs by configuring the appropriate SMR, no?
> 
> Yes, but there are limited SMRs.  In our case there are only
> 128 SMRs in SMMU-500 and we have potentially way more masters than
> that.

Right, but you still only have 64 context banks at the end of the day, so do
you really anticipate having more than 128 masters concurrently using the
SMMU? If so, then we have devices sharing context banks so we could consider
reusing SMRs across masters, but historically that's not been something that
we've managed to solve.

> > Wouldn't
> > that sort of thing be preferable to dynamic StreamID assignment? It would
> > certainly make life easier for the MSIs.
> 
> It would be preferable, but given only 128 total stream IDS and
> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> PCI and the fsl-mc bus (see description here:
> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> more masters than streamIDS. So, for those busses we would essentially
> view a streamID as a "context ID"-- each SMR is associated with
> 1 context bank register.
> 
> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> mapping table in the PCI controller that is dynamically
> programmable.
> 
> Looking at it like that means that we could have
> any number of masters but only 64 "contexts"
> and since the masters all all programmable it's
> seems feasbile to envision doing some bus/vendor
> specific set up when a device is added to an
> IOMMU domain.   One thing that would need to be conveyed
> to the SMMU driver if doing dynamic streamID setup
> is what streamIDs are available to be used.

Ok, but this is going to make life difficult for the MSI people, I suspect.

Marc...?

Will

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-24 16:18                   ` Will Deacon
  0 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-24 16:18 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > > However, there is an improvement we envision as possible due to
> > > the limited number of SMMU contexts (i.e. 64).  If there are
> > > 64 SMMU context registers it means that there is a max of
> > > 64 software contexts where things can be isolated.  But, say I have
> > > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > > to a KVM VM.  Those 8 PCI devices could share the same
> > > streamID/ITS-device-ID since they all share the same isolation
> > > context.
> > >
> > > What would be nice is at the time the 8 VFS are being added
> > > to the IOMMU domain is for the pcidevid -> streamID mapping
> > > table to be updated dynamically.  It simply lets us make
> > > more efficient use of the limited streamIDs we have.
> > >
> > > I think it is this improvement that Minghuan had in mind
> > > in this patch.
> > 
> > Ok, but in this case it should be possible to use a single context bank for
> > all of the VF streamIDs by configuring the appropriate SMR, no?
> 
> Yes, but there are limited SMRs.  In our case there are only
> 128 SMRs in SMMU-500 and we have potentially way more masters than
> that.

Right, but you still only have 64 context banks at the end of the day, so do
you really anticipate having more than 128 masters concurrently using the
SMMU? If so, then we have devices sharing context banks so we could consider
reusing SMRs across masters, but historically that's not been something that
we've managed to solve.

> > Wouldn't
> > that sort of thing be preferable to dynamic StreamID assignment? It would
> > certainly make life easier for the MSIs.
> 
> It would be preferable, but given only 128 total stream IDS and
> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> PCI and the fsl-mc bus (see description here:
> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> more masters than streamIDS. So, for those busses we would essentially
> view a streamID as a "context ID"-- each SMR is associated with
> 1 context bank register.
> 
> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> mapping table in the PCI controller that is dynamically
> programmable.
> 
> Looking at it like that means that we could have
> any number of masters but only 64 "contexts"
> and since the masters all all programmable it's
> seems feasbile to envision doing some bus/vendor
> specific set up when a device is added to an
> IOMMU domain.   One thing that would need to be conveyed
> to the SMMU driver if doing dynamic streamID setup
> is what streamIDs are available to be used.

Ok, but this is going to make life difficult for the MSI people, I suspect.

Marc...?

Will

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-24 16:18                   ` Will Deacon
@ 2015-04-24 16:44                     ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-24 16:44 UTC (permalink / raw)
  To: Will Deacon, Stuart Yoder
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel

On 24/04/15 17:18, Will Deacon wrote:
> On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
>>>> However, there is an improvement we envision as possible due to
>>>> the limited number of SMMU contexts (i.e. 64).  If there are
>>>> 64 SMMU context registers it means that there is a max of
>>>> 64 software contexts where things can be isolated.  But, say I have
>>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
>>>> to a KVM VM.  Those 8 PCI devices could share the same
>>>> streamID/ITS-device-ID since they all share the same isolation
>>>> context.
>>>>
>>>> What would be nice is at the time the 8 VFS are being added
>>>> to the IOMMU domain is for the pcidevid -> streamID mapping
>>>> table to be updated dynamically.  It simply lets us make
>>>> more efficient use of the limited streamIDs we have.
>>>>
>>>> I think it is this improvement that Minghuan had in mind
>>>> in this patch.
>>>
>>> Ok, but in this case it should be possible to use a single context bank for
>>> all of the VF streamIDs by configuring the appropriate SMR, no?
>>
>> Yes, but there are limited SMRs.  In our case there are only
>> 128 SMRs in SMMU-500 and we have potentially way more masters than
>> that.
> 
> Right, but you still only have 64 context banks at the end of the day, so do
> you really anticipate having more than 128 masters concurrently using the
> SMMU? If so, then we have devices sharing context banks so we could consider
> reusing SMRs across masters, but historically that's not been something that
> we've managed to solve.
> 
>>> Wouldn't
>>> that sort of thing be preferable to dynamic StreamID assignment? It would
>>> certainly make life easier for the MSIs.
>>
>> It would be preferable, but given only 128 total stream IDS and
>> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
>> PCI and the fsl-mc bus (see description here:
>> https://lkml.org/lkml/2015/3/5/795) that potentially have way
>> more masters than streamIDS. So, for those busses we would essentially
>> view a streamID as a "context ID"-- each SMR is associated with
>> 1 context bank register.
>>
>> For PCI we have a programmable "PCI req ID"-to-"stream ID"
>> mapping table in the PCI controller that is dynamically
>> programmable.
>>
>> Looking at it like that means that we could have
>> any number of masters but only 64 "contexts"
>> and since the masters all all programmable it's
>> seems feasbile to envision doing some bus/vendor
>> specific set up when a device is added to an
>> IOMMU domain.   One thing that would need to be conveyed
>> to the SMMU driver if doing dynamic streamID setup
>> is what streamIDs are available to be used.
> 
> Ok, but this is going to make life difficult for the MSI people, I suspect.
> 
> Marc...?

We're really facing two conflicting requirements: in order to minimize
SMR usage, we want to alias multiple ReqIDs to a single StreamID, but in
order to efficiently deal with MSIs, we want to see discrete DeviceIDs
(the actual ReqIDs). I don't easily see how we reconcile the two.

We can deal with the aliasing, provided that we extend the level of
quirkiness that pci_for_each_dma_alias can deal with. But that doesn't
solve any form of hotplug/SR-IOV behaviour.

Somehow, we're going to end-up with grossly oversized ITTs, just to
accommodate for the fact that we have no idea how many MSIs we're going
to end-up needing. I'm not thrilled with that prospect.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-24 16:44                     ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-24 16:44 UTC (permalink / raw)
  To: linux-arm-kernel

On 24/04/15 17:18, Will Deacon wrote:
> On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
>>>> However, there is an improvement we envision as possible due to
>>>> the limited number of SMMU contexts (i.e. 64).  If there are
>>>> 64 SMMU context registers it means that there is a max of
>>>> 64 software contexts where things can be isolated.  But, say I have
>>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
>>>> to a KVM VM.  Those 8 PCI devices could share the same
>>>> streamID/ITS-device-ID since they all share the same isolation
>>>> context.
>>>>
>>>> What would be nice is at the time the 8 VFS are being added
>>>> to the IOMMU domain is for the pcidevid -> streamID mapping
>>>> table to be updated dynamically.  It simply lets us make
>>>> more efficient use of the limited streamIDs we have.
>>>>
>>>> I think it is this improvement that Minghuan had in mind
>>>> in this patch.
>>>
>>> Ok, but in this case it should be possible to use a single context bank for
>>> all of the VF streamIDs by configuring the appropriate SMR, no?
>>
>> Yes, but there are limited SMRs.  In our case there are only
>> 128 SMRs in SMMU-500 and we have potentially way more masters than
>> that.
> 
> Right, but you still only have 64 context banks at the end of the day, so do
> you really anticipate having more than 128 masters concurrently using the
> SMMU? If so, then we have devices sharing context banks so we could consider
> reusing SMRs across masters, but historically that's not been something that
> we've managed to solve.
> 
>>> Wouldn't
>>> that sort of thing be preferable to dynamic StreamID assignment? It would
>>> certainly make life easier for the MSIs.
>>
>> It would be preferable, but given only 128 total stream IDS and
>> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
>> PCI and the fsl-mc bus (see description here:
>> https://lkml.org/lkml/2015/3/5/795) that potentially have way
>> more masters than streamIDS. So, for those busses we would essentially
>> view a streamID as a "context ID"-- each SMR is associated with
>> 1 context bank register.
>>
>> For PCI we have a programmable "PCI req ID"-to-"stream ID"
>> mapping table in the PCI controller that is dynamically
>> programmable.
>>
>> Looking at it like that means that we could have
>> any number of masters but only 64 "contexts"
>> and since the masters all all programmable it's
>> seems feasbile to envision doing some bus/vendor
>> specific set up when a device is added to an
>> IOMMU domain.   One thing that would need to be conveyed
>> to the SMMU driver if doing dynamic streamID setup
>> is what streamIDs are available to be used.
> 
> Ok, but this is going to make life difficult for the MSI people, I suspect.
> 
> Marc...?

We're really facing two conflicting requirements: in order to minimize
SMR usage, we want to alias multiple ReqIDs to a single StreamID, but in
order to efficiently deal with MSIs, we want to see discrete DeviceIDs
(the actual ReqIDs). I don't easily see how we reconcile the two.

We can deal with the aliasing, provided that we extend the level of
quirkiness that pci_for_each_dma_alias can deal with. But that doesn't
solve any form of hotplug/SR-IOV behaviour.

Somehow, we're going to end-up with grossly oversized ITTs, just to
accommodate for the fact that we have no idea how many MSIs we're going
to end-up needing. I'm not thrilled with that prospect.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-24 16:18                   ` Will Deacon
@ 2015-04-24 18:09                     ` Stuart Yoder
  -1 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-24 18:09 UTC (permalink / raw)
  To: Will Deacon
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel,
	marc.zyngier



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon@arm.com]
> Sent: Friday, April 24, 2015 11:18 AM
> To: Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org; marc.zyngier@arm.com
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > > > However, there is an improvement we envision as possible due to
> > > > the limited number of SMMU contexts (i.e. 64).  If there are
> > > > 64 SMMU context registers it means that there is a max of
> > > > 64 software contexts where things can be isolated.  But, say I have
> > > > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > > > to a KVM VM.  Those 8 PCI devices could share the same
> > > > streamID/ITS-device-ID since they all share the same isolation
> > > > context.
> > > >
> > > > What would be nice is at the time the 8 VFS are being added
> > > > to the IOMMU domain is for the pcidevid -> streamID mapping
> > > > table to be updated dynamically.  It simply lets us make
> > > > more efficient use of the limited streamIDs we have.
> > > >
> > > > I think it is this improvement that Minghuan had in mind
> > > > in this patch.
> > >
> > > Ok, but in this case it should be possible to use a single context bank for
> > > all of the VF streamIDs by configuring the appropriate SMR, no?
> >
> > Yes, but there are limited SMRs.  In our case there are only
> > 128 SMRs in SMMU-500 and we have potentially way more masters than
> > that.
> 
> Right, but you still only have 64 context banks at the end of the day, so do
> you really anticipate having more than 128 masters concurrently using the
> SMMU?

Yes.  We anticiapte quite possibly quite a few more than 128 masters sharing
the 64 context banks.

> If so, then we have devices sharing context banks so we could consider
> reusing SMRs across masters, but historically that's not been something that
> we've managed to solve.

But isn't that what iommu groups are all about?... multiple masters that share
an IOMMU context because of the isolation characteristics of the hardware
like PCI devices behind a PCI bridge.   All the devices might be in
one iommu group.

What is not solved?

Stuart

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-24 18:09                     ` Stuart Yoder
  0 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-24 18:09 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon at arm.com]
> Sent: Friday, April 24, 2015 11:18 AM
> To: Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org; marc.zyngier at arm.com
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > > > However, there is an improvement we envision as possible due to
> > > > the limited number of SMMU contexts (i.e. 64).  If there are
> > > > 64 SMMU context registers it means that there is a max of
> > > > 64 software contexts where things can be isolated.  But, say I have
> > > > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > > > to a KVM VM.  Those 8 PCI devices could share the same
> > > > streamID/ITS-device-ID since they all share the same isolation
> > > > context.
> > > >
> > > > What would be nice is at the time the 8 VFS are being added
> > > > to the IOMMU domain is for the pcidevid -> streamID mapping
> > > > table to be updated dynamically.  It simply lets us make
> > > > more efficient use of the limited streamIDs we have.
> > > >
> > > > I think it is this improvement that Minghuan had in mind
> > > > in this patch.
> > >
> > > Ok, but in this case it should be possible to use a single context bank for
> > > all of the VF streamIDs by configuring the appropriate SMR, no?
> >
> > Yes, but there are limited SMRs.  In our case there are only
> > 128 SMRs in SMMU-500 and we have potentially way more masters than
> > that.
> 
> Right, but you still only have 64 context banks at the end of the day, so do
> you really anticipate having more than 128 masters concurrently using the
> SMMU?

Yes.  We anticiapte quite possibly quite a few more than 128 masters sharing
the 64 context banks.

> If so, then we have devices sharing context banks so we could consider
> reusing SMRs across masters, but historically that's not been something that
> we've managed to solve.

But isn't that what iommu groups are all about?... multiple masters that share
an IOMMU context because of the isolation characteristics of the hardware
like PCI devices behind a PCI bridge.   All the devices might be in
one iommu group.

What is not solved?

Stuart

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-24 16:44                     ` Marc Zyngier
@ 2015-04-24 18:18                       ` Stuart Yoder
  -1 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-24 18:18 UTC (permalink / raw)
  To: Marc Zyngier, Will Deacon
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel



> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> Sent: Friday, April 24, 2015 11:44 AM
> To: Will Deacon; Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On 24/04/15 17:18, Will Deacon wrote:
> > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> >>>> However, there is an improvement we envision as possible due to
> >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> >>>> 64 SMMU context registers it means that there is a max of
> >>>> 64 software contexts where things can be isolated.  But, say I have
> >>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> >>>> to a KVM VM.  Those 8 PCI devices could share the same
> >>>> streamID/ITS-device-ID since they all share the same isolation
> >>>> context.
> >>>>
> >>>> What would be nice is at the time the 8 VFS are being added
> >>>> to the IOMMU domain is for the pcidevid -> streamID mapping
> >>>> table to be updated dynamically.  It simply lets us make
> >>>> more efficient use of the limited streamIDs we have.
> >>>>
> >>>> I think it is this improvement that Minghuan had in mind
> >>>> in this patch.
> >>>
> >>> Ok, but in this case it should be possible to use a single context bank for
> >>> all of the VF streamIDs by configuring the appropriate SMR, no?
> >>
> >> Yes, but there are limited SMRs.  In our case there are only
> >> 128 SMRs in SMMU-500 and we have potentially way more masters than
> >> that.
> >
> > Right, but you still only have 64 context banks at the end of the day, so do
> > you really anticipate having more than 128 masters concurrently using the
> > SMMU? If so, then we have devices sharing context banks so we could consider
> > reusing SMRs across masters, but historically that's not been something that
> > we've managed to solve.
> >
> >>> Wouldn't
> >>> that sort of thing be preferable to dynamic StreamID assignment? It would
> >>> certainly make life easier for the MSIs.
> >>
> >> It would be preferable, but given only 128 total stream IDS and
> >> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> >> PCI and the fsl-mc bus (see description here:
> >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> >> more masters than streamIDS. So, for those busses we would essentially
> >> view a streamID as a "context ID"-- each SMR is associated with
> >> 1 context bank register.
> >>
> >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> >> mapping table in the PCI controller that is dynamically
> >> programmable.
> >>
> >> Looking at it like that means that we could have
> >> any number of masters but only 64 "contexts"
> >> and since the masters all all programmable it's
> >> seems feasbile to envision doing some bus/vendor
> >> specific set up when a device is added to an
> >> IOMMU domain.   One thing that would need to be conveyed
> >> to the SMMU driver if doing dynamic streamID setup
> >> is what streamIDs are available to be used.
> >
> > Ok, but this is going to make life difficult for the MSI people, I suspect.
> >
> > Marc...?
> 
> We're really facing two conflicting requirements: in order to minimize
> SMR usage, we want to alias multiple ReqIDs to a single StreamID

Another reason could be the isolation characteristics of the
hardware...see comment below about PCI bridges.

> but in
> order to efficiently deal with MSIs, we want to see discrete DeviceIDs
> (the actual ReqIDs). I don't easily see how we reconcile the two.
> 
> We can deal with the aliasing, provided that we extend the level of
> quirkiness that pci_for_each_dma_alias can deal with. But that doesn't
> solve any form of hotplug/SR-IOV behaviour.
> 
> Somehow, we're going to end-up with grossly oversized ITTs, just to
> accommodate for the fact that we have no idea how many MSIs we're going
> to end-up needing. I'm not thrilled with that prospect.

How can we avoid that in the face of hotplug?

And what are we really worried about regarding over-sized ITTs...bytes
of memory saved?

A fundamental thing built into the IOMMU subsystem in Linux is
representing iommu groups that can represent things like
multiple PCI devices that for hardware reasons cannot
be isolated (and the example I've seen given relates to 
devices behind PCI bridges).

So, I think the thing we are facing here is that while the
IOMMU subsystem has accounted for reprsenting the isolation
characteristics of a system with iommu groups, there is
no corresponding "msi group" concept.

In the SMMU/GIC-500-ITS world the iommu isolation
ID (the stream ID) and the GIC-ITS device ID are in
fact the same ID.

Is there some way we could sanely correlate IOMMU group creation
(which establishes isolation granularity) with the creation
of an ITT for the GIC-ITS?

(I don't have a good feel for how device IDs work on x86,
I know there is an interrupt remapping table in the
x86 IOMMUs that is distinct from the memory isolation
page tables)

Thanks,
Stuart

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-24 18:18                       ` Stuart Yoder
  0 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-24 18:18 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> Sent: Friday, April 24, 2015 11:44 AM
> To: Will Deacon; Yoder Stuart-B08248
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On 24/04/15 17:18, Will Deacon wrote:
> > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> >>>> However, there is an improvement we envision as possible due to
> >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> >>>> 64 SMMU context registers it means that there is a max of
> >>>> 64 software contexts where things can be isolated.  But, say I have
> >>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> >>>> to a KVM VM.  Those 8 PCI devices could share the same
> >>>> streamID/ITS-device-ID since they all share the same isolation
> >>>> context.
> >>>>
> >>>> What would be nice is at the time the 8 VFS are being added
> >>>> to the IOMMU domain is for the pcidevid -> streamID mapping
> >>>> table to be updated dynamically.  It simply lets us make
> >>>> more efficient use of the limited streamIDs we have.
> >>>>
> >>>> I think it is this improvement that Minghuan had in mind
> >>>> in this patch.
> >>>
> >>> Ok, but in this case it should be possible to use a single context bank for
> >>> all of the VF streamIDs by configuring the appropriate SMR, no?
> >>
> >> Yes, but there are limited SMRs.  In our case there are only
> >> 128 SMRs in SMMU-500 and we have potentially way more masters than
> >> that.
> >
> > Right, but you still only have 64 context banks at the end of the day, so do
> > you really anticipate having more than 128 masters concurrently using the
> > SMMU? If so, then we have devices sharing context banks so we could consider
> > reusing SMRs across masters, but historically that's not been something that
> > we've managed to solve.
> >
> >>> Wouldn't
> >>> that sort of thing be preferable to dynamic StreamID assignment? It would
> >>> certainly make life easier for the MSIs.
> >>
> >> It would be preferable, but given only 128 total stream IDS and
> >> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> >> PCI and the fsl-mc bus (see description here:
> >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> >> more masters than streamIDS. So, for those busses we would essentially
> >> view a streamID as a "context ID"-- each SMR is associated with
> >> 1 context bank register.
> >>
> >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> >> mapping table in the PCI controller that is dynamically
> >> programmable.
> >>
> >> Looking at it like that means that we could have
> >> any number of masters but only 64 "contexts"
> >> and since the masters all all programmable it's
> >> seems feasbile to envision doing some bus/vendor
> >> specific set up when a device is added to an
> >> IOMMU domain.   One thing that would need to be conveyed
> >> to the SMMU driver if doing dynamic streamID setup
> >> is what streamIDs are available to be used.
> >
> > Ok, but this is going to make life difficult for the MSI people, I suspect.
> >
> > Marc...?
> 
> We're really facing two conflicting requirements: in order to minimize
> SMR usage, we want to alias multiple ReqIDs to a single StreamID

Another reason could be the isolation characteristics of the
hardware...see comment below about PCI bridges.

> but in
> order to efficiently deal with MSIs, we want to see discrete DeviceIDs
> (the actual ReqIDs). I don't easily see how we reconcile the two.
> 
> We can deal with the aliasing, provided that we extend the level of
> quirkiness that pci_for_each_dma_alias can deal with. But that doesn't
> solve any form of hotplug/SR-IOV behaviour.
> 
> Somehow, we're going to end-up with grossly oversized ITTs, just to
> accommodate for the fact that we have no idea how many MSIs we're going
> to end-up needing. I'm not thrilled with that prospect.

How can we avoid that in the face of hotplug?

And what are we really worried about regarding over-sized ITTs...bytes
of memory saved?

A fundamental thing built into the IOMMU subsystem in Linux is
representing iommu groups that can represent things like
multiple PCI devices that for hardware reasons cannot
be isolated (and the example I've seen given relates to 
devices behind PCI bridges).

So, I think the thing we are facing here is that while the
IOMMU subsystem has accounted for reprsenting the isolation
characteristics of a system with iommu groups, there is
no corresponding "msi group" concept.

In the SMMU/GIC-500-ITS world the iommu isolation
ID (the stream ID) and the GIC-ITS device ID are in
fact the same ID.

Is there some way we could sanely correlate IOMMU group creation
(which establishes isolation granularity) with the creation
of an ITT for the GIC-ITS?

(I don't have a good feel for how device IDs work on x86,
I know there is an interrupt remapping table in the
x86 IOMMUs that is distinct from the memory isolation
page tables)

Thanks,
Stuart

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-24 16:44                     ` Marc Zyngier
@ 2015-04-24 19:24                       ` Stuart Yoder
  -1 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-24 19:24 UTC (permalink / raw)
  To: Marc Zyngier, Will Deacon
  Cc: Varun Sethi, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel,
	Alex Williamson

+Alex W

> -----Original Message-----
> From: Yoder Stuart-B08248
> Sent: Friday, April 24, 2015 1:19 PM
> To: 'Marc Zyngier'; Will Deacon
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> 
> 
> > -----Original Message-----
> > From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> > Sent: Friday, April 24, 2015 11:44 AM
> > To: Will Deacon; Yoder Stuart-B08248
> > Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> > Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > On 24/04/15 17:18, Will Deacon wrote:
> > > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > >>>> However, there is an improvement we envision as possible due to
> > >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> > >>>> 64 SMMU context registers it means that there is a max of
> > >>>> 64 software contexts where things can be isolated.  But, say I have
> > >>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > >>>> to a KVM VM.  Those 8 PCI devices could share the same
> > >>>> streamID/ITS-device-ID since they all share the same isolation
> > >>>> context.
> > >>>>
> > >>>> What would be nice is at the time the 8 VFS are being added
> > >>>> to the IOMMU domain is for the pcidevid -> streamID mapping
> > >>>> table to be updated dynamically.  It simply lets us make
> > >>>> more efficient use of the limited streamIDs we have.
> > >>>>
> > >>>> I think it is this improvement that Minghuan had in mind
> > >>>> in this patch.
> > >>>
> > >>> Ok, but in this case it should be possible to use a single context bank for
> > >>> all of the VF streamIDs by configuring the appropriate SMR, no?
> > >>
> > >> Yes, but there are limited SMRs.  In our case there are only
> > >> 128 SMRs in SMMU-500 and we have potentially way more masters than
> > >> that.
> > >
> > > Right, but you still only have 64 context banks at the end of the day, so do
> > > you really anticipate having more than 128 masters concurrently using the
> > > SMMU? If so, then we have devices sharing context banks so we could consider
> > > reusing SMRs across masters, but historically that's not been something that
> > > we've managed to solve.
> > >
> > >>> Wouldn't
> > >>> that sort of thing be preferable to dynamic StreamID assignment? It would
> > >>> certainly make life easier for the MSIs.
> > >>
> > >> It would be preferable, but given only 128 total stream IDS and
> > >> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> > >> PCI and the fsl-mc bus (see description here:
> > >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> > >> more masters than streamIDS. So, for those busses we would essentially
> > >> view a streamID as a "context ID"-- each SMR is associated with
> > >> 1 context bank register.
> > >>
> > >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> > >> mapping table in the PCI controller that is dynamically
> > >> programmable.
> > >>
> > >> Looking at it like that means that we could have
> > >> any number of masters but only 64 "contexts"
> > >> and since the masters all all programmable it's
> > >> seems feasbile to envision doing some bus/vendor
> > >> specific set up when a device is added to an
> > >> IOMMU domain.   One thing that would need to be conveyed
> > >> to the SMMU driver if doing dynamic streamID setup
> > >> is what streamIDs are available to be used.
> > >
> > > Ok, but this is going to make life difficult for the MSI people, I suspect.
> > >
> > > Marc...?
> >
> > We're really facing two conflicting requirements: in order to minimize
> > SMR usage, we want to alias multiple ReqIDs to a single StreamID
> 
> Another reason could be the isolation characteristics of the
> hardware...see comment below about PCI bridges.
> 
> > but in
> > order to efficiently deal with MSIs, we want to see discrete DeviceIDs
> > (the actual ReqIDs). I don't easily see how we reconcile the two.
> >
> > We can deal with the aliasing, provided that we extend the level of
> > quirkiness that pci_for_each_dma_alias can deal with. But that doesn't
> > solve any form of hotplug/SR-IOV behaviour.
> >
> > Somehow, we're going to end-up with grossly oversized ITTs, just to
> > accommodate for the fact that we have no idea how many MSIs we're going
> > to end-up needing. I'm not thrilled with that prospect.
> 
> How can we avoid that in the face of hotplug?
> 
> And what are we really worried about regarding over-sized ITTs...bytes
> of memory saved?
> 
> A fundamental thing built into the IOMMU subsystem in Linux is
> representing iommu groups that can represent things like
> multiple PCI devices that for hardware reasons cannot
> be isolated (and the example I've seen given relates to
> devices behind PCI bridges).
> 
> So, I think the thing we are facing here is that while the
> IOMMU subsystem has accounted for reprsenting the isolation
> characteristics of a system with iommu groups, there is
> no corresponding "msi group" concept.
> 
> In the SMMU/GIC-500-ITS world the iommu isolation
> ID (the stream ID) and the GIC-ITS device ID are in
> fact the same ID.
> 
> Is there some way we could sanely correlate IOMMU group creation
> (which establishes isolation granularity) with the creation
> of an ITT for the GIC-ITS?
> 
> (I don't have a good feel for how device IDs work on x86,
> I know there is an interrupt remapping table in the
> x86 IOMMUs that is distinct from the memory isolation
> page tables)

For reference see Alex Williamson's description of IOMMU
isolation scenarios in Documentation/vfio.txt:

   ...
   This isolation is not always at the granularity of a single device
   though.  Even when an IOMMU is capable of this, properties of devices,
   interconnects, and IOMMU topologies can each reduce this isolation.
   For instance, an individual device may be part of a larger multi-
   function enclosure.  While the IOMMU may be able to distinguish
   between devices within the enclosure, the enclosure may not require
   transactions between devices to reach the IOMMU.  Examples of this
   could be anything from a multi-function PCI device with backdoors
   between functions to a non-PCI-ACS (Access Control Services) capable
   bridge allowing redirection without reaching the IOMMU.  Topology
   can also play a factor in terms of hiding devices.  A PCIe-to-PCI
   bridge masks the devices behind it, making transaction appear as if
   from the bridge itself.  Obviously IOMMU design plays a major factor
   as well.

   Therefore, while for the most part an IOMMU may have device level
   granularity, any system is susceptible to reduced granularity.  The
   IOMMU API therefore supports a notion of IOMMU groups.  A group is
   a set of devices which is isolatable from all other devices in the
   system.  Groups are therefore the unit of ownership used by VFIO.
   ...

The isolation granularity issues he raises are going to impact how
we deal with MSIs with GIC ITS because again, isolation ID and 
GIC ITS device ID are the same.

Stuart

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-24 19:24                       ` Stuart Yoder
  0 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-04-24 19:24 UTC (permalink / raw)
  To: linux-arm-kernel

+Alex W

> -----Original Message-----
> From: Yoder Stuart-B08248
> Sent: Friday, April 24, 2015 1:19 PM
> To: 'Marc Zyngier'; Will Deacon
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> 
> 
> > -----Original Message-----
> > From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> > Sent: Friday, April 24, 2015 11:44 AM
> > To: Will Deacon; Yoder Stuart-B08248
> > Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> > Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > On 24/04/15 17:18, Will Deacon wrote:
> > > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > >>>> However, there is an improvement we envision as possible due to
> > >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> > >>>> 64 SMMU context registers it means that there is a max of
> > >>>> 64 software contexts where things can be isolated.  But, say I have
> > >>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > >>>> to a KVM VM.  Those 8 PCI devices could share the same
> > >>>> streamID/ITS-device-ID since they all share the same isolation
> > >>>> context.
> > >>>>
> > >>>> What would be nice is at the time the 8 VFS are being added
> > >>>> to the IOMMU domain is for the pcidevid -> streamID mapping
> > >>>> table to be updated dynamically.  It simply lets us make
> > >>>> more efficient use of the limited streamIDs we have.
> > >>>>
> > >>>> I think it is this improvement that Minghuan had in mind
> > >>>> in this patch.
> > >>>
> > >>> Ok, but in this case it should be possible to use a single context bank for
> > >>> all of the VF streamIDs by configuring the appropriate SMR, no?
> > >>
> > >> Yes, but there are limited SMRs.  In our case there are only
> > >> 128 SMRs in SMMU-500 and we have potentially way more masters than
> > >> that.
> > >
> > > Right, but you still only have 64 context banks at the end of the day, so do
> > > you really anticipate having more than 128 masters concurrently using the
> > > SMMU? If so, then we have devices sharing context banks so we could consider
> > > reusing SMRs across masters, but historically that's not been something that
> > > we've managed to solve.
> > >
> > >>> Wouldn't
> > >>> that sort of thing be preferable to dynamic StreamID assignment? It would
> > >>> certainly make life easier for the MSIs.
> > >>
> > >> It would be preferable, but given only 128 total stream IDS and
> > >> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> > >> PCI and the fsl-mc bus (see description here:
> > >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> > >> more masters than streamIDS. So, for those busses we would essentially
> > >> view a streamID as a "context ID"-- each SMR is associated with
> > >> 1 context bank register.
> > >>
> > >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> > >> mapping table in the PCI controller that is dynamically
> > >> programmable.
> > >>
> > >> Looking at it like that means that we could have
> > >> any number of masters but only 64 "contexts"
> > >> and since the masters all all programmable it's
> > >> seems feasbile to envision doing some bus/vendor
> > >> specific set up when a device is added to an
> > >> IOMMU domain.   One thing that would need to be conveyed
> > >> to the SMMU driver if doing dynamic streamID setup
> > >> is what streamIDs are available to be used.
> > >
> > > Ok, but this is going to make life difficult for the MSI people, I suspect.
> > >
> > > Marc...?
> >
> > We're really facing two conflicting requirements: in order to minimize
> > SMR usage, we want to alias multiple ReqIDs to a single StreamID
> 
> Another reason could be the isolation characteristics of the
> hardware...see comment below about PCI bridges.
> 
> > but in
> > order to efficiently deal with MSIs, we want to see discrete DeviceIDs
> > (the actual ReqIDs). I don't easily see how we reconcile the two.
> >
> > We can deal with the aliasing, provided that we extend the level of
> > quirkiness that pci_for_each_dma_alias can deal with. But that doesn't
> > solve any form of hotplug/SR-IOV behaviour.
> >
> > Somehow, we're going to end-up with grossly oversized ITTs, just to
> > accommodate for the fact that we have no idea how many MSIs we're going
> > to end-up needing. I'm not thrilled with that prospect.
> 
> How can we avoid that in the face of hotplug?
> 
> And what are we really worried about regarding over-sized ITTs...bytes
> of memory saved?
> 
> A fundamental thing built into the IOMMU subsystem in Linux is
> representing iommu groups that can represent things like
> multiple PCI devices that for hardware reasons cannot
> be isolated (and the example I've seen given relates to
> devices behind PCI bridges).
> 
> So, I think the thing we are facing here is that while the
> IOMMU subsystem has accounted for reprsenting the isolation
> characteristics of a system with iommu groups, there is
> no corresponding "msi group" concept.
> 
> In the SMMU/GIC-500-ITS world the iommu isolation
> ID (the stream ID) and the GIC-ITS device ID are in
> fact the same ID.
> 
> Is there some way we could sanely correlate IOMMU group creation
> (which establishes isolation granularity) with the creation
> of an ITT for the GIC-ITS?
> 
> (I don't have a good feel for how device IDs work on x86,
> I know there is an interrupt remapping table in the
> x86 IOMMUs that is distinct from the memory isolation
> page tables)

For reference see Alex Williamson's description of IOMMU
isolation scenarios in Documentation/vfio.txt:

   ...
   This isolation is not always at the granularity of a single device
   though.  Even when an IOMMU is capable of this, properties of devices,
   interconnects, and IOMMU topologies can each reduce this isolation.
   For instance, an individual device may be part of a larger multi-
   function enclosure.  While the IOMMU may be able to distinguish
   between devices within the enclosure, the enclosure may not require
   transactions between devices to reach the IOMMU.  Examples of this
   could be anything from a multi-function PCI device with backdoors
   between functions to a non-PCI-ACS (Access Control Services) capable
   bridge allowing redirection without reaching the IOMMU.  Topology
   can also play a factor in terms of hiding devices.  A PCIe-to-PCI
   bridge masks the devices behind it, making transaction appear as if
   from the bridge itself.  Obviously IOMMU design plays a major factor
   as well.

   Therefore, while for the most part an IOMMU may have device level
   granularity, any system is susceptible to reduced granularity.  The
   IOMMU API therefore supports a notion of IOMMU groups.  A group is
   a set of devices which is isolatable from all other devices in the
   system.  Groups are therefore the unit of ownership used by VFIO.
   ...

The isolation granularity issues he raises are going to impact how
we deal with MSIs with GIC ITS because again, isolation ID and 
GIC ITS device ID are the same.

Stuart

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-24 18:18                       ` Stuart Yoder
@ 2015-04-25 10:39                         ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-25 10:39 UTC (permalink / raw)
  To: Stuart Yoder
  Cc: Will Deacon, Varun Sethi, Minghuan.Lian, linux-pci,
	Arnd Bergmann, Mingkai.Hu, Roy Zang, Bjorn Helgaas, Scott Wood,
	linux-arm-kernel

On Fri, 24 Apr 2015 19:18:44 +0100
Stuart Yoder <stuart.yoder@freescale.com> wrote:

Hi Stuart,

> 
> 
> > -----Original Message-----
> > From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> > Sent: Friday, April 24, 2015 11:44 AM
> > To: Will Deacon; Yoder Stuart-B08248
> > Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> > Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > 
> > On 24/04/15 17:18, Will Deacon wrote:
> > > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > >>>> However, there is an improvement we envision as possible due to
> > >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> > >>>> 64 SMMU context registers it means that there is a max of
> > >>>> 64 software contexts where things can be isolated.  But, say I have
> > >>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > >>>> to a KVM VM.  Those 8 PCI devices could share the same
> > >>>> streamID/ITS-device-ID since they all share the same isolation
> > >>>> context.
> > >>>>
> > >>>> What would be nice is at the time the 8 VFS are being added
> > >>>> to the IOMMU domain is for the pcidevid -> streamID mapping
> > >>>> table to be updated dynamically.  It simply lets us make
> > >>>> more efficient use of the limited streamIDs we have.
> > >>>>
> > >>>> I think it is this improvement that Minghuan had in mind
> > >>>> in this patch.
> > >>>
> > >>> Ok, but in this case it should be possible to use a single context bank for
> > >>> all of the VF streamIDs by configuring the appropriate SMR, no?
> > >>
> > >> Yes, but there are limited SMRs.  In our case there are only
> > >> 128 SMRs in SMMU-500 and we have potentially way more masters than
> > >> that.
> > >
> > > Right, but you still only have 64 context banks at the end of the day, so do
> > > you really anticipate having more than 128 masters concurrently using the
> > > SMMU? If so, then we have devices sharing context banks so we could consider
> > > reusing SMRs across masters, but historically that's not been something that
> > > we've managed to solve.
> > >
> > >>> Wouldn't
> > >>> that sort of thing be preferable to dynamic StreamID assignment? It would
> > >>> certainly make life easier for the MSIs.
> > >>
> > >> It would be preferable, but given only 128 total stream IDS and
> > >> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> > >> PCI and the fsl-mc bus (see description here:
> > >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> > >> more masters than streamIDS. So, for those busses we would essentially
> > >> view a streamID as a "context ID"-- each SMR is associated with
> > >> 1 context bank register.
> > >>
> > >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> > >> mapping table in the PCI controller that is dynamically
> > >> programmable.
> > >>
> > >> Looking at it like that means that we could have
> > >> any number of masters but only 64 "contexts"
> > >> and since the masters all all programmable it's
> > >> seems feasbile to envision doing some bus/vendor
> > >> specific set up when a device is added to an
> > >> IOMMU domain.   One thing that would need to be conveyed
> > >> to the SMMU driver if doing dynamic streamID setup
> > >> is what streamIDs are available to be used.
> > >
> > > Ok, but this is going to make life difficult for the MSI people, I suspect.
> > >
> > > Marc...?
> > 
> > We're really facing two conflicting requirements: in order to minimize
> > SMR usage, we want to alias multiple ReqIDs to a single StreamID
> 
> Another reason could be the isolation characteristics of the
> hardware...see comment below about PCI bridges.
> 
> > but in
> > order to efficiently deal with MSIs, we want to see discrete DeviceIDs
> > (the actual ReqIDs). I don't easily see how we reconcile the two.
> > 
> > We can deal with the aliasing, provided that we extend the level of
> > quirkiness that pci_for_each_dma_alias can deal with. But that
> > doesn't solve any form of hotplug/SR-IOV behaviour.
> > 
> > Somehow, we're going to end-up with grossly oversized ITTs, just to
> > accommodate for the fact that we have no idea how many MSIs we're
> > going to end-up needing. I'm not thrilled with that prospect.
> 
> How can we avoid that in the face of hotplug?

Fortunately, hotplug is not always synonymous of aliasing. The ITS is
built around the hypothesis that aliasing doesn't happen, and that you
know upfront how many LPIs the device will be allowed to generate.

> And what are we really worried about regarding over-sized ITTs...bytes
> of memory saved?

That's one thing, yes. But more fundamentally, how do you size your MSI
capacity for a single alias? Do you evenly split your LPI space among
all possible aliases? Assuming 64 aliases and 16 bits of interrupt ID
space, you end up with 10 bit per alias. Is that always enough? Or do
you need something more fine-grained?

> A fundamental thing built into the IOMMU subsystem in Linux is
> representing iommu groups that can represent things like
> multiple PCI devices that for hardware reasons cannot
> be isolated (and the example I've seen given relates to 
> devices behind PCI bridges).
> 
> So, I think the thing we are facing here is that while the
> IOMMU subsystem has accounted for reprsenting the isolation
> characteristics of a system with iommu groups, there is
> no corresponding "msi group" concept.
> 
> In the SMMU/GIC-500-ITS world the iommu isolation
> ID (the stream ID) and the GIC-ITS device ID are in
> fact the same ID.

The DeviceID is the "MSI group" you mention. This is what provides
isolation at the ITS level.

> Is there some way we could sanely correlate IOMMU group creation
> (which establishes isolation granularity) with the creation
> of an ITT for the GIC-ITS?

The problem you have is that your ITT already exists before you start
"hotpluging" new devices. Take the following (made up) example:

System boots, device X is discovered, claims 64 MSIs. An ITT for device
X is allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
function that is aliased to X, claiming another 64 MSIs. Fail.

What do we do here? The ITT is live (X is generating interrupts), and
there is no provision to resize it (I've come up with a horrible
scheme, but that could fail as well). The only sane option would be to
guess how many MSIs a given alias could possibly use. How wrong is this
guess going to be?

The problem we have is that IOMMU groups are dynamic, while ITT
allocation is completely static for a given DeviceID. The architecture
doesn't give you any mechanism to resize it, and I have the ugly
feeling that static allocation of the ID space to aliases is too
rigid...

	M.
-- 
Jazz is not dead. It just smells funny.

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-25 10:39                         ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-25 10:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, 24 Apr 2015 19:18:44 +0100
Stuart Yoder <stuart.yoder@freescale.com> wrote:

Hi Stuart,

> 
> 
> > -----Original Message-----
> > From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> > Sent: Friday, April 24, 2015 11:44 AM
> > To: Will Deacon; Yoder Stuart-B08248
> > Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284;
> > Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > 
> > On 24/04/15 17:18, Will Deacon wrote:
> > > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > >>>> However, there is an improvement we envision as possible due to
> > >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> > >>>> 64 SMMU context registers it means that there is a max of
> > >>>> 64 software contexts where things can be isolated.  But, say I have
> > >>>> an SRIOV card with 64 VFs, and I want to assign 8 of the VFs
> > >>>> to a KVM VM.  Those 8 PCI devices could share the same
> > >>>> streamID/ITS-device-ID since they all share the same isolation
> > >>>> context.
> > >>>>
> > >>>> What would be nice is at the time the 8 VFS are being added
> > >>>> to the IOMMU domain is for the pcidevid -> streamID mapping
> > >>>> table to be updated dynamically.  It simply lets us make
> > >>>> more efficient use of the limited streamIDs we have.
> > >>>>
> > >>>> I think it is this improvement that Minghuan had in mind
> > >>>> in this patch.
> > >>>
> > >>> Ok, but in this case it should be possible to use a single context bank for
> > >>> all of the VF streamIDs by configuring the appropriate SMR, no?
> > >>
> > >> Yes, but there are limited SMRs.  In our case there are only
> > >> 128 SMRs in SMMU-500 and we have potentially way more masters than
> > >> that.
> > >
> > > Right, but you still only have 64 context banks at the end of the day, so do
> > > you really anticipate having more than 128 masters concurrently using the
> > > SMMU? If so, then we have devices sharing context banks so we could consider
> > > reusing SMRs across masters, but historically that's not been something that
> > > we've managed to solve.
> > >
> > >>> Wouldn't
> > >>> that sort of thing be preferable to dynamic StreamID assignment? It would
> > >>> certainly make life easier for the MSIs.
> > >>
> > >> It would be preferable, but given only 128 total stream IDS and
> > >> 64 context registers it's potentially an issue.  On our LS2085 SoC it is
> > >> PCI and the fsl-mc bus (see description here:
> > >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> > >> more masters than streamIDS. So, for those busses we would essentially
> > >> view a streamID as a "context ID"-- each SMR is associated with
> > >> 1 context bank register.
> > >>
> > >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> > >> mapping table in the PCI controller that is dynamically
> > >> programmable.
> > >>
> > >> Looking at it like that means that we could have
> > >> any number of masters but only 64 "contexts"
> > >> and since the masters all all programmable it's
> > >> seems feasbile to envision doing some bus/vendor
> > >> specific set up when a device is added to an
> > >> IOMMU domain.   One thing that would need to be conveyed
> > >> to the SMMU driver if doing dynamic streamID setup
> > >> is what streamIDs are available to be used.
> > >
> > > Ok, but this is going to make life difficult for the MSI people, I suspect.
> > >
> > > Marc...?
> > 
> > We're really facing two conflicting requirements: in order to minimize
> > SMR usage, we want to alias multiple ReqIDs to a single StreamID
> 
> Another reason could be the isolation characteristics of the
> hardware...see comment below about PCI bridges.
> 
> > but in
> > order to efficiently deal with MSIs, we want to see discrete DeviceIDs
> > (the actual ReqIDs). I don't easily see how we reconcile the two.
> > 
> > We can deal with the aliasing, provided that we extend the level of
> > quirkiness that pci_for_each_dma_alias can deal with. But that
> > doesn't solve any form of hotplug/SR-IOV behaviour.
> > 
> > Somehow, we're going to end-up with grossly oversized ITTs, just to
> > accommodate for the fact that we have no idea how many MSIs we're
> > going to end-up needing. I'm not thrilled with that prospect.
> 
> How can we avoid that in the face of hotplug?

Fortunately, hotplug is not always synonymous of aliasing. The ITS is
built around the hypothesis that aliasing doesn't happen, and that you
know upfront how many LPIs the device will be allowed to generate.

> And what are we really worried about regarding over-sized ITTs...bytes
> of memory saved?

That's one thing, yes. But more fundamentally, how do you size your MSI
capacity for a single alias? Do you evenly split your LPI space among
all possible aliases? Assuming 64 aliases and 16 bits of interrupt ID
space, you end up with 10 bit per alias. Is that always enough? Or do
you need something more fine-grained?

> A fundamental thing built into the IOMMU subsystem in Linux is
> representing iommu groups that can represent things like
> multiple PCI devices that for hardware reasons cannot
> be isolated (and the example I've seen given relates to 
> devices behind PCI bridges).
> 
> So, I think the thing we are facing here is that while the
> IOMMU subsystem has accounted for reprsenting the isolation
> characteristics of a system with iommu groups, there is
> no corresponding "msi group" concept.
> 
> In the SMMU/GIC-500-ITS world the iommu isolation
> ID (the stream ID) and the GIC-ITS device ID are in
> fact the same ID.

The DeviceID is the "MSI group" you mention. This is what provides
isolation at the ITS level.

> Is there some way we could sanely correlate IOMMU group creation
> (which establishes isolation granularity) with the creation
> of an ITT for the GIC-ITS?

The problem you have is that your ITT already exists before you start
"hotpluging" new devices. Take the following (made up) example:

System boots, device X is discovered, claims 64 MSIs. An ITT for device
X is allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
function that is aliased to X, claiming another 64 MSIs. Fail.

What do we do here? The ITT is live (X is generating interrupts), and
there is no provision to resize it (I've come up with a horrible
scheme, but that could fail as well). The only sane option would be to
guess how many MSIs a given alias could possibly use. How wrong is this
guess going to be?

The problem we have is that IOMMU groups are dynamic, while ITT
allocation is completely static for a given DeviceID. The architecture
doesn't give you any mechanism to resize it, and I have the ugly
feeling that static allocation of the ID space to aliases is too
rigid...

	M.
-- 
Jazz is not dead. It just smells funny.

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-25 10:39                         ` Marc Zyngier
@ 2015-04-26 18:20                           ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-26 18:20 UTC (permalink / raw)
  To: Marc Zyngier, Stuart Yoder
  Cc: Will Deacon, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Marc,

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> Sent: Saturday, April 25, 2015 4:10 PM
> To: Yoder Stuart-B08248
> Cc: Will Deacon; Sethi Varun-B16395; Lian Minghuan-B31939; linux-
> pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911;
> Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Fri, 24 Apr 2015 19:18:44 +0100
> Stuart Yoder <stuart.yoder@freescale.com> wrote:
> 
> Hi Stuart,
> 
> >
> >
> > > -----Original Message-----
> > > From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> > > Sent: Friday, April 24, 2015 11:44 AM
> > > To: Will Deacon; Yoder Stuart-B08248
> > > Cc: Sethi Varun-B16395; Lian Minghuan-B31939;
> > > linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> > > Roy-R61911; Bjorn Helgaas; Wood Scott-B07421;
> > > linux-arm-kernel@lists.infradead.org
> > > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > >
> > > On 24/04/15 17:18, Will Deacon wrote:
> > > > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > > >>>> However, there is an improvement we envision as possible due to
> > > >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> > > >>>> 64 SMMU context registers it means that there is a max of
> > > >>>> 64 software contexts where things can be isolated.  But, say I
> > > >>>> have an SRIOV card with 64 VFs, and I want to assign 8 of the
> > > >>>> VFs to a KVM VM.  Those 8 PCI devices could share the same
> > > >>>> streamID/ITS-device-ID since they all share the same isolation
> > > >>>> context.
> > > >>>>
> > > >>>> What would be nice is at the time the 8 VFS are being added to
> > > >>>> the IOMMU domain is for the pcidevid -> streamID mapping table
> > > >>>> to be updated dynamically.  It simply lets us make more
> > > >>>> efficient use of the limited streamIDs we have.
> > > >>>>
> > > >>>> I think it is this improvement that Minghuan had in mind in
> > > >>>> this patch.
> > > >>>
> > > >>> Ok, but in this case it should be possible to use a single
> > > >>> context bank for all of the VF streamIDs by configuring the
> appropriate SMR, no?
> > > >>
> > > >> Yes, but there are limited SMRs.  In our case there are only
> > > >> 128 SMRs in SMMU-500 and we have potentially way more masters
> > > >> than that.
> > > >
> > > > Right, but you still only have 64 context banks at the end of the
> > > > day, so do you really anticipate having more than 128 masters
> > > > concurrently using the SMMU? If so, then we have devices sharing
> > > > context banks so we could consider reusing SMRs across masters,
> > > > but historically that's not been something that we've managed to solve.
> > > >
> > > >>> Wouldn't
> > > >>> that sort of thing be preferable to dynamic StreamID assignment?
> > > >>> It would certainly make life easier for the MSIs.
> > > >>
> > > >> It would be preferable, but given only 128 total stream IDS and
> > > >> 64 context registers it's potentially an issue.  On our LS2085
> > > >> SoC it is PCI and the fsl-mc bus (see description here:
> > > >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> > > >> more masters than streamIDS. So, for those busses we would
> > > >> essentially view a streamID as a "context ID"-- each SMR is
> > > >> associated with
> > > >> 1 context bank register.
> > > >>
> > > >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> > > >> mapping table in the PCI controller that is dynamically
> > > >> programmable.
> > > >>
> > > >> Looking at it like that means that we could have any number of
> > > >> masters but only 64 "contexts"
> > > >> and since the masters all all programmable it's seems feasbile to
> > > >> envision doing some bus/vendor specific set up when a device is
> > > >> added to an
> > > >> IOMMU domain.   One thing that would need to be conveyed
> > > >> to the SMMU driver if doing dynamic streamID setup is what
> > > >> streamIDs are available to be used.
> > > >
> > > > Ok, but this is going to make life difficult for the MSI people, I suspect.
> > > >
> > > > Marc...?
> > >
> > > We're really facing two conflicting requirements: in order to
> > > minimize SMR usage, we want to alias multiple ReqIDs to a single
> > > StreamID
> >
> > Another reason could be the isolation characteristics of the
> > hardware...see comment below about PCI bridges.
> >
> > > but in
> > > order to efficiently deal with MSIs, we want to see discrete
> > > DeviceIDs (the actual ReqIDs). I don't easily see how we reconcile the
> two.
> > >
> > > We can deal with the aliasing, provided that we extend the level of
> > > quirkiness that pci_for_each_dma_alias can deal with. But that
> > > doesn't solve any form of hotplug/SR-IOV behaviour.
> > >
[varun] Can you please elaborate on "extending the quirkiness of pci_for_each_dma_alias". How do you see the case for transparent host bridege being handled? We would see a device ID corresponding to the host bridge for masters behind that bridge.

> > > Somehow, we're going to end-up with grossly oversized ITTs, just to
> > > accommodate for the fact that we have no idea how many MSIs we're
> > > going to end-up needing. I'm not thrilled with that prospect.
> >
> > How can we avoid that in the face of hotplug?
> 
> Fortunately, hotplug is not always synonymous of aliasing. The ITS is built
> around the hypothesis that aliasing doesn't happen, and that you know
> upfront how many LPIs the device will be allowed to generate.
> 
> > And what are we really worried about regarding over-sized ITTs...bytes
> > of memory saved?
> 
> That's one thing, yes. But more fundamentally, how do you size your MSI
> capacity for a single alias? Do you evenly split your LPI space among all
> possible aliases? Assuming 64 aliases and 16 bits of interrupt ID space, you
> end up with 10 bit per alias. Is that always enough? Or do you need
> something more fine-grained?
> 
> > A fundamental thing built into the IOMMU subsystem in Linux is
> > representing iommu groups that can represent things like multiple PCI
> > devices that for hardware reasons cannot be isolated (and the example
> > I've seen given relates to devices behind PCI bridges).
> >
> > So, I think the thing we are facing here is that while the IOMMU
> > subsystem has accounted for reprsenting the isolation characteristics
> > of a system with iommu groups, there is no corresponding "msi group"
> > concept.
> >
> > In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > and the GIC-ITS device ID are in fact the same ID.
> 
> The DeviceID is the "MSI group" you mention. This is what provides isolation
> at the ITS level.
> 
[varun] True, in case of a transparent host bridge device Id won't provide the necessary isolation.

> > Is there some way we could sanely correlate IOMMU group creation
> > (which establishes isolation granularity) with the creation of an ITT
> > for the GIC-ITS?
> 
> The problem you have is that your ITT already exists before you start
> "hotpluging" new devices. Take the following (made up) example:
> 
> System boots, device X is discovered, claims 64 MSIs. An ITT for device X is
> allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
> function that is aliased to X, claiming another 64 MSIs. Fail.
> 
> What do we do here? The ITT is live (X is generating interrupts), and there is
> no provision to resize it (I've come up with a horrible scheme, but that could
> fail as well). The only sane option would be to guess how many MSIs a given
> alias could possibly use. How wrong is this guess going to be?
> 
> The problem we have is that IOMMU groups are dynamic, while ITT allocation
> is completely static for a given DeviceID. The architecture doesn't give you
> any mechanism to resize it, and I have the ugly feeling that static allocation of
> the ID space to aliases is too rigid...

[varun] One way would be to restrict the number of stream Ids(device Ids) per PCIe controller. In our scheme we have a device id -> stream ID translation table, we can restrict the number of entries in the table. This would restrict number of virtual functions.

-Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-26 18:20                           ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-26 18:20 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc,

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> Sent: Saturday, April 25, 2015 4:10 PM
> To: Yoder Stuart-B08248
> Cc: Will Deacon; Sethi Varun-B16395; Lian Minghuan-B31939; linux-
> pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911;
> Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Fri, 24 Apr 2015 19:18:44 +0100
> Stuart Yoder <stuart.yoder@freescale.com> wrote:
> 
> Hi Stuart,
> 
> >
> >
> > > -----Original Message-----
> > > From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> > > Sent: Friday, April 24, 2015 11:44 AM
> > > To: Will Deacon; Yoder Stuart-B08248
> > > Cc: Sethi Varun-B16395; Lian Minghuan-B31939;
> > > linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> > > Roy-R61911; Bjorn Helgaas; Wood Scott-B07421;
> > > linux-arm-kernel at lists.infradead.org
> > > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > >
> > > On 24/04/15 17:18, Will Deacon wrote:
> > > > On Wed, Apr 22, 2015 at 08:41:02PM +0100, Stuart Yoder wrote:
> > > >>>> However, there is an improvement we envision as possible due to
> > > >>>> the limited number of SMMU contexts (i.e. 64).  If there are
> > > >>>> 64 SMMU context registers it means that there is a max of
> > > >>>> 64 software contexts where things can be isolated.  But, say I
> > > >>>> have an SRIOV card with 64 VFs, and I want to assign 8 of the
> > > >>>> VFs to a KVM VM.  Those 8 PCI devices could share the same
> > > >>>> streamID/ITS-device-ID since they all share the same isolation
> > > >>>> context.
> > > >>>>
> > > >>>> What would be nice is at the time the 8 VFS are being added to
> > > >>>> the IOMMU domain is for the pcidevid -> streamID mapping table
> > > >>>> to be updated dynamically.  It simply lets us make more
> > > >>>> efficient use of the limited streamIDs we have.
> > > >>>>
> > > >>>> I think it is this improvement that Minghuan had in mind in
> > > >>>> this patch.
> > > >>>
> > > >>> Ok, but in this case it should be possible to use a single
> > > >>> context bank for all of the VF streamIDs by configuring the
> appropriate SMR, no?
> > > >>
> > > >> Yes, but there are limited SMRs.  In our case there are only
> > > >> 128 SMRs in SMMU-500 and we have potentially way more masters
> > > >> than that.
> > > >
> > > > Right, but you still only have 64 context banks at the end of the
> > > > day, so do you really anticipate having more than 128 masters
> > > > concurrently using the SMMU? If so, then we have devices sharing
> > > > context banks so we could consider reusing SMRs across masters,
> > > > but historically that's not been something that we've managed to solve.
> > > >
> > > >>> Wouldn't
> > > >>> that sort of thing be preferable to dynamic StreamID assignment?
> > > >>> It would certainly make life easier for the MSIs.
> > > >>
> > > >> It would be preferable, but given only 128 total stream IDS and
> > > >> 64 context registers it's potentially an issue.  On our LS2085
> > > >> SoC it is PCI and the fsl-mc bus (see description here:
> > > >> https://lkml.org/lkml/2015/3/5/795) that potentially have way
> > > >> more masters than streamIDS. So, for those busses we would
> > > >> essentially view a streamID as a "context ID"-- each SMR is
> > > >> associated with
> > > >> 1 context bank register.
> > > >>
> > > >> For PCI we have a programmable "PCI req ID"-to-"stream ID"
> > > >> mapping table in the PCI controller that is dynamically
> > > >> programmable.
> > > >>
> > > >> Looking at it like that means that we could have any number of
> > > >> masters but only 64 "contexts"
> > > >> and since the masters all all programmable it's seems feasbile to
> > > >> envision doing some bus/vendor specific set up when a device is
> > > >> added to an
> > > >> IOMMU domain.   One thing that would need to be conveyed
> > > >> to the SMMU driver if doing dynamic streamID setup is what
> > > >> streamIDs are available to be used.
> > > >
> > > > Ok, but this is going to make life difficult for the MSI people, I suspect.
> > > >
> > > > Marc...?
> > >
> > > We're really facing two conflicting requirements: in order to
> > > minimize SMR usage, we want to alias multiple ReqIDs to a single
> > > StreamID
> >
> > Another reason could be the isolation characteristics of the
> > hardware...see comment below about PCI bridges.
> >
> > > but in
> > > order to efficiently deal with MSIs, we want to see discrete
> > > DeviceIDs (the actual ReqIDs). I don't easily see how we reconcile the
> two.
> > >
> > > We can deal with the aliasing, provided that we extend the level of
> > > quirkiness that pci_for_each_dma_alias can deal with. But that
> > > doesn't solve any form of hotplug/SR-IOV behaviour.
> > >
[varun] Can you please elaborate on "extending the quirkiness of pci_for_each_dma_alias". How do you see the case for transparent host bridege being handled? We would see a device ID corresponding to the host bridge for masters behind that bridge.

> > > Somehow, we're going to end-up with grossly oversized ITTs, just to
> > > accommodate for the fact that we have no idea how many MSIs we're
> > > going to end-up needing. I'm not thrilled with that prospect.
> >
> > How can we avoid that in the face of hotplug?
> 
> Fortunately, hotplug is not always synonymous of aliasing. The ITS is built
> around the hypothesis that aliasing doesn't happen, and that you know
> upfront how many LPIs the device will be allowed to generate.
> 
> > And what are we really worried about regarding over-sized ITTs...bytes
> > of memory saved?
> 
> That's one thing, yes. But more fundamentally, how do you size your MSI
> capacity for a single alias? Do you evenly split your LPI space among all
> possible aliases? Assuming 64 aliases and 16 bits of interrupt ID space, you
> end up with 10 bit per alias. Is that always enough? Or do you need
> something more fine-grained?
> 
> > A fundamental thing built into the IOMMU subsystem in Linux is
> > representing iommu groups that can represent things like multiple PCI
> > devices that for hardware reasons cannot be isolated (and the example
> > I've seen given relates to devices behind PCI bridges).
> >
> > So, I think the thing we are facing here is that while the IOMMU
> > subsystem has accounted for reprsenting the isolation characteristics
> > of a system with iommu groups, there is no corresponding "msi group"
> > concept.
> >
> > In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > and the GIC-ITS device ID are in fact the same ID.
> 
> The DeviceID is the "MSI group" you mention. This is what provides isolation
> at the ITS level.
> 
[varun] True, in case of a transparent host bridge device Id won't provide the necessary isolation.

> > Is there some way we could sanely correlate IOMMU group creation
> > (which establishes isolation granularity) with the creation of an ITT
> > for the GIC-ITS?
> 
> The problem you have is that your ITT already exists before you start
> "hotpluging" new devices. Take the following (made up) example:
> 
> System boots, device X is discovered, claims 64 MSIs. An ITT for device X is
> allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
> function that is aliased to X, claiming another 64 MSIs. Fail.
> 
> What do we do here? The ITT is live (X is generating interrupts), and there is
> no provision to resize it (I've come up with a horrible scheme, but that could
> fail as well). The only sane option would be to guess how many MSIs a given
> alias could possibly use. How wrong is this guess going to be?
> 
> The problem we have is that IOMMU groups are dynamic, while ITT allocation
> is completely static for a given DeviceID. The architecture doesn't give you
> any mechanism to resize it, and I have the ugly feeling that static allocation of
> the ID space to aliases is too rigid...

[varun] One way would be to restrict the number of stream Ids(device Ids) per PCIe controller. In our scheme we have a device id -> stream ID translation table, we can restrict the number of entries in the table. This would restrict number of virtual functions.

-Varun

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-22 19:41                 ` Stuart Yoder
@ 2015-04-26 18:26                   ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-26 18:26 UTC (permalink / raw)
  To: Stuart Yoder, Will Deacon
  Cc: Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu, Roy Zang,
	Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Will/Stuart,

> -----Original Message-----
> From: Yoder Stuart-B08248
> Sent: Thursday, April 23, 2015 1:11 AM
> To: Will Deacon
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci@vger.kernel.org;
> Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood
> Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> 
> 
> > -----Original Message-----
> > From: Will Deacon [mailto:will.deacon@arm.com]
> > Sent: Wednesday, April 22, 2015 12:07 PM
> > To: Yoder Stuart-B08248
> > Cc: Sethi Varun-B16395; Lian Minghuan-B31939;
> > linux-pci@vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> > Roy-R61911; Bjorn Helgaas; Wood Scott-B07421;
> > linux-arm-kernel@lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Hi Stuart,
> >
> > First of, thanks for taking the time to explain this in more detail.
> > Comments inline.
> >
> > On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > > > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure
> > > > > if TBU ID would also be forwarded as a part of stream id to GIC.
> > > > > My understanding is that TBU ID is forwarded (as a part of the
> > > > > stream ID) to the TCU in case of a TBU translation miss. In case
> > > > > of the LS2085 PCIe controller you would have to setup the PCIe
> > > > > device ID to stream ID translation table. We may have to
> > > > > restrict the number of entries based on the available number of
> contexts.
> > > >
> > > > Unfortunately, I'm having a really hard time parsing this thread
> > > > (some parts of it simply don't make sense; others use
> > > > non-architectural terms and overall I don't get a feeling for the
> problem).
> > > >
> > > > Please could you explain your system design step by step so that I
> > > > can understand (a) what you've built and (b) why the current
> > > > design of Linux is causing you problems?
> > > >
> > > > Sorry if I'm just being thick, but it's important that we get this right.
> > >
> > > I'll try to summarize some key points about the system...
> > >
> > > System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.
> > > There are PCI, fsl-mc, and platform devices that do DMA.  Devices on
> > > the PCI and fsl-mc bus generate message interrupts.
> >
> > Ah cool, so you have multiple buses sharing a single SMMU? That's
> > going to necessitate some ID remapping in the device-tree. Perhaps you
> > could comment on Mark Rutland's proposal if it does/doesn't work for you:
> >
> >
> > http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/33319
> > 9.html
> 
> Thanks for the pointer, I had not seen that before.  Will read and comment
> on it.
> 
> > > The flow a message interrupt would take is this:
> > >
> > >     --------------
> > >       PCI device
> > >     --------------
> > >           |
> > >           | pcidevid + MSI msg
> > >           |
> > >           V
> > >     --------------
> > >     PCI controller
> > >       pcidevid ->
> > >       streamID
> > >       mapping
> > >     --------------
> > >           |
> > >           | streamID + MSI msg
> > >           |
> > >           V
> > >     --------------
> > >         SMMU
> > >     --------------
> > >           |
> > >           | streamID + MSI msg
> > >           |
> > >           V
> > >     --------------
> > >        CCN-504 (Dickens)
> > >     --------------
> > >           |
> > >           | streamID + MSI msg
> > >           |
> > >           V
> >
> > The streamID here as the same as the one coming out of the SMMU, right?
> 
> Yes.
> 
> > (just trying to out why you have the CCN-504 in the picture).
> 
> It really isn't relevant I guess, just the picture I had in my head.
> 
> > >     --------------
> > >       GICv3 ITS    streamID == ITS deviceID
> > >     --------------
> > >
> > > So, the way things work (at least initially) is that each PCI device
> > > maps to a single streamID, and thus each device has a separate ITT
> > > in the ITS.  So, things should be cool.
> > >
> > > However, there is an improvement we envision as possible due to the
> > > limited number of SMMU contexts (i.e. 64).  If there are
> > > 64 SMMU context registers it means that there is a max of
> > > 64 software contexts where things can be isolated.  But, say I have
> > > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs to a
> > > KVM VM.  Those 8 PCI devices could share the same
> > > streamID/ITS-device-ID since they all share the same isolation
> > > context.
> > >
> > > What would be nice is at the time the 8 VFS are being added to the
> > > IOMMU domain is for the pcidevid -> streamID mapping table to be
> > > updated dynamically.  It simply lets us make more efficient use of
> > > the limited streamIDs we have.
> > >
> > > I think it is this improvement that Minghuan had in mind in this
> > > patch.
> >
> > Ok, but in this case it should be possible to use a single context
> > bank for all of the VF streamIDs by configuring the appropriate SMR, no?
> 
> Yes, but there are limited SMRs.  In our case there are only
> 128 SMRs in SMMU-500 and we have potentially way more masters than
> that.
> 
> > Wouldn't
> > that sort of thing be preferable to dynamic StreamID assignment? It
> > would certainly make life easier for the MSIs.
> 
> It would be preferable, but given only 128 total stream IDS and
> 64 context registers it's potentially an issue.  On our LS2085 SoC it is PCI and
> the fsl-mc bus (see description here:
> https://lkml.org/lkml/2015/3/5/795) that potentially have way more masters
> than streamIDS. So, for those busses we would essentially view a streamID
> as a "context ID"-- each SMR is associated with
> 1 context bank register.
> 
[varun]  On thing to note here is that we would also be hooking up DMA API with the SMMU driver. In that case we would typically require one context per device. We would have to restrict the number of available stream IDs.

-Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-26 18:26                   ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-26 18:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Will/Stuart,

> -----Original Message-----
> From: Yoder Stuart-B08248
> Sent: Thursday, April 23, 2015 1:11 AM
> To: Will Deacon
> Cc: Sethi Varun-B16395; Lian Minghuan-B31939; linux-pci at vger.kernel.org;
> Arnd Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood
> Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> 
> 
> > -----Original Message-----
> > From: Will Deacon [mailto:will.deacon at arm.com]
> > Sent: Wednesday, April 22, 2015 12:07 PM
> > To: Yoder Stuart-B08248
> > Cc: Sethi Varun-B16395; Lian Minghuan-B31939;
> > linux-pci at vger.kernel.org; Arnd Bergmann; Hu Mingkai-B21284; Zang
> > Roy-R61911; Bjorn Helgaas; Wood Scott-B07421;
> > linux-arm-kernel at lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> >
> > Hi Stuart,
> >
> > First of, thanks for taking the time to explain this in more detail.
> > Comments inline.
> >
> > On Fri, Apr 17, 2015 at 03:19:08PM +0100, Stuart Yoder wrote:
> > > > On Wed, Apr 15, 2015 at 02:18:13PM +0100, Varun Sethi wrote:
> > > > > Yes, deviceid=stream id (i.e. ICID + other bits). I am not sure
> > > > > if TBU ID would also be forwarded as a part of stream id to GIC.
> > > > > My understanding is that TBU ID is forwarded (as a part of the
> > > > > stream ID) to the TCU in case of a TBU translation miss. In case
> > > > > of the LS2085 PCIe controller you would have to setup the PCIe
> > > > > device ID to stream ID translation table. We may have to
> > > > > restrict the number of entries based on the available number of
> contexts.
> > > >
> > > > Unfortunately, I'm having a really hard time parsing this thread
> > > > (some parts of it simply don't make sense; others use
> > > > non-architectural terms and overall I don't get a feeling for the
> problem).
> > > >
> > > > Please could you explain your system design step by step so that I
> > > > can understand (a) what you've built and (b) why the current
> > > > design of Linux is causing you problems?
> > > >
> > > > Sorry if I'm just being thick, but it's important that we get this right.
> > >
> > > I'll try to summarize some key points about the system...
> > >
> > > System is using a single SMMU-500 (1 TCU, 6 TBUs) and GICv3-ITS.
> > > There are PCI, fsl-mc, and platform devices that do DMA.  Devices on
> > > the PCI and fsl-mc bus generate message interrupts.
> >
> > Ah cool, so you have multiple buses sharing a single SMMU? That's
> > going to necessitate some ID remapping in the device-tree. Perhaps you
> > could comment on Mark Rutland's proposal if it does/doesn't work for you:
> >
> >
> > http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/33319
> > 9.html
> 
> Thanks for the pointer, I had not seen that before.  Will read and comment
> on it.
> 
> > > The flow a message interrupt would take is this:
> > >
> > >     --------------
> > >       PCI device
> > >     --------------
> > >           |
> > >           | pcidevid + MSI msg
> > >           |
> > >           V
> > >     --------------
> > >     PCI controller
> > >       pcidevid ->
> > >       streamID
> > >       mapping
> > >     --------------
> > >           |
> > >           | streamID + MSI msg
> > >           |
> > >           V
> > >     --------------
> > >         SMMU
> > >     --------------
> > >           |
> > >           | streamID + MSI msg
> > >           |
> > >           V
> > >     --------------
> > >        CCN-504 (Dickens)
> > >     --------------
> > >           |
> > >           | streamID + MSI msg
> > >           |
> > >           V
> >
> > The streamID here as the same as the one coming out of the SMMU, right?
> 
> Yes.
> 
> > (just trying to out why you have the CCN-504 in the picture).
> 
> It really isn't relevant I guess, just the picture I had in my head.
> 
> > >     --------------
> > >       GICv3 ITS    streamID == ITS deviceID
> > >     --------------
> > >
> > > So, the way things work (at least initially) is that each PCI device
> > > maps to a single streamID, and thus each device has a separate ITT
> > > in the ITS.  So, things should be cool.
> > >
> > > However, there is an improvement we envision as possible due to the
> > > limited number of SMMU contexts (i.e. 64).  If there are
> > > 64 SMMU context registers it means that there is a max of
> > > 64 software contexts where things can be isolated.  But, say I have
> > > an SRIOV card with 64 VFs, and I want to assign 8 of the VFs to a
> > > KVM VM.  Those 8 PCI devices could share the same
> > > streamID/ITS-device-ID since they all share the same isolation
> > > context.
> > >
> > > What would be nice is at the time the 8 VFS are being added to the
> > > IOMMU domain is for the pcidevid -> streamID mapping table to be
> > > updated dynamically.  It simply lets us make more efficient use of
> > > the limited streamIDs we have.
> > >
> > > I think it is this improvement that Minghuan had in mind in this
> > > patch.
> >
> > Ok, but in this case it should be possible to use a single context
> > bank for all of the VF streamIDs by configuring the appropriate SMR, no?
> 
> Yes, but there are limited SMRs.  In our case there are only
> 128 SMRs in SMMU-500 and we have potentially way more masters than
> that.
> 
> > Wouldn't
> > that sort of thing be preferable to dynamic StreamID assignment? It
> > would certainly make life easier for the MSIs.
> 
> It would be preferable, but given only 128 total stream IDS and
> 64 context registers it's potentially an issue.  On our LS2085 SoC it is PCI and
> the fsl-mc bus (see description here:
> https://lkml.org/lkml/2015/3/5/795) that potentially have way more masters
> than streamIDS. So, for those busses we would essentially view a streamID
> as a "context ID"-- each SMR is associated with
> 1 context bank register.
> 
[varun]  On thing to note here is that we would also be hooking up DMA API with the SMMU driver. In that case we would typically require one context per device. We would have to restrict the number of available stream IDs.

-Varun

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-26 18:20                           ` Varun Sethi
@ 2015-04-27  7:58                             ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-27  7:58 UTC (permalink / raw)
  To: Varun Sethi, Stuart Yoder
  Cc: Will Deacon, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Varun,

On 26/04/15 19:20, Varun Sethi wrote:
> Hi Marc,
> 
>>>> We can deal with the aliasing, provided that we extend the level of
>>>> quirkiness that pci_for_each_dma_alias can deal with. But that
>>>> doesn't solve any form of hotplug/SR-IOV behaviour.
>>>>
> [varun] Can you please elaborate on "extending the quirkiness of
> pci_for_each_dma_alias". How do you see the case for transparent host
> bridege being handled? We would see a device ID corresponding to the
> host bridge for masters behind that bridge.

The PCI code already has code to deal with aliases, and can deal with
them in a number of cases.

At the moment, this aliasing code can only deal with aliases that belong
to the same PCI bus (or aliasing with the bus itself). Given the way the
problem has been described, I understand that you can have devices
sitting on different buses that will end up with the same DeviceID. This
is where expanding the "quirkiness" of pci_for_each_dma_alias comes into
play. You need to teach it about this kind of topology.

>>>> Somehow, we're going to end-up with grossly oversized ITTs, just to
>>>> accommodate for the fact that we have no idea how many MSIs we're
>>>> going to end-up needing. I'm not thrilled with that prospect.
>>>
>>> How can we avoid that in the face of hotplug?
>>
>> Fortunately, hotplug is not always synonymous of aliasing. The ITS is built
>> around the hypothesis that aliasing doesn't happen, and that you know
>> upfront how many LPIs the device will be allowed to generate.
>>
>>> And what are we really worried about regarding over-sized ITTs...bytes
>>> of memory saved?
>>
>> That's one thing, yes. But more fundamentally, how do you size your MSI
>> capacity for a single alias? Do you evenly split your LPI space among all
>> possible aliases? Assuming 64 aliases and 16 bits of interrupt ID space, you
>> end up with 10 bit per alias. Is that always enough? Or do you need
>> something more fine-grained?
>>
>>> A fundamental thing built into the IOMMU subsystem in Linux is
>>> representing iommu groups that can represent things like multiple PCI
>>> devices that for hardware reasons cannot be isolated (and the example
>>> I've seen given relates to devices behind PCI bridges).
>>>
>>> So, I think the thing we are facing here is that while the IOMMU
>>> subsystem has accounted for reprsenting the isolation characteristics
>>> of a system with iommu groups, there is no corresponding "msi group"
>>> concept.
>>>
>>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
>>> and the GIC-ITS device ID are in fact the same ID.
>>
>> The DeviceID is the "MSI group" you mention. This is what provides isolation
>> at the ITS level.
>>
> [varun] True, in case of a transparent host bridge device Id won't
> provide the necessary isolation.

Well, it depends how you look at it. How necessary is this isolation,
since we've already established that you couldn't distinguish between
these devices at the IOMMU level?

>>> Is there some way we could sanely correlate IOMMU group creation
>>> (which establishes isolation granularity) with the creation of an ITT
>>> for the GIC-ITS?
>>
>> The problem you have is that your ITT already exists before you start
>> "hotpluging" new devices. Take the following (made up) example:
>>
>> System boots, device X is discovered, claims 64 MSIs. An ITT for device X is
>> allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
>> function that is aliased to X, claiming another 64 MSIs. Fail.
>>
>> What do we do here? The ITT is live (X is generating interrupts), and there is
>> no provision to resize it (I've come up with a horrible scheme, but that could
>> fail as well). The only sane option would be to guess how many MSIs a given
>> alias could possibly use. How wrong is this guess going to be?
>>
>> The problem we have is that IOMMU groups are dynamic, while ITT allocation
>> is completely static for a given DeviceID. The architecture doesn't give you
>> any mechanism to resize it, and I have the ugly feeling that static allocation of
>> the ID space to aliases is too rigid...
> 
> [varun] One way would be to restrict the number of stream Ids(device
> Ids) per PCIe controller. In our scheme we have a device id -> stream
> ID translation table, we can restrict the number of entries in the
> table. This would restrict number of virtual functions.

Do you mean reserving a number of StreamIDs per PCIe controller, and
letting virtual functions use these spare StreamIDs? This would indeed
be more restrictive. But more importantly, who is going to be in charge
of this mapping/allocation?

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-27  7:58                             ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-27  7:58 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Varun,

On 26/04/15 19:20, Varun Sethi wrote:
> Hi Marc,
> 
>>>> We can deal with the aliasing, provided that we extend the level of
>>>> quirkiness that pci_for_each_dma_alias can deal with. But that
>>>> doesn't solve any form of hotplug/SR-IOV behaviour.
>>>>
> [varun] Can you please elaborate on "extending the quirkiness of
> pci_for_each_dma_alias". How do you see the case for transparent host
> bridege being handled? We would see a device ID corresponding to the
> host bridge for masters behind that bridge.

The PCI code already has code to deal with aliases, and can deal with
them in a number of cases.

At the moment, this aliasing code can only deal with aliases that belong
to the same PCI bus (or aliasing with the bus itself). Given the way the
problem has been described, I understand that you can have devices
sitting on different buses that will end up with the same DeviceID. This
is where expanding the "quirkiness" of pci_for_each_dma_alias comes into
play. You need to teach it about this kind of topology.

>>>> Somehow, we're going to end-up with grossly oversized ITTs, just to
>>>> accommodate for the fact that we have no idea how many MSIs we're
>>>> going to end-up needing. I'm not thrilled with that prospect.
>>>
>>> How can we avoid that in the face of hotplug?
>>
>> Fortunately, hotplug is not always synonymous of aliasing. The ITS is built
>> around the hypothesis that aliasing doesn't happen, and that you know
>> upfront how many LPIs the device will be allowed to generate.
>>
>>> And what are we really worried about regarding over-sized ITTs...bytes
>>> of memory saved?
>>
>> That's one thing, yes. But more fundamentally, how do you size your MSI
>> capacity for a single alias? Do you evenly split your LPI space among all
>> possible aliases? Assuming 64 aliases and 16 bits of interrupt ID space, you
>> end up with 10 bit per alias. Is that always enough? Or do you need
>> something more fine-grained?
>>
>>> A fundamental thing built into the IOMMU subsystem in Linux is
>>> representing iommu groups that can represent things like multiple PCI
>>> devices that for hardware reasons cannot be isolated (and the example
>>> I've seen given relates to devices behind PCI bridges).
>>>
>>> So, I think the thing we are facing here is that while the IOMMU
>>> subsystem has accounted for reprsenting the isolation characteristics
>>> of a system with iommu groups, there is no corresponding "msi group"
>>> concept.
>>>
>>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
>>> and the GIC-ITS device ID are in fact the same ID.
>>
>> The DeviceID is the "MSI group" you mention. This is what provides isolation
>> at the ITS level.
>>
> [varun] True, in case of a transparent host bridge device Id won't
> provide the necessary isolation.

Well, it depends how you look at it. How necessary is this isolation,
since we've already established that you couldn't distinguish between
these devices at the IOMMU level?

>>> Is there some way we could sanely correlate IOMMU group creation
>>> (which establishes isolation granularity) with the creation of an ITT
>>> for the GIC-ITS?
>>
>> The problem you have is that your ITT already exists before you start
>> "hotpluging" new devices. Take the following (made up) example:
>>
>> System boots, device X is discovered, claims 64 MSIs. An ITT for device X is
>> allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
>> function that is aliased to X, claiming another 64 MSIs. Fail.
>>
>> What do we do here? The ITT is live (X is generating interrupts), and there is
>> no provision to resize it (I've come up with a horrible scheme, but that could
>> fail as well). The only sane option would be to guess how many MSIs a given
>> alias could possibly use. How wrong is this guess going to be?
>>
>> The problem we have is that IOMMU groups are dynamic, while ITT allocation
>> is completely static for a given DeviceID. The architecture doesn't give you
>> any mechanism to resize it, and I have the ugly feeling that static allocation of
>> the ID space to aliases is too rigid...
> 
> [varun] One way would be to restrict the number of stream Ids(device
> Ids) per PCIe controller. In our scheme we have a device id -> stream
> ID translation table, we can restrict the number of entries in the
> table. This would restrict number of virtual functions.

Do you mean reserving a number of StreamIDs per PCIe controller, and
letting virtual functions use these spare StreamIDs? This would indeed
be more restrictive. But more importantly, who is going to be in charge
of this mapping/allocation?

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-27  7:58                             ` Marc Zyngier
@ 2015-04-27 13:08                               ` Varun Sethi
  -1 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-27 13:08 UTC (permalink / raw)
  To: Marc Zyngier, Stuart Yoder
  Cc: Will Deacon, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel

Hi Marc,

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier@arm.com]
> Sent: Monday, April 27, 2015 1:28 PM
> To: Sethi Varun-B16395; Yoder Stuart-B08248
> Cc: Will Deacon; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd
> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-
> B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Varun,
> 
> On 26/04/15 19:20, Varun Sethi wrote:
> > Hi Marc,
> >
> >>>> We can deal with the aliasing, provided that we extend the level of
> >>>> quirkiness that pci_for_each_dma_alias can deal with. But that
> >>>> doesn't solve any form of hotplug/SR-IOV behaviour.
> >>>>
> > [varun] Can you please elaborate on "extending the quirkiness of
> > pci_for_each_dma_alias". How do you see the case for transparent host
> > bridege being handled? We would see a device ID corresponding to the
> > host bridge for masters behind that bridge.
> 
> The PCI code already has code to deal with aliases, and can deal with them in
> a number of cases.
> 
> At the moment, this aliasing code can only deal with aliases that belong to
> the same PCI bus (or aliasing with the bus itself). Given the way the problem
> has been described, I understand that you can have devices sitting on
> different buses that will end up with the same DeviceID. This is where
> expanding the "quirkiness" of pci_for_each_dma_alias comes into play. You
> need to teach it about this kind of topology.
> 
[varun] Agreed, in our case the PCIe controller maintains a stream ID to device ID  translation table. So, we can actually avoid this problem by setting up unique stream IDs across PCIe controllers. We would need a layer to allow translation from device id to stream ID.

> >>>> Somehow, we're going to end-up with grossly oversized ITTs, just to
> >>>> accommodate for the fact that we have no idea how many MSIs we're
> >>>> going to end-up needing. I'm not thrilled with that prospect.
> >>>
> >>> How can we avoid that in the face of hotplug?
> >>
> >> Fortunately, hotplug is not always synonymous of aliasing. The ITS is
> >> built around the hypothesis that aliasing doesn't happen, and that
> >> you know upfront how many LPIs the device will be allowed to generate.
> >>
> >>> And what are we really worried about regarding over-sized
> >>> ITTs...bytes of memory saved?
> >>
> >> That's one thing, yes. But more fundamentally, how do you size your
> >> MSI capacity for a single alias? Do you evenly split your LPI space
> >> among all possible aliases? Assuming 64 aliases and 16 bits of
> >> interrupt ID space, you end up with 10 bit per alias. Is that always
> >> enough? Or do you need something more fine-grained?
> >>
> >>> A fundamental thing built into the IOMMU subsystem in Linux is
> >>> representing iommu groups that can represent things like multiple
> >>> PCI devices that for hardware reasons cannot be isolated (and the
> >>> example I've seen given relates to devices behind PCI bridges).
> >>>
> >>> So, I think the thing we are facing here is that while the IOMMU
> >>> subsystem has accounted for reprsenting the isolation
> >>> characteristics of a system with iommu groups, there is no corresponding
> "msi group"
> >>> concept.
> >>>
> >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> >>> and the GIC-ITS device ID are in fact the same ID.
> >>
> >> The DeviceID is the "MSI group" you mention. This is what provides
> >> isolation at the ITS level.
> >>
> > [varun] True, in case of a transparent host bridge device Id won't
> > provide the necessary isolation.
> 
> Well, it depends how you look at it. How necessary is this isolation, since
> we've already established that you couldn't distinguish between these
> devices at the IOMMU level?
> 
[varun] Yes, the devices would fall in the same IOMMU group. So, devices would end up sharing the interrupt?

> >>> Is there some way we could sanely correlate IOMMU group creation
> >>> (which establishes isolation granularity) with the creation of an
> >>> ITT for the GIC-ITS?
> >>
> >> The problem you have is that your ITT already exists before you start
> >> "hotpluging" new devices. Take the following (made up) example:
> >>
> >> System boots, device X is discovered, claims 64 MSIs. An ITT for
> >> device X is allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
> >> function that is aliased to X, claiming another 64 MSIs. Fail.
> >>
> >> What do we do here? The ITT is live (X is generating interrupts), and
> >> there is no provision to resize it (I've come up with a horrible
> >> scheme, but that could fail as well). The only sane option would be
> >> to guess how many MSIs a given alias could possibly use. How wrong is
> this guess going to be?
> >>
> >> The problem we have is that IOMMU groups are dynamic, while ITT
> >> allocation is completely static for a given DeviceID. The
> >> architecture doesn't give you any mechanism to resize it, and I have
> >> the ugly feeling that static allocation of the ID space to aliases is too rigid...
> >
> > [varun] One way would be to restrict the number of stream Ids(device
> > Ids) per PCIe controller. In our scheme we have a device id -> stream
> > ID translation table, we can restrict the number of entries in the
> > table. This would restrict number of virtual functions.
> 
> Do you mean reserving a number of StreamIDs per PCIe controller, and
> letting virtual functions use these spare StreamIDs? This would indeed be
> more restrictive. But more importantly, who is going to be in charge of this
> mapping/allocation?

[varun] My understanding is that, as per the new IOMMU API (of_xlate) this would be done in the bus driver code, while setting up the IOMMU groups.

-Varun

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-27 13:08                               ` Varun Sethi
  0 siblings, 0 replies; 74+ messages in thread
From: Varun Sethi @ 2015-04-27 13:08 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marc,

> -----Original Message-----
> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
> Sent: Monday, April 27, 2015 1:28 PM
> To: Sethi Varun-B16395; Yoder Stuart-B08248
> Cc: Will Deacon; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd
> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-
> B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> Hi Varun,
> 
> On 26/04/15 19:20, Varun Sethi wrote:
> > Hi Marc,
> >
> >>>> We can deal with the aliasing, provided that we extend the level of
> >>>> quirkiness that pci_for_each_dma_alias can deal with. But that
> >>>> doesn't solve any form of hotplug/SR-IOV behaviour.
> >>>>
> > [varun] Can you please elaborate on "extending the quirkiness of
> > pci_for_each_dma_alias". How do you see the case for transparent host
> > bridege being handled? We would see a device ID corresponding to the
> > host bridge for masters behind that bridge.
> 
> The PCI code already has code to deal with aliases, and can deal with them in
> a number of cases.
> 
> At the moment, this aliasing code can only deal with aliases that belong to
> the same PCI bus (or aliasing with the bus itself). Given the way the problem
> has been described, I understand that you can have devices sitting on
> different buses that will end up with the same DeviceID. This is where
> expanding the "quirkiness" of pci_for_each_dma_alias comes into play. You
> need to teach it about this kind of topology.
> 
[varun] Agreed, in our case the PCIe controller maintains a stream ID to device ID  translation table. So, we can actually avoid this problem by setting up unique stream IDs across PCIe controllers. We would need a layer to allow translation from device id to stream ID.

> >>>> Somehow, we're going to end-up with grossly oversized ITTs, just to
> >>>> accommodate for the fact that we have no idea how many MSIs we're
> >>>> going to end-up needing. I'm not thrilled with that prospect.
> >>>
> >>> How can we avoid that in the face of hotplug?
> >>
> >> Fortunately, hotplug is not always synonymous of aliasing. The ITS is
> >> built around the hypothesis that aliasing doesn't happen, and that
> >> you know upfront how many LPIs the device will be allowed to generate.
> >>
> >>> And what are we really worried about regarding over-sized
> >>> ITTs...bytes of memory saved?
> >>
> >> That's one thing, yes. But more fundamentally, how do you size your
> >> MSI capacity for a single alias? Do you evenly split your LPI space
> >> among all possible aliases? Assuming 64 aliases and 16 bits of
> >> interrupt ID space, you end up with 10 bit per alias. Is that always
> >> enough? Or do you need something more fine-grained?
> >>
> >>> A fundamental thing built into the IOMMU subsystem in Linux is
> >>> representing iommu groups that can represent things like multiple
> >>> PCI devices that for hardware reasons cannot be isolated (and the
> >>> example I've seen given relates to devices behind PCI bridges).
> >>>
> >>> So, I think the thing we are facing here is that while the IOMMU
> >>> subsystem has accounted for reprsenting the isolation
> >>> characteristics of a system with iommu groups, there is no corresponding
> "msi group"
> >>> concept.
> >>>
> >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> >>> and the GIC-ITS device ID are in fact the same ID.
> >>
> >> The DeviceID is the "MSI group" you mention. This is what provides
> >> isolation at the ITS level.
> >>
> > [varun] True, in case of a transparent host bridge device Id won't
> > provide the necessary isolation.
> 
> Well, it depends how you look at it. How necessary is this isolation, since
> we've already established that you couldn't distinguish between these
> devices at the IOMMU level?
> 
[varun] Yes, the devices would fall in the same IOMMU group. So, devices would end up sharing the interrupt?

> >>> Is there some way we could sanely correlate IOMMU group creation
> >>> (which establishes isolation granularity) with the creation of an
> >>> ITT for the GIC-ITS?
> >>
> >> The problem you have is that your ITT already exists before you start
> >> "hotpluging" new devices. Take the following (made up) example:
> >>
> >> System boots, device X is discovered, claims 64 MSIs. An ITT for
> >> device X is allocated, and sized for 64 LPIs. SR-IOV kick is, creates a new X'
> >> function that is aliased to X, claiming another 64 MSIs. Fail.
> >>
> >> What do we do here? The ITT is live (X is generating interrupts), and
> >> there is no provision to resize it (I've come up with a horrible
> >> scheme, but that could fail as well). The only sane option would be
> >> to guess how many MSIs a given alias could possibly use. How wrong is
> this guess going to be?
> >>
> >> The problem we have is that IOMMU groups are dynamic, while ITT
> >> allocation is completely static for a given DeviceID. The
> >> architecture doesn't give you any mechanism to resize it, and I have
> >> the ugly feeling that static allocation of the ID space to aliases is too rigid...
> >
> > [varun] One way would be to restrict the number of stream Ids(device
> > Ids) per PCIe controller. In our scheme we have a device id -> stream
> > ID translation table, we can restrict the number of entries in the
> > table. This would restrict number of virtual functions.
> 
> Do you mean reserving a number of StreamIDs per PCIe controller, and
> letting virtual functions use these spare StreamIDs? This would indeed be
> more restrictive. But more importantly, who is going to be in charge of this
> mapping/allocation?

[varun] My understanding is that, as per the new IOMMU API (of_xlate) this would be done in the bus driver code, while setting up the IOMMU groups.

-Varun

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-27 13:08                               ` Varun Sethi
@ 2015-04-27 17:04                                 ` Will Deacon
  -1 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-27 17:04 UTC (permalink / raw)
  To: Varun Sethi
  Cc: Marc Zyngier, Stuart Yoder, Minghuan.Lian, linux-pci,
	Arnd Bergmann, Mingkai.Hu, Roy Zang, Bjorn Helgaas, Scott Wood,
	linux-arm-kernel

On Mon, Apr 27, 2015 at 02:08:10PM +0100, Varun Sethi wrote:
> > >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > >>> and the GIC-ITS device ID are in fact the same ID.
> > >>
> > >> The DeviceID is the "MSI group" you mention. This is what provides
> > >> isolation at the ITS level.
> > >>
> > > [varun] True, in case of a transparent host bridge device Id won't
> > > provide the necessary isolation.
> > 
> > Well, it depends how you look at it. How necessary is this isolation, since
> > we've already established that you couldn't distinguish between these
> > devices at the IOMMU level?
> > 
> [varun] Yes, the devices would fall in the same IOMMU group. So, devices
> would end up sharing the interrupt?

Well, I think that's the crux of the issue here. If IOMMU groups are also
needed to relay constraints to the IRQ subsystem, then perhaps we need a
more general notion of device grouping and ID transformations between
the different levels of group hierarchy.

Will

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-27 17:04                                 ` Will Deacon
  0 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-04-27 17:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Apr 27, 2015 at 02:08:10PM +0100, Varun Sethi wrote:
> > >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > >>> and the GIC-ITS device ID are in fact the same ID.
> > >>
> > >> The DeviceID is the "MSI group" you mention. This is what provides
> > >> isolation at the ITS level.
> > >>
> > > [varun] True, in case of a transparent host bridge device Id won't
> > > provide the necessary isolation.
> > 
> > Well, it depends how you look at it. How necessary is this isolation, since
> > we've already established that you couldn't distinguish between these
> > devices at the IOMMU level?
> > 
> [varun] Yes, the devices would fall in the same IOMMU group. So, devices
> would end up sharing the interrupt?

Well, I think that's the crux of the issue here. If IOMMU groups are also
needed to relay constraints to the IRQ subsystem, then perhaps we need a
more general notion of device grouping and ID transformations between
the different levels of group hierarchy.

Will

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-27 13:08                               ` Varun Sethi
@ 2015-04-27 17:17                                 ` Marc Zyngier
  -1 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-27 17:17 UTC (permalink / raw)
  To: Varun Sethi, Stuart Yoder
  Cc: Will Deacon, Minghuan.Lian, linux-pci, Arnd Bergmann, Mingkai.Hu,
	Roy Zang, Bjorn Helgaas, Scott Wood, linux-arm-kernel

On 27/04/15 14:08, Varun Sethi wrote:
> Hi Marc,
> 
>> -----Original Message-----
>> From: Marc Zyngier [mailto:marc.zyngier@arm.com]
>> Sent: Monday, April 27, 2015 1:28 PM
>> To: Sethi Varun-B16395; Yoder Stuart-B08248
>> Cc: Will Deacon; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd
>> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-
>> B07421; linux-arm-kernel@lists.infradead.org
>> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
>>
>> Hi Varun,
>>
>> On 26/04/15 19:20, Varun Sethi wrote:
>>> Hi Marc,
>>>
>>>>>> We can deal with the aliasing, provided that we extend the level of
>>>>>> quirkiness that pci_for_each_dma_alias can deal with. But that
>>>>>> doesn't solve any form of hotplug/SR-IOV behaviour.
>>>>>>
>>> [varun] Can you please elaborate on "extending the quirkiness of
>>> pci_for_each_dma_alias". How do you see the case for transparent host
>>> bridege being handled? We would see a device ID corresponding to the
>>> host bridge for masters behind that bridge.
>>
>> The PCI code already has code to deal with aliases, and can deal with them in
>> a number of cases.
>>
>> At the moment, this aliasing code can only deal with aliases that belong to
>> the same PCI bus (or aliasing with the bus itself). Given the way the problem
>> has been described, I understand that you can have devices sitting on
>> different buses that will end up with the same DeviceID. This is where
>> expanding the "quirkiness" of pci_for_each_dma_alias comes into play. You
>> need to teach it about this kind of topology.
>>
> [varun] Agreed, in our case the PCIe controller maintains a stream ID to device ID  translation table. So, we can actually avoid this problem by setting up unique stream IDs across PCIe controllers. We would need a layer to allow translation from device id to stream ID.
> 
>>>>>> Somehow, we're going to end-up with grossly oversized ITTs, just to
>>>>>> accommodate for the fact that we have no idea how many MSIs we're
>>>>>> going to end-up needing. I'm not thrilled with that prospect.
>>>>>
>>>>> How can we avoid that in the face of hotplug?
>>>>
>>>> Fortunately, hotplug is not always synonymous of aliasing. The ITS is
>>>> built around the hypothesis that aliasing doesn't happen, and that
>>>> you know upfront how many LPIs the device will be allowed to generate.
>>>>
>>>>> And what are we really worried about regarding over-sized
>>>>> ITTs...bytes of memory saved?
>>>>
>>>> That's one thing, yes. But more fundamentally, how do you size your
>>>> MSI capacity for a single alias? Do you evenly split your LPI space
>>>> among all possible aliases? Assuming 64 aliases and 16 bits of
>>>> interrupt ID space, you end up with 10 bit per alias. Is that always
>>>> enough? Or do you need something more fine-grained?
>>>>
>>>>> A fundamental thing built into the IOMMU subsystem in Linux is
>>>>> representing iommu groups that can represent things like multiple
>>>>> PCI devices that for hardware reasons cannot be isolated (and the
>>>>> example I've seen given relates to devices behind PCI bridges).
>>>>>
>>>>> So, I think the thing we are facing here is that while the IOMMU
>>>>> subsystem has accounted for reprsenting the isolation
>>>>> characteristics of a system with iommu groups, there is no corresponding
>> "msi group"
>>>>> concept.
>>>>>
>>>>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
>>>>> and the GIC-ITS device ID are in fact the same ID.
>>>>
>>>> The DeviceID is the "MSI group" you mention. This is what provides
>>>> isolation at the ITS level.
>>>>
>>> [varun] True, in case of a transparent host bridge device Id won't
>>> provide the necessary isolation.
>>
>> Well, it depends how you look at it. How necessary is this isolation, since
>> we've already established that you couldn't distinguish between these
>> devices at the IOMMU level?
>>
> [varun] Yes, the devices would fall in the same IOMMU group. So,
> devices would end up sharing the interrupt?

No, they would end-up sharing an Interrupt Translation Table (ITT),
Basically the equivalent of your page IOMMU page tables, but for
interrupts. Basically, all the devices in this group would have their
own set of interrupts, but would also be able to spoof interrupts for
each others. Probably not a big deal isolation wise, but problematic
from an allocation point of view (given the current way the ITS driver
is architected).

	M.
-- 
Jazz is not dead. It just smells funny...

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-04-27 17:17                                 ` Marc Zyngier
  0 siblings, 0 replies; 74+ messages in thread
From: Marc Zyngier @ 2015-04-27 17:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 27/04/15 14:08, Varun Sethi wrote:
> Hi Marc,
> 
>> -----Original Message-----
>> From: Marc Zyngier [mailto:marc.zyngier at arm.com]
>> Sent: Monday, April 27, 2015 1:28 PM
>> To: Sethi Varun-B16395; Yoder Stuart-B08248
>> Cc: Will Deacon; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd
>> Bergmann; Hu Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-
>> B07421; linux-arm-kernel at lists.infradead.org
>> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
>>
>> Hi Varun,
>>
>> On 26/04/15 19:20, Varun Sethi wrote:
>>> Hi Marc,
>>>
>>>>>> We can deal with the aliasing, provided that we extend the level of
>>>>>> quirkiness that pci_for_each_dma_alias can deal with. But that
>>>>>> doesn't solve any form of hotplug/SR-IOV behaviour.
>>>>>>
>>> [varun] Can you please elaborate on "extending the quirkiness of
>>> pci_for_each_dma_alias". How do you see the case for transparent host
>>> bridege being handled? We would see a device ID corresponding to the
>>> host bridge for masters behind that bridge.
>>
>> The PCI code already has code to deal with aliases, and can deal with them in
>> a number of cases.
>>
>> At the moment, this aliasing code can only deal with aliases that belong to
>> the same PCI bus (or aliasing with the bus itself). Given the way the problem
>> has been described, I understand that you can have devices sitting on
>> different buses that will end up with the same DeviceID. This is where
>> expanding the "quirkiness" of pci_for_each_dma_alias comes into play. You
>> need to teach it about this kind of topology.
>>
> [varun] Agreed, in our case the PCIe controller maintains a stream ID to device ID  translation table. So, we can actually avoid this problem by setting up unique stream IDs across PCIe controllers. We would need a layer to allow translation from device id to stream ID.
> 
>>>>>> Somehow, we're going to end-up with grossly oversized ITTs, just to
>>>>>> accommodate for the fact that we have no idea how many MSIs we're
>>>>>> going to end-up needing. I'm not thrilled with that prospect.
>>>>>
>>>>> How can we avoid that in the face of hotplug?
>>>>
>>>> Fortunately, hotplug is not always synonymous of aliasing. The ITS is
>>>> built around the hypothesis that aliasing doesn't happen, and that
>>>> you know upfront how many LPIs the device will be allowed to generate.
>>>>
>>>>> And what are we really worried about regarding over-sized
>>>>> ITTs...bytes of memory saved?
>>>>
>>>> That's one thing, yes. But more fundamentally, how do you size your
>>>> MSI capacity for a single alias? Do you evenly split your LPI space
>>>> among all possible aliases? Assuming 64 aliases and 16 bits of
>>>> interrupt ID space, you end up with 10 bit per alias. Is that always
>>>> enough? Or do you need something more fine-grained?
>>>>
>>>>> A fundamental thing built into the IOMMU subsystem in Linux is
>>>>> representing iommu groups that can represent things like multiple
>>>>> PCI devices that for hardware reasons cannot be isolated (and the
>>>>> example I've seen given relates to devices behind PCI bridges).
>>>>>
>>>>> So, I think the thing we are facing here is that while the IOMMU
>>>>> subsystem has accounted for reprsenting the isolation
>>>>> characteristics of a system with iommu groups, there is no corresponding
>> "msi group"
>>>>> concept.
>>>>>
>>>>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
>>>>> and the GIC-ITS device ID are in fact the same ID.
>>>>
>>>> The DeviceID is the "MSI group" you mention. This is what provides
>>>> isolation at the ITS level.
>>>>
>>> [varun] True, in case of a transparent host bridge device Id won't
>>> provide the necessary isolation.
>>
>> Well, it depends how you look at it. How necessary is this isolation, since
>> we've already established that you couldn't distinguish between these
>> devices at the IOMMU level?
>>
> [varun] Yes, the devices would fall in the same IOMMU group. So,
> devices would end up sharing the interrupt?

No, they would end-up sharing an Interrupt Translation Table (ITT),
Basically the equivalent of your page IOMMU page tables, but for
interrupts. Basically, all the devices in this group would have their
own set of interrupts, but would also be able to spoof interrupts for
each others. Probably not a big deal isolation wise, but problematic
from an allocation point of view (given the current way the ITS driver
is architected).

	M.
-- 
Jazz is not dead. It just smells funny...

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

* RE: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-04-27 17:04                                 ` Will Deacon
@ 2015-05-01 15:23                                   ` Stuart Yoder
  -1 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-05-01 15:23 UTC (permalink / raw)
  To: Will Deacon, Varun Sethi
  Cc: Marc Zyngier, Minghuan.Lian, linux-pci, Arnd Bergmann,
	Mingkai.Hu, Roy Zang, Bjorn Helgaas, Scott Wood,
	linux-arm-kernel, Alex Williamson



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon@arm.com]
> Sent: Monday, April 27, 2015 12:04 PM
> To: Sethi Varun-B16395
> Cc: Marc Zyngier; Yoder Stuart-B08248; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu
> Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Mon, Apr 27, 2015 at 02:08:10PM +0100, Varun Sethi wrote:
> > > >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > > >>> and the GIC-ITS device ID are in fact the same ID.
> > > >>
> > > >> The DeviceID is the "MSI group" you mention. This is what provides
> > > >> isolation at the ITS level.
> > > >>
> > > > [varun] True, in case of a transparent host bridge device Id won't
> > > > provide the necessary isolation.
> > >
> > > Well, it depends how you look at it. How necessary is this isolation, since
> > > we've already established that you couldn't distinguish between these
> > > devices at the IOMMU level?
> > >
> > [varun] Yes, the devices would fall in the same IOMMU group. So, devices
> > would end up sharing the interrupt?
> 
> Well, I think that's the crux of the issue here. If IOMMU groups are also
> needed to relay constraints to the IRQ subsystem, then perhaps we need a
> more general notion of device grouping and ID transformations between
> the different levels of group hierarchy.

I agree.  Have been thinking about it over the last few days...is is
a matter of renaming what we currently call an "IOMMU group"?   Or,
do we really need to separate general 'device grouping' and 'iommu groups'
in the Linux kernel?

Stuart

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-05-01 15:23                                   ` Stuart Yoder
  0 siblings, 0 replies; 74+ messages in thread
From: Stuart Yoder @ 2015-05-01 15:23 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Will Deacon [mailto:will.deacon at arm.com]
> Sent: Monday, April 27, 2015 12:04 PM
> To: Sethi Varun-B16395
> Cc: Marc Zyngier; Yoder Stuart-B08248; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu
> Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> 
> On Mon, Apr 27, 2015 at 02:08:10PM +0100, Varun Sethi wrote:
> > > >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > > >>> and the GIC-ITS device ID are in fact the same ID.
> > > >>
> > > >> The DeviceID is the "MSI group" you mention. This is what provides
> > > >> isolation at the ITS level.
> > > >>
> > > > [varun] True, in case of a transparent host bridge device Id won't
> > > > provide the necessary isolation.
> > >
> > > Well, it depends how you look at it. How necessary is this isolation, since
> > > we've already established that you couldn't distinguish between these
> > > devices at the IOMMU level?
> > >
> > [varun] Yes, the devices would fall in the same IOMMU group. So, devices
> > would end up sharing the interrupt?
> 
> Well, I think that's the crux of the issue here. If IOMMU groups are also
> needed to relay constraints to the IRQ subsystem, then perhaps we need a
> more general notion of device grouping and ID transformations between
> the different levels of group hierarchy.

I agree.  Have been thinking about it over the last few days...is is
a matter of renaming what we currently call an "IOMMU group"?   Or,
do we really need to separate general 'device grouping' and 'iommu groups'
in the Linux kernel?

Stuart

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

* Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
  2015-05-01 15:23                                   ` Stuart Yoder
@ 2015-05-01 15:26                                     ` Will Deacon
  -1 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-05-01 15:26 UTC (permalink / raw)
  To: Stuart Yoder
  Cc: Varun Sethi, Marc Zyngier, Minghuan.Lian, linux-pci,
	Arnd Bergmann, Mingkai.Hu, Roy Zang, Bjorn Helgaas, Scott Wood,
	linux-arm-kernel, Alex Williamson

On Fri, May 01, 2015 at 04:23:31PM +0100, Stuart Yoder wrote:
> 
> 
> > -----Original Message-----
> > From: Will Deacon [mailto:will.deacon@arm.com]
> > Sent: Monday, April 27, 2015 12:04 PM
> > To: Sethi Varun-B16395
> > Cc: Marc Zyngier; Yoder Stuart-B08248; Lian Minghuan-B31939; linux-pci@vger.kernel.org; Arnd Bergmann; Hu
> > Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel@lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > 
> > On Mon, Apr 27, 2015 at 02:08:10PM +0100, Varun Sethi wrote:
> > > > >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > > > >>> and the GIC-ITS device ID are in fact the same ID.
> > > > >>
> > > > >> The DeviceID is the "MSI group" you mention. This is what provides
> > > > >> isolation at the ITS level.
> > > > >>
> > > > > [varun] True, in case of a transparent host bridge device Id won't
> > > > > provide the necessary isolation.
> > > >
> > > > Well, it depends how you look at it. How necessary is this isolation, since
> > > > we've already established that you couldn't distinguish between these
> > > > devices at the IOMMU level?
> > > >
> > > [varun] Yes, the devices would fall in the same IOMMU group. So, devices
> > > would end up sharing the interrupt?
> > 
> > Well, I think that's the crux of the issue here. If IOMMU groups are also
> > needed to relay constraints to the IRQ subsystem, then perhaps we need a
> > more general notion of device grouping and ID transformations between
> > the different levels of group hierarchy.
> 
> I agree.  Have been thinking about it over the last few days...is is
> a matter of renaming what we currently call an "IOMMU group"?   Or,
> do we really need to separate general 'device grouping' and 'iommu groups'
> in the Linux kernel?

It depends. Right now, the IOMMU drivers are responsible for creating the
IOMMU groups and I don't think that's general enough for what we need in
practice. If we move the group creation to be done as part of the bus, then
that would be the first step in having an abstraction that could be re-used
by the interrupt code imo. It would also move us a step closer to having
a generic device group description for platform-bus devices (i.e. as part
of the devicetree).

I suspect the only way we'll really find out is by prototyping stuff and
sending patches.

Will

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

* [PATCH 1/2] irqchip/gicv3-its: Support share device ID
@ 2015-05-01 15:26                                     ` Will Deacon
  0 siblings, 0 replies; 74+ messages in thread
From: Will Deacon @ 2015-05-01 15:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, May 01, 2015 at 04:23:31PM +0100, Stuart Yoder wrote:
> 
> 
> > -----Original Message-----
> > From: Will Deacon [mailto:will.deacon at arm.com]
> > Sent: Monday, April 27, 2015 12:04 PM
> > To: Sethi Varun-B16395
> > Cc: Marc Zyngier; Yoder Stuart-B08248; Lian Minghuan-B31939; linux-pci at vger.kernel.org; Arnd Bergmann; Hu
> > Mingkai-B21284; Zang Roy-R61911; Bjorn Helgaas; Wood Scott-B07421; linux-arm-kernel at lists.infradead.org
> > Subject: Re: [PATCH 1/2] irqchip/gicv3-its: Support share device ID
> > 
> > On Mon, Apr 27, 2015 at 02:08:10PM +0100, Varun Sethi wrote:
> > > > >>> In the SMMU/GIC-500-ITS world the iommu isolation ID (the stream ID)
> > > > >>> and the GIC-ITS device ID are in fact the same ID.
> > > > >>
> > > > >> The DeviceID is the "MSI group" you mention. This is what provides
> > > > >> isolation at the ITS level.
> > > > >>
> > > > > [varun] True, in case of a transparent host bridge device Id won't
> > > > > provide the necessary isolation.
> > > >
> > > > Well, it depends how you look at it. How necessary is this isolation, since
> > > > we've already established that you couldn't distinguish between these
> > > > devices at the IOMMU level?
> > > >
> > > [varun] Yes, the devices would fall in the same IOMMU group. So, devices
> > > would end up sharing the interrupt?
> > 
> > Well, I think that's the crux of the issue here. If IOMMU groups are also
> > needed to relay constraints to the IRQ subsystem, then perhaps we need a
> > more general notion of device grouping and ID transformations between
> > the different levels of group hierarchy.
> 
> I agree.  Have been thinking about it over the last few days...is is
> a matter of renaming what we currently call an "IOMMU group"?   Or,
> do we really need to separate general 'device grouping' and 'iommu groups'
> in the Linux kernel?

It depends. Right now, the IOMMU drivers are responsible for creating the
IOMMU groups and I don't think that's general enough for what we need in
practice. If we move the group creation to be done as part of the bus, then
that would be the first step in having an abstraction that could be re-used
by the interrupt code imo. It would also move us a step closer to having
a generic device group description for platform-bus devices (i.e. as part
of the devicetree).

I suspect the only way we'll really find out is by prototyping stuff and
sending patches.

Will

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

end of thread, other threads:[~2015-05-01 15:26 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-15  9:49 [PATCH] irqchip/gicv3-its: Decrease page size when needed Minghuan Lian
2015-04-15  9:49 ` Minghuan Lian
2015-04-15  9:49 ` [PATCH 1/2] irqchip/gicv3-its: Support share device ID Minghuan Lian
2015-04-15  9:49   ` Minghuan Lian
2015-04-15 11:08   ` Varun Sethi
2015-04-15 11:08     ` Varun Sethi
2015-04-15 11:38     ` Minghuan.Lian
2015-04-15 11:38       ` Minghuan.Lian at freescale.com
2015-04-15 13:18       ` Varun Sethi
2015-04-15 13:18         ` Varun Sethi
2015-04-16 10:40         ` Will Deacon
2015-04-16 10:40           ` Will Deacon
2015-04-17 14:19           ` Stuart Yoder
2015-04-17 14:19             ` Stuart Yoder
2015-04-17 17:57             ` Varun Sethi
2015-04-17 17:57               ` Varun Sethi
2015-04-22 17:07             ` Will Deacon
2015-04-22 17:07               ` Will Deacon
2015-04-22 18:40               ` Varun Sethi
2015-04-22 18:40                 ` Varun Sethi
2015-04-22 19:41               ` Stuart Yoder
2015-04-22 19:41                 ` Stuart Yoder
2015-04-24 16:18                 ` Will Deacon
2015-04-24 16:18                   ` Will Deacon
2015-04-24 16:44                   ` Marc Zyngier
2015-04-24 16:44                     ` Marc Zyngier
2015-04-24 18:18                     ` Stuart Yoder
2015-04-24 18:18                       ` Stuart Yoder
2015-04-25 10:39                       ` Marc Zyngier
2015-04-25 10:39                         ` Marc Zyngier
2015-04-26 18:20                         ` Varun Sethi
2015-04-26 18:20                           ` Varun Sethi
2015-04-27  7:58                           ` Marc Zyngier
2015-04-27  7:58                             ` Marc Zyngier
2015-04-27 13:08                             ` Varun Sethi
2015-04-27 13:08                               ` Varun Sethi
2015-04-27 17:04                               ` Will Deacon
2015-04-27 17:04                                 ` Will Deacon
2015-05-01 15:23                                 ` Stuart Yoder
2015-05-01 15:23                                   ` Stuart Yoder
2015-05-01 15:26                                   ` Will Deacon
2015-05-01 15:26                                     ` Will Deacon
2015-04-27 17:17                               ` Marc Zyngier
2015-04-27 17:17                                 ` Marc Zyngier
2015-04-24 19:24                     ` Stuart Yoder
2015-04-24 19:24                       ` Stuart Yoder
2015-04-24 18:09                   ` Stuart Yoder
2015-04-24 18:09                     ` Stuart Yoder
2015-04-26 18:26                 ` Varun Sethi
2015-04-26 18:26                   ` Varun Sethi
2015-04-15 16:36   ` Marc Zyngier
2015-04-15 16:36     ` Marc Zyngier
2015-04-16  2:57     ` Minghuan.Lian
2015-04-16  2:57       ` Minghuan.Lian at freescale.com
2015-04-16 10:04       ` Marc Zyngier
2015-04-16 10:04         ` Marc Zyngier
2015-04-16 10:57         ` Minghuan.Lian
2015-04-16 10:57           ` Minghuan.Lian at freescale.com
2015-04-16 11:50           ` Marc Zyngier
2015-04-16 11:50             ` Marc Zyngier
2015-04-16 18:38             ` Varun Sethi
2015-04-16 18:38               ` Varun Sethi
2015-04-17  2:34               ` Minghuan.Lian
2015-04-17  2:34                 ` Minghuan.Lian at freescale.com
2015-04-15  9:49 ` [PATCH 2/2] pci/layerscape: Add LS2085A MSI support Minghuan Lian
2015-04-15  9:49   ` Minghuan Lian
2015-04-15 11:51 ` [PATCH] irqchip/gicv3-its: Decrease page size when needed Jason Cooper
2015-04-15 11:51   ` Jason Cooper
2015-04-15 14:17   ` Marc Zyngier
2015-04-15 14:17     ` Marc Zyngier
2015-04-16  1:15     ` Minghuan.Lian
2015-04-16  1:15       ` Minghuan.Lian at freescale.com
2015-04-15 16:31 ` Marc Zyngier
2015-04-15 16:31   ` Marc Zyngier

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.