1. 17 1月, 2020 15 次提交
  2. 15 1月, 2020 20 次提交
  3. 02 1月, 2020 1 次提交
  4. 27 12月, 2019 4 次提交
    • T
      x86/mm/cpa: Prevent large page split when ftrace flips RW on kernel text · da57ae3d
      Thomas Gleixner 提交于
      commit 7af0145067bc429a09ac4047b167c0971c9f0dc7 upstream.
      
      ftrace does not use text_poke() for enabling trace functionality. It uses
      its own mechanism and flips the whole kernel text to RW and back to RO.
      
      The CPA rework removed a loop based check of 4k pages which tried to
      preserve a large page by checking each 4k page whether the change would
      actually cover all pages in the large page.
      
      This resulted in endless loops for nothing as in testing it turned out that
      it actually never preserved anything. Of course testing missed to include
      ftrace, which is the one and only case which benefitted from the 4k loop.
      
      As a consequence enabling function tracing or ftrace based kprobes results
      in a full 4k split of the kernel text, which affects iTLB performance.
      
      The kernel RO protection is the only valid case where this can actually
      preserve large pages.
      
      All other static protections (RO data, data NX, PCI, BIOS) are truly
      static.  So a conflict with those protections which results in a split
      should only ever happen when a change of memory next to a protected region
      is attempted. But these conflicts are rightfully splitting the large page
      to preserve the protected regions. In fact a change to the protected
      regions itself is a bug and is warned about.
      
      Add an exception for the static protection check for kernel text RO when
      the to be changed region spawns a full large page which allows to preserve
      the large mappings. This also prevents the syslog to be spammed about CPA
      violations when ftrace is used.
      
      The exception needs to be removed once ftrace switched over to text_poke()
      which avoids the whole issue.
      
      Fixes: 585948f4f695 ("x86/mm/cpa: Avoid the 4k pages check completely")
      Reported-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Tested-by: NSong Liu <songliubraving@fb.com>
      Reviewed-by: NSong Liu <songliubraving@fb.com>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1908282355340.1938@nanos.tec.linutronix.deSigned-off-by: NShile Zhang <shile.zhang@linux.alibaba.com>
      Reviewed-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
      da57ae3d
    • Q
      x86/mm: Remove unused variable 'old_pte' · 9737e3ab
      Qian Cai 提交于
      commit 24c41220659ecc5576c34c6f23537f8d3949fb05 upstream.
      
      The commit 3a19109e ("x86/mm: Fix try_preserve_large_page() to
      handle large PAT bit") fixed try_preserve_large_page() by using the
      corresponding pud/pmd prot/pfn interfaces, but left a variable unused
      because it no longer used pte_pfn().
      
      Later, the commit 8679de0959e6 ("x86/mm/cpa: Split, rename and clean up
      try_preserve_large_page()") renamed try_preserve_large_page() to
      __should_split_large_page(), but the unused variable remains.
      
      arch/x86/mm/pageattr.c: In function '__should_split_large_page':
      arch/x86/mm/pageattr.c:741:17: warning: variable 'old_pte' set but not
      used [-Wunused-but-set-variable]
      
      Fixes: 3a19109e ("x86/mm: Fix try_preserve_large_page() to handle large PAT bit")
      Signed-off-by: NQian Cai <cai@lca.pw>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: dave.hansen@linux.intel.com
      Cc: luto@kernel.org
      Cc: peterz@infradead.org
      Cc: toshi.kani@hpe.com
      Cc: bp@alien8.de
      Cc: hpa@zytor.com
      Link: https://lkml.kernel.org/r/20190301152924.94762-1-cai@lca.pwSigned-off-by: NShile Zhang <shile.zhang@linux.alibaba.com>
      Reviewed-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
      9737e3ab
    • T
      x86/mm/cpa: Avoid the 4k pages check completely · d5c07e58
      Thomas Gleixner 提交于
      commit 585948f4f695b07204702cfee0f828424af32aa7 upstream.
      
      The extra loop which tries hard to preserve large pages in case of conflicts
      with static protection regions turns out to be not preserving anything, at
      least not in the experiments which have been conducted.
      
      There might be corner cases in which the code would be able to preserve a
      large page oaccsionally, but it's really not worth the extra code and the
      cycles wasted in the common case.
      
      Before:
      
       1G pages checked:                    2
       1G pages sameprot:                   0
       1G pages preserved:                  0
       2M pages checked:                  541
       2M pages sameprot:                 466
       2M pages preserved:                 47
       4K pages checked:                  514
       4K pages set-checked:             7668
      
      After:
       1G pages checked:                    2
       1G pages sameprot:                   0
       1G pages preserved:                  0
       2M pages checked:                  538
       2M pages sameprot:                 466
       2M pages preserved:                 47
       4K pages set-checked:             7668
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NDave Hansen <dave.hansen@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Bin Yang <bin.yang@intel.com>
      Cc: Mark Gross <mark.gross@intel.com>
      Link: https://lkml.kernel.org/r/20180917143546.589642503@linutronix.deSigned-off-by: NShile Zhang <shile.zhang@linux.alibaba.com>
      Acked-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
      d5c07e58
    • T
      x86/mm/cpa: Do the range check early · d935f3fe
      Thomas Gleixner 提交于
      commit 9cc9f17a5a0a8564b41b7c5c460e7f078c42d712 upstream.
      
      To avoid excessive 4k wise checks in the common case do a quick check first
      whether the requested new page protections conflict with a static
      protection area in the large page. If there is no conflict then the
      decision whether to preserve or to split the page can be made immediately.
      
      If the requested range covers the full large page, preserve it. Otherwise
      split it up. No point in doing a slow crawl in 4k steps.
      
      Before:
      
       1G pages checked:                    2
       1G pages sameprot:                   0
       1G pages preserved:                  0
       2M pages checked:                  538
       2M pages sameprot:                 466
       2M pages preserved:                 47
       4K pages checked:               560642
       4K pages set-checked:             7668
      
      After:
      
       1G pages checked:                    2
       1G pages sameprot:                   0
       1G pages preserved:                  0
       2M pages checked:                  541
       2M pages sameprot:                 466
       2M pages preserved:                 47
       4K pages checked:                  514
       4K pages set-checked:             7668
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NDave Hansen <dave.hansen@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Bin Yang <bin.yang@intel.com>
      Cc: Mark Gross <mark.gross@intel.com>
      Link: https://lkml.kernel.org/r/20180917143546.507259989@linutronix.deSigned-off-by: NShile Zhang <shile.zhang@linux.alibaba.com>
      Acked-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
      d935f3fe