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

Document limitations of net_buf queuing functions #28355

Closed
JordanYates opened this issue Sep 14, 2020 · 2 comments · Fixed by #30987
Closed

Document limitations of net_buf queuing functions #28355

JordanYates opened this issue Sep 14, 2020 · 2 comments · Fixed by #30987
Assignees
Labels
Enhancement Changes/Updates/Additions to existing features

Comments

@JordanYates
Copy link
Collaborator

Is your enhancement proposal related to a problem? Please describe.
The current documentation for net_buf_get and net_buf_slist_get does not specify that the functions are only safe to use from a single thread if the net_buf contains fragments.

Describe the solution you'd like
Documentation that describes the above, or an alternate implementation that does not suffer the same problems.

Additional context
The functions are not thread safe due to multiple independent calls to k_fifo_get, which can be interrupted at any point in time.
The net_buf_put variants are fine as they use an atomic function k_fifo_put_list.

@JordanYates JordanYates added the Enhancement Changes/Updates/Additions to existing features label Sep 14, 2020
@jhedberg
Copy link
Member

I vaguely remember some discussion around moving to use a separate fragments list net_buf struct member rather than reusing the first four bytes of the net_buf struct (combined with flags) for this purpose. This would remove this limitation in the implementation. @carlescufi was it with you that this came up?

@carlescufi
Copy link
Member

I vaguely remember some discussion around moving to use a separate fragments list net_buf struct member rather than reusing the first four bytes of the net_buf struct (combined with flags) for this purpose. This would remove this limitation in the implementation. @carlescufi was it with you that this came up?

It might've been because I also have a vague recollection of this. I am not up to speed with the problem right now, but feel free to include me in a discussion about this after the release.

jhedberg pushed a commit that referenced this issue Jan 4, 2021
Document limitations on the FIFO queuing functions when fragments are
used. Namely that the `get` functions are not thread-safe when fragments
are present.

This is due to multiple independent calls to `k_fifo_get/sys_slist_get`.
A second thread can interrupt the retrieval before all fragments have
been removed. The second thread can then read from the FIFO, obtaining
the trailing fragments as a 'new' `net_buf`. The first thread will then
either assert or pull in the next `net_buf` on the queue as part of the
first `net_buf`.

Fixes #28355

Signed-off-by: Jordan Yates <[email protected]>
bwasim pushed a commit to bwasim/zephyr that referenced this issue Jan 5, 2021
Document limitations on the FIFO queuing functions when fragments are
used. Namely that the `get` functions are not thread-safe when fragments
are present.

This is due to multiple independent calls to `k_fifo_get/sys_slist_get`.
A second thread can interrupt the retrieval before all fragments have
been removed. The second thread can then read from the FIFO, obtaining
the trailing fragments as a 'new' `net_buf`. The first thread will then
either assert or pull in the next `net_buf` on the queue as part of the
first `net_buf`.

Fixes zephyrproject-rtos#28355

Signed-off-by: Jordan Yates <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants