Skip to content

Commit 954ffcb

Browse files
hkamezawaLinus Torvalds
authored andcommitted
flush icache before set_pte() on ia64: flush icache at set_pte
Current ia64 kernel flushes icache by lazy_mmu_prot_update() *after* set_pte(). This is too late. This patch removes lazy_mmu_prot_update and add modfied set_pte() for flushing if necessary. This patch flush icache of a page when new pte has exec bit. && new pte has present bit && new pte is user's page. && (old *ptep is not present || new pte's pfn is not same to old *ptep's ptn) && new pte's page has no Pg_arch_1 bit. Pg_arch_1 is set when a page is cache consistent. I think this condition checks are much easier to understand than considering "Where sync_icache_dcache() should be inserted ?". pte_user() for ia64 was removed by http://lkml.org/lkml/2007/6/12/67 as clean-up. So, I added it again. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: "Luck, Tony" <tony.luck@intel.com> Cc: Christoph Lameter <clameter@sgi.com> Cc: Hugh Dickins <hugh@veritas.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 97ee052 commit 954ffcb

9 files changed

Lines changed: 33 additions & 39 deletions

File tree

‎Documentation/cachetlb.txt‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ changes occur:
133133
The ia64 sn2 platform is one example of a platform
134134
that uses this interface.
135135

136-
8) void lazy_mmu_prot_update(pte_t pte)
137-
This interface is called whenever the protection on
138-
any user PTEs change. This interface provides a notification
139-
to architecture specific code to take appropriate action.
140-
141-
142136
Next, we have the cache flushing interfaces. In general, when Linux
143137
is changing an existing virtual-->physical mapping to a new value,
144138
the sequence will be in one of the following forms:

‎arch/ia64/mm/init.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ struct page *zero_page_memmap_ptr; /* map entry for zero page */
5454
EXPORT_SYMBOL(zero_page_memmap_ptr);
5555

5656
void
57-
lazy_mmu_prot_update (pte_t pte)
57+
__ia64_sync_icache_dcache (pte_t pte)
5858
{
5959
unsigned long addr;
6060
struct page *page;
6161
unsigned long order;
6262

63-
if (!pte_exec(pte))
64-
return; /* not an executable page... */
65-
6663
page = pte_page(pte);
6764
addr = (unsigned long) page_address(page);
6865

‎include/asm-generic/pgtable.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres
125125
#define pgd_offset_gate(mm, addr) pgd_offset(mm, addr)
126126
#endif
127127

128-
#ifndef __HAVE_ARCH_LAZY_MMU_PROT_UPDATE
129-
#define lazy_mmu_prot_update(pte) do { } while (0)
130-
#endif
131-
132128
#ifndef __HAVE_ARCH_MOVE_PTE
133129
#define move_pte(pte, prot, old_addr, new_addr) (pte)
134130
#endif

‎include/asm-ia64/pgtable.h‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ ia64_phys_addr_valid (unsigned long addr)
223223
* page table.
224224
*/
225225

226-
/*
227-
* On some architectures, special things need to be done when setting
228-
* the PTE in a page table. Nothing special needs to be on IA-64.
229-
*/
230-
#define set_pte(ptep, pteval) (*(ptep) = (pteval))
231-
#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
232226

233227
#define VMALLOC_START (RGN_BASE(RGN_GATE) + 0x200000000UL)
234228
#ifdef CONFIG_VIRTUAL_MEM_MAP
@@ -320,6 +314,36 @@ ia64_phys_addr_valid (unsigned long addr)
320314
#define pte_mkdirty(pte) (__pte(pte_val(pte) | _PAGE_D))
321315
#define pte_mkhuge(pte) (__pte(pte_val(pte)))
322316

317+
/*
318+
* Because ia64's Icache and Dcache is not coherent (on a cpu), we need to
319+
* sync icache and dcache when we insert *new* executable page.
320+
* __ia64_sync_icache_dcache() check Pg_arch_1 bit and flush icache
321+
* if necessary.
322+
*
323+
* set_pte() is also called by the kernel, but we can expect that the kernel
324+
* flushes icache explicitly if necessary.
325+
*/
326+
#define pte_present_exec_user(pte)\
327+
((pte_val(pte) & (_PAGE_P | _PAGE_PL_MASK | _PAGE_AR_RX)) == \
328+
(_PAGE_P | _PAGE_PL_3 | _PAGE_AR_RX))
329+
330+
extern void __ia64_sync_icache_dcache(pte_t pteval);
331+
static inline void set_pte(pte_t *ptep, pte_t pteval)
332+
{
333+
/* page is present && page is user && page is executable
334+
* && (page swapin or new page or page migraton
335+
* || copy_on_write with page copying.)
336+
*/
337+
if (pte_present_exec_user(pteval) &&
338+
(!pte_present(*ptep) ||
339+
pte_pfn(*ptep) != pte_pfn(pteval)))
340+
/* load_module() calles flush_icache_range() explicitly*/
341+
__ia64_sync_icache_dcache(pteval);
342+
*ptep = pteval;
343+
}
344+
345+
#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
346+
323347
/*
324348
* Make page protection values cacheable, uncacheable, or write-
325349
* combining. Note that "protection" is really a misnomer here as the
@@ -489,12 +513,6 @@ extern struct page *zero_page_memmap_ptr;
489513
#define HUGETLB_PGDIR_MASK (~(HUGETLB_PGDIR_SIZE-1))
490514
#endif
491515

492-
/*
493-
* IA-64 doesn't have any external MMU info: the page tables contain all the necessary
494-
* information. However, we use this routine to take care of any (delayed) i-cache
495-
* flushing that may be necessary.
496-
*/
497-
extern void lazy_mmu_prot_update (pte_t pte);
498516

499517
#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
500518
/*
@@ -584,7 +602,7 @@ extern void lazy_mmu_prot_update (pte_t pte);
584602
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
585603
#define __HAVE_ARCH_PTE_SAME
586604
#define __HAVE_ARCH_PGD_OFFSET_GATE
587-
#define __HAVE_ARCH_LAZY_MMU_PROT_UPDATE
605+
588606

589607
#ifndef CONFIG_PGTABLE_4
590608
#include <asm-generic/pgtable-nopud.h>

‎mm/hugetlb.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ static void set_huge_ptep_writable(struct vm_area_struct *vma,
355355
entry = pte_mkwrite(pte_mkdirty(*ptep));
356356
if (ptep_set_access_flags(vma, address, ptep, entry, 1)) {
357357
update_mmu_cache(vma, address, entry);
358-
lazy_mmu_prot_update(entry);
359358
}
360359
}
361360

@@ -708,7 +707,6 @@ void hugetlb_change_protection(struct vm_area_struct *vma,
708707
pte = huge_ptep_get_and_clear(mm, address, ptep);
709708
pte = pte_mkhuge(pte_modify(pte, newprot));
710709
set_huge_pte_at(mm, address, ptep, pte);
711-
lazy_mmu_prot_update(pte);
712710
}
713711
}
714712
spin_unlock(&mm->page_table_lock);

‎mm/memory.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,10 +1611,8 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
16111611
flush_cache_page(vma, address, pte_pfn(orig_pte));
16121612
entry = pte_mkyoung(orig_pte);
16131613
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
1614-
if (ptep_set_access_flags(vma, address, page_table, entry,1)) {
1614+
if (ptep_set_access_flags(vma, address, page_table, entry,1))
16151615
update_mmu_cache(vma, address, entry);
1616-
lazy_mmu_prot_update(entry);
1617-
}
16181616
ret |= VM_FAULT_WRITE;
16191617
goto unlock;
16201618
}
@@ -1650,7 +1648,6 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
16501648
flush_cache_page(vma, address, pte_pfn(orig_pte));
16511649
entry = mk_pte(new_page, vma->vm_page_prot);
16521650
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
1653-
lazy_mmu_prot_update(entry);
16541651
/*
16551652
* Clear the pte entry and flush it first, before updating the
16561653
* pte with the new entry. This will avoid a race condition
@@ -2180,7 +2177,6 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
21802177

21812178
/* No need to invalidate - it was non-present before */
21822179
update_mmu_cache(vma, address, entry);
2183-
lazy_mmu_prot_update(entry);
21842180
unlock:
21852181
pte_unmap_unlock(page_table, ptl);
21862182
return 0;
@@ -2333,7 +2329,6 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
23332329

23342330
/* no need to invalidate: a not-present page won't be cached */
23352331
update_mmu_cache(vma, address, entry);
2336-
lazy_mmu_prot_update(entry);
23372332
} else {
23382333
if (anon)
23392334
page_cache_release(page);
@@ -2505,7 +2500,6 @@ static inline int handle_pte_fault(struct mm_struct *mm,
25052500
entry = pte_mkyoung(entry);
25062501
if (ptep_set_access_flags(vma, address, pte, entry, write_access)) {
25072502
update_mmu_cache(vma, address, entry);
2508-
lazy_mmu_prot_update(entry);
25092503
} else {
25102504
/*
25112505
* This is needed only for protection faults but the arch code

‎mm/migrate.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ static void remove_migration_pte(struct vm_area_struct *vma,
181181

182182
/* No need to invalidate - it was non-present before */
183183
update_mmu_cache(vma, addr, pte);
184-
lazy_mmu_prot_update(pte);
185184

186185
out:
187186
pte_unmap_unlock(ptep, ptl);

‎mm/mprotect.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static void change_pte_range(struct mm_struct *mm, pmd_t *pmd,
5353
if (dirty_accountable && pte_dirty(ptent))
5454
ptent = pte_mkwrite(ptent);
5555
set_pte_at(mm, addr, pte, ptent);
56-
lazy_mmu_prot_update(ptent);
5756
#ifdef CONFIG_MIGRATION
5857
} else if (!pte_file(oldpte)) {
5958
swp_entry_t entry = pte_to_swp_entry(oldpte);

‎mm/rmap.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ static int page_mkclean_one(struct page *page, struct vm_area_struct *vma)
436436
entry = pte_wrprotect(entry);
437437
entry = pte_mkclean(entry);
438438
set_pte_at(mm, address, pte, entry);
439-
lazy_mmu_prot_update(entry);
440439
ret = 1;
441440
}
442441

0 commit comments

Comments
 (0)