Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: smp_wmb before bpf_ringbuf really commit #7993

Open
wants to merge 1 commit into
base: bpf-next_base
Choose a base branch
from

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: bpf: smp_wmb before bpf_ringbuf really commit
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e626a13
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e5e4799
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4d99e50
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 77017b9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: f2daa5a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 9a78313
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

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]>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 1850ce1
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=904951
version: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants