I am trying to apply the RT PREEMPT patch for the Linux kernel. As mentioned in guides like this and this, you are supposed to do it like this:

zcat patch-4.14.15-rt13.patch.gz | patch -p1

(assuming that you are in the directory containing the kernel sources.)

But I get a lot of messages like:

The next patch would create the file tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-createremove.tc,
which already exists!  Assume -R? [n] 
Apply anyway? [n] 
Skipping patch.
1 out of 1 hunk ignored
patching file virt/kvm/arm/arm.c
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
Skipping patch.
3 out of 3 hunks ignored -- saving rejects to file virt/kvm/arm/arm.c.rej

And in the end the process fails. I have tried this in an ubuntu:16.04 and a debian:stretch docker container, the result was the same.

I can not interact with the patching process btw because it is part of a bash script.

I am applying the patch on the kernel sources for the Raspberry Pi btw.

Here is the complete patch output.

What am I doing wrong? How can I apply the patch correctly?

The contents of virt/kvm/arm/arm.c.rej are:

--- virt/kvm/arm/arm.c
+++ virt/kvm/arm/arm.c
@@ -650,7 +650,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
         * involves poking the GIC, which must be done in a
         * non-preemptible context.
-       preempt_disable();
+       migrate_disable();


@@ -687,7 +687,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
-           preempt_enable();
+           migrate_enable();

@@ -742,7 +742,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)


-       preempt_enable();
+       migrate_enable();

        ret = handle_exit(vcpu, run, ret);

after the build.

  • The preempt patch you have is for kernel version 4.14.15 - make sure you check out the 4.14.y branch of the Raspberry Pi kernel (i.e. this) - and even then you might have problems (but they might be easily fixable) ... looks like the 4.14.y branch is up to 4.14.17 so you might get lucky Feb 8 '18 at 5:40
  • I think there was no 4.14.y branch. I used rpi-4.14.y.
    – Forivin
    Feb 8 '18 at 8:55
  • Yes, that is what I meant - rpi-4.14.y - see link I posted. Feb 8 '18 at 12:44

If you still have the problem, now the official raspberry pi kernel repository has a branch for the Preempt-RT patched kernel version. You don't need to patch the "vanilla" kernel anymore. That means, you don't need to find a match between the kernel version and the rt patch version. Additionally, some other patches are included.

I wrote a tutorial and made some performance tests. There are still some problems with the usb/lan irqs. I'm making some tests with the RPi 3 B+, I will publishing them this week.

  • Well, I have already tried that weeks ago without success. Though I used the official build instructions as found here: raspberrypi.org/documentation/linux/kernel/building.md and I simply used the rpi-4.14.y-rt branch instead. That should already have everything built in and even generate the right config automatically. Or do you see a problem with that?
    – Forivin
    Mar 19 '18 at 6:52
  • No, there is no problem with that, it is almost the same procedure that I explained in my post. The deployment is different. As I said, the Preempt-RT is now a branch of the official repository, and you don't need to match the kernel version with the RT patch anymore. If you are using the LAN/USB you will have a problem with the IRQ39 (USB int), and you need to add these options: dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0 to the /boot/cmdline.txt. Otherwise, the rpi freezes. But a prob. remains: You lose about 15% of the CPU performance, because of the interruption.
    – M. H. Riva
    Mar 19 '18 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.