Blame SOURCES/0170-ndctl-dimm-Flush-invalidated-labels-after-overwrite.patch

26ccd9
From 8186ec87dcd1b347ab0ee27ec5e87bda8c9a67e2 Mon Sep 17 00:00:00 2001
26ccd9
From: Dan Williams <dan.j.williams@intel.com>
26ccd9
Date: Thu, 28 Apr 2022 16:54:48 -0700
26ccd9
Subject: [PATCH 170/217] ndctl/dimm: Flush invalidated labels after overwrite
26ccd9
26ccd9
Similar to "ndctl write-labels", after "ndctl sanitize-dimm --overwrite"
26ccd9
the kernel may contain a cached copy of the label area that has been
26ccd9
invalidated by the overwrite. Toggle the enabled state of the dimm-device
26ccd9
to trigger the kernel to release the cached copy.
26ccd9
26ccd9
Link: https://lore.kernel.org/all/165118817010.1772793.5101398830527716084.stgit@dwillia2-desk3.amr.corp.intel.com/
26ccd9
Link: https://lore.kernel.org/r/165119008839.1783158.3766085644383173318.stgit@dwillia2-desk3.amr.corp.intel.com
26ccd9
Cc: Jeff Moyer <jmoyer@redhat.com>
26ccd9
Cc: Dave Jiang <dave.jiang@intel.com>
26ccd9
Acked-by: Jeff Moyer <jmoyer@redhat.com>
26ccd9
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 ndctl/dimm.c | 34 ++++++++++++++++++++++------------
26ccd9
 1 file changed, 22 insertions(+), 12 deletions(-)
26ccd9
26ccd9
diff --git a/ndctl/dimm.c b/ndctl/dimm.c
26ccd9
index d9718a3..ac7c527 100644
26ccd9
--- a/ndctl/dimm.c
26ccd9
+++ b/ndctl/dimm.c
26ccd9
@@ -354,6 +354,23 @@ static int rw_bin(FILE *f, struct ndctl_cmd *cmd, ssize_t size,
26ccd9
 	return 0;
26ccd9
 }
26ccd9
 
26ccd9
+static int revalidate_labels(struct ndctl_dimm *dimm)
26ccd9
+{
26ccd9
+	int rc;
26ccd9
+
26ccd9
+	/*
26ccd9
+	 * If the dimm is already disabled the kernel is not holding a cached
26ccd9
+	 * copy of the label space.
26ccd9
+	 */
26ccd9
+	if (!ndctl_dimm_is_enabled(dimm))
26ccd9
+		return 0;
26ccd9
+
26ccd9
+	rc = ndctl_dimm_disable(dimm);
26ccd9
+	if (rc)
26ccd9
+		return rc;
26ccd9
+	return ndctl_dimm_enable(dimm);
26ccd9
+}
26ccd9
+
26ccd9
 static int action_write(struct ndctl_dimm *dimm, struct action_context *actx)
26ccd9
 {
26ccd9
 	struct ndctl_cmd *cmd_read, *cmd_write;
26ccd9
@@ -377,18 +394,10 @@ static int action_write(struct ndctl_dimm *dimm, struct action_context *actx)
26ccd9
 
26ccd9
 	size = ndctl_cmd_cfg_read_get_size(cmd_read);
26ccd9
 	rc = rw_bin(actx->f_in, cmd_write, size, param.offset, WRITE);
26ccd9
-
26ccd9
-	/*
26ccd9
-	 * If the dimm is already disabled the kernel is not holding a cached
26ccd9
-	 * copy of the label space.
26ccd9
-	 */
26ccd9
-	if (!ndctl_dimm_is_enabled(dimm))
26ccd9
-		goto out;
26ccd9
-
26ccd9
-	rc = ndctl_dimm_disable(dimm);
26ccd9
 	if (rc)
26ccd9
 		goto out;
26ccd9
-	rc = ndctl_dimm_enable(dimm);
26ccd9
+
26ccd9
+	rc = revalidate_labels(dimm);
26ccd9
 
26ccd9
  out:
26ccd9
 	ndctl_cmd_unref(cmd_read);
26ccd9
@@ -1043,7 +1052,7 @@ static int action_security_freeze(struct ndctl_dimm *dimm,
26ccd9
 static int action_sanitize_dimm(struct ndctl_dimm *dimm,
26ccd9
 		struct action_context *actx)
26ccd9
 {
26ccd9
-	int rc;
26ccd9
+	int rc = 0;
26ccd9
 	enum ndctl_key_type key_type;
26ccd9
 
26ccd9
 	if (ndctl_dimm_get_security(dimm) < 0) {
26ccd9
@@ -1085,9 +1094,10 @@ static int action_sanitize_dimm(struct ndctl_dimm *dimm,
26ccd9
 		rc = ndctl_dimm_overwrite_key(dimm);
26ccd9
 		if (rc < 0)
26ccd9
 			return rc;
26ccd9
+		rc = revalidate_labels(dimm);
26ccd9
 	}
26ccd9
 
26ccd9
-	return 0;
26ccd9
+	return rc;
26ccd9
 }
26ccd9
 
26ccd9
 static int action_wait_overwrite(struct ndctl_dimm *dimm,
26ccd9
-- 
26ccd9
2.27.0
26ccd9