Skip to content

Commit 32271ec

Browse files
dceraolorodrigovivi
authored andcommitted
drm/i915/pxp: start the arb session on demand
Now that we can handle destruction and re-creation of the arb session, we can postpone the start of the session to the first submission that requires it, to avoid keeping it running with no user. v10: increase timeout when waiting in intel_pxp_start as firmware session startup is slower right after boot. v13: increase the same timeout by 50 milisec because previous timeout was not enough to cover two lower level 100 milisec timeouts in the session termination + creation steps. Signed-off-by: Alan Previn <alan.previn.teres.alexis@intel.com> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@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-12-alan.previn.teres.alexis@intel.com
1 parent d3ac8d4 commit 32271ec

File tree

7 files changed

+42
-29
lines changed

7 files changed

+42
-29
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ static int proto_context_set_protected(struct drm_i915_private *i915,
267267
* which in turn requires the device to be active.
268268
*/
269269
pc->pxp_wakeref = intel_runtime_pm_get(&i915->runtime_pm);
270-
ret = intel_pxp_wait_for_arb_start(&i915->gt.pxp);
270+
271+
if (!intel_pxp_is_active(&i915->gt.pxp))
272+
ret = intel_pxp_start(&i915->gt.pxp);
271273
}
272274

273275
return ret;

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void intel_pxp_init(struct intel_pxp *pxp)
9191
init_completion(&pxp->termination);
9292
complete_all(&pxp->termination);
9393

94+
mutex_init(&pxp->arb_mutex);
9495
INIT_WORK(&pxp->session_work, intel_pxp_session_work);
9596

9697
ret = create_vcs_context(pxp);
@@ -127,7 +128,7 @@ void intel_pxp_mark_termination_in_progress(struct intel_pxp *pxp)
127128
reinit_completion(&pxp->termination);
128129
}
129130

130-
static void intel_pxp_queue_termination(struct intel_pxp *pxp)
131+
static void pxp_queue_termination(struct intel_pxp *pxp)
131132
{
132133
struct intel_gt *gt = pxp_to_gt(pxp);
133134

@@ -146,31 +147,41 @@ static void intel_pxp_queue_termination(struct intel_pxp *pxp)
146147
* the arb session is restarted from the irq work when we receive the
147148
* termination completion interrupt
148149
*/
149-
int intel_pxp_wait_for_arb_start(struct intel_pxp *pxp)
150+
int intel_pxp_start(struct intel_pxp *pxp)
150151
{
152+
int ret = 0;
153+
151154
if (!intel_pxp_is_enabled(pxp))
152-
return 0;
155+
return -ENODEV;
156+
157+
mutex_lock(&pxp->arb_mutex);
158+
159+
if (pxp->arb_is_valid)
160+
goto unlock;
161+
162+
pxp_queue_termination(pxp);
153163

154164
if (!wait_for_completion_timeout(&pxp->termination,
155-
msecs_to_jiffies(100)))
156-
return -ETIMEDOUT;
165+
msecs_to_jiffies(250))) {
166+
ret = -ETIMEDOUT;
167+
goto unlock;
168+
}
169+
170+
/* make sure the compiler doesn't optimize the double access */
171+
barrier();
157172

158173
if (!pxp->arb_is_valid)
159-
return -EIO;
174+
ret = -EIO;
160175

161-
return 0;
176+
unlock:
177+
mutex_unlock(&pxp->arb_mutex);
178+
return ret;
162179
}
163180

164181
void intel_pxp_init_hw(struct intel_pxp *pxp)
165182
{
166183
kcr_pxp_enable(pxp_to_gt(pxp));
167184
intel_pxp_irq_enable(pxp);
168-
169-
/*
170-
* the session could've been attacked while we weren't loaded, so
171-
* handle it as if it was and re-create it.
172-
*/
173-
intel_pxp_queue_termination(pxp);
174185
}
175186

176187
void intel_pxp_fini_hw(struct intel_pxp *pxp)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ void intel_pxp_init_hw(struct intel_pxp *pxp);
2626
void intel_pxp_fini_hw(struct intel_pxp *pxp);
2727

2828
void intel_pxp_mark_termination_in_progress(struct intel_pxp *pxp);
29-
int intel_pxp_wait_for_arb_start(struct intel_pxp *pxp);
29+
30+
int intel_pxp_start(struct intel_pxp *pxp);
3031

3132
int intel_pxp_key_check(struct intel_pxp *pxp, struct drm_i915_gem_object *obj);
3233

@@ -40,11 +41,16 @@ static inline void intel_pxp_fini(struct intel_pxp *pxp)
4041
{
4142
}
4243

43-
static inline int intel_pxp_wait_for_arb_start(struct intel_pxp *pxp)
44+
static inline int intel_pxp_start(struct intel_pxp *pxp)
4445
{
4546
return -ENODEV;
4647
}
4748

49+
static inline bool intel_pxp_is_active(const struct intel_pxp *pxp)
50+
{
51+
return false;
52+
}
53+
4854
static inline int intel_pxp_key_check(struct intel_pxp *pxp,
4955
struct drm_i915_gem_object *obj)
5056
{

drivers/gpu/drm/i915/pxp/intel_pxp_irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void intel_pxp_irq_handler(struct intel_pxp *pxp, u16 iir)
3232
GEN12_DISPLAY_APP_TERMINATED_PER_FW_REQ_INTERRUPT)) {
3333
/* immediately mark PXP as inactive on termination */
3434
intel_pxp_mark_termination_in_progress(pxp);
35-
pxp->session_events |= PXP_TERMINATION_REQUEST;
35+
pxp->session_events |= PXP_TERMINATION_REQUEST | PXP_INVAL_REQUIRED;
3636
}
3737

3838
if (iir & GEN12_DISPLAY_STATE_RESET_COMPLETE_INTERRUPT)

drivers/gpu/drm/i915/pxp/intel_pxp_session.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ static int pxp_terminate_arb_session_and_global(struct intel_pxp *pxp)
8888
/* must mark termination in progress calling this function */
8989
GEM_WARN_ON(pxp->arb_is_valid);
9090

91-
/* invalidate protected objects */
92-
intel_pxp_invalidate(pxp);
93-
9491
/* terminate the hw sessions */
9592
ret = intel_pxp_terminate_session(pxp, ARB_SESSION);
9693
if (ret) {
@@ -147,6 +144,9 @@ void intel_pxp_session_work(struct work_struct *work)
147144
if (!events)
148145
return;
149146

147+
if (events & PXP_INVAL_REQUIRED)
148+
intel_pxp_invalidate(pxp);
149+
150150
if (events & PXP_TERMINATION_REQUEST) {
151151
events &= ~PXP_TERMINATION_COMPLETE;
152152
pxp_terminate(pxp);

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ static int intel_pxp_tee_io_message(struct intel_pxp *pxp,
7878
static int i915_pxp_tee_component_bind(struct device *i915_kdev,
7979
struct device *tee_kdev, void *data)
8080
{
81-
struct drm_i915_private *i915 = kdev_to_i915(i915_kdev);
8281
struct intel_pxp *pxp = i915_dev_to_pxp(i915_kdev);
83-
int ret;
8482

8583
mutex_lock(&pxp->tee_mutex);
8684
pxp->pxp_component = data;
@@ -89,14 +87,8 @@ static int i915_pxp_tee_component_bind(struct device *i915_kdev,
8987

9088
/* the component is required to fully start the PXP HW */
9189
intel_pxp_init_hw(pxp);
92-
ret = intel_pxp_wait_for_arb_start(pxp);
93-
if (ret) {
94-
drm_err(&i915->drm, "Failed to create arb session during bind\n");
95-
intel_pxp_fini_hw(pxp);
96-
pxp->pxp_component = NULL;
97-
}
9890

99-
return ret;
91+
return 0;
10092
}
10193

10294
static void i915_pxp_tee_component_unbind(struct device *i915_kdev,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct intel_pxp {
2727
* even if the keys are gone, so we can't rely on the HW state of the
2828
* session to know if it's valid and need to track the status in SW.
2929
*/
30+
struct mutex arb_mutex; /* protects arb session start */
3031
bool arb_is_valid;
3132

3233
/*
@@ -53,6 +54,7 @@ struct intel_pxp {
5354
u32 session_events; /* protected with gt->irq_lock */
5455
#define PXP_TERMINATION_REQUEST BIT(0)
5556
#define PXP_TERMINATION_COMPLETE BIT(1)
57+
#define PXP_INVAL_REQUIRED BIT(2)
5658
};
5759

5860
#endif /* __INTEL_PXP_TYPES_H__ */

0 commit comments

Comments
 (0)