Add Virtual Box vboxguest and vboxsf guest drivers to the mainline kernel
Subsystems (4)
cover Add Virtual Box vboxguest and vboxsf guest drivers to the mainline kernel
Hello Greg, Arnd, Alexander, et al.,
Here is a first RFC version of my cleaned up version of the VirtualBox vboxguest and vboxsf guest drivers.
This is an RFC because there are still some checkpatch and other small style issues which I need to fix.
I'm posting this now because the majority of the major cleanup these 2 drivers needed before being suitable for mainlining has been done now and I believe the code is ready for a quick look by others (but not ready yet for a full review).
I've removed all depenencies on vbox's OO-independent runtime and the runtime itself, reducing the vboxguest driver from 100000+ lines of code to aprox. 6500 and the vboxsf driver from 60000 lines to 5000. This reduces the non debug vboxguest.ko size from 450kB to less then 100 kB. I've also cleaned up various other warts such as doing hardware init in module_init rather then in a pci_probe callback.
The vboxguest driver introduces a new userspace API + ABI in the form of ioctls on a character device. VirtualBox upstream not willing to commit to keeping this ABI stable was one of the things which has kept this driver driver out of mainline sofar. I've been talking to VirtualBox upstream about mainlining the guest drivers and VirtualBox upstream has agreed to consider the userspace ABI stable and only extend it in a backwards compatible manner.
As said this is a RFC, the main comments I'm looking for is an answer to these 2 questions:
Greg, Arnd would you be willing to merge the vboxguest driver under drivers/misc (in principle), assuming I do the remaining cleanup and the driver gets a favorable review of course ?
Al, the same question for you for the vboxsf (shared folder) driver?
Regards,
Hans
RFC 1/2 misc: Add vboxguest driver for Virtual Box Guest integration
This commit adds a driver for the Virtual Box Guest PCI device used in Virtual Box virtual machines. Enabling this driver will add support for Virtual Box Guest integration features such as copy-and-paste, seamless mode and OpenGL pass-through.
This driver also offers vboxguest IPC functionality which is needed for the vboxfs driver which offers folder sharing support.
--- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/vboxguest/Kconfig | 16 + drivers/misc/vboxguest/Makefile | 3 + drivers/misc/vboxguest/vboxguest_core.c | 1818 ++++++++++++++++++++++++++++ drivers/misc/vboxguest/vboxguest_core.h | 194 +++ drivers/misc/vboxguest/vboxguest_linux.c | 464 +++++++ drivers/misc/vboxguest/vboxguest_utils.c | 1124 +++++++++++++++++ drivers/misc/vboxguest/vboxguest_version.h | 18 + include/linux/vbox_err.h | 6 + include/linux/vbox_ostypes.h | 6 + include/linux/vbox_utils.h | 98 ++ include/linux/vbox_vmmdev.h | 128 ++ include/linux/vboxguest.h | 6 + include/uapi/linux/vbox_err.h | 178 +++ include/uapi/linux/vbox_ostypes.h | 158 +++ include/uapi/linux/vbox_vmmdev.h | 1743 ++++++++++++++++++++++++++ include/uapi/linux/vboxguest.h | 374 ++++++ 18 files changed, 6336 insertions(+) create mode 100644 drivers/misc/vboxguest/Kconfig create mode 100644 drivers/misc/vboxguest/Makefile create mode 100644 drivers/misc/vboxguest/vboxguest_core.c create mode 100644 drivers/misc/vboxguest/vboxguest_core.h create mode 100644 drivers/misc/vboxguest/vboxguest_linux.c create mode 100644 drivers/misc/vboxguest/vboxguest_utils.c create mode 100644 drivers/misc/vboxguest/vboxguest_version.h create mode 100644 include/linux/vbox_err.h create mode 100644 include/linux/vbox_ostypes.h create mode 100644 include/linux/vbox_utils.h create mode 100644 include/linux/vbox_vmmdev.h create mode 100644 include/linux/vboxguest.h create mode 100644 include/uapi/linux/vbox_err.h create mode 100644 include/uapi/linux/vbox_ostypes.h create mode 100644 include/uapi/linux/vbox_vmmdev.h create mode 100644 include/uapi/linux/vboxguest.h
drivers/misc/Kconfig +1 -0
@@ -518,4 +518,5 @@ source "drivers/misc/mic/Kconfig" source "drivers/misc/genwqe/Kconfig" source "drivers/misc/echo/Kconfig" source "drivers/misc/cxl/Kconfig" +source "drivers/misc/vboxguest/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_CXL_BASE) += cxl/ obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o +obj-y += vboxguest/ lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o
drivers/misc/vboxguest/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +config VBOXGUEST + tristate "Virtual Box Guest integration support" + depends on X86 && PCI && INPUT + help + This is a driver for the Virtual Box Guest PCI device used in + Virtual Box virtual machines. Enabling this driver will add + support for Virtual Box Guest integration features such as + copy-and-paste, seamless mode and OpenGL pass-through. + + This driver also offers vboxguest IPC functionality which is needed + for the vboxfs driver which offers folder sharing support. + + Although it is possible to build this module in, it is advised + to build this driver as a module, so that it can be updated + independently of the kernel. Select M to build this driver as a + module.
drivers/misc/vboxguest/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +vboxguest-y := vboxguest_linux.o vboxguest_core.o vboxguest_utils.o + +obj-$(CONFIG_VBOXGUEST) += vboxguest.o
drivers/misc/vboxguest/vboxguest_core.c new file +1818 -0
1,818 lines not on this page · raw message
drivers/misc/vboxguest/vboxguest_core.h new file +194 -0
194 lines not on this page · raw message
drivers/misc/vboxguest/vboxguest_linux.c new file +464 -0
464 lines not on this page · raw message
drivers/misc/vboxguest/vboxguest_utils.c new file +1124 -0
493 lines not on this page · raw message
drivers/misc/vboxguest/vboxguest_version.h new file +18 -0
Lines of this file are not shown. View the raw message.
include/linux/vbox_utils.h new file +98 -0
98 lines not on this page · raw message
include/linux/vbox_vmmdev.h new file +128 -0
128 lines not on this page · raw message
include/uapi/linux/vbox_err.h new file +178 -0
178 lines not on this page · raw message
include/uapi/linux/vbox_ostypes.h new file +158 -0
158 lines not on this page · raw message
include/uapi/linux/vbox_vmmdev.h new file +1743 -0
1,743 lines not on this page · raw message
include/uapi/linux/vboxguest.h new file +374 -0
374 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.3
Part of the diff is not shown here. View the raw message.
Arnd Bergmann
maintainerRe: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
Quoted 9 lines · Hans de Goede
This commit adds a driver for the Virtual Box Guest PCI device used in Virtual Box virtual machines. Enabling this driver will add support for Virtual Box Guest integration features such as copy-and-paste, seamless mode and OpenGL pass-through.
This driver also offers vboxguest IPC functionality which is needed for the vboxfs driver which offers folder sharing support.
Signed-off-by Hans de Goede <[email protected]>
Since you are still working on coding style cleanups, I'll comment mainly on the ioctl interface for now. Overall it already looks much better than I expected
from previous experience with the vbox source.
Most of the issues I would normally comment on are already moot based on the assumption that we won't be able to make substantial changes to either the user space portion or the hypervisor side.
Quoted 13 lines
drivers/misc/vboxguest/vboxguest_core.c new file +13
-0+/** +* Inflate the balloon by one chunk. +* +* The caller owns the balloon mutex. +* +* @returns VBox status code +* @param gdev The Guest extension device. +* @param chunk_idx Index of the chunk. +*/ +static int vbg_balloon_inflate (PVBOXGUESTDEVEXT gdev,u32 chunk_idx) +{ +VMMDevChangeMemBalloon *req = gdev->mem_balloon.change_req; +struct page **pages;
drivers/misc/vboxguest/vboxguest_core.c line 304
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_core.c new file +10
-0+int i, rc; + + pages =kmalloc (sizeof (*pages) *VMMDEV_MEMORY_BALLOON_CHUNK_PAGES , +GFP_KERNEL | __GFP_NOWARN); +if (!pages) +return VERR_NO_MEMORY ; + + req->header.size =sizeof (*req); + req->inflate = true; + req->pages =VMMDEV_MEMORY_BALLOON_CHUNK_PAGES ;
The balloon section seems to be rather simplistic with its ioctl interface. Ideally this should use CONFIG_BALLOON_COMPACTION and an
oom notifier like the virtio_balloon driver does. Yes, I realize that only one of the six (or more) balloon drivers we have in the kernel does it ;-)
drivers/misc/vboxguest/vboxguest_core.c line 415
Quoted 11 lines
drivers/misc/vboxguest/vboxguest_core.c new file +11
-0+/** +* Callback for heartbeat timer. +*/ +static void vbg_heartbeat_timer (unsigned long data) +{ +PVBOXGUESTDEVEXT gdev = (PVBOXGUESTDEVEXT )data; + +vbg_req_perform (gdev, gdev->guest_heartbeat_req); +mod_timer (&gdev->heartbeat_timer, +msecs_to_jiffies (gdev->heartbeat_interval_ms)); +}
This looks like a watchdog and should use the drivers/watchdog subsystem interfaces.
Quoted 5 lines
drivers/misc/vboxguest/vboxguest_core.c new file +5
-0+/** +* vbg_query_host_version try get the host feature mask and version information +* (vbg_host_version). +* +* @returns 0 or negative errno value (ignored).
drivers/misc/vboxguest/vboxguest_core.c line 500
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_core.c new file +10
-0+* @param gdev The Guest extension device. +*/ +static int vbg_query_host_version (PVBOXGUESTDEVEXT gdev) +{ +VMMDevReqHostVersion *req; +int rc, ret; + + req =vbg_req_alloc (sizeof (*req), VMMDevReq_GetHostVersion); +if (!req) +return -ENOMEM ;
While I understand you want to keep the ioctl interface, the version information looks like something that we should also have in sysfs in an appropriate location.
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 5 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +0
-0
This looks like a fairly short file, and could be merged into the core file.
drivers/misc/vboxguest/vboxguest_linux.c line 101
Quoted 13 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +13
-0+/** The file_operations structures. */ +static const struct file_operations vbg_misc_device_fops = { + .owner =THIS_MODULE , + .open = vbg_misc_device_open, + .release = vbg_misc_device_close, + .unlocked_ioctl = vgdrvLinuxIOCtl, +}; +static const struct file_operations vbg_misc_device_user_fops = { + .owner =THIS_MODULE , + .open = vbg_misc_device_user_open, + .release = vbg_misc_device_close, + .unlocked_ioctl = vgdrvLinuxIOCtl, +};
These lack a .compat_ioctl callback.
Quoted 27 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +27
-0+/** +* Device I/O Control entry point. +* +* @returns -ENOMEM or -EFAULT for errors inside the ioctl callback; 0 +* on success, or a positive VBox status code on vbox guest-device errors. +* +* @param pInode Associated inode pointer. +* @param pFilp Associated file pointer. +* @param uCmd The function specified to ioctl(). +* @param ulArg The argument specified to ioctl(). +*/ +static long vgdrvLinuxIOCtl(struct file *pFilp, unsigned int uCmd, + unsigned long ulArg) +{ + PVBOXGUESTSESSION session = (PVBOXGUESTSESSION) pFilp->private_data; + u32 cbData = _IOC_SIZE(uCmd); + void *pvBufFree; + void *pvBuf; + int rc, ret = 0; + u64 au64Buf[32 / sizeof(u64)]; + + /* + * For small amounts of data being passed we use a stack based buffer + * except for VMMREQUESTs where the data must not be on the stack. + */ + if (cbData <= sizeof(au64Buf) && + VBOXGUEST_IOCTL_STRIP_SIZE(uCmd) !=
drivers/misc/vboxguest/vboxguest_linux.c line 386
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +10
-0+ VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_VMMREQUEST(0))) { + pvBufFree = NULL; + pvBuf = &au64Buf[0]; + } else { +/* __GFP_DMA32 for VBOXGUEST_IOCTL_VMMREQUEST */ + pvBufFree = pvBuf =kmalloc (cbData,GFP_KERNEL | __GFP_DMA32); +if (!pvBuf) +return -ENOMEM ; + } +if (copy_from_user (pvBuf, (void *)ulArg, cbData) ==0 ) {
There should be a check for a maximum argument size. I'd also change the commands
to not always do both read and write, but only whichever applies. This function would then do the copy_from_user/copy_to_user conditionally.
Quoted 19 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +19
-0+static int hgcm_call_preprocess_linaddr (const HGCMFunctionParameter *src_parm, +bool is_user,void **bounce_buf_ret, +size_t *pcb_extra) +{ +void *buf, *bounce_buf; +bool copy_in; +u32 len; +int ret; + + buf = (void *)src_parm->u.Pointer.u.linearAddr; + len = src_parm->u.Pointer.size; + copy_in = src_parm->type != VMMDevHGCMParmType_LinAddr_Out; + +if (!is_user) { +if (WARN_ON (len >VBGLR0_MAX_HGCM_KERNEL_PARM )) +return VERR_OUT_OF_RANGE ; + +hgcm_call_inc_pcb_extra (buf, len, pcb_extra); +return VINF_SUCCESS ;
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +10
-0+ } + +if (len >VBGLR0_MAX_HGCM_USER_PARM ) +return VERR_OUT_OF_RANGE ; + +if (len <=PAGE_SIZE *2 ) + bounce_buf =kmalloc (len,GFP_KERNEL ); +else + bounce_buf =vmalloc (len); +
we have kvmalloc() for this now
Quoted 33 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +33
-0+#ifdef CONFIG_X86_64 +int vbg_hgcm_call32 (VBOXGUESTDEVEXT *gdev,VBoxGuestHGCMCallInfo * pCallInfo, +u32 cbCallInfo,u32 timeout_ms,bool is_user) +{ +VBoxGuestHGCMCallInfo *pCallInfo64 =NULL ; +HGCMFunctionParameter *pParm64 =NULL ; +HGCMFunctionParameter32 *pParm32 =NULL ; +u32 cParms = pCallInfo->cParms; +u32 iParm; +int rc =VINF_SUCCESS ; + +/* +* The simple approach, allocate a temporary request and convert the parameters. +*/ + pCallInfo64 =kzalloc (sizeof (*pCallInfo64) + + cParms *sizeof (HGCMFunctionParameter), +GFP_KERNEL ); +if (!pCallInfo64) +return VERR_NO_MEMORY ; + + *pCallInfo64 = *pCallInfo; + pParm32 =VBOXGUEST_HGCM_CALL_PARMS32 (pCallInfo); + pParm64 =VBOXGUEST_HGCM_CALL_PARMS (pCallInfo64); +for (iParm =0 ; iParm < cParms; iParm++, pParm32++, pParm64++) { +switch (pParm32->type) { +case VMMDevHGCMParmType_32bit: + pParm64->type = VMMDevHGCMParmType_32bit; + pParm64->u.value32 = pParm32->u.value32; +break ; + +case VMMDevHGCMParmType_64bit: + pParm64->type = VMMDevHGCMParmType_64bit; + pParm64->u.value64 = pParm32->u.value64;
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +10
-0+break ; + +case VMMDevHGCMParmType_LinAddr_Out: +case VMMDevHGCMParmType_LinAddr: +case VMMDevHGCMParmType_LinAddr_In: + pParm64->type = pParm32->type; + pParm64->u.Pointer.size = pParm32->u.Pointer.size; + pParm64->u.Pointer.u.linearAddr = + pParm32->u.Pointer.u.linearAddr; +break ;
It would be good to clean this up and always use the same structure here.
Quoted 30 lines
include/linux/vbox_err.h new file +6
-0@@ -0,0 +1,6 @@ +#ifndef __VBOX_ERR_H__ +#define __VBOX_ERR_H__ + +#include <uapi/linux/vbox_err.h> + +#endif include/linux/vbox_ostypes.h new file +6
-0@@ -0,0 +1,6 @@ +#ifndef __VBOX_OSTYPES_H__ +#define __VBOX_OSTYPES_H__ + +#include <uapi/linux/vbox_ostypes.h> + +#endif include/linux/vboxguest.h new file +0
-0
include/linux/vboxguest.h line 6
Quoted 6 lines
include/linux/vboxguest.h new file +6
-0@@ -0,0 +1,6 @@ +#ifndef __VBOXGUEST_H__ +#define __VBOXGUEST_H__ + +#include <uapi/linux/vboxguest.h> + +#endif
This should not be needed, we add -I${srctree}/include/uapi/ to the include path already.
Quoted 5 lines
include/linux/vboxguest.h new file +5
-0+/** +* The layout of VMMDEV RAM region that contains information for guest. +*/ +typedef struct VMMDevMemory { + /** The size of this structure. */
include/linux/vboxguest.h
Quoted 10 lines
include/linux/vboxguest.h new file +10
-0+u32 u32Size; +/** The structure version. (VMMDEV_MEMORY_VERSION) */ +u32 u32Version; + +union { +struct { +/** Flag telling that VMMDev has events pending. */ +bool fHaveEvents; + } V1_04; +
As this is a hardware interface, maybe use u32 instead of 'bool'.
Strictly speaking, the ring buffer structures would even have to be __le32 and use byteorder specific read/write access, but that could perhaps be skipped here when you add a Kconfig dependency on !CONFIG_CPU_BIG_ENDIAN (which won't
ever be set on x86).
include/uapi/linux/vbox_ostypes.h
Quoted 11 lines
include/uapi/linux/vbox_err.h new file +0
-0include/uapi/linux/vbox_ostypes.h new file +0
-0@@ -0,0 +1,158 @@
Some of these headers are not really ABI between the kernel and user space but are between the vbox host and guest, so include/uapi is maybe not the best place for them.
Do we need all of this both in the kernel and in the header that actually defines the kernel/user interface?
Quoted 8 lines
include/uapi/linux/vbox_ostypes.h new file +8
-0+/** +* @name VBoxGuest IOCTL codes and structures. +* +* The range 0..15 is for basic driver communication. +* The range 16..31 is for HGCM communication. +* The range 32..47 is reserved for future use. +* The range 48..63 is for OS specific communication. +* The 7th bit is reserved for future hacks.
include/uapi/linux/vbox_ostypes.h line 18
Quoted 10 lines
include/uapi/linux/vbox_ostypes.h new file +10
-0+* The 8th bit is reserved for distinguishing between 32-bit and 64-bit +* processes in future 64-bit guest additions. +* @{ +*/ +#if __BITS_PER_LONG ==64 +#define VBOXGUEST_IOCTL_FLAG 128 +#else +#define VBOXGUEST_IOCTL_FLAG 0 +#endif +/** @} */
This seems misguided, we already know the difference between 32-bit and 64-bit tasks based on the entry point, and if the interface is properly designed then we don't care about this difference at all.
include/uapi/linux/vbox_ostypes.h line 28
Quoted 10 lines
include/uapi/linux/vbox_ostypes.h new file +10
-0+#define VBOXGUEST_IOCTL_CODE_ (function, size) \ + _IOC(_IOC_READ|_IOC_WRITE, 'V', (function), (size)) +#define VBOXGUEST_IOCTL_STRIP_SIZE (code) \ + VBOXGUEST_IOCTL_CODE_(_IOC_NR((code)), 0) + +#define VBOXGUEST_IOCTL_CODE (function, size) \ + VBOXGUEST_IOCTL_CODE_((function) | VBOXGUEST_IOCTL_FLAG, size) +/* Define 32 bit codes to support 32 bit applications in 64 bit guest driver. */ +#define VBOXGUEST_IOCTL_CODE_32 (function, size) \ +VBOXGUEST_IOCTL_CODE_(function, size)
If the command numbers can be changed wihtout causing too many problems, I'd just do away with these wrappers and use _IOR/_IOW/_IORW as needed.
include/uapi/linux/vbox_ostypes.h line 40
Quoted 12 lines
include/uapi/linux/vbox_ostypes.h new file +12
-0+/** Input and output buffers layout of the IOCTL_VBOXGUEST_WAITEVENT */ +typedef struct VBoxGuestWaitEventInfo { +/** timeout in milliseconds */ +u32 u32TimeoutIn; +/** events to wait for */ +u32 u32EventMaskIn; +/** result code */ +u32 u32Result; +/** events occurred */ +u32 u32EventFlagsOut; +}VBoxGuestWaitEventInfo ; +VBOXGUEST_ASSERT_SIZE (VBoxGuestWaitEventInfo,16 );
'u32' is not an approprioate type for a kernel header, use '__u32' instead.
Arnd
Re: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
Hi,
Quoted 6 lines · Arnd Bergmann
Quoted 5 lines · Hans de Goede
This commit adds a driver for the Virtual Box Guest PCI device used in Virtual Box virtual machines. Enabling this driver will add support for Virtual Box Guest integration features such as copy-and-paste, seamless mode and OpenGL pass-through.
Quoted 7 lines
Quoted 4 lines
This driver also offers vboxguest IPC functionality which is needed for the vboxfs driver which offers folder sharing support.
Signed-off-by Hans de Goede <[email protected]>Since you are still working on coding style cleanups, I'll comment mainly on the ioctl interface for now.
Thank you for the taking the time to review the ioctl interface.
Quoted 3 lines
Overall it already looks much better than
I expected
from previous experience with the vbox source.
I'm glad you like it, cleaning it up has been quite a bit of work, so I'm happy to see this being appreciated.
Quoted 24 lines
Most of the issues I would normally comment on are already moot based on the assumption that we won't be able to make substantial changes to either the user space portion or the hypervisor side.
Quoted 20 lines
(quoted diff) +20
-0+/** + * Inflate the balloon by one chunk. + * + * The caller owns the balloon mutex. + * + * @returns VBox status code + * @param gdev The Guest extension device. + * @param chunk_idx Index of the chunk. + */ +static int vbg_balloon_inflate(PVBOXGUESTDEVEXT gdev, u32 chunk_idx) +{ + VMMDevChangeMemBalloon *req = gdev->mem_balloon.change_req; + struct page **pages; + int i, rc; + + pages = kmalloc(sizeof(*pages) * VMMDEV_MEMORY_BALLOON_CHUNK_PAGES, + GFP_KERNEL | __GFP_NOWARN); + if (!pages) + return VERR_NO_MEMORY; +
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ req->header.size = sizeof(*req); + req->inflate = true; + req->pages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;The balloon section seems to be rather simplistic with its ioctl interface. Ideally this should use
CONFIG_BALLOON_COMPACTIONand an
oom notifier like thevirtio_balloondriver does. Yes, I realize that only one of the six (or more) balloon drivers we have in the kernel does it ;-)
The way the balloon code works is that the baloon-size is fully controlled by the host, all the guest-additions do is wait for an event indicating that the host wants to change it and then call this ioctl which will get the desired balloon size from the host and tries to adjust the size accordingly.
Hooking into the oom killer is not really useful because there is no way we can indicate to the host we are running low on mem and I don't think that trying to shrink the balloon to be smaller then the host requested size is a good idea.
Quoted 15 lines
Review
Quoted 12 lines
(quoted diff) +11
-0+/** + * Callback for heartbeat timer. + */ +static void vbg_heartbeat_timer(unsigned long data) +{ + PVBOXGUESTDEVEXT gdev = (PVBOXGUESTDEVEXT)data; + + vbg_req_perform(gdev, gdev->guest_heartbeat_req); + mod_timer(&gdev->heartbeat_timer, + msecs_to_jiffies(gdev->heartbeat_interval_ms)); +}This looks like a watchdog and should use the
drivers/watchdogsubsystem interfaces.
This is not really a watchdog, this also is fully under host control, the host controls if the guest should send a heartbeat and if so at which interval, where normally with a watchdog starting the timer and deciding the interval is under control of the watchdog user.
Also if we miss to generate the heartbeat then the host will just log a message, not reset the system as one would expect with a watchdog. TL;DR: I understand why suggest this but the watchdog interface seems a poor match for this.
Quoted 12 lines
Quoted 12 lines
(quoted diff) +11
-0+/** + * vbg_query_host_version try get the host feature mask and version information + * (vbg_host_version). + * + * @returns 0 or negative errno value (ignored). + * @param gdev The Guest extension device. + */ +static int vbg_query_host_version(PVBOXGUESTDEVEXT gdev) +{ + VMMDevReqHostVersion *req; + int rc, ret;
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ + req = vbg_req_alloc(sizeof(*req), VMMDevReq_GetHostVersion); + if (!req) + return -ENOMEM;While I understand you want to keep the ioctl interface, the version information looks like something that we should also have in sysfs in an appropriate location.
Yes I can add a sysfs attribute for the version and flags :)
Quoted 7 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 5 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +0
-0This looks like a fairly short file, and could be merged into the core file.
I would prefer to keep it separate to keep more or less 1 : 1 mapping between mainline kernel and vbox upstream svn files.
Quoted 7 lines
Quoted 7 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +7
-0+/** The file_operations structures. */ +static const struct file_operations vbg_misc_device_fops = { + .owner =THIS_MODULE , + .open = vbg_misc_device_open, + .release = vbg_misc_device_close, + .unlocked_ioctl = vgdrvLinuxIOCtl, +};
Quoted 8 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 6 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +6
-0+static const struct file_operations vbg_misc_device_user_fops = { + .owner =THIS_MODULE , + .open = vbg_misc_device_user_open, + .release = vbg_misc_device_close, + .unlocked_ioctl = vgdrvLinuxIOCtl, +};These lack a .compat_ioctl callback.
Good catch, so I guess that the code paths for 32 bit OpenGL pass on 64 bits have never been used / tested under Linux, I will take a look at this.
Quoted 31 lines
Quoted 31 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +31
-0+/** +* Device I/O Control entry point. +* +* @returns -ENOMEM or -EFAULT for errors inside the ioctl callback; 0 +* on success, or a positive VBox status code on vbox guest-device errors. +* +* @param pInode Associated inode pointer. +* @param pFilp Associated file pointer. +* @param uCmd The function specified to ioctl(). +* @param ulArg The argument specified to ioctl(). +*/ +static long vgdrvLinuxIOCtl (struct file *pFilp,unsigned int uCmd, +unsigned long ulArg) +{ +PVBOXGUESTSESSION session = (PVBOXGUESTSESSION ) pFilp->private_data; +u32 cbData =_IOC_SIZE (uCmd); +void *pvBufFree; +void *pvBuf; +int rc, ret =0 ; +u64 au64Buf[32 /sizeof (u64)]; + +/* +* For small amounts of data being passed we use a stack based buffer +* except for VMMREQUESTs where the data must not be on the stack. +*/ +if (cbData <=sizeof (au64Buf) && +VBOXGUEST_IOCTL_STRIP_SIZE (uCmd) != +VBOXGUEST_IOCTL_STRIP_SIZE (VBOXGUEST_IOCTL_VMMREQUEST (0 ))) { + pvBufFree =NULL ; + pvBuf = &au64Buf[0 ]; + }else {
Quoted 8 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 6 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +6
-0+/* __GFP_DMA32 for VBOXGUEST_IOCTL_VMMREQUEST */ + pvBufFree = pvBuf =kmalloc (cbData,GFP_KERNEL | __GFP_DMA32); +if (!pvBuf) +return -ENOMEM ; + } +if (copy_from_user (pvBuf, (void *)ulArg, cbData) ==0 ) {There should be a check for a maximum argument size.
Good point.
Quoted 3 lines
I'd also change the commands
to not always do both read and write, but only whichever applies. This function would then do the copy_from_user/copy_to_user conditionally.
This is actually an upstream TODO item I believe. One which would probably be best fixed by using _IOR/_IOW/_IORW IOCTL macros, but that needs to be coordinated with upstream.
Quoted 23 lines
Quoted 23 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +23
-0+static int hgcm_call_preprocess_linaddr (const HGCMFunctionParameter *src_parm, +bool is_user,void **bounce_buf_ret, +size_t *pcb_extra) +{ +void *buf, *bounce_buf; +bool copy_in; +u32 len; +int ret; + + buf = (void *)src_parm->u.Pointer.u.linearAddr; + len = src_parm->u.Pointer.size; + copy_in = src_parm->type != VMMDevHGCMParmType_LinAddr_Out; + +if (!is_user) { +if (WARN_ON (len >VBGLR0_MAX_HGCM_KERNEL_PARM )) +return VERR_OUT_OF_RANGE ; + +hgcm_call_inc_pcb_extra (buf, len, pcb_extra); +return VINF_SUCCESS ; + } + +if (len >VBGLR0_MAX_HGCM_USER_PARM ) +return VERR_OUT_OF_RANGE ;
Quoted 8 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 6 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +6
-0+ +if (len <=PAGE_SIZE *2 ) + bounce_buf =kmalloc (len,GFP_KERNEL ); +else + bounce_buf =vmalloc (len); +we have
kvmalloc()for this now
Cool I did not know that, will fix.
Quoted 39 lines
Quoted 39 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +37
-0+#ifdef CONFIG_X86_64 +int vbg_hgcm_call32 (VBOXGUESTDEVEXT *gdev,VBoxGuestHGCMCallInfo * pCallInfo, +u32 cbCallInfo,u32 timeout_ms,bool is_user) +{ +VBoxGuestHGCMCallInfo *pCallInfo64 =NULL ; +HGCMFunctionParameter *pParm64 =NULL ; +HGCMFunctionParameter32 *pParm32 =NULL ; +u32 cParms = pCallInfo->cParms; +u32 iParm; +int rc =VINF_SUCCESS ; + +/* +* The simple approach, allocate a temporary request and convert the parameters. +*/ + pCallInfo64 =kzalloc (sizeof (*pCallInfo64) + + cParms *sizeof (HGCMFunctionParameter), +GFP_KERNEL ); +if (!pCallInfo64) +return VERR_NO_MEMORY ; + + *pCallInfo64 = *pCallInfo; + pParm32 =VBOXGUEST_HGCM_CALL_PARMS32 (pCallInfo); + pParm64 =VBOXGUEST_HGCM_CALL_PARMS (pCallInfo64); +for (iParm =0 ; iParm < cParms; iParm++, pParm32++, pParm64++) { +switch (pParm32->type) { +case VMMDevHGCMParmType_32bit: + pParm64->type = VMMDevHGCMParmType_32bit; + pParm64->u.value32 = pParm32->u.value32; +break ; + +case VMMDevHGCMParmType_64bit: + pParm64->type = VMMDevHGCMParmType_64bit; + pParm64->u.value64 = pParm32->u.value64; +break ; + +case VMMDevHGCMParmType_LinAddr_Out: +case VMMDevHGCMParmType_LinAddr:
Quoted 8 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 6 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +6
-0+case VMMDevHGCMParmType_LinAddr_In: + pParm64->type = pParm32->type; + pParm64->u.Pointer.size = pParm32->u.Pointer.size; + pParm64->u.Pointer.u.linearAddr = + pParm32->u.Pointer.u.linearAddr; +break ;It would be good to clean this up and always use the same structure here.
The HGCMFunctionParameter struct describes function-parameters in a Host-Guest-Control-Method function call, so this is part of the host ABI interface and we cannot change this.
Any 32 bit apps running on a 64 bit kernel will be using the 32 bit version of this struct and we need to translate.
Quoted 32 lines
Quoted 32 lines
include/linux/vbox_err.h new file +6
-0@@ -0,0 +1,6 @@ +#ifndef __VBOX_ERR_H__ +#define __VBOX_ERR_H__ + +#include <uapi/linux/vbox_err.h> + +#endif include/linux/vbox_ostypes.h new file +6
-0@@ -0,0 +1,6 @@ +#ifndef __VBOX_OSTYPES_H__ +#define __VBOX_OSTYPES_H__ + +#include <uapi/linux/vbox_ostypes.h> + +#endif include/linux/vboxguest.h new file +1
-0@@ -0,0 +1,6 @@ +#ifndef __VBOXGUEST_H__
Quoted 8 lines
include/linux/vboxguest.h line 6
Quoted 5 lines
include/linux/vboxguest.h new file +5
-0+#define __VBOXGUEST_H__ + +#include <uapi/linux/vboxguest.h> + +#endif This should not be needed, we add -I${srctree}/include/uapi/ to the include path already.
Ok.
Quoted 10 lines
Quoted 10 lines
include/linux/vboxguest.h new file +9
-0+/** +* The layout of VMMDEV RAM region that contains information for guest. +*/ +typedef struct VMMDevMemory { + /** The size of this structure. */ + u32 u32Size; + /** The structure version. (VMMDEV_MEMORY_VERSION) */ + u32 u32Version; +
Quoted 8 lines
include/linux/vboxguest.h
Quoted 6 lines
include/linux/vboxguest.h new file +6
-0+union { +struct { +/** Flag telling that VMMDev has events pending. */ +bool fHaveEvents; + } V1_04; +As this is a hardware interface, maybe use u32 instead of 'bool'.
I guess that should work here, since we only every do "if (fHaveEvents)" but in other cases where we also set bool variables in the hardware interface structs we also need to know which bit(s) get set on true to move this over to non bool use.
I agree that the choice of bool in a (virtual) hardware interface is unfortunate, but we should not be trying to change the (virtual) hardware definition IMHO.
Quoted 6 lines
Strictly speaking, the ring buffer structures would even have to be
__le32and use byteorder specific read/write access, but that could perhaps be skipped here when you add aKconfigdependency on !CONFIG_CPU_BIG_ENDIAN (which won't
ever be set on x86).
Quoted 15 lines
include/uapi/linux/vbox_ostypes.h
Quoted 11 lines
include/uapi/linux/vbox_err.h new file +0
-0include/uapi/linux/vbox_ostypes.h new file +0
-0@@ -0,0 +1,158 @@Some of these headers are not really ABI between the kernel and user space but are between the vbox host and guest, so
include/uapiis maybe not the best place for them.
I assume you refer mainly to vbox_vmmdev.h here, the problem is that the ioctl API leaks a lot of vbox_vmmdev.h things through VBOXGUEST_IOCTL_VMMREQUEST which allows userspace to submit arbitrary vmmdev-requests. Note that the vboxguest driver does do several sanity checks on these, including limiting them to a specific list of allowed requests. But as said this does leak almost all of the vbox_vmmdev.h hardware interface into the userspace API.
I checked and VBOXGUEST_IOCTL_VMMREQUEST is used in various places, so I cannot just drop it.
Quoted 2 lines
Do we need all of this both in the kernel and in the header that actually defines the kernel/user interface?
Yes, see above.
Quoted 15 lines
Quoted 15 lines
include/uapi/linux/vbox_ostypes.h new file +15
-0+/** +* @name VBoxGuest IOCTL codes and structures. +* +* The range 0..15 is for basic driver communication. +* The range 16..31 is for HGCM communication. +* The range 32..47 is reserved for future use. +* The range 48..63 is for OS specific communication. +* The 7th bit is reserved for future hacks. +* The 8th bit is reserved for distinguishing between 32-bit and 64-bit +* processes in future 64-bit guest additions. +* @{ +*/ +#if __BITS_PER_LONG ==64 +#define VBOXGUEST_IOCTL_FLAG 128 +#else
Quoted 8 lines
include/uapi/linux/vbox_ostypes.h line 18
Quoted 3 lines
include/uapi/linux/vbox_ostypes.h new file +3
-0+#define VBOXGUEST_IOCTL_FLAG 0 +#endif +/** @} */ This seems misguided, we already know the difference between 32-bit and 64-bit tasks based on the entry point, and if the interface is properly designed then we don't care about this difference at all.
I guess (and really guess at that) that this is there because on some guest OS-es supported by vbox the distinction between a 32 bit or 64 bit app calling the ioctl cannot be made in another way.
But I would not mind dropping this flag for linux. Michael / Knut would something like this be acceptable ?
include/VBox/VBoxGuest.h +2 -2
@@ -123,9 +123,9 @@* used. * @{ */ -#if defined(RT_ARCH_AMD64 ) || defined(RT_ARCH_SPARC64 ) +#if (defined(RT_ARCH_AMD64 ) || defined(RT_ARCH_SPARC64 )) && !defined(RT_OS_LINUX )# define VBOXGUEST_IOCTL_FLAG 128 -#elif defined(RT_ARCH_X86 ) || defined(RT_ARCH_SPARC ) +#elif defined(RT_ARCH_X86 ) || defined(RT_ARCH_SPARC ) || defined(RT_OS_LINUX )# define VBOXGUEST_IOCTL_FLAG 0#else # error "dunno which arch this is!"
(extend with some other changes such as properly adding a .compat_ioctl file-op ?
Quoted 6 lines
Quoted 6 lines
include/uapi/linux/vbox_ostypes.h new file +6
-0+#define VBOXGUEST_IOCTL_CODE_ (function, size) \ + _IOC(_IOC_READ|_IOC_WRITE, 'V', (function), (size)) +#define VBOXGUEST_IOCTL_STRIP_SIZE (code) \ + VBOXGUEST_IOCTL_CODE_(_IOC_NR((code)), 0) + +#define VBOXGUEST_IOCTL_CODE (function, size) \
Quoted 8 lines
include/uapi/linux/vbox_ostypes.h line 28
Quoted 4 lines
include/uapi/linux/vbox_ostypes.h new file +4
-0+VBOXGUEST_IOCTL_CODE_ ((function) |VBOXGUEST_IOCTL_FLAG , size) +/* Define 32 bit codes to support 32 bit applications in 64 bit guest driver. */ +#define VBOXGUEST_IOCTL_CODE_32 (function, size) \ +VBOXGUEST_IOCTL_CODE_(function, size)If the command numbers can be changed wihtout causing too many problems, I'd just do away with these wrappers and use _IOR/_IOW/_IORW as needed.
The upstream vboxguest.h header defines VBOXGUEST_IOCTL_CODE for many different guest platforms. I guess not all of them have the _IOR/_IOW/_IORW flags embedded in the ioctl-code concept and I believe some of them only have a small amount of bits which can actually be used for the code, so we cannot just cram these flags in there.
I think that instead we need an ioctl_direction_flags table which can be used to determine if we need todo the copy_from_user and friends, without changing the codes.
Quoted 16 lines
include/uapi/linux/vbox_ostypes.h line 40
Quoted 13 lines
include/uapi/linux/vbox_ostypes.h new file +12
-0+/** Input and output buffers layout of the IOCTL_VBOXGUEST_WAITEVENT */ +typedef struct VBoxGuestWaitEventInfo { +/** timeout in milliseconds */ +u32 u32TimeoutIn; +/** events to wait for */ +u32 u32EventMaskIn; +/** result code */ +u32 u32Result; +/** events occurred */ +u32 u32EventFlagsOut; +}VBoxGuestWaitEventInfo ; +VBOXGUEST_ASSERT_SIZE (VBoxGuestWaitEventInfo,16 );'u32' is not an approprioate type for a kernel header, use '
__u32' instead.
Huh I thought that u32 was preferred, but I guess that it is not allowed in uapi headers due to potential conflicts and it should be __u32 in uapi headers ?
Regards,
Hans
Greg Kroah-Hartman
maintainerRe: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
Quoted 6 lines · Hans de Goede
Quoted 2 lines
'u32' is not an approprioate type for a kernel header, use '
__u32' instead.Huh I thought that u32 was preferred, but I guess that it is not allowed in uapi headers due to potential conflicts and it should be
__u32in uapi headers ?
The __ version should always be used in structures/variables that cross the user/kernel boundry as they are guaranteed to be correct that way. That is a requirement.
Use the "normal" non __ versions for in-kernel only variables.
hope this helps,
greg k-h
Re: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
In reply to Hans de GoedeHi,
Quoted 1 line · Hans de Goede
On 11-08-17 23:23, Arnd Bergmann wrote:
<snip>
Quoted 47 lines
Quoted 15 lines
Quoted 15 lines
(quoted diff) +15
-0+/** + * @name VBoxGuest IOCTL codes and structures. + * + * The range 0..15 is for basic driver communication. + * The range 16..31 is for HGCM communication. + * The range 32..47 is reserved for future use. + * The range 48..63 is for OS specific communication. + * The 7th bit is reserved for future hacks. + * The 8th bit is reserved for distinguishing between 32-bit and 64-bit + * processes in future 64-bit guest additions. + * @{ + */ +#if __BITS_PER_LONG == 64 +#define VBOXGUEST_IOCTL_FLAG 128 +#elseQuoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+#define VBOXGUEST_IOCTL_FLAG 0 +#endif +/** @} */This seems misguided, we already know the difference between 32-bit and 64-bit tasks based on the entry point, and if the interface is properly designed then we don't care about this difference at all.
I guess (and really guess at that) that this is there because on some guest OS-es supported by vbox the distinction between a 32 bit or 64 bit app calling the ioctl cannot be made in another way.
But I would not mind dropping this flag for linux. Michael / Knut would something like this be acceptable ?
include/VBox/VBoxGuest.h +2
-2@@ -123,9 +123,9 @@* used. * @{ */ -#if defined(RT_ARCH_AMD64 ) || defined(RT_ARCH_SPARC64 ) +#if (defined(RT_ARCH_AMD64 ) || defined(RT_ARCH_SPARC64 )) && !defined(RT_OS_LINUX )# define VBOXGUEST_IOCTL_FLAG 128 -#elif defined(RT_ARCH_X86 ) || defined(RT_ARCH_SPARC ) +#elif defined(RT_ARCH_X86 ) || defined(RT_ARCH_SPARC ) || defined(RT_OS_LINUX )# define VBOXGUEST_IOCTL_FLAG 0#else # error "dunno which arch this is!"
Quoted 2 lines
(extend with some other changes such as properly adding a .compat_ioctl file-op ?
So I've extended the above into a proper patch to upstream vbox svn (attached for reference). One thing which I've learned while doing that is that Linux seems to be unique with its compat_ioctl callback. Neither the BSDs nor Windows has this, they all use different ioctl numbers for 32 / 64bit, see e.g. :
https://tsyrklevich.net/clang_analyzer/freebsd_030917/report-de8f10.html
Which deals with 32 bit ioctl compat on freebsd, note all the ioctls checked for are post_fixed with _32.
So given the cross-platform nature of the vboxguest ioctl API I think we may end up having to stick with the (small) VBOXGUEST_IOCTL_FLAG wart in the API. Because I certainly don't want to break ABI compat between the mainline version and the out of tree version.
But first lets see what vbox upstream has to say about my patch to always make VBOXGUEST_IOCTL_FLAG 0 under Linux.
Regards,
Hans
Quoted 1 line
From
17237897ed2b654ba9de90a7dad8e0dffdefe65bMon Sep 17 00:00:00 2001
From: Hans de Goede <[email protected]>
Date: Mon, 14 Aug 2017 09:01:29 +0200
Subject: [PATCH] VGDrvCommonIoCtl: Add f32bit flag argument
On some operating-systems the driver can tell whether an ioctl is a 32bit compat callback or not without looking at the ioctl-nr, at a flag argument to pass this info along and use it for Linux to not need separate ioctl codes for 32 and 64 bit.
--- include/VBox/VBoxGuest.h | 4 +-- .../Additions/common/VBoxGuest/VBoxDev-haiku.c | 2 +- .../common/VBoxGuest/VBoxGuest-darwin.cpp | 2 +- .../Additions/common/VBoxGuest/VBoxGuest-freebsd.c | 2 +- .../common/VBoxGuest/VBoxGuest-haiku-stubs.c | 4 +-- .../Additions/common/VBoxGuest/VBoxGuest-haiku.h | 2 +- .../Additions/common/VBoxGuest/VBoxGuest-linux.c | 35 ++++++++++++++-------- .../Additions/common/VBoxGuest/VBoxGuest-netbsd.c | 2 +- .../Additions/common/VBoxGuest/VBoxGuest-os2.cpp | 4 +-- .../Additions/common/VBoxGuest/VBoxGuest-solaris.c | 2 +- .../Additions/common/VBoxGuest/VBoxGuest-win.cpp | 2 +- src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp | 16 +++++----- .../common/VBoxGuest/VBoxGuestIDC-unix.c.h | 2 +- .../Additions/common/VBoxGuest/VBoxGuestInternal.h | 2 +- 14 files changed, 47 insertions(+), 34 deletions(-)
include/VBox/VBoxGuest.h +2 -2
@@ -123,9 +123,9 @@* used. * @{ */ -#if defined(RT_ARCH_AMD64 ) || defined(RT_ARCH_SPARC64 ) +#if (defined(RT_ARCH_AMD64 ) || defined(RT_ARCH_SPARC64 )) && !defined(RT_OS_LINUX )# define VBOXGUEST_IOCTL_FLAG 128 -#elif defined(RT_ARCH_X86 ) || defined(RT_ARCH_SPARC ) +#elif defined(RT_ARCH_X86 ) || defined(RT_ARCH_SPARC ) || defined(RT_OS_LINUX )# define VBOXGUEST_IOCTL_FLAG 0#else # error "dunno which arch this is!"
src/VBox/Additions/common/VBoxGuest/VBoxDev-haiku.c +1 -1
@@ -236,7 +236,7 @@ static status_t vgdrvHaikuIOCtl(void *cookie, uint32 op, void *data, size_t len)* Process the IOCtl. */ size_t cbDataReturned; - rc =VGDrvCommonIoCtl (op, &g_DevExt, pSession, pvBuf, len, &cbDataReturned); + rc =VGDrvCommonIoCtl (op, &g_DevExt, pSession, pvBuf, len, &cbDataReturned, false);if (RT_SUCCESS (rc)) { rc =0 ;
src/VBox/Additions/common/VBoxGuest/VBoxGuest-darwin.cpp +1 -1
@@ -543,7 +543,7 @@ static int vgdrvDarwinIOCtlSlow(PVBOXGUESTSESSION pSession, u_long iCmd, caddr_t * Process the IOCtl. */ size_t cbReqRet = 0; - int rc = VGDrvCommonIoCtl(iCmd, &g_DevExt, pSession, pvReqData, cbReq, &cbReqRet); + int rc = VGDrvCommonIoCtl(iCmd, &g_DevExt, pSession, pvReqData, cbReq, &cbReqRet, false); if (RT_SUCCESS(rc)) { /*
src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c +1 -1
@@ -345,7 +345,7 @@ static int vgdrvFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, in* Process the IOCtl. */ size_t cbDataReturned; - rc =VGDrvCommonIoCtl (ulCmd, &g_DevExt, pSession, pvBuf, ReqWrap->cbData, &cbDataReturned); + rc =VGDrvCommonIoCtl (ulCmd, &g_DevExt, pSession, pvBuf, ReqWrap->cbData, &cbDataReturned, false);if (RT_SUCCESS (rc)) { rc =0 ;
src/VBox/Additions/common/VBoxGuest/VBoxGuest-haiku-stubs.c +2 -2
@@ -346,9 +346,9 @@ RTDECL(int) RTErrConvertToErrno(int iErr) {return g_VBoxGuest->_RTErrConvertToErrno (iErr); } -int VGDrvCommonIoCtl (unsigned iFunction,PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION pSession,void *pvData,size_t cbData,size_t *pcbDataReturned) +int VGDrvCommonIoCtl (unsigned iFunction,PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION pSession,void *pvData,size_t cbData,size_t *pcbDataReturned,bool f32bit) { -return g_VBoxGuest->_VGDrvCommonIoCtl (iFunction, pDevExt, pSession, pvData, cbData, pcbDataReturned); +return g_VBoxGuest->_VGDrvCommonIoCtl (iFunction, pDevExt, pSession, pvData, cbData, pcbDataReturned, f32bit); }int VGDrvCommonCreateUserSession (PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION *ppSession) {
src/VBox/Additions/common/VBoxGuest/VBoxGuest-haiku.h +1 -1
@@ -184,7 +184,7 @@ struct vboxguest_module_infoPRTLOGGER (*_RTLogRelGetDefaultInstanceEx)(uint32_t fFlagsAndGroup);int (*_RTErrConvertToErrno)(int iErr);int (*_VGDrvCommonIoCtl)(unsigned iFunction,PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION pSession, -void *pvData,size_t cbData,size_t *pcbDataReturned); +void *pvData,size_t cbData,size_t *pcbDataReturned,bool f32bit);int (*_VGDrvCommonCreateUserSession)(PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION *ppSession);void (*_VGDrvCommonCloseSession)(PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION pSession);void * (*_VBoxGuestIDCOpen)(uint32_t *pu32Version);
src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c +23 -12
@@ -78,11 +78,7 @@ static int vgdrvLinuxModInit(void);static void vgdrvLinuxModExit (void );static int vgdrvLinuxOpen (struct inode *pInode,struct file *pFilp);static int vgdrvLinuxRelease (struct inode *pInode,struct file *pFilp); -#ifdef HAVE_UNLOCKED_IOCTL -static long vgdrvLinuxIOCtl (struct file *pFilp,unsigned int uCmd,unsigned long ulArg); -#else -static int vgdrvLinuxIOCtl (struct inode *pInode,struct file *pFilp,unsigned int uCmd,unsigned long ulArg); -#endif +static long vgdrvLinuxIOCtlImpl (struct file *pFilp,unsigned int uCmd,unsigned long ulArg,bool f23bit);static int vgdrvLinuxFAsync (int fd,struct file *pFile,int fOn);static unsigned int vgdrvLinuxPoll (struct file *pFile,poll_table *pPt);static ssize_t vgdrvLinuxRead (struct file *pFile,char *pbBuf,size_t cbRead,loff_t *poff);
@@ -138,6 +134,22 @@ static char g_szDbgLogDst[128];static struct input_dev *g_pInputDevice =NULL ;#endif +#ifdef HAVE_UNLOCKED_IOCTL +static long vgdrvLinuxIOCtl(struct file *pFilp, unsigned int uCmd, unsigned long ulArg) +#else +static int vgdrvLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg) +#endif +{ + return vgdrvLinuxIOCtlImpl(pFilp, uCmd, ulArg, false); +} + +#ifdef CONFIG_COMPAT +static long vgdrvLinuxIOCtlCompat(struct file *pFilp, unsigned int uCmd, unsigned long ulArg) +{ + return vgdrvLinuxIOCtlImpl(pFilp, uCmd, ulArg, true); +} +#endif + /** The file_operations structure. */ static struct file_operations g_FileOps = {
@@ -149,6 +161,9 @@ static struct file_operations g_FileOps =#else ioctl: vgdrvLinuxIOCtl,#endif +#ifdef CONFIG_COMPAT + compat_ioctl: vgdrvLinuxIOCtlCompat, +#endif fasync: vgdrvLinuxFAsync, read: vgdrvLinuxRead, poll: vgdrvLinuxPoll,
@@ -395,7 +410,7 @@ static void vgdrvLinuxTermISR(void)*/ static int vgdrvLinuxSetMouseStatus (uint32_t fStatus) { -return VGDrvCommonIoCtl (VBOXGUEST_IOCTL_SET_MOUSE_STATUS , &g_DevExt, g_pKernelSession, &fStatus,sizeof (fStatus),NULL ); +return VGDrvCommonIoCtl (VBOXGUEST_IOCTL_SET_MOUSE_STATUS , &g_DevExt, g_pKernelSession, &fStatus,sizeof (fStatus),NULL , false); }
@@ -754,11 +769,7 @@ static int vgdrvLinuxRelease(struct inode *pInode, struct file *pFilp)* @param uCmd The function specified to ioctl(). * @param ulArg The argument specified to ioctl(). */ -#ifdef HAVE_UNLOCKED_IOCTL -static long vgdrvLinuxIOCtl(struct file *pFilp, unsigned int uCmd, unsigned long ulArg) -#else -static int vgdrvLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg) -#endif +static long vgdrvLinuxIOCtlImpl (struct file *pFilp,unsigned int uCmd,unsigned long ulArg,bool f32bit) {PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION )pFilp->private_data;uint32_t cbData =_IOC_SIZE (uCmd);
@@ -792,7 +803,7 @@ static int vgdrvLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned in* Process the IOCtl. */ size_t cbDataReturned; - rc =VGDrvCommonIoCtl (uCmd, &g_DevExt, pSession, pvBuf, cbData, &cbDataReturned); + rc =VGDrvCommonIoCtl (uCmd, &g_DevExt, pSession, pvBuf, cbData, &cbDataReturned, f32bit);/* * Copy ioctl data and output buffer back to user space.
src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c +1 -1
@@ -317,7 +317,7 @@ static int VBoxGuestNetBSDIOCtl(struct file *fp, u_long command, void *data)* Process the IOCtl. */ size_t cbDataReturned; - rc =VGDrvCommonIoCtl (command, &g_DevExt, session->session, pvBuf, ReqWrap->cbData, &cbDataReturned); + rc =VGDrvCommonIoCtl (command, &g_DevExt, session->session, pvBuf, ReqWrap->cbData, &cbDataReturned, false);if (RT_SUCCESS (rc)) { rc =0 ;
src/VBox/Additions/common/VBoxGuest/VBoxGuest-os2.cpp +2 -2
@@ -486,7 +486,7 @@ DECLASM(int) VGDrvOS2IDCService(uint32_t u32Session, unsigned iFunction, void *p switch (iFunction) { default: - rc = VGDrvCommonIoCtl(iFunction, &g_DevExt, pSession, pvData, cbData, pcbDataReturned); + rc = VGDrvCommonIoCtl(iFunction, &g_DevExt, pSession, pvData, cbData, pcbDataReturned, false); break; case VBOXGUEST_IOCTL_OS2_IDC_DISCONNECT:
@@ -590,7 +590,7 @@ DECLASM(int) vgdrvOS2IOCtl(uint16_t sfn, uint8_t iCat, uint8_t iFunction, void * * Process the IOCtl. */ size_t cbDataReturned; - rc = VGDrvCommonIoCtl(iFunction, &g_DevExt, pSession, pvParm, *pcbParm, &cbDataReturned); + rc = VGDrvCommonIoCtl(iFunction, &g_DevExt, pSession, pvParm, *pcbParm, &cbDataReturned, false); /* * Unlock the buffers.
src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris.c +1 -1
@@ -735,7 +735,7 @@ static int vgdrvSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArg, int Mode, cred_t* Process the IOCtl. */ size_t cbDataReturned =0 ; - rc =VGDrvCommonIoCtl (Cmd, &g_DevExt, pSession, pvBuf, ReqWrap.cbData, &cbDataReturned); + rc =VGDrvCommonIoCtl (Cmd, &g_DevExt, pSession, pvBuf, ReqWrap.cbData, &cbDataReturned, false);if (RT_SUCCESS (rc)) { rc =0 ;
src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp +1 -1
@@ -788,7 +788,7 @@ static NTSTATUS vgdrvNtIOCtl(PDEVICE_OBJECT pDevObj, PIRP pIrp) * Process the common IOCtls. */ size_t cbDataReturned; - int vrc = VGDrvCommonIoCtl(uCmd, &pDevExt->Core, pSession, pBuf, cbData, &cbDataReturned); + int vrc = VGDrvCommonIoCtl(uCmd, &pDevExt->Core, pSession, pBuf, cbData, &cbDataReturned, false); LogFlowFunc(("rc=%Rrc, pBuf=0x%p, cbData=%u, cbDataReturned=%u\n", vrc, pBuf, cbData, cbDataReturned));
src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp +9 -7
@@ -3374,9 +3374,11 @@ static int vgdrvIoCtl_SetCapabilities(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSIO * @param pvData The input/output data buffer. Can be NULL depending on the function. * @param cbData The max size of the data buffer. * @param pcbDataReturned Where to store the amount of returned data. Can be NULL. + * @param f32bit Is this a 32 bit compat call? Note when false the iFunction + * itself may still indicate this is a 32 bit compat call. */ int VGDrvCommonIoCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession, - void *pvData, size_t cbData, size_t *pcbDataReturned) + void *pvData, size_t cbData, size_t *pcbDataReturned, bool f32bit) { int rc; LogFlow(("VGDrvCommonIoCtl: iFunction=%#x pDevExt=%p pSession=%p pvData=%p cbData=%zu\n",
@@ -3448,7 +3450,7 @@ int VGDrvCommonIoCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSES bool fInterruptible = pSession->R0Process != NIL_RTR0PROCESS; CHECKRET_MIN_SIZE("HGCM_CALL", sizeof(VBoxGuestHGCMCallInfo)); rc = vgdrvIoCtl_HGCMCall(pDevExt, pSession, (VBoxGuestHGCMCallInfo *)pvData, RT_INDEFINITE_WAIT, - fInterruptible, false /*f32bit*/, false /* fUserData */, + fInterruptible, f32bit, false /* fUserData */, 0, cbData, pcbDataReturned); } else if (VBOXGUEST_IOCTL_STRIP_SIZE(iFunction) == VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL_TIMED(0)))
@@ -3457,7 +3459,7 @@ int VGDrvCommonIoCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSES CHECKRET_MIN_SIZE("HGCM_CALL_TIMED", sizeof(VBoxGuestHGCMCallInfoTimed)); rc = vgdrvIoCtl_HGCMCall(pDevExt, pSession, &pInfo->info, pInfo->u32Timeout, !!pInfo->fInterruptible || pSession->R0Process != NIL_RTR0PROCESS, - false /*f32bit*/, false /* fUserData */, + f32bit, false /* fUserData */, RT_OFFSETOF(VBoxGuestHGCMCallInfoTimed, info), cbData, pcbDataReturned); } else if (VBOXGUEST_IOCTL_STRIP_SIZE(iFunction) == VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL_USERDATA(0)))
@@ -3465,10 +3467,10 @@ int VGDrvCommonIoCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSES bool fInterruptible = true; CHECKRET_MIN_SIZE("HGCM_CALL", sizeof(VBoxGuestHGCMCallInfo)); rc = vgdrvIoCtl_HGCMCall(pDevExt, pSession, (VBoxGuestHGCMCallInfo *)pvData, RT_INDEFINITE_WAIT, - fInterruptible, false /*f32bit*/, true /* fUserData */, + fInterruptible, f32bit, true /* fUserData */, 0, cbData, pcbDataReturned); } -# ifdef RT_ARCH_AMD64 +# if defined RT_ARCH_AMD64 && !defined(RT_OS_LINUX) else if (VBOXGUEST_IOCTL_STRIP_SIZE(iFunction) == VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_HGCM_CALL_32(0))) { bool fInterruptible = pSession->R0Process != NIL_RTR0PROCESS;
@@ -3529,7 +3531,7 @@ int VGDrvCommonIoCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSES #ifdef VBOX_WITH_HGCM case VBOXGUEST_IOCTL_HGCM_CONNECT: -# ifdef RT_ARCH_AMD64 +# if defined RT_ARCH_AMD64 && !defined(RT_OS_LINUX) case VBOXGUEST_IOCTL_HGCM_CONNECT_32: # endif CHECKRET_MIN_SIZE("HGCM_CONNECT", sizeof(VBoxGuestHGCMConnectInfo));
@@ -3537,7 +3539,7 @@ int VGDrvCommonIoCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSES break; case VBOXGUEST_IOCTL_HGCM_DISCONNECT: -# ifdef RT_ARCH_AMD64 +# if defined RT_ARCH_AMD64 && !defined(RT_OS_LINUX) case VBOXGUEST_IOCTL_HGCM_DISCONNECT_32: # endif CHECKRET_MIN_SIZE("HGCM_DISCONNECT", sizeof(VBoxGuestHGCMDisconnectInfo));
src/VBox/Additions/common/VBoxGuest/VBoxGuestIDC-unix.c.h +1 -1
@@ -142,6 +142,6 @@ DECLEXPORT(int) VBOXCALL VBoxGuestIDCCall(void *pvSession, unsigned iCmd, void *AssertPtrReturn (pSession,VERR_INVALID_POINTER );AssertMsgReturn (pSession->pDevExt == &g_DevExt, ("SC: %p != %p\n" , pSession->pDevExt, &g_DevExt),VERR_INVALID_HANDLE ); -return VGDrvCommonIoCtl (iCmd, &g_DevExt, pSession, pvData, cbData, pcbDataReturned); +return VGDrvCommonIoCtl (iCmd, &g_DevExt, pSession, pvData, cbData, pcbDataReturned, false); }
src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h +1 -1
@@ -336,7 +336,7 @@ void VGDrvCommonCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSessioint VGDrvCommonIoCtlFast (unsigned iFunction,PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION pSession);int VGDrvCommonIoCtl (unsigned iFunction,PVBOXGUESTDEVEXT pDevExt,PVBOXGUESTSESSION pSession, -void *pvData,size_t cbData,size_t *pcbDataReturned); +void *pvData,size_t cbData,size_t *pcbDataReturned,bool f32bit);/** * ISR callback for notifying threads polling for mouse events.
Signature · 1 line
2.13.4
Arnd Bergmann
maintainerRe: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
In reply to Hans de GoedeQuoted 45 lines · Hans de Goede
Quoted 29 lines · Arnd Bergmann
On Fri, Aug 11, 2017 at 3:23 PM, Hans de Goede <[email protected]> wrote:
Most of the issues I would normally comment on are already moot based on the assumption that we won't be able to make substantial changes to either the user space portion or the hypervisor side.Quoted 23 lines
(quoted diff) +16
-0+/** + * Inflate the balloon by one chunk. + * + * The caller owns the balloon mutex. + * + * @returns VBox status code + * @param gdev The Guest extension device. + * @param chunk_idx Index of the chunk. + */ +static int vbg_balloon_inflate(PVBOXGUESTDEVEXT gdev, u32 chunk_idx) +{ + VMMDevChangeMemBalloon *req = gdev->mem_balloon.change_req; + struct page **pages; + int i, rc; + + pages = kmalloc(sizeof(*pages) *
VMMDEV_MEMORY_BALLOON_CHUNK_PAGES,(quoted diff) +6
-0+ GFP_KERNEL | __GFP_NOWARN); + if (!pages) + return VERR_NO_MEMORY; + + req->header.size = sizeof(*req); + req->inflate = true;Quoted 8 lines
Quoted 1 line
+
req->pages=VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;The balloon section seems to be rather simplistic with its ioctl interface.
Ideally this should useCONFIG_BALLOON_COMPACTIONand an
oom notifier like thevirtio_balloondriver does. Yes, I realize that only one of the six (or more) balloon drivers we have in the kernel does it ;-)The way the balloon code works is that the baloon-size is fully controlled by the host, all the guest-additions do is wait for an event indicating that the host wants to change it and then call this ioctl which will get the desired balloon size from the host and tries to adjust the size accordingly.
Quoted 4 lines
Hooking into the oom killer is not really useful because there is no way we can indicate to the host we are running low on mem and I don't think that trying to shrink the balloon to be smaller then the host requested size is a good idea.
Are you sure the guest can't just claim the memory back by using it? Usually that is how the balloon drivers work: the host asks the guest to free up some memory, and the guest frees up memory that it tells to the host, but if the guest runs out of memory, it just starts using it again and the host faults in empty pages.
For CONFIG_BALLOON_COMPACTION, you don't even need that, you just put some memory into the balloon before you take some other page out that is required for compaction. This might be less of an issue here when the balloon always operates on 1MB chunks.
Quoted 22 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7
-0+/** + * Callback for heartbeat timer. + */ +static void vbg_heartbeat_timer(unsigned long data) +{ + PVBOXGUESTDEVEXT gdev = (PVBOXGUESTDEVEXT)data; +Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ vbg_req_perform(gdev, gdev->guest_heartbeat_req); + mod_timer(&gdev->heartbeat_timer, + msecs_to_jiffies(gdev->heartbeat_interval_ms)); +}This looks like a watchdog and should use the
drivers/watchdogsubsystem interfaces.This is not really a watchdog, this also is fully under host control, the host controls if the guest should send a heartbeat and if so at which interval, where normally with a watchdog starting the timer and deciding the interval is under control of the watchdog user.
Quoted 4 lines
Also if we miss to generate the heartbeat then the host will just log a message, not reset the system as one would expect with a watchdog. TL;DR: I understand why suggest this but the watchdog interface seems a poor match for this.
Ok.
Quoted 12 lines
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 6 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +0
-0This looks like a fairly short file, and could be merged into the core file.
Quoted 2 lines
I would prefer to keep it separate to keep more or less 1 : 1 mapping between mainline kernel and vbox upstream svn files.
ok.
Quoted 30 lines
Quoted 16 lines
Quoted 10 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +9
-0+*/ +if (cbData <=sizeof (au64Buf) && +VBOXGUEST_IOCTL_STRIP_SIZE (uCmd) != +VBOXGUEST_IOCTL_STRIP_SIZE (VBOXGUEST_IOCTL_VMMREQUEST (0 ))) { + pvBufFree =NULL ; + pvBuf = &au64Buf[0 ]; + }else { +/* __GFP_DMA32 for VBOXGUEST_IOCTL_VMMREQUEST */ + pvBufFree = pvBuf = kmalloc(cbData, GFP_KERNEL |
__GFP_DMA32);drivers/misc/vboxguest/vboxguest_linux.c
Quoted 4 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +4
-0+if (!pvBuf) +return -ENOMEM ; + } +if (copy_from_user (pvBuf, (void *)ulArg, cbData) ==0 ) {Quoted 4 lines
I'd also change the commands
to not always do both read and write, but only whichever applies. This function
would then do the copy_from_user/copy_to_user conditionally.This is actually an upstream TODO item I believe. One which would probably be best fixed by using _IOR/_IOW/_IORW IOCTL macros, but that needs to be coordinated with upstream.
Quoted 1 line
It would be good to clean this up and always use the same structure here.
Quoted 6 lines
The HGCMFunctionParameter struct describes function-parameters in a Host-Guest-Control-Method function call, so this is part of the host ABI interface and we cannot change this.
Any 32 bit apps running on a 64 bit kernel will be using the 32 bit version of this struct and we need to translate.
I don't see the difference between changing the command codes and changing the structure layout here. In both cases, that is an incompatible ABI change but shouldn't much impact the source-level ABI if you do it right.
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +11
-0+/** +* The layout of VMMDEV RAM region that contains information for guest. +*/ +typedef struct VMMDevMemory { + /** The size of this structure. */ + u32 u32Size; + /** The structure version. (VMMDEV_MEMORY_VERSION) */ + u32 u32Version; + + union { + struct {Quoted 8 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 5 lines
+ /** Flag telling that VMMDev has events pending.
*/drivers/misc/vboxguest/vboxguest_linux.c new file +3
-0+bool fHaveEvents; + }V1_04 ; +As this is a hardware interface, maybe use u32 instead of 'bool'.
Quoted 8 lines
I guess that should work here, since we only every do "if (fHaveEvents)" but in other cases where we also set bool variables in the hardware interface structs we also need to know which bit(s) get set on true to move this over to non bool use.
I agree that the choice of bool in a (virtual) hardware interface is unfortunate, but we should not be trying to change the (virtual) hardware definition IMHO.
According to the x86 psABI (https://www.uclibc.org/docs/psABI-x86_64.pdf),
a _Bool should be represented in memory like an 'unsigned char' but only contain the values 0 or 1 (the upper 7 bits are zero).
Before linux-2.6.18, we defined 'bool' as 'typedef enum { false, true} __packed bool;', which would make it a 32-bit integer that can take the values 0 and 1.
Inside of the union, the two have the same binary layout on little-endian architectures, as the information is still stored in the low bit of the first of four bytes.
I think if you do
union {
struct {
/** Flag telling that VMMDev has events pending. */
u8 fHaveEvents;
u8 pad[3];
} V1_04;that will be a portable representation if the existing ABI.
Quoted 15 lines
Quoted 5 lines
Some of these headers are not really ABI between the kernel and user space but are between the vbox host and guest, so
include/uapiis maybe not the best place for them.I assume you refer mainly to
vbox_vmmdev.hhere, the problem is that the ioctl API leaks a lot ofvbox_vmmdev.hthings throughVBOXGUEST_IOCTL_VMMREQUESTwhich allows userspace to submit arbitrary vmmdev-requests. Note that the vboxguest driver does do several sanity checks on these, including limiting them to a specific list of allowed requests. But as said this does leak almost all of thevbox_vmmdev.hhardware interface into the userspace API.
Quoted 2 lines
I checked and
VBOXGUEST_IOCTL_VMMREQUESTis used in various places, so I cannot just drop it.
I see.
Quoted 13 lines
Quoted 11 lines
drivers/misc/vboxguest/vboxguest_linux.c
Quoted 6 lines
drivers/misc/vboxguest/vboxguest_linux.c new file +3
-0+#define VBOXGUEST_IOCTL_CODE (function, size) \ + VBOXGUEST_IOCTL_CODE_((function) | VBOXGUEST_IOCTL_FLAG, size) +/* Define 32 bit codes to support 32 bit applications in 64 bit guest driver. */
drivers/misc/vboxguest/vboxguest_linux.c new file +2
-0+#define VBOXGUEST_IOCTL_CODE_32 (function, size) \ +VBOXGUEST_IOCTL_CODE_(function, size)If the command numbers can be changed wihtout causing too many problems, I'd just do away with these wrappers and use _IOR/_IOW/_IORW as needed.
Quoted 5 lines
The upstream
vboxguest.hheader definesVBOXGUEST_IOCTL_CODEfor many different guest platforms. I guess not all of them have the _IOR/_IOW/_IORW flags embedded in the ioctl-code concept and I believe some of them only have a small amount of bits which can actually be used for the code, so we cannot just cram these flags in there.
Do you have a specific example? I think the BSDs and derived operating systems are actually much stricter with those flags than Linux is, and the macros I suggested originate in BSD.
Quoted 3 lines
I think that instead we need an
ioctl_direction_flagstable which can be used to determine if we need todo thecopy_from_userand friends, without changing the codes.
I would not bother with that. Either we fix the command codes to correctly reflect the direction, or we should actually copy the data both ways as the current implementation does.
Arnd
Re: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
Hi,
Quoted 46 lines · Arnd Bergmann
Quoted 45 lines · Hans de Goede
Quoted 29 lines · Arnd Bergmann
On Fri, Aug 11, 2017 at 3:23 PM, Hans de Goede <[email protected]> wrote:
Most of the issues I would normally comment on are already moot based on the assumption that we won't be able to make substantial changes to either the user space portion or the hypervisor side.Quoted 23 lines
(quoted diff) +16
-0+/** + * Inflate the balloon by one chunk. + * + * The caller owns the balloon mutex. + * + * @returns VBox status code + * @param gdev The Guest extension device. + * @param chunk_idx Index of the chunk. + */ +static int vbg_balloon_inflate(PVBOXGUESTDEVEXT gdev, u32 chunk_idx) +{ + VMMDevChangeMemBalloon *req = gdev->mem_balloon.change_req; + struct page **pages; + int i, rc; + + pages = kmalloc(sizeof(*pages) *
VMMDEV_MEMORY_BALLOON_CHUNK_PAGES,(quoted diff) +6
-0+ GFP_KERNEL | __GFP_NOWARN); + if (!pages) + return VERR_NO_MEMORY; + + req->header.size = sizeof(*req); + req->inflate = true;Quoted 8 lines
Quoted 1 line
+
req->pages=VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;The balloon section seems to be rather simplistic with its ioctl interface.
Ideally this should useCONFIG_BALLOON_COMPACTIONand an
oom notifier like thevirtio_balloondriver does. Yes, I realize that only one of the six (or more) balloon drivers we have in the kernel does it ;-)The way the balloon code works is that the baloon-size is fully controlled by the host, all the guest-additions do is wait for an event indicating that the host wants to change it and then call this ioctl which will get the desired balloon size from the host and tries to adjust the size accordingly.
Quoted 6 lines
Quoted 4 lines
Hooking into the oom killer is not really useful because there is no way we can indicate to the host we are running low on mem and I don't think that trying to shrink the balloon to be smaller then the host requested size is a good idea.
Are you sure the guest can't just claim the memory back by using it?
I don't think so the original code certainly does not do anything of the sorts, the balloon code uses alloc_page(GFP_KERNEL | __GFP_NOWARN) and only calls __free_page() again on the pages after a successful deflate request to the host.
So first we tell the host we want a chunk (1MiB worth of pages) back and only if the host says ok do we call __free_page which means it can get used for something else again.
Michael, Knut can you shed some light on this ?
Quoted 9 lines
Usually that is how the balloon drivers work: the host asks the guest to free up some memory, and the guest frees up memory that it tells to the host, but if the guest runs out of memory, it just starts using it again and the host faults in empty pages.
For
CONFIG_BALLOON_COMPACTION, you don't even need that, you just put some memory into the balloon before you take some other page out that is required for compaction. This might be less of an issue here when the balloon always operates on 1MB chunks.
<snip>
Quoted 34 lines
Quoted 34 lines
Quoted 16 lines
Quoted 10 lines
(quoted diff) +9
-0+ */ + if (cbData <= sizeof(au64Buf) && + VBOXGUEST_IOCTL_STRIP_SIZE(uCmd) != + VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_VMMREQUEST(0))) { + pvBufFree = NULL; + pvBuf = &au64Buf[0]; + } else { + /* __GFP_DMA32 for VBOXGUEST_IOCTL_VMMREQUEST */ + pvBufFree = pvBuf = kmalloc(cbData, GFP_KERNEL |
__GFP_DMA32);Review
Quoted 4 lines
(quoted diff) +4
-0+ if (!pvBuf) + return -ENOMEM; + } + if (copy_from_user(pvBuf, (void *)ulArg, cbData) == 0) {Quoted 4 lines
I'd also change the commands
to not always do both read and write, but only whichever applies. This function
would then do the copy_from_user/copy_to_user conditionally.This is actually an upstream TODO item I believe. One which would probably be best fixed by using _IOR/_IOW/_IORW IOCTL macros, but that needs to be coordinated with upstream.
Quoted 1 line
It would be good to clean this up and always use the same structure here.
The HGCMFunctionParameter struct describes function-parameters in a Host-Guest-Control-Method function call, so this is part of the host ABI interface and we cannot change this.
Quoted 6 lines
Quoted 2 lines
Any 32 bit apps running on a 64 bit kernel will be using the 32 bit version of this struct and we need to translate. >
I don't see the difference between changing the command codes and changing the structure layout here. In both cases, that is an incompatible ABI change but shouldn't much impact the source-level ABI if you do it right.
This struct is defined in vmmdev.h because it is part of the hardware interface, a 32 bit host expects the 32 bit version of the struct when calling into the host, where as a 64 bit host expects the 64 bit version.
The hgcm-call ioctl uses this struct _directly_, so a 64 bit app will pass in the 64 bit version and a 32 bit app the 32 bit version, and on 64 bit we need to translate the 32 bit version coming from a 32 bit app.
The only way around this would be to make userspace always see / use the 64 bit version but then we would need to always translate the structs back to their 32 bit version on 32 bit hosts, so we would still end up with a translation function and now we are calling it a lot more often.
Quoted 43 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
+ * The layout of VMMDEV RAM region that contains information for guest.
+ */(quoted diff) +8
-0+typedef struct VMMDevMemory { + /** The size of this structure. */ + u32 u32Size; + /** The structure version. (VMMDEV_MEMORY_VERSION) */ + u32 u32Version; + + union { + struct {Quoted 8 lines
Review
Quoted 5 lines
+ /** Flag telling that VMMDev has events pending.
*/(quoted diff) +3
-0+ bool fHaveEvents; + } V1_04; +As this is a hardware interface, maybe use u32 instead of 'bool'.
Quoted 8 lines
I guess that should work here, since we only every do "if (fHaveEvents)" but in other cases where we also set bool variables in the hardware interface structs we also need to know which bit(s) get set on true to move this over to non bool use.
I agree that the choice of bool in a (virtual) hardware interface is unfortunate, but we should not be trying to change the (virtual) hardware definition IMHO.
According to the x86 psABI (https://www.uclibc.org/docs/psABI-x86_64.pdf),
a_Boolshould be represented in memory like an 'unsigned char' but only contain the values 0 or 1 (the upper 7 bits are zero).Before linux-2.6.18, we defined 'bool' as 'typedef enum { false, true}
__packedbool;', which would make it a 32-bit integer that can take the values 0 and 1.Inside of the union, the two have the same binary layout on little-endian architectures, as the information is still stored in the low bit of the first of four bytes.
I think if you do
Quoted 8 lines
union { struct { /** Flag telling that VMMDev has events pending. */ u8 fHaveEvents; u8 pad[3]; } V1_04;that will be a portable representation if the existing ABI.
Ok, looking at the various VMMDEV_ASSERT_SIZE calls in there bool indeed seems to be u8, so I should be able to fix this.
Michael, Knut any input on this ? Do you want me to submit a similar change upstream ?
<snip>
Quoted 19 lines
Quoted 13 lines
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +3
-0+#define VBOXGUEST_IOCTL_CODE(function, size) \ + VBOXGUEST_IOCTL_CODE_((function) | VBOXGUEST_IOCTL_FLAG, size) +/* Define 32 bit codes to support 32 bit applications in 64 bit guestdriver. */
(quoted diff) +2
-0+#define VBOXGUEST_IOCTL_CODE_32(function, size) \ +VBOXGUEST_IOCTL_CODE_(function, size)If the command numbers can be changed wihtout causing too many problems, I'd just do away with these wrappers and use _IOR/_IOW/_IORW as needed.
Quoted 5 lines
The upstream
vboxguest.hheader definesVBOXGUEST_IOCTL_CODEfor many different guest platforms. I guess not all of them have the _IOR/_IOW/_IORW flags embedded in the ioctl-code concept and I believe some of them only have a small amount of bits which can actually be used for the code, so we cannot just cram these flags in there.
Quoted 3 lines
Do you have a specific example? I think the BSDs and derived operating systems are actually much stricter with those flags than Linux is, and the macros I suggested originate in BSD.
So the vbox-upstream header has this:
/** @name VBoxGuest IOCTL codes and structures.
*
* The range 0..15 is for basic driver communication.
* The range 16..31 is for HGCM communication.
* The range 32..47 is reserved for future use.
* The range 48..63 is for OS specific communication.
* The 7th bit is reserved for future hacks.
* The 8th bit is reserved for distinguishing between 32-bit and 64-bit
* processes in future 64-bit guest additions.
*
* @remarks When creating new IOCtl interfaces keep in mind that not all OSes supports
* reporting back the output size. (This got messed up a little bit in VBoxDrv.)
*
* The request size is also a little bit tricky as it's passed as part of the * request code on unix. The size field is 14 bits on Linux, 12 bits on *BSD, * 13 bits Darwin, and 8-bits on Solaris. All the BSDs and Darwin kernels * will make use of the size field, while Linux and Solaris will not. We're of * course using the size to validate and/or map/lock the request, so it has * to be valid. * * For Solaris we will have to do something special though, 255 isn't * sufficient for all we need. A 4KB restriction (BSD) is probably not * too problematic (yet) as a general one.
*
* More info can be found in SUPDRVIOC.h and related sources.
*
* @remarks If adding interfaces that only has input or only has output, some new macros
* needs to be created so the most efficient IOCtl data buffering method can be
* used.
* @{
*/
Reading this a second time I think that the reasons why there are no separate R / W / RW versions of the macros is because all current ioctls are RW and from the top of my mind (I've not done a full audit) that seems correct.
So yes we should be able to just use _IOWR instead of _IOC(_IOC_READ|_IOC_WRITE but depending on how discussion on the 64 bit flag goes we may still need a wrapper to add in the 64 bit flag, in which case not much will change.
Hmm, rereading the header I see that the 64 bit flag is not used everywhere, a bunch of ioctls use VBOXGUEST_IOCTL_CODE_ instead of VBOXGUEST_IOCTL_CODE, so they never get the flag (really 2 different macros with only a _ difference in name is a bad idea).
So the flag is only used on the following calls:
VBOXGUEST_IOCTL_GETVMMDEVPORT
VBOXGUEST_IOCTL_WRITE_CORE_DUMPVBOXGUEST_IOCTL_HGCM_CONNECTVBOXGUEST_IOCTL_HGCM_DISCONNECTVBOXGUEST_IOCTL_HGCM_CALLVBOXGUEST_IOCTL_HGCM_CALL_TIMED
VBOXGUEST_IOCTL_HGCM_CALL_USERDATAVBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACKVBOXGUEST_IOCTL_GUEST_CAPS_ACQUIRE
Of which the first one and the last 3 are not used under Linux.
So would could use _IOWR('V', ... directly for most of the ioctls and then keep the 64 bit flag and have:
VBOXGUEST_IOCTL_CODEVBOXGUEST_IOCTL_CODE32
Just for the HGCM calls.
Also I believe it would be good to move the following over to not using the 64 bit flag:
VBOXGUEST_IOCTL_WRITE_CORE_DUMPVBOXGUEST_IOCTL_GETVMMDEVPORTVBOXGUEST_IOCTL_HGCM_CALL_USERDATAVBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACKVBOXGUEST_IOCTL_GUEST_CAPS_ACQUIRE
Since they have no 32 bit equivalent. Michael, Knut would you be willing to take a patch moving those to using VBOXGUEST_IOCTL_CODE_ and thus not using the 64 bit flag?
Quoted 7 lines
Quoted 3 lines
I think that instead we need an
ioctl_direction_flagstable which can be used to determine if we need todo thecopy_from_userand friends, without changing the codes.I would not bother with that. Either we fix the command codes to correctly reflect the direction, or we should actually copy the data both ways as the current implementation does.
Ok.
Regards,
Hans
Re: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
Hi,
Quoted 56 lines · Hans de Goede
Hi,
Quoted 46 lines · Arnd Bergmann
Quoted 45 lines · Hans de Goede
Quoted 29 lines · Arnd Bergmann
On Fri, Aug 11, 2017 at 3:23 PM, Hans de Goede <[email protected]> wrote:
Most of the issues I would normally comment on are already moot based on the assumption that we won't be able to make substantial changes to either the user space portion or the hypervisor side.Quoted 23 lines
(quoted diff) +16
-0+/** + * Inflate the balloon by one chunk. + * + * The caller owns the balloon mutex. + * + * @returns VBox status code + * @param gdev The Guest extension device. + * @param chunk_idx Index of the chunk. + */ +static int vbg_balloon_inflate(PVBOXGUESTDEVEXT gdev, u32 chunk_idx) +{ + VMMDevChangeMemBalloon *req = gdev->mem_balloon.change_req; + struct page **pages; + int i, rc; + + pages = kmalloc(sizeof(*pages) *
VMMDEV_MEMORY_BALLOON_CHUNK_PAGES,(quoted diff) +6
-0+ GFP_KERNEL | __GFP_NOWARN); + if (!pages) + return VERR_NO_MEMORY; + + req->header.size = sizeof(*req); + req->inflate = true;Quoted 8 lines
Quoted 1 line
+
req->pages=VMMDEV_MEMORY_BALLOON_CHUNK_PAGES;The balloon section seems to be rather simplistic with its ioctl interface.
Ideally this should useCONFIG_BALLOON_COMPACTIONand an
oom notifier like thevirtio_balloondriver does. Yes, I realize that only one of the six (or more) balloon drivers we have in the kernel does it ;-)The way the balloon code works is that the baloon-size is fully controlled by the host, all the guest-additions do is wait for an event indicating that the host wants to change it and then call this ioctl which will get the desired balloon size from the host and tries to adjust the size accordingly.
Quoted 6 lines
Quoted 4 lines
Hooking into the oom killer is not really useful because there is no way we can indicate to the host we are running low on mem and I don't think that trying to shrink the balloon to be smaller then the host requested size is a good idea.
Are you sure the guest can't just claim the memory back by using it?
Quoted 8 lines
I don't think so the original code certainly does not do anything of the sorts, the balloon code uses
alloc_page(GFP_KERNEL | __GFP_NOWARN)and only calls__free_page()again on the pages after a successful deflate request to the host.So first we tell the host we want a chunk (1MiB worth of pages) back and only if the host says ok do we call
__free_pagewhich means it can get used for something else again.
Ok, so while working on the final cleanups of the code I realized that the kernel driver will actually re-claim the memory without the host indicating that this is ok when the vboxservice which monitors for host events to change the balloon size dies. When it dies the kernel tries to reclaim all the memory from the host and this seems to work fine.
So we could hook up to an OOM signal and try to reclaim some memory here then, but the out-of-tree version of the driver does not do this.
Michael, Knut, what is the intended behavior of the kernel here?
I'm also thinking that under Linux since we never use userspace to alloc memory for the balloon, we don't need to involve userspace at all, the drivers interrupt handler could detect the event that the host wants to change the balloonsize itself and start a workqueue item which then asks for what the new size should be and do the adjustment all inside the kernel. I think that will even lead to simpler code as we no longer need to track the balloon userspace owner and do reclaim when it dies.
Typing this out I really see no reason to not do this inside the kernel, so I think I'm going to implement that right away / for the [RFC v2] I plan to post later today or tomorrow.
Regards,
Hans
Quoted 254 lines
Michael, Knut can you shed some light on this ?
Quoted 9 lines
Usually that is how the balloon drivers work: the host asks the guest to free up some memory, and the guest frees up memory that it tells to the host, but if the guest runs out of memory, it just starts using it again and the host faults in empty pages.
For
CONFIG_BALLOON_COMPACTION, you don't even need that, you just put some memory into the balloon before you take some other page out that is required for compaction. This might be less of an issue here when the balloon always operates on 1MB chunks.<snip>
Quoted 34 lines
Quoted 34 lines
Quoted 16 lines
Quoted 10 lines
(quoted diff) +9
-0+ */ + if (cbData <= sizeof(au64Buf) && + VBOXGUEST_IOCTL_STRIP_SIZE(uCmd) != + VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_VMMREQUEST(0))) { + pvBufFree = NULL; + pvBuf = &au64Buf[0]; + } else { + /* __GFP_DMA32 for VBOXGUEST_IOCTL_VMMREQUEST */ + pvBufFree = pvBuf = kmalloc(cbData, GFP_KERNEL |
__GFP_DMA32);Review
Quoted 4 lines
(quoted diff) +4
-0+ if (!pvBuf) + return -ENOMEM; + } + if (copy_from_user(pvBuf, (void *)ulArg, cbData) == 0) {Quoted 4 lines
I'd also change the commands
to not always do both read and write, but only whichever applies. This function
would then do the copy_from_user/copy_to_user conditionally.This is actually an upstream TODO item I believe. One which would probably be best fixed by using _IOR/_IOW/_IORW IOCTL macros, but that needs to be coordinated with upstream.
Quoted 1 line
It would be good to clean this up and always use the same structure here.
The HGCMFunctionParameter struct describes function-parameters in a Host-Guest-Control-Method function call, so this is part of the host ABI interface and we cannot change this.
Quoted 6 lines
Quoted 2 lines
Any 32 bit apps running on a 64 bit kernel will be using the 32 bit version of this struct and we need to translate. >
I don't see the difference between changing the command codes and changing the structure layout here. In both cases, that is an incompatible ABI change but shouldn't much impact the source-level ABI if you do it right.
This struct is defined in
vmmdev.hbecause it is part of the hardware interface, a 32 bit host expects the 32 bit version of the struct when calling into the host, where as a 64 bit host expects the 64 bit version.The hgcm-call ioctl uses this struct _directly_, so a 64 bit app will pass in the 64 bit version and a 32 bit app the 32 bit version, and on 64 bit we need to translate the 32 bit version coming from a 32 bit app.
The only way around this would be to make userspace always see / use the 64 bit version but then we would need to always translate the structs back to their 32 bit version on 32 bit hosts, so we would still end up with a translation function and now we are calling it a lot more often.
Quoted 43 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
+ * The layout of VMMDEV RAM region that contains information for guest.
+ */(quoted diff) +8
-0+typedef struct VMMDevMemory { + /** The size of this structure. */ + u32 u32Size; + /** The structure version. (VMMDEV_MEMORY_VERSION) */ + u32 u32Version; + + union { + struct {Quoted 8 lines
Review
Quoted 5 lines
+ /** Flag telling that VMMDev has events pending.
*/(quoted diff) +3
-0+ bool fHaveEvents; + } V1_04; +As this is a hardware interface, maybe use u32 instead of 'bool'.
Quoted 8 lines
I guess that should work here, since we only every do "if (fHaveEvents)" but in other cases where we also set bool variables in the hardware interface structs we also need to know which bit(s) get set on true to move this over to non bool use.
I agree that the choice of bool in a (virtual) hardware interface is unfortunate, but we should not be trying to change the (virtual) hardware definition IMHO.
According to the x86 psABI (https://www.uclibc.org/docs/psABI-x86_64.pdf),
a_Boolshould be represented in memory like an 'unsigned char' but only contain the values 0 or 1 (the upper 7 bits are zero).Before linux-2.6.18, we defined 'bool' as 'typedef enum { false, true}
__packedbool;', which would make it a 32-bit integer that can take the values 0 and 1.Inside of the union, the two have the same binary layout on little-endian architectures, as the information is still stored in the low bit of the first of four bytes.
I think if you do
Quoted 8 lines
union { struct { /** Flag telling that VMMDev has events pending. */ u8 fHaveEvents; u8 pad[3]; } V1_04;that will be a portable representation if the existing ABI.
Ok, looking at the various
VMMDEV_ASSERT_SIZEcalls in there bool indeed seems to be u8, so I should be able to fix this.Michael, Knut any input on this ? Do you want me to submit a similar change upstream ?
<snip>
Quoted 19 lines
Quoted 13 lines
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +3
-0+#define VBOXGUEST_IOCTL_CODE(function, size) \ + VBOXGUEST_IOCTL_CODE_((function) | VBOXGUEST_IOCTL_FLAG, size) +/* Define 32 bit codes to support 32 bit applications in 64 bit guestdriver. */
(quoted diff) +2
-0+#define VBOXGUEST_IOCTL_CODE_32(function, size) \ +VBOXGUEST_IOCTL_CODE_(function, size)If the command numbers can be changed wihtout causing too many problems, I'd just do away with these wrappers and use _IOR/_IOW/_IORW as needed.
Quoted 5 lines
The upstream
vboxguest.hheader definesVBOXGUEST_IOCTL_CODEfor many different guest platforms. I guess not all of them have the _IOR/_IOW/_IORW flags embedded in the ioctl-code concept and I believe some of them only have a small amount of bits which can actually be used for the code, so we cannot just cram these flags in there.Quoted 3 lines
Do you have a specific example? I think the BSDs and derived operating systems are actually much stricter with those flags than Linux is, and the macros I suggested originate in BSD.
So the vbox-upstream header has this:
/** @name VBoxGuest IOCTL codes and structures.
*
* The range 0..15 is for basic driver communication.
* The range 16..31 is for HGCM communication.
* The range 32..47 is reserved for future use.
* The range 48..63 is for OS specific communication.
* The 7th bit is reserved for future hacks.
* The 8th bit is reserved for distinguishing between 32-bit and 64-bit
* processes in future 64-bit guest additions.
*
* @remarks When creating new IOCtl interfaces keep in mind that not all OSes supports
* reporting back the output size. (This got messed up a little bit in VBoxDrv.)
** The request size is also a little bit tricky as it's passed as part of the * request code on unix. The size field is 14 bits on Linux, 12 bits on *BSD, * 13 bits Darwin, and 8-bits on Solaris. All the BSDs and Darwin kernels * will make use of the size field, while Linux and Solaris will not. We're of * course using the size to validate and/or map/lock the request, so it has * to be valid. * * For Solaris we will have to do something special though, 255 isn't * sufficient for all we need. A 4KB restriction (BSD) is probably not * too problematic (yet) as a general one.*
* More info can be found inSUPDRVIOC.hand related sources.
*
* @remarks If adding interfaces that only has input or only has output, some new macros
* needs to be created so the most efficient IOCtl data buffering method can be
* used.
* @{
*/Reading this a second time I think that the reasons why there are no separate R / W / RW versions of the macros is because all current ioctls are RW and from the top of my mind (I've not done a full audit) that seems correct.
So yes we should be able to just use
_IOWRinstead of _IOC(_IOC_READ|_IOC_WRITE but depending on how discussion on the 64 bit flag goes we may still need a wrapper to add in the 64 bit flag, in which case not much will change.Hmm, rereading the header I see that the 64 bit flag is not used everywhere, a bunch of ioctls use
VBOXGUEST_IOCTL_CODE_instead ofVBOXGUEST_IOCTL_CODE, so they never get the flag (really 2 different macros with only a _ difference in name is a bad idea).So the flag is only used on the following calls:
VBOXGUEST_IOCTL_GETVMMDEVPORT
VBOXGUEST_IOCTL_WRITE_CORE_DUMPVBOXGUEST_IOCTL_HGCM_CONNECTVBOXGUEST_IOCTL_HGCM_DISCONNECTVBOXGUEST_IOCTL_HGCM_CALLVBOXGUEST_IOCTL_HGCM_CALL_TIMED
VBOXGUEST_IOCTL_HGCM_CALL_USERDATAVBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACKVBOXGUEST_IOCTL_GUEST_CAPS_ACQUIREOf which the first one and the last 3 are not used under Linux.
So would could use _IOWR('V', ... directly for most of the ioctls and then keep the 64 bit flag and have:
VBOXGUEST_IOCTL_CODEVBOXGUEST_IOCTL_CODE32Just for the HGCM calls.
Also I believe it would be good to move the following over to not using the 64 bit flag:
VBOXGUEST_IOCTL_WRITE_CORE_DUMPVBOXGUEST_IOCTL_GETVMMDEVPORTVBOXGUEST_IOCTL_HGCM_CALL_USERDATAVBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACKVBOXGUEST_IOCTL_GUEST_CAPS_ACQUIRESince they have no 32 bit equivalent. Michael, Knut would you be willing to take a patch moving those to using
VBOXGUEST_IOCTL_CODE_and thus not using the 64 bit flag?Quoted 7 lines
Quoted 3 lines
I think that instead we need an
ioctl_direction_flagstable which can be used to determine if we need todo thecopy_from_userand friends, without changing the codes.I would not bother with that. Either we fix the command codes to correctly reflect the direction, or we should actually copy the data both ways as the current implementation does.
Ok.
Regards,
Hans
Re: [RFC 1/2] misc: Add vboxguest driver for Virtual Box Guest integration
Hi,
On 21-08-17 13:43, Hans de Goede wrote:
<snip>
Quoted 9 lines
I'm also thinking that under Linux since we never use userspace to alloc memory for the balloon, we don't need to involve userspace at all, the drivers interrupt handler could detect the event that the host wants to change the balloonsize itself and start a workqueue item which then asks for what the new size should be and do the adjustment all inside the kernel. I think that will even lead to simpler code as we no longer need to track the balloon userspace owner and do reclaim when it dies.
Quoted 3 lines
Typing this out I really see no reason to not do this inside the kernel, so I think I'm going to implement that right away / for the [RFC v2] I plan to post later today or tomorrow.
Done:
https://github.com/jwrdegoede/vboxguest/commit/2920882cb0ce9af11a843affc58d4a08ef47e16b
Regards,
Hans
RFC 2/2 fs: Add VirtualBox guest shared folder (vboxsf) support
In reply to Hans de GoedeVirtualBox hosts can share folders with guests, this commit adds a VFS driver implementing the Linux-guest side of this, allowing folders exported by the host to be mounted under Linux.
This driver depends on the guest <-> host IPC functions exported by the vboxguest driver.
--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/vboxsf/Kconfig | 9 + fs/vboxsf/Makefile | 3 + fs/vboxsf/dirops.c | 730 ++++++++++++++++++++++++ fs/vboxsf/lnkops.c | 41 ++ fs/vboxsf/regops.c | 557 ++++++++++++++++++ fs/vboxsf/shfl_hostintf.h | 1318 +++++++++++++++++++++++++++++++++++++++++++ fs/vboxsf/utils.c | 671 ++++++++++++++++++++++ fs/vboxsf/vboxsf_wrappers.c | 542 ++++++++++++++++++ fs/vboxsf/vboxsf_wrappers.h | 104 ++++ fs/vboxsf/vbsfmount.h | 69 +++ fs/vboxsf/vfsmod.c | 412 ++++++++++++++ fs/vboxsf/vfsmod.h | 111 ++++ 14 files changed, 4569 insertions(+) create mode 100644 fs/vboxsf/Kconfig create mode 100644 fs/vboxsf/Makefile create mode 100644 fs/vboxsf/dirops.c create mode 100644 fs/vboxsf/lnkops.c create mode 100644 fs/vboxsf/regops.c create mode 100644 fs/vboxsf/shfl_hostintf.h create mode 100644 fs/vboxsf/utils.c create mode 100644 fs/vboxsf/vboxsf_wrappers.c create mode 100644 fs/vboxsf/vboxsf_wrappers.h create mode 100644 fs/vboxsf/vbsfmount.h create mode 100644 fs/vboxsf/vfsmod.c create mode 100644 fs/vboxsf/vfsmod.h
fs/Kconfig +1 -0
@@ -248,6 +248,7 @@ source "fs/pstore/Kconfig" source "fs/sysv/Kconfig" source "fs/ufs/Kconfig" source "fs/exofs/Kconfig" +source "fs/vboxsf/Kconfig" endif # MISC_FILESYSTEMS
fs/Makefile +1 -0
@@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules obj-$(CONFIG_CEPH_FS) += ceph/ obj-$(CONFIG_PSTORE) += pstore/ obj-$(CONFIG_EFIVAR_FS) += efivarfs/ +obj-$(CONFIG_VBOXSF_FS) += vboxsf/
fs/vboxsf/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +config VBOXSF_FS + tristate "VirtualBox guest shared folder (vboxsf) support" + depends on VBOXGUEST + help + VirtualBox hosts can share folders with guests, this driver + implements the Linux-guest side of this allowing folders exported + by the host to be mounted under Linux. + + If you want to use shared folders in VirtualBox guests, answer Y or M.
fs/vboxsf/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_VBOXSF_FS) += vboxsf.o + +vboxsf-objs := dirops.o lnkops.o regops.o utils.o vboxsf_wrappers.o vfsmod.o
fs/vboxsf/dirops.c new file +730 -0
730 lines not on this page · raw message
fs/vboxsf/lnkops.c new file +41 -0
41 lines not on this page · raw message
fs/vboxsf/regops.c new file +557 -0
557 lines not on this page · raw message
fs/vboxsf/shfl_hostintf.h new file +1318 -0
1,318 lines not on this page · raw message
fs/vboxsf/utils.c new file +671 -0
331 lines not on this page · raw message
fs/vboxsf/vboxsf_wrappers.c new file +542 -0
542 lines not on this page · raw message
fs/vboxsf/vboxsf_wrappers.h new file +104 -0
104 lines not on this page · raw message
fs/vboxsf/vbsfmount.h new file +69 -0
69 lines not on this page · raw message
fs/vboxsf/vfsmod.c new file +412 -0
412 lines not on this page · raw message
fs/vboxsf/vfsmod.h new file +111 -0
111 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.3
Part of the diff is not shown here. View the raw message.
Greg Kroah-Hartman
maintainerQuoted 28 lines · Hans de Goede
Hello Greg, Arnd, Alexander, et al.,
Here is a first RFC version of my cleaned up version of the VirtualBox vboxguest and vboxsf guest drivers.
This is an RFC because there are still some checkpatch and other small style issues which I need to fix.
I'm posting this now because the majority of the major cleanup these 2 drivers needed before being suitable for mainlining has been done now and I believe the code is ready for a quick look by others (but not ready yet for a full review).
I've removed all depenencies on vbox's OO-independent runtime and the runtime itself, reducing the vboxguest driver from 100000+ lines of code to aprox. 6500 and the vboxsf driver from 60000 lines to 5000. This reduces the non debug vboxguest.ko size from 450kB to less then 100 kB. I've also cleaned up various other warts such as doing hardware init in
module_initrather then in apci_probecallback.The vboxguest driver introduces a new userspace API + ABI in the form of ioctls on a character device. VirtualBox upstream not willing to commit to keeping this ABI stable was one of the things which has kept this driver driver out of mainline sofar. I've been talking to VirtualBox upstream about mainlining the guest drivers and VirtualBox upstream has agreed to consider the userspace ABI stable and only extend it in a backwards compatible manner.
Quoted 6 lines
As said this is a RFC, the main comments I'm looking for is an answer to these 2 questions:
Greg, Arnd would you be willing to merge the vboxguest driver under
drivers/misc(in principle), assuming I do the remaining cleanup and the driver gets a favorable review of course ?
I have no objection to taking it there at all.
thanks,
greg k-h
Arnd Bergmann
maintainerQuoted 7 lines · Hans de Goede
The vboxguest driver introduces a new userspace API + ABI in the form of ioctls on a character device. VirtualBox upstream not willing to commit to keeping this ABI stable was one of the things which has kept this driver driver out of mainline sofar. I've been talking to VirtualBox upstream about mainlining the guest drivers and VirtualBox upstream has agreed to consider the userspace ABI stable and only extend it in a backwards compatible manner.
Can you clarify which ioctl interface they agreed to? Would they only keep the one that the proposed driver implements today, or the one we end up with after a full review? ;-)
Quoted 8 lines
As said this is a RFC, the main comments I'm looking for is an answer to these 2 questions:
Greg, Arnd would you be willing to merge the vboxguest driver under
drivers/misc(in principle), assuming I do the remaining cleanup and the driver gets a favorable review of course ?Al, the same question for you for the vboxsf (shared folder) driver?
I think these drivers should be part of the kernel, but I see drivers/misc/ as a last resort location for things that don't fit anywhere else. In this case, would maybe drivers/platform/vbox or drivers/firmware/vbox be better?
For vboxsf, putting it in fs/vboxsf as your patch does seems fine.
Arnd
Hi,
Quoted 10 lines · Arnd Bergmann
Quoted 7 lines · Hans de Goede
The vboxguest driver introduces a new userspace API + ABI in the form of ioctls on a character device. VirtualBox upstream not willing to commit to keeping this ABI stable was one of the things which has kept this driver driver out of mainline sofar. I've been talking to VirtualBox upstream about mainlining the guest drivers and VirtualBox upstream has agreed to consider the userspace ABI stable and only extend it in a backwards compatible manner.
Quoted 3 lines
Can you clarify which ioctl interface they agreed to? Would they only keep the one that the proposed driver implements today, or the one we end up with after a full review? ;-)
Given that there are a lot of users already using the existing interface more the former (the proposed driver implements today) then the latter.
But for now they assume that the userspace and kernel module versions are always in sync, so some small fixes might be possible. Some questions from me about unclear behavior of one ioctl command have already let to one small fix. But in general given the long out of tree history of this driver the interface is something which will be hard to change.
Quoted 11 lines
Quoted 8 lines
As said this is a RFC, the main comments I'm looking for is an answer to these 2 questions:
Greg, Arnd would you be willing to merge the vboxguest driver under
drivers/misc(in principle), assuming I do the remaining cleanup and the driver gets a favorable review of course ?Al, the same question for you for the vboxsf (shared folder) driver?
I think these drivers should be part of the kernel, but I see
drivers/misc/as a last resort location for things that don't fit anywhere else.
I ended up using drivers/misc because that is where the vmware drivers are.
Quoted 2 lines
In this case,
would maybedrivers/platform/vboxordrivers/firmware/vboxbe better?
Definitely not drivers/firmware that feels wrong (the driver talks to a pci device), I personally think adding a new dir under drivers/platform for just the single driver is overkill.
Regards,
hans
Arnd Bergmann
maintainerQuoted 6 lines · Hans de Goede
Quoted 3 lines · Arnd Bergmann
Can you clarify which ioctl interface they agreed to? Would they only keep the one that the proposed driver implements today, or the one we end up with after a full review? ;-)
Quoted 8 lines
Given that there are a lot of users already using the existing interface more the former (the proposed driver implements today) then the latter.
But for now they assume that the userspace and kernel module versions are always in sync, so some small fixes might be possible. Some questions from me about unclear behavior of one ioctl command have already let to one small fix. But in general given the long out of tree history of this driver the interface is something which will be hard to change.
Ok.
Quoted 8 lines
Quoted 3 lines
I think these drivers should be part of the kernel, but I see
drivers/misc/
as a last resort location for things that don't fit anywhere else.I ended up using
drivers/miscbecause that is where the vmware drivers are.
Quoted 7 lines
Quoted 2 lines
In this case,
would maybedrivers/platform/vboxordrivers/firmware/vboxbe better?Definitely not
drivers/firmwarethat feels wrong (the driver talks to a pci device), I personally think adding a new dir underdrivers/platformfor just the single driver is overkill.
Actually we have a lot of different places already. I wasn't aware of drivers/misc/vmw_vmci/, then we also have drivers/xen, drivers/hv drivers/lguest and drivers/virtio for hypervisor specific interfaces, and there is drivers/virt/fsl_hypervisor.c.
In drivers/firmware, we have a couple of similar things, mostly for ARM Trustzone based firmware which has a lot in common with a hypervisor.
How about adding it to drivers/virt/ then?
Arnd
Hi,
Quoted 39 lines · Arnd Bergmann
Quoted 6 lines · Hans de Goede
Quoted 3 lines · Arnd Bergmann
Can you clarify which ioctl interface they agreed to? Would they only keep the one that the proposed driver implements today, or the one we end up with after a full review? ;-)
Quoted 8 lines
Given that there are a lot of users already using the existing interface more the former (the proposed driver implements today) then the latter.
But for now they assume that the userspace and kernel module versions are always in sync, so some small fixes might be possible. Some questions from me about unclear behavior of one ioctl command have already let to one small fix. But in general given the long out of tree history of this driver the interface is something which will be hard to change.
Ok.
Quoted 8 lines
Quoted 3 lines
I think these drivers should be part of the kernel, but I see
drivers/misc/
as a last resort location for things that don't fit anywhere else.I ended up using
drivers/miscbecause that is where the vmware drivers are.Quoted 7 lines
Quoted 2 lines
In this case,
would maybedrivers/platform/vboxordrivers/firmware/vboxbe better?Definitely not
drivers/firmwarethat feels wrong (the driver talks to a pci device), I personally think adding a new dir underdrivers/platformfor just the single driver is overkill.Actually we have a lot of different places already. I wasn't aware of
drivers/misc/vmw_vmci/, then we also havedrivers/xen,drivers/hvdrivers/lguestanddrivers/virtiofor hypervisor specific interfaces, and there isdrivers/virt/fsl_hypervisor.c.
Quoted 5 lines
In
drivers/firmware, we have a couple of similar things, mostly for ARM Trustzone based firmware which has a lot in common with a hypervisor.How about adding it to
drivers/virt/then?
That as actually my first choice, but there is only the 1 driver there now, so I was thinking that we should move that 1 driver out of there and get rid of it actually :)
But as said it was my first choice, so maybe it should go there and then over time we can move all the things you've listed there (assuming anyone finds the time to do this).
One issues with drivers/virt is no-one is listed for it in MAINTAINERS...
Regards,
Hans
Arnd Bergmann
maintainerQuoted 11 lines · Hans de Goede
Quoted 4 lines · Arnd Bergmann
Quoted 1 line · Hans de Goede
On 11-08-17 18:02, Arnd Bergmann wrote:
How about adding it to
drivers/virt/then?That as actually my first choice, but there is only the 1 driver there now, so I was thinking that we should move that 1 driver out of there and get rid of it actually :)
Quoted 5 lines
But as said it was my first choice, so maybe it should go there and then over time we can move all the things you've listed there (assuming anyone finds the time to do this).
One issues with
drivers/virtis no-one is listed for it inMAINTAINERS...
Maybe we could add it to the "CHAR and MISC DRIVERS" section in the absence of any other subsystem for it, if you want a well-defined path for where to send patches. Or you could become maintainer for the directory ;-)
I wouldn't move virtio, hyperv etc here, as they are large enough to be subsystems of their own, but we could move the vmw_vmci from drivers/misc to drivers/virt and have three drivers to make up something of a subsystem. It is already in the "char and misc" group and has no direct MAINTAINERS entry.
Arnd
Hi,
Quoted 16 lines · Arnd Bergmann
Quoted 15 lines · Hans de Goede
Quoted 4 lines · Arnd Bergmann
Quoted 1 line · Hans de Goede
On 11-08-17 18:02, Arnd Bergmann wrote:
How about adding it to
drivers/virt/then?That as actually my first choice, but there is only the 1 driver there now, so I was thinking that we should move that 1 driver out of there and get rid of it actually :)
But as said it was my first choice, so maybe it should go there and then over time we can move all the things you've listed there (assuming anyone finds the time to do this).
Quoted 5 lines
Quoted 1 line
One issues with
drivers/virtis no-one is listed for it inMAINTAINERS...Maybe we could add it to the "CHAR and MISC DRIVERS" section in the absence of any other subsystem for it, if you want a well-defined path for where to send patches.
That sounds like a good plan, I will send out a MAINTAINERS patch adding drivers/misc/* to the files list for the "CHAR and MISC DRIVERS" section.
Regards,
Hans