mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 05:35:20 +00:00
virtio-devices: Rename address translation function for more clarity
Renaming translate() to translate_gva() to clarify we want to translate a GVA address into a GPA. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
16c525b2c0
commit
059e787cb5
@ -209,7 +209,7 @@ impl Request {
|
||||
|
||||
let hdr_desc_addr = hdr_desc
|
||||
.addr()
|
||||
.translate(access_platform, hdr_desc.len() as usize);
|
||||
.translate_gva(access_platform, hdr_desc.len() as usize);
|
||||
|
||||
let mut req = Request {
|
||||
request_type: request_type(desc_chain.memory(), hdr_desc_addr)?,
|
||||
@ -249,7 +249,8 @@ impl Request {
|
||||
}
|
||||
|
||||
req.data_descriptors.push((
|
||||
desc.addr().translate(access_platform, desc.len() as usize),
|
||||
desc.addr()
|
||||
.translate_gva(access_platform, desc.len() as usize),
|
||||
desc.len(),
|
||||
));
|
||||
desc = desc_chain
|
||||
@ -274,7 +275,7 @@ impl Request {
|
||||
|
||||
req.status_addr = status_desc
|
||||
.addr()
|
||||
.translate(access_platform, status_desc.len() as usize);
|
||||
.translate_gva(access_platform, status_desc.len() as usize);
|
||||
|
||||
Ok(req)
|
||||
}
|
||||
|
@ -71,14 +71,14 @@ impl CtrlQueue {
|
||||
.read_obj(
|
||||
ctrl_desc
|
||||
.addr()
|
||||
.translate(access_platform, ctrl_desc.len() as usize),
|
||||
.translate_gva(access_platform, ctrl_desc.len() as usize),
|
||||
)
|
||||
.map_err(Error::GuestMemory)?;
|
||||
let data_desc = desc_chain.next().ok_or(Error::NoDataDescriptor)?;
|
||||
|
||||
let data_desc_addr = data_desc
|
||||
.addr()
|
||||
.translate(access_platform, data_desc.len() as usize);
|
||||
.translate_gva(access_platform, data_desc.len() as usize);
|
||||
|
||||
let status_desc = desc_chain.next().ok_or(Error::NoStatusDescriptor)?;
|
||||
|
||||
@ -135,7 +135,7 @@ impl CtrlQueue {
|
||||
if ok { VIRTIO_NET_OK } else { VIRTIO_NET_ERR } as u8,
|
||||
status_desc
|
||||
.addr()
|
||||
.translate(access_platform, status_desc.len() as usize),
|
||||
.translate_gva(access_platform, status_desc.len() as usize),
|
||||
)
|
||||
.map_err(Error::GuestMemory)?;
|
||||
let len = ctrl_desc.len() + data_desc.len() + status_desc.len();
|
||||
|
@ -60,7 +60,9 @@ impl TxVirtio {
|
||||
|
||||
let mut iovecs = Vec::new();
|
||||
while let Some(desc) = next_desc {
|
||||
let desc_addr = desc.addr().translate(access_platform, desc.len() as usize);
|
||||
let desc_addr = desc
|
||||
.addr()
|
||||
.translate_gva(access_platform, desc.len() as usize);
|
||||
if !desc.is_write_only() && desc.len() > 0 {
|
||||
let buf = desc_chain
|
||||
.memory()
|
||||
@ -192,7 +194,8 @@ impl RxVirtio {
|
||||
let num_buffers_addr = desc_chain
|
||||
.memory()
|
||||
.checked_offset(
|
||||
desc.addr().translate(access_platform, desc.len() as usize),
|
||||
desc.addr()
|
||||
.translate_gva(access_platform, desc.len() as usize),
|
||||
10,
|
||||
)
|
||||
.unwrap();
|
||||
@ -200,7 +203,9 @@ impl RxVirtio {
|
||||
|
||||
let mut iovecs = Vec::new();
|
||||
while let Some(desc) = next_desc {
|
||||
let desc_addr = desc.addr().translate(access_platform, desc.len() as usize);
|
||||
let desc_addr = desc
|
||||
.addr()
|
||||
.translate_gva(access_platform, desc.len() as usize);
|
||||
if desc.is_write_only() && desc.len() > 0 {
|
||||
let buf = desc_chain
|
||||
.memory()
|
||||
|
@ -151,7 +151,7 @@ impl ConsoleEpollHandler {
|
||||
if let Err(e) = desc_chain.memory().write_slice(
|
||||
&source_slice[..],
|
||||
desc.addr()
|
||||
.translate(self.access_platform.as_ref(), desc.len() as usize),
|
||||
.translate_gva(self.access_platform.as_ref(), desc.len() as usize),
|
||||
) {
|
||||
error!("Failed to write slice: {:?}", e);
|
||||
avail_iter.go_to_previous_position();
|
||||
@ -190,7 +190,7 @@ impl ConsoleEpollHandler {
|
||||
if let Some(ref mut out) = self.endpoint.out_file() {
|
||||
let _ = desc_chain.memory().write_to(
|
||||
desc.addr()
|
||||
.translate(self.access_platform.as_ref(), desc.len() as usize),
|
||||
.translate_gva(self.access_platform.as_ref(), desc.len() as usize),
|
||||
out,
|
||||
desc.len() as usize,
|
||||
);
|
||||
|
@ -207,7 +207,8 @@ pub trait VirtioDevice: Send {
|
||||
/// On the other side, the implementation itself should be provided by the code
|
||||
/// emulating the IOMMU for the guest.
|
||||
pub trait DmaRemapping: Send + Sync {
|
||||
fn translate(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
/// Provide a way to translate GVA address ranges into GPAs.
|
||||
fn translate_gva(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
}
|
||||
|
||||
/// Structure to handle device state common to all devices
|
||||
|
@ -683,7 +683,7 @@ pub struct IommuMapping {
|
||||
}
|
||||
|
||||
impl DmaRemapping for IommuMapping {
|
||||
fn translate(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error> {
|
||||
fn translate_gva(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error> {
|
||||
debug!("Translate addr 0x{:x}", addr);
|
||||
if let Some(domain) = self.endpoints.read().unwrap().get(&id) {
|
||||
if let Some(mapping) = self.mappings.read().unwrap().get(domain) {
|
||||
@ -720,8 +720,8 @@ impl AccessPlatformMapping {
|
||||
}
|
||||
|
||||
impl AccessPlatform for AccessPlatformMapping {
|
||||
fn translate(&self, base: u64, _size: u64) -> std::result::Result<u64, std::io::Error> {
|
||||
self.mapping.translate(self.id, base)
|
||||
fn translate_gva(&self, base: u64, _size: u64) -> std::result::Result<u64, std::io::Error> {
|
||||
self.mapping.translate_gva(self.id, base)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,10 @@ impl Request {
|
||||
|
||||
let request: VirtioPmemReq = desc_chain
|
||||
.memory()
|
||||
.read_obj(desc.addr().translate(access_platform, desc.len() as usize))
|
||||
.read_obj(
|
||||
desc.addr()
|
||||
.translate_gva(access_platform, desc.len() as usize),
|
||||
)
|
||||
.map_err(Error::GuestMemory)?;
|
||||
|
||||
let request_type = match request.type_ {
|
||||
@ -156,7 +159,7 @@ impl Request {
|
||||
type_: request_type,
|
||||
status_addr: status_desc
|
||||
.addr()
|
||||
.translate(access_platform, status_desc.len() as usize),
|
||||
.translate_gva(access_platform, status_desc.len() as usize),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ impl RngEpollHandler {
|
||||
.memory()
|
||||
.read_from(
|
||||
desc.addr()
|
||||
.translate(self.access_platform.as_ref(), desc.len() as usize),
|
||||
.translate_gva(self.access_platform.as_ref(), desc.len() as usize),
|
||||
&mut self.random_file,
|
||||
desc.len() as usize,
|
||||
)
|
||||
|
@ -204,11 +204,15 @@ impl VirtioPciCommonConfig {
|
||||
// Translate address of descriptor table and vrings.
|
||||
if let Some(access_platform) = &self.access_platform {
|
||||
if ready {
|
||||
let desc_table =
|
||||
access_platform.translate(q.state.desc_table.0, 0).unwrap();
|
||||
let avail_ring =
|
||||
access_platform.translate(q.state.avail_ring.0, 0).unwrap();
|
||||
let used_ring = access_platform.translate(q.state.used_ring.0, 0).unwrap();
|
||||
let desc_table = access_platform
|
||||
.translate_gva(q.state.desc_table.0, 0)
|
||||
.unwrap();
|
||||
let avail_ring = access_platform
|
||||
.translate_gva(q.state.avail_ring.0, 0)
|
||||
.unwrap();
|
||||
let used_ring = access_platform
|
||||
.translate_gva(q.state.used_ring.0, 0)
|
||||
.unwrap();
|
||||
q.set_desc_table_address(
|
||||
Some((desc_table & 0xffff_ffff) as u32),
|
||||
Some((desc_table >> 32) as u32),
|
||||
|
@ -127,7 +127,8 @@ impl VsockPacket {
|
||||
let mut pkt = Self {
|
||||
hdr: get_host_address_range(
|
||||
desc_chain.memory(),
|
||||
head.addr().translate(access_platform, head.len() as usize),
|
||||
head.addr()
|
||||
.translate_gva(access_platform, head.len() as usize),
|
||||
VSOCK_PKT_HDR_SIZE,
|
||||
)
|
||||
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||
@ -166,7 +167,7 @@ impl VsockPacket {
|
||||
desc_chain.memory(),
|
||||
buf_desc
|
||||
.addr()
|
||||
.translate(access_platform, buf_desc.len() as usize),
|
||||
.translate_gva(access_platform, buf_desc.len() as usize),
|
||||
pkt.buf_size,
|
||||
)
|
||||
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||
@ -207,7 +208,8 @@ impl VsockPacket {
|
||||
Ok(Self {
|
||||
hdr: get_host_address_range(
|
||||
desc_chain.memory(),
|
||||
head.addr().translate(access_platform, head.len() as usize),
|
||||
head.addr()
|
||||
.translate_gva(access_platform, head.len() as usize),
|
||||
VSOCK_PKT_HDR_SIZE,
|
||||
)
|
||||
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||
@ -216,7 +218,7 @@ impl VsockPacket {
|
||||
desc_chain.memory(),
|
||||
buf_desc
|
||||
.addr()
|
||||
.translate(access_platform, buf_desc.len() as usize),
|
||||
.translate_gva(access_platform, buf_desc.len() as usize),
|
||||
buf_size,
|
||||
)
|
||||
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||
|
@ -94,19 +94,18 @@ impl fmt::Display for VirtioDeviceType {
|
||||
/// Trait for devices with access to data in memory being limited and/or
|
||||
/// translated.
|
||||
pub trait AccessPlatform: Send + Sync + Debug {
|
||||
/// Provide a way to translate address ranges.
|
||||
fn translate(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
/// Provide a way to translate GVA address ranges into GPAs.
|
||||
fn translate_gva(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
}
|
||||
|
||||
pub trait Translatable {
|
||||
#[must_use]
|
||||
fn translate(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self;
|
||||
fn translate_gva(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self;
|
||||
}
|
||||
|
||||
impl Translatable for GuestAddress {
|
||||
fn translate(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
fn translate_gva(&self, access_platform: Option<&Arc<dyn AccessPlatform>>, len: usize) -> Self {
|
||||
if let Some(access_platform) = access_platform {
|
||||
GuestAddress(access_platform.translate(self.0, len as u64).unwrap())
|
||||
GuestAddress(access_platform.translate_gva(self.0, len as u64).unwrap())
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user