Skip to content

Commit 510ee09

Browse files
djbwdavejiang
authored andcommitted
x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses
In preparation for using set_memory_uc() instead set_memory_np() for isolating poison from speculation, teach the memtype code to sanitize physical addresses vs __PHYSICAL_MASK. The motivation for using set_memory_uc() for this case is to allow ongoing access to persistent memory pages via the pmem-driver + memcpy_mcsafe() until the poison is repaired. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: <linux-edac@vger.kernel.org> Cc: <x86@kernel.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Acked-by: Ingo Molnar <mingo@redhat.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 6100e34 commit 510ee09

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arch/x86/mm/pat.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,17 @@ static int free_ram_pages_type(u64 start, u64 end)
512512
return 0;
513513
}
514514

515+
static u64 sanitize_phys(u64 address)
516+
{
517+
/*
518+
* When changing the memtype for pages containing poison allow
519+
* for a "decoy" virtual address (bit 63 clear) passed to
520+
* set_memory_X(). __pa() on a "decoy" address results in a
521+
* physical address with bit 63 set.
522+
*/
523+
return address & __PHYSICAL_MASK;
524+
}
525+
515526
/*
516527
* req_type typically has one of the:
517528
* - _PAGE_CACHE_MODE_WB
@@ -533,6 +544,8 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,
533544
int is_range_ram;
534545
int err = 0;
535546

547+
start = sanitize_phys(start);
548+
end = sanitize_phys(end);
536549
BUG_ON(start >= end); /* end is exclusive */
537550

538551
if (!pat_enabled()) {
@@ -609,6 +622,9 @@ int free_memtype(u64 start, u64 end)
609622
if (!pat_enabled())
610623
return 0;
611624

625+
start = sanitize_phys(start);
626+
end = sanitize_phys(end);
627+
612628
/* Low ISA region is always mapped WB. No need to track */
613629
if (x86_platform.is_untracked_pat_range(start, end))
614630
return 0;

0 commit comments

Comments
 (0)