Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754290AbcKJAiG (ORCPT ); Wed, 9 Nov 2016 19:38:06 -0500 Received: from mail-co1nam03on0049.outbound.protection.outlook.com ([104.47.40.49]:34528 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752796AbcKJAiB (ORCPT ); Wed, 9 Nov 2016 19:38:01 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [RFC PATCH v3 16/20] x86: Do not specify encrypted memory for video mappings To: , , , , , , , , CC: Rik van Riel , Radim =?utf-8?b?S3LEjW3DocWZ?= , Arnd Bergmann , Jonathan Corbet , Matt Fleming , Joerg Roedel , Konrad Rzeszutek Wilk , "Paolo Bonzini" , Larry Woodman , "Ingo Molnar" , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , "Thomas Gleixner" , Dmitry Vyukov Date: Wed, 9 Nov 2016 18:37:53 -0600 Message-ID: <20161110003753.3280.36113.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20161110003426.3280.2999.stgit@tlendack-t1.amdoffice.net> References: <20161110003426.3280.2999.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0040.namprd17.prod.outlook.com (10.175.189.26) To DM5PR12MB1148.namprd12.prod.outlook.com (10.168.236.143) X-MS-Office365-Filtering-Correlation-Id: 27af509a-ea4f-4b34-c389-08d40901d1e9 X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1148;2:MuK8AWHGNcFDg7Tz8T8uRekPbIgooSJNI8kpWhrfrzpbVsdPQ79Lx1Dt7qDxWxnjv+BV5gsU8N/jV1gl4+Vcim1Dm4x2l1t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CmR1xqUfV2PzcCVX4CaLXcp/X48lAQ==;20:DfkQkVg30lwJp6sMVhALCQVXlEhV0G2HN43m31M+HjycT0/nzd92zlIHk5VNre7bm2qy80TrDGlxxECPBduvzPaic/6JdZiYraIzlsxeaB2lKXBPh1f9n2nJrIYmxr0WtNCy6iZqT1+gomiZGhyeyIaKEqhFBgUZ5Aw2IYgwJZbHHcWWOeqZMbNhbmPcffqYohlT9F6rEVcwVpb8Li0bwzsN530vRirb9oGJBIzfhhefBvDAYkjYNg+8zFs6XOh+4Fxz22wuIIxCDkfQOfSc5SJY4alwEySt8BwKIiIbWKB2DC77RAOq5CuG4chbxyPCzHuM15ln5MSto1p+f8tHNHl5reCsoliuOWPr+2SRKoSYhGy81q7XpeFke9Ywlxdj0FtZ265ilmviDGUIbSLdCBlgPX5ZzPvuhZkw4BiJBr+sqNFpkS2pr0ojxp5Xn3APPPAQPTSrmLSld3jKeWoD3CZs4pg/I15Er6gYIw7FAxD+RgW3qANoWdYNwOFB0hwF X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026);SRVR:DM5PR12MB1148;BCL:0;PCL:0;RULEID:;SRVR:DM5PR12MB1148; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1148;4:LzQjyrOoqdOc4LdP/6EEbUdy/tuadZmUyN044kma/6YrtwFfzf4s6I72JSkAP+w/bzsvuobku++Pqmqq+ptBbbyJWtd6EvL5WSy+L8odRBUF9Mu/8r/jvb+aDNhg9PJMG5R0fvtwaR4PJ9VTwW9SChaIsidnF42sv6lGMbxbOmJnyDoSVyRJ4o/2mrJrQWeQRdLb1eLFdWQEYLvIwPw9sADaE745Moha/O/DLacx1/feG3qHs1F19Axe+jk+1TxE29fOACuxHHGa8ByjjOzSY4zxDBS1wQ33SfuRWGr/MoYd5+4M6d5QZEBf4Auebf5c96M2m7isuyMzYQaA/6j8nAu6MT56s+cCCjkvz4N4PNlQF0eKkhqLQe/+AGvZOVKZEyEtY/RMmVgqd3DQUbASWe/9y3oihojJLrPMu695Pjb08TMmWBEN2EV3MR2be0yEuQmYzaO5MtJxjTl+5APaQQ== X-Forefront-PRVS: 01221E3973 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(189998001)(69596002)(5001770100001)(4001350100001)(33646002)(50986999)(9686002)(97736004)(106356001)(101416001)(81156014)(50466002)(305945005)(8676002)(105586002)(7736002)(7846002)(81166006)(53416004)(83506001)(92566002)(42186005)(77096005)(4326007)(86362001)(1076002)(6666003)(5660300001)(6116002)(230700001)(586003)(7416002)(97746001)(2906002)(66066001)(2201001)(68736007)(23676002)(76176999)(54356999)(47776003)(2950100002)(103116003)(3846002)(71626007)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1148;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMTQ4OzIzOlRJazlVd3pMWStReXBRdFhJSzlMWlNCNFBo?= =?utf-8?B?d1ZqRXkxeXhxa3g0c0FvWG5sSkFjeGRLTjk2cDEzYUtPQTJxb3lMc1JWL1hm?= =?utf-8?B?N2UvZHc4cjlra1BQckVNVVNjQmtDWS9Jb0NTOEoyanNiWTVlY2xHY2gzM0Vl?= =?utf-8?B?bXJTV2NEUzNRK1dDNmdVN2dkVnJxOVNpcVdFV3RBTmYxeHhBYXNVblBxOXdr?= =?utf-8?B?NUdNTCtvVERhSlIvRjJxYUp5d3R5WjNESERYTlpobThpL3RFSWRmK1FNTmI4?= =?utf-8?B?cnYza1RpUkw1ZHpRUFlkQ0lTa2J1ZjBSdGpVV0RHNXRyN25Bb1hmdnByS2lw?= =?utf-8?B?eUVybUgxdmNwSHdzOURJdVNST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u8yJLM+XRhfgfq90Jdp/CxkwmZc397gcFyCHaYAiFBv4rgIbVYyoAUgeQrWtPGSu4i8/dRhep7CFgypaAuBlF0cBCCQ+gIU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1148;7:mVK+6nHyqLwUGgU1rEZR/x4e45AAVgZYbMB6m3QPG0pmBE38FXAmptMvxuzkspHeHkAXYFMI4eKdHjY2EvQaYJ1ViGeJBqD9+YZgnKp17kAHbGV00ZvhGrAw9mKDtabZGVwcNG6o5haNzKXXX+XaCgfxuBMCfqavEVwsWaSpOX7W7m5cP51Bu//tuvrNn1+aKujkYOjDZgicvB0PU42T/zy+26nzhQ92W/AvgIB5Ck+Ps/JWcmC8s0JhjoyRUz6VA/7Ci9YiF4w0zN90cFWlf4l7LAX/pqFGQBFfK5SOL5Ag61Y9FMpxll1/tIC/CnNDY5bminTUGVb0h0kwf+MSYY/3XTTUZIZf0K1xY/z74O4=;20:lcDvMl77XIwAp2bW3W53dF7GMCV+lKQabFHor7N76BQ6MmSYQd3peRwoRhatM/LLv5a1iOs6kPVyN4q8RjPIJkm+UfUiWTcJ5GtrnlbmemDFnaidvPIn4LhUlurOdWo1mXusMRKylcIDteQMUhxU/oV/udngepMKz3ltieJOlWrUaZAxme+kVNBXjUn7JNpL14LOo34RC0rSr2UJ52awPlWvYN+JwoT3ADtDYHbu7p5kkwlim7fFXiSwQEu04DwS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2016 00:37:56.3838 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1148 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5702 Lines: 170 Since video memory needs to be accessed unencrypted be sure that the memory encryption mask is not set for the video ranges. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/vga.h | 13 +++++++++++++ drivers/gpu/drm/drm_gem.c | 2 ++ drivers/gpu/drm/drm_vm.c | 4 ++++ drivers/gpu/drm/ttm/ttm_bo_vm.c | 7 +++++-- drivers/gpu/drm/udl/udl_fb.c | 4 ++++ drivers/video/fbdev/core/fbmem.c | 12 ++++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/vga.h b/arch/x86/include/asm/vga.h index c4b9dc2..7f944a4 100644 --- a/arch/x86/include/asm/vga.h +++ b/arch/x86/include/asm/vga.h @@ -7,12 +7,25 @@ #ifndef _ASM_X86_VGA_H #define _ASM_X86_VGA_H +#include + /* * On the PC, we can just recalculate addresses and then * access the videoram directly without any black magic. + * To support memory encryption however, we need to access + * the videoram as un-encrypted memory. */ +#ifdef CONFIG_AMD_MEM_ENCRYPT +#define VGA_MAP_MEM(x, s) \ +({ \ + unsigned long start = (unsigned long)phys_to_virt(x); \ + sme_set_mem_unenc((void *)start, s); \ + start; \ +}) +#else #define VGA_MAP_MEM(x, s) (unsigned long)phys_to_virt(x) +#endif #define vga_readb(x) (*(x)) #define vga_writeb(x, y) (*(y) = (x)) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 9134ae1..44f9563 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -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_private_data = obj; vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); + pgprot_val(vma->vm_page_prot) &= ~sme_me_mask; /* Take a ref for this mapping of the object, so that the fault * handler can dereference the mmap offset's pointer to the object. diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c index caa4e4c..d04752c 100644 --- a/drivers/gpu/drm/drm_vm.c +++ b/drivers/gpu/drm/drm_vm.c @@ -40,6 +40,7 @@ #include #include #endif +#include #include #include "drm_internal.h" #include "drm_legacy.h" @@ -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); + /* We don't want graphics memory to be mapped encrypted */ + pgprot_val(tmp) &= ~sme_me_mask; + #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) if (map->type == _DRM_REGISTERS && !(map->flags & _DRM_WRITE_COMBINING)) tmp = pgprot_noncached(tmp); diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c index a6ed9d5..f5fbd53 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -39,6 +39,7 @@ #include #include #include +#include #define TTM_BO_VM_NUM_PREFAULT 16 @@ -218,9 +219,11 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) * first page. */ 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 */ + pgprot_val(cvma.vm_page_prot) &= ~sme_me_mask; pfn = ((bo->mem.bus.base + bo->mem.bus.offset) >> PAGE_SHIFT) + page_offset; - else { + } else { page = ttm->pages[page_offset]; if (unlikely(!page && i == 0)) { retval = VM_FAULT_OOM; diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c index 611b6b9..64212ca 100644 --- a/drivers/gpu/drm/udl/udl_fb.c +++ b/drivers/gpu/drm/udl/udl_fb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -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", pos, size); + /* We don't want the framebuffer to be mapped encrypted */ + pgprot_val(vma->vm_page_prot) &= ~sme_me_mask; + while (size > 0) { page = vmalloc_to_pfn((void *)pos); if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 76c1ad9..ac51a5e 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -1405,6 +1406,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) mutex_lock(&info->mm_lock); if (fb->fb_mmap) { int res; + + /* + * The framebuffer needs to be accessed un-encrypted, be sure + * SME protection is removed ahead of the call + */ + pgprot_val(vma->vm_page_prot) &= ~sme_me_mask; res = fb->fb_mmap(info, vma); mutex_unlock(&info->mm_lock); return res; @@ -1430,6 +1437,11 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) mutex_unlock(&info->mm_lock); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); + /* + * The framebuffer needs to be accessed un-encrypted, be sure + * SME protection is removed + */ + pgprot_val(vma->vm_page_prot) &= ~sme_me_mask; fb_pgprotect(file, vma, start); return vm_iomap_memory(vma, start, len);