Skip to contentSkip to conversation

libnvdimm/region: Update nvdimm_has_flush() to handle ND_REGION_ASYNC

PATCH Superseded Vaibhav Jain 3 participants 4 messages Apr 2, 2021 – Apr 10, 2021 libnvdimm: non-volatile memory device

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnvdimm/region: Update nvdimm_has_flush() to handle ND_REGION_ASYNC

In case a platform doesn't provide explicit flush-hints but provides an explicit flush callback via ND_REGION_ASYNC region flag, then nvdimm_has_flush() still returns '0' indicating that writes do not require flushing. This happens on PPC64 with patch at [1] applied, where 'deep_flush' of a region was denied even though an explicit flush function was provided.

Fix this by adding a condition to nvdimm_has_flush() to test for the ND_REGION_ASYNC flag on the region and see if a 'region->flush' callback is assigned.

References:
[1] "powerpc/papr_scm: Implement support for H_SCM_FLUSH hcall"
https://lore.kernel.org/linux-nvdimm/161703936121.36.7260632399 582101498.stgit@e1fbed493c87

---
 drivers/nvdimm/region_devs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/nvdimm/region_devs.c +7 -2
index ef23119db574..e05cc9f8a9fd 100644
@@ -1239,6 +1239,11 @@ int nvdimm_has_flush(struct nd_region *nd_region)
 			|| !IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
 		return -ENXIO;
 
+	/* Test if an explicit flush function is defined */
+	if (test_bit(ND_REGION_ASYNC, &nd_region->flags) && nd_region->flush)
+		return 1;
+
+	/* Test if any flush hints for the region are available */
 	for (i = 0; i < nd_region->ndr_mappings; i++) {
 		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
 		struct nvdimm *nvdimm = nd_mapping->nvdimm;
@@ -1249,8 +1254,8 @@ int nvdimm_has_flush(struct nd_region *nd_region)
 	}
 
 	/*
-	 * The platform defines dimm devices without hints, assume
-	 * platform persistence mechanism like ADR
+	 * The platform defines dimm devices without hints nor explicit flush,
+	 * assume platform persistence mechanism like ADR
 	 */
 	return 0;
 }
Signature · 4 lines
2.30.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw
Quoted 11 lines · Vaibhav Jain

In case a platform doesn't provide explicit flush-hints but provides an explicit flush callback via ND_REGION_ASYNC region flag, then nvdimm_has_flush() still returns '0' indicating that writes do not require flushing. This happens on PPC64 with patch at [1] applied, where 'deep_flush' of a region was denied even though an explicit flush function was provided.

Fix this by adding a condition to nvdimm_has_flush() to test for the ND_REGION_ASYNC flag on the region and see if a 'region->flush' callback is assigned.

May be this should have

Fixes c5d4355d10d4 ("libnvdimm: nd_region flush callback support")

Without this we will mark the pmem disk not having FUA support?

Quoted 43 lines

References:
[1] "powerpc/papr_scm: Implement support for H_SCM_FLUSH hcall"
https://lore.kernel.org/linux-nvdimm/161703936121.36.7260632399 582101498.stgit@e1fbed493c87

---
 drivers/nvdimm/region_devs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/nvdimm/region_devs.c +5 -0
index ef23119db574..e05cc9f8a9fd 100644
@@ -1239,6 +1239,11 @@ int nvdimm_has_flush(struct nd_region *nd_region)
 			|| !IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
 		return -ENXIO;
 
+	/* Test if an explicit flush function is defined */
+	if (test_bit(ND_REGION_ASYNC, &nd_region->flags) && nd_region->flush)
+		return 1;
 
+
+	/* Test if any flush hints for the region are available */
 	for (i = 0; i < nd_region->ndr_mappings; i++) {
 		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
drivers/nvdimm/region_devs.c +2 -2
 		struct nvdimm *nvdimm = nd_mapping->nvdimm;
@@ -1249,8 +1254,8 @@ int nvdimm_has_flush(struct nd_region *nd_region)
 	}
 
 	/*
-	 * The platform defines dimm devices without hints, assume
-	 * platform persistence mechanism like ADR
+	 * The platform defines dimm devices without hints nor explicit flush,
+	 * assume platform persistence mechanism like ADR
 	 */
 	return 0;
 }
Signature · 4 lines
2.30.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#2 lore raw
Quoted 10 lines · Aneesh Kumar K.V
Quoted 7 lines · Vaibhav Jain

In case a platform doesn't provide explicit flush-hints but provides an explicit flush callback via ND_REGION_ASYNC region flag, then nvdimm_has_flush() still returns '0' indicating that writes do not require flushing. This happens on PPC64 with patch at [1] applied, where 'deep_flush' of a region was denied even though an explicit flush function was provided.

Quoted 7 lines
Quoted 4 lines

Fix this by adding a condition to nvdimm_has_flush() to test for the ND_REGION_ASYNC flag on the region and see if a 'region->flush' callback is assigned.

May be this should have

Fixes c5d4355d10d4 ("libnvdimm: nd_region flush callback support")

Yes, thanks for that.

Quoted 2 lines

Without this we will mark the pmem disk not having FUA support?

Yes.

Quoted 32 lines
Quoted 32 lines

References:
[1] "powerpc/papr_scm: Implement support for H_SCM_FLUSH hcall"
https://lore.kernel.org/linux-nvdimm/161703936121.36.7260632399 582101498.stgit@e1fbed493c87

---
 drivers/nvdimm/region_devs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/nvdimm/region_devs.c +5 -0
index ef23119db574..e05cc9f8a9fd 100644
@@ -1239,6 +1239,11 @@ int nvdimm_has_flush(struct nd_region *nd_region)
                      || !IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
              return -ENXIO;
 
+     /* Test if an explicit flush function is defined */
+     if (test_bit(ND_REGION_ASYNC, &nd_region->flags) && nd_region->flush)
+             return 1;
 
+
+     /* Test if any flush hints for the region are available */
      for (i = 0; i < nd_region->ndr_mappings; i++) {
              struct nd_mapping *nd_mapping = &nd_region->mapping[i];
              struct nvdimm *nvdimm = nd_mapping->nvdimm;
drivers/nvdimm/region_devs.c +0 -0
@@ -1249,8 +1254,8 @@ int nvdimm_has_flush(struct nd_region *nd_region)
      }
 
Quoted 13 lines
Quoted 9 lines
drivers/nvdimm/region_devs.c +2 -3
      /*
-      * The platform defines dimm devices without hints, assume
-      * platform persistence mechanism like ADR
+      * The platform defines dimm devices without hints nor explicit flush,
+      * assume platform persistence mechanism like ADR
       */
      return 0;
 }
--
Quoted 4 lines

2.30.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#3 lore raw
In reply to Vaibhav Jain
Quoted 11 lines · Vaibhav Jain

In case a platform doesn't provide explicit flush-hints but provides an explicit flush callback via ND_REGION_ASYNC region flag, then nvdimm_has_flush() still returns '0' indicating that writes do not require flushing. This happens on PPC64 with patch at [1] applied, where 'deep_flush' of a region was denied even though an explicit flush function was provided.

Fix this by adding a condition to nvdimm_has_flush() to test for the ND_REGION_ASYNC flag on the region and see if a 'region->flush' callback is assigned.

Looks good.

Quoted 4 lines

References:
[1] "powerpc/papr_scm: Implement support for H_SCM_FLUSH hcall"
https://lore.kernel.org/linux-nvdimm/161703936121.36.7260632399 582101498.stgit@e1fbed493c87

Looks like a typo happened in that link, I can fix that up. I'll also change this to the canonical "Link:" tag for references.

Quoted 35 lines
---
 drivers/nvdimm/region_devs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/nvdimm/region_devs.c +7 -3
index ef23119db574..e05cc9f8a9fd 100644
@@ -1239,6 +1239,11 @@ int nvdimm_has_flush(struct nd_region *nd_region)
                        || !IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
                return -ENXIO;
 
+       /* Test if an explicit flush function is defined */
+       if (test_bit(ND_REGION_ASYNC, &nd_region->flags) && nd_region->flush)
+               return 1;
+
+       /* Test if any flush hints for the region are available */
        for (i = 0; i < nd_region->ndr_mappings; i++) {
                struct nd_mapping *nd_mapping = &nd_region->mapping[i];
                struct nvdimm *nvdimm = nd_mapping->nvdimm;
@@ -1249,8 +1254,8 @@ int nvdimm_has_flush(struct nd_region *nd_region)
        }
 
        /*
-        * The platform defines dimm devices without hints, assume
-        * platform persistence mechanism like ADR
+        * The platform defines dimm devices without hints nor explicit flush,
+        * assume platform persistence mechanism like ADR
         */
        return 0;
 }
--
Quoted 2 lines

2.30.2

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]