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 v6:
* rename flush barrier to pmem_wmb(). Update documentation.
* Drop the WARN_ON in flush routines.
* Drop pap_scm ndr_region flush callback.
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 (7):
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: Update ppc64 to use the new barrier instruction.
powerpc/pmem: Avoid the barrier in flush routines
powerpc/pmem: Initialize pmem device on newer hardware
Documentation/memory-barriers.txt | 14 ++++++++
arch/powerpc/include/asm/barrier.h | 13 +++++++
arch/powerpc/include/asm/cacheflush.h | 1 +
arch/powerpc/include/asm/ppc-opcode.h | 12 +++++++
arch/powerpc/lib/pmem.c | 44 ++++++++++++++++++++---
arch/powerpc/platforms/pseries/papr_scm.c | 1 +
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/barrier.h | 10 ++++++
11 files changed, 103 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(+)
From: Michal Suchánek <hidden> Date: 2022-01-21 08:41:48
Hello,
On Wed, Jul 01, 2020 at 12:52:29PM +0530, Aneesh Kumar K.V wrote:
quoted hunk
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(+)
This looks superfluous.
The hypervisor is responsible for publishing the pmem in devicetree when
present, kernel is responsible for using it when supported by the
kernel.
Or is there a problem that the flush instruction is not available in P7
compat mode?
Even then volatile regions should still work.
Thanks
Michal
Hello,
On Wed, Jul 01, 2020 at 12:52:29PM +0530, Aneesh Kumar K.V wrote:
quoted
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(+)
This looks superfluous.
The hypervisor is responsible for publishing the pmem in devicetree when
present, kernel is responsible for using it when supported by the
kernel.
Or is there a problem that the flush instruction is not available in P7
compat mode?
We want to avoid the usage of persistent memory on p7 compat mode
because such a guest can LPM migrate to p7 systems. Now ideally I would
expect hypervisor to avoid such migration, that is a p7 compat mode
guest running on p10 using persistence memory migrating to p7
(considering p7 never really had support for persistent memory).
There was also the complexity w.r.t what instructions the userspace will
use. So it was discussed at that point that we could comfortably state
and prevent the usage of persistent memory on p7 and below.
Even then volatile regions should still work.
That is a different problem altogether. We could really kill the usage of
cache flush w.r.t volatile regions from the nvdimm driver right?
For all these reason, disabling pmem on p7 was found to be the simplest solution.
-aneesh
From: Michal Suchánek <hidden> Date: 2022-01-21 13:28:14
On Fri, Jan 21, 2022 at 02:48:32PM +0530, Aneesh Kumar K.V wrote:
Michal Suchánek [off-list ref] writes:
quoted
Hello,
On Wed, Jul 01, 2020 at 12:52:29PM +0530, Aneesh Kumar K.V wrote:
quoted
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(+)
This looks superfluous.
The hypervisor is responsible for publishing the pmem in devicetree when
present, kernel is responsible for using it when supported by the
kernel.
Or is there a problem that the flush instruction is not available in P7
compat mode?
We want to avoid the usage of persistent memory on p7 compat mode
because such a guest can LPM migrate to p7 systems. Now ideally I would
expect hypervisor to avoid such migration, that is a p7 compat mode
guest running on p10 using persistence memory migrating to p7
(considering p7 never really had support for persistent memory).
Yes, I would expect the hypervisor to prevent migration to host that
does not have all the hardawre that the guest uses. It could still
migrate to P8 or whatever in compat mode.
There was also the complexity w.r.t what instructions the userspace will
use. So it was discussed at that point that we could comfortably state
and prevent the usage of persistent memory on p7 and below.
But is that arbitrary or does POWER7 not support the pmem sync instructions?
If that is true then how is POWER7 compat mode behaving WRT those
instructions?
Thanks
Michal
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(-)
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.
Before this patch, the flush was done for all.
After this patch, IIUC the flush is done only on CPUs having feature
CPU_FTR_ARCH_207S.
What about other CPUs ?
I don't know much about PMEM, my concern is about the UACCESS_FLUSHCACHE
API introduced by commit 6c44741d75a2 ("powerpc/lib: Implement
UACCESS_FLUSHCACHE API")
After your patch, __copy_from_user_flushcache() and memcpy_flushcache()
are not doing cache flush anymore.
Is that intended ?
I'm trying to optimise some ALSA driver that does copy_from_user +
cache_flush for DMA, and I was wondering if using
__copy_from_user_flushcache() was an alternative.
Or is it __copy_from_user_inatomic_nocache() which has to be done for that ?
Thanks
Christophe
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.
Before this patch, the flush was done for all.
After this patch, IIUC the flush is done only on CPUs having feature
CPU_FTR_ARCH_207S.
What about other CPUs ?
I don't know much about PMEM, my concern is about the UACCESS_FLUSHCACHE
API introduced by commit 6c44741d75a2 ("powerpc/lib: Implement
UACCESS_FLUSHCACHE API")
After your patch, __copy_from_user_flushcache() and memcpy_flushcache()
are not doing cache flush anymore.
Is that intended ?
yes, with the understanding that these functions are used with
persistent memory . We restrict the persistent memory usage to p8 and
above via commit c83040192f3763b243ece26073d61a895b4a230f
I'm trying to optimise some ALSA driver that does copy_from_user +
cache_flush for DMA, and I was wondering if using
__copy_from_user_flushcache() was an alternative.
Or is it __copy_from_user_inatomic_nocache() which has to be done for that ?
Thanks
Christophe
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.
Reviewed-by: Dan Williams <redacted>
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 reached a platform+ durability domain.++ For example, after a non-temporal write to pmem region, we use pmem_wmb()+ to ensure that stores have reached a platform durability domain. 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
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(+)
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/barrier.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
nvdimm expect the flush routines to just mark the cache clean. The barrier
that mark the store globally visible is done in nvdimm_flush().
Signed-off-by: Aneesh Kumar K.V <redacted>
---
arch/powerpc/lib/pmem.c | 6 ------
1 file changed, 6 deletions(-)
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.
[...]