fabian.freyer_physik.tu-berlin.de created this revision.
fabian.freyer_physik.tu-berlin.de added a project: bhyve.
Herald added subscribers: Contributor Reviews (base), imp.

REVISION SUMMARY
  The current userboot interface sets this capability using 
`vm_setup_freebsd_registers_i386` in lib/libvmmapi/libvmmapi_freebsd.c. This 
patch adds support for loaders to explicitly query and/or set this capability 
without having to go through the `exec` callback, but set up registers 
themselves.
  
  This change is backwards-compatible as all new callbacks are added to the end 
of the callback structure.

TEST PLAN
  test with a library implementing `loader_main` and calling these callbacks. 
Check whether capability is set.

REPOSITORY
  rS FreeBSD src repository

REVISION DETAIL
  https://reviews.freebsd.org/D14473

AFFECTED FILES
  stand/userboot/userboot.h
  usr.sbin/bhyveload/bhyveload.c

EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: fabian.freyer_physik.tu-berlin.de
Cc: imp, freebsd-virtualization-list, #contributor_reviews_base
diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c
--- a/usr.sbin/bhyveload/bhyveload.c
+++ b/usr.sbin/bhyveload/bhyveload.c
@@ -560,6 +560,24 @@
 	return (vm_set_desc(ctx, vcpu, reg, base, limit, access));
 }
 
+static int
+cb_vm_get_unrestricted_guest(void* arg, int vcpu, int *retval)
+{
+	return (vm_get_capability(ctx, vcpu,
+			VM_CAP_UNRESTRICTED_GUEST, retval));
+}
+
+static int
+cb_vm_set_unrestricted_guest(void* arg, int vcpu, int val)
+{
+	int error, tmp;
+	if ((error = cb_vm_get_unrestricted_guest(arg, vcpu, &tmp)))
+		return error;
+
+	return (vm_set_capability(ctx, vcpu,
+			VM_CAP_UNRESTRICTED_GUEST, val));
+}
+
 static struct loader_callbacks cb = {
 	.getc = cb_getc,
 	.putc = cb_putc,
@@ -593,6 +611,10 @@
 	/* Version 4 additions */
 	.vm_set_register = cb_vm_set_register,
 	.vm_set_desc = cb_vm_set_desc,
+
+	/* Version 5 additions */
+	.vm_set_unrestricted_guest = cb_vm_set_unrestricted_guest,
+	.vm_get_unrestricted_guest = cb_vm_get_unrestricted_guest,
 };
 
 static int
diff --git a/stand/userboot/userboot.h b/stand/userboot/userboot.h
--- a/stand/userboot/userboot.h
+++ b/stand/userboot/userboot.h
@@ -41,6 +41,14 @@
  */
 #define	USERBOOT_VERSION_4      4
 
+/*
+ * Version 5 adds callbacks to set up long mode and set
+ * unrestricted guest capabilities. The callback structure
+ * backward compatible (new callbacks have been added at
+ * the tail end).
+ */
+#define	USERBOOT_VERSION_5      5
+
 /*
  * Exit codes from the loader
  */
@@ -210,4 +218,17 @@
 	int	(*vm_set_register)(void *arg, int vcpu, int reg, uint64_t val);
 	int	(*vm_set_desc)(void *arg, int vcpu, int reg, uint64_t base,
 	    u_int limit, u_int access);
+
+	/*
+	 * Version 5 additions.
+	 *
+	 * vm_get_unrestricted_guest checks support for the UNRESTRICTED_GUEST
+	 * capability and if supported, sets 'retval'. If unsupported, an error
+	 * code is returned.
+	 *
+	 * vm_set_unrestricted_guest sets the UNRESTRICTED_GUEST capability if
+	 * supported, and returns an error code otherwise.
+	 */
+	int	(*vm_get_unrestricted_guest)(void* arg, int vcpu, int *retval);
+	int	(*vm_set_unrestricted_guest)(void* arg, int vcpu, int val);
 };

_______________________________________________
freebsd-virtualization@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-virtualization
To unsubscribe, send any mail to 
"freebsd-virtualization-unsubscr...@freebsd.org"

Reply via email to