termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.98k stars 2.99k forks source link

[Package]: crosvm #19194

Open codrutpopescu opened 7 months ago

codrutpopescu commented 7 months ago

Why is it worth to add this package?

Snapdragon 8 Gen 2 and higher processors support a new hypervisor called Gunyah

:/data/data/com.termux/files/home # uname -a Linux localhost 5.15.94-android13-8-27940245-abX916BXXU1BWK6 #1 SMP PREEMPT Wed Nov 15 07:38:57 UTC 2023 aarch64 Toybox :/data/data/com.termux/files/home # ls -l /dev/gunyah crw------- 1 root root 10, 121 2022-08-14 08:12 /dev/gunyah

but qemu does not support this hypervisor. Qualcomm worked with crosvm. It would be amazing to run VMs at hypervisor speeds using crosvm on these processors.

Home page URL

https://crosvm.dev/

Source code URL

https://github.com/google/crosvm

Packaging policy acknowledgement

Additional information

No response

twaik commented 7 months ago

AFAIK for this you must rebuild kernel with KVM support. That is a nogo. @licy183 what do you think?

codrutpopescu commented 7 months ago

No, I don't think so, it uses Gunyah instead of KVM https://developer.qualcomm.com/blog/gunyah-hypervisor-software-supporting-protected-vms-android-virtualization-framework I am not really an expert, I am just looking for ways to run VMs efficiently

twaik commented 7 months ago

crosvm repo contains a few Gunyah mentions. Maybe it can work.

licy183 commented 7 months ago

Emmm... It may work but I'm afraid that it needs root permission.

codrutpopescu commented 6 months ago

According to this: https://github.com/quic/gunyah-hypervisor/issues/24 It's probaby not supported on mobile phones CPUs, so you may close this. You might understand better than me what they ar talking about and better decide.

jglathe commented 6 months ago

hmm there are two components. This SM8550 chip is fairly new (newer then the sc8280xp I'm typing on), and /dev/gunyah means its gunyah-aware in the sense that it may interact with it. Gunyah itself neeeds to be loaded from the boot rom before Android even starts. So Android is a guest of Gunyah (they call it PVM, primary-os virtual machine). But only if this tablet is shipped with it. Gunyah is also fairly new. My attempts with Gunyah were trying out the x86 quemu demonstrator (this worked here), and integrating the gunyah patches into my kernel. But, since my device didn't have Gunyah running from the rom, no effect. Would be containers (docker, lxd) enough for what you have in mind?

codrutpopescu commented 6 months ago

hmm there are two components. This SM8550 chip is fairly new (newer then the sc8280xp I'm typing on), and /dev/gunyah means its gunyah-aware in the sense that it may interact with it. Gunyah itself neeeds to be loaded from the boot rom before Android even starts. So Android is a guest of Gunyah (they call it PVM, primary-os virtual machine). But only if this tablet is shipped with it. Gunyah is also fairly new. My attempts with Gunyah were trying out the x86 quemu demonstrator (this worked here), and integrating the gunyah patches into my kernel. But, since my device didn't have Gunyah running from the rom, no effect. Would be containers (docker, lxd) enough for what you have in mind?

My wish is to run an arm64 Linux VM (ideally RedHat) using hardware acceleration. For now I am using qemu with the option -tcg If anyone knows something better please let me know, I will be grateful.

DienoX commented 5 months ago

I have Snapdragon 8 generation 3 and I also have this file in /dev. It seems to me that if we gave termux virtualization permissions via adb, we would be able to run the VM on the phone.

The main difference I see between this and termux or containers is the ability to redirect phone components, e.g. USB. Termux enables USB but it doesn't work as well as with virtualization.

DienoX commented 5 months ago

A little more about this hypervisor https://youtu.be/hLdUCrlheKg?si=MrocW4lCtN3n3bSg

Soranokuni commented 2 months ago

No update regarding this I pressume as I don't see any mention or changelog. This could be a really nice addition, I am really dumbfound that there is nothing out yet that uses gunyah as even modern Samsung devices seem to have it enabled by default.

KusakabeShi commented 1 month ago

AFAIK for this you must rebuild kernel with KVM support. That is a nogo. @licy183 what do you think?

In the current android kernel, the KVM module is enabled by default(GKI). But unfortunately, it requires the linux kernel be loaded into EL2, and currently both Qualcomm and Mediatek loads kernel into EL1 instead of EL2.

So it's impossible to enable KVM at Qualcomm/Mediatek chip(even with unlocked bootloader).

But since 8Gn2 and 8Gen3, Qualcomm loads Gunyah into the EL2, and the linux kernel in EL1 can communicate with Gunyah to request it to create another VM in EL1.

In this case, crosvm is just a userspace client can communicate to gunyah driver to create vm, it's reasonable to me to add crosvm to termux package.

fish4terrisa-MSDSM commented 2 weeks ago

I owns a rootred oneplus ace3 with sm8550(8Gn2), and I noticed the existing /dev/gunyah. I also rebuilt the kernel to make pKVM unprotected, so crosvm seems will be able run VM without a signed kernel(great) I expects to run ArchLinux in a native speed with full systemd support and good enough gpu accel(virtio-gpu is acceptable) As the crosvm binary is not shiped with Oxygenos, now I'm badly in need of this package. Really looking forward to see this package added to the repo:-) Much thanks XD!

Freak21227 commented 6 days ago

Avf supports only 8gen3 and later on Qualcomm socs.it's confirmed enabled on these devices :

https://opengles.gpuinfo.org/listreports.php?devicefeature=android.software.virtualization_framework

A additional patched qemu termux package would be very useful on Qualcomm devices since they only expose /dev/gunyah

Patch is here https://patchew.org/QEMU/20240516143356.1739402-1-quic._5Fsvaddagi@quicinc.com/

DienoX commented 6 days ago

@Freak21227 And doesn't Termux require appropriate permissions to use the virtualization API?

Freak21227 commented 5 days ago

@DienoX i don't know much but this shizuku application uses virtualization API https://github.com/frap129/Machina And with root we can can use crosvm directly from termux Also Google developing a terminal app for virtualization media_GW9nZmTXQAEE01Z