Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Compatibility with kernels >= 5.7 #76

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Compatibility with kernels >= 5.7 #76

wants to merge 26 commits into from

Conversation

choff
Copy link

@choff choff commented Mar 8, 2021

Various changes were made to get the kernel modules for Anbox working with kernels 5.7 and later:

  • Making kallsyms_lookup_name() accessible again with a VERY DIRTY hack that relies on KProbes
  • Two other small compile fixes to make everything compile with kernel 5.8

I know that ashmem and binder are now upstream in the kernel, but there are still many distributions that don't enable ashmem and binder support in their kernel config. In that case, one might still want to try "anbox-modules" if nothing else helps. This patch makes it possible to compile ashmem and binder as kernel modules with such newer kernels. It's surely not a great solution, but it's a solution of last resort.

choff added 3 commits March 8, 2021 20:19
On kernel 5.7 and later, kallsyms_lookup_name() can no longer be called from a kernel
module for reasons described here: https://lwn.net/Articles/813350/
As binder really needs to use kallsysms_lookup_name() to access some kernel
functions that otherwise wouldn't be accessible, KProbes are used on later
kernels to get the address of kallsysms_lookup_name(). The function is
afterwards used just as before. This is a very dirty hack though and the much
better solution would be if all the functions that are currently resolved
with kallsysms_lookup_name() would get an EXPORT_SYMBOL() annotation to
make them directly accessible to kernel modules.
With the commit 64fe66e8a95e in the Linux kernel, the member "mmap_sem" in the
struct mm_struct was renamed to "mmap_lock". This patch fixes the resulting
compile errors.
With kernel 5.8, the return value of map_kernel_range_noflush()
was changed. This function now returns 0 on success (instead of
the number of successfully mapped pages).

This commit adjusts binder accordingly.
@TommyTran732
Copy link

This seems to work nicely on Fedora 33 with kernel 5.10. However, on Fedora 34 pre-release with kernel 5.11, it doesn't seem like the modules can be built at all. I am not sure if this is an issue with kernel 5.11 or if it is simply because Fedora 34 pre-release is still somewhat buggy, but it would be awesome if you can have a look :)

@TommyTran732
Copy link

TommyTran732 commented Mar 13, 2021

Oh, and to add a bit more info, dkms was complaining about incompatible gcc/plugin versions when I tried it.

@choff
Copy link
Author

choff commented Mar 13, 2021

Hello @TommyTran732 ,

unfortunately, I cannot invest the time to install Fedora 34 on my machine to duplicate this error... The only kind of help I can offer is to take a look at the error and see if something comes to my mind.. But for this I need the full console output.

Best regards,

Christian

@TommyTran732
Copy link

Hi,

Fedora 33 just got updated to kernel 5.11 today and it seems like it broke binder. It is a different error from what I got on Fedora 34 last time, but here are the logs:

`[Tomster@dhcp-172-30-79-244 ~]$ sudo ls -la /dev/{ashmem,binder}
[sudo] password for Tomster:
ls: cannot access '/dev/binder': No such file or directory
crw-------. 1 root root 10, 124 Mar 20 01:08 /dev/ashmem
[Tomster@dhcp-172-30-79-244 ~]$ sudo dkms status
anbox-ashmem, 1, 5.10.22-200.fc33.x86_64, x86_64: installed
anbox-ashmem, 1, 5.10.23-200.fc33.x86_64, x86_64: installed
anbox-ashmem, 1, 5.11.7-200.fc33.x86_64, x86_64: installed
anbox-binder, 1, 5.10.22-200.fc33.x86_64, x86_64: installed
anbox-binder, 1, 5.10.23-200.fc33.x86_64, x86_64: installed
[Tomster@dhcp-172-30-79-244 ~]$ sudo dkms install anbox-binder/1

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j12 KERNELRELEASE=5.11.7-200.fc33.x86_64 all KERNEL_SRC=/lib/modules/5.11.7-200.fc33.x86_64/build...(bad exit status: 2)
Error! Bad return status for module build on kernel: 5.11.7-200.fc33.x86_64 (x86_64)
Consult /var/lib/dkms/anbox-binder/1/build/make.log for more information.
[Tomster@dhcp-172-30-79-244 ~]$ cat /var/lib/dkms/anbox-binder/1/build/make.log
cat: /var/lib/dkms/anbox-binder/1/build/make.log: Permission denied
[Tomster@dhcp-172-30-79-244 ~]$ sudo cat /var/lib/dkms/anbox-binder/1/build/make.log
DKMS make.log for anbox-binder-1 for kernel 5.11.7-200.fc33.x86_64 (x86_64)
Sat 20 Mar 2021 01:10:05 AM EDT
make -C /lib/modules/5.11.7-200.fc33.x86_64/build V=0 M=$PWD
make[1]: Entering directory '/usr/src/kernels/5.11.7-200.fc33.x86_64'
CC [M] /var/lib/dkms/anbox-binder/1/build/deps.o
CC [M] /var/lib/dkms/anbox-binder/1/build/binder.o
/var/lib/dkms/anbox-binder/1/build/binder.c: In function ‘task_get_unused_fd_flags’:
/var/lib/dkms/anbox-binder/1/build/binder.c:447:9: error: implicit declaration of function ‘__alloc_fd’ [-Werror=implicit-function-declaration]
447 | return __alloc_fd(files, 0, rlim_cur, flags);
| ^~~~~~~~~~
/var/lib/dkms/anbox-binder/1/build/binder.c: In function ‘task_fd_install’:
/var/lib/dkms/anbox-binder/1/build/binder.c:457:3: error: implicit declaration of function ‘__fd_install’; did you mean ‘fd_install’? [-Werror=implicit-function-declaration]
457 | __fd_install(proc->files, fd, file);
| ^~~~~~~~~~~~
| fd_install
/var/lib/dkms/anbox-binder/1/build/binder.c: In function ‘task_close_fd’:
/var/lib/dkms/anbox-binder/1/build/binder.c:470:11: error: implicit declaration of function ‘__close_fd’; did you mean ‘close_fd’? [-Werror=implicit-function-declaration]
470 | retval = __close_fd(proc->files, fd);
| ^~~~~~~~~~
| close_fd
/var/lib/dkms/anbox-binder/1/build/binder.c: In function ‘binder_mmap’:
/var/lib/dkms/anbox-binder/1/build/binder.c:3501:16: error: implicit declaration of function ‘get_files_struct’; did you mean ‘put_files_struct’? [-Werror=implicit-function-declaration]
3501 | proc->files = get_files_struct(current);
| ^~~~~~~~~~~~~~~~
| put_files_struct
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:279: /var/lib/dkms/anbox-binder/1/build/binder.o] Error 1
make[1]: *** [Makefile:1807: /var/lib/dkms/anbox-binder/1/build] Error 2
make[1]: Leaving directory '/usr/src/kernels/5.11.7-200.fc33.x86_64'
make: *** [Makefile:8: all] Error 2`

@chrihoff
Copy link

Hello @TommyTran732 ,

yes, indeed it seems like some kernel changes broke the build. Unfortunately, I am travelling tomorrow and will be away for the next 3 weeks. Today I need to pack my things and it is unlikely that I find the time to look into it. I will try to have a look after I return.

Best regards,

Christian

@vikashraghavan
Copy link

Is there any update on this? I'm too facing the same issue

@chrihoff
Copy link

chrihoff commented May 9, 2021

Hello @vikashraghavan ,

no, no update on this. And I don't know when / if I will look into it at all because kernel 5.11 is not yet available for Raspsberry Pi OS. If you have the skills (or someone else who is affected), you could try to fix it yourself and set a PR to my branch, which I will be happy to integrate. I cannot give any commitment if I find time for it at all.

Best regards,

Christian

@vikashraghavan
Copy link

vikashraghavan commented May 9, 2021

Hi @chrihoff

I found some patch docs related to the error

__alloc_fd
__fd_install
__close_fd

I'm not sure whether it would be useful or not.
Any assistance would be really helpful if you think it's a simple bug to fix.

@chrihoff
Copy link

chrihoff commented May 9, 2021

Hello @vikashraghavan ,

I just had a look at these kernel patches. The links are helpful indeed and pointed me in the right direction. So, it seems like the functions __alloc_fd(), __fd_install() and __close_fd() were removed from the kernel without replacement. However, Binder was refactored upstream upstream in 2018 (see http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/2018-August/125424.html). Since that refactoring, binder no longer needs to use these three functions and can use standard functions instead.

So the task here would be to backport this refactoring to binder also to anbox-modules. That should fix those issues. Unfortunately, this refactoring is quite complex and involves some restructuring, so I am not sure how easy it would be to backport it.

Then the only problem remaining would be the compile error in 'binder_mmap' that @TommyTran732 reported. As of now, I cannot tell what the root cause of this other error is or how to fix it as I simply didn't have the time to look into it.

Best regards,

Christian

@vikashraghavan
Copy link

hey @chrihoff,

I found a binder code for latest kernels
binder.c

Is something possible to do with these?

@chrihoff
Copy link

Hello @vikashraghavan ,

well, you could try to replace binder.c in anbox-modules by the latest one you found... Maybe you'd need to copy over other files, too... But this is not a generic solution for every user as anbox-modules were designed to be compilable against old kernels also. So, there is a lot of compatibility code in there that is missing in the version of binder.c for the latest kernel.

Best regards,

Christian

@vikashraghavan
Copy link

vikashraghavan commented May 10, 2021

Can you please mention which are the other files to be copied?
should all the files in the previous directory should be used?

@chrihoff
Copy link

Hello @vikashraghavan ,

unfortunately, I cannot tell and I don't have time to look into it, either. I guess you'd need to try yourself. I am not sure how well this approach works at all...

Best regards,

Christian

@vikashraghavan
Copy link

Stuck over here while trying to compile latest binder module

DKMS make.log for anbox-binder-1 for kernel 5.11.18-300.fc34.x86_64 (x86_64)
Mon May 10 06:42:54 PM IST 2021
make -C /lib/modules/5.11.18-300.fc34.x86_64/build V=0 M=$PWD
make[1]: Entering directory '/usr/src/kernels/5.11.18-300.fc34.x86_64'
CC [M] /var/lib/dkms/anbox-binder/1/build/binder.o
CC [M] /var/lib/dkms/anbox-binder/1/build/binder_alloc.o
LD [M] /var/lib/dkms/anbox-binder/1/build/binder_linux.o
MODPOST /var/lib/dkms/anbox-binder/1/build/Module.symvers
ERROR: modpost: "can_nice" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "mmput_async" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "task_work_add" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "security_binder_transaction" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "security_binder_transfer_file" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "security_binder_set_context_mgr" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "security_binder_transfer_binder" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "close_fd_get_file" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
ERROR: modpost: "zap_page_range" [/var/lib/dkms/anbox-binder/1/build/binder_linux.ko] undefined!
make[2]: *** [scripts/Makefile.modpost:111: /var/lib/dkms/anbox-binder/1/build/Module.symvers] Error 1
make[2]: *** Deleting file '/var/lib/dkms/anbox-binder/1/build/Module.symvers'
make[1]: *** [Makefile:1725: modules] Error 2
make[1]: Leaving directory '/usr/src/kernels/5.11.18-300.fc34.x86_64'
make: *** [Makefile:9: all] Error 2

Is there some changes should be done to deps.c?
I tried to compile both with and without deps.c (I just suspect it... I really don't know why that file is used)

Any suggestions to direct me in the right way would be really helpful !!!

Over the last years, many fixes and changes have been applied to
Binder in the Linux kernel, but these fixes were never backported
to anbox-modules. The meant that the version of Binder in anbox-modules
was very outdated.

With this commit, Binder has been update to the latest state from
the Linux kernel. This should also fix the compile on kernel 5.12
and later.
@Catiks
Copy link

Catiks commented Nov 15, 2021

hi,
make -C /lib/modules/5.13.0-21-generic/build V=0 M=$PWD
make[1]: 进入目录“/usr/src/linux-headers-5.13.0-21-generic”
CC [M] /var/lib/dkms/anbox-binder/1/build/deps.o
CC [M] /var/lib/dkms/anbox-binder/1/build/binder.o
CC [M] /var/lib/dkms/anbox-binder/1/build/binder_alloc.o
CC [M] /var/lib/dkms/anbox-binder/1/build/binderfs.o
In file included from ././include/linux/kconfig.h:5,
from :
./include/generated/autoconf.h:4426: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined
4426 | #define CONFIG_ANDROID_BINDER_DEVICES ""
|
: note: this is the location of the previous definition
In file included from ././include/linux/kconfig.h:5,
from :
./include/generated/autoconf.h:4426: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined
4426 | #define CONFIG_ANDROID_BINDER_DEVICES ""
|
: note: this is the location of the previous definition
In file included from ././include/linux/kconfig.h:5,
from :
./include/generated/autoconf.h:4426: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined
4426 | #define CONFIG_ANDROID_BINDER_DEVICES ""
|
: note: this is the location of the previous definition
In file included from ././include/linux/kconfig.h:5,
from :
./include/generated/autoconf.h:4426: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined
4426 | #define CONFIG_ANDROID_BINDER_DEVICES ""
|
: note: this is the location of the previous definition
/var/lib/dkms/anbox-binder/1/build/binder.c: In function ‘binder_transaction’:
/var/lib/dkms/anbox-binder/1/build/binder.c:3098:55: error: passing argument 2 of ‘security_task_getsecid_obj’ from incompatible pointer type [-Werror=incompatible-pointer-types]
3098 | security_task_getsecid_obj(proc->tsk, &secid);
| ^~~~~~
| |
| u32 * {aka unsigned int *}
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:63:
./include/linux/security.h:545:72: note: expected ‘struct lsmblob *’ but argument is of type ‘u32 *’ {aka ‘unsigned int *’}
545 | void security_task_getsecid_obj(struct task_struct *p, struct lsmblob *blob);
| ~~~~~~~~~~~~~~~~^~~~
/var/lib/dkms/anbox-binder/1/build/binder.c:3102:55: error: passing argument 2 of ‘security_secid_to_secctx’ from incompatible pointer type [-Werror=incompatible-pointer-types]
3102 | ret = security_secid_to_secctx(secid, &secctx, &secctx_sz);
| ^~~~~~~
| |
| char **
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:63:
./include/linux/security.h:591:71: note: expected ‘struct lsmcontext *’ but argument is of type ‘char **’
591 | int security_secid_to_secctx(struct lsmblob *blob, struct lsmcontext *cp,
| ~~~~~~~~~~~~~~~~~~~^~
/var/lib/dkms/anbox-binder/1/build/binder.c:3151:41: error: passing argument 1 of ‘security_release_secctx’ from incompatible pointer type [-Werror=incompatible-pointer-types]
3151 | security_release_secctx(secctx, secctx_sz);
| ^~~~~~
| |
| char *
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:63:
./include/linux/security.h:595:49: note: expected ‘struct lsmcontext *’ but argument is of type ‘char *’
595 | void security_release_secctx(struct lsmcontext *cp);
| ~~~~~~~~~~~~~~~~~~~^~
/var/lib/dkms/anbox-binder/1/build/binder.c:3151:17: error: too many arguments to function ‘security_release_secctx’
3151 | security_release_secctx(secctx, secctx_sz);
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:63:
./include/linux/security.h:595:6: note: declared here
595 | void security_release_secctx(struct lsmcontext *cp);
| ^~~~~~~~~~~~~~~~~~~~~~~
/var/lib/dkms/anbox-binder/1/build/binder.c:3486:41: error: passing argument 1 of ‘security_release_secctx’ from incompatible pointer type [-Werror=incompatible-pointer-types]
3486 | security_release_secctx(secctx, secctx_sz);
| ^~~~~~
| |
| char *
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:63:
./include/linux/security.h:595:49: note: expected ‘struct lsmcontext *’ but argument is of type ‘char *’
595 | void security_release_secctx(struct lsmcontext *cp);
| ~~~~~~~~~~~~~~~~~~~^~
/var/lib/dkms/anbox-binder/1/build/binder.c:3486:17: error: too many arguments to function ‘security_release_secctx’
3486 | security_release_secctx(secctx, secctx_sz);
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:63:
./include/linux/security.h:595:6: note: declared here
595 | void security_release_secctx(struct lsmcontext *cp);
| ^~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:281:/var/lib/dkms/anbox-binder/1/build/binder.o] 错误 1

Linux 5.15.2 updated security.h  security_binder_* functions (like security_binder_transfer_binder(), so it uses struct cred* instead of struct task_struct*)
@Vnzq4Qje3zzU
Copy link

Any chance to look at @Catiks problem ? I had the exactly same issue on ubuntu 21.10. Maybe something related to https://patchwork.kernel.org/project/linux-nfs/patch/[email protected]/ ?

@choff
Copy link
Author

choff commented Dec 11, 2021

Hello @enz0nun3s15 and @Catiks ,

to me it looks like you are trying to compile anbox-modules even though binder and ashmem are already compiled with your kernel. But anbox-modules are intended only for the corner case that the kernel of your distribution doesn't include binder and ashmem already. Ubuntu 21.10 and also earlier versions include binder and ashmem in their kernel image, so no need to use anbox-modules.

Best regards,

Christian

@Vnzq4Qje3zzU
Copy link

Actually I was trying to install it in a server with ubuntu server with custom kernel which hasn't the binder installed - there is no /lib/modules/5.13.0-22-X/kernel/drivers/android/ (I tried both Azure and Oracle). Any idea of how to handle it ?

@choff
Copy link
Author

choff commented Dec 12, 2021

Hello @enz0nun3s15 ,

binder and ashmem are not compiled as kernel modules anymore. Instead, they are built into the main kernel (vmlinux). Therefore, you cannot find binder and ashmem under drivers/android. The only way to check if you kernel has binder and ashmem is to check the kernel config. I suppose that is the case, both because of the error message you see when compiling anbox-modules and then also because you are running Ubuntu (where the default kernel comes with binder and ashmem).

Best regards,

Christian

@SoulInfernoDE
Copy link

SoulInfernoDE commented Dec 25, 2021

Actually I was trying to install it in a server with ubuntu server with custom kernel which hasn't the binder installed - there is no /lib/modules/5.13.0-22-X/kernel/drivers/android/ (I tried both Azure and Oracle). Any idea of how to handle it ?

If you are trying to use anbox try this anbox command:
anbox system-info | grep -E 'name|version|binder|ashmem'

output should be printing something like this:
binder: true
ashmem: true

best regards SI

@SoulInfernoDE
Copy link

SoulInfernoDE commented Jun 27, 2022

Some basic information to kernel building and installation:

  • you can install multiple kernels at the same time and test them
  • after a restart you can select the kernel that you want to boot
  • if a kernel simple doesn't boot you can restart your computer and boot the known working generic kernel of your distribution
  • I recommend to check if your grub boot menu is showing after a restart and have a timer set (you can edit the file with a text editor and sudo update-grub afterwards:

cat /etc/default/grub | grep GRUB_TIMEOUT
image

@SoulInfernoDE
Copy link

SoulInfernoDE commented Jun 27, 2022

@datsoy i rewrote my script for you. ❤️‍🔥

Please have a look at:

https://raw.githubusercontent.com/SoulInfernoDE/compile-kernel-from-source/test/nogui/ubuntu_and_oracle_kernel_from_source.sh

How to use it:

  • Right click --> Save as..
  • Right click the file and set permissions to: "can be executed as a program"
  • double click it and select open in terminal
  • enter your password when asked
  • WARNING! Kernel compiling can use up to 40 GB of disk space temporarly and 1 hour to ~8 hours depending
    on your cpu speed

The source code will be pulled with apt source from the ubuntu repository with the oracle branch…
..you need to enable source code sources in your system settings first:

image

@ricklambrechts
Copy link

Hi, thanks for the updates. Currently i am running debian on a surface Linux 5.19.4-surface.
By checkout this pr i get the following.
sudo dkms install anbox-binder/1 works
sudo dkms install anbox-binder/1 does not work.

The output of the command is:

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make -j8 KERNELRELEASE=5.19.4-surface all KERNEL_SRC=/lib/modules/5.19.4-surface/build...(bad exit status: 2)
Error! Bad return status for module build on kernel: 5.19.4-surface (x86_64)
Consult /var/lib/dkms/anbox-binder/1/build/make.log for more information.

The output of make.log:

DKMS make.log for anbox-binder-1 for kernel 5.19.4-surface (x86_64)
Wed 31 Aug 2022 03:13:57 PM CEST
make -C /lib/modules/5.19.4-surface/build V=0 M=$PWD
make[1]: Entering directory '/usr/src/linux-headers-5.19.4-surface'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
  You are using:           gcc (Debian 10.2.1-6) 10.2.1 20210110
  CC [M]  /var/lib/dkms/anbox-binder/1/build/deps.o
  CC [M]  /var/lib/dkms/anbox-binder/1/build/binder.o
  CC [M]  /var/lib/dkms/anbox-binder/1/build/binder_alloc.o
  CC [M]  /var/lib/dkms/anbox-binder/1/build/binderfs.o
/var/lib/dkms/anbox-binder/1/build/deps.c:76:5: error: conflicting types for ‘close_fd_get_file’
   76 | int close_fd_get_file(unsigned int fd, struct file **res)
      |     ^~~~~~~~~~~~~~~~~
In file included from /var/lib/dkms/anbox-binder/1/build/deps.c:3:
./include/linux/fdtable.h:128:21: note: previous declaration of ‘close_fd_get_file’ was here
  128 | extern struct file *close_fd_get_file(unsigned int fd);
      |                     ^~~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:249: /var/lib/dkms/anbox-binder/1/build/deps.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/var/lib/dkms/anbox-binder/1/build/binder.c: In function ‘binder_deferred_fd_close’:
/var/lib/dkms/anbox-binder/1/build/binder.c:2240:2: error: too many arguments to function ‘close_fd_get_file’
 2240 |  close_fd_get_file(fd, &twcb->file);
      |  ^~~~~~~~~~~~~~~~~
In file included from /var/lib/dkms/anbox-binder/1/build/binder.c:45:
./include/linux/fdtable.h:128:21: note: declared here
  128 | extern struct file *close_fd_get_file(unsigned int fd);
      |                     ^~~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:249: /var/lib/dkms/anbox-binder/1/build/binder.o] Error 1
make[1]: *** [Makefile:1853: /var/lib/dkms/anbox-binder/1/build] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.19.4-surface'
make: *** [Makefile:8: all] Error 2

@choff
Copy link
Author

choff commented Aug 31, 2022 via email

@Apacelus
Copy link

Hey, just tried the fork, can confirm it works

@ricklambrechts
Copy link

Thanks! I can also confirm that for kernel 5.19 the pull request choff#4 works.

@morphis
Copy link
Member

morphis commented Sep 13, 2022

@choff Is this PR up-to-date? Happy to merge it

@choff
Copy link
Author

choff commented Sep 13, 2022

Hello @morphis ,

yes, the PR is up to date. After my original fixes (which fixed the compilation for kernel versions up to 5.13), I also received fixes for version 5.15 and 5.19 by the community (thank you all!). They are part of this PR, too.

Best regards,

Christian

@choff
Copy link
Author

choff commented Sep 13, 2022

Hello @morphis,

one last thing. I think this PR will break compilation with old kernels (older than v5.12 or v5.11). The reason for this is that I updated the code for binder inside anbox-modules to the upstream state of binder from kernel 5.12 or 5.11 (cannot exactly remember which version I used).

The main reason for this update of the binder inside anbox-modules was that the binder code shipped with anbox-modules was outdated. The upstream version of binder has received many fixes meanwhile. Also, the function signature of many functions used by binder changed in newer kernel versions and I remember that it was very hard to backport these changes to the outdated binder code in anbox-modules. This is why I decided to update binder.

There is also an "old-kernel" branch in my GIIT repo that works (only) with older kernels up to 5.11. On that branch, I did not update the code of binder.

Best regards,

Christian

@munix9
Copy link

munix9 commented Oct 7, 2022

Hi @choff,

FYI: this is a possible fix for kernel 6.0 based on this request. It compiles, but is currently untested:

diff -ruNp a/ashmem/ashmem.c b/ashmem/ashmem.c
--- a/ashmem/ashmem.c
+++ b/ashmem/ashmem.c
@@ -874,7 +874,11 @@ static int __init ashmem_init(void)
 		return ret;
 	}
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
+	register_shrinker(&ashmem_shrinker, "ashmem-shrinker");
+#else
 	register_shrinker(&ashmem_shrinker);
+#endif
 
 	return 0;
 }
diff -ruNp a/binder/binder_alloc.c b/binder/binder_alloc.c
--- a/binder/binder_alloc.c
+++ b/binder/binder_alloc.c
@@ -23,6 +23,7 @@
 #include <linux/uaccess.h>
 #include <linux/highmem.h>
 #include <linux/sizes.h>
+#include <linux/version.h>
 #include "binder_alloc.h"
 #include "binder_trace.h"
 
@@ -1079,7 +1080,11 @@ int binder_alloc_shrinker_init(void)
 	int ret = list_lru_init(&binder_alloc_lru);
 
 	if (ret == 0) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
+		ret = register_shrinker(&binder_shrinker, "binder-shrinker");
+#else
 		ret = register_shrinker(&binder_shrinker);
+#endif
 		if (ret)
 			list_lru_destroy(&binder_alloc_lru);
 	}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.