-
Notifications
You must be signed in to change notification settings - Fork 363
ring_buffer: do not use the reserved byte #1840
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
ring_buffer: do not use the reserved byte #1840
Conversation
Reviewer's GuideThis PR enhances buffer safety by adding tests that verify reserved-byte handling and wraparound integrity, adjusts ring_buffer read/write IOV logic to exclude the reserved slot and fix the fullness check, and updates the channel processing logic to correctly detect available space. Sequence diagram for channel_fd_pair_process buffer space checksequenceDiagram
participant Channel as channel_fd_pair
participant RB as ring_buffer
Channel->>RB: ring_buffer_get_space_available()
alt space available > 0
Channel->>RB: ring_buffer_read(...)
else
Channel-->>Channel: Skip read (buffer full)
end
Class diagram for updated ring_buffer logicclassDiagram
class ring_buffer {
+char* buffer
+size_t head
+size_t tail
+size_t size
+ring_buffer_get_read_iov(struct iovec *iov)
+ring_buffer_get_write_iov(struct iovec *iov)
+ring_buffer_get_space_available()
+ring_buffer_get_size()
}
class channel_fd_pair {
+ring_buffer* rb
+int in_fd
+channel_fd_pair_process(int epollfd, libcrun_error_t *err)
}
ring_buffer <.. channel_fd_pair : uses
Flow diagram for reserved byte handling in ring_bufferflowchart TD
A[Start Read/Write Operation] --> B{Is operation at buffer end?}
B -- Yes --> C[Exclude reserved byte from IOV length]
B -- No --> D[Proceed with normal IOV calculation]
C --> E[Return IOV]
D --> E
E --> F[Operation Complete]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @giuseppe - I've reviewed your changes - here's some feedback:
- test_ring_buffer_reserved_byte_boundary defines test_cases but never applies head/tail to the buffer or asserts should_be_full—update the test to actually set rb->head/rb->tail and verify full/not‐full behavior per case.
- ring_buffer_get_read_iov and ring_buffer_get_write_iov both use "-1" to skip the reserved byte; consider extracting this into a named constant or helper function to reduce duplication and improve clarity.
- Hardcoding the TAP plan header as "1..4" in main() is error-prone; consider computing the test count automatically or using a macro so it stays in sync when tests are added or removed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- test_ring_buffer_reserved_byte_boundary defines test_cases but never applies head/tail to the buffer or asserts should_be_full—update the test to actually set rb->head/rb->tail and verify full/not‐full behavior per case.
- ring_buffer_get_read_iov and ring_buffer_get_write_iov both use "-1" to skip the reserved byte; consider extracting this into a named constant or helper function to reduce duplication and improve clarity.
- Hardcoding the TAP plan header as "1..4" in main() is error-prone; consider computing the test count automatically or using a macro so it stays in sync when tests are added or removed.
## Individual Comments
### Comment 1
<location> `src/libcrun/utils.c:2782` </location>
<code_context>
for (i = 0, repeat = true; i < 1000 && repeat; i++)
{
repeat = false;
- if (ring_buffer_get_space_available (channel->rb) >= ring_buffer_get_size (channel->rb))
+ if (ring_buffer_get_space_available (channel->rb) > 0)
{
ret = ring_buffer_read (channel->rb, channel->in_fd, &is_input_eagain, err);
</code_context>
<issue_to_address>
The new condition allows processing when there is any space, not just when the buffer is empty.
Please confirm that processing when any space is available is intentional, as this may impact throughput or blocking behavior.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -2779,7 +2779,7 @@ channel_fd_pair_process (struct channel_fd_pair *channel, int epollfd, libcrun_e | |||
for (i = 0, repeat = true; i < 1000 && repeat; i++) | |||
{ | |||
repeat = false; | |||
if (ring_buffer_get_space_available (channel->rb) >= ring_buffer_get_size (channel->rb)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (bug_risk): The new condition allows processing when there is any space, not just when the buffer is empty.
Please confirm that processing when any space is available is intentional, as this may impact throughput or blocking behavior.
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
it is used for tracking of the status Closes: https://issues.redhat.com/browse/OCPBUGS-59854 Signed-off-by: Giuseppe Scrivano <[email protected]>
30ab276
to
59066cc
Compare
@kolyshkin @flouthoc PTAL |
@eriksjolund PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
it is used for tracking of the status
Closes: https://issues.redhat.com/browse/OCPBUGS-59854
Closes: #1838
Summary by Sourcery
Prevent ring buffer operations from using the reserved byte, correct full-condition detection for wraparound, and enhance test coverage with comprehensive boundary and integrity scenarios
New Features:
Enhancements:
Tests: