← Back to Pull requests

Fix VEX.128 crypto instruction feature gates #849

Closed
unknown closed this pull request without merging on Aug 29, 2026 04:20 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 19:46 UTC
Author

Problem

The VEX.128 forms of the AES and carry-less multiplication instructions
require the corresponding legacy crypto feature in addition to AVX.

Specifically, the VEX.128 AES instructions require
CPUID.01H:ECX.AES[25] and AVX, while VEX.128 VPCLMULQDQ requires
CPUID.01H:ECX.PCLMULQDQ[1] and AVX.

Their seven Bochs opcode declarations currently use only BX_ISA_AVX
as their feature guard. Decoder initialization therefore retains the
execution handlers when AVX is available but AES and PCLMULQDQ are not
advertised.

For example, with corei7_skylake_x and
exclude_features=aes_pclmulqdq:

CPUID.1:ECX:  0x7dfaf39d
AES:          0
PCLMULQDQ:    0
AVX:          1
OSXSAVE:      1
XCR0:         0xe7
mode:         long mode, CPL3

c4 e2 71 de c2       vaesdec xmm0, xmm1, xmm2
c4 e2 71 df c2       vaesdeclast xmm0, xmm1, xmm2
c4 e2 71 dc c2       vaesenc xmm0, xmm1, xmm2
c4 e2 71 dd c2       vaesenclast xmm0, xmm1, xmm2
c4 e2 79 db c1       vaesimc xmm0, xmm1
c4 e3 79 df c1 01    vaeskeygenassist xmm0, xmm1, 1
c4 e3 71 44 c2 00    vpclmulqdq xmm0, xmm1, xmm2, 0

expected: #UD for all seven instructions
before:   all seven instructions execute

The newer VAES and VPCLMULQDQ feature is used for wider vector forms;
it does not replace the AES or PCLMULQDQ requirement for these VEX.128
encodings.

Fix

Use BX_ISA_AES_PCLMULQDQ as the feature guard for the six VEX.128 AES
declarations and the VEX.128 VPCLMULQDQ declaration, while retaining
their existing BX_PREPARE_AVX checks.

Bochs models AES and PCLMULQDQ together under this extension and already
uses it for the corresponding legacy instruction declarations. The
feature guard now checks crypto availability, while BX_PREPARE_AVX
continues to enforce AVX and its architectural state requirements.

Architectural reference

The Intel® 64 and IA-32 Architectures Software Developer’s Manual,
Volume 2, specifies AES together with AVX for the VEX.128 AES encodings
and PCLMULQDQ together with AVX for the VEX.128 VPCLMULQDQ encoding.
The instructions raise #UD when their required CPUID feature is absent.

  • Intel® 64 and IA-32 Architectures Software Developer’s Manual

  • Intel® Software Developer Manuals download page
  • Validation

    The affected 32- and 64-bit decoder objects were forcibly rebuilt,
    followed by a successful full Bochs build:

    make -C bochs/cpu -B decoder/fetchdecode32.o decoder/fetchdecode64.o
    make -C bochs -j2
    

    A temporary long-mode CPL3 probe tested all seven VEX.128 encodings
    under three feature configurations.

    With AVX enabled and aes_pclmulqdq excluded:

    CPUID.1:ECX=0x7dfaf39d
    XCR0=0xe7
    
    VAESDEC=#UD
    VAESDECLAST=#UD
    VAESENC=#UD
    VAESENCLAST=#UD
    VAESIMC=#UD
    VAESKEYGENASSIST=#UD
    VPCLMULQDQ=#UD
    BV:DONE status=pass
    

    With AVX, AES, and PCLMULQDQ enabled, all seven instructions continued
    to execute:

    CPUID.1:ECX=0x7ffaf39f
    XCR0=0xe7
    
    VAESDEC=EXECUTED
    VAESDECLAST=EXECUTED
    VAESENC=EXECUTED
    VAESENCLAST=EXECUTED
    VAESIMC=EXECUTED
    VAESKEYGENASSIST=EXECUTED
    VPCLMULQDQ=EXECUTED
    BV:DONE status=pass
    

    Finally, a control test verified that the fix does not make these VEX
    encodings available on processors without AVX.

    AES and PCLMULQDQ were enabled, but AVX was disabled. XCR0 contained
    only x87 and SSE state (0x3), with no AVX state enabled:

    AES:          1
    PCLMULQDQ:    1
    AVX:          0
    XCR0:         0x3
    

    All seven instructions correctly raised #UD:

    VAESDEC=#UD
    VAESDECLAST=#UD
    VAESENC=#UD
    VAESENCLAST=#UD
    VAESIMC=#UD
    VAESKEYGENASSIST=#UD
    VPCLMULQDQ=#UD
    BV:DONE status=pass
    

    This confirms that BX_ISA_AES_PCLMULQDQ enforces crypto availability,
    while the retained BX_PREPARE_AVX checks continue to enforce the
    independent AVX and AVX-state requirements.

    Diff: 507 lines (+380 / -127) across 6 files Reviewer: stlintel Review duration: 513m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.71) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.71 · 507 lines diff across 6 files
    0.71
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.373
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.071
    Real PR Conversation Timeline
    1 comments
    "Review active on #849"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 70.8% (HIGH) · Higher = larger blast radius
    70.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.0% · Safe to merge
    28.0%