Re: [PATCH] LoongArch: Update the flush cache policy

From: Xi Ruoyao
Date: Tue May 07 2024 - 03:48:21 EST


On Tue, 2024-05-07 at 14:38 +0800, lijun wrote:
> I guess, final the value of addr is not important, just all of addr must
> read once is very important,
>
> so use two 'for()' and 'volatile' to flush all of addr  's cache,
> exactly as the name of the function is
>
> "flush_cache_last_level".

AFAIK do a read does not mean flushing the cache. The cacop instruction
is intended to do the cache flushing.

So why the cacop instruction in flush_cache_leaf is not enough to flush
it? Is there something wrong in flush_cache_leaf? It currently reads:

static void flush_cache_leaf(unsigned int leaf)
{
int i, j, nr_nodes;
uint64_t addr = CSR_DMW0_BASE;
struct cache_desc *cdesc = current_cpu_data.cache_leaves + leaf;

nr_nodes = cache_private(cdesc) ? 1 : loongson_sysconf.nr_nodes;

do {
for (i = 0; i < cdesc->sets; i++) {
for (j = 0; j < cdesc->ways; j++) {
flush_cache_line(leaf, addr);
addr++;
}

addr -= cdesc->ways;
addr += cdesc->linesz;
}
addr += (1ULL << NODE_ADDRSPACE_SHIFT);
} while (--nr_nodes > 0);
}

There is something bizarre: the flush_cache_line function uses the cacop
instruction in the Index Invalidate / Invalidate and Writeback mode, and
if I read the LoongArch manual correctly in this mode CSR_DMW0_BASE and
1ULL << NODE_ADDRSPACE_SHIFT are just ignored.

Is this something undocumented or flush_cache_leaf is just "incorrect"?

--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University