Differential D16119 Diff 105825 emulators/virtualbox-ose/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
Changeset View
Changeset View
Standalone View
Standalone View
emulators/virtualbox-ose/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
--- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig 2021-10-18 17:58:03 UTC | --- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig 2021-10-18 10:58:03.000000000 -0700 | ||||
+++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c | +++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c 2021-11-19 15:31:33.152269000 -0800 | ||||
@@ -44,8 +44,10 @@ | @@ -44,8 +44,10 @@ | ||||
#include <sys/fcntl.h> | #include <sys/fcntl.h> | ||||
#include <sys/conf.h> | #include <sys/conf.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
+#include <sys/mutex.h> | +#include <sys/mutex.h> | ||||
#include "../SUPDrvInternal.h" | #include "../SUPDrvInternal.h" | ||||
+#include "freebsd/the-freebsd-kernel.h" | +#include "freebsd/the-freebsd-kernel.h" | ||||
Show All 20 Lines | |||||
static void vboxdrvFreeBSDDtr(void *pvData); | static void vboxdrvFreeBSDDtr(void *pvData); | ||||
static d_ioctl_t VBoxDrvFreeBSDIOCtl; | static d_ioctl_t VBoxDrvFreeBSDIOCtl; | ||||
+static d_ioctl_t VBoxDrvFreeBSDIOCtlSMAP; | +static d_ioctl_t VBoxDrvFreeBSDIOCtlSMAP; | ||||
static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd); | static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd); | ||||
+static bool VBoxDrvFreeBSDCpuHasSMAP(void); | +static bool VBoxDrvFreeBSDCpuHasSMAP(void); | ||||
/********************************************************************************************************************************* | /********************************************************************************************************************************* | ||||
@@ -182,6 +193,13 @@ static int VBoxDrvFreeBSDLoad(void) | @@ -93,7 +104,8 @@ static moduledata_t g_VBoxDrvFreeBSDModule = | ||||
}; | |||||
/** Declare the module as a pseudo device. */ | |||||
-DECLARE_MODULE(vboxdrv, g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY); | |||||
+#define KERNEL_RELBRANCHEND (roundup(__FreeBSD_version, 500) - 1) | |||||
+DECLARE_MODULE_WITH_MAXVER(vboxdrv, g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY, KERNEL_RELBRANCHEND); | |||||
MODULE_VERSION(vboxdrv, 1); | |||||
/** | |||||
@@ -182,6 +194,13 @@ static int VBoxDrvFreeBSDLoad(void) | |||||
rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION)); | rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION)); | ||||
if (RT_SUCCESS(rc)) | if (RT_SUCCESS(rc)) | ||||
{ | { | ||||
+ if (VBoxDrvFreeBSDCpuHasSMAP()) | + if (VBoxDrvFreeBSDCpuHasSMAP()) | ||||
+ { | + { | ||||
+ LogRel(("disabling SMAP for VBoxDrvFreeBSDIOCtl\n")); | + LogRel(("disabling SMAP for VBoxDrvFreeBSDIOCtl\n")); | ||||
+ g_VBoxDrvFreeBSDChrDevSwSys.d_ioctl = VBoxDrvFreeBSDIOCtlSMAP; | + g_VBoxDrvFreeBSDChrDevSwSys.d_ioctl = VBoxDrvFreeBSDIOCtlSMAP; | ||||
+ g_VBoxDrvFreeBSDChrDevSwUsr.d_ioctl = VBoxDrvFreeBSDIOCtlSMAP; | + g_VBoxDrvFreeBSDChrDevSwUsr.d_ioctl = VBoxDrvFreeBSDIOCtlSMAP; | ||||
+ } | + } | ||||
+ | + | ||||
/* | /* | ||||
* Configure character devices. Add symbolic links for compatibility. | * Configure character devices. Add symbolic links for compatibility. | ||||
*/ | */ | ||||
@@ -324,6 +342,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo | @@ -324,6 +343,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo | ||||
/** | /** | ||||
+ * Alternative Device I/O Control entry point on hosts with SMAP support. | + * Alternative Device I/O Control entry point on hosts with SMAP support. | ||||
+ * | + * | ||||
+ * @returns depends... | + * @returns depends... | ||||
+ * @param pDev The device. | + * @param pDev The device. | ||||
+ * @param ulCmd The command. | + * @param ulCmd The command. | ||||
Show All 29 Lines | |||||
+ return rc; | + return rc; | ||||
+} | +} | ||||
+ | + | ||||
+ | + | ||||
+/** | +/** | ||||
* Deal with the 'slow' I/O control requests. | * Deal with the 'slow' I/O control requests. | ||||
* | * | ||||
* @returns 0 on success, appropriate errno on failure. | * @returns 0 on success, appropriate errno on failure. | ||||
@@ -372,11 +429,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes | @@ -372,11 +430,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes | ||||
*/ | */ | ||||
SUPREQHDR Hdr; | SUPREQHDR Hdr; | ||||
pvUser = *(void **)pvData; | pvUser = *(void **)pvData; | ||||
- int rc = copyin(pvUser, &Hdr, sizeof(Hdr)); | - int rc = copyin(pvUser, &Hdr, sizeof(Hdr)); | ||||
- if (RT_UNLIKELY(rc)) | - if (RT_UNLIKELY(rc)) | ||||
+ if (RT_FAILURE(RTR0MemUserCopyFrom(&Hdr, pvUser, sizeof(Hdr)))) | + if (RT_FAILURE(RTR0MemUserCopyFrom(&Hdr, pvUser, sizeof(Hdr)))) | ||||
{ | { | ||||
- OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,) -> %#x; ulCmd=%#lx\n", pvUser, rc, ulCmd)); | - OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,) -> %#x; ulCmd=%#lx\n", pvUser, rc, ulCmd)); | ||||
- return rc; | - return rc; | ||||
+ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,); ulCmd=%#lx\n", pvUser, ulCmd)); | + OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,); ulCmd=%#lx\n", pvUser, ulCmd)); | ||||
+ return EFAULT; | + return EFAULT; | ||||
} | } | ||||
if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC)) | if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC)) | ||||
{ | { | ||||
@@ -401,13 +457,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes | @@ -401,13 +458,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes | ||||
OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd)); | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd)); | ||||
return ENOMEM; | return ENOMEM; | ||||
} | } | ||||
- rc = copyin(pvUser, pHdr, Hdr.cbIn); | - rc = copyin(pvUser, pHdr, Hdr.cbIn); | ||||
- if (RT_UNLIKELY(rc)) | - if (RT_UNLIKELY(rc)) | ||||
+ if (RT_FAILURE(RTR0MemUserCopyFrom(pHdr, pvUser, Hdr.cbIn))) | + if (RT_FAILURE(RTR0MemUserCopyFrom(pHdr, pvUser, Hdr.cbIn))) | ||||
{ | { | ||||
- OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x) -> %#x; ulCmd=%#lx\n", | - OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x) -> %#x; ulCmd=%#lx\n", | ||||
- pvUser, pHdr, Hdr.cbIn, rc, ulCmd)); | - pvUser, pHdr, Hdr.cbIn, rc, ulCmd)); | ||||
+ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x); ulCmd=%#lx\n", | + OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x); ulCmd=%#lx\n", | ||||
+ pvUser, pHdr, Hdr.cbIn, ulCmd)); | + pvUser, pHdr, Hdr.cbIn, ulCmd)); | ||||
RTMemTmpFree(pHdr); | RTMemTmpFree(pHdr); | ||||
- return rc; | - return rc; | ||||
+ return EFAULT; | + return EFAULT; | ||||
} | } | ||||
if (Hdr.cbIn < cbReq) | if (Hdr.cbIn < cbReq) | ||||
RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn); | RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn); | ||||
@@ -435,9 +490,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes | @@ -435,9 +491,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes | ||||
OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd)); | OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd)); | ||||
cbOut = cbReq; | cbOut = cbReq; | ||||
} | } | ||||
- rc = copyout(pHdr, pvUser, cbOut); | - rc = copyout(pHdr, pvUser, cbOut); | ||||
- if (RT_UNLIKELY(rc)) | - if (RT_UNLIKELY(rc)) | ||||
- OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x) -> %d; uCmd=%#lx!\n", pHdr, pvUser, cbOut, rc, ulCmd)); | - OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x) -> %d; uCmd=%#lx!\n", pHdr, pvUser, cbOut, rc, ulCmd)); | ||||
+ if (RT_FAILURE(RTR0MemUserCopyTo(pvUser, pHdr, cbOut))) | + if (RT_FAILURE(RTR0MemUserCopyTo(pvUser, pHdr, cbOut))) | ||||
+ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x); uCmd=%#lx!\n", pHdr, pvUser, cbOut, ulCmd)); | + OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x); uCmd=%#lx!\n", pHdr, pvUser, cbOut, ulCmd)); | ||||
Log(("VBoxDrvFreeBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd)); | Log(("VBoxDrvFreeBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd)); | ||||
@@ -540,8 +594,7 @@ bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDE | @@ -540,8 +595,7 @@ bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDE | ||||
bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void) | bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void) | ||||
{ | { | ||||
- /** @todo verify this. */ | - /** @todo verify this. */ | ||||
- return false; | - return false; | ||||
+ return true; | + return true; | ||||
} | } | ||||
@@ -624,19 +677,43 @@ int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, | @@ -624,19 +678,43 @@ int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, | ||||
#endif /* SUPDRV_WITH_MSR_PROBER */ | #endif /* SUPDRV_WITH_MSR_PROBER */ | ||||
+/** | +/** | ||||
+ * Check if the CPU has SMAP support. | + * Check if the CPU has SMAP support. | ||||
+ */ | + */ | ||||
+static bool VBoxDrvFreeBSDCpuHasSMAP(void) | +static bool VBoxDrvFreeBSDCpuHasSMAP(void) | ||||
+{ | +{ | ||||
Show All 36 Lines |