[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] xen/riscv: update defintion of vmap_to_mfn()



commit 814d24a572242246bf767710c83d2a26ae6f43b9
Author:     Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
AuthorDate: Tue Feb 25 08:47:12 2025 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Feb 25 08:47:12 2025 +0100

    xen/riscv: update defintion of vmap_to_mfn()
    
    vmap_to_mfn() uses virt_to_maddr(), which is designed to work with VA from
    either the direct map region or Xen's linkage region (XEN_VIRT_START).
    An assertion will occur if it is used with other regions, in particular for
    the VMAP region.
    
    Since RISC-V lacks a hardware feature to request the MMU to translate a VA 
to
    a PA (as Arm does, for example), software page table walking (pt_walk()) is
    used for the VMAP region to obtain the mfn from pte_t.
    
    To avoid introduce a circular dependency between asm/mm.h and asm/page.h by
    including each other, the static inline function  _vmap_to_mfn() is 
introduced
    in asm/page.h, as it uses struct pte_t and pte_is_mapping() from asm/page.h.
    _vmap_to_mfn() is then reused in the definition of vmap_to_mfn() macro in
    asm/mm.h.
    
    Fixes: 7db8d2bd9b ("xen/riscv: add minimal stuff to mm.h to build full Xen")
    Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/riscv/include/asm/mm.h   | 2 +-
 xen/arch/riscv/include/asm/page.h | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h
index 292aa48fc1..4035cd400a 100644
--- a/xen/arch/riscv/include/asm/mm.h
+++ b/xen/arch/riscv/include/asm/mm.h
@@ -23,7 +23,7 @@ extern vaddr_t directmap_virt_start;
 #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)     maddr_to_mfn(virt_to_maddr((vaddr_t)(va)))
+#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)
diff --git a/xen/arch/riscv/include/asm/page.h 
b/xen/arch/riscv/include/asm/page.h
index 0439a1a9ee..bf8988f657 100644
--- a/xen/arch/riscv/include/asm/page.h
+++ b/xen/arch/riscv/include/asm/page.h
@@ -210,6 +210,15 @@ static inline pte_t pte_from_mfn(mfn_t mfn, unsigned int 
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 */
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.