[vbox-dev] Kernel API changes for kernel 4.10

Larry Finger Larry.Finger at lwfinger.net
Sun Jan 15 17:49:33 GMT 2017


On 01/06/2017 11:06 AM, Larry Finger wrote:
> On 01/06/2017 08:06 AM, Frank Mehnert wrote:
>> Hi Larry,
>>
>> On Dienstag, 3. Januar 2017 21:48:06 CET Larry Finger wrote:
>>> On 12/27/2016 11:16 AM, Larry Finger wrote:
>>>> On 12/27/2016 10:56 AM, Larry Finger wrote:
>>>>> In kernel 4.10-rc1, the kernel routines register_cpu_notifier() and
>>>>> unregister_cpu_notifier() have been removed and their function replaced by
>>>>> callbacks from the hotplug state machine. After looking at the changes
>>>>> required
>>>>> in some other drivers, I have seen that the required changes will not be
>>>>> trivial. Before I start doing the work, I want to know if the changes have
>>>>> been
>>>>> started and/or done by Oracle.
>>>>
>>>> One thing I failed to mention. Commit 7fd8329ba502 in 4.10-rc1 also messes up
>>>> the ability to define true/false in an out-of-kernel driver. I have submitted a
>>>> kernel patch to fix this
>>>> (http://lkml.iu.edu/hypermail/linux/kernel/1612.3/00086.html), but it has not
>>>> yet been merged or received any comments.
>>>
>>> My patch was merged today. It has not yet hit mainline, but I expect it to be
>>> there as of 4.10-rc3. I still have no fix for the missing
>>> register_cpu_notifier(), etc.
>>
>> thanks for the information. I assume we will do it like the Linux kernel and use
>> cpuhp_setup_state_nocalls() to register CPU hotplug callbacks. But before we can
>> provide a fix we need to do a few tests.
>
> I think that is the correct approach, but I have not had time to actually do it
> yet. Unlike most API changes, this one is a bit more intrusive. Once you get a
> patch, I would be pleased to help test it. Having to boot an old kernel to run a
> VM is getting old. In addition, the openSUSE kernel HEAD project is running
> 4.10-rcX kernels, and the VB build fails every time they trigger a new build.

This is not a complete and final solution, but the hack below will get VB 
running on kernel 4.10. Note: A successful build also requires the fix for 
true/false redefinition. That patch has been accepted, but not yet merged into 
mainline.

Index: virtualbox/vboxdrv/r0drv/linux/memobj-r0drv-linux.c
===================================================================
--- virtualbox.orig/vboxdrv/r0drv/linux/memobj-r0drv-linux.c
+++ virtualbox/vboxdrv/r0drv/linux/memobj-r0drv-linux.c
@@ -1064,7 +1064,12 @@ DECLHIDDEN(int) rtR0MemObjNativeLockUser
                                  cPages,                 /* How many pages. */
                                  fWrite,                 /* Write to memory. */
                                  &pMemLnx->apPages[0],   /* Page array. */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
+                                papVMAs,               /* vmas */
+                               NULL);
+#else
                                  papVMAs);               /* vmas */
+#endif
  #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
          if (R0Process == RTR0ProcHandleSelf())
              rc = get_user_pages(R3Ptr,                  /* Where from. */
@@ -1086,7 +1091,12 @@ DECLHIDDEN(int) rtR0MemObjNativeLockUser
                                  fWrite,                 /* Write to memory. */
                                  fWrite,                 /* force write access. */
                                  &pMemLnx->apPages[0],   /* Page array. */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
+                                papVMAs,               /* vmas */
+                               NULL);
+#else
                                  papVMAs);               /* vmas */
+#endif
  #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) */
              rc = get_user_pages(pTask,                  /* Task for fault 
accounting. */
                                  pTask->mm,              /* Whose pages. */
Index: virtualbox/vboxdrv/r0drv/linux/mpnotification-r0drv-linux.c
===================================================================
--- virtualbox.orig/vboxdrv/r0drv/linux/mpnotification-r0drv-linux.c
+++ virtualbox/vboxdrv/r0drv/linux/mpnotification-r0drv-linux.c
@@ -39,8 +39,41 @@


  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 71) && defined(CONFIG_SMP)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
+/* This hack allows VB to build under kernel 4.10 and later, but it
+ * should be replaced with a version that uses the hotplug state machine
+ */

+static DEFINE_MUTEX(cpu_add_remove_lock);
+static RAW_NOTIFIER_HEAD(cpu_chain);
+static void vb_cpu_maps_update_begin(void)
+{
+        mutex_lock(&cpu_add_remove_lock);
+}

+static void vb_cpu_maps_update_done(void)
+{
+        mutex_unlock(&cpu_add_remove_lock);
+}
+
+/* Need to know about CPUs going up/down? */
+int register_cpu_notifier(struct notifier_block *nb)
+{
+       int ret;
+       vb_cpu_maps_update_begin();
+       ret = raw_notifier_chain_register(&cpu_chain, nb);
+       vb_cpu_maps_update_done();
+       return ret;
+}
+
+/* Need to know about CPUs going up/down? */
+void unregister_cpu_notifier(struct notifier_block *nb)
+{
+       vb_cpu_maps_update_begin();
+       raw_notifier_chain_unregister(&cpu_chain, nb);
+       vb_cpu_maps_update_done();
+}
+#endif
 
/*********************************************************************************************************************************
  *   Internal Functions 
                                                   *
 
*********************************************************************************************************************************/






More information about the vbox-dev mailing list