OSDN Git Service

x86/speculation/l1tf: Protect swap entries against L1TF
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Jun 2018 22:48:23 +0000 (15:48 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 20 Jun 2018 17:09:59 +0000 (19:09 +0200)
commit2f22b4cd45b67b3496f4aa4c7180a1271c6452f6
treed825bf38c1beb5a30ba4d9440ee91e4b3fdc4124
parentbcd11afa7adad8d720e7ba5ef58bdcd9775cf45f
x86/speculation/l1tf: Protect swap entries against L1TF

With L1 terminal fault the CPU speculates into unmapped PTEs, and resulting
side effects allow to read the memory the PTE is pointing too, if its
values are still in the L1 cache.

For swapped out pages Linux uses unmapped PTEs and stores a swap entry into
them.

To protect against L1TF it must be ensured that the swap entry is not
pointing to valid memory, which requires setting higher bits (between bit
36 and bit 45) that are inside the CPUs physical address space, but outside
any real memory.

To do this invert the offset to make sure the higher bits are always set,
as long as the swap file is not too big.

Note there is no workaround for 32bit !PAE, or on systems which have more
than MAX_PA/2 worth of memory. The later case is very unlikely to happen on
real systems.

[AK: updated description and minor tweaks by. Split out from the original
     patch ]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Dave Hansen <dave.hansen@intel.com>
arch/x86/include/asm/pgtable_64.h