Skip to content

Commit 593befa

Browse files
Dominik DingelMartin Schwidefsky
authored andcommitted
mm: introduce mm_forbids_zeropage function
Add a new function stub to allow architectures to disable for an mm_structthe backing of non-present, anonymous pages with read-only empty zero pages. Signed-off-by: Dominik Dingel <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Signed-off-by: Martin Schwidefsky <[email protected]>
1 parent a13cff3 commit 593befa

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

include/linux/mm.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ extern int sysctl_legacy_va_layout;
5656
#define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
5757
#endif
5858

59+
/*
60+
* To prevent common memory management code establishing
61+
* a zero page mapping on a read fault.
62+
* This macro should be defined within <asm/pgtable.h>.
63+
* s390 does this to prevent multiplexing of hardware bits
64+
* related to the physical page in case of virtualization.
65+
*/
66+
#ifndef mm_forbids_zeropage
67+
#define mm_forbids_zeropage(X) (0)
68+
#endif
69+
5970
extern unsigned long sysctl_user_reserve_kbytes;
6071
extern unsigned long sysctl_admin_reserve_kbytes;
6172

mm/huge_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ int do_huge_pmd_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
805805
return VM_FAULT_OOM;
806806
if (unlikely(khugepaged_enter(vma)))
807807
return VM_FAULT_OOM;
808-
if (!(flags & FAULT_FLAG_WRITE) &&
808+
if (!(flags & FAULT_FLAG_WRITE) && !mm_forbids_zeropage(mm) &&
809809
transparent_hugepage_use_zero_page()) {
810810
spinlock_t *ptl;
811811
pgtable_t pgtable;

mm/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
26402640
return VM_FAULT_SIGBUS;
26412641

26422642
/* Use the zero-page for reads */
2643-
if (!(flags & FAULT_FLAG_WRITE)) {
2643+
if (!(flags & FAULT_FLAG_WRITE) && !mm_forbids_zeropage(mm)) {
26442644
entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
26452645
vma->vm_page_prot));
26462646
page_table = pte_offset_map_lock(mm, pmd, address, &ptl);

0 commit comments

Comments
 (0)