| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * SN Platform GRU Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * DRIVER TABLE MANAGER + GRU CONTEXT LOAD/UNLOAD |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * 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 |
|---|
| 21 | 8 | */ |
|---|
| 22 | 9 | |
|---|
| 23 | 10 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 729 | 716 | * chiplet. Misassignment can occur if the process migrates to a different |
|---|
| 730 | 717 | * blade or if the user changes the selected blade/chiplet. |
|---|
| 731 | 718 | */ |
|---|
| 732 | | -void gru_check_context_placement(struct gru_thread_state *gts) |
|---|
| 719 | +int gru_check_context_placement(struct gru_thread_state *gts) |
|---|
| 733 | 720 | { |
|---|
| 734 | 721 | struct gru_state *gru; |
|---|
| 722 | + int ret = 0; |
|---|
| 735 | 723 | |
|---|
| 736 | 724 | /* |
|---|
| 737 | 725 | * If the current task is the context owner, verify that the |
|---|
| .. | .. |
|---|
| 739 | 727 | * references. Pthread apps use non-owner references to the CBRs. |
|---|
| 740 | 728 | */ |
|---|
| 741 | 729 | 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 | + */ |
|---|
| 742 | 736 | if (!gru || gts->ts_tgid_owner != current->tgid) |
|---|
| 743 | | - return; |
|---|
| 737 | + return ret; |
|---|
| 744 | 738 | |
|---|
| 745 | 739 | if (!gru_check_chiplet_assignment(gru, gts)) { |
|---|
| 746 | 740 | STAT(check_context_unload); |
|---|
| 747 | | - gru_unload_context(gts, 1); |
|---|
| 741 | + ret = -EINVAL; |
|---|
| 748 | 742 | } else if (gru_retarget_intr(gts)) { |
|---|
| 749 | 743 | STAT(check_context_retarget_intr); |
|---|
| 750 | 744 | } |
|---|
| 745 | + |
|---|
| 746 | + return ret; |
|---|
| 751 | 747 | } |
|---|
| 752 | 748 | |
|---|
| 753 | 749 | |
|---|
| .. | .. |
|---|
| 947 | 943 | mutex_lock(>s->ts_ctxlock); |
|---|
| 948 | 944 | preempt_disable(); |
|---|
| 949 | 945 | |
|---|
| 950 | | - gru_check_context_placement(gts); |
|---|
| 946 | + if (gru_check_context_placement(gts)) { |
|---|
| 947 | + preempt_enable(); |
|---|
| 948 | + mutex_unlock(>s->ts_ctxlock); |
|---|
| 949 | + gru_unload_context(gts, 1); |
|---|
| 950 | + return VM_FAULT_NOPAGE; |
|---|
| 951 | + } |
|---|
| 951 | 952 | |
|---|
| 952 | 953 | if (!gts->ts_gru) { |
|---|
| 953 | 954 | STAT(load_user_context); |
|---|