|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v3 5/9] xen/riscv: introduce asm/pmap.h header
Introduces arch_pmap_{un}map functions and select HAS_PMAP
for CONFIG_RISCV.
Additionaly it was necessary to introduce functions:
- mfn_from_xen_entry
- mfn_to_pte
Also flush_xen_tlb_range_va_local() and flush_xen_tlb_one_local()
are introduced and use in arch_pmap_unmap().
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
Changes in V3:
- rename argument of function mfn_to_xen_entry(..., attr -> flags ).
- update the code of mfn_to_xen_entry() to use flags argument.
- add blank in mfn_from_pte() in return line.
- introduce flush_xen_tlb_range_va_local() and use it inside
arch_pmap_{un}map().
- s/__ASM_PMAP_H__/ASM_PMAP_H
- add SPDX-License-Identifier: GPL-2.0
---
xen/arch/riscv/Kconfig | 1 +
xen/arch/riscv/include/asm/flushtlb.h | 22 ++++++++++++++++++
xen/arch/riscv/include/asm/page.h | 2 ++
xen/arch/riscv/include/asm/pmap.h | 33 +++++++++++++++++++++++++++
xen/arch/riscv/mm.c | 15 ++++++++++++
5 files changed, 73 insertions(+)
create mode 100644 xen/arch/riscv/include/asm/pmap.h
diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig
index 259eea8d3b..0112aa8778 100644
--- a/xen/arch/riscv/Kconfig
+++ b/xen/arch/riscv/Kconfig
@@ -3,6 +3,7 @@ config RISCV
select FUNCTION_ALIGNMENT_16B
select GENERIC_BUG_FRAME
select HAS_DEVICE_TREE
+ select HAS_PMAP
config RISCV_64
def_bool y
diff --git a/xen/arch/riscv/include/asm/flushtlb.h
b/xen/arch/riscv/include/asm/flushtlb.h
index 7ce32bea0b..cf66e90773 100644
--- a/xen/arch/riscv/include/asm/flushtlb.h
+++ b/xen/arch/riscv/include/asm/flushtlb.h
@@ -5,6 +5,28 @@
#include <xen/bug.h>
#include <xen/cpumask.h>
+/* Flush TLB of local processor for address va. */
+static inline void flush_xen_tlb_one_local(vaddr_t va)
+{
+ asm volatile ( "sfence.vma %0" :: "r" (va) : "memory" );
+}
+
+/*
+ * Flush a range of VA's hypervisor mappings from the TLB of the local
+ * processor.
+ */
+static inline void flush_xen_tlb_range_va_local(vaddr_t va,
+ unsigned long size)
+{
+ vaddr_t end = va + size;
+
+ while ( va < end )
+ {
+ flush_xen_tlb_one_local(va);
+ va += PAGE_SIZE;
+ }
+}
+
/*
* Filter the given set of CPUs, removing those that definitely flushed their
* TLB since @page_timestamp.
diff --git a/xen/arch/riscv/include/asm/page.h
b/xen/arch/riscv/include/asm/page.h
index 0cc2f37cf8..2308cefb0a 100644
--- a/xen/arch/riscv/include/asm/page.h
+++ b/xen/arch/riscv/include/asm/page.h
@@ -52,6 +52,8 @@ typedef struct {
#endif
} pte_t;
+pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int access_bits);
+
static inline pte_t paddr_to_pte(paddr_t paddr,
unsigned int permissions)
{
diff --git a/xen/arch/riscv/include/asm/pmap.h
b/xen/arch/riscv/include/asm/pmap.h
new file mode 100644
index 0000000000..068d0794b1
--- /dev/null
+++ b/xen/arch/riscv/include/asm/pmap.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ASM_PMAP_H
+#define ASM_PMAP_H
+
+#include <xen/bug.h>
+#include <xen/mm.h>
+#include <xen/page-size.h>
+
+#include <asm/fixmap.h>
+#include <asm/flushtlb.h>
+#include <asm/system.h>
+
+static inline void arch_pmap_map(unsigned int slot, mfn_t mfn)
+{
+ pte_t *entry = &xen_fixmap[slot];
+ pte_t pte;
+
+ ASSERT(!pte_is_valid(*entry));
+
+ pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW);
+ write_pte(entry, pte);
+}
+
+static inline void arch_pmap_unmap(unsigned int slot)
+{
+ pte_t pte = {};
+
+ write_pte(&xen_fixmap[slot], pte);
+
+ flush_xen_tlb_range_va_local(FIXMAP_ADDR(slot), PAGE_SIZE);
+}
+
+#endif /* ASM_PMAP_H */
diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c
index 35724505ec..959b6fc63e 100644
--- a/xen/arch/riscv/mm.c
+++ b/xen/arch/riscv/mm.c
@@ -382,3 +382,18 @@ int map_pages_to_xen(unsigned long virt,
BUG_ON("unimplemented");
return -1;
}
+
+static inline pte_t mfn_from_pte(mfn_t mfn)
+{
+ unsigned long pte = mfn_x(mfn) << PTE_PPN_SHIFT;
+ return (pte_t){ .pte = pte };
+}
+
+inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int access_bits)
+{
+ pte_t pte = mfn_from_pte(mfn);
+
+ pte.pte |= access_bits;
+
+ return pte;
+}
--
2.45.2
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |