-
Notifications
You must be signed in to change notification settings - Fork 53
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
Rectify accessing virtq struct members #73
Open
Cuda-Chen
wants to merge
1
commit into
sysprog21:master
Choose a base branch
from
Cuda-Chen:rectify-vsnd-desc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -696,10 +696,10 @@ static void virtio_snd_cb(struct CNFADriver *dev, | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
#define VSND_DESC_CNT 3 | ||||||||||||||||
static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd, | ||||||||||||||||
const virtio_snd_queue_t *queue, | ||||||||||||||||
uint32_t desc_idx, | ||||||||||||||||
uint32_t *plen) | ||||||||||||||||
static int virtio_snd_ctrl_desc_handler(virtio_snd_state_t *vsnd, | ||||||||||||||||
const virtio_snd_queue_t *queue, | ||||||||||||||||
uint32_t desc_idx, | ||||||||||||||||
uint32_t *plen) | ||||||||||||||||
{ | ||||||||||||||||
/* A control message uses at most 3 virtqueue descriptors, where | ||||||||||||||||
* the first descriptor contains: | ||||||||||||||||
|
@@ -713,13 +713,14 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd, | |||||||||||||||
/* Collect the descriptors */ | ||||||||||||||||
for (int i = 0; i < VSND_DESC_CNT; i++) { | ||||||||||||||||
/* The size of the `struct virtq_desc` is 4 words */ | ||||||||||||||||
const uint32_t *desc = &vsnd->ram[queue->QueueDesc + desc_idx * 4]; | ||||||||||||||||
const struct virtq_desc *desc = | ||||||||||||||||
(struct virtq_desc *) &vsnd->ram[queue->QueueDesc + desc_idx * 4]; | ||||||||||||||||
|
||||||||||||||||
/* Retrieve the fields of current descriptor */ | ||||||||||||||||
vq_desc[i].addr = desc[0]; | ||||||||||||||||
vq_desc[i].len = desc[2]; | ||||||||||||||||
vq_desc[i].flags = desc[3]; | ||||||||||||||||
desc_idx = desc[3] >> 16; /* vq_desc[desc_cnt].next */ | ||||||||||||||||
vq_desc[i].addr = desc->addr; | ||||||||||||||||
vq_desc[i].len = desc->len; | ||||||||||||||||
vq_desc[i].flags = desc->flags; | ||||||||||||||||
desc_idx = desc->next; | ||||||||||||||||
|
||||||||||||||||
/* Leave the loop if next-flag is not set */ | ||||||||||||||||
if (!(vq_desc[i].flags & VIRTIO_DESC_F_NEXT)) | ||||||||||||||||
|
@@ -836,20 +837,21 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd, | |||||||||||||||
int cnt = 0; | ||||||||||||||||
for (;;) { | ||||||||||||||||
/* The size of the `struct virtq_desc` is 4 words */ | ||||||||||||||||
const uint32_t *desc = &vsnd->ram[queue->QueueDesc + desc_idx * 4]; | ||||||||||||||||
const struct virtq_desc *desc = | ||||||||||||||||
(struct virtq_desc *) &vsnd->ram[queue->QueueDesc + desc_idx * 4]; | ||||||||||||||||
Comment on lines
+840
to
+841
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding alignment checks for struct
Consider adding alignment checks when casting memory address to Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #2fcc69 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||||||||||||
|
||||||||||||||||
/* Retrieve the fields of current descriptor */ | ||||||||||||||||
node = (virtq_desc_queue_node_t *) malloc(sizeof(*node)); | ||||||||||||||||
node->vq_desc.addr = desc[0]; | ||||||||||||||||
node->vq_desc.len = desc[2]; | ||||||||||||||||
node->vq_desc.flags = desc[3]; | ||||||||||||||||
node->vq_desc.addr = desc->addr; | ||||||||||||||||
node->vq_desc.len = desc->len; | ||||||||||||||||
node->vq_desc.flags = desc->flags; | ||||||||||||||||
list_push(&node->q, &q); | ||||||||||||||||
desc_idx = desc[3] >> 16; /* vq_desc[desc_cnt].next */ | ||||||||||||||||
desc_idx = desc->next; | ||||||||||||||||
|
||||||||||||||||
cnt++; | ||||||||||||||||
|
||||||||||||||||
/* Leave the loop if next-flag is not set */ | ||||||||||||||||
if (!(desc[3] & VIRTIO_DESC_F_NEXT)) | ||||||||||||||||
if (!(desc->flags & VIRTIO_DESC_F_NEXT)) | ||||||||||||||||
break; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -1088,7 +1090,7 @@ static bool virtio_snd_reg_write(virtio_snd_state_t *vsnd, | |||||||||||||||
switch (value) { | ||||||||||||||||
case VSND_QUEUE_CTRL: | ||||||||||||||||
virtio_queue_notify_handler(vsnd, value, | ||||||||||||||||
virtio_snd_desc_handler); | ||||||||||||||||
virtio_snd_ctrl_desc_handler); | ||||||||||||||||
break; | ||||||||||||||||
case VSND_QUEUE_TX: | ||||||||||||||||
tx_ev_notify++; | ||||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider using proper type casting when converting memory addresses to struct pointers. The current cast may cause alignment issues on some architectures. Consider using
aligned_cast
or ensuring proper alignment.Code suggestion
Code Review Run #2fcc69
Is this a valid issue, or was it incorrectly flagged by the Agent?