-
Notifications
You must be signed in to change notification settings - Fork 103
virtio-queue: add verify_add_used and stub memory region #346
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
959d811
to
7113f45
Compare
96d3228
to
89e9614
Compare
89e9614
to
7f83b55
Compare
7f83b55
to
f8c3526
Compare
LGTM! |
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.
Please for the commit description, follow the style of other commits, using the crate as prefix, something like this:
virtio-queue: add unit proof for add_used method (sec 2.8.22)
@@ -14,11 +290,11 @@ use super::*; | |||
/// meaning we can use `kani::unwind(0)` instead of `kani::unwind(2)`. Functionally, | |||
/// it works identically to `GuestMemoryMmap` with only a single contained region. | |||
pub struct SingleRegionGuestMemory { | |||
the_region: vm_memory::GuestRegionMmap, | |||
the_region: StubRegion, |
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.
I'd split this patch in 2 patches, one where you introduce StubRegion (explaining why we need to do that) using it in the existing proofs and another patch where you add the new proof.
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.
I can add that we needed to rely on a StubRegion
otherwise Kani won't finish if GuestRegionMmap
is used. I agree that this needs to be explained.
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.
done
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.
@priyasiddharth I meant 2 patches in this PR, why removing the other changes from this PR?
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.
fixed
|
||
/// Kani proof harness for verifying the behavior of the `add_used` method of the `Queue`. | ||
/// | ||
/// # Specification (VirtIO 1.3, Section 2.8.22: "Receiving Used Buffers From The Device") |
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.
I think section 2.8 is for packed virtqueues whereas here we are only dealing with split virtqueues. I think the section should be 2.7.14 (see https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.html#x1-7100014)
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.
Also, I could not find what the spec says about using a descriptor id that is out of bonds. I think that the spec may let the implementation decide that.
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.
I think what we try to enforce here is 2.7.8.2 Device Requirements: The Virtqueue Used Ring
. I think we may need a comment like in firecraker in which we state all the things we do not verify, e.g., the order in which the used-ring indexes are updated.
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.
We are not enforcing any of the following in the current proof therefore I don't think 2.7.8.2
applies:
- The device MUST set len prior to updating the used idx.
- The device MUST write at least len bytes to descriptor, beginning at the first device-writable buffer, prior to updating the used idx.
- The device MAY write more than len bytes to descriptor. Note: There are potential error cases where a device might not know what parts of the buffers have been written. This is why len is permitted to be an underestimate: that’s preferable to the driver believing that uninitialized memory has been overwritten when it has not.
/// When the device has finished processing a buffer, it must add an element to the used ring, | ||
/// indicating which descriptor chain was used and how many bytes were written. The device must | ||
/// increment the used index after writing the element. If the descriptor index is out of bounds, | ||
/// the operation must fail and the used index must not be incremented. |
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.
I think this last sentence is not part of the specification. There is no requirement about what to do when the index in the descriptor is out of bonds. I think it is a decision of the implementation what to do in this case.
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.
closing as not relevant to this PR
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.
@priyasiddharth this means that we will lose all the comments of that code, so we need to review again the same changes. Why you removed that changes completely from this PR?
Maybe I was unclear, but I meant just to split the changes in multiple patches but still in the same PR.
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.
Ok I will add it back. I interpreted the word patch
to mean different PRs but perhaps you meant commit: #346 (comment)
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.
@priyasiddharth sorry, just to be clear, in my mind commit = patch + description.
PR (or series) is a set of commits/patches.
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.
I clarified in the function doc
assert_eq!(queue.next_used, used_idx); | ||
assert!(used_desc_table_index >= queue.size()); | ||
// The old value should still be the same as before the add_used call. | ||
assert_eq!(old_val, get_used_idx(&queue, &memory).unwrap()); |
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.
I think different that the proof in firecraker (see https://sourcegraph.com/github.com/firecracker-microvm/firecracker/-/blob/src/vmm/src/devices/virtio/queue.rs?L982) we are checking that the memory values has not changed, right?
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.
I don't understand the link. But to answer your question, firecracker proof does not check guestmemory (because of path explosion), we add this extra check cause kani seems to be able to handle it.
Kani proofs do not finish in practical time if we use the production memory region. So we implement a stub region with a simple vector backing it. This will help subsequent proofs work and also enable stateful proofs. Signed-off-by: Siddharth Priya <[email protected]>
f8c3526
to
433129f
Compare
Signed-off-by: Siddharth Priya <[email protected]>
Signed-off-by: Siddharth Priya <[email protected]>
Summary of the PR
virtio-queue: add verification for
add_used
operationKani proofs like
verify_add_used
do not finish in practical time if we use the production memory region. So we implement a stub region with a simple vector backing it. This will help subsequent proofs work and also enable stateful proofs.Note that
unsafe
code is added only for StubRegion that will run in Kani.Kani verifies all
unsafe
accesses do not cause undefined behaviour (in the context of unit proof execution).Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s
), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafe
code is properly documented.