All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] powerpc/pseries/vas: VAS/NXGZIP support with LPM
@ 2021-12-27 10:56 Haren Myneni
  2021-12-27 10:58 ` [RFC PATCH 1/3] powerpc/pseries/vas: Modify reconfig open/close functions for migration Haren Myneni
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Haren Myneni @ 2021-12-27 10:56 UTC (permalink / raw)
  To: mpe, linuxppc-dev, npiggin, nathanl; +Cc: haren


Virtual Accelerator Switchboard (VAS) is an engine stays on the
chip. So all windows opened on a specific engine belongs to VAS
the chip. The hypervisor expects the partition to close all
active windows on the sources system and reopen them after
migration on the destination machine.

This patch series adds VAS support with the partition migration.
When the migration initiates, the VAS code gets suspend notifier
which closes all active windows and sets VAS_WIN_MIGRATE_CLOSE as
window status. Whereas receives resume notifier after migration
to reopen all windows which has VAS_WIN_MIGRATE_CLOSE status.

These patches depend on VAS/DLPAR support patch series
(https://lists.ozlabs.org/pipermail/linuxppc-dev/2021-December/238331.html)
Also the suspend/resume notifier code is added in a separate patch
and will be posted later with the actual patches.

Haren Myneni (3):
  powerpc/pseries/vas: Modify reconfig open/close functions for
    migration
  powerpc/pseries/vas: Add VAS suspend/resume notifier
  powerpc/pseries/vas: Use migration_in_progress to disable DLPAR

 arch/powerpc/include/asm/vas.h       |   2 +
 arch/powerpc/platforms/pseries/vas.c | 176 ++++++++++++++++++++++++---
 2 files changed, 162 insertions(+), 16 deletions(-)

-- 
2.27.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC PATCH 1/3] powerpc/pseries/vas: Modify reconfig open/close functions for migration
  2021-12-27 10:56 [RFC PATCH 0/3] powerpc/pseries/vas: VAS/NXGZIP support with LPM Haren Myneni
@ 2021-12-27 10:58 ` Haren Myneni
  2021-12-27 10:59 ` [RFC PATCH 2/3] powerpc/pseries/vas: Add VAS suspend/resume notifier Haren Myneni
  2021-12-27 11:00 ` [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR Haren Myneni
  2 siblings, 0 replies; 6+ messages in thread
From: Haren Myneni @ 2021-12-27 10:58 UTC (permalink / raw)
  To: mpe, linuxppc-dev, npiggin, nathanl


VAS is a hardware engine stays on the chip. So when the partition
migrates, all VAS windows on the source system have to be closed
and reopen them on the destination after migration.

This patch make changes to the current reconfig_open/close_windows
functions to support migration:
- Sets the window status to VAS_WIN_MIGRATE_CLOSE when closes and
  reopen windows with the same status during resume.
- Continue to close all windows even if deallocate HCALL failed
  (should not happen) since no way to stop migration with the
  current LPM implementation.

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
---
 arch/powerpc/include/asm/vas.h       |  2 +
 arch/powerpc/platforms/pseries/vas.c | 63 ++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h
index 72d1df038b4b..8b28cd7aaedc 100644
--- a/arch/powerpc/include/asm/vas.h
+++ b/arch/powerpc/include/asm/vas.h
@@ -41,6 +41,8 @@
 #define VAS_WIN_NO_CRED_CLOSE	0x4	/* Linux specific status when */
 					/* window is closed due to lost */
 					/* credit */
+#define VAS_WIN_MIGRATE_CLOSE	0x5	/* Linux status when window is */
+					/* closed due to migration */
 /*
  * Get/Set bit fields
  */
diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c
index 169f0cccb166..b9d1c0bac624 100644
--- a/arch/powerpc/platforms/pseries/vas.c
+++ b/arch/powerpc/platforms/pseries/vas.c
@@ -449,11 +449,12 @@ static int vas_deallocate_window(struct vas_window *vwin)
 	mutex_lock(&vas_pseries_mutex);
 	/*
 	 * VAS window is already closed in the hypervisor when
-	 * lost the credit. So just remove the entry from
-	 * the list, remove task references and free vas_window
+	 * lost the credit or with migration. So just remove the entry
+	 * from the list, remove task references and free vas_window
 	 * struct.
 	 */
-	if (win->vas_win.status != VAS_WIN_NO_CRED_CLOSE) {
+	if ((win->vas_win.status != VAS_WIN_NO_CRED_CLOSE) &&
+		(win->vas_win.status != VAS_WIN_MIGRATE_CLOSE)) {
 		rc = deallocate_free_window(win);
 		if (rc) {
 			mutex_unlock(&vas_pseries_mutex);
@@ -570,12 +571,14 @@ static int get_vas_capabilities(u8 feat, enum vas_cop_feat_type type,
  * by setting the remapping to new paste address if the window is
  * active.
  */
-static int reconfig_open_windows(struct vas_caps *vcaps, int creds)
+static int reconfig_open_windows(struct vas_caps *vcaps, int creds,
+				 bool migrate)
 {
 	long domain[PLPAR_HCALL9_BUFSIZE] = {VAS_DEFAULT_DOMAIN_ID};
 	struct vas_cop_feat_caps *caps = &vcaps->caps;
 	struct pseries_vas_window *win = NULL, *tmp;
 	int rc, mv_ents = 0;
+	int status;
 
 	/*
 	 * Nothing to do if there are no closed windows.
@@ -594,8 +597,10 @@ static int reconfig_open_windows(struct vas_caps *vcaps, int creds)
 	 * (dedicated). If 1 core is added, this LPAR can have 20 more
 	 * credits. It means the kernel can reopen 20 windows. So move
 	 * 20 entries in the VAS windows lost and reopen next 20 windows.
+	 * For partition migration, reopen all windows that are closed
+	 * during resume.
 	 */
-	if (vcaps->close_wins > creds)
+	if ((vcaps->close_wins > creds) && !migrate)
 		mv_ents = vcaps->close_wins - creds;
 
 	list_for_each_entry_safe(win, tmp, &vcaps->list, win_list) {
@@ -605,11 +610,20 @@ static int reconfig_open_windows(struct vas_caps *vcaps, int creds)
 		mv_ents--;
 	}
 
+	/*
+	 * Open windows if they are closed only with migration or
+	 * DLPAR (lost credit) before.
+	 */
+	if (migrate)
+		status = VAS_WIN_MIGRATE_CLOSE;
+	else
+		status = VAS_WIN_NO_CRED_CLOSE;
+
 	list_for_each_entry_safe_from(win, tmp, &vcaps->list, win_list) {
 		/*
 		 * Nothing to do on this window if it is active.
 		 */
-		if (win->vas_win.status != VAS_WIN_NO_CRED_CLOSE)
+		if (win->vas_win.status != status)
 			continue;
 
 		rc = allocate_setup_window(win, (u64 *)&domain[0],
@@ -652,17 +666,26 @@ static int reconfig_open_windows(struct vas_caps *vcaps, int creds)
  * the user space to fall back to SW compression and manage with the
  * existing windows.
  */
-static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds)
+static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds,
+									bool migrate)
 {
 	struct pseries_vas_window *win, *tmp;
 	struct vas_user_win_ref *task_ref;
 	struct vm_area_struct *vma;
-	int rc = 0;
+	int rc = 0, status;
+
+	if (migrate)
+		status = VAS_WIN_MIGRATE_CLOSE;
+	else
+		status = VAS_WIN_NO_CRED_CLOSE;
 
 	list_for_each_entry_safe(win, tmp, &vcap->list, win_list) {
 		/*
 		 * This window is already closed due to lost credit
 		 * before. Go for next window.
+		 * For migration, nothing to do since this window
+		 * closed for DLPAR and will be reopened even on
+		 * the destination system with other DLPAR operation.
 		 */
 		if (win->vas_win.status == VAS_WIN_NO_CRED_CLOSE)
 			continue;
@@ -674,7 +697,7 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds)
 		 * Number of available credits are reduced, So select
 		 * and close windows.
 		 */
-		win->vas_win.status = VAS_WIN_NO_CRED_CLOSE;
+		win->vas_win.status = status;
 
 		mmap_write_lock(task_ref->mm);
 		/*
@@ -697,12 +720,24 @@ static int reconfig_close_windows(struct vas_caps *vcap, int excess_creds)
 		 * later when the process issued with close(FD).
 		 */
 		rc = deallocate_free_window(win);
-		if (rc)
+		/*
+		 * This failure is from the hypervisor.
+		 * No way to stop migration for these failures.
+		 * So ignore error and continue closing other windows.
+		 */
+		if (rc && !migrate)
 			return rc;
 
 		vcap->close_wins++;
 
-		if (!--excess_creds)
+		/*
+		 * For migration, do not depend on lpar_creds in case if
+		 * mismatch with the hypervisor value (should not happen).
+		 * So close all active windows in the list and will be
+		 * reopened windows based on the new lpar_creds on the
+		 * destination system during resume.
+		 */
+		if (!migrate && !--excess_creds)
 			break;
 	}
 
@@ -757,7 +792,8 @@ int vas_reconfig_capabilties(u8 type)
 		 * target, reopen windows if they are closed due to
 		 * the previous DLPAR (core removal).
 		 */
-		rc = reconfig_open_windows(vcaps, new_creds - lpar_creds);
+		rc = reconfig_open_windows(vcaps, new_creds - lpar_creds,
+									false);
 	} else {
 		/*
 		 * # active windows is more than new LPAR available
@@ -765,7 +801,8 @@ int vas_reconfig_capabilties(u8 type)
 		 */
 		active_wins = vcaps->num_wins - vcaps->close_wins;
 		if (active_wins > new_creds)
-			rc = reconfig_close_windows(vcaps, active_wins - new_creds);
+			rc = reconfig_close_windows(vcaps, active_wins - new_creds,
+										false);
 	}
 
 out:
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 2/3] powerpc/pseries/vas: Add VAS suspend/resume notifier
  2021-12-27 10:56 [RFC PATCH 0/3] powerpc/pseries/vas: VAS/NXGZIP support with LPM Haren Myneni
  2021-12-27 10:58 ` [RFC PATCH 1/3] powerpc/pseries/vas: Modify reconfig open/close functions for migration Haren Myneni
@ 2021-12-27 10:59 ` Haren Myneni
  2021-12-27 11:00 ` [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR Haren Myneni
  2 siblings, 0 replies; 6+ messages in thread
From: Haren Myneni @ 2021-12-27 10:59 UTC (permalink / raw)
  To: mpe, linuxppc-dev, npiggin, nathanl


Since VAS windows belong to the VAS hardware resource, the
hypervisor expects the partition to close them on source partition
and reopen them after the partition migrated on the destination
machine.

This suspend/resume notifier invokes suspend operation before
and resume operation after migration. All active windows for
both default and QoS types will be closed during suspend and
reopen them during resume. During migration, the user space
should expect paste instruction failure if issues copy/paste
on these active windows.

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
---
 arch/powerpc/platforms/pseries/vas.c | 97 +++++++++++++++++++++++++++-
 1 file changed, 96 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c
index b9d1c0bac624..d2d7202a4f4e 100644
--- a/arch/powerpc/platforms/pseries/vas.c
+++ b/arch/powerpc/platforms/pseries/vas.c
@@ -16,6 +16,7 @@
 #include <asm/machdep.h>
 #include <asm/hvcall.h>
 #include <asm/plpar_wrappers.h>
+#include <asm/pseries-suspend.h>
 #include <asm/vas.h>
 #include "vas.h"
 
@@ -845,6 +846,98 @@ static struct notifier_block pseries_vas_nb = {
 	.notifier_call = pseries_vas_notifier,
 };
 
+/*
+ * For LPM, all windows have to be closed on the source partition
+ * before migration and reopen them on the destination partition
+ * after migration. So closing windows during suspend and
+ * reopen them during resume.
+ */
+static int vas_migrate_windows(bool suspend)
+{
+	struct hv_vas_cop_feat_caps *hv_caps;
+	struct vas_cop_feat_caps *caps;
+	int lpar_creds, new_creds = 0;
+	struct vas_caps *vcaps;
+	int i, rc = 0;
+
+	hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
+	if (!hv_caps)
+		return -ENOMEM;
+
+	mutex_lock(&vas_pseries_mutex);
+
+	for (i = 0; i < VAS_MAX_FEAT_TYPE; i++) {
+		vcaps = &vascaps[i];
+		caps = &vcaps->caps;
+		lpar_creds = atomic_read(&caps->target_creds);
+
+		rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, vcaps->feat,
+									(u64)virt_to_phys(hv_caps));
+		if (!rc) {
+			new_creds = be16_to_cpu(hv_caps->target_lpar_creds);
+			/*
+			 * Should not happen. But incase print messages, close all
+			 * windows in the list during suspend and reopen windows
+			 * based on new lpar_creds on the destination system.
+			 */
+			if (lpar_creds != new_creds) {
+				pr_err("%s: lpar creds: %d HV lpar creds: %d\n",
+						suspend ? "Suspend" : "Resume", lpar_creds,
+						new_creds);
+				pr_err("Used creds: %d, Active creds: %d\n",
+						atomic_read(&caps->used_creds),
+						vcaps->num_wins - vcaps->close_wins);
+			}
+		} else {
+			pr_err("%s: Get VAS capabilities failed with %d\n",
+					suspend ? "Suspend" : "Resume", rc);
+			/*
+			 * We can not stop migration with the current lpm
+			 * implementation. So continue closing all windows in the
+			 * list (during suspend) and return without opending windows
+			 * (during resume) if VAS capabilities HCALL failed.
+			 */
+			if (!suspend)
+				goto out;
+		}
+
+		if (suspend)
+			rc = reconfig_close_windows(vcaps, vcaps->num_wins, true);
+		else {
+			atomic_set(&caps->target_creds, new_creds);
+			rc = reconfig_open_windows(vcaps, new_creds, true);
+		}
+
+		/*
+		 * Ignore errors during suspend and return for resume.
+		 */
+		if (rc && !suspend)
+			goto out;
+	}
+
+out:
+	mutex_unlock(&vas_pseries_mutex);
+	kfree(hv_caps);
+	return rc;
+}
+
+static int vas_migration_handler(struct notifier_block *nb,
+								 unsigned long action, void *data)
+{
+	if (action == PSERIES_RESUMING)
+		return vas_migrate_windows(false);
+	else
+		return vas_migrate_windows(true);
+
+}
+
+static struct pseries_suspend_handler vas_suspend_handler = {
+	.notifier_block = {
+		.notifier_call = vas_migration_handler,
+	},
+};
+
+
 static int __init pseries_vas_init(void)
 {
 	struct hv_vas_cop_feat_caps *hv_cop_caps;
@@ -901,8 +994,10 @@ static int __init pseries_vas_init(void)
 	}
 
 	/* Processors can be added/removed only on LPAR */
-	if (copypaste_feat && firmware_has_feature(FW_FEATURE_LPAR))
+	if (copypaste_feat && firmware_has_feature(FW_FEATURE_LPAR)) {
 		of_reconfig_notifier_register(&pseries_vas_nb);
+		pseries_register_suspend_handler(&vas_suspend_handler);
+	}
 
 	pr_info("GZIP feature is available\n");
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR
  2021-12-27 10:56 [RFC PATCH 0/3] powerpc/pseries/vas: VAS/NXGZIP support with LPM Haren Myneni
  2021-12-27 10:58 ` [RFC PATCH 1/3] powerpc/pseries/vas: Modify reconfig open/close functions for migration Haren Myneni
  2021-12-27 10:59 ` [RFC PATCH 2/3] powerpc/pseries/vas: Add VAS suspend/resume notifier Haren Myneni
@ 2021-12-27 11:00 ` Haren Myneni
  2022-01-14 17:59   ` Nathan Lynch
  2 siblings, 1 reply; 6+ messages in thread
From: Haren Myneni @ 2021-12-27 11:00 UTC (permalink / raw)
  To: mpe, linuxppc-dev, npiggin, nathanl


Before migration starts, all secondary CPUs will be offline which
can invoke VAS DLPAR event. So disable VAS DLPAR event with
migration_in_progress flag during suspend and enable after resume
operations.

The current partition migration implementation does not freeze the
user space and the user space can continue open VAS windows. So
when migration_in_progress flag is enabled, VAS open window
API returns -EBUSY.

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
---
 arch/powerpc/platforms/pseries/vas.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c
index d2d7202a4f4e..1a10c1904aaa 100644
--- a/arch/powerpc/platforms/pseries/vas.c
+++ b/arch/powerpc/platforms/pseries/vas.c
@@ -30,6 +30,7 @@ static bool copypaste_feat;
 
 static struct vas_caps vascaps[VAS_MAX_FEAT_TYPE];
 static DEFINE_MUTEX(vas_pseries_mutex);
+static bool migration_in_progress;
 
 static long hcall_return_busy_check(long rc)
 {
@@ -349,8 +350,11 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
 	 * same fault IRQ is not freed by the OS before.
 	 */
 	mutex_lock(&vas_pseries_mutex);
-	rc = allocate_setup_window(txwin, (u64 *)&domain[0],
-				   cop_feat_caps->win_type);
+	if (migration_in_progress)
+		rc = -EBUSY;
+	else
+		rc = allocate_setup_window(txwin, (u64 *)&domain[0],
+					   cop_feat_caps->win_type);
 	mutex_unlock(&vas_pseries_mutex);
 	if (rc)
 		goto out;
@@ -771,6 +775,9 @@ int vas_reconfig_capabilties(u8 type)
 		return -ENOMEM;
 
 	mutex_lock(&vas_pseries_mutex);
+	if (migration_in_progress)
+		goto out;
+
 	rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, vcaps->feat,
 				      (u64)virt_to_phys(hv_caps));
 	if (rc)
@@ -866,6 +873,11 @@ static int vas_migrate_windows(bool suspend)
 
 	mutex_lock(&vas_pseries_mutex);
 
+	if (suspend)
+		migration_in_progress = true;
+	else
+		migration_in_progress = false;
+
 	for (i = 0; i < VAS_MAX_FEAT_TYPE; i++) {
 		vcaps = &vascaps[i];
 		caps = &vcaps->caps;
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR
  2021-12-27 11:00 ` [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR Haren Myneni
@ 2022-01-14 17:59   ` Nathan Lynch
  2022-01-18  9:28     ` Haren Myneni
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Lynch @ 2022-01-14 17:59 UTC (permalink / raw)
  To: Haren Myneni, mpe, linuxppc-dev, npiggin

Haren Myneni <haren@linux.ibm.com> writes:

> Before migration starts, all secondary CPUs will be offline which
> can invoke VAS DLPAR event.

I don't understand this statement, so I can't evaluate the patch. The
current LPM implementation does not offline any CPUs.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR
  2022-01-14 17:59   ` Nathan Lynch
@ 2022-01-18  9:28     ` Haren Myneni
  0 siblings, 0 replies; 6+ messages in thread
From: Haren Myneni @ 2022-01-18  9:28 UTC (permalink / raw)
  To: Nathan Lynch, mpe, linuxppc-dev, npiggin

On Fri, 2022-01-14 at 11:59 -0600, Nathan Lynch wrote:
> Haren Myneni <haren@linux.ibm.com> writes:
> 
> > Before migration starts, all secondary CPUs will be offline which
> > can invoke VAS DLPAR event.
> 
> I don't understand this statement, so I can't evaluate the patch. The
> current LPM implementation does not offline any CPUs.

Thanks for your comment. My mistake..

VAS notifier with of_reconfig_notifier_register() is called during
migration for other events. VAS notifier has a bug (
https://lists.ozlabs.org/pipermail/linuxppc-dev/2021-December/238333.html
) and will fix it:

if ((action == OF_RECONFIG_ATTACH_NODE) ||
        (action == OF_RECONFIG_DETACH_NODE))
        intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s",
&len);

As the current LPM notifier does not freeze the system, thought of
ignoring DLPAR CPU hotplug event with this migration_in_progress flag. 

I will fix this as well and repost DLPAR NXGZIP series. 

Thanks
Haren




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-18  9:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-27 10:56 [RFC PATCH 0/3] powerpc/pseries/vas: VAS/NXGZIP support with LPM Haren Myneni
2021-12-27 10:58 ` [RFC PATCH 1/3] powerpc/pseries/vas: Modify reconfig open/close functions for migration Haren Myneni
2021-12-27 10:59 ` [RFC PATCH 2/3] powerpc/pseries/vas: Add VAS suspend/resume notifier Haren Myneni
2021-12-27 11:00 ` [RFC PATCH 3/3] powerpc/pseries/vas: Use migration_in_progress to disable DLPAR Haren Myneni
2022-01-14 17:59   ` Nathan Lynch
2022-01-18  9:28     ` Haren Myneni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.