Skip to content

Commit

Permalink
Make pager a service with secure gates.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbittman committed Jan 9, 2025
1 parent 7845083 commit a696e88
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 47 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 6 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ members = [
"src/bin/bootstrap",
"src/bin/devmgr",
"src/bin/etl_twizzler",
"src/bin/pager",
"src/bin/mnemosyne",
"src/bin/random_validation",
"src/bin/genrandom",
Expand Down Expand Up @@ -39,9 +38,11 @@ members = [
"src/rt/minimal",
"src/lib/logboi",
"src/srv/logboi-srv",
"src/srv/pager-srv",
"src/bin/logboi-test",
"src/lib/virtio-net",
"src/bin/object-store-test",
"src/lib/pager",
]

exclude = ["toolchain/src/rust"]
Expand All @@ -52,31 +53,21 @@ initrd = [
"crate:bootstrap",
"crate:init",
"crate:devmgr",
"crate:pager",
"crate:etl_twizzler",
"crate:virtio",
"lib:twz-rt",
"crate:monitor",
"crate:montest",
"lib:montest-lib",
"crate:mnemosyne",
"crate:stdfs_demo",
"crate:logboi-test",
"lib:logboi-srv",
"crate:random_validation",
"crate:virtio",
"lib:twz-rt",
"crate:monitor",
"crate:montest",
"lib:montest-lib",
"crate:mnemosyne",
"crate:stdfs_demo",
"crate:logboi-test",
"lib:logboi-srv",
"crate:randtest",
"crate:randtest",
"crate:genrandom",
"crate:object-store-test",
"lib:twz-rt",
"lib:montest-lib",
"lib:logboi-srv",
"lib:pager-srv",
#"third-party:hello-world-rs"
]

Expand Down
1 change: 1 addition & 0 deletions src/bin/init/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ polling = "3.6.0"
futures = "*"
twizzler-futures = { path = "../../lib/twizzler-futures" }
monitor-api = { path = "../../rt/monitor-api" }
pager = { path = "../../lib/pager" }
14 changes: 1 addition & 13 deletions src/bin/init/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,8 @@ fn initialize_pager() {
NewHandleFlags::empty(),
)
.unwrap();
let pager_comp = monitor_api::CompartmentLoader::new(
"pager",
"pager",
monitor_api::NewCompartmentFlags::EXPORT_GATES,
)
.args([
"pager",
&queue.object().id().raw().to_string(),
&queue2.object().id().raw().to_string(),
])
.load()
.expect("failed to start pager");

std::mem::forget(pager_comp);
pager::pager_start(queue.object().id(), queue2.object().id());
}

fn main() {
Expand Down
13 changes: 13 additions & 0 deletions src/lib/pager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "pager"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["rlib"]

[dependencies]
secgate = { path = "../../lib/secgate" }
twizzler-runtime = { path = "../../rt" }
twizzler-rt-abi = "0.99"
pager-srv = { path = "../../srv/pager-srv" }
8 changes: 8 additions & 0 deletions src/lib/pager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use twizzler_rt_abi::object::ObjID;

#[link(name = "pager_srv")]
extern "C" {}

pub fn pager_start(q1: ObjID, q2: ObjID) {
pager_srv::pager_start(q1, q2).ok().unwrap();
}
15 changes: 13 additions & 2 deletions src/rt/monitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,19 @@ fn monitor_init() -> miette::Result<()> {
tracing::error!("failed to start monitor tests: {}", ki_name.name());
}
}
info!("monitor early init completed, starting init");

info!("monitor early init completed, starting pager");

let pager_comp = monitor_api::CompartmentLoader::new(
"pager-srv",
"libpager_srv.so",
monitor_api::NewCompartmentFlags::EXPORT_GATES,
)
.args(["pager-srv"])
.load()
.expect("failed to start pager");
std::mem::forget(pager_comp);

info!("starting init");
let comp: CompartmentHandle =
CompartmentLoader::new("init", "init", NewCompartmentFlags::empty())
.args(&["init"])
Expand Down
5 changes: 4 additions & 1 deletion src/bin/pager/Cargo.toml → src/srv/pager-srv/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[package]
name = "pager"
name = "pager-srv"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
twizzler-abi = { path = "../../lib/twizzler-abi" }
Expand All @@ -20,6 +22,7 @@ volatile = "0.5"
tracing = "0.1"
tracing-subscriber = "0.3.17"
bitvec = "1.0.1"
secgate = { path = "../../lib/secgate" }

async-io = "2.3.2"
async-executor = { version = "1.9.1", features = [] }
Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 27 additions & 16 deletions src/bin/pager/src/main.rs → src/srv/pager-srv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(ptr_sub_ptr)]
#![feature(naked_functions)]

use std::{
collections::BTreeMap,
Expand All @@ -13,9 +14,12 @@ use futures::executor::block_on;
use tickv::{success_codes::SuccessCode, ErrorCode};
use tracing::{debug, info, warn, Level};
use tracing_subscriber::FmtSubscriber;
use twizzler_abi::pager::{
CompletionToKernel, CompletionToPager, KernelCommand, KernelCompletionData, ObjectRange,
PagerCompletionData, PhysRange, RequestFromKernel, RequestFromPager,
use twizzler_abi::{
klog_println,
pager::{
CompletionToKernel, CompletionToPager, KernelCommand, KernelCompletionData, ObjectRange,
PagerCompletionData, PhysRange, RequestFromKernel, RequestFromPager,
},
};
use twizzler_object::{ObjID, Object, ObjectInitFlags, Protections};

Expand Down Expand Up @@ -70,15 +74,11 @@ fn memory_init(data: PagerData, range: PhysRange) {
* Queue Initializing
*/
fn attach_queue<T: std::marker::Copy, U: std::marker::Copy, Q>(
id_str: &str,
obj_id: ObjID,
queue_constructor: impl FnOnce(twizzler_queue::Queue<T, U>) -> Q,
) -> Result<Q, String> {
tracing::info!("Pager Attaching Queue: {}", id_str);
tracing::info!("Pager Attaching Queue: {}", obj_id);

// Parse the ID from the string
let id = id_str.parse::<u128>().unwrap();
// Initialize the object
let obj_id = ObjID::new(id);
let object = Object::init_id(
obj_id,
Protections::READ | Protections::WRITE,
Expand All @@ -96,17 +96,20 @@ fn queue_args(i: usize) -> String {
return std::env::args().nth(i).unwrap();
}

fn queue_init() -> (
fn queue_init(
q1: ObjID,
q2: ObjID,
) -> (
twizzler_queue::CallbackQueueReceiver<RequestFromKernel, CompletionToKernel>,
twizzler_queue::QueueSender<RequestFromPager, CompletionToPager>,
) {
let rq = attach_queue::<RequestFromKernel, CompletionToKernel, _>(
&queue_args(1),
q1,
twizzler_queue::CallbackQueueReceiver::new,
)
.unwrap();
let sq = attach_queue::<RequestFromPager, CompletionToPager, _>(
&queue_args(2),
q2,
twizzler_queue::QueueSender::new,
)
.unwrap();
Expand Down Expand Up @@ -165,7 +168,10 @@ fn verify_health(health: Result<(), String>) {
/***
* Pager Initialization generic function which calls specific initialization functions
*/
fn pager_init() -> (
fn pager_init(
q1: ObjID,
q2: ObjID,
) -> (
twizzler_queue::CallbackQueueReceiver<RequestFromKernel, CompletionToKernel>,
twizzler_queue::QueueSender<RequestFromPager, CompletionToPager>,
PagerData,
Expand All @@ -174,7 +180,7 @@ fn pager_init() -> (
tracing::info!("init start");
tracing_init();
let data = data_structure_init();
let (rq, sq) = queue_init();
let (rq, sq) = queue_init(q1, q2);
let ex = async_runtime_init(2);

let health = health_check(&rq, &sq, ex, None);
Expand Down Expand Up @@ -267,8 +273,8 @@ async fn report_ready(
}
}

fn main() {
let (rq, sq, data, ex) = pager_init();
fn do_pager_start(q1: ObjID, q2: ObjID) {
let (rq, sq, data, ex) = pager_init(q1, q2);
spawn_queues(rq, data.clone(), ex);
let sq = Arc::new(sq);
let sqc = Arc::clone(&sq);
Expand Down Expand Up @@ -341,6 +347,11 @@ fn main() {
//Done
}

#[secgate::secure_gate]
pub fn pager_start(q1: ObjID, q2: ObjID) {
do_pager_start(q1, q2);
}

#[repr(C, packed)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
struct Foo {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a696e88

Please sign in to comment.