Skip to content

[Bug]: Variable MTRR setting function improperly calculates the range #109

Description

@olegilyasov

Is there an existing issue for this?

  • I have searched existing issues

Current Behavior

In fn mtrr_set_memory_attributes_internal:

  • mtrr_valid_bits_mask = (1 << physical_address_bits) - 1, i.e. all N low bits set,
    where N = CPU-reported physical address bits.
  • high_bit_set_64(mtrr_valid_bits_mask) returns the index of the highest set bit,
    which is N-1 for a mask with N bits set.
  • So 1 << (N-1) is a half of the true total address space (mtrr_valid_bits_mask + 1 = 2^N).
  • Panic with "MTRR vertex order violation" on gDS->SetMemorySpaceAttributes call (EFI_MEMORY_WB at 0x7A000000, size 0x2000000)

Expected Behavior

The expected bit mask should be calculated as:
1 << high_bit_set_64(mtrr_valid_bits_mask + 1)

Steps To Reproduce

Variable MTRR[00]: Base=0x00000000FF000000 Mask=0x0000007FFF000000 Type=5
Variable MTRR[01]: Base=0x0000000000000000 Mask=0x0000007F80000000 Type=6
Variable MTRR[02]: Base=0x000000007A000000 Mask=0x0000007FFE000000 Type=0
Variable MTRR[03]: Base=0x000000007C000000 Mask=0x0000007FFC000000 Type=0
Variable MTRR[04]: Base=0x0000000100000000 Mask=0x0000007F00000000 Type=6
Variable MTRR[05]: Base=0x0000000200000000 Mask=0x0000007E00000000 Type=6

Build Environment

- OS(s):
- Targets Impacted:

Version Information

Commit: 3318c0687f7d991ca4129504116aa3bd456694aa

Urgency

Low

Are you going to fix this?

I will fix it

Do you need maintainer feedback?

No maintainer feedback needed

Anything else?

No response

Metadata

Metadata

Assignees

Labels

state:needs-triageNeeds to triaged to determine next stepstype:bugSomething isn't workingurgency:lowLittle to no impact

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions