^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * SN Platform GRU Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * FAULT HANDLER FOR GRU DETECTED TLB MISSES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This file contains code that handles TLB misses within the GRU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * These misses are reported either via interrupts or user polling of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * the user CB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/hugetlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/sync_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "gru.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "grutables.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "grulib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "gru_instructions.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/uv/uv_hub.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Return codes for vtop functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define VTOP_SUCCESS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define VTOP_INVALID -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define VTOP_RETRY -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Test if a physical address is a valid GRU GSEG address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static inline int is_gru_paddr(unsigned long paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return paddr >= gru_start_paddr && paddr < gru_end_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Find the vma of a GRU segment. Caller must hold mmap_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct vm_area_struct *gru_find_vma(unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) vma = find_vma(current->mm, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (vma && vma->vm_start <= vaddr && vma->vm_ops == &gru_vm_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Find and lock the gts that contains the specified user vaddr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * - *gts with the mmap_lock locked for read and the GTS locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * - NULL if vaddr invalid OR is not a valid GSEG vaddr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static struct gru_thread_state *gru_find_lock_gts(unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct gru_thread_state *gts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) mmap_read_lock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) vma = gru_find_vma(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) gts = gru_find_thread_state(vma, TSID(vaddr, vma));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) mutex_lock(>s->ts_ctxlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static struct gru_thread_state *gru_alloc_locked_gts(unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct gru_thread_state *gts = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) mmap_write_lock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) vma = gru_find_vma(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (!vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) gts = gru_alloc_thread_state(vma, TSID(vaddr, vma));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (IS_ERR(gts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) mutex_lock(>s->ts_ctxlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) mmap_write_downgrade(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) mmap_write_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * Unlock a GTS that was previously locked with gru_find_lock_gts().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static void gru_unlock_gts(struct gru_thread_state *gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) mutex_unlock(>s->ts_ctxlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mmap_read_unlock(current->mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Set a CB.istatus to active using a user virtual address. This must be done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * just prior to a TFH RESTART. The new cb.istatus is an in-cache status ONLY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * If the line is evicted, the status may be lost. The in-cache update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * is necessary to prevent the user from seeing a stale cb.istatus that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * change as soon as the TFH restart is complete. Races may cause an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * occasional failure to clear the cb.istatus, but that is ok.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void gru_cb_set_istatus_active(struct gru_instruction_bits *cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (cbk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) cbk->istatus = CBS_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Read & clear a TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * The GRU has an array of fault maps. A map is private to a cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Only one cpu will be accessing a cpu's fault map.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * This function scans the cpu-private fault map & clears all bits that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * are set. The function returns a bitmap that indicates the bits that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * were cleared. Note that sense the maps may be updated asynchronously by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * the GRU, atomic operations must be used to clear bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void get_clear_fault_map(struct gru_state *gru,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct gru_tlb_fault_map *imap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct gru_tlb_fault_map *dmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned long i, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct gru_tlb_fault_map *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) tfm = get_tfm_for_cpu(gru, gru_cpu_fault_map_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) prefetchw(tfm); /* Helps on hardware, required for emulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) for (i = 0; i < BITS_TO_LONGS(GRU_NUM_CBE); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) k = tfm->fault_bits[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) k = xchg(&tfm->fault_bits[i], 0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) imap->fault_bits[i] = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) k = tfm->done_bits[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) k = xchg(&tfm->done_bits[i], 0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) dmap->fault_bits[i] = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * Not functionally required but helps performance. (Required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * on emulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) gru_flush_cache(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * Atomic (interrupt context) & non-atomic (user context) functions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * convert a vaddr into a physical address. The size of the page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * is returned in pageshift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * 0 - successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * < 0 - error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * 1 - (atomic only) try again in non-atomic context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int non_atomic_pte_lookup(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned long vaddr, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned long *paddr, int *pageshift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #ifdef CONFIG_HUGETLB_PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *pageshift = is_vm_hugetlb_page(vma) ? HPAGE_SHIFT : PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *pageshift = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page, NULL) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) *paddr = page_to_phys(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * atomic_pte_lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * Convert a user virtual address to a physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * Only supports Intel large pages (2MB only) on x86_64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * ZZZ - hugepage support is incomplete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * NOTE: mmap_lock is already held on entry to this function. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * guarantees existence of the page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int write, unsigned long *paddr, int *pageshift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pgd_t *pgdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) p4d_t *p4dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pud_t *pudp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) pmd_t *pmdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pte_t pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pgdp = pgd_offset(vma->vm_mm, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (unlikely(pgd_none(*pgdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) p4dp = p4d_offset(pgdp, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (unlikely(p4d_none(*p4dp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) pudp = pud_offset(p4dp, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (unlikely(pud_none(*pudp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pmdp = pmd_offset(pudp, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (unlikely(pmd_none(*pmdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (unlikely(pmd_large(*pmdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) pte = *(pte_t *) pmdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) pte = *pte_offset_kernel(pmdp, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (unlikely(!pte_present(pte) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) (write && (!pte_write(pte) || !pte_dirty(pte)))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) *paddr = pte_pfn(pte) << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #ifdef CONFIG_HUGETLB_PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) *pageshift = is_vm_hugetlb_page(vma) ? HPAGE_SHIFT : PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) *pageshift = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int gru_vtop(struct gru_thread_state *gts, unsigned long vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int write, int atomic, unsigned long *gpa, int *pageshift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct mm_struct *mm = gts->ts_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) unsigned long paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int ret, ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) vma = find_vma(mm, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) goto inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * Atomic lookup is faster & usually works even if called in non-atomic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) rmb(); /* Must/check ms_range_active before loading PTEs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = atomic_pte_lookup(vma, vaddr, write, &paddr, &ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (atomic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto upm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (non_atomic_pte_lookup(vma, vaddr, write, &paddr, &ps))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) goto inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (is_gru_paddr(paddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) paddr = paddr & ~((1UL << ps) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) *gpa = uv_soc_phys_ram_to_gpa(paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *pageshift = ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return VTOP_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) inval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return VTOP_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) upm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return VTOP_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Flush a CBE from cache. The CBE is clean in the cache. Dirty the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * CBE cacheline so that the line will be written back to home agent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * Otherwise the line may be silently dropped. This has no impact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * except on performance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void gru_flush_cache_cbe(struct gru_control_block_extended *cbe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (unlikely(cbe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) cbe->cbrexecstatus = 0; /* make CL dirty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) gru_flush_cache(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Preload the TLB with entries that may be required. Currently, preloading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * is implemented only for BCOPY. Preload <tlb_preload_count> pages OR to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * the end of the bcopy tranfer, whichever is smaller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static void gru_preload_tlb(struct gru_state *gru,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct gru_thread_state *gts, int atomic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) unsigned long fault_vaddr, int asid, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) unsigned char tlb_preload_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct gru_tlb_fault_handle *tfh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct gru_control_block_extended *cbe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) unsigned long vaddr = 0, gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int ret, pageshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (cbe->opccpy != OP_BCOPY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (fault_vaddr == cbe->cbe_baddr0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) vaddr = fault_vaddr + GRU_CACHE_LINE_BYTES * cbe->cbe_src_cl - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) else if (fault_vaddr == cbe->cbe_baddr1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) vaddr = fault_vaddr + (1 << cbe->xtypecpy) * cbe->cbe_nelemcur - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) fault_vaddr &= PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) vaddr &= PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) vaddr = min(vaddr, fault_vaddr + tlb_preload_count * PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) while (vaddr > fault_vaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) ret = gru_vtop(gts, vaddr, write, atomic, &gpa, &pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (ret || tfh_write_only(tfh, gpa, GAA_RAM, vaddr, asid, write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) GRU_PAGESIZE(pageshift)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) gru_dbg(grudev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) "%s: gid %d, gts 0x%p, tfh 0x%p, vaddr 0x%lx, asid 0x%x, rw %d, ps %d, gpa 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) atomic ? "atomic" : "non-atomic", gru->gs_gid, gts, tfh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) vaddr, asid, write, pageshift, gpa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) vaddr -= PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) STAT(tlb_preload_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * Drop a TLB entry into the GRU. The fault is described by info in an TFH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * cb Address of user CBR. Null if not running in user context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * 0 = dropin, exception, or switch to UPM successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * 1 = range invalidate active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * < 0 = error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static int gru_try_dropin(struct gru_state *gru,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct gru_thread_state *gts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct gru_tlb_fault_handle *tfh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct gru_instruction_bits *cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct gru_control_block_extended *cbe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) unsigned char tlb_preload_count = gts->ts_tlb_preload_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) int pageshift = 0, asid, write, ret, atomic = !cbk, indexway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) unsigned long gpa = 0, vaddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * NOTE: The GRU contains magic hardware that eliminates races between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * TLB invalidates and TLB dropins. If an invalidate occurs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * in the window between reading the TFH and the subsequent TLB dropin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * the dropin is ignored. This eliminates the need for additional locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * Prefetch the CBE if doing TLB preloading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (unlikely(tlb_preload_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) cbe = gru_tfh_to_cbe(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) prefetchw(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * Error if TFH state is IDLE or FMM mode & the user issuing a UPM call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * Might be a hardware race OR a stupid user. Ignore FMM because FMM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * is a transient state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (tfh->status != TFHSTATUS_EXCEPTION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) gru_flush_cache(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) sync_core();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (tfh->status != TFHSTATUS_EXCEPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) goto failnoexception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) STAT(tfh_stale_on_fault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (tfh->state == TFHSTATE_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) goto failidle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (tfh->state == TFHSTATE_MISS_FMM && cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) goto failfmm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) write = (tfh->cause & TFHCAUSE_TLB_MOD) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) vaddr = tfh->missvaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) asid = tfh->missasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) indexway = tfh->indexway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (asid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) goto failnoasid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) rmb(); /* TFH must be cache resident before reading ms_range_active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * TFH is cache resident - at least briefly. Fail the dropin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * if a range invalidate is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (atomic_read(>s->ts_gms->ms_range_active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) goto failactive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ret = gru_vtop(gts, vaddr, write, atomic, &gpa, &pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (ret == VTOP_INVALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) goto failinval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (ret == VTOP_RETRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) goto failupm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (!(gts->ts_sizeavail & GRU_SIZEAVAIL(pageshift))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) gts->ts_sizeavail |= GRU_SIZEAVAIL(pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (atomic || !gru_update_cch(gts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) gts->ts_force_cch_reload = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) goto failupm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (unlikely(cbe) && pageshift == PAGE_SHIFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) gru_preload_tlb(gru, gts, atomic, vaddr, asid, write, tlb_preload_count, tfh, cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) gru_cb_set_istatus_active(cbk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) gts->ustats.tlbdropin++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) tfh_write_restart(tfh, gpa, GAA_RAM, vaddr, asid, write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) GRU_PAGESIZE(pageshift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) gru_dbg(grudev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) "%s: gid %d, gts 0x%p, tfh 0x%p, vaddr 0x%lx, asid 0x%x, indexway 0x%x,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) " rw %d, ps %d, gpa 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) atomic ? "atomic" : "non-atomic", gru->gs_gid, gts, tfh, vaddr, asid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) indexway, write, pageshift, gpa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) STAT(tlb_dropin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) failnoasid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /* No asid (delayed unload). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) STAT(tlb_dropin_fail_no_asid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) gru_dbg(grudev, "FAILED no_asid tfh: 0x%p, vaddr 0x%lx\n", tfh, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (!cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) tfh_user_polling_mode(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) gru_flush_cache(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) failupm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /* Atomic failure switch CBR to UPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) tfh_user_polling_mode(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) STAT(tlb_dropin_fail_upm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) gru_dbg(grudev, "FAILED upm tfh: 0x%p, vaddr 0x%lx\n", tfh, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) failfmm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* FMM state on UPM call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) gru_flush_cache(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) STAT(tlb_dropin_fail_fmm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) gru_dbg(grudev, "FAILED fmm tfh: 0x%p, state %d\n", tfh, tfh->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) failnoexception:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* TFH status did not show exception pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) gru_flush_cache(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) gru_flush_cache(cbk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) STAT(tlb_dropin_fail_no_exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) gru_dbg(grudev, "FAILED non-exception tfh: 0x%p, status %d, state %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) tfh, tfh->status, tfh->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) failidle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* TFH state was idle - no miss pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) gru_flush_cache(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) gru_flush_cache(cbk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) STAT(tlb_dropin_fail_idle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) gru_dbg(grudev, "FAILED idle tfh: 0x%p, state %d\n", tfh, tfh->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) failinval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* All errors (atomic & non-atomic) switch CBR to EXCEPTION state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) tfh_exception(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) STAT(tlb_dropin_fail_invalid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) gru_dbg(grudev, "FAILED inval tfh: 0x%p, vaddr 0x%lx\n", tfh, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) failactive:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* Range invalidate active. Switch to UPM iff atomic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (!cbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) tfh_user_polling_mode(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) gru_flush_cache(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) STAT(tlb_dropin_fail_range_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) gru_dbg(grudev, "FAILED range active: tfh 0x%p, vaddr 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) tfh, vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * Process an external interrupt from the GRU. This interrupt is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * caused by a TLB miss.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * Note that this is the interrupt handler that is registered with linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * interrupt handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static irqreturn_t gru_intr(int chiplet, int blade)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct gru_state *gru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct gru_tlb_fault_map imap, dmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct gru_tlb_fault_handle *tfh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct completion *cmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int cbrnum, ctxnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) STAT(intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) gru = &gru_base[blade]->bs_grus[chiplet];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!gru) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) dev_err(grudev, "GRU: invalid interrupt: cpu %d, chiplet %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) raw_smp_processor_id(), chiplet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) get_clear_fault_map(gru, &imap, &dmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) gru_dbg(grudev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) "cpu %d, chiplet %d, gid %d, imap %016lx %016lx, dmap %016lx %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) smp_processor_id(), chiplet, gru->gs_gid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) imap.fault_bits[0], imap.fault_bits[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) dmap.fault_bits[0], dmap.fault_bits[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) for_each_cbr_in_tfm(cbrnum, dmap.fault_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) STAT(intr_cbr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) cmp = gru->gs_blade->bs_async_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (cmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) complete(cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) gru_dbg(grudev, "gid %d, cbr_done %d, done %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) gru->gs_gid, cbrnum, cmp ? cmp->done : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) for_each_cbr_in_tfm(cbrnum, imap.fault_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) STAT(intr_tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) tfh = get_tfh_by_index(gru, cbrnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) prefetchw(tfh); /* Helps on hdw, required for emulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * When hardware sets a bit in the faultmap, it implicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * locks the GRU context so that it cannot be unloaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * The gts cannot change until a TFH start/writestart command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * is issued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) ctxnum = tfh->ctxnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) gts = gru->gs_gts[ctxnum];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* Spurious interrupts can cause this. Ignore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (!gts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) STAT(intr_spurious);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * This is running in interrupt context. Trylock the mmap_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * If it fails, retry the fault in user context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) gts->ustats.fmm_tlbmiss++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (!gts->ts_force_cch_reload &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) mmap_read_trylock(gts->ts_mm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) gru_try_dropin(gru, gts, tfh, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) mmap_read_unlock(gts->ts_mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) tfh_user_polling_mode(tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) STAT(intr_mm_lock_failed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) irqreturn_t gru0_intr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) return gru_intr(0, uv_numa_blade_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) irqreturn_t gru1_intr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return gru_intr(1, uv_numa_blade_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) irqreturn_t gru_intr_mblade(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) int blade;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) for_each_possible_blade(blade) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (uv_blade_nr_possible_cpus(blade))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) gru_intr(0, blade);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) gru_intr(1, blade);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static int gru_user_dropin(struct gru_thread_state *gts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) struct gru_tlb_fault_handle *tfh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) void *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct gru_mm_struct *gms = gts->ts_gms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) gts->ustats.upm_tlbmiss++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) wait_event(gms->ms_wait_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) atomic_read(&gms->ms_range_active) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) prefetchw(tfh); /* Helps on hdw, required for emulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) ret = gru_try_dropin(gts->ts_gru, gts, tfh, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) STAT(call_os_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * This interface is called as a result of a user detecting a "call OS" bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * in a user CB. Normally means that a TLB fault has occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * cb - user virtual address of the CB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int gru_handle_user_call_os(unsigned long cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct gru_tlb_fault_handle *tfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) void *cbk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) int ucbnum, cbrnum, ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) STAT(call_os);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* sanity check the cb pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) ucbnum = get_cb_number((void *)cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if ((cb & (GRU_HANDLE_STRIDE - 1)) || ucbnum >= GRU_NUM_CB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) gts = gru_find_lock_gts(cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (!gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) gru_dbg(grudev, "address 0x%lx, gid %d, gts 0x%p\n", cb, gts->ts_gru ? gts->ts_gru->gs_gid : -1, gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (ucbnum >= gts->ts_cbr_au_count * GRU_CBR_AU_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) gru_check_context_placement(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * CCH may contain stale data if ts_force_cch_reload is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (gts->ts_gru && gts->ts_force_cch_reload) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) gts->ts_force_cch_reload = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) gru_update_cch(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) cbrnum = thread_cbr_number(gts, ucbnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (gts->ts_gru) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) tfh = get_tfh_by_index(gts->ts_gru, cbrnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) cbk = get_gseg_base_address_cb(gts->ts_gru->gs_gru_base_vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) gts->ts_ctxnum, ucbnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ret = gru_user_dropin(gts, tfh, cbk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) gru_unlock_gts(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * Fetch the exception detail information for a CB that terminated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) * an exception.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) int gru_get_exception_detail(unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) struct control_block_extended_exc_detail excdet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) struct gru_control_block_extended *cbe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int ucbnum, cbrnum, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) STAT(user_exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (copy_from_user(&excdet, (void __user *)arg, sizeof(excdet)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) gts = gru_find_lock_gts(excdet.cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (!gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) gru_dbg(grudev, "address 0x%lx, gid %d, gts 0x%p\n", excdet.cb, gts->ts_gru ? gts->ts_gru->gs_gid : -1, gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) ucbnum = get_cb_number((void *)excdet.cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (ucbnum >= gts->ts_cbr_au_count * GRU_CBR_AU_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) } else if (gts->ts_gru) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) cbrnum = thread_cbr_number(gts, ucbnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) cbe = get_cbe_by_index(gts->ts_gru, cbrnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) gru_flush_cache(cbe); /* CBE not coherent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) sync_core(); /* make sure we are have current data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) excdet.opc = cbe->opccpy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) excdet.exopc = cbe->exopccpy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) excdet.ecause = cbe->ecause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) excdet.exceptdet0 = cbe->idef1upd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) excdet.exceptdet1 = cbe->idef3upd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) excdet.cbrstate = cbe->cbrstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) excdet.cbrexecstatus = cbe->cbrexecstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) gru_flush_cache_cbe(cbe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) gru_unlock_gts(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) gru_dbg(grudev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) "cb 0x%lx, op %d, exopc %d, cbrstate %d, cbrexecstatus 0x%x, ecause 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) "exdet0 0x%lx, exdet1 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) excdet.cb, excdet.opc, excdet.exopc, excdet.cbrstate, excdet.cbrexecstatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) excdet.ecause, excdet.exceptdet0, excdet.exceptdet1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (!ret && copy_to_user((void __user *)arg, &excdet, sizeof(excdet)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * User request to unload a context. Content is saved for possible reload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static int gru_unload_all_contexts(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct gru_state *gru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) int gid, ctxnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) foreach_gid(gid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) gru = GID_TO_GRU(gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) spin_lock(&gru->gs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) for (ctxnum = 0; ctxnum < GRU_NUM_CCH; ctxnum++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) gts = gru->gs_gts[ctxnum];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (gts && mutex_trylock(>s->ts_ctxlock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) spin_unlock(&gru->gs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) gru_unload_context(gts, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) mutex_unlock(>s->ts_ctxlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) spin_lock(&gru->gs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) spin_unlock(&gru->gs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) int gru_user_unload_context(unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct gru_unload_context_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) STAT(user_unload_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (copy_from_user(&req, (void __user *)arg, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) gru_dbg(grudev, "gseg 0x%lx\n", req.gseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (!req.gseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return gru_unload_all_contexts();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) gts = gru_find_lock_gts(req.gseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (!gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (gts->ts_gru)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) gru_unload_context(gts, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) gru_unlock_gts(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * User request to flush a range of virtual addresses from the GRU TLB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) * (Mainly for testing).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int gru_user_flush_tlb(unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct gru_flush_tlb_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct gru_mm_struct *gms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) STAT(user_flush_tlb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (copy_from_user(&req, (void __user *)arg, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) gru_dbg(grudev, "gseg 0x%lx, vaddr 0x%lx, len 0x%lx\n", req.gseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) req.vaddr, req.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) gts = gru_find_lock_gts(req.gseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (!gts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) gms = gts->ts_gms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) gru_unlock_gts(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) gru_flush_tlb_range(gms, req.vaddr, req.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * Fetch GSEG statisticss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) long gru_get_gseg_statistics(unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) struct gru_get_gseg_statistics_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (copy_from_user(&req, (void __user *)arg, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) * The library creates arrays of contexts for threaded programs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * If no gts exists in the array, the context has never been used & all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * statistics are implicitly 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) gts = gru_find_lock_gts(req.gseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (gts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) memcpy(&req.stats, >s->ustats, sizeof(gts->ustats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) gru_unlock_gts(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) memset(&req.stats, 0, sizeof(gts->ustats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (copy_to_user((void __user *)arg, &req, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) * Register the current task as the user of the GSEG slice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * Needed for TLB fault interrupt targeting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) int gru_set_context_option(unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) struct gru_thread_state *gts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct gru_set_context_option_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) STAT(set_context_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (copy_from_user(&req, (void __user *)arg, sizeof(req)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) gru_dbg(grudev, "op %d, gseg 0x%lx, value1 0x%lx\n", req.op, req.gseg, req.val1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) gts = gru_find_lock_gts(req.gseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if (!gts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) gts = gru_alloc_locked_gts(req.gseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (IS_ERR(gts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return PTR_ERR(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) switch (req.op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) case sco_blade_chiplet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) /* Select blade/chiplet for GRU context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (req.val0 < -1 || req.val0 >= GRU_CHIPLETS_PER_HUB ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) req.val1 < -1 || req.val1 >= GRU_MAX_BLADES ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) (req.val1 >= 0 && !gru_base[req.val1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) gts->ts_user_blade_id = req.val1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) gts->ts_user_chiplet_id = req.val0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) gru_check_context_placement(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) case sco_gseg_owner:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) /* Register the current task as the GSEG owner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) gts->ts_tgid_owner = current->tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) case sco_cch_req_slice:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) /* Set the CCH slice option */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) gts->ts_cch_req_slice = req.val1 & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) gru_unlock_gts(gts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }