Lines Matching +full:non +full:- +full:descriptive
1 // SPDX-License-Identifier: GPL-2.0
5 * Pseudo-locking support built on top of Cache Allocation Technology (CAT)
26 #include <asm/intel-family.h>
44 * pseudo-locked regions.
51 * get_prefetch_disable_bits - prefetch disable bits of supported platforms
55 * pseudo-locking. This includes testing to ensure pseudo-locked regions
57 * as well as that these pseudo-locked regions can maintain their low cache
60 * After a platform has been validated to support pseudo-locking its
106 * pseudo_lock_minor_get - Obtain available minor number
121 return -ENOSPC; in pseudo_lock_minor_get()
130 * pseudo_lock_minor_release - Return minor number to available
139 * region_find_by_minor - Locate a pseudo-lock region by inode minor number
140 * @minor: The minor number of the device representing pseudo-locked region
143 * pseudo-locked region it belongs to. This is done by matching the minor
144 * number of the device to the pseudo-locked region it belongs.
146 * Minor numbers are assigned at the time a pseudo-locked region is associated
149 * Return: On success return pointer to resource group owning the pseudo-locked
157 if (rdtgrp->plr && rdtgrp->plr->minor == minor) { in region_find_by_minor()
166 * struct pseudo_lock_pm_req - A power management QoS request list entry
167 * @list: Entry within the @pm_reqs list for a pseudo-locked region
179 list_for_each_entry_safe(pm_req, next, &plr->pm_reqs, list) { in pseudo_lock_cstates_relax()
180 dev_pm_qos_remove_request(&pm_req->req); in pseudo_lock_cstates_relax()
181 list_del(&pm_req->list); in pseudo_lock_cstates_relax()
187 * pseudo_lock_cstates_constrain - Restrict cores from entering C6
188 * @plr: Pseudo-locked region
210 for_each_cpu(cpu, &plr->d->cpu_mask) { in pseudo_lock_cstates_constrain()
214 ret = -ENOMEM; in pseudo_lock_cstates_constrain()
218 &pm_req->req, in pseudo_lock_cstates_constrain()
225 ret = -1; in pseudo_lock_cstates_constrain()
228 list_add(&pm_req->list, &plr->pm_reqs); in pseudo_lock_cstates_constrain()
239 * pseudo_lock_region_clear - Reset pseudo-lock region data
240 * @plr: pseudo-lock region
242 * All content of the pseudo-locked region is reset - any memory allocated
249 plr->size = 0; in pseudo_lock_region_clear()
250 plr->line_size = 0; in pseudo_lock_region_clear()
251 kfree(plr->kmem); in pseudo_lock_region_clear()
252 plr->kmem = NULL; in pseudo_lock_region_clear()
253 plr->s = NULL; in pseudo_lock_region_clear()
254 if (plr->d) in pseudo_lock_region_clear()
255 plr->d->plr = NULL; in pseudo_lock_region_clear()
256 plr->d = NULL; in pseudo_lock_region_clear()
257 plr->cbm = 0; in pseudo_lock_region_clear()
258 plr->debugfs_dir = NULL; in pseudo_lock_region_clear()
262 * pseudo_lock_region_init - Initialize pseudo-lock region information
263 * @plr: pseudo-lock region
265 * Called after user provided a schemata to be pseudo-locked. From the
268 * required for pseudo-locking is deduced from this data and &struct
270 * - size in bytes of the region to be pseudo-locked
271 * - cache line size to know the stride with which data needs to be accessed
272 * to be pseudo-locked
273 * - a cpu associated with the cache instance on which the pseudo-locking
276 * Return: 0 on success, <0 on failure. Descriptive error will be written
286 plr->cpu = cpumask_first(&plr->d->cpu_mask); in pseudo_lock_region_init()
288 if (!cpu_online(plr->cpu)) { in pseudo_lock_region_init()
290 plr->cpu); in pseudo_lock_region_init()
291 ret = -ENODEV; in pseudo_lock_region_init()
295 ci = get_cpu_cacheinfo(plr->cpu); in pseudo_lock_region_init()
297 plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm); in pseudo_lock_region_init()
299 for (i = 0; i < ci->num_leaves; i++) { in pseudo_lock_region_init()
300 if (ci->info_list[i].level == plr->s->res->cache_level) { in pseudo_lock_region_init()
301 plr->line_size = ci->info_list[i].coherency_line_size; in pseudo_lock_region_init()
306 ret = -1; in pseudo_lock_region_init()
314 * pseudo_lock_init - Initialize a pseudo-lock region
315 * @rdtgrp: resource group to which new pseudo-locked region will belong
317 * A pseudo-locked region is associated with a resource group. When this
318 * association is created the pseudo-locked region is initialized. The
319 * details of the pseudo-locked region are not known at this time so only
330 return -ENOMEM; in pseudo_lock_init()
332 init_waitqueue_head(&plr->lock_thread_wq); in pseudo_lock_init()
333 INIT_LIST_HEAD(&plr->pm_reqs); in pseudo_lock_init()
334 rdtgrp->plr = plr; in pseudo_lock_init()
339 * pseudo_lock_region_alloc - Allocate kernel memory that will be pseudo-locked
340 * @plr: pseudo-lock region
342 * Initialize the details required to set up the pseudo-locked region and
343 * allocate the contiguous memory that will be pseudo-locked to the cache.
345 * Return: 0 on success, <0 on failure. Descriptive error will be written
360 if (plr->size > KMALLOC_MAX_SIZE) { in pseudo_lock_region_alloc()
362 ret = -E2BIG; in pseudo_lock_region_alloc()
366 plr->kmem = kzalloc(plr->size, GFP_KERNEL); in pseudo_lock_region_alloc()
367 if (!plr->kmem) { in pseudo_lock_region_alloc()
369 ret = -ENOMEM; in pseudo_lock_region_alloc()
382 * pseudo_lock_free - Free a pseudo-locked region
383 * @rdtgrp: resource group to which pseudo-locked region belonged
385 * The pseudo-locked region's resources have already been released, or not
393 pseudo_lock_region_clear(rdtgrp->plr); in pseudo_lock_free()
394 kfree(rdtgrp->plr); in pseudo_lock_free()
395 rdtgrp->plr = NULL; in pseudo_lock_free()
399 * pseudo_lock_fn - Load kernel memory into cache
400 * @_rdtgrp: resource group to which pseudo-lock region belongs
402 * This is the core pseudo-locking flow.
407 * with class of service set to the bitmask of the pseudo-locked region.
420 struct pseudo_lock_region *plr = rdtgrp->plr; in pseudo_lock_fn()
431 * pseudo-locking success rate when KASAN is active. in pseudo_lock_fn()
444 * will get a cache hit in below loop from outside of pseudo-locked in pseudo_lock_fn()
463 * being pseudo-locked is reached the hardware will not read beyond in pseudo_lock_fn()
464 * the buffer and evict pseudo-locked memory read earlier from the in pseudo_lock_fn()
471 mem_r = plr->kmem; in pseudo_lock_fn()
472 size = plr->size; in pseudo_lock_fn()
473 line_size = plr->line_size; in pseudo_lock_fn()
477 * pseudo-locked followed by reading of kernel memory to load it in pseudo_lock_fn()
480 __wrmsr(IA32_PQR_ASSOC, rmid_p, rdtgrp->closid); in pseudo_lock_fn()
483 * into cache region associated with just activated plr->closid. in pseudo_lock_fn()
485 * - In first loop the cache region is shared with the page walker in pseudo_lock_fn()
487 * - In the second loop the paging structure caches are used and in pseudo_lock_fn()
514 * does not overlap with pseudo-locked region. in pseudo_lock_fn()
518 /* Re-enable the hardware prefetcher(s) */ in pseudo_lock_fn()
522 plr->thread_done = 1; in pseudo_lock_fn()
523 wake_up_interruptible(&plr->lock_thread_wq); in pseudo_lock_fn()
528 * rdtgroup_monitor_in_progress - Test if monitoring in progress
536 return !list_empty(&rdtgrp->mon.crdtgrp_list); in rdtgroup_monitor_in_progress()
540 * rdtgroup_locksetup_user_restrict - Restrict user access to group
543 * A resource group used for cache pseudo-locking cannot have cpus or tasks
590 * rdtgroup_locksetup_user_restore - Restore user access to group
637 * rdtgroup_locksetup_enter - Resource group enters locksetup mode
641 * to represent a pseudo-locked region and is in the process of being set
642 * up to do so. A resource group used for a pseudo-locked region would
645 * future. Monitoring of a pseudo-locked region is not allowed either.
647 * The above and more restrictions on a pseudo-locked region are checked
663 rdt_last_cmd_puts("Cannot pseudo-lock default group\n"); in rdtgroup_locksetup_enter()
664 return -EINVAL; in rdtgroup_locksetup_enter()
668 * Cache Pseudo-locking not supported when CDP is enabled. in rdtgroup_locksetup_enter()
672 * - When CDP is enabled two separate resources are exposed, in rdtgroup_locksetup_enter()
674 * The implication for pseudo-locking is that if a in rdtgroup_locksetup_enter()
675 * pseudo-locked region is created on a domain of one in rdtgroup_locksetup_enter()
676 * resource (eg. L3CODE), then a pseudo-locked region cannot in rdtgroup_locksetup_enter()
679 * pseudo-locked region involves a call to wbinvd that will in rdtgroup_locksetup_enter()
681 * - Considering the previous, it may be possible to only in rdtgroup_locksetup_enter()
682 * expose one of the CDP resources to pseudo-locking and in rdtgroup_locksetup_enter()
686 * - If only one region is exposed to pseudo-locking we should in rdtgroup_locksetup_enter()
688 * for pseudo-locking should take into account both resources. in rdtgroup_locksetup_enter()
689 * Similarly, if a pseudo-locked region is created in one in rdtgroup_locksetup_enter()
696 return -EINVAL; in rdtgroup_locksetup_enter()
701 * platform does not support Cache Pseudo-Locking. in rdtgroup_locksetup_enter()
705 rdt_last_cmd_puts("Pseudo-locking not supported\n"); in rdtgroup_locksetup_enter()
706 return -EINVAL; in rdtgroup_locksetup_enter()
711 return -EINVAL; in rdtgroup_locksetup_enter()
716 return -EINVAL; in rdtgroup_locksetup_enter()
719 if (!cpumask_empty(&rdtgrp->cpu_mask)) { in rdtgroup_locksetup_enter()
721 return -EINVAL; in rdtgroup_locksetup_enter()
726 return -EIO; in rdtgroup_locksetup_enter()
731 rdt_last_cmd_puts("Unable to init pseudo-lock region\n"); in rdtgroup_locksetup_enter()
738 * anymore when this group would be used for pseudo-locking. This in rdtgroup_locksetup_enter()
741 free_rmid(rdtgrp->mon.rmid); in rdtgroup_locksetup_enter()
753 * rdtgroup_locksetup_exit - resource group exist locksetup mode
771 rdtgrp->mon.rmid = ret; in rdtgroup_locksetup_exit()
776 free_rmid(rdtgrp->mon.rmid); in rdtgroup_locksetup_exit()
785 * rdtgroup_cbm_overlaps_pseudo_locked - Test if CBM or portion is pseudo-locked
791 * pseudo-locked region on @d.
796 * Return: true if @cbm overlaps with pseudo-locked region on @d, false
804 if (d->plr) { in rdtgroup_cbm_overlaps_pseudo_locked()
805 cbm_len = d->plr->s->res->cache.cbm_len; in rdtgroup_cbm_overlaps_pseudo_locked()
806 cbm_b = d->plr->cbm; in rdtgroup_cbm_overlaps_pseudo_locked()
814 * rdtgroup_pseudo_locked_in_hierarchy - Pseudo-locked region in cache hierarchy
817 * The setup of a pseudo-locked region affects all cache instances within
819 * pseudo-locked regions exist within a cache hierarchy to prevent any
820 * attempts to create new pseudo-locked regions in the same hierarchy.
822 * Return: true if a pseudo-locked region exists in the hierarchy of @d or
837 * First determine which cpus have pseudo-locked regions in rdtgroup_pseudo_locked_in_hierarchy()
841 list_for_each_entry(d_i, &r->domains, list) { in rdtgroup_pseudo_locked_in_hierarchy()
842 if (d_i->plr) in rdtgroup_pseudo_locked_in_hierarchy()
844 &d_i->cpu_mask); in rdtgroup_pseudo_locked_in_hierarchy()
849 * Next test if new pseudo-locked region would intersect with in rdtgroup_pseudo_locked_in_hierarchy()
852 if (cpumask_intersects(&d->cpu_mask, cpu_with_psl)) in rdtgroup_pseudo_locked_in_hierarchy()
860 * measure_cycles_lat_fn - Measure cycle latency to read pseudo-locked memory
861 * @_plr: pseudo-lock region to measure
887 mem_r = READ_ONCE(plr->kmem); in measure_cycles_lat_fn()
893 for (i = 0; i < plr->size; i += 32) { in measure_cycles_lat_fn()
900 trace_pseudo_lock_mem_latency((u32)(end - start)); in measure_cycles_lat_fn()
904 plr->thread_done = 1; in measure_cycles_lat_fn()
905 wake_up_interruptible(&plr->lock_thread_wq); in measure_cycles_lat_fn()
954 miss_event = perf_event_create_kernel_counter(miss_attr, plr->cpu, in measure_residency_fn()
959 hit_event = perf_event_create_kernel_counter(hit_attr, plr->cpu, in measure_residency_fn()
987 * interrupts disabled - it is thus safe to read the counter index. in measure_residency_fn()
991 line_size = READ_ONCE(plr->line_size); in measure_residency_fn()
992 mem_r = READ_ONCE(plr->kmem); in measure_residency_fn()
993 size = READ_ONCE(plr->size); in measure_residency_fn()
996 * Read counter variables twice - first to load the instructions in measure_residency_fn()
1003 * From SDM: Performing back-to-back fast reads are not guaranteed in measure_residency_fn()
1039 /* Re-enable hardware prefetchers */ in measure_residency_fn()
1050 counts->miss_before = miss_before; in measure_residency_fn()
1051 counts->hits_before = hits_before; in measure_residency_fn()
1052 counts->miss_after = miss_after; in measure_residency_fn()
1053 counts->hits_after = hits_after; in measure_residency_fn()
1063 * Non-architectural event for the Goldmont Microarchitecture in measure_l2_residency()
1087 trace_pseudo_lock_l2(counts.hits_after - counts.hits_before, in measure_l2_residency()
1088 counts.miss_after - counts.miss_before); in measure_l2_residency()
1090 plr->thread_done = 1; in measure_l2_residency()
1091 wake_up_interruptible(&plr->lock_thread_wq); in measure_l2_residency()
1127 counts.miss_after -= counts.miss_before; in measure_l3_residency()
1137 counts.hits_after -= counts.hits_before; in measure_l3_residency()
1139 counts.hits_after -= min(counts.miss_after, counts.hits_after); in measure_l3_residency()
1141 counts.hits_after -= counts.hits_before; in measure_l3_residency()
1146 plr->thread_done = 1; in measure_l3_residency()
1147 wake_up_interruptible(&plr->lock_thread_wq); in measure_l3_residency()
1152 * pseudo_lock_measure_cycles - Trigger latency measure to pseudo-locked region
1153 * @rdtgrp: Resource group to which the pseudo-locked region belongs.
1154 * @sel: Selector of which measurement to perform on a pseudo-locked region.
1156 * The measurement of latency to access a pseudo-locked region should be
1157 * done from a cpu that is associated with that pseudo-locked region.
1165 struct pseudo_lock_region *plr = rdtgrp->plr; in pseudo_lock_measure_cycles()
1168 int ret = -1; in pseudo_lock_measure_cycles()
1173 if (rdtgrp->flags & RDT_DELETED) { in pseudo_lock_measure_cycles()
1174 ret = -ENODEV; in pseudo_lock_measure_cycles()
1178 if (!plr->d) { in pseudo_lock_measure_cycles()
1179 ret = -ENODEV; in pseudo_lock_measure_cycles()
1183 plr->thread_done = 0; in pseudo_lock_measure_cycles()
1184 cpu = cpumask_first(&plr->d->cpu_mask); in pseudo_lock_measure_cycles()
1186 ret = -ENODEV; in pseudo_lock_measure_cycles()
1190 plr->cpu = cpu; in pseudo_lock_measure_cycles()
1217 ret = wait_event_interruptible(plr->lock_thread_wq, in pseudo_lock_measure_cycles()
1218 plr->thread_done == 1); in pseudo_lock_measure_cycles()
1234 struct rdtgroup *rdtgrp = file->private_data; in pseudo_lock_measure_trigger()
1240 buf_size = min(count, (sizeof(buf) - 1)); in pseudo_lock_measure_trigger()
1242 return -EFAULT; in pseudo_lock_measure_trigger()
1248 return -EINVAL; in pseudo_lock_measure_trigger()
1249 ret = debugfs_file_get(file->f_path.dentry); in pseudo_lock_measure_trigger()
1255 debugfs_file_put(file->f_path.dentry); in pseudo_lock_measure_trigger()
1268 * rdtgroup_pseudo_lock_create - Create a pseudo-locked region
1269 * @rdtgrp: resource group to which pseudo-lock region belongs
1271 * Called when a resource group in the pseudo-locksetup mode receives a
1272 * valid schemata that should be pseudo-locked. Since the resource group is
1273 * in pseudo-locksetup mode the &struct pseudo_lock_region has already been
1275 * occurs the resource group remains in the pseudo-locksetup mode with the
1277 * information and ready for the user to re-attempt pseudo-locking by
1280 * Return: 0 if the pseudo-locked region was successfully pseudo-locked, <0
1281 * on failure. Descriptive error will be written to last_cmd_status buffer.
1285 struct pseudo_lock_region *plr = rdtgrp->plr; in rdtgroup_pseudo_lock_create()
1297 ret = -EINVAL; in rdtgroup_pseudo_lock_create()
1301 plr->thread_done = 0; in rdtgroup_pseudo_lock_create()
1304 cpu_to_node(plr->cpu), in rdtgroup_pseudo_lock_create()
1305 "pseudo_lock/%u", plr->cpu); in rdtgroup_pseudo_lock_create()
1312 kthread_bind(thread, plr->cpu); in rdtgroup_pseudo_lock_create()
1315 ret = wait_event_interruptible(plr->lock_thread_wq, in rdtgroup_pseudo_lock_create()
1316 plr->thread_done == 1); in rdtgroup_pseudo_lock_create()
1324 * empty pseudo-locking loop. in rdtgroup_pseudo_lock_create()
1338 * pseudo-locked region will still be here on return. in rdtgroup_pseudo_lock_create()
1341 * deadlock with the mm->mmap_lock which is obtained in the in rdtgroup_pseudo_lock_create()
1348 plr->debugfs_dir = debugfs_create_dir(rdtgrp->kn->name, in rdtgroup_pseudo_lock_create()
1350 if (!IS_ERR_OR_NULL(plr->debugfs_dir)) in rdtgroup_pseudo_lock_create()
1352 plr->debugfs_dir, rdtgrp, in rdtgroup_pseudo_lock_create()
1358 rdtgrp, "%s", rdtgrp->kn->name); in rdtgroup_pseudo_lock_create()
1369 /* We released the mutex - check if group was removed while we did so */ in rdtgroup_pseudo_lock_create()
1370 if (rdtgrp->flags & RDT_DELETED) { in rdtgroup_pseudo_lock_create()
1371 ret = -ENODEV; in rdtgroup_pseudo_lock_create()
1375 plr->minor = new_minor; in rdtgroup_pseudo_lock_create()
1377 rdtgrp->mode = RDT_MODE_PSEUDO_LOCKED; in rdtgroup_pseudo_lock_create()
1378 closid_free(rdtgrp->closid); in rdtgroup_pseudo_lock_create()
1388 debugfs_remove_recursive(plr->debugfs_dir); in rdtgroup_pseudo_lock_create()
1399 * rdtgroup_pseudo_lock_remove - Remove a pseudo-locked region
1400 * @rdtgrp: resource group to which the pseudo-locked region belongs
1402 * The removal of a pseudo-locked region can be initiated when the resource
1405 * not go back to pseudo-locksetup mode before it is removed, instead it is
1414 struct pseudo_lock_region *plr = rdtgrp->plr; in rdtgroup_pseudo_lock_remove()
1416 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { in rdtgroup_pseudo_lock_remove()
1418 * Default group cannot be a pseudo-locked region so we can in rdtgroup_pseudo_lock_remove()
1421 closid_free(rdtgrp->closid); in rdtgroup_pseudo_lock_remove()
1426 debugfs_remove_recursive(rdtgrp->plr->debugfs_dir); in rdtgroup_pseudo_lock_remove()
1427 device_destroy(pseudo_lock_class, MKDEV(pseudo_lock_major, plr->minor)); in rdtgroup_pseudo_lock_remove()
1428 pseudo_lock_minor_release(plr->minor); in rdtgroup_pseudo_lock_remove()
1443 return -ENODEV; in pseudo_lock_dev_open()
1446 filp->private_data = rdtgrp; in pseudo_lock_dev_open()
1447 atomic_inc(&rdtgrp->waitcount); in pseudo_lock_dev_open()
1448 /* Perform a non-seekable open - llseek is not supported */ in pseudo_lock_dev_open()
1449 filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE); in pseudo_lock_dev_open()
1461 rdtgrp = filp->private_data; in pseudo_lock_dev_release()
1465 return -ENODEV; in pseudo_lock_dev_release()
1467 filp->private_data = NULL; in pseudo_lock_dev_release()
1468 atomic_dec(&rdtgrp->waitcount); in pseudo_lock_dev_release()
1476 return -EINVAL; in pseudo_lock_dev_mremap()
1485 unsigned long vsize = vma->vm_end - vma->vm_start; in pseudo_lock_dev_mmap()
1486 unsigned long off = vma->vm_pgoff << PAGE_SHIFT; in pseudo_lock_dev_mmap()
1494 rdtgrp = filp->private_data; in pseudo_lock_dev_mmap()
1498 return -ENODEV; in pseudo_lock_dev_mmap()
1501 plr = rdtgrp->plr; in pseudo_lock_dev_mmap()
1503 if (!plr->d) { in pseudo_lock_dev_mmap()
1505 return -ENODEV; in pseudo_lock_dev_mmap()
1510 * with the pseudo-locked region. If this is not the case the task in pseudo_lock_dev_mmap()
1512 * pseudo-locked region. in pseudo_lock_dev_mmap()
1514 if (!cpumask_subset(current->cpus_ptr, &plr->d->cpu_mask)) { in pseudo_lock_dev_mmap()
1516 return -EINVAL; in pseudo_lock_dev_mmap()
1519 physical = __pa(plr->kmem) >> PAGE_SHIFT; in pseudo_lock_dev_mmap()
1520 psize = plr->size - off; in pseudo_lock_dev_mmap()
1522 if (off > plr->size) { in pseudo_lock_dev_mmap()
1524 return -ENOSPC; in pseudo_lock_dev_mmap()
1529 * do not allow copy-on-write mapping. in pseudo_lock_dev_mmap()
1531 if (!(vma->vm_flags & VM_SHARED)) { in pseudo_lock_dev_mmap()
1533 return -EINVAL; in pseudo_lock_dev_mmap()
1538 return -ENOSPC; in pseudo_lock_dev_mmap()
1541 memset(plr->kmem + off, 0, vsize); in pseudo_lock_dev_mmap()
1543 if (remap_pfn_range(vma, vma->vm_start, physical + vma->vm_pgoff, in pseudo_lock_dev_mmap()
1544 vsize, vma->vm_page_prot)) { in pseudo_lock_dev_mmap()
1546 return -EAGAIN; in pseudo_lock_dev_mmap()
1548 vma->vm_ops = &pseudo_mmap_ops; in pseudo_lock_dev_mmap()
1570 return kasprintf(GFP_KERNEL, "pseudo_lock/%s", rdtgrp->kn->name); in pseudo_lock_devnode()
1590 pseudo_lock_class->devnode = pseudo_lock_devnode; in rdt_pseudo_lock_init()