mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
Patch series "Add and use memdesc_flags_t". At some point struct page will be separated from struct slab and struct folio. This is a step towards that by introducing a type for the 'flags' word of all three structures. This gives us a certain amount of type safety by establishing that some of these unsigned longs are different from other unsigned longs in that they contain things like node ID, section number and zone number in the upper bits. That lets us have functions that can be easily called by anyone who has a slab, folio or page (but not easily by anyone else) to get the node or zone. There's going to be some unusual merge problems with this as some odd bits of the kernel decide they want to print out the flags value or something similar by writing page->flags and now they'll need to write page->flags.f instead. That's most of the churn here. Maybe we should be removing these things from the debug output? This patch (of 11): Wrap the unsigned long flags in a typedef. In upcoming patches, this will provide a strong hint that you can't just pass a random unsigned long to functions which take this as an argument. [willy@infradead.org: s/flags/flags.f/ in several architectures] Link: https://lkml.kernel.org/r/aKMgPRLD-WnkPxYm@casper.infradead.org [nicola.vetrini@gmail.com: mips: fix compilation error] Link: https://lore.kernel.org/lkml/CA+G9fYvkpmqGr6wjBNHY=dRp71PLCoi2341JxOudi60yqaeUdg@mail.gmail.com/ Link: https://lkml.kernel.org/r/20250825214245.1838158-1-nicola.vetrini@gmail.com Link: https://lkml.kernel.org/r/20250805172307.1302730-1-willy@infradead.org Link: https://lkml.kernel.org/r/20250805172307.1302730-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Acked-by: Zi Yan <ziy@nvidia.com> Cc: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
100 lines
2.5 KiB
C
100 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* OpenRISC cache.c
|
|
*
|
|
* Linux architectural port borrowing liberally from similar works of
|
|
* others. All original copyrights apply as per the original source
|
|
* declaration.
|
|
*
|
|
* Modifications for the OpenRISC architecture:
|
|
* Copyright (C) 2015 Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de>
|
|
*/
|
|
|
|
#include <asm/spr.h>
|
|
#include <asm/spr_defs.h>
|
|
#include <asm/cache.h>
|
|
#include <asm/cacheflush.h>
|
|
#include <asm/cpuinfo.h>
|
|
#include <asm/tlbflush.h>
|
|
|
|
/*
|
|
* Check if the cache component exists.
|
|
*/
|
|
bool cpu_cache_is_present(const unsigned int cache_type)
|
|
{
|
|
unsigned long upr = mfspr(SPR_UPR);
|
|
unsigned long mask = SPR_UPR_UP | cache_type;
|
|
|
|
return !((upr & mask) ^ mask);
|
|
}
|
|
|
|
static __always_inline void cache_loop(unsigned long paddr, unsigned long end,
|
|
const unsigned short reg, const unsigned int cache_type)
|
|
{
|
|
if (!cpu_cache_is_present(cache_type))
|
|
return;
|
|
|
|
while (paddr < end) {
|
|
mtspr(reg, paddr);
|
|
paddr += L1_CACHE_BYTES;
|
|
}
|
|
}
|
|
|
|
static __always_inline void cache_loop_page(struct page *page, const unsigned short reg,
|
|
const unsigned int cache_type)
|
|
{
|
|
unsigned long paddr = page_to_pfn(page) << PAGE_SHIFT;
|
|
unsigned long end = paddr + PAGE_SIZE;
|
|
|
|
paddr &= ~(L1_CACHE_BYTES - 1);
|
|
|
|
cache_loop(paddr, end, reg, cache_type);
|
|
}
|
|
|
|
void local_dcache_page_flush(struct page *page)
|
|
{
|
|
cache_loop_page(page, SPR_DCBFR, SPR_UPR_DCP);
|
|
}
|
|
EXPORT_SYMBOL(local_dcache_page_flush);
|
|
|
|
void local_icache_page_inv(struct page *page)
|
|
{
|
|
cache_loop_page(page, SPR_ICBIR, SPR_UPR_ICP);
|
|
}
|
|
EXPORT_SYMBOL(local_icache_page_inv);
|
|
|
|
void local_dcache_range_flush(unsigned long start, unsigned long end)
|
|
{
|
|
cache_loop(start, end, SPR_DCBFR, SPR_UPR_DCP);
|
|
}
|
|
|
|
void local_dcache_range_inv(unsigned long start, unsigned long end)
|
|
{
|
|
cache_loop(start, end, SPR_DCBIR, SPR_UPR_DCP);
|
|
}
|
|
|
|
void local_icache_range_inv(unsigned long start, unsigned long end)
|
|
{
|
|
cache_loop(start, end, SPR_ICBIR, SPR_UPR_ICP);
|
|
}
|
|
|
|
void update_cache(struct vm_area_struct *vma, unsigned long address,
|
|
pte_t *pte)
|
|
{
|
|
unsigned long pfn = pte_val(*pte) >> PAGE_SHIFT;
|
|
struct folio *folio = page_folio(pfn_to_page(pfn));
|
|
int dirty = !test_and_set_bit(PG_dc_clean, &folio->flags.f);
|
|
|
|
/*
|
|
* Since icaches do not snoop for updated data on OpenRISC, we
|
|
* must write back and invalidate any dirty pages manually. We
|
|
* can skip data pages, since they will not end up in icaches.
|
|
*/
|
|
if ((vma->vm_flags & VM_EXEC) && dirty) {
|
|
unsigned int nr = folio_nr_pages(folio);
|
|
|
|
while (nr--)
|
|
sync_icache_dcache(folio_page(folio, nr));
|
|
}
|
|
}
|