Re: [PATCH] bitops: remove "optimizations"

David Miller
2008-04-29T23:30:23Z

From: David Miller <davem@davemloft.net>
Date: Tue, 29 Apr 2008 15:58:24 -0700 (PDT)

> Given that others who tested could not find one case where the
> optimization cases actually applied, and it's breaking things for me,
> my theory is that it's triggering for some obscure case on sparc64 and
> thus showing a bug in these optimizations since in practice I'm the
> only person to actually test this new code.

Ok, I think I see the problem.

The core issue is that (X << N) is undefined when N is >= the
word size, but that's exactly what the find_next_bit() inline
optimizations do.

This optimization code will trigger on 64-bit if NR_CPUS is set
to 64, and you actually have 64 cpus. It should also occur
on 32-bit if NR_CPUS=32 and you have 32 cpus.

The bogus expansion occurs in lib/cpumask.c:__next_cpu()

After processing cpu 63, we'll use offset==64 and thus try
to make the undefined shift I described above, causing the
caller's cpumask iteration loop to run forever.

This code was really not tested very well at all.