lkml.org 
[lkml]   [2022]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2 20/39] mm/mprotect: Exclude shadow stack from preserve_write
    Date
    From: Yu-cheng Yu <yu-cheng.yu@intel.com>

    In change_pte_range(), when a PTE is changed for prot_numa, _PAGE_RW is
    preserved to avoid the additional write fault after the NUMA hinting fault.
    However, pte_write() now includes both normal writable and shadow stack
    (Write=0, Dirty=1) PTEs, but the latter does not have _PAGE_RW and has no
    need to preserve it.

    Exclude shadow stack from preserve_write test, and apply the same change to
    change_huge_pmd().

    Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
    Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>

    ---

    Yu-cheng v25:
    - Move is_shadow_stack_mapping() to a separate line.

    Yu-cheng v24:
    - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping().

    mm/huge_memory.c | 7 +++++++
    mm/mprotect.c | 7 +++++++
    2 files changed, 14 insertions(+)

    diff --git a/mm/huge_memory.c b/mm/huge_memory.c
    index 11fc69eb4717..492c4f190f55 100644
    --- a/mm/huge_memory.c
    +++ b/mm/huge_memory.c
    @@ -1800,6 +1800,13 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
    return 0;

    preserve_write = prot_numa && pmd_write(*pmd);
    +
    + /*
    + * Preserve only normal writable huge PMD, but not shadow
    + * stack (RW=0, Dirty=1).
    + */
    + if (vma->vm_flags & VM_SHADOW_STACK)
    + preserve_write = false;
    ret = 1;

    #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
    diff --git a/mm/mprotect.c b/mm/mprotect.c
    index bc6bddd156ca..983206529dce 100644
    --- a/mm/mprotect.c
    +++ b/mm/mprotect.c
    @@ -114,6 +114,13 @@ static unsigned long change_pte_range(struct mmu_gather *tlb,
    pte_t ptent;
    bool preserve_write = prot_numa && pte_write(oldpte);

    + /*
    + * Preserve only normal writable PTE, but not shadow
    + * stack (RW=0, Dirty=1).
    + */
    + if (vma->vm_flags & VM_SHADOW_STACK)
    + preserve_write = false;
    +
    /*
    * Avoid trapping faults against the zero or KSM
    * pages. See similar comment in change_huge_pmd.
    --
    2.17.1
    \
     
     \ /
      Last update: 2022-09-30 00:35    [W:3.200 / U:0.124 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site