CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Wed Apr 22 20:49:08 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: hypervisor.c Log Message: Don't try to attach vcpu on !XENPV remove debug printf and other misc cosmetic changes To generate a diff of this commit: cvs rdiff -u -r1.73.2.8 -r1.73.2.9 src/sys/arch/xen/xen/hypervisor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/hypervisor.c diff -u src/sys/arch/xen/xen/hypervisor.c:1.73.2.8 src/sys/arch/xen/xen/hypervisor.c:1.73.2.9 --- src/sys/arch/xen/xen/hypervisor.c:1.73.2.8 Mon Apr 20 11:29:01 2020 +++ src/sys/arch/xen/xen/hypervisor.c Wed Apr 22 20:49:08 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hypervisor.c,v 1.73.2.8 2020/04/20 11:29:01 bouyer Exp $ */ +/* $NetBSD: hypervisor.c,v 1.73.2.9 2020/04/22 20:49:08 bouyer Exp $ */ /* * Copyright (c) 2005 Manuel Bouyer. @@ -53,7 +53,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.8 2020/04/20 11:29:01 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.9 2020/04/22 20:49:08 bouyer Exp $"); #include #include @@ -399,8 +399,6 @@ xen_hvm_init_cpu(struct cpu_info *ci) vm_guest = VM_GUEST_XENHVM; return 0; } - printf("cpu %s ci_acpiid %d vcpuid %d domid %d\n", - device_xname(ci->ci_dev), ci->ci_acpiid, descs[1], descs[2]); ci->ci_vcpuid = descs[1]; ci->ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[ci->ci_vcpuid]; @@ -434,9 +432,9 @@ xen_hvm_init_cpu(struct cpu_info *ci) * From FreeBSD: * Trick toolstack to think we are enlightened */ + xen_hvm_param.value = 1; aprint_verbose_dev(ci->ci_dev, "using event upcall vector: %d\n", xen_hvm_vec ); - xen_hvm_param.value = 1; } } @@ -476,14 +474,14 @@ hypervisor_match(device_t parent, cfdata return 1; } -#ifdef MULTIPROCESSOR +#if defined(MULTIPROCESSOR) && defined(XENPV) static int hypervisor_vcpu_print(void *aux, const char *parent) { /* Unconfigured cpus are ignored quietly. */ return (QUIET); } -#endif /* MULTIPROCESSOR */ +#endif /* MULTIPROCESSOR && XENPV */ /* * Attach the hypervisor. @@ -591,6 +589,7 @@ hypervisor_attach(device_t parent, devic xengnt_init(); events_init(); +#ifdef XENPV memset(&hac, 0, sizeof(hac)); hac.hac_vcaa.vcaa_name = "vcpu"; hac.hac_vcaa.vcaa_caa.cpu_number = 0; @@ -622,6 +621,7 @@ hypervisor_attach(device_t parent, devic } #endif /* MULTIPROCESSOR */ +#endif /* XENPV */ #if NXENBUS > 0 extern struct x86_bus_dma_tag xenbus_bus_dma_tag;
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Tue Apr 21 16:57:40 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: xengnt.c Log Message: It is possible to use grant_v2 with HVM guest; but the status table has to be mapped using XENMEM_add_to_physmap. To generate a diff of this commit: cvs rdiff -u -r1.29.2.2 -r1.29.2.3 src/sys/arch/xen/xen/xengnt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xengnt.c diff -u src/sys/arch/xen/xen/xengnt.c:1.29.2.2 src/sys/arch/xen/xen/xengnt.c:1.29.2.3 --- src/sys/arch/xen/xen/xengnt.c:1.29.2.2 Mon Apr 20 19:42:10 2020 +++ src/sys/arch/xen/xen/xengnt.c Tue Apr 21 16:57:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xengnt.c,v 1.29.2.2 2020/04/20 19:42:10 bouyer Exp $ */ +/* $NetBSD: xengnt.c,v 1.29.2.3 2020/04/21 16:57:40 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.29.2.2 2020/04/20 19:42:10 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.29.2.3 2020/04/21 16:57:40 bouyer Exp $"); #include #include @@ -44,16 +44,6 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1 #include "opt_xen.h" -/* - * grant table v2 is not supported for HVM guests on 4.11 at last. - * see xen/arch/x86/hvm/hypercall.c in Xen sources (missing - * GNTTABOP_get_status_frames) - */ - -#ifdef XENPV -#define USE_GRANT_V2 -#endif - /* #define XENDEBUG */ #ifdef XENDEBUG #define DPRINTF(x) printf x @@ -77,7 +67,6 @@ int last_gnt_entry; #define XENGNT_NO_ENTRY 0x /* VM address of the grant table */ -#ifdef USE_GRANT_V2 #define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t)) #define NR_GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t)) @@ -86,10 +75,6 @@ grant_entry_v2_t *grant_table; int gnt_status_frames; grant_status_t *grant_status; -#else /* USE_GRANT_V2 */ -#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v1_t)) -grant_entry_v1_t *grant_table; -#endif /* USE_GRANT_V2 */ kmutex_t grant_lock; static grant_ref_t xengnt_get_entry(void); @@ -118,13 +103,11 @@ xengnt_init(void) gnt_nr_grant_frames = gnt_max_grant_frames; -#ifdef USE_GRANT_V2 struct gnttab_set_version gntversion; gntversion.version = 2; rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gntversion, 1); if (rc < 0 || gntversion.version != 2) panic("GNTTABOP_set_version 2 failed %d", rc); -#endif /* USE_GRANT_V2 */ nr_grant_entries = gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE; @@ -139,14 +122,12 @@ xengnt_init(void) for (i = 0; i <= nr_grant_entries; i++) gnt_entries[i] = XENGNT_NO_ENTRY; -#ifdef USE_GRANT_V2 gnt_status_frames = round_page(nr_grant_entries * sizeof(grant_status_t)) / PAGE_SIZE; grant_status = (void *)uvm_km_alloc(kernel_map, gnt_status_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY); if (grant_status == NULL) panic("xengnt_init() status no VM space"); -#endif /* USE_GRANT_V2 */ mutex_init(&grant_lock, MUTEX_DEFAULT, IPL_VM); @@ -194,10 +175,8 @@ xengnt_suspend(void) { /* Remove virtual => machine mapping for grant table */ pmap_kremove((vaddr_t)grant_table, gnt_nr_grant_frames * PAGE_SIZE); -#ifdef USE_GRANT_V2 /* Remove virtual => machine mapping for status table */ pmap_kremove((vaddr_t)grant_status, gnt_status_frames * PAGE_SIZE); -#endif pmap_update(pmap_kernel()); mutex_exit(&grant_lock); @@ -210,12 +189,8 @@ xengnt_suspend(void) { static int xengnt_map_status(void) { -#ifdef USE_GRANT_V2 - gnttab_get_status_frames_t getstatus; uint64_t *pages; size_t sz; - int err; - KASSERT(mutex_owned(&grant_lock)); sz = gnt_status_frames * sizeof(*pages); @@ -223,6 +198,10 @@ xengnt_map_status(void) if (pages == NULL) return ENOMEM; +#ifdef XENPV + gnttab_get_status_frames_t getstatus; + int err; + getstatus.dom = DOMID_SELF; getstatus.nr_frames = gnt_status_frames; set_xen_guest_handle(getstatus.frame_list, pages); @@ -240,7 +219,23 @@ xengnt_map_status(void) kmem_free(pages, sz); return ENOMEM; } +#else /* XENPV */ + for (int i = 0; i < gnt_status_frames; i++) { + struct vm_page *pg; + struct xen_add_to_physmap xmap; + + pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_USERESERVE|UVM_PGA_ZERO); + pages[i] = atop(uvm_vm_page_to_phys(pg)); + + xmap.domid = DOMID_SELF; + xmap.space = XENMAPSPACE_grant_table; + xmap.idx = i | XENMAPIDX_grant_table_status; + xmap.gpfn = pages[i]; + if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xmap) < 0) + panic("%s: Unable to add grant tables\n", __func__); + } +#endif /* XENPV */ /* * map between status_table addresses and the machine addresses of * the status table frames @@ -253,8 +248,6 @@ xengnt_map_status(void) pmap_update(pmap_kernel()); kmem_free(pages, sz); - -#endif /* USE_GRANT_V2 */ return 0; } @@ -298,7 +291,7 @@ xengnt_mo
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Mon Apr 20 19:42:10 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: xengnt.c Log Message: Bad news: * grant table v2 is not supported for HVM guests on 4.11 at last. * see xen/arch/x86/hvm/hypercall.c in Xen sources (missing * GNTTABOP_get_status_frames) So restore grant table v1 for !XENPV To generate a diff of this commit: cvs rdiff -u -r1.29.2.1 -r1.29.2.2 src/sys/arch/xen/xen/xengnt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xengnt.c diff -u src/sys/arch/xen/xen/xengnt.c:1.29.2.1 src/sys/arch/xen/xen/xengnt.c:1.29.2.2 --- src/sys/arch/xen/xen/xengnt.c:1.29.2.1 Mon Apr 20 11:29:01 2020 +++ src/sys/arch/xen/xen/xengnt.c Mon Apr 20 19:42:10 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xengnt.c,v 1.29.2.1 2020/04/20 11:29:01 bouyer Exp $ */ +/* $NetBSD: xengnt.c,v 1.29.2.2 2020/04/20 19:42:10 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.29.2.1 2020/04/20 11:29:01 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1.29.2.2 2020/04/20 19:42:10 bouyer Exp $"); #include #include @@ -42,6 +42,18 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1 #include #include +#include "opt_xen.h" + +/* + * grant table v2 is not supported for HVM guests on 4.11 at last. + * see xen/arch/x86/hvm/hypercall.c in Xen sources (missing + * GNTTABOP_get_status_frames) + */ + +#ifdef XENPV +#define USE_GRANT_V2 +#endif + /* #define XENDEBUG */ #ifdef XENDEBUG #define DPRINTF(x) printf x @@ -49,9 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1 #define DPRINTF(x) #endif -#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t)) -#define NR_GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t)) - /* External tools reserve first few grant table entries. */ #define NR_RESERVED_ENTRIES 8 @@ -59,8 +68,6 @@ __KERNEL_RCSID(0, "$NetBSD: xengnt.c,v 1 int gnt_nr_grant_frames; /* Maximum number of frames that can make up the grant table */ int gnt_max_grant_frames; -/* Number of grant status frames */ -int gnt_status_frames; /* table of free grant entries */ grant_ref_t *gnt_entries; @@ -70,8 +77,19 @@ int last_gnt_entry; #define XENGNT_NO_ENTRY 0x /* VM address of the grant table */ +#ifdef USE_GRANT_V2 +#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t)) +#define NR_GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t)) + grant_entry_v2_t *grant_table; +/* Number of grant status frames */ +int gnt_status_frames; + grant_status_t *grant_status; +#else /* USE_GRANT_V2 */ +#define NR_GRANT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v1_t)) +grant_entry_v1_t *grant_table; +#endif /* USE_GRANT_V2 */ kmutex_t grant_lock; static grant_ref_t xengnt_get_entry(void); @@ -83,7 +101,6 @@ void xengnt_init(void) { struct gnttab_query_size query; - struct gnttab_set_version gntversion; int rc; int nr_grant_entries; int i; @@ -100,10 +117,14 @@ xengnt_init(void) */ gnt_nr_grant_frames = gnt_max_grant_frames; + +#ifdef USE_GRANT_V2 + struct gnttab_set_version gntversion; gntversion.version = 2; rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gntversion, 1); if (rc < 0 || gntversion.version != 2) panic("GNTTABOP_set_version 2 failed %d", rc); +#endif /* USE_GRANT_V2 */ nr_grant_entries = gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE; @@ -118,12 +139,14 @@ xengnt_init(void) for (i = 0; i <= nr_grant_entries; i++) gnt_entries[i] = XENGNT_NO_ENTRY; +#ifdef USE_GRANT_V2 gnt_status_frames = round_page(nr_grant_entries * sizeof(grant_status_t)) / PAGE_SIZE; grant_status = (void *)uvm_km_alloc(kernel_map, gnt_status_frames * PAGE_SIZE, 0, UVM_KMF_VAONLY); if (grant_status == NULL) panic("xengnt_init() status no VM space"); +#endif /* USE_GRANT_V2 */ mutex_init(&grant_lock, MUTEX_DEFAULT, IPL_VM); @@ -171,8 +194,10 @@ xengnt_suspend(void) { /* Remove virtual => machine mapping for grant table */ pmap_kremove((vaddr_t)grant_table, gnt_nr_grant_frames * PAGE_SIZE); +#ifdef USE_GRANT_V2 /* Remove virtual => machine mapping for status table */ pmap_kremove((vaddr_t)grant_status, gnt_status_frames * PAGE_SIZE); +#endif pmap_update(pmap_kernel()); mutex_exit(&grant_lock); @@ -185,9 +210,11 @@ xengnt_suspend(void) { static int xengnt_map_status(void) { +#ifdef USE_GRANT_V2 gnttab_get_status_frames_t getstatus; uint64_t *pages; size_t sz; + int err; KASSERT(mutex_owned(&grant_lock)); @@ -204,9 +231,9 @@ xengnt_map_status(void) * get the status frames, and return the list of their virtual * addresses in 'pages' */ - if (HYPERVISOR_grant_table_op(GNTTABOP_get_status_frames, - &getstatus, 1) != 0) - panic("%s: get_status_frames failed", __func__); + if ((err
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Mon Apr 20 19:40:51 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: xbdback_xenbus.c Log Message: Fix build with DIAGNOSTIC To generate a diff of this commit: cvs rdiff -u -r1.77.2.2 -r1.77.2.3 src/sys/arch/xen/xen/xbdback_xenbus.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xbdback_xenbus.c diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.77.2.2 src/sys/arch/xen/xen/xbdback_xenbus.c:1.77.2.3 --- src/sys/arch/xen/xen/xbdback_xenbus.c:1.77.2.2 Mon Apr 20 18:50:46 2020 +++ src/sys/arch/xen/xen/xbdback_xenbus.c Mon Apr 20 19:40:51 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xbdback_xenbus.c,v 1.77.2.2 2020/04/20 18:50:46 bouyer Exp $ */ +/* $NetBSD: xbdback_xenbus.c,v 1.77.2.3 2020/04/20 19:40:51 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.77.2.2 2020/04/20 18:50:46 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.77.2.3 2020/04/20 19:40:51 bouyer Exp $"); #include #include @@ -1049,7 +1049,6 @@ xbdback_co_main_done2(struct xbdback_ins { int work_to_do; - KASSERT(xbdi->xbdio_io == NULL); RING_FINAL_CHECK_FOR_REQUESTS(&xbdi->xbdi_ring.ring_n, work_to_do); if (work_to_do) xbdi->xbdi_cont = xbdback_co_main; @@ -1233,7 +1232,6 @@ static void * xbdback_co_do_io(struct xbdback_instance *xbdi, void *obj) { struct xbdback_io *xbd_io = xbdi->xbdi_io; - int nsegs __diagused; switch (xbd_io->xio_operation) { case BLKIF_OP_FLUSH_DISKCACHE:
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Mon Apr 20 18:50:46 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: xbdback_xenbus.c Log Message: Bring in 1.82 and 1.83 from HEAD To generate a diff of this commit: cvs rdiff -u -r1.77.2.1 -r1.77.2.2 src/sys/arch/xen/xen/xbdback_xenbus.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xbdback_xenbus.c diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.77.2.1 src/sys/arch/xen/xen/xbdback_xenbus.c:1.77.2.2 --- src/sys/arch/xen/xen/xbdback_xenbus.c:1.77.2.1 Mon Apr 20 11:29:01 2020 +++ src/sys/arch/xen/xen/xbdback_xenbus.c Mon Apr 20 18:50:46 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xbdback_xenbus.c,v 1.77.2.1 2020/04/20 11:29:01 bouyer Exp $ */ +/* $NetBSD: xbdback_xenbus.c,v 1.77.2.2 2020/04/20 18:50:46 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.77.2.1 2020/04/20 11:29:01 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.77.2.2 2020/04/20 18:50:46 bouyer Exp $"); #include #include @@ -74,9 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: xbdback_xenb /* Need to alloc one extra page to account for possible mapping offset */ #define VBD_VA_SIZE (MAXPHYS + PAGE_SIZE) -struct xbdback_request; struct xbdback_io; -struct xbdback_fragment; struct xbdback_instance; /* @@ -98,8 +96,8 @@ typedef enum {WAITING, RUN, DISCONNECTIN * callback), the return value of a continuation can be set to NULL. In that * case, the thread will go back to sleeping and wait for the proper * condition before it starts processing requests again from where it left. - * Continuation state is "stored" in the xbdback instance (xbdi_cont and - * xbdi_cont_aux), and should only be manipulated by the instance thread. + * Continuation state is "stored" in the xbdback instance (xbdi_cont), + * and should only be manipulated by the instance thread. * * As xbdback(4) has to handle different sort of asynchronous events (Xen * event channels, biointr() soft interrupts, xenbus commands), the xbdi_lock @@ -109,36 +107,23 @@ typedef enum {WAITING, RUN, DISCONNECTIN * Here's how the call graph is supposed to be for a single I/O: * * xbdback_co_main() - *| - *| --> xbdback_co_cache_doflush() or NULL - *| | - *| - xbdback_co_cache_flush2() <- xbdback_co_do_io() <- - *|| | - *| |-> xbdback_co_cache_flush() -> xbdback_co_map_io()- + *| --> xbdback_co_cache_flush() + *| || + *| |-> xbdback_co_cache_doflush() or NULL + *| || + *| |-> xbdback_co_do_io() * xbdback_co_main_loop()-| - *| |-> xbdback_co_main_done() ---> xbdback_co_map_io()- - *| | | - *| -- xbdback_co_main_done2() <-- xbdback_co_do_io() <- + *| |-> xbdback_co_main_done2() or NULL *| | - *| --> xbdback_co_main() or NULL + *| --> xbdback_co_main_incr() -> xbdback_co_main_loop() *| * xbdback_co_io() -> xbdback_co_main_incr() -> xbdback_co_main_loop() *| - * xbdback_co_io_gotreq()--+--> xbdback_co_map_io() --- - *|| | - * -> xbdback_co_io_loop()| <- xbdback_co_do_io() <-- - * | | | | - * | | | |--> xbdback_co_io_gotio() - * | | | | - * | | xbdback_co_main_incr() | - * | | | | - * | | xbdback_co_main_loop() | - * | | | - * | xbdback_co_io_gotio2() <---| - * | | | - * | | |--> xbdback_co_io_gotfrag() - * | | | - * -- xbdback_co_io_gotfrag2() <-| + * xbdback_co_io_gotio() -> xbdback_map_shm() + *| | + *| xbdback_co_main_incr() -> xbdback_co_main_loop() + *| + * xbdback_co_do_io() *| * xbdback_co_main_incr() -> xbdback_co_main_loop() */ @@ -192,17 +177,12 @@ struct xbdback_instance { * continuation-ness (see above). */ RING_IDX xbdi_req_prod; /* limit on request indices */ - xbdback_cont_t xbdi_cont, xbdi_cont_aux; + xbdback_cont_t xbdi_cont; /* _request state: track requests fetched from ring */ struct xbdback_request *xbdi_req; /* if NULL, ignore following */ blkif_request_t xbdi_xen_req; - int xbdi_segno; /* _io state: I/O ass
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Sat Apr 18 20:36:31 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: evtchn.c Log Message: If we get an event for another CPU just ignore it. The hypervisor will callback on the other CPU anyway. To generate a diff of this commit: cvs rdiff -u -r1.88.2.5 -r1.88.2.6 src/sys/arch/xen/xen/evtchn.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/evtchn.c diff -u src/sys/arch/xen/xen/evtchn.c:1.88.2.5 src/sys/arch/xen/xen/evtchn.c:1.88.2.6 --- src/sys/arch/xen/xen/evtchn.c:1.88.2.5 Sat Apr 18 15:06:18 2020 +++ src/sys/arch/xen/xen/evtchn.c Sat Apr 18 20:36:31 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: evtchn.c,v 1.88.2.5 2020/04/18 15:06:18 bouyer Exp $ */ +/* $NetBSD: evtchn.c,v 1.88.2.6 2020/04/18 20:36:31 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -54,7 +54,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.5 2020/04/18 15:06:18 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.6 2020/04/18 20:36:31 bouyer Exp $"); #include "opt_xen.h" #include "isa.h" @@ -341,15 +341,14 @@ evtchn_do_event(int evtch, struct intrfr } KASSERTMSG(evtsource[evtch] != NULL, "unknown event %d", evtch); + + if (evtsource[evtch]->ev_cpu != ci) + return 0; + ci->ci_data.cpu_nintr++; evtsource[evtch]->ev_evcnt.ev_count++; ilevel = ci->ci_ilevel; - if (evtsource[evtch]->ev_cpu != ci /* XXX: get stats */) { - hypervisor_send_event(evtsource[evtch]->ev_cpu, evtch); - return 0; - } - if (evtsource[evtch]->ev_maxlevel <= ilevel) { #ifdef IRQ_DEBUG if (evtch == IRQ_DEBUG)
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Thu Apr 16 20:21:45 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: xen_clock.c Log Message: MOve the #ifdef XENPV block to the end, so that XEN3_DOM0 builds again. To generate a diff of this commit: cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/arch/xen/xen/xen_clock.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xen_clock.c diff -u src/sys/arch/xen/xen/xen_clock.c:1.1.2.1 src/sys/arch/xen/xen/xen_clock.c:1.1.2.2 --- src/sys/arch/xen/xen/xen_clock.c:1.1.2.1 Thu Apr 16 19:23:50 2020 +++ src/sys/arch/xen/xen/xen_clock.c Thu Apr 16 20:21:44 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_clock.c,v 1.1.2.1 2020/04/16 19:23:50 bouyer Exp $ */ +/* $NetBSD: xen_clock.c,v 1.1.2.2 2020/04/16 20:21:44 bouyer Exp $ */ /*- * Copyright (c) 2017, 2018 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.1.2.1 2020/04/16 19:23:50 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xen_clock.c,v 1.1.2.2 2020/04/16 20:21:44 bouyer Exp $"); #include #include @@ -114,128 +114,6 @@ static void xen_timepush_intr(void *); static int sysctl_xen_timepush(SYSCTLFN_ARGS); #endif -#ifdef XENPV -static int xen_rtc_get(struct todr_chip_handle *, struct timeval *); -static int xen_rtc_set(struct todr_chip_handle *, struct timeval *); -static void xen_wallclock_time(struct timespec *); -/* - * xen time of day register: - * - * Xen wall clock time, plus a Xen vCPU system time adjustment. - */ -static struct todr_chip_handle xen_todr_chip = { - .todr_gettime = xen_rtc_get, - .todr_settime = xen_rtc_set, -}; - -/* - * startrtclock() - * - * Initialize the real-time clock from x86 machdep autoconf. - */ -void -startrtclock(void) -{ - - todr_attach(&xen_todr_chip); -} - -/* - * setstatclockrate(rate) - * - * Set the statclock to run at rate, in units of ticks per second. - * - * Currently Xen does not have a separate statclock, so this is a - * noop; instad the statclock runs in hardclock. - */ -void -setstatclockrate(int rate) -{ -} - -/* - * xen_rtc_get(todr, tv) - * - * Get the current real-time clock from the Xen wall clock time - * and vCPU system time adjustment. - */ -static int -xen_rtc_get(struct todr_chip_handle *todr, struct timeval *tvp) -{ - struct timespec ts; - - xen_wallclock_time(&ts); - TIMESPEC_TO_TIMEVAL(tvp, &ts); - - return 0; -} - -/* - * xen_rtc_set(todr, tv) - * - * Set the Xen wall clock time, if we can. - */ -static int -xen_rtc_set(struct todr_chip_handle *todr, struct timeval *tvp) -{ -#ifdef DOM0OPS - struct clock_ymdhms dt; - xen_platform_op_t op; - uint64_t systime_ns; - - if (xendomain_is_privileged()) { - /* Convert to ymdhms and set the x86 ISA RTC. */ - clock_secs_to_ymdhms(tvp->tv_sec, &dt); - rtc_set_ymdhms(NULL, &dt); - - /* Get the global system time so we can preserve it. */ - systime_ns = xen_global_systime_ns(); - - /* Set the hypervisor wall clock time. */ - op.cmd = XENPF_settime; - op.u.settime.secs = tvp->tv_sec; - op.u.settime.nsecs = tvp->tv_usec * 1000; - op.u.settime.system_time = systime_ns; - return HYPERVISOR_platform_op(&op); - } -#endif - - /* XXX Should this fail if not on privileged dom0? */ - return 0; -} - -/* - * xen_wallclock_time(tsp) - * - * Return a snapshot of the current low-resolution wall clock - * time, as reported by the hypervisor, in tsp. - */ -static void -xen_wallclock_time(struct timespec *tsp) -{ - struct xen_wallclock_ticket ticket; - uint64_t systime_ns; - - int s = splsched(); /* make sure we won't be interrupted */ - /* Read the last wall clock sample from the hypervisor. */ - do { - xen_wallclock_enter(&ticket); - tsp->tv_sec = HYPERVISOR_shared_info->wc_sec; - tsp->tv_nsec = HYPERVISOR_shared_info->wc_nsec; - } while (!xen_wallclock_exit(&ticket)); - - /* Get the global system time. */ - systime_ns = xen_global_systime_ns(); - splx(s); - - /* Add the system time to the wall clock time. */ - systime_ns += tsp->tv_nsec; - tsp->tv_sec += systime_ns / 10ull; - tsp->tv_nsec = systime_ns % 10ull; -} - -#endif /* XENPV */ - /* * idle_block() * @@ -1011,3 +889,125 @@ sysctl_xen_timepush(SYSCTLFN_ARGS) } #endif /* DOM0OPS */ + +#ifdef XENPV +static int xen_rtc_get(struct todr_chip_handle *, struct timeval *); +static int xen_rtc_set(struct todr_chip_handle *, struct timeval *); +static void xen_wallclock_time(struct timespec *); +/* + * xen time of day register: + * + * Xen wall clock time, plus a Xen vCPU system time adjustment. + */ +static struct todr_chip_handle xen_todr_chip = { + .todr_gettime = xen_rtc_get, + .todr_settime = xen_rtc_set, +}; + +/* + * startrtclock() + * + * Initialize the real-time clock from x86 machdep autoconf. + */ +void +startrtclock(void) +{ + + todr_attach(&xen_todr_chip); +} + +/* + * setstatclockrate(rate) + * + * Set the statclock to run at rat
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Thu Apr 16 20:21:04 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: hypervisor.c Log Message: switch vm_guest to VM_GUEST_XENPVHVM only after all tests succeeded. To generate a diff of this commit: cvs rdiff -u -r1.73.2.4 -r1.73.2.5 src/sys/arch/xen/xen/hypervisor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/hypervisor.c diff -u src/sys/arch/xen/xen/hypervisor.c:1.73.2.4 src/sys/arch/xen/xen/hypervisor.c:1.73.2.5 --- src/sys/arch/xen/xen/hypervisor.c:1.73.2.4 Thu Apr 16 19:23:50 2020 +++ src/sys/arch/xen/xen/hypervisor.c Thu Apr 16 20:21:04 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hypervisor.c,v 1.73.2.4 2020/04/16 19:23:50 bouyer Exp $ */ +/* $NetBSD: hypervisor.c,v 1.73.2.5 2020/04/16 20:21:04 bouyer Exp $ */ /* * Copyright (c) 2005 Manuel Bouyer. @@ -53,7 +53,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.4 2020/04/16 19:23:50 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.5 2020/04/16 20:21:04 bouyer Exp $"); #include #include @@ -251,8 +251,6 @@ hypervisor_match(device_t parent, cfdata /* XXX: vtophys(&hypercall_page) */ wrmsr(descs[1], (uintptr_t)&hypercall_page - KERNBASE); - vm_guest = VM_GUEST_XENPVHVM; /* Be more specific */ - } else { return 0; } @@ -427,7 +425,7 @@ hypervisor_match(device_t parent, cfdata bi.common.len = sizeof(struct btinfo_rootdevice); /* From i386/multiboot.c */ - /* $NetBSD: hypervisor.c,v 1.73.2.4 2020/04/16 19:23:50 bouyer Exp $ */ + /* $NetBSD: hypervisor.c,v 1.73.2.5 2020/04/16 20:21:04 bouyer Exp $ */ int i, len; vaddr_t data; extern struct bootinfo bootinfo; @@ -456,6 +454,8 @@ hypervisor_match(device_t parent, cfdata events_default_setup(); delay_func = xen_delay; initclock_func = xen_initclocks; + vm_guest = VM_GUEST_XENPVHVM; /* Be more specific */ + #endif /* XENPVHVM */ /* If we got here, it must mean we matched */
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Thu Apr 16 17:47:37 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: hypervisor.c Log Message: fail silently if hypervisor is not found. To generate a diff of this commit: cvs rdiff -u -r1.73.2.2 -r1.73.2.3 src/sys/arch/xen/xen/hypervisor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/hypervisor.c diff -u src/sys/arch/xen/xen/hypervisor.c:1.73.2.2 src/sys/arch/xen/xen/hypervisor.c:1.73.2.3 --- src/sys/arch/xen/xen/hypervisor.c:1.73.2.2 Sat Apr 11 21:21:16 2020 +++ src/sys/arch/xen/xen/hypervisor.c Thu Apr 16 17:47:37 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hypervisor.c,v 1.73.2.2 2020/04/11 21:21:16 bouyer Exp $ */ +/* $NetBSD: hypervisor.c,v 1.73.2.3 2020/04/16 17:47:37 bouyer Exp $ */ /* * Copyright (c) 2005 Manuel Bouyer. @@ -53,7 +53,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.2 2020/04/11 21:21:16 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.3 2020/04/16 17:47:37 bouyer Exp $"); #include #include @@ -250,8 +250,6 @@ hypervisor_match(device_t parent, cfdata vm_guest = VM_GUEST_XENPVHVM; /* Be more specific */ } else { - aprint_normal("%s: Xen HVM mode not identified. Exiting.\n", - haa->haa_busname); return 0; } @@ -425,7 +423,7 @@ hypervisor_match(device_t parent, cfdata bi.common.len = sizeof(struct btinfo_rootdevice); /* From i386/multiboot.c */ - /* $NetBSD: hypervisor.c,v 1.73.2.2 2020/04/11 21:21:16 bouyer Exp $ */ + /* $NetBSD: hypervisor.c,v 1.73.2.3 2020/04/16 17:47:37 bouyer Exp $ */ int i, len; vaddr_t data; extern struct bootinfo bootinfo;
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Sun Apr 12 11:16:59 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: evtchn.c Log Message: Now that we return from hypervisor_callback via Xdoreti, no need to emulate it in evtchn_do_event() any more. To generate a diff of this commit: cvs rdiff -u -r1.88.2.1 -r1.88.2.2 src/sys/arch/xen/xen/evtchn.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/evtchn.c diff -u src/sys/arch/xen/xen/evtchn.c:1.88.2.1 src/sys/arch/xen/xen/evtchn.c:1.88.2.2 --- src/sys/arch/xen/xen/evtchn.c:1.88.2.1 Fri Apr 10 14:38:19 2020 +++ src/sys/arch/xen/xen/evtchn.c Sun Apr 12 11:16:58 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: evtchn.c,v 1.88.2.1 2020/04/10 14:38:19 bouyer Exp $ */ +/* $NetBSD: evtchn.c,v 1.88.2.2 2020/04/12 11:16:58 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -54,7 +54,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.1 2020/04/10 14:38:19 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.2 2020/04/12 11:16:58 bouyer Exp $"); #include "opt_xen.h" #include "isa.h" @@ -316,8 +316,6 @@ evtchn_do_event(int evtch, struct intrfr struct intrhand *ih; int (*ih_fun)(void *, void *); uint32_t iplmask; - int i; - uint32_t iplbit; KASSERTMSG(evtch >= 0, "negative evtch: %d", evtch); KASSERTMSG(evtch < NR_EVENT_CHANNELS, @@ -404,35 +402,6 @@ evtchn_do_event(int evtch, struct intrfr #endif /* NPCI > 0 || NISA > 0 */ splx: - /* - * C version of spllower(). ASTs will be checked when - * hypevisor_callback() exits, so no need to check here. - */ - iplmask = (XUNMASK(ci, ilevel) & ci->ci_xpending); - while (iplmask != 0) { - iplbit = 1 << (NIPL - 1); - i = (NIPL - 1); - while (iplmask != 0 && i > ilevel) { - while (iplmask & iplbit) { -ci->ci_xpending &= ~iplbit; -ci->ci_ilevel = i; -for (ih = ci->ci_xsources[i]->is_handlers; -ih != NULL; ih = ih->ih_next) { - KASSERT(ih->ih_cpu == ci); - x86_enable_intr(); - ih_fun = (void *)ih->ih_fun; - ih_fun(ih->ih_arg, regs); - x86_disable_intr(); -} -hypervisor_enable_ipl(i); -/* more pending IPLs may have been registered */ -iplmask = -(XUNMASK(ci, ilevel) & ci->ci_xpending); - } - i--; - iplbit >>= 1; - } - } ci->ci_ilevel = ilevel; return 0; }
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Sat Apr 11 21:21:16 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: hypervisor.c Log Message: Use some PIO magic to disable qemu emulated disks and network device when PVHVM is configured. From FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.73.2.1 -r1.73.2.2 src/sys/arch/xen/xen/hypervisor.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/hypervisor.c diff -u src/sys/arch/xen/xen/hypervisor.c:1.73.2.1 src/sys/arch/xen/xen/hypervisor.c:1.73.2.2 --- src/sys/arch/xen/xen/hypervisor.c:1.73.2.1 Wed Apr 8 17:59:17 2020 +++ src/sys/arch/xen/xen/hypervisor.c Sat Apr 11 21:21:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hypervisor.c,v 1.73.2.1 2020/04/08 17:59:17 bouyer Exp $ */ +/* $NetBSD: hypervisor.c,v 1.73.2.2 2020/04/11 21:21:16 bouyer Exp $ */ /* * Copyright (c) 2005 Manuel Bouyer. @@ -53,7 +53,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.1 2020/04/08 17:59:17 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.73.2.2 2020/04/11 21:21:16 bouyer Exp $"); #include #include @@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: hypervisor.c #include #include #include +#include #include #include @@ -191,6 +192,15 @@ int xen_version; static bool hypervisor_suspend(device_t, const pmf_qual_t *); static bool hypervisor_resume(device_t, const pmf_qual_t *); +/* from FreeBSD */ +#define XEN_MAGIC_IOPORT 0x10 +enum { + XMI_MAGIC= 0x49d2, + XMI_UNPLUG_IDE_DISKS = 0x01, + XMI_UNPLUG_NICS = 0x02, + XMI_UNPLUG_IDE_EXCEPT_PRI_MASTER = 0x04 +}; + /* * Probe for the hypervisor; always succeeds. */ @@ -415,7 +425,7 @@ hypervisor_match(device_t parent, cfdata bi.common.len = sizeof(struct btinfo_rootdevice); /* From i386/multiboot.c */ - /* $NetBSD: hypervisor.c,v 1.73.2.1 2020/04/08 17:59:17 bouyer Exp $ */ + /* $NetBSD: hypervisor.c,v 1.73.2.2 2020/04/11 21:21:16 bouyer Exp $ */ int i, len; vaddr_t data; extern struct bootinfo bootinfo; @@ -434,6 +444,13 @@ hypervisor_match(device_t parent, cfdata bip->bi_nentries++; } + /* disable emulated devices */ + if (inw(XEN_MAGIC_IOPORT) == XMI_MAGIC) { + outw(XEN_MAGIC_IOPORT, XMI_UNPLUG_IDE_DISKS | XMI_UNPLUG_NICS); + } else { + aprint_error("%s: Unable to disable emulated devices\n", + haa->haa_busname); + } #endif /* XENPVHVM */ /* If we got here, it must mean we matched */
CVS commit: [bouyer-xenpvh] src/sys/arch/xen/xen
Module Name:src Committed By: bouyer Date: Fri Apr 10 14:38:19 UTC 2020 Modified Files: src/sys/arch/xen/xen [bouyer-xenpvh]: evtchn.c Log Message: Remove extra assignement To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.88.2.1 src/sys/arch/xen/xen/evtchn.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/evtchn.c diff -u src/sys/arch/xen/xen/evtchn.c:1.88 src/sys/arch/xen/xen/evtchn.c:1.88.2.1 --- src/sys/arch/xen/xen/evtchn.c:1.88 Mon Apr 6 19:26:00 2020 +++ src/sys/arch/xen/xen/evtchn.c Fri Apr 10 14:38:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: evtchn.c,v 1.88 2020/04/06 19:26:00 jdolecek Exp $ */ +/* $NetBSD: evtchn.c,v 1.88.2.1 2020/04/10 14:38:19 bouyer Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -54,7 +54,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88 2020/04/06 19:26:00 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.88.2.1 2020/04/10 14:38:19 bouyer Exp $"); #include "opt_xen.h" #include "isa.h" @@ -942,7 +942,6 @@ event_set_iplhandler(struct cpu_info *ci KM_NOSLEEP); if (ipls == NULL) panic("can't allocate fixed interrupt source"); - ipls->is_recurse = xenev_stubs[level].ist_entry; ipls->is_recurse = xenev_stubs[level].ist_recurse; ipls->is_resume = xenev_stubs[level].ist_resume; ipls->is_handlers = ih;