[ASUS ZenFone 7 / 7 Pro ROMs, Kernels, Recoveries, ] Freak07:
Kirisakura-Kernel for the Asus Zenfone 7/Pro

Hello everyone,

To keep it short: Here is Kirisakura - Kernel for the Asus Zenfone 7/Pro aka Tequila. The Zenfone line- up internal codenames are derived from alcoholic drinks, last year the Zenfone 6 bore the title Kirin.

I would appreciate if everybody that flashes the kernel, reads at least once through this opening post and the following ones.

Kirisakura - Kernel is designed to bring a handful of beneficial features to the device, while ensuring excellent performance and smoothness to get you safely through the day!

If you expect a custom kernel to magically improve your devices battery life manifold and this is your only priority then this might not be the right place for you. Instead there is an option called battery saver in the options of your phone.

However the kernel is built to keep battery life close to the same as you would experience the on stock kernel while being tuned to perform better in various UI related benchmarks. The same benches are used by google to verify and ensure UI smoothness on the Pixel devices. The scheduler is tuned to yield lower jitter and reduce jank frames.

If that got your curious, I welcome you to continue reading if you´re still interested!

This project aims to keep most of the subsystems updated, way ahead of the stock kernel, thereby improving security and performance, while keeping stability as the foucs during testing! This includes Linux-Stable, CAF-Upstream and kernel/common.

Kernel Control Flow Integrity (Kernel-CFI), which is achieved by linking the kernel with LLD and Link Time Optimization (LTO), more precisely ThinLTO, are quite unique security features.

The recently released Kirisakura-Kernel for the OnePlus 8 Pro was featured on the XDA-Portal due to the inclusion of CFI. The featured article explains CFI in great details, is easy to understand and definitely worth to read.

If possible the latest Kirisakura-Kernel releases for various devices aim to include CFI in enforcing mode so users can benefit from this security features.

Another security feature is Shadow Call Stack (SCS).

SCS is another security patchset that is aimed at preventing attacks via return oriented programming (ROP).

ROP is a technique where the attacker gains control of the kernel stack to overwrite function return addresses and redirect execution to carefully selected parts of existing kernel code.

If you´re interested here are a few good links:

Google Security Blog explaining SCS.

LLVM doc about SCS

Android DOCs documenting SCS

If reading about upstream in the paragraph above got you curious,have a read about Linux-Stable and why it is important here. The stable-process is not the same for every subsystem, but the general idea, rule of thumb and benefits are applicable for other subsystems as well.

Quick explanation of CAF-Upstream. CAF is short for Codeaurora-Forums. This is the place where development from Qualcomm for their SoCs happens. This includes the Snapdragon 865/+ that´s built into the different SKUs of the Zenfone 7/Pro.

The kernel-bases available on the Codeaurora-Forums, are basically the foundations OEMs use, to build their own kernel additions on top for devices featuring Qualcomm SoCs.

The Qualcomm developers push regular updates to the bases of the different SoCs, a bit similar to how Linux-Upstream works. OEMs usually stop updating the initial base after the phone is released.

This kernel focuses amongst the other features to provide the latest CAF-Updates merged in a regular manner, to provide updates, improvements and enhancements for SoC specific drivers and subsystems! This might take a while, because a lot of device specific testing is done on my end to ensure stability.

The kernel includes a lot of improvements and contributions from other developers as well. Without this kernel would not exist.

A big part of improvements originate from @arter97´s, @kdrag0n´s and @Sultanxda´s work. Many others contributed in some way or another to this kernel.

A big thanks to all of them at this place!

Now lets continue with a list of features in the next paragraph!

Main Features:

- Based on latest kernel sources from Asus for Android 12 and intended for use on the latest Asus Stock-Firmware

- compiled with Clang 13.0.1 and built with -O3 speed optimizations

- Linux-Stable-Upstream included to 4.19.2240

- CAF base for the Snapdragon 865/+ (SD865/+) updated to upstream CAF

- Kernel Control-Flow-Integration (CFI) andLink-Time-Optimization (LTO) ported from 4.19 kernel/common and Pixel 5/4/XL Kernel

- Shadow Call Stack (SCS) Security-Feature

- Use ThinLTO which was first used in the Pixel 4 XL Android R-Preview Kernel instead of full LTO for full program visibility (needed by CFI)

- fix CFI-Violations found in various subsystems like Asus/device specific drivers and qualcomm drivers

- Link the kernel with LLD and use RELR-Relocation

- include important fixes/improvements from kernel/common

- Flashing the kernel will keep root!

- Flashable via EXKM, FKM or TWRP on a rooted system!

- Anykernel zip is based on the Anykernel3 release from @osm0sis

- disable various debugging configs, that are not needed in a perf build kernel according to google.

- disable selinux auditing (we don´t have to adress selinux denials running a stock rom)

- display tweaks to reduce power consumption on statically rendered images

- option to limit max cpu frequency (3 levels) also to cpu boosting during input, without enabling powersaver mode that restricts background data sometimes killing notifications

EAS related features:

- EAS implementation patched up to latest CAF state

- disable autogroups and use cgroups for more efficient task placement!

- updates from kernel/common

- scheduler updates from Googles Pixel kernel

- tune scheduler for improved jitter and less jank frames

- scheduler updates for RT tasks

- scheduler updates from sd888/ 5.4 kernel

- mainline scheduler updates for better load balancing on sched_idle cpus

CPU related features:

- Change various drivers (WLAN, MM, audio, charger, power, thermal, glink etc) to user power efficient workingqueues. This compliments EAS

- improvements to cpufreq/times/stats

- improve memory allocations in binder driver

- vdso32 patches as found on Google Pixel devices (brief documentation here)

- arm64: lse: Prefetch operands to speed up atomic operations, thanks @kdrag0n

- implement fast refcount checking

- remove RTB logging to reduce overhead

- remove event debug logging

GPU related features:

- GPU driver updated to latest CAF-State

- remove POPP functionality from GPU driver to avoid constant fight about downscaling with msm-adreno-tz

- don´t wake the gpu on touch input, instead wake when receiving an ioctl

- don´t copy fence names by default to save a bit of cpu-time (explanation)

- msm: kgsl: Stop slab shrinker when no more pages can be reclaimed

- gpu/kgsl improvements from pixel 4/pixel 5 kernel

- add low_prio_worker thread for gpu driver (Improves performance when tearing down processes (eg, via LMK) and not blocking currently running UI from submitting work to the GPU

File System related features:

- improve memory allocations in sdcardfs

- improve eventpoll logging to stop indicting timerfd (improves kernel wakelock readability)

- improve memory allocations in kernfs

- writeback: hardcode dirty_expire_centisecs=3000 based on this commit

- ufs improvements from pixel 4/ pixel 5 kernel

- default IO scheduler to CFQ and readahead to 128

- improve GC as to not interfere while user interaction is happening and prevent possible jitter or latency spikes

UI/UX/Usability:

- Backlight Dimmer (reduce minimal brightness on a solid white background from 2,3 lux to 1,6 lux)

- sweep to sleep

- touch sampling override option (set stock touchsampling rate from 120hz to 200hz for reduced touch latency)

Network related features:

- Wireguard Support (Details)

- advanced TCP algorithms enabled

- use bbr as default TCP congestion algorithm (fasted algo according to this excellent research from @kdrag0n found here )

- includes new bbr and bbr2

Memory related features:

- Speculative Page Faults left enabled (1. 2) (CAF default)

- various fixes for PSI-Monitor, which is used by the userspace lowmemorykiller-daemon

- Fix various memory leaks in different subsystems

- improved mm with patches from mainline

- various other changes from mainline

- included zstd as an option for ZRAM-algorithm (lz4 is probably the best all around, so only change it if you know why and what you are doing)

- improve memory allocations in various subsystems

- Backport to enable CONFIG_HAVE_MOVE_PMD (see here) , thanks @arter97

- Backport to enable CONFIG_HAVE_MOVE_PUD (commit here) , thanks @arter97

- allow max swappiness over 100, to favor swapping instead of dropping the cache

- free more RAM by removing unused reserved memory regions

Security related features:

- Control-Flow-Integration (CFI) and Link-Time-Optimization (LTO) ported from 4.19 kernel/common and Pixel 5 Kernel

- Use ThinLTO which was first used in the Pixel 4 XL Android R-Kernel instead of full LTO

- Shadow Call Stack (SCS) Security-Feature

- fix various CFI-Violations found in various subsystems like Asus/device specific drivers and qualcomm drivers

- enable init_on_alloc for even more security, more information can be found in the commit message

- Backport mainline Selinux commits for improved performance in the selinux subsystem, thanks @arter97 (you must be on magisk 21.0 or higher, otherwise the kernel won´t boot)

Misc Features:

TCP Congestion Algorithms:

- advanced algorithms enabled, enable them with your favorite kernel manager

- use bbr as default TCP congestion algorithm (fasted algo according to this excellent research from @kdrag0n found here )

- includes new bbr2

Wakelock Blocker:

- advanced wakelock blocker with the ability to block any wakelocks (dangerous, use with caution)

- please read [URL="https://arstechnica.com/gadgets/2018/08/p-is-for-power-how-google-tests-tracks-and-improves-android-battery-life/"]this for further info

- blocking a kernel wakelock should only be done in case of firmware incompatabilities (WiFi network at work (can´t be changed) causes deep sleep to not work on the phone.) That´s the only use case I see for this feature. The kernel does not features this to improve battery life!

Other features:

- disable logging and debugging to make the kernel more lightweight in various places (includes binder, mm, vma, gpu, ipa etc)

- fix several coding issues detected by newer Clang-Toolchains

- implement ramoops functionality to be able to easily debug kernel panics

Feature section for the "non visible" but perceptible improvements:

- updated binder section (responsible for interprocess communication)

Flashing Guide, Download and Changelog

Requirements:

- unlocked Bootloader

- USB-Debugging in developer options enabled

- latest adb and fastboot binaries

- working adb and fastboot environment

- magisk root (magisk 22.0 or higher), usually magisk stable works best

- a backup of stock boot.img and dtbo.img so you can go back to stock conditions (simplest way is TWRP)

How to flash the Kernel:

1. Download the latest kernel.zip and make sure you have properly updated to the latest matching Asus Stock-Firmware. When the Zenfone 7/Pro receives an update it takes Asus a while to release the source code for the new OS and me a while to build a new kernel. If you don´t want to face any issues, wait until I either release an updated kernel or give green light because there were no kernel changes.

Always make sure to run the firmware the kernel is built for!

If you feel adventurous, make sure you have a backup ready!

2. Flash the kernel.zip via latest TWRP, EXKM or FKM app and do a full reboot.

3. Reboot and profit.

DOWNLOAD:

Download is located always in this folder:

Downloads for : -Android- Generic Device/Other | AndroidFileHost.com | Download GApps, Roms, Kernels, Themes, Firmware and more. Free file hosting for all Android developers.

Download GApps, Roms, Kernels, Themes, Firmware, and more. Free file hosting for all Android developers.

www.androidfilehost.com

Important: Read after Download

Please take a look at the second post after flashing the kernel!

Changelog:

Android 11

1.0.0 Initial Release

1.1.3 https://xdaforums.com/t/kernel-29-0...nfone-7-pro-aka-tequila.4269677/post-85018787

1.2.0 https://xdaforums.com/t/kernel-15-0...nfone-7-pro-aka-tequila.4269677/post-85369449

1.2.1 https://xdaforums.com/t/kernel-23-0...nfone-7-pro-aka-tequila.4269677/post-85432205

1.2.5 https://xdaforums.com/t/kernel-05-0...nfone-7-pro-aka-tequila.4269677/post-85797313

1.2.6 https://xdaforums.com/t/kernel-19-1...nfone-7-pro-aka-tequila.4269677/post-86238683

Android 12

1.0.0 https://xdaforums.com/t/kernel-11-0...nfone-7-pro-aka-tequila.4269677/post-87106135

1.0.1 https://xdaforums.com/t/kernel-04-0...nfone-7-pro-aka-tequila.4269677/post-87949953

Donations:

Donations are not mandatory but very welcome if you want to support development or just buy me a coffee/tea :)

If you like my work: http://paypal.me/freak07

Credits:

Asus for the development device, giving me the opportunity to create this project!

@osm0sis for all his work, including the ak3 installer!

@tbalden for being the best HTC, Pixel, OnePlus and now Asus wingman!

@LeeDroid and @mwilky for their awesome roms and work I used on multiple devices!

@Captain_Throwback for all the mentoring and guidance!

@Eliminater74 for bringing me into the game and the Inspiration

@nathanchance for his upstream guidance and assistance

@RenderBroken for helping me out

@flar2 for all his work

@joshuous for all the help he provided to me in the past!

@arter97 for giving me advice

@kdrag0n for his help and advices!

@topjohnwu for magisk!

Source Code: https://github.com/freak07/Kirisakura_TEQUILA_Zenfone_7