All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Huang, Sean Z" <sean.z.huang@intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC-v8 19/23] drm/i915/pxp: Termiante the session upon app crash
Date: Fri, 11 Dec 2020 01:04:53 -0800	[thread overview]
Message-ID: <20201211090457.32674-20-sean.z.huang@intel.com> (raw)
In-Reply-To: <20201211090457.32674-1-sean.z.huang@intel.com>

PXP should terminate the hardware session and cleanup the software
state gracefully when the application has established the
protection session, but doesn't close the session correctly due to
some cases like application crash.

Signed-off-by: Huang, Sean Z <sean.z.huang@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.c         |  3 +++
 drivers/gpu/drm/i915/pxp/intel_pxp.c    | 15 +++++++++++++++
 drivers/gpu/drm/i915/pxp/intel_pxp.h    |  5 +++++
 drivers/gpu/drm/i915/pxp/intel_pxp_sm.c | 25 +++++++++++++++++++++++++
 drivers/gpu/drm/i915/pxp/intel_pxp_sm.h |  1 +
 5 files changed, 49 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 3dbda949bf71..e74201e81369 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -69,6 +69,7 @@
 #include "gt/intel_rc6.h"
 
 #include "pxp/intel_pxp_pm.h"
+#include "pxp/intel_pxp.h"
 
 #include "i915_debugfs.h"
 #include "i915_drv.h"
@@ -1026,6 +1027,8 @@ static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
 
 	/* Catch up with all the deferred frees from "this" client */
 	i915_gem_flush_free_objects(to_i915(dev));
+
+	intel_pxp_close(&(to_i915(dev)->gt.pxp), file);
 }
 
 static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c
index 46ad2ab229c1..3a49dd97cab2 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
@@ -320,3 +320,18 @@ int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmf
 			ret = -EFAULT;
 	return ret;
 }
+
+void intel_pxp_close(struct intel_pxp *pxp, struct drm_file *drmfile)
+{
+	int ret;
+	struct intel_gt *gt = container_of(pxp, typeof(*gt), pxp);
+
+	if (pxp->ctx.id == 0 || !drmfile)
+		return;
+
+	mutex_lock(&pxp->ctx.mutex);
+	ret = intel_pxp_sm_close(pxp, drmfile);
+	if (ret)
+		drm_err(&gt->i915->drm, "Failed to %s, ret=[%d]\n", __func__, ret);
+	mutex_unlock(&pxp->ctx.mutex);
+}
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.h b/drivers/gpu/drm/i915/pxp/intel_pxp.h
index 133e3df9b1f6..ffb460327315 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp.h
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp.h
@@ -64,6 +64,7 @@ int intel_pxp_init(struct intel_pxp *pxp);
 void intel_pxp_uninit(struct intel_pxp *pxp);
 bool intel_pxp_gem_object_status(struct drm_i915_private *i915);
 int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile);
+void intel_pxp_close(struct intel_pxp *pxp, struct drm_file *drmfile);
 #else
 static inline void intel_pxp_irq_handler(struct intel_pxp *pxp, u16 iir)
 {
@@ -97,6 +98,10 @@ static inline int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct
 {
 	return 0;
 }
+
+static inline void intel_pxp_close(struct intel_pxp *pxp, struct drm_file *drmfile)
+{
+}
 #endif
 
 #endif /* __INTEL_PXP_PM_H__ */
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c
index c4b55e1531c1..e03c2b039192 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c
@@ -460,3 +460,28 @@ int intel_pxp_sm_ioctl_query_pxp_tag(struct intel_pxp *pxp,
 
 	return 0;
 }
+
+int intel_pxp_sm_close(struct intel_pxp *pxp, struct drm_file *drmfile)
+{
+	int ret;
+	struct intel_pxp_sm_session *curr, *n;
+
+	list_for_each_entry_safe(curr, n, session_list(pxp, SESSION_TYPE_TYPE0), list) {
+		if (curr->drmfile && curr->drmfile == drmfile &&
+		    curr->pid == pid_nr(drmfile->pid)) {
+			ret = pxp_terminate_hw_session(pxp, curr->type,
+						       curr->index);
+			if (ret)
+				return ret;
+
+			ret = pxp_set_pxp_tag(pxp, curr->type, curr->index,
+					      PROTECTION_MODE_NONE);
+			if (ret)
+				return ret;
+
+			list_del(&curr->list);
+			kfree(curr);
+		}
+	}
+	return 0;
+}
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h
index 09a26bb7a1a4..d2acbd1298b4 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h
@@ -50,4 +50,5 @@ int intel_pxp_sm_ioctl_query_pxp_tag(struct intel_pxp *pxp,
 bool intel_pxp_sm_is_hw_session_in_play(struct intel_pxp *pxp,
 					int session_type, int session_index);
 int intel_pxp_sm_terminate_all_sessions(struct intel_pxp *pxp, int session_type);
+int intel_pxp_sm_close(struct intel_pxp *pxp, struct drm_file *drmfile);
 #endif /* __INTEL_PXP_SM_H__ */
-- 
2.17.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2020-12-11  9:05 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11  9:04 [Intel-gfx] [RFC-v8 00/23] Introduce Intel PXP component - Mesa single session Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 01/23] drm/i915/pxp: Introduce Intel PXP component Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 02/23] drm/i915/pxp: set KCR reg init during the boot time Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 03/23] drm/i915/pxp: Implement funcs to create the TEE channel Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 04/23] drm/i915/pxp: Create the arbitrary session after boot Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 05/23] drm/i915/pxp: Func to send hardware session termination Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 06/23] drm/i915/pxp: Enable PXP irq worker and callback stub Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 07/23] drm/i915/pxp: Destroy arb session upon teardown Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 08/23] drm/i915/pxp: Enable PXP power management Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 09/23] drm/i915/pxp: Expose session state for display protection flip Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 10/23] mei: pxp: export pavp client to me client bus Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 11/23] drm/i915/uapi: introduce drm_i915_gem_create_ext Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 12/23] drm/i915/pxp: User interface for Protected buffer Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 13/23] drm/i915/pxp: Add plane decryption support Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 14/23] drm/i915/pxp: Implement ioctl action to reserve session slots Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 15/23] drm/i915/pxp: Implement ioctl action to set session in play Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 16/23] drm/i915/pxp: Implement ioctl action to terminate the session Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 17/23] drm/i915/pxp: Implement ioctl action to send TEE commands Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 18/23] drm/i915/pxp: Implement ioctl action to query PXP tag Huang, Sean Z
2020-12-11  9:04 ` Huang, Sean Z [this message]
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 20/23] drm/i915/pxp: Add PXP-related registers into allowlist Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 21/23] mei: bus: add vtag support Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 22/23] mei: pxp: add vtag parameter to mei_pxp_send/receive interface Huang, Sean Z
2020-12-11  9:04 ` [Intel-gfx] [RFC-v8 23/23] drm/i915/pxp: Enable the PXP ioctl for protected session Huang, Sean Z
2020-12-11  9:36 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Introduce Intel PXP component - Mesa single session (rev8) Patchwork
2020-12-11  9:41 ` [Intel-gfx] ✗ Fi.CI.DOCS: " Patchwork
2020-12-11 10:05 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-12-11 11:12 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

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=20201211090457.32674-20-sean.z.huang@intel.com \
    --to=sean.z.huang@intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.