Skip to content

Commit 5c20a3a

Browse files
jones-drewavpatel
authored andcommitted
RISC-V: Fix compilation without RISCV_ISA_ZICBOM
riscv_cbom_block_size and riscv_init_cbom_blocksize() should always be available and riscv_init_cbom_blocksize() should always be invoked, even when compiling without RISCV_ISA_ZICBOM enabled. This is because disabling RISCV_ISA_ZICBOM means "don't use zicbom instructions in the kernel" not "pretend there isn't zicbom, even when there is". When zicbom is available, whether the kernel enables its use with RISCV_ISA_ZICBOM or not, KVM will offer it to guests. Ensure we can build KVM and that the block size is initialized even when compiling without RISCV_ISA_ZICBOM. Fixes: 8f7e001 ("RISC-V: Clean up the Zicbom block size probing") Reported-by: kernel test robot <[email protected]> Signed-off-by: Andrew Jones <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Heiko Stuebner <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent 9abf231 commit 5c20a3a

File tree

3 files changed

+38
-49
lines changed

3 files changed

+38
-49
lines changed

arch/riscv/include/asm/cacheflush.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,8 @@ void flush_icache_mm(struct mm_struct *mm, bool local);
4242

4343
#endif /* CONFIG_SMP */
4444

45-
/*
46-
* The T-Head CMO errata internally probe the CBOM block size, but otherwise
47-
* don't depend on Zicbom.
48-
*/
4945
extern unsigned int riscv_cbom_block_size;
50-
#ifdef CONFIG_RISCV_ISA_ZICBOM
5146
void riscv_init_cbom_blocksize(void);
52-
#else
53-
static inline void riscv_init_cbom_blocksize(void) { }
54-
#endif
5547

5648
#ifdef CONFIG_RISCV_DMA_NONCOHERENT
5749
void riscv_noncoherent_supported(void);

arch/riscv/mm/cacheflush.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2017 SiFive
44
*/
55

6+
#include <linux/of.h>
67
#include <asm/cacheflush.h>
78

89
#ifdef CONFIG_SMP
@@ -86,3 +87,40 @@ void flush_icache_pte(pte_t pte)
8687
flush_icache_all();
8788
}
8889
#endif /* CONFIG_MMU */
90+
91+
unsigned int riscv_cbom_block_size;
92+
EXPORT_SYMBOL_GPL(riscv_cbom_block_size);
93+
94+
void riscv_init_cbom_blocksize(void)
95+
{
96+
struct device_node *node;
97+
unsigned long cbom_hartid;
98+
u32 val, probed_block_size;
99+
int ret;
100+
101+
probed_block_size = 0;
102+
for_each_of_cpu_node(node) {
103+
unsigned long hartid;
104+
105+
ret = riscv_of_processor_hartid(node, &hartid);
106+
if (ret)
107+
continue;
108+
109+
/* set block-size for cbom extension if available */
110+
ret = of_property_read_u32(node, "riscv,cbom-block-size", &val);
111+
if (ret)
112+
continue;
113+
114+
if (!probed_block_size) {
115+
probed_block_size = val;
116+
cbom_hartid = hartid;
117+
} else {
118+
if (probed_block_size != val)
119+
pr_warn("cbom-block-size mismatched between harts %lu and %lu\n",
120+
cbom_hartid, hartid);
121+
}
122+
}
123+
124+
if (probed_block_size)
125+
riscv_cbom_block_size = probed_block_size;
126+
}

arch/riscv/mm/dma-noncoherent.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88
#include <linux/dma-direct.h>
99
#include <linux/dma-map-ops.h>
1010
#include <linux/mm.h>
11-
#include <linux/of.h>
12-
#include <linux/of_device.h>
1311
#include <asm/cacheflush.h>
1412

15-
unsigned int riscv_cbom_block_size;
16-
EXPORT_SYMBOL_GPL(riscv_cbom_block_size);
17-
1813
static bool noncoherent_supported;
1914

2015
void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
@@ -77,42 +72,6 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
7772
dev->dma_coherent = coherent;
7873
}
7974

80-
#ifdef CONFIG_RISCV_ISA_ZICBOM
81-
void riscv_init_cbom_blocksize(void)
82-
{
83-
struct device_node *node;
84-
unsigned long cbom_hartid;
85-
u32 val, probed_block_size;
86-
int ret;
87-
88-
probed_block_size = 0;
89-
for_each_of_cpu_node(node) {
90-
unsigned long hartid;
91-
92-
ret = riscv_of_processor_hartid(node, &hartid);
93-
if (ret)
94-
continue;
95-
96-
/* set block-size for cbom extension if available */
97-
ret = of_property_read_u32(node, "riscv,cbom-block-size", &val);
98-
if (ret)
99-
continue;
100-
101-
if (!probed_block_size) {
102-
probed_block_size = val;
103-
cbom_hartid = hartid;
104-
} else {
105-
if (probed_block_size != val)
106-
pr_warn("cbom-block-size mismatched between harts %lu and %lu\n",
107-
cbom_hartid, hartid);
108-
}
109-
}
110-
111-
if (probed_block_size)
112-
riscv_cbom_block_size = probed_block_size;
113-
}
114-
#endif
115-
11675
void riscv_noncoherent_supported(void)
11776
{
11877
WARN(!riscv_cbom_block_size,

0 commit comments

Comments
 (0)