x86: Fix possible ASSERT(cpu < nr_cpu_ids)
PATCH v3 1/1 x86: Fix possible ASSERT(cpu < nr_cpu_ids)
From: David Wang <[email protected]>
CPUs may share an in-use channel. Hence clearing of a bit from the cpumask (in hpet_broadcast_exit()) as well as setting one (in hpet_broadcast_enter()) must not race evaluation of that same cpumask. Therefore avoid evaluating the cpumask twice in hpet_detach_channel(). Otherwise cpumask_empty() may e.g.return false while the subsequent cpumask_first() could return nr_cpu_ids, which then triggers the assertion in cpumask_of() reached through set_channel_irq_affinity().
--- xen/arch/x86/hpet.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/hpet.c +5 -2
@@ -509,15 +509,18 @@ static void hpet_attach_channel(unsigned int cpu,static void hpet_detach_channel (unsigned int cpu,struct hpet_event_channel *ch) { +unsigned int next; +spin_lock_irq (&ch->lock);ASSERT (ch ==per_cpu (cpu_bc_channel, cpu));per_cpu (cpu_bc_channel, cpu) =NULL ; + next =cpumask_first (ch->cpumask);if ( cpu != ch->cpu )spin_unlock_irq (&ch->lock); -else if (cpumask_empty (ch->cpumask) ) +else if ( next == nr_cpu_ids ) { ch->cpu =-1 ;clear_bit (HPET_EVT_USED_BIT , &ch->flags);
@@ -525,7 +528,7 @@ static void hpet_detach_channel(unsigned int cpu, }else { - ch->cpu =cpumask_first (ch->cpumask); + ch->cpu = next;set_channel_irq_affinity (ch);local_irq_enable (); }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 19.04.18 at 12:20, <[email protected]> wrote:
From: David Wang <[email protected]>
CPUs may share an in-use channel. Hence clearing of a bit from the cpumask (in
hpet_broadcast_exit()) as well as setting one (inhpet_broadcast_enter()) must not race evaluation of that same cpumask. Therefore avoid evaluating the cpumask twice inhpet_detach_channel(). Otherwisecpumask_empty()may e.g.return false while the subsequentcpumask_first()could returnnr_cpu_ids, which then triggers the assertion incpumask_of()reached throughset_channel_irq_affinity().
Quoted 1 line
Sign-off-by David Wang <[email protected]>
Signed-off-by
Quoted 9 lines
xen/arch/x86/hpet.c +2
-0@@ -509,15 +509,18 @@ static void hpet_attach_channel(unsigned int cpu,static void hpet_detach_channel (unsigned int cpu,struct hpet_event_channel *ch) { +unsigned int next; +spin_lock_irq (&ch->lock);
xen/arch/x86/hpet.c static void hpet_attach_channel(unsigned int cpu, · line 523
Quoted 10 lines
xen/arch/x86/hpet.c +2
-1ASSERT (ch ==per_cpu (cpu_bc_channel, cpu));per_cpu (cpu_bc_channel, cpu) =NULL ; + next =cpumask_first (ch->cpumask);if ( cpu != ch->cpu )spin_unlock_irq (&ch->lock); -else if (cpumask_empty (ch->cpumask) ) +else if ( next == nr_cpu_ids )
This should be >= .
Also I'd prefer if the cpumask_first() was avoided in the cpu != ch->cpu case.
With these
(and the changes are easy enough to make while committing)
Also Cc Jürgen.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 19.04.18 at 12:20, <[email protected]> wrote:
From: David Wang <[email protected]>
CPUs may share an in-use channel. Hence clearing of a bit from the cpumask (in
hpet_broadcast_exit()) as well as setting one (inhpet_broadcast_enter()) must not race evaluation of that same cpumask. Therefore avoid evaluating the cpumask twice inhpet_detach_channel(). Otherwisecpumask_empty()may e.g.return false while the subsequentcpumask_first()could returnnr_cpu_ids, which then triggers the assertion incpumask_of()reached throughset_channel_irq_affinity().
Quoted 3 lines
Quoted 1 line
Sign-off-by David Wang <[email protected]>Signed-off-by
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel