Page MenuHomeFreeBSD

riscv/pmap.c: Add an Svinval-aware variant of pmap_invalidate_range
AcceptedPublic

Authored by bnovkov on Jun 17 2026, 9:23 PM.
Tags
None
Referenced Files
F163137983: D57624.id181986.diff
Mon, Jul 20, 10:43 AM
F163136742: D57624.id181919.diff
Mon, Jul 20, 10:24 AM
F163127869: D57624.id181310.diff
Mon, Jul 20, 8:09 AM
Unknown Object (File)
Wed, Jul 15, 1:53 PM
Unknown Object (File)
Mon, Jul 13, 2:34 PM
Unknown Object (File)
Sun, Jul 12, 12:20 AM
Unknown Object (File)
Fri, Jul 10, 6:05 PM
Unknown Object (File)
Wed, Jul 8, 2:24 PM
Subscribers

Details

Reviewers
markj
mhorne
Group Reviewers
riscv
Summary

This change introduces a variant of pmap_invalidate_range that uses
the fine-grained TLB invalidation instructions introduced by the
Svinval extension. These instructions allow for more efficient TLB
flushing on certain implementations. Under this new scheme,
pmap_invalidate_range was converted to an ifunc that selects the
appropriate variant during boot.

Event: BSDCan 2026

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 74799
Build 71682: arc lint + arc unit

Event Timeline

mhorne added a subscriber: mhorne.
mhorne added inline comments.
sys/riscv/riscv/pmap.c
1115–1116
This revision is now accepted and ready to land.Wed, Jun 24, 2:03 PM
sys/riscv/riscv/pmap.c
1102

The relationship between this check and the definition above was a momentary confusion for me.

You might do away with the atop() and PAGE_SIZE division altogether.

Why not use this for pmap_invalidate_page() as well?

Address @markj 's and @mhorne 's comments:

  • add an svinval-aware pmap_invalidate_page variant
  • remove awkward atop conversion
This revision now requires review to proceed.Sun, Jul 5, 12:45 PM
This revision is now accepted and ready to land.Thu, Jul 9, 5:21 PM
sys/riscv/riscv/pmap.c
1129

Why is this done in the callback? Shouldn't we just fall back to a direct pmap_invalidate_all() call?

1152

I think you want to pass smp_no_rendezvous_barrier instead of NULL here, otherwise all CPUs will needlessly synchronize before invoking the callback, and again after. See smp_rendezvous_action().

This revision now requires review to proceed.Mon, Jul 13, 6:20 PM
bnovkov added inline comments.
sys/riscv/riscv/pmap.c
1129

No particular reason, it seemed like the most straightforward solution at the time.
I have no preferences here, I've worked your suggestion into the patch.

sys/riscv/riscv/pmap.c
1151

Why exactly do we need this fence? Is it just copied from the SBI implementation?

1157

So above we invoked the callback on all harts except this one, waiting for them to finish, and now we're doing the invalidation on the current hart. Why not do them all in parallel?

bnovkov added inline comments.
sys/riscv/riscv/pmap.c
1151

The fence here follows the convention outlined in the comment above pmap_invalidate_page_sbi, which was introduced back in D17414.
I assume it's here because sfence_vmas that target an address only apply to the leaf PTEs, but I'm not sure.

1157

Right, that pattern only makes sense in the sbi_* variants where I assume we want to avoid calling into openSBI.
I'll include the original cpu in the mask as well.

Avoid clearing CPU mask for range invalidation

Did you microbenchmark the new implementation? I'd be curious to know, say, how many cycles it takes to execute 10000 back-to-back 4KB page invalidations using the old and new implementations respectively, when the target CPU mask is just the current CPU and when it's the set of all CPUs.

This revision is now accepted and ready to land.Wed, Jul 15, 2:01 PM