Skip to content

[viostor] Fix SRB Extension struct member alignment#1472

Draft
benyamin-codez wants to merge 1 commit intovirtio-win:masterfrom
benyamin-codez:viostor-fua-as-flag
Draft

[viostor] Fix SRB Extension struct member alignment#1472
benyamin-codez wants to merge 1 commit intovirtio-win:masterfrom
benyamin-codez:viostor-fua-as-flag

Conversation

@benyamin-codez
Copy link
Copy Markdown
Contributor

@benyamin-codez benyamin-codez commented Dec 22, 2025

Refactors to fix a struct member misalignment in _SRB_EXTENSION:

  1. Creates a new _SRB_EXTENSION_FLAGS struct of 32 bits length
  2. The first bit is fua (Forced Unit Access)
  3. The other bits are unused padding
  4. Replaces the _SRB_EXTENSION member fua with new flags member
  5. Updates references to srbExt->fua to use srbExt->flags.fua
  6. Enforces 1-byte alignment of structs _SRB_EXTENSION and _SRB_EXTENSION_FLAGS

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @benyamin-codez, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves a struct member misalignment issue within the _SRB_EXTENSION structure in the viostor driver. By refactoring the fua flag into a dedicated, properly padded _SRB_EXTENSION_FLAGS struct and adjusting the member order within _SRB_EXTENSION, the changes ensure correct memory alignment. This is critical for stability and preventing potential data corruption or undefined behavior in low-level driver operations, ultimately improving the robustness of the driver.

Highlights

  • New Struct for Flags: A new _SRB_EXTENSION_FLAGS struct has been introduced to encapsulate the fua flag and ensure proper alignment.
  • FUA Flag Encapsulation: The fua (Forced Unit Access) flag is now the first bit within the newly created _SRB_EXTENSION_FLAGS struct.
  • Struct Padding: Padding bytes have been added to the _SRB_EXTENSION_FLAGS struct to guarantee a 32-bit length and correct memory alignment.
  • SRB_EXTENSION Modification: The direct fua member in _SRB_EXTENSION has been replaced with an instance of the new SRB_EXTENSION_FLAGS struct, named flags.
  • Code References Updated: All existing references to srbExt->fua have been updated to srbExt->flags.fua to reflect the new struct hierarchy.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@YanVugenfirer
Copy link
Copy Markdown
Collaborator

[Jenkins CI]: Can one of the admins verify this patch?

@benyamin-codez
Copy link
Copy Markdown
Contributor Author

Will rebase following merge of #1467 or #1468...

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a structure member misalignment issue in _SRB_EXTENSION by reordering its members. The change to introduce an _SRB_EXTENSION_FLAGS struct for the fua flag is a good approach. However, the implementation of _SRB_EXTENSION_FLAGS seems to deviate from the stated intent in the pull request description, resulting in a larger-than-necessary struct and an inefficient memory layout. I've provided a suggestion to align the implementation with the description, which will result in a more efficient memory layout.

Refactors to fix a struct member misalignment:

1. Creates a new _SRB_EXTENSION_FLAGS struct of 32 bits length
2. The first bit is fua (Forced Unit Access)
3. The other bits are unused padding
4. Replaces the _SRB_EXTENSION member fua with new flags member
5. Updates references to srbExt->fua to use srbExt->flags.fua
6. Enforces 1-byte alignment of structs _SRB_EXTENSION and _SRB_EXTENSION_FLAGS

Signed-off-by: benyamin-codez <115509179+benyamin-codez@users.noreply.github.com>
@kostyanf14
Copy link
Copy Markdown
Member

ok to test

@benyamin-codez
Copy link
Copy Markdown
Contributor Author

@kostyanf14

I'm not sure this one will work. I ended up with BSODs in my stress tests for both 32 and 16 bit members. I'll try to test some more in coming hours, but in any case, I think this one is likely to get another push... Methinks it might be better to just wrap the extension in a pragma pack (1) and keep the fua bit in the extension. Anyway, I'm minded to run up some variants in the debugger and try to see what is actually happening...

@kostyanf14
Copy link
Copy Markdown
Member

@benyamin-codez so you also can reproduce bsod with qcow2 image and viostor. Am I correct?

@benyamin-codez
Copy link
Copy Markdown
Contributor Author

@benyamin-codez so you also can reproduce bsod with qcow2 image and viostor. Am I correct?

@kostyanf14, with the changes in this PR in my WIP, yes, I get BSODs on qcow2 images.

I haven't checked it as is because without the other changes, it will likely get BSODs anyway.

I don't get the BSODs with PR #1467, even on qcow2 images.

It is the combination of pragma pack(1) wrapping and the fua change. With just the (incorrect 32 byte) fua change it was ok. I just need to flesh it out a bit more, hopefully in the next few hours, but it will still need to be after rebasing on #1467 / #1468, if that merges.

@benyamin-codez
Copy link
Copy Markdown
Contributor Author

@kostyanf14

By way of update:

I've gone with a different and more simple approach here that is just as effective.
I'll force-push a new commit when my time permits...

I note this only helps to resolve the BSODs and 4KiB block write performance, and not the QCOW2 issue.

cc: @YanVugenfirer @vrozenfe

@YanVugenfirer
Copy link
Copy Markdown
Collaborator

@benyamin-codez - Please rebase.

@benyamin-codez
Copy link
Copy Markdown
Contributor Author

Please rebase.

@YanVugenfirer

As mentioned above, I went a different (wholistic - imho better) path with this. I just need to do some recalculations and tests following the blk_discard_write_zeroes moves @kevmw made with the relevant structs. I don't think anything changed because, iirc, they still aligned with 4 and 8-byte boundaries, but I just want to check to be sure.

I think a new PR is probably best.
I'll close this one as soon as I raise the new one.

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.

3 participants