Skip to content

Commit 5948612

Browse files
committed
acpi, nfit: Further restrict userspace ARS start requests
In addition to not allowing ARS start while the background thread is actively running, prevent ARS start while any scrub request is pending. This aligns the window for ARS start submission with the status of ARS reported via sysfs. Previously userspace could sneak its own ARS start requests in while sysfs reported -EBUSY. Reviewed-by: Dave Jiang <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent d3abaf4 commit 5948612

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/acpi/nfit/core.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,8 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
33413341
struct nvdimm *nvdimm, unsigned int cmd)
33423342
{
33433343
struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
3344+
struct nfit_spa *nfit_spa;
3345+
int rc = 0;
33443346

33453347
if (nvdimm)
33463348
return 0;
@@ -3350,13 +3352,20 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
33503352
/*
33513353
* The kernel and userspace may race to initiate a scrub, but
33523354
* the scrub thread is prepared to lose that initial race. It
3353-
* just needs guarantees that any ars it initiates are not
3354-
* interrupted by any intervening start reqeusts from userspace.
3355+
* just needs guarantees that any ARS it initiates are not
3356+
* interrupted by any intervening start requests from userspace.
33553357
*/
3356-
if (work_busy(&acpi_desc->dwork.work))
3357-
return -EBUSY;
3358+
mutex_lock(&acpi_desc->init_mutex);
3359+
list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
3360+
if (acpi_desc->scrub_spa
3361+
|| test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state)
3362+
|| test_bit(ARS_REQ_LONG, &nfit_spa->ars_state)) {
3363+
rc = -EBUSY;
3364+
break;
3365+
}
3366+
mutex_unlock(&acpi_desc->init_mutex);
33583367

3359-
return 0;
3368+
return rc;
33603369
}
33613370

33623371
int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc,

0 commit comments

Comments
 (0)