Allow privileged user to map the OA buffer
Subsystems (3)
cover Allow privileged user to map the OA buffer
This cover letter is included to trigger "Test-with" an IGT patch.
Tests - https://patchwork.freedesktop.org/series/79829/
Test-with: [email protected]
Piotr Maciejewski (4):
drm/i915/perf: Ensure observation logic is not clock gated drm/i915/perf: Whitelist OA report trigger registers drm/i915/perf: Whitelist OA counter and buffer registers drm/i915/perf: Map OA buffer to user space for gen12 performance query
drivers/gpu/drm/i915/gem/i915_gem_mman.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_mman.h | 2 + drivers/gpu/drm/i915/gt/intel_workarounds.c | 60 +++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 38 ++- drivers/gpu/drm/i915/i915_perf.c | 254 +++++++++++++++++- drivers/gpu/drm/i915/i915_perf_types.h | 17 ++ drivers/gpu/drm/i915/i915_reg.h | 12 + include/uapi/drm/i915_drm.h | 32 +++ 8 files changed, 411 insertions(+), 6 deletions(-)
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/4 drm/i915/perf: Ensure observation logic is not clock gated
From: Piotr Maciejewski <[email protected]>
A clock gating switch can control if the performance monitoring and observation logic is enaled or not. Ensure that we enable the clocks.
v2: Separate code from other patches (Lionel)
v3: Reset PMON enable when disabling perf to save power (Lionel)
--- drivers/gpu/drm/i915/i915_perf.c | 13 +++++++++++++ drivers/gpu/drm/i915/i915_reg.h | 2 ++ 2 files changed, 15 insertions(+)
drivers/gpu/drm/i915/i915_perf.c +13 -0
@@ -2493,6 +2493,14 @@ gen12_enable_metric_set(struct i915_perf_stream *stream, (period_exponent << GEN12_OAG_OAGLBCTXCTRL_TIMER_PERIOD_SHIFT)) : 0); +/* +* Initialize Super Queue Internal Cnt Register +* Set PMON Enable in order to collect valid metrics. +*/ +intel_uncore_write (uncore,GEN12_SQCNT1 , +intel_uncore_read (uncore,GEN12_SQCNT1 ) | +GEN12_SQCNT1_PMON_ENABLE ); +/* * Update all contexts prior writing the mux configurations as we need * to make sure all slices/subslices are ON before writing to NOA
@@ -2552,6 +2560,11 @@ static void gen12_disable_metric_set(struct i915_perf_stream *stream)/* Make sure we disable noa to save power. */ intel_uncore_rmw (uncore,RPM_CONFIG1 ,GEN10_GT_NOA_ENABLE ,0 ); + +/* Reset PMON Enable to save power. */ +intel_uncore_write (uncore,GEN12_SQCNT1 , +intel_uncore_read (uncore,GEN12_SQCNT1 ) & + ~GEN12_SQCNT1_PMON_ENABLE ); }static void gen7_oa_enable (struct i915_perf_stream *stream)
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -696,6 +696,8 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define OABUFFER_SIZE_16M (7 << 3)#define GEN12_OA_TLB_INV_CR _MMIO(0xceec) +#define GEN12_SQCNT1 _MMIO(0x8718) +#define GEN12_SQCNT1_PMON_ENABLE (1 << 30)/* Gen12 OAR unit */ #define GEN12_OAR_OACONTROL _MMIO(0x2960)
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/4 drm/i915/perf: Whitelist OA report trigger registers
In reply to Umesh Nerlige RamappaFrom: Piotr Maciejewski <[email protected]>
OA reports can be triggered into the OA buffer by writing into the OAREPORTTRIG registers. Whitelist the registers to allow user to trigger reports.
v2:
- Move related change to this patch (Lionel)
- Bump up perf revision (Lionel)
v3: Pardon whitelisted registers for selftest (Umesh)
v4: Document supported gens for the feature (Lionel)
--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 26 +++++++++++++++++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 8 ++++++ drivers/gpu/drm/i915/i915_perf.c | 11 +++++--- 3 files changed, 42 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_workarounds.c +26 -0
@@ -1387,6 +1387,20 @@ whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg)whitelist_reg_ext (wal, reg,RING_FORCE_TO_NONPRIV_ACCESS_RW ); } +static void gen9_whitelist_build_performance_counters (struct i915_wa_list *w) +{ +/* OA buffer trigger report 2/6 used by performance query */ +whitelist_reg (w,OAREPORTTRIG2 ); +whitelist_reg (w,OAREPORTTRIG6 ); +} + +static void gen12_whitelist_build_performance_counters (struct i915_wa_list *w) +{ +/* OA buffer trigger report 2/6 used by performance query */ +whitelist_reg (w,GEN12_OAG_OAREPORTTRIG2 ); +whitelist_reg (w,GEN12_OAG_OAREPORTTRIG6 ); +} +static void gen9_whitelist_build (struct i915_wa_list *w) {/* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */
@@ -1400,6 +1414,9 @@ static void gen9_whitelist_build(struct i915_wa_list *w)/* WaSendPushConstantsFromMMIO:skl,bxt */ whitelist_reg (w,COMMON_SLICE_CHICKEN2 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w); }static void skl_whitelist_build (struct intel_engine_cs *engine)
@@ -1493,6 +1510,9 @@ static void cnl_whitelist_build(struct intel_engine_cs *engine)/* WaEnablePreemptionGranularityControlByUMD:cnl */ whitelist_reg (w,GEN8_CS_CHICKEN1 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w); }static void icl_whitelist_build (struct intel_engine_cs *engine)
@@ -1522,6 +1542,9 @@ static void icl_whitelist_build(struct intel_engine_cs *engine)whitelist_reg_ext (w,PS_INVOCATION_COUNT ,RING_FORCE_TO_NONPRIV_ACCESS_RD |RING_FORCE_TO_NONPRIV_RANGE_4 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w);break ;case VIDEO_DECODE_CLASS :
@@ -1572,6 +1595,9 @@ static void tgl_whitelist_build(struct intel_engine_cs *engine)/* Wa_1806527549:tgl */ whitelist_reg (w,HIZ_CHICKEN ); + +/* Performance counters support */ +gen12_whitelist_build_performance_counters (w);break ;default : whitelist_reg_ext(w,
drivers/gpu/drm/i915/gt/selftest_workarounds.c +8 -0
@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) }, };return find_reg (i915, reg, pardon,ARRAY_SIZE (pardon));
@@ -956,6 +960,10 @@ static bool writeonly_reg(struct drm_i915_private *i915, i915_reg_t reg)/* Some registers do not seem to behave and our writes unreadable */ static const struct regmask wo[] = { {GEN9_SLICE_COMMON_ECO_CHICKEN1 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) }, };return find_reg (i915, reg, wo,ARRAY_SIZE (wo));
drivers/gpu/drm/i915/i915_perf.c +8 -3
@@ -1448,7 +1448,8 @@ static void gen8_init_oa_buffer(struct i915_perf_stream *stream)* bit." */ intel_uncore_write (uncore,GEN8_OABUFFER , gtt_offset | -OABUFFER_SIZE_16M |GEN8_OABUFFER_MEM_SELECT_GGTT ); +OABUFFER_SIZE_16M |GEN8_OABUFFER_MEM_SELECT_GGTT | +GEN7_OABUFFER_EDGE_TRIGGER );intel_uncore_write (uncore,GEN8_OATAILPTR , gtt_offset &GEN8_OATAILPTR_MASK );/* Mark that we need updated tail pointers to read from... */
@@ -1501,7 +1502,8 @@ static void gen12_init_oa_buffer(struct i915_perf_stream *stream)* bit." */ intel_uncore_write (uncore,GEN12_OAG_OABUFFER , gtt_offset | -OABUFFER_SIZE_16M |GEN8_OABUFFER_MEM_SELECT_GGTT ); +OABUFFER_SIZE_16M |GEN8_OABUFFER_MEM_SELECT_GGTT | +GEN7_OABUFFER_EDGE_TRIGGER );intel_uncore_write (uncore,GEN12_OAG_OATAILPTR , gtt_offset &GEN12_OAG_OATAILPTR_MASK );
@@ -4445,8 +4447,11 @@ int i915_perf_ioctl_version(void)* * 5: Add DRM_I915_PERF_PROP_POLL_OA_PERIOD parameter that controls the * interval for the hrtimer used to check for OA data. +* +* 6: Whitelist OATRIGGER registers to allow user to trigger reports +* into the OA buffer. This applies only to gen8+. */ -return 5 ; +return 6 ; }#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST )
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
Quoted 27 lines
From: Piotr Maciejewski <[email protected]>
OA reports can be triggered into the OA buffer by writing into the OAREPORTTRIG registers. Whitelist the registers to allow user to trigger reports.
v2:
- Move related change to this patch (Lionel)
- Bump up perf revision (Lionel)v3: Pardon whitelisted registers for selftest (Umesh)
v4: Document supported gens for the feature (Lionel)Signed-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>Reviewed-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 26 +++++++++++++++++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 8 ++++++ drivers/gpu/drm/i915/i915_perf.c | 11 +++++--- 3 files changed, 42 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/intel_workarounds.c +0
-0
drivers/gpu/drm/i915/gt/intel_workarounds.c whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg) · line 1394
Quoted 8 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c +5
-0@@ -1387,6 +1387,20 @@ whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg)whitelist_reg_ext (wal, reg,RING_FORCE_TO_NONPRIV_ACCESS_RW ); } +static void gen9_whitelist_build_performance_counters (struct i915_wa_list *w) +{ +/* OA buffer trigger report 2/6 used by performance query */ +whitelist_reg (w,OAREPORTTRIG2 ); +whitelist_reg (w,OAREPORTTRIG6 );
The other question is: are you sure these are per-context registers?
Quoted 57 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c +21
-0+} + +static void gen12_whitelist_build_performance_counters (struct i915_wa_list *w) +{ +/* OA buffer trigger report 2/6 used by performance query */ +whitelist_reg (w,GEN12_OAG_OAREPORTTRIG2 ); +whitelist_reg (w,GEN12_OAG_OAREPORTTRIG6 ); +} +static void gen9_whitelist_build (struct i915_wa_list *w) {/* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */ @@ -1400,6 +1414,9 @@ static void gen9_whitelist_build(struct i915_wa_list *w)/* WaSendPushConstantsFromMMIO:skl,bxt */ whitelist_reg (w,COMMON_SLICE_CHICKEN2 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w); }static void skl_whitelist_build (struct intel_engine_cs *engine)@@ -1493,6 +1510,9 @@ static void cnl_whitelist_build(struct intel_engine_cs *engine)/* WaEnablePreemptionGranularityControlByUMD:cnl */ whitelist_reg (w,GEN8_CS_CHICKEN1 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w); }static void icl_whitelist_build (struct intel_engine_cs *engine)@@ -1522,6 +1542,9 @@ static void icl_whitelist_build(struct intel_engine_cs *engine)whitelist_reg_ext (w,PS_INVOCATION_COUNT ,RING_FORCE_TO_NONPRIV_ACCESS_RD |RING_FORCE_TO_NONPRIV_RANGE_4 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w);break ;case VIDEO_DECODE_CLASS :@@ -1572,6 +1595,9 @@ static void tgl_whitelist_build(struct intel_engine_cs *engine)/* Wa_1806527549:tgl */ whitelist_reg (w,HIZ_CHICKEN ); + +/* Performance counters support */ +gen12_whitelist_build_performance_counters (w);break ;default : whitelist_reg_ext(w,drivers/gpu/drm/i915/gt/selftest_workarounds.c +0
-0
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 7 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) },
Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more. -Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
Quoted 31 lines · Chris Wilson
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
Quoted 30 lines
From: Piotr Maciejewski <[email protected]>
OA reports can be triggered into the OA buffer by writing into the OAREPORTTRIG registers. Whitelist the registers to allow user to trigger reports.
v2:
- Move related change to this patch (Lionel)
- Bump up perf revision (Lionel)v3: Pardon whitelisted registers for selftest (Umesh)
v4: Document supported gens for the feature (Lionel)Signed-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>Reviewed-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 26 +++++++++++++++++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 8 ++++++ drivers/gpu/drm/i915/i915_perf.c | 11 +++++--- 3 files changed, 42 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/intel_workarounds.c +0
-0@@ -1387,6 +1387,20 @@ whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg)whitelist_reg_ext (wal, reg,RING_FORCE_TO_NONPRIV_ACCESS_RW ); }
Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg) · line 1394
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c +5
-0+static void gen9_whitelist_build_performance_counters (struct i915_wa_list *w) +{ +/* OA buffer trigger report 2/6 used by performance query */ +whitelist_reg (w,OAREPORTTRIG2 ); +whitelist_reg (w,OAREPORTTRIG6 );The other question is: are you sure these are per-context registers?
All the registers exposed in this series are global.
Quoted 58 lines
Quoted 58 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c +21
-0+} + +static void gen12_whitelist_build_performance_counters (struct i915_wa_list *w) +{ +/* OA buffer trigger report 2/6 used by performance query */ +whitelist_reg (w,GEN12_OAG_OAREPORTTRIG2 ); +whitelist_reg (w,GEN12_OAG_OAREPORTTRIG6 ); +} +static void gen9_whitelist_build (struct i915_wa_list *w) {/* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */ @@ -1400,6 +1414,9 @@ static void gen9_whitelist_build(struct i915_wa_list *w)/* WaSendPushConstantsFromMMIO:skl,bxt */ whitelist_reg (w,COMMON_SLICE_CHICKEN2 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w); }static void skl_whitelist_build (struct intel_engine_cs *engine)@@ -1493,6 +1510,9 @@ static void cnl_whitelist_build(struct intel_engine_cs *engine)/* WaEnablePreemptionGranularityControlByUMD:cnl */ whitelist_reg (w,GEN8_CS_CHICKEN1 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w); }static void icl_whitelist_build (struct intel_engine_cs *engine)@@ -1522,6 +1542,9 @@ static void icl_whitelist_build(struct intel_engine_cs *engine)whitelist_reg_ext (w,PS_INVOCATION_COUNT ,RING_FORCE_TO_NONPRIV_ACCESS_RD |RING_FORCE_TO_NONPRIV_RANGE_4 ); + +/* Performance counters support */ +gen9_whitelist_build_performance_counters (w);break ;case VIDEO_DECODE_CLASS :@@ -1572,6 +1595,9 @@ static void tgl_whitelist_build(struct intel_engine_cs *engine)/* Wa_1806527549:tgl */ whitelist_reg (w,HIZ_CHICKEN ); + +/* Performance counters support */ +gen12_whitelist_build_performance_counters (w);break ;default : whitelist_reg_ext(w,drivers/gpu/drm/i915/gt/selftest_workarounds.c +0
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = {
Quoted 8 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 6 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0{ GEN9_CTX_PREEMPT_REG, INTEL_GEN_MASK(9, 9) }, { GEN8_L3SQCREG4, INTEL_GEN_MASK(9, 9) }, + { OAREPORTTRIG2, INTEL_GEN_MASK(8, 11) }, + { OAREPORTTRIG6, INTEL_GEN_MASK(8, 11) }, + { GEN12_OAG_OAREPORTTRIG2, INTEL_GEN_MASK(12, 12) }, + { GEN12_OAG_OAREPORTTRIG6, INTEL_GEN_MASK(12, 12) },Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more.
I'm afraid the HW design leave us no choice on Gen12 :(
-Lionel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
Quoting Lionel Landwerlin (2020-07-24 11:07:18)
Quoted 17 lines · Chris Wilson
Quoted 15 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 12 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) },Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more.
Quoted 1 line
I'm afraid the HW design leave us no choice on Gen12 :(
The question then is how much mischief can a client get up to if they subvert the OA of the privileged user. It's a privilege escalation hole, but is there anything dangerous behind it? Or is it just going to disturb the data being fed to the privileged client... (Which seems scary enough.) -Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
Quoting Chris Wilson (2020-07-24 11:19:05)
Quoted 18 lines
Quoting Lionel Landwerlin (2020-07-24 11:07:18)
Quoted 17 lines · Chris Wilson
Quoted 15 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 12 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) },Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more.
Quoted 6 lines
Quoted 1 line
I'm afraid the HW design leave us no choice on Gen12 :(
The question then is how much mischief can a client get up to if they subvert the OA of the privileged user. It's a privilege escalation hole, but is there anything dangerous behind it? Or is it just going to disturb the data being fed to the privileged client... (Which seems scary enough.)
The other angle is whether the RING_NONPRIV are context saved; I have vague memories of seeing them in the context image. If they are, we can add them the to privileged OA client. We still need to respect the hard limit on the number, but that would close the hole. -Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
Quoted 23 lines · Chris Wilson
Quoting Chris Wilson (2020-07-24 11:19:05)
Quoted 17 lines
Quoting Lionel Landwerlin (2020-07-24 11:07:18)
Quoted 16 lines · Chris Wilson
Quoted 15 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 12 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) },Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more.
Quoted 5 lines
Quoted 1 line
I'm afraid the HW design leave us no choice on Gen12 :(
The question then is how much mischief can a client get up to if they subvert the OA of the privileged user. It's a privilege escalation hole, but is there anything dangerous behind it? Or is it just going to disturb the data being fed to the privileged client... (Which seems scary enough.)
Quoted 5 lines
The other angle is whether the
RING_NONPRIVare context saved; I have vague memories of seeing them in the context image. If they are, we can add them the to privileged OA client. We still need to respect the hard limit on the number, but that would close the hole. -Chris
I couldn't find how to do this whitelisting per context. If that's possible, that's probably what we should do.
-Lionel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
Quoting Lionel Landwerlin (2020-07-24 11:33:38)
Quoted 24 lines · Chris Wilson
Quoted 23 lines
Quoting Chris Wilson (2020-07-24 11:19:05)
Quoted 22 lines
Quoting Lionel Landwerlin (2020-07-24 11:07:18)
Quoted 16 lines · Chris Wilson
Quoted 15 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 12 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) },Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more.
Quoted 1 line
I'm afraid the HW design leave us no choice on Gen12 :(
The question then is how much mischief can a client get up to if they subvert the OA of the privileged user. It's a privilege escalation hole, but is there anything dangerous behind it? Or is it just going to disturb the data being fed to the privileged client... (Which seems scary enough.)
Quoted 7 lines
Quoted 4 lines
The other angle is whether the
RING_NONPRIVare context saved; I have vague memories of seeing them in the context image. If they are, we can add them the to privileged OA client. We still need to respect the hard limit on the number, but that would close the hole.I couldn't find how to do this whitelisting per context. If that's possible, that's probably what we should do.
I've had do luck in finding them in the context image either. Figment of my imagination, or wishful thinking.
-Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 2/4] drm/i915/perf: Whitelist OA report trigger registers
In reply to Chris WilsonQuoted 17 lines · Chris Wilson
Quoting Lionel Landwerlin (2020-07-24 11:07:18)
Quoted 16 lines · Chris Wilson
Quoted 15 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:18:59)
drivers/gpu/drm/i915/gt/selftest_workarounds.c static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) · line 940
Quoted 12 lines
drivers/gpu/drm/i915/gt/selftest_workarounds.c +4
-0@@ -934,6 +934,10 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg)static const struct regmask pardon[] = { {GEN9_CTX_PREEMPT_REG ,INTEL_GEN_MASK (9 ,9 ) }, {GEN8_L3SQCREG4 ,INTEL_GEN_MASK (9 ,9 ) }, + {OAREPORTTRIG2 ,INTEL_GEN_MASK (8 ,11 ) }, + {OAREPORTTRIG6 ,INTEL_GEN_MASK (8 ,11 ) }, + {GEN12_OAG_OAREPORTTRIG2 ,INTEL_GEN_MASK (12 ,12 ) }, + {GEN12_OAG_OAREPORTTRIG6 ,INTEL_GEN_MASK (12 ,12 ) },Because we are not making the mistake of exposing more globals, and the pardon is a list of our past sins, not an excuse for more.
Quoted 6 lines
Quoted 1 line
I'm afraid the HW design leave us no choice on Gen12 :(
The question then is how much mischief can a client get up to if they subvert the OA of the privileged user. It's a privilege escalation hole, but is there anything dangerous behind it? Or is it just going to disturb the data being fed to the privileged client... (Which seems scary enough.) -Chris
The trigger registers will allow any other application to generate reports in the global OA buffer.
If you've built your OA report parsing correctly, this shouldn't be a problem because you'll filter on context ID prior to the reason of the report being recorded.
That's a downside of this patch, that's also a feature because you can use this to monitor particular chunks of work in a global timeline of OA reports for multiple applications.
-Lionel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/4 drm/i915/perf: Whitelist OA counter and buffer registers
In reply to Umesh Nerlige RamappaFrom: Piotr Maciejewski <[email protected]>
It is useful to have markers in the OA reports to identify triggered reports. Whitelist some OA counters that can be used as markers.
A triggered report can be found faster if we can sample the HW tail and head registers when the report was triggered. Whitelist OA buffer specific registers.
v2:
- Bump up the perf revision (Lionel)
- Use indexing for counters (Lionel)
- Fix selftest for oa ticking register (Umesh)
v3: Pardon whitelisted registers for selftest (Umesh)
v4:
- Document whitelisted registers (Lionel)
- Fix live isolated whitelist for OA regs (Umesh)
--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 34 +++++++++++++++++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 30 +++++++++++++++- drivers/gpu/drm/i915/i915_perf.c | 8 ++++- drivers/gpu/drm/i915/i915_reg.h | 10 ++++++ 4 files changed, 80 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_workarounds.c +34 -0
@@ -1392,6 +1392,23 @@ static void gen9_whitelist_build_performance_counters(struct i915_wa_list *w)/* OA buffer trigger report 2/6 used by performance query */ whitelist_reg (w,OAREPORTTRIG2 );whitelist_reg (w,OAREPORTTRIG6 ); + +/* Performance counters A18-20 used by tbs marker query */ +whitelist_reg_ext (w,OA_PERF_COUNTER_A (18 ), +RING_FORCE_TO_NONPRIV_ACCESS_RW | +RING_FORCE_TO_NONPRIV_RANGE_4 ); + +whitelist_reg (w,OA_PERF_COUNTER_A (20 )); +whitelist_reg (w,OA_PERF_COUNTER_A_UPPER (20 )); + +/* Read access to gpu ticks */ +whitelist_reg_ext (w,GEN8_GPU_TICKS , +RING_FORCE_TO_NONPRIV_ACCESS_RD ); + +/* Read access to: oa status, head, tail, buffer settings */ +whitelist_reg_ext (w,GEN8_OASTATUS , +RING_FORCE_TO_NONPRIV_ACCESS_RD | +RING_FORCE_TO_NONPRIV_RANGE_4 ); }static void gen12_whitelist_build_performance_counters (struct i915_wa_list *w)
@@ -1399,6 +1416,23 @@ static void gen12_whitelist_build_performance_counters(struct i915_wa_list *w)/* OA buffer trigger report 2/6 used by performance query */ whitelist_reg (w,GEN12_OAG_OAREPORTTRIG2 );whitelist_reg (w,GEN12_OAG_OAREPORTTRIG6 ); + +/* Performance counters A18-20 used by tbs marker query */ +whitelist_reg_ext (w,GEN12_OAG_PERF_COUNTER_A (18 ), +RING_FORCE_TO_NONPRIV_ACCESS_RW | +RING_FORCE_TO_NONPRIV_RANGE_4 ); + +whitelist_reg (w,GEN12_OAG_PERF_COUNTER_A (20 )); +whitelist_reg (w,GEN12_OAG_PERF_COUNTER_A_UPPER (20 )); + +/* Read access to gpu ticks */ +whitelist_reg_ext (w,GEN12_OAG_GPU_TICKS , +RING_FORCE_TO_NONPRIV_ACCESS_RD ); + +/* Read access to: oa status, head, tail, buffer settings */ +whitelist_reg_ext (w,GEN12_OAG_OASTATUS , +RING_FORCE_TO_NONPRIV_ACCESS_RD | +RING_FORCE_TO_NONPRIV_RANGE_4 ); }static void gen9_whitelist_build (struct i915_wa_list *w)
drivers/gpu/drm/i915/gt/selftest_workarounds.c +29 -1
@@ -431,6 +431,19 @@ static bool timestamp(const struct intel_engine_cs *engine, u32 reg) } } +static bool oa_gpu_ticks (u32 reg) +{ + reg = reg & ~RING_FORCE_TO_NONPRIV_ACCESS_MASK ; +switch (reg) { +case 0x2910 : +case 0xda90 : +return true; + +default : +return false; + } +} +static bool ro_register (u32 reg) { if ((reg & RING_FORCE_TO_NONPRIV_ACCESS_MASK) ==
@@ -511,7 +524,7 @@ static int check_dirty_whitelist(struct intel_context *ce)if (wo_register (engine, reg))continue ; -if (timestamp (engine, reg)) +if (timestamp (engine, reg) ||oa_gpu_ticks (reg))continue ;/* timestamps are expected to autoincrement */ ro_reg =ro_register (reg);
@@ -918,6 +931,9 @@ static bool find_reg(struct drm_i915_private *i915, {u32 offset =i915_mmio_reg_offset (reg); +/* Clear non priv flags */ + offset &=RING_FORCE_TO_NONPRIV_ADDRESS_MASK ; +while (count--) {if (INTEL_INFO (i915)->gen_mask & tbl->gen_mask &&i915_mmio_reg_offset (tbl->reg) == offset)
@@ -938,6 +954,12 @@ static bool pardon_reg(struct drm_i915_private *i915, i915_reg_t reg) { OAREPORTTRIG6, INTEL_GEN_MASK(8, 11) }, { GEN12_OAG_OAREPORTTRIG2, INTEL_GEN_MASK(12, 12) }, { GEN12_OAG_OAREPORTTRIG6, INTEL_GEN_MASK(12, 12) }, + { OA_PERF_COUNTER_A(18), INTEL_GEN_MASK(8, 11) }, + { OA_PERF_COUNTER_A(20), INTEL_GEN_MASK(8, 11) }, + { OA_PERF_COUNTER_A_UPPER(20), INTEL_GEN_MASK(8, 11) }, + { GEN12_OAG_PERF_COUNTER_A(18), INTEL_GEN_MASK(12, 12) }, + { GEN12_OAG_PERF_COUNTER_A(20), INTEL_GEN_MASK(12, 12) }, + { GEN12_OAG_PERF_COUNTER_A_UPPER(20), INTEL_GEN_MASK(12, 12) }, };return find_reg (i915, reg, pardon,ARRAY_SIZE (pardon));
@@ -964,6 +986,12 @@ static bool writeonly_reg(struct drm_i915_private *i915, i915_reg_t reg) { OAREPORTTRIG6, INTEL_GEN_MASK(8, 11) }, { GEN12_OAG_OAREPORTTRIG2, INTEL_GEN_MASK(12, 12) }, { GEN12_OAG_OAREPORTTRIG6, INTEL_GEN_MASK(12, 12) }, + { OA_PERF_COUNTER_A(18), INTEL_GEN_MASK(8, 11) }, + { OA_PERF_COUNTER_A(20), INTEL_GEN_MASK(8, 11) }, + { OA_PERF_COUNTER_A_UPPER(20), INTEL_GEN_MASK(8, 11) }, + { GEN12_OAG_PERF_COUNTER_A(18), INTEL_GEN_MASK(12, 12) }, + { GEN12_OAG_PERF_COUNTER_A(20), INTEL_GEN_MASK(12, 12) }, + { GEN12_OAG_PERF_COUNTER_A_UPPER(20), INTEL_GEN_MASK(12, 12) }, };return find_reg (i915, reg, wo,ARRAY_SIZE (wo));
drivers/gpu/drm/i915/i915_perf.c +7 -1
@@ -4450,8 +4450,14 @@ int i915_perf_ioctl_version(void)* * 6: Whitelist OATRIGGER registers to allow user to trigger reports * into the OA buffer. This applies only to gen8+. +* +* 7: Whitelist below OA registers for user to identify the location of +* triggered reports in the OA buffer. This applies only to gen8+. +* +* - OA buffer head/tail/status/buffer registers for read only +* - OA counters A18, A19, A20 for read/write */ -return 6 ; +return 7 ; }#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST )
drivers/gpu/drm/i915/i915_reg.h +10 -0
@@ -675,6 +675,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define GEN7_OASTATUS2_HEAD_MASK 0xffffffc0#define GEN7_OASTATUS2_MEM_SELECT_GGTT (1 << 0)/* 0: PPGTT, 1: GGTT */ +#define GEN8_GPU_TICKS _MMIO(0x2910)#define GEN8_OASTATUS _MMIO(0x2b08)#define GEN8_OASTATUS_OVERRUN_STATUS (1 << 3)#define GEN8_OASTATUS_COUNTER_OVERFLOW (1 << 2)
@@ -733,6 +734,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define GEN12_OAG_OA_DEBUG_DISABLE_GO_1_0_REPORTS (1 << 2)#define GEN12_OAG_OA_DEBUG_DISABLE_CTX_SWITCH_REPORTS (1 << 1) +#define GEN12_OAG_GPU_TICKS _MMIO(0xda90)#define GEN12_OAG_OASTATUS _MMIO(0xdafc)#define GEN12_OAG_OASTATUS_COUNTER_OVERFLOW (1 << 2)#define GEN12_OAG_OASTATUS_BUFFER_OVERFLOW (1 << 1)
@@ -974,6 +976,14 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define OAREPORTTRIG8_NOA_SELECT_6_SHIFT 24#define OAREPORTTRIG8_NOA_SELECT_7_SHIFT 28 +/* Performance counters registers */ +#define OA_PERF_COUNTER_A (idx) _MMIO(0x2800 + 8 * (idx)) +#define OA_PERF_COUNTER_A_UPPER (idx) _MMIO(0x2800 + 8 * (idx) + 4) + +/* Gen12 Performance counters registers */ +#define GEN12_OAG_PERF_COUNTER_A (idx) _MMIO(0xD980 + 8 * (idx)) +#define GEN12_OAG_PERF_COUNTER_A_UPPER (idx) _MMIO(0xD980 + 8 * (idx) + 4) +/* Same layout as OASTARTTRIGX */ #define GEN12_OAG_OASTARTTRIG1 _MMIO(0xd900)#define GEN12_OAG_OASTARTTRIG2 _MMIO(0xd904)
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 3/4] drm/i915/perf: Whitelist OA counter and buffer registers
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:00)
Quoted 45 lines
From: Piotr Maciejewski <[email protected]>
It is useful to have markers in the OA reports to identify triggered reports. Whitelist some OA counters that can be used as markers.
A triggered report can be found faster if we can sample the HW tail and head registers when the report was triggered. Whitelist OA buffer specific registers.
v2:
- Bump up the perf revision (Lionel)
- Use indexing for counters (Lionel)
- Fix selftest for oa ticking register (Umesh)v3: Pardon whitelisted registers for selftest (Umesh)
v4:
- Document whitelisted registers (Lionel)
- Fix live isolated whitelist for OA regs (Umesh)Signed-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>Reviewed-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 34 +++++++++++++++++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 30 +++++++++++++++- drivers/gpu/drm/i915/i915_perf.c | 8 ++++- drivers/gpu/drm/i915/i915_reg.h | 10 ++++++ 4 files changed, 80 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/intel_workarounds.c +7
-0@@ -1392,6 +1392,23 @@ static void gen9_whitelist_build_performance_counters(struct i915_wa_list *w)/* OA buffer trigger report 2/6 used by performance query */ whitelist_reg (w,OAREPORTTRIG2 );whitelist_reg (w,OAREPORTTRIG6 ); + +/* Performance counters A18-20 used by tbs marker query */ +whitelist_reg_ext (w,OA_PERF_COUNTER_A (18 ), +RING_FORCE_TO_NONPRIV_ACCESS_RW | +RING_FORCE_TO_NONPRIV_RANGE_4 ); + +whitelist_reg (w,OA_PERF_COUNTER_A (20 ));
drivers/gpu/drm/i915/gt/intel_workarounds.c static void gen9_whitelist_build_performance_counters(struct i915_wa_list *w) · line 1411
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c +10
-0+whitelist_reg (w,OA_PERF_COUNTER_A_UPPER (20 )); + +/* Read access to gpu ticks */ +whitelist_reg_ext (w,GEN8_GPU_TICKS , +RING_FORCE_TO_NONPRIV_ACCESS_RD ); + +/* Read access to: oa status, head, tail, buffer settings */ +whitelist_reg_ext (w,GEN8_OASTATUS , +RING_FORCE_TO_NONPRIV_ACCESS_RD | +RING_FORCE_TO_NONPRIV_RANGE_4 );
Great. This completely fills RING_MAX_NONPRIV_SLOTS, with over half the slots going to OA. That does not seem sustainable.
I did not think the extended whitelist settings were available before cml.
-Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 3/4] drm/i915/perf: Whitelist OA counter and buffer registers
Quoted 60 lines · Chris Wilson
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:00)
Quoted 45 lines
From: Piotr Maciejewski <[email protected]>
It is useful to have markers in the OA reports to identify triggered reports. Whitelist some OA counters that can be used as markers.
A triggered report can be found faster if we can sample the HW tail and head registers when the report was triggered. Whitelist OA buffer specific registers.
v2:
- Bump up the perf revision (Lionel)
- Use indexing for counters (Lionel)
- Fix selftest for oa ticking register (Umesh)v3: Pardon whitelisted registers for selftest (Umesh)
v4:
- Document whitelisted registers (Lionel)
- Fix live isolated whitelist for OA regs (Umesh)Signed-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>Reviewed-by Lionel Landwerlin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 34 +++++++++++++++++++ .../gpu/drm/i915/gt/selftest_workarounds.c | 30 +++++++++++++++- drivers/gpu/drm/i915/i915_perf.c | 8 ++++- drivers/gpu/drm/i915/i915_reg.h | 10 ++++++ 4 files changed, 80 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/intel_workarounds.c +7
-0@@ -1392,6 +1392,23 @@ static void gen9_whitelist_build_performance_counters(struct i915_wa_list *w)/* OA buffer trigger report 2/6 used by performance query */ whitelist_reg (w,OAREPORTTRIG2 );whitelist_reg (w,OAREPORTTRIG6 ); + +/* Performance counters A18-20 used by tbs marker query */ +whitelist_reg_ext (w,OA_PERF_COUNTER_A (18 ), +RING_FORCE_TO_NONPRIV_ACCESS_RW | +RING_FORCE_TO_NONPRIV_RANGE_4 ); + +whitelist_reg (w,OA_PERF_COUNTER_A (20 ));drivers/gpu/drm/i915/gt/intel_workarounds.c static void gen9_whitelist_build_performance_counters(struct i915_wa_list *w) · line 1411
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_workarounds.c +10
-0+whitelist_reg (w,OA_PERF_COUNTER_A_UPPER (20 )); + +/* Read access to gpu ticks */ +whitelist_reg_ext (w,GEN8_GPU_TICKS , +RING_FORCE_TO_NONPRIV_ACCESS_RD ); + +/* Read access to: oa status, head, tail, buffer settings */ +whitelist_reg_ext (w,GEN8_OASTATUS , +RING_FORCE_TO_NONPRIV_ACCESS_RD | +RING_FORCE_TO_NONPRIV_RANGE_4 );Great. This completely fills
RING_MAX_NONPRIV_SLOTS, with over half the slots going to OA. That does not seem sustainable.
Quoted 2 lines
I did not think the extended whitelist settings were available before cml.
Looks like we can remove A20, A20_upper and gpu ticks to free up 3 slots. Will post that in the new series. Hoping that will do for now.
Thanks,
Umesh
Quoted 1 line
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/4 drm/i915/perf: Map OA buffer to user space for gen12 performance query
In reply to Umesh Nerlige RamappaFrom: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.
These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user space
v2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, use perf_fd and support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not expose gpu_address (Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)
v3: (Chris)
- Omit redundant checks
- Return VM_FAULT_SIGBUS is old stream is closed
- Maintain reference counts to stream in vm_open and vm_close
- Use switch to identify object to be mapped
v4: Call kref_put on closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. Use VM_DONTCOPY
- Enforce MAP_PRIVATE by checking for VM_MAYSHARE
--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_mman.h | 2 + drivers/gpu/drm/i915/i915_perf.c | 226 ++++++++++++++++++++++- drivers/gpu/drm/i915/i915_perf_types.h | 17 ++ include/uapi/drm/i915_drm.h | 32 ++++ 5 files changed, 276 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +1 -1
@@ -204,7 +204,7 @@ compute_partial_view(const struct drm_i915_gem_object *obj,return view; } -static vm_fault_t i915_error_to_vmf_fault (int err) +vm_fault_t i915_error_to_vmf_fault (int err) {switch (err) {default :
drivers/gpu/drm/i915/gem/i915_gem_mman.h +2 -0
@@ -29,4 +29,6 @@ void i915_gem_object_release_mmap_gtt(struct drm_i915_gem_object *obj);void i915_gem_object_release_mmap_offset (struct drm_i915_gem_object *obj); +vm_fault_t i915_error_to_vmf_fault (int err); +#endif
drivers/gpu/drm/i915/i915_perf.c +224 -2
321 lines not on this page · raw message
drivers/gpu/drm/i915/i915_perf_types.h +17 -0
@@ -311,6 +311,18 @@ struct i915_perf_stream {* buffer should be checked for available data. */ u64 poll_oa_period; + +/** +* @closed: Open or closed state of the stream. +* True if stream is closed. +*/ +bool closed; + +/** +* @refcount: References to the mapped OA buffer managed by this +* stream. +*/ +struct kref refcount; };/**
@@ -377,6 +389,11 @@ struct i915_oa_ops {* generations. */ u32 (*oa_hw_tail_read)(struct i915_perf_stream *stream); + +/** +* @oa_hw_head_read: read the OA head pointer register +*/ +u32 (*oa_hw_head_read)(struct i915_perf_stream *stream); };struct i915_perf {
include/uapi/drm/i915_drm.h +32 -0
@@ -2048,6 +2048,38 @@ struct drm_i915_perf_open_param {*/ #define I915_PERF_IOCTL_CONFIG _IO('i', 0x2) +/** +* Returns OA buffer properties to be used with mmap. +* +* This ioctl is available in perf revision 8. +*/ +#define I915_PERF_IOCTL_GET_OA_BUFFER_INFO _IO('i', 0x3) + +/** +* OA buffer size and offset. +*/ +struct drm_i915_perf_oa_buffer_info { +__u32 size; +__u32 offset; +__u64 reserved[4 ]; +}; + +/** +* Returns current position of OA buffer head and tail. +* +* This ioctl is available in perf revision 8. +*/ +#define I915_PERF_IOCTL_GET_OA_BUFFER_HEAD_TAIL _IO('i', 0x4) + +/** +* OA buffer head and tail. +*/ +struct drm_i915_perf_oa_buffer_head_tail { +__u32 head; +__u32 tail; +__u64 reserved[4 ]; +}; +/** * Common to all i915 perf records */
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:01)
Quoted 64 lines
From: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user spacev2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, useperf_fdand support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not exposegpu_address(Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)v3: (Chris)
- Omit redundant checks
- ReturnVM_FAULT_SIGBUSis old stream is closed
- Maintain reference counts to stream invm_openandvm_close
- Use switch to identify object to be mappedv4: Call
kref_puton closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. UseVM_DONTCOPY
- EnforceMAP_PRIVATEby checking forVM_MAYSHARESigned-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>---
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3430
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -3314,12 +3427,113 @@ static int i915_perf_release(struct inode *inode, struct file *file)i915_perf_destroy_locked (stream);mutex_unlock (&perf->lock); +unmap_mapping_range (file->f_mapping,0 ,OA_BUFFER_SIZE ,1 );
You can just used unmap_mapping_range(file->f_mapping, 0, -1, 1); It scales with the number of vma present, so no worries, be conservative. (Otherwise, you need s/0/OA_BUFFER_OFFSET/.)
Quoted 21 lines
drivers/gpu/drm/i915/i915_perf.c +15
-0+/* Release the reference the perf stream kept on the driver. */ drm_dev_put (&perf->i915->drm);return 0 ; } +static void vm_open_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_get (stream); +} + +static void vm_close_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_put (stream);
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3461
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+} + +static vm_fault_t vm_fault_oa (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma; +struct i915_perf_stream *stream = vma->vm_private_data; +struct i915_perf *perf = stream->perf; +struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj; +int err; +bool closed;
So vm_area_struct has a reference to the stream, that looks good now. But there's no reference held to the vma itself.
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3465
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+mutex_lock (&perf->lock); + closed =READ_ONCE (stream->closed); +mutex_unlock (&perf->lock);
We do WRITE_ONCE(stream->closed, true) then invalidate all the mappings, so that part looks good. The invalidate is serialised with the vm_fault_oa, so we can just use a plain READ_ONCE(stream->closed) here and not worry about the perf->lock.
However... I think it should close&invalidate before releasing stream->oa_buffer.
And the read here of stream->oa_buffer should be after checking stream->closed.
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3478
Quoted 13 lines
drivers/gpu/drm/i915/i915_perf.c +13
-0+ +if (closed) +return VM_FAULT_SIGBUS ; + + err =i915_gem_object_pin_pages (obj); +if (err) + goto out; + + err =remap_io_sg (vma, + vma->vm_start, vma->vm_end - vma->vm_start, + obj->mm.pages->sgl,-1 ); + +i915_gem_object_unpin_pages (obj);
I'd be really tempted here not to use stream->oa_buffer.vma->obj at all. We know the oa_buffer is pinned while it is open (and we know we will be serialised against close/destroy), so this can be reduced to just
err = remap_io_sg(vma,
vma->vm_start, vma->vm_end - vma->vm_start,
stream->oa_buffer.vma->pages, -1);Quoted 15 lines
drivers/gpu/drm/i915/i915_perf.c +15
-0+ +out: +return i915_error_to_vmf_fault (err); +} + +static const struct vm_operations_struct vm_ops_oa = { + .open = vm_open_oa, + .close = vm_close_oa, + .fault = vm_fault_oa, +}; + +int i915_perf_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = file->private_data; +
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3503
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+/* mmap-ing OA buffer to user space MUST absolutely be privileged */ +if (i915_perf_stream_paranoid && !perfmon_capable ()) { +DRM_DEBUG ("Insufficient privileges to map OA buffer\n" ); +return -EACCES ; + } + +switch (vma->vm_pgoff) { +/* A non-zero offset ensures that we are mapping the right object. Also +* leaves room for future objects added to this implementation. +*/
/*
* Kernel block comment style.
*/
(There's a few subsystems, i.e net/ that use the other style, but we've switch over to the more common open style and try to stick to it.)
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +8
-0+case I915_PERF_OA_BUFFER_MMAP_OFFSET : +if (vma->vm_end - vma->vm_start >OA_BUFFER_SIZE ) +return -EINVAL ; + +/* Only support VM_READ. Enforce MAP_PRIVATE by checking for +* VM_MAYSHARE. +*/ + if (vma->vm_flags & (VM_WRITE | VM_EXEC |
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3521
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+ VM_SHARED | VM_MAYSHARE)) +return -EINVAL ; + + vma->vm_flags &= ~(VM_MAYWRITE |VM_MAYEXEC ); + +/* If the privileged parent forks and child drops root +* privilege, we do not want the child to retain access to the +* mapped OA buffer. Explicitly set VM_DONTCOPY to avoid such +* cases. +*/
The explanations are extremely valuable :)
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ vma->vm_flags |=VM_PFNMAP |VM_DONTEXPAND | +VM_DONTDUMP |VM_DONTCOPY ; +break ; + +default :
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3536
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+return -EINVAL ; + } + + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_private_data = stream; + vma->vm_ops = &vm_ops_oa; +vm_open_oa (vma); + +return 0 ; +}
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoted 100 lines · Chris Wilson
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:01)
Quoted 64 lines
From: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user spacev2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, useperf_fdand support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not exposegpu_address(Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)v3: (Chris)
- Omit redundant checks
- ReturnVM_FAULT_SIGBUSis old stream is closed
- Maintain reference counts to stream invm_openandvm_close
- Use switch to identify object to be mappedv4: Call
kref_puton closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. UseVM_DONTCOPY
- EnforceMAP_PRIVATEby checking forVM_MAYSHARESigned-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>---
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3430
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -3314,12 +3427,113 @@ static int i915_perf_release(struct inode *inode, struct file *file)i915_perf_destroy_locked (stream);mutex_unlock (&perf->lock); +unmap_mapping_range (file->f_mapping,0 ,OA_BUFFER_SIZE ,1 );You can just used
unmap_mapping_range(file->f_mapping, 0, -1, 1); It scales with the number of vma present, so no worries, be conservative. (Otherwise, you need s/0/OA_BUFFER_OFFSET/.)Quoted 26 lines
drivers/gpu/drm/i915/i915_perf.c +20
-0+/* Release the reference the perf stream kept on the driver. */ drm_dev_put (&perf->i915->drm);return 0 ; } +static void vm_open_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_get (stream); +} + +static void vm_close_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_put (stream); +} + +static vm_fault_t vm_fault_oa (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma;
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3461
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+struct i915_perf_stream *stream = vma->vm_private_data; +struct i915_perf *perf = stream->perf; +struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj; +int err; +bool closed;So
vm_area_structhas a reference to the stream, that looks good now. But there's no reference held to the vma itself.
How do I get a reference to the vma.
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3465
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+mutex_lock (&perf->lock); + closed =READ_ONCE (stream->closed); +mutex_unlock (&perf->lock);We do
WRITE_ONCE(stream->closed, true)then invalidate all the mappings, so that part looks good. The invalidate is serialised with thevm_fault_oa, so we can just use a plainREAD_ONCE(stream->closed)here and not worry about theperf->lock.
will do
Quoted 3 lines
However... I think it should close&invalidate before releasing
stream->oa_buffer.
will do
Quoted 3 lines
And the read here of
stream->oa_buffershould be after checkingstream->closed.
I don't understand. I am checking for closed before remap_io_sg.
Thanks,
Umesh
Quoted 77 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+ +if (closed) +return VM_FAULT_SIGBUS ;drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3478
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+ + err =i915_gem_object_pin_pages (obj); +if (err) + goto out; + + err =remap_io_sg (vma, + vma->vm_start, vma->vm_end - vma->vm_start, + obj->mm.pages->sgl,-1 ); + +i915_gem_object_unpin_pages (obj);I'd be really tempted here not to use
stream->oa_buffer.vma->objat all. We know theoa_bufferis pinned while it is open (and we know we will be serialised against close/destroy), so this can be reduced to justerr = remap_io_sg(vma, vma->vm_start, vma->vm_end - vma->vm_start, stream->oa_buffer.vma->pages, -1);Quoted 15 lines
drivers/gpu/drm/i915/i915_perf.c +15
-0+ +out: +return i915_error_to_vmf_fault (err); +} + +static const struct vm_operations_struct vm_ops_oa = { + .open = vm_open_oa, + .close = vm_close_oa, + .fault = vm_fault_oa, +}; + +int i915_perf_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = file->private_data; +drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3503
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+/* mmap-ing OA buffer to user space MUST absolutely be privileged */ +if (i915_perf_stream_paranoid && !perfmon_capable ()) { +DRM_DEBUG ("Insufficient privileges to map OA buffer\n" ); +return -EACCES ; + } + +switch (vma->vm_pgoff) { +/* A non-zero offset ensures that we are mapping the right object. Also +* leaves room for future objects added to this implementation. +*/ /*
* Kernel block comment style.
*/(There's a few subsystems, i.e
net/that use the other style, but we've switch over to the more common open style and try to stick to it.)Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +8
-0+case I915_PERF_OA_BUFFER_MMAP_OFFSET : +if (vma->vm_end - vma->vm_start >OA_BUFFER_SIZE ) +return -EINVAL ; + +/* Only support VM_READ. Enforce MAP_PRIVATE by checking for +* VM_MAYSHARE. +*/ + if (vma->vm_flags & (VM_WRITE | VM_EXEC |drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3521
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+ VM_SHARED | VM_MAYSHARE)) +return -EINVAL ; + + vma->vm_flags &= ~(VM_MAYWRITE |VM_MAYEXEC ); + +/* If the privileged parent forks and child drops root +* privilege, we do not want the child to retain access to the +* mapped OA buffer. Explicitly set VM_DONTCOPY to avoid such +* cases. +*/ The explanations are extremely valuable :)
Quoted 15 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ vma->vm_flags |=VM_PFNMAP |VM_DONTEXPAND | +VM_DONTDUMP |VM_DONTCOPY ; +break ; + +default :drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3536
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+return -EINVAL ; + } + + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_private_data = stream; + vma->vm_ops = &vm_ops_oa; +vm_open_oa (vma); + +return 0 ; +}
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoting Umesh Nerlige Ramappa (2020-07-24 17:29:56)
Quoted 110 lines · Chris Wilson
Quoted 100 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:01)
Quoted 64 lines
From: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user spacev2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, useperf_fdand support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not exposegpu_address(Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)v3: (Chris)
- Omit redundant checks
- ReturnVM_FAULT_SIGBUSis old stream is closed
- Maintain reference counts to stream invm_openandvm_close
- Use switch to identify object to be mappedv4: Call
kref_puton closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. UseVM_DONTCOPY
- EnforceMAP_PRIVATEby checking forVM_MAYSHARESigned-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>---
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3430
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -3314,12 +3427,113 @@ static int i915_perf_release(struct inode *inode, struct file *file)i915_perf_destroy_locked (stream);mutex_unlock (&perf->lock); +unmap_mapping_range (file->f_mapping,0 ,OA_BUFFER_SIZE ,1 );You can just used
unmap_mapping_range(file->f_mapping, 0, -1, 1); It scales with the number of vma present, so no worries, be conservative. (Otherwise, you need s/0/OA_BUFFER_OFFSET/.)Quoted 26 lines
drivers/gpu/drm/i915/i915_perf.c +20
-0+/* Release the reference the perf stream kept on the driver. */ drm_dev_put (&perf->i915->drm);return 0 ; } +static void vm_open_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_get (stream); +} + +static void vm_close_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_put (stream); +} + +static vm_fault_t vm_fault_oa (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma;Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3461
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+struct i915_perf_stream *stream = vma->vm_private_data; +struct i915_perf *perf = stream->perf; +struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj; +int err; +bool closed;So
vm_area_structhas a reference to the stream, that looks good now. But there's no reference held to the vma itself.
Quoted 1 line
How do I get a reference to the vma.
That would be i915_vma_get(), but you don't need to if we control the order correctly, as then neither the PTE nor the ongoing faulthandler last longer than the i915_perf_stream
Quoted 14 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3465
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+mutex_lock (&perf->lock); + closed =READ_ONCE (stream->closed); +mutex_unlock (&perf->lock);We do
WRITE_ONCE(stream->closed, true)then invalidate all the mappings, so that part looks good. The invalidate is serialised with thevm_fault_oa, so we can just use a plainREAD_ONCE(stream->closed)here and not worry about theperf->lock.will do
Quoted 3 lines
However... I think it should close&invalidate before releasing
stream->oa_buffer.
Quoted 6 lines
will do
Quoted 3 lines
And the read here of
stream->oa_buffershould be after checkingstream->closed.I don't understand. I am checking for closed before
remap_io_sg.
It's the
struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj;
that's before the stream->closed check. That's dereferencing vma, but vma will be set to NULL in i915_perf_destroy.
-Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoted 111 lines · Chris Wilson
Quoting Umesh Nerlige Ramappa (2020-07-24 17:29:56)
Quoted 110 lines · Chris Wilson
Quoted 108 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:01)
Quoted 64 lines
From: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user spacev2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, useperf_fdand support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not exposegpu_address(Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)v3: (Chris)
- Omit redundant checks
- ReturnVM_FAULT_SIGBUSis old stream is closed
- Maintain reference counts to stream invm_openandvm_close
- Use switch to identify object to be mappedv4: Call
kref_puton closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. UseVM_DONTCOPY
- EnforceMAP_PRIVATEby checking forVM_MAYSHARESigned-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>---
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3430
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -3314,12 +3427,113 @@ static int i915_perf_release(struct inode *inode, struct file *file)i915_perf_destroy_locked (stream);mutex_unlock (&perf->lock); +unmap_mapping_range (file->f_mapping,0 ,OA_BUFFER_SIZE ,1 );You can just used
unmap_mapping_range(file->f_mapping, 0, -1, 1); It scales with the number of vma present, so no worries, be conservative. (Otherwise, you need s/0/OA_BUFFER_OFFSET/.)Quoted 21 lines
drivers/gpu/drm/i915/i915_perf.c +15
-0+/* Release the reference the perf stream kept on the driver. */ drm_dev_put (&perf->i915->drm);return 0 ; } +static void vm_open_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_get (stream); +} + +static void vm_close_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_put (stream);drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3461
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+} + +static vm_fault_t vm_fault_oa (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma; +struct i915_perf_stream *stream = vma->vm_private_data; +struct i915_perf *perf = stream->perf; +struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj; +int err; +bool closed;So
vm_area_structhas a reference to the stream, that looks good now. But there's no reference held to the vma itself.
Quoted 5 lines
Quoted 1 line
How do I get a reference to the vma.
That would be
i915_vma_get(), but you don't need to if we control the order correctly, as then neither the PTE nor the ongoing faulthandler last longer than thei915_perf_stream
I see that the do_mmap()->mmap_region() takes a reference to file
vma->vm_file = get_file(file);
In our case this is perf_fd. do_munmap does a corresponding fput.
so unmap_mapping_range() is never called unless both unmap() and close(perf_fd) are called by user (or process terminates).
Is that good to take care of this ordering?
This also explains why I cannot get a VM_FAULT_SIGBUS with the IGTs.
Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3465
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+mutex_lock (&perf->lock); + closed =READ_ONCE (stream->closed); +mutex_unlock (&perf->lock);We do
WRITE_ONCE(stream->closed, true)then invalidate all the mappings, so that part looks good. The invalidate is serialised with thevm_fault_oa, so we can just use a plainREAD_ONCE(stream->closed)here and not worry about theperf->lock.will do
Quoted 3 lines
However... I think it should close&invalidate before releasing
stream->oa_buffer.will do
Quoted 3 lines
And the read here of
stream->oa_buffershould be after checkingstream->closed.
Quoted 8 lines
Quoted 1 line
I don't understand. I am checking for closed before
remap_io_sg.It's the
struct
drm_i915_gem_object*obj =stream->oa_buffer.vma->obj;that's before the
stream->closedcheck. That's dereferencing vma, but vma will be set to NULL ini915_perf_destroy.
I will not use stream->oa_buffer.vma->obj in vm_fault_oa based on your earlier comments, so this should be taken care of.
Thanks,
Umesh
Quoted 1 line
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoting Umesh Nerlige Ramappa (2020-07-24 19:47:37)
Quoted 114 lines · Chris Wilson
Quoted 113 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 17:29:56)
Quoted 111 lines · Chris Wilson
Quoted 100 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:01)
Quoted 64 lines
From: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user spacev2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, useperf_fdand support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not exposegpu_address(Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)v3: (Chris)
- Omit redundant checks
- ReturnVM_FAULT_SIGBUSis old stream is closed
- Maintain reference counts to stream invm_openandvm_close
- Use switch to identify object to be mappedv4: Call
kref_puton closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. UseVM_DONTCOPY
- EnforceMAP_PRIVATEby checking forVM_MAYSHARESigned-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>---
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3430
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -3314,12 +3427,113 @@ static int i915_perf_release(struct inode *inode, struct file *file)i915_perf_destroy_locked (stream);mutex_unlock (&perf->lock); +unmap_mapping_range (file->f_mapping,0 ,OA_BUFFER_SIZE ,1 );You can just used
unmap_mapping_range(file->f_mapping, 0, -1, 1); It scales with the number of vma present, so no worries, be conservative. (Otherwise, you need s/0/OA_BUFFER_OFFSET/.)Quoted 26 lines
drivers/gpu/drm/i915/i915_perf.c +20
-0+/* Release the reference the perf stream kept on the driver. */ drm_dev_put (&perf->i915->drm);return 0 ; } +static void vm_open_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_get (stream); +} + +static void vm_close_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_put (stream); +} + +static vm_fault_t vm_fault_oa (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma;Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3461
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+struct i915_perf_stream *stream = vma->vm_private_data; +struct i915_perf *perf = stream->perf; +struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj; +int err; +bool closed;So
vm_area_structhas a reference to the stream, that looks good now. But there's no reference held to the vma itself.How do I get a reference to the vma.
Quoted 7 lines
Quoted 3 lines
That would be
i915_vma_get(), but you don't need to if we control the order correctly, as then neither the PTE nor the ongoing faulthandler last longer than thei915_perf_streamI see that the do_mmap()->mmap_region() takes a reference to file
vma->vm_file=get_file(file);
By vma, I meant stream-oa_buffer.vma
Quoted 4 lines
In our case this is
perf_fd.do_munmapdoes a corresponding fput.so
unmap_mapping_range()is never called unless bothunmap()andclose(perf_fd)are called by user (or process terminates).
The unmap_mapping_range() is called by destroy, so that should be independent of userspace munmap.
Quoted 3 lines
Is that good to take care of this ordering?
This also explains why I cannot get a
VM_FAULT_SIGBUSwith the IGTs.
To hit the stream->close you'll need to race mmap/munmap against perf destroy. You may like to challenge yourself to hit it :)
Quoted 23 lines
Quoted 23 lines
Quoted 14 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3465
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+mutex_lock (&perf->lock); + closed =READ_ONCE (stream->closed); +mutex_unlock (&perf->lock);We do
WRITE_ONCE(stream->closed, true)then invalidate all the mappings, so that part looks good. The invalidate is serialised with thevm_fault_oa, so we can just use a plainREAD_ONCE(stream->closed)here and not worry about theperf->lock.will do
Quoted 3 lines
However... I think it should close&invalidate before releasing
stream->oa_buffer.Quoted 6 lines
will do
Quoted 3 lines
And the read here of
stream->oa_buffershould be after checkingstream->closed.I don't understand. I am checking for closed before
remap_io_sg.It's the
Quoted 7 lines
Quoted 4 lines
struct
drm_i915_gem_object*obj =stream->oa_buffer.vma->obj;that's before the
stream->closedcheck. That's dereferencing vma, but vma will be set to NULL ini915_perf_destroy.I will not use
stream->oa_buffer.vma->objinvm_fault_oabased on your earlier comments, so this should be taken care of.
Aye.
-Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoted 119 lines · Chris Wilson
Quoting Umesh Nerlige Ramappa (2020-07-24 19:47:37)
Quoted 118 lines · Chris Wilson
Quoted 116 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 17:29:56)
Quoted 110 lines · Chris Wilson
Quoted 100 lines
Quoting Umesh Nerlige Ramappa (2020-07-24 01:19:01)
Quoted 64 lines
From: Piotr Maciejewski <[email protected]>
i915 used to support time based sampling mode which is good for overall system monitoring, but is not enough for query mode used to measure a single draw call or dispatch. Gen9-Gen11 are using current i915 perf implementation for query, but Gen12+ requires a new approach for query based on triggered reports within oa buffer.
Triggering reports into the OA buffer is achieved by writing into a a trigger register. Optionally an unused counter/register is set with a marker value such that a triggered report can be identified in the OA buffer. Reports are usually triggered at the start and end of work that is measured.
Since OA buffer is large and queries can be frequent, an efficient way to look for triggered reports is required. By knowing the current head and tail offsets into the OA buffer, it is easier to determine the locality of the reports of interest.
Current perf OA interface does not expose head/tail information to the user and it filters out invalid reports before sending data to user. Also considering limited size of user buffer used during a query, creating a 1:1 copy of the OA buffer at the user space added undesired complexity.
The solution was to map the OA buffer to user space provided
(1) that it is accessed from a privileged user.
(2) OA report filtering is not used.These 2 conditions would satisfy the safety criteria that the current perf interface addresses.
To enable the query:
- Add an ioctl to expose head and tail to the user
- Add an ioctl to return size and offset of the OA buffer
- Map the OA buffer to the user spacev2:
- Improve commit message (Chris)
- Do not mmap based on gem object filp. Instead, useperf_fdand support mmap syscall (Chris)
- Pass non-zero offset in mmap to enforce the right object is mapped (Chris)
- Do not exposegpu_address(Chris)
- Verify start and length of vma for page alignment (Lionel)
- Move SQNTL config out (Lionel)v3: (Chris)
- Omit redundant checks
- ReturnVM_FAULT_SIGBUSis old stream is closed
- Maintain reference counts to stream invm_openandvm_close
- Use switch to identify object to be mappedv4: Call
kref_puton closing perf fd (Chris)
v5:
- Strip access to OA buffer from unprivileged child of a privileged parent. UseVM_DONTCOPY
- EnforceMAP_PRIVATEby checking forVM_MAYSHARESigned-off-by Piotr Maciejewski <[email protected]>Signed-off-by Umesh Nerlige Ramappa <[email protected]>---
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3430
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -3314,12 +3427,113 @@ static int i915_perf_release(struct inode *inode, struct file *file)i915_perf_destroy_locked (stream);mutex_unlock (&perf->lock); +unmap_mapping_range (file->f_mapping,0 ,OA_BUFFER_SIZE ,1 );You can just used
unmap_mapping_range(file->f_mapping, 0, -1, 1); It scales with the number of vma present, so no worries, be conservative. (Otherwise, you need s/0/OA_BUFFER_OFFSET/.)Quoted 26 lines
drivers/gpu/drm/i915/i915_perf.c +20
-0+/* Release the reference the perf stream kept on the driver. */ drm_dev_put (&perf->i915->drm);return 0 ; } +static void vm_open_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_get (stream); +} + +static void vm_close_oa (struct vm_area_struct *vma) +{ +struct i915_perf_stream *stream = vma->vm_private_data; + +GEM_BUG_ON (!stream); +perf_stream_put (stream); +} + +static vm_fault_t vm_fault_oa (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma;Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3461
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+struct i915_perf_stream *stream = vma->vm_private_data; +struct i915_perf *perf = stream->perf; +struct drm_i915_gem_object *obj = stream->oa_buffer.vma->obj; +int err; +bool closed;So
vm_area_structhas a reference to the stream, that looks good now. But there's no reference held to the vma itself.Quoted 1 line
How do I get a reference to the vma.
That would be
i915_vma_get(), but you don't need to if we control the order correctly, as then neither the PTE nor the ongoing faulthandler last longer than thei915_perf_stream
Quoted 5 lines
Quoted 3 lines
I see that the do_mmap()->mmap_region() takes a reference to file
vma->vm_file=get_file(file);By vma, I meant stream-oa_buffer.vma
aah, ok.
Quoted 8 lines
Quoted 5 lines
In our case this is
perf_fd.do_munmapdoes a corresponding fput.so
unmap_mapping_range()is never called unless bothunmap()andclose(perf_fd)are called by user (or process terminates).The
unmap_mapping_range()is called by destroy, so that should be independent of userspace munmap.
I agree, but strangely, with mmap sequence below, I don't see i915_perf_release() called at all. So destroy() is not called.
perf_fd = i915_perf_open_ioctl()mmap(..., perf_fd...)close(perf_fd)
delay for a few seconds.
If I call munmap() after the close(), I see i915_perf_release() -> destroy() -> unmap_mapping_range()
Thanks,
Umesh
Quoted 33 lines
Quoted 4 lines
Is that good to take care of this ordering?
This also explains why I cannot get a
VM_FAULT_SIGBUSwith the IGTs.To hit the
stream->closeyou'll need to race mmap/munmap against perf destroy. You may like to challenge yourself to hit it :)Quoted 25 lines
Quoted 25 lines
Quoted 14 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c static int i915_perf_release(struct inode *inode, struct file *file) · line 3465
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+mutex_lock (&perf->lock); + closed =READ_ONCE (stream->closed); +mutex_unlock (&perf->lock);We do
WRITE_ONCE(stream->closed, true)then invalidate all the mappings, so that part looks good. The invalidate is serialised with thevm_fault_oa, so we can just use a plainREAD_ONCE(stream->closed)here and not worry about theperf->lock.will do
Quoted 3 lines
However... I think it should close&invalidate before releasing
stream->oa_buffer.Quoted 6 lines
will do
Quoted 3 lines
And the read here of
stream->oa_buffershould be after checkingstream->closed.I don't understand. I am checking for closed before
remap_io_sg.It's the
struct
drm_i915_gem_object*obj =stream->oa_buffer.vma->obj;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
that's before the
stream->closedcheck. That's dereferencing vma, but vma will be set to NULL ini915_perf_destroy.I will not use
stream->oa_buffer.vma->objinvm_fault_oabased on your earlier comments, so this should be taken care of.Aye.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoting Umesh Nerlige Ramappa (2020-07-24 20:35:11)
Quoted 10 lines
I agree, but strangely, with mmap sequence below, I don't see
i915_perf_release()called at all. Sodestroy()is not called.
perf_fd=i915_perf_open_ioctl()mmap(..., perf_fd...)close(perf_fd)
delay for a few seconds.If I call
munmap()after theclose(), I seei915_perf_release()->destroy()->unmap_mapping_range()
Hmm, vma->vm_file is pointing to the perf-fd. Ah, that's a big difference to what I'm used to. So all the references are handled for you by the correct vma->vm_file, and you don't need the vm_open/vm_close, the kref or the closed. Sorry.
-Chris
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 4/4] drm/i915/perf: Map OA buffer to user space for gen12 performance query
Quoted 9 lines · Chris Wilson
Quoting Umesh Nerlige Ramappa (2020-07-24 20:35:11)
Quoted 8 lines
I agree, but strangely, with mmap sequence below, I don't see
i915_perf_release()called at all. Sodestroy()is not called.
perf_fd=i915_perf_open_ioctl()mmap(..., perf_fd...)close(perf_fd)
delay for a few seconds.
Quoted 7 lines
Quoted 2 lines
If I call
munmap()after theclose(), I seei915_perf_release()->destroy()->unmap_mapping_range()Hmm,
vma->vm_fileis pointing to the perf-fd. Ah, that's a big difference to what I'm used to. So all the references are handled for you by the correctvma->vm_file, and you don't need the vm_open/vm_close, the kref or the closed. Sorry.
no worries at all. This is all new for me, so I appreciate all your prompt guidance that helped me look into this implementation in detail.
Thanks,
Umesh
Quoted 1 line
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[Intel-gfx] ✗ Fi.CI.SPARSE: warning for Allow privileged user to map the OA buffer (rev5)
In reply to Umesh Nerlige Ramappa== Series Details ==
== Series Details ==
Series: Allow privileged user to map the OA buffer (rev5)
URL : https://patchwork.freedesktop.org/series/79460/
State : warning
== Summary ==
$ dim sparse --fast origin/drm-tip Sparse version: v0.6.0 Fast mode used, each commit won't be checked separately.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BAT: failure for Allow privileged user to map the OA buffer (rev5)
In reply to Umesh Nerlige Ramappa== Series Details ==
== Series Details ==
Series: Allow privileged user to map the OA buffer (rev5)
URL : https://patchwork.freedesktop.org/series/79460/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_8783 -> Patchwork_18237
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_18237 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_18237, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/index.html
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_18237:
### IGT changes ###
#### Possible regressions ####
* igt@i915_selftest@live@workarounds:
- fi-skl-6700k2: [PASS][1] -> [DMESG-FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-skl-6700k2/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-skl-6700k2/igt@i915_selftest@[email protected]
- fi-kbl-x1275: [PASS][3] -> [DMESG-FAIL][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-x1275/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-x1275/igt@i915_selftest@[email protected]
- fi-cfl-guc: [PASS][5] -> [DMESG-FAIL][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-cfl-guc/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-cfl-guc/igt@i915_selftest@[email protected]
- fi-skl-guc: [PASS][7] -> [DMESG-FAIL][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-skl-guc/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-skl-guc/igt@i915_selftest@[email protected]
- fi-skl-6600u: [PASS][9] -> [DMESG-FAIL][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-skl-6600u/igt@i915_selftest@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-skl-6600u/igt@i915_selftest@[email protected]
- fi-kbl-8809g: [PASS][11] -> [DMESG-FAIL][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-8809g/igt@i915_selftest@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-8809g/igt@i915_selftest@[email protected]
- fi-cfl-8700k: [PASS][13] -> [DMESG-FAIL][14]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-cfl-8700k/igt@i915_selftest@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-cfl-8700k/igt@i915_selftest@[email protected]
- fi-kbl-r: [PASS][15] -> [DMESG-FAIL][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-r/igt@i915_selftest@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-r/igt@i915_selftest@[email protected]
- fi-cfl-8109u: [PASS][17] -> [DMESG-FAIL][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-cfl-8109u/igt@i915_selftest@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-cfl-8109u/igt@i915_selftest@[email protected]
- fi-skl-lmem: [PASS][19] -> [DMESG-FAIL][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-skl-lmem/igt@i915_selftest@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-skl-lmem/igt@i915_selftest@[email protected]
- fi-kbl-7500u: [PASS][21] -> [DMESG-FAIL][22]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-7500u/igt@i915_selftest@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-7500u/igt@i915_selftest@[email protected]
- fi-kbl-guc: [PASS][23] -> [DMESG-FAIL][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-guc/igt@i915_selftest@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-guc/igt@i915_selftest@[email protected]
- fi-kbl-soraka: [PASS][25] -> [DMESG-FAIL][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-soraka/igt@i915_selftest@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-soraka/igt@i915_selftest@[email protected]
#### Suppressed ####
The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.
* igt@i915_selftest@live@workarounds:
- {fi-kbl-7560u}: [PASS][27] -> [DMESG-FAIL][28]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-7560u/igt@i915_selftest@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-7560u/igt@i915_selftest@[email protected]
Known issues
------------
Here are the changes found in Patchwork_18237 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@gem_exec_suspend@basic-s0:
- fi-tgl-u2: [PASS][29] -> [FAIL][30] ([i915#1888])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-tgl-u2/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-tgl-u2/igt@[email protected]
* igt@i915_module_load@reload:
- fi-apl-guc: [PASS][31] -> [DMESG-WARN][32] ([i915#1635] / [i915#1982])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-apl-guc/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-apl-guc/igt@[email protected]
* igt@i915_selftest@live@workarounds:
- fi-apl-guc: [PASS][33] -> [DMESG-FAIL][34] ([i915#1635])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-apl-guc/igt@i915_selftest@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-apl-guc/igt@i915_selftest@[email protected]
- fi-bxt-dsi: [PASS][35] -> [DMESG-FAIL][36] ([i915#1635])
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-bxt-dsi/igt@i915_selftest@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-bxt-dsi/igt@i915_selftest@[email protected]
* igt@kms_addfb_basic@addfb25-yf-tiled:
- fi-tgl-y: [PASS][37] -> [DMESG-WARN][38] ([i915#402]) +1 similar issue
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-tgl-y/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-tgl-y/igt@[email protected]
#### Possible fixes ####
* igt@gem_exec_suspend@basic-s3:
- fi-tgl-u2: [FAIL][39] ([i915#1888]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-tgl-u2/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-tgl-u2/igt@[email protected]
* igt@i915_module_load@reload:
- fi-bsw-kefka: [DMESG-WARN][41] ([i915#1982]) -> [PASS][42] +1 similar issue
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-bsw-kefka/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-bsw-kefka/igt@[email protected]
* igt@i915_selftest@live@gt_lrc:
- fi-tgl-u2: [DMESG-FAIL][43] ([i915#1233]) -> [PASS][44]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-tgl-u2/igt@i915_selftest@live@gt_lrc.html
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-tgl-u2/igt@i915_selftest@live@gt_lrc.html
* igt@prime_vgem@basic-fence-flip:
- fi-tgl-y: [DMESG-WARN][45] ([i915#402]) -> [PASS][46] +1 similar issue
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-tgl-y/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-tgl-y/igt@[email protected]
#### Warnings ####
* igt@kms_force_connector_basic@force-connector-state:
- fi-kbl-x1275: [DMESG-WARN][47] ([i915#62] / [i915#92]) -> [DMESG-WARN][48] ([i915#62] / [i915#92] / [i915#95]) +2 similar issues
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-x1275/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-x1275/igt@[email protected]
* igt@kms_force_connector_basic@force-edid:
- fi-kbl-x1275: [DMESG-WARN][49] ([i915#62] / [i915#92] / [i915#95]) -> [DMESG-WARN][50] ([i915#62] / [i915#92]) +4 similar issues
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_8783/fi-kbl-x1275/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/fi-kbl-x1275/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[i915#1233]: https://gitlab.freedesktop.org/drm/intel/issues/1233
[i915#1635]: https://gitlab.freedesktop.org/drm/intel/issues/1635
[i915#1888]: https://gitlab.freedesktop.org/drm/intel/issues/1888
[i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
[i915#402]: https://gitlab.freedesktop.org/drm/intel/issues/402
[i915#62]: https://gitlab.freedesktop.org/drm/intel/issues/62
[i915#92]: https://gitlab.freedesktop.org/drm/intel/issues/92
[i915#95]: https://gitlab.freedesktop.org/drm/intel/issues/95
Participating hosts (47 -> 40)
------------------------------
Missing (7): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-clapper fi-bdw-samus
Build changes
-------------
* IGT: IGT_5746 -> IGTPW_4796
* Linux: CI_DRM_8783 -> Patchwork_18237
CI-20190529: 20190529
CI_DRM_8783: 9780545cd4109baff8c6eb1cb1060a29b7ab919f @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_4796: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_4796/index.html
IGT_5746: d818f0c54e5e781ba3fb372aab8f270cf153776c @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_18237: 8bcbc3e0f07c9452c99d8245fde369f01d5b64d5 @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
8bcbc3e0f07c drm/i915/perf: Map OA buffer to user space for gen12 performance query 0830d3c4ac64 drm/i915/perf: Whitelist OA counter and buffer registers 2626ca288d71 drm/i915/perf: Whitelist OA report trigger registers 3af9e7de1bfe drm/i915/perf: Ensure observation logic is not clock gated
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_18237/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx