[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] xen/riscv: rework asm/mm.h and asm/page.h includes to match other architectures
commit 17104a7462bb0bffd9105f517b2b93bfc213e749 Author: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx> AuthorDate: Mon Jun 16 10:14:59 2025 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Mon Jun 16 10:14:59 2025 +0200 xen/riscv: rework asm/mm.h and asm/page.h includes to match other architectures To align with other architectures where <asm/page.h> is included from <asm/mm.h> (and not the other way around), the following changes are made: - Since <asm/mm.h> is no longer included in <asm/page.h>: - Move the definitions of paddr_to_pte() and pte_to_paddr() to <asm/mm.h>, as paddr_to_pfn() and pte_to_paddr() are already defined there. - Move _vmap_to_mfn() to <asm/mm.h> because mfn_from_pte() is defined there and open-code it inside macros vmap_to_mfn(). - Drop the inclusion of <xen/domain_page.h> from <asm/page.h> to resolve a compilation error: ./include/xen/domain_page.h:63:12: error: implicit declaration of function '__mfn_to_virt'; did you mean 'mfn_to_nid'? [-Werror=implicit-function-declaration] 63 | return __mfn_to_virt(mfn_x(mfn)); This happens because __mfn_to_virt() is defined in <asm/mm.h>, but due to the current include chain: <xen/domain.h> <asm/domain.h> <xen/mm.h> <asm/mm.h> <asm/page.h> <xen/domain_page.h> static inline void *map_domain_page_global(mfn_t mfn) { return __mfn_to_virt(mfn_x(mfn)); } ... ... #define __mfn_to_virt() ... This leads to a circular dependency and the build error above. As a result, since <xen/domain_page.h> is no longer included in <asm/page.h>, the flush_page_to_ram() definition cannot remain there. It is now moved to riscv/mm.c. Including <asm/page.h> from <asm/mm.h> does not cause issues with the declaration/definition of clear_page() when <xen/mm.h> is included, and also prevents build errors such as: common/domain.c: In function 'alloc_domain_struct': common/domain.c:797:5: error: implicit declaration of function 'clear_page';did you mean 'steal_page'? [-Werror=implicit-function-declaration] 797 | clear_page(d); | ^~~~~~~~~~ | steal_page caused by using clear_page() in common/domain.c. Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx> Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- xen/arch/riscv/include/asm/mm.h | 24 +++++++++++++++++++++--- xen/arch/riscv/include/asm/page.h | 35 +---------------------------------- xen/arch/riscv/mm.c | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h index 01bbd92a06..9283616c02 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -12,6 +12,7 @@ #include <xen/sections.h> #include <xen/types.h> +#include <asm/page.h> #include <asm/page-bits.h> extern vaddr_t directmap_virt_start; @@ -19,11 +20,21 @@ extern vaddr_t directmap_virt_start; #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT) #define paddr_to_pfn(pa) ((unsigned long)((pa) >> PAGE_SHIFT)) +static inline pte_t paddr_to_pte(paddr_t paddr, + unsigned int permissions) +{ + return (pte_t) { .pte = (paddr_to_pfn(paddr) << PTE_PPN_SHIFT) | permissions }; +} + +static inline paddr_t pte_to_paddr(pte_t pte) +{ + return pfn_to_paddr(pte.pte >> PTE_PPN_SHIFT); +} + #define gfn_to_gaddr(gfn) pfn_to_paddr(gfn_x(gfn)) #define gaddr_to_gfn(ga) _gfn(paddr_to_pfn(ga)) #define mfn_to_maddr(mfn) pfn_to_paddr(mfn_x(mfn)) #define maddr_to_mfn(ma) _mfn(paddr_to_pfn(ma)) -#define vmap_to_mfn(va) _vmap_to_mfn((vaddr_t)(va)) #define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va)) static inline void *maddr_to_virt(paddr_t ma) @@ -35,6 +46,15 @@ static inline void *maddr_to_virt(paddr_t ma) return (void *)va; } +#define mfn_from_pte(pte) maddr_to_mfn(pte_to_paddr(pte)) + +#define vmap_to_mfn(va) \ +({ \ + pte_t __entry = pt_walk((vaddr_t)(va), NULL); \ + BUG_ON(!pte_is_mapping(__entry)); \ + maddr_to_mfn(pte_to_paddr(__entry)); \ +}) + /* * virt_to_maddr() is expected to work with virtual addresses from either * the directmap region or Xen's linkage (XEN_VIRT_START) region. @@ -76,8 +96,6 @@ static inline unsigned long virt_to_maddr(unsigned long va) #define virt_to_mfn(va) __virt_to_mfn(va) #define mfn_to_virt(mfn) __mfn_to_virt(mfn) -#define mfn_from_pte(pte) maddr_to_mfn(pte_to_paddr(pte)) - struct page_info { /* Each frame can be threaded onto a doubly-linked list. */ diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm/page.h index 4cb0179648..0684229790 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -7,12 +7,10 @@ #include <xen/bug.h> #include <xen/const.h> -#include <xen/domain_page.h> #include <xen/errno.h> #include <xen/types.h> #include <asm/atomic.h> -#include <asm/mm.h> #include <asm/page-bits.h> #define VPN_MASK (PAGETABLE_ENTRIES - 1UL) @@ -114,17 +112,6 @@ typedef struct { #endif } pte_t; -static inline pte_t paddr_to_pte(paddr_t paddr, - unsigned int permissions) -{ - return (pte_t) { .pte = (paddr_to_pfn(paddr) << PTE_PPN_SHIFT) | permissions }; -} - -static inline paddr_t pte_to_paddr(pte_t pte) -{ - return pfn_to_paddr(pte.pte >> PTE_PPN_SHIFT); -} - static inline bool pte_is_valid(pte_t p) { return p.pte & PTE_VALID; @@ -198,18 +185,7 @@ static inline void invalidate_icache(void) #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) #define copy_page(dp, sp) memcpy(dp, sp, PAGE_SIZE) -static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) -{ - const void *v = map_domain_page(_mfn(mfn)); - - if ( clean_and_invalidate_dcache_va_range(v, PAGE_SIZE) ) - BUG(); - - unmap_domain_page(v); - - if ( sync_icache ) - invalidate_icache(); -} +void flush_page_to_ram(unsigned long mfn, bool sync_icache); /* Write a pagetable entry. */ static inline void write_pte(pte_t *p, pte_t pte) @@ -231,15 +207,6 @@ static inline pte_t pte_from_mfn(mfn_t mfn, pte_attr_t flags) pte_t pt_walk(vaddr_t va, unsigned int *pte_level); -static inline mfn_t _vmap_to_mfn(vaddr_t va) -{ - pte_t entry = pt_walk(va, NULL); - - BUG_ON(!pte_is_mapping(entry)); - - return mfn_from_pte(entry); -} - #endif /* __ASSEMBLY__ */ #endif /* ASM__RISCV__PAGE_H */ diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index 4047d67c0e..774ea42f2d 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -3,6 +3,7 @@ #include <xen/bootfdt.h> #include <xen/bug.h> #include <xen/compiler.h> +#include <xen/domain_page.h> #include <xen/init.h> #include <xen/kernel.h> #include <xen/libfdt/libfdt.h> @@ -613,3 +614,16 @@ void __iomem *ioremap(paddr_t pa, size_t len) { return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); } + +void flush_page_to_ram(unsigned long mfn, bool sync_icache) +{ + const void *v = map_domain_page(_mfn(mfn)); + + if ( clean_and_invalidate_dcache_va_range(v, PAGE_SIZE) ) + BUG(); + + unmap_domain_page(v); + + if ( sync_icache ) + invalidate_icache(); +} -- generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |