Skip to content

Commit 2ac02e5

Browse files
kvaneeshmpe
authored andcommitted
powerpc/mm: Remove dcache flush from memory remove.
We added dcache flush on memory add/remove in commit fb5924f ("powerpc/mm: Flush cache on memory hot(un)plug") to handle crashes on GPU hotplug. Instead of adding dcache flush in generic memory add/remove routine which is used even for regular memory, we should handle these devices specific flush in the device driver code. memtrace did handle this in the driver and that was removed by commit 7fd6641 ("powerpc/powernv/memtrace: Let the arch hotunplug code flush cache"). This patch reverts that commit. The dcache flush in memory add was removed by commit ea458ef ("powerpc: Don't flush caches when adding memory") which I don't think is correct. The reason why we require dcache flush in memtrace is to make sure we don't have a dirty cache when we remap a pfn to cache inhibited. We should do that when the memtrace module removes the memory and make the pfn available for HTM traces to map it as cache inhibited. The other device mentioned in commit fb5924f ("powerpc/mm: Flush cache on memory hot(un)plug") is nvlink device with coherent memory. The support for that was removed in commit 7eb3cf7 ("powerpc/powernv: remove unused NPU DMA code") and commit 25b2995 ("mm: remove MEMORY_DEVICE_PUBLIC support") Signed-off-by: Aneesh Kumar K.V <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ec94b9b commit 2ac02e5

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

arch/powerpc/mm/mem.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,6 @@ int __weak remove_section_mapping(unsigned long start, unsigned long end)
9191
return -ENODEV;
9292
}
9393

94-
#define FLUSH_CHUNK_SIZE SZ_1G
95-
/**
96-
* flush_dcache_range_chunked(): Write any modified data cache blocks out to
97-
* memory and invalidate them, in chunks of up to FLUSH_CHUNK_SIZE
98-
* Does not invalidate the corresponding instruction cache blocks.
99-
*
100-
* @start: the start address
101-
* @stop: the stop address (exclusive)
102-
* @chunk: the max size of the chunks
103-
*/
104-
static void flush_dcache_range_chunked(unsigned long start, unsigned long stop,
105-
unsigned long chunk)
106-
{
107-
unsigned long i;
108-
109-
for (i = start; i < stop; i += chunk) {
110-
flush_dcache_range(i, min(stop, i + chunk));
111-
cond_resched();
112-
}
113-
}
114-
11594
int __ref arch_create_linear_mapping(int nid, u64 start, u64 size,
11695
struct mhp_params *params)
11796
{
@@ -136,7 +115,6 @@ void __ref arch_remove_linear_mapping(u64 start, u64 size)
136115

137116
/* Remove htab bolted mappings for this section of memory */
138117
start = (unsigned long)__va(start);
139-
flush_dcache_range_chunked(start, start + size, FLUSH_CHUNK_SIZE);
140118

141119
mutex_lock(&linear_mapping_mutex);
142120
ret = remove_section_mapping(start, start + size);

arch/powerpc/platforms/powernv/memtrace.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/numa.h>
2020
#include <asm/machdep.h>
2121
#include <asm/debugfs.h>
22+
#include <asm/cacheflush.h>
2223

2324
/* This enables us to keep track of the memory removed from each node. */
2425
struct memtrace_entry {
@@ -51,6 +52,27 @@ static const struct file_operations memtrace_fops = {
5152
.open = simple_open,
5253
};
5354

55+
#define FLUSH_CHUNK_SIZE SZ_1G
56+
/**
57+
* flush_dcache_range_chunked(): Write any modified data cache blocks out to
58+
* memory and invalidate them, in chunks of up to FLUSH_CHUNK_SIZE
59+
* Does not invalidate the corresponding instruction cache blocks.
60+
*
61+
* @start: the start address
62+
* @stop: the stop address (exclusive)
63+
* @chunk: the max size of the chunks
64+
*/
65+
static void flush_dcache_range_chunked(unsigned long start, unsigned long stop,
66+
unsigned long chunk)
67+
{
68+
unsigned long i;
69+
70+
for (i = start; i < stop; i += chunk) {
71+
flush_dcache_range(i, min(stop, i + chunk));
72+
cond_resched();
73+
}
74+
}
75+
5476
static void memtrace_clear_range(unsigned long start_pfn,
5577
unsigned long nr_pages)
5678
{
@@ -62,6 +84,13 @@ static void memtrace_clear_range(unsigned long start_pfn,
6284
cond_resched();
6385
clear_page(__va(PFN_PHYS(pfn)));
6486
}
87+
/*
88+
* Before we go ahead and use this range as cache inhibited range
89+
* flush the cache.
90+
*/
91+
flush_dcache_range_chunked(PFN_PHYS(start_pfn),
92+
PFN_PHYS(start_pfn + nr_pages),
93+
FLUSH_CHUNK_SIZE);
6594
}
6695

6796
static u64 memtrace_alloc_node(u32 nid, u64 size)

0 commit comments

Comments
 (0)