linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiandi An <jiandi.an@amd.com>
To: dri-devel@lists.freedesktop.org
Cc: jiandi.an@amd.com, christian.koenig@amd.com, ray.huang@amd.com,
	Jerry.Zhang@amd.com, airlied@linux.ie,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] drm/ttm: Set memory as decrypted for ttm framebuffer mappings
Date: Wed, 22 Aug 2018 13:57:54 -0500	[thread overview]
Message-ID: <20180822185754.104729-1-jiandi.an@amd.com> (raw)

Framebuffer memory needs to be accessed decrypted.  Ensure the
memory encryption mask is not set for the ttm framebuffer mappings.

Signed-off-by: Jiandi An <jiandi.an@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 12 +++++++++++-
 drivers/gpu/drm/ttm/ttm_bo_vm.c   |  6 ++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 046a6dda690a..b3f5d26f571e 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -29,6 +29,7 @@
  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  */
 
+#include <asm/set_memory.h>
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_placement.h>
 #include <drm/drm_vma_manager.h>
@@ -639,7 +640,11 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo,
 	if (ret)
 		return ret;
 	if (!bo->mem.bus.is_iomem) {
-		return ttm_bo_kmap_ttm(bo, start_page, num_pages, map);
+		ret = ttm_bo_kmap_ttm(bo, start_page, num_pages, map);
+		if (!ret && sev_active())
+			set_memory_decrypted((unsigned long) map->virtual,
+					     num_pages);
+		return ret;
 	} else {
 		offset = start_page << PAGE_SHIFT;
 		size = num_pages << PAGE_SHIFT;
@@ -661,9 +666,14 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
 		iounmap(map->virtual);
 		break;
 	case ttm_bo_map_vmap:
+		if (sev_active())
+			set_memory_encrypted((unsigned long) map->virtual,
+					     bo->num_pages);
 		vunmap(map->virtual);
 		break;
 	case ttm_bo_map_kmap:
+		if (sev_active())
+			set_memory_encrypted((unsigned long) map->virtual, 1);
 		kunmap(map->page);
 		break;
 	case ttm_bo_map_premapped:
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 6fe91c1b692d..211d3549fd9f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -249,10 +249,12 @@ static vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 	 * Speculatively prefault a number of pages. Only error on
 	 * first page.
 	 */
+
+	/* Mark framebuffer pages decrypted */
+	cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
+
 	for (i = 0; i < TTM_BO_VM_NUM_PREFAULT; ++i) {
 		if (bo->mem.bus.is_iomem) {
-			/* Iomem should not be marked encrypted */
-			cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
 			pfn = ttm_bo_io_mem_pfn(bo, page_offset);
 		} else {
 			page = ttm->pages[page_offset];
-- 
2.17.1


             reply	other threads:[~2018-08-22 18:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 18:57 Jiandi An [this message]
2018-08-22 19:09 ` [PATCH 1/1] drm/ttm: Set memory as decrypted for ttm framebuffer mappings Christian König
2018-08-22 20:57   ` Jiandi An
2018-08-23  6:47     ` Christian König
2018-08-23 23:05       ` Jiandi An
2018-08-24  7:21         ` Christian König
2018-09-27 20:28           ` Jiandi An
2018-08-23  6:23 ` kbuild test robot
2018-08-23  6:42 ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180822185754.104729-1-jiandi.an@amd.com \
    --to=jiandi.an@amd.com \
    --cc=Jerry.Zhang@amd.com \
    --cc=airlied@linux.ie \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ray.huang@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).