Skip to content

Commit 38860b2

Browse files
danglin44hdeller
authored andcommitted
parisc: Flush kernel data mapping in set_pte_at() when installing pte for user page
For years, there have been random segmentation faults in userspace on SMP PA-RISC machines. It occurred to me that this might be a problem in set_pte_at(). MIPS and some other architectures do cache flushes when installing PTEs with the present bit set. Here I have adapted the code in update_mmu_cache() to flush the kernel mapping when the kernel flush is deferred, or when the kernel mapping may alias with the user mapping. This simplifies calls to update_mmu_cache(). I also changed the barrier in set_pte() from a compiler barrier to a full memory barrier. I know this change is not sufficient to fix the problem. It might not be needed. I have had a few days of operation with 5.14.16 to 5.15.1 and haven't seen any random segmentation faults on rp3440 or c8000 so far. Signed-off-by: John David Anglin <[email protected]> Signed-off-by: Helge Deller <[email protected]> Cc: [email protected] # 5.12+
1 parent f0d1cfa commit 38860b2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

arch/parisc/include/asm/pgtable.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,23 @@ static inline void purge_tlb_entries(struct mm_struct *mm, unsigned long addr)
7676
purge_tlb_end(flags);
7777
}
7878

79+
extern void __update_cache(pte_t pte);
80+
7981
/* Certain architectures need to do special things when PTEs
8082
* within a page table are directly modified. Thus, the following
8183
* hook is made available.
8284
*/
8385
#define set_pte(pteptr, pteval) \
8486
do { \
8587
*(pteptr) = (pteval); \
86-
barrier(); \
88+
mb(); \
8789
} while(0)
8890

8991
#define set_pte_at(mm, addr, pteptr, pteval) \
9092
do { \
93+
if (pte_present(pteval) && \
94+
pte_user(pteval)) \
95+
__update_cache(pteval); \
9196
*(pteptr) = (pteval); \
9297
purge_tlb_entries(mm, addr); \
9398
} while (0)
@@ -303,6 +308,7 @@ extern unsigned long *empty_zero_page;
303308

304309
#define pte_none(x) (pte_val(x) == 0)
305310
#define pte_present(x) (pte_val(x) & _PAGE_PRESENT)
311+
#define pte_user(x) (pte_val(x) & _PAGE_USER)
306312
#define pte_clear(mm, addr, xp) set_pte_at(mm, addr, xp, __pte(0))
307313

308314
#define pmd_flag(x) (pmd_val(x) & PxD_FLAG_MASK)
@@ -410,7 +416,7 @@ extern void paging_init (void);
410416

411417
#define PG_dcache_dirty PG_arch_1
412418

413-
extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
419+
#define update_mmu_cache(vms,addr,ptep) __update_cache(*ptep)
414420

415421
/* Encode and de-code a swap entry */
416422

arch/parisc/kernel/cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ EXPORT_SYMBOL(flush_cache_all_local);
8383
#define pfn_va(pfn) __va(PFN_PHYS(pfn))
8484

8585
void
86-
update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
86+
__update_cache(pte_t pte)
8787
{
88-
unsigned long pfn = pte_pfn(*ptep);
88+
unsigned long pfn = pte_pfn(pte);
8989
struct page *page;
9090

9191
/* We don't have pte special. As a result, we can be called with

0 commit comments

Comments
 (0)