Skip to content

Commit cbbd376

Browse files
seanzhuarodrigovivi
authored andcommitted
drm/i915/pxp: Create the arbitrary session after boot
Create the arbitrary session, with the fixed session id 0xf, after system boot, for the case that application allocates the protected buffer without establishing any protection session. Because the hardware requires at least one alive session for protected buffer creation. This arbitrary session will need to be re-created after teardown or power event because hardware encryption key won't be valid after such cases. The session ID is exposed as part of the uapi so it can be used as part of userspace commands. v2: use gt->uncore->rpm (Chris) v3: s/arb_is_in_play/arb_is_valid (Chris), move set-up to the new init_hw function v4: move interface defs to separate header, set arb_is valid to false on fini (Rodrigo) v5: handle async component binding Signed-off-by: Huang, Sean Z <sean.z.huang@intel.com> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20210924191452.1539378-8-alan.previn.teres.alexis@intel.com
1 parent e0111ce commit cbbd376

10 files changed

Lines changed: 243 additions & 0 deletions

File tree

‎drivers/gpu/drm/i915/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ i915-y += i915_perf.o
281281
# Protected execution platform (PXP) support
282282
i915-$(CONFIG_DRM_I915_PXP) += \
283283
pxp/intel_pxp.o \
284+
pxp/intel_pxp_session.o \
284285
pxp/intel_pxp_tee.o
285286

286287
# Post-mortem debug and GPU hang state capture

‎drivers/gpu/drm/i915/pxp/intel_pxp.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright(c) 2020 Intel Corporation.
44
*/
55
#include "intel_pxp.h"
6+
#include "intel_pxp_session.h"
67
#include "intel_pxp_tee.h"
78
#include "gt/intel_context.h"
89
#include "i915_drv.h"
@@ -12,6 +13,11 @@ struct intel_gt *pxp_to_gt(const struct intel_pxp *pxp)
1213
return container_of(pxp, struct intel_gt, pxp);
1314
}
1415

16+
bool intel_pxp_is_active(const struct intel_pxp *pxp)
17+
{
18+
return pxp->arb_is_valid;
19+
}
20+
1521
/* KCR register definitions */
1622
#define KCR_INIT _MMIO(0x320f0)
1723
/* Setting KCR Init bit is required after system boot */
@@ -72,6 +78,8 @@ void intel_pxp_init(struct intel_pxp *pxp)
7278
if (!HAS_PXP(gt->i915))
7379
return;
7480

81+
mutex_init(&pxp->tee_mutex);
82+
7583
ret = create_vcs_context(pxp);
7684
if (ret)
7785
return;
@@ -93,6 +101,8 @@ void intel_pxp_fini(struct intel_pxp *pxp)
93101
if (!intel_pxp_is_enabled(pxp))
94102
return;
95103

104+
pxp->arb_is_valid = false;
105+
96106
intel_pxp_tee_component_fini(pxp);
97107

98108
destroy_vcs_context(pxp);
@@ -101,6 +111,8 @@ void intel_pxp_fini(struct intel_pxp *pxp)
101111
void intel_pxp_init_hw(struct intel_pxp *pxp)
102112
{
103113
kcr_pxp_enable(pxp_to_gt(pxp));
114+
115+
intel_pxp_create_arb_session(pxp);
104116
}
105117

106118
void intel_pxp_fini_hw(struct intel_pxp *pxp)

‎drivers/gpu/drm/i915/pxp/intel_pxp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static inline bool intel_pxp_is_enabled(const struct intel_pxp *pxp)
1515

1616
#ifdef CONFIG_DRM_I915_PXP
1717
struct intel_gt *pxp_to_gt(const struct intel_pxp *pxp);
18+
bool intel_pxp_is_active(const struct intel_pxp *pxp);
19+
1820
void intel_pxp_init(struct intel_pxp *pxp);
1921
void intel_pxp_fini(struct intel_pxp *pxp);
2022

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Copyright(c) 2020, Intel Corporation. All rights reserved.
4+
*/
5+
6+
#include "drm/i915_drm.h"
7+
#include "i915_drv.h"
8+
9+
#include "intel_pxp.h"
10+
#include "intel_pxp_session.h"
11+
#include "intel_pxp_tee.h"
12+
#include "intel_pxp_types.h"
13+
14+
#define ARB_SESSION I915_PROTECTED_CONTENT_DEFAULT_SESSION /* shorter define */
15+
16+
#define GEN12_KCR_SIP _MMIO(0x32260) /* KCR hwdrm session in play 0-31 */
17+
18+
static bool intel_pxp_session_is_in_play(struct intel_pxp *pxp, u32 id)
19+
{
20+
struct intel_gt *gt = pxp_to_gt(pxp);
21+
intel_wakeref_t wakeref;
22+
u32 sip = 0;
23+
24+
with_intel_runtime_pm(gt->uncore->rpm, wakeref)
25+
sip = intel_uncore_read(gt->uncore, GEN12_KCR_SIP);
26+
27+
return sip & BIT(id);
28+
}
29+
30+
static int pxp_wait_for_session_state(struct intel_pxp *pxp, u32 id, bool in_play)
31+
{
32+
struct intel_gt *gt = pxp_to_gt(pxp);
33+
intel_wakeref_t wakeref;
34+
u32 mask = BIT(id);
35+
int ret;
36+
37+
with_intel_runtime_pm(gt->uncore->rpm, wakeref)
38+
ret = intel_wait_for_register(gt->uncore,
39+
GEN12_KCR_SIP,
40+
mask,
41+
in_play ? mask : 0,
42+
100);
43+
44+
return ret;
45+
}
46+
47+
int intel_pxp_create_arb_session(struct intel_pxp *pxp)
48+
{
49+
struct intel_gt *gt = pxp_to_gt(pxp);
50+
int ret;
51+
52+
pxp->arb_is_valid = false;
53+
54+
if (intel_pxp_session_is_in_play(pxp, ARB_SESSION)) {
55+
drm_err(&gt->i915->drm, "arb session already in play at creation time\n");
56+
return -EEXIST;
57+
}
58+
59+
ret = intel_pxp_tee_cmd_create_arb_session(pxp, ARB_SESSION);
60+
if (ret) {
61+
drm_err(&gt->i915->drm, "tee cmd for arb session creation failed\n");
62+
return ret;
63+
}
64+
65+
ret = pxp_wait_for_session_state(pxp, ARB_SESSION, true);
66+
if (ret) {
67+
drm_err(&gt->i915->drm, "arb session failed to go in play\n");
68+
return ret;
69+
}
70+
71+
pxp->arb_is_valid = true;
72+
73+
return 0;
74+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright(c) 2020, Intel Corporation. All rights reserved.
4+
*/
5+
6+
#ifndef __INTEL_PXP_SESSION_H__
7+
#define __INTEL_PXP_SESSION_H__
8+
9+
#include <linux/types.h>
10+
11+
struct intel_pxp;
12+
13+
int intel_pxp_create_arb_session(struct intel_pxp *pxp);
14+
15+
#endif /* __INTEL_PXP_SESSION_H__ */

‎drivers/gpu/drm/i915/pxp/intel_pxp_tee.c‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,63 @@
88
#include "drm/i915_component.h"
99
#include "i915_drv.h"
1010
#include "intel_pxp.h"
11+
#include "intel_pxp_session.h"
1112
#include "intel_pxp_tee.h"
13+
#include "intel_pxp_tee_interface.h"
1214

1315
static inline struct intel_pxp *i915_dev_to_pxp(struct device *i915_kdev)
1416
{
1517
return &kdev_to_i915(i915_kdev)->gt.pxp;
1618
}
1719

20+
static int intel_pxp_tee_io_message(struct intel_pxp *pxp,
21+
void *msg_in, u32 msg_in_size,
22+
void *msg_out, u32 msg_out_max_size,
23+
u32 *msg_out_rcv_size)
24+
{
25+
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
26+
struct i915_pxp_component *pxp_component = pxp->pxp_component;
27+
int ret = 0;
28+
29+
mutex_lock(&pxp->tee_mutex);
30+
31+
/*
32+
* The binding of the component is asynchronous from i915 probe, so we
33+
* can't be sure it has happened.
34+
*/
35+
if (!pxp_component) {
36+
ret = -ENODEV;
37+
goto unlock;
38+
}
39+
40+
ret = pxp_component->ops->send(pxp_component->tee_dev, msg_in, msg_in_size);
41+
if (ret) {
42+
drm_err(&i915->drm, "Failed to send PXP TEE message\n");
43+
goto unlock;
44+
}
45+
46+
ret = pxp_component->ops->recv(pxp_component->tee_dev, msg_out, msg_out_max_size);
47+
if (ret < 0) {
48+
drm_err(&i915->drm, "Failed to receive PXP TEE message\n");
49+
goto unlock;
50+
}
51+
52+
if (ret > msg_out_max_size) {
53+
drm_err(&i915->drm,
54+
"Failed to receive PXP TEE message due to unexpected output size\n");
55+
ret = -ENOSPC;
56+
goto unlock;
57+
}
58+
59+
if (msg_out_rcv_size)
60+
*msg_out_rcv_size = ret;
61+
62+
ret = 0;
63+
unlock:
64+
mutex_unlock(&pxp->tee_mutex);
65+
return ret;
66+
}
67+
1868
/**
1969
* i915_pxp_tee_component_bind - bind function to pass the function pointers to pxp_tee
2070
* @i915_kdev: pointer to i915 kernel device
@@ -28,14 +78,24 @@ static inline struct intel_pxp *i915_dev_to_pxp(struct device *i915_kdev)
2878
static int i915_pxp_tee_component_bind(struct device *i915_kdev,
2979
struct device *tee_kdev, void *data)
3080
{
81+
struct drm_i915_private *i915 = kdev_to_i915(i915_kdev);
3182
struct intel_pxp *pxp = i915_dev_to_pxp(i915_kdev);
3283

84+
mutex_lock(&pxp->tee_mutex);
3385
pxp->pxp_component = data;
3486
pxp->pxp_component->tee_dev = tee_kdev;
87+
mutex_unlock(&pxp->tee_mutex);
3588

3689
/* the component is required to fully start the PXP HW */
3790
intel_pxp_init_hw(pxp);
3891

92+
if (!pxp->arb_is_valid) {
93+
drm_err(&i915->drm, "Failed to create arb session during bind\n");
94+
intel_pxp_fini_hw(pxp);
95+
pxp->pxp_component = NULL;
96+
return -EIO;
97+
}
98+
3999
return 0;
40100
}
41101

@@ -46,7 +106,9 @@ static void i915_pxp_tee_component_unbind(struct device *i915_kdev,
46106

47107
intel_pxp_fini_hw(pxp);
48108

109+
mutex_lock(&pxp->tee_mutex);
49110
pxp->pxp_component = NULL;
111+
mutex_unlock(&pxp->tee_mutex);
50112
}
51113

52114
static const struct component_ops i915_pxp_tee_component_ops = {
@@ -82,3 +144,28 @@ void intel_pxp_tee_component_fini(struct intel_pxp *pxp)
82144
component_del(i915->drm.dev, &i915_pxp_tee_component_ops);
83145
pxp->pxp_component_added = false;
84146
}
147+
148+
int intel_pxp_tee_cmd_create_arb_session(struct intel_pxp *pxp,
149+
int arb_session_id)
150+
{
151+
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
152+
struct pxp_tee_create_arb_in msg_in = {0};
153+
struct pxp_tee_create_arb_out msg_out = {0};
154+
int ret;
155+
156+
msg_in.header.api_version = PXP_TEE_APIVER;
157+
msg_in.header.command_id = PXP_TEE_ARB_CMDID;
158+
msg_in.header.buffer_len = sizeof(msg_in) - sizeof(msg_in.header);
159+
msg_in.protection_mode = PXP_TEE_ARB_PROTECTION_MODE;
160+
msg_in.session_id = arb_session_id;
161+
162+
ret = intel_pxp_tee_io_message(pxp,
163+
&msg_in, sizeof(msg_in),
164+
&msg_out, sizeof(msg_out),
165+
NULL);
166+
167+
if (ret)
168+
drm_err(&i915->drm, "Failed to send tee msg ret=[%d]\n", ret);
169+
170+
return ret;
171+
}

‎drivers/gpu/drm/i915/pxp/intel_pxp_tee.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
int intel_pxp_tee_component_init(struct intel_pxp *pxp);
1212
void intel_pxp_tee_component_fini(struct intel_pxp *pxp);
1313

14+
int intel_pxp_tee_cmd_create_arb_session(struct intel_pxp *pxp,
15+
int arb_session_id);
16+
1417
#endif /* __INTEL_PXP_TEE_H__ */
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright(c) 2020, Intel Corporation. All rights reserved.
4+
*/
5+
6+
#ifndef __INTEL_PXP_TEE_INTERFACE_H__
7+
#define __INTEL_PXP_TEE_INTERFACE_H__
8+
9+
#include <linux/types.h>
10+
11+
#define PXP_TEE_APIVER 0x40002
12+
#define PXP_TEE_ARB_CMDID 0x1e
13+
#define PXP_TEE_ARB_PROTECTION_MODE 0x2
14+
15+
/* PXP TEE message header */
16+
struct pxp_tee_cmd_header {
17+
u32 api_version;
18+
u32 command_id;
19+
u32 status;
20+
/* Length of the message (excluding the header) */
21+
u32 buffer_len;
22+
} __packed;
23+
24+
/* PXP TEE message input to create a arbitrary session */
25+
struct pxp_tee_create_arb_in {
26+
struct pxp_tee_cmd_header header;
27+
u32 protection_mode;
28+
u32 session_id;
29+
} __packed;
30+
31+
/* PXP TEE message output to create a arbitrary session */
32+
struct pxp_tee_create_arb_out {
33+
struct pxp_tee_cmd_header header;
34+
} __packed;
35+
36+
#endif /* __INTEL_PXP_TEE_INTERFACE_H__ */

‎drivers/gpu/drm/i915/pxp/intel_pxp_types.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef __INTEL_PXP_TYPES_H__
77
#define __INTEL_PXP_TYPES_H__
88

9+
#include <linux/mutex.h>
910
#include <linux/types.h>
1011

1112
struct intel_context;
@@ -16,6 +17,15 @@ struct intel_pxp {
1617
bool pxp_component_added;
1718

1819
struct intel_context *ce;
20+
21+
/*
22+
* After a teardown, the arb session can still be in play on the HW
23+
* even if the keys are gone, so we can't rely on the HW state of the
24+
* session to know if it's valid and need to track the status in SW.
25+
*/
26+
bool arb_is_valid;
27+
28+
struct mutex tee_mutex; /* protects the tee channel binding */
1929
};
2030

2131
#endif /* __INTEL_PXP_TYPES_H__ */

‎include/uapi/drm/i915_drm.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,6 +3038,9 @@ struct drm_i915_gem_create_ext_memory_regions {
30383038
__u64 regions;
30393039
};
30403040

3041+
/* ID of the protected content session managed by i915 when PXP is active */
3042+
#define I915_PROTECTED_CONTENT_DEFAULT_SESSION 0xf
3043+
30413044
#if defined(__cplusplus)
30423045
}
30433046
#endif

0 commit comments

Comments
 (0)