@@ -690,6 +690,15 @@ static int do_switch_rcs(struct intel_engine_cs *ring,
*/
from = ring->last_context;
+ /* The only context which 'from' can be, if it was changed, is the default
+ * context. The default context cannot end up in evict everything (as
+ * commented above) because it is always pinned.
+ */
+ if (WARN_ON(from == to)) {
+ ret = -EPERM;
+ goto unpin_out;
+ }
+
if (needs_pd_load) {
/* Older GENs still want the load first, "PP_DCLV followed by
* PP_DIR_BASE register through Load Register Immediate commands