From 957d3deeeaf98978a0fcfcdfef048dc37b623aee Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Wed, 30 Jun 2021 18:00:45 +0800 Subject: [PATCH] arch: gic: Extend GicV3Its with `its_device` field In current code, the ITS device fd of GICv3 will be lost after the creation of GIC. This commit adds a new `its_device` field for the `GicV3Its` struct, which will be useful to save the ITS device fd. This fd will be used in restoring the ITS device. Signed-off-by: Henry Wang --- arch/src/aarch64/gic/gicv3.rs | 9 +++++++-- arch/src/aarch64/gic/gicv3_its.rs | 22 +++++++++++++++++++--- arch/src/aarch64/gic/mod.rs | 13 ++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/arch/src/aarch64/gic/gicv3.rs b/arch/src/aarch64/gic/gicv3.rs index 7716e34a9..1620956dc 100644 --- a/arch/src/aarch64/gic/gicv3.rs +++ b/arch/src/aarch64/gic/gicv3.rs @@ -1,5 +1,8 @@ +// Copyright 2021 Arm Limited (or its affiliates). All rights reserved. // Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// +// This file implements the GicV3 device. pub mod kvm { use crate::aarch64::gic::dist_regs::{get_dist_regs, read_ctlr, set_dist_regs, write_ctlr}; @@ -50,7 +53,7 @@ pub mod kvm { type Result = result::Result; pub struct KvmGicV3 { - /// The hypervisor agnostic device + /// The hypervisor agnostic device for the GicV3 device: Arc, /// Vector holding values of GICR_TYPER for each vCPU @@ -168,6 +171,8 @@ pub mod kvm { self.vcpu_count } + fn set_its_device(&mut self, _its_device: Option>) {} + fn set_gicr_typers(&mut self, vcpu_states: &[CpuState]) { let gicr_typers = construct_gicr_typers(vcpu_states); self.gicr_typers = gicr_typers; @@ -202,7 +207,7 @@ pub mod kvm { fn init_device_attributes( _vm: &Arc, - gic_device: &dyn GicDevice, + gic_device: &mut dyn GicDevice, ) -> crate::aarch64::gic::Result<()> { /* Setting up the distributor attribute. We are placing the GIC below 1GB so we need to substract the size of the distributor. diff --git a/arch/src/aarch64/gic/gicv3_its.rs b/arch/src/aarch64/gic/gicv3_its.rs index c9ec07186..e110c9206 100644 --- a/arch/src/aarch64/gic/gicv3_its.rs +++ b/arch/src/aarch64/gic/gicv3_its.rs @@ -1,5 +1,7 @@ -// Copyright 2020 ARM Limited +// Copyright 2021 Arm Limited (or its affiliates). All rights reserved. // SPDX-License-Identifier: Apache-2.0 +// +// This file implements the GicV3 device with ITS (Virtual Interrupt Translation Service). pub mod kvm { use std::any::Any; @@ -13,9 +15,12 @@ pub mod kvm { use hypervisor::CpuState; pub struct KvmGicV3Its { - /// The hypervisor agnostic device + /// The hypervisor agnostic device for the GicV3 device: Arc, + /// The hypervisor agnostic device for the Its device + its_device: Option>, + /// GIC device properties, to be used for setting up the fdt entry gic_properties: [u64; 4], @@ -43,6 +48,10 @@ pub mod kvm { &self.device } + fn its_device(&self) -> Option<&Arc> { + self.its_device.as_ref() + } + fn fdt_compatibility(&self) -> &str { "arm,gic-v3" } @@ -71,6 +80,10 @@ pub mod kvm { self.vcpu_count } + fn set_its_device(&mut self, its_device: Option>) { + self.its_device = its_device; + } + fn set_gicr_typers(&mut self, _vcpu_states: &[CpuState]) {} fn as_any_concrete_mut(&mut self) -> &mut dyn Any { @@ -89,6 +102,7 @@ pub mod kvm { ) -> Box { Box::new(KvmGicV3Its { device, + its_device: None, gic_properties: [ KvmGicV3::get_dist_addr(), KvmGicV3::get_dist_size(), @@ -105,7 +119,7 @@ pub mod kvm { fn init_device_attributes( vm: &Arc, - gic_device: &dyn GicDevice, + gic_device: &mut dyn GicDevice, ) -> Result<()> { KvmGicV3::init_device_attributes(vm, gic_device)?; @@ -135,6 +149,8 @@ pub mod kvm { 0, )?; + gic_device.set_its_device(Some(its_fd)); + Ok(()) } } diff --git a/arch/src/aarch64/gic/mod.rs b/arch/src/aarch64/gic/mod.rs index 62008a8b7..217aa6606 100644 --- a/arch/src/aarch64/gic/mod.rs +++ b/arch/src/aarch64/gic/mod.rs @@ -31,6 +31,11 @@ pub trait GicDevice: Send { /// Returns the hypervisor agnostic Device of the GIC device fn device(&self) -> &Arc; + /// Returns the hypervisor agnostic Device of the ITS device + fn its_device(&self) -> Option<&Arc> { + None + } + /// Returns the fdt compatibility property of the device fn fdt_compatibility(&self) -> &str; @@ -58,6 +63,8 @@ pub trait GicDevice: Send { &[] } + fn set_its_device(&mut self, its_device: Option>); + /// Get the values of GICR_TYPER for each vCPU. fn set_gicr_typers(&mut self, vcpu_states: &[CpuState]); @@ -88,7 +95,7 @@ pub mod kvm { /// Setup the device-specific attributes fn init_device_attributes( vm: &Arc, - gic_device: &dyn GicDevice, + gic_device: &mut dyn GicDevice, ) -> Result<()>; /// Initialize a GIC device @@ -179,9 +186,9 @@ pub mod kvm { fn new(vm: &Arc, vcpu_count: u64) -> Result> { let vgic_fd = Self::init_device(vm)?; - let device = Self::create_device(vgic_fd, vcpu_count); + let mut device = Self::create_device(vgic_fd, vcpu_count); - Self::init_device_attributes(vm, &*device)?; + Self::init_device_attributes(vm, &mut *device)?; Self::finalize_device(&*device)?;