Skip to content

refactor(virtqueue): Don't swallow errors on incorrect pop order #1740

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

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

Gelbpunkt
Copy link
Member

@Gelbpunkt Gelbpunkt commented Jun 4, 2025

Currently, callers have no way to know whether pop_front_* methods returning None means that no data was received yet or whether they were trying to pop in the wrong order, e.g. trying to read a packet payload before the header. This would keep repeating infinitely if a driver was reading in the wrong order.

This is always an irrecoverable programming mistake, so let's panic.

@mkroening mkroening self-requested a review June 4, 2025 14:30
@mkroening mkroening self-assigned this Jun 4, 2025
@Gelbpunkt Gelbpunkt force-pushed the no-swallow-error-pop-order branch 2 times, most recently from fcc292f to 47277e4 Compare June 4, 2025 14:33
Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning a Result<Box<T>, PopError> would be preferable to having this extra option inside the result. Similar to io::Error::WouldBlock, we could add an appropriate variant to our error for signaling no data is available.

We should think about if it is useful for the driver to know there was an incorrect pop order? Is there any scenario in which this is not a programming error but something that can be usefully recovered from? If not, we should probably just stick to panicking.

@Gelbpunkt
Copy link
Member Author

I think returning a Result<Box<T>, PopError> would be preferable to having this extra option inside the result. Similar to io::Error::WouldBlock, we could add an appropriate variant to our error for signaling no data is available.

We should think about if it is useful for the driver to know there was an incorrect pop order? Is there any scenario in which this is not a programming error but something that can be usefully recovered from? If not, we should probably just stick to panicking.

In pretty much any case I can think of, this would be a programming error that cannot be recovered from. I initially wanted to panic here, but @cagatay-y was in favor of returning a Result. IMO either way is fine, the question really just is where we want to panic - in the drivers or in the virtqueue code.

Currently, callers have no way to know whether pop_front_* methods
returning None means that no data was received yet or whether they were
trying to pop in the wrong order, e.g. trying to read a packet payload
before the header. This would keep repeating infinitely if a driver was
reading in the wrong order.

This is an irrecoverable programming mistake that we should not swallow,
we should panic instead.

Signed-off-by: Jens Reidel <[email protected]>
@Gelbpunkt Gelbpunkt force-pushed the no-swallow-error-pop-order branch from 47277e4 to c5e31ae Compare June 6, 2025 16:45
@Gelbpunkt
Copy link
Member Author

Changed to a panic.

@Gelbpunkt Gelbpunkt requested a review from mkroening June 6, 2025 16:50
@mkroening mkroening added this pull request to the merge queue Jun 13, 2025
Merged via the queue into hermit-os:main with commit da12b6b Jun 13, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants