Page MenuHomeFreeBSD

Extract the logic from pmap_kextract

Authored by andrew on Dec 15 2020, 2:57 PM.



This allows us to use it when we only need to check if the virtual address
is valid. For example when checking if an address in the DMAP region is

Diff Detail

R10 FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

This is untested, I just moved the code to a new function as a proof of concept.

Fix the build and boot tested on N1SDP

I was always envy for aarch64 AT instructions. AT S1E0R (or W) seems to do exactly what you want, and avoid manual parsing of the page tables. Why not use the instruction?

Use an AT instruction with a fallback on walking the page table.


Why do we need to disable interrupts around AT ?


It's two instructions. The at instruction stores the result in par_el1 so we then need the following to get the result in x1:

at      s1e1r, x0
mrs     x1, par_el1

If a interrupt happens after the at, but before the mrs we may have an invalid value in par_el, e.g. if the thread is moved to a new CPU. We could handle this by restarting the instruction, however disabling interrupts on arm64 is cheap so there is no need.

kib added inline comments.

May be add a comment there noting that operation is not atomic?

This revision is now accepted and ready to land.Jan 15 2021, 12:42 PM

BTW would it make sense to use AT in pmap_extract()?

Add a comment explaining why interrupts are disabled

This revision now requires review to proceed.Jan 15 2021, 3:10 PM

Extra newline.


Or perhaps disable interrupts in the implementation rather than the caller.


I think pmap_klookup() might be a better name. kva_to_pa is a bit confusing since 1) translating KVAs to PAs is ostensibly pmap_kextract()'s job, and 2) the function is used here only to see if the address is valid.

I expect we could do something similar in pmap_extract. We would need to limit it to stage 1 pmaps (i.e. non-hypervisor pmaps), and need to check if it's a userspace or kernel pmap.

It looks like we would only need the page table walking code for stage 2 pmaps as we only modify them with the pmap lock that pmap_extract holds.

Update based on feedback from markj

This revision is now accepted and ready to land.Jan 15 2021, 4:25 PM
This revision was automatically updated to reflect the committed changes.