Custom kernel snap with PREEMPT_RT patch for UC

Hi all,

I am trying to create a custom kernel snap for a Generic x86 custom image of Ubuntu Core 18, since I need to use the PREEMPT_RT patch.

Up to now, I have followed these passages (https://stackoverflow.com/questions/51669724/install-rt-linux-patch-for-ubuntu) to apply the patch on a kernel version, so my kernel directory looks like this (it is placed in /home/USER/kernel/):
kernel

Moreover, my /boot directory looks like this (in particular you can see the initrd.img-5.4.5-rt3, vmlinuz-5.4.5-rt3 and config-5.4.5-rt3 files):
boot

Could you please tell me how to proceed to build a custom kernel snap? I tried to look for the code of the pc-kernel snap in order to try to understand what to do, but I was not able to find it.
I do not even know if the steps I have done until now are needed, maybe it is possible to define a snapcraft.yaml file in the /home/USER/kernel/ folder and put something inside that file to apply the patch on the kernel… But, in this case, does my folder alredy have all the needed files?

Thank you in advance!

Hi,

It seems like, your reference from stackoverflow is for classic ubuntu systems. Ubuntu Core and classic Ubuntu are quite different.

If you would like to use Ubuntu Core, please first have a look at how to create a custom image. There is a well-documented tutorial available here;

After understanding how things are working, you could go through the documentation where it has been described how to create a custom kernel snap.

Hi,

thanks for your reply.
I have read those guides, but I still have a couple of doubts:

  1. Which kind of instruction do I need to put (I think in the kernel snapcraft.yaml) to apply a patch to a kernel?

  2. Is there a way to access the code of the pc-kernel snap? It would be easier to understand how to correctly set all the parameters…

Thank you in advance.

Hi,

1- Yes you need to modify the snapcraft.yaml file to apply your patches. Probably, you could use the overide-pull keyword for this purpose.

2- It seems like, there was a similar discussion in the forum about the pc-kernel.

Please have a look at the following post. I believe you will find your answers there.

there is a snapcraft.yaml in the git trees of all ubuntu kernels … the 5.4 one of 20.04 (which is the base of the pc-kernel snap in the store) is at:

note that the official snaps are actually a re-pack of the deb from the archive (the secureboot setup requires a signed vmlinuz binary. the signing key for this can only be applied during the .deb build). for custom kernels using the snapcraft.yaml from the git source is the preferred way though.

Hi @bugraaydogar and @ogra,

thank you for your advices. I thought about a possible way to proceed that could be simple, but I do not know if it is reasonable.

To start with, I downloaded this (https://github.com/snapcore/sample-kernels/tree/stable-4.4.y) sample kernel. Then, I added a /patch folder in it and modified the snapcraft.yaml as follows:

name: my-kernel
version: 1.0.0
summary: xxxx
description: xxxx
type: kernel
grade: stable
confinement: strict

parts:
  kernel:
    plugin: kernel
    source: .
    kdefconfig: [x86_64_defconfig, snappy/generic.config, snappy/security.config, snappy/systemd.config, snappy/snappy.config, snappy/containers.config]
    kconfigs:
      - CONFIG_LOCALVERSION="-stable-4.4.y"
    override-pull: |
      snapcraftctl pull
      set -e
      echo "applying snappy configs patches"
      git apply -v ./patches/patch-4.4.50-rt63.patch
    kernel-image-target: bzImage

After that, I used the snapcraft command and obtained the .snap file.
Then, following the guide to create a custom UC image, I created the .json file:

{
  "type": "model",
  "series": "16",
  "model": "ubuntu-core-18-amd64",
  "display-name":"Ubuntu Core 18 (amd64)",
  "architecture": "amd64",
  "kernel": "my-kernel",
  "gadget": "pc=18",
  "base": "core18",
  "required-snaps": ["core"],
  "authority-id": "xxxxx",
  "brand-id": "xxxxx",
  "timestamp": "xxxxx"
}

I got the .model file by using the cat my-model.json | snap sign -k my-key-name > my-model.model command and then I used ubuntu-image snap --extra-snaps my-kernel_1.0.0_amd64.snap my-model.model to get the .img file.

Although, after creating a bootable USB with it and starting the configuration of UC, in the part of the configuration where you need to select the network (Network connections) to use to perform the configuration I get no networks (whereas with the “official” image I got eth0 and eth1).

So, is this procedure reasonable? And, if so, what could be the cause of this network issue?

the “sample-kernels” are really that … samples to show you the setup and configuration … the trees are rather unmaintained, better start off a kernel tree like the one i linked (look for the actual ubuntu-bionic branch on kernel.ubuntu.com) …

1 Like

Hi @ogra ,

as you suggested, now I am trying to use the ubuntu-bionic kernel, but I have issues in applying the patch to it.
I first used git clone git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git, created a /patches folder and put the patch there, and then I modified the snapcraft.yaml file.

In particular, I tried adding the override-pull section as you can see below:

parts:
  kernel:
    plugin: kernel
    source: .
    source-type: git
    kconfigflavour: generic
    kconfigs:
      - CONFIG_DEBUG_INFO=n
    override-pull: |
      snapcraftctl pull
      set -e
      echo "applying snappy configs patches"
      git apply -v ./patches/patch-5.4.10-rt4.patch
    override-build: |
      cp debian/scripts/retpoline-extract-one \
        $SNAPCRAFT_PART_BUILD/scripts/ubuntu-retpoline-extract-one
      snapcraftctl build
    kernel-with-firmware: false

Although, I get the following error when running snapcraft in the snap folder:
error: can't open patch './patches/patch-5.4.10-rt4.patch': No such file or directory

My kernel snap directory looks like this now:
dir

How can I correctly change the snapcraft to make it apply the patch? I thought the path was correct… Of course I checked that the patch name is correct, so the path must be wrong.

i’d put the git apply as first line into override-build and try using $SNAPCRAFT_PART_SRC/patches/patch-5.4.10-rt4.patch for the file path (and completely omit the override-pull step)

Yes, it seems that now it finds the patch. However, soon after it gives an error about the fact that the patch cannot be correctly applied… I guess due to the fact that the kernel version does not match the patch one (this should be a requirement of the patch that I am trying to apply).

The patch versions are available here (https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/) and the ubuntu-bionic ones here (https://kernel.ubuntu.com/git/ubuntu/ubuntu-bionic.git/refs/), and there is no version that is common to both it seems…

Instead, the sample kernel I found here (https://github.com/snapcore/sample-kernels/tree/stable-4.4.y) had version 4.4.50, for which there exists a corresponding patch version.

By consequence, I think that the only way I can use the patch is to keep trying to use the latter kernel version, but I need to solve the Network configuration issue that I mentioned:

Do you have any advice for that? Or do you find an ubuntu-bionic kernel matching one of the PREEMPT_RT versions?

perhaps you could try the 5.4 patch and the ubuntu-focal tree ?

Actually, the patch version must exactly match the kernel one to avoid errors.
The main issue is that it seems that all the ubuntu-bionic and ubuntu-focal versions are in the form x.y.0-z, whereas all the patch ones are x.y.h with h different from 0, so it should not be possible to find two matching versions.

Instead, the sample-kernel version is 4.4.50, for which a corresponding patch exists. Indeed, when running snapcraft the kernel snap is correctly built (but then I get the Network configuration issue during the UC configuration procedure).

Therefore, I think that the only way I can apply the patch without errors is to find other UC kernel versions compatible with it. Or do you see other possible strategies? For example, is it possible to build a UC kernel snap from these (https://mirrors.edge.kernel.org/pub/linux/kernel/) kernels?

The error I get with snapcraft that I think is due to the versions mismatch is the following one:

Building kernel 
Checking patch Documentation/RCU/Design/Expedited-Grace-Periods/Expedited-Grace-Periods.html...
Checking patch Documentation/RCU/Design/Requirements/Requirements.html...
Checking patch Documentation/RCU/checklist.txt...
Checking patch Documentation/RCU/rcubarrier.txt...
Checking patch Documentation/RCU/stallwarn.txt...
Checking patch Documentation/RCU/whatisRCU.txt...
Checking patch Documentation/printk-ringbuffer.txt...
Checking patch Documentation/trace/ftrace-uses.rst...
Checking patch arch/Kconfig...
Checking patch arch/alpha/include/asm/spinlock_types.h...
Checking patch arch/arc/kernel/entry.S...
Checking patch arch/arm/Kconfig...
Hunk #3 succeeded at 104 (offset 1 line).
Checking patch arch/arm/include/asm/irq.h...
Checking patch arch/arm/include/asm/spinlock_types.h...
Checking patch arch/arm/include/asm/switch_to.h...
Checking patch arch/arm/include/asm/thread_info.h...
Checking patch arch/arm/kernel/asm-offsets.c...
Checking patch arch/arm/kernel/entry-armv.S...
Checking patch arch/arm/kernel/entry-common.S...
Checking patch arch/arm/kernel/signal.c...
Checking patch arch/arm/kernel/smp.c...
Hunk #1 succeeded at 682 (offset 4 lines).
Checking patch arch/arm/kernel/traps.c...
Checking patch arch/arm/mm/cache-v7.S...
Checking patch arch/arm/mm/cache-v7m.S...
Checking patch arch/arm/mm/fault.c...
Checking patch arch/arm/mm/highmem.c...
Checking patch arch/arm64/Kconfig...
Hunk #3 succeeded at 160 (offset 1 line).
Checking patch arch/arm64/crypto/sha256-glue.c...
Checking patch arch/arm64/include/asm/assembler.h...
Checking patch arch/arm64/include/asm/kvm_mmu.h...
Checking patch arch/arm64/include/asm/preempt.h...
Checking patch arch/arm64/include/asm/spinlock_types.h...
Checking patch arch/arm64/include/asm/thread_info.h...
Checking patch arch/arm64/kernel/asm-offsets.c...
Checking patch arch/arm64/kernel/entry.S...
Checking patch arch/arm64/kernel/fpsimd.c...
Hunk #2 succeeded at 1020 (offset 2 lines).
Hunk #3 succeeded at 1033 (offset 2 lines).
Hunk #4 succeeded at 1067 (offset 2 lines).
Checking patch arch/arm64/kernel/signal.c...
Checking patch arch/arm64/kernel/smp.c...
Checking patch arch/arm64/kernel/traps.c...
Checking patch arch/arm64/kvm/va_layout.c...
Checking patch arch/c6x/kernel/entry.S...
Checking patch arch/csky/kernel/entry.S...
Checking patch arch/h8300/kernel/entry.S...
Checking patch arch/hexagon/include/asm/spinlock_types.h...
Checking patch arch/hexagon/kernel/vm_entry.S...
Checking patch arch/ia64/include/asm/spinlock_types.h...
Checking patch arch/ia64/kernel/entry.S...
Checking patch arch/ia64/kernel/kprobes.c...
Checking patch arch/m68k/coldfire/entry.S...
Checking patch arch/microblaze/kernel/entry.S...
Checking patch arch/mips/Kconfig...
Checking patch arch/mips/include/asm/asmmacro.h...
Checking patch arch/mips/kernel/entry.S...
Checking patch arch/nds32/Kconfig...
Checking patch arch/nds32/kernel/ex-exit.S...
Checking patch arch/nios2/kernel/entry.S...
Checking patch arch/parisc/Kconfig...
Hunk #1 succeeded at 82 (offset 1 line).
Checking patch arch/parisc/kernel/entry.S...
Checking patch arch/powerpc/Kconfig...
error: while searching for:
	select HAVE_HARDLOCKUP_DETECTOR_PERF	if PERF_EVENTS && HAVE_PERF_EVENTS_NMI && !HAVE_HARDLOCKUP_DETECTOR_ARCH
	select HAVE_PERF_REGS
	select HAVE_PERF_USER_STACK_DUMP
	select HAVE_RCU_TABLE_FREE		if SMP
	select HAVE_RCU_TABLE_NO_INVALIDATE	if HAVE_RCU_TABLE_FREE
	select HAVE_MMU_GATHER_PAGE_SIZE

error: patch failed: arch/powerpc/Kconfig:221
error: arch/powerpc/Kconfig: patch does not apply
Checking patch arch/powerpc/include/asm/spinlock_types.h...
Checking patch arch/powerpc/include/asm/stackprotector.h...
Checking patch arch/powerpc/include/asm/thread_info.h...
Checking patch arch/powerpc/kernel/asm-offsets.c...
Checking patch arch/powerpc/kernel/entry_32.S...
Hunk #1 succeeded at 401 (offset 1 line).
Hunk #2 succeeded at 518 (offset 1 line).
Hunk #3 succeeded at 533 (offset 1 line).
Hunk #4 succeeded at 900 (offset 1 line).
Hunk #5 succeeded at 931 (offset 1 line).
Hunk #6 succeeded at 1234 (offset 1 line).
Hunk #7 succeeded at 1255 (offset 1 line).
Checking patch arch/powerpc/kernel/entry_64.S...
Checking patch arch/powerpc/kernel/irq.c...
Checking patch arch/powerpc/kernel/misc_32.S...
Checking patch arch/powerpc/kernel/misc_64.S...
Checking patch arch/powerpc/kernel/traps.c...
error: while searching for:

static int __die(const char *str, struct pt_regs *regs, long err)
{
	printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);

	printk("%s PAGE_SIZE=%luK%s%s%s%s%s%s%s %s\n",
	       IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN) ? "LE" : "BE",
	       PAGE_SIZE / 1024,
	       early_radix_enabled() ? " MMU=Radix" : "",
	       early_mmu_has_feature(MMU_FTR_HPTE_TABLE) ? " MMU=Hash" : "",
	       IS_ENABLED(CONFIG_PREEMPT) ? " PREEMPT" : "",
	       IS_ENABLED(CONFIG_SMP) ? " SMP" : "",
	       IS_ENABLED(CONFIG_SMP) ? (" NR_CPUS=" __stringify(NR_CPUS)) : "",
	       debug_pagealloc_enabled() ? " DEBUG_PAGEALLOC" : "",

error: patch failed: arch/powerpc/kernel/traps.c:252
error: arch/powerpc/kernel/traps.c: patch does not apply
Checking patch arch/powerpc/kernel/watchdog.c...
Checking patch arch/powerpc/kvm/Kconfig...
Checking patch arch/powerpc/platforms/ps3/device-init.c...
Checking patch arch/powerpc/platforms/pseries/iommu.c...
Hunk #2 succeeded at 178 (offset -1 lines).
error: while searching for:
		tcep = (__be64 *)__get_free_page(GFP_ATOMIC);
		/* If allocation fails, fall back to the loop implementation */
		if (!tcep) {
			local_irq_restore(flags);
			return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
					    direction, attrs);
		}

error: patch failed: arch/powerpc/platforms/pseries/iommu.c:209
error: arch/powerpc/platforms/pseries/iommu.c: patch does not apply
Checking patch arch/riscv/kernel/entry.S...
Hunk #2 succeeded at 293 (offset 24 lines).
Checking patch arch/s390/Kconfig...
Checking patch arch/s390/include/asm/preempt.h...
Checking patch arch/s390/include/asm/spinlock_types.h...
Checking patch arch/s390/kernel/dumpstack.c...
Checking patch arch/s390/kernel/entry.S...
Hunk #1 succeeded at 800 (offset 10 lines).
Checking patch arch/sh/Kconfig...
Checking patch arch/sh/include/asm/spinlock_types.h...
Checking patch arch/sh/kernel/cpu/sh5/entry.S...
Checking patch arch/sh/kernel/entry-common.S...
Checking patch arch/sh/kernel/irq.c...
Checking patch arch/sparc/Kconfig...
Hunk #1 succeeded at 276 (offset -1 lines).
Checking patch arch/sparc/kernel/irq_64.c...
Checking patch arch/sparc/kernel/rtrap_64.S...
Checking patch arch/x86/Kconfig...
Checking patch arch/x86/crypto/aesni-intel_glue.c...
Checking patch arch/x86/crypto/cast5_avx_glue.c...
Checking patch arch/x86/crypto/chacha_glue.c...
Checking patch arch/x86/crypto/glue_helper.c...
Checking patch arch/x86/entry/common.c...
Checking patch arch/x86/entry/entry_32.S...
Checking patch arch/x86/entry/entry_64.S...
Hunk #1 succeeded at 671 (offset 1 line).
Hunk #2 succeeded at 1091 (offset 1 line).
Hunk #3 succeeded at 1102 (offset 1 line).
Checking patch arch/x86/include/asm/fpu/api.h...
Checking patch arch/x86/include/asm/preempt.h...
Checking patch arch/x86/include/asm/signal.h...
Checking patch arch/x86/include/asm/stackprotector.h...
Checking patch arch/x86/include/asm/thread_info.h...
Checking patch arch/x86/kernel/apic/io_apic.c...
error: while searching for:
	return false;
}

static inline bool ioapic_irqd_mask(struct irq_data *data)
{
	/* If we are moving the irq we need to mask it */
	if (unlikely(irqd_is_setaffinity_pending(data))) {
		mask_ioapic_irq(data);
		return true;
	}
	return false;
}

static inline void ioapic_irqd_unmask(struct irq_data *data, bool masked)
{
	if (unlikely(masked)) {
		/* Only migrate the irq if the ack has been received.
		 *
		 * On rare occasions the broadcast level triggered ack gets

error: patch failed: arch/x86/kernel/apic/io_apic.c:1725
error: arch/x86/kernel/apic/io_apic.c: patch does not apply
Checking patch arch/x86/kernel/asm-offsets.c...
Checking patch arch/x86/kernel/cpu/mshyperv.c...
Checking patch arch/x86/kernel/fpu/core.c...
Checking patch arch/x86/kernel/irq_32.c...
Checking patch arch/x86/kernel/process_32.c...
Checking patch arch/x86/kvm/x86.c...
Hunk #1 succeeded at 7257 (offset 50 lines).
Checking patch arch/x86/mm/highmem_32.c...
Checking patch arch/x86/mm/iomap_32.c...
Checking patch arch/xtensa/include/asm/spinlock_types.h...
Checking patch arch/xtensa/kernel/entry.S...
Checking patch arch/xtensa/kernel/traps.c...
Checking patch block/blk-ioc.c...
Hunk #2 succeeded at 117 (offset 1 line).
Checking patch block/blk-mq.c...
Hunk #3 succeeded at 1476 (offset 2 lines).
Checking patch block/blk-softirq.c...
Checking patch crypto/cryptd.c...
Checking patch drivers/block/zram/zcomp.c...
Checking patch drivers/block/zram/zcomp.h...
Checking patch drivers/block/zram/zram_drv.c...
Hunk #3 succeeded at 1189 (offset -1 lines).
Hunk #4 succeeded at 1252 (offset -1 lines).
Hunk #5 succeeded at 1283 (offset -1 lines).
Hunk #6 succeeded at 1291 (offset -1 lines).
Checking patch drivers/block/zram/zram_drv.h...
Checking patch drivers/char/random.c...
Checking patch drivers/char/tpm/tpm-dev-common.c...
Checking patch drivers/char/tpm/tpm_tis.c...
Checking patch drivers/clocksource/Kconfig...
Checking patch drivers/clocksource/timer-atmel-tcb.c...
Checking patch drivers/connector/cn_proc.c...
Checking patch drivers/dma-buf/dma-buf.c...
Hunk #1 succeeded at 215 (offset 1 line).
Hunk #2 succeeded at 224 (offset 1 line).
Hunk #3 succeeded at 1191 (offset 2 lines).
Checking patch drivers/dma-buf/dma-resv.c...
Checking patch drivers/firmware/efi/efi.c...
Hunk #1 succeeded at 69 (offset 1 line).
Hunk #2 succeeded at 95 (offset 1 line).
Checking patch drivers/gpu/drm/Kconfig...
Checking patch drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c...
Checking patch drivers/gpu/drm/i915/display/intel_sprite.c...
Checking patch drivers/gpu/drm/i915/gem/i915_gem_busy.c...
Checking patch drivers/gpu/drm/i915/gt/intel_breadcrumbs.c...
Checking patch drivers/gpu/drm/i915/gt/intel_engine.h...
Hunk #1 succeeded at 357 (offset 8 lines).
Checking patch drivers/gpu/drm/i915/gt/intel_hangcheck.c...
Checking patch drivers/gpu/drm/i915/gt/intel_reset.c...
Checking patch drivers/gpu/drm/i915/i915_irq.c...
Checking patch drivers/gpu/drm/i915/i915_request.c...
error: while searching for:
	 * check that the rq still belongs to the newly locked engine.
	 */
	locked = READ_ONCE(rq->engine);
	spin_lock(&locked->active.lock);
	while (unlikely(locked != (engine = READ_ONCE(rq->engine)))) {
		spin_unlock(&locked->active.lock);
		spin_lock(&engine->active.lock);
		locked = engine;
	}
	list_del(&rq->sched.link);
	spin_unlock(&locked->active.lock);
}

static bool i915_request_retire(struct i915_request *rq)

error: patch failed: drivers/gpu/drm/i915/i915_request.c:205
error: drivers/gpu/drm/i915/i915_request.c: patch does not apply
Checking patch drivers/gpu/drm/i915/i915_trace.h...
Checking patch drivers/gpu/drm/radeon/radeon_display.c...
Hunk #1 succeeded at 1821 (offset 2 lines).
Hunk #2 succeeded at 1914 (offset 2 lines).
Checking patch drivers/hv/hyperv_vmbus.h...
Checking patch drivers/hv/vmbus_drv.c...
Hunk #2 succeeded at 1242 (offset 42 lines).
Hunk #3 succeeded at 1288 (offset 42 lines).
Checking patch drivers/leds/trigger/Kconfig...
Checking patch drivers/md/bcache/Kconfig...
Checking patch drivers/md/raid5.c...
Checking patch drivers/md/raid5.h...
Checking patch drivers/media/platform/Kconfig...
Checking patch drivers/net/wireless/intersil/orinoco/orinoco_usb.c...
Checking patch drivers/of/base.c...
Checking patch drivers/of/dynamic.c...
Checking patch drivers/of/of_private.h...
Checking patch drivers/of/overlay.c...
Hunk #1 succeeded at 976 (offset 5 lines).
Hunk #2 succeeded at 1218 (offset 5 lines).
Checking patch drivers/pci/switch/switchtec.c...
error: while searching for:
	kref_get(&stuser->kref);
	stuser->read_len = sizeof(stuser->data);
	stuser_set_state(stuser, MRPC_QUEUED);
	init_completion(&stuser->comp);
	list_add_tail(&stuser->list, &stdev->mrpc_queue);

	mrpc_cmd_submit(stdev);

error: patch failed: drivers/pci/switch/switchtec.c:175
error: drivers/pci/switch/switchtec.c: patch does not apply
Checking patch drivers/scsi/fcoe/fcoe.c...
Checking patch drivers/scsi/fcoe/fcoe_ctlr.c...
Checking patch drivers/scsi/libfc/fc_exch.c...
Checking patch drivers/thermal/intel/x86_pkg_temp_thermal.c...
Checking patch drivers/tty/serial/8250/8250.h...
Checking patch drivers/tty/serial/8250/8250_core.c...
Hunk #2 succeeded at 274 (offset -1 lines).
Hunk #3 succeeded at 283 (offset -1 lines).
Hunk #4 succeeded at 307 (offset -1 lines).
Hunk #5 succeeded at 585 (offset -1 lines).
Hunk #6 succeeded at 678 (offset -1 lines).
Checking patch drivers/tty/serial/8250/8250_dma.c...
Checking patch drivers/tty/serial/8250/8250_port.c...
Hunk #11 succeeded at 2398 (offset 4 lines).
Hunk #12 succeeded at 2683 (offset 4 lines).
Hunk #13 succeeded at 3147 (offset 4 lines).
Hunk #14 succeeded at 3155 (offset 4 lines).
Hunk #15 succeeded at 3188 (offset 4 lines).
Hunk #16 succeeded at 3224 (offset 4 lines).
Hunk #17 succeeded at 3238 (offset 4 lines).
Hunk #18 succeeded at 3259 (offset 4 lines).
Hunk #19 succeeded at 3280 (offset 4 lines).
Hunk #20 succeeded at 3289 (offset 4 lines).
Checking patch drivers/tty/serial/amba-pl011.c...
Checking patch drivers/tty/serial/omap-serial.c...
Checking patch drivers/usb/gadget/function/f_fs.c...
Hunk #1 succeeded at 1709 (offset -6 lines).
Checking patch drivers/usb/gadget/legacy/inode.c...
Checking patch drivers/video/backlight/Kconfig...
Checking patch drivers/watchdog/watchdog_dev.c...
error: while searching for:
		ktime_t t = watchdog_next_keepalive(wdd);

		if (t > 0)
			hrtimer_start(&wd_data->timer, t, HRTIMER_MODE_REL);
	} else {
		hrtimer_cancel(&wd_data->timer);
	}

error: patch failed: drivers/watchdog/watchdog_dev.c:158
error: drivers/watchdog/watchdog_dev.c: patch does not apply
Checking patch drivers/xen/preempt.c...
Hunk #2 succeeded at 39 (offset 2 lines).
Checking patch fs/afs/dir_silly.c...
Hunk #1 succeeded at 210 (offset 8 lines).
Checking patch fs/btrfs/volumes.h...
Checking patch fs/buffer.c...
Hunk #6 succeeded at 3350 (offset -12 lines).
Checking patch fs/cifs/readdir.c...
Checking patch fs/dcache.c...
Hunk #1 succeeded at 2483 (offset 1 line).
Hunk #2 succeeded at 2494 (offset 1 line).
Hunk #3 succeeded at 2531 (offset 1 line).
Hunk #4 succeeded at 2559 (offset 1 line).
Hunk #5 succeeded at 2632 (offset 1 line).
Hunk #6 succeeded at 3146 (offset 2 lines).
Hunk #7 succeeded at 3164 (offset 2 lines).
Hunk #8 succeeded at 3197 (offset 2 lines).
Checking patch fs/eventpoll.c...
Checking patch fs/ext4/page-io.c...
Checking patch fs/fscache/cookie.c...
Checking patch fs/fscache/main.c...
Checking patch fs/fuse/readdir.c...
Checking patch fs/inode.c...
Hunk #1 succeeded at 157 (offset 1 line).
Checking patch fs/jbd2/commit.c...
Hunk #2 succeeded at 920 (offset 2 lines).
Hunk #3 succeeded at 930 (offset 2 lines).
Hunk #4 succeeded at 1030 (offset 7 lines).
Checking patch fs/jbd2/journal.c...
Hunk #4 succeeded at 2407 (offset -3 lines).
Hunk #5 succeeded at 2528 (offset -3 lines).
Hunk #6 succeeded at 2562 (offset -3 lines).
Checking patch fs/jbd2/transaction.c...
Hunk #1 succeeded at 877 (offset -2 lines).
Hunk #2 succeeded at 927 (offset -2 lines).
Hunk #3 succeeded at 991 (offset -2 lines).
Hunk #4 succeeded at 1012 (offset -2 lines).
Hunk #5 succeeded at 1031 (offset -2 lines).
Hunk #6 succeeded at 1173 (offset 1 line).
Hunk #7 succeeded at 1208 (offset 1 line).
Hunk #8 succeeded at 1279 (offset 4 lines).
Hunk #9 succeeded at 1293 (offset 4 lines).
Hunk #10 succeeded at 1394 (offset 4 lines).
Hunk #11 succeeded at 1413 (offset 4 lines).
Hunk #12 succeeded at 1505 (offset 4 lines).
Hunk #13 succeeded at 1543 (offset 4 lines).
Hunk #14 succeeded at 1604 (offset 4 lines).
Hunk #15 succeeded at 1646 (offset 4 lines).
Hunk #16 succeeded at 1656 (offset 4 lines).
Hunk #17 succeeded at 1669 (offset 4 lines).
Hunk #18 succeeded at 1876 (offset 4 lines).
Hunk #19 succeeded at 1900 (offset 4 lines).
Hunk #20 succeeded at 1932 (offset 4 lines).
Hunk #21 succeeded at 1969 (offset 4 lines).
Hunk #22 succeeded at 1986 (offset 4 lines).
Hunk #23 succeeded at 2085 (offset 4 lines).
Hunk #24 succeeded at 2109 (offset 4 lines).
Hunk #25 succeeded at 2130 (offset 4 lines).
Hunk #26 succeeded at 2197 (offset 4 lines).
Hunk #27 succeeded at 2284 (offset 4 lines).
error: while searching for:
		set_buffer_freed(bh);
		if (journal->j_running_transaction && buffer_jbddirty(bh))
			jh->b_next_transaction = journal->j_running_transaction;
		jbd2_journal_put_journal_head(jh);
		spin_unlock(&journal->j_list_lock);
		jbd_unlock_bh_state(bh);
		write_unlock(&journal->j_state_lock);
		return 0;
	} else {
		/* Good, the buffer belongs to the running transaction.

error: patch failed: fs/jbd2/transaction.c:2304
error: fs/jbd2/transaction.c: patch does not apply
Checking patch fs/namei.c...
Hunk #1 succeeded at 1638 (offset 1 line).
Hunk #2 succeeded at 3126 (offset 1 line).
Checking patch fs/namespace.c...
Checking patch fs/nfs/delegation.c...
Checking patch fs/nfs/dir.c...
Hunk #1 succeeded at 457 (offset 12 lines).
Hunk #2 succeeded at 1517 (offset 21 lines).
Hunk #3 succeeded at 1846 (offset 21 lines).
Hunk #4 succeeded at 1860 (offset 21 lines).
Checking patch fs/nfs/inode.c...
Checking patch fs/nfs/nfs4_fs.h...
Checking patch fs/nfs/nfs4proc.c...
error: while searching for:
	unsigned int seq;
	int ret;

	seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);

	ret = _nfs4_proc_open(opendata, ctx);
	if (ret != 0)

error: patch failed: fs/nfs/nfs4proc.c:2956
error: fs/nfs/nfs4proc.c: patch does not apply
Checking patch fs/nfs/nfs4state.c...
Hunk #1 succeeded at 508 (offset -2 lines).
Hunk #2 succeeded at 1616 (offset -2 lines).
Hunk #3 succeeded at 1682 (offset -2 lines).
Checking patch fs/nfs/unlink.c...
Checking patch fs/ntfs/aops.c...
Checking patch fs/ocfs2/suballoc.c...
Checking patch fs/proc/base.c...
Checking patch fs/proc/kmsg.c...
Checking patch fs/proc/proc_sysctl.c...
Checking patch fs/squashfs/decompressor_multi_percpu.c...
Checking patch fs/stack.c...
Checking patch fs/userfaultfd.c...
Hunk #5 succeeded at 1939 (offset 4 lines).
Checking patch include/Kbuild...
error: include/Kbuild: No such file or directory
Checking patch include/linux/bottom_half.h...
Checking patch include/linux/buffer_head.h...
Checking patch include/linux/cgroup-defs.h...
Checking patch include/linux/cgroup.h...
Hunk #1 succeeded at 751 (offset 1 line).
Checking patch include/linux/completion.h...
Checking patch include/linux/console.h...
Checking patch include/linux/dcache.h...
Checking patch include/linux/delay.h...
Checking patch include/linux/dma-resv.h...
Checking patch include/linux/fs.h...
Hunk #1 succeeded at 717 (offset 1 line).
Hunk #2 succeeded at 856 (offset 1 line).
Hunk #3 succeeded at 881 (offset 1 line).
Checking patch include/linux/fscache.h...
Checking patch include/linux/genhd.h...
Checking patch include/linux/gfp.h...
Hunk #1 succeeded at 586 (offset 6 lines).
Checking patch include/linux/hardirq.h...
Checking patch include/linux/highmem.h...
Checking patch include/linux/idr.h...
Checking patch include/linux/interrupt.h...
Checking patch include/linux/irq_work.h...
Checking patch include/linux/irqdesc.h...
Checking patch include/linux/irqflags.h...
Checking patch include/linux/jbd2.h...
Checking patch include/linux/journal-head.h...
Checking patch include/linux/kernel.h...
Checking patch include/linux/kmsg_dump.h...
Checking patch include/linux/list_bl.h...
Checking patch include/linux/locallock.h...
Checking patch include/linux/mm_types.h...
Hunk #2 succeeded at 523 (offset 2 lines).
Checking patch include/linux/mutex.h...
Checking patch include/linux/mutex_rt.h...
Checking patch include/linux/netdevice.h...
Hunk #1 succeeded at 3018 (offset 2 lines).
Checking patch include/linux/nfs_fs.h...
Checking patch include/linux/nfs_xdr.h...
Hunk #1 succeeded at 1596 (offset 2 lines).
Checking patch include/linux/percpu-refcount.h...
Checking patch include/linux/percpu-rwsem.h...
Checking patch include/linux/percpu.h...
Checking patch include/linux/pid.h...
Checking patch include/linux/posix-timers.h...
Checking patch include/linux/preempt.h...
Checking patch include/linux/printk.h...
error: while searching for:
void dump_stack_print_info(const char *log_lvl);
void show_regs_print_info(const char *log_lvl);
extern asmlinkage void dump_stack(void) __cold;
extern void printk_safe_init(void);
extern void printk_safe_flush(void);
extern void printk_safe_flush_on_panic(void);
#else
static inline __printf(1, 0)
int vprintk(const char *s, va_list args)

error: patch failed: include/linux/printk.h:202
error: include/linux/printk.h: patch does not apply
Checking patch include/linux/printk_ringbuffer.h...
Checking patch include/linux/radix-tree.h...
Checking patch include/linux/random.h...
Checking patch include/linux/ratelimit.h...
Checking patch include/linux/rbtree.h...
Checking patch include/linux/rcu_assign_pointer.h...
Checking patch include/linux/rcupdate.h...
Checking patch include/linux/rtmutex.h...
Checking patch include/linux/rwlock_rt.h...
Checking patch include/linux/rwlock_types.h...
Checking patch include/linux/rwlock_types_rt.h...
Checking patch include/linux/rwsem-rt.h...
Checking patch include/linux/rwsem.h...
Checking patch include/linux/sched.h...
Checking patch include/linux/sched/mm.h...
Checking patch include/linux/sched/wake_q.h...
Checking patch include/linux/seqlock.h...
Checking patch include/linux/serial_8250.h...
Checking patch include/linux/signal.h...
Checking patch include/linux/skbuff.h...
Hunk #2 succeeded at 1847 (offset 2 lines).
Checking patch include/linux/smp.h...
Checking patch include/linux/spinlock.h...
Checking patch include/linux/spinlock_api_smp.h...
Checking patch include/linux/spinlock_rt.h...
Checking patch include/linux/spinlock_types.h...
Checking patch include/linux/spinlock_types_nort.h...
Checking patch include/linux/spinlock_types_raw.h...
Checking patch include/linux/spinlock_types_rt.h...
Checking patch include/linux/spinlock_types_up.h...
Checking patch include/linux/stop_machine.h...
Checking patch include/linux/suspend.h...
Checking patch include/linux/swait.h...
Checking patch include/linux/thread_info.h...
Checking patch include/linux/trace_events.h...
Checking patch include/linux/uaccess.h...
Checking patch include/linux/vmstat.h...
Checking patch include/linux/wait.h...
Checking patch include/net/gen_stats.h...
Checking patch include/net/neighbour.h...
Hunk #1 succeeded at 459 (offset -1 lines).
Hunk #2 succeeded at 502 (offset -1 lines).
Hunk #3 succeeded at 543 (offset -1 lines).
Checking patch include/net/net_seq_lock.h...
Checking patch include/net/sch_generic.h...
Hunk #5 succeeded at 556 (offset 6 lines).
Checking patch include/xen/xen-ops.h...
Checking patch init/Kconfig...
Hunk #1 succeeded at 913 (offset -10 lines).
Hunk #2 succeeded at 1620 (offset -10 lines).
Hunk #3 succeeded at 1796 (offset -10 lines).
Hunk #4 succeeded at 1817 (offset -10 lines).
Hunk #5 succeeded at 1883 (offset -10 lines).
Checking patch init/init_task.c...
Checking patch init/main.c...
error: while searching for:
	boot_init_stack_canary();

	time_init();
	printk_safe_init();
	perf_event_init();
	profile_init();
	call_function_init();

error: patch failed: init/main.c:693
error: init/main.c: patch does not apply
Checking patch kernel/Kconfig.locks...
Checking patch kernel/Kconfig.preempt...
Checking patch kernel/cgroup/cgroup.c...
Hunk #2 succeeded at 5026 (offset 14 lines).
Hunk #3 succeeded at 5087 (offset 14 lines).
Hunk #4 succeeded at 5095 (offset 14 lines).
Hunk #5 succeeded at 5196 (offset 14 lines).
Checking patch kernel/cgroup/cpuset.c...
Checking patch kernel/cgroup/rstat.c...
Checking patch kernel/cpu.c...
Hunk #1 succeeded at 848 (offset -1 lines).
Hunk #2 succeeded at 886 (offset -1 lines).
Hunk #3 succeeded at 904 (offset -1 lines).
Hunk #4 succeeded at 955 (offset -1 lines).
Checking patch kernel/events/core.c...
Hunk #1 succeeded at 10279 (offset 21 lines).
Checking patch kernel/exit.c...
Checking patch kernel/fork.c...
Hunk #2 succeeded at 295 (offset 5 lines).
Hunk #3 succeeded at 702 (offset 5 lines).
Hunk #4 succeeded at 756 (offset 5 lines).
Hunk #5 succeeded at 955 (offset 5 lines).
Hunk #6 succeeded at 1934 (offset 10 lines).
Checking patch kernel/futex.c...
Hunk #1 succeeded at 962 (offset 17 lines).
Hunk #2 succeeded at 1573 (offset 17 lines).
Hunk #3 succeeded at 1633 (offset 17 lines).
Hunk #4 succeeded at 2263 (offset 17 lines).
Hunk #5 succeeded at 2981 (offset 17 lines).
Hunk #6 succeeded at 2997 (offset 17 lines).
Hunk #7 succeeded at 3013 (offset 17 lines).
Hunk #8 succeeded at 3162 (offset 17 lines).
Hunk #9 succeeded at 3346 (offset 17 lines).
Hunk #10 succeeded at 3367 (offset 17 lines).
Hunk #11 succeeded at 3398 (offset 17 lines).
Hunk #12 succeeded at 3455 (offset 17 lines).
Hunk #13 succeeded at 3467 (offset 17 lines).
Hunk #14 succeeded at 3481 (offset 17 lines).
Checking patch kernel/irq/handle.c...
Checking patch kernel/irq/manage.c...
Hunk #1 succeeded at 1098 (offset -1 lines).
Hunk #2 succeeded at 2686 (offset -1 lines).
Checking patch kernel/irq/spurious.c...
Checking patch kernel/irq_work.c...
Checking patch kernel/kexec_core.c...
Checking patch kernel/ksysfs.c...
Checking patch kernel/locking/Makefile...
Checking patch kernel/locking/lockdep.c...
Hunk #1 succeeded at 4415 (offset 5 lines).
Hunk #2 succeeded at 4430 (offset 5 lines).
Checking patch kernel/locking/locktorture.c...
Checking patch kernel/locking/mutex-rt.c...
Checking patch kernel/locking/rtmutex.c...
Checking patch kernel/locking/rtmutex_common.h...
Checking patch kernel/locking/rwlock-rt.c...
Checking patch kernel/locking/rwsem-rt.c...
Checking patch kernel/locking/rwsem.c...
Checking patch kernel/locking/rwsem.h...
Checking patch kernel/locking/spinlock.c...
Checking patch kernel/locking/spinlock_debug.c...
Checking patch kernel/panic.c...
Checking patch kernel/power/hibernate.c...
Checking patch kernel/power/suspend.c...
Hunk #1 succeeded at 595 (offset 1 line).
Hunk #2 succeeded at 611 (offset 1 line).
Hunk #3 succeeded at 621 (offset 1 line).
Checking patch kernel/printk/Makefile...
Checking patch kernel/printk/internal.h...
error: while searching for:
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * internal.h - printk internal definitions
 */
#include <linux/percpu.h>

#ifdef CONFIG_PRINTK

#define PRINTK_SAFE_CONTEXT_MASK	 0x3fffffff
#define PRINTK_NMI_DIRECT_CONTEXT_MASK	 0x40000000
#define PRINTK_NMI_CONTEXT_MASK		 0x80000000

extern raw_spinlock_t logbuf_lock;

__printf(5, 0)
int vprintk_store(int facility, int level,
		  const char *dict, size_t dictlen,
		  const char *fmt, va_list args);

__printf(1, 0) int vprintk_default(const char *fmt, va_list args);
__printf(1, 0) int vprintk_deferred(const char *fmt, va_list args);
__printf(1, 0) int vprintk_func(const char *fmt, va_list args);
void __printk_safe_enter(void);
void __printk_safe_exit(void);

#define printk_safe_enter_irqsave(flags)	\
	do {					\
		local_irq_save(flags);		\
		__printk_safe_enter();		\
	} while (0)

#define printk_safe_exit_irqrestore(flags)	\
	do {					\
		__printk_safe_exit();		\
		local_irq_restore(flags);	\
	} while (0)

#define printk_safe_enter_irq()		\
	do {					\
		local_irq_disable();		\
		__printk_safe_enter();		\
	} while (0)

#define printk_safe_exit_irq()			\
	do {					\
		__printk_safe_exit();		\
		local_irq_enable();		\
	} while (0)

void defer_console_output(void);

#else

__printf(1, 0) int vprintk_func(const char *fmt, va_list args) { return 0; }

/*
 * In !PRINTK builds we still export logbuf_lock spin_lock, console_sem
 * semaphore and some of console functions (console_unlock()/etc.), so
 * printk-safe must preserve the existing local IRQ guarantees.
 */
#define printk_safe_enter_irqsave(flags) local_irq_save(flags)
#define printk_safe_exit_irqrestore(flags) local_irq_restore(flags)

#define printk_safe_enter_irq() local_irq_disable()
#define printk_safe_exit_irq() local_irq_enable()

#endif /* CONFIG_PRINTK */

error: patch failed: kernel/printk/internal.h:1
error: kernel/printk/internal.h: patch does not apply
Checking patch kernel/printk/printk.c...
error: while searching for:
#define LOG_LEVEL(v)		((v) & 0x07)
#define LOG_FACILITY(v)		((v) >> 3 & 0xff)

/* record buffer */
#define LOG_ALIGN __alignof__(struct printk_log)
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
#define LOG_BUF_LEN_MAX (u32)(1 << 31)
static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
static char *log_buf = __log_buf;
static u32 log_buf_len = __LOG_BUF_LEN;

/* Return log buffer address */
char *log_buf_addr_get(void)
{
	return log_buf;
}

/* Return log buffer size */
u32 log_buf_len_get(void)
{
	return log_buf_len;
}

/* human readable text of the record */

error: patch failed: kernel/printk/printk.c:452
error: kernel/printk/printk.c: patch does not apply
Checking patch kernel/printk/printk_safe.c...
error: while searching for:
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * printk_safe.c - Safe printk for printk-deadlock-prone contexts
 */

#include <linux/preempt.h>
#include <linux/spinlock.h>
#include <linux/debug_locks.h>
#include <linux/smp.h>
#include <linux/cpumask.h>
#include <linux/irq_work.h>
#include <linux/printk.h>

#include "internal.h"

/*
 * printk() could not take logbuf_lock in NMI context. Instead,
 * it uses an alternative implementation that temporary stores
 * the strings into a per-CPU buffer. The content of the buffer
 * is later flushed into the main ring buffer via IRQ work.
 *
 * The alternative implementation is chosen transparently
 * by examinig current printk() context mask stored in @printk_context
 * per-CPU variable.
 *
 * The implementation allows to flush the strings also from another CPU.
 * There are situations when we want to make sure that all buffers
 * were handled or when IRQs are blocked.
 */
static int printk_safe_irq_ready __read_mostly;

#define SAFE_LOG_BUF_LEN ((1 << CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT) -	\
				sizeof(atomic_t) -			\
				sizeof(atomic_t) -			\
				sizeof(struct irq_work))

struct printk_safe_seq_buf {
	atomic_t		len;	/* length of written data */
	atomic_t		message_lost;
	struct irq_work		work;	/* IRQ work that flushes the buffer */
	unsigned char		buffer[SAFE_LOG_BUF_LEN];
};

static DEFINE_PER_CPU(struct printk_safe_seq_buf, safe_print_seq);
static DEFINE_PER_CPU(int, printk_context);

#ifdef CONFIG_PRINTK_NMI
static DEFINE_PER_CPU(struct printk_safe_seq_buf, nmi_print_seq);
#endif

/* Get flushed in a more safe context. */
static void queue_flush_work(struct printk_safe_seq_buf *s)
{
	if (printk_safe_irq_ready)
		irq_work_queue(&s->work);
}

/*
 * Add a message to per-CPU context-dependent buffer. NMI and printk-safe
 * have dedicated buffers, because otherwise printk-safe preempted by
 * NMI-printk would have overwritten the NMI messages.
 *
 * The messages are flushed from irq work (or from panic()), possibly,
 * from other CPU, concurrently with printk_safe_log_store(). Should this
 * happen, printk_safe_log_store() will notice the buffer->len mismatch
 * and repeat the write.
 */
static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
						const char *fmt, va_list args)
{
	int add;
	size_t len;
	va_list ap;

again:
	len = atomic_read(&s->len);

	/* The trailing '\0' is not counted into len. */
	if (len >= sizeof(s->buffer) - 1) {
		atomic_inc(&s->message_lost);
		queue_flush_work(s);
		return 0;
	}

	/*
	 * Make sure that all old data have been read before the buffer
	 * was reset. This is not needed when we just append data.
	 */
	if (!len)
		smp_rmb();

	va_copy(ap, args);
	add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, ap);
	va_end(ap);
	if (!add)
		return 0;

	/*
	 * Do it once again if the buffer has been flushed in the meantime.
	 * Note that atomic_cmpxchg() is an implicit memory barrier that
	 * makes sure that the data were written before updating s->len.
	 */
	if (atomic_cmpxchg(&s->len, len, len + add) != len)
		goto again;

	queue_flush_work(s);
	return add;
}

static inline void printk_safe_flush_line(const char *text, int len)
{
	/*
	 * Avoid any console drivers calls from here, because we may be
	 * in NMI or printk_safe context (when in panic). The messages
	 * must go only into the ring buffer at this stage.  Consoles will
	 * get explicitly called later when a crashdump is not generated.
	 */
	printk_deferred("%.*s", len, text);
}

/* printk part of the temporary buffer line by line */
static int printk_safe_flush_buffer(const char *start, size_t len)
{
	const char *c, *end;
	bool header;

	c = start;
	end = start + len;
	header = true;

	/* Print line by line. */
	while (c < end) {
		if (*c == '\n') {
			printk_safe_flush_line(start, c - start + 1);
			start = ++c;
			header = true;
			continue;
		}

		/* Handle continuous lines or missing new line. */
		if ((c + 1 < end) && printk_get_level(c)) {
			if (header) {
				c = printk_skip_level(c);
				continue;
			}

			printk_safe_flush_line(star
error: patch failed: kernel/printk/printk_safe.c:1
error: kernel/printk/printk_safe.c: patch does not apply
Checking patch kernel/ptrace.c...
Checking patch kernel/rcu/Kconfig...
Checking patch kernel/rcu/rcutorture.c...
Checking patch kernel/rcu/srcutiny.c...
Checking patch kernel/rcu/srcutree.c...
error: while searching for:
	unsigned long t;

	/* If the local srcu_data structure has callbacks, not idle.  */
	local_irq_save(flags);
	sdp = this_cpu_ptr(ssp->sda);
	if (rcu_segcblist_pend_cbs(&sdp->srcu_cblist)) {
		local_irq_restore(flags);
		return false; /* Callbacks already present, so not idle. */
	}
	local_irq_restore(flags);

	/*
	 * No local callbacks, so probabalistically probe global state.

error: patch failed: kernel/rcu/srcutree.c:764
error: kernel/rcu/srcutree.c: patch does not apply
Checking patch kernel/rcu/tree.c...
Hunk #2 succeeded at 1097 (offset 1 line).
Hunk #3 succeeded at 2671 (offset 1 line).
Checking patch kernel/rcu/tree_exp.h...
Hunk #1 succeeded at 668 (offset -2 lines).
Checking patch kernel/rcu/tree_plugin.h...
Hunk #2 succeeded at 793 (offset 1 line).
Hunk #3 succeeded at 843 (offset 1 line).
Checking patch kernel/rcu/update.c...
Checking patch kernel/sched/completion.c...
Checking patch kernel/sched/core.c...
Hunk #6 succeeded at 1525 (offset -4 lines).
Hunk #7 succeeded at 1574 (offset -4 lines).
Hunk #8 succeeded at 1610 (offset -4 lines).
Hunk #9 succeeded at 1637 (offset -4 lines).
Hunk #10 succeeded at 1655 (offset -4 lines).
Hunk #11 succeeded at 1733 (offset -4 lines).
Hunk #12 succeeded at 1755 (offset -4 lines).
Hunk #13 succeeded at 1953 (offset -4 lines).
Hunk #14 succeeded at 2009 (offset -4 lines).
Hunk #15 succeeded at 2024 (offset -4 lines).
Hunk #16 succeeded at 2613 (offset -4 lines).
Hunk #17 succeeded at 2637 (offset -4 lines).
Hunk #18 succeeded at 2646 (offset -4 lines).
Hunk #19 succeeded at 2758 (offset -4 lines).
Hunk #20 succeeded at 2786 (offset -4 lines).
Hunk #21 succeeded at 3040 (offset -4 lines).
Hunk #22 succeeded at 3370 (offset -4 lines).
Hunk #23 succeeded at 4087 (offset -1 lines).
Hunk #24 succeeded at 4159 (offset -1 lines).
Hunk #25 succeeded at 4183 (offset -1 lines).
Hunk #26 succeeded at 4371 (offset -1 lines).
Hunk #27 succeeded at 4408 (offset -1 lines).
Hunk #28 succeeded at 4436 (offset -1 lines).
Hunk #35 succeeded at 8139 (offset 13 lines).
Checking patch kernel/sched/debug.c...
Checking patch kernel/sched/fair.c...
Hunk #1 succeeded at 4130 (offset 8 lines).
Hunk #2 succeeded at 4154 (offset 8 lines).
Hunk #3 succeeded at 4297 (offset 8 lines).
Hunk #4 succeeded at 4422 (offset 8 lines).
Hunk #5 succeeded at 5146 (offset 19 lines).
Hunk #6 succeeded at 6749 (offset 20 lines).
Hunk #7 succeeded at 10016 (offset 32 lines).
Hunk #8 succeeded at 10040 (offset 32 lines).
Checking patch kernel/sched/features.h...
Checking patch kernel/sched/isolation.c...
Checking patch kernel/sched/sched.h...
Hunk #1 succeeded at 1005 (offset 6 lines).
Hunk #2 succeeded at 1654 (offset 6 lines).
Hunk #3 succeeded at 1882 (offset 6 lines).
Checking patch kernel/sched/swait.c...
Checking patch kernel/sched/topology.c...
Checking patch kernel/signal.c...
error: while searching for:
	if (override_rlimit ||
	    atomic_read(&user->sigpending) <=
			task_rlimit(t, RLIMIT_SIGPENDING)) {
		q = kmem_cache_alloc(sigqueue_cachep, flags);
	} else {
		print_dropped_signal(sig);
	}

error: patch failed: kernel/signal.c:426
error: kernel/signal.c: patch does not apply
Checking patch kernel/softirq.c...
Checking patch kernel/stop_machine.c...
Checking patch kernel/sysctl.c...
Hunk #1 succeeded at 1500 (offset 12 lines).
Hunk #2 succeeded at 1510 (offset 12 lines).
Checking patch kernel/time/hrtimer.c...
Hunk #1 succeeded at 1819 (offset 3 lines).
Hunk #2 succeeded at 1873 (offset 3 lines).
Hunk #3 succeeded at 1982 (offset 3 lines).
Checking patch kernel/time/jiffies.c...
Checking patch kernel/time/posix-cpu-timers.c...
Checking patch kernel/time/tick-common.c...
Checking patch kernel/time/tick-sched.c...
Hunk #1 succeeded at 65 (offset 1 line).
Hunk #2 succeeded at 92 (offset 4 lines).
Hunk #3 succeeded at 108 (offset 4 lines).
Hunk #4 succeeded at 239 (offset 4 lines).
Hunk #5 succeeded at 671 (offset 4 lines).
Hunk #6 succeeded at 904 (offset 4 lines).
Checking patch kernel/time/timekeeping.c...
Checking patch kernel/time/timekeeping.h...
Checking patch kernel/time/timer.c...
Checking patch kernel/trace/trace.c...
Hunk #1 succeeded at 2343 (offset 8 lines).
Hunk #2 succeeded at 2355 (offset 8 lines).
Hunk #3 succeeded at 3585 (offset 8 lines).
Hunk #4 succeeded at 3631 (offset 8 lines).
Hunk #5 succeeded at 3670 (offset 8 lines).
Hunk #6 succeeded at 8952 (offset 34 lines).
Hunk #7 succeeded at 9028 (offset 34 lines).
Checking patch kernel/trace/trace.h...
Checking patch kernel/trace/trace_events.c...
Checking patch kernel/trace/trace_output.c...
Checking patch kernel/workqueue.c...
error: while searching for:
 * ignored.
 */
#define for_each_pwq(pwq, wq)						\
	list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node)		\
		if (({ assert_rcu_or_wq_mutex(wq); false; })) { }	\
		else

#ifdef CONFIG_DEBUG_OBJECTS_WORK


error: patch failed: kernel/workqueue.c:425
error: kernel/workqueue.c: patch does not apply
Checking patch lib/Kconfig.debug...
Hunk #2 succeeded at 1061 (offset -9 lines).
Hunk #3 succeeded at 1239 (offset -9 lines).
Checking patch lib/Makefile...
Checking patch lib/bust_spinlocks.c...
Checking patch lib/debugobjects.c...
Hunk #1 succeeded at 537 (offset 4 lines).
Checking patch lib/irq_poll.c...
Checking patch lib/locking-selftest.c...
Checking patch lib/nmi_backtrace.c...
Checking patch lib/printk_ringbuffer.c...
Checking patch lib/radix-tree.c...
Checking patch lib/scatterlist.c...
Checking patch lib/smp_processor_id.c...
Checking patch lib/ubsan.c...
error: while searching for:
	}
}

static DEFINE_SPINLOCK(report_lock);

static void ubsan_prologue(struct source_location *location,
			unsigned long *flags)
{
	current->in_ubsan++;
	spin_lock_irqsave(&report_lock, *flags);

	pr_err("========================================"
		"========================================\n");
	print_source_location("UBSAN: Undefined behaviour in", location);
}

static void ubsan_epilogue(unsigned long *flags)
{
	dump_stack();
	pr_err("========================================"
		"========================================\n");
	spin_unlock_irqrestore(&report_lock, *flags);
	current->in_ubsan--;
}


error: patch failed: lib/ubsan.c:140
error: lib/ubsan.c: patch does not apply
Checking patch localversion-rt...
Checking patch mm/Kconfig...
Checking patch mm/compaction.c...
Checking patch mm/highmem.c...
Checking patch mm/internal.h...
Checking patch mm/kmemleak.c...
Checking patch mm/memcontrol.c...
Hunk #3 succeeded at 2281 (offset 13 lines).
Hunk #4 succeeded at 2302 (offset 13 lines).
Hunk #5 succeeded at 5556 (offset 38 lines).
Hunk #6 succeeded at 6609 (offset 38 lines).
Hunk #7 succeeded at 6681 (offset 38 lines).
Hunk #8 succeeded at 6689 (offset 38 lines).
Hunk #9 succeeded at 6852 (offset 38 lines).
Hunk #10 succeeded at 7037 (offset 28 lines).
Hunk #11 succeeded at 7083 (offset 28 lines).
Checking patch mm/memory.c...
Hunk #1 succeeded at 2134 (offset 1 line).
Checking patch mm/page_alloc.c...
Hunk #2 succeeded at 345 (offset -13 lines).
Hunk #3 succeeded at 1236 (offset -20 lines).
Hunk #4 succeeded at 1246 (offset -20 lines).
Hunk #5 succeeded at 1328 (offset -20 lines).
Hunk #6 succeeded at 1343 (offset -20 lines).
Hunk #7 succeeded at 1443 (offset -20 lines).
Hunk #8 succeeded at 2819 (offset -15 lines).
Hunk #9 succeeded at 2846 (offset -15 lines).
Hunk #10 succeeded at 2879 (offset -15 lines).
Hunk #11 succeeded at 2897 (offset -15 lines).
Hunk #12 succeeded at 2984 (offset -15 lines).
Hunk #13 succeeded at 3069 (offset -15 lines).
Hunk #14 succeeded at 3099 (offset -15 lines).
Hunk #15 succeeded at 3111 (offset -15 lines).
Hunk #16 succeeded at 3132 (offset -15 lines).
Hunk #17 succeeded at 3146 (offset -15 lines).
Hunk #18 succeeded at 3316 (offset -15 lines).
Hunk #19 succeeded at 3324 (offset -15 lines).
Hunk #20 succeeded at 3351 (offset -15 lines).
Hunk #21 succeeded at 3371 (offset -15 lines).
Hunk #22 succeeded at 3384 (offset -15 lines).
Hunk #23 succeeded at 8618 (offset -5 lines).
Hunk #24 succeeded at 8627 (offset -5 lines).
Checking patch mm/slab.c...
Checking patch mm/slab.h...
Checking patch mm/slub.c...
Hunk #10 succeeded at 1991 (offset -2 lines).
Hunk #11 succeeded at 2036 (offset -2 lines).
Hunk #12 succeeded at 2150 (offset -2 lines).
Hunk #13 succeeded at 2161 (offset -2 lines).
Hunk #14 succeeded at 2185 (offset -2 lines).
Hunk #15 succeeded at 2224 (offset -2 lines).
Hunk #16 succeeded at 2256 (offset -2 lines).
Hunk #17 succeeded at 2293 (offset -2 lines).
Hunk #18 succeeded at 2375 (offset -2 lines).
Hunk #19 succeeded at 2445 (offset -2 lines).
Hunk #20 succeeded at 2587 (offset -2 lines).
Hunk #21 succeeded at 2656 (offset 8 lines).
Hunk #22 succeeded at 2678 (offset 8 lines).
Hunk #23 succeeded at 2691 (offset 8 lines).
Hunk #24 succeeded at 2703 (offset 8 lines).
Hunk #25 succeeded at 2715 (offset 8 lines).
Hunk #26 succeeded at 2761 (offset 8 lines).
Hunk #27 succeeded at 2916 (offset 8 lines).
Hunk #28 succeeded at 2948 (offset 8 lines).
Hunk #29 succeeded at 2989 (offset 8 lines).
Hunk #30 succeeded at 3004 (offset 8 lines).
Hunk #31 succeeded at 3041 (offset 8 lines).
Hunk #32 succeeded at 3209 (offset 10 lines).
Hunk #33 succeeded at 3242 (offset 19 lines).
Hunk #34 succeeded at 3257 (offset 19 lines).
Hunk #35 succeeded at 3272 (offset 19 lines).
Hunk #36 succeeded at 3408 (offset 19 lines).
Hunk #37 succeeded at 3757 (offset 19 lines).
Hunk #38 succeeded at 3781 (offset 19 lines).
Hunk #39 succeeded at 3796 (offset 19 lines).
Hunk #40 succeeded at 3806 (offset 19 lines).
Hunk #41 succeeded at 4078 (offset 19 lines).
Hunk #42 succeeded at 4109 (offset 19 lines).
Hunk #43 succeeded at 4316 (offset 19 lines).
Hunk #44 succeeded at 4523 (offset 19 lines).
Hunk #45 succeeded at 4545 (offset 19 lines).
Hunk #46 succeeded at 4731 (offset 19 lines).
Checking patch mm/swap.c...
Checking patch mm/vmalloc.c...
Hunk #1 succeeded at 1078 (offset 1 line).
Hunk #2 succeeded at 1463 (offset 1 line).
Hunk #3 succeeded at 1506 (offset 1 line).
Hunk #4 succeeded at 1580 (offset 1 line).
Hunk #5 succeeded at 1595 (offset 1 line).
Hunk #6 succeeded at 1619 (offset 1 line).
Checking patch mm/vmstat.c...
Checking patch mm/workingset.c...
Checking patch mm/zsmalloc.c...
Checking patch mm/zswap.c...
Checking patch net/Kconfig...
Hunk #1 succeeded at 281 (offset 3 lines).
Checking patch net/core/dev.c...
Hunk #1 succeeded at 195 (offset -1 lines).
Hunk #2 succeeded at 218 (offset -1 lines).
Hunk #3 succeeded at 820 (offset -1 lines).
Hunk #4 succeeded at 839 (offset -1 lines).
Hunk #5 succeeded at 1117 (offset -1 lines).
Hunk #6 succeeded at 1140 (offset -1 lines).
Hunk #7 succeeded at 1166 (offset -1 lines).
Hunk #8 succeeded at 1180 (offset -1 lines).
Hunk #9 succeeded at 2674 (offset -1 lines).
Hunk #10 succeeded at 2737 (offset -1 lines).
Hunk #11 succeeded at 3409 (offset -17 lines).
Hunk #12 succeeded at 4207 (offset -16 lines).
Hunk #13 succeeded at 4422 (offset -16 lines).
Hunk #14 succeeded at 4432 (offset -16 lines).
Hunk #15 succeeded at 4478 (offset -16 lines).
Hunk #16 succeeded at 5232 (offset -16 lines).
Hunk #17 succeeded at 5242 (offset -16 lines).
Hunk #18 succeeded at 5833 (offset -15 lines).
Hunk #19 succeeded at 5870 (offset -15 lines).
Hunk #20 succeeded at 5880 (offset -15 lines).
Hunk #21 succeeded at 5920 (offset -15 lines).
Hunk #22 succeeded at 6364 (offset -14 lines).
Hunk #23 succeeded at 9888 (offset -7 lines).
Hunk #24 succeeded at 9902 (offset -7 lines).
Hunk #25 succeeded at 10219 (offset -7 lines).
Checking patch net/core/gen_estimator.c...
Checking patch net/core/gen_stats.c...
Checking patch net/kcm/Kconfig...
Checking patch net/packet/af_packet.c...
Hunk #2 succeeded at 661 (offset 1 line).
Hunk #3 succeeded at 923 (offset 1 line).
Checking patch net/sched/sch_api.c...
Checking patch net/sched/sch_generic.c...
Checking patch net/sunrpc/svc_xprt.c...
Checking patch security/apparmor/include/path.h...
Hunk #1 succeeded at 37 (offset 1 line).
Hunk #2 succeeded at 50 (offset 1 line).
Hunk #3 succeeded at 76 (offset 1 line).
Checking patch security/apparmor/lsm.c...
Hunk #1 succeeded at 42 (offset -2 lines).
Checking patch virt/kvm/arm/arch_timer.c...
Checking patch virt/kvm/arm/arm.c...
Sorry, an error occurred in Snapcraft:
Failed to run 'override-build': Exit code was 1.

what about using git instead of pre-made patches:

https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

and as last resort, simply use the rt tree as base and apply the missing apprmor patch on top of it, here is an example of using a BSP kernel where i apply the config defaults needed for UC and add the matching apparmor patch (ignore the wlan firmware in that commit):

You can’t compare the Ubuntu kernel versions with upstream’s kernel versions like that. As Ubuntu kernels are all based on upstream’s kernels, you can find out which upstream kernels they are based on, by either looking at the git log, or the mapping table here (scroll to focal linux if you look for v5.4). After you have figured out the base kernel version, you can pick the corresponding RT patches.

I also suggest you to apply the RT patches manually on the kernel tree first to see if it works, instead of doing that in snapcraft build from the beginning. Once you have a working tree and patches, then you can do that in snapcraft.yaml.

2 Likes

Thank you for your great suggestions @ogra and @anthonywong,
now I am able to correctly build a patched custom kernel snap.

Although, I have a new issue now. In particular, after having built a custom UC image having a custom kernel snap, I get the following “error” when performing the first boot:

Begin: Running /scripts/local-premount ... findfs: unable to resolve 'LABEL=writable'
done.

The installation does not proceed after that. This also occurs if I do not patch the kernel but simply build a custom kernel snap based on a version of ubuntu-bionic kernel “as it is”.

In particular, the procedure I follow to build this custom kernel snap is:

$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-bionic.git
$ cd ubuntu-bionic
$ git checkout -b myversion Ubuntu-hwe-5.0.0-37.40_18.04.1
$ snapcraft

(I also tried with git checkout -b myversion Ubuntu-4.13.0-25.29)
Then, I use the resulting .snap to build a custom UC image having the following .json file:

{
  "type": "model",
  "series": "16",
  "model": "ubuntu-core-18-amd64",
  "display-name": "Ubuntu Core 18 (amd64)",
  "architecture": "amd64",
  "kernel": "my-custom-kernel",
  "gadget": "pc=18",
  "base": "core18",
  "required-snaps": ["core"],
  "authority-id": "my-developer-id",
  "brand-id": "my-developer-id",
  "timestamp": "current_time"
}

Then I use $ ubuntu-image snap --extra-snaps my-custom-kernel.snap my-model.model
And finally I create a bootable USB using the resulting pc.img file.

Do you have any idea about why I get this issue?

you are probably missing usb-storage support … either build it into teh kernel or define it in the snapcraft.yaml in the kernel part (there is an option to add initramfs modules, i cant look up the exact word for it atm)

1 Like

Thank you, I think that it could be:
kernel-image-target: bzImage

I try

it is kernel-initrd-modules …

1 Like

[anthonywong] anthonywong https://forum.snapcraft.io/u/anthonywong
April 14

You can’t compare the Ubuntu kernel versions with upstream’s kernel
versions like that. As Ubuntu kernels are all based on upstream’s
kernels, you can find out which upstream kernels they are based on, by
either looking at the git log
https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal/log/,
or the mapping table here
https://people.canonical.com/~kernel/info/kernel-version-map.html
(scroll to focal linux if you look for v5.4). After you have figured
out the base kernel version, you can pick the corresponding RT patches.

I also suggest you to apply the RT patches manually on the kernel tree
first to see if it works, instead of doing that in snapcraft build from
the beginning. Once you have a working tree and patches, then you can do
that in snapcraft.yaml.

Also one needs to be sure the correct config is being used. Enabling RT
options based on the ubuntu kernel config may lead to build issues as
some drivers may be enabled and may not build or not work reliably with
RT enabled. You will find that if you use the default RT configs then
this will deviate from the larger super set of enabled options.

There are times where RT is not the silver bullet you are looking for,
it maybe preferable to use the lowlatency kernel as this is fully
supported and may offer the latency requirements you desire without the
complexities of RT.

Colin

1 Like

Oh OK @ogra, sorry but I am not really familiar with this… What should I put to add the usb-storage support? I mean, is the following good?
kernel-initrd-modules: ["initramfs"]