Skip to content

Comments

Run the payload at EL2#5

Open
m4tx wants to merge 6 commits intomainfrom
el2-support
Open

Run the payload at EL2#5
m4tx wants to merge 6 commits intomainfrom
el2-support

Conversation

@m4tx
Copy link
Collaborator

@m4tx m4tx commented Nov 21, 2025

No description provided.

@m4tx m4tx requested review from qperret2 and qwandor November 21, 2025 15:48
Base automatically changed from lint-config to main November 28, 2025 14:17
src/arch.rs Outdated
///
/// * The register is readable at the current Exception Level.
/// * Reading the register does not destructively alter hardware state (e.g.,
/// acknowledging an interrupt by reading `ICC_IAR1_EL1`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

How would acknowledging an interrupt cause undefined behaviour?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair, altering hardware state sounded more serious, but after reading about this more, seems like this specifically shouldn't cause any memory issues/UBs. Also, since we control the list of registers we wrap with this helper anyway, I guess there's no harm in making this function safe.

src/arch.rs Outdated
sctlr &= !sctlr_el2::C; // Data Cache Enable
sctlr &= !sctlr_el2::I; // Instruction Cache Enable
// SAFETY: We assume we have an identity mapped pagetables for the currently running
// code, so disabling MMU is safe.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if so, it's not really safe. The compiler is free to emit atomic memory accesses in safe Rust code, but these have undefined behaviour when the data cache is disabled. So it's not really safe to run arbitrary Rust code with the MMU disabled.

I think the best solution would be to disable the MMU and caches in the same inline assembly block as you jump to the payload image.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair - I've moved the cache disable code to a separate assembly function.

@m4tx m4tx requested a review from qwandor January 12, 2026 13:42
Copy link
Collaborator

@qwandor qwandor left a comment

Choose a reason for hiding this comment

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

Please make sure someone else looks over the cache maintenance side of things, I'm not super familiar with that.

src/arch.rs Outdated
sys_reg!(cnthctl_el2);
sys_reg!(spsr_el2);
sys_reg!(elr_el2);
sys_reg!(sp_el1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using the arm-sysregs crate which we've recently published.

Copy link
Collaborator Author

@m4tx m4tx Feb 5, 2026

Choose a reason for hiding this comment

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

Done, although probably could be better. ccsidr_el1 seems to be missing support for Associativity and NumSets fields, for instance. I'm happy to fix this, but is there any specific process for Googlers to contribute to Trusted Firmware-A repositories, like there is for GitHub, for instance?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to login to https://review.trustedfirmware.org/ with your GitHub account and then add your SSH key at https://review.trustedfirmware.org/settings/#SSHKeys to upload patches.

For the missing fields, this is probably because they are conditional and clash with other fields. In this case the size and location of the Associativity and NumSets fields depends on whether FEAT_CCIDX is implemented.

@m4tx m4tx requested a review from qwandor February 5, 2026 11:16
let mut sctlr = read_sctlr_el2();
sctlr.remove(SctlrEl2::M); // MMU Enable
sctlr.remove(SctlrEl2::C); // Data Cache Enable
sctlr.remove(SctlrEl2::I); // Instruction Cache Enable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: you can use the -= operator if you like.

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.

2 participants