Skip to content

Fix xcr0 sanity check#31

Open
hky1999 wants to merge 1 commit intomasterfrom
handle_xsetbv
Open

Fix xcr0 sanity check#31
hky1999 wants to merge 1 commit intomasterfrom
handle_xsetbv

Conversation

@hky1999
Copy link
Contributor

@hky1999 hky1999 commented Jan 21, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical logic bug in the XCR0 (Extended Control Register 0) validation code for handling the XSETBV instruction in virtual machine execution. The bug was introduced in commit 5f6eaf4 where operator precedence caused the validation condition to always evaluate to true, making it ineffective.

Changes:

  • Fixed the XCR0 AVX-512 state validation logic by properly grouping conditions with parentheses and using AND instead of chained ORs
  • Improved error reporting by changing from ok_or to ok_or_else with a detailed error message showing the invalid xcr0 value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

|| !x.contains(Xcr0::XCR0_OPMASK_STATE)
|| !x.contains(Xcr0::XCR0_ZMM_HI256_STATE)
|| !x.contains(Xcr0::XCR0_HI16_ZMM_STATE)
|| !x.contains(Xcr0::XCR0_HI16_ZMM_STATE))
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The indentation on this line appears inconsistent with the previous lines in the same logical group. It should align with lines 1227-1228 to maintain consistent formatting.

Suggested change
|| !x.contains(Xcr0::XCR0_HI16_ZMM_STATE))
|| !x.contains(Xcr0::XCR0_HI16_ZMM_STATE))

Copilot uses AI. Check for mistakes.
}

if x.contains(Xcr0::XCR0_OPMASK_STATE)
if (x.contains(Xcr0::XCR0_OPMASK_STATE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add some comments here to describe why these combinations are invalid

Copy link
Contributor

Choose a reason for hiding this comment

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

Also maybe we can extract these ifs into a new validator function?

@aarkegz aarkegz changed the title [fix] bug introduces by commit 5f6eaf4 Fix xcr0 sanity check Jan 22, 2026
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