# VirtualBox and kernel-4.8.0

## Cyker

GAAH! IT'S BROKEN AGAAAIIINNNN!!

Thankfully, because of last time I had a better chance of figuring out what to do \o/

Assuming you are using VirtualBox-4.3.38, you will need to put this in your overlay under "app-emulation/virtualbox-modules/virtualbox-modules-4.3.38.ebuild"

```

# Copyright 1999-2016 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Id$

# XXX: the tarball here is just the kernel modules split out of the binary

#      package that comes from virtualbox-bin

EAPI=5

inherit eutils linux-mod user

MY_P=vbox-kernel-module-src-${PV}

DESCRIPTION="Kernel Modules for Virtualbox"

HOMEPAGE="http://www.virtualbox.org/"

SRC_URI="https://dev.gentoo.org/~polynomial-c/virtualbox/${MY_P}.tar.xz"

LICENSE="GPL-2"

SLOT="0"

KEYWORDS="amd64 x86"

IUSE="pax_kernel"

RDEPEND="!=app-emulation/virtualbox-9999"

S=${WORKDIR}

BUILD_TARGETS="all"

BUILD_TARGET_ARCH="${ARCH}"

MODULE_NAMES="vboxdrv(misc:${S}) vboxnetflt(misc:${S}) vboxnetadp(misc:${S}) vboxpci(misc:${S})"

pkg_setup() {

   linux-mod_pkg_setup

   BUILD_PARAMS="KERN_DIR=${KV_DIR} O=${KV_OUT_DIR} V=1 KBUILD_VERBOSE=1"

   enewgroup vboxusers

}

src_prepare() {

   if kernel_is -ge 2 6 33 ; then

      # evil patch for new kernels - header moved

      grep -lR linux/autoconf.h *  | xargs sed -i -e 's:<linux/autoconf.h>:<generated/autoconf.h>:'

   fi

   if use pax_kernel && kernel_is -ge 3 0 0 ; then

      epatch "${FILESDIR}"/${PN}-4.1.4-pax-const.patch

   fi

   if kernel_is -ge 4 8 ; then

      epatch "${FILESDIR}"/${PN}-kernel-4.8-mod-timer.patch

   fi

}

src_install() {

   linux-mod_src_install

   insinto /usr/lib/modules-load.d/

   doins "${FILESDIR}"/virtualbox.conf

}

pkg_postinst() {

   linux-mod_pkg_postinst

   elog "If you are using sys-apps/openrc, please add \"vboxdrv\", \"vboxnetflt\""

   elog "and \"vboxnetadp\" to:"

   elog "  /etc/conf.d/modules"

}

```

and put this in "app-emulation/virtualbox-modules/files/virtualbox-modules-kernel-4.8-mod-timer.patch"

```

--- a/vboxdrv/r0drv/linux/timer-r0drv-linux.c   2015-10-13 15:27:18.000000000 +0100

+++ b/vboxdrv/r0drv/linux/timer-r0drv-linux.c   2016-10-08 21:40:26.668732713 +0100

@@ -361,7 +361,13 @@

         pSubTimer->u.Std.fFirstAfterChg = true;

 #ifdef CONFIG_SMP

         if (fPinned)

+        {

+# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) 

+            mod_timer(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

+# else

             mod_timer_pinned(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

+# endif

+        }

         else

 #endif

             mod_timer(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

@@ -796,7 +802,13 @@

         {

 #ifdef CONFIG_SMP

             if (pTimer->fSpecificCpu || pTimer->fAllCpus)

+            {

+# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)

+                mod_timer(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

+# else

                 mod_timer_pinned(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

+# endif

+            }

             else

 #endif

                 mod_timer(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

@@ -853,7 +865,13 @@

 

 #ifdef CONFIG_SMP

                     if (pTimer->fSpecificCpu || pTimer->fAllCpus)

+                    {

+# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)

+                        mod_timer(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

+# else

                         mod_timer_pinned(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

+# endif

+                    }

                     else

 #endif

                         mod_timer(&pSubTimer->u.Std.LnxTimer, pSubTimer->u.Std.ulNextJiffies);

@@ -1563,7 +1581,11 @@

         else

 #endif

         {

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)

+            init_timer_pinned(&pTimer->aSubTimers[iCpu].u.Std.LnxTimer);

+#else

             init_timer(&pTimer->aSubTimers[iCpu].u.Std.LnxTimer);

+#endif

             pTimer->aSubTimers[iCpu].u.Std.LnxTimer.data        = (unsigned long)&pTimer->aSubTimers[iCpu];

             pTimer->aSubTimers[iCpu].u.Std.LnxTimer.function    = rtTimerLinuxStdCallback;

             pTimer->aSubTimers[iCpu].u.Std.LnxTimer.expires     = jiffies;

--- a/vboxnetadp/linux/VBoxNetAdp-linux.c   2016-10-08 21:52:24.983596056 +0100

+++ b/vboxnetadp/linux/VBoxNetAdp-linux.c   2016-10-08 21:55:12.171311337 +0100

@@ -134,8 +134,10 @@

     /* Update the stats. */

     pPriv->Stats.tx_packets++;

     pPriv->Stats.tx_bytes += pSkb->len;

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)

     /* Update transmission time stamp. */

     pNetDev->trans_start = jiffies;

+#endif

     /* Nothing else to do, just free the sk_buff. */

     dev_kfree_skb(pSkb);

     return 0;

```

Should be relatively easy to adapt it for other versions.

You don't need any of this with VirtualBox-5.1.6, but sadly that has its own set of problems and I've been unable to figure all of them out.

One big issue is that you need to disable CONFIG_TRIM_UNUSED_KSYMS in your kernel config otherwise the kernel modules don't work after they've been emerged.

The other, and as-yet unfixed problem, is that VirtualBox segfaults on launch with e.g.

```
[ 1094.164306] VirtualBox[15991]: segfault at 8 ip 00007f3dcdc25fcd sp 00007ffd17c23b10 error 4 in libQt5DBusVBox.so.5[7f3dcdbed000+81000]
```

and I don't know why.

(If anyone has any ideas on this, please tell me!!!)

----------

## xpetex

thank you.

Will give it a try.

Same problem here. I am using 4.3.40 and i like to continue with it due to the problems with VB 5.X.

----------

## marax_faraii

I'm using Virtualbox 5.1.8 and I haven't had any issues with it.

----------

## fedeliallalinea

 *marax_faraii wrote:*   

> I'm using Virtualbox 5.1.8 and I haven't had any issues with it.

 

Yes, me too. But I think that the thread is related to stable (4.x) version of virtualbox.

----------

## marax_faraii

The 4.* version of Virtualbox doesn't work on that release of the kernel. At least not the ebuilds from the tree which is why I also upgraded virtualbox to 5.*

----------

## fedeliallalinea

 *marax_faraii wrote:*   

> The 4.* version of Virtualbox doesn't work on that release of the kernel. At least not the ebuilds from the tree which is why I also upgraded virtualbox to 5.*

 

Ah ok, I see now on virtualbox website VirtualBox 4.3.x is no longer supported!, sorry my fault I was convinced it was yet supported.

----------

