Module Name:    src
Committed By:   bouyer
Date:           Wed Sep  9 16:46:06 UTC 2020

Modified Files:
        src/sys/arch/xen/xen: hypervisor.c

Log Message:
Workarounds for amazon's Xen 4.2 version, still present on some instances:
- It doens't provides an xencons, so allow HVM_PARAM_CONSOLE_PFN to fail
- the xen clock is not fully functionnal, so don't try to use it if
  HVM_PARAM_CONSOLE_PFN failed.
- it doesn't have XEN_HVM_CPUID_VCPU_ID_PRESENT so fall back to ci_acpiid
  as ci_vcpuid in this case.

It also doesn't support the per-CPU event callback; so fix the fallback
to global vector (don't try to register more per-cpu vector)
Should fix port-amd64/55543


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 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.87 src/sys/arch/xen/xen/hypervisor.c:1.88
--- src/sys/arch/xen/xen/hypervisor.c:1.87	Tue Jul 14 00:45:53 2020
+++ src/sys/arch/xen/xen/hypervisor.c	Wed Sep  9 16:46:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.87 2020/07/14 00:45:53 yamaguchi Exp $ */
+/* $NetBSD: hypervisor.c,v 1.88 2020/09/09 16:46:06 bouyer Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.87 2020/07/14 00:45:53 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor.c,v 1.88 2020/09/09 16:46:06 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -413,31 +413,41 @@ xen_hvm_init(void)
 	xen_hvm_param.index = HVM_PARAM_CONSOLE_PFN;
 	
 	if ( HYPERVISOR_hvm_op(HVMOP_get_param, &xen_hvm_param) < 0) {
-		aprint_error(
+		aprint_debug(
 		    "Xen HVM: Unable to obtain xencons page address\n");
-		return 0;
-	}
-
-	/* Re-use PV field */
-	xen_start_info.console.domU.mfn = xen_hvm_param.value;
-
-	pmap_kenter_pa((vaddr_t) xencons_interface, ptoa(xen_start_info.console.domU.mfn),
-	    VM_PROT_READ|VM_PROT_WRITE, 0);
+		xen_start_info.console.domU.mfn = 0;
+		xen_start_info.console.domU.evtchn = -1;
+		xencons_interface = 0;
+	} else {
+		/* Re-use PV field */
+		xen_start_info.console.domU.mfn = xen_hvm_param.value;
 
-	xen_hvm_param.domid = DOMID_SELF;
-	xen_hvm_param.index = HVM_PARAM_CONSOLE_EVTCHN;
+		pmap_kenter_pa((vaddr_t) xencons_interface,
+		    ptoa(xen_start_info.console.domU.mfn),
+		    VM_PROT_READ|VM_PROT_WRITE, 0);
+
+		xen_hvm_param.domid = DOMID_SELF;
+		xen_hvm_param.index = HVM_PARAM_CONSOLE_EVTCHN;
+
+		if ( HYPERVISOR_hvm_op(HVMOP_get_param, &xen_hvm_param) < 0) {
+			aprint_error(
+			   "Xen HVM: Unable to obtain xencons event channel\n");
+			return 0;
+		}
 
-	if ( HYPERVISOR_hvm_op(HVMOP_get_param, &xen_hvm_param) < 0) {
-		aprint_error(
-		    "Xen HVM: Unable to obtain xencons event channel\n");
-		return 0;
+		xen_start_info.console.domU.evtchn = xen_hvm_param.value;
 	}
 
-	xen_start_info.console.domU.evtchn = xen_hvm_param.value;
-
-
-	delay_func = x86_delay = xen_delay;
-	x86_initclock_func = xen_initclocks;
+	/*
+	 * PR port-amd64/55543
+	 * workround for amazon's Xen 4.2: it looks like the Xen clock is not
+	 * fully funtionnal here. This version also doesn't support
+	 * HVM_PARAM_CONSOLE_PFN. 
+	 */
+	if (xencons_interface != 0) {
+		delay_func = x86_delay = xen_delay;
+		x86_initclock_func = xen_initclocks;
+	}
 
 	vm_guest = VM_GUEST_XENPVHVM; /* Be more specific */
 	return 1;
@@ -458,13 +468,14 @@ xen_hvm_init_cpu(struct cpu_info *ci)
 
 	descs[0] = 0;
 	x86_cpuid(XEN_CPUID_LEAF(4), descs);
-	if (!(descs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT)) {
-		aprint_error_dev(ci->ci_dev, "Xen HVM: can't get VCPU id\n");
-		vm_guest = VM_GUEST_XENHVM;
-		return 0;
+	if (descs[0] & XEN_HVM_CPUID_VCPU_ID_PRESENT) {
+		ci->ci_vcpuid = descs[1];
+	} else {
+		aprint_debug_dev(ci->ci_dev,
+		    "Xen HVM: can't get VCPU id, falling back to ci_acpiid\n");
+		ci->ci_vcpuid = ci->ci_acpiid;
 	}
 
-	ci->ci_vcpuid = descs[1];
 	ci->ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[ci->ci_vcpuid];
 
 	/* Register event callback handler. */
@@ -491,6 +502,7 @@ xen_hvm_init_cpu(struct cpu_info *ci)
 				panic("event upcall vector");
 			aprint_error_dev(ci->ci_dev,
 			    "falling back to global vector\n");
+			xenhvm_use_percpu_callback = 0;
 		} else {
 			/*
 			 * From FreeBSD:
@@ -664,9 +676,11 @@ hypervisor_attach(device_t parent, devic
 	config_found_ia(self, "xendevbus", &hac.hac_xenbus, hypervisor_print);
 #endif
 #if NXENCONS > 0
-	memset(&hac, 0, sizeof(hac));
-	hac.hac_xencons.xa_device = "xencons";
-	config_found_ia(self, "xendevbus", &hac.hac_xencons, hypervisor_print);
+	if (xencons_interface != 0) {
+		memset(&hac, 0, sizeof(hac));
+		hac.hac_xencons.xa_device = "xencons";
+		config_found_ia(self, "xendevbus", &hac.hac_xencons, hypervisor_print);
+	}
 #endif
 #if defined(XENPV) && defined(DOM0OPS)
 #if NPCI > 0

Reply via email to