lockless_dereference() is planned to grow a sanity check to ensure that the input parameter is a pointer. __ref_is_percpu() passes in an unsinged long value which is a combination of a pointer and a flag. While it can be casted to a pointer lvalue, the casting looks messy and it's a special case anyway. Let's revert back to open-coding READ_ONCE() and explicit barrier. This doesn't cause any functional changes.
Unified · Split
| @@ -136,14 +136,12 @@ static inline bool __ref_is_percpu(struct percpu_ref *ref, · 135 unmodified lines | ||
| 136 | 136 | * used as a pointer. If the compiler generates a separate fetch |
| 137 | 137 | * when using it as a pointer, __PERCPU_REF_ATOMIC may be set in |
| 138 | 138 | * between contaminating the pointer value, meaning that |
| 139 | − * ACCESS_ONCE() is required when fetching it. | |
| 140 | − * | |
| 141 | − * Also, we need a data dependency barrier to be paired with | |
| 142 | − * smp_store_release() in __percpu_ref_switch_to_percpu(). | |
| 143 | − * | |
| 144 | − * Use lockless deref which contains both. | |
| 139 | + * READ_ONCE() is required when fetching it. | |
| 145 | 140 | */ |
| 146 | − percpu_ptr = lockless_dereference(ref->percpu_count_ptr); | |
| 141 | + percpu_ptr = READ_ONCE(ref->percpu_count_ptr); | |
| 142 | + | |
| 143 | + /* paired with smp_store_release() in __percpu_ref_switch_to_percpu() */ | |
| 144 | + smp_read_barrier_depends(); | |
| 147 | 145 | |
| 148 | 146 | /* |
| 149 | 147 | * Theoretically, the following could test just ATOMIC; however, |