1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2020-21 IBM Corp.
6 #define pr_fmt(fmt) "vas: " fmt
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/export.h>
11 #include <linux/types.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
14 #include <linux/interrupt.h>
15 #include <linux/irqdomain.h>
16 #include <asm/machdep.h>
17 #include <asm/hvcall.h>
18 #include <asm/plpar_wrappers.h>
22 #define VAS_INVALID_WIN_ADDRESS 0xFFFFFFFFFFFFFFFFul
23 #define VAS_DEFAULT_DOMAIN_ID 0xFFFFFFFFFFFFFFFFul
24 /* The hypervisor allows one credit per window right now */
25 #define DEF_WIN_CREDS 1
27 static struct vas_all_caps caps_all;
28 static bool copypaste_feat;
29 static struct hv_vas_cop_feat_caps hv_cop_caps;
31 static struct vas_caps vascaps[VAS_MAX_FEAT_TYPE];
32 static DEFINE_MUTEX(vas_pseries_mutex);
33 static bool migration_in_progress;
35 static long hcall_return_busy_check(long rc)
37 /* Check if we are stalled for some time */
38 if (H_IS_LONG_BUSY(rc)) {
39 msleep(get_longbusy_msecs(rc));
41 } else if (rc == H_BUSY) {
49 * Allocate VAS window hcall
51 static int h_allocate_vas_window(struct pseries_vas_window *win, u64 *domain,
52 u8 wintype, u16 credits)
54 long retbuf[PLPAR_HCALL9_BUFSIZE] = {0};
58 rc = plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, wintype,
59 credits, domain[0], domain[1], domain[2],
60 domain[3], domain[4], domain[5]);
62 rc = hcall_return_busy_check(rc);
63 } while (rc == H_BUSY);
65 if (rc == H_SUCCESS) {
66 if (win->win_addr == VAS_INVALID_WIN_ADDRESS) {
67 pr_err("H_ALLOCATE_VAS_WINDOW: COPY/PASTE is not supported\n");
70 win->vas_win.winid = retbuf[0];
71 win->win_addr = retbuf[1];
72 win->complete_irq = retbuf[2];
73 win->fault_irq = retbuf[3];
77 pr_err("H_ALLOCATE_VAS_WINDOW error: %ld, wintype: %u, credits: %u\n",
78 rc, wintype, credits);
84 * Deallocate VAS window hcall.
86 static int h_deallocate_vas_window(u64 winid)
91 rc = plpar_hcall_norets(H_DEALLOCATE_VAS_WINDOW, winid);
93 rc = hcall_return_busy_check(rc);
94 } while (rc == H_BUSY);
99 pr_err("H_DEALLOCATE_VAS_WINDOW error: %ld, winid: %llu\n",
106 * After the window is opened with allocate window hcall, configure it
107 * with flags and LPAR PID before using.
109 static int h_modify_vas_window(struct pseries_vas_window *win)
114 * AMR value is not supported in Linux VAS implementation.
115 * The hypervisor ignores it if 0 is passed.
118 rc = plpar_hcall_norets(H_MODIFY_VAS_WINDOW,
119 win->vas_win.winid, win->pid, 0,
120 VAS_MOD_WIN_FLAGS, 0);
122 rc = hcall_return_busy_check(rc);
123 } while (rc == H_BUSY);
128 pr_err("H_MODIFY_VAS_WINDOW error: %ld, winid %u pid %u\n",
129 rc, win->vas_win.winid, win->pid);
134 * This hcall is used to determine the capabilities from the hypervisor.
135 * @hcall: H_QUERY_VAS_CAPABILITIES or H_QUERY_NX_CAPABILITIES
136 * @query_type: If 0 is passed, the hypervisor returns the overall
137 * capabilities which provides all feature(s) that are
138 * available. Then query the hypervisor to get the
139 * corresponding capabilities for the specific feature.
140 * Example: H_QUERY_VAS_CAPABILITIES provides VAS GZIP QoS
141 * and VAS GZIP Default capabilities.
142 * H_QUERY_NX_CAPABILITIES provides NX GZIP
144 * @result: Return buffer to save capabilities.
146 int h_query_vas_capabilities(const u64 hcall, u8 query_type, u64 result)
150 rc = plpar_hcall_norets(hcall, query_type, result);
155 /* H_FUNCTION means HV does not support VAS so don't print an error */
156 if (rc != H_FUNCTION) {
157 pr_err("%s error %ld, query_type %u, result buffer 0x%llx\n",
158 (hcall == H_QUERY_VAS_CAPABILITIES) ?
159 "H_QUERY_VAS_CAPABILITIES" :
160 "H_QUERY_NX_CAPABILITIES",
161 rc, query_type, result);
166 EXPORT_SYMBOL_GPL(h_query_vas_capabilities);
169 * hcall to get fault CRB from the hypervisor.
171 static int h_get_nx_fault(u32 winid, u64 buffer)
175 rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer);
180 pr_err("H_GET_NX_FAULT error: %ld, winid %u, buffer 0x%llx\n",
187 * Handle the fault interrupt.
188 * When the fault interrupt is received for each window, query the
189 * hypervisor to get the fault CRB on the specific fault. Then
190 * process the CRB by updating CSB or send signal if the user space
192 * Note: The hypervisor forwards an interrupt for each fault request.
193 * So one fault CRB to process for each H_GET_NX_FAULT hcall.
195 static irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data)
197 struct pseries_vas_window *txwin = data;
198 struct coprocessor_request_block crb;
199 struct vas_user_win_ref *tsk_ref;
202 rc = h_get_nx_fault(txwin->vas_win.winid, (u64)virt_to_phys(&crb));
204 tsk_ref = &txwin->vas_win.task_ref;
206 vas_update_csb(&crb, tsk_ref);
213 * Allocate window and setup IRQ mapping.
215 static int allocate_setup_window(struct pseries_vas_window *txwin,
216 u64 *domain, u8 wintype)
220 rc = h_allocate_vas_window(txwin, domain, wintype, DEF_WIN_CREDS);
224 * On PowerVM, the hypervisor setup and forwards the fault
225 * interrupt per window. So the IRQ setup and fault handling
226 * will be done for each open window separately.
228 txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq);
229 if (!txwin->fault_virq) {
230 pr_err("Failed irq mapping %d\n", txwin->fault_irq);
235 txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d",
236 txwin->vas_win.winid);
242 rc = request_threaded_irq(txwin->fault_virq, NULL,
243 pseries_vas_fault_thread_fn, IRQF_ONESHOT,
246 pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n",
247 txwin->vas_win.winid, txwin->fault_virq, rc);
251 txwin->vas_win.wcreds_max = DEF_WIN_CREDS;
257 irq_dispose_mapping(txwin->fault_virq);
259 h_deallocate_vas_window(txwin->vas_win.winid);
263 static inline void free_irq_setup(struct pseries_vas_window *txwin)
265 free_irq(txwin->fault_virq, txwin);
267 irq_dispose_mapping(txwin->fault_virq);
270 static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
271 enum vas_cop_type cop_type)
273 long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID};
274 struct vas_cop_feat_caps *cop_feat_caps;
275 struct vas_caps *caps;
276 struct pseries_vas_window *txwin;
279 txwin = kzalloc(sizeof(*txwin), GFP_KERNEL);
281 return ERR_PTR(-ENOMEM);
284 * A VAS window can have many credits which means that many
285 * requests can be issued simultaneously. But the hypervisor
286 * restricts one credit per window.
287 * The hypervisor introduces 2 different types of credits:
288 * Default credit type (Uses normal priority FIFO):
289 * A limited number of credits are assigned to partitions
290 * based on processor entitlement. But these credits may be
291 * over-committed on a system depends on whether the CPUs
292 * are in shared or dedicated modes - that is, more requests
293 * may be issued across the system than NX can service at
294 * once which can result in paste command failure (RMA_busy).
295 * Then the process has to resend requests or fall-back to
297 * Quality of Service (QoS) credit type (Uses high priority FIFO):
298 * To avoid NX HW contention, the system admins can assign
299 * QoS credits for each LPAR so that this partition is
300 * guaranteed access to NX resources. These credits are
301 * assigned to partitions via the HMC.
302 * Refer PAPR for more information.
304 * Allocate window with QoS credits if user requested. Otherwise
305 * default credits are used.
307 if (flags & VAS_TX_WIN_FLAG_QOS_CREDIT)
308 caps = &vascaps[VAS_GZIP_QOS_FEAT_TYPE];
310 caps = &vascaps[VAS_GZIP_DEF_FEAT_TYPE];
312 cop_feat_caps = &caps->caps;
314 if (atomic_inc_return(&cop_feat_caps->nr_used_credits) >
315 atomic_read(&cop_feat_caps->nr_total_credits)) {
316 pr_err("Credits are not available to allocate window\n");
323 * The user space is requesting to allocate a window on
324 * a VAS instance where the process is executing.
325 * On PowerVM, domain values are passed to the hypervisor
326 * to select VAS instance. Useful if the process is
327 * affinity to NUMA node.
328 * The hypervisor selects VAS instance if
329 * VAS_DEFAULT_DOMAIN_ID (-1) is passed for domain values.
330 * The h_allocate_vas_window hcall is defined to take a
331 * domain values as specified by h_home_node_associativity,
332 * So no unpacking needs to be done.
334 rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain,
335 VPHN_FLAG_VCPU, smp_processor_id());
336 if (rc != H_SUCCESS) {
337 pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc);
342 txwin->pid = mfspr(SPRN_PID);
345 * Allocate / Deallocate window hcalls and setup / free IRQs
346 * have to be protected with mutex.
347 * Open VAS window: Allocate window hcall and setup IRQ
348 * Close VAS window: Deallocate window hcall and free IRQ
349 * The hypervisor waits until all NX requests are
350 * completed before closing the window. So expects OS
351 * to handle NX faults, means IRQ can be freed only
352 * after the deallocate window hcall is returned.
353 * So once the window is closed with deallocate hcall before
354 * the IRQ is freed, it can be assigned to new allocate
355 * hcall with the same fault IRQ by the hypervisor. It can
356 * result in setup IRQ fail for the new window since the
357 * same fault IRQ is not freed by the OS before.
359 mutex_lock(&vas_pseries_mutex);
360 if (migration_in_progress)
363 rc = allocate_setup_window(txwin, (u64 *)&domain[0],
364 cop_feat_caps->win_type);
365 mutex_unlock(&vas_pseries_mutex);
370 * Modify window and it is ready to use.
372 rc = h_modify_vas_window(txwin);
374 rc = get_vas_user_win_ref(&txwin->vas_win.task_ref);
378 txwin->win_type = cop_feat_caps->win_type;
379 mutex_lock(&vas_pseries_mutex);
381 * Possible to lose the acquired credit with DLPAR core
382 * removal after the window is opened. So if there are any
383 * closed windows (means with lost credits), do not give new
384 * window to user space. New windows will be opened only
385 * after the existing windows are reopened when credits are
388 if (!caps->nr_close_wins) {
389 list_add(&txwin->win_list, &caps->list);
390 caps->nr_open_windows++;
391 mutex_unlock(&vas_pseries_mutex);
392 vas_user_win_add_mm_context(&txwin->vas_win.task_ref);
393 return &txwin->vas_win;
395 mutex_unlock(&vas_pseries_mutex);
397 put_vas_user_win_ref(&txwin->vas_win.task_ref);
399 pr_err("No credit is available to allocate window\n");
403 * Window is not operational. Free IRQ before closing
404 * window so that do not have to hold mutex.
406 free_irq_setup(txwin);
407 h_deallocate_vas_window(txwin->vas_win.winid);
409 atomic_dec(&cop_feat_caps->nr_used_credits);
414 static u64 vas_paste_address(struct vas_window *vwin)
416 struct pseries_vas_window *win;
418 win = container_of(vwin, struct pseries_vas_window, vas_win);
419 return win->win_addr;
422 static int deallocate_free_window(struct pseries_vas_window *win)
427 * The hypervisor waits for all requests including faults
428 * are processed before closing the window - Means all
429 * credits have to be returned. In the case of fault
430 * request, a credit is returned after OS issues
431 * H_GET_NX_FAULT hcall.
432 * So free IRQ after executing H_DEALLOCATE_VAS_WINDOW
435 rc = h_deallocate_vas_window(win->vas_win.winid);
442 static int vas_deallocate_window(struct vas_window *vwin)
444 struct pseries_vas_window *win;
445 struct vas_cop_feat_caps *caps;
451 win = container_of(vwin, struct pseries_vas_window, vas_win);
453 /* Should not happen */
454 if (win->win_type >= VAS_MAX_FEAT_TYPE) {
455 pr_err("Window (%u): Invalid window type %u\n",
456 vwin->winid, win->win_type);
460 caps = &vascaps[win->win_type].caps;
461 mutex_lock(&vas_pseries_mutex);
463 * VAS window is already closed in the hypervisor when
464 * lost the credit or with migration. So just remove the entry
465 * from the list, remove task references and free vas_window
468 if (!(win->vas_win.status & VAS_WIN_NO_CRED_CLOSE) &&
469 !(win->vas_win.status & VAS_WIN_MIGRATE_CLOSE)) {
470 rc = deallocate_free_window(win);
472 mutex_unlock(&vas_pseries_mutex);
476 vascaps[win->win_type].nr_close_wins--;
478 list_del(&win->win_list);
479 atomic_dec(&caps->nr_used_credits);
480 vascaps[win->win_type].nr_open_windows--;
481 mutex_unlock(&vas_pseries_mutex);
483 put_vas_user_win_ref(&vwin->task_ref);
484 mm_context_remove_vas_window(vwin->task_ref.mm);
490 static const struct vas_user_win_ops vops_pseries = {
491 .open_win = vas_allocate_window, /* Open and configure window */
492 .paste_addr = vas_paste_address, /* To do copy/paste */
493 .close_win = vas_deallocate_window, /* Close window */
497 * Supporting only nx-gzip coprocessor type now, but this API code
498 * extended to other coprocessor types later.
500 int vas_register_api_pseries(struct module *mod, enum vas_cop_type cop_type,
508 rc = vas_register_coproc_api(mod, cop_type, name, &vops_pseries);
512 EXPORT_SYMBOL_GPL(vas_register_api_pseries);
514 void vas_unregister_api_pseries(void)
516 vas_unregister_coproc_api();
518 EXPORT_SYMBOL_GPL(vas_unregister_api_pseries);
521 * Get the specific capabilities based on the feature type.
522 * Right now supports GZIP default and GZIP QoS capabilities.
524 static int __init get_vas_capabilities(u8 feat, enum vas_cop_feat_type type,
525 struct hv_vas_cop_feat_caps *hv_caps)
527 struct vas_cop_feat_caps *caps;
528 struct vas_caps *vcaps;
531 vcaps = &vascaps[type];
532 memset(vcaps, 0, sizeof(*vcaps));
533 INIT_LIST_HEAD(&vcaps->list);
538 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, feat,
539 (u64)virt_to_phys(hv_caps));
543 caps->user_mode = hv_caps->user_mode;
544 if (!(caps->user_mode & VAS_COPY_PASTE_USER_MODE)) {
545 pr_err("User space COPY/PASTE is not supported\n");
549 caps->descriptor = be64_to_cpu(hv_caps->descriptor);
550 caps->win_type = hv_caps->win_type;
551 if (caps->win_type >= VAS_MAX_FEAT_TYPE) {
552 pr_err("Unsupported window type %u\n", caps->win_type);
555 caps->max_lpar_creds = be16_to_cpu(hv_caps->max_lpar_creds);
556 caps->max_win_creds = be16_to_cpu(hv_caps->max_win_creds);
557 atomic_set(&caps->nr_total_credits,
558 be16_to_cpu(hv_caps->target_lpar_creds));
559 if (feat == VAS_GZIP_DEF_FEAT) {
560 caps->def_lpar_creds = be16_to_cpu(hv_caps->def_lpar_creds);
562 if (caps->max_win_creds < DEF_WIN_CREDS) {
563 pr_err("Window creds(%u) > max allowed window creds(%u)\n",
564 DEF_WIN_CREDS, caps->max_win_creds);
569 rc = sysfs_add_vas_caps(caps);
573 copypaste_feat = true;
579 * VAS windows can be closed due to lost credits when the core is
580 * removed. So reopen them if credits are available due to DLPAR
581 * core add and set the window active status. When NX sees the page
582 * fault on the unmapped paste address, the kernel handles the fault
583 * by setting the remapping to new paste address if the window is
586 static int reconfig_open_windows(struct vas_caps *vcaps, int creds,
589 long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID};
590 struct vas_cop_feat_caps *caps = &vcaps->caps;
591 struct pseries_vas_window *win = NULL, *tmp;
596 * Nothing to do if there are no closed windows.
598 if (!vcaps->nr_close_wins)
602 * For the core removal, the hypervisor reduces the credits
603 * assigned to the LPAR and the kernel closes VAS windows
604 * in the hypervisor depends on reduced credits. The kernel
605 * uses LIFO (the last windows that are opened will be closed
606 * first) and expects to open in the same order when credits
608 * For example, 40 windows are closed when the LPAR lost 2 cores
609 * (dedicated). If 1 core is added, this LPAR can have 20 more
610 * credits. It means the kernel can reopen 20 windows. So move
611 * 20 entries in the VAS windows lost and reopen next 20 windows.
612 * For partition migration, reopen all windows that are closed
615 if ((vcaps->nr_close_wins > creds) && !migrate)
616 mv_ents = vcaps->nr_close_wins - creds;
618 list_for_each_entry_safe(win, tmp, &vcaps->list, win_list) {
626 * Open windows if they are closed only with migration or
627 * DLPAR (lost credit) before.
630 flag = VAS_WIN_MIGRATE_CLOSE;
632 flag = VAS_WIN_NO_CRED_CLOSE;
634 list_for_each_entry_safe_from(win, tmp, &vcaps->list, win_list) {
636 * This window is closed with DLPAR and migration events.
637 * So reopen the window with the last event.
638 * The user space is not suspended with the current
639 * migration notifier. So the user space can issue DLPAR
640 * CPU hotplug while migration in progress. In this case
641 * this window will be opened with the last event.
643 if ((win->vas_win.status & VAS_WIN_NO_CRED_CLOSE) &&
644 (win->vas_win.status & VAS_WIN_MIGRATE_CLOSE)) {
645 win->vas_win.status &= ~flag;
650 * Nothing to do on this window if it is not closed
653 if (!(win->vas_win.status & flag))
656 rc = allocate_setup_window(win, (u64 *)&domain[0],
661 rc = h_modify_vas_window(win);
665 mutex_lock(&win->vas_win.task_ref.mmap_mutex);
667 * Set window status to active
669 win->vas_win.status &= ~flag;
670 mutex_unlock(&win->vas_win.task_ref.mmap_mutex);
671 win->win_type = caps->win_type;
672 if (!--vcaps->nr_close_wins)
679 * Window modify HCALL failed. So close the window to the
680 * hypervisor and return.
683 h_deallocate_vas_window(win->vas_win.winid);
688 * The hypervisor reduces the available credits if the LPAR lost core. It
689 * means the excessive windows should not be active and the user space
690 * should not be using these windows to send compression requests to NX.
691 * So the kernel closes the excessive windows and unmap the paste address
692 * such that the user space receives paste instruction failure. Then up to
693 * the user space to fall back to SW compression and manage with the
696 static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
699 struct pseries_vas_window *win, *tmp;
700 struct vas_user_win_ref *task_ref;
701 struct vm_area_struct *vma;
705 flag = VAS_WIN_MIGRATE_CLOSE;
707 flag = VAS_WIN_NO_CRED_CLOSE;
709 list_for_each_entry_safe(win, tmp, &vcap->list, win_list) {
711 * This window is already closed due to lost credit
712 * or for migration before. Go for next window.
713 * For migration, nothing to do since this window
714 * closed for DLPAR and will be reopened even on
715 * the destination system with other DLPAR operation.
717 if ((win->vas_win.status & VAS_WIN_MIGRATE_CLOSE) ||
718 (win->vas_win.status & VAS_WIN_NO_CRED_CLOSE)) {
719 win->vas_win.status |= flag;
723 task_ref = &win->vas_win.task_ref;
724 mutex_lock(&task_ref->mmap_mutex);
727 * Number of available credits are reduced, So select
730 win->vas_win.status |= flag;
732 mmap_write_lock(task_ref->mm);
734 * vma is set in the original mapping. But this mapping
735 * is done with mmap() after the window is opened with ioctl.
736 * so we may not see the original mapping if the core remove
737 * is done before the original mmap() and after the ioctl.
740 zap_page_range(vma, vma->vm_start,
741 vma->vm_end - vma->vm_start);
743 mmap_write_unlock(task_ref->mm);
744 mutex_unlock(&task_ref->mmap_mutex);
746 * Close VAS window in the hypervisor, but do not
747 * free vas_window struct since it may be reused
748 * when the credit is available later (DLPAR with
749 * adding cores). This struct will be used
750 * later when the process issued with close(FD).
752 rc = deallocate_free_window(win);
754 * This failure is from the hypervisor.
755 * No way to stop migration for these failures.
756 * So ignore error and continue closing other windows.
761 vcap->nr_close_wins++;
764 * For migration, do not depend on lpar_creds in case if
765 * mismatch with the hypervisor value (should not happen).
766 * So close all active windows in the list and will be
767 * reopened windows based on the new lpar_creds on the
768 * destination system during resume.
770 if (!migrate && !--excess_creds)
778 * Get new VAS capabilities when the core add/removal configuration
779 * changes. Reconfig window configurations based on the credits
780 * availability from this new capabilities.
782 int vas_reconfig_capabilties(u8 type)
784 struct vas_cop_feat_caps *caps;
785 int old_nr_creds, new_nr_creds;
786 struct vas_caps *vcaps;
787 int rc = 0, nr_active_wins;
789 if (type >= VAS_MAX_FEAT_TYPE) {
790 pr_err("Invalid credit type %d\n", type);
794 vcaps = &vascaps[type];
797 mutex_lock(&vas_pseries_mutex);
798 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, vcaps->feat,
799 (u64)virt_to_phys(&hv_cop_caps));
803 new_nr_creds = be16_to_cpu(hv_cop_caps.target_lpar_creds);
805 old_nr_creds = atomic_read(&caps->nr_total_credits);
807 atomic_set(&caps->nr_total_credits, new_nr_creds);
809 * The total number of available credits may be decreased or
810 * inceased with DLPAR operation. Means some windows have to be
811 * closed / reopened. Hold the vas_pseries_mutex so that the
812 * the user space can not open new windows.
814 if (old_nr_creds < new_nr_creds) {
816 * If the existing target credits is less than the new
817 * target, reopen windows if they are closed due to
818 * the previous DLPAR (core removal).
820 rc = reconfig_open_windows(vcaps, new_nr_creds - old_nr_creds,
824 * # active windows is more than new LPAR available
825 * credits. So close the excessive windows.
826 * On pseries, each window will have 1 credit.
828 nr_active_wins = vcaps->nr_open_windows - vcaps->nr_close_wins;
829 if (nr_active_wins > new_nr_creds)
830 rc = reconfig_close_windows(vcaps,
831 nr_active_wins - new_nr_creds,
836 mutex_unlock(&vas_pseries_mutex);
840 * Total number of default credits available (target_credits)
841 * in LPAR depends on number of cores configured. It varies based on
842 * whether processors are in shared mode or dedicated mode.
843 * Get the notifier when CPU configuration is changed with DLPAR
844 * operation so that get the new target_credits (vas default capabilities)
845 * and then update the existing windows usage if needed.
847 static int pseries_vas_notifier(struct notifier_block *nb,
848 unsigned long action, void *data)
850 struct of_reconfig_data *rd = data;
851 struct device_node *dn = rd->dn;
852 const __be32 *intserv = NULL;
855 if ((action == OF_RECONFIG_ATTACH_NODE) ||
856 (action == OF_RECONFIG_DETACH_NODE))
857 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
860 * Processor config is not changed
865 rc = vas_reconfig_capabilties(VAS_GZIP_DEF_FEAT_TYPE);
867 pr_err("Failed reconfig VAS capabilities with DLPAR\n");
872 static struct notifier_block pseries_vas_nb = {
873 .notifier_call = pseries_vas_notifier,
877 * For LPM, all windows have to be closed on the source partition
878 * before migration and reopen them on the destination partition
879 * after migration. So closing windows during suspend and
880 * reopen them during resume.
882 int vas_migration_handler(int action)
884 struct vas_cop_feat_caps *caps;
885 int old_nr_creds, new_nr_creds = 0;
886 struct vas_caps *vcaps;
890 * NX-GZIP is not enabled. Nothing to do for migration.
895 mutex_lock(&vas_pseries_mutex);
897 if (action == VAS_SUSPEND)
898 migration_in_progress = true;
900 migration_in_progress = false;
902 for (i = 0; i < VAS_MAX_FEAT_TYPE; i++) {
905 old_nr_creds = atomic_read(&caps->nr_total_credits);
907 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES,
909 (u64)virt_to_phys(&hv_cop_caps));
911 new_nr_creds = be16_to_cpu(hv_cop_caps.target_lpar_creds);
913 * Should not happen. But incase print messages, close
914 * all windows in the list during suspend and reopen
915 * windows based on new lpar_creds on the destination
918 if (old_nr_creds != new_nr_creds) {
919 pr_err("Target credits mismatch with the hypervisor\n");
920 pr_err("state(%d): lpar creds: %d HV lpar creds: %d\n",
921 action, old_nr_creds, new_nr_creds);
922 pr_err("Used creds: %d, Active creds: %d\n",
923 atomic_read(&caps->nr_used_credits),
924 vcaps->nr_open_windows - vcaps->nr_close_wins);
927 pr_err("state(%d): Get VAS capabilities failed with %d\n",
930 * We can not stop migration with the current lpm
931 * implementation. So continue closing all windows in
932 * the list (during suspend) and return without
933 * opening windows (during resume) if VAS capabilities
936 if (action == VAS_RESUME)
942 rc = reconfig_close_windows(vcaps, vcaps->nr_open_windows,
946 atomic_set(&caps->nr_total_credits, new_nr_creds);
947 rc = reconfig_open_windows(vcaps, new_nr_creds, true);
950 /* should not happen */
951 pr_err("Invalid migration action %d\n", action);
957 * Ignore errors during suspend and return for resume.
959 if (rc && (action == VAS_RESUME))
964 mutex_unlock(&vas_pseries_mutex);
968 static int __init pseries_vas_init(void)
970 struct hv_vas_all_caps *hv_caps;
974 * Linux supports user space COPY/PASTE only with Radix
976 if (!radix_enabled()) {
977 pr_err("API is supported only with radix page tables\n");
981 hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
985 * Get VAS overall capabilities by passing 0 to feature type.
987 rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, 0,
988 (u64)virt_to_phys(hv_caps));
992 caps_all.descriptor = be64_to_cpu(hv_caps->descriptor);
993 caps_all.feat_type = be64_to_cpu(hv_caps->feat_type);
995 sysfs_pseries_vas_init(&caps_all);
998 * QOS capabilities available
1000 if (caps_all.feat_type & VAS_GZIP_QOS_FEAT_BIT) {
1001 rc = get_vas_capabilities(VAS_GZIP_QOS_FEAT,
1002 VAS_GZIP_QOS_FEAT_TYPE, &hv_cop_caps);
1008 * Default capabilities available
1010 if (caps_all.feat_type & VAS_GZIP_DEF_FEAT_BIT)
1011 rc = get_vas_capabilities(VAS_GZIP_DEF_FEAT,
1012 VAS_GZIP_DEF_FEAT_TYPE, &hv_cop_caps);
1014 if (!rc && copypaste_feat) {
1015 if (firmware_has_feature(FW_FEATURE_LPAR))
1016 of_reconfig_notifier_register(&pseries_vas_nb);
1018 pr_info("GZIP feature is available\n");
1021 * Should not happen, but only when get default
1022 * capabilities HCALL failed. So disable copy paste
1025 copypaste_feat = false;
1032 machine_device_initcall(pseries, pseries_vas_init);