summary refs log tree commit diff
path: root/arch
diff options
context:
space:
mode:
authorKansho Nishida <kansho@google.com>2019-12-18 13:13:14 +0900
committerCommit Bot <commit-bot@chromium.org>2020-02-03 05:45:14 +0000
commit282115bcdb3842e507357ec131d1c3685551fb1b (patch)
treecdf9e5068b1b913cf8be1fd8189851c388ecefbe /arch
parent95885316c25147ffe85700e4db5477aa8e516005 (diff)
downloadcrosvm-282115bcdb3842e507357ec131d1c3685551fb1b.tar
crosvm-282115bcdb3842e507357ec131d1c3685551fb1b.tar.gz
crosvm-282115bcdb3842e507357ec131d1c3685551fb1b.tar.bz2
crosvm-282115bcdb3842e507357ec131d1c3685551fb1b.tar.lz
crosvm-282115bcdb3842e507357ec131d1c3685551fb1b.tar.xz
crosvm-282115bcdb3842e507357ec131d1c3685551fb1b.tar.zst
crosvm-282115bcdb3842e507357ec131d1c3685551fb1b.zip
crosvm: pstore works for ARCVM on x86_64
Adds support for pstore on ARCVM on x86_64.
The backend file of the buffer will be passed via argument of the crosvm.

BUG=b:144962428
TEST=kernel crash on eve-arcvm, check /sys/fs/pstore/console-ramoops-0
     Launch crostini manually on eve-arcvm

Change-Id: I29492ac7a9067aa2ae23eb03fbb942ab7dd3aa8d
Signed-off-by: Kansho Nishida <kansho@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1973391
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kansho Nishida <kansho@chromium.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/src/lib.rs9
-rw-r--r--arch/src/pstore.rs74
2 files changed, 83 insertions, 0 deletions
diff --git a/arch/src/lib.rs b/arch/src/lib.rs
index ca9cd66..16cd6fa 100644
--- a/arch/src/lib.rs
+++ b/arch/src/lib.rs
@@ -4,6 +4,7 @@
 
 pub mod android;
 pub mod fdt;
+pub mod pstore;
 
 use std::collections::BTreeMap;
 use std::error::Error as StdError;
@@ -11,6 +12,7 @@ use std::fmt::{self, Display};
 use std::fs::File;
 use std::io::{self, Read, Seek, SeekFrom};
 use std::os::unix::io::AsRawFd;
+use std::path::PathBuf;
 use std::sync::Arc;
 
 use devices::virtio::VirtioDevice;
@@ -29,6 +31,12 @@ pub enum VmImage {
     Bios(File),
 }
 
+#[derive(Clone)]
+pub struct Pstore {
+    pub path: PathBuf,
+    pub size: u32,
+}
+
 /// Holds the pieces needed to build a VM. Passed to `build_vm` in the `LinuxArch` trait below to
 /// create a `RunnableLinuxVm`.
 pub struct VmComponents {
@@ -37,6 +45,7 @@ pub struct VmComponents {
     pub vcpu_affinity: Vec<usize>,
     pub vm_image: VmImage,
     pub android_fstab: Option<File>,
+    pub pstore: Option<Pstore>,
     pub initrd_image: Option<File>,
     pub extra_kernel_params: Vec<String>,
     pub wayland_dmabuf: bool,
diff --git a/arch/src/pstore.rs b/arch/src/pstore.rs
new file mode 100644
index 0000000..a06ea1b
--- /dev/null
+++ b/arch/src/pstore.rs
@@ -0,0 +1,74 @@
+// Copyright 2020 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+use std::fmt::{self, Display};
+use std::fs::OpenOptions;
+use std::io;
+
+use crate::Pstore;
+use kvm::Vm;
+use resources::SystemAllocator;
+use resources::{Alloc, MmioType};
+use sys_util::{GuestAddress, MemoryMapping};
+
+/// Error for pstore.
+#[derive(Debug)]
+pub enum Error {
+    IoError(io::Error),
+    MmapError(sys_util::MmapError),
+    ResourcesError(resources::Error),
+    SysUtilError(sys_util::Error),
+}
+
+impl Display for Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        use self::Error::*;
+
+        match self {
+            IoError(e) => write!(f, "failed to create pstore backend file: {}", e),
+            MmapError(e) => write!(f, "failed to get file mapped address: {}", e),
+            ResourcesError(e) => write!(f, "failed to allocate pstore region: {}", e),
+            SysUtilError(e) => write!(f, "file to add pstore region to mmio: {}", e),
+        }
+    }
+}
+
+impl std::error::Error for Error {}
+type Result<T> = std::result::Result<T, Error>;
+
+pub struct RamoopsRegion {
+    pub address: u64,
+    pub size: u32,
+}
+
+/// Creates a mmio memory region for pstore.
+pub fn create_memory_region(
+    vm: &mut Vm,
+    resources: &mut SystemAllocator,
+    pstore: &Pstore,
+) -> Result<RamoopsRegion> {
+    let file = OpenOptions::new()
+        .read(true)
+        .write(true)
+        .create(true)
+        .open(&pstore.path)
+        .map_err(Error::IoError)?;
+    file.set_len(pstore.size as u64).map_err(Error::IoError)?;
+
+    let address = resources
+        .mmio_allocator(MmioType::High)
+        .allocate(pstore.size as u64, Alloc::Pstore, "pstore".to_owned())
+        .map_err(Error::ResourcesError)?;
+
+    let memory_mapping =
+        MemoryMapping::from_fd(&file, pstore.size as usize).map_err(Error::MmapError)?;
+
+    vm.add_mmio_memory(GuestAddress(address), memory_mapping, false, false)
+        .map_err(Error::SysUtilError)?;
+
+    Ok(RamoopsRegion {
+        address,
+        size: pstore.size,
+    })
+}