hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/misc/sgi-gru/grumain.c
....@@ -716,9 +716,10 @@
716716 * chiplet. Misassignment can occur if the process migrates to a different
717717 * blade or if the user changes the selected blade/chiplet.
718718 */
719
-void gru_check_context_placement(struct gru_thread_state *gts)
719
+int gru_check_context_placement(struct gru_thread_state *gts)
720720 {
721721 struct gru_state *gru;
722
+ int ret = 0;
722723
723724 /*
724725 * If the current task is the context owner, verify that the
....@@ -726,15 +727,23 @@
726727 * references. Pthread apps use non-owner references to the CBRs.
727728 */
728729 gru = gts->ts_gru;
730
+ /*
731
+ * If gru or gts->ts_tgid_owner isn't initialized properly, return
732
+ * success to indicate that the caller does not need to unload the
733
+ * gru context.The caller is responsible for their inspection and
734
+ * reinitialization if needed.
735
+ */
729736 if (!gru || gts->ts_tgid_owner != current->tgid)
730
- return;
737
+ return ret;
731738
732739 if (!gru_check_chiplet_assignment(gru, gts)) {
733740 STAT(check_context_unload);
734
- gru_unload_context(gts, 1);
741
+ ret = -EINVAL;
735742 } else if (gru_retarget_intr(gts)) {
736743 STAT(check_context_retarget_intr);
737744 }
745
+
746
+ return ret;
738747 }
739748
740749
....@@ -934,7 +943,12 @@
934943 mutex_lock(&gts->ts_ctxlock);
935944 preempt_disable();
936945
937
- gru_check_context_placement(gts);
946
+ if (gru_check_context_placement(gts)) {
947
+ preempt_enable();
948
+ mutex_unlock(&gts->ts_ctxlock);
949
+ gru_unload_context(gts, 1);
950
+ return VM_FAULT_NOPAGE;
951
+ }
938952
939953 if (!gts->ts_gru) {
940954 STAT(load_user_context);