• Toshi Kani's avatar
    x86/mm/mtrr: Fix MTRR lookup to handle an inclusive entry · 7f0431e3
    Toshi Kani authored
    When an MTRR entry is inclusive to a requested range, i.e. the
    start and end of the request are not within the MTRR entry range
    but the range contains the MTRR entry entirely:
      range_start ... [mtrr_start ... mtrr_end] ... range_end
    __mtrr_type_lookup() ignores such a case because both
    start_state and end_state are set to zero.
    This bug can cause the following issues:
    1) reserve_memtype() tracks an effective memory type in case
       a request type is WB (ex. /dev/mem blindly uses WB). Missing
       to track with its effective type causes a subsequent request
       to map the same range with the effective type to fail.
    2) pud_set_huge() and pmd_set_huge() check if a requested range
       has any overlap with MTRRs. Missing to detect an overlap may
       cause a performance penalty or undefined behavior.
    This patch fixes the bug by adding a new flag, 'inclusive',
    to detect the inclusive case.  This case is then handled in
    the same way as end_state:1 since the first region is the same.
    With this fix, __mtrr_type_lookup() handles the inclusive case
    Signed-off-by: default avatarToshi Kani <toshi.kani@hp.com>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Lutomirski <luto@amacapital.net>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Denys Vlasenko <dvlasenk@redhat.com>
    Cc: Elliott@hp.com
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Luis R. Rodriguez <mcgrof@suse.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: dave.hansen@intel.com
    Cc: linux-mm <linux-mm@kvack.org>
    Cc: pebolle@tiscali.nl
    Link: http://lkml.kernel.org/r/1431714237-880-3-git-send-email-toshi.kani@hp.com
    Link: http://lkml.kernel.org/r/1432628901-18044-3-git-send-email-bp@alien8.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
generic.c 21.1 KB