Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe/guc: Ratelimit diagnostic messages from the relay

There might be some malicious VFs that by sending an invalid VF2PF
relay messages will flood PF's dmesg with our diagnostics messages.

Rate limit all relay messages, unless running in DEBUG_SRIOV mode.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Link: https://lore.kernel.org/r/20251005173946.2784-1-michal.wajdeczko@intel.com

+19 -2
+15 -2
drivers/gpu/drm/xe/xe_guc_relay.c
··· 56 56 return gt_to_xe(relay_to_gt(relay)); 57 57 } 58 58 59 + #define XE_RELAY_DIAG_RATELIMIT_INTERVAL (10 * HZ) 60 + #define XE_RELAY_DIAG_RATELIMIT_BURST 10 61 + 62 + #define relay_ratelimit_printk(relay, _level, fmt...) ({ \ 63 + typeof(relay) _r = (relay); \ 64 + if (IS_ENABLED(CONFIG_DRM_XE_DEBUG_SRIOV) || \ 65 + ___ratelimit(&_r->diag_ratelimit, "xe_guc_relay")) \ 66 + xe_gt_sriov_##_level(relay_to_gt(_r), "relay: " fmt); \ 67 + }) 68 + 59 69 #define relay_assert(relay, condition) xe_gt_assert(relay_to_gt(relay), condition) 60 - #define relay_notice(relay, msg...) xe_gt_sriov_notice(relay_to_gt(relay), "relay: " msg) 61 - #define relay_debug(relay, msg...) xe_gt_sriov_dbg_verbose(relay_to_gt(relay), "relay: " msg) 70 + #define relay_notice(relay, msg...) relay_ratelimit_printk((relay), notice, msg) 71 + #define relay_debug(relay, msg...) relay_ratelimit_printk((relay), dbg_verbose, msg) 62 72 63 73 static int relay_get_totalvfs(struct xe_guc_relay *relay) 64 74 { ··· 355 345 INIT_WORK(&relay->worker, relays_worker_fn); 356 346 INIT_LIST_HEAD(&relay->pending_relays); 357 347 INIT_LIST_HEAD(&relay->incoming_actions); 348 + ratelimit_state_init(&relay->diag_ratelimit, 349 + XE_RELAY_DIAG_RATELIMIT_INTERVAL, 350 + XE_RELAY_DIAG_RATELIMIT_BURST); 358 351 359 352 err = mempool_init_kmalloc_pool(&relay->pool, XE_RELAY_MEMPOOL_MIN_NUM + 360 353 relay_get_totalvfs(relay),
+4
drivers/gpu/drm/xe/xe_guc_relay_types.h
··· 7 7 #define _XE_GUC_RELAY_TYPES_H_ 8 8 9 9 #include <linux/mempool.h> 10 + #include <linux/ratelimit_types.h> 10 11 #include <linux/spinlock.h> 11 12 #include <linux/workqueue.h> 12 13 ··· 32 31 33 32 /** @last_rid: last Relay-ID used while sending a message. */ 34 33 u32 last_rid; 34 + 35 + /** @diag_ratelimit: ratelimit state used to throttle diagnostics messages. */ 36 + struct ratelimit_state diag_ratelimit; 35 37 }; 36 38 37 39 #endif