nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] libnvdimm, nfit: fix persistence domain reporting
@ 2018-03-21 22:39 Dan Williams
  2018-03-21 22:50 ` Jiang, Dave
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2018-03-21 22:39 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Rafael J. Wysocki, linux-kernel, linux-acpi

The persistence domain is a point in the platform where once writes
reach that destination the platform claims it will make them persistent
relative to power loss. In the ACPI NFIT this is currently communicated
as 2 bits in the "NFIT - Platform Capabilities Structure". The bits
comprise a hierarchy, i.e. bit0 "CPU Cache Flush to NVDIMM Durability on
Power Loss Capable" implies bit1 "Memory Controller Flush to NVDIMM
Durability on Power Loss Capable".

Commit 96c3a239054a "libnvdimm: expose platform persistence attr..."
shows the persistence domain as flags, but it's really an enumerated
hierarchy.

Fix this newly introduced user ABI to show the closest available
persistence domain before userspace develops dependencies on seeing, or
needing to develop code to tolerate, the raw NFIT flags communicated
through the libnvdimm-generic region attribute.

Fixes: 96c3a239054a ("libnvdimm: expose platform persistence attr...")
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/acpi/nfit/core.c     |   10 +++++++---
 drivers/nvdimm/region_devs.c |   10 ++++++----
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index bbe48ad20886..eb09ef55c38a 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -2675,10 +2675,14 @@ static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
 	else
 		ndr_desc->numa_node = NUMA_NO_NODE;
 
-	if(acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
+	/*
+	 * Persistence domain bits are hierarchical, if
+	 * ACPI_NFIT_CAPABILITY_CACHE_FLUSH is set then
+	 * ACPI_NFIT_CAPABILITY_MEM_FLUSH is implied.
+	 */
+	if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
 		set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags);
-
-	if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
+	else if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
 		set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags);
 
 	list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index a8e9d428c0a5..1593e1806b16 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -532,11 +532,13 @@ static ssize_t persistence_domain_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct nd_region *nd_region = to_nd_region(dev);
-	unsigned long flags = nd_region->flags;
 
-	return sprintf(buf, "%s%s\n",
-			flags & BIT(ND_REGION_PERSIST_CACHE) ? "cpu_cache " : "",
-			flags & BIT(ND_REGION_PERSIST_MEMCTRL) ? "memory_controller " : "");
+	if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags))
+		return sprintf(buf, "cpu_cache\n");
+	else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags))
+		return sprintf(buf, "memory_controller\n");
+	else
+		return sprintf(buf, "\n");
 }
 static DEVICE_ATTR_RO(persistence_domain);
 

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

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

* RE: [PATCH] libnvdimm, nfit: fix persistence domain reporting
  2018-03-21 22:39 [PATCH] libnvdimm, nfit: fix persistence domain reporting Dan Williams
@ 2018-03-21 22:50 ` Jiang, Dave
  0 siblings, 0 replies; 2+ messages in thread
From: Jiang, Dave @ 2018-03-21 22:50 UTC (permalink / raw)
  To: Williams, Dan J, linux-nvdimm; +Cc: linux-acpi, Rafael J. Wysocki, linux-kernel



> -----Original Message-----
> From: Williams, Dan J
> Sent: Wednesday, March 21, 2018 3:39 PM
> To: linux-nvdimm@lists.01.org
> Cc: Jiang, Dave <dave.jiang@intel.com>; Rafael J. Wysocki <rjw@rjwysocki.net>; Ross Zwisler <ross.zwisler@linux.intel.com>; linux-
> acpi@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [PATCH] libnvdimm, nfit: fix persistence domain reporting
> 
> The persistence domain is a point in the platform where once writes
> reach that destination the platform claims it will make them persistent
> relative to power loss. In the ACPI NFIT this is currently communicated
> as 2 bits in the "NFIT - Platform Capabilities Structure". The bits
> comprise a hierarchy, i.e. bit0 "CPU Cache Flush to NVDIMM Durability on
> Power Loss Capable" implies bit1 "Memory Controller Flush to NVDIMM
> Durability on Power Loss Capable".
> 
> Commit 96c3a239054a "libnvdimm: expose platform persistence attr..."
> shows the persistence domain as flags, but it's really an enumerated
> hierarchy.
> 
> Fix this newly introduced user ABI to show the closest available
> persistence domain before userspace develops dependencies on seeing, or
> needing to develop code to tolerate, the raw NFIT flags communicated
> through the libnvdimm-generic region attribute.
> 
> Fixes: 96c3a239054a ("libnvdimm: expose platform persistence attr...")
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>


Thanks for the fix!

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

> ---
>  drivers/acpi/nfit/core.c     |   10 +++++++---
>  drivers/nvdimm/region_devs.c |   10 ++++++----
>  2 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index bbe48ad20886..eb09ef55c38a 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -2675,10 +2675,14 @@ static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
>  	else
>  		ndr_desc->numa_node = NUMA_NO_NODE;
> 
> -	if(acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
> +	/*
> +	 * Persistence domain bits are hierarchical, if
> +	 * ACPI_NFIT_CAPABILITY_CACHE_FLUSH is set then
> +	 * ACPI_NFIT_CAPABILITY_MEM_FLUSH is implied.
> +	 */
> +	if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
>  		set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags);
> -
> -	if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
> +	else if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
>  		set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags);
> 
>  	list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
> diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
> index a8e9d428c0a5..1593e1806b16 100644
> --- a/drivers/nvdimm/region_devs.c
> +++ b/drivers/nvdimm/region_devs.c
> @@ -532,11 +532,13 @@ static ssize_t persistence_domain_show(struct device *dev,
>  		struct device_attribute *attr, char *buf)
>  {
>  	struct nd_region *nd_region = to_nd_region(dev);
> -	unsigned long flags = nd_region->flags;
> 
> -	return sprintf(buf, "%s%s\n",
> -			flags & BIT(ND_REGION_PERSIST_CACHE) ? "cpu_cache " : "",
> -			flags & BIT(ND_REGION_PERSIST_MEMCTRL) ? "memory_controller " : "");
> +	if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags))
> +		return sprintf(buf, "cpu_cache\n");
> +	else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags))
> +		return sprintf(buf, "memory_controller\n");
> +	else
> +		return sprintf(buf, "\n");
>  }
>  static DEVICE_ATTR_RO(persistence_domain);
> 

_______________________________________________
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-03-21 22:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-21 22:39 [PATCH] libnvdimm, nfit: fix persistence domain reporting Dan Williams
2018-03-21 22:50 ` Jiang, Dave

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).