Skip to content

Commit 985c30e

Browse files
committed
[MIPS] Fix aliasing bug in copy_user_highpage, take 2.
Turns out b868868 wasn't quite right. When called for a page that isn't marked dirty it would artificially create an alias instead of doing the obvious thing and access the page via KSEG0. The same issue also exists in copy_to_user_page and copy_from_user_page which was causing the machine to die under rare circumstances for example when running ps if the BUG_ON() assertion added by the earlier fix was getting triggered. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 736fad1 commit 985c30e

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎arch/mips/mm/init.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void copy_user_highpage(struct page *to, struct page *from,
211211
void *vfrom, *vto;
212212

213213
vto = kmap_atomic(to, KM_USER1);
214-
if (cpu_has_dc_aliases && !Page_dcache_dirty(from)) {
214+
if (cpu_has_dc_aliases && page_mapped(from)) {
215215
vfrom = kmap_coherent(from, vaddr);
216216
copy_page(vto, vfrom);
217217
kunmap_coherent();
@@ -234,12 +234,15 @@ void copy_to_user_page(struct vm_area_struct *vma,
234234
struct page *page, unsigned long vaddr, void *dst, const void *src,
235235
unsigned long len)
236236
{
237-
if (cpu_has_dc_aliases) {
237+
if (cpu_has_dc_aliases && page_mapped(page)) {
238238
void *vto = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
239239
memcpy(vto, src, len);
240240
kunmap_coherent();
241-
} else
241+
} else {
242242
memcpy(dst, src, len);
243+
if (cpu_has_dc_aliases)
244+
SetPageDcacheDirty(page);
245+
}
243246
if ((vma->vm_flags & VM_EXEC) && !cpu_has_ic_fills_f_dc)
244247
flush_cache_page(vma, vaddr, page_to_pfn(page));
245248
}
@@ -250,13 +253,15 @@ void copy_from_user_page(struct vm_area_struct *vma,
250253
struct page *page, unsigned long vaddr, void *dst, const void *src,
251254
unsigned long len)
252255
{
253-
if (cpu_has_dc_aliases) {
254-
void *vfrom =
255-
kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
256+
if (cpu_has_dc_aliases && page_mapped(page)) {
257+
void *vfrom = kmap_coherent(page, vaddr) + (vaddr & ~PAGE_MASK);
256258
memcpy(dst, vfrom, len);
257259
kunmap_coherent();
258-
} else
260+
} else {
259261
memcpy(dst, src, len);
262+
if (cpu_has_dc_aliases)
263+
SetPageDcacheDirty(page);
264+
}
260265
}
261266

262267
EXPORT_SYMBOL(copy_from_user_page);

0 commit comments

Comments
 (0)