forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/misc/sgi-gru/grumain.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * SN Platform GRU Driver
34 *
45 * DRIVER TABLE MANAGER + GRU CONTEXT LOAD/UNLOAD
56 *
67 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218 */
229
2310 #include <linux/kernel.h>
....@@ -729,9 +716,10 @@
729716 * chiplet. Misassignment can occur if the process migrates to a different
730717 * blade or if the user changes the selected blade/chiplet.
731718 */
732
-void gru_check_context_placement(struct gru_thread_state *gts)
719
+int gru_check_context_placement(struct gru_thread_state *gts)
733720 {
734721 struct gru_state *gru;
722
+ int ret = 0;
735723
736724 /*
737725 * If the current task is the context owner, verify that the
....@@ -739,15 +727,23 @@
739727 * references. Pthread apps use non-owner references to the CBRs.
740728 */
741729 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
+ */
742736 if (!gru || gts->ts_tgid_owner != current->tgid)
743
- return;
737
+ return ret;
744738
745739 if (!gru_check_chiplet_assignment(gru, gts)) {
746740 STAT(check_context_unload);
747
- gru_unload_context(gts, 1);
741
+ ret = -EINVAL;
748742 } else if (gru_retarget_intr(gts)) {
749743 STAT(check_context_retarget_intr);
750744 }
745
+
746
+ return ret;
751747 }
752748
753749
....@@ -947,7 +943,12 @@
947943 mutex_lock(&gts->ts_ctxlock);
948944 preempt_disable();
949945
950
- 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
+ }
951952
952953 if (!gts->ts_gru) {
953954 STAT(load_user_context);