GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(locality): own and withdraw runtime maps before startup · arencloud/unf@462102f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Cargo.lock
  • crates/unf-locality
    • Cargo.toml
    • examples
      • kernel_observed_bank.rs
      • support
        • runtime_owner.rs
    • src
      • admission.rs
      • kernel.rs
      • kernel
        • pins.rs
        • runtime.rs
  • docs
    • adr
      • 0423-owned-locality-runtime-startup.md
    • development
      • phase9-attested-encryption-fabric-plan.md
      • phase9-required-locality-plan.md
    • project-status.md
  • hack
    • verify-locality-incarnation-gate.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Cargo.lock‎

Copy file name to clipboardExpand all lines: Cargo.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎crates/unf-locality/Cargo.toml‎

Copy file name to clipboardExpand all lines: crates/unf-locality/Cargo.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ repository.workspace = true
99
[dependencies]
1010
anyhow.workspace = true
1111
aya.workspace = true
12+
aya-obj = "0.3.0"
1213
rustix.workspace = true
1314
tempfile = "3.27.0"
1415
thiserror.workspace = true
Collapse file

‎crates/unf-locality/examples/kernel_observed_bank.rs‎

Copy file name to clipboardExpand all lines: crates/unf-locality/examples/kernel_observed_bank.rs
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use unf_route::{NativeRoutePlan, NativeRoutingProvider, RoutingProvider};
2121
mod journal_floor;
2222
#[path = "support/kernel_bank.rs"]
2323
mod kernel_bank;
24+
#[path = "support/runtime_owner.rs"]
25+
mod runtime_owner;
2426

2527
fn request(operation: TransactionOperation) -> TransactionRequest {
2628
TransactionRequest::new(CNI_TRANSACTION_SCHEMA_VERSION, operation)
@@ -195,6 +197,13 @@ async fn main() {
195197
let second_plan = create(&mut journal, provider, "second", &args[1]).await;
196198
let records = journal.records();
197199
let (evidence, context) = evidence(&records);
200+
if std::env::var("UNF_LOCALITY_RUNTIME_OWNER_TEST").as_deref() == Ok("yes") {
201+
runtime_owner::verify(
202+
Path::new(&std::env::var("UNF_KERNEL_BANK_BPFFS").unwrap()),
203+
&context,
204+
)
205+
.unwrap();
206+
}
198207
let gate = IncarnationGate::install(&mut journal, 8).unwrap();
199208
if std::env::var("UNF_LOCALITY_JOURNAL_FLOOR_TEST").as_deref() == Ok("yes") {
200209
journal_floor::verify(
Collapse file

‎crates/unf-locality/examples/support/runtime_owner.rs‎

Copy file name to clipboard
+175Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
//! Owned disposable startup pins. No production path, map or attachment.
2+
use std::os::fd::AsFd as _;
3+
use std::{fs, path::Path};
4+
5+
use anyhow::{Context as _, Result, ensure};
6+
use aya::{
7+
Ebpf, EbpfLoader,
8+
maps::{Array, Map, ProgramArray},
9+
programs::SchedClassifier,
10+
};
11+
use unf_encryption::EncryptionLocalityContext;
12+
use unf_locality::LocalityRuntimeMaps;
13+
14+
const NAMES: [&str; 4] = [
15+
"UL_INPUT_V1",
16+
"UL_FENCE_V1",
17+
"UL_RESUME_V1",
18+
"UL_DISPATCH_V1",
19+
];
20+
21+
fn program(object: &Ebpf) -> Result<&SchedClassifier> {
22+
object
23+
.program("unf_locality_fixture")
24+
.context("fixture program")?
25+
.try_into()
26+
.map_err(Into::into)
27+
}
28+
29+
fn load(runtime: &LocalityRuntimeMaps) -> Result<Ebpf> {
30+
let mut loader = EbpfLoader::new();
31+
runtime.configure_loader(&mut loader)?;
32+
let mut object = loader.load_file("/usr/local/lib/unf/locality-fixture")?;
33+
runtime.verify_loaded(&object)?;
34+
let classifier: &mut SchedClassifier = object
35+
.program_mut("unf_locality_fixture")
36+
.context("fixture program")?
37+
.try_into()?;
38+
classifier.load()?;
39+
Ok(object)
40+
}
41+
42+
fn data<'a>(object: &'a Ebpf, name: &str) -> Result<&'a aya::maps::MapData> {
43+
match object.map(name).context("fixture map")? {
44+
Map::Array(data) | Map::PerCpuArray(data) | Map::ProgramArray(data) => Ok(data),
45+
_ => anyhow::bail!("unexpected map type"),
46+
}
47+
}
48+
49+
fn assert_withdrawn(object: &Ebpf) -> Result<()> {
50+
let fence: Array<_, [u64; 4]> = Array::try_from(object.map("UL_FENCE_V1").context("fence")?)?;
51+
ensure!(fence.get(&0, 0)? == [0; 4], "reopen left an armed fence");
52+
// Program-array UAPI lookup returns a fixed-width program ID, or ENOENT.
53+
let dispatch: Array<_, u32> = Array::try_from(Map::Array(aya::maps::MapData::from_fd(
54+
data(object, "UL_DISPATCH_V1")?
55+
.fd()
56+
.as_fd()
57+
.try_clone_to_owned()?,
58+
)?))?;
59+
ensure!(
60+
matches!(dispatch.get(&0, 0), Err(aya::maps::MapError::KeyNotFound)),
61+
"reopen left a selected program"
62+
);
63+
let resume: Array<_, u32> = Array::try_from(Map::Array(aya::maps::MapData::from_fd(
64+
data(object, "UL_RESUME_V1")?
65+
.fd()
66+
.as_fd()
67+
.try_clone_to_owned()?,
68+
)?))?;
69+
for index in 0..4 {
70+
ensure!(
71+
matches!(resume.get(&index, 0), Err(aya::maps::MapError::KeyNotFound)),
72+
"reopen retained an old continuation"
73+
);
74+
}
75+
Ok(())
76+
}
77+
78+
pub fn verify(bpffs: &Path, context: &EncryptionLocalityContext) -> Result<()> {
79+
ensure!(
80+
bpffs.starts_with("/tmp") && bpffs.file_name().is_some_and(|name| name == "bpffs"),
81+
"fixture bpffs scope"
82+
);
83+
let parent = tempfile::Builder::new()
84+
.prefix("unf-locality-owned-")
85+
.tempdir_in(bpffs)?;
86+
let regular = tempfile::tempdir()?;
87+
let owner = regular.path().join("owner.lock");
88+
let pins = parent.path().join("v1");
89+
ensure!(
90+
LocalityRuntimeMaps::open_owned(&pins, &owner).is_err() && !pins.exists(),
91+
"missing pins silently became fresh authority"
92+
);
93+
let mut runtime = LocalityRuntimeMaps::create_owned(&pins, &owner)?;
94+
let object = load(&runtime)?;
95+
assert_withdrawn(&object)?;
96+
ensure!(
97+
LocalityRuntimeMaps::open_owned(&pins, &owner).is_err(),
98+
"competing runtime owner accepted"
99+
);
100+
runtime.set_applied(context)?;
101+
// A deliberately armed private table, not a production consumer. No TC
102+
// attachment and no packet invocation; reopen must clear this real table.
103+
let mut dispatch =
104+
ProgramArray::try_from(aya::maps::Map::ProgramArray(aya::maps::MapData::from_fd(
105+
data(&object, "UL_DISPATCH_V1")?
106+
.fd()
107+
.as_fd()
108+
.try_clone_to_owned()?,
109+
)?))?;
110+
dispatch.set(0, program(&object)?.fd()?, 0)?;
111+
drop(dispatch);
112+
let mut resume = ProgramArray::try_from(Map::ProgramArray(aya::maps::MapData::from_fd(
113+
data(&object, "UL_RESUME_V1")?
114+
.fd()
115+
.as_fd()
116+
.try_clone_to_owned()?,
117+
)?))?;
118+
for index in 0..4 {
119+
resume.set(index, program(&object)?.fd()?, 0)?;
120+
}
121+
drop(resume);
122+
drop(runtime);
123+
let reopened = LocalityRuntimeMaps::open_owned(&pins, &owner)?;
124+
reopened.verify_loaded(&object)?;
125+
assert_withdrawn(&object)?;
126+
let foreign = Ebpf::load_file("/usr/local/lib/unf/locality-fixture")?;
127+
ensure!(
128+
reopened.verify_loaded(&foreign).is_err(),
129+
"foreign runtime accepted by shape"
130+
);
131+
drop(foreign);
132+
drop(reopened);
133+
134+
let missing = pins.join("UL_FENCE_V1");
135+
// This exact fixture-created pin is recoverable from the retained FD.
136+
fs::remove_file(&missing)?;
137+
ensure!(
138+
LocalityRuntimeMaps::open_owned(&pins, &owner).is_err(),
139+
"partial inventory accepted"
140+
);
141+
ensure!(
142+
!missing.exists(),
143+
"partial inventory silently recreated a map"
144+
);
145+
data(&object, "UL_FENCE_V1")?.pin(&missing)?;
146+
let extra = pins.join("unexpected");
147+
data(&object, "UL_INPUT_V1")?.pin(&extra)?;
148+
ensure!(
149+
LocalityRuntimeMaps::open_owned(&pins, &owner).is_err(),
150+
"foreign inventory accepted"
151+
);
152+
ensure!(extra.exists(), "foreign inventory silently removed");
153+
fs::remove_file(&extra)?;
154+
let final_owner = LocalityRuntimeMaps::open_owned(&pins, &owner)?;
155+
final_owner.verify_loaded(&object)?;
156+
assert_withdrawn(&object)?;
157+
drop(final_owner);
158+
for name in NAMES {
159+
let path = pins.join(name);
160+
let pinned = aya::maps::MapData::from_pin(&path)?;
161+
ensure!(
162+
pinned.info()?.id() == data(&object, name)?.info()?.id(),
163+
"cleanup pin was substituted"
164+
);
165+
fs::remove_file(path)?;
166+
}
167+
fs::remove_dir(&pins)?;
168+
drop(object);
169+
parent.close()?;
170+
regular.close()?;
171+
println!(
172+
"kernel-locality-runtime-owner: PASS atomic-create=true exclusive-owner=true reopen-withdrawn=true exact-bindings=true partial-rejected=true foreign-preserved=true cleanup=true"
173+
);
174+
Ok(())
175+
}
Collapse file

‎crates/unf-locality/src/admission.rs‎

Copy file name to clipboardExpand all lines: crates/unf-locality/src/admission.rs
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ impl LocalityApplyGuard {
224224
}
225225

226226
impl LocalityAdmission {
227+
/// Bind the real loader while retaining exclusive startup ownership.
228+
///
229+
/// # Errors
230+
/// Reports missing owned pins or poisoned synchronization.
231+
pub fn configure_loader(&self, loader: &mut aya::EbpfLoader<'_>) -> Result<()> {
232+
lock(&self.state)?.runtime.configure_loader(loader)
233+
}
234+
235+
/// Check the newly loaded runtime's actual shared map identities before
236+
/// any TC attachment. Names or compatible shapes alone are insufficient.
237+
///
238+
/// # Errors
239+
/// Reports missing/substituted maps or poisoned synchronization.
240+
pub fn verify_loaded(&self, object: &aya::Ebpf) -> Result<()> {
241+
lock(&self.state)?.runtime.verify_loaded(object)
242+
}
243+
227244
/// Take exclusive map ownership and withdraw before any CNI-serving startup
228245
/// or input mutation. Both components start unknown, including on restart.
229246
///
Collapse file

‎crates/unf-locality/src/kernel.rs‎

Copy file name to clipboardExpand all lines: crates/unf-locality/src/kernel.rs
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! delivery and cannot be restored from serialized metadata or old pins.
33
44
pub(crate) mod build;
5+
mod pins;
56
pub(crate) mod runtime;
67
mod sys;
78

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.