This patch series enables the usage os new pmem flush and sync instructions on POWER
architecture. POWER10 introduces two new variants of dcbf instructions (dcbstps and dcbfps)
that can be used to write modified locations back to persistent storage. Additionally,
POWER10 also introduce phwsync and plwsync which can be used to establish order of these
writes to persistent storage.
This series exposes these instructions to the rest of the kernel. The existing
dcbf and hwsync instructions in P8 and P9 are adequate to enable appropriate
synchronization with OpenCAPI-hosted persistent storage. Hence the new instructions
are added as a variant of the old ones that old hardware won't differentiate.
On POWER10, pmem devices will be represented by a different device tree compat
strings. This ensures that older kernels won't initialize pmem devices on POWER10.
With this:
1) vPMEM continues to work since it is a volatile region. That
doesn't need any flush instructions.
2) pmdk and other user applications get updated to use new instructions
and updated packages are made available to all distributions
3) On newer hardware, the device will appear with a new compat string.
Hence older distributions won't initialize pmem on newer hardware.
Changes from v5:
* Drop CONFIG_ARCH_MAP_SYNC_DISABLE and related changes
Changes from V4:
* Add namespace specific sychronous fault control.
Changes from V3:
* Add new compat string to be used for the device.
* Use arch_pmem_flush_barrier() in dm-writecache.
Aneesh Kumar K.V (8):
powerpc/pmem: Restrict papr_scm to P8 and above.
powerpc/pmem: Add new instructions for persistent storage and sync
powerpc/pmem: Add flush routines using new pmem store and sync
instruction
libnvdimm/nvdimm/flush: Allow architecture to override the flush
barrier
powerpc/pmem/of_pmem: Update of_pmem to use the new barrier
instruction.
powerpc/pmem: Avoid the barrier in flush routines
powerpc/pmem: Add WARN_ONCE to catch the wrong usage of pmem flush
functions.
powerpc/pmem: Initialize pmem device on newer hardware
arch/powerpc/include/asm/cacheflush.h | 10 +++++
arch/powerpc/include/asm/ppc-opcode.h | 12 ++++++
arch/powerpc/lib/pmem.c | 46 +++++++++++++++++++++--
arch/powerpc/platforms/pseries/papr_scm.c | 14 +++++++
arch/powerpc/platforms/pseries/pmem.c | 6 +++
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/of_pmem.c | 1 +
drivers/nvdimm/region_devs.c | 8 ++--
include/asm-generic/cacheflush.h | 4 ++
9 files changed, 94 insertions(+), 9 deletions(-)
--
2.26.2
The PAPR based virtualized persistent memory devices are only supported on
POWER9 and above. In the followup patch, the kernel will switch the persistent
memory cache flush functions to use a new `dcbf` variant instruction. The new
instructions even though added in ISA 3.1 works even on P8 and P9 because these
are implemented as a variant of existing `dcbf` and `hwsync` and on P8 and
P9 behaves as such.
Considering these devices are only supported on P8 and above, update the driver
to prevent a P7-compat guest from using persistent memory devices.
We don't update of_pmem driver with the same condition, because, on bare-metal,
the firmware enables pmem support only on P9 and above. There the kernel depends
on OPAL firmware to restrict exposing persistent memory related device tree
entries on older hardware. of_pmem.ko is written without any arch dependency and
we don't want to add ppc64 specific cpu feature check in of_pmem driver.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/platforms/pseries/pmem.c | 6 ++++++
1 file changed, 6 insertions(+)
POWER10 introduces two new variants of dcbf instructions (dcbstps and dcbfps)
that can be used to write modified locations back to persistent storage.
Additionally, POWER10 also introduce phwsync and plwsync which can be used
to establish order of these writes to persistent storage.
This patch exposes these instructions to the rest of the kernel. The existing
dcbf and hwsync instructions in P8 and P9 are adequate to enable appropriate
synchronization with OpenCAPI-hosted persistent storage. Hence the new
instructions are added as a variant of the old ones that old hardware
won't differentiate.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/ppc-opcode.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
Start using dcbstps; phwsync; sequence for flushing persistent memory range.
The new instructions are implemented as a variant of dcbf and hwsync and on
P8 and P9 they will be executed as those instructions. We avoid using them on
older hardware. This helps to avoid difficult to debug bugs.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 1 +
arch/powerpc/lib/pmem.c | 50 ++++++++++++++++++++++++---
2 files changed, 47 insertions(+), 4 deletions(-)
of_pmem on POWER10 can now use phwsync instead of hwsync to ensure
all previous writes are architecturally visible for the platform
buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 7 +++++++
1 file changed, 7 insertions(+)
From: Dan Williams <hidden> Date: 2020-06-30 01:39:55
On Mon, Jun 29, 2020 at 6:58 AM Aneesh Kumar K.V
[off-list ref] wrote:
quoted hunk
of_pmem on POWER10 can now use phwsync instead of hwsync to ensure
all previous writes are architecturally visible for the platform
buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 7 +++++++
1 file changed, 7 insertions(+)
On Mon, Jun 29, 2020 at 6:58 AM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
of_pmem on POWER10 can now use phwsync instead of hwsync to ensure
all previous writes are architecturally visible for the platform
buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 7 +++++++
1 file changed, 7 insertions(+)
Shouldn't this fallback to a compatible store-fence in an else statement?
The idea was to avoid calling this on anything else. We ensure that by
making sure that pmem devices are not initialized on systems without that
cpu feature. Patch 1 does that. Also, the last patch adds a WARN_ON() to
catch the usage of this outside pmem devices and on systems without that
cpu feature.
-aneesh
From: Dan Williams <hidden> Date: 2020-06-30 07:18:16
On Mon, Jun 29, 2020 at 10:05 PM Aneesh Kumar K.V
[off-list ref] wrote:
Dan Williams [off-list ref] writes:
quoted
On Mon, Jun 29, 2020 at 6:58 AM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
of_pmem on POWER10 can now use phwsync instead of hwsync to ensure
all previous writes are architecturally visible for the platform
buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 7 +++++++
1 file changed, 7 insertions(+)
Shouldn't this fallback to a compatible store-fence in an else statement?
The idea was to avoid calling this on anything else. We ensure that by
making sure that pmem devices are not initialized on systems without that
cpu feature. Patch 1 does that. Also, the last patch adds a WARN_ON() to
catch the usage of this outside pmem devices and on systems without that
cpu feature.
If patch1 handles this why re-check the cpu-feature in this helper? If
the intent is for these routines to be generic why not have them fall
back to the P8 barrier instructions for example like x86 clwb(). Any
kernel code can call it, and it falls back to a compatible clflush()
call on older cpus. I otherwise don't get the point of patch7.
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/asm-generic/cacheflush.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
drivers/nvdimm/region_devs.c:1215:2: error: implicit declaration of function 'arch_pmem_flush_barrier' [-Werror=implicit-function-declaration]
1215 | arch_pmem_flush_barrier();
| ^~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/arch_pmem_flush_barrier +1215 drivers/nvdimm/region_devs.c
1178
1179 int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
1180 {
1181 int rc = 0;
1182
1183 if (!nd_region->flush)
1184 rc = generic_nvdimm_flush(nd_region);
1185 else {
1186 if (nd_region->flush(nd_region, bio))
1187 rc = -EIO;
1188 }
1189
1190 return rc;
1191 }
1192 /**
1193 * nvdimm_flush - flush any posted write queues between the cpu and pmem media
1194 * @nd_region: blk or interleaved pmem region
1195 */
1196 int generic_nvdimm_flush(struct nd_region *nd_region)
1197 {
1198 struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev);
1199 int i, idx;
1200
1201 /*
1202 * Try to encourage some diversity in flush hint addresses
1203 * across cpus assuming a limited number of flush hints.
1204 */
1205 idx = this_cpu_read(flush_idx);
1206 idx = this_cpu_add_return(flush_idx, hash_32(current->pid + idx, 8));
1207
1208 /*
1209 * The first arch_pmem_flush_barrier() is needed to 'sfence' all
1210 * previous writes such that they are architecturally visible for
1211 * the platform buffer flush. Note that we've already arranged for pmem
1212 * writes to avoid the cache via memcpy_flushcache(). The final
1213 * wmb() ensures ordering for the NVDIMM flush write.
1214 */
1215 arch_pmem_flush_barrier();
1216 for (i = 0; i < nd_region->ndr_mappings; i++)
1217 if (ndrd_get_flush_wpq(ndrd, i, 0))
1218 writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
1219 wmb();
1220
1221 return 0;
1222 }
1223 EXPORT_SYMBOL_GPL(nvdimm_flush);
1224
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/linux/libnvdimm.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
From: Dan Williams <hidden> Date: 2020-06-30 01:34:48
On Mon, Jun 29, 2020 at 1:29 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted hunk
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/linux/libnvdimm.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
I think it is out of place to define this in libnvdimm.h and it is odd
to give it such a long name. The other pmem api helpers like
arch_wb_cache_pmem() and arch_invalidate_pmem() are function calls for
libnvdimm driver operations, this barrier is just an instruction and
is closer to wmb() than the pmem api routine.
Since it is a store fence for pmem, so let's just call it pmem_wmb()
and define the generic version in include/linux/compiler.h. It should
probably also be documented alongside dma_wmb() in
Documentation/memory-barriers.txt about why code would use it over
wmb(), and why a symmetric pmem_rmb() is not needed.
On Mon, Jun 29, 2020 at 1:29 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/linux/libnvdimm.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
I think it is out of place to define this in libnvdimm.h and it is odd
to give it such a long name. The other pmem api helpers like
arch_wb_cache_pmem() and arch_invalidate_pmem() are function calls for
libnvdimm driver operations, this barrier is just an instruction and
is closer to wmb() than the pmem api routine.
Since it is a store fence for pmem, so let's just call it pmem_wmb()
and define the generic version in include/linux/compiler.h. It should
probably also be documented alongside dma_wmb() in
Documentation/memory-barriers.txt about why code would use it over
wmb(), and why a symmetric pmem_rmb() is not needed.
How about the below? I used pmem_barrier() instead of pmem_wmb(). I
guess we wanted this to order() any data access not jus the following
stores to persistent storage? W.r.t why a symmetric pmem_rmb() is not
needed I was not sure how to explain that. Are you suggesting to explain
why a read/load from persistent storage don't want to wait for
pmem_barrier() ?
modified Documentation/memory-barriers.txt
@@ -1935,6 +1935,16 @@ There are some more advanced barrier functions: relaxed I/O accessors and the Documentation/DMA-API.txt file for more information on consistent memory.+ (*) pmem_barrier();++ These are for use with persistent memory to esure the ordering of stores+ to persistent memory region.++ For example, after a non temporal write to persistent storage we use pmem_barrier()+ to ensures that stores have updated the persistent storage before+ any data access or data transfer caused by subsequent instructions is initiated.+ =============================== IMPLICIT KERNEL MEMORY BARRIERS
modified arch/powerpc/include/asm/barrier.h
@@ -97,6 +97,19 @@ do { \ #define barrier_nospec() #endif /* CONFIG_PPC_BARRIER_NOSPEC */+/*+ * pmem_barrier() ensures that all stores for which the modification+ * are written to persistent storage by preceding dcbfps/dcbstps+ * instructions have updated persistent storage before any data+ * access or data transfer caused by subsequent instructions is+ * initiated.+ */+#define pmem_barrier pmem_barrier+static inline void pmem_barrier(void)+{+ asm volatile(PPC_PHWSYNC ::: "memory");+}+ #include <asm-generic/barrier.h> #endif /* _ASM_POWERPC_BARRIER_H */
modified include/asm-generic/barrier.h
@@ -257,5 +257,16 @@ do { \ }) #endif+/*+ * pmem_barrier() ensures that all stores for which the modification+ * are written to persistent storage by preceding instructions have+ * updated persistent storage before any data access or data transfer+ * caused by subsequent instructions is+ * initiated.+ */+#ifndef pmem_barrier+#define pmem_barrier wmb()+#endif+ #endif /* !__ASSEMBLY__ */ #endif /* __ASM_GENERIC_BARRIER_H */
From: Dan Williams <hidden> Date: 2020-06-30 07:08:46
On Mon, Jun 29, 2020 at 10:02 PM Aneesh Kumar K.V
[off-list ref] wrote:
Dan Williams [off-list ref] writes:
quoted
On Mon, Jun 29, 2020 at 1:29 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/linux/libnvdimm.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
I think it is out of place to define this in libnvdimm.h and it is odd
to give it such a long name. The other pmem api helpers like
arch_wb_cache_pmem() and arch_invalidate_pmem() are function calls for
libnvdimm driver operations, this barrier is just an instruction and
is closer to wmb() than the pmem api routine.
Since it is a store fence for pmem, so let's just call it pmem_wmb()
and define the generic version in include/linux/compiler.h. It should
probably also be documented alongside dma_wmb() in
Documentation/memory-barriers.txt about why code would use it over
wmb(), and why a symmetric pmem_rmb() is not needed.
How about the below? I used pmem_barrier() instead of pmem_wmb().
Why? A barrier() is a bi-directional ordering mechanic for reads and
writes, and the proposed semantics mechanism only orders writes +
persistence. Otherwise the default fallback to wmb() on archs that
don't override it does not make sense.
I
guess we wanted this to order() any data access not jus the following
stores to persistent storage?
Why?
W.r.t why a symmetric pmem_rmb() is not
needed I was not sure how to explain that. Are you suggesting to explain
why a read/load from persistent storage don't want to wait for
pmem_barrier() ?
I would expect that the explanation is that a typical rmb() is
sufficient and that there is nothing pmem specific semantic for read
ordering for pmem vs normal read-barrier semantics.
quoted hunk
modified Documentation/memory-barriers.txt
@@ -1935,6 +1935,16 @@ There are some more advanced barrier functions: relaxed I/O accessors and the Documentation/DMA-API.txt file for more information on consistent memory.+ (*) pmem_barrier();++ These are for use with persistent memory to esure the ordering of stores+ to persistent memory region.
If it was just ordering I would expect a typical wmb() to be
sufficient, why is the pmem-specific instruction needed? I thought it
was handshaking with hardware to ensure acceptance into a persistence
domain *in addition* to ordering the stores.
+ For example, after a non temporal write to persistent storage we use pmem_barrier()
+ to ensures that stores have updated the persistent storage before
+ any data access or data transfer caused by subsequent instructions is initiated.
Isn't the ordering aspect is irrelevant relative to traditional wmb()?
For example if you used the wrong sync instruction the store ordering
will still be correct it would just not persist at the same time as
barrier completes. Or am I misunderstanding how these new instructions
are distinct?
@@ -97,6 +97,19 @@ do { \ #define barrier_nospec() #endif /* CONFIG_PPC_BARRIER_NOSPEC */+/*+ * pmem_barrier() ensures that all stores for which the modification+ * are written to persistent storage by preceding dcbfps/dcbstps+ * instructions have updated persistent storage before any data+ * access or data transfer caused by subsequent instructions is+ * initiated.+ */+#define pmem_barrier pmem_barrier+static inline void pmem_barrier(void)+{+ asm volatile(PPC_PHWSYNC ::: "memory");+}+ #include <asm-generic/barrier.h> #endif /* _ASM_POWERPC_BARRIER_H */
modified include/asm-generic/barrier.h
@@ -257,5 +257,16 @@ do { \ }) #endif+/*+ * pmem_barrier() ensures that all stores for which the modification+ * are written to persistent storage by preceding instructions have+ * updated persistent storage before any data access or data transfer+ * caused by subsequent instructions is+ * initiated.+ */+#ifndef pmem_barrier+#define pmem_barrier wmb()+#endif+ #endif /* !__ASSEMBLY__ */ #endif /* __ASM_GENERIC_BARRIER_H */
On Mon, Jun 29, 2020 at 10:02 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Dan Williams [off-list ref] writes:
quoted
On Mon, Jun 29, 2020 at 1:29 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/linux/libnvdimm.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
I think it is out of place to define this in libnvdimm.h and it is odd
to give it such a long name. The other pmem api helpers like
arch_wb_cache_pmem() and arch_invalidate_pmem() are function calls for
libnvdimm driver operations, this barrier is just an instruction and
is closer to wmb() than the pmem api routine.
Since it is a store fence for pmem, so let's just call it pmem_wmb()
and define the generic version in include/linux/compiler.h. It should
probably also be documented alongside dma_wmb() in
Documentation/memory-barriers.txt about why code would use it over
wmb(), and why a symmetric pmem_rmb() is not needed.
How about the below? I used pmem_barrier() instead of pmem_wmb().
Why? A barrier() is a bi-directional ordering mechanic for reads and
writes, and the proposed semantics mechanism only orders writes +
persistence. Otherwise the default fallback to wmb() on archs that
don't override it does not make sense.
quoted
I
guess we wanted this to order() any data access not jus the following
stores to persistent storage?
Why?
quoted
W.r.t why a symmetric pmem_rmb() is not
needed I was not sure how to explain that. Are you suggesting to explain
why a read/load from persistent storage don't want to wait for
pmem_barrier() ?
I would expect that the explanation is that a typical rmb() is
sufficient and that there is nothing pmem specific semantic for read
ordering for pmem vs normal read-barrier semantics.
quoted
modified Documentation/memory-barriers.txt
@@ -1935,6 +1935,16 @@ There are some more advanced barrier functions: relaxed I/O accessors and the Documentation/DMA-API.txt file for more information on consistent memory.+ (*) pmem_barrier();++ These are for use with persistent memory to esure the ordering of stores+ to persistent memory region.
If it was just ordering I would expect a typical wmb() to be
sufficient, why is the pmem-specific instruction needed? I thought it
was handshaking with hardware to ensure acceptance into a persistence
domain *in addition* to ordering the stores.
quoted
+ For example, after a non temporal write to persistent storage we use pmem_barrier()
+ to ensures that stores have updated the persistent storage before
+ any data access or data transfer caused by subsequent instructions is initiated.
Isn't the ordering aspect is irrelevant relative to traditional wmb()?
For example if you used the wrong sync instruction the store ordering
will still be correct it would just not persist at the same time as
barrier completes. Or am I misunderstanding how these new instructions
are distinct?
On Mon, Jun 29, 2020 at 10:02 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Dan Williams [off-list ref] writes:
quoted
On Mon, Jun 29, 2020 at 1:29 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is
initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/linux/libnvdimm.h | 4 ++++
3 files changed, 9 insertions(+), 5 deletions(-)
@@ -1206,13 +1206,13 @@ int generic_nvdimm_flush(struct nd_region
*nd_region)
idx = this_cpu_add_return(flush_idx, hash_32(current->pid
+ idx, 8));
/*
- * The first wmb() is needed to 'sfence' all previous writes
- * such that they are architecturally visible for the platform
- * buffer flush. Note that we've already arranged for pmem
+ * The first arch_pmem_flush_barrier() is needed to
'sfence' all
+ * previous writes such that they are architecturally
visible for
+ * the platform buffer flush. Note that we've already
arranged for pmem
* writes to avoid the cache via memcpy_flushcache(). The
final
* wmb() ensures ordering for the NVDIMM flush write.
*/
- wmb();
+ arch_pmem_flush_barrier();
for (i = 0; i < nd_region->ndr_mappings; i++)
if (ndrd_get_flush_wpq(ndrd, i, 0))
writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
I think it is out of place to define this in libnvdimm.h and it is odd
to give it such a long name. The other pmem api helpers like
arch_wb_cache_pmem() and arch_invalidate_pmem() are function calls for
libnvdimm driver operations, this barrier is just an instruction and
is closer to wmb() than the pmem api routine.
Since it is a store fence for pmem, so let's just call it pmem_wmb()
and define the generic version in include/linux/compiler.h. It should
probably also be documented alongside dma_wmb() in
Documentation/memory-barriers.txt about why code would use it over
wmb(), and why a symmetric pmem_rmb() is not needed.
How about the below? I used pmem_barrier() instead of pmem_wmb().
Why? A barrier() is a bi-directional ordering mechanic for reads and
writes, and the proposed semantics mechanism only orders writes +
persistence. Otherwise the default fallback to wmb() on archs that
don't override it does not make sense.
quoted
I
guess we wanted this to order() any data access not jus the following
stores to persistent storage?
Why?
quoted
W.r.t why a symmetric pmem_rmb() is not
needed I was not sure how to explain that. Are you suggesting to explain
why a read/load from persistent storage don't want to wait for
pmem_barrier() ?
I would expect that the explanation is that a typical rmb() is
sufficient and that there is nothing pmem specific semantic for read
ordering for pmem vs normal read-barrier semantics.
Should that be rmb()? A smp_rmb() would suffice right?
-aneesh
Update patch.
From 1e6aa6c4182e14ec5d6bf878ae44c3f69ebff745 Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <redacted>
Date: Tue, 12 May 2020 20:58:33 +0530
Subject: [PATCH] libnvdimm/nvdimm/flush: Allow architecture to override the
flush barrier
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
Documentation/memory-barriers.txt | 14 ++++++++++++++
drivers/md/dm-writecache.c | 2 +-
drivers/nvdimm/region_devs.c | 8 ++++----
include/asm-generic/barrier.h | 10 ++++++++++
4 files changed, 29 insertions(+), 5 deletions(-)
@@ -1935,6 +1935,20 @@ There are some more advanced barrier functions: relaxed I/O accessors and the Documentation/DMA-API.txt file for more information on consistent memory.+ (*) pmem_wmb();++ This is for use with persistent memory to ensure that stores for which+ modifications are written to persistent storage have updated the persistent+ storage.++ For example, after a non-temporal write to pmem region, we use pmem_wmb()+ to ensures that stores have updated the persistent storage. This ensures+ that stores have updated persistent storage before any data access or+ data transfer caused by subsequent instructions is initiated. This is+ in addition to the ordering done by wmb().++ For load from persistent memory, existing read memory barriers are sufficient+ to ensure read ordering. =============================== IMPLICIT KERNEL MEMORY BARRIERS
From: Dan Williams <hidden> Date: 2020-06-30 19:24:03
On Tue, Jun 30, 2020 at 5:48 AM Aneesh Kumar K.V
[off-list ref] wrote:
Update patch.
From 1e6aa6c4182e14ec5d6bf878ae44c3f69ebff745 Mon Sep 17 00:00:00 2001
From: "Aneesh Kumar K.V" <redacted>
Date: Tue, 12 May 2020 20:58:33 +0530
Subject: [PATCH] libnvdimm/nvdimm/flush: Allow architecture to override the
flush barrier
Architectures like ppc64 provide persistent memory specific barriers
that will ensure that all stores for which the modifications are
written to persistent storage by preceding dcbfps and dcbstps
instructions have updated persistent storage before any data
access or data transfer caused by subsequent instructions is initiated.
This is in addition to the ordering done by wmb()
Update nvdimm core such that architecture can use barriers other than
wmb to ensure all previous writes are architecturally visible for
the platform buffer flush.
Looks good, after a few minor fixups below you can add:
Reviewed-by: Dan Williams <redacted>
I'm expecting that these will be merged through the powerpc tree since
they mostly impact powerpc with only minor touches to libnvdimm.
@@ -1935,6 +1935,20 @@ There are some more advanced barrier functions: relaxed I/O accessors and the Documentation/DMA-API.txt file for more information on consistent memory.+ (*) pmem_wmb();++ This is for use with persistent memory to ensure that stores for which+ modifications are written to persistent storage have updated the persistent+ storage.
I think this should be:
s/updated the persistent storage/reached a platform durability domain/
+
+ For example, after a non-temporal write to pmem region, we use pmem_wmb()
+ to ensures that stores have updated the persistent storage. This ensures
s/ensures/ensure/
...and the same comment about "persistent storage" because pmem_wmb()
as implemented on x86 does not guarantee that the writes have reached
storage it ensures that writes have reached buffers / queues that are
within the ADR (platform persistence / durability) domain.
quoted hunk
+ that stores have updated persistent storage before any data access or
+ data transfer caused by subsequent instructions is initiated. This is
+ in addition to the ordering done by wmb().
+
+ For load from persistent memory, existing read memory barriers are sufficient
+ to ensure read ordering.
===============================
IMPLICIT KERNEL MEMORY BARRIERS
@@ -1206,13 +1206,13 @@ int generic_nvdimm_flush(struct nd_region *nd_region)idx=this_cpu_add_return(flush_idx,hash_32(current->pid+idx,8));/*-*Thefirstwmb()isneededto'sfence'allpreviouswrites-*suchthattheyarearchitecturallyvisiblefortheplatform-*bufferflush.Notethatwe'vealreadyarrangedforpmem+*Thefirstarch_pmem_flush_barrier()isneededto'sfence'all
One missed arch_pmem_flush_barrier() rename.
quoted hunk
+ * previous writes such that they are architecturally visible for
+ * the platform buffer flush. Note that we've already arranged for pmem
* writes to avoid the cache via memcpy_flushcache(). The final
* wmb() ensures ordering for the NVDIMM flush write.
*/
- wmb();
+ pmem_wmb();
for (i = 0; i < nd_region->ndr_mappings; i++)
if (ndrd_get_flush_wpq(ndrd, i, 0))
writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
@@ -257,5 +257,15 @@ do { \})#endif+/*+*pmem_barrier()ensuresthatallstoresforwhichthemodification
One missed pmem_barrier() conversion.
+ * are written to persistent storage by preceding instructions have
+ * updated persistent storage before any data access or data transfer
+ * caused by subsequent instructions is initiated.
+ */
+#ifndef pmem_wmb
+#define pmem_wmb() wmb()
+#endif
+
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_GENERIC_BARRIER_H */
--
2.26.2
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Update the papr_scm driver to a simplified nvdim_flush callback that do
only the required barrier.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
arch/powerpc/platforms/pseries/papr_scm.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
From: Michal Suchánek <hidden> Date: 2020-06-29 16:11:51
Hello,
On Mon, Jun 29, 2020 at 07:27:20PM +0530, Aneesh Kumar K.V wrote:
quoted hunk
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Update the papr_scm driver to a simplified nvdim_flush callback that do
only the required barrier.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
arch/powerpc/platforms/pseries/papr_scm.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
@@ -630,6 +630,18 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,return0;}+/*+*Wehavemadesurethepmemwritesaredonesuchthatbeforecallingthis+*allthecachesareflushed/clean.Weusedcbf/dcbfpstoensurethis.Here+*wejustneedtoaddthenecessarybarriertomakesuretheaboveflushes+*arehaveupdatedpersistentstoragebeforeanydataaccessordatatransfer+*causedbysubsequentinstructionsisinitiated.+*/+staticintpapr_scm_flush_sync(structnd_region*nd_region,structbio*bio)+{+arch_pmem_flush_barrier();+return0;+}staticssize_tflags_show(structdevice*dev,structdevice_attribute*attr,char*buf)
@@ -743,6 +755,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)ndr_desc.mapping=&mapping;ndr_desc.num_mappings=1;ndr_desc.nd_set=&p->nd_set;+ndr_desc.flush=papr_scm_flush_sync;
AFAICT currently the only device that implements flush is virtio_pmem.
How does the nfit driver get away without implementing flush?
Also the flush takes arguments that are completely unused but a user of
the pmem region must assume they are used, and call flush() on the
region rather than arch_pmem_flush_barrier() directly. This may not
work well with md as discussed with earlier iteration of the patchest.
Thanks
Michal
Hello,
On Mon, Jun 29, 2020 at 07:27:20PM +0530, Aneesh Kumar K.V wrote:
quoted
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Update the papr_scm driver to a simplified nvdim_flush callback that do
only the required barrier.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
arch/powerpc/platforms/pseries/papr_scm.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
@@ -630,6 +630,18 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,return0;}+/*+*Wehavemadesurethepmemwritesaredonesuchthatbeforecallingthis+*allthecachesareflushed/clean.Weusedcbf/dcbfpstoensurethis.Here+*wejustneedtoaddthenecessarybarriertomakesuretheaboveflushes+*arehaveupdatedpersistentstoragebeforeanydataaccessordatatransfer+*causedbysubsequentinstructionsisinitiated.+*/+staticintpapr_scm_flush_sync(structnd_region*nd_region,structbio*bio)+{+arch_pmem_flush_barrier();+return0;+}staticssize_tflags_show(structdevice*dev,structdevice_attribute*attr,char*buf)
@@ -743,6 +755,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)ndr_desc.mapping=&mapping;ndr_desc.num_mappings=1;ndr_desc.nd_set=&p->nd_set;+ndr_desc.flush=papr_scm_flush_sync;
AFAICT currently the only device that implements flush is virtio_pmem.
How does the nfit driver get away without implementing flush?
generic_nvdimm_flush does the required barrier for nfit. The reason for
adding ndr_desc.flush call back for papr_scm was to avoid the usage
of iomem based deep flushing (ndr_region_data.flush_wpq) which is not
supported by papr_scm.
BTW we do return NULL for ndrd_get_flush_wpq() on power. So the upstream
code also does the same thing, but in a different way.
Also the flush takes arguments that are completely unused but a user of
the pmem region must assume they are used, and call flush() on the
region rather than arch_pmem_flush_barrier() directly.
The bio argument can help a pmem driver to do range based flushing in
case of pmem_make_request. If bio is null then we must assume a full
device flush.
This may not
work well with md as discussed with earlier iteration of the patchest.
dm-writecache needs some major changes to work with asynchronous pmem
devices.
-aneesh
From: Dan Williams <hidden> Date: 2020-06-30 01:52:34
On Mon, Jun 29, 2020 at 1:41 PM Aneesh Kumar K.V
[off-list ref] wrote:
Michal Suchánek [off-list ref] writes:
quoted
Hello,
On Mon, Jun 29, 2020 at 07:27:20PM +0530, Aneesh Kumar K.V wrote:
quoted
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Update the papr_scm driver to a simplified nvdim_flush callback that do
only the required barrier.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
arch/powerpc/platforms/pseries/papr_scm.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
@@ -630,6 +630,18 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,return0;}+/*+*Wehavemadesurethepmemwritesaredonesuchthatbeforecallingthis+*allthecachesareflushed/clean.Weusedcbf/dcbfpstoensurethis.Here+*wejustneedtoaddthenecessarybarriertomakesuretheaboveflushes+*arehaveupdatedpersistentstoragebeforeanydataaccessordatatransfer+*causedbysubsequentinstructionsisinitiated.+*/+staticintpapr_scm_flush_sync(structnd_region*nd_region,structbio*bio)+{+arch_pmem_flush_barrier();+return0;+}staticssize_tflags_show(structdevice*dev,structdevice_attribute*attr,char*buf)
@@ -743,6 +755,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)ndr_desc.mapping=&mapping;ndr_desc.num_mappings=1;ndr_desc.nd_set=&p->nd_set;+ndr_desc.flush=papr_scm_flush_sync;
AFAICT currently the only device that implements flush is virtio_pmem.
How does the nfit driver get away without implementing flush?
generic_nvdimm_flush does the required barrier for nfit. The reason for
adding ndr_desc.flush call back for papr_scm was to avoid the usage
of iomem based deep flushing (ndr_region_data.flush_wpq) which is not
supported by papr_scm.
BTW we do return NULL for ndrd_get_flush_wpq() on power. So the upstream
code also does the same thing, but in a different way.
quoted
Also the flush takes arguments that are completely unused but a user of
the pmem region must assume they are used, and call flush() on the
region rather than arch_pmem_flush_barrier() directly.
The bio argument can help a pmem driver to do range based flushing in
case of pmem_make_request. If bio is null then we must assume a full
device flush.
The bio argument isn't for range based flushing, it is for flush
operations that need to complete asynchronously.
There's no mechanism for the block layer to communicate range based
cache flushing, block-device flushing is assumed to be the device's
entire cache. For pmem that would be the entirety of the cpu cache.
Instead of modeling the cpu cache as a storage device cache it is
modeled as page-cache. Once the fs-layer writes back page-cache /
cpu-cache the storage device is only responsible for flushing those
cache-writes into the persistence domain.
Additionally there is a concept of deep-flush that relegates some
power-fail scenarios to a smaller failure domain. For example consider
the difference between a write arriving at the head of a device-queue
and successfully traversing a device-queue to media. The expectation
of pmem applications is that data is persisted once they reach the
equivalent of the x86 ADR domain, deep-flush is past ADR.
From: Michal Suchánek <hidden> Date: 2020-06-30 08:56:12
On Mon, Jun 29, 2020 at 06:50:15PM -0700, Dan Williams wrote:
On Mon, Jun 29, 2020 at 1:41 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Michal Suchánek [off-list ref] writes:
quoted
Hello,
On Mon, Jun 29, 2020 at 07:27:20PM +0530, Aneesh Kumar K.V wrote:
quoted
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Update the papr_scm driver to a simplified nvdim_flush callback that do
only the required barrier.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
arch/powerpc/platforms/pseries/papr_scm.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
@@ -630,6 +630,18 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,return0;}+/*+*Wehavemadesurethepmemwritesaredonesuchthatbeforecallingthis+*allthecachesareflushed/clean.Weusedcbf/dcbfpstoensurethis.Here+*wejustneedtoaddthenecessarybarriertomakesuretheaboveflushes+*arehaveupdatedpersistentstoragebeforeanydataaccessordatatransfer+*causedbysubsequentinstructionsisinitiated.+*/+staticintpapr_scm_flush_sync(structnd_region*nd_region,structbio*bio)+{+arch_pmem_flush_barrier();+return0;+}staticssize_tflags_show(structdevice*dev,structdevice_attribute*attr,char*buf)
@@ -743,6 +755,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)ndr_desc.mapping=&mapping;ndr_desc.num_mappings=1;ndr_desc.nd_set=&p->nd_set;+ndr_desc.flush=papr_scm_flush_sync;
AFAICT currently the only device that implements flush is virtio_pmem.
How does the nfit driver get away without implementing flush?
generic_nvdimm_flush does the required barrier for nfit. The reason for
adding ndr_desc.flush call back for papr_scm was to avoid the usage
of iomem based deep flushing (ndr_region_data.flush_wpq) which is not
supported by papr_scm.
BTW we do return NULL for ndrd_get_flush_wpq() on power. So the upstream
code also does the same thing, but in a different way.
quoted
Also the flush takes arguments that are completely unused but a user of
the pmem region must assume they are used, and call flush() on the
region rather than arch_pmem_flush_barrier() directly.
The bio argument can help a pmem driver to do range based flushing in
case of pmem_make_request. If bio is null then we must assume a full
device flush.
The bio argument isn't for range based flushing, it is for flush
operations that need to complete asynchronously.
How does the block layer determine that the pmem device needs
asynchronous fushing?
The flush() was designed for the purpose with the bio argument and only
virtio_pmem which is fulshed asynchronously used it. Now that papr_scm
resuses it fir different purpose how do you tell?
Thanks
Michal
On Mon, Jun 29, 2020 at 06:50:15PM -0700, Dan Williams wrote:
quoted
On Mon, Jun 29, 2020 at 1:41 PM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
Michal Suchánek [off-list ref] writes:
quoted
Hello,
On Mon, Jun 29, 2020 at 07:27:20PM +0530, Aneesh Kumar K.V wrote:
quoted
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Update the papr_scm driver to a simplified nvdim_flush callback that do
only the required barrier.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
arch/powerpc/platforms/pseries/papr_scm.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 6 deletions(-)
@@ -630,6 +630,18 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,return0;}+/*+*Wehavemadesurethepmemwritesaredonesuchthatbeforecallingthis+*allthecachesareflushed/clean.Weusedcbf/dcbfpstoensurethis.Here+*wejustneedtoaddthenecessarybarriertomakesuretheaboveflushes+*arehaveupdatedpersistentstoragebeforeanydataaccessordatatransfer+*causedbysubsequentinstructionsisinitiated.+*/+staticintpapr_scm_flush_sync(structnd_region*nd_region,structbio*bio)+{+arch_pmem_flush_barrier();+return0;+}staticssize_tflags_show(structdevice*dev,structdevice_attribute*attr,char*buf)
@@ -743,6 +755,7 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)ndr_desc.mapping=&mapping;ndr_desc.num_mappings=1;ndr_desc.nd_set=&p->nd_set;+ndr_desc.flush=papr_scm_flush_sync;
AFAICT currently the only device that implements flush is virtio_pmem.
How does the nfit driver get away without implementing flush?
generic_nvdimm_flush does the required barrier for nfit. The reason for
adding ndr_desc.flush call back for papr_scm was to avoid the usage
of iomem based deep flushing (ndr_region_data.flush_wpq) which is not
supported by papr_scm.
BTW we do return NULL for ndrd_get_flush_wpq() on power. So the upstream
code also does the same thing, but in a different way.
quoted
Also the flush takes arguments that are completely unused but a user of
the pmem region must assume they are used, and call flush() on the
region rather than arch_pmem_flush_barrier() directly.
The bio argument can help a pmem driver to do range based flushing in
case of pmem_make_request. If bio is null then we must assume a full
device flush.
The bio argument isn't for range based flushing, it is for flush
operations that need to complete asynchronously.
How does the block layer determine that the pmem device needs
asynchronous fushing?
set_bit(ND_REGION_ASYNC, &ndr_desc.flags);
and dax_synchronous(dev)
The flush() was designed for the purpose with the bio argument and only
virtio_pmem which is fulshed asynchronously used it. Now that papr_scm
resuses it fir different purpose how do you tell?
From: Dan Williams <hidden> Date: 2020-06-30 19:47:31
On Tue, Jun 30, 2020 at 2:21 AM Aneesh Kumar K.V
[off-list ref] wrote:
[..]
quoted
quoted
The bio argument isn't for range based flushing, it is for flush
operations that need to complete asynchronously.
How does the block layer determine that the pmem device needs
asynchronous fushing?
set_bit(ND_REGION_ASYNC, &ndr_desc.flags);
and dax_synchronous(dev)
Yes, but I think it is overkill to have an indirect function call just
for a single instruction.
How about something like this instead, to share a common pmem_wmb()
across x86 and powerpc.
@@ -1180,6 +1180,13 @@ int nvdimm_flush(struct nd_region *nd_region,
struct bio *bio)
{
int rc = 0;
+ /*
+ * pmem_wmb() is needed to 'sfence' all previous writes such
+ * that they are architecturally visible for the platform buffer
+ * flush.
+ */
+ pmem_wmb();
+
if (!nd_region->flush)
rc = generic_nvdimm_flush(nd_region);
else {
@@ -1206,17 +1213,14 @@ int generic_nvdimm_flush(struct nd_region *nd_region) idx = this_cpu_add_return(flush_idx, hash_32(current->pid + idx, 8)); /*- * The first wmb() is needed to 'sfence' all previous writes- * such that they are architecturally visible for the platform- * buffer flush. Note that we've already arranged for pmem- * writes to avoid the cache via memcpy_flushcache(). The final- * wmb() ensures ordering for the NVDIMM flush write.+ * Note that we've already arranged for pmem writes to avoid the+ * cache via memcpy_flushcache(). The final wmb() ensures+ * ordering for the NVDIMM flush write. */- wmb(); for (i = 0; i < nd_region->ndr_mappings; i++) if (ndrd_get_flush_wpq(ndrd, i, 0)) writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));- wmb();+ pmem_wmb(); return 0; }
On Tue, Jun 30, 2020 at 2:21 AM Aneesh Kumar K.V
[off-list ref] wrote:
[..]
quoted
quoted
quoted
The bio argument isn't for range based flushing, it is for flush
operations that need to complete asynchronously.
How does the block layer determine that the pmem device needs
asynchronous fushing?
set_bit(ND_REGION_ASYNC, &ndr_desc.flags);
and dax_synchronous(dev)
Yes, but I think it is overkill to have an indirect function call just
for a single instruction.
How about something like this instead, to share a common pmem_wmb()
across x86 and powerpc.
@@ -1180,6 +1180,13 @@ int nvdimm_flush(struct nd_region *nd_region,
struct bio *bio)
{
int rc = 0;
+ /*
+ * pmem_wmb() is needed to 'sfence' all previous writes such
+ * that they are architecturally visible for the platform buffer
+ * flush.
+ */
+ pmem_wmb();
+
if (!nd_region->flush)
rc = generic_nvdimm_flush(nd_region);
else {
@@ -1206,17 +1213,14 @@ int generic_nvdimm_flush(struct nd_region *nd_region) idx = this_cpu_add_return(flush_idx, hash_32(current->pid + idx, 8)); /*- * The first wmb() is needed to 'sfence' all previous writes- * such that they are architecturally visible for the platform- * buffer flush. Note that we've already arranged for pmem- * writes to avoid the cache via memcpy_flushcache(). The final- * wmb() ensures ordering for the NVDIMM flush write.+ * Note that we've already arranged for pmem writes to avoid the+ * cache via memcpy_flushcache(). The final wmb() ensures+ * ordering for the NVDIMM flush write. */- wmb();
The series already convert this to pmem_wmb().
for (i = 0; i < nd_region->ndr_mappings; i++)
if (ndrd_get_flush_wpq(ndrd, i, 0))
writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
- wmb();
+ pmem_wmb();
Should this be pmem_wmb()? This is ordering the above writeq() right?
return 0;
}
This still results in two pmem_wmb() on platforms that doesn't have
flush_wpq. I was trying to avoid that by adding a nd_region->flush call
back.
-aneesh
From: Dan Williams <hidden> Date: 2020-07-01 05:11:05
On Tue, Jun 30, 2020 at 8:09 PM Aneesh Kumar K.V
[off-list ref] wrote:
On 7/1/20 1:15 AM, Dan Williams wrote:
quoted
On Tue, Jun 30, 2020 at 2:21 AM Aneesh Kumar K.V
[off-list ref] wrote:
[..]
quoted
quoted
quoted
The bio argument isn't for range based flushing, it is for flush
operations that need to complete asynchronously.
How does the block layer determine that the pmem device needs
asynchronous fushing?
set_bit(ND_REGION_ASYNC, &ndr_desc.flags);
and dax_synchronous(dev)
Yes, but I think it is overkill to have an indirect function call just
for a single instruction.
How about something like this instead, to share a common pmem_wmb()
across x86 and powerpc.
@@ -1180,6 +1180,13 @@ int nvdimm_flush(struct nd_region *nd_region,
struct bio *bio)
{
int rc = 0;
+ /*
+ * pmem_wmb() is needed to 'sfence' all previous writes such
+ * that they are architecturally visible for the platform buffer
+ * flush.
+ */
+ pmem_wmb();
+
if (!nd_region->flush)
rc = generic_nvdimm_flush(nd_region);
else {
@@ -1206,17 +1213,14 @@ int generic_nvdimm_flush(struct nd_region *nd_region) idx = this_cpu_add_return(flush_idx, hash_32(current->pid + idx, 8)); /*- * The first wmb() is needed to 'sfence' all previous writes- * such that they are architecturally visible for the platform- * buffer flush. Note that we've already arranged for pmem- * writes to avoid the cache via memcpy_flushcache(). The final- * wmb() ensures ordering for the NVDIMM flush write.+ * Note that we've already arranged for pmem writes to avoid the+ * cache via memcpy_flushcache(). The final wmb() ensures+ * ordering for the NVDIMM flush write. */- wmb();
The series already convert this to pmem_wmb().
quoted
for (i = 0; i < nd_region->ndr_mappings; i++)
if (ndrd_get_flush_wpq(ndrd, i, 0))
writeq(1, ndrd_get_flush_wpq(ndrd, i, idx));
- wmb();
+ pmem_wmb();
Should this be pmem_wmb()? This is ordering the above writeq() right?
Correct, this can just be wmb().
quoted
return 0;
}
This still results in two pmem_wmb() on platforms that doesn't have
flush_wpq. I was trying to avoid that by adding a nd_region->flush call
back.
How about skip or exit early out of generic_nvdimm_flush if
ndrd->flush_wpq is NULL? That still saves an indirect branch at the
cost of another conditional, but that should still be worth it.
We only support persistent memory on P8 and above. This is enforced by the
firmware and further checked on virtualzied platform during platform init.
Add WARN_ONCE in pmem flush routines to catch the wrong usage of these.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 2 ++
arch/powerpc/lib/pmem.c | 2 ++
2 files changed, 4 insertions(+)
From: Dan Williams <hidden> Date: 2020-06-30 01:54:30
On Mon, Jun 29, 2020 at 6:58 AM Aneesh Kumar K.V
[off-list ref] wrote:
quoted hunk
We only support persistent memory on P8 and above. This is enforced by the
firmware and further checked on virtualzied platform during platform init.
Add WARN_ONCE in pmem flush routines to catch the wrong usage of these.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 2 ++
arch/powerpc/lib/pmem.c | 2 ++
2 files changed, 4 insertions(+)
On Mon, Jun 29, 2020 at 6:58 AM Aneesh Kumar K.V
[off-list ref] wrote:
quoted
We only support persistent memory on P8 and above. This is enforced by the
firmware and further checked on virtualzied platform during platform init.
Add WARN_ONCE in pmem flush routines to catch the wrong usage of these.
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/include/asm/cacheflush.h | 2 ++
arch/powerpc/lib/pmem.c | 2 ++
2 files changed, 4 insertions(+)
With kernel now supporting new pmem flush/sync instructions, we can now
enable the kernel to initialize the device. On P10 these devices would
appear with a new compatible string. For PAPR device we have
compatible "ibm,pmemory-v2"
and for OF pmem device we have
compatible "pmem-region-v2"
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/platforms/pseries/papr_scm.c | 1 +
drivers/nvdimm/of_pmem.c | 1 +
2 files changed, 2 insertions(+)