| .. | .. |
|---|
| 716 | 716 | * chiplet. Misassignment can occur if the process migrates to a different |
|---|
| 717 | 717 | * blade or if the user changes the selected blade/chiplet. |
|---|
| 718 | 718 | */ |
|---|
| 719 | | -void gru_check_context_placement(struct gru_thread_state *gts) |
|---|
| 719 | +int gru_check_context_placement(struct gru_thread_state *gts) |
|---|
| 720 | 720 | { |
|---|
| 721 | 721 | struct gru_state *gru; |
|---|
| 722 | + int ret = 0; |
|---|
| 722 | 723 | |
|---|
| 723 | 724 | /* |
|---|
| 724 | 725 | * If the current task is the context owner, verify that the |
|---|
| .. | .. |
|---|
| 726 | 727 | * references. Pthread apps use non-owner references to the CBRs. |
|---|
| 727 | 728 | */ |
|---|
| 728 | 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 | + */ |
|---|
| 729 | 736 | if (!gru || gts->ts_tgid_owner != current->tgid) |
|---|
| 730 | | - return; |
|---|
| 737 | + return ret; |
|---|
| 731 | 738 | |
|---|
| 732 | 739 | if (!gru_check_chiplet_assignment(gru, gts)) { |
|---|
| 733 | 740 | STAT(check_context_unload); |
|---|
| 734 | | - gru_unload_context(gts, 1); |
|---|
| 741 | + ret = -EINVAL; |
|---|
| 735 | 742 | } else if (gru_retarget_intr(gts)) { |
|---|
| 736 | 743 | STAT(check_context_retarget_intr); |
|---|
| 737 | 744 | } |
|---|
| 745 | + |
|---|
| 746 | + return ret; |
|---|
| 738 | 747 | } |
|---|
| 739 | 748 | |
|---|
| 740 | 749 | |
|---|
| .. | .. |
|---|
| 934 | 943 | mutex_lock(>s->ts_ctxlock); |
|---|
| 935 | 944 | preempt_disable(); |
|---|
| 936 | 945 | |
|---|
| 937 | | - 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 | + } |
|---|
| 938 | 952 | |
|---|
| 939 | 953 | if (!gts->ts_gru) { |
|---|
| 940 | 954 | STAT(load_user_context); |
|---|