From 1776c645c9689ea740f854e77e33a0a341b9ae93 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Wed, 21 Mar 2018 18:26:22 -0700 Subject: [PATCH] x86_64: Add separate error for getting sregs Re-using the set error could cause confusion. BUG=none TEST=none Change-Id: I47445b28946484028bf96cff9ee0bc8c89b6f3e5 Signed-off-by: Dylan Reid Reviewed-on: https://chromium-review.googlesource.com/974741 Reviewed-by: Zach Reizner --- x86_64/src/regs.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/x86_64/src/regs.rs b/x86_64/src/regs.rs index 31b6bab3f0..aac058e5a1 100644 --- a/x86_64/src/regs.rs +++ b/x86_64/src/regs.rs @@ -22,10 +22,12 @@ pub enum Error { MsrIoctlFailed(sys_util::Error), /// Failed to configure the FPU. FpuIoctlFailed(sys_util::Error), + /// Failed to get sregs for this cpu. + GetSRegsIoctlFailed(sys_util::Error), /// Failed to set base registers for this cpu. SettingRegistersIoctl(sys_util::Error), /// Failed to set sregs for this cpu. - SRegsIoctlFailed(sys_util::Error), + SetSRegsIoctlFailed(sys_util::Error), /// Writing the GDT to RAM failed. WriteGDTFailure, /// Writing the IDT to RAM failed. @@ -46,9 +48,11 @@ impl error::Error for Error { "Setting up msrs failed", &Error::FpuIoctlFailed(_) => "Failed to configure the FPU", + &Error::GetSRegsIoctlFailed(_) => + "Failed to get sregs for this cpu", &Error::SettingRegistersIoctl(_) => "Failed to set base registers for this cpu", - &Error::SRegsIoctlFailed(_) => + &Error::SetSRegsIoctlFailed(_) => "Failed to set sregs for this cpu", &Error::WriteGDTFailure => "Writing the GDT to RAM failed", @@ -298,12 +302,12 @@ fn setup_page_tables(mem: &GuestMemory, sregs: &mut kvm_sregs) -> Result<()> { /// * `mem` - The memory that will be passed to the guest. /// * `vcpu_fd` - The FD returned from the KVM_CREATE_VCPU ioctl. pub fn setup_sregs(mem: &GuestMemory, vcpu: &kvm::Vcpu) -> Result<()> { - let mut sregs: kvm_sregs = vcpu.get_sregs().map_err(Error::SRegsIoctlFailed)?; + let mut sregs: kvm_sregs = vcpu.get_sregs().map_err(Error::GetSRegsIoctlFailed)?; configure_segments_and_sregs(mem, &mut sregs)?; setup_page_tables(mem, &mut sregs)?; // TODO(dgreid) - Can this be done once per system instead? - vcpu.set_sregs(&sregs).map_err(Error::SRegsIoctlFailed)?; + vcpu.set_sregs(&sregs).map_err(Error::SetSRegsIoctlFailed)?; Ok(()) }