From: Simon Kuenzer Date: Tue, 10 Dec 2024 15:06:22 +0000 (-0800) Subject: plat/xen: Export public API of libxenplat X-Git-Tag: RELEASE-0.18.0~10 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0509e5d075de9c527eb764180b09c8932cc7e9ac;p=unikraft%2Funikraft.git plat/xen: Export public API of libxenplat As part of platform rearch, this commit treats `libxenplat` as a regular driver library that exports an API. Although it is intended that `libxenplat` will be further decomposed into several driver libraries (e.g., CPU, memory), this step avoids that other Xen drivers or services require to cross-include headers and compile definitions from `libxenplat` which were technically defined as platform-internal. Such an approach breaks convention of regular libraries and is typical source of problems that have to do with Makefile processing order and symbol linking errors. As part of platform re-arch, the definition of a platform-internal scope is intended to get removed because it caused confusion and restrictions (e.g., application code was not able to directly access driver APIs that were within platform scope). With this change, the compile flag `CONFIG_PARAVIRT` is name spaced to `XEN_PARAVIRT`, as well. Checkpatch-Ignore: SUSPECT_CODE_INDENT Signed-off-by: Simon Kuenzer Reviewed-by: Oleksii Moisieiev Reviewed-by: Oleksii Moisieiev Reviewed-by: Michalis Pappas Approved-by: Michalis Pappas GitHub-Closes: #1501 --- diff --git a/arch/x86/x86_64/include/uk/asm/paging.h b/arch/x86/x86_64/include/uk/asm/paging.h index 83141d1be..866571e11 100644 --- a/arch/x86/x86_64/include/uk/asm/paging.h +++ b/arch/x86/x86_64/include/uk/asm/paging.h @@ -234,7 +234,7 @@ static inline int ukarch_vaddr_range_isvalid(__vaddr_t start, __sz len) X86_PAT_ENTRY(6, X86_PAT_UCM) | \ X86_PAT_ENTRY(7, X86_PAT_UC)) -#ifndef CONFIG_PARAVIRT +#ifndef XEN_PARAVIRT #ifndef __ASSEMBLY__ static inline int ukarch_pte_read(__vaddr_t pt_vaddr, unsigned int lvl, unsigned int idx, __pte_t *pte) @@ -291,4 +291,4 @@ static inline void ukarch_tlb_flush(void) ukarch_pt_write_base(ukarch_pt_read_base()); } #endif /* !__ASSEMBLY__ */ -#endif /* !CONFIG_PARAVIRT */ +#endif /* !XEN_PARAVIRT */ diff --git a/drivers/xen/9pfront/Makefile.uk b/drivers/xen/9pfront/Makefile.uk index 4d14b4877..9a674bf05 100644 --- a/drivers/xen/9pfront/Makefile.uk +++ b/drivers/xen/9pfront/Makefile.uk @@ -1,7 +1,4 @@ $(eval $(call addlib_s,lib9pfront,$(CONFIG_LIB9PFRONT))) -# FIXME: Extra includes should be removed -LIB9PFRONT_CFLAGS-y += $(LIBXENPLAT_CFLAGS-y) -LIB9PFRONT_CINCLUDES-y += $(LIBXENPLAT_CINCLUDES-y) LIB9PFRONT_SRCS-y += $(LIB9PFRONT_BASE)/9pfront.c LIB9PFRONT_SRCS-y += $(LIB9PFRONT_BASE)/9pfront_xs.c diff --git a/drivers/xen/blkfront/Makefile.uk b/drivers/xen/blkfront/Makefile.uk index d5ee6cee4..18290aa4d 100644 --- a/drivers/xen/blkfront/Makefile.uk +++ b/drivers/xen/blkfront/Makefile.uk @@ -1,7 +1,4 @@ $(eval $(call addlib_s,libblkfront,$(CONFIG_LIBBLKFRONT))) -# FIXME: Extra includes should be removed -LIBBLKFRONT_CFLAGS-y += $(LIBXENPLAT_CFLAGS-y) -LIBBLKFRONT_CINCLUDES-y += $(LIBXENPLAT_CINCLUDES-y) LIBBLKFRONT_SRCS-y += $(LIBBLKFRONT_BASE)/blkfront.c LIBBLKFRONT_SRCS-y += $(LIBBLKFRONT_BASE)/blkfront_xs.c diff --git a/drivers/xen/netfront/Makefile.uk b/drivers/xen/netfront/Makefile.uk index 99ffdaa34..eba408e5e 100644 --- a/drivers/xen/netfront/Makefile.uk +++ b/drivers/xen/netfront/Makefile.uk @@ -1,7 +1,4 @@ $(eval $(call addlib_s,libnetfront,$(CONFIG_LIBNETFRONT))) -# FIXME: Extra includes should be removed -LIBNETFRONT_CFLAGS-y += $(LIBXENPLAT_CFLAGS-y) -LIBNETFRONT_CINCLUDES-y += $(LIBXENPLAT_CINCLUDES-y) LIBNETFRONT_SRCS-y += $(LIBNETFRONT_BASE)/netfront.c LIBNETFRONT_SRCS-y += $(LIBNETFRONT_BASE)/netfront_xs.c diff --git a/drivers/xen/xenbus/Makefile.uk b/drivers/xen/xenbus/Makefile.uk index f7f812662..23bce16f1 100644 --- a/drivers/xen/xenbus/Makefile.uk +++ b/drivers/xen/xenbus/Makefile.uk @@ -1,9 +1,7 @@ $(eval $(call addlib_s,libxenbus,$(CONFIG_LIBXENBUS))) CINCLUDES-$(CONFIG_LIBXENBUS) += -I$(LIBXENBUS_BASE)/include -LIBXENBUS_CINCLUDES-y += $(LIBXENPLAT_CINCLUDES-y) -LIBXENBUS_CFLAGS-y += $(LIBXENPLAT_CFLAGS-y) LIBXENBUS_SRCS-y += $(LIBXENBUS_BASE)/xenbus.c LIBXENBUS_SRCS-y += $(LIBXENBUS_BASE)/client.c LIBXENBUS_SRCS-y += $(LIBXENBUS_BASE)/xs_comms.c diff --git a/drivers/xen/xencons/Makefile.uk b/drivers/xen/xencons/Makefile.uk index df3a3a41d..1bf36ced2 100644 --- a/drivers/xen/xencons/Makefile.uk +++ b/drivers/xen/xencons/Makefile.uk @@ -2,7 +2,4 @@ $(eval $(call addlib_s,libxencons,$(CONFIG_LIBXENCONS))) CINCLUDES-$(CONFIG_LIBXENCONS) += -I$(LIBXENCONS_BASE)/include -# FIXME: Extra includes should be removed -LIBXENCONS_CFLAGS-y += $(LIBXENPLAT_CFLAGS-y) -LIBXENCONS_CINCLUDES-y += $(LIBXENPLAT_CINCLUDES-y) LIBXENCONS_SRCS-y += $(LIBXENCONS_BASE)/console.c|isr diff --git a/drivers/xen/xencons/console.c b/drivers/xen/xencons/console.c index 9f5cafc32..cf27f2b0d 100644 --- a/drivers/xen/xencons/console.c +++ b/drivers/xen/xencons/console.c @@ -267,7 +267,7 @@ static struct uk_console_ops console_ops = { static struct uk_console console_dev; -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT static int hv_console_prepare(struct ukplat_bootinfo *bi __unused) { console_ring = mfn_to_virt(HYPERVISOR_start_info->console.domU.mfn); diff --git a/drivers/xen/xenemgcons/Makefile.uk b/drivers/xen/xenemgcons/Makefile.uk index 3b0127bb3..d2226167b 100644 --- a/drivers/xen/xenemgcons/Makefile.uk +++ b/drivers/xen/xenemgcons/Makefile.uk @@ -1,6 +1,3 @@ $(eval $(call addlib_s,libxenemgcon,$(CONFIG_LIBXENEMGCONS))) -LIBXENEMGCONS_CFLAGS-y += $(LIBXENPLAT_CFLAGS-y) -LIBXENEMGCONS_CINCLUDES-y += $(LIBXENPLAT_CINCLUDES-y) - LIBXENEMGCONS_SRCS-y += $(LIBXENEMGCONS_BASE)/emg_console.c|isr diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk index 45fd600e9..72c857528 100644 --- a/plat/xen/Makefile.uk +++ b/plat/xen/Makefile.uk @@ -14,17 +14,26 @@ $(eval $(call addplatlib_s,xen,libxenpvcalls,$(CONFIG_XEN_PVCALLS))) ## ## Xen platform compilation settings ## -LIBXENPLAT_ASFLAGS-y += -DXENPLAT -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) -LIBXENPLAT_CFLAGS-y += -DXENPLAT -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) -LIBXENPLAT_CXXFLAGS-y += -DXENPLAT -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) +# TODO: For now, we set the Xen interface options here. These options are +# picked up by `libxenheaders` and thereby have an influence on the +# Xen drivers (e.g., XenBus, netfront). +# With the re-structuring of the Xen platform library, we should find a +# a better place for this: probably with a Xen boot/entry driver. +ASFLAGS-$(CONFIG_PLAT_XEN) += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) +CFLAGS-$(CONFIG_PLAT_XEN) += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) +CXXFLAGS-$(CONFIG_PLAT_XEN) += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) +ifeq ($(CONFIG_ARCH_ARM_64), y) +CFLAGS-$(CONFIG_PLAT_XEN) += -DXEN_HAVE_PV_GUEST_ENTRY +endif + +LIBXENPLAT_ASFLAGS-y += -DXENPLAT +LIBXENPLAT_CFLAGS-y += -DXENPLAT +LIBXENPLAT_CXXFLAGS-y += -DXENPLAT LIBXENPLAT_ASFLAGS-y += -DUK_USE_SECTION_SEGMENTS LIBXENPLAT_CFLAGS-y += -DUK_USE_SECTION_SEGMENTS LIBXENPLAT_CXXFLAGS-y += -DUK_USE_SECTION_SEGMENTS -ifeq ($(CONFIG_ARCH_ARM_64), y) -LIBXENPLAT_CFLAGS-y += -DXEN_HAVE_PV_GUEST_ENTRY -endif ## ## Default Linker script ifeq ($(CONFIG_ARCH_X86_64),y) @@ -42,11 +51,16 @@ endif ## ## Platform library definitions ## -LIBXENPLAT_ASINCLUDES-y += -I$(LIBXENPLAT_BASE)/include -LIBXENPLAT_ASINCLUDES-y += -I$(UK_PLAT_COMMON_BASE)/include -LIBXENPLAT_CINCLUDES-y += -I$(LIBXENPLAT_BASE)/include -LIBXENPLAT_CINCLUDES-y += -I$(UK_PLAT_COMMON_BASE)/include -LIBXENPLAT_CINCLUDES-y += -I$(UK_PLAT_DRIVERS_BASE)/include +# TODO: We intend to decompose(re-arch) the `libxenplat` library into +# individual driver libraries (e.g., CPU, memory). With this in place +# we aim a cleaner organization of these headers. +# NOTE: We globally export these header includes because they are currently +# forming the API of `libxenplat`. +ASINCLUDES-$(CONFIG_PLAT_XEN) += -I$(LIBXENPLAT_BASE)/include +ASINCLUDES-$(CONFIG_PLAT_XEN) += -I$(UK_PLAT_COMMON_BASE)/include +CINCLUDES-$(CONFIG_PLAT_XEN) += -I$(LIBXENPLAT_BASE)/include +CINCLUDES-$(CONFIG_PLAT_XEN) += -I$(UK_PLAT_COMMON_BASE)/include +CINCLUDES-$(CONFIG_PLAT_XEN) += -I$(UK_PLAT_DRIVERS_BASE)/include LIBXENPLAT_SRCS-y += $(UK_PLAT_XEN_DEF_LDS) LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/hypervisor.c @@ -70,8 +84,10 @@ LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/arch_events.c LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/arch_time.c ifneq ($(CONFIG_XEN_HVMLITE),y) -LIBXENPLAT_ASFLAGS-y += -DCONFIG_PARAVIRT -LIBXENPLAT_CFLAGS-y += -DCONFIG_PARAVIRT +# NOTE: Compile flag needed for being able to correctly use `libxenplat` +# headers: xen-x86/irq.h, xen-x86/mm.h +ASFLAGS-$(CONFIG_PLAT_XEN) += -DXEN_PARAVIRT +CFLAGS-$(CONFIG_PLAT_XEN) += -DXEN_PARAVIRT LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/cpu_pv.c else LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/cpu_native.c diff --git a/plat/xen/include/xen-x86/irq.h b/plat/xen/include/xen-x86/irq.h index 4b81d4788..0163d1b98 100644 --- a/plat/xen/include/xen-x86/irq.h +++ b/plat/xen/include/xen-x86/irq.h @@ -30,7 +30,7 @@ #ifndef PLAT_XEN_INCLUDE_XEN_X86_IRQ_H_ #define PLAT_XEN_INCLUDE_XEN_X86_IRQ_H_ -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT #include #include diff --git a/plat/xen/include/xen-x86/mm.h b/plat/xen/include/xen-x86/mm.h index 143362451..47b9381ff 100644 --- a/plat/xen/include/xen-x86/mm.h +++ b/plat/xen/include/xen-x86/mm.h @@ -43,7 +43,7 @@ #define CONST(x) x #endif -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT #include #endif @@ -171,7 +171,7 @@ typedef unsigned long paddr_t; typedef unsigned long maddr_t; extern pgentry_t *pt_base; -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT extern unsigned long *phys_to_machine_mapping; #endif diff --git a/plat/xen/x86/entry64.S b/plat/xen/x86/entry64.S index 39b5f6781..f0176aa58 100644 --- a/plat/xen/x86/entry64.S +++ b/plat/xen/x86/entry64.S @@ -45,7 +45,7 @@ 4:.align 4 ; \ .popsection -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "Unikraft") ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic") ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _WORD hypercall_page) @@ -183,7 +183,7 @@ KERNEL_CS_MASK = 0xfc /* Macros */ .macro SAVE_PARAVIRT -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT pop %rcx pop %r11 /* rsp points to the error code */ #endif @@ -255,7 +255,7 @@ ENTRY(ASM_TRAP_SYM(\trapname)) .endm .macro HYPERVISOR_IRET -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT testl $NMI_MASK,2*8(%rsp) jnz 2f @@ -265,7 +265,7 @@ ENTRY(ASM_TRAP_SYM(\trapname)) #endif iretq -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT 2: /* Slow iret via hypervisor. */ andl $~NMI_MASK, 16(%rsp) pushq $0 @@ -288,7 +288,7 @@ error_entry: jmp error_exit -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT /* * Xen event (virtual interrupt) entry point. */ @@ -392,7 +392,7 @@ critical_region_fixup: #endif ENTRY(asm_failsafe_callback) -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT popq %rcx popq %r11 #endif diff --git a/plat/xen/x86/mm.c b/plat/xen/x86/mm.c index e940fbab9..8ebbf370f 100644 --- a/plat/xen/x86/mm.c +++ b/plat/xen/x86/mm.c @@ -46,7 +46,7 @@ #include #include -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT #include unsigned long *phys_to_machine_mapping; #endif @@ -72,7 +72,7 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, { pgentry_t *tab; unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT mmu_update_t mmu_updates[1]; int rc; #endif @@ -87,7 +87,7 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, UK_ASSERT(level >= 1 && level <= PAGETABLE_LEVELS); -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT /* Make PFN a page table page */ tab = pt_base; #if defined(__x86_64__) @@ -126,7 +126,7 @@ void _init_mem_build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn) pgentry_t *tab = pt_base, page; unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base)); unsigned long offset; -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1]; int count = 0; int rc; @@ -136,7 +136,7 @@ void _init_mem_build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn) mapped, start the loop at the very beginning. */ pfn_to_map = *start_pfn; -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT if ( *max_pfn >= virt_to_pfn(HYPERVISOR_VIRT_START) ) { uk_pr_warn("Trying to use Xen virtual space. " @@ -179,7 +179,7 @@ void _init_mem_build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn) pt_mfn = pte_to_mfn(page); tab = to_virt(mfn_to_pfn(pt_mfn) << PAGE_SHIFT); offset = l2_table_offset(start_address); -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT /* Need new L1 pt frame */ if ( !(tab[offset] & _PAGE_PRESENT) ) new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME); @@ -350,7 +350,7 @@ int do_map_frames(unsigned long va, memset(err, 0, n * sizeof(int)); while (mapped < n) { -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT unsigned long i; int rc; unsigned long batched; @@ -480,7 +480,7 @@ void *map_frames_ex(const unsigned long *mfns, unsigned long n, #define UNMAP_BATCH ((STACK_SIZE / 4) / sizeof(multicall_entry_t)) int unmap_frames(unsigned long va, unsigned long num_frames) { -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT unsigned long i, n = UNMAP_BATCH; multicall_entry_t call[n]; int ret; @@ -492,7 +492,7 @@ int unmap_frames(unsigned long va, unsigned long num_frames) (void *) va, num_frames); while (num_frames) { -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT if (n > num_frames) n = num_frames; @@ -543,7 +543,7 @@ void _init_mem_set_readonly(void *text, void *etext) unsigned long mfn; unsigned long offset; unsigned long page_size = PAGE_SIZE; -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1]; int count = 0; int rc; @@ -579,7 +579,7 @@ void _init_mem_set_readonly(void *text, void *etext) if ( start_address != (unsigned long)&_libxenplat_shared_info ) { -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT mmu_updates[count].ptr = ((pgentry_t)mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset; mmu_updates[count].val = tab[offset] & ~_PAGE_RW; @@ -591,7 +591,7 @@ void _init_mem_set_readonly(void *text, void *etext) start_address += page_size; -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT if ( count == L1_PAGETABLE_ENTRIES || start_address + page_size > end_address ) { @@ -603,7 +603,7 @@ void _init_mem_set_readonly(void *text, void *etext) #endif } -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT { mmuext_op_t op = { .cmd = MMUEXT_TLB_FLUSH_ALL, @@ -619,7 +619,7 @@ void _init_mem_set_readonly(void *text, void *etext) */ void _init_mem_clear_bootstrap(void) { -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT pte_t nullpte = { }; int rc; #endif @@ -629,7 +629,7 @@ void _init_mem_clear_bootstrap(void) /* Use first page as the CoW zero page */ memset((void *)__TEXT, 0, PAGE_SIZE); mfn_zero = virt_to_mfn(__TEXT); -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT if ( (rc = HYPERVISOR_update_va_mapping(0, nullpte, UVMF_INVLPG)) ) uk_pr_err("Unable to unmap NULL page. rc=%d\n", rc); #endif @@ -711,7 +711,7 @@ void arch_mm_init(struct uk_alloc *a) void _init_mem_prepare(unsigned long *start_pfn, unsigned long *max_pfn) { -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT phys_to_machine_mapping = (unsigned long *)HYPERVISOR_start_info->mfn_list; pt_base = (pgentry_t *)HYPERVISOR_start_info->pt_base; *start_pfn = PFN_UP(to_phys(pt_base)) + HYPERVISOR_start_info->nr_pt_frames; diff --git a/plat/xen/x86/traps.c b/plat/xen/x86/traps.c index 4c01b2b13..7d944bd9a 100644 --- a/plat/xen/x86/traps.c +++ b/plat/xen/x86/traps.c @@ -35,7 +35,7 @@ DECLARE_TRAP_EC(coproc_seg_overrun, "coprocessor segment overrun", NULL) DECLARE_TRAP (spurious_int, "spurious interrupt bug", NULL) -#ifdef CONFIG_PARAVIRT +#ifdef XEN_PARAVIRT #define TRAP_TABLE_ENTRY(trapname, pl) \ { TRAP_##trapname, pl, __KERNEL_CS, (unsigned long) ASM_TRAP_SYM(trapname) }