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> |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 33 | #include <linux/spinlock.h> |
| 34 | #include <linux/cpuhotplug.h> |
| 35 | #include <linux/workqueue.h> |
| 36 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/processor.h> |
| 38 | #include <asm/mmu.h> |
| 39 | #include <asm/page.h> |
| 40 | #include <asm/pgtable.h> |
| 41 | #include <asm/machdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/iommu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/tlb.h> |
| 45 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/cputable.h> |
David Gibson | dcad47f | 2005-11-07 09:49:43 +1100 | [diff] [blame] | 47 | #include <asm/udbg.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame] | 48 | #include <asm/smp.h> |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 49 | #include <asm/trace.h> |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 50 | #include <asm/firmware.h> |
Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 51 | #include <asm/plpar_wrappers.h> |
Hari Bathini | c1caae3 | 2014-12-18 23:36:55 +0530 | [diff] [blame] | 52 | #include <asm/kexec.h> |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 53 | #include <asm/fadump.h> |
Daniel Axtens | 42f5b4c | 2016-05-18 11:16:50 +1000 | [diff] [blame] | 54 | #include <asm/asm-prototypes.h> |
Aravinda Prasad | c6c26fb | 2018-10-16 17:20:05 +0530 | [diff] [blame] | 55 | #include <asm/debugfs.h> |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 56 | |
Michael Ellerman | 21cf913 | 2008-04-16 13:51:48 +1000 | [diff] [blame] | 57 | #include "pseries.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 59 | /* Flag bits for H_BULK_REMOVE */ |
| 60 | #define HBR_REQUEST 0x4000000000000000UL |
| 61 | #define HBR_RESPONSE 0x8000000000000000UL |
| 62 | #define HBR_END 0xc000000000000000UL |
| 63 | #define HBR_AVPN 0x0200000000000000UL |
| 64 | #define HBR_ANDCOND 0x0100000000000000UL |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 67 | /* in hvCall.S */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | EXPORT_SYMBOL(plpar_hcall); |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 69 | EXPORT_SYMBOL(plpar_hcall9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | EXPORT_SYMBOL(plpar_hcall_norets); |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 71 | |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 72 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 73 | static u8 dtl_mask = DTL_LOG_PREEMPT; |
| 74 | #else |
| 75 | static u8 dtl_mask; |
| 76 | #endif |
| 77 | |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 78 | void alloc_dtl_buffers(void) |
| 79 | { |
| 80 | int cpu; |
| 81 | struct paca_struct *pp; |
| 82 | struct dtl_entry *dtl; |
| 83 | |
| 84 | for_each_possible_cpu(cpu) { |
| 85 | pp = paca_ptrs[cpu]; |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 86 | if (pp->dispatch_log) |
| 87 | continue; |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 88 | dtl = kmem_cache_alloc(dtl_cache, GFP_KERNEL); |
| 89 | if (!dtl) { |
| 90 | pr_warn("Failed to allocate dispatch trace log for cpu %d\n", |
| 91 | cpu); |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 92 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 93 | pr_warn("Stolen time statistics will be unreliable\n"); |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 94 | #endif |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 95 | break; |
| 96 | } |
| 97 | |
| 98 | pp->dtl_ridx = 0; |
| 99 | pp->dispatch_log = dtl; |
| 100 | pp->dispatch_log_end = dtl + N_DISPATCH_LOG; |
| 101 | pp->dtl_curr = dtl; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void register_dtl_buffer(int cpu) |
| 106 | { |
| 107 | long ret; |
| 108 | struct paca_struct *pp; |
| 109 | struct dtl_entry *dtl; |
| 110 | int hwcpu = get_hard_smp_processor_id(cpu); |
| 111 | |
| 112 | pp = paca_ptrs[cpu]; |
| 113 | dtl = pp->dispatch_log; |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 114 | if (dtl && dtl_mask) { |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 115 | pp->dtl_ridx = 0; |
| 116 | pp->dtl_curr = dtl; |
| 117 | lppaca_of(cpu).dtl_idx = 0; |
| 118 | |
| 119 | /* hypervisor reads buffer length from this field */ |
| 120 | dtl->enqueue_to_dispatch_time = cpu_to_be32(DISPATCH_LOG_BYTES); |
| 121 | ret = register_dtl(hwcpu, __pa(dtl)); |
| 122 | if (ret) |
| 123 | pr_err("WARNING: DTL registration of cpu %d (hw %d) failed with %ld\n", |
| 124 | cpu, hwcpu, ret); |
| 125 | |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 126 | lppaca_of(cpu).dtl_enable_mask = dtl_mask; |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Naveen N. Rao | 06220d7 | 2019-07-03 22:33:57 +0530 | [diff] [blame] | 130 | #ifdef CONFIG_PPC_SPLPAR |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 131 | struct dtl_worker { |
| 132 | struct delayed_work work; |
| 133 | int cpu; |
| 134 | }; |
| 135 | |
| 136 | struct vcpu_dispatch_data { |
| 137 | int last_disp_cpu; |
| 138 | |
| 139 | int total_disp; |
| 140 | |
| 141 | int same_cpu_disp; |
| 142 | int same_chip_disp; |
| 143 | int diff_chip_disp; |
| 144 | int far_chip_disp; |
| 145 | |
| 146 | int numa_home_disp; |
| 147 | int numa_remote_disp; |
| 148 | int numa_far_disp; |
| 149 | }; |
| 150 | |
| 151 | /* |
| 152 | * This represents the number of cpus in the hypervisor. Since there is no |
| 153 | * architected way to discover the number of processors in the host, we |
| 154 | * provision for dealing with NR_CPUS. This is currently 2048 by default, and |
| 155 | * is sufficient for our purposes. This will need to be tweaked if |
| 156 | * CONFIG_NR_CPUS is changed. |
| 157 | */ |
| 158 | #define NR_CPUS_H NR_CPUS |
| 159 | |
Naveen N. Rao | 06220d7 | 2019-07-03 22:33:57 +0530 | [diff] [blame] | 160 | DEFINE_RWLOCK(dtl_access_lock); |
Naveen N. Rao | d62c8de | 2019-07-03 22:34:00 +0530 | [diff] [blame^] | 161 | static DEFINE_PER_CPU(struct vcpu_dispatch_data, vcpu_disp_data); |
| 162 | static DEFINE_PER_CPU(u64, dtl_entry_ridx); |
| 163 | static DEFINE_PER_CPU(struct dtl_worker, dtl_workers); |
| 164 | static enum cpuhp_state dtl_worker_state; |
| 165 | static DEFINE_MUTEX(dtl_enable_mutex); |
| 166 | static int vcpudispatch_stats_on __read_mostly; |
| 167 | static int vcpudispatch_stats_freq = 50; |
| 168 | static __be32 *vcpu_associativity, *pcpu_associativity; |
| 169 | |
| 170 | |
| 171 | static void free_dtl_buffers(void) |
| 172 | { |
| 173 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 174 | int cpu; |
| 175 | struct paca_struct *pp; |
| 176 | |
| 177 | for_each_possible_cpu(cpu) { |
| 178 | pp = paca_ptrs[cpu]; |
| 179 | if (!pp->dispatch_log) |
| 180 | continue; |
| 181 | kmem_cache_free(dtl_cache, pp->dispatch_log); |
| 182 | pp->dtl_ridx = 0; |
| 183 | pp->dispatch_log = 0; |
| 184 | pp->dispatch_log_end = 0; |
| 185 | pp->dtl_curr = 0; |
| 186 | } |
| 187 | #endif |
| 188 | } |
| 189 | |
| 190 | static int init_cpu_associativity(void) |
| 191 | { |
| 192 | vcpu_associativity = kcalloc(num_possible_cpus() / threads_per_core, |
| 193 | VPHN_ASSOC_BUFSIZE * sizeof(__be32), GFP_KERNEL); |
| 194 | pcpu_associativity = kcalloc(NR_CPUS_H / threads_per_core, |
| 195 | VPHN_ASSOC_BUFSIZE * sizeof(__be32), GFP_KERNEL); |
| 196 | |
| 197 | if (!vcpu_associativity || !pcpu_associativity) { |
| 198 | pr_err("error allocating memory for associativity information\n"); |
| 199 | return -ENOMEM; |
| 200 | } |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static void destroy_cpu_associativity(void) |
| 206 | { |
| 207 | kfree(vcpu_associativity); |
| 208 | kfree(pcpu_associativity); |
| 209 | vcpu_associativity = pcpu_associativity = 0; |
| 210 | } |
| 211 | |
| 212 | static __be32 *__get_cpu_associativity(int cpu, __be32 *cpu_assoc, int flag) |
| 213 | { |
| 214 | __be32 *assoc; |
| 215 | int rc = 0; |
| 216 | |
| 217 | assoc = &cpu_assoc[(int)(cpu / threads_per_core) * VPHN_ASSOC_BUFSIZE]; |
| 218 | if (!assoc[0]) { |
| 219 | rc = hcall_vphn(cpu, flag, &assoc[0]); |
| 220 | if (rc) |
| 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | return assoc; |
| 225 | } |
| 226 | |
| 227 | static __be32 *get_pcpu_associativity(int cpu) |
| 228 | { |
| 229 | return __get_cpu_associativity(cpu, pcpu_associativity, VPHN_FLAG_PCPU); |
| 230 | } |
| 231 | |
| 232 | static __be32 *get_vcpu_associativity(int cpu) |
| 233 | { |
| 234 | return __get_cpu_associativity(cpu, vcpu_associativity, VPHN_FLAG_VCPU); |
| 235 | } |
| 236 | |
| 237 | static int cpu_relative_dispatch_distance(int last_disp_cpu, int cur_disp_cpu) |
| 238 | { |
| 239 | __be32 *last_disp_cpu_assoc, *cur_disp_cpu_assoc; |
| 240 | |
| 241 | if (last_disp_cpu >= NR_CPUS_H || cur_disp_cpu >= NR_CPUS_H) |
| 242 | return -EINVAL; |
| 243 | |
| 244 | last_disp_cpu_assoc = get_pcpu_associativity(last_disp_cpu); |
| 245 | cur_disp_cpu_assoc = get_pcpu_associativity(cur_disp_cpu); |
| 246 | |
| 247 | if (!last_disp_cpu_assoc || !cur_disp_cpu_assoc) |
| 248 | return -EIO; |
| 249 | |
| 250 | return cpu_distance(last_disp_cpu_assoc, cur_disp_cpu_assoc); |
| 251 | } |
| 252 | |
| 253 | static int cpu_home_node_dispatch_distance(int disp_cpu) |
| 254 | { |
| 255 | __be32 *disp_cpu_assoc, *vcpu_assoc; |
| 256 | int vcpu_id = smp_processor_id(); |
| 257 | |
| 258 | if (disp_cpu >= NR_CPUS_H) { |
| 259 | pr_debug_ratelimited("vcpu dispatch cpu %d > %d\n", |
| 260 | disp_cpu, NR_CPUS_H); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
| 264 | disp_cpu_assoc = get_pcpu_associativity(disp_cpu); |
| 265 | vcpu_assoc = get_vcpu_associativity(vcpu_id); |
| 266 | |
| 267 | if (!disp_cpu_assoc || !vcpu_assoc) |
| 268 | return -EIO; |
| 269 | |
| 270 | return cpu_distance(disp_cpu_assoc, vcpu_assoc); |
| 271 | } |
| 272 | |
| 273 | static void update_vcpu_disp_stat(int disp_cpu) |
| 274 | { |
| 275 | struct vcpu_dispatch_data *disp; |
| 276 | int distance; |
| 277 | |
| 278 | disp = this_cpu_ptr(&vcpu_disp_data); |
| 279 | if (disp->last_disp_cpu == -1) { |
| 280 | disp->last_disp_cpu = disp_cpu; |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | disp->total_disp++; |
| 285 | |
| 286 | if (disp->last_disp_cpu == disp_cpu || |
| 287 | (cpu_first_thread_sibling(disp->last_disp_cpu) == |
| 288 | cpu_first_thread_sibling(disp_cpu))) |
| 289 | disp->same_cpu_disp++; |
| 290 | else { |
| 291 | distance = cpu_relative_dispatch_distance(disp->last_disp_cpu, |
| 292 | disp_cpu); |
| 293 | if (distance < 0) |
| 294 | pr_debug_ratelimited("vcpudispatch_stats: cpu %d: error determining associativity\n", |
| 295 | smp_processor_id()); |
| 296 | else { |
| 297 | switch (distance) { |
| 298 | case 0: |
| 299 | disp->same_chip_disp++; |
| 300 | break; |
| 301 | case 1: |
| 302 | disp->diff_chip_disp++; |
| 303 | break; |
| 304 | case 2: |
| 305 | disp->far_chip_disp++; |
| 306 | break; |
| 307 | default: |
| 308 | pr_debug_ratelimited("vcpudispatch_stats: cpu %d (%d -> %d): unexpected relative dispatch distance %d\n", |
| 309 | smp_processor_id(), |
| 310 | disp->last_disp_cpu, |
| 311 | disp_cpu, |
| 312 | distance); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | distance = cpu_home_node_dispatch_distance(disp_cpu); |
| 318 | if (distance < 0) |
| 319 | pr_debug_ratelimited("vcpudispatch_stats: cpu %d: error determining associativity\n", |
| 320 | smp_processor_id()); |
| 321 | else { |
| 322 | switch (distance) { |
| 323 | case 0: |
| 324 | disp->numa_home_disp++; |
| 325 | break; |
| 326 | case 1: |
| 327 | disp->numa_remote_disp++; |
| 328 | break; |
| 329 | case 2: |
| 330 | disp->numa_far_disp++; |
| 331 | break; |
| 332 | default: |
| 333 | pr_debug_ratelimited("vcpudispatch_stats: cpu %d on %d: unexpected numa dispatch distance %d\n", |
| 334 | smp_processor_id(), |
| 335 | disp_cpu, |
| 336 | distance); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | disp->last_disp_cpu = disp_cpu; |
| 341 | } |
| 342 | |
| 343 | static void process_dtl_buffer(struct work_struct *work) |
| 344 | { |
| 345 | struct dtl_entry dtle; |
| 346 | u64 i = __this_cpu_read(dtl_entry_ridx); |
| 347 | struct dtl_entry *dtl = local_paca->dispatch_log + (i % N_DISPATCH_LOG); |
| 348 | struct dtl_entry *dtl_end = local_paca->dispatch_log_end; |
| 349 | struct lppaca *vpa = local_paca->lppaca_ptr; |
| 350 | struct dtl_worker *d = container_of(work, struct dtl_worker, work.work); |
| 351 | |
| 352 | if (!local_paca->dispatch_log) |
| 353 | return; |
| 354 | |
| 355 | /* if we have been migrated away, we cancel ourself */ |
| 356 | if (d->cpu != smp_processor_id()) { |
| 357 | pr_debug("vcpudispatch_stats: cpu %d worker migrated -- canceling worker\n", |
| 358 | smp_processor_id()); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | if (i == be64_to_cpu(vpa->dtl_idx)) |
| 363 | goto out; |
| 364 | |
| 365 | while (i < be64_to_cpu(vpa->dtl_idx)) { |
| 366 | dtle = *dtl; |
| 367 | barrier(); |
| 368 | if (i + N_DISPATCH_LOG < be64_to_cpu(vpa->dtl_idx)) { |
| 369 | /* buffer has overflowed */ |
| 370 | pr_debug_ratelimited("vcpudispatch_stats: cpu %d lost %lld DTL samples\n", |
| 371 | d->cpu, |
| 372 | be64_to_cpu(vpa->dtl_idx) - N_DISPATCH_LOG - i); |
| 373 | i = be64_to_cpu(vpa->dtl_idx) - N_DISPATCH_LOG; |
| 374 | dtl = local_paca->dispatch_log + (i % N_DISPATCH_LOG); |
| 375 | continue; |
| 376 | } |
| 377 | update_vcpu_disp_stat(be16_to_cpu(dtle.processor_id)); |
| 378 | ++i; |
| 379 | ++dtl; |
| 380 | if (dtl == dtl_end) |
| 381 | dtl = local_paca->dispatch_log; |
| 382 | } |
| 383 | |
| 384 | __this_cpu_write(dtl_entry_ridx, i); |
| 385 | |
| 386 | out: |
| 387 | schedule_delayed_work_on(d->cpu, to_delayed_work(work), |
| 388 | HZ / vcpudispatch_stats_freq); |
| 389 | } |
| 390 | |
| 391 | static int dtl_worker_online(unsigned int cpu) |
| 392 | { |
| 393 | struct dtl_worker *d = &per_cpu(dtl_workers, cpu); |
| 394 | |
| 395 | memset(d, 0, sizeof(*d)); |
| 396 | INIT_DELAYED_WORK(&d->work, process_dtl_buffer); |
| 397 | d->cpu = cpu; |
| 398 | |
| 399 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 400 | per_cpu(dtl_entry_ridx, cpu) = 0; |
| 401 | register_dtl_buffer(cpu); |
| 402 | #else |
| 403 | per_cpu(dtl_entry_ridx, cpu) = be64_to_cpu(lppaca_of(cpu).dtl_idx); |
| 404 | #endif |
| 405 | |
| 406 | schedule_delayed_work_on(cpu, &d->work, HZ / vcpudispatch_stats_freq); |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | static int dtl_worker_offline(unsigned int cpu) |
| 411 | { |
| 412 | struct dtl_worker *d = &per_cpu(dtl_workers, cpu); |
| 413 | |
| 414 | cancel_delayed_work_sync(&d->work); |
| 415 | |
| 416 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 417 | unregister_dtl(get_hard_smp_processor_id(cpu)); |
| 418 | #endif |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | static void set_global_dtl_mask(u8 mask) |
| 424 | { |
| 425 | int cpu; |
| 426 | |
| 427 | dtl_mask = mask; |
| 428 | for_each_present_cpu(cpu) |
| 429 | lppaca_of(cpu).dtl_enable_mask = dtl_mask; |
| 430 | } |
| 431 | |
| 432 | static void reset_global_dtl_mask(void) |
| 433 | { |
| 434 | int cpu; |
| 435 | |
| 436 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 437 | dtl_mask = DTL_LOG_PREEMPT; |
| 438 | #else |
| 439 | dtl_mask = 0; |
| 440 | #endif |
| 441 | for_each_present_cpu(cpu) |
| 442 | lppaca_of(cpu).dtl_enable_mask = dtl_mask; |
| 443 | } |
| 444 | |
| 445 | static int dtl_worker_enable(void) |
| 446 | { |
| 447 | int rc = 0, state; |
| 448 | |
| 449 | if (!write_trylock(&dtl_access_lock)) { |
| 450 | rc = -EBUSY; |
| 451 | goto out; |
| 452 | } |
| 453 | |
| 454 | set_global_dtl_mask(DTL_LOG_ALL); |
| 455 | |
| 456 | /* Setup dtl buffers and register those */ |
| 457 | alloc_dtl_buffers(); |
| 458 | |
| 459 | state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powerpc/dtl:online", |
| 460 | dtl_worker_online, dtl_worker_offline); |
| 461 | if (state < 0) { |
| 462 | pr_err("vcpudispatch_stats: unable to setup workqueue for DTL processing\n"); |
| 463 | free_dtl_buffers(); |
| 464 | reset_global_dtl_mask(); |
| 465 | write_unlock(&dtl_access_lock); |
| 466 | rc = -EINVAL; |
| 467 | goto out; |
| 468 | } |
| 469 | dtl_worker_state = state; |
| 470 | |
| 471 | out: |
| 472 | return rc; |
| 473 | } |
| 474 | |
| 475 | static void dtl_worker_disable(void) |
| 476 | { |
| 477 | cpuhp_remove_state(dtl_worker_state); |
| 478 | free_dtl_buffers(); |
| 479 | reset_global_dtl_mask(); |
| 480 | write_unlock(&dtl_access_lock); |
| 481 | } |
| 482 | |
| 483 | static ssize_t vcpudispatch_stats_write(struct file *file, const char __user *p, |
| 484 | size_t count, loff_t *ppos) |
| 485 | { |
| 486 | struct vcpu_dispatch_data *disp; |
| 487 | int rc, cmd, cpu; |
| 488 | char buf[16]; |
| 489 | |
| 490 | if (count > 15) |
| 491 | return -EINVAL; |
| 492 | |
| 493 | if (copy_from_user(buf, p, count)) |
| 494 | return -EFAULT; |
| 495 | |
| 496 | buf[count] = 0; |
| 497 | rc = kstrtoint(buf, 0, &cmd); |
| 498 | if (rc || cmd < 0 || cmd > 1) { |
| 499 | pr_err("vcpudispatch_stats: please use 0 to disable or 1 to enable dispatch statistics\n"); |
| 500 | return rc ? rc : -EINVAL; |
| 501 | } |
| 502 | |
| 503 | mutex_lock(&dtl_enable_mutex); |
| 504 | |
| 505 | if ((cmd == 0 && !vcpudispatch_stats_on) || |
| 506 | (cmd == 1 && vcpudispatch_stats_on)) |
| 507 | goto out; |
| 508 | |
| 509 | if (cmd) { |
| 510 | rc = init_cpu_associativity(); |
| 511 | if (rc) |
| 512 | goto out; |
| 513 | |
| 514 | for_each_possible_cpu(cpu) { |
| 515 | disp = per_cpu_ptr(&vcpu_disp_data, cpu); |
| 516 | memset(disp, 0, sizeof(*disp)); |
| 517 | disp->last_disp_cpu = -1; |
| 518 | } |
| 519 | |
| 520 | rc = dtl_worker_enable(); |
| 521 | if (rc) { |
| 522 | destroy_cpu_associativity(); |
| 523 | goto out; |
| 524 | } |
| 525 | } else { |
| 526 | dtl_worker_disable(); |
| 527 | destroy_cpu_associativity(); |
| 528 | } |
| 529 | |
| 530 | vcpudispatch_stats_on = cmd; |
| 531 | |
| 532 | out: |
| 533 | mutex_unlock(&dtl_enable_mutex); |
| 534 | if (rc) |
| 535 | return rc; |
| 536 | return count; |
| 537 | } |
| 538 | |
| 539 | static int vcpudispatch_stats_display(struct seq_file *p, void *v) |
| 540 | { |
| 541 | int cpu; |
| 542 | struct vcpu_dispatch_data *disp; |
| 543 | |
| 544 | if (!vcpudispatch_stats_on) { |
| 545 | seq_puts(p, "off\n"); |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | for_each_online_cpu(cpu) { |
| 550 | disp = per_cpu_ptr(&vcpu_disp_data, cpu); |
| 551 | seq_printf(p, "cpu%d", cpu); |
| 552 | seq_put_decimal_ull(p, " ", disp->total_disp); |
| 553 | seq_put_decimal_ull(p, " ", disp->same_cpu_disp); |
| 554 | seq_put_decimal_ull(p, " ", disp->same_chip_disp); |
| 555 | seq_put_decimal_ull(p, " ", disp->diff_chip_disp); |
| 556 | seq_put_decimal_ull(p, " ", disp->far_chip_disp); |
| 557 | seq_put_decimal_ull(p, " ", disp->numa_home_disp); |
| 558 | seq_put_decimal_ull(p, " ", disp->numa_remote_disp); |
| 559 | seq_put_decimal_ull(p, " ", disp->numa_far_disp); |
| 560 | seq_puts(p, "\n"); |
| 561 | } |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int vcpudispatch_stats_open(struct inode *inode, struct file *file) |
| 567 | { |
| 568 | return single_open(file, vcpudispatch_stats_display, NULL); |
| 569 | } |
| 570 | |
| 571 | static const struct file_operations vcpudispatch_stats_proc_ops = { |
| 572 | .open = vcpudispatch_stats_open, |
| 573 | .read = seq_read, |
| 574 | .write = vcpudispatch_stats_write, |
| 575 | .llseek = seq_lseek, |
| 576 | .release = single_release, |
| 577 | }; |
| 578 | |
| 579 | static ssize_t vcpudispatch_stats_freq_write(struct file *file, |
| 580 | const char __user *p, size_t count, loff_t *ppos) |
| 581 | { |
| 582 | int rc, freq; |
| 583 | char buf[16]; |
| 584 | |
| 585 | if (count > 15) |
| 586 | return -EINVAL; |
| 587 | |
| 588 | if (copy_from_user(buf, p, count)) |
| 589 | return -EFAULT; |
| 590 | |
| 591 | buf[count] = 0; |
| 592 | rc = kstrtoint(buf, 0, &freq); |
| 593 | if (rc || freq < 1 || freq > HZ) { |
| 594 | pr_err("vcpudispatch_stats_freq: please specify a frequency between 1 and %d\n", |
| 595 | HZ); |
| 596 | return rc ? rc : -EINVAL; |
| 597 | } |
| 598 | |
| 599 | vcpudispatch_stats_freq = freq; |
| 600 | |
| 601 | return count; |
| 602 | } |
| 603 | |
| 604 | static int vcpudispatch_stats_freq_display(struct seq_file *p, void *v) |
| 605 | { |
| 606 | seq_printf(p, "%d\n", vcpudispatch_stats_freq); |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static int vcpudispatch_stats_freq_open(struct inode *inode, struct file *file) |
| 611 | { |
| 612 | return single_open(file, vcpudispatch_stats_freq_display, NULL); |
| 613 | } |
| 614 | |
| 615 | static const struct file_operations vcpudispatch_stats_freq_proc_ops = { |
| 616 | .open = vcpudispatch_stats_freq_open, |
| 617 | .read = seq_read, |
| 618 | .write = vcpudispatch_stats_freq_write, |
| 619 | .llseek = seq_lseek, |
| 620 | .release = single_release, |
| 621 | }; |
| 622 | |
| 623 | static int __init vcpudispatch_stats_procfs_init(void) |
| 624 | { |
| 625 | if (!lppaca_shared_proc(get_lppaca())) |
| 626 | return 0; |
| 627 | |
| 628 | if (!proc_create("powerpc/vcpudispatch_stats", 0600, NULL, |
| 629 | &vcpudispatch_stats_proc_ops)) |
| 630 | pr_err("vcpudispatch_stats: error creating procfs file\n"); |
| 631 | else if (!proc_create("powerpc/vcpudispatch_stats_freq", 0600, NULL, |
| 632 | &vcpudispatch_stats_freq_proc_ops)) |
| 633 | pr_err("vcpudispatch_stats_freq: error creating procfs file\n"); |
| 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | machine_device_initcall(pseries, vcpudispatch_stats_procfs_init); |
Naveen N. Rao | 06220d7 | 2019-07-03 22:33:57 +0530 | [diff] [blame] | 639 | #endif /* CONFIG_PPC_SPLPAR */ |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | void vpa_init(int cpu) |
| 642 | { |
| 643 | int hwcpu = get_hard_smp_processor_id(cpu); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 644 | unsigned long addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | long ret; |
Olof Johansson | 233ccd0 | 2005-09-03 15:55:59 -0700 | [diff] [blame] | 646 | |
Michael Ellerman | b89bdfb | 2013-08-15 15:22:15 +1000 | [diff] [blame] | 647 | /* |
| 648 | * The spec says it "may be problematic" if CPU x registers the VPA of |
| 649 | * CPU y. We should never do that, but wail if we ever do. |
| 650 | */ |
| 651 | WARN_ON(cpu != smp_processor_id()); |
| 652 | |
Olof Johansson | 233ccd0 | 2005-09-03 15:55:59 -0700 | [diff] [blame] | 653 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
Paul Mackerras | 8154c5d | 2010-08-12 20:18:15 +0000 | [diff] [blame] | 654 | lppaca_of(cpu).vmxregs_in_use = 1; |
Olof Johansson | 233ccd0 | 2005-09-03 15:55:59 -0700 | [diff] [blame] | 655 | |
Michael Ellerman | 6e0b8bc9 | 2013-06-28 18:15:18 +1000 | [diff] [blame] | 656 | if (cpu_has_feature(CPU_FTR_ARCH_207S)) |
| 657 | lppaca_of(cpu).ebb_regs_in_use = 1; |
| 658 | |
Paul Mackerras | 8154c5d | 2010-08-12 20:18:15 +0000 | [diff] [blame] | 659 | addr = __pa(&lppaca_of(cpu)); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 660 | ret = register_vpa(hwcpu, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 662 | if (ret) { |
Anton Blanchard | 711ef84 | 2011-07-25 01:46:33 +0000 | [diff] [blame] | 663 | pr_err("WARNING: VPA registration for cpu %d (hw %d) of area " |
| 664 | "%lx failed with %ld\n", cpu, hwcpu, addr, ret); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 665 | return; |
| 666 | } |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 667 | |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 668 | #ifdef CONFIG_PPC_BOOK3S_64 |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 669 | /* |
| 670 | * PAPR says this feature is SLB-Buffer but firmware never |
| 671 | * reports that. All SPLPAR support SLB shadow buffer. |
| 672 | */ |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 673 | if (!radix_enabled() && firmware_has_feature(FW_FEATURE_SPLPAR)) { |
Nicholas Piggin | d2e6007 | 2018-02-14 01:08:12 +1000 | [diff] [blame] | 674 | addr = __pa(paca_ptrs[cpu]->slb_shadow_ptr); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 675 | ret = register_slb_shadow(hwcpu, addr); |
| 676 | if (ret) |
Anton Blanchard | 711ef84 | 2011-07-25 01:46:33 +0000 | [diff] [blame] | 677 | pr_err("WARNING: SLB shadow buffer registration for " |
| 678 | "cpu %d (hw %d) of area %lx failed with %ld\n", |
| 679 | cpu, hwcpu, addr, ret); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 680 | } |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 681 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 682 | |
| 683 | /* |
| 684 | * Register dispatch trace log, if one has been allocated. |
| 685 | */ |
Naveen N. Rao | 1c85a2a1 | 2019-07-03 22:33:56 +0530 | [diff] [blame] | 686 | register_dtl_buffer(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 689 | #ifdef CONFIG_PPC_BOOK3S_64 |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 690 | |
Geoff Levand | 035223f | 2006-10-05 11:35:10 -0700 | [diff] [blame] | 691 | static long pSeries_lpar_hpte_insert(unsigned long hpte_group, |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 692 | unsigned long vpn, unsigned long pa, |
| 693 | unsigned long rflags, unsigned long vflags, |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 694 | int psize, int apsize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | unsigned long lpar_rc; |
| 697 | unsigned long flags; |
| 698 | unsigned long slot; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 699 | unsigned long hpte_v, hpte_r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 701 | if (!(vflags & HPTE_V_BOLTED)) |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 702 | pr_devel("hpte_insert(group=%lx, vpn=%016lx, " |
| 703 | "pa=%016lx, rflags=%lx, vflags=%lx, psize=%d)\n", |
| 704 | hpte_group, vpn, pa, rflags, vflags, psize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 706 | 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] | 707 | hpte_r = hpte_encode_r(pa, psize, apsize) | rflags; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 708 | |
| 709 | if (!(vflags & HPTE_V_BOLTED)) |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 710 | 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] | 711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | /* Now fill in the actual HPTE */ |
| 713 | /* Set CEC cookie to 0 */ |
| 714 | /* Zero page = 0 */ |
| 715 | /* I-cache Invalidate = 0 */ |
| 716 | /* I-cache synchronize = 0 */ |
| 717 | /* Exact = 0 */ |
| 718 | flags = 0; |
| 719 | |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 720 | if (firmware_has_feature(FW_FEATURE_XCMO) && !(hpte_r & HPTE_R_N)) |
| 721 | flags |= H_COALESCE_CAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 723 | 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] | 724 | if (unlikely(lpar_rc == H_PTEG_FULL)) { |
Aneesh Kumar K.V | ca42d8d2d | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 725 | pr_devel("Hash table group is full\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return -1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
| 729 | /* |
| 730 | * Since we try and ioremap PHBs we don't own, the pte insert |
| 731 | * will fail. However we must catch the failure in hash_page |
| 732 | * or we will loop forever, so return -2 in this case. |
| 733 | */ |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 734 | if (unlikely(lpar_rc != H_SUCCESS)) { |
Aneesh Kumar K.V | ca42d8d2d | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 735 | pr_err("Failed hash pte insert with error %ld\n", lpar_rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | return -2; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 737 | } |
| 738 | if (!(vflags & HPTE_V_BOLTED)) |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 739 | pr_devel(" -> slot: %lu\n", slot & 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | /* Because of iSeries, we have to pass down the secondary |
| 742 | * bucket bit here as well |
| 743 | */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 744 | return (slot & 7) | (!!(vflags & HPTE_V_SECONDARY) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static DEFINE_SPINLOCK(pSeries_lpar_tlbie_lock); |
| 748 | |
| 749 | static long pSeries_lpar_hpte_remove(unsigned long hpte_group) |
| 750 | { |
| 751 | unsigned long slot_offset; |
| 752 | unsigned long lpar_rc; |
| 753 | int i; |
| 754 | unsigned long dummy1, dummy2; |
| 755 | |
| 756 | /* pick a random slot to start at */ |
| 757 | slot_offset = mftb() & 0x7; |
| 758 | |
| 759 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
| 760 | |
| 761 | /* don't remove a bolted entry */ |
| 762 | lpar_rc = plpar_pte_remove(H_ANDCOND, hpte_group + slot_offset, |
| 763 | (0x1UL << 4), &dummy1, &dummy2); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 764 | if (lpar_rc == H_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | return i; |
Michael Wolf | 9fb2640 | 2013-04-05 10:41:40 +0000 | [diff] [blame] | 766 | |
| 767 | /* |
| 768 | * The test for adjunct partition is performed before the |
| 769 | * ANDCOND test. H_RESOURCE may be returned, so we need to |
| 770 | * check for that as well. |
| 771 | */ |
| 772 | BUG_ON(lpar_rc != H_NOT_FOUND && lpar_rc != H_RESOURCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | slot_offset++; |
| 775 | slot_offset &= 0x7; |
| 776 | } |
| 777 | |
| 778 | return -1; |
| 779 | } |
| 780 | |
Anton Blanchard | 5246ade | 2016-10-01 20:41:56 +1000 | [diff] [blame] | 781 | static void manual_hpte_clear_all(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
| 783 | unsigned long size_bytes = 1UL << ppc64_pft_size; |
| 784 | unsigned long hpte_count = size_bytes >> 4; |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 785 | struct { |
| 786 | unsigned long pteh; |
| 787 | unsigned long ptel; |
| 788 | } ptes[4]; |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 789 | long lpar_rc; |
Anton Blanchard | bed9a31 | 2011-07-26 18:15:03 +0000 | [diff] [blame] | 790 | unsigned long i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 792 | /* Read in batches of 4, |
| 793 | * invalidate only valid entries not in the VRMA |
| 794 | * hpte_count will be a multiple of 4 |
| 795 | */ |
| 796 | for (i = 0; i < hpte_count; i += 4) { |
| 797 | lpar_rc = plpar_pte_read_4_raw(0, i, (void *)ptes); |
Aneesh Kumar K.V | ca42d8d2d | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 798 | if (lpar_rc != H_SUCCESS) { |
| 799 | pr_info("Failed to read hash page table at %ld err %ld\n", |
| 800 | i, lpar_rc); |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 801 | continue; |
Aneesh Kumar K.V | ca42d8d2d | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 802 | } |
Michael Neuling | d504bed | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 803 | for (j = 0; j < 4; j++){ |
| 804 | if ((ptes[j].pteh & HPTE_V_VRMA_MASK) == |
| 805 | HPTE_V_VRMA_MASK) |
| 806 | continue; |
| 807 | if (ptes[j].pteh & HPTE_V_VALID) |
| 808 | plpar_pte_remove_raw(0, i + j, 0, |
| 809 | &(ptes[j].pteh), &(ptes[j].ptel)); |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 810 | } |
| 811 | } |
Anton Blanchard | 5246ade | 2016-10-01 20:41:56 +1000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | static int hcall_hpte_clear_all(void) |
| 815 | { |
| 816 | int rc; |
| 817 | |
| 818 | do { |
| 819 | rc = plpar_hcall_norets(H_CLEAR_HPT); |
| 820 | } while (rc == H_CONTINUE); |
| 821 | |
| 822 | return rc; |
| 823 | } |
| 824 | |
| 825 | static void pseries_hpte_clear_all(void) |
| 826 | { |
| 827 | int rc; |
| 828 | |
| 829 | rc = hcall_hpte_clear_all(); |
| 830 | if (rc != H_SUCCESS) |
| 831 | manual_hpte_clear_all(); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 832 | |
| 833 | #ifdef __LITTLE_ENDIAN__ |
Hari Bathini | 408cddd | 2014-10-01 12:32:30 +0530 | [diff] [blame] | 834 | /* |
| 835 | * Reset exceptions to big endian. |
| 836 | * |
| 837 | * FIXME this is a hack for kexec, we need to reset the exception |
| 838 | * endian before starting the new kernel and this is a convenient place |
| 839 | * to do it. |
| 840 | * |
| 841 | * This is also called on boot when a fadump happens. In that case we |
| 842 | * must not change the exception endian mode. |
| 843 | */ |
Benjamin Herrenschmidt | d3cbff1 | 2016-07-05 15:03:49 +1000 | [diff] [blame] | 844 | if (firmware_has_feature(FW_FEATURE_SET_MODE) && !is_fadump_active()) |
| 845 | pseries_big_endian_exceptions(); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 846 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /* |
| 850 | * NOTE: for updatepp ops we are fortunate that the linux "newpp" bits and |
| 851 | * the low 3 bits of flags happen to line up. So no transform is needed. |
| 852 | * We can probably optimize here and assume the high bits of newpp are |
| 853 | * already zero. For now I am paranoid. |
| 854 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 855 | static long pSeries_lpar_hpte_updatepp(unsigned long slot, |
| 856 | unsigned long newpp, |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 857 | unsigned long vpn, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 858 | int psize, int apsize, |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 859 | int ssize, unsigned long inv_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | { |
| 861 | unsigned long lpar_rc; |
Balbir Singh | e71ff98 | 2017-06-29 03:04:07 +1000 | [diff] [blame] | 862 | unsigned long flags; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 863 | unsigned long want_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 865 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Balbir Singh | e71ff98 | 2017-06-29 03:04:07 +1000 | [diff] [blame] | 867 | flags = (newpp & 7) | H_AVPN; |
| 868 | if (mmu_has_feature(MMU_FTR_KERNEL_RO)) |
| 869 | /* Move pp0 into bit 8 (IBM 55) */ |
| 870 | flags |= (newpp & HPTE_R_PP0) >> 55; |
| 871 | |
Alexey Kardashevskiy | a8c0bf3 | 2018-01-09 16:52:14 +1100 | [diff] [blame] | 872 | pr_devel(" update: avpnv=%016lx, hash=%016lx, f=%lx, psize: %d ...", |
| 873 | want_v, slot, flags, psize); |
| 874 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 875 | lpar_rc = plpar_pte_protect(flags, slot, want_v); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 876 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 877 | if (lpar_rc == H_NOT_FOUND) { |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 878 | pr_devel("not found !\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | return -1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 880 | } |
| 881 | |
Michael Ellerman | 551a232 | 2009-06-17 18:13:50 +0000 | [diff] [blame] | 882 | pr_devel("ok\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 884 | BUG_ON(lpar_rc != H_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 889 | 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] | 890 | { |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 891 | long lpar_rc; |
| 892 | unsigned long i, j; |
| 893 | struct { |
| 894 | unsigned long pteh; |
| 895 | unsigned long ptel; |
| 896 | } ptes[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 898 | for (i = 0; i < HPTES_PER_GROUP; i += 4, hpte_group += 4) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 900 | lpar_rc = plpar_pte_read_4(0, hpte_group, (void *)ptes); |
Aneesh Kumar K.V | ca42d8d2d | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 901 | if (lpar_rc != H_SUCCESS) { |
| 902 | pr_info("Failed to read hash page table at %ld err %ld\n", |
| 903 | hpte_group, lpar_rc); |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 904 | continue; |
Aneesh Kumar K.V | ca42d8d2d | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 907 | for (j = 0; j < 4; j++) { |
| 908 | if (HPTE_V_COMPARE(ptes[j].pteh, want_v) && |
| 909 | (ptes[j].pteh & HPTE_V_VALID)) |
| 910 | return i + j; |
| 911 | } |
| 912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 914 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 917 | 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] | 918 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | long slot; |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 920 | unsigned long hash; |
| 921 | unsigned long want_v; |
| 922 | unsigned long hpte_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 924 | hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize); |
| 925 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 927 | /* Bolted entries are always in the primary group */ |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 928 | hpte_group = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 929 | slot = __pSeries_lpar_hpte_find(want_v, hpte_group); |
| 930 | if (slot < 0) |
| 931 | return -1; |
| 932 | return hpte_group + slot; |
| 933 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | static void pSeries_lpar_hpte_updateboltedpp(unsigned long newpp, |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 936 | unsigned long ea, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 937 | int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 939 | unsigned long vpn; |
| 940 | unsigned long lpar_rc, slot, vsid, flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 942 | vsid = get_kernel_vsid(ea, ssize); |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 943 | vpn = hpt_vpn(ea, vsid, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 945 | slot = pSeries_lpar_hpte_find(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | BUG_ON(slot == -1); |
| 947 | |
| 948 | flags = newpp & 7; |
Balbir Singh | e71ff98 | 2017-06-29 03:04:07 +1000 | [diff] [blame] | 949 | if (mmu_has_feature(MMU_FTR_KERNEL_RO)) |
| 950 | /* Move pp0 into bit 8 (IBM 55) */ |
| 951 | flags |= (newpp & HPTE_R_PP0) >> 55; |
| 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | lpar_rc = plpar_pte_protect(flags, slot, 0); |
| 954 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 955 | BUG_ON(lpar_rc != H_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 958 | 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] | 959 | int psize, int apsize, |
| 960 | int ssize, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 962 | unsigned long want_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | unsigned long lpar_rc; |
| 964 | unsigned long dummy1, dummy2; |
| 965 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 966 | pr_devel(" inval : slot=%lx, vpn=%016lx, psize: %d, local: %d\n", |
| 967 | slot, vpn, psize, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 969 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 970 | lpar_rc = plpar_pte_remove(H_AVPN, slot, want_v, &dummy1, &dummy2); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 971 | if (lpar_rc == H_NOT_FOUND) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | return; |
| 973 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 974 | BUG_ON(lpar_rc != H_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Laurent Dufour | ba2dd8a | 2018-08-20 16:29:36 +0200 | [diff] [blame] | 977 | |
| 978 | /* |
| 979 | * As defined in the PAPR's section 14.5.4.1.8 |
| 980 | * The control mask doesn't include the returned reference and change bit from |
| 981 | * the processed PTE. |
| 982 | */ |
| 983 | #define HBLKR_AVPN 0x0100000000000000UL |
| 984 | #define HBLKR_CTRL_MASK 0xf800000000000000UL |
| 985 | #define HBLKR_CTRL_SUCCESS 0x8000000000000000UL |
| 986 | #define HBLKR_CTRL_ERRNOTFOUND 0x8800000000000000UL |
| 987 | #define HBLKR_CTRL_ERRBUSY 0xa000000000000000UL |
| 988 | |
| 989 | /** |
| 990 | * H_BLOCK_REMOVE caller. |
| 991 | * @idx should point to the latest @param entry set with a PTEX. |
| 992 | * If PTE cannot be processed because another CPUs has already locked that |
| 993 | * group, those entries are put back in @param starting at index 1. |
| 994 | * If entries has to be retried and @retry_busy is set to true, these entries |
| 995 | * are retried until success. If @retry_busy is set to false, the returned |
| 996 | * is the number of entries yet to process. |
| 997 | */ |
| 998 | static unsigned long call_block_remove(unsigned long idx, unsigned long *param, |
| 999 | bool retry_busy) |
| 1000 | { |
| 1001 | unsigned long i, rc, new_idx; |
| 1002 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; |
| 1003 | |
| 1004 | if (idx < 2) { |
| 1005 | pr_warn("Unexpected empty call to H_BLOCK_REMOVE"); |
| 1006 | return 0; |
| 1007 | } |
| 1008 | again: |
| 1009 | new_idx = 0; |
| 1010 | if (idx > PLPAR_HCALL9_BUFSIZE) { |
| 1011 | pr_err("Too many PTEs (%lu) for H_BLOCK_REMOVE", idx); |
| 1012 | idx = PLPAR_HCALL9_BUFSIZE; |
| 1013 | } else if (idx < PLPAR_HCALL9_BUFSIZE) |
| 1014 | param[idx] = HBR_END; |
| 1015 | |
| 1016 | rc = plpar_hcall9(H_BLOCK_REMOVE, retbuf, |
| 1017 | param[0], /* AVA */ |
| 1018 | param[1], param[2], param[3], param[4], /* TS0-7 */ |
| 1019 | param[5], param[6], param[7], param[8]); |
| 1020 | if (rc == H_SUCCESS) |
| 1021 | return 0; |
| 1022 | |
| 1023 | BUG_ON(rc != H_PARTIAL); |
| 1024 | |
| 1025 | /* Check that the unprocessed entries were 'not found' or 'busy' */ |
| 1026 | for (i = 0; i < idx-1; i++) { |
| 1027 | unsigned long ctrl = retbuf[i] & HBLKR_CTRL_MASK; |
| 1028 | |
| 1029 | if (ctrl == HBLKR_CTRL_ERRBUSY) { |
| 1030 | param[++new_idx] = param[i+1]; |
| 1031 | continue; |
| 1032 | } |
| 1033 | |
| 1034 | BUG_ON(ctrl != HBLKR_CTRL_SUCCESS |
| 1035 | && ctrl != HBLKR_CTRL_ERRNOTFOUND); |
| 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * If there were entries found busy, retry these entries if requested, |
| 1040 | * of if all the entries have to be retried. |
| 1041 | */ |
| 1042 | if (new_idx && (retry_busy || new_idx == (PLPAR_HCALL9_BUFSIZE-1))) { |
| 1043 | idx = new_idx + 1; |
| 1044 | goto again; |
| 1045 | } |
| 1046 | |
| 1047 | return new_idx; |
| 1048 | } |
| 1049 | |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 1050 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1051 | /* |
| 1052 | * Limit iterations holding pSeries_lpar_tlbie_lock to 3. We also need |
| 1053 | * to make sure that we avoid bouncing the hypervisor tlbie lock. |
| 1054 | */ |
| 1055 | #define PPC64_HUGE_HPTE_BATCH 12 |
| 1056 | |
Laurent Dufour | ba2dd8a | 2018-08-20 16:29:36 +0200 | [diff] [blame] | 1057 | static void hugepage_block_invalidate(unsigned long *slot, unsigned long *vpn, |
| 1058 | int count, int psize, int ssize) |
| 1059 | { |
| 1060 | unsigned long param[PLPAR_HCALL9_BUFSIZE]; |
| 1061 | unsigned long shift, current_vpgb, vpgb; |
| 1062 | int i, pix = 0; |
| 1063 | |
| 1064 | shift = mmu_psize_defs[psize].shift; |
| 1065 | |
| 1066 | for (i = 0; i < count; i++) { |
| 1067 | /* |
| 1068 | * Shifting 3 bits more on the right to get a |
| 1069 | * 8 pages aligned virtual addresse. |
| 1070 | */ |
| 1071 | vpgb = (vpn[i] >> (shift - VPN_SHIFT + 3)); |
| 1072 | if (!pix || vpgb != current_vpgb) { |
| 1073 | /* |
| 1074 | * Need to start a new 8 pages block, flush |
| 1075 | * the current one if needed. |
| 1076 | */ |
| 1077 | if (pix) |
| 1078 | (void)call_block_remove(pix, param, true); |
| 1079 | current_vpgb = vpgb; |
| 1080 | param[0] = hpte_encode_avpn(vpn[i], psize, ssize); |
| 1081 | pix = 1; |
| 1082 | } |
| 1083 | |
| 1084 | param[pix++] = HBR_REQUEST | HBLKR_AVPN | slot[i]; |
| 1085 | if (pix == PLPAR_HCALL9_BUFSIZE) { |
| 1086 | pix = call_block_remove(pix, param, false); |
| 1087 | /* |
| 1088 | * pix = 0 means that all the entries were |
| 1089 | * removed, we can start a new block. |
| 1090 | * Otherwise, this means that there are entries |
| 1091 | * to retry, and pix points to latest one, so |
| 1092 | * we should increment it and try to continue |
| 1093 | * the same block. |
| 1094 | */ |
| 1095 | if (pix) |
| 1096 | pix++; |
| 1097 | } |
| 1098 | } |
| 1099 | if (pix) |
| 1100 | (void)call_block_remove(pix, param, true); |
| 1101 | } |
| 1102 | |
| 1103 | static void hugepage_bulk_invalidate(unsigned long *slot, unsigned long *vpn, |
| 1104 | int count, int psize, int ssize) |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1105 | { |
Laurent Dufour | 05af40e | 2016-10-06 15:33:21 +0200 | [diff] [blame] | 1106 | unsigned long param[PLPAR_HCALL9_BUFSIZE]; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1107 | int i = 0, pix = 0, rc; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1108 | |
| 1109 | for (i = 0; i < count; i++) { |
| 1110 | |
| 1111 | if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) { |
| 1112 | pSeries_lpar_hpte_invalidate(slot[i], vpn[i], psize, 0, |
| 1113 | ssize, 0); |
| 1114 | } else { |
| 1115 | param[pix] = HBR_REQUEST | HBR_AVPN | slot[i]; |
| 1116 | param[pix+1] = hpte_encode_avpn(vpn[i], psize, ssize); |
| 1117 | pix += 2; |
| 1118 | if (pix == 8) { |
| 1119 | rc = plpar_hcall9(H_BULK_REMOVE, param, |
| 1120 | param[0], param[1], param[2], |
| 1121 | param[3], param[4], param[5], |
| 1122 | param[6], param[7]); |
| 1123 | BUG_ON(rc != H_SUCCESS); |
| 1124 | pix = 0; |
| 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | if (pix) { |
| 1129 | param[pix] = HBR_END; |
| 1130 | rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1], |
| 1131 | param[2], param[3], param[4], param[5], |
| 1132 | param[6], param[7]); |
| 1133 | BUG_ON(rc != H_SUCCESS); |
| 1134 | } |
Laurent Dufour | ba2dd8a | 2018-08-20 16:29:36 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | static inline void __pSeries_lpar_hugepage_invalidate(unsigned long *slot, |
| 1138 | unsigned long *vpn, |
| 1139 | int count, int psize, |
| 1140 | int ssize) |
| 1141 | { |
| 1142 | unsigned long flags = 0; |
| 1143 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
| 1144 | |
| 1145 | if (lock_tlbie) |
| 1146 | spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags); |
| 1147 | |
| 1148 | if (firmware_has_feature(FW_FEATURE_BLOCK_REMOVE)) |
| 1149 | hugepage_block_invalidate(slot, vpn, count, psize, ssize); |
| 1150 | else |
| 1151 | hugepage_bulk_invalidate(slot, vpn, count, psize, ssize); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1152 | |
| 1153 | if (lock_tlbie) |
| 1154 | spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags); |
| 1155 | } |
| 1156 | |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 1157 | static void pSeries_lpar_hugepage_invalidate(unsigned long vsid, |
| 1158 | unsigned long addr, |
| 1159 | unsigned char *hpte_slot_array, |
Aneesh Kumar K.V | d557b09 | 2014-11-02 21:15:28 +0530 | [diff] [blame] | 1160 | int psize, int ssize, int local) |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1161 | { |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 1162 | int i, index = 0; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1163 | unsigned long s_addr = addr; |
| 1164 | unsigned int max_hpte_count, valid; |
| 1165 | unsigned long vpn_array[PPC64_HUGE_HPTE_BATCH]; |
| 1166 | unsigned long slot_array[PPC64_HUGE_HPTE_BATCH]; |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 1167 | unsigned long shift, hidx, vpn = 0, hash, slot; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1168 | |
| 1169 | shift = mmu_psize_defs[psize].shift; |
| 1170 | max_hpte_count = 1U << (PMD_SHIFT - shift); |
| 1171 | |
| 1172 | for (i = 0; i < max_hpte_count; i++) { |
| 1173 | valid = hpte_valid(hpte_slot_array, i); |
| 1174 | if (!valid) |
| 1175 | continue; |
| 1176 | hidx = hpte_hash_index(hpte_slot_array, i); |
| 1177 | |
| 1178 | /* get the vpn */ |
| 1179 | addr = s_addr + (i * (1ul << shift)); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1180 | vpn = hpt_vpn(addr, vsid, ssize); |
| 1181 | hash = hpt_hash(vpn, shift, ssize); |
| 1182 | if (hidx & _PTEIDX_SECONDARY) |
| 1183 | hash = ~hash; |
| 1184 | |
| 1185 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 1186 | slot += hidx & _PTEIDX_GROUP_IX; |
| 1187 | |
| 1188 | slot_array[index] = slot; |
| 1189 | vpn_array[index] = vpn; |
| 1190 | if (index == PPC64_HUGE_HPTE_BATCH - 1) { |
| 1191 | /* |
| 1192 | * Now do a bluk invalidate |
| 1193 | */ |
| 1194 | __pSeries_lpar_hugepage_invalidate(slot_array, |
| 1195 | vpn_array, |
| 1196 | PPC64_HUGE_HPTE_BATCH, |
| 1197 | psize, ssize); |
| 1198 | index = 0; |
| 1199 | } else |
| 1200 | index++; |
| 1201 | } |
| 1202 | if (index) |
| 1203 | __pSeries_lpar_hugepage_invalidate(slot_array, vpn_array, |
| 1204 | index, psize, ssize); |
| 1205 | } |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 1206 | #else |
| 1207 | static void pSeries_lpar_hugepage_invalidate(unsigned long vsid, |
| 1208 | unsigned long addr, |
| 1209 | unsigned char *hpte_slot_array, |
| 1210 | int psize, int ssize, int local) |
| 1211 | { |
| 1212 | WARN(1, "%s called without THP support\n", __func__); |
| 1213 | } |
| 1214 | #endif |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 1215 | |
David Gibson | 27828f9 | 2016-02-09 13:32:41 +1000 | [diff] [blame] | 1216 | static int pSeries_lpar_hpte_removebolted(unsigned long ea, |
| 1217 | int psize, int ssize) |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 1218 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1219 | unsigned long vpn; |
| 1220 | unsigned long slot, vsid; |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 1221 | |
| 1222 | vsid = get_kernel_vsid(ea, ssize); |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1223 | vpn = hpt_vpn(ea, vsid, ssize); |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 1224 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1225 | slot = pSeries_lpar_hpte_find(vpn, psize, ssize); |
David Gibson | 27828f9 | 2016-02-09 13:32:41 +1000 | [diff] [blame] | 1226 | if (slot == -1) |
| 1227 | return -ENOENT; |
| 1228 | |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 1229 | /* |
| 1230 | * lpar doesn't use the passed actual page size |
| 1231 | */ |
| 1232 | pSeries_lpar_hpte_invalidate(slot, vpn, psize, 0, ssize, 0); |
David Gibson | 27828f9 | 2016-02-09 13:32:41 +1000 | [diff] [blame] | 1233 | return 0; |
Badari Pulavarty | f8c8803 | 2008-01-29 09:19:24 +1100 | [diff] [blame] | 1234 | } |
| 1235 | |
Laurent Dufour | 0effa48 | 2018-08-20 16:29:35 +0200 | [diff] [blame] | 1236 | |
| 1237 | static inline unsigned long compute_slot(real_pte_t pte, |
| 1238 | unsigned long vpn, |
| 1239 | unsigned long index, |
| 1240 | unsigned long shift, |
| 1241 | int ssize) |
| 1242 | { |
| 1243 | unsigned long slot, hash, hidx; |
| 1244 | |
| 1245 | hash = hpt_hash(vpn, shift, ssize); |
| 1246 | hidx = __rpte_to_hidx(pte, index); |
| 1247 | if (hidx & _PTEIDX_SECONDARY) |
| 1248 | hash = ~hash; |
| 1249 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 1250 | slot += hidx & _PTEIDX_GROUP_IX; |
| 1251 | return slot; |
| 1252 | } |
| 1253 | |
Laurent Dufour | ba2dd8a | 2018-08-20 16:29:36 +0200 | [diff] [blame] | 1254 | /** |
| 1255 | * The hcall H_BLOCK_REMOVE implies that the virtual pages to processed are |
| 1256 | * "all within the same naturally aligned 8 page virtual address block". |
| 1257 | */ |
| 1258 | static void do_block_remove(unsigned long number, struct ppc64_tlb_batch *batch, |
| 1259 | unsigned long *param) |
| 1260 | { |
| 1261 | unsigned long vpn; |
| 1262 | unsigned long i, pix = 0; |
| 1263 | unsigned long index, shift, slot, current_vpgb, vpgb; |
| 1264 | real_pte_t pte; |
| 1265 | int psize, ssize; |
| 1266 | |
| 1267 | psize = batch->psize; |
| 1268 | ssize = batch->ssize; |
| 1269 | |
| 1270 | for (i = 0; i < number; i++) { |
| 1271 | vpn = batch->vpn[i]; |
| 1272 | pte = batch->pte[i]; |
| 1273 | pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) { |
| 1274 | /* |
| 1275 | * Shifting 3 bits more on the right to get a |
| 1276 | * 8 pages aligned virtual addresse. |
| 1277 | */ |
| 1278 | vpgb = (vpn >> (shift - VPN_SHIFT + 3)); |
| 1279 | if (!pix || vpgb != current_vpgb) { |
| 1280 | /* |
| 1281 | * Need to start a new 8 pages block, flush |
| 1282 | * the current one if needed. |
| 1283 | */ |
| 1284 | if (pix) |
| 1285 | (void)call_block_remove(pix, param, |
| 1286 | true); |
| 1287 | current_vpgb = vpgb; |
| 1288 | param[0] = hpte_encode_avpn(vpn, psize, |
| 1289 | ssize); |
| 1290 | pix = 1; |
| 1291 | } |
| 1292 | |
| 1293 | slot = compute_slot(pte, vpn, index, shift, ssize); |
| 1294 | param[pix++] = HBR_REQUEST | HBLKR_AVPN | slot; |
| 1295 | |
| 1296 | if (pix == PLPAR_HCALL9_BUFSIZE) { |
| 1297 | pix = call_block_remove(pix, param, false); |
| 1298 | /* |
| 1299 | * pix = 0 means that all the entries were |
| 1300 | * removed, we can start a new block. |
| 1301 | * Otherwise, this means that there are entries |
| 1302 | * to retry, and pix points to latest one, so |
| 1303 | * we should increment it and try to continue |
| 1304 | * the same block. |
| 1305 | */ |
| 1306 | if (pix) |
| 1307 | pix++; |
| 1308 | } |
| 1309 | } pte_iterate_hashed_end(); |
| 1310 | } |
| 1311 | |
| 1312 | if (pix) |
| 1313 | (void)call_block_remove(pix, param, true); |
| 1314 | } |
| 1315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | /* |
| 1317 | * Take a spinlock around flushes to avoid bouncing the hypervisor tlbie |
| 1318 | * lock. |
| 1319 | */ |
Geoff Levand | 035223f | 2006-10-05 11:35:10 -0700 | [diff] [blame] | 1320 | static void pSeries_lpar_flush_hash_range(unsigned long number, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1322 | unsigned long vpn; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1323 | unsigned long i, pix, rc; |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 1324 | unsigned long flags = 0; |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 1325 | struct ppc64_tlb_batch *batch = this_cpu_ptr(&ppc64_tlb_batch); |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 1326 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
Laurent Dufour | 05af40e | 2016-10-06 15:33:21 +0200 | [diff] [blame] | 1327 | unsigned long param[PLPAR_HCALL9_BUFSIZE]; |
Laurent Dufour | 0effa48 | 2018-08-20 16:29:35 +0200 | [diff] [blame] | 1328 | unsigned long index, shift, slot; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1329 | real_pte_t pte; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 1330 | int psize, ssize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
| 1332 | if (lock_tlbie) |
| 1333 | spin_lock_irqsave(&pSeries_lpar_tlbie_lock, flags); |
| 1334 | |
Laurent Dufour | ba2dd8a | 2018-08-20 16:29:36 +0200 | [diff] [blame] | 1335 | if (firmware_has_feature(FW_FEATURE_BLOCK_REMOVE)) { |
| 1336 | do_block_remove(number, batch, param); |
| 1337 | goto out; |
| 1338 | } |
| 1339 | |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1340 | psize = batch->psize; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 1341 | ssize = batch->ssize; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1342 | pix = 0; |
| 1343 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1344 | vpn = batch->vpn[i]; |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1345 | pte = batch->pte[i]; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1346 | pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) { |
Laurent Dufour | 0effa48 | 2018-08-20 16:29:35 +0200 | [diff] [blame] | 1347 | slot = compute_slot(pte, vpn, index, shift, ssize); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 1348 | if (!firmware_has_feature(FW_FEATURE_BULK_REMOVE)) { |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 1349 | /* |
| 1350 | * lpar doesn't use the passed actual page size |
| 1351 | */ |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1352 | pSeries_lpar_hpte_invalidate(slot, vpn, psize, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 1353 | 0, ssize, local); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 1354 | } else { |
| 1355 | param[pix] = HBR_REQUEST | HBR_AVPN | slot; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 1356 | param[pix+1] = hpte_encode_avpn(vpn, psize, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 1357 | ssize); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 1358 | pix += 2; |
| 1359 | if (pix == 8) { |
| 1360 | rc = plpar_hcall9(H_BULK_REMOVE, param, |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1361 | param[0], param[1], param[2], |
| 1362 | param[3], param[4], param[5], |
| 1363 | param[6], param[7]); |
Paul Mackerras | 12e86f9 | 2007-02-08 15:02:35 +1100 | [diff] [blame] | 1364 | BUG_ON(rc != H_SUCCESS); |
| 1365 | pix = 0; |
| 1366 | } |
Paul Mackerras | f03e64f | 2007-02-06 21:10:31 +1100 | [diff] [blame] | 1367 | } |
| 1368 | } pte_iterate_hashed_end(); |
| 1369 | } |
| 1370 | if (pix) { |
| 1371 | param[pix] = HBR_END; |
| 1372 | rc = plpar_hcall9(H_BULK_REMOVE, param, param[0], param[1], |
| 1373 | param[2], param[3], param[4], param[5], |
| 1374 | param[6], param[7]); |
| 1375 | BUG_ON(rc != H_SUCCESS); |
| 1376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
Laurent Dufour | ba2dd8a | 2018-08-20 16:29:36 +0200 | [diff] [blame] | 1378 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | if (lock_tlbie) |
| 1380 | spin_unlock_irqrestore(&pSeries_lpar_tlbie_lock, flags); |
| 1381 | } |
| 1382 | |
Will Schmidt | 4e89a2d | 2010-09-28 15:33:12 +0000 | [diff] [blame] | 1383 | static int __init disable_bulk_remove(char *str) |
| 1384 | { |
| 1385 | if (strcmp(str, "off") == 0 && |
| 1386 | firmware_has_feature(FW_FEATURE_BULK_REMOVE)) { |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1387 | pr_info("Disabling BULK_REMOVE firmware feature"); |
| 1388 | powerpc_firmware_features &= ~FW_FEATURE_BULK_REMOVE; |
Will Schmidt | 4e89a2d | 2010-09-28 15:33:12 +0000 | [diff] [blame] | 1389 | } |
| 1390 | return 1; |
| 1391 | } |
| 1392 | |
| 1393 | __setup("bulk_remove=", disable_bulk_remove); |
| 1394 | |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1395 | #define HPT_RESIZE_TIMEOUT 10000 /* ms */ |
| 1396 | |
| 1397 | struct hpt_resize_state { |
| 1398 | unsigned long shift; |
| 1399 | int commit_rc; |
| 1400 | }; |
| 1401 | |
| 1402 | static int pseries_lpar_resize_hpt_commit(void *data) |
| 1403 | { |
| 1404 | struct hpt_resize_state *state = data; |
| 1405 | |
| 1406 | state->commit_rc = plpar_resize_hpt_commit(0, state->shift); |
| 1407 | if (state->commit_rc != H_SUCCESS) |
| 1408 | return -EIO; |
| 1409 | |
| 1410 | /* Hypervisor has transitioned the HTAB, update our globals */ |
| 1411 | ppc64_pft_size = state->shift; |
| 1412 | htab_size_bytes = 1UL << ppc64_pft_size; |
| 1413 | htab_hash_mask = (htab_size_bytes >> 7) - 1; |
| 1414 | |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | /* Must be called in user context */ |
| 1419 | static int pseries_lpar_resize_hpt(unsigned long shift) |
| 1420 | { |
| 1421 | struct hpt_resize_state state = { |
| 1422 | .shift = shift, |
| 1423 | .commit_rc = H_FUNCTION, |
| 1424 | }; |
| 1425 | unsigned int delay, total_delay = 0; |
| 1426 | int rc; |
| 1427 | ktime_t t0, t1, t2; |
| 1428 | |
| 1429 | might_sleep(); |
| 1430 | |
| 1431 | if (!firmware_has_feature(FW_FEATURE_HPT_RESIZE)) |
| 1432 | return -ENODEV; |
| 1433 | |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1434 | pr_info("Attempting to resize HPT to shift %lu\n", shift); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1435 | |
| 1436 | t0 = ktime_get(); |
| 1437 | |
| 1438 | rc = plpar_resize_hpt_prepare(0, shift); |
| 1439 | while (H_IS_LONG_BUSY(rc)) { |
| 1440 | delay = get_longbusy_msecs(rc); |
| 1441 | total_delay += delay; |
| 1442 | if (total_delay > HPT_RESIZE_TIMEOUT) { |
| 1443 | /* prepare with shift==0 cancels an in-progress resize */ |
| 1444 | rc = plpar_resize_hpt_prepare(0, 0); |
| 1445 | if (rc != H_SUCCESS) |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1446 | pr_warn("Unexpected error %d cancelling timed out HPT resize\n", |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1447 | rc); |
| 1448 | return -ETIMEDOUT; |
| 1449 | } |
| 1450 | msleep(delay); |
| 1451 | rc = plpar_resize_hpt_prepare(0, shift); |
| 1452 | }; |
| 1453 | |
| 1454 | switch (rc) { |
| 1455 | case H_SUCCESS: |
| 1456 | /* Continue on */ |
| 1457 | break; |
| 1458 | |
| 1459 | case H_PARAMETER: |
Laurent Vivier | f172acb | 2019-03-13 11:25:28 +0100 | [diff] [blame] | 1460 | pr_warn("Invalid argument from H_RESIZE_HPT_PREPARE\n"); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1461 | return -EINVAL; |
| 1462 | case H_RESOURCE: |
Laurent Vivier | f172acb | 2019-03-13 11:25:28 +0100 | [diff] [blame] | 1463 | pr_warn("Operation not permitted from H_RESIZE_HPT_PREPARE\n"); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1464 | return -EPERM; |
| 1465 | default: |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1466 | pr_warn("Unexpected error %d from H_RESIZE_HPT_PREPARE\n", rc); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1467 | return -EIO; |
| 1468 | } |
| 1469 | |
| 1470 | t1 = ktime_get(); |
| 1471 | |
| 1472 | rc = stop_machine(pseries_lpar_resize_hpt_commit, &state, NULL); |
| 1473 | |
| 1474 | t2 = ktime_get(); |
| 1475 | |
| 1476 | if (rc != 0) { |
| 1477 | switch (state.commit_rc) { |
| 1478 | case H_PTEG_FULL: |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1479 | return -ENOSPC; |
| 1480 | |
| 1481 | default: |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1482 | pr_warn("Unexpected error %d from H_RESIZE_HPT_COMMIT\n", |
| 1483 | state.commit_rc); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1484 | return -EIO; |
| 1485 | }; |
| 1486 | } |
| 1487 | |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1488 | pr_info("HPT resize to shift %lu complete (%lld ms / %lld ms)\n", |
| 1489 | shift, (long long) ktime_ms_delta(t1, t0), |
| 1490 | (long long) ktime_ms_delta(t2, t1)); |
David Gibson | dbcf929 | 2016-12-09 11:07:36 +1100 | [diff] [blame] | 1491 | |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 1495 | static int pseries_lpar_register_process_table(unsigned long base, |
| 1496 | unsigned long page_size, unsigned long table_size) |
| 1497 | { |
| 1498 | long rc; |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 1499 | unsigned long flags = 0; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 1500 | |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 1501 | if (table_size) |
| 1502 | flags |= PROC_TABLE_NEW; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 1503 | if (radix_enabled()) |
| 1504 | flags |= PROC_TABLE_RADIX | PROC_TABLE_GTSE; |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 1505 | else |
| 1506 | flags |= PROC_TABLE_HPT_SLB; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 1507 | for (;;) { |
| 1508 | rc = plpar_hcall_norets(H_REGISTER_PROC_TBL, flags, base, |
| 1509 | page_size, table_size); |
| 1510 | if (!H_IS_LONG_BUSY(rc)) |
| 1511 | break; |
| 1512 | mdelay(get_longbusy_msecs(rc)); |
| 1513 | } |
| 1514 | if (rc != H_SUCCESS) { |
| 1515 | pr_err("Failed to register process table (rc=%ld)\n", rc); |
| 1516 | BUG(); |
| 1517 | } |
| 1518 | return rc; |
| 1519 | } |
| 1520 | |
Michael Ellerman | 6364e84 | 2016-07-26 10:33:03 +1000 | [diff] [blame] | 1521 | void __init hpte_init_pseries(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | { |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 1523 | mmu_hash_ops.hpte_invalidate = pSeries_lpar_hpte_invalidate; |
| 1524 | mmu_hash_ops.hpte_updatepp = pSeries_lpar_hpte_updatepp; |
| 1525 | mmu_hash_ops.hpte_updateboltedpp = pSeries_lpar_hpte_updateboltedpp; |
| 1526 | mmu_hash_ops.hpte_insert = pSeries_lpar_hpte_insert; |
| 1527 | mmu_hash_ops.hpte_remove = pSeries_lpar_hpte_remove; |
| 1528 | mmu_hash_ops.hpte_removebolted = pSeries_lpar_hpte_removebolted; |
| 1529 | mmu_hash_ops.flush_hash_range = pSeries_lpar_flush_hash_range; |
Anton Blanchard | 5246ade | 2016-10-01 20:41:56 +1000 | [diff] [blame] | 1530 | mmu_hash_ops.hpte_clear_all = pseries_hpte_clear_all; |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 1531 | mmu_hash_ops.hugepage_invalidate = pSeries_lpar_hugepage_invalidate; |
Paul Mackerras | dbfcf3c | 2017-02-16 16:03:39 +1100 | [diff] [blame] | 1532 | register_process_table = pseries_lpar_register_process_table; |
Michael Ellerman | 8971e1c | 2017-03-17 16:02:35 +1100 | [diff] [blame] | 1533 | |
| 1534 | if (firmware_has_feature(FW_FEATURE_HPT_RESIZE)) |
| 1535 | mmu_hash_ops.resize_hpt = pseries_lpar_resize_hpt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 1537 | |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 1538 | void radix_init_pseries(void) |
| 1539 | { |
| 1540 | pr_info("Using radix MMU under hypervisor\n"); |
| 1541 | register_process_table = pseries_lpar_register_process_table; |
| 1542 | } |
| 1543 | |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 1544 | #ifdef CONFIG_PPC_SMLPAR |
| 1545 | #define CMO_FREE_HINT_DEFAULT 1 |
| 1546 | static int cmo_free_hint_flag = CMO_FREE_HINT_DEFAULT; |
| 1547 | |
| 1548 | static int __init cmo_free_hint(char *str) |
| 1549 | { |
| 1550 | char *parm; |
| 1551 | parm = strstrip(str); |
| 1552 | |
| 1553 | if (strcasecmp(parm, "no") == 0 || strcasecmp(parm, "off") == 0) { |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1554 | pr_info("%s: CMO free page hinting is not active.\n", __func__); |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 1555 | cmo_free_hint_flag = 0; |
| 1556 | return 1; |
| 1557 | } |
| 1558 | |
| 1559 | cmo_free_hint_flag = 1; |
Aneesh Kumar K.V | 65471d7 | 2018-06-29 14:09:04 +0530 | [diff] [blame] | 1560 | pr_info("%s: CMO free page hinting is active.\n", __func__); |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 1561 | |
| 1562 | if (strcasecmp(parm, "yes") == 0 || strcasecmp(parm, "on") == 0) |
| 1563 | return 1; |
| 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
| 1568 | __setup("cmo_free_hint=", cmo_free_hint); |
| 1569 | |
| 1570 | static void pSeries_set_page_state(struct page *page, int order, |
| 1571 | unsigned long state) |
| 1572 | { |
| 1573 | int i, j; |
| 1574 | unsigned long cmo_page_sz, addr; |
| 1575 | |
| 1576 | cmo_page_sz = cmo_get_page_size(); |
| 1577 | addr = __pa((unsigned long)page_address(page)); |
| 1578 | |
| 1579 | for (i = 0; i < (1 << order); i++, addr += PAGE_SIZE) { |
| 1580 | for (j = 0; j < PAGE_SIZE; j += cmo_page_sz) |
| 1581 | plpar_hcall_norets(H_PAGE_INIT, state, addr + j, 0); |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | void arch_free_page(struct page *page, int order) |
| 1586 | { |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 1587 | if (radix_enabled()) |
| 1588 | return; |
Robert Jennings | 14f966e | 2009-04-15 05:55:32 +0000 | [diff] [blame] | 1589 | if (!cmo_free_hint_flag || !firmware_has_feature(FW_FEATURE_CMO)) |
| 1590 | return; |
| 1591 | |
| 1592 | pSeries_set_page_state(page, order, H_PAGE_SET_UNUSED); |
| 1593 | } |
| 1594 | EXPORT_SYMBOL(arch_free_page); |
| 1595 | |
Aneesh Kumar K.V | d8c476e | 2016-04-29 23:26:08 +1000 | [diff] [blame] | 1596 | #endif /* CONFIG_PPC_SMLPAR */ |
Michael Ellerman | 4e00374 | 2017-10-19 15:08:43 +1100 | [diff] [blame] | 1597 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1598 | |
| 1599 | #ifdef CONFIG_TRACEPOINTS |
Masahiro Yamada | e9666d1 | 2018-12-31 00:14:15 +0900 | [diff] [blame] | 1600 | #ifdef CONFIG_JUMP_LABEL |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 1601 | struct static_key hcall_tracepoint_key = STATIC_KEY_INIT; |
| 1602 | |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 1603 | int hcall_tracepoint_regfunc(void) |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 1604 | { |
| 1605 | static_key_slow_inc(&hcall_tracepoint_key); |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 1606 | return 0; |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | void hcall_tracepoint_unregfunc(void) |
| 1610 | { |
| 1611 | static_key_slow_dec(&hcall_tracepoint_key); |
| 1612 | } |
| 1613 | #else |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1614 | /* |
| 1615 | * We optimise our hcall path by placing hcall_tracepoint_refcount |
| 1616 | * directly in the TOC so we can check if the hcall tracepoints are |
| 1617 | * enabled via a single load. |
| 1618 | */ |
| 1619 | |
| 1620 | /* NB: reg/unreg are called while guarded with the tracepoints_mutex */ |
| 1621 | extern long hcall_tracepoint_refcount; |
| 1622 | |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 1623 | int hcall_tracepoint_regfunc(void) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1624 | { |
| 1625 | hcall_tracepoint_refcount++; |
Steven Rostedt (Red Hat) | 8cf868a | 2016-11-28 13:03:21 -0500 | [diff] [blame] | 1626 | return 0; |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | void hcall_tracepoint_unregfunc(void) |
| 1630 | { |
| 1631 | hcall_tracepoint_refcount--; |
| 1632 | } |
Anton Blanchard | cc1adb5 | 2014-07-03 15:52:03 +1000 | [diff] [blame] | 1633 | #endif |
| 1634 | |
| 1635 | /* |
| 1636 | * Since the tracing code might execute hcalls we need to guard against |
| 1637 | * recursion. One example of this are spinlocks calling H_YIELD on |
| 1638 | * shared processor partitions. |
| 1639 | */ |
| 1640 | static DEFINE_PER_CPU(unsigned int, hcall_trace_depth); |
| 1641 | |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1642 | |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 1643 | void __trace_hcall_entry(unsigned long opcode, unsigned long *args) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1644 | { |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1645 | unsigned long flags; |
| 1646 | unsigned int *depth; |
| 1647 | |
Anton Blanchard | a5ccfee | 2012-01-09 14:29:15 +0000 | [diff] [blame] | 1648 | /* |
| 1649 | * We cannot call tracepoints inside RCU idle regions which |
| 1650 | * means we must not trace H_CEDE. |
| 1651 | */ |
| 1652 | if (opcode == H_CEDE) |
| 1653 | return; |
| 1654 | |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1655 | local_irq_save(flags); |
| 1656 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 1657 | depth = this_cpu_ptr(&hcall_trace_depth); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1658 | |
| 1659 | if (*depth) |
| 1660 | goto out; |
| 1661 | |
| 1662 | (*depth)++; |
Li Zhong | e4f387d | 2011-12-18 16:03:04 +0000 | [diff] [blame] | 1663 | preempt_disable(); |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 1664 | trace_hcall_entry(opcode, args); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1665 | (*depth)--; |
| 1666 | |
| 1667 | out: |
| 1668 | local_irq_restore(flags); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
Michael Ellerman | 8f2133c | 2018-05-07 23:03:55 +1000 | [diff] [blame] | 1671 | void __trace_hcall_exit(long opcode, long retval, unsigned long *retbuf) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1672 | { |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1673 | unsigned long flags; |
| 1674 | unsigned int *depth; |
| 1675 | |
Anton Blanchard | a5ccfee | 2012-01-09 14:29:15 +0000 | [diff] [blame] | 1676 | if (opcode == H_CEDE) |
| 1677 | return; |
| 1678 | |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1679 | local_irq_save(flags); |
| 1680 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 1681 | depth = this_cpu_ptr(&hcall_trace_depth); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1682 | |
| 1683 | if (*depth) |
| 1684 | goto out; |
| 1685 | |
| 1686 | (*depth)++; |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 1687 | trace_hcall_exit(opcode, retval, retbuf); |
Li Zhong | e4f387d | 2011-12-18 16:03:04 +0000 | [diff] [blame] | 1688 | preempt_enable(); |
Anton Blanchard | 57cdfdf | 2010-10-21 00:52:12 +0000 | [diff] [blame] | 1689 | (*depth)--; |
| 1690 | |
| 1691 | out: |
| 1692 | local_irq_restore(flags); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 1693 | } |
| 1694 | #endif |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 1695 | |
| 1696 | /** |
| 1697 | * h_get_mpp |
| 1698 | * H_GET_MPP hcall returns info in 7 parms |
| 1699 | */ |
| 1700 | int h_get_mpp(struct hvcall_mpp_data *mpp_data) |
| 1701 | { |
| 1702 | int rc; |
| 1703 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; |
| 1704 | |
| 1705 | rc = plpar_hcall9(H_GET_MPP, retbuf); |
| 1706 | |
| 1707 | mpp_data->entitled_mem = retbuf[0]; |
| 1708 | mpp_data->mapped_mem = retbuf[1]; |
| 1709 | |
| 1710 | mpp_data->group_num = (retbuf[2] >> 2 * 8) & 0xffff; |
| 1711 | mpp_data->pool_num = retbuf[2] & 0xffff; |
| 1712 | |
| 1713 | mpp_data->mem_weight = (retbuf[3] >> 7 * 8) & 0xff; |
| 1714 | mpp_data->unallocated_mem_weight = (retbuf[3] >> 6 * 8) & 0xff; |
Anton Blanchard | b0d436c | 2013-08-07 02:01:24 +1000 | [diff] [blame] | 1715 | mpp_data->unallocated_entitlement = retbuf[3] & 0xffffffffffffUL; |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 1716 | |
| 1717 | mpp_data->pool_size = retbuf[4]; |
| 1718 | mpp_data->loan_request = retbuf[5]; |
| 1719 | mpp_data->backing_mem = retbuf[6]; |
| 1720 | |
| 1721 | return rc; |
| 1722 | } |
| 1723 | EXPORT_SYMBOL(h_get_mpp); |
| 1724 | |
| 1725 | int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data) |
| 1726 | { |
| 1727 | int rc; |
| 1728 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE] = { 0 }; |
| 1729 | |
| 1730 | rc = plpar_hcall9(H_GET_MPP_X, retbuf); |
| 1731 | |
| 1732 | mpp_x_data->coalesced_bytes = retbuf[0]; |
| 1733 | mpp_x_data->pool_coalesced_bytes = retbuf[1]; |
| 1734 | mpp_x_data->pool_purr_cycles = retbuf[2]; |
| 1735 | mpp_x_data->pool_spurr_cycles = retbuf[3]; |
| 1736 | |
| 1737 | return rc; |
| 1738 | } |
Aneesh Kumar K.V | 82228e3 | 2017-03-22 09:07:00 +0530 | [diff] [blame] | 1739 | |
| 1740 | static unsigned long vsid_unscramble(unsigned long vsid, int ssize) |
| 1741 | { |
| 1742 | unsigned long protovsid; |
| 1743 | unsigned long va_bits = VA_BITS; |
| 1744 | unsigned long modinv, vsid_modulus; |
| 1745 | unsigned long max_mod_inv, tmp_modinv; |
| 1746 | |
| 1747 | if (!mmu_has_feature(MMU_FTR_68_BIT_VA)) |
| 1748 | va_bits = 65; |
| 1749 | |
| 1750 | if (ssize == MMU_SEGSIZE_256M) { |
| 1751 | modinv = VSID_MULINV_256M; |
| 1752 | vsid_modulus = ((1UL << (va_bits - SID_SHIFT)) - 1); |
| 1753 | } else { |
| 1754 | modinv = VSID_MULINV_1T; |
| 1755 | vsid_modulus = ((1UL << (va_bits - SID_SHIFT_1T)) - 1); |
| 1756 | } |
| 1757 | |
| 1758 | /* |
| 1759 | * vsid outside our range. |
| 1760 | */ |
| 1761 | if (vsid >= vsid_modulus) |
| 1762 | return 0; |
| 1763 | |
| 1764 | /* |
| 1765 | * If modinv is the modular multiplicate inverse of (x % vsid_modulus) |
| 1766 | * and vsid = (protovsid * x) % vsid_modulus, then we say: |
| 1767 | * protovsid = (vsid * modinv) % vsid_modulus |
| 1768 | */ |
| 1769 | |
| 1770 | /* Check if (vsid * modinv) overflow (63 bits) */ |
| 1771 | max_mod_inv = 0x7fffffffffffffffull / vsid; |
| 1772 | if (modinv < max_mod_inv) |
| 1773 | return (vsid * modinv) % vsid_modulus; |
| 1774 | |
| 1775 | tmp_modinv = modinv/max_mod_inv; |
| 1776 | modinv %= max_mod_inv; |
| 1777 | |
| 1778 | protovsid = (((vsid * max_mod_inv) % vsid_modulus) * tmp_modinv) % vsid_modulus; |
| 1779 | protovsid = (protovsid + vsid * modinv) % vsid_modulus; |
| 1780 | |
| 1781 | return protovsid; |
| 1782 | } |
| 1783 | |
| 1784 | static int __init reserve_vrma_context_id(void) |
| 1785 | { |
| 1786 | unsigned long protovsid; |
| 1787 | |
| 1788 | /* |
| 1789 | * Reserve context ids which map to reserved virtual addresses. For now |
| 1790 | * we only reserve the context id which maps to the VRMA VSID. We ignore |
| 1791 | * the addresses in "ibm,adjunct-virtual-addresses" because we don't |
| 1792 | * enable adjunct support via the "ibm,client-architecture-support" |
| 1793 | * interface. |
| 1794 | */ |
| 1795 | protovsid = vsid_unscramble(VRMA_VSID, MMU_SEGSIZE_1T); |
| 1796 | hash__reserve_context_id(protovsid >> ESID_BITS_1T); |
| 1797 | return 0; |
| 1798 | } |
| 1799 | machine_device_initcall(pseries, reserve_vrma_context_id); |
Aravinda Prasad | c6c26fb | 2018-10-16 17:20:05 +0530 | [diff] [blame] | 1800 | |
| 1801 | #ifdef CONFIG_DEBUG_FS |
| 1802 | /* debugfs file interface for vpa data */ |
| 1803 | static ssize_t vpa_file_read(struct file *filp, char __user *buf, size_t len, |
| 1804 | loff_t *pos) |
| 1805 | { |
| 1806 | int cpu = (long)filp->private_data; |
| 1807 | struct lppaca *lppaca = &lppaca_of(cpu); |
| 1808 | |
| 1809 | return simple_read_from_buffer(buf, len, pos, lppaca, |
| 1810 | sizeof(struct lppaca)); |
| 1811 | } |
| 1812 | |
| 1813 | static const struct file_operations vpa_fops = { |
| 1814 | .open = simple_open, |
| 1815 | .read = vpa_file_read, |
| 1816 | .llseek = default_llseek, |
| 1817 | }; |
| 1818 | |
| 1819 | static int __init vpa_debugfs_init(void) |
| 1820 | { |
| 1821 | char name[16]; |
| 1822 | long i; |
| 1823 | static struct dentry *vpa_dir; |
| 1824 | |
| 1825 | if (!firmware_has_feature(FW_FEATURE_SPLPAR)) |
| 1826 | return 0; |
| 1827 | |
| 1828 | vpa_dir = debugfs_create_dir("vpa", powerpc_debugfs_root); |
| 1829 | if (!vpa_dir) { |
| 1830 | pr_warn("%s: can't create vpa root dir\n", __func__); |
| 1831 | return -ENOMEM; |
| 1832 | } |
| 1833 | |
| 1834 | /* set up the per-cpu vpa file*/ |
| 1835 | for_each_possible_cpu(i) { |
| 1836 | struct dentry *d; |
| 1837 | |
| 1838 | sprintf(name, "cpu-%ld", i); |
| 1839 | |
| 1840 | d = debugfs_create_file(name, 0400, vpa_dir, (void *)i, |
| 1841 | &vpa_fops); |
| 1842 | if (!d) { |
| 1843 | pr_warn("%s: can't create per-cpu vpa file\n", |
| 1844 | __func__); |
| 1845 | return -ENOMEM; |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | return 0; |
| 1850 | } |
| 1851 | machine_arch_initcall(pseries, vpa_debugfs_init); |
| 1852 | #endif /* CONFIG_DEBUG_FS */ |