Browse Source

disp: msm: perform delayed buf attach during secure transitions

While transitioning from secure usecases, the secure
context bank is attached back only during the commit
phase. This leads to invalid secure context-bank device
issue, when the prime_to_fd call is made for the next
frame. Avoid it, by attaching to default drm device
during the prime_to_fd call and reattach it to the
secure context-bank device at the delayed import time.

Change-Id: I43e6da7f117f20746943a48b5f2657e9ae2947ea
Signed-off-by: Veera Sundaram Sankaran <[email protected]>
Veera Sundaram Sankaran 5 years ago
parent
commit
a9574eb8c2
2 changed files with 45 additions and 7 deletions
  1. 29 2
      msm/msm_gem.c
  2. 16 5
      msm/msm_gem_prime.c

+ 29 - 2
msm/msm_gem.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  * Copyright (C) 2013 Red Hat
  * Author: Rob Clark <[email protected]>
  *
@@ -416,9 +416,36 @@ static int msm_gem_get_iova_locked(struct drm_gem_object *obj,
 
 	if (!vma) {
 		struct page **pages;
+		struct device *dev;
+		struct dma_buf *dmabuf;
+		bool reattach = false;
+
+		dev = msm_gem_get_aspace_device(aspace);
+		if (dev && obj->import_attach &&
+				(dev != obj->import_attach->dev)) {
+			dmabuf = obj->import_attach->dmabuf;
+
+			DRM_DEBUG("detach nsec-dev:%pK attach sec-dev:%pK\n",
+					obj->import_attach->dev, dev);
+			SDE_EVT32(obj->import_attach->dev, dev, msm_obj->sgt);
+
+			if (msm_obj->sgt)
+				dma_buf_unmap_attachment(obj->import_attach,
+					msm_obj->sgt, DMA_BIDIRECTIONAL);
+			dma_buf_detach(dmabuf, obj->import_attach);
+
+			obj->import_attach = dma_buf_attach(dmabuf, dev);
+			if (IS_ERR(obj->import_attach)) {
+				DRM_ERROR("dma_buf_attach failure, err=%ld\n",
+						PTR_ERR(obj->import_attach));
+				goto unlock;
+			}
+			reattach = true;
+		}
 
 		/* perform delayed import for buffers without existing sgt */
-		if (((msm_obj->flags & MSM_BO_EXTBUF) && !(msm_obj->sgt))) {
+		if (((msm_obj->flags & MSM_BO_EXTBUF) && !(msm_obj->sgt))
+				|| reattach) {
 			ret = msm_gem_delayed_import(obj);
 			if (ret) {
 				DRM_ERROR("delayed dma-buf import failed %d\n",

+ 16 - 5
msm/msm_gem_prime.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  * Copyright (C) 2013 Red Hat
  * Author: Rob Clark <[email protected]>
  *
@@ -133,15 +133,26 @@ struct drm_gem_object *msm_gem_prime_import(struct drm_device *dev,
 	}
 
 	if (flags & ION_FLAG_SECURE) {
-		if (flags & ION_FLAG_CP_PIXEL)
+		if (flags & ION_FLAG_CP_PIXEL) {
 			attach_dev = kms->funcs->get_address_space_device(kms,
 						MSM_SMMU_DOMAIN_SECURE);
+			/*
+			 * While transitioning from secure use-cases, the
+			 * secure-cb might still not be attached back, while
+			 * the prime_fd_to_handle call is made for the next
+			 * frame. Attach those buffers to default drm device
+			 * and reattaching with the correct context-bank
+			 * will be handled in msm_gem_delayed_import
+			 */
+			if (!attach_dev)
+				attach_dev = dev->dev;
 
-		else if ((flags & ION_FLAG_CP_SEC_DISPLAY)
-				|| (flags & ION_FLAG_CP_CAMERA_PREVIEW))
+		} else if ((flags & ION_FLAG_CP_SEC_DISPLAY)
+				|| (flags & ION_FLAG_CP_CAMERA_PREVIEW)) {
 			attach_dev = dev->dev;
-		else
+		} else {
 			DRM_ERROR("invalid ion secure flag: 0x%lx\n", flags);
+		}
 	} else {
 		attach_dev = kms->funcs->get_address_space_device(kms,
 						MSM_SMMU_DOMAIN_UNSECURE);