* [ndctl PATCH] ndctl/dimm: Flush invalidated labels after overwrite
@ 2022-04-28 23:54 Dan Williams
2022-05-02 14:48 ` Jeff Moyer
0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2022-04-28 23:54 UTC (permalink / raw)
To: vishal.l.verma; +Cc: Jeff Moyer, Dave Jiang, linux-cxl, nvdimm
Similar to "ndctl write-labels", after "ndctl sanitize-dimm --overwrite"
the kernel may contain a cached copy of the label area that has been
invalidated by the overwrite. Toggle the enabled state of the dimm-device
to trigger the kernel to release the cached copy.
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/all/165118817010.1772793.5101398830527716084.stgit@dwillia2-desk3.amr.corp.intel.com/
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
ndctl/dimm.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/ndctl/dimm.c b/ndctl/dimm.c
index d9718a33b22f..ac7c5270e971 100644
--- a/ndctl/dimm.c
+++ b/ndctl/dimm.c
@@ -354,6 +354,23 @@ static int rw_bin(FILE *f, struct ndctl_cmd *cmd, ssize_t size,
return 0;
}
+static int revalidate_labels(struct ndctl_dimm *dimm)
+{
+ int rc;
+
+ /*
+ * If the dimm is already disabled the kernel is not holding a cached
+ * copy of the label space.
+ */
+ if (!ndctl_dimm_is_enabled(dimm))
+ return 0;
+
+ rc = ndctl_dimm_disable(dimm);
+ if (rc)
+ return rc;
+ return ndctl_dimm_enable(dimm);
+}
+
static int action_write(struct ndctl_dimm *dimm, struct action_context *actx)
{
struct ndctl_cmd *cmd_read, *cmd_write;
@@ -377,18 +394,10 @@ static int action_write(struct ndctl_dimm *dimm, struct action_context *actx)
size = ndctl_cmd_cfg_read_get_size(cmd_read);
rc = rw_bin(actx->f_in, cmd_write, size, param.offset, WRITE);
-
- /*
- * If the dimm is already disabled the kernel is not holding a cached
- * copy of the label space.
- */
- if (!ndctl_dimm_is_enabled(dimm))
- goto out;
-
- rc = ndctl_dimm_disable(dimm);
if (rc)
goto out;
- rc = ndctl_dimm_enable(dimm);
+
+ rc = revalidate_labels(dimm);
out:
ndctl_cmd_unref(cmd_read);
@@ -1043,7 +1052,7 @@ static int action_security_freeze(struct ndctl_dimm *dimm,
static int action_sanitize_dimm(struct ndctl_dimm *dimm,
struct action_context *actx)
{
- int rc;
+ int rc = 0;
enum ndctl_key_type key_type;
if (ndctl_dimm_get_security(dimm) < 0) {
@@ -1085,9 +1094,10 @@ static int action_sanitize_dimm(struct ndctl_dimm *dimm,
rc = ndctl_dimm_overwrite_key(dimm);
if (rc < 0)
return rc;
+ rc = revalidate_labels(dimm);
}
- return 0;
+ return rc;
}
static int action_wait_overwrite(struct ndctl_dimm *dimm,
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [ndctl PATCH] ndctl/dimm: Flush invalidated labels after overwrite
2022-04-28 23:54 [ndctl PATCH] ndctl/dimm: Flush invalidated labels after overwrite Dan Williams
@ 2022-05-02 14:48 ` Jeff Moyer
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Moyer @ 2022-05-02 14:48 UTC (permalink / raw)
To: Dan Williams; +Cc: vishal.l.verma, Dave Jiang, linux-cxl, nvdimm
Dan Williams <dan.j.williams@intel.com> writes:
> Similar to "ndctl write-labels", after "ndctl sanitize-dimm --overwrite"
> the kernel may contain a cached copy of the label area that has been
> invalidated by the overwrite. Toggle the enabled state of the dimm-device
> to trigger the kernel to release the cached copy.
>
> Cc: Jeff Moyer <jmoyer@redhat.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Link: https://lore.kernel.org/all/165118817010.1772793.5101398830527716084.stgit@dwillia2-desk3.amr.corp.intel.com/
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> ndctl/dimm.c | 34 ++++++++++++++++++++++------------
> 1 file changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/ndctl/dimm.c b/ndctl/dimm.c
> index d9718a33b22f..ac7c5270e971 100644
> --- a/ndctl/dimm.c
> +++ b/ndctl/dimm.c
> @@ -354,6 +354,23 @@ static int rw_bin(FILE *f, struct ndctl_cmd *cmd, ssize_t size,
> return 0;
> }
>
> +static int revalidate_labels(struct ndctl_dimm *dimm)
> +{
> + int rc;
> +
> + /*
> + * If the dimm is already disabled the kernel is not holding a cached
> + * copy of the label space.
> + */
> + if (!ndctl_dimm_is_enabled(dimm))
> + return 0;
> +
> + rc = ndctl_dimm_disable(dimm);
> + if (rc)
> + return rc;
> + return ndctl_dimm_enable(dimm);
> +}
> +
> static int action_write(struct ndctl_dimm *dimm, struct action_context *actx)
> {
> struct ndctl_cmd *cmd_read, *cmd_write;
> @@ -377,18 +394,10 @@ static int action_write(struct ndctl_dimm *dimm, struct action_context *actx)
>
> size = ndctl_cmd_cfg_read_get_size(cmd_read);
> rc = rw_bin(actx->f_in, cmd_write, size, param.offset, WRITE);
> -
> - /*
> - * If the dimm is already disabled the kernel is not holding a cached
> - * copy of the label space.
> - */
> - if (!ndctl_dimm_is_enabled(dimm))
> - goto out;
> -
> - rc = ndctl_dimm_disable(dimm);
> if (rc)
> goto out;
> - rc = ndctl_dimm_enable(dimm);
> +
> + rc = revalidate_labels(dimm);
>
> out:
> ndctl_cmd_unref(cmd_read);
> @@ -1043,7 +1052,7 @@ static int action_security_freeze(struct ndctl_dimm *dimm,
> static int action_sanitize_dimm(struct ndctl_dimm *dimm,
> struct action_context *actx)
> {
> - int rc;
> + int rc = 0;
> enum ndctl_key_type key_type;
>
> if (ndctl_dimm_get_security(dimm) < 0) {
> @@ -1085,9 +1094,10 @@ static int action_sanitize_dimm(struct ndctl_dimm *dimm,
> rc = ndctl_dimm_overwrite_key(dimm);
> if (rc < 0)
> return rc;
> + rc = revalidate_labels(dimm);
> }
>
> - return 0;
> + return rc;
> }
>
> static int action_wait_overwrite(struct ndctl_dimm *dimm,
Acked-by: Jeff Moyer <jmoyer@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-02 14:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 23:54 [ndctl PATCH] ndctl/dimm: Flush invalidated labels after overwrite Dan Williams
2022-05-02 14:48 ` Jeff Moyer
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.