Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pSeries_lpar.c |
| 3 | * Copyright (C) 2001 Todd Inglett, IBM Corporation |
| 4 | * |
| 5 | * pSeries LPAR support. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
Michael Ellerman | f7ebf35 | 2008-04-24 15:13:19 +1000 | [diff] [blame] | 22 | /* Enables debugging of low-level hash table routines - careful! */ |
| 23 | #undef DEBUG |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 24 | #define pr_fmt(fmt) "lpar: " fmt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/dma-mapping.h> |
Benjamin Herrenschmidt | 463ce0e | 2005-11-23 17:56:06 +1100 | [diff] [blame] | 28 | #include <linux/console.h> |
Paul Gortmaker | 66b15db | 2011-05-27 10:46:24 -0400 | [diff] [blame] | 29 | #include <linux/export.h> |
Anton Blanchard | 58995a9 | 2015-04-09 13:51:32 +1000 | [diff] [blame] | 30 | #include <linux/jump_label.h> |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 31 | #include <linux/delay.h> |
| 32 | #include <linux/stop_machine.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/processor.h> |
| 34 | #include <asm/mmu.h> |
| 35 | #include <asm/page.h> |
| 36 | #include <asm/pgtable.h> |
| 37 | #include <asm/machdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/iommu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/tlb.h> |
| 41 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/cputable.h> |
David Gibson | dcad47f | 2005-11-07 09:49:43 +1100 | [diff] [blame] | 43 | #include <asm/udbg.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame] | 44 | #include <asm/smp.h> |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 45 | #include <asm/trace.h> |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 46 | #include <asm/firmware.h> |
Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 47 | #include <asm/plpar_wrappers.h> |
Hari Bathini | c1caae3 | 2014-12-18 23:36:55 +0530 | [diff] [blame] | 48 | #include <asm/kexec.h> |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 49 | #include <asm/fadump.h> |
Daniel Axtens | 42f5b4c | 2016-05-18 11:16:50 +1000 | [diff] [blame] | 50 | #include <asm/asm-prototypes.h> |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 51 | |
Michael Ellerman | 21cf913 | 2008-04-16 13:51:48 +1000 | [diff] [blame] | 52 | #include "pseries.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 54 | /* Flag bits for H_BULK_REMOVE */ |
| 55 | #define HBR_REQUEST 0x4000000000000000UL |
| 56 | #define HBR_RESPONSE 0x8000000000000000UL |
| 57 | #define HBR_END 0xc000000000000000UL |
| 58 | #define HBR_AVPN 0x0200000000000000UL |
| 59 | #define HBR_ANDCOND 0x0100000000000000UL |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 62 | /* in hvCall.S */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | EXPORT_SYMBOL(plpar_hcall); |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 64 | EXPORT_SYMBOL(plpar_hcall9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | EXPORT_SYMBOL(plpar_hcall_norets); |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | void vpa_init(int cpu) |
| 68 | { |
| 69 | int hwcpu = get_hard_smp_processor_id(cpu); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 70 | unsigned long addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | long ret; |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 72 | struct paca_struct *pp; |
| 73 | struct dtl_entry *dtl; |
Olof Johansson | 233ccd0 | 2005-09-03 15:55:59 -0700 | [diff] [blame] | 74 | |
Michael Ellerman | b89bdfb | 2013-08-15 15:22:15 +1000 | [diff] [blame] | 75 | /* |
| 76 | * The spec says it "may be problematic" if CPU x registers the VPA of |
| 77 | * CPU y. We should never do that, but wail if we ever do. |
| 78 | */ |
| 79 | WARN_ON(cpu != smp_processor_id()); |
| 80 | |
Olof Johansson | 233ccd0 | 2005-09-03 15:55:59 -0700 | [diff] [blame] | 81 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
Paul Mackerras | 8154c5d | 2010-08-12 20:18:15 +0000 | [diff] [blame] | 82 | lppaca_of(cpu).vmxregs_in_use = 1; |
Olof Johansson | 233ccd0 | 2005-09-03 15:55:59 -0700 | [diff] [blame] | 83 | |
Michael Ellerman | 6e0b8bc9 | 2013-06-28 18:15:18 +1000 | [diff] [blame] | 84 | if (cpu_has_feature(CPU_FTR_ARCH_207S)) |
| 85 | lppaca_of(cpu).ebb_regs_in_use = 1; |
| 86 | |
Paul Mackerras | 8154c5d | 2010-08-12 20:18:15 +0000 | [diff] [blame] | 87 | addr = __pa(&lppaca_of(cpu)); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 88 | ret = register_vpa(hwcpu, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 90 | if (ret) { |
Anton Blanchard | 711ef84 | 2011-07-25 01:46:33 +0000 | [diff] [blame] | 91 | pr_err("WARNING: VPA registration for cpu %d (hw %d) of area " |
| 92 | "%lx failed with %ld\n", cpu, hwcpu, addr, ret); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 93 | return; |
| 94 | } |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 95 | |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 96 | #ifdef CONFIG_PPC_BOOK3S_64 |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 97 | /* |
| 98 | * PAPR says this feature is SLB-Buffer but firmware never |
| 99 | * reports that. All SPLPAR support SLB shadow buffer. |
| 100 | */ |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 101 | if (!radix_enabled() && firmware_has_feature(FW_FEATURE_SPLPAR)) { |
Nicholas Piggin | d2e6007 | 2018-02-14 01:08:12 +1000 | [diff] [blame] | 102 | addr = __pa(paca_ptrs[cpu]->slb_shadow_ptr); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 103 | ret = register_slb_shadow(hwcpu, addr); |
| 104 | if (ret) |
Anton Blanchard | 711ef84 | 2011-07-25 01:46:33 +0000 | [diff] [blame] | 105 | pr_err("WARNING: SLB shadow buffer registration for " |
| 106 | "cpu %d (hw %d) of area %lx failed with %ld\n", |
| 107 | cpu, hwcpu, addr, ret); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 108 | } |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 109 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * Register dispatch trace log, if one has been allocated. |
| 113 | */ |
Nicholas Piggin | d2e6007 | 2018-02-14 01:08:12 +1000 | [diff] [blame] | 114 | pp = paca_ptrs[cpu]; |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 115 | dtl = pp->dispatch_log; |
| 116 | if (dtl) { |
| 117 | pp->dtl_ridx = 0; |
| 118 | pp->dtl_curr = dtl; |
| 119 | lppaca_of(cpu).dtl_idx = 0; |
| 120 | |
| 121 | /* hypervisor reads buffer length from this field */ |
Anton Blanchard | 7ffcf8e | 2013-08-07 02:01:46 +1000 | [diff] [blame] | 122 | dtl->enqueue_to_dispatch_time = cpu_to_be32(DISPATCH_LOG_BYTES); |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 123 | ret = register_dtl(hwcpu, __pa(dtl)); |
| 124 | if (ret) |
Anton Blanchard | 711ef84 | 2011-07-25 01:46:33 +0000 | [diff] [blame] | 125 | pr_err("WARNING: DTL registration of cpu %d (hw %d) " |
| 126 | "failed with %ld\n", smp_processor_id(), |
| 127 | hwcpu, ret); |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 128 | lppaca_of(cpu).dtl_enable_mask = 2; |
| 129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 132 | #ifdef CONFIG_PPC_BOOK3S_64 |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 133 | |
Geoff Levand | 035223f | 2006-10-05 11:35:10 -0700 | [diff] [blame] | 134 | static long pSeries_lpar_hpte_insert(unsigned long hpte_group, |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 135 | unsigned long vpn, unsigned long pa, |
| 136 | unsigned long rflags, unsigned long vflags, |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 137 | int psize, int apsize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | unsigned long lpar_rc; |
| 140 | unsigned long flags; |
| 141 | unsigned long slot; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 142 | unsigned long hpte_v, hpte_r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 144 | if (!(vflags & HPTE_V_BOLTED)) |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 145 | pr_devel("hpte_insert(group=%lx, vpn=%016lx, " |
| 146 | "pa=%016lx, rflags=%lx, vflags=%lx, psize=%d)\n", |
| 147 | hpte_group, vpn, pa, rflags, vflags, psize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 149 | hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID; |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 150 | hpte_r = hpte_encode_r(pa, psize, apsize) | rflags; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 151 | |
| 152 | if (!(vflags & HPTE_V_BOLTED)) |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 153 | pr_devel(" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* Now fill in the actual HPTE */ |
| 156 | /* Set CEC cookie to 0 */ |
| 157 | /* Zero page = 0 */ |
| 158 | /* I-cache Invalidate = 0 */ |
| 159 | /* I-cache synchronize = 0 */ |
| 160 | /* Exact = 0 */ |
| 161 | flags = 0; |
| 162 | |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 163 | if (firmware_has_feature(FW_FEATURE_XCMO) && !(hpte_r & HPTE_R_N)) |
| 164 | flags |= H_COALESCE_CAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 166 | lpar_rc = plpar_pte_enter(flags, hpte_group, hpte_v, hpte_r, &slot); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 167 | if (unlikely(lpar_rc == H_PTEG_FULL)) { |
Aneesh Kumar K.V | ca42d8d2 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 168 | pr_devel("Hash table group is full\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | return -1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Since we try and ioremap PHBs we don't own, the pte insert |
| 174 | * will fail. However we must catch the failure in hash_page |
| 175 | * or we will loop forever, so return -2 in this case. |
| 176 | */ |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 177 | if (unlikely(lpar_rc != H_SUCCESS)) { |
Aneesh Kumar K.V | ca42d8d2 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 178 | pr_err("Failed hash pte insert with error %ld\n", lpar_rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return -2; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 180 | } |
| 181 | if (!(vflags & HPTE_V_BOLTED)) |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 182 | pr_devel(" -> slot: %lu\n", slot & 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | /* Because of iSeries, we have to pass down the secondary |
| 185 | * bucket bit here as well |
| 186 | */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 187 | return (slot & 7) | (!!(vflags & HPTE_V_SECONDARY) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static DEFINE_SPINLOCK(pSeries_lpar_tlbie_lock); |
| 191 | |
| 192 | static long pSeries_lpar_hpte_remove(unsigned long hpte_group) |
| 193 | { |
| 194 | unsigned long slot_offset; |
| 195 | unsigned long lpar_rc; |
| 196 | int i; |
| 197 | unsigned long dummy1, dummy2; |
| 198 | |
| 199 | /* pick a random slot to start at */ |
| 200 | slot_offset = mftb() & 0x7; |
| 201 | |
| 202 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
| 203 | |
| 204 | /* don't remove a bolted entry */ |
| 205 | lpar_rc = plpar_pte_remove(H_ANDCOND, hpte_group + slot_offset, |
| 206 | (0x1UL << 4), &dummy1, &dummy2); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 207 | if (lpar_rc == H_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return i; |
Michael Wolf | 9fb2640 | 2013-04-05 10:41:40 +0000 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * The test for adjunct partition is performed before the |
| 212 | * ANDCOND test. H_RESOURCE may be returned, so we need to |
| 213 | * check for that as well. |
| 214 | */ |
| 215 | BUG_ON(lpar_rc != H_NOT_FOUND && lpar_rc != H_RESOURCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | slot_offset++; |
| 218 | slot_offset &= 0x7; |
| 219 | } |
| 220 | |
| 221 | return -1; |
| 222 | } |
| 223 | |
Anton Blanchard | 5246ade | 2016-10-01 20:41:56 +1000 | [diff] [blame] | 224 | static void manual_hpte_clear_all(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | unsigned long size_bytes = 1UL << ppc64_pft_size; |
| 227 | unsigned long hpte_count = size_bytes >> 4; |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 228 | struct { |
| 229 | unsigned long pteh; |
| 230 | unsigned long ptel; |
| 231 | } ptes[4]; |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 232 | long lpar_rc; |
Anton Blanchard | bed9a31 | 2011-07-26 18:15:03 +0000 | [diff] [blame] | 233 | unsigned long i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 235 | /* Read in batches of 4, |
| 236 | * invalidate only valid entries not in the VRMA |
| 237 | * hpte_count will be a multiple of 4 |
| 238 | */ |
| 239 | for (i = 0; i < hpte_count; i += 4) { |
| 240 | lpar_rc = plpar_pte_read_4_raw(0, i, (void *)ptes); |
Aneesh Kumar K.V | ca42d8d2 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 241 | if (lpar_rc != H_SUCCESS) { |
| 242 | pr_info("Failed to read hash page table at %ld err %ld\n", |
| 243 | i, lpar_rc); |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 244 | continue; |
Aneesh Kumar K.V | ca42d8d2 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 245 | } |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 246 | for (j = 0; j < 4; j++){ |
| 247 | if ((ptes[j].pteh & HPTE_V_VRMA_MASK) == |
| 248 | HPTE_V_VRMA_MASK) |
| 249 | continue; |
| 250 | if (ptes[j].pteh & HPTE_V_VALID) |
| 251 | plpar_pte_remove_raw(0, i + j, 0, |
| 252 | &(ptes[j].pteh), &(ptes[j].ptel)); |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 253 | } |
| 254 | } |
Anton Blanchard | 5246ade | 2016-10-01 20:41:56 +1000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static int hcall_hpte_clear_all(void) |
| 258 | { |
| 259 | int rc; |
| 260 | |
| 261 | do { |
| 262 | rc = plpar_hcall_norets(H_CLEAR_HPT); |
| 263 | } while (rc == H_CONTINUE); |
| 264 | |
| 265 | return rc; |
| 266 | } |
| 267 | |
| 268 | static void pseries_hpte_clear_all(void) |
| 269 | { |
| 270 | int rc; |
| 271 | |
| 272 | rc = hcall_hpte_clear_all(); |
| 273 | if (rc != H_SUCCESS) |
| 274 | manual_hpte_clear_all(); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 275 | |
| 276 | #ifdef __LITTLE_ENDIAN__ |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 277 | /* |
| 278 | * Reset exceptions to big endian. |
| 279 | * |
| 280 | * FIXME this is a hack for kexec, we need to reset the exception |
| 281 | * endian before starting the new kernel and this is a convenient place |
| 282 | * to do it. |
| 283 | * |
| 284 | * This is also called on boot when a fadump happens. In that case we |
| 285 | * must not change the exception endian mode. |
| 286 | */ |
Benjamin Herrenschmidt | d3cbff1 | 2016-07-05 15:03:49 +1000 | [diff] [blame] | 287 | if (firmware_has_feature(FW_FEATURE_SET_MODE) && !is_fadump_active()) |
| 288 | pseries_big_endian_exceptions(); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 289 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* |
| 293 | * NOTE: for updatepp ops we are fortunate that the linux "newpp" bits and |
| 294 | * the low 3 bits of flags happen to line up. So no transform is needed. |
| 295 | * We can probably optimize here and assume the high bits of newpp are |
| 296 | * already zero. For now I am paranoid. |
| 297 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 298 | static long pSeries_lpar_hpte_updatepp(unsigned long slot, |
| 299 | unsigned long newpp, |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 300 | unsigned long vpn, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 301 | int psize, int apsize, |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 302 | int ssize, unsigned long inv_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
| 304 | unsigned long lpar_rc; |
Balbir Singh | e71ff98 | 2017-06-29 03:04:07 +1000 | [diff] [blame] | 305 | unsigned long flags; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 306 | unsigned long want_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 308 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Balbir Singh | e71ff98 | 2017-06-29 03:04:07 +1000 | [diff] [blame] | 310 | flags = (newpp & 7) | H_AVPN; |
| 311 | if (mmu_has_feature(MMU_FTR_KERNEL_RO)) |
| 312 | /* Move pp0 into bit 8 (IBM 55) */ |
| 313 | flags |= (newpp & HPTE_R_PP0) >> 55; |
| 314 | |
Alexey Kardashevskiy | a8c0bf3 | 2018-01-09 16:52:14 +1100 | [diff] [blame] | 315 | pr_devel(" update: avpnv=%016lx, hash=%016lx, f=%lx, psize: %d ...", |
| 316 | want_v, slot, flags, psize); |
| 317 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 318 | lpar_rc = plpar_pte_protect(flags, slot, want_v); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 319 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 320 | if (lpar_rc == H_NOT_FOUND) { |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 321 | pr_devel("not found !\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | return -1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 323 | } |
| 324 | |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 325 | pr_devel("ok\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 327 | BUG_ON(lpar_rc != H_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 332 | static long __pSeries_lpar_hpte_find(unsigned long want_v, unsigned long hpte_group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 334 | long lpar_rc; |
| 335 | unsigned long i, j; |
| 336 | struct { |
| 337 | unsigned long pteh; |
| 338 | unsigned long ptel; |
| 339 | } ptes[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 341 | for (i = 0; i < HPTES_PER_GROUP; i += 4, hpte_group += 4) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 343 | lpar_rc = plpar_pte_read_4(0, hpte_group, (void *)ptes); |
Aneesh Kumar K.V | ca42d8d2 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 344 | if (lpar_rc != H_SUCCESS) { |
| 345 | pr_info("Failed to read hash page table at %ld err %ld\n", |
| 346 | hpte_group, lpar_rc); |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 347 | continue; |
Aneesh Kumar K.V | ca42d8d2 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 350 | for (j = 0; j < 4; j++) { |
| 351 | if (HPTE_V_COMPARE(ptes[j].pteh, want_v) && |
| 352 | (ptes[j].pteh & HPTE_V_VALID)) |
| 353 | return i + j; |
| 354 | } |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 357 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 360 | static long pSeries_lpar_hpte_find(unsigned long vpn, int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | long slot; |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 363 | unsigned long hash; |
| 364 | unsigned long want_v; |
| 365 | unsigned long hpte_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 367 | hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize); |
| 368 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 370 | /* Bolted entries are always in the primary group */ |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 371 | hpte_group = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 372 | slot = __pSeries_lpar_hpte_find(want_v, hpte_group); |
| 373 | if (slot < 0) |
| 374 | return -1; |
| 375 | return hpte_group + slot; |
| 376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp, |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 379 | unsigned long ea, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 380 | int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 382 | unsigned long vpn; |
| 383 | unsigned long lpar_rc, slot, vsid, flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 385 | vsid = get_kernel_vsid(ea, ssize); |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 386 | vpn = hpt_vpn(ea, vsid, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 388 | slot = pSeries_lpar_hpte_find(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | BUG_ON(slot == -1); |
| 390 | |
| 391 | flags = newpp & 7; |
Balbir Singh | e71ff98 | 2017-06-29 03:04:07 +1000 | [diff] [blame] | 392 | if (mmu_has_feature(MMU_FTR_KERNEL_RO)) |
| 393 | /* Move pp0 into bit 8 (IBM 55) */ |
| 394 | flags |= (newpp & HPTE_R_PP0) >> 55; |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | lpar_rc = plpar_pte_protect(flags, slot, 0); |
| 397 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 398 | BUG_ON(lpar_rc != H_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 401 | static void pSeries_lpar_hpte_invalidate(unsigned long slot, unsigned long vpn, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 402 | int psize, int apsize, |
| 403 | int ssize, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 405 | unsigned long want_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | unsigned long lpar_rc; |
| 407 | unsigned long dummy1, dummy2; |
| 408 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 409 | pr_devel(" inval : slot=%lx, vpn=%016lx, psize: %d, local: %d\n", |
| 410 | slot, vpn, psize, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 412 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 413 | lpar_rc = plpar_pte_remove(H_AVPN, slot, want_v, &dummy1, &dummy2); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 414 | if (lpar_rc == H_NOT_FOUND) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | return; |
| 416 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 417 | BUG_ON(lpar_rc != H_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 420 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 421 | /* |
| 422 | * Limit iterations holding pSeries_lpar_tlbie_lock to 3. We also need |
| 423 | * to make sure that we avoid bouncing the hypervisor tlbie lock. |
| 424 | */ |
| 425 | #define PPC64_HUGE_HPTE_BATCH 12 |
| 426 | |
| 427 | static void __pSeries_lpar_hugepage_invalidate(unsigned long *slot, |
| 428 | unsigned long *vpn, int count, |
| 429 | int psize, int ssize) |
| 430 | { |
Laurent Dufour | 05af40e | 2016-10-06 15:33:21 +0200 | [diff] [blame] | 431 | unsigned long param[PLPAR_HCALL9_BUFSIZE]; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 432 | int i = 0, pix = 0, rc; |
| 433 | unsigned long flags = 0; |
| 434 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
| 435 | |
| 436 | if (lock_tlbie) |
| 437 | spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags); |
| 438 | |
| 439 | for (i = 0; i < count; i++) { |
| 440 | |
| 441 | if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) { |
| 442 | pSeries_lpar_hpte_invalidate(slot[i], vpn[i], psize, 0, |
| 443 | ssize, 0); |
| 444 | } else { |
| 445 | param[pix] = HBR_REQUEST | HBR_AVPN | slot[i]; |
| 446 | param[pix+1] = hpte_encode_avpn(vpn[i], psize, ssize); |
| 447 | pix += 2; |
| 448 | if (pix == 8) { |
| 449 | rc = plpar_hcall9(H_BULK_REMOVE, param, |
| 450 | param[0], param[1], param[2], |
| 451 | param[3], param[4], param[5], |
| 452 | param[6], param[7]); |
| 453 | BUG_ON(rc != H_SUCCESS); |
| 454 | pix = 0; |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | if (pix) { |
| 459 | param[pix] = HBR_END; |
| 460 | rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1], |
| 461 | param[2], param[3], param[4], param[5], |
| 462 | param[6], param[7]); |
| 463 | BUG_ON(rc != H_SUCCESS); |
| 464 | } |
| 465 | |
| 466 | if (lock_tlbie) |
| 467 | spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags); |
| 468 | } |
| 469 | |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 470 | static void pSeries_lpar_hugepage_invalidate(unsigned long vsid, |
| 471 | unsigned long addr, |
| 472 | unsigned char *hpte_slot_array, |
Aneesh Kumar K.V | d557b09 | 2014-11-02 21:15:28 +0530 | [diff] [blame] | 473 | int psize, int ssize, int local) |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 474 | { |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 475 | int i, index = 0; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 476 | unsigned long s_addr = addr; |
| 477 | unsigned int max_hpte_count, valid; |
| 478 | unsigned long vpn_array[PPC64_HUGE_HPTE_BATCH]; |
| 479 | unsigned long slot_array[PPC64_HUGE_HPTE_BATCH]; |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 480 | unsigned long shift, hidx, vpn = 0, hash, slot; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 481 | |
| 482 | shift = mmu_psize_defs[psize].shift; |
| 483 | max_hpte_count = 1U << (PMD_SHIFT - shift); |
| 484 | |
| 485 | for (i = 0; i < max_hpte_count; i++) { |
| 486 | valid = hpte_valid(hpte_slot_array, i); |
| 487 | if (!valid) |
| 488 | continue; |
| 489 | hidx = hpte_hash_index(hpte_slot_array, i); |
| 490 | |
| 491 | /* get the vpn */ |
| 492 | addr = s_addr + (i * (1ul << shift)); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 493 | vpn = hpt_vpn(addr, vsid, ssize); |
| 494 | hash = hpt_hash(vpn, shift, ssize); |
| 495 | if (hidx & _PTEIDX_SECONDARY) |
| 496 | hash = ~hash; |
| 497 | |
| 498 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 499 | slot += hidx & _PTEIDX_GROUP_IX; |
| 500 | |
| 501 | slot_array[index] = slot; |
| 502 | vpn_array[index] = vpn; |
| 503 | if (index == PPC64_HUGE_HPTE_BATCH - 1) { |
| 504 | /* |
| 505 | * Now do a bluk invalidate |
| 506 | */ |
| 507 | __pSeries_lpar_hugepage_invalidate(slot_array, |
| 508 | vpn_array, |
| 509 | PPC64_HUGE_HPTE_BATCH, |
| 510 | psize, ssize); |
| 511 | index = 0; |
| 512 | } else |
| 513 | index++; |
| 514 | } |
| 515 | if (index) |
| 516 | __pSeries_lpar_hugepage_invalidate(slot_array, vpn_array, |
| 517 | index, psize, ssize); |
| 518 | } |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 519 | #else |
| 520 | static void pSeries_lpar_hugepage_invalidate(unsigned long vsid, |
| 521 | unsigned long addr, |
| 522 | unsigned char *hpte_slot_array, |
| 523 | int psize, int ssize, int local) |
| 524 | { |
| 525 | WARN(1, "%s called without THP support\n", __func__); |
| 526 | } |
| 527 | #endif |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 528 | |
David Gibson | 27828f9 | 2016-02-09 13:32:41 +1000 | [diff] [blame] | 529 | static int pSeries_lpar_hpte_removebolted(unsigned long ea, |
| 530 | int psize, int ssize) |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 531 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 532 | unsigned long vpn; |
| 533 | unsigned long slot, vsid; |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 534 | |
| 535 | vsid = get_kernel_vsid(ea, ssize); |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 536 | vpn = hpt_vpn(ea, vsid, ssize); |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 537 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 538 | slot = pSeries_lpar_hpte_find(vpn, psize, ssize); |
David Gibson | 27828f9 | 2016-02-09 13:32:41 +1000 | [diff] [blame] | 539 | if (slot == -1) |
| 540 | return -ENOENT; |
| 541 | |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 542 | /* |
| 543 | * lpar doesn't use the passed actual page size |
| 544 | */ |
| 545 | pSeries_lpar_hpte_invalidate(slot, vpn, psize, 0, ssize, 0); |
David Gibson | 27828f9 | 2016-02-09 13:32:41 +1000 | [diff] [blame] | 546 | return 0; |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 547 | } |
| 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | /* |
| 550 | * Take a spinlock around flushes to avoid bouncing the hypervisor tlbie |
| 551 | * lock. |
| 552 | */ |
Geoff Levand | 035223f | 2006-10-05 11:35:10 -0700 | [diff] [blame] | 553 | static void pSeries_lpar_flush_hash_range(unsigned long number, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 555 | unsigned long vpn; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 556 | unsigned long i, pix, rc; |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 557 | unsigned long flags = 0; |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 558 | struct ppc64_tlb_batch *batch = this_cpu_ptr(&ppc64_tlb_batch); |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 559 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
Laurent Dufour | 05af40e | 2016-10-06 15:33:21 +0200 | [diff] [blame] | 560 | unsigned long param[PLPAR_HCALL9_BUFSIZE]; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 561 | unsigned long hash, index, shift, hidx, slot; |
| 562 | real_pte_t pte; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 563 | int psize, ssize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | if (lock_tlbie) |
| 566 | spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags); |
| 567 | |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 568 | psize = batch->psize; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 569 | ssize = batch->ssize; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 570 | pix = 0; |
| 571 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 572 | vpn = batch->vpn[i]; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 573 | pte = batch->pte[i]; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 574 | pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) { |
| 575 | hash = hpt_hash(vpn, shift, ssize); |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 576 | hidx = __rpte_to_hidx(pte, index); |
| 577 | if (hidx & _PTEIDX_SECONDARY) |
| 578 | hash = ~hash; |
| 579 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 580 | slot += hidx & _PTEIDX_GROUP_IX; |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 581 | if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) { |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 582 | /* |
| 583 | * lpar doesn't use the passed actual page size |
| 584 | */ |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 585 | pSeries_lpar_hpte_invalidate(slot, vpn, psize, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 586 | 0, ssize, local); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 587 | } else { |
| 588 | param[pix] = HBR_REQUEST | HBR_AVPN | slot; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 589 | param[pix+1] = hpte_encode_avpn(vpn, psize, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 590 | ssize); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 591 | pix += 2; |
| 592 | if (pix == 8) { |
| 593 | rc = plpar_hcall9(H_BULK_REMOVE, param, |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 594 | param[0], param[1], param[2], |
| 595 | param[3], param[4], param[5], |
| 596 | param[6], param[7]); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 597 | BUG_ON(rc != H_SUCCESS); |
| 598 | pix = 0; |
| 599 | } |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 600 | } |
| 601 | } pte_iterate_hashed_end(); |
| 602 | } |
| 603 | if (pix) { |
| 604 | param[pix] = HBR_END; |
| 605 | rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1], |
| 606 | param[2], param[3], param[4], param[5], |
| 607 | param[6], param[7]); |
| 608 | BUG_ON(rc != H_SUCCESS); |
| 609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | if (lock_tlbie) |
| 612 | spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags); |
| 613 | } |
| 614 | |
Will Schmidt | 4e89a2d | 2010-09-28 15:33:12 +0000 | [diff] [blame] | 615 | static int __init disable_bulk_remove(char *str) |
| 616 | { |
| 617 | if (strcmp(str, "off") == 0 && |
| 618 | firmware_has_feature(FW_FEATURE_BULK_REMOVE)) { |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 619 | pr_info("Disabling BULK_REMOVE firmware feature"); |
| 620 | powerpc_firmware_features &= ~FW_FEATURE_BULK_REMOVE; |
Will Schmidt | 4e89a2d | 2010-09-28 15:33:12 +0000 | [diff] [blame] | 621 | } |
| 622 | return 1; |
| 623 | } |
| 624 | |
| 625 | __setup("bulk_remove=", disable_bulk_remove); |
| 626 | |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 627 | #define HPT_RESIZE_TIMEOUT 10000 /* ms */ |
| 628 | |
| 629 | struct hpt_resize_state { |
| 630 | unsigned long shift; |
| 631 | int commit_rc; |
| 632 | }; |
| 633 | |
| 634 | static int pseries_lpar_resize_hpt_commit(void *data) |
| 635 | { |
| 636 | struct hpt_resize_state *state = data; |
| 637 | |
| 638 | state->commit_rc = plpar_resize_hpt_commit(0, state->shift); |
| 639 | if (state->commit_rc != H_SUCCESS) |
| 640 | return -EIO; |
| 641 | |
| 642 | /* Hypervisor has transitioned the HTAB, update our globals */ |
| 643 | ppc64_pft_size = state->shift; |
| 644 | htab_size_bytes = 1UL << ppc64_pft_size; |
| 645 | htab_hash_mask = (htab_size_bytes >> 7) - 1; |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
Gautham R. Shenoy | f5f31a6 | 2019-05-15 13:15:52 +0530 | [diff] [blame] | 650 | /* |
| 651 | * Must be called in process context. The caller must hold the |
| 652 | * cpus_lock. |
| 653 | */ |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 654 | static int pseries_lpar_resize_hpt(unsigned long shift) |
| 655 | { |
| 656 | struct hpt_resize_state state = { |
| 657 | .shift = shift, |
| 658 | .commit_rc = H_FUNCTION, |
| 659 | }; |
| 660 | unsigned int delay, total_delay = 0; |
| 661 | int rc; |
| 662 | ktime_t t0, t1, t2; |
| 663 | |
| 664 | might_sleep(); |
| 665 | |
| 666 | if (!firmware_has_feature(FW_FEATURE_HPT_RESIZE)) |
| 667 | return -ENODEV; |
| 668 | |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 669 | pr_info("Attempting to resize HPT to shift %lu\n", shift); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 670 | |
| 671 | t0 = ktime_get(); |
| 672 | |
| 673 | rc = plpar_resize_hpt_prepare(0, shift); |
| 674 | while (H_IS_LONG_BUSY(rc)) { |
| 675 | delay = get_longbusy_msecs(rc); |
| 676 | total_delay += delay; |
| 677 | if (total_delay > HPT_RESIZE_TIMEOUT) { |
| 678 | /* prepare with shift==0 cancels an in-progress resize */ |
| 679 | rc = plpar_resize_hpt_prepare(0, 0); |
| 680 | if (rc != H_SUCCESS) |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 681 | pr_warn("Unexpected error %d cancelling timed out HPT resize\n", |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 682 | rc); |
| 683 | return -ETIMEDOUT; |
| 684 | } |
| 685 | msleep(delay); |
| 686 | rc = plpar_resize_hpt_prepare(0, shift); |
| 687 | }; |
| 688 | |
| 689 | switch (rc) { |
| 690 | case H_SUCCESS: |
| 691 | /* Continue on */ |
| 692 | break; |
| 693 | |
| 694 | case H_PARAMETER: |
| 695 | return -EINVAL; |
| 696 | case H_RESOURCE: |
| 697 | return -EPERM; |
| 698 | default: |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 699 | pr_warn("Unexpected error %d from H_RESIZE_HPT_PREPARE\n", rc); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 700 | return -EIO; |
| 701 | } |
| 702 | |
| 703 | t1 = ktime_get(); |
| 704 | |
Gautham R. Shenoy | f5f31a6 | 2019-05-15 13:15:52 +0530 | [diff] [blame] | 705 | rc = stop_machine_cpuslocked(pseries_lpar_resize_hpt_commit, |
| 706 | &state, NULL); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 707 | |
| 708 | t2 = ktime_get(); |
| 709 | |
| 710 | if (rc != 0) { |
| 711 | switch (state.commit_rc) { |
| 712 | case H_PTEG_FULL: |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 713 | pr_warn("Hash collision while resizing HPT\n"); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 714 | return -ENOSPC; |
| 715 | |
| 716 | default: |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 717 | pr_warn("Unexpected error %d from H_RESIZE_HPT_COMMIT\n", |
| 718 | state.commit_rc); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 719 | return -EIO; |
| 720 | }; |
| 721 | } |
| 722 | |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 723 | pr_info("HPT resize to shift %lu complete (%lld ms / %lld ms)\n", |
| 724 | shift, (long long) ktime_ms_delta(t1, t0), |
| 725 | (long long) ktime_ms_delta(t2, t1)); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 730 | static int pseries_lpar_register_process_table(unsigned long base, |
| 731 | unsigned long page_size, unsigned long table_size) |
| 732 | { |
| 733 | long rc; |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 734 | unsigned long flags = 0; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 735 | |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 736 | if (table_size) |
| 737 | flags |= PROC_TABLE_NEW; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 738 | if (radix_enabled()) |
| 739 | flags |= PROC_TABLE_RADIX | PROC_TABLE_GTSE; |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 740 | else |
| 741 | flags |= PROC_TABLE_HPT_SLB; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 742 | for (;;) { |
| 743 | rc = plpar_hcall_norets(H_REGISTER_PROC_TBL, flags, base, |
| 744 | page_size, table_size); |
| 745 | if (!H_IS_LONG_BUSY(rc)) |
| 746 | break; |
| 747 | mdelay(get_longbusy_msecs(rc)); |
| 748 | } |
| 749 | if (rc != H_SUCCESS) { |
| 750 | pr_err("Failed to register process table (rc=%ld)\n", rc); |
| 751 | BUG(); |
| 752 | } |
| 753 | return rc; |
| 754 | } |
| 755 | |
Michael Ellerman | 6364e84 | 2016-07-26 10:33:03 +1000 | [diff] [blame] | 756 | void __init hpte_init_pseries(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 758 | mmu_hash_ops.hpte_invalidate = pSeries_lpar_hpte_invalidate; |
| 759 | mmu_hash_ops.hpte_updatepp = pSeries_lpar_hpte_updatepp; |
| 760 | mmu_hash_ops.hpte_updateboltedpp = pSeries_lpar_hpte_updateboltedpp; |
| 761 | mmu_hash_ops.hpte_insert = pSeries_lpar_hpte_insert; |
| 762 | mmu_hash_ops.hpte_remove = pSeries_lpar_hpte_remove; |
| 763 | mmu_hash_ops.hpte_removebolted = pSeries_lpar_hpte_removebolted; |
| 764 | mmu_hash_ops.flush_hash_range = pSeries_lpar_flush_hash_range; |
Anton Blanchard | 5246ade | 2016-10-01 20:41:56 +1000 | [diff] [blame] | 765 | mmu_hash_ops.hpte_clear_all = pseries_hpte_clear_all; |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 766 | mmu_hash_ops.hugepage_invalidate = pSeries_lpar_hugepage_invalidate; |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 767 | register_process_table = pseries_lpar_register_process_table; |
Michael Ellerman | 8971e1c | 2017-03-17 16:02:35 +1100 | [diff] [blame] | 768 | |
| 769 | if (firmware_has_feature(FW_FEATURE_HPT_RESIZE)) |
| 770 | mmu_hash_ops.resize_hpt = pseries_lpar_resize_hpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 772 | |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 773 | void radix_init_pseries(void) |
| 774 | { |
| 775 | pr_info("Using radix MMU under hypervisor\n"); |
| 776 | register_process_table = pseries_lpar_register_process_table; |
| 777 | } |
| 778 | |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 779 | #ifdef CONFIG_PPC_SMLPAR |
| 780 | #define CMO_FREE_HINT_DEFAULT 1 |
| 781 | static int cmo_free_hint_flag = CMO_FREE_HINT_DEFAULT; |
| 782 | |
| 783 | static int __init cmo_free_hint(char *str) |
| 784 | { |
| 785 | char *parm; |
| 786 | parm = strstrip(str); |
| 787 | |
| 788 | if (strcasecmp(parm, "no") == 0 || strcasecmp(parm, "off") == 0) { |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 789 | pr_info("%s: CMO free page hinting is not active.\n", __func__); |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 790 | cmo_free_hint_flag = 0; |
| 791 | return 1; |
| 792 | } |
| 793 | |
| 794 | cmo_free_hint_flag = 1; |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 795 | pr_info("%s: CMO free page hinting is active.\n", __func__); |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 796 | |
| 797 | if (strcasecmp(parm, "yes") == 0 || strcasecmp(parm, "on") == 0) |
| 798 | return 1; |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | __setup("cmo_free_hint=", cmo_free_hint); |
| 804 | |
| 805 | static void pSeries_set_page_state(struct page *page, int order, |
| 806 | unsigned long state) |
| 807 | { |
| 808 | int i, j; |
| 809 | unsigned long cmo_page_sz, addr; |
| 810 | |
| 811 | cmo_page_sz = cmo_get_page_size(); |
| 812 | addr = __pa((unsigned long)page_address(page)); |
| 813 | |
| 814 | for (i = 0; i < (1 << order); i++, addr += PAGE_SIZE) { |
| 815 | for (j = 0; j < PAGE_SIZE; j += cmo_page_sz) |
| 816 | plpar_hcall_norets(H_PAGE_INIT, state, addr + j, 0); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | void arch_free_page(struct page *page, int order) |
| 821 | { |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 822 | if (radix_enabled()) |
| 823 | return; |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 824 | if (!cmo_free_hint_flag || !firmware_has_feature(FW_FEATURE_CMO)) |
| 825 | return; |
| 826 | |
| 827 | pSeries_set_page_state(page, order, H_PAGE_SET_UNUSED); |
| 828 | } |
| 829 | EXPORT_SYMBOL(arch_free_page); |
| 830 | |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 831 | #endif /* CONFIG_PPC_SMLPAR */ |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 832 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 833 | |
| 834 | #ifdef CONFIG_TRACEPOINTS |
Masahiro Yamada | 0276ebf | 2018-12-31 00:14:15 +0900 | [diff] [blame] | 835 | #ifdef CONFIG_JUMP_LABEL |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 836 | struct static_key hcall_tracepoint_key = STATIC_KEY_INIT; |
| 837 | |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 838 | int hcall_tracepoint_regfunc(void) |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 839 | { |
| 840 | static_key_slow_inc(&hcall_tracepoint_key); |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 841 | return 0; |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | void hcall_tracepoint_unregfunc(void) |
| 845 | { |
| 846 | static_key_slow_dec(&hcall_tracepoint_key); |
| 847 | } |
| 848 | #else |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 849 | /* |
| 850 | * We optimise our hcall path by placing hcall_tracepoint_refcount |
| 851 | * directly in the TOC so we can check if the hcall tracepoints are |
| 852 | * enabled via a single load. |
| 853 | */ |
| 854 | |
| 855 | /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ |
| 856 | extern long hcall_tracepoint_refcount; |
| 857 | |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 858 | int hcall_tracepoint_regfunc(void) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 859 | { |
| 860 | hcall_tracepoint_refcount++; |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 861 | return 0; |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | void hcall_tracepoint_unregfunc(void) |
| 865 | { |
| 866 | hcall_tracepoint_refcount--; |
| 867 | } |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 868 | #endif |
| 869 | |
| 870 | /* |
| 871 | * Since the tracing code might execute hcalls we need to guard against |
| 872 | * recursion. One example of this are spinlocks calling H_YIELD on |
| 873 | * shared processor partitions. |
| 874 | */ |
| 875 | static DEFINE_PER_CPU(unsigned int, hcall_trace_depth); |
| 876 | |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 877 | |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 878 | void __trace_hcall_entry(unsigned long opcode, unsigned long *args) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 879 | { |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 880 | unsigned long flags; |
| 881 | unsigned int *depth; |
| 882 | |
Anton Blanchard | a5ccfee | 2012-01-09 14:29:15 +0000 | [diff] [blame] | 883 | /* |
| 884 | * We cannot call tracepoints inside RCU idle regions which |
| 885 | * means we must not trace H_CEDE. |
| 886 | */ |
| 887 | if (opcode == H_CEDE) |
| 888 | return; |
| 889 | |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 890 | local_irq_save(flags); |
| 891 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 892 | depth = this_cpu_ptr(&hcall_trace_depth); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 893 | |
| 894 | if (*depth) |
| 895 | goto out; |
| 896 | |
| 897 | (*depth)++; |
Li Zhong | e4f387d | 2011-12-18 16:03:04 +0000 | [diff] [blame] | 898 | preempt_disable(); |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 899 | trace_hcall_entry(opcode, args); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 900 | (*depth)--; |
| 901 | |
| 902 | out: |
| 903 | local_irq_restore(flags); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Michael Ellerman | 8f2133c | 2018-05-07 23:03:55 +1000 | [diff] [blame] | 906 | void __trace_hcall_exit(long opcode, long retval, unsigned long *retbuf) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 907 | { |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 908 | unsigned long flags; |
| 909 | unsigned int *depth; |
| 910 | |
Anton Blanchard | a5ccfee | 2012-01-09 14:29:15 +0000 | [diff] [blame] | 911 | if (opcode == H_CEDE) |
| 912 | return; |
| 913 | |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 914 | local_irq_save(flags); |
| 915 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 916 | depth = this_cpu_ptr(&hcall_trace_depth); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 917 | |
| 918 | if (*depth) |
| 919 | goto out; |
| 920 | |
| 921 | (*depth)++; |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 922 | trace_hcall_exit(opcode, retval, retbuf); |
Li Zhong | e4f387d | 2011-12-18 16:03:04 +0000 | [diff] [blame] | 923 | preempt_enable(); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 924 | (*depth)--; |
| 925 | |
| 926 | out: |
| 927 | local_irq_restore(flags); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 928 | } |
| 929 | #endif |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 930 | |
| 931 | /** |
| 932 | * h_get_mpp |
| 933 | * H_GET_MPP hcall returns info in 7 parms |
| 934 | */ |
| 935 | int h_get_mpp(struct hvcall_mpp_data *mpp_data) |
| 936 | { |
| 937 | int rc; |
| 938 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; |
| 939 | |
| 940 | rc = plpar_hcall9(H_GET_MPP, retbuf); |
| 941 | |
| 942 | mpp_data->entitled_mem = retbuf[0]; |
| 943 | mpp_data->mapped_mem = retbuf[1]; |
| 944 | |
| 945 | mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff; |
| 946 | mpp_data->pool_num = retbuf[2] & 0xffff; |
| 947 | |
| 948 | mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff; |
| 949 | mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff; |
Anton Blanchard | b0d436c | 2013-08-07 02:01:24 +1000 | [diff] [blame] | 950 | mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffffUL; |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 951 | |
| 952 | mpp_data->pool_size = retbuf[4]; |
| 953 | mpp_data->loan_request = retbuf[5]; |
| 954 | mpp_data->backing_mem = retbuf[6]; |
| 955 | |
| 956 | return rc; |
| 957 | } |
| 958 | EXPORT_SYMBOL(h_get_mpp); |
| 959 | |
| 960 | int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data) |
| 961 | { |
| 962 | int rc; |
| 963 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE] = { 0 }; |
| 964 | |
| 965 | rc = plpar_hcall9(H_GET_MPP_X, retbuf); |
| 966 | |
| 967 | mpp_x_data->coalesced_bytes = retbuf[0]; |
| 968 | mpp_x_data->pool_coalesced_bytes = retbuf[1]; |
| 969 | mpp_x_data->pool_purr_cycles = retbuf[2]; |
| 970 | mpp_x_data->pool_spurr_cycles = retbuf[3]; |
| 971 | |
| 972 | return rc; |
| 973 | } |
Aneesh Kumar K.V | 82228e3 | 2017-03-22 09:07:00 +0530 | [diff] [blame] | 974 | |
| 975 | static unsigned long vsid_unscramble(unsigned long vsid, int ssize) |
| 976 | { |
| 977 | unsigned long protovsid; |
| 978 | unsigned long va_bits = VA_BITS; |
| 979 | unsigned long modinv, vsid_modulus; |
| 980 | unsigned long max_mod_inv, tmp_modinv; |
| 981 | |
| 982 | if (!mmu_has_feature(MMU_FTR_68_BIT_VA)) |
| 983 | va_bits = 65; |
| 984 | |
| 985 | if (ssize == MMU_SEGSIZE_256M) { |
| 986 | modinv = VSID_MULINV_256M; |
| 987 | vsid_modulus = ((1UL << (va_bits - SID_SHIFT)) - 1); |
| 988 | } else { |
| 989 | modinv = VSID_MULINV_1T; |
| 990 | vsid_modulus = ((1UL << (va_bits - SID_SHIFT_1T)) - 1); |
| 991 | } |
| 992 | |
| 993 | /* |
| 994 | * vsid outside our range. |
| 995 | */ |
| 996 | if (vsid >= vsid_modulus) |
| 997 | return 0; |
| 998 | |
| 999 | /* |
| 1000 | * If modinv is the modular multiplicate inverse of (x % vsid_modulus) |
| 1001 | * and vsid = (protovsid * x) % vsid_modulus, then we say: |
| 1002 | * protovsid = (vsid * modinv) % vsid_modulus |
| 1003 | */ |
| 1004 | |
| 1005 | /* Check if (vsid * modinv) overflow (63 bits) */ |
| 1006 | max_mod_inv = 0x7fffffffffffffffull / vsid; |
| 1007 | if (modinv < max_mod_inv) |
| 1008 | return (vsid * modinv) % vsid_modulus; |
| 1009 | |
| 1010 | tmp_modinv = modinv/max_mod_inv; |
| 1011 | modinv %= max_mod_inv; |
| 1012 | |
| 1013 | protovsid = (((vsid * max_mod_inv) % vsid_modulus) * tmp_modinv) % vsid_modulus; |
| 1014 | protovsid = (protovsid + vsid * modinv) % vsid_modulus; |
| 1015 | |
| 1016 | return protovsid; |
| 1017 | } |
| 1018 | |
| 1019 | static int __init reserve_vrma_context_id(void) |
| 1020 | { |
| 1021 | unsigned long protovsid; |
| 1022 | |
| 1023 | /* |
| 1024 | * Reserve context ids which map to reserved virtual addresses. For now |
| 1025 | * we only reserve the context id which maps to the VRMA VSID. We ignore |
| 1026 | * the addresses in "ibm,adjunct-virtual-addresses" because we don't |
| 1027 | * enable adjunct support via the "ibm,client-architecture-support" |
| 1028 | * interface. |
| 1029 | */ |
| 1030 | protovsid = vsid_unscramble(VRMA_VSID, MMU_SEGSIZE_1T); |
| 1031 | hash__reserve_context_id(protovsid >> ESID_BITS_1T); |
| 1032 | return 0; |
| 1033 | } |
| 1034 | machine_device_initcall(pseries, reserve_vrma_context_id); |