Make atomic_load_ptr type-aware

Returned value has type based on the argument, meaning consumers no longer
have to cast in the commmon case.

This commit keeps the kernel compilable without patching the rest.
This commit is contained in:
Mateusz Guzik 2020-02-14 23:15:41 +00:00
parent 23f6a81e49
commit 082a6b2a92
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=357940
4 changed files with 10 additions and 6 deletions

View File

@ -796,7 +796,7 @@ pmap_delayed_invl_start_u(void)
PV_STAT(i = 0);
for (p = &pmap_invl_gen_head;; p = prev.next) {
PV_STAT(i++);
prevl = atomic_load_ptr(&p->next);
prevl = (uintptr_t)atomic_load_ptr(&p->next);
if ((prevl & PMAP_INVL_GEN_NEXT_INVALID) != 0) {
PV_STAT(atomic_add_long(&invl_start_restart, 1));
lock_delay(&lda);
@ -903,7 +903,7 @@ pmap_delayed_invl_finish_u(void)
again:
for (p = &pmap_invl_gen_head; p != NULL; p = (void *)prevl) {
prevl = atomic_load_ptr(&p->next);
prevl = (uintptr_t)atomic_load_ptr(&p->next);
if ((prevl & PMAP_INVL_GEN_NEXT_INVALID) != 0) {
PV_STAT(atomic_add_long(&invl_finish_restart, 1));
lock_delay(&lda);
@ -954,7 +954,7 @@ DB_SHOW_COMMAND(di_queue, pmap_di_queue)
for (p = &pmap_invl_gen_head, first = true; p != NULL; p = pn,
first = false) {
nextl = atomic_load_ptr(&p->next);
nextl = (uintptr_t)atomic_load_ptr(&p->next);
pn = (void *)(nextl & ~PMAP_INVL_GEN_NEXT_INVALID);
td = first ? NULL : __containerof(p, struct thread,
td_md.md_invl_gen);

View File

@ -170,7 +170,11 @@ void kcsan_atomic_thread_fence_seq_cst(void);
#define atomic_fcmpset_acq_ptr kcsan_atomic_fcmpset_acq_ptr
#define atomic_fcmpset_rel_ptr kcsan_atomic_fcmpset_rel_ptr
#define atomic_fetchadd_ptr kcsan_atomic_fetchadd_ptr
#define atomic_load_ptr(x) kcsan_atomic_load_ptr((volatile uintptr_t *)(x))
#define atomic_load_ptr(x) ({ \
__typeof(*x) __retptr; \
__retptr = (void *)kcsan_atomic_load_ptr((volatile uintptr_t *)(x)); \
__retptr; \
})
#define atomic_load_acq_ptr kcsan_atomic_load_acq_ptr
#define atomic_readandclear_ptr kcsan_atomic_readandclear_ptr
#define atomic_set_ptr kcsan_atomic_set_ptr

View File

@ -41,7 +41,7 @@
#define atomic_load_short(p) (*(volatile u_short *)(p))
#define atomic_load_int(p) (*(volatile u_int *)(p))
#define atomic_load_long(p) (*(volatile u_long *)(p))
#define atomic_load_ptr(p) (*(volatile uintptr_t*)(p))
#define atomic_load_ptr(p) (*(volatile __typeof(p))(p))
#define atomic_load_8(p) (*(volatile uint8_t *)(p))
#define atomic_load_16(p) (*(volatile uint16_t *)(p))
#define atomic_load_32(p) (*(volatile uint32_t *)(p))

View File

@ -1106,7 +1106,7 @@ smp_after_idle_runnable(void *arg __unused)
for (cpu = 1; cpu < mp_ncpus; cpu++) {
pc = pcpu_find(cpu);
while (atomic_load_ptr(&pc->pc_curpcb) == (uintptr_t)NULL)
while (atomic_load_ptr(&pc->pc_curpcb) == NULL)
cpu_spinwait();
kmem_free((vm_offset_t)bootstacks[cpu], kstack_pages *
PAGE_SIZE);