Merge with upstream 2024-02-16

11994dbba35 linux: remove memfd panic handler
557f1555b4e Change get_host_cpu_clusters to get unique clusters
ea6b43607f2 Roll recipe dependencies (trivial).
4e5b49bed30 Roll recipe dependencies (trivial).

https://chromium.googlesource.com/crosvm/crosvm/+log/d93be8c65f5ae343aba5f51820ed3a1f3b051033..11994dbba354c62d9b52526a3a830142d439f78d

BUG=b:309651697
BUG=b:325081271
Bug=b:284369518

Change-Id: I096876f95db7b17ca035b1a1c0947afabbb285be
diff --git a/Cargo.toml b/Cargo.toml
index 3394e78..f5728fb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -154,9 +154,6 @@
 ## Enables virtio-net and vhost-user-net backend.
 net = ["devices/net"]
 
-## Enables a panic handler that writes panic info to the `RUST_PANIC_SIG` memfd.
-panic-memfd = []
-
 ## Enables PCI hotplug. Only available on Linux, and currently only for x86/x86-64.
 pci-hotplug = ["devices/pci-hotplug", "vm_control/pci-hotplug"]
 
@@ -334,7 +331,6 @@
     "libvda-stub",
     "net",
     "noncoherent-dma",
-    "panic-memfd",
     "pci-hotplug",
     "power-monitor-powerd",
     "slirp",
@@ -395,7 +391,7 @@
 all-msvc64 = [ "all-mingw64" ]
 
 ## All features that are enabled in ChromeOS builds.
-all-chromeos = ["audio_cras", "panic-memfd", "arc_quota", "vtpm", "registered_events"]
+all-chromeos = ["audio_cras", "arc_quota", "vtpm", "registered_events"]
 
 # Deprecated feature flag. Remove after ChromeOS-side is updated.
 chromeos = ["all-chromeos"]
diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs
index d9cafc5..6bf1b61 100644
--- a/aarch64/src/lib.rs
+++ b/aarch64/src/lib.rs
@@ -871,7 +871,7 @@
     fn get_host_cpu_clusters() -> std::result::Result<Vec<CpuSet>, Self::Error> {
         let cluster_ids = Self::collect_for_each_cpu(base::logical_core_cluster_id)
             .map_err(Error::CpuTopology)?;
-        Ok(cluster_ids
+        let mut unique_clusters: Vec<CpuSet> = cluster_ids
             .iter()
             .map(|&vcpu_cluster_id| {
                 cluster_ids
@@ -881,7 +881,10 @@
                     .map(|(cpu_id, _)| cpu_id)
                     .collect()
             })
-            .collect())
+            .collect();
+        unique_clusters.sort_unstable();
+        unique_clusters.dedup();
+        Ok(unique_clusters)
     }
 }
 
diff --git a/arch/src/lib.rs b/arch/src/lib.rs
index 0a7d8b4..65ae770 100644
--- a/arch/src/lib.rs
+++ b/arch/src/lib.rs
@@ -140,7 +140,7 @@
 }
 
 /// Set of CPU cores.
-#[derive(Clone, Debug, Default, PartialEq, Eq)]
+#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
 pub struct CpuSet(Vec<usize>);
 
 impl CpuSet {
diff --git a/base/src/sys/linux/mod.rs b/base/src/sys/linux/mod.rs
index 212b7ff..bd72d5e 100644
--- a/base/src/sys/linux/mod.rs
+++ b/base/src/sys/linux/mod.rs
@@ -29,7 +29,6 @@
 mod net;
 mod netlink;
 mod notifiers;
-pub mod panic_handler;
 pub mod platform_timer_resolution;
 mod poll;
 mod priority;
diff --git a/base/src/sys/linux/panic_handler.rs b/base/src/sys/linux/panic_handler.rs
deleted file mode 100644
index fc82f6d..0000000
--- a/base/src/sys/linux/panic_handler.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2022 The ChromiumOS Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-//! A panic handler for better crash signatures for rust apps.
-
-use std::fmt::Write;
-use std::fs::File;
-use std::io;
-use std::mem;
-use std::panic;
-use std::process::abort;
-
-use crate::SafeDescriptor;
-use crate::SharedMemory;
-
-const PANIC_MEMFD_NAME: &str = "RUST_PANIC_SIG";
-
-// TODO(b/309651697): This was written to be compatible with existing PanicInfo formatting, but it
-// should probably be made more stable.
-fn format_panic_info(panic_info: &panic::PanicInfo<'_>) -> String {
-    // 128 is arbitrary, but should be enough to cover most cases.
-    let mut result = String::with_capacity(128);
-    result += "panicked at '";
-    result += panic_info
-        .payload()
-        .downcast_ref::<&'static str>()
-        .unwrap_or(&"<unknown>");
-    result += ", ";
-
-    // At the time of writing, `PanicInfo::location()` cannot return `None`.
-    match panic_info.location() {
-        Some(location) => {
-            let _ = write!(&mut result, "{}", location);
-        }
-        None => {
-            result += "no location info";
-        }
-    }
-
-    result
-}
-
-/// Inserts a panic handler that writes the panic info to a memfd called
-/// "RUST_PANIC_SIG" before calling the original panic handler. This
-/// makes it possible for external crash handlers to recover the panic info.
-pub fn install_memfd_handler() {
-    let hook = panic::take_hook();
-    panic::set_hook(Box::new(move |p| {
-        let panic_info = format_panic_info(p);
-        let panic_bytes = panic_info.as_bytes();
-        // On failure, ignore the error and call the original handler.
-        if let Ok(panic_memfd) = SharedMemory::new(PANIC_MEMFD_NAME, panic_bytes.len() as u64) {
-            let mut panic_memfd = File::from(SafeDescriptor::from(panic_memfd));
-            io::Write::write_all(&mut panic_memfd, panic_bytes).ok();
-            // Intentionally leak panic_memfd so it is picked up by the crash handler.
-            mem::forget(panic_memfd);
-        }
-        hook(p);
-
-        // If this is a multithreaded program, a panic in one thread will not kill the whole
-        // process. Abort so the entire process gets killed and produces a core dump.
-        abort();
-    }));
-}
diff --git a/infra/README.recipes.md b/infra/README.recipes.md
index 3a6a7c6..6b4ef2e 100644
--- a/infra/README.recipes.md
+++ b/infra/README.recipes.md
@@ -174,19 +174,19 @@
 
 &mdash; **def [RunSteps](/infra/recipes/update_chromeos_merges.py#14)(api):**
 
-[depot_tools/recipe_modules/bot_update]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/b1b1a43f071dc4888070cae0c983c9bd333c5db6/recipes/README.recipes.md#recipe_modules-bot_update
-[depot_tools/recipe_modules/depot_tools]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/b1b1a43f071dc4888070cae0c983c9bd333c5db6/recipes/README.recipes.md#recipe_modules-depot_tools
-[depot_tools/recipe_modules/gclient]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/b1b1a43f071dc4888070cae0c983c9bd333c5db6/recipes/README.recipes.md#recipe_modules-gclient
-[depot_tools/recipe_modules/git]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/b1b1a43f071dc4888070cae0c983c9bd333c5db6/recipes/README.recipes.md#recipe_modules-git
-[depot_tools/recipe_modules/gsutil]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/b1b1a43f071dc4888070cae0c983c9bd333c5db6/recipes/README.recipes.md#recipe_modules-gsutil
-[recipe_engine/recipe_modules/buildbucket]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-buildbucket
-[recipe_engine/recipe_modules/cipd]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-cipd
-[recipe_engine/recipe_modules/context]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-context
-[recipe_engine/recipe_modules/file]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-file
-[recipe_engine/recipe_modules/json]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-json
-[recipe_engine/recipe_modules/path]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-path
-[recipe_engine/recipe_modules/platform]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-platform
-[recipe_engine/recipe_modules/properties]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-properties
-[recipe_engine/recipe_modules/raw_io]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-raw_io
-[recipe_engine/recipe_modules/step]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/README.recipes.md#recipe_modules-step
-[recipe_engine/wkt/RecipeApi]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783/recipe_engine/recipe_api.py#473
+[depot_tools/recipe_modules/bot_update]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/9d7c8e76f82ddc6a3bbc307217e31dec44a0f73a/recipes/README.recipes.md#recipe_modules-bot_update
+[depot_tools/recipe_modules/depot_tools]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/9d7c8e76f82ddc6a3bbc307217e31dec44a0f73a/recipes/README.recipes.md#recipe_modules-depot_tools
+[depot_tools/recipe_modules/gclient]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/9d7c8e76f82ddc6a3bbc307217e31dec44a0f73a/recipes/README.recipes.md#recipe_modules-gclient
+[depot_tools/recipe_modules/git]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/9d7c8e76f82ddc6a3bbc307217e31dec44a0f73a/recipes/README.recipes.md#recipe_modules-git
+[depot_tools/recipe_modules/gsutil]: https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/9d7c8e76f82ddc6a3bbc307217e31dec44a0f73a/recipes/README.recipes.md#recipe_modules-gsutil
+[recipe_engine/recipe_modules/buildbucket]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-buildbucket
+[recipe_engine/recipe_modules/cipd]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-cipd
+[recipe_engine/recipe_modules/context]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-context
+[recipe_engine/recipe_modules/file]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-file
+[recipe_engine/recipe_modules/json]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-json
+[recipe_engine/recipe_modules/path]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-path
+[recipe_engine/recipe_modules/platform]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-platform
+[recipe_engine/recipe_modules/properties]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-properties
+[recipe_engine/recipe_modules/raw_io]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-raw_io
+[recipe_engine/recipe_modules/step]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/README.recipes.md#recipe_modules-step
+[recipe_engine/wkt/RecipeApi]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/88c63dd9fd4210f845eca55b6053910803bce13c/recipe_engine/recipe_api.py#473
diff --git a/infra/config/recipes.cfg b/infra/config/recipes.cfg
index d8f4d2b..e972622 100644
--- a/infra/config/recipes.cfg
+++ b/infra/config/recipes.cfg
@@ -20,12 +20,12 @@
   "deps": {
     "depot_tools": {
       "branch": "refs/heads/main",
-      "revision": "b1b1a43f071dc4888070cae0c983c9bd333c5db6",
+      "revision": "9d7c8e76f82ddc6a3bbc307217e31dec44a0f73a",
       "url": "https://chromium.googlesource.com/chromium/tools/depot_tools.git"
     },
     "recipe_engine": {
       "branch": "refs/heads/main",
-      "revision": "c9c93ff2210aaf7fbb0894d2e62bd49fc4bf9783",
+      "revision": "88c63dd9fd4210f845eca55b6053910803bce13c",
       "url": "https://chromium.googlesource.com/infra/luci/recipes-py.git"
     }
   },
diff --git a/src/sys/linux/panic_hook.rs b/src/sys/linux/panic_hook.rs
index b67e440..491eb48 100644
--- a/src/sys/linux/panic_hook.rs
+++ b/src/sys/linux/panic_hook.rs
@@ -121,8 +121,4 @@
         // Abort to trigger the crash reporter so that a minidump is generated.
         abort();
     }));
-
-    // Install the memfd handler last so it will run before the panic hook above that calls abort().
-    #[cfg(feature = "panic-memfd")]
-    base::sys::linux::panic_handler::install_memfd_handler();
 }