Enable build of full Xen for RISC-V
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
In reply to Jan BeulichQuoted 43 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message??? (yet again)
Quoted 19 lines
xen/arch/riscv/include/asm/mm.h +0
-0@@ -3,8 +3,251 @@ #ifndef _ASM_RISCV_MM_H #define _ASM_RISCV_MM_Hxen/arch/riscv/include/asm/mm.h +5
-0+#include <public/xen.h> +#include <xen/pdx.h> +#include <xen/types.h> + +#include <asm/page.h> #include <
asm/page-bits.h>xen/arch/riscv/include/asm/mm.h +6
-0+#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#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)Quoted 2 lines
maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va))
Everything you have above ...
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#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)maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va))
... appears a 2nd time right afterwards.
Quoted 14 lines
Quoted 9 lines
xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_maddr (va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) +#define maddr_to_virt (pa) ((void *)((paddr_t)(pa) |
DIRECTMAP_VIRT_START))xen/arch/riscv/include/asm/mm.h +2
-0+ +/* Convert between Xen-heap virtual addresses and machine frame numbers. */
xen/arch/riscv/include/asm/mm.h +2
-0+#define __virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __mfn_to_virt (mfn) maddr_to_virt((paddr_t)(mfn) <<
PAGE_SHIFT)These would imo better use
maddr_to_mfn()andmfn_to_maddr(), rather than
kind of open-coding them. The former could also usePFN_DOWN()as an alternative.
We can't to as __virt_to_mfn() when is used it is usually wrapped by _mfn() which expect to have unsigned long as an argument.
Quoted 14 lines
Quoted 14 lines
+/* Convert between Xen-heap virtual addresses and page-info structures. */
xen/arch/riscv/include/asm/mm.h +8
-0+static inline struct page_info *virt_to_page (const void *v) +{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored version
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h line 48
Quoted 4 lines
+ * remain intact.
+ */xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn)Is this really still needed? Would be pretty nice if in a new port we could get to start cleanly right away (i.e. by not needing per-file overrides, but using type-safe expansions here right away).
We still need __virt_to_mfn and __mfn_to_virt as common code use them:
* xen/common/xenoprof.c:24:#define virt_to_mfn(va)
mfn(__virt_to_mfn(va))
* xen/include/xen/domain_page.h:59:#define domain_page_map_to_mfn(ptr)_mfn(__virt_to_mfn((unsigned long)(ptr)))
~ Oleksii
Quoted 271 lines
Quoted 35 lines
xen/arch/riscv/include/asm/mm.h +11
-0+struct page_info +{ + /* Each frame can be threaded onto a doubly-linked list. */ + struct page_list_entry list; + + /* Reference count and various PGC_xxx flags and fields. */ + unsigned long count_info; + + /* Context-dependent fields follow... */ + union { + /* Page is in use: ((count_info & PGC_count_mask) != 0).*/
+ struct {
+ /* Type reference count and variousPGT_xxxflags and fields. */
+ unsigned longtype_info;
+ } inuse;
+ /* Page is on a free list: ((count_info&PGC_count_mask) == 0). */
+ union {
+ struct {
+ /*
+ * Index of the first *possibly* unscrubbed page in the buddy.
+ * One more bit than maximum possible order to accommodate
+ *INVALID_DIRTY_IDX.
+ */xen/arch/riscv/include/asm/mm.h +4
-0+#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1) + unsigned long first_dirty:MAX_ORDER + 1; + + /* Do TLBs need flushing for safety before nextpage use? */
+ bool need_tlbflush:1;xen/arch/riscv/include/asm/mm.h line 86
Quoted 9 lines
xen/arch/riscv/include/asm/mm.h +9
-0+ +#define BUDDY_NOT_SCRUBBING 0 +#define BUDDY_SCRUBBING 1 +#define BUDDY_SCRUB_ABORT 2 + unsigned long scrub_state:2; + }; + + unsigned long val; + } free;Indentation is wrong (and thus misleading) for these two lines.
Quoted 2 lines
+
+ } u;Nit: I don't see the value of the trailing blank line inside the union.
Quoted 2 lines
+ union {
+ /* Page is in use, but not as a shadow. */I question the appicability of "shadow" here.
Quoted 24 lines
+ struct {
+ /* Owner of this page (zero if page is anonymous). */ + struct domain *domain;
+ } inuse;
+
+ /* Page is on a free list. */
+ struct {
+ /* Order-size of the free chunk this page is the head of. */
+ unsigned int order;
+ } free;xen/arch/riscv/include/asm/mm.h +6
-0+ + } v; + + union { + /* +* Timestamp from 'TLB clock', used to avoid extra safety flushes.
+ * Only valid for: a) free pages, and b) pages with zero type count
+ */
+uint32_ttlbflush_timestamp;
+ };
+uint64_tpad;xen/arch/riscv/include/asm/mm.h line 118
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +6
-0+}; + +#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) + +/* PDX of the first page in the frame table. */ +extern unsigned long frametable_base_pdx;From this I conclude memory on RISC-V systems may not start at (or near) 0?
Quoted 49 lines
+/* Convert between machine frame numbers and page-info structures. */
+#define
mfn_to_page(mfn) \
+ (frame_table+ (mfn_to_pdx(mfn)-frametable_base_pdx)) +#define
page_to_mfn(pg) \
+pdx_to_mfn((unsigned long)((pg) - frame_table) + frametable_base_pdx)xen/arch/riscv/include/asm/mm.h +9
-0+ +static inline void *page_to_virt (const struct page_info *pg) +{ + return mfn_to_virt(mfn_x(page_to_mfn(pg))); +} + +/* +* Common code requires get_page_type and put_page_type. +* We don't care about typecounts so we just do the minimum to make it
+ * happy.
+ */
+static inline intget_page_type(struct page_info *page, unsigned long type)xen/arch/riscv/include/asm/mm.h +16
-0+{ + return 1; +} + +static inline void put_page_type (struct page_info *page) +{ +} + +static inline void put_page_and_type (struct page_info *page) +{ + put_page_type(page); + put_page(page); +} + +/* +* RISC-V does not have an M2P, but common code expects a handful of
+ * M2P-related defines and functions. Provide dummy versions of these.
+ */xen/arch/riscv/include/asm/mm.h +6
-0+#define INVALID_M2P_ENTRY (~0UL) +#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY) + +/* Xen always owns P2M on RISC-V */ +#define set_gpfn_from_mfn (mfn, pfn) do { (void) (mfn),Quoted 1 line
(void)(pfn); } while (0)
Nit: Stray blank again after cast.
Quoted 1 line
+#define
mfn_to_gfn(d, mfn)((void)(d), _gfn(mfn_x(mfn)))What's the relation of the comment with these two #define-s?
Quoted 35 lines
xen/arch/riscv/include/asm/mm.h +3
-0+#define PDX_GROUP_SHIFT (16 + 5) + +static inline unsigned long domain_get_maximum_gpfn(struct domain*d)
xen/arch/riscv/include/asm/mm.h +6
-0+{ + BUG(); + return 0; +} + +static inline long arch_memory_op(int op,
XEN_GUEST_HANDLE_PARAM(void)arg)xen/arch/riscv/include/asm/mm.h +10
-0+{ + BUG(); + return 0; +} + +/* +* On RISCV, all the RAM is currently direct mapped in Xen. +* Hence return always true. +*/ +static inline bool arch_mfns_in_directmap(unsigned long mfn,unsigned long nr)
xen/arch/riscv/include/asm/mm.h +8
-0+{ + return true; +} + +#define PG_shift (idx) (BITS_PER_LONG - (idx)) +#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) + +#define PGT_none PG_mask(0, 1)/* no special uses of this page */
+#definePGT_writable_pagePG_mask(1, 1)/* has writable mappings? */
+#define PGT_type_maskPG_mask(1, 1)/* Bits 31 or 63. */xen/arch/riscv/include/asm/mm.h line 195
Quoted 4 lines
xen/arch/riscv/include/asm/mm.h +4
-0+ +/* Count of uses of this frame as its current type. */ +#define PGT_count_width PG_shift(2) +#define PGT_count_mask ((1UL<<PGT_count_width)-1)Nit: Style (missing blanks around binary operators). Also a few more times further down.
xen/arch/riscv/include/asm/mm.h line 204
Quoted 9 lines
+/*
+ * Page needs to be scrubbed. Since this bit can only be set on a page that is
+ * free (i.e. inPGC_state_free) we can reusePGC_allocatedbit.
+ */xen/arch/riscv/include/asm/mm.h +4
-0+#define _PGC_need_scrub _PGC_allocated +#define PGC_need_scrub PGC_allocated + +// /* Cleared when the owning guest 'frees' this page. */ Why a commented out comment?
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +9
-0+#define _PGC_allocated PG_shift(1) +#define PGC_allocated PG_mask(1, 1) + /* Page is Xen heap? */ +#define _PGC_xen_heap PG_shift(2) +#define PGC_xen_heap PG_mask(1, 2) +/* Page is broken? */ +#define _PGC_broken PG_shift(7) +#define PGC_broken PG_mask(1, 7) +/* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
Can similar comments in this block please all be similarly indented (or not)?
Quoted 7 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define PGC_state PG_mask(3, 9) +#define PGC_state_inuse PG_mask(0, 9) +#define PGC_state_offlining PG_mask(1, 9) +#define PGC_state_offlined PG_mask(2, 9) +#define PGC_state_free PG_mask(3, 9) +// #define page_state_is(pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
???
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +5
-0+/* Count of references to this frame. */ +#define PGC_count_width PG_shift(9) +#define PGC_count_mask ((1UL<<PGC_count_width)-1) + +#define page_state_is (pg, st) (((pg)->count_info&PGC_state) ==PGC_state_##st)
And here it then "properly" appears?
xen/arch/riscv/include/asm/mm.h line 236
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+#define _PGC_extra PG_shift(10) +#define PGC_extra PG_mask(1, 10) + +#define is_xen_heap_page (page) ((page)->count_info & PGC_xen_heap) +#define is_xen_heap_mfn (mfn) \ + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) + +#define is_xen_fixed_mfn (mfn) \ + ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) && \ + (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1)))Why does
_startneed prefixing wuth & and_endprefixing with a cast? First and foremost both want to be consistent. And then preferably with as little extra clutter as possible.xen/arch/riscv/include/asm/mm.h line 244
Quoted 7 lines
xen/arch/riscv/include/asm/mm.h +7
-0+#define page_get_owner (_p) (_p)->v.inuse.domain +#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d)) + +/* TODO: implement */ +#define mfn_valid (mfn) ({ (void) (mfn); 0; }) + +#define mfn_to_gfn (d, mfn) ((void)(d), _gfn(mfn_x(mfn)))This appeared further up already.
Quoted 1 line
+#define
domain_set_alloc_bitsize(d)((void)0)Better ((void)(d)) ? And then ...
Quoted 1 line
+#define
domain_clamp_alloc_bitsize(d, b)(b)... ((void)(d), (b)) here?
Jan
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 12 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
+/* Convert between Xen-heap virtual addresses and machine frame numbers. */
(quoted diff) +2
-0+#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __mfn_to_virt(mfn) maddr_to_virt((paddr_t)(mfn) <<
PAGE_SHIFT)These would imo better use
maddr_to_mfn()andmfn_to_maddr(), rather than
kind of open-coding them. The former could also usePFN_DOWN()as an alternative.
Quoted 2 lines
We can't to as
__virt_to_mfn()when is used it is usually wrapped by_mfn()which expect to have unsigned long as an argument.
#define __virt_to_mfn(va) mfn_x(maddr_to_mfn(virt_to_maddr(va)) #define __mfn_to_virt(mfn) maddr_to_virt(mfn_to_maddr(_mfn(mfn)))
?
Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
+/* Convert between Xen-heap virtual addresses and page-info structures. */
xen/arch/riscv/include/asm/mm.h +8
-0+static inline struct page_info *virt_to_page (const void *v) +{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored versionQuoted 8 lines
xen/arch/riscv/include/asm/mm.h line 48
Quoted 4 lines
+ * remain intact.
+ */xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn)Is this really still needed? Would be pretty nice if in a new port we could get to start cleanly right away (i.e. by not needing per-file overrides, but using type-safe expansions here right away).
Quoted 3 lines
We still need
__virt_to_mfnand__mfn_to_virtas common code use them:
* xen/common/xenoprof.c:24:#definevirt_to_mfn(va)
mfn(__virt_to_mfn(va))
Are you meaning to enable this code on RISC-V.
Quoted 2 lines
* xen/include/xen/domain_page.h:59:#define
domain_page_map_to_mfn(ptr)_mfn(__virt_to_mfn((unsigned long)(ptr)))
Hmm, yes, we should finally get this sorted. But yeah, not something I want to ask you to do.
Jan
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Oleksii
Quoted 14 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
+/* Convert between Xen-heap virtual addresses and machine frame
numbers. */(quoted diff) +2
-0+#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __mfn_to_virt(mfn) maddr_to_virt((paddr_t)(mfn) <<
PAGE_SHIFT)These would imo better use
maddr_to_mfn()andmfn_to_maddr(), rather
than
kind of open-coding them. The former could also usePFN_DOWN()as an
alternative.
Quoted 8 lines
Quoted 3 lines
We can't to as
__virt_to_mfn()when is used it is usually wrapped by_mfn()which expect to have unsigned long as an argument.#define __virt_to_mfn(va) mfn_x(maddr_to_mfn(virt_to_maddr(va)) #define
__mfn_to_virt(mfn)maddr_to_virt(mfn_to_maddr(_mfn(mfn)))?
I had an issue with the compilation when I tried to define them in similar way.
I'll double check again.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 17 lines
+/* Convert between Xen-heap virtual addresses and page-info structures. */
xen/arch/riscv/include/asm/mm.h +8
-0+static inline struct page_info *virt_to_page (const void *v) +{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored
version
+ * remain intact.
+ */xen/arch/riscv/include/asm/mm.h line 48
Quoted 2 lines
xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn)Is this really still needed? Would be pretty nice if in a new port we
could get to start cleanly right away (i.e. by not needing per- file
overrides, but using type-safe expansions here right away).
Quoted 6 lines
Quoted 4 lines
We still need
__virt_to_mfnand__mfn_to_virtas common code use them:
* xen/common/xenoprof.c:24:#definevirt_to_mfn(va)mfn(__virt_to_mfn(va))Are you meaning to enable this code on RISC-V.
Yes, that is what I meant.
~ Oleksii
Quoted 10 lines
Quoted 4 lines
* xen/include/xen/domain_page.h:59:#define
domain_page_map_to_mfn(ptr)_mfn(__virt_to_mfn((unsigned long)(ptr)))Hmm, yes, we should finally get this sorted. But yeah, not something I want
to ask you to do.Jan
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 28 lines · Oleksii
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Oleksii
Quoted 25 lines · Jan Beulich
Quoted 16 lines · Oleksii Kurochko
+/* Convert between Xen-heap virtual addresses and page-info structures. */
xen/arch/riscv/include/asm/mm.h +8
-0+static inline struct page_info *virt_to_page (const void *v) +{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored
version
+ * remain intact.
+ */xen/arch/riscv/include/asm/mm.h line 48
Quoted 2 lines
xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn)Is this really still needed? Would be pretty nice if in a new port we
could get to start cleanly right away (i.e. by not needing per- file
overrides, but using type-safe expansions here right away).
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
We still need
__virt_to_mfnand__mfn_to_virtas common code use them:
* xen/common/xenoprof.c:24:#definevirt_to_mfn(va)mfn(__virt_to_mfn(va))Are you meaning to enable this code on RISC-V.
Yes, that is what I meant.
And why would you do that? Even Arm doesn't use it, and I'd expect no newer port would care about this very old interface.
Jan
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 38 lines · Jan Beulich
Quoted 37 lines · Oleksii
Quoted 36 lines · Jan Beulich
Quoted 34 lines · Oleksii
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Oleksii Kurochko
+/* Convert between Xen-heap virtual addresses and page- info
structures. */
+static inline structpage_info*virt_to_page(const void *v)xen/arch/riscv/include/asm/mm.h +7
-0+{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored
version
+ * remain intact.
+ */
+#define virt_to_mfn(va)__virt_to_mfn(va)Quoted 8 lines
Quoted 1 line
+#define mfn_to_virt(mfn)
__mfn_to_virt(mfn)Is this really still needed? Would be pretty nice if in a new port we
could get to start cleanly right away (i.e. by not needing per-
file
overrides, but using type-safe expansions here right away).We still need
__virt_to_mfnand__mfn_to_virtas common code use
them:
* xen/common/xenoprof.c:24:#definevirt_to_mfn(va)mfn(__virt_to_mfn(va))
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Are you meaning to enable this code on RISC-V.
Yes, that is what I meant.
And why would you do that? Even Arm doesn't use it, and I'd expect no newer port would care about this very old interface.
Oh, sorry, I read your question wrongly. I am not going to enable that config.
~ Oleksii
PATCH v3 32/34 xen/rirscv: add minimal amount of stubs to build full Xen
In reply to Oleksii Kurochko---
Changes in V3:
- code style fixes.
- update attribute for frametable_base_pdx and frametable_virt_end to __ro_after_init. insteaf of read_mostly.
- use BUG() instead of assert_failed/WARN for newly introduced stubs.
- drop "#include <public/vm_event.h>" in stubs.c and use forward declaration instead.
- drop ack_node() and end_node() as they aren't used now.
---
Changes in V2:
- define udelay stub
- remove 'select HAS_PDX' from RISC-V Kconfig because of
https://lore.kernel.org/xen-devel/[email protected]/
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/early_printk.c | 168 -------------- xen/arch/riscv/mm.c | 52 ++++- xen/arch/riscv/setup.c | 9 +- xen/arch/riscv/stubs.c | 422 ++++++++++++++++++++++++++++++++++ xen/arch/riscv/traps.c | 25 ++ 6 files changed, 507 insertions(+), 170 deletions(-) create mode 100644 xen/arch/riscv/stubs.c
xen/arch/riscv/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-y += mm.o obj-$(CONFIG_RISCV_64) += riscv64/ obj-y += sbi.o obj-y += setup.o +obj-y += stubs.o obj-y += traps.o $(TARGET): $(TARGET)-syms
xen/arch/riscv/early_printk.c +0 -168
171 lines not on this page · raw message
xen/arch/riscv/mm.c +51 -1
73 lines not on this page · raw message
xen/arch/riscv/setup.c +8 -1
@@ -2,9 +2,16 @@#include <xen/compile.h> #include <xen/init.h> +#include <xen/mm.h> + +#include <public/version.h> #include <asm/early_printk.h> -#include <asm/mm.h> + +void arch_get_xen_caps (xen_capabilities_info_t *info) +{ +assert_failed ("need to be implemented" ); +}/* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE ]
xen/arch/riscv/stubs.c new file +422 -0
422 lines not on this page · raw message
xen/arch/riscv/traps.c +25 -0
@@ -4,6 +4,10 @@* * RISC-V Trap handlers */ + +#include <xen/lib.h> +#include <xen/sched.h> +#include <asm/processor.h> #include <asm/traps.h>
@@ -11,3 +15,24 @@ void do_trap(struct cpu_user_regs *cpu_regs) {die (); } + +void vcpu_show_execution_state (struct vcpu *v) +{ +assert_failed ("need to be implented" ); +} + +void show_execution_state (const struct cpu_user_regs *regs) +{ +printk ("implement show_execution_state(regs)\n" ); +} + +void arch_hypercall_tasklet_result (struct vcpu *v,long res) +{ +assert_failed ("need to be implented" ); +} + +enum mc_disposition arch_do_multicall_call (struct mc_state *state) +{ +assert_failed ("need to be implented" ); +return mc_continue; +}
Signature · 1 line
2.43.0
Re: [PATCH v3 32/34] xen/rirscv: add minimal amount of stubs to build full Xen
Quoted 164 lines · Oleksii Kurochko
xen/arch/riscv/early_printk.c +0
-158@@ -40,171 +40,3 @@ void early_printk(const char *str) str++; } } - -/* -* The following #if 1 ... #endif should be removed after printk -* and related stuff are ready. -*/ -#if 1 - -#include <xen/stdarg.h> -#include <xen/string.h> - -/** -* strlen - Find the length of a string -* @s: The string to be sized -*/ -size_t (strlen)(const char * s) -{ -const char *sc; - -for (sc = s; *sc !='\0' ; ++sc) -/* nothing */ ; -return sc - s; -} - -/** -* memcpy - Copy one area of memory to another -* @dest: Where to copy to -* @src: Where to copy from -* @count: The size of the area. -* -* You should not use this function to access IO space, use memcpy_toio() -* or memcpy_fromio() instead. -*/ -void *(memcpy)(void *dest,const void *src,size_t count) -{ -char *tmp = (char *) dest, *s = (char *) src; - -while (count--) - *tmp++ = *s++; - -return dest; -} - -int vsnprintf (char * str,size_t size,const char * format,va_list args) -{ -size_t i =0 ;/* Current position in the output string */ -size_t written =0 ;/* Total number of characters written */ -char * dest = str; - -while ( format[i] !='\0' && written < size -1 ) - { -if ( format[i] =='%' ) - { - i++; - -if ( format[i] =='\0' ) -break ; - -if ( format[i] =='%' ) - { -if ( written < size -1 ) - { - dest[written] ='%' ; - written++; - } - i++; -continue ; - } - -/* -* Handle format specifiers. -* For simplicity, only %s and %d are implemented here. -*/ - -if ( format[i] =='s' ) - { - char* arg = va_arg(args, char*); -size_t arglen =strlen (arg); - -size_t remaining = size - written -1 ; - -if ( arglen > remaining ) - arglen = remaining; - -memcpy (dest + written, arg, arglen); - - written += arglen; - i++; - } -else if ( format[i] =='d' ) - { -int arg =va_arg (args, int); - -/* Convert the integer to string representation */ -char numstr[32 ];/* Assumes a maximum of 32 digits */ -int numlen =0 ; -int num = arg; -size_t remaining; - -if ( arg <0 ) - { -if ( written < size -1 ) - { - dest[written] ='-' ; - written++; - } - - num = -arg; - } - -do - { - numstr[numlen] ='0' + num %10 ; - num = num /10 ; - numlen++; - }while ( num >0 ); - -/* Reverse the string */ -for (int j =0 ; j < numlen /2 ; j++) - { -char tmp = numstr[j]; - numstr[j] = numstr[numlen -1 - j]; - numstr[numlen -1 - j] = tmp; - } - - remaining = size - written -1 ; - -if ( numlen > remaining ) - numlen = remaining; - -memcpy (dest + written, numstr, numlen); - - written += numlen; - i++; - } - } -else - { -if ( written < size -1 ) - { - dest[written] = format[i]; - written++; - } - i++; - } - } - -if ( size >0 ) - dest[written] ='\0' ; - -return written; -} - -void printk (const char *format, ...) -{ -static char buf[1024 ]; - -va_list args; -va_start (args, format);
xen/arch/riscv/early_printk.c void early_printk(const char *str) · line 210
Quoted 10 lines
xen/arch/riscv/early_printk.c +0
-10- - (void )vsnprintf (buf,sizeof (buf), format, args); - -early_printk (buf); - - va_end(args); -} - -#endif -
Aren't you transiently breaking the build by removing these here, rather than in the next patch?
Quoted 22 lines
xen/arch/riscv/stubs.c new file +19
-0@@ -0,0 +1,422 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/cpumask.h> +#include <xen/domain.h> +#include <xen/irq.h> +#include <xen/nodemask.h> +#include <xen/time.h> +#include <public/domctl.h> + +#include <asm/current.h> + +/* smpboot.c */ + +cpumask_t cpu_online_map; +cpumask_t cpu_present_map; +cpumask_t cpu_possible_map; + +/* ID of the PCPU we're running on */ +DEFINE_PER_CPU(unsigned int, cpu_id); +/* XXX these seem awfully x86ish... */
xen/arch/riscv/stubs.c line 29
Quoted 10 lines
xen/arch/riscv/stubs.c new file +10
-0+/* representing HT siblings of each logical CPU */ +DEFINE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_sibling_mask); +/* representing HT and core siblings of each logical CPU */ +DEFINE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_core_mask); + +nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } }; + +/* time.c */ + +unsigned long __read_mostly cpu_khz;/* CPU clock frequency in kHz. */
__ro_after_init?
Quoted 45 lines
xen/arch/riscv/stubs.c new file +45
-0+s_time_t get_s_time (void ) +{ +BUG (); +} + +int reprogram_timer (s_time_t timeout) +{ +BUG (); +} + +void send_timer_event (struct vcpu *v) +{ +BUG (); +} + +void domain_set_time_offset (struct domain *d,int64_t time_offset_seconds) +{ +BUG (); +} + +/* shutdown.c */ + +void machine_restart (unsigned int delay_millisecs) +{ +BUG (); +} + +void machine_halt (void ) +{ +BUG (); +} + +/* vm_event.c */ + +struct vm_event_st ; + +void vm_event_fill_regs (struct vm_event_st *req) +{ +BUG (); +} + +void vm_event_set_registers (struct vcpu *v,struct vm_event_st *rsp) +{ +BUG (); +}
xen/arch/riscv/stubs.c line 85
Quoted 10 lines
xen/arch/riscv/stubs.c new file +10
-0+ +void vm_event_monitor_next_interrupt (struct vcpu *v) +{ +/* Not supported on RISCV. */ +} + +void vm_event_reset_vmtrace (struct vcpu *v) +{ +/* Not supported on RISCV. */ +}
Judging from the comments these last two are in their final shape. Wouldn't it make sense to put them in vm_event.c right away then? And then perhaps together with the two stubs?
Yet then - Arm gets away without vm_event_reset_vmtrace()? Can you explain why the same isn't true for RISC-V?
xen/arch/riscv/stubs.c void do_trap(struct cpu_user_regs *cpu_regs) · line 21
Quoted 8 lines
xen/arch/riscv/stubs.c new file +4
-0@@ -11,3 +15,24 @@ void do_trap(struct cpu_user_regs *cpu_regs) {die (); } + +void vcpu_show_execution_state (struct vcpu *v) +{ +assert_failed ("need to be implented" );
Just to mention it again - the expectation is that all instances will use the same "canonical" pattern for identifying yet-to-be-implemented functions.
Jan
Re: [PATCH v3 32/34] xen/rirscv: add minimal amount of stubs to build full Xen
Quoted 175 lines · Jan Beulich
Quoted 174 lines · Oleksii Kurochko
xen/arch/riscv/early_printk.c +0
-30@@ -40,171 +40,3 @@ void early_printk(const char *str) str++; } } - -/* -* The following #if 1 ... #endif should be removed after printk -* and related stuff are ready. -*/ -#if 1 - -#include <xen/stdarg.h> -#include <xen/string.h> - -/** -* strlen - Find the length of a string -* @s: The string to be sized -*/ -size_t (strlen)(const char * s) -{ - const char *sc; - - for (sc = s; *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} - -/** -* memcpy - Copy one area of memory to another -* @dest: Where to copy to -* @src: Where to copy from -* @count: The size of the area. -* -* You should not use this function to access IO space, use
memcpy_toio()
- * ormemcpy_fromio()instead.
- */xen/arch/riscv/early_printk.c +0
-11-void *(memcpy)(void *dest,const void *src,size_t count) -{ - char *tmp = (char *) dest, *s = (char *) src; - - while (count--) - *tmp++ = *s++; - - return dest; -} - -int vsnprintf(char* str, size_t size, const char* format, va_listargs)
xen/arch/riscv/early_printk.c +0
-28-{ - size_t i = 0; /* Current position in the output string */ - size_t written = 0; /* Total number of characters written */ - char* dest = str; - - while ( format[i] != '\0' && written < size - 1 ) - { - if ( format[i] == '%' ) - { - i++; - - if ( format[i] == '\0' ) - break; - - if ( format[i] == '%' ) - { - if ( written < size - 1 ) - { - dest[written] = '%'; - written++; - } - i++; - continue; - } - - /* -* Handle format specifiers. -* For simplicity, only %s and %d are implemented here.
- */xen/arch/riscv/early_printk.c +0
-22- - if ( format[i] == 's' ) - { - char* arg = va_arg(args, char*); - size_t arglen = strlen(arg); - - size_t remaining = size - written - 1; - - if ( arglen > remaining ) - arglen = remaining; - - memcpy(dest + written, arg, arglen); - - written += arglen; - i++; - } - else if ( format[i] == 'd' ) - { - int arg = va_arg(args, int); - - /* Convert the integer to string representation */ - char numstr[32]; /* Assumes a maximum of 32 digits*/
- int numlen = 0;
- int num = arg;
-size_tremaining;xen/arch/riscv/early_printk.c +0
-67- - if ( arg < 0 ) - { - if ( written < size - 1 ) - { - dest[written] = '-'; - written++; - } - - num = -arg; - } - - do - { - numstr[numlen] = '0' + num % 10; - num = num / 10; - numlen++; - } while ( num > 0 ); - - /* Reverse the string */ - for (int j = 0; j < numlen / 2; j++) - { - char tmp = numstr[j]; - numstr[j] = numstr[numlen - 1 - j]; - numstr[numlen - 1 - j] = tmp; - } - - remaining = size - written - 1; - - if ( numlen > remaining ) - numlen = remaining; - - memcpy(dest + written, numstr, numlen); - - written += numlen; - i++; - } - } - else - { - if ( written < size - 1 ) - { - dest[written] = format[i]; - written++; - } - i++; - } - } - - if ( size > 0 ) - dest[written] = '\0'; - - return written; -} - -void printk (const char *format, ...) -{ - static char buf[1024]; - - va_list args; - va_start(args, format); - - (void)vsnprintf(buf, sizeof(buf), format, args); - - early_printk(buf); - - va_end(args);
Quoted 8 lines
xen/arch/riscv/early_printk.c void early_printk(const char *str) · line 210
Quoted 4 lines
xen/arch/riscv/early_printk.c +0
-4-} - -#endif -Aren't you transiently breaking the build by removing these here, rather
than in the next patch?
It should break. I'll double check. If it will, then I'll move these changes in the next patch.
Quoted 28 lines
Quoted 28 lines
xen/arch/riscv/stubs.c new file +24
-0@@ -0,0 +1,422 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/cpumask.h> +#include <xen/domain.h> +#include <xen/irq.h> +#include <xen/nodemask.h> +#include <xen/time.h> +#include <public/domctl.h> + +#include <asm/current.h> + +/* smpboot.c */ + +cpumask_t cpu_online_map; +cpumask_t cpu_present_map; +cpumask_t cpu_possible_map; + +/* ID of the PCPU we're running on */ +DEFINE_PER_CPU(unsigned int, cpu_id); +/* XXX these seem awfully x86ish... */ +/* representing HT siblings of each logical CPU */ +DEFINE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_sibling_mask); +/* representing HT and core siblings of each logical CPU */ +DEFINE_PER_CPU_READ_MOSTLY (cpumask_var_t, cpu_core_mask); +
Quoted 8 lines
Quoted 6 lines
xen/arch/riscv/stubs.c new file +5
-0+nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } }; + +/* time.c */ + +unsigned long __read_mostly cpu_khz; /* CPU clock frequency inkHz. */
__ro_after_init?
Yes, it should be __ro_after_init. Thanks.
Quoted 54 lines
Quoted 54 lines
xen/arch/riscv/stubs.c new file +16
-0+s_time_t get_s_time (void ) +{ + BUG(); +} + +int reprogram_timer (s_time_t timeout) +{ + BUG(); +} + +void send_timer_event (struct vcpu *v) +{ + BUG(); +} + +void domain_set_time_offset(struct domain *d, int64_t
time_offset_seconds)xen/arch/riscv/stubs.c new file +26
-0+{ + BUG(); +} + +/* shutdown.c */ + +void machine_restart (unsigned int delay_millisecs) +{ + BUG(); +} + +void machine_halt (void ) +{ + BUG(); +} + +/* vm_event.c */ + +struct vm_event_st ; + +void vm_event_fill_regs (struct vm_event_st *req) +{ + BUG(); +} + +void vm_event_set_registers(struct vcpu *v, struct vm_event_st*rsp)
xen/arch/riscv/stubs.c new file +9
-0+{ + BUG(); +} + +void vm_event_monitor_next_interrupt (struct vcpu *v) +{ + /* Not supported on RISCV. */ +} +
Quoted 8 lines
xen/arch/riscv/stubs.c line 85
Quoted 4 lines
xen/arch/riscv/stubs.c new file +4
-0+void vm_event_reset_vmtrace (struct vcpu *v) +{ + /* Not supported on RISCV. */ +}Judging from the comments these last two are in their final shape. Wouldn't it make sense to put them in
vm_event.cright away then? And then perhaps together with the two stubs?
Yes, it makes sense.
Quoted 3 lines
Yet then - Arm gets away without
vm_event_reset_vmtrace()? Can you explain why the same isn't true for RISC-V?
It should true and for RISC-V. I'll look at when they gets away vm_event_reset_vmtrace().
Quoted 14 lines
xen/arch/riscv/stubs.c void do_trap(struct cpu_user_regs *cpu_regs) · line 21
Quoted 9 lines
xen/arch/riscv/stubs.c new file +4
-0@@ -11,3 +15,24 @@ void do_trap(struct cpu_user_regs *cpu_regs) { die(); } + +void vcpu_show_execution_state (struct vcpu *v) +{ + assert_failed("need to be implented");Just to mention it again - the expectation is that all instances will use the same "canonical" pattern for identifying yet-to-be- implemented
functions.
Sure, I'll update using BUG_ON("unimplemented");
Thanks for review.
~ Oleksii
PATCH v3 33/34 xen/riscv: enable full Xen build
In reply to Oleksii Kurochko---
Changes in V3:
- Reviewed-by: Jan Beulich <[email protected]>
- unrealted change dropped in tiny64_defconfig
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/Makefile | 16 +++++++++++++++- xen/arch/riscv/arch.mk | 4 ---- 2 files changed, 15 insertions(+), 5 deletions(-)
xen/arch/riscv/Makefile +15 -1
@@ -11,10 +11,24 @@ $(TARGET): $(TARGET)-syms $(OBJCOPY) -O binary -S $< $@ $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds - $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) -o $@ + $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< \ + $(objtree)/common/symbols-dummy.o -o $(dot-target).0 + $(NM) -pa --format=sysv $(dot-target).0 \ + | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \ + > $(dot-target).0.S + $(MAKE) $(build)=$(@D) $(dot-target).0.o + $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< \ + $(dot-target).0.o -o $(dot-target).1 + $(NM) -pa --format=sysv $(dot-target).1 \ + | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \ + > $(dot-target).1.S + $(MAKE) $(build)=$(@D) $(dot-target).1.o + $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \ + $(dot-target).1.o -o $@ $(NM) -pa --format=sysv $@ \ | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ > [email protected] + rm -f $(@D)/.$(@F).[0-9]* $(obj)/xen.lds: $(src)/xen.lds.S FORCE $(call if_changed_dep,cpp_lds_S)
xen/arch/riscv/arch.mk +0 -4
@@ -13,7 +13,3 @@ riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c # -mcmodel=medlow would force Xen into the lower half. CFLAGS += -march=$(riscv-march-y) -mstrict-align -mcmodel=medany - -# TODO: Drop override when more of the build is working -override ALL_OBJS-y = arch/$(SRCARCH)/built_in.o -override ALL_LIBS-y =
Signature · 1 line
2.43.0
PATCH v3 34/34 xen/README: add compiler and binutils versions for RISC-V64
In reply to Oleksii Kurochko---
Changes in V3:
- new patch
--- README | 3 +++ 1 file changed, 3 insertions(+)
README +3 -0
@@ -48,6 +48,9 @@ provided by your OS distributor: - For ARM 64-bit: - GCC 5.1 or later - GNU Binutils 2.24 or later + - For RISC-V 64-bit: + - GCC 13.2.1 or later + - GNU Binutils 2.40 or later * POSIX compatible awk * Development install of zlib (e.g., zlib-dev) * Development install of Python 2.7 or later (e.g., python-dev)
Signature · 1 line
2.43.0
Re: [PATCH v3 34/34] xen/README: add compiler and binutils versions for RISC-V64
Quoted 13 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- new patch--- README | 3 +++ 1 file changed, 3 insertions(+)README +0
-0
README provided by your OS distributor: · line 53
Quoted 6 lines
README +3
-0@@ -48,6 +48,9 @@ provided by your OS distributor: - For ARM 64-bit: - GCC 5.1 or later - GNU Binutils 2.24 or later + - For RISC-V 64-bit: + - GCC 13.2.1 or later + - GNU Binutils 2.40 or later
That's pretty new. For gcc that's even newer than the newest release. If older versions really won't do, I don't think you can leave this unjustified (by having an empty description). Till now gcc 13.2 has served me well, and iirc 13.1, 12.3, and 12.2 were fine, too.
Jan
Re: [PATCH v3 34/34] xen/README: add compiler and binutils versions for RISC-V64
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- new patch
---
README | 3 +++1 file changed, 3 insertions(+)
Quoted 16 lines
Quoted 11 lines
README +0
-0@@ -48,6 +48,9 @@ provided by your OS distributor:- For ARM 64-bit:
- GCC 5.1 or later
- GNU Binutils 2.24 or later
+ - For RISC-V 64-bit:
+ - GCC 13.2.1 or later
+ - GNU Binutils 2.40 or laterThat's pretty new. For gcc that's even newer than the newest release. If older versions really won't do, I don't think you can leave this unjustified (by having an empty description). Till now gcc 13.2 has served me well, and iirc 13.1, 12.3, and 12.2 were fine, too.
It can be 12.2.0 for GCC and 2.39 for GNU Binutils. ( it is toolchain which is used by contrainer for RISC-V in Xen ). I'll update versions then.
But could you please explain again why it can't be 13.2.1 ( it is a version which I have in my distribution, so it is the reason why I used this version in README file ) ?
~ Oleksii
Re: [PATCH v3 34/34] xen/README: add compiler and binutils versions for RISC-V64
Quoted 26 lines · Oleksii
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- new patch
---
README | 3 +++1 file changed, 3 insertions(+)Quoted 16 lines
Quoted 11 lines
README +0
-0@@ -48,6 +48,9 @@ provided by your OS distributor:- For ARM 64-bit:
- GCC 5.1 or later
- GNU Binutils 2.24 or later
+ - For RISC-V 64-bit:
+ - GCC 13.2.1 or later
+ - GNU Binutils 2.40 or laterThat's pretty new. For gcc that's even newer than the newest release. If older versions really won't do, I don't think you can leave this unjustified (by having an empty description). Till now gcc 13.2 has served me well, and iirc 13.1, 12.3, and 12.2 were fine, too.
Quoted 7 lines
It can be 12.2.0 for GCC and 2.39 for GNU Binutils. ( it is toolchain which is used by contrainer for RISC-V in Xen ). I'll update versions then.
But could you please explain again why it can't be 13.2.1 ( it is a version which I have in my distribution, so it is the reason why I used this version in README file ) ?
13.2.1 is a pre-release of 13.3.0. Only versions ending in .0 are upstream released versions these days. And I think it would be helpful if the minimum version also was the first in a major-version series, i.e. I'd generally prefer naming <N>.1.0 (or <N>.1 for simplicity; see Arm's entry). Of course if no such suitable version exists (because of being buggy), then specifying another one is okay. As to x.y.1 - nobody will then really know which version it is, because every distro will ship its own variant.
Jan
Re: [PATCH v3 34/34] xen/README: add compiler and binutils versions for RISC-V64
Quoted 41 lines · Jan Beulich
Quoted 35 lines · Oleksii
Quoted 21 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- new patch
---
README | 3 +++1 file changed, 3 insertions(+)README +0
-0@@ -48,6 +48,9 @@ provided by your OS distributor:Quoted 6 lines
- For ARM 64-bit:
- GCC 5.1 or later
- GNU Binutils 2.24 or later
+ - For RISC-V 64-bit:
+ - GCC 13.2.1 or later
+ - GNU Binutils 2.40 or laterQuoted 7 lines
That's pretty new. For gcc that's even newer than the newest release.
If older versions really won't do, I don't think you can leave this
unjustified (by having an empty description). Till now gcc 13.2 has
served me well, and iirc 13.1, 12.3, and 12.2 were fine, too.It can be 12.2.0 for GCC and 2.39 for GNU Binutils. ( it is toolchain
which is used by contrainer for RISC-V in Xen ). I'll update versions
then.Quoted 4 lines
But could you please explain again why it can't be 13.2.1 ( it is a version which I have in my distribution, so it is the reason why I used
this version in README file ) ?
Quoted 13 lines
13.2.1 is a pre-release of 13.3.0. Only versions ending in .0 are upstream
released versions these days. And I think it would be helpful if the minimum version also was the first in a major-version series, i.e. I'd
generally prefer naming <N>.1.0 (or <N>.1 for simplicity; see Arm's entry).
Of course if no such suitable version exists (because of being buggy), then
specifying another one is okay. As to x.y.1 - nobody will then really know
which version it is, because every distro will ship its own variant.
Thanks for explanation.
I'll drop the last number then.
~ Oleksii