1 From 9281279f81f6ab6cc0486ac7b874c01e562772ba Mon Sep 17 00:00:00 2001
2 From: Dan Williams <dan.j.williams@intel.com>
3 Date: Mon, 22 Apr 2019 16:08:26 -0700
4 Subject: nfit/ars: Avoid stale ARS results
6 commit 78153dd45e7e0596ba32b15d02bda08e1513111e upstream.
8 Gate ARS result consumption on whether the OS issued start-ARS since the
9 previous consumption. The BIOS may only clear its result buffers after a
12 Fixes: 0caeef63e6d2 ("libnvdimm: Add a poison list and export badblocks")
13 Cc: <stable@vger.kernel.org>
14 Reported-by: Krzysztof Rusocki <krzysztof.rusocki@intel.com>
15 Reported-by: Vishal Verma <vishal.l.verma@intel.com>
16 Reviewed-by: Toshi Kani <toshi.kani@hpe.com>
17 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
18 Signed-off-by: Sasha Levin <sashal@kernel.org>
20 drivers/acpi/nfit/core.c | 17 ++++++++++++++++-
21 drivers/acpi/nfit/nfit.h | 1 +
22 2 files changed, 17 insertions(+), 1 deletion(-)
24 diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
25 index 4b489d14a680..925dbc751322 100644
26 --- a/drivers/acpi/nfit/core.c
27 +++ b/drivers/acpi/nfit/core.c
28 @@ -2540,7 +2540,10 @@ static int ars_start(struct acpi_nfit_desc *acpi_desc,
35 + set_bit(ARS_VALID, &acpi_desc->scrub_flags);
39 static int ars_continue(struct acpi_nfit_desc *acpi_desc)
40 @@ -2633,6 +2636,17 @@ static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc)
42 if (ars_status->out_length < 44)
46 + * Ignore potentially stale results that are only refreshed
47 + * after a start-ARS event.
49 + if (!test_and_clear_bit(ARS_VALID, &acpi_desc->scrub_flags)) {
50 + dev_dbg(acpi_desc->dev, "skip %d stale records\n",
51 + ars_status->num_records);
55 for (i = 0; i < ars_status->num_records; i++) {
56 /* only process full records */
57 if (ars_status->out_length
58 @@ -3117,6 +3131,7 @@ static int acpi_nfit_register_regions(struct acpi_nfit_desc *acpi_desc)
59 struct nfit_spa *nfit_spa;
62 + set_bit(ARS_VALID, &acpi_desc->scrub_flags);
63 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
64 switch (nfit_spa_type(nfit_spa->spa)) {
65 case NFIT_SPA_VOLATILE:
66 diff --git a/drivers/acpi/nfit/nfit.h b/drivers/acpi/nfit/nfit.h
67 index b5fd3522abc7..68848fc4b7c9 100644
68 --- a/drivers/acpi/nfit/nfit.h
69 +++ b/drivers/acpi/nfit/nfit.h
70 @@ -184,6 +184,7 @@ struct nfit_mem {