Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpf: smp_wmb before bpf_ringbuf really commit
To guarantee visibility of writing ringbuffer,it is necessary to call smp_wmb before ringbuffer really commit. for instance, when updating the data of buffer in cpu1, it is not visible for the cpu2 which may be accessing buffer. This may lead to the consumer accessing a incorrect data. using the smp_wmb before commmit will guarantee that the consume can access the correct data. CPU1: struct mem_event_t* data = bpf_ringbuf_reserve(); data->type = MEM_EVENT_KSWAPD_WAKE; data->event_data.kswapd_wake.node_id = args->nid; bpf_ringbuf_commit(data); CPU2: cons_pos = smp_load_acquire(r->consumer_pos); len_ptr = r->data + (cons_pos & r->mask); sample = (void *)len_ptr + BPF_RINGBUF_HDR_SZ; access to sample Signed-off-by: zhongjinji <[email protected]>
- Loading branch information