From: Dan Williams <dan.j.williams@intel.com>
Date: Wed, 13 Feb 2019 09:28:40 -0800
Subject: [PATCH] nfit/ars: Avoid stale ARS results
Patch-mainline: v5.1-rc1
Git-commit: 78153dd45e7e0596ba32b15d02bda08e1513111e
References: jsc#SLE-5433
Gate ARS result consumption on whether the OS issued start-ARS since the
previous consumption. The BIOS may only clear its result buffers after a
successful start-ARS.
Fixes: 0caeef63e6d2 ("libnvdimm: Add a poison list and export badblocks")
Cc: <stable@vger.kernel.org>
Reported-by: Krzysztof Rusocki <krzysztof.rusocki@intel.com>
Reported-by: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: Toshi Kani <toshi.kani@hpe.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/acpi/nfit/core.c | 17 ++++++++++++++++-
drivers/acpi/nfit/nfit.h | 1 +
2 files changed, 17 insertions(+), 1 deletion(-)
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -2529,7 +2529,10 @@ static int ars_start(struct acpi_nfit_de
if (rc < 0)
return rc;
- return cmd_rc;
+ if (cmd_rc < 0)
+ return cmd_rc;
+ set_bit(ARS_VALID, &acpi_desc->scrub_flags);
+ return 0;
}
static int ars_continue(struct acpi_nfit_desc *acpi_desc)
@@ -2623,6 +2626,17 @@ static int ars_status_process_records(st
*/
if (ars_status->out_length < 44)
return 0;
+
+ /*
+ * Ignore potentially stale results that are only refreshed
+ * after a start-ARS event.
+ */
+ if (!test_and_clear_bit(ARS_VALID, &acpi_desc->scrub_flags)) {
+ dev_dbg(acpi_desc->dev, "skip %d stale records\n",
+ ars_status->num_records);
+ return 0;
+ }
+
for (i = 0; i < ars_status->num_records; i++) {
/* only process full records */
if (ars_status->out_length
@@ -3108,6 +3122,7 @@ static int acpi_nfit_register_regions(st
struct nfit_spa *nfit_spa;
int rc;
+ set_bit(ARS_VALID, &acpi_desc->scrub_flags);
list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
switch (nfit_spa_type(nfit_spa->spa)) {
case NFIT_SPA_VOLATILE:
--- a/drivers/acpi/nfit/nfit.h
+++ b/drivers/acpi/nfit/nfit.h
@@ -185,6 +185,7 @@ enum scrub_flags {
ARS_BUSY,
ARS_CANCEL,
ARS_POLL,
+ ARS_VALID,
};
struct acpi_nfit_desc {