drivers/gpu/drm/xe: Don't whitelist OA registers unconditionally
v2 cover drivers/gpu/drm/xe: Don't whitelist OA registers unconditionally
Backport of the following series to Linux 6.12.y:
https://lore.kernel.org/intel-xe/[email protected]/
v2: Fix upstream commit sha's (Sasha Levin)
Ashutosh Dixit (10):
drm/xe/rtp: Refactor OAG MMIO trigger register whitelisting drm/xe/rtp: Add RING_FORCE_TO_NONPRIV_DENY to OA whitelists drm/xe/rtp: Maintain OA whitelists separately
drm/xe/rtp: Keep track of non-OA nonpriv slots drm/xe/rtp: Generalize whitelist_apply_to_hwe
drm/xe/rtp: Save OA nonpriv registers to register save/restore lists drm/xe/rtp: Toggle 'deny' bit to (de-)whitelist OA regs drm/xe/rtp: (De-)whitelist OA registers for all hwe's for a gt drm/xe/oa: (De-)whitelist OA registers on OA stream open/release drm/xe/rtp: Ensure locking/ref counting for OA whitelists
Lucas De Marchi (1):
drm/xe: Apply whitelist to engine save-restore
Michal Wajdeczko (1):
drm/xe: Introduce xe_gt_dbg_printer()
drivers/gpu/drm/xe/xe_gt.c | 4 +- drivers/gpu/drm/xe/xe_gt_debugfs.c | 4 +- drivers/gpu/drm/xe/xe_gt_printk.h | 31 +++++ drivers/gpu/drm/xe/xe_hw_engine.c | 3 +- drivers/gpu/drm/xe/xe_hw_engine_types.h | 8 ++ drivers/gpu/drm/xe/xe_oa.c | 7 ++ drivers/gpu/drm/xe/xe_oa_types.h | 3 + drivers/gpu/drm/xe/xe_reg_sr.c | 53 --------- drivers/gpu/drm/xe/xe_reg_whitelist.c | 147 +++++++++++++++++++++--- drivers/gpu/drm/xe/xe_reg_whitelist.h | 4 + 10 files changed, 189 insertions(+), 75 deletions(-)
Signature · 1 line
2.54.0
PATCH v2 1/12 drm/xe/rtp: Refactor OAG MMIO trigger register whitelisting
[ Upstream commit ed455775c5a68b75e5f6ad6c8e0e3e9c98fd3f64 ]
Minor refactor of OAG MMIO trigger register whitelisting for code reuse with OAM MMIO trigger register whitelisting.
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-)
drivers/gpu/drm/xe/xe_reg_whitelist.c +13 -16
@@ -64,27 +64,24 @@ static const struct xe_rtp_entry_sr register_whitelist[] = { ENGINE_CLASS(RENDER)), XE_RTP_ACTIONS(WHITELIST(CSBE_DEBUG_STATUS(RENDER_RING_BASE), 0)) }, - {XE_RTP_NAME ("oa_reg_render" ), + +#define WHITELIST_OA_MMIO_TRG (trg, status, head) \ + WHITELIST(trg, RING_FORCE_TO_NONPRIV_ACCESS_RW), \ + WHITELIST(status, RING_FORCE_TO_NONPRIV_ACCESS_RD), \ + WHITELIST(head, RING_FORCE_TO_NONPRIV_ACCESS_RD | RING_FORCE_TO_NONPRIV_RANGE_4) + +#define WHITELIST_OAG_MMIO_TRG \ + WHITELIST_OA_MMIO_TRG(OAG_MMIOTRIGGER, OAG_OASTATUS, OAG_OAHEADPTR) + + {XE_RTP_NAME ("oag_mmio_trg_rcs" ),XE_RTP_RULES (GRAPHICS_VERSION_RANGE (1200 ,XE_RTP_END_VERSION_UNDEFINED ),ENGINE_CLASS (RENDER )), -XE_RTP_ACTIONS (WHITELIST (OAG_MMIOTRIGGER , -RING_FORCE_TO_NONPRIV_ACCESS_RW ), -WHITELIST (OAG_OASTATUS , -RING_FORCE_TO_NONPRIV_ACCESS_RD ), -WHITELIST (OAG_OAHEADPTR , -RING_FORCE_TO_NONPRIV_ACCESS_RD | -RING_FORCE_TO_NONPRIV_RANGE_4 )) +XE_RTP_ACTIONS (WHITELIST_OAG_MMIO_TRG ) }, - { XE_RTP_NAME("oa_reg_compute"), + { XE_RTP_NAME("oag_mmio_trg_ccs"),XE_RTP_RULES (GRAPHICS_VERSION_RANGE (1200 ,XE_RTP_END_VERSION_UNDEFINED ),ENGINE_CLASS (COMPUTE )), -XE_RTP_ACTIONS (WHITELIST (OAG_MMIOTRIGGER , -RING_FORCE_TO_NONPRIV_ACCESS_RW ), -WHITELIST (OAG_OASTATUS , -RING_FORCE_TO_NONPRIV_ACCESS_RD ), -WHITELIST (OAG_OAHEADPTR , -RING_FORCE_TO_NONPRIV_ACCESS_RD | -RING_FORCE_TO_NONPRIV_RANGE_4 )) +XE_RTP_ACTIONS (WHITELIST_OAG_MMIO_TRG ) }, {} };
Signature · 1 line
2.54.0
PATCH v2 2/12 drm/xe: Introduce xe_gt_dbg_printer()
In reply to Ashutosh DixitFrom: Michal Wajdeczko <[email protected]>
[ Upstream commit 26582fc61a923e81832df8d5a169bbdab095d15e ]
We didn't have GT-oriented debug level printer as it was hard to correctly show actual callsite annotation. But this is now doable from commit c2ef66e9ad88 ("drm/print: Improve drm_dbg_printer").
--- drivers/gpu/drm/xe/xe_gt_printk.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/gpu/drm/xe/xe_gt_printk.h +31 -0
@@ -60,6 +60,21 @@ static inline void __xe_gt_printfn_info(struct drm_printer *p, struct va_formatxe_gt_info (gt,"%pV" , vaf); } +static inline void __xe_gt_printfn_dbg (struct drm_printer *p,struct va_format *vaf) +{ +struct xe_gt *gt = p->arg; +struct drm_printer dbg; + +/* +* The original xe_gt_dbg() callsite annotations are useless here, +* redirect to the tweaked drm_dbg_printer() instead. +*/ + dbg =drm_dbg_printer (>_to_xe (gt)->drm,DRM_UT_DRIVER ,NULL ); + dbg.origin = p->origin; + +drm_printf (&dbg,"GT%u: %pV" , gt->info.id, vaf); +} +/** * xe_gt_err_printer - Construct a &drm_printer that outputs to xe_gt_err() * @gt: the &xe_gt pointer to use in xe_gt_err()
@@ -90,4 +105,20 @@ static inline struct drm_printer xe_gt_info_printer(struct xe_gt *gt) return p; } +/** +* xe_gt_dbg_printer - Construct a &drm_printer that outputs like xe_gt_dbg() +* @gt: the &xe_gt pointer to use in xe_gt_dbg() +* +* Return: The &drm_printer object. +*/ +static inline struct drm_printer xe_gt_dbg_printer (struct xe_gt *gt) +{ +struct drm_printer p = { + .printfn = __xe_gt_printfn_dbg, + .arg = gt, + .origin = (const void *)_THIS_IP_, + }; +return p; +} +#endif
Signature · 1 line
2.54.0
PATCH v2 3/12 drm/xe: Apply whitelist to engine save-restore
In reply to Ashutosh DixitFrom: Lucas De Marchi <[email protected]>
[ Upstream commit 3fcf68d7393fd622b96cd45124ccb1eddf77684c ]
Changes in xe_guc_ads.c in the above commit are not needed for linux-6.12.y.
Instead of handling the whitelist directly in the GuC ADS initialization, make it follow the same logic as other engine registers that are save-restored. Main benefit is that then the SW tracking then shows it in debugfs and there's no risk of an engine workaround to write to the same nopriv register that is being passed directly to GuC.
This means that xe_reg_whitelist_process_engine() only has to process the RTP and convert them to entries for the hwe. With that all the registers should be covered by xe_reg_sr_apply_mmio() to write to the HW and there's no special handling in GuC ADS to also add these registers to the list of registers that is passed to GuC.
Example for DG2:
# cat /sys/kernel/debug/dri/0000\:03\:00.0/gt0/register-save-restore ... Engine rcs0 ... REG[0x24d0] clr=0xffffffff set=0x1000dafc masked=no mcr=no REG[0x24d4] clr=0xffffffff set=0x1000db01 masked=no mcr=no REG[0x24d8] clr=0xffffffff set=0x0000db1c masked=no mcr=no ... Whitelist rcs0 REG[0xdafc-0xdaff]: allow read access REG[0xdb00-0xdb1f]: allow read access REG[0xdb1c-0xdb1f]: allow rw access
v2:
- Use ~0u for clr bits so it's just a write (Matt Roper)
- Simplify helpers now that unused slots are not written
--- drivers/gpu/drm/xe/xe_gt.c | 4 +- drivers/gpu/drm/xe/xe_hw_engine.c | 1 - drivers/gpu/drm/xe/xe_reg_sr.c | 53 --------------------------- drivers/gpu/drm/xe/xe_reg_whitelist.c | 37 +++++++++++++++++++ 4 files changed, 38 insertions(+), 57 deletions(-)
drivers/gpu/drm/xe/xe_gt.c +1 -3
@@ -722,10 +722,8 @@ static int do_gt_restart(struct xe_gt *gt)xe_mocs_init (gt); -for_each_hw_engine (hwe, gt, id) { +for_each_hw_engine (hwe, gt, id)xe_reg_sr_apply_mmio (&hwe->reg_sr, gt); -xe_reg_sr_apply_whitelist (hwe); - }/* Get CCS mode in sync between sw/hw */ xe_gt_apply_ccs_mode (gt);
drivers/gpu/drm/xe/xe_hw_engine.c +0 -1
@@ -546,7 +546,6 @@ static int hw_engine_init(struct xe_gt *gt, struct xe_hw_engine *hwe,xe_gt_assert (gt, gt->info.engine_mask &BIT (id));xe_reg_sr_apply_mmio (&hwe->reg_sr, gt); -xe_reg_sr_apply_whitelist (hwe); hwe->hwsp = xe_managed_bo_create_pin_map(xe, tile, SZ_4K, XE_BO_FLAG_VRAM_IF_DGFX(tile) |
drivers/gpu/drm/xe/xe_reg_sr.c +0 -53
65 lines not on this page · raw message
drivers/gpu/drm/xe/xe_reg_whitelist.c +37 -0
@@ -10,7 +10,9 @@#include "regs/xe_oa_regs.h" #include "regs/xe_regs.h" #include "xe_gt_types.h" +#include "xe_gt_printk.h" #include "xe_platform_types.h" +#include "xe_reg_sr.h" #include "xe_rtp.h" #include "xe_step.h"
@@ -86,6 +88,40 @@ static const struct xe_rtp_entry_sr register_whitelist[] = { {} }; +static void whitelist_apply_to_hwe (struct xe_hw_engine *hwe) +{ +struct xe_reg_sr *sr = &hwe->reg_whitelist; +struct xe_reg_sr_entry *entry; +struct drm_printer p; +unsigned long reg; +unsigned int slot; + +xe_gt_dbg (hwe->gt,"Add %s whitelist to engine\n" , sr->name); + p =xe_gt_dbg_printer (hwe->gt); + + slot =0 ; +xa_for_each (&sr->xa, reg, entry) { +struct xe_reg_sr_entry hwe_entry = { + .reg =RING_FORCE_TO_NONPRIV (hwe->mmio_base, slot), + .set_bits = entry->reg.addr | entry->set_bits, + .clr_bits = ~0u , + .read_mask = entry->read_mask, + }; + +if (slot ==RING_MAX_NONPRIV_SLOTS ) { +xe_gt_err (hwe->gt, +"hwe %s: maximum register whitelist slots (%d) reached, refusing to add more\n" , + hwe->name,RING_MAX_NONPRIV_SLOTS ); +break ; + } + +xe_reg_whitelist_print_entry (&p,0 , reg, entry); +xe_reg_sr_add (&hwe->reg_sr, &hwe_entry, hwe->gt); + + slot++; + } +} +/** * xe_reg_whitelist_process_engine - process table of registers to whitelist * @hwe: engine instance to process whitelist for
@@ -99,6 +135,7 @@ void xe_reg_whitelist_process_engine(struct xe_hw_engine *hwe)struct xe_rtp_process_ctx ctx =XE_RTP_PROCESS_CTX_INITIALIZER (hwe);xe_rtp_process_to_sr (&ctx, register_whitelist, &hwe->reg_whitelist); +whitelist_apply_to_hwe (hwe); }/**
Signature · 1 line
2.54.0
PATCH v2 4/12 drm/xe/rtp: Add RING_FORCE_TO_NONPRIV_DENY to OA whitelists
In reply to Ashutosh Dixit[ Upstream commit e70086a3a06d276b4a5d9a2c51c9330c6cf72780 ]
Unconditionally whitelisting OA registers is a security violation. Set RING_FORCE_TO_NONPRIV_DENY bit in OA nonpriv slots, so that OA registers don't get whitelisted by default after probe, gt reset, resume and engine reset.
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_reg_whitelist.c +5 -3
@@ -67,10 +67,12 @@ static const struct xe_rtp_entry_sr register_whitelist[] = { XE_RTP_ACTIONS(WHITELIST(CSBE_DEBUG_STATUS(RENDER_RING_BASE), 0)) }, +#define WHITELIST_DENY (r, f) WHITELIST(r, (f) | RING_FORCE_TO_NONPRIV_DENY) +#define WHITELIST_OA_MMIO_TRG (trg, status, head) \ - WHITELIST(trg, RING_FORCE_TO_NONPRIV_ACCESS_RW), \ - WHITELIST(status, RING_FORCE_TO_NONPRIV_ACCESS_RD), \ - WHITELIST(head, RING_FORCE_TO_NONPRIV_ACCESS_RD | RING_FORCE_TO_NONPRIV_RANGE_4) + WHITELIST_DENY(trg, RING_FORCE_TO_NONPRIV_ACCESS_RW), \ + WHITELIST_DENY(status, RING_FORCE_TO_NONPRIV_ACCESS_RD), \ + WHITELIST_DENY(head, RING_FORCE_TO_NONPRIV_ACCESS_RD | RING_FORCE_TO_NONPRIV_RANGE_4)#define WHITELIST_OAG_MMIO_TRG \ WHITELIST_OA_MMIO_TRG(OAG_MMIOTRIGGER, OAG_OASTATUS, OAG_OAHEADPTR)
Signature · 1 line
2.54.0
PATCH v2 5/12 drm/xe/rtp: Maintain OA whitelists separately
In reply to Ashutosh Dixit[ Upstream commit 31e2437561621b4867c08efc890bf629d017df03 ]
Contains minor modification of the above commit because of changed API.
OA registers are dynamically whitelisted (and again dewhitelisted) on OA stream open/close. Maintaining OA whitelists separately from non-OA register whitlists simplifies this management of OA register whitelisting/dewhitelisting.
--- drivers/gpu/drm/xe/xe_gt_debugfs.c | 4 +++- drivers/gpu/drm/xe/xe_hw_engine.c | 2 ++ drivers/gpu/drm/xe/xe_hw_engine_types.h | 8 ++++++++ drivers/gpu/drm/xe/xe_reg_whitelist.c | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_gt_debugfs.c +3 -1
@@ -191,8 +191,10 @@ static int register_save_restore(struct xe_gt *gt, struct drm_printer *p)drm_printf (p,"\n" );drm_printf (p,"Whitelist\n" ); -for_each_hw_engine (hwe, gt, id) +for_each_hw_engine (hwe, gt, id) {xe_reg_whitelist_dump (&hwe->reg_whitelist, p); +xe_reg_whitelist_dump (&hwe->oa_whitelist, p); + }xe_pm_runtime_put (gt_to_xe (gt));
drivers/gpu/drm/xe/xe_hw_engine.c +2 -0
@@ -532,6 +532,8 @@ static void hw_engine_init_early(struct xe_gt *gt, struct xe_hw_engine *hwe,hw_engine_setup_default_state (hwe);xe_reg_sr_init (&hwe->reg_whitelist, hwe->name,gt_to_xe (gt)); +xe_reg_sr_init (&hwe->oa_whitelist, hwe->name,gt_to_xe (gt)); +xe_reg_sr_init (&hwe->oa_sr, hwe->name,gt_to_xe (gt));xe_reg_whitelist_process_engine (hwe); }
drivers/gpu/drm/xe/xe_hw_engine_types.h +8 -0
@@ -128,6 +128,14 @@ struct xe_hw_engine {* @reg_whitelist: table with registers to be whitelisted */ struct xe_reg_sr reg_whitelist; +/** +* @oa_whitelist: oa registers to be whitelisted +*/ +struct xe_reg_sr oa_whitelist; +/** +* @oa_sr: oa nonpriv whitelist registers, changed on oa stream open/close +*/ +struct xe_reg_sr oa_sr;/** * @reg_lrc: LRC workaround registers */
drivers/gpu/drm/xe/xe_reg_whitelist.c +6 -0
@@ -66,6 +66,10 @@ static const struct xe_rtp_entry_sr register_whitelist[] = { ENGINE_CLASS(RENDER)),XE_RTP_ACTIONS (WHITELIST (CSBE_DEBUG_STATUS (RENDER_RING_BASE ),0 )) }, + {} +}; + +static const struct xe_rtp_entry_sr oa_whitelist[] = { #define WHITELIST_DENY(r, f) WHITELIST(r, (f) | RING_FORCE_TO_NONPRIV_DENY)
@@ -138,6 +142,8 @@ void xe_reg_whitelist_process_engine(struct xe_hw_engine *hwe)xe_rtp_process_to_sr (&ctx, register_whitelist, &hwe->reg_whitelist);whitelist_apply_to_hwe (hwe); + +xe_rtp_process_to_sr (&ctx, oa_whitelist, &hwe->oa_whitelist); }/**
Signature · 1 line
2.54.0
PATCH v2 6/12 drm/xe/rtp: Keep track of non-OA nonpriv slots
In reply to Ashutosh Dixit[ Upstream commit 60d49ea28bb190a640bd8dc3f4c946e0811a948c ]
In order to dynamically whitelist/dewhitelist OA registers on OA stream open/close, we need to keep track of nonpriv slots occupied by non-OA register whitelists.
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_reg_whitelist.c +5 -2
@@ -94,7 +94,7 @@ static const struct xe_rtp_entry_sr oa_whitelist[] = { {} }; -static void whitelist_apply_to_hwe (struct xe_hw_engine *hwe) +static int whitelist_apply_to_hwe (struct xe_hw_engine *hwe) {struct xe_reg_sr *sr = &hwe->reg_whitelist;struct xe_reg_sr_entry *entry;
@@ -126,6 +126,8 @@ static void whitelist_apply_to_hwe(struct xe_hw_engine *hwe) slot++; } + +return slot; }/**
@@ -139,9 +141,10 @@ static void whitelist_apply_to_hwe(struct xe_hw_engine *hwe)void xe_reg_whitelist_process_engine (struct xe_hw_engine *hwe) {struct xe_rtp_process_ctx ctx =XE_RTP_PROCESS_CTX_INITIALIZER (hwe); +int first_oa_slot;xe_rtp_process_to_sr (&ctx, register_whitelist, &hwe->reg_whitelist); -whitelist_apply_to_hwe (hwe); + first_oa_slot =whitelist_apply_to_hwe (hwe);xe_rtp_process_to_sr (&ctx, oa_whitelist, &hwe->oa_whitelist); }
Signature · 1 line
2.54.0
PATCH v2 7/12 drm/xe/rtp: Generalize whitelist_apply_to_hwe
In reply to Ashutosh Dixit[ Upstream commit 4fe2844b0f0c7cdc45ca4c4c62ca56b7f26c514c ]
Generalize whitelist_apply_to_hwe to construct both non-OA and OA whitelist nonpriv registers.
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_reg_whitelist.c +6 -5
@@ -94,9 +94,10 @@ static const struct xe_rtp_entry_sr oa_whitelist[] = { {} }; -static int whitelist_apply_to_hwe (struct xe_hw_engine *hwe) +static int whitelist_apply_to_hwe (struct xe_hw_engine *hwe,struct xe_reg_sr *in, +struct xe_reg_sr *out,int first_slot) { -struct xe_reg_sr *sr = &hwe->reg_whitelist; +struct xe_reg_sr *sr = in;struct xe_reg_sr_entry *entry;struct drm_printer p;unsigned long reg;
@@ -105,7 +106,7 @@ static int whitelist_apply_to_hwe(struct xe_hw_engine *hwe)xe_gt_dbg (hwe->gt,"Add %s whitelist to engine\n" , sr->name); p =xe_gt_dbg_printer (hwe->gt); - slot =0 ; + slot = first_slot;xa_for_each (&sr->xa, reg, entry) {struct xe_reg_sr_entry hwe_entry = { .reg =RING_FORCE_TO_NONPRIV (hwe->mmio_base, slot),
@@ -122,7 +123,7 @@ static int whitelist_apply_to_hwe(struct xe_hw_engine *hwe) }xe_reg_whitelist_print_entry (&p,0 , reg, entry); -xe_reg_sr_add (&hwe->reg_sr, &hwe_entry, hwe->gt); +xe_reg_sr_add (out, &hwe_entry, hwe->gt); slot++; }
@@ -144,7 +145,7 @@ void xe_reg_whitelist_process_engine(struct xe_hw_engine *hwe)int first_oa_slot;xe_rtp_process_to_sr (&ctx, register_whitelist, &hwe->reg_whitelist); - first_oa_slot =whitelist_apply_to_hwe (hwe); + first_oa_slot =whitelist_apply_to_hwe (hwe, &hwe->reg_whitelist, &hwe->reg_sr,0 );xe_rtp_process_to_sr (&ctx, oa_whitelist, &hwe->oa_whitelist); }
Signature · 1 line
2.54.0
PATCH v2 8/12 drm/xe/rtp: Save OA nonpriv registers to register save/restore lists
In reply to Ashutosh Dixit[ Upstream commit a19a83721a28ccaddace846da70da5c53d7dd052 ]
Now we can save OA whitelisting nonpriv registers to register save/restore lists. OA nonpriv registers are saved to both hwe->oa_sr as well as hwe->reg_sr.
During probe, resume and gt-reset flows KMD will apply hwe->reg_sr, ensuring OA registers are de-whitelisted after these events. For engine-reset, hwe->reg_sr is registered with GuC and GuC will apply these registers, ensuring OA registers are de-whitelisted after engine resets.
hwe->oa_sr is used for whitelisting or de-whitelisting OA registers during OA operation, by toggling the 'deny' bit on oa stream open/close.
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/xe/xe_reg_whitelist.c +12 -0
@@ -148,6 +148,18 @@ void xe_reg_whitelist_process_engine(struct xe_hw_engine *hwe) first_oa_slot =whitelist_apply_to_hwe (hwe, &hwe->reg_whitelist, &hwe->reg_sr,0 );xe_rtp_process_to_sr (&ctx, oa_whitelist, &hwe->oa_whitelist); + +/* +* Save oa nonpriv registers to hwe->oa_sr, from which oa registers are whitelisted +* or de-whitelisted, by toggling the 'deny' bit on oa stream open/close +*/ +whitelist_apply_to_hwe (hwe, &hwe->oa_whitelist, &hwe->oa_sr, first_oa_slot); + +/* +* Also save oa nonpriv registers to hwe->reg_sr, to ensure oa registers are not +* whitelisted by default after probe, gt reset, resume and engine reset +*/ +whitelist_apply_to_hwe (hwe, &hwe->oa_whitelist, &hwe->reg_sr, first_oa_slot); }/**
Signature · 1 line
2.54.0
PATCH v2 9/12 drm/xe/rtp: Toggle 'deny' bit to (de-)whitelist OA regs
In reply to Ashutosh Dixit[ Upstream commit b422babd77fac2c96b92db484050e460899bddaf ]
Whitelist or de-whitelist OA registers by setting or resetting the 'deny' bit in OA nonpriv registers and writing new register values to HW.
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/xe/xe_reg_whitelist.c +15 -0
@@ -162,6 +162,21 @@ void xe_reg_whitelist_process_engine(struct xe_hw_engine *hwe)whitelist_apply_to_hwe (hwe, &hwe->oa_whitelist, &hwe->reg_sr, first_oa_slot); } +__maybe_unused static void __whitelist_oa_regs (struct xe_hw_engine *hwe,bool whitelist) +{ +struct xe_reg_sr_entry *entry; +unsigned long reg; + +xa_for_each (&hwe->oa_sr.xa, reg, entry) { +if (whitelist) + entry->set_bits &= ~RING_FORCE_TO_NONPRIV_DENY ; +else + entry->set_bits |=RING_FORCE_TO_NONPRIV_DENY ; + } + +xe_reg_sr_apply_mmio (&hwe->oa_sr, hwe->gt); +} +/** * xe_reg_whitelist_print_entry - print one whitelist entry * @p: DRM printer
Signature · 1 line
2.54.0
PATCH v2 10/12 drm/xe/rtp: (De-)whitelist OA registers for all hwe's for a gt
In reply to Ashutosh Dixit[ Upstream commit ebba7ce65252a4ab0e3794ff14854df2afca5c08 ]
Whitelist or de-whitelist OA registers for all hwe's on the gt on which the OA stream is opened. This simplifies the case where an oa unit has 0 attached hwe's (but which monitors OA events on the associated GT).
--- drivers/gpu/drm/xe/xe_reg_whitelist.c | 34 +++++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_reg_whitelist.h | 4 ++++ 2 files changed, 36 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_reg_whitelist.c +32 -2
@@ -9,7 +9,7 @@#include "regs/xe_gt_regs.h" #include "regs/xe_oa_regs.h" #include "regs/xe_regs.h" -#include "xe_gt_types.h" +#include "xe_gt.h" #include "xe_gt_printk.h" #include "xe_platform_types.h" #include "xe_reg_sr.h"
@@ -162,7 +162,7 @@ void xe_reg_whitelist_process_engine(struct xe_hw_engine *hwe)whitelist_apply_to_hwe (hwe, &hwe->oa_whitelist, &hwe->reg_sr, first_oa_slot); } -__maybe_unused static void __whitelist_oa_regs (struct xe_hw_engine *hwe,bool whitelist) +static void __whitelist_oa_regs (struct xe_hw_engine *hwe,bool whitelist) {struct xe_reg_sr_entry *entry;unsigned long reg;
@@ -177,6 +177,36 @@ __maybe_unused static void __whitelist_oa_regs(struct xe_hw_engine *hwe, bool whxe_reg_sr_apply_mmio (&hwe->oa_sr, hwe->gt); } +/** +* xe_reg_whitelist_oa_regs - whitelist oa registers for gt +* @gt: gt to whitelist oa registers for +* +* Whitelist OA registers by resetting RING_FORCE_TO_NONPRIV_DENY +*/ +void xe_reg_whitelist_oa_regs (struct xe_gt *gt) +{ +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; + +for_each_hw_engine (hwe, gt, id) +__whitelist_oa_regs (hwe, true); +} + +/** +* xe_reg_dewhitelist_oa_regs - dewhitelist oa registers for gt +* @gt: gt to dewhitelist oa registers for +* +* Dewhitelist OA registers by setting RING_FORCE_TO_NONPRIV_DENY +*/ +void xe_reg_dewhitelist_oa_regs (struct xe_gt *gt) +{ +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; + +for_each_hw_engine (hwe, gt, id) +__whitelist_oa_regs (hwe, false); +} +/** * xe_reg_whitelist_print_entry - print one whitelist entry * @p: DRM printer
drivers/gpu/drm/xe/xe_reg_whitelist.h +4 -0
@@ -9,12 +9,16 @@#include <linux/types.h> struct drm_printer ; +struct xe_gt ;struct xe_hw_engine ;struct xe_reg_sr ;struct xe_reg_sr_entry ;void xe_reg_whitelist_process_engine (struct xe_hw_engine *hwe); +void xe_reg_whitelist_oa_regs (struct xe_gt *gt); +void xe_reg_dewhitelist_oa_regs (struct xe_gt *gt); +void xe_reg_whitelist_print_entry (struct drm_printer *p,unsigned int indent,u32 reg,struct xe_reg_sr_entry *entry);
Signature · 1 line
2.54.0
PATCH v2 11/12 drm/xe/oa: (De-)whitelist OA registers on OA stream open/release
In reply to Ashutosh Dixit[ Upstream commit 63ddb3ad08ff4e89c108499dfec5e9be5ddc25c9 ]
Whitelist OA registers on stream open and de-whitelist on stream close/release. Whitelisting is only done when 'stream->sample' is true. 'stream->sample' is only true when (a) xe_observation_paranoid is set to false by system admin, or (b) the process is perfmon_capable(). This therefore enforces the OA register whitelisting security requirements.
--- drivers/gpu/drm/xe/xe_oa.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/xe/xe_oa.c +7 -0
@@ -34,6 +34,7 @@#include "xe_oa.h" #include "xe_observation.h" #include "xe_pm.h" +#include "xe_reg_whitelist.h" #include "xe_sched_job.h" #include "xe_sriov.h" #include "xe_sync.h"
@@ -836,6 +837,9 @@ static void xe_oa_stream_destroy(struct xe_oa_stream *stream)mutex_destroy (&stream->stream_lock); +if (stream->sample) +xe_reg_dewhitelist_oa_regs (stream->gt); +xe_oa_disable_metric_set (stream);xe_exec_queue_put (stream->k_exec_q);
@@ -1868,6 +1872,9 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa, goto err_disable; } +if (stream->sample) +xe_reg_whitelist_oa_regs (stream->gt); +/* Hold a reference on the drm device till stream_fd is released */ drm_dev_get (&stream->oa->xe->drm);
Signature · 1 line
2.54.0
PATCH v2 12/12 drm/xe/rtp: Ensure locking/ref counting for OA whitelists
In reply to Ashutosh Dixit[ Upstream commit ef78e2a22f72c892fd6663f0760abd208d49a3e2 ]
Since multiple OA streams might be open in parallel on a gt, ensure that proper locking is in place. Also ensure that OA registers are whitelisted when the first OA stream is open and de-whitelisted after the last OA stream is closed.
--- drivers/gpu/drm/xe/xe_oa_types.h | 3 +++ drivers/gpu/drm/xe/xe_reg_whitelist.c | 10 ++++++++++ 2 files changed, 13 insertions(+)
drivers/gpu/drm/xe/xe_oa_types.h +3 -0
@@ -120,6 +120,9 @@ struct xe_oa_gt {/** @oa_unit: array of oa_units */ struct xe_oa_unit *oa_unit; + +/** @whitelist_count: number of open streams for which oa registers are whitelisted */ +u32 whitelist_count; };/**
drivers/gpu/drm/xe/xe_reg_whitelist.c +10 -0
@@ -9,6 +9,7 @@#include "regs/xe_gt_regs.h" #include "regs/xe_oa_regs.h" #include "regs/xe_regs.h" +#include "xe_assert.h" #include "xe_gt.h" #include "xe_gt_printk.h" #include "xe_platform_types.h"
@@ -188,6 +189,10 @@ void xe_reg_whitelist_oa_regs(struct xe_gt *gt)struct xe_hw_engine *hwe;enum xe_hw_engine_id id; +lockdep_assert_held (>->oa.gt_lock); +if (gt->oa.whitelist_count++) +return ; +for_each_hw_engine (hwe, gt, id)__whitelist_oa_regs (hwe, true); }
@@ -203,6 +208,11 @@ void xe_reg_dewhitelist_oa_regs(struct xe_gt *gt)struct xe_hw_engine *hwe;enum xe_hw_engine_id id; +lockdep_assert_held (>->oa.gt_lock); +xe_assert (gt_to_xe (gt), gt->oa.whitelist_count); +if (--gt->oa.whitelist_count) +return ; +for_each_hw_engine (hwe, gt, id)__whitelist_oa_regs (hwe, false); }
Signature · 1 line
2.54.0
Quoted 5 lines · Ashutosh Dixit
Backport of the following series to Linux 6.12.y:
https://lore.kernel.org/intel-xe/[email protected]/
v2: Fix upstream commit sha's (Sasha Levin)
Queued the series for 6.12, thanks.
Signature · 2 lines
Thanks, Sasha