Virtio-9P device attach: fix initialization of virtio_9p struct #2030
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.
Since commit d037970, in multi-vCPU instances root filesystem initialization can complete before PCI bus discovery; this means that any filesystem mount points specified in the manifest options can be already processed by the time a virtio-9p device is probed and a corresponding volume is added; this in turn means that the
volume_add()
function called byv9p_dev_attach()
can trigger a direct call tov9p_fs_init()
.The
v9p_fs_init()
function uses thegeneral
field of thevirtio_9p
struct, which in the current code is initialized after calling thevolume_add()
function; this causesv9p_fs_init()
to access an uninitialized pointer, leading to an unhandled page fault. The same issue applies to thebacked
field of the struct.This change fixes the above issue by moving the initialization of the struct fields before the call to
volume_add()
. In addition, the unuseddev
field is being removed, and setting the DRIVER_OK flag in the device status field is being moved before the call tovolume_add()
(according to the virtio specs, a driver must not send any buffer available notifications to the device before setting DRIVER_OK).