]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
powerpc/pseries: Skip using reserved virtual address range
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Wed, 22 Mar 2017 03:37:00 +0000 (09:07 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 1 Apr 2017 10:12:27 +0000 (21:12 +1100)
Now that we use all the available virtual address range, we need to make
sure we don't generate VSID such that it overlaps with the reserved vsid
range. Reserved vsid range include the virtual address range used by the
adjunct partition and also the VRMA virtual segment. We find the context
value that can result in generating such a VSID and reserve it early in
boot.

We don't look at the adjunct range, because for now we disable the
adjunct usage in a Linux LPAR via CAS interface.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
[mpe: Rewrite hash__reserve_context_id(), move the rest into pseries]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/book3s/64/mmu-hash.h
arch/powerpc/include/asm/kvm_book3s_64.h
arch/powerpc/include/asm/mmu_context.h
arch/powerpc/mm/hash_utils_64.c
arch/powerpc/mm/mmu_context_book3s64.c
arch/powerpc/platforms/pseries/lpar.c

index 5961b0d65a7924519ac1e052652c8c62c71ba55a..6d56974adf2872f2b20279d3f9b2596b7438f24d 100644 (file)
@@ -589,11 +589,18 @@ extern void slb_set_size(u16 size);
 #define VSID_MULTIPLIER_256M   ASM_CONST(12538073)     /* 24-bit prime */
 #define VSID_BITS_256M         (VA_BITS - SID_SHIFT)
 #define VSID_BITS_65_256M      (65 - SID_SHIFT)
+/*
+ * Modular multiplicative inverse of VSID_MULTIPLIER under modulo VSID_MODULUS
+ */
+#define VSID_MULINV_256M       ASM_CONST(665548017062)
 
 #define VSID_MULTIPLIER_1T     ASM_CONST(12538073)     /* 24-bit prime */
 #define VSID_BITS_1T           (VA_BITS - SID_SHIFT_1T)
 #define VSID_BITS_65_1T                (65 - SID_SHIFT_1T)
+#define VSID_MULINV_1T         ASM_CONST(209034062)
 
+/* 1TB VSID reserved for VRMA */
+#define VRMA_VSID      0x1ffffffUL
 #define USER_VSID_RANGE        (1UL << (ESID_BITS + SID_SHIFT))
 
 /* 4 bits per slice and we have one slice per 1TB */
index d9b48f5bb606a79259a6598380c874399e9def47..d55c7f881ce754528651ae4ed66d7599c5eb90a8 100644 (file)
@@ -49,8 +49,6 @@ static inline bool kvm_is_radix(struct kvm *kvm)
 #define KVM_DEFAULT_HPT_ORDER  24      /* 16MB HPT by default */
 #endif
 
-#define VRMA_VSID      0x1ffffffUL     /* 1TB VSID reserved for VRMA */
-
 /*
  * We use a lock bit in HPTE dword 0 to synchronize updates and
  * accesses to each HPTE, and another bit to indicate non-present
index 7d721101ec78dfa08c9a111fef8dc1c6b20aeb62..78803a7ebdd9cff10fb1f105d0e9c29638e2fbeb 100644 (file)
@@ -52,6 +52,7 @@ static inline void switch_mmu_context(struct mm_struct *prev,
 }
 
 extern int hash__alloc_context_id(void);
+extern void hash__reserve_context_id(int id);
 extern void __destroy_context(int context_id);
 static inline void mmu_context_init(void) { }
 #else
index 716255f88bbdd59cb38327b46a74b6e2da2e2b44..8848fec51ce94c0e5415148bc15f03b814a1ff30 100644 (file)
@@ -1868,5 +1868,4 @@ static int __init hash64_debugfs(void)
        return 0;
 }
 machine_device_initcall(pseries, hash64_debugfs);
-
 #endif /* CONFIG_DEBUG_FS */
index fd0bc6db2dcde9457e0d878754e60a31532c4c50..7bc5b63034db6bf5ffb345c4abcbd5499c69426c 100644 (file)
@@ -57,6 +57,22 @@ again:
        return index;
 }
 
+void hash__reserve_context_id(int id)
+{
+       int rc, result = 0;
+
+       do {
+               if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL))
+                       break;
+
+               spin_lock(&mmu_context_lock);
+               rc = ida_get_new_above(&mmu_context_ida, id, &result);
+               spin_unlock(&mmu_context_lock);
+       } while (rc == -EAGAIN);
+
+       WARN(result != id, "mmu: Failed to reserve context id %d (rc %d)\n", id, result);
+}
+
 int hash__alloc_context_id(void)
 {
        unsigned long max;
index 8b1fe895daa3f076bf57b6b9fe3283a6ba686fad..6541d0b03e4c5949c75bee70f40f79d82532c10f 100644 (file)
@@ -958,3 +958,64 @@ int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data)
 
        return rc;
 }
+
+static unsigned long vsid_unscramble(unsigned long vsid, int ssize)
+{
+       unsigned long protovsid;
+       unsigned long va_bits = VA_BITS;
+       unsigned long modinv, vsid_modulus;
+       unsigned long max_mod_inv, tmp_modinv;
+
+       if (!mmu_has_feature(MMU_FTR_68_BIT_VA))
+               va_bits = 65;
+
+       if (ssize == MMU_SEGSIZE_256M) {
+               modinv = VSID_MULINV_256M;
+               vsid_modulus = ((1UL << (va_bits - SID_SHIFT)) - 1);
+       } else {
+               modinv = VSID_MULINV_1T;
+               vsid_modulus = ((1UL << (va_bits - SID_SHIFT_1T)) - 1);
+       }
+
+       /*
+        * vsid outside our range.
+        */
+       if (vsid >= vsid_modulus)
+               return 0;
+
+       /*
+        * If modinv is the modular multiplicate inverse of (x % vsid_modulus)
+        * and vsid = (protovsid * x) % vsid_modulus, then we say:
+        *   protovsid = (vsid * modinv) % vsid_modulus
+        */
+
+       /* Check if (vsid * modinv) overflow (63 bits) */
+       max_mod_inv = 0x7fffffffffffffffull / vsid;
+       if (modinv < max_mod_inv)
+               return (vsid * modinv) % vsid_modulus;
+
+       tmp_modinv = modinv/max_mod_inv;
+       modinv %= max_mod_inv;
+
+       protovsid = (((vsid * max_mod_inv) % vsid_modulus) * tmp_modinv) % vsid_modulus;
+       protovsid = (protovsid + vsid * modinv) % vsid_modulus;
+
+       return protovsid;
+}
+
+static int __init reserve_vrma_context_id(void)
+{
+       unsigned long protovsid;
+
+       /*
+        * Reserve context ids which map to reserved virtual addresses. For now
+        * we only reserve the context id which maps to the VRMA VSID. We ignore
+        * the addresses in "ibm,adjunct-virtual-addresses" because we don't
+        * enable adjunct support via the "ibm,client-architecture-support"
+        * interface.
+        */
+       protovsid = vsid_unscramble(VRMA_VSID, MMU_SEGSIZE_1T);
+       hash__reserve_context_id(protovsid >> ESID_BITS_1T);
+       return 0;
+}
+machine_device_initcall(pseries, reserve_vrma_context_id);