anbox / anbox-modules

Anbox kernel modules
327 stars 224 forks source link

Compatibility with kernels >= 5.7 #76

Open choff opened 3 years ago

choff commented 3 years ago

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

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.

TommyTran732 commented 3 years ago

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 commented 3 years ago

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

choff commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

chrihoff commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

hey @chrihoff,

I found a binder code for latest kernels binder.c

Is something possible to do with these?

chrihoff commented 3 years ago

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 commented 3 years ago

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

chrihoff commented 3 years ago

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 commented 3 years ago

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 !!!

Catiks commented 2 years ago
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
Vnzq4Qje3zzU commented 2 years ago

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/20210924175441.7943-16-casey@schaufler-ca.com/ ?

choff commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

datsoy commented 2 years ago

Managed to build ashmem but got error on binder.

DKMS make.log for anbox-binder-1 for kernel 5.13.0-1028-oracle (aarch64) Mon Jun 20 07:33:45 UTC 2022 make -C /lib/modules/5.13.0-1028-oracle/build V=0 M=$PWD make[1]: Entering directory '/usr/src/linux-headers-5.13.0-1028-oracle' 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:5107: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined 5107 #define CONFIG_ANDROID_BINDER_DEVICES ""
In file included from ././include/linux/kconfig.h:5, from : ./include/generated/autoconf.h:5107: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined 5107 #define CONFIG_ANDROID_BINDER_DEVICES ""
: note: this is the location of the previous definition : note: this is the location of the previous definition In file included from ././include/linux/kconfig.h:5, from : ./include/generated/autoconf.h:5107: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined 5107 | #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:5107: warning: "CONFIG_ANDROID_BINDER_DEVICES" redefined 5107 | #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:3125:41: error: passing argument 2 of ‘security_task_getsecid_obj’ from incompatible pointer type [-Werror=incompatible-pointer-types] 3125 | 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:3129:41: error: passing argument 2 of ‘security_secid_to_secctx’ from incompatible pointer type [-Werror=incompatible-pointer-types] 3129 | 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:3178:27: error: passing argument 1 of ‘security_release_secctx’ from incompatible pointer type [-Werror=incompatible-pointer-types] 3178 | 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:3178:3: error: too many arguments to function ‘security_release_secctx’ 3178 | 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:3513:27: error: passing argument 1 of ‘security_release_secctx’ from incompatible pointer type [-Werror=incompatible-pointer-types] 3513 | 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:3513:3: error: too many arguments to function ‘security_release_secctx’ 3513 | 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] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [Makefile:1879: /var/lib/dkms/anbox-binder/1/build] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-5.13.0-1028-oracle' make: *** [Makefile:8: all] Error 2
chrihoff commented 2 years ago

It is very likely that you are seeing these errors because binder is already part of your current kernel. In that case, you don't have to (and should not!) compile binder from anbox-modules. Please check your kernel config to confirm. anbox-modules is intended only for the case that your distribution provides a kernel that doesn't enable ashmem and binder.

datsoy commented 2 years ago

I tried building it but throws ERROR: modpost: "kallsyms_lookup_name" officially.

So I tried your fork to build.

heres a result of grep of "BINDER" in my current kernel config

CONFIG_ANDROID_BINDER_IPC=m CONFIG_ANDROID_BINDERFS=m CONFIG_ANDROID_BINDER_DEVICES=""

CONFIG_ANDROID_BINDER_IPC_SELFTEST is not set

Thanks.

chrihoff commented 2 years ago

Thanks and that proves that you already have Binder. You can ignore "BINDER_IPC_SELFTEST" as that is just for debugging. The important think is that "BINDER_IPC" and "BINDERFS" are set. As they are compiled as kernel modules (since the value of the options is 'm'), you have to load these kernel modules with 'modprobe' before you can use them.

I assume that you also have ashmem support in your kernel since Binder and Ashmem are usually enabled together. So, there should be no reason for you to use anbox-modules.

datsoy commented 2 years ago

Thank you. When I try sudo modprobe binder_linux and ashmem It throws a modprobe: FATAL: Module binder_linux not found in directory /lib/modules/5.13.0-1028-oracle

chrihoff commented 2 years ago

You are welcome :-)

This is a strange error message - clearly, your kernel was built with binder, so you should be able to load it. Maybe you are missing an RPM / Debian package that contains these extra kernel modules; that would be the only obvious explanation I have. If that doesn't help, I'm afraid you'll have to ask your distribution maintainers for advice.

datsoy commented 2 years ago

Yeah I think so too, maybe it was removed or wahtever purposely by oracle. Ill try to built a kernel if possible or roll back to 18.04. Thanks again. Cheers.

SoulInfernoDE commented 2 years ago

Thank you. When I try sudo modprobe binder_linux and ashmem It throws a modprobe: FATAL: Module binder_linux not found in directory /lib/modules/5.13.0-1028-oracle

Are you sure that it is in your kernel as a module? ..as far as i know module compatibility for the android section has been removed in newer kernels! If it is build as module i guess it should be already loaded in your kernel without the module way.

Can you check the output of:

ls -1 /dev/{ashmem,binder} && uname -a image

Are you using this kernel ?: https://github.com/oracle/linux-uek

chrihoff commented 2 years ago

@SoulInfernoDE , you are right; I forgot. In newer kernels (and I think this includes version 5.13), binder cannot be built as a kernel module anymore as it uses functions from the Linux kernel that are not available to kernel modules. So, probably binder and ashmem are compiled into your kernel. You can try to check /dev/ashmem and mount binderfs to double check.

datsoy commented 2 years ago

Hello, and thank you.

This is the output of ls -1 /dev/{ashmem,binder} && uname -a

ls: cannot access '/dev/ashmem': No such file or directory ls: cannot access '/dev/binder': No such file or directory Linux a1-instance 5.13.0-1028-oracle #33~20.04.1-Ubuntu SMP Mon May 2 03:56:22 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

No, Its the kernel that come off with oracles ubuntu os for their vps.

chrihoff commented 2 years ago

I see... And what I read was that ashmem and binder were once compiled as kernel modules in Ubuntu. Who knows what kernel patches Oracle and Ubuntu have applied - they might also have patched their kernel such that ashmem and binder can still be compiled as modules.

As the modules have been compile (the kernel config shows this), but cannot be loaded, I suspect that they can either be installed as a separate Debian package or that they have been accidentally removed.

SoulInfernoDE commented 2 years ago

@datsoy I really think the kernel .config is malformed due to no ashmem and binder present. I would recommend to recompile the kernel from the oracle os. I guess you are using the oracle os and as far as i know they are using their UEK kernel. https://github.com/oracle/linux-uek

Here is a write up how i did compile my kernel: https://github.com/anbox/anbox-modules/issues/75#issuecomment-794079944

If it is a debian based system with apt manager you can try my script to build it: https://github.com/SoulInfernoDE/compile-kernel-from-source


compile-from-source.sh

``` #!/bin/bash # Save the number of your cores to the variable CPUCORES CPUCORES=$(nproc) # You can change this variable to compile in any other folder CPATH=~/Downloads echo "Kernel Pull Merge Script v0.1a" echo 'Installing dependencies' sudo apt install git dwarves build-essential fakeroot bc kmod cpio libxi-dev libncurses5-dev libgtk2.0-dev libglib2.0-dev libglade2-dev libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev dpkg-dev autoconf libdw-dev cmake zstd packagekit qt5ct libpackagekitqt5-dev nano cd $CPATH # rm linux-*.tar.xz 2> /dev/null mkdir kernel # We create a work directory folder cd kernel read -p "Which kernel version do you want to compile? (example: 5.19-rc1) " KERNEL_VERSION echo 'kernel version you entered: '$KERNEL_VERSION'_android' apt source $KERNEL_VERSION cd $KERNEL_VERSION # we open the kernel source code folder downloaded by apt cp /boot/config-$(uname -r) ./.config # we copy your current configuration file from /boot/config to the kernel source code folder and rename it to .config echo 'Downloading the ASHMEM source code removal patch from upstream' wget -O remove_ashmem.patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=721412ed3d819e767cac2b06646bf03aa158aaec echo '' echo 'Reverting the removal patch code..' interdiff -q remove_ashmem.patch /dev/null > enable_ashmem.patch echo '' echo 'Patching the kernel sources to bring back ASHMEM..' patch -p1 -i enable_ashmem.patch echo '' echo 'DONE! ASHMEM is now selectable again in your kernel .config file! NOTE: THIS MAY BREAK ANYTIME AS ASHMEM IS REPLACED WITH MEMFD' echo 'which is not supported by Anbox yet..' make olddefconfig # we re-generate the copied config file to update new lines in newer kernel versions with the pre-defined default answer echo 'Configuration file with standard defaults options: '$KERNEL_VERSION'_android has been created..' # Downloading the merge fragments file - if you need this changed create a pull request wget https://raw.githubusercontent.com/SoulInfernoDE/compile-kernel-from-source/main/nogui/.config-fragment # Using terminal script from torvalds to modify the needed lines into the .config file found in the kernel sources under kernel/scripts/kconfig/merge_config.sh # Merge IP fragment CONFIG_ settings into the main .config file ./scripts/kconfig/merge_config.sh .config .config-fragment echo 'merging new android options into the .config file:' make olddefconfig # we have added the ANDROID lines at the end of the config file, however we re-generate the config file again to maintain the correct structure echo 'You have' $CPUCORES 'cpu cores' echo "Ready to start compiling! Enter 'time nice make bindeb-pkg' -j'YOUR NUMBER OF CORES HERE' to start compiling with multi-core mode.." echo '' read -r -p " ############################################################### # deb-file creation will start. Do you want to continue? # # # # - Make sure configuration changes are correct! # ############################################################### (y|Y)es (n|N)o # " input case $input in [yY][eE][sS]|[yY]) echo "Executing..!" ;; [nN][oO]|[nN]) echo "No, we stop here.." exit 1 ;; *) echo "Invalid selection input.. ..aborting!" exit 1 ;; esac time nice make bindeb-pkg -j'$CPUCORES' # we start compiling process with: counting the time needed to compile, show less and nicer compile information, generate deb-files at the end and use x-cpu cores to speed up compiling procedure read -r -p " ############################################################### # deb-files will be installed. Do you want to continue? # # # # - Make sure compiling finished successfully! # ############################################################### (y|Y)es (n|N)o # " install case $install in [yY][eE][sS]|[yY]) echo "Executing..!" ;; [nN][oO]|[nN]) echo "No, we stop here.." exit 1 ;; *) echo "Invalid selection input.. ..aborting!" exit 1 ;; esac sudo dpkg -i $CPATH/linux-*.deb # we install the compiled *.deb kernel files echo '' echo 'If the script has an error for you, please report it on github. You can leave a screenshot if you like to in the issues section' echo '' echo 'If you are using uefi secure boot within your linux installation then you need to sign your kernel. You can download my script for automation here: Right-click and save-as' echo 'https://raw.githubusercontent.com/SoulInfernoDE/compile-kernel-from-source/test/signkernel/cfs_signkernel.sh'' ```

Im not sure where to locate the correct kernel source for your linux system. So you may need to search a bit for yourself. In most linux systems the original kernel from kernel.org still works. But if there is a customized one you could try to find that source code and use that instead of the one located at kernel.org.

best regards

datsoy commented 2 years ago

Thank you, I'll check them out.

My system shows, Ubuntu 20.04.4 LTS aarch64 5.13.0-1028-oracle

and upon searching I find This Im not sure if its the correct source though.

As an average user, and new to this, I will read and search more, before trying this out and if time permits. Ill let you know, maybe creating issue on your git.

I really appreciate all the help. Thank you.

SoulInfernoDE commented 2 years ago

Some basic information to kernel building and installation:

cat /etc/default/grub | grep GRUB_TIMEOUT image

SoulInfernoDE commented 2 years ago

@datsoy i rewrote my script for you. :heart_on_fire:

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:


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 commented 2 years ago

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 commented 2 years ago

Hello Rick,

yes, for kernel 5.19 there is currently an open pull request, which I first have to review and then merge into my branch: https://github.com/choff/anbox-modules/pull/4 . Feel free to try it out and let me know the result.

Best regards,

  Christian

Message ID: @.***

Apacelus commented 2 years ago

Hey, just tried the fork, can confirm it works

ricklambrechts commented 2 years ago

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

morphis commented 1 year ago

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

choff commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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);
    }