lkml.org 
[lkml]   [2020]   [Dec]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.19 09/57] arm64: pgtable: Fix pte_accessible()
    Date
    From: Will Deacon <will@kernel.org>

    commit 07509e10dcc77627f8b6a57381e878fe269958d3 upstream.

    pte_accessible() is used by ptep_clear_flush() to figure out whether TLB
    invalidation is necessary when unmapping pages for reclaim. Although our
    implementation is correct according to the architecture, returning true
    only for valid, young ptes in the absence of racing page-table
    modifications, this is in fact flawed due to lazy invalidation of old
    ptes in ptep_clear_flush_young() where we elide the expensive DSB
    instruction for completing the TLB invalidation.

    Rather than penalise the aging path, adjust pte_accessible() to return
    true for any valid pte, even if the access flag is cleared.

    Cc: <stable@vger.kernel.org>
    Fixes: 76c714be0e5e ("arm64: pgtable: implement pte_accessible()")
    Reported-by: Yu Zhao <yuzhao@google.com>
    Acked-by: Yu Zhao <yuzhao@google.com>
    Reviewed-by: Minchan Kim <minchan@kernel.org>
    Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
    Link: https://lore.kernel.org/r/20201120143557.6715-2-will@kernel.org
    Signed-off-by: Will Deacon <will@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    arch/arm64/include/asm/pgtable.h | 7 ++++---
    1 file changed, 4 insertions(+), 3 deletions(-)

    --- a/arch/arm64/include/asm/pgtable.h
    +++ b/arch/arm64/include/asm/pgtable.h
    @@ -107,8 +107,6 @@ extern unsigned long empty_zero_page[PAG
    #define pte_valid(pte) (!!(pte_val(pte) & PTE_VALID))
    #define pte_valid_not_user(pte) \
    ((pte_val(pte) & (PTE_VALID | PTE_USER)) == PTE_VALID)
    -#define pte_valid_young(pte) \
    - ((pte_val(pte) & (PTE_VALID | PTE_AF)) == (PTE_VALID | PTE_AF))
    #define pte_valid_user(pte) \
    ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER))

    @@ -116,9 +114,12 @@ extern unsigned long empty_zero_page[PAG
    * Could the pte be present in the TLB? We must check mm_tlb_flush_pending
    * so that we don't erroneously return false for pages that have been
    * remapped as PROT_NONE but are yet to be flushed from the TLB.
    + * Note that we can't make any assumptions based on the state of the access
    + * flag, since ptep_clear_flush_young() elides a DSB when invalidating the
    + * TLB.
    */
    #define pte_accessible(mm, pte) \
    - (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid_young(pte))
    + (mm_tlb_flush_pending(mm) ? pte_present(pte) : pte_valid(pte))

    /*
    * p??_access_permitted() is true for valid user mappings (subject to the

    \
     
     \ /
      Last update: 2020-12-01 10:04    [W:4.461 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site