^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __MMU_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __MMU_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) cpumask_t cpu_attach_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) atomic_t flush_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) unsigned int flush_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct list_head pgtable_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct list_head gmap_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long gmap_asce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned long asce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned long asce_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned long vdso_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* The mmu context belongs to a secure guest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) atomic_t is_protected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * The following bitfields need a down_write on the mm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * semaphore when they are written to. As they are only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * written once, they can be read without a lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * The mmu context allocates 4K page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned int alloc_pgste:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* The mmu context uses extended page tables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned int has_pgste:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* The mmu context uses storage keys. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int uses_skeys:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* The mmu context uses CMM. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned int uses_cmm:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* The gmaps associated with this context are allowed to use huge pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned int allow_gmap_hpage_1m:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) } mm_context_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define INIT_MM_CONTEXT(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .context.lock = __SPIN_LOCK_UNLOCKED(name.context.lock), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .context.pgtable_list = LIST_HEAD_INIT(name.context.pgtable_list), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .context.gmap_list = LIST_HEAD_INIT(name.context.gmap_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static inline int tprot(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) " tprot 0(%1),0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) "0: ipm %0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) " srl %0,28\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) "1:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) EX_TABLE(0b,1b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) : "+d" (rc) : "a" (addr) : "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return rc;
^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) #endif