Merge "doc: Remove cros_workon_make" into main
diff --git a/Android.bp b/Android.bp
index dcf67dd..3b6b8b5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -27,6 +27,7 @@
         "release_avf_enable_dice_changes",
         "release_avf_enable_llpvm_changes",
         "release_avf_enable_multi_tenant_microdroid_vm",
+        "release_avf_enable_network",
         "release_avf_enable_remote_attestation",
         "release_avf_enable_vendor_modules",
         "release_avf_enable_virt_cpufreq",
@@ -52,6 +53,9 @@
         release_avf_enable_multi_tenant_microdroid_vm: {
             cfgs: ["multi_tenant"],
         },
+        release_avf_enable_network: {
+            cfgs: ["network"],
+        },
         release_avf_enable_remote_attestation: {
             cfgs: ["remote_attestation"],
         },
diff --git a/apex/Android.bp b/apex/Android.bp
index 48b7b1f..0eb8b9e 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -46,6 +46,7 @@
     bool_variables: [
         "release_avf_enable_device_assignment",
         "release_avf_enable_llpvm_changes",
+        "release_avf_enable_network",
         "release_avf_enable_remote_attestation",
         "release_avf_enable_vendor_modules",
         "release_avf_enable_virt_cpufreq",
@@ -190,6 +191,16 @@
         release_avf_enable_llpvm_changes: {
             androidManifest: "AndroidManifest.xml",
         },
+        release_avf_enable_network: {
+            arch: {
+                arm64: {
+                    binaries: ["vmnic"],
+                },
+                x86_64: {
+                    binaries: ["vmnic"],
+                },
+            },
+        },
         release_avf_enable_remote_attestation: {
             vintf_fragments: [
                 "virtualizationservice.xml",
diff --git a/docs/custom_vm.md b/docs/custom_vm.md
index 5e2d933..7b30835 100644
--- a/docs/custom_vm.md
+++ b/docs/custom_vm.md
@@ -34,6 +34,21 @@
 As of today (April 2024), ChromiumOS is the only officially supported guest
 payload. We will be adding more OSes in the future.
 
+#### Download from build server
+
+  - Step 1) Go to the link https://ci.chromium.org/ui/p/chromeos/builders/chromiumos/ferrochrome-public-main/
+    - Note: I 'searched' the ferrochrome target with builder search.
+  - Step 2) Click a build number
+  - Step 3) Expand steps and find `48. upload artifacts`.
+  - Step 4) Click `gs upload dir`. You'll see Cloud storage with comprehensive artifacts (e.g. [Here](https://pantheon.corp.google.com/storage/browser/chromiumos-image-archive/ferrochrome-public/R126-15883.0.0) is the initial build of ferrochrome)
+  - Step 5) Download `image.zip`, which contains working vmlinuz.
+    - Note: DO NOT DOWNLOAD `vmlinuz.tar.xz` from the CI.
+  - Step 6) Uncompress `image.zip`, and boot with `chromiumos_test_image.bin` and `boot_images/vmlinuz`.
+    - Note: DO NOT USE `vmlinuz.bin`.
+
+IMPORTANT: DO NOT USE `vmlinuz.bin` for passing to crosvm. It doesn't pick-up the correct `init` process (picks `/init` instead of `/sbin/init`, and `cfg80211` keeps crashing (i.e. no network)
+
+
 #### Build ChromiumOS for VM
 
 First, check out source code from the ChromiumOS and Chromium projects.
@@ -121,7 +136,7 @@
 You need two outputs:
 
 * ChromiumOS disk image: ~/chromiumos/src/build/images/ferrochrome/latest/chromiumos_test_image.bin
-* The kernel: ~/chromiumos/out/build/ferrochrome/boot/vmlinuz
+* The kernel: ~/chromiumos/src/build/images/ferrochrome/latest/boot_images/vmlinuz
 
 ### Create a guest VM configuration
 
diff --git a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
index e7e9ded..f424ce0 100644
--- a/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
+++ b/tests/hostside/java/com/android/microdroid/test/MicrodroidHostTests.java
@@ -59,6 +59,7 @@
 import org.json.JSONObject;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
@@ -660,6 +661,7 @@
     }
 
     @Test
+    @Ignore("b/341087884") // TODO(b/341087884): fix & re-enable
     public void testTombstonesAreGeneratedUponKernelCrash() throws Exception {
         assumeFalse("Cuttlefish is not supported", isCuttlefish());
         assumeFalse("Skipping test because ramdump is disabled on user build", isUserBuild());
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice_internal/IVmnic.aidl b/virtualizationservice/aidl/android/system/virtualizationservice_internal/IVmnic.aidl
new file mode 100644
index 0000000..3796763
--- /dev/null
+++ b/virtualizationservice/aidl/android/system/virtualizationservice_internal/IVmnic.aidl
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.system.virtualizationservice_internal;
+
+interface IVmnic {
+    /**
+     * Create TAP network interface for a VM.
+     * @param CID of VM.
+     * @return file descriptor of the TAP network interface.
+     */
+    ParcelFileDescriptor createTapInterface(int cid);
+}
diff --git a/virtualizationservice/vmnic/Android.bp b/virtualizationservice/vmnic/Android.bp
new file mode 100644
index 0000000..4313a82
--- /dev/null
+++ b/virtualizationservice/vmnic/Android.bp
@@ -0,0 +1,21 @@
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+rust_binary {
+    name: "vmnic",
+    crate_name: "vmnic",
+    defaults: ["avf_build_flags_rust"],
+    edition: "2021",
+    srcs: ["src/main.rs"],
+    prefer_rlib: true,
+    rustlibs: [
+        "android.system.virtualizationservice_internal-rust",
+        "libandroid_logger",
+        "libanyhow",
+        "libbinder_rs",
+        "liblog_rust",
+    ],
+    apex_available: ["com.android.virt"],
+    init_rc: ["vmnic.rc"],
+}
diff --git a/virtualizationservice/vmnic/src/aidl.rs b/virtualizationservice/vmnic/src/aidl.rs
new file mode 100644
index 0000000..26a0eff
--- /dev/null
+++ b/virtualizationservice/vmnic/src/aidl.rs
@@ -0,0 +1,37 @@
+// Copyright 2024, The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Implementation of the AIDL interface of Vmnic.
+
+use anyhow::anyhow;
+use android_system_virtualizationservice_internal::aidl::android::system::virtualizationservice_internal::IVmnic::IVmnic;
+use binder::{self, ExceptionCode, Interface, IntoBinderResult, ParcelFileDescriptor};
+
+#[derive(Debug, Default)]
+pub struct Vmnic {}
+
+impl Vmnic {
+    pub fn init() -> Vmnic {
+        Vmnic::default()
+    }
+}
+
+impl Interface for Vmnic {}
+
+impl IVmnic for Vmnic {
+    fn createTapInterface(&self, _cid: i32) -> binder::Result<ParcelFileDescriptor> {
+        Err(anyhow!("Creating TAP network interface is not supported yet"))
+            .or_binder_exception(ExceptionCode::UNSUPPORTED_OPERATION)
+    }
+}
diff --git a/virtualizationservice/vmnic/src/main.rs b/virtualizationservice/vmnic/src/main.rs
new file mode 100644
index 0000000..8c73c40
--- /dev/null
+++ b/virtualizationservice/vmnic/src/main.rs
@@ -0,0 +1,44 @@
+// Copyright 2024 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Android Vmnic (Virtual Machine Network Interface Creator)
+
+mod aidl;
+
+use crate::aidl::Vmnic;
+use android_logger::Config;
+use android_system_virtualizationservice_internal::aidl::android::system::virtualizationservice_internal::IVmnic::{
+    BnVmnic,
+    BpVmnic,
+    IVmnic,
+};
+use binder::{register_lazy_service, BinderFeatures, ProcessState};
+use log::{info, LevelFilter};
+
+const LOG_TAG: &str = "Vmnic";
+
+fn main() {
+    android_logger::init_once(
+        Config::default()
+            .with_tag(LOG_TAG)
+            .with_max_level(LevelFilter::Info)
+            .with_log_buffer(android_logger::LogId::System),
+    );
+
+    let service = Vmnic::init();
+    let service = BnVmnic::new_binder(service, BinderFeatures::default());
+    register_lazy_service(<BpVmnic as IVmnic>::get_descriptor(), service.as_binder()).unwrap();
+    info!("Registered Binder service, joining threadpool.");
+    ProcessState::join_thread_pool();
+}
diff --git a/virtualizationservice/vmnic/vmnic.rc b/virtualizationservice/vmnic/vmnic.rc
new file mode 100644
index 0000000..486f387
--- /dev/null
+++ b/virtualizationservice/vmnic/vmnic.rc
@@ -0,0 +1,20 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+service vmnic /apex/com.android.virt/bin/vmnic
+    user system
+    group system
+    interface aidl android.system.virtualizationservice_internal.IVmnic
+    disabled
+    oneshot
diff --git a/vm_payload/Android.bp b/vm_payload/Android.bp
index 97d4649..229f533 100644
--- a/vm_payload/Android.bp
+++ b/vm_payload/Android.bp
@@ -79,6 +79,7 @@
         // Implementation is available inside a Microdroid VM.
         implementation_installable: false,
     },
+    visibility: ["//visibility:public"],
 }
 
 // Just the headers. Mostly useful for clients that only want the
@@ -88,6 +89,7 @@
     defaults: ["avf_build_flags_cc"],
     apex_available: ["com.android.compos"],
     export_include_dirs: ["include"],
+    visibility: ["//visibility:public"],
 }
 
 // Restricted headers for use by internal clients & associated tests.