On Tue, May 14 2024 at 09:47, Yury Norov wrote: >> Instead of sprinkling these conditional all over the place, can't you >> just do the obvious and check for ptr1 == ptr2 in bitmap_copy() and >> bitmap_equal()? > > I proposed this a while (few years) ago, and it has been rejected. On > bitmaps level we decided not to do that for the reasons memcpy() and > memcmp() doesn't, and on cpumasks and nodemasks level it hasn't > been discussed at all. > > Now that most of bitmap ops have inline and outline implementation, > we technically can move this checks in outline code, as inline bitmap > ops are very lightweight already. > > So I see the following options: > - Implement these sanity checks in outline bitmap API (lib/bitmap.c); > - Implement them on cpumask and nodemask level; or > - add a new family of helpers that do this check, like > bitmap_copy_if_needed() (better name appreciated). > > The argument against #1 and #2 these days was that memcpy() and > similarly bitmap_copy() with dst == src may be a sign of error, and > we don't want to add a code that optimizes for it. That's a fair argument. > Now, I ran the kernel through the LTP test and in practice all the > cases that I spot look pretty normal. So I can continue sprinkling > the checks once a few years, or do something like described above. I don't see these checks as valuable in most cases and I detest them as they make the code harder to read. Except for smp_call_function_many_cond() and to a lesser extent irq_do_set_affinity() none of them you added really matters. Though it might be worth to have helper functions which make it obvious that the src == dst case is intentional. Thanks, tglx