Skip to content

Conversation

@nvmochs
Copy link
Collaborator

@nvmochs nvmochs commented Jan 23, 2026

Add CONFIG_ARM64_WORKAROUND_NC_TO_NGNRE configuration option that
enables conversion of MT_NORMAL_NC (Normal Non-Cacheable) memory
attribute to Device-nGnRE memory type in MAIR_EL1 for hardware that
requires stricter memory ordering or has issues with Non-Cacheable
memory mappings.


Tested kernel parameter enabled and disabled:

  • Verified workaround status is properly reflected in kernel log
  • Verified that mair is set correctly for all CPUs
  • Verified pgprot_dmacoherent works correctly
  • Verified unaligned access to ioremap_wc generates SIGBUS when workaround enabled

…evice-nGnRE

Add CONFIG_ARM64_WORKAROUND_NC_TO_NGNRE configuration option that
enables conversion of MT_NORMAL_NC (Normal Non-Cacheable) memory
attribute to Device-nGnRE memory type in MAIR_EL1 for hardware that
requires stricter memory ordering or has issues with Non-Cacheable
memory mappings.

Key changes:

1. New memory type MT_NORMAL_NC_DMA (Attr5):
   - Introduced specifically for DMA coherent memory mappings
   - Configured with the same Normal Non-Cacheable attribute (0x44)
     as MT_NORMAL_NC (Attr2) by default
   - pgprot_dmacoherent uses MT_NORMAL_NC_DMA when workaround is
     enabled, MT_NORMAL_NC otherwise

2. MAIR_EL1 conversion via alternatives framework:
   - arch/arm64/mm/proc.S uses ARM64 alternatives to patch MAIR_EL1
     during early boot
   - Converts MT_NORMAL_NC (Attr2) from 0x44 to 0x04 (Device-nGnRE)
     using efficient bfi instruction
   - MT_NORMAL_NC_DMA (Attr5) keeps the same attribute value as
     MT_NORMAL_NC originally had
   - Zero performance overhead when workaround is disabled

3. Boot-time configuration:
   - Enabled via kernel command line: mair_el1_nc_to_ngnre=1
   - Boot CPU fixup in enable_nc_to_ngnre() applies conversion before
     alternatives are patched
   - Secondary CPUs automatically use patched alternatives in
     __cpu_setup
   - Runtime changes not supported as alternatives cannot be
     re-patched after boot

4. Errata framework integration:
   - Registered in arm64_errata[] array as ARM64_WORKAROUND_NC_TO_NGNRE
   - Capability type: ARM64_CPUCAP_BOOT_CPU_FEATURE
   - Uses cpucap_is_possible() for build-time capability checking

The workaround preserves pgprot_dmacoherent behavior while allowing
MT_NORMAL_NC to be converted to Device memory type for other mappings
that may be affected by hardware issues.

Signed-off-by: Shanker Donthineni <sdonthineni@nvidia.com>
Signed-off-by: Matthew R. Ochs <mochs@nvidia.com>
Copy link
Collaborator

@nirmoy nirmoy left a comment

Choose a reason for hiding this comment

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

Acked-by: Nirmoy Das <nirmoyd@nvidia.com>

Copy link
Collaborator

@clsotog clsotog left a comment

Choose a reason for hiding this comment

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

Acked-by: Carol L Soto <csoto@nvidia.com>

@nvmochs
Copy link
Collaborator Author

nvmochs commented Jan 23, 2026

merged, closing PR.

@nvmochs nvmochs closed this Jan 23, 2026
@nvmochs nvmochs reopened this Jan 27, 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.

4 participants