Skip to contentSkip to conversation

drivers: irqchip: Allocate alignment addr by ITS_BASER.Page_size

PATCH In review wangwudi 2 participants 5 messages Jul 16, 2022 – Jul 21, 2022

Subsystems (2)
lore
Share & tools
lore

wangwudi

author
#0 lore raw

PATCH 1/1 drivers: irqchip: Allocate alignment addr by ITS_BASER.Page_size

The description of the ITS_BASER.Physical_Address field in the ARM GIC spec is as follows:
"The address must be aligned to the size specified in the Page Size field." The Page_Size field in ITS_BASER might be RO.

Currently, the address is aligned based on the system page_size, not the HW Page_Size field. In some case, this is in contradiction with the spec.

For example:
ITS_BASER.Page_Size indicate 16K, and kernel page size is 4K. If HW need 4K-size memory, the driver may alloc a 4K aligned address. This has been proven in hardware.

Cc Thomas Gleixner <[email protected]>
Cc Marc Zyngier <[email protected]>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +3 -0
index 5ff09de6c48f..0e25e887d45c 100644
@@ -2310,6 +2310,9 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
 		order = get_order(GITS_BASER_PAGES_MAX * psz);
 	}
 
+	if ((psz > PAGE_SIZE) && (PAGE_ORDER_TO_SIZE(order) < psz)) {
+		order = get_order(psz);
+	}
 	page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
 	if (!page)
 		return -ENOMEM;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 6 lines · wangwudi

The description of the ITS_BASER.Physical_Address field in the ARM GIC spec is as follows:
"The address must be aligned to the size specified in the Page Size field." The Page_Size field in ITS_BASER might be RO.

Quoted 7 lines

Currently, the address is aligned based on the system page_size, not the HW Page_Size field. In some case, this is in contradiction with the spec.

For example:
ITS_BASER.Page_Size indicate 16K, and kernel page size is 4K. If HW need 4K-size memory, the driver may alloc a 4K aligned address. This has been proven in hardware.

Ah, interesting bug. Thanks for bringing this up. Can you describe how this occurs? I suspect you are using indirect tables.

Quoted 13 lines
Cc Thomas Gleixner <[email protected]>
Cc Marc Zyngier <[email protected]>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 5ff09de6c48f..0e25e887d45c 100644

drivers/irqchip/irq-gic-v3-its.c static int its_setup_baser(struct its_node *its, struct its_baser *baser, · line 2318

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +3 -0
@@ -2310,6 +2310,9 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
 		order = get_order(GITS_BASER_PAGES_MAX * psz);
 	}
 
+	if ((psz > PAGE_SIZE) && (PAGE_ORDER_TO_SIZE(order) < psz)) {
+		order = get_order(psz);
+	}
 	page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
 	if (!page)
 		return -ENOMEM;

However, I don't see how you end-up with the incorrect value here.

* No indirect table:

	alloc_its_tables():
		order = get_order(baser->psz);

* Indirect tables:

	alloc_its_tables():
		order = get_order(baser->psz);
	its_parse_indirect_baser():
		new_order = *order;
		new_order = max_t(u32, get_order(esz << ids), new_order);

So in both cases, we should end-up with order >= get_order(psz).

Clearly, I'm missing a path, but your commit message doesn't make it obvious. Can you please enlighten me?

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author
#2 lore raw

Hi Marc,

Quoted 11 lines · Marc Zyngier
Quoted 9 lines · wangwudi

The description of the ITS_BASER.Physical_Address field in the ARM GIC spec is as follows:
"The address must be aligned to the size specified in the Page Size field." The Page_Size field in ITS_BASER might be RO.

Currently, the address is aligned based on the system page_size, not the HW Page_Size field. In some case, this is in contradiction with the spec.

Quoted 8 lines
Quoted 4 lines

For example:
ITS_BASER.Page_Size indicate 16K, and kernel page size is 4K. If HW need 4K-size memory, the driver may alloc a 4K aligned address. This has been proven in hardware.

Ah, interesting bug. Thanks for bringing this up. Can you describe how this occurs? I suspect you are using indirect tables.

Sure. In the system, kernel page size is 4K, and ITS_BASER.Page_Size is 16K.

As you suspected, HW used indirect VPE table and indication supports a small number of vpeids, like 2-bits vpeid. So that HW requires only less than 4K- size memory, and 16K aligned base address. But driver alloctes 4K aligend base address.

Quoted 29 lines
Quoted 13 lines
Cc Thomas Gleixner <[email protected]>
Cc Marc Zyngier <[email protected]>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 5ff09de6c48f..0e25e887d45c 100644

drivers/irqchip/irq-gic-v3-its.c static int its_setup_baser(struct its_node *its, struct its_baser *baser, · line 2318

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +3 -0
@@ -2310,6 +2310,9 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
 		order = get_order(GITS_BASER_PAGES_MAX * psz);
 	}
 
+	if ((psz > PAGE_SIZE) && (PAGE_ORDER_TO_SIZE(order) < psz)) {
+		order = get_order(psz);
+	}
 	page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
 	if (!page)
 		return -ENOMEM;

However, I don't see how you end-up with the incorrect value here.

* No indirect table:

	alloc_its_tables():
		order = get_order(baser->psz);
Quoted 8 lines

* Indirect tables:

	alloc_its_tables():
		order = get_order(baser->psz);
	its_parse_indirect_baser():
		new_order = *order;
		new_order = max_t(u32, get_order(esz << ids), new_order);

So in both cases, we should end-up with order >= get_order(psz).

Yes, totally agree.

Quoted 4 lines

Clearly, I'm missing a path, but your commit message doesn't make it obvious. Can you please enlighten me?

My commit is based on the premise:
"alloc_pages_node gives a size-aligend address".
For example, if HW apply for 4K-size memory, then allocated address is 4K aligned.

Quoted 4 lines

Thanks,

	M.
maintainer
#3 lore raw
Quoted 24 lines · wangwudi

Hi Marc,

Quoted 11 lines · Marc Zyngier
Quoted 9 lines · wangwudi

The description of the ITS_BASER.Physical_Address field in the ARM GIC spec is as follows:
"The address must be aligned to the size specified in the Page Size field." The Page_Size field in ITS_BASER might be RO.

Currently, the address is aligned based on the system page_size, not the HW Page_Size field. In some case, this is in contradiction with the spec.

Quoted 8 lines
Quoted 4 lines

For example:
ITS_BASER.Page_Size indicate 16K, and kernel page size is 4K. If HW need 4K-size memory, the driver may alloc a 4K aligned address. This has been proven in hardware.

Ah, interesting bug. Thanks for bringing this up. Can you describe how this occurs? I suspect you are using indirect tables.

Quoted 6 lines

Sure. In the system, kernel page size is 4K, and ITS_BASER.Page_Size is 16K.

As you suspected, HW used indirect VPE table and indication supports a small number of vpeids, like 2-bits vpeid. So that HW requires only less than 4K- size memory, and 16K aligned base address. But driver alloctes 4K aligend base address.

Well, that I dispute, see below.

Quoted 37 lines
Quoted 37 lines
Quoted 14 lines
Cc Thomas Gleixner <[email protected]>
Cc Marc Zyngier <[email protected]>
---
 drivers/irqchip/irq-gic-v3-its.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 5ff09de6c48f..0e25e887d45c 100644

drivers/irqchip/irq-gic-v3-its.c static int its_setup_baser(struct its_node *its, struct its_baser *baser, · line 2318

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +3 -0
@@ -2310,6 +2310,9 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
 		order = get_order(GITS_BASER_PAGES_MAX * psz);
 	}
 
+	if ((psz > PAGE_SIZE) && (PAGE_ORDER_TO_SIZE(order) < psz)) {
+		order = get_order(psz);
+	}
 	page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
 	if (!page)
 		return -ENOMEM;

However, I don't see how you end-up with the incorrect value here.

* No indirect table:

	alloc_its_tables():
		order = get_order(baser->psz);

* Indirect tables:

	alloc_its_tables():
		order = get_order(baser->psz);
	its_parse_indirect_baser():
		new_order = *order;
		new_order = max_t(u32, get_order(esz << ids), new_order);
Quoted 2 lines
Quoted 1 line

So in both cases, we should end-up with order >= get_order(psz).

Yes, totally agree.

OK. So what does your patch actually fixes?

Quoted 9 lines
Quoted 5 lines

Clearly, I'm missing a path, but your commit message doesn't make it obvious. Can you please enlighten me?

My commit is based on the premise:
"alloc_pages_node gives a size-aligend address".
For example, if HW apply for 4K-size memory, then allocated address is 4K aligned.

Right. And if baser->psz is 16K, the memory returned will be 16K aligned.

The only thing I can imagine is that there is a code path that doesn't use baser->psz as the minimum value when allocating memory programmed into a ITS_BASER register. But I can't see that path. Can you?

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author
#4 lore raw
Quoted 75 lines · Marc Zyngier
Quoted 20 lines · wangwudi

Hi Marc,

Quoted 10 lines · Marc Zyngier
Quoted 8 lines · wangwudi

The description of the ITS_BASER.Physical_Address field in the ARM GIC spec is as follows:
"The address must be aligned to the size specified in the Page Size field." The Page_Size field in ITS_BASER might be RO.

Currently, the address is aligned based on the system page_size, not the HW Page_Size field. In some case, this is in contradiction with the spec.

Quoted 7 lines
Quoted 4 lines

For example:
ITS_BASER.Page_Size indicate 16K, and kernel page size is 4K. If HW need 4K-size memory, the driver may alloc a 4K aligned address. This has been proven in hardware.

Ah, interesting bug. Thanks for bringing this up. Can you describe how this occurs? I suspect you are using indirect tables.

Quoted 6 lines

Sure. In the system, kernel page size is 4K, and ITS_BASER.Page_Size is 16K.

As you suspected, HW used indirect VPE table and indication supports a small number of vpeids, like 2-bits vpeid. So that HW requires only less than 4K- size memory, and 16K aligned base address. But driver alloctes 4K aligend base address.

Well, that I dispute, see below.

Quoted 34 lines
Quoted 34 lines
Quoted 12 lines
Cc Thomas Gleixner <[email protected]>
Cc Marc Zyngier <[email protected]>
---
  drivers/irqchip/irq-gic-v3-its.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v3-its.c +0 -0
index 5ff09de6c48f..0e25e887d45c 100644

drivers/irqchip/irq-gic-v3-its.c static int its_setup_baser(struct its_node *its, struct its_baser *baser, · line 2318

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +3 -0
@@ -2310,6 +2310,9 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
  		order = get_order(GITS_BASER_PAGES_MAX * psz);
  	}
 
+	if ((psz > PAGE_SIZE) && (PAGE_ORDER_TO_SIZE(order) < psz)) {
+		order = get_order(psz);
+	}
  	page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
  	if (!page)
  		return -ENOMEM;

However, I don't see how you end-up with the incorrect value here.

* No indirect table:

	alloc_its_tables():
		order = get_order(baser->psz);

* Indirect tables:

	alloc_its_tables():
		order = get_order(baser->psz);
	its_parse_indirect_baser():
		new_order = *order;
		new_order = max_t(u32, get_order(esz << ids), new_order);
Quoted 2 lines
Quoted 1 line

So in both cases, we should end-up with order >= get_order(psz).

Yes, totally agree.

OK. So what does your patch actually fixes?

Quoted 7 lines
Quoted 3 lines

Clearly, I'm missing a path, but your commit message doesn't make it obvious. Can you please enlighten me?

My commit is based on the premise:
"alloc_pages_node gives a size-aligend address".
For example, if HW apply for 4K-size memory, then allocated address is 4K aligned.

Quoted 8 lines

Right. And if baser->psz is 16K, the memory returned will be 16K aligned.

The only thing I can imagine is that there is a code path that doesn't use baser->psz as the minimum value when allocating memory programmed into a ITS_BASER register. But I can't see that path. Can you?

	M.

Thank you for your reply. Yes, the path doesn't exist.

I'm sorry I made a mistake, I reviewed the process and found that my commit

was based on a wrong code.