]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/mm: Add a x86_has_pat_wp() helper
authorChristoph Hellwig <hch@lst.de>
Wed, 8 Apr 2020 15:27:42 +0000 (17:27 +0200)
committerBorislav Petkov <bp@suse.de>
Mon, 20 Apr 2020 10:39:11 +0000 (12:39 +0200)
Abstract the ioremap code away from the caching mode internals.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200408152745.1565832-2-hch@lst.de
arch/x86/include/asm/memtype.h
arch/x86/mm/init.c
arch/x86/mm/ioremap.c

index 9c2447b3555dc3fefab63235d3feda8f554efc0e..1e4e99b407110fe558fe5f6b202a1c8122a3406d 100644 (file)
@@ -24,4 +24,6 @@ extern void memtype_free_io(resource_size_t start, resource_size_t end);
 
 extern bool pat_pfn_immune_to_uc_mtrr(unsigned long pfn);
 
+bool x86_has_pat_wp(void);
+
 #endif /* _ASM_X86_MEMTYPE_H */
index 1bba16c5742b3307bfbb69f9978cc489062e92e1..6005f83b8111190d36f46d00b9f01d06922c54c5 100644 (file)
@@ -71,6 +71,12 @@ uint8_t __pte2cachemode_tbl[8] = {
 };
 EXPORT_SYMBOL(__pte2cachemode_tbl);
 
+/* Check that the write-protect PAT entry is set for write-protect */
+bool x86_has_pat_wp(void)
+{
+       return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] == _PAGE_CACHE_MODE_WP;
+}
+
 static unsigned long __initdata pgt_buf_start;
 static unsigned long __initdata pgt_buf_end;
 static unsigned long __initdata pgt_buf_top;
index 18c637c0dc6fa8c2f51393903f8d4e1546fb6d5d..41536f523a5ffe43285bd4c03476ef537dfe1bd2 100644 (file)
@@ -778,10 +778,8 @@ void __init *early_memremap_encrypted(resource_size_t phys_addr,
 void __init *early_memremap_encrypted_wp(resource_size_t phys_addr,
                                         unsigned long size)
 {
-       /* Be sure the write-protect PAT entry is set for write-protect */
-       if (__pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] != _PAGE_CACHE_MODE_WP)
+       if (!x86_has_pat_wp())
                return NULL;
-
        return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_ENC_WP);
 }
 
@@ -799,10 +797,8 @@ void __init *early_memremap_decrypted(resource_size_t phys_addr,
 void __init *early_memremap_decrypted_wp(resource_size_t phys_addr,
                                         unsigned long size)
 {
-       /* Be sure the write-protect PAT entry is set for write-protect */
-       if (__pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] != _PAGE_CACHE_MODE_WP)
+       if (!x86_has_pat_wp())
                return NULL;
-
        return early_memremap_prot(phys_addr, size, __PAGE_KERNEL_NOENC_WP);
 }
 #endif /* CONFIG_AMD_MEM_ENCRYPT */