All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] irqchip/gicv3: iterate over possible CPUs by for_each_possible_cpu()
@ 2017-09-14  5:15 zijun_hu
  2017-09-14 19:20 ` Marc Zyngier
  0 siblings, 1 reply; 4+ messages in thread
From: zijun_hu @ 2017-09-14  5:15 UTC (permalink / raw)
  To: tglx, jason, marc.zyngier, james.morse, sudeep.holla
  Cc: linux-kernel, zijun_hu

From: zijun_hu <zijun_hu@htc.com>

get_cpu_number() doesn't use existing helper to iterate over possible
CPUs, so error happens in case of discontinuous @cpu_possible_mask
such as 0b11110001.

fixed by using existing helper for_each_possible_cpu().

Signed-off-by: zijun_hu <zijun_hu@htc.com>
---
 drivers/irqchip/irq-gic-v3.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index 19d642eae096..2a0427c2971e 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -990,7 +990,7 @@ static int get_cpu_number(struct device_node *dn)
 {
 	const __be32 *cell;
 	u64 hwid;
-	int i;
+	int cpu;
 
 	cell = of_get_property(dn, "reg", NULL);
 	if (!cell)
@@ -1004,9 +1004,9 @@ static int get_cpu_number(struct device_node *dn)
 	if (hwid & ~MPIDR_HWID_BITMASK)
 		return -1;
 
-	for (i = 0; i < num_possible_cpus(); i++)
-		if (cpu_logical_map(i) == hwid)
-			return i;
+	for_each_possible_cpu(cpu)
+		if (cpu_logical_map(cpu) == hwid)
+			return cpu;
 
 	return -1;
 }
-- 
1.9.1

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

* Re: [PATCH 1/1] irqchip/gicv3: iterate over possible CPUs by for_each_possible_cpu()
  2017-09-14  5:15 [PATCH 1/1] irqchip/gicv3: iterate over possible CPUs by for_each_possible_cpu() zijun_hu
@ 2017-09-14 19:20 ` Marc Zyngier
  2017-09-15  3:05   ` zijun_hu
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Zyngier @ 2017-09-14 19:20 UTC (permalink / raw)
  To: zijun_hu; +Cc: tglx, jason, james.morse, sudeep.holla, linux-kernel, zijun_hu

On Thu, Sep 14 2017 at  1:15:14 pm BST, zijun_hu <zijun_hu@zoho.com> wrote:
> From: zijun_hu <zijun_hu@htc.com>
>
> get_cpu_number() doesn't use existing helper to iterate over possible
> CPUs, so error happens in case of discontinuous @cpu_possible_mask
> such as 0b11110001.

Do you have an example of such a situation? Your patch is definitely an
improvement, but I'd like to understand how you get there...

Thanks,

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

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

* Re: [PATCH 1/1] irqchip/gicv3: iterate over possible CPUs by for_each_possible_cpu()
  2017-09-14 19:20 ` Marc Zyngier
@ 2017-09-15  3:05   ` zijun_hu
  2017-09-15 14:42     ` Marc Zyngier
  0 siblings, 1 reply; 4+ messages in thread
From: zijun_hu @ 2017-09-15  3:05 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-kernel, zijun_hu, tglx, jason, james.morse, sudeep.holla

On 09/15/2017 03:20 AM, Marc Zyngier wrote:
> On Thu, Sep 14 2017 at  1:15:14 pm BST, zijun_hu <zijun_hu@zoho.com> wrote:
>> From: zijun_hu <zijun_hu@htc.com>
>>
>> get_cpu_number() doesn't use existing helper to iterate over possible
>> CPUs, so error happens in case of discontinuous @cpu_possible_mask
>> such as 0b11110001.
> 
> Do you have an example of such a situation? Your patch is definitely an
> improvement, but I'd like to understand how you get there...
> 
> Thanks,
> 
> 	M.
> 
a few conditions which maybe result in discontiguous @cpu_possible_mask
are noticed and considered of by ARM64 init code as indicated by bellow code
segments:
in arch/arm64/kernel/smp.c :
void __init smp_init_cpus(void) {
......
	/*
	 * We need to set the cpu_logical_map entries before enabling
	 * the cpus so that cpu processor description entries (DT cpu nodes
	 * and ACPI MADT entries) can be retrieved by matching the cpu hwid
	 * with entries in cpu_logical_map while initializing the cpus.
	 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
	 */
	for (i = 1; i < nr_cpu_ids; i++) {
		if (cpu_logical_map(i) != INVALID_HWID) {
			if (smp_cpu_setup(i))
				cpu_logical_map(i) = INVALID_HWID;
		}
	}
......
}

/*
 * Initialize cpu operations for a logical cpu and
 * set it in the possible mask on success
 */
static int __init smp_cpu_setup(int cpu)
{
	if (cpu_read_ops(cpu))
		return -ENODEV;

	if (cpu_ops[cpu]->cpu_init(cpu))
		return -ENODEV;

	set_cpu_possible(cpu, true);

	return 0;
}

i browses GICv3 drivers code and notice that a little weird code segments 

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

* Re: [PATCH 1/1] irqchip/gicv3: iterate over possible CPUs by for_each_possible_cpu()
  2017-09-15  3:05   ` zijun_hu
@ 2017-09-15 14:42     ` Marc Zyngier
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2017-09-15 14:42 UTC (permalink / raw)
  To: zijun_hu; +Cc: linux-kernel, zijun_hu, tglx, jason, james.morse, sudeep.holla

On Fri, Sep 15 2017 at 11:05:25 am BST, zijun_hu <zijun_hu@zoho.com> wrote:
> On 09/15/2017 03:20 AM, Marc Zyngier wrote:
>> On Thu, Sep 14 2017 at  1:15:14 pm BST, zijun_hu <zijun_hu@zoho.com> wrote:
>>> From: zijun_hu <zijun_hu@htc.com>
>>>
>>> get_cpu_number() doesn't use existing helper to iterate over possible
>>> CPUs, so error happens in case of discontinuous @cpu_possible_mask
>>> such as 0b11110001.
>> 
>> Do you have an example of such a situation? Your patch is definitely an
>> improvement, but I'd like to understand how you get there...
>> 
>> Thanks,
>> 
>> 	M.
>> 
> a few conditions which maybe result in discontiguous @cpu_possible_mask
> are noticed and considered of by ARM64 init code as indicated by bellow code
> segments:
> in arch/arm64/kernel/smp.c :
> void __init smp_init_cpus(void) {
> ......
> 	/*
> 	 * We need to set the cpu_logical_map entries before enabling
> 	 * the cpus so that cpu processor description entries (DT cpu nodes
> 	 * and ACPI MADT entries) can be retrieved by matching the cpu hwid
> 	 * with entries in cpu_logical_map while initializing the cpus.
> 	 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
> 	 */
> 	for (i = 1; i < nr_cpu_ids; i++) {
> 		if (cpu_logical_map(i) != INVALID_HWID) {
> 			if (smp_cpu_setup(i))
> 				cpu_logical_map(i) = INVALID_HWID;
> 		}
> 	}

Right. It is not so much that the CPU doesn't exist as I initially
thought (and couldn't really believe that it could happen), but rather
that the CPU may have failed to come up (which is slightly more likely).

Well spotted. Would you mind respinning it with a commit message that
outlines the condition under which this can happen? I'll the take it as
a fix post -rc1.

Thanks,

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

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

end of thread, other threads:[~2017-09-15 14:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-14  5:15 [PATCH 1/1] irqchip/gicv3: iterate over possible CPUs by for_each_possible_cpu() zijun_hu
2017-09-14 19:20 ` Marc Zyngier
2017-09-15  3:05   ` zijun_hu
2017-09-15 14:42     ` 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.