mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-14 15:56:47 +00:00
Add tdx-guest device
This commit is contained in:
parent
a91a35ebce
commit
55ea3dc86f
@ -1,6 +1,8 @@
|
|||||||
mod null;
|
mod null;
|
||||||
mod pty;
|
mod pty;
|
||||||
mod random;
|
mod random;
|
||||||
|
#[cfg(feature = "intel_tdx")]
|
||||||
|
mod tdxguest;
|
||||||
pub mod tty;
|
pub mod tty;
|
||||||
mod urandom;
|
mod urandom;
|
||||||
mod zero;
|
mod zero;
|
||||||
@ -10,6 +12,8 @@ use crate::prelude::*;
|
|||||||
pub use pty::new_pty_pair;
|
pub use pty::new_pty_pair;
|
||||||
pub use pty::{PtyMaster, PtySlave};
|
pub use pty::{PtyMaster, PtySlave};
|
||||||
pub use random::Random;
|
pub use random::Random;
|
||||||
|
#[cfg(feature = "intel_tdx")]
|
||||||
|
pub use tdxguest::TdxGuest;
|
||||||
pub use urandom::Urandom;
|
pub use urandom::Urandom;
|
||||||
|
|
||||||
use self::tty::get_n_tty;
|
use self::tty::get_n_tty;
|
||||||
@ -25,6 +29,10 @@ pub fn init() -> Result<()> {
|
|||||||
add_node(console, "console")?;
|
add_node(console, "console")?;
|
||||||
let tty = Arc::new(tty::TtyDevice);
|
let tty = Arc::new(tty::TtyDevice);
|
||||||
add_node(tty, "tty")?;
|
add_node(tty, "tty")?;
|
||||||
|
#[cfg(feature = "intel_tdx")]
|
||||||
|
let tdx_guest = Arc::new(tdxguest::TdxGuest);
|
||||||
|
#[cfg(feature = "intel_tdx")]
|
||||||
|
add_node(tdx_guest, "tdx-guest")?;
|
||||||
let random = Arc::new(random::Random);
|
let random = Arc::new(random::Random);
|
||||||
add_node(random, "random")?;
|
add_node(random, "random")?;
|
||||||
let urandom = Arc::new(urandom::Urandom);
|
let urandom = Arc::new(urandom::Urandom);
|
||||||
|
55
services/libs/jinux-std/src/device/tdxguest/mod.rs
Normal file
55
services/libs/jinux-std/src/device/tdxguest/mod.rs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
use super::*;
|
||||||
|
use crate::events::IoEvents;
|
||||||
|
use crate::fs::inode_handle::FileIo;
|
||||||
|
use crate::fs::utils::IoctlCmd;
|
||||||
|
use crate::process::signal::Poller;
|
||||||
|
use crate::util::{read_val_from_user, write_val_to_user};
|
||||||
|
use tdx_guest::tdcall::get_report;
|
||||||
|
|
||||||
|
const TDX_REPORTDATA_LEN: usize = 64;
|
||||||
|
const TDX_REPORT_LEN: usize = 1024;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Pod)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct TdxReportRequest {
|
||||||
|
reportdata: [u8; TDX_REPORTDATA_LEN],
|
||||||
|
tdreport: [u8; TDX_REPORT_LEN],
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TdxGuest;
|
||||||
|
|
||||||
|
impl Device for TdxGuest {
|
||||||
|
fn type_(&self) -> DeviceType {
|
||||||
|
DeviceType::MiscDevice
|
||||||
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> DeviceId {
|
||||||
|
DeviceId::new(10, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl FileIo for TdxGuest {
|
||||||
|
fn read(&self, buf: &mut [u8]) -> Result<usize> {
|
||||||
|
return_errno_with_message!(Errno::EPERM, "Read operation not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(&self, buf: &[u8]) -> Result<usize> {
|
||||||
|
return_errno_with_message!(Errno::EPERM, "Write operation not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ioctl(&self, cmd: IoctlCmd, arg: usize) -> Result<i32> {
|
||||||
|
match cmd {
|
||||||
|
IoctlCmd::TDXGETREPORT => {
|
||||||
|
let tdx_report: TdxReportRequest = read_val_from_user(arg)?;
|
||||||
|
get_report(&tdx_report.tdreport, &tdx_report.reportdata).unwrap();
|
||||||
|
write_val_to_user(arg, &tdx_report)?;
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
_ => return_errno_with_message!(Errno::EPERM, "Unsupported ioctl"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll(&self, mask: IoEvents, poller: Option<&Poller>) -> IoEvents {
|
||||||
|
let events = IoEvents::IN | IoEvents::OUT;
|
||||||
|
events & mask
|
||||||
|
}
|
||||||
|
}
|
@ -33,6 +33,7 @@ impl Debug for dyn Device {
|
|||||||
pub enum DeviceType {
|
pub enum DeviceType {
|
||||||
CharDevice,
|
CharDevice,
|
||||||
BlockDevice,
|
BlockDevice,
|
||||||
|
MiscDevice,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Device Id
|
/// Device Id
|
||||||
|
@ -51,6 +51,7 @@ impl From<DeviceType> for InodeType {
|
|||||||
match type_ {
|
match type_ {
|
||||||
DeviceType::CharDevice => InodeType::CharDevice,
|
DeviceType::CharDevice => InodeType::CharDevice,
|
||||||
DeviceType::BlockDevice => InodeType::BlockDevice,
|
DeviceType::BlockDevice => InodeType::BlockDevice,
|
||||||
|
DeviceType::MiscDevice => InodeType::CharDevice,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,4 +29,6 @@ pub enum IoctlCmd {
|
|||||||
TIOCSPTLCK = 0x40045431,
|
TIOCSPTLCK = 0x40045431,
|
||||||
/// Safely open the slave
|
/// Safely open the slave
|
||||||
TIOCGPTPEER = 0x40045441,
|
TIOCGPTPEER = 0x40045441,
|
||||||
|
/// Get tdx report using TDCALL
|
||||||
|
TDXGETREPORT = 0xc4405401,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user