Skip to content

hv: Fix SPRR shadow table lifetime and userspace permissions - #765

Open
a-ramses wants to merge 2 commits into
AsahiLinux:mainfrom
a-ramses:m4-hv-memory-permissions
Open

a-ramses wants to merge 2 commits into
AsahiLinux:mainfrom
a-ramses:m4-hv-memory-permissions

Conversation

@a-ramses

Copy link
Copy Markdown
Contributor

Fix premature shadow-table reuse and separate user/kernel permissions to support protected JIT


Please check all boxes that apply:

  • This code was developed in accordance with the Asahi Linux Copyright Policy
  • I have not used generative AI/LLMs to develop this code, in accordance with the Asahi Linux LLM Policy
  • I have certified the above by adding a Signed-off-by: trailer to every commit

All boxes must be checked before your pull request can be reviewed.

Comment thread proxyclient/m1n1/hv/__init__.py Resolved
Comment thread src/hv/hv_sprr.c Resolved
Comment thread src/hv/hv_sprr.c Resolved
Comment thread src/hv/hv_sprr.c Outdated
return false;
}

if (full_broadcast || full_local) {

@svenpeter42 svenpeter42 Nov 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this could also use a comment why we need a dsb sy + isb just in this special case here

Comment thread src/hv/hv_sprr.c Resolved
Comment thread src/hv/hv_sprr.c Resolved
@a-ramses
a-ramses force-pushed the m4-hv-memory-permissions branch from eba9293 to 05495b0 Compare November 15, 2026 22:30
Removing a shadow table from cur[] doesn't mean the CPU has stopped
using it. We can still reuse its memory while a CPU is walking the old
table, which can send the guest to an unrelated mapping.

Keep detached tables around until the CPUs that could still use them
have completed a full TLB invalidation. Collection needs the hypervisor
lock, so don't do it from the unlocked GENTER/GEXIT path.

When the pool fills up, reclaim inactive shadows that have no remaining
readers. Pin the owners while updating or building tables so we don't
reclaim one halfway through.

Signed-off-by: Ramzi Abdiche <abdicheramzi@gmail.com>
@a-ramses
a-ramses force-pushed the m4-hv-memory-permissions branch from 05495b0 to 646feaa Compare November 15, 2026 22:36
Comment thread src/hv/hv_sprr.c Outdated

if (slot == 8) {
enum mmu_sysreg_result result = hv_sprr_emulate_uperm(ctx, cpu, locked);
if (result != MMU_SYSREG_UNHANDLED)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is very hard to read, how about a switch instead with all three cases similar to hv_sprr_emulate_sysreg?

Right now a shared shadow mapping becomes writable if either userspace
or the kernel can write to it. Making a JIT page writable in userspace
can therefore also let the kernel write through a mapping that should
be read-only.

Keep separate user and kernel shadow views and switch between them on
exception entry and return, including guarded transitions. Also handle
userspace UPERM accesses with the UMPRR write mask, so the guest can
change the permissions it's allowed to change.

This lets macOS use its normal JIT permission switching. Keep the
commpage xPRR feature value and stop forcing aprr_jit=0.

Signed-off-by: Ramzi Abdiche <abdicheramzi@gmail.com>
@a-ramses
a-ramses force-pushed the m4-hv-memory-permissions branch from 646feaa to de285a8 Compare November 17, 2026 22:00
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