OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 2:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to invalidate TLB on ARMv8?
PostPosted: Sat Jan 04, 2020 7:24 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 201
How do I invalidate TLB on ARMv8 CPU? This architecture has waaaaay too many different instructions for that purpose. The most suitable for whole TLB seems to be
Code:
TLBI ALLE1
but it is not available in EL1. And
Code:
TLBI VAE1, X0
for single page seems to do absolutely nothing (old mapping is still used).


Top
 Profile  
 
 Post subject: Re: How to invalidate TLB on ARMv8?
PostPosted: Sun Jan 05, 2020 11:44 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Hi,

To invalidate the entire mapping on EL1 (same as reloading CR3 on x86), use
Code:
TLBI VMALLE1
DSB ISH
ISB
The first instruction invalidates the MMU. The second reloads the data cache, and the third the instruction cache.

To invalidate one page only (INVPLG on x86), do
Code:
DSB ISHST
TLBI VAAE1, (addr>>12)
The barrier is needed to flush pending cache operations. Note that TLBI does not expect an address, but a page number!

But on some ARM implementations with multiple cores and dcache, you'll need this:
Code:
DSB ISHST
TLBI VAAE1, (addr>>12)
DC CVAU, (addr)
DSB ISH
Not entirely sure why, but this is how the ARM Trusted Firmware does it. I'd recommend to check it out, it's on github, and it does lots of interesting things that are not documented at all. For example, when it sets the paging address in TTBRx_ELx, it also sets the lowest bit to 1 (and comment calls this CnP saying it is required for shared pages), which I have never read about in no docs nor specs, yet there it is...

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: How to invalidate TLB on ARMv8?
PostPosted: Sun Jan 05, 2020 1:19 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 201
Thanks, man!
Adding that 12 bit shift worked like a charm. I would never suspect that it's needed there. I thought that addresses passed to TLBI instruction are just plain VAs.
TLBI VMALLE1 seems to work as well, yet its name and description in ARM docs are confusing. VM implies that some kind of virtualization is used.
But… it works!
Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 194 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group