提交 95cf9264 编写于 作者: T Tom Lendacky 提交者: Ingo Molnar

x86, drm, fbdev: Do not specify encrypted memory for video mappings

Since video memory needs to be accessed decrypted, be sure that the
memory encryption mask is not set for the video ranges.
Signed-off-by: NTom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
Reviewed-by: NBorislav Petkov <bp@suse.de>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Larry Woodman <lwoodman@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Toshimitsu Kani <toshi.kani@hpe.com>
Cc: kasan-dev@googlegroups.com
Cc: kvm@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-efi@vger.kernel.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/a19436f30424402e01f63a09b32ab103272acced.1500319216.git.thomas.lendacky@amd.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
上级 46d010e0
...@@ -7,12 +7,24 @@ ...@@ -7,12 +7,24 @@
#ifndef _ASM_X86_VGA_H #ifndef _ASM_X86_VGA_H
#define _ASM_X86_VGA_H #define _ASM_X86_VGA_H
#include <asm/set_memory.h>
/* /*
* On the PC, we can just recalculate addresses and then * On the PC, we can just recalculate addresses and then
* access the videoram directly without any black magic. * access the videoram directly without any black magic.
* To support memory encryption however, we need to access
* the videoram as decrypted memory.
*/ */
#define VGA_MAP_MEM(x, s) (unsigned long)phys_to_virt(x) #define VGA_MAP_MEM(x, s) \
({ \
unsigned long start = (unsigned long)phys_to_virt(x); \
\
if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) \
set_memory_decrypted(start, (s) >> PAGE_SHIFT); \
\
start; \
})
#define vga_readb(x) (*(x)) #define vga_readb(x) (*(x))
#define vga_writeb(x, y) (*(y) = (x)) #define vga_writeb(x, y) (*(y) = (x))
......
...@@ -1831,11 +1831,13 @@ int set_memory_encrypted(unsigned long addr, int numpages) ...@@ -1831,11 +1831,13 @@ int set_memory_encrypted(unsigned long addr, int numpages)
{ {
return __set_memory_enc_dec(addr, numpages, true); return __set_memory_enc_dec(addr, numpages, true);
} }
EXPORT_SYMBOL_GPL(set_memory_encrypted);
int set_memory_decrypted(unsigned long addr, int numpages) int set_memory_decrypted(unsigned long addr, int numpages)
{ {
return __set_memory_enc_dec(addr, numpages, false); return __set_memory_enc_dec(addr, numpages, false);
} }
EXPORT_SYMBOL_GPL(set_memory_decrypted);
int set_pages_uc(struct page *page, int numpages) int set_pages_uc(struct page *page, int numpages)
{ {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/shmem_fs.h> #include <linux/shmem_fs.h>
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <linux/mem_encrypt.h>
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/drm_vma_manager.h> #include <drm/drm_vma_manager.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
...@@ -928,6 +929,7 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, ...@@ -928,6 +929,7 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
vma->vm_ops = dev->driver->gem_vm_ops; vma->vm_ops = dev->driver->gem_vm_ops;
vma->vm_private_data = obj; vma->vm_private_data = obj;
vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
/* Take a ref for this mapping of the object, so that the fault /* Take a ref for this mapping of the object, so that the fault
* handler can dereference the mmap offset's pointer to the object. * handler can dereference the mmap offset's pointer to the object.
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/efi.h> #include <linux/efi.h>
#include <linux/slab.h> #include <linux/slab.h>
#endif #endif
#include <linux/mem_encrypt.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include "drm_internal.h" #include "drm_internal.h"
#include "drm_legacy.h" #include "drm_legacy.h"
...@@ -58,6 +59,9 @@ static pgprot_t drm_io_prot(struct drm_local_map *map, ...@@ -58,6 +59,9 @@ static pgprot_t drm_io_prot(struct drm_local_map *map,
{ {
pgprot_t tmp = vm_get_page_prot(vma->vm_flags); pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
/* We don't want graphics memory to be mapped encrypted */
tmp = pgprot_decrypted(tmp);
#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
if (map->type == _DRM_REGISTERS && !(map->flags & _DRM_WRITE_COMBINING)) if (map->type == _DRM_REGISTERS && !(map->flags & _DRM_WRITE_COMBINING))
tmp = pgprot_noncached(tmp); tmp = pgprot_noncached(tmp);
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/mem_encrypt.h>
#define TTM_BO_VM_NUM_PREFAULT 16 #define TTM_BO_VM_NUM_PREFAULT 16
...@@ -230,9 +231,11 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf) ...@@ -230,9 +231,11 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
* first page. * first page.
*/ */
for (i = 0; i < TTM_BO_VM_NUM_PREFAULT; ++i) { for (i = 0; i < TTM_BO_VM_NUM_PREFAULT; ++i) {
if (bo->mem.bus.is_iomem) if (bo->mem.bus.is_iomem) {
/* Iomem should not be marked encrypted */
cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
pfn = bdev->driver->io_mem_pfn(bo, page_offset); pfn = bdev->driver->io_mem_pfn(bo, page_offset);
else { } else {
page = ttm->pages[page_offset]; page = ttm->pages[page_offset];
if (unlikely(!page && i == 0)) { if (unlikely(!page && i == 0)) {
retval = VM_FAULT_OOM; retval = VM_FAULT_OOM;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <linux/mem_encrypt.h>
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/drm_crtc.h> #include <drm/drm_crtc.h>
...@@ -169,6 +170,9 @@ static int udl_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) ...@@ -169,6 +170,9 @@ static int udl_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
pr_notice("mmap() framebuffer addr:%lu size:%lu\n", pr_notice("mmap() framebuffer addr:%lu size:%lu\n",
pos, size); pos, size);
/* We don't want the framebuffer to be mapped encrypted */
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
while (size > 0) { while (size > 0) {
page = vmalloc_to_pfn((void *)pos); page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/efi.h> #include <linux/efi.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <linux/mem_encrypt.h>
#include <asm/fb.h> #include <asm/fb.h>
...@@ -1396,6 +1397,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) ...@@ -1396,6 +1397,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
mutex_lock(&info->mm_lock); mutex_lock(&info->mm_lock);
if (fb->fb_mmap) { if (fb->fb_mmap) {
int res; int res;
/*
* The framebuffer needs to be accessed decrypted, be sure
* SME protection is removed ahead of the call
*/
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
res = fb->fb_mmap(info, vma); res = fb->fb_mmap(info, vma);
mutex_unlock(&info->mm_lock); mutex_unlock(&info->mm_lock);
return res; return res;
...@@ -1421,6 +1428,11 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) ...@@ -1421,6 +1428,11 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
mutex_unlock(&info->mm_lock); mutex_unlock(&info->mm_lock);
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
/*
* The framebuffer needs to be accessed decrypted, be sure
* SME protection is removed
*/
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
fb_pgprotect(file, vma, start); fb_pgprotect(file, vma, start);
return vm_iomap_memory(vma, start, len); return vm_iomap_memory(vma, start, len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册