nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] acpi, nfit: Further restrict userspace ARS start requests
@ 2018-10-15 21:00 Dan Williams
  2018-10-15 21:24 ` Dave Jiang
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2018-10-15 21:00 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: linux-acpi

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.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Changes in v2:
* Require acpi_desc->scrub_spa to be NULL to prevent requests being sent
  while a scrub is active, or whose results are waiting to be reaped.

 drivers/acpi/nfit/core.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index f7efcd9843e0..253c0e85554d 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -3364,6 +3364,8 @@ static int __acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
 		struct nvdimm *nvdimm, unsigned int cmd)
 {
 	struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
+	struct nfit_spa *nfit_spa;
+	int rc = 0;
 
 	if (nvdimm)
 		return 0;
@@ -3373,13 +3375,20 @@ static int __acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
 	/*
 	 * The kernel and userspace may race to initiate a scrub, but
 	 * the scrub thread is prepared to lose that initial race.  It
-	 * just needs guarantees that any ars it initiates are not
-	 * interrupted by any intervening start reqeusts from userspace.
+	 * just needs guarantees that any ARS it initiates are not
+	 * interrupted by any intervening start requests from userspace.
 	 */
-	if (work_busy(&acpi_desc->dwork.work))
-		return -EBUSY;
+	mutex_lock(&acpi_desc->init_mutex);
+	list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
+		if (acpi_desc->scrub_spa
+				|| test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state)
+				|| test_bit(ARS_REQ_LONG, &nfit_spa->ars_state)) {
+			rc = -EBUSY;
+			break;
+		}
+	mutex_unlock(&acpi_desc->init_mutex);
 
-	return 0;
+	return rc;
 }
 
 /* prevent security commands from being issued via ioctl */

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] acpi, nfit: Further restrict userspace ARS start requests
  2018-10-15 21:00 [PATCH v2] acpi, nfit: Further restrict userspace ARS start requests Dan Williams
@ 2018-10-15 21:24 ` Dave Jiang
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Jiang @ 2018-10-15 21:24 UTC (permalink / raw)
  To: Dan Williams, linux-nvdimm; +Cc: linux-acpi



On 10/15/2018 02:00 PM, Dan Williams wrote:
> 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.
> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
> Changes in v2:
> * Require acpi_desc->scrub_spa to be NULL to prevent requests being sent
>   while a scrub is active, or whose results are waiting to be reaped.
> 
>  drivers/acpi/nfit/core.c |   19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index f7efcd9843e0..253c0e85554d 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -3364,6 +3364,8 @@ static int __acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
>  		struct nvdimm *nvdimm, unsigned int cmd)
>  {
>  	struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
> +	struct nfit_spa *nfit_spa;
> +	int rc = 0;
>  
>  	if (nvdimm)
>  		return 0;
> @@ -3373,13 +3375,20 @@ static int __acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
>  	/*
>  	 * The kernel and userspace may race to initiate a scrub, but
>  	 * the scrub thread is prepared to lose that initial race.  It
> -	 * just needs guarantees that any ars it initiates are not
> -	 * interrupted by any intervening start reqeusts from userspace.
> +	 * just needs guarantees that any ARS it initiates are not
> +	 * interrupted by any intervening start requests from userspace.
>  	 */
> -	if (work_busy(&acpi_desc->dwork.work))
> -		return -EBUSY;
> +	mutex_lock(&acpi_desc->init_mutex);
> +	list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
> +		if (acpi_desc->scrub_spa
> +				|| test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state)
> +				|| test_bit(ARS_REQ_LONG, &nfit_spa->ars_state)) {
> +			rc = -EBUSY;
> +			break;
> +		}
> +	mutex_unlock(&acpi_desc->init_mutex);
>  
> -	return 0;
> +	return rc;
>  }
>  
>  /* prevent security commands from being issued via ioctl */
> 
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-15 21:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15 21:00 [PATCH v2] acpi, nfit: Further restrict userspace ARS start requests Dan Williams
2018-10-15 21:24 ` Dave Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).