162306a36Sopenharmony_ci================================== 262306a36Sopenharmony_ciCache and TLB Flushing Under Linux 362306a36Sopenharmony_ci================================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci:Author: David S. Miller <davem@redhat.com> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciThis document describes the cache/tlb flushing interfaces called 862306a36Sopenharmony_ciby the Linux VM subsystem. It enumerates over each interface, 962306a36Sopenharmony_cidescribes its intended purpose, and what side effect is expected 1062306a36Sopenharmony_ciafter the interface is invoked. 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciThe side effects described below are stated for a uniprocessor 1362306a36Sopenharmony_ciimplementation, and what is to happen on that single processor. The 1462306a36Sopenharmony_ciSMP cases are a simple extension, in that you just extend the 1562306a36Sopenharmony_cidefinition such that the side effect for a particular interface occurs 1662306a36Sopenharmony_cion all processors in the system. Don't let this scare you into 1762306a36Sopenharmony_cithinking SMP cache/tlb flushing must be so inefficient, this is in 1862306a36Sopenharmony_cifact an area where many optimizations are possible. For example, 1962306a36Sopenharmony_ciif it can be proven that a user address space has never executed 2062306a36Sopenharmony_cion a cpu (see mm_cpumask()), one need not perform a flush 2162306a36Sopenharmony_cifor this address space on that cpu. 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciFirst, the TLB flushing interfaces, since they are the simplest. The 2462306a36Sopenharmony_ci"TLB" is abstracted under Linux as something the cpu uses to cache 2562306a36Sopenharmony_civirtual-->physical address translations obtained from the software 2662306a36Sopenharmony_cipage tables. Meaning that if the software page tables change, it is 2762306a36Sopenharmony_cipossible for stale translations to exist in this "TLB" cache. 2862306a36Sopenharmony_ciTherefore when software page table changes occur, the kernel will 2962306a36Sopenharmony_ciinvoke one of the following flush methods _after_ the page table 3062306a36Sopenharmony_cichanges occur: 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci1) ``void flush_tlb_all(void)`` 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci The most severe flush of all. After this interface runs, 3562306a36Sopenharmony_ci any previous page table modification whatsoever will be 3662306a36Sopenharmony_ci visible to the cpu. 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci This is usually invoked when the kernel page tables are 3962306a36Sopenharmony_ci changed, since such translations are "global" in nature. 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci2) ``void flush_tlb_mm(struct mm_struct *mm)`` 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci This interface flushes an entire user address space from 4462306a36Sopenharmony_ci the TLB. After running, this interface must make sure that 4562306a36Sopenharmony_ci any previous page table modifications for the address space 4662306a36Sopenharmony_ci 'mm' will be visible to the cpu. That is, after running, 4762306a36Sopenharmony_ci there will be no entries in the TLB for 'mm'. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci This interface is used to handle whole address space 5062306a36Sopenharmony_ci page table operations such as what happens during 5162306a36Sopenharmony_ci fork, and exec. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci3) ``void flush_tlb_range(struct vm_area_struct *vma, 5462306a36Sopenharmony_ci unsigned long start, unsigned long end)`` 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci Here we are flushing a specific range of (user) virtual 5762306a36Sopenharmony_ci address translations from the TLB. After running, this 5862306a36Sopenharmony_ci interface must make sure that any previous page table 5962306a36Sopenharmony_ci modifications for the address space 'vma->vm_mm' in the range 6062306a36Sopenharmony_ci 'start' to 'end-1' will be visible to the cpu. That is, after 6162306a36Sopenharmony_ci running, there will be no entries in the TLB for 'mm' for 6262306a36Sopenharmony_ci virtual addresses in the range 'start' to 'end-1'. 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci The "vma" is the backing store being used for the region. 6562306a36Sopenharmony_ci Primarily, this is used for munmap() type operations. 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci The interface is provided in hopes that the port can find 6862306a36Sopenharmony_ci a suitably efficient method for removing multiple page 6962306a36Sopenharmony_ci sized translations from the TLB, instead of having the kernel 7062306a36Sopenharmony_ci call flush_tlb_page (see below) for each entry which may be 7162306a36Sopenharmony_ci modified. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci4) ``void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)`` 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci This time we need to remove the PAGE_SIZE sized translation 7662306a36Sopenharmony_ci from the TLB. The 'vma' is the backing structure used by 7762306a36Sopenharmony_ci Linux to keep track of mmap'd regions for a process, the 7862306a36Sopenharmony_ci address space is available via vma->vm_mm. Also, one may 7962306a36Sopenharmony_ci test (vma->vm_flags & VM_EXEC) to see if this region is 8062306a36Sopenharmony_ci executable (and thus could be in the 'instruction TLB' in 8162306a36Sopenharmony_ci split-tlb type setups). 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci After running, this interface must make sure that any previous 8462306a36Sopenharmony_ci page table modification for address space 'vma->vm_mm' for 8562306a36Sopenharmony_ci user virtual address 'addr' will be visible to the cpu. That 8662306a36Sopenharmony_ci is, after running, there will be no entries in the TLB for 8762306a36Sopenharmony_ci 'vma->vm_mm' for virtual address 'addr'. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci This is used primarily during fault processing. 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci5) ``void update_mmu_cache_range(struct vm_fault *vmf, 9262306a36Sopenharmony_ci struct vm_area_struct *vma, unsigned long address, pte_t *ptep, 9362306a36Sopenharmony_ci unsigned int nr)`` 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci At the end of every page fault, this routine is invoked to tell 9662306a36Sopenharmony_ci the architecture specific code that translations now exists 9762306a36Sopenharmony_ci in the software page tables for address space "vma->vm_mm" 9862306a36Sopenharmony_ci at virtual address "address" for "nr" consecutive pages. 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci This routine is also invoked in various other places which pass 10162306a36Sopenharmony_ci a NULL "vmf". 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci A port may use this information in any way it so chooses. 10462306a36Sopenharmony_ci For example, it could use this event to pre-load TLB 10562306a36Sopenharmony_ci translations for software managed TLB configurations. 10662306a36Sopenharmony_ci The sparc64 port currently does this. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciNext, we have the cache flushing interfaces. In general, when Linux 10962306a36Sopenharmony_ciis changing an existing virtual-->physical mapping to a new value, 11062306a36Sopenharmony_cithe sequence will be in one of the following forms:: 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci 1) flush_cache_mm(mm); 11362306a36Sopenharmony_ci change_all_page_tables_of(mm); 11462306a36Sopenharmony_ci flush_tlb_mm(mm); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci 2) flush_cache_range(vma, start, end); 11762306a36Sopenharmony_ci change_range_of_page_tables(mm, start, end); 11862306a36Sopenharmony_ci flush_tlb_range(vma, start, end); 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci 3) flush_cache_page(vma, addr, pfn); 12162306a36Sopenharmony_ci set_pte(pte_pointer, new_pte_val); 12262306a36Sopenharmony_ci flush_tlb_page(vma, addr); 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciThe cache level flush will always be first, because this allows 12562306a36Sopenharmony_cius to properly handle systems whose caches are strict and require 12662306a36Sopenharmony_cia virtual-->physical translation to exist for a virtual address 12762306a36Sopenharmony_ciwhen that virtual address is flushed from the cache. The HyperSparc 12862306a36Sopenharmony_cicpu is one such cpu with this attribute. 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ciThe cache flushing routines below need only deal with cache flushing 13162306a36Sopenharmony_cito the extent that it is necessary for a particular cpu. Mostly, 13262306a36Sopenharmony_cithese routines must be implemented for cpus which have virtually 13362306a36Sopenharmony_ciindexed caches which must be flushed when virtual-->physical 13462306a36Sopenharmony_citranslations are changed or removed. So, for example, the physically 13562306a36Sopenharmony_ciindexed physically tagged caches of IA32 processors have no need to 13662306a36Sopenharmony_ciimplement these interfaces since the caches are fully synchronized 13762306a36Sopenharmony_ciand have no dependency on translation information. 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciHere are the routines, one by one: 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci1) ``void flush_cache_mm(struct mm_struct *mm)`` 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci This interface flushes an entire user address space from 14462306a36Sopenharmony_ci the caches. That is, after running, there will be no cache 14562306a36Sopenharmony_ci lines associated with 'mm'. 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci This interface is used to handle whole address space 14862306a36Sopenharmony_ci page table operations such as what happens during exit and exec. 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci2) ``void flush_cache_dup_mm(struct mm_struct *mm)`` 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci This interface flushes an entire user address space from 15362306a36Sopenharmony_ci the caches. That is, after running, there will be no cache 15462306a36Sopenharmony_ci lines associated with 'mm'. 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci This interface is used to handle whole address space 15762306a36Sopenharmony_ci page table operations such as what happens during fork. 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci This option is separate from flush_cache_mm to allow some 16062306a36Sopenharmony_ci optimizations for VIPT caches. 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci3) ``void flush_cache_range(struct vm_area_struct *vma, 16362306a36Sopenharmony_ci unsigned long start, unsigned long end)`` 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci Here we are flushing a specific range of (user) virtual 16662306a36Sopenharmony_ci addresses from the cache. After running, there will be no 16762306a36Sopenharmony_ci entries in the cache for 'vma->vm_mm' for virtual addresses in 16862306a36Sopenharmony_ci the range 'start' to 'end-1'. 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci The "vma" is the backing store being used for the region. 17162306a36Sopenharmony_ci Primarily, this is used for munmap() type operations. 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci The interface is provided in hopes that the port can find 17462306a36Sopenharmony_ci a suitably efficient method for removing multiple page 17562306a36Sopenharmony_ci sized regions from the cache, instead of having the kernel 17662306a36Sopenharmony_ci call flush_cache_page (see below) for each entry which may be 17762306a36Sopenharmony_ci modified. 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci4) ``void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn)`` 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci This time we need to remove a PAGE_SIZE sized range 18262306a36Sopenharmony_ci from the cache. The 'vma' is the backing structure used by 18362306a36Sopenharmony_ci Linux to keep track of mmap'd regions for a process, the 18462306a36Sopenharmony_ci address space is available via vma->vm_mm. Also, one may 18562306a36Sopenharmony_ci test (vma->vm_flags & VM_EXEC) to see if this region is 18662306a36Sopenharmony_ci executable (and thus could be in the 'instruction cache' in 18762306a36Sopenharmony_ci "Harvard" type cache layouts). 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci The 'pfn' indicates the physical page frame (shift this value 19062306a36Sopenharmony_ci left by PAGE_SHIFT to get the physical address) that 'addr' 19162306a36Sopenharmony_ci translates to. It is this mapping which should be removed from 19262306a36Sopenharmony_ci the cache. 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci After running, there will be no entries in the cache for 19562306a36Sopenharmony_ci 'vma->vm_mm' for virtual address 'addr' which translates 19662306a36Sopenharmony_ci to 'pfn'. 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci This is used primarily during fault processing. 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci5) ``void flush_cache_kmaps(void)`` 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci This routine need only be implemented if the platform utilizes 20362306a36Sopenharmony_ci highmem. It will be called right before all of the kmaps 20462306a36Sopenharmony_ci are invalidated. 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci After running, there will be no entries in the cache for 20762306a36Sopenharmony_ci the kernel virtual address range PKMAP_ADDR(0) to 20862306a36Sopenharmony_ci PKMAP_ADDR(LAST_PKMAP). 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci This routing should be implemented in asm/highmem.h 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci6) ``void flush_cache_vmap(unsigned long start, unsigned long end)`` 21362306a36Sopenharmony_ci ``void flush_cache_vunmap(unsigned long start, unsigned long end)`` 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci Here in these two interfaces we are flushing a specific range 21662306a36Sopenharmony_ci of (kernel) virtual addresses from the cache. After running, 21762306a36Sopenharmony_ci there will be no entries in the cache for the kernel address 21862306a36Sopenharmony_ci space for virtual addresses in the range 'start' to 'end-1'. 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci The first of these two routines is invoked after vmap_range() 22162306a36Sopenharmony_ci has installed the page table entries. The second is invoked 22262306a36Sopenharmony_ci before vunmap_range() deletes the page table entries. 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ciThere exists another whole class of cpu cache issues which currently 22562306a36Sopenharmony_cirequire a whole different set of interfaces to handle properly. 22662306a36Sopenharmony_ciThe biggest problem is that of virtual aliasing in the data cache 22762306a36Sopenharmony_ciof a processor. 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ciIs your port susceptible to virtual aliasing in its D-cache? 23062306a36Sopenharmony_ciWell, if your D-cache is virtually indexed, is larger in size than 23162306a36Sopenharmony_ciPAGE_SIZE, and does not prevent multiple cache lines for the same 23262306a36Sopenharmony_ciphysical address from existing at once, you have this problem. 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ciIf your D-cache has this problem, first define asm/shmparam.h SHMLBA 23562306a36Sopenharmony_ciproperly, it should essentially be the size of your virtually 23662306a36Sopenharmony_ciaddressed D-cache (or if the size is variable, the largest possible 23762306a36Sopenharmony_cisize). This setting will force the SYSv IPC layer to only allow user 23862306a36Sopenharmony_ciprocesses to mmap shared memory at address which are a multiple of 23962306a36Sopenharmony_cithis value. 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci.. note:: 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci This does not fix shared mmaps, check out the sparc64 port for 24462306a36Sopenharmony_ci one way to solve this (in particular SPARC_FLAG_MMAPSHARED). 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ciNext, you have to solve the D-cache aliasing issue for all 24762306a36Sopenharmony_ciother cases. Please keep in mind that fact that, for a given page 24862306a36Sopenharmony_cimapped into some user address space, there is always at least one more 24962306a36Sopenharmony_cimapping, that of the kernel in its linear mapping starting at 25062306a36Sopenharmony_ciPAGE_OFFSET. So immediately, once the first user maps a given 25162306a36Sopenharmony_ciphysical page into its address space, by implication the D-cache 25262306a36Sopenharmony_cialiasing problem has the potential to exist since the kernel already 25362306a36Sopenharmony_cimaps this page at its virtual address. 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ci ``void copy_user_page(void *to, void *from, unsigned long addr, struct page *page)`` 25662306a36Sopenharmony_ci ``void clear_user_page(void *to, unsigned long addr, struct page *page)`` 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci These two routines store data in user anonymous or COW 25962306a36Sopenharmony_ci pages. It allows a port to efficiently avoid D-cache alias 26062306a36Sopenharmony_ci issues between userspace and the kernel. 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci For example, a port may temporarily map 'from' and 'to' to 26362306a36Sopenharmony_ci kernel virtual addresses during the copy. The virtual address 26462306a36Sopenharmony_ci for these two pages is chosen in such a way that the kernel 26562306a36Sopenharmony_ci load/store instructions happen to virtual addresses which are 26662306a36Sopenharmony_ci of the same "color" as the user mapping of the page. Sparc64 26762306a36Sopenharmony_ci for example, uses this technique. 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci The 'addr' parameter tells the virtual address where the 27062306a36Sopenharmony_ci user will ultimately have this page mapped, and the 'page' 27162306a36Sopenharmony_ci parameter gives a pointer to the struct page of the target. 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci If D-cache aliasing is not an issue, these two routines may 27462306a36Sopenharmony_ci simply call memcpy/memset directly and do nothing more. 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci ``void flush_dcache_folio(struct folio *folio)`` 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci This routines must be called when: 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci a) the kernel did write to a page that is in the page cache page 28162306a36Sopenharmony_ci and / or in high memory 28262306a36Sopenharmony_ci b) the kernel is about to read from a page cache page and user space 28362306a36Sopenharmony_ci shared/writable mappings of this page potentially exist. Note 28462306a36Sopenharmony_ci that {get,pin}_user_pages{_fast} already call flush_dcache_folio 28562306a36Sopenharmony_ci on any page found in the user address space and thus driver 28662306a36Sopenharmony_ci code rarely needs to take this into account. 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci .. note:: 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci This routine need only be called for page cache pages 29162306a36Sopenharmony_ci which can potentially ever be mapped into the address 29262306a36Sopenharmony_ci space of a user process. So for example, VFS layer code 29362306a36Sopenharmony_ci handling vfs symlinks in the page cache need not call 29462306a36Sopenharmony_ci this interface at all. 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci The phrase "kernel writes to a page cache page" means, specifically, 29762306a36Sopenharmony_ci that the kernel executes store instructions that dirty data in that 29862306a36Sopenharmony_ci page at the kernel virtual mapping of that page. It is important to 29962306a36Sopenharmony_ci flush here to handle D-cache aliasing, to make sure these kernel stores 30062306a36Sopenharmony_ci are visible to user space mappings of that page. 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci The corollary case is just as important, if there are users which have 30362306a36Sopenharmony_ci shared+writable mappings of this file, we must make sure that kernel 30462306a36Sopenharmony_ci reads of these pages will see the most recent stores done by the user. 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci If D-cache aliasing is not an issue, this routine may simply be defined 30762306a36Sopenharmony_ci as a nop on that architecture. 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci There is a bit set aside in folio->flags (PG_arch_1) as "architecture 31062306a36Sopenharmony_ci private". The kernel guarantees that, for pagecache pages, it will 31162306a36Sopenharmony_ci clear this bit when such a page first enters the pagecache. 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci This allows these interfaces to be implemented much more 31462306a36Sopenharmony_ci efficiently. It allows one to "defer" (perhaps indefinitely) the 31562306a36Sopenharmony_ci actual flush if there are currently no user processes mapping this 31662306a36Sopenharmony_ci page. See sparc64's flush_dcache_folio and update_mmu_cache_range 31762306a36Sopenharmony_ci implementations for an example of how to go about doing this. 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci The idea is, first at flush_dcache_folio() time, if 32062306a36Sopenharmony_ci folio_flush_mapping() returns a mapping, and mapping_mapped() on that 32162306a36Sopenharmony_ci mapping returns %false, just mark the architecture private page 32262306a36Sopenharmony_ci flag bit. Later, in update_mmu_cache_range(), a check is made 32362306a36Sopenharmony_ci of this flag bit, and if set the flush is done and the flag bit 32462306a36Sopenharmony_ci is cleared. 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci .. important:: 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci It is often important, if you defer the flush, 32962306a36Sopenharmony_ci that the actual flush occurs on the same CPU 33062306a36Sopenharmony_ci as did the cpu stores into the page to make it 33162306a36Sopenharmony_ci dirty. Again, see sparc64 for examples of how 33262306a36Sopenharmony_ci to deal with this. 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci ``void copy_to_user_page(struct vm_area_struct *vma, struct page *page, 33562306a36Sopenharmony_ci unsigned long user_vaddr, void *dst, void *src, int len)`` 33662306a36Sopenharmony_ci ``void copy_from_user_page(struct vm_area_struct *vma, struct page *page, 33762306a36Sopenharmony_ci unsigned long user_vaddr, void *dst, void *src, int len)`` 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci When the kernel needs to copy arbitrary data in and out 34062306a36Sopenharmony_ci of arbitrary user pages (f.e. for ptrace()) it will use 34162306a36Sopenharmony_ci these two routines. 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci Any necessary cache flushing or other coherency operations 34462306a36Sopenharmony_ci that need to occur should happen here. If the processor's 34562306a36Sopenharmony_ci instruction cache does not snoop cpu stores, it is very 34662306a36Sopenharmony_ci likely that you will need to flush the instruction cache 34762306a36Sopenharmony_ci for copy_to_user_page(). 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ci ``void flush_anon_page(struct vm_area_struct *vma, struct page *page, 35062306a36Sopenharmony_ci unsigned long vmaddr)`` 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci When the kernel needs to access the contents of an anonymous 35362306a36Sopenharmony_ci page, it calls this function (currently only 35462306a36Sopenharmony_ci get_user_pages()). Note: flush_dcache_folio() deliberately 35562306a36Sopenharmony_ci doesn't work for an anonymous page. The default 35662306a36Sopenharmony_ci implementation is a nop (and should remain so for all coherent 35762306a36Sopenharmony_ci architectures). For incoherent architectures, it should flush 35862306a36Sopenharmony_ci the cache of the page at vmaddr. 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci ``void flush_icache_range(unsigned long start, unsigned long end)`` 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_ci When the kernel stores into addresses that it will execute 36362306a36Sopenharmony_ci out of (eg when loading modules), this function is called. 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci If the icache does not snoop stores then this routine will need 36662306a36Sopenharmony_ci to flush it. 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci ``void flush_icache_page(struct vm_area_struct *vma, struct page *page)`` 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci All the functionality of flush_icache_page can be implemented in 37162306a36Sopenharmony_ci flush_dcache_folio and update_mmu_cache_range. In the future, the hope 37262306a36Sopenharmony_ci is to remove this interface completely. 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ciThe final category of APIs is for I/O to deliberately aliased address 37562306a36Sopenharmony_ciranges inside the kernel. Such aliases are set up by use of the 37662306a36Sopenharmony_civmap/vmalloc API. Since kernel I/O goes via physical pages, the I/O 37762306a36Sopenharmony_cisubsystem assumes that the user mapping and kernel offset mapping are 37862306a36Sopenharmony_cithe only aliases. This isn't true for vmap aliases, so anything in 37962306a36Sopenharmony_cithe kernel trying to do I/O to vmap areas must manually manage 38062306a36Sopenharmony_cicoherency. It must do this by flushing the vmap range before doing 38162306a36Sopenharmony_ciI/O and invalidating it after the I/O returns. 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci ``void flush_kernel_vmap_range(void *vaddr, int size)`` 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci flushes the kernel cache for a given virtual address range in 38662306a36Sopenharmony_ci the vmap area. This is to make sure that any data the kernel 38762306a36Sopenharmony_ci modified in the vmap range is made visible to the physical 38862306a36Sopenharmony_ci page. The design is to make this area safe to perform I/O on. 38962306a36Sopenharmony_ci Note that this API does *not* also flush the offset map alias 39062306a36Sopenharmony_ci of the area. 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci ``void invalidate_kernel_vmap_range(void *vaddr, int size) invalidates`` 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci the cache for a given virtual address range in the vmap area 39562306a36Sopenharmony_ci which prevents the processor from making the cache stale by 39662306a36Sopenharmony_ci speculatively reading data while the I/O was occurring to the 39762306a36Sopenharmony_ci physical pages. This is only necessary for data reads into the 39862306a36Sopenharmony_ci vmap area. 399