From 85f755f50a30c379a61203ce82df1b84eb469d09 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 26 Mar 2024 18:07:06 +0000 Subject: [PATCH 01/16] Update nightly toolchain. --- .github/buildomat/jobs/opte-api.sh | 4 ++-- .github/buildomat/jobs/opte-ioctl.sh | 4 ++-- .github/buildomat/jobs/opte.sh | 8 ++++---- .github/buildomat/jobs/opteadm.sh | 4 ++-- .github/buildomat/jobs/oxide-vpc.sh | 8 ++++---- .github/buildomat/jobs/p5p.sh | 2 +- .github/buildomat/jobs/xde.sh | 6 +++--- xde/rust-toolchain.toml | 2 +- xde/x86_64-unknown-unknown.json | 2 +- xde/xde-link/i686-unknown-illumos.json | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/buildomat/jobs/opte-api.sh b/.github/buildomat/jobs/opte-api.sh index 3dd1ec99..a4ededaf 100755 --- a/.github/buildomat/jobs/opte-api.sh +++ b/.github/buildomat/jobs/opte-api.sh @@ -3,7 +3,7 @@ #: name = "opte-api" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [] #: @@ -24,7 +24,7 @@ header "check API_VERSION" ./check-api-version.sh header "check style" -ptime -m cargo +nightly-2024-02-06 fmt -- --check +ptime -m cargo +nightly-2024-03-26 fmt -- --check header "analyze std" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte-ioctl.sh b/.github/buildomat/jobs/opte-ioctl.sh index ca535d0b..c287515c 100755 --- a/.github/buildomat/jobs/opte-ioctl.sh +++ b/.github/buildomat/jobs/opte-ioctl.sh @@ -3,7 +3,7 @@ #: name = "opte-ioctl" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/opte-ioctl header "check style" -ptime -m cargo +nightly-2024-02-06 fmt -- --check +ptime -m cargo +nightly-2024-03-26 fmt -- --check header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte.sh b/.github/buildomat/jobs/opte.sh index 0718b18d..c25ad71e 100755 --- a/.github/buildomat/jobs/opte.sh +++ b/.github/buildomat/jobs/opte.sh @@ -3,7 +3,7 @@ #: name = "opte" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/opte header "check style" -ptime -m cargo +nightly-2024-02-06 fmt -- --check +ptime -m cargo +nightly-2024-03-26 fmt -- --check header "check docs" # @@ -30,13 +30,13 @@ header "check docs" # # Use nightly which is needed for the `kernel` feature. RUSTDOCFLAGS="-D warnings" ptime -m \ - cargo +nightly-2024-02-06 doc --no-default-features --features=api,std,engine,kernel + cargo +nightly-2024-03-26 doc --no-default-features --features=api,std,engine,kernel header "analyze std + api" ptime -m cargo clippy --all-targets header "analyze no_std + engine + kernel" -ptime -m cargo +nightly-2024-02-06 clippy --no-default-features --features engine,kernel +ptime -m cargo +nightly-2024-03-26 clippy --no-default-features --features engine,kernel header "test" ptime -m cargo test diff --git a/.github/buildomat/jobs/opteadm.sh b/.github/buildomat/jobs/opteadm.sh index 317ccacb..c434572c 100755 --- a/.github/buildomat/jobs/opteadm.sh +++ b/.github/buildomat/jobs/opteadm.sh @@ -3,7 +3,7 @@ #: name = "opteadm" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [ #: "=/work/debug/opteadm", #: "=/work/debug/opteadm.debug.sha256", @@ -26,7 +26,7 @@ rustc --version pushd bin/opteadm header "check style" -ptime -m cargo +nightly-2024-02-06 fmt -- --check +ptime -m cargo +nightly-2024-03-26 fmt -- --check header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/oxide-vpc.sh b/.github/buildomat/jobs/oxide-vpc.sh index 93f2b220..1b5715d5 100755 --- a/.github/buildomat/jobs/oxide-vpc.sh +++ b/.github/buildomat/jobs/oxide-vpc.sh @@ -3,7 +3,7 @@ #: name = "oxide-vpc" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/oxide-vpc header "check style" -ptime -m cargo +nightly-2024-02-06 fmt -- --check +ptime -m cargo +nightly-2024-03-26 fmt -- --check header "check docs" # @@ -30,13 +30,13 @@ header "check docs" # # Use nightly which is needed for the `kernel` feature. RUSTDOCFLAGS="-D warnings" ptime -m \ - cargo +nightly-2024-02-06 doc --no-default-features --features=api,std,engine,kernel + cargo +nightly-2024-03-26 doc --no-default-features --features=api,std,engine,kernel header "analyze std + api + usdt" ptime -m cargo clippy --features usdt --all-targets header "analyze no_std + engine + kernel" -ptime -m cargo +nightly-2024-02-06 clippy --no-default-features --features engine,kernel +ptime -m cargo +nightly-2024-03-26 clippy --no-default-features --features engine,kernel header "test" ptime -m cargo test diff --git a/.github/buildomat/jobs/p5p.sh b/.github/buildomat/jobs/p5p.sh index 139fefcc..2b377ab1 100755 --- a/.github/buildomat/jobs/p5p.sh +++ b/.github/buildomat/jobs/p5p.sh @@ -3,7 +3,7 @@ #: name = "opte-p5p" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [ #: "=/out/opte.p5p", #: "=/out/opte.p5p.sha256", diff --git a/.github/buildomat/jobs/xde.sh b/.github/buildomat/jobs/xde.sh index 543d0924..04307968 100755 --- a/.github/buildomat/jobs/xde.sh +++ b/.github/buildomat/jobs/xde.sh @@ -3,7 +3,7 @@ #: name = "opte-xde" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-02-06" +#: rust_toolchain = "nightly-2024-03-26" #: output_rules = [ #: "=/work/debug/xde.dbg", #: "=/work/debug/xde.dbg.sha256", @@ -75,7 +75,7 @@ pushd xde cp xde.conf /work/xde.conf header "check style" -ptime -m cargo +nightly-2024-02-06 fmt -p xde -p xde-link -- --check +ptime -m cargo +nightly-2024-03-26 fmt -p xde -p xde-link -- --check header "analyze" ptime -m cargo clippy -- \ @@ -123,7 +123,7 @@ sha256sum $REL_TGT/xde_link.so > $REL_TGT/xde_link.so.sha256 header "build xde integration tests" pushd xde-tests -cargo +nightly-2024-02-06 fmt -- --check +cargo +nightly-2024-03-26 fmt -- --check cargo clippy --all-targets cargo build --test loopback loopback_test=$( diff --git a/xde/rust-toolchain.toml b/xde/rust-toolchain.toml index 36dfe7ff..ba0c1e06 100644 --- a/xde/rust-toolchain.toml +++ b/xde/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2024-02-06" +channel = "nightly-2024-03-26" target = "x86_64-unknown-illumos" components = [ "clippy", "rustfmt", "rust-src" ] profile = "minimal" diff --git a/xde/x86_64-unknown-unknown.json b/xde/x86_64-unknown-unknown.json index 11c99c06..4cafc73d 100644 --- a/xde/x86_64-unknown-unknown.json +++ b/xde/x86_64-unknown-unknown.json @@ -2,7 +2,7 @@ "arch": "x86_64", "code-model": "kernel", "cpu": "x86-64", - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", "disable-redzone": true, "dynamic-linking": false, "eh-frame-header": false, diff --git a/xde/xde-link/i686-unknown-illumos.json b/xde/xde-link/i686-unknown-illumos.json index e989095f..779b0412 100644 --- a/xde/xde-link/i686-unknown-illumos.json +++ b/xde/xde-link/i686-unknown-illumos.json @@ -1,7 +1,7 @@ { "arch": "x86", "cpu": "pentium4", - "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128", + "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128", "dynamic-linking": true, "eh-frame-header": false, "frame-pointer": "always", From cdba670b9e38d70a8c79421250affaf0a8a6dc0e Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 26 Mar 2024 18:22:33 +0000 Subject: [PATCH 02/16] UB no longer. --- xde/src/xde.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xde/src/xde.rs b/xde/src/xde.rs index e588b4cd..61d0f38a 100644 --- a/xde/src/xde.rs +++ b/xde/src/xde.rs @@ -37,6 +37,8 @@ use core::convert::TryInto; use core::ffi::CStr; use core::num::NonZeroU32; use core::ptr; +use core::ptr::addr_of; +use core::ptr::addr_of_mut; use core::time::Duration; use illumos_sys_hdrs::*; use opte::api::CmdOk; @@ -307,13 +309,13 @@ struct XdeDev { #[no_mangle] unsafe extern "C" fn _init() -> c_int { xde_devs.init(KRwLockType::Driver); - mac::mac_init_ops(&mut xde_devops, XDE_STR); + mac::mac_init_ops(addr_of_mut!(xde_devops), XDE_STR); match mod_install(&xde_linkage) { 0 => 0, err => { warn!("mod_install failed: {}", err); - mac::mac_fini_ops(&mut xde_devops); + mac::mac_fini_ops(addr_of_mut!(xde_devops)); err } } @@ -329,7 +331,7 @@ unsafe extern "C" fn _info(modinfop: *mut modinfo) -> c_int { unsafe extern "C" fn _fini() -> c_int { match mod_remove(&xde_linkage) { 0 => { - mac::mac_fini_ops(&mut xde_devops); + mac::mac_fini_ops(addr_of_mut!(xde_devops)); 0 } err => { @@ -721,7 +723,7 @@ fn create_xde(req: &CreateXdeReq) -> Result { unsafe { mreg.m_dip = xde_dip; - mreg.m_callbacks = &mut xde_mac_callbacks; + mreg.m_callbacks = addr_of_mut!(xde_mac_callbacks); } // TODO Total hack to allow a VNIC atop of xde to have the guest's @@ -1222,7 +1224,7 @@ static mut xde_devops: dev_ops = dev_ops { // Safety: Yes, this is a mutable static. No, there is no race as // it's mutated only during `_init()`. Yes, it needs to be mutable // to allow `dld_init_ops()` to set `cb_str`. - devo_cb_ops: unsafe { &xde_cb_ops }, + devo_cb_ops: unsafe { addr_of!(xde_cb_ops) }, devo_bus_ops: 0 as *const bus_ops, devo_power: nodev_power, devo_quiesce: ddi_quiesce_not_needed, @@ -1231,9 +1233,9 @@ static mut xde_devops: dev_ops = dev_ops { #[no_mangle] static xde_modldrv: modldrv = unsafe { modldrv { - drv_modops: &mod_driverops, + drv_modops: addr_of!(mod_driverops), drv_linkinfo: XDE_STR, - drv_dev_ops: &xde_devops, + drv_dev_ops: addr_of!(xde_devops), } }; From b0da9464694e4952618dfdc8c5bbfeccf8f0374b Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 13:58:41 +0000 Subject: [PATCH 03/16] `c""`-ify most (non-bindgen) CStrs. --- crates/derror-macro/src/lib.rs | 2 +- crates/illumos-sys-hdrs/src/kernel.rs | 5 ++--- lib/opte/src/d_error.rs | 24 ++++++------------------ xde/src/xde.rs | 26 +++++++++++++------------- xde/xde-link/src/lib.rs | 14 +++++++------- 5 files changed, 29 insertions(+), 42 deletions(-) diff --git a/crates/derror-macro/src/lib.rs b/crates/derror-macro/src/lib.rs index ae9f7975..4a68fffe 100644 --- a/crates/derror-macro/src/lib.rs +++ b/crates/derror-macro/src/lib.rs @@ -82,7 +82,7 @@ pub fn derive_derror( let static_name_val = syn::LitByteStr::new(&var_name_bytes, var_name.span()); - // TODO: use c"" from Rust 1.77 onwards, and when syn gets that. + // TODO: use c"" once proc_macro_c_str_literals (https://github.com/rust-lang/rust/issues/119750) stabilised. cstr_decls.push(quote! { static #static_name: &CStr = if let Ok(s) = CStr::from_bytes_with_nul(#static_name_val) { s diff --git a/crates/illumos-sys-hdrs/src/kernel.rs b/crates/illumos-sys-hdrs/src/kernel.rs index 26077661..461a2b5e 100644 --- a/crates/illumos-sys-hdrs/src/kernel.rs +++ b/crates/illumos-sys-hdrs/src/kernel.rs @@ -376,7 +376,7 @@ pub const DDI_IPL_10: c_int = 10; pub const DDI_SUCCESS: c_int = 0; pub const DDI_FAILURE: c_int = -1; -pub const DDI_PSEUDO: *const c_char = b"ddi_pseudo\0".as_ptr() as *const c_char; +pub const DDI_PSEUDO: *const c_char = c"ddi_pseudo".as_ptr(); pub const KM_SLEEP: i32 = 0x0000; pub const KM_NOSLEEP: i32 = 0x0001; @@ -387,8 +387,7 @@ pub const S_IFCHR: c_int = 0x2000; pub const MAC_VERSION_V1: c_int = 0x1; pub const MAC_VERSION: c_int = MAC_VERSION_V1; -pub const MAC_PLUGIN_IDENT_ETHER: *const c_char = - b"mac_ether\0".as_ptr() as *const c_char; +pub const MAC_PLUGIN_IDENT_ETHER: *const c_char = c"mac_ether".as_ptr(); pub type periodic_cb = unsafe extern "C" fn(arg: *mut c_void); diff --git a/lib/opte/src/d_error.rs b/lib/opte/src/d_error.rs index 9987b60e..c8e433da 100644 --- a/lib/opte/src/d_error.rs +++ b/lib/opte/src/d_error.rs @@ -10,23 +10,11 @@ use core::ffi::CStr; pub use derror_macro::DError; -/// Compile-time const cstring from a byte slice. Callers must -/// include a `b'\0'`. -macro_rules! cstr { - ($e:expr) => { - if let Ok(s) = CStr::from_bytes_with_nul($e) { - s - } else { - panic!("Bad cstring constant!") - } - }; -} - /// Compile-time const cstring from a byte slice, including declaration. /// Callers must include a `b'\0'`. macro_rules! static_cstr { ($i:ident, $e:expr) => { - static $i: &CStr = cstr!($e); + static $i: &CStr = $e; }; } @@ -46,7 +34,7 @@ pub trait DError { fn leaf_data(&self, _data: &mut [u64]) {} } -static_cstr!(EMPTY_STRING, b"\0"); +static_cstr!(EMPTY_STRING, c""); /// An error trace designed to be passed to a Dtrace handler, which contains /// the names of all `enum` discriminators encountered when resolving an error @@ -207,10 +195,10 @@ impl<'a, const L: usize> ExactSizeIterator for ErrorBlockIter<'a, L> { mod tests { use super::*; - static_cstr!(A_C, b"A\0"); - static_cstr!(B_C, b"B\0"); - static_cstr!(ND_C, b"NoData\0"); - static_cstr!(D_C, b"Data\0"); + static_cstr!(A_C, c"A"); + static_cstr!(B_C, c"B"); + static_cstr!(ND_C, c"NoData"); + static_cstr!(D_C, c"Data"); #[derive(DError)] enum TestEnum { diff --git a/xde/src/xde.rs b/xde/src/xde.rs index 61d0f38a..7f9dbcc6 100644 --- a/xde/src/xde.rs +++ b/xde/src/xde.rs @@ -102,10 +102,10 @@ const FW_FT_LIMIT: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(8096) }; const FT_LIMIT_ONE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(1) }; /// The name of this driver. -const XDE_STR: *const c_char = b"xde\0".as_ptr() as *const c_char; +const XDE_STR: *const c_char = c"xde".as_ptr(); /// Name of the control device. -const XDE_CTL_STR: *const c_char = b"ctl\0".as_ptr() as *const c_char; +const XDE_CTL_STR: *const c_char = c"ctl".as_ptr(); /// Minor number for the control device. // Set once in `xde_attach`. @@ -139,7 +139,7 @@ extern "C" { gw: uintptr_t, gw_ether_src: uintptr_t, gw_ether_dst: uintptr_t, - msg: uintptr_t, + msg: *const c_char, ); pub fn __dtrace_probe_rx(mp: uintptr_t); pub fn __dtrace_probe_rx__chain__todo(mp: uintptr_t); @@ -203,7 +203,7 @@ fn next_hop_probe( gw: Option<&Ipv6Addr>, gw_eth_src: EtherAddr, gw_eth_dst: EtherAddr, - msg: &[u8], + msg: &CStr, ) { let gw_bytes = gw.unwrap_or(&Ipv6Addr::from([0u8; 16])).bytes(); @@ -213,7 +213,7 @@ fn next_hop_probe( gw_bytes.as_ptr() as uintptr_t, gw_eth_src.to_bytes().as_ptr() as uintptr_t, gw_eth_dst.to_bytes().as_ptr() as uintptr_t, - msg.as_ptr() as uintptr_t, + msg.as_ptr(), ); } } @@ -1809,7 +1809,7 @@ fn next_hop<'a>( None, EtherAddr::zero(), EtherAddr::zero(), - b"no IRE for destination\0", + c"no IRE for destination", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1821,7 +1821,7 @@ fn next_hop<'a>( None, EtherAddr::zero(), EtherAddr::zero(), - b"destination ILL is NULL\0", + c"destination ILL is NULL", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1865,7 +1865,7 @@ fn next_hop<'a>( Some(&gw_ip6), EtherAddr::zero(), EtherAddr::zero(), - b"no IRE for gateway\0", + c"no IRE for gateway", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1884,7 +1884,7 @@ fn next_hop<'a>( Some(&gw_ip6), EtherAddr::zero(), EtherAddr::zero(), - b"gateway ILL phys addr is NULL\0", + c"gateway ILL phys addr is NULL", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1912,7 +1912,7 @@ fn next_hop<'a>( Some(&gw_ip6), src, EtherAddr::zero(), - b"no NCE for gateway\0", + c"no NCE for gateway", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1925,7 +1925,7 @@ fn next_hop<'a>( Some(&gw_ip6), src, EtherAddr::zero(), - b"no NCE common for gateway\0", + c"no NCE common for gateway", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1938,7 +1938,7 @@ fn next_hop<'a>( Some(&gw_ip6), src, EtherAddr::zero(), - b"NCE MAC address if NULL for gateway\0", + c"NCE MAC address if NULL for gateway", ); return (EtherAddr::zero(), EtherAddr::zero(), underlay_port); } @@ -1951,7 +1951,7 @@ fn next_hop<'a>( .expect("mac from pointer"); let dst = EtherAddr::from(dst); - next_hop_probe(ip6_dst, Some(&gw_ip6), src, dst, b"\0"); + next_hop_probe(ip6_dst, Some(&gw_ip6), src, dst, c""); (src, dst, underlay_port) } diff --git a/xde/xde-link/src/lib.rs b/xde/xde-link/src/lib.rs index 32ead0f9..e9dab73b 100644 --- a/xde/xde-link/src/lib.rs +++ b/xde/xde-link/src/lib.rs @@ -22,9 +22,9 @@ pub static _devfsadm_create_reg: _devfsadm_create_reg_t = version: DEVFSADM_V0, count: 1, tblp: &devfsadm_create_t { - device_class: b"pseudo\0".as_ptr().cast(), + device_class: c"pseudo".as_ptr(), node_type: DDI_PSEUDO, - drv_name: b"xde\0".as_ptr().cast(), + drv_name: c"xde".as_ptr(), flags: TYPE_EXACT | DRV_EXACT, interpose_lvl: ILEVEL_0, callback_fcn: create_xde_link, @@ -38,8 +38,8 @@ pub static _devfsadm_remove_reg: _devfsadm_remove_reg_t = version: DEVFSADM_V0, count: 1, tblp: &devfsadm_remove_t { - device_class: b"pseudo\0".as_ptr().cast(), - dev_dirs_re: b"^xde$\0".as_ptr().cast(), + device_class: c"pseudo".as_ptr(), + dev_dirs_re: c"^xde$".as_ptr(), flags: RM_HOT | RM_PRE | RM_ALWAYS, interpose_lvl: ILEVEL_0, callback_fcn: devfsadm_rm_all, @@ -56,8 +56,8 @@ unsafe extern "C" fn create_xde_link( extern "C" { fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int; } - if strcmp(di_minor_name(minor), b"ctl\0".as_ptr().cast()) == 0 { - devfsadm_mklink(b"xde\0".as_ptr().cast(), node, minor, 0); + if strcmp(di_minor_name(minor), c"ctl".as_ptr()) == 0 { + devfsadm_mklink(c"xde".as_ptr(), node, minor, 0); } 0 } @@ -88,7 +88,7 @@ pub const RM_PRE: c_int = 0x02; pub const RM_ALWAYS: c_int = 0x08; /// Minor node type for pseudo devices -pub const DDI_PSEUDO: *const c_char = b"ddi_pseudo\0".as_ptr().cast(); +pub const DDI_PSEUDO: *const c_char = c"ddi_pseudo".as_ptr(); /// Opaque minor node handle type di_minor = core::ffi::c_void; From b0c7496cd46e733f1f733ba3042c08e676c4f729 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 14:05:03 +0000 Subject: [PATCH 04/16] Fix outbound TCP stat counting. Since the recent refactor, count + bytes have all been ending up in `segs_in`/`bytes_in`, which can make for some confusing reading at the best of times. --- lib/opte/src/engine/port.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/opte/src/engine/port.rs b/lib/opte/src/engine/port.rs index 614a7fcf..1bbff566 100644 --- a/lib/opte/src/engine/port.rs +++ b/lib/opte/src/engine/port.rs @@ -1595,8 +1595,16 @@ impl Port { entry.hit(); let tfes = entry.state_mut(); - tfes.segs_in += 1; - tfes.bytes_in += pkt_len; + match *dir { + TcpDirection::In { .. } => { + tfes.segs_in += 1; + tfes.bytes_in += pkt_len; + } + TcpDirection::Out { .. } => { + tfes.segs_out += 1; + tfes.bytes_out += pkt_len; + } + } let next_state = tfes.tcp_state.process( self.name_cstr.as_c_str(), From 2ad26de66f6422b5513f03093a2aa3222de1a774 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 14:13:59 +0000 Subject: [PATCH 05/16] Solve 'duplicate `use`' warnings. --- crates/illumos-sys-hdrs/src/kernel.rs | 1 - crates/opte-api/src/dns.rs | 1 - crates/opte-api/src/ip.rs | 1 - crates/opte-api/src/mac.rs | 1 - lib/opte/src/engine/arp.rs | 1 - lib/opte/src/engine/dhcpv6/mod.rs | 1 - lib/oxide-vpc/src/engine/gateway/arp.rs | 1 - lib/oxide-vpc/src/engine/gateway/dhcp.rs | 1 - lib/oxide-vpc/src/engine/gateway/icmp.rs | 1 - lib/oxide-vpc/src/engine/gateway/icmpv6.rs | 1 - lib/oxide-vpc/src/engine/nat.rs | 1 - xde/src/xde.rs | 1 - 12 files changed, 12 deletions(-) diff --git a/crates/illumos-sys-hdrs/src/kernel.rs b/crates/illumos-sys-hdrs/src/kernel.rs index 461a2b5e..9111a080 100644 --- a/crates/illumos-sys-hdrs/src/kernel.rs +++ b/crates/illumos-sys-hdrs/src/kernel.rs @@ -52,7 +52,6 @@ impl ddi_reset_cmd_t { // TODO Technically this is not a "raw" interface. This should live // somewhere else. -use core::ptr; impl kmutex_t { pub fn new(mtype: kmutex_type_t) -> Self { let mut kmutex = kmutex_t { _opaque: 0 }; diff --git a/crates/opte-api/src/dns.rs b/crates/opte-api/src/dns.rs index f99a1f1e..823e44fd 100644 --- a/crates/opte-api/src/dns.rs +++ b/crates/opte-api/src/dns.rs @@ -9,7 +9,6 @@ use alloc::str; use alloc::string::String; use alloc::vec::Vec; -use core::convert::TryFrom; use core::fmt; use core::str::FromStr; use serde::Deserialize; diff --git a/crates/opte-api/src/ip.rs b/crates/opte-api/src/ip.rs index 153f4733..1ea58648 100644 --- a/crates/opte-api/src/ip.rs +++ b/crates/opte-api/src/ip.rs @@ -9,7 +9,6 @@ use crate::DomainName; use alloc::string::String; use alloc::string::ToString; use alloc::vec::Vec; -use core::convert::AsRef; use core::fmt; use core::fmt::Debug; use core::fmt::Display; diff --git a/crates/opte-api/src/mac.rs b/crates/opte-api/src/mac.rs index 1023cf97..8a133f4b 100644 --- a/crates/opte-api/src/mac.rs +++ b/crates/opte-api/src/mac.rs @@ -7,7 +7,6 @@ use alloc::str::FromStr; use alloc::string::String; use alloc::vec::Vec; -use core::convert::AsRef; use core::fmt; use core::fmt::Debug; use core::fmt::Display; diff --git a/lib/opte/src/engine/arp.rs b/lib/opte/src/engine/arp.rs index d927edc5..e9ba7956 100644 --- a/lib/opte/src/engine/arp.rs +++ b/lib/opte/src/engine/arp.rs @@ -15,7 +15,6 @@ use super::packet::Packet; use super::packet::PacketReadMut; use super::packet::ReadErr; use crate::d_error::DError; -use core::convert::TryFrom; use core::fmt; use core::fmt::Display; use opte_api::Ipv4Addr; diff --git a/lib/opte/src/engine/dhcpv6/mod.rs b/lib/opte/src/engine/dhcpv6/mod.rs index 20320013..06e9864c 100644 --- a/lib/opte/src/engine/dhcpv6/mod.rs +++ b/lib/opte/src/engine/dhcpv6/mod.rs @@ -76,7 +76,6 @@ pub use protocol::MessageType; use alloc::borrow::Cow; use alloc::vec::Vec; -use core::convert::AsRef; use core::fmt; use core::fmt::Display; use core::ops::Deref; diff --git a/lib/oxide-vpc/src/engine/gateway/arp.rs b/lib/oxide-vpc/src/engine/gateway/arp.rs index cda14af5..d530ce16 100644 --- a/lib/oxide-vpc/src/engine/gateway/arp.rs +++ b/lib/oxide-vpc/src/engine/gateway/arp.rs @@ -7,7 +7,6 @@ //! The ARP implementation of the Virtual Gateway. use crate::cfg::VpcCfg; -use core::result::Result; use opte::api::Direction; use opte::api::MacAddr; use opte::api::OpteError; diff --git a/lib/oxide-vpc/src/engine/gateway/dhcp.rs b/lib/oxide-vpc/src/engine/gateway/dhcp.rs index 84f12231..ee616441 100644 --- a/lib/oxide-vpc/src/engine/gateway/dhcp.rs +++ b/lib/oxide-vpc/src/engine/gateway/dhcp.rs @@ -9,7 +9,6 @@ use crate::cfg::Ipv4Cfg; use crate::cfg::VpcCfg; use alloc::sync::Arc; -use core::result::Result; use opte::api::DhcpCfg; use opte::api::DhcpReplyType; use opte::api::Direction; diff --git a/lib/oxide-vpc/src/engine/gateway/icmp.rs b/lib/oxide-vpc/src/engine/gateway/icmp.rs index f572dd37..c4c48550 100644 --- a/lib/oxide-vpc/src/engine/gateway/icmp.rs +++ b/lib/oxide-vpc/src/engine/gateway/icmp.rs @@ -9,7 +9,6 @@ use crate::cfg::Ipv4Cfg; use crate::cfg::VpcCfg; use alloc::sync::Arc; -use core::result::Result; use opte::api::Direction; use opte::api::OpteError; use opte::engine::icmp::v4::IcmpEchoReply; diff --git a/lib/oxide-vpc/src/engine/gateway/icmpv6.rs b/lib/oxide-vpc/src/engine/gateway/icmpv6.rs index a59dc4df..2821325b 100644 --- a/lib/oxide-vpc/src/engine/gateway/icmpv6.rs +++ b/lib/oxide-vpc/src/engine/gateway/icmpv6.rs @@ -9,7 +9,6 @@ use crate::cfg::Ipv6Cfg; use crate::cfg::VpcCfg; use alloc::sync::Arc; -use core::result::Result; use opte::api::Direction; use opte::api::Ipv6Addr; use opte::api::OpteError; diff --git a/lib/oxide-vpc/src/engine/nat.rs b/lib/oxide-vpc/src/engine/nat.rs index 48df632f..3deb85ec 100644 --- a/lib/oxide-vpc/src/engine/nat.rs +++ b/lib/oxide-vpc/src/engine/nat.rs @@ -17,7 +17,6 @@ use alloc::string::ToString; use alloc::sync::Arc; use alloc::vec::Vec; use core::num::NonZeroU32; -use core::result::Result; use opte::api::IpAddr; use opte::api::Ipv4Addr; use opte::api::Ipv6Addr; diff --git a/xde/src/xde.rs b/xde/src/xde.rs index 7f9dbcc6..959d4194 100644 --- a/xde/src/xde.rs +++ b/xde/src/xde.rs @@ -33,7 +33,6 @@ use alloc::string::String; use alloc::string::ToString; use alloc::sync::Arc; use alloc::vec::Vec; -use core::convert::TryInto; use core::ffi::CStr; use core::num::NonZeroU32; use core::ptr; From 29a0c47268d5a4af132356a7ba0e6e41e0c51b35 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 17:21:43 +0000 Subject: [PATCH 06/16] Clippy appeasement: XDE. Unfortunately the Arc around non Send+Sync will need some fairly intrusive bound insertion, by the looks of things. When we do that it should be its own PR. --- crates/derror-macro/src/lib.rs | 2 +- lib/opte/src/d_error.rs | 26 ++++++++++++++++++++------ lib/opte/src/engine/ether.rs | 7 ++----- xde/src/lib.rs | 1 - 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/derror-macro/src/lib.rs b/crates/derror-macro/src/lib.rs index 4a68fffe..4b6a8ebf 100644 --- a/crates/derror-macro/src/lib.rs +++ b/crates/derror-macro/src/lib.rs @@ -59,7 +59,7 @@ pub fn derive_derror( let parsed_args = match Args::from_derive_input(&derive_input) { Ok(o) => o, - Err(e) => return TokenStream::from(e.write_errors()).into(), + Err(e) => return e.write_errors().into(), }; let DeriveInput { ident, data, .. } = derive_input; diff --git a/lib/opte/src/d_error.rs b/lib/opte/src/d_error.rs index c8e433da..4d1e8ce8 100644 --- a/lib/opte/src/d_error.rs +++ b/lib/opte/src/d_error.rs @@ -54,6 +54,16 @@ pub struct ErrorBlock { entries: [*const i8; L], } +/// Signals that an [`ErrorBlock`] could not contain a new string entry. +#[derive(Clone, Copy, Debug)] +pub struct ErrorBlockFull; + +impl Default for ErrorBlock { + fn default() -> Self { + Self::new() + } +} + impl ErrorBlock { /// Create storage to hold at most `L` static string entries. pub fn new() -> Self { @@ -82,7 +92,7 @@ impl ErrorBlock { } /// Push all layers (and data) of an error into a block. - pub fn append(&mut self, err: &dyn DError) -> Result<(), ()> { + pub fn append(&mut self, err: &dyn DError) -> Result<(), ErrorBlockFull> { let mut top: Option<&dyn DError> = Some(err); while let Some(el) = top { self.append_name(el)?; @@ -96,10 +106,13 @@ impl ErrorBlock { } /// Appends the top layer name of a given error. - pub fn append_name(&mut self, err: &dyn DError) -> Result<(), ()> { + pub fn append_name( + &mut self, + err: &dyn DError, + ) -> Result<(), ErrorBlockFull> { if self.len >= L { self.more = true; - return Err(()); + return Err(ErrorBlockFull); } self.entries[self.len] = err.discriminant().as_ptr(); @@ -110,14 +123,15 @@ impl ErrorBlock { /// Appends the top layer name of a given error. /// + /// # Safety /// Callers must ensure that pointee outlives this ErrorBlock. pub unsafe fn append_name_raw<'a, 'b: 'a>( &'a mut self, err: &'b CStr, - ) -> Result<(), ()> { + ) -> Result<(), ErrorBlockFull> { if self.len >= L { self.more = true; - return Err(()); + return Err(ErrorBlockFull); } self.entries[self.len] = err.as_ptr(); @@ -137,7 +151,7 @@ impl ErrorBlock { } /// Provides access to all stored [`CStr`]s. - pub fn entries<'a>(&'a self) -> ErrorBlockIter<'a, L> { + pub fn entries(&self) -> ErrorBlockIter<'_, L> { ErrorBlockIter { pos: 0, inner: self } } diff --git a/lib/opte/src/engine/ether.rs b/lib/opte/src/engine/ether.rs index 613d0963..05927fec 100644 --- a/lib/opte/src/engine/ether.rs +++ b/lib/opte/src/engine/ether.rs @@ -303,11 +303,8 @@ pub enum EtherHdrError { impl EtherHdrError { fn derror_data(&self, data: &mut [u64]) { - match self { - Self::UnsupportedEtherType { ether_type } => { - data[0] = *ether_type as u64; - } - _ => {} + if let Self::UnsupportedEtherType { ether_type } = self { + data[0] = *ether_type as u64; } } } diff --git a/xde/src/lib.rs b/xde/src/lib.rs index e4b4f073..252d16b8 100644 --- a/xde/src/lib.rs +++ b/xde/src/lib.rs @@ -8,7 +8,6 @@ #![feature(extern_types)] #![feature(panic_info_message)] #![no_std] -#![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] // XXX We do not use double in the kernel. We should not allow // "improper C types". This hack is here is because of the ip.rs code From d83e4dac0e1b422859e7371b0f157f132c149f5d Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 17:43:11 +0000 Subject: [PATCH 07/16] Clippy appeasement: Opteadm --- bin/opteadm/src/bin/opteadm.rs | 9 +++++---- crates/opte-api/src/lib.rs | 2 +- lib/opte/src/engine/print.rs | 14 +++++++------- lib/oxide-vpc/src/engine/print.rs | 3 +-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/opteadm/src/bin/opteadm.rs b/bin/opteadm/src/bin/opteadm.rs index 8cc45206..b6baabd7 100644 --- a/bin/opteadm/src/bin/opteadm.rs +++ b/bin/opteadm/src/bin/opteadm.rs @@ -424,6 +424,7 @@ fn opte_pkg_version() -> String { format!("{MAJOR_VERSION}.{API_VERSION}.{COMMIT_COUNT}") } +#[allow(clippy::write_literal)] fn print_port_header(t: &mut impl Write) -> std::io::Result<()> { writeln!( t, @@ -453,7 +454,7 @@ fn print_port(t: &mut impl Write, pi: PortInfo) -> std::io::Result<()> { t, "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}", pi.name, - pi.mac_addr.to_string(), + pi.mac_addr, pi.ip4_addr.map(|x| x.to_string()).unwrap_or_else(|| none.clone()), pi.ephemeral_ip4_addr .map(|x| x.to_string()) @@ -483,12 +484,12 @@ fn print_port(t: &mut impl Write, pi: PortInfo) -> std::io::Result<()> { .as_ref() .and_then(|vec| vec.get(i)) .map(|x| x.to_string()) - .unwrap_or_else(String::new), + .unwrap_or_default(), pi.floating_ip6_addrs .as_ref() .and_then(|vec| vec.get(i)) .map(|x| x.to_string()) - .unwrap_or_else(String::new), + .unwrap_or_default(), )?; } @@ -522,7 +523,7 @@ fn main() -> anyhow::Result<()> { Command::DumpLayer { port, name } => { let resp = &hdl.get_layer_by_name(&port, &name)?; print!("Port {port} - "); - print_layer(&resp)?; + print_layer(resp)?; } Command::ClearUft { port } => { diff --git a/crates/opte-api/src/lib.rs b/crates/opte-api/src/lib.rs index c82d1cb2..60b1c1d7 100644 --- a/crates/opte-api/src/lib.rs +++ b/crates/opte-api/src/lib.rs @@ -47,7 +47,7 @@ pub use ulp::*; /// /// We rely on CI and the check-api-version.sh script to verify that /// this number is incremented anytime the oxide-api code changes. -pub const API_VERSION: u64 = 28; +pub const API_VERSION: u64 = 29; /// Major version of the OPTE package. pub const MAJOR_VERSION: u64 = 0; diff --git a/lib/opte/src/engine/print.rs b/lib/opte/src/engine/print.rs index 3878e08f..221815df 100644 --- a/lib/opte/src/engine/print.rs +++ b/lib/opte/src/engine/print.rs @@ -206,10 +206,10 @@ pub fn print_lft_flow( writeln!( t, "{}\t{}\t{}\t{}\t{}\t{}\t{}", - flow_id.proto.to_string(), - flow_id.src_ip.to_string(), + flow_id.proto, + flow_id.src_ip, flow_id.src_port, - flow_id.dst_ip.to_string(), + flow_id.dst_ip, flow_id.dst_port, flow_entry.hits, flow_entry.summary, @@ -233,10 +233,10 @@ pub fn print_uft_flow( writeln!( t, "{}\t{}\t{}\t{}\t{}\t{}\t{}", - flow_id.proto.to_string(), - flow_id.src_ip.to_string(), + flow_id.proto, + flow_id.src_ip, flow_id.src_port, - flow_id.dst_ip.to_string(), + flow_id.dst_ip, flow_id.dst_port, flow_entry.hits, flow_entry.summary, @@ -271,7 +271,7 @@ fn print_tcp_flow( writeln!( t, "{id}\t{}\t{}\t{}\t{}\t{}\t{}", - entry.tcp_state.tcp_state.to_string(), + entry.tcp_state.tcp_state, entry.hits, entry.segs_in, entry.segs_out, diff --git a/lib/oxide-vpc/src/engine/print.rs b/lib/oxide-vpc/src/engine/print.rs index fa72119a..9313367e 100644 --- a/lib/oxide-vpc/src/engine/print.rs +++ b/lib/oxide-vpc/src/engine/print.rs @@ -14,7 +14,6 @@ use crate::api::Ipv4Addr; use crate::api::Ipv6Addr; use crate::engine::overlay::DumpVirt2BoundaryResp; use crate::engine::overlay::DumpVirt2PhysResp; -use alloc::string::ToString; use opte::api::IpCidr; use opte::engine::geneve::Vni; use opte::engine::print::*; @@ -72,7 +71,7 @@ fn print_v2b_entry( boundary: Ipv6Addr, vni: Vni, ) -> std::io::Result<()> { - writeln!(t, "{}\t{}\t{vni}", prefix.to_string(), boundary.to_string()) + writeln!(t, "{prefix}\t{boundary}\t{vni}") } /// Print a [`DumpVirt2BoundaryResp`]. From c94f6a1318bbfa98539ad3347422d5483effb9e0 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 18:05:34 +0000 Subject: [PATCH 08/16] Seemingly clippy-clean. --- lib/opte/src/d_error.rs | 2 +- lib/opte/src/engine/ip6.rs | 2 +- lib/oxide-vpc/tests/fuzz_regression.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/opte/src/d_error.rs b/lib/opte/src/d_error.rs index 4d1e8ce8..597427a2 100644 --- a/lib/opte/src/d_error.rs +++ b/lib/opte/src/d_error.rs @@ -270,6 +270,6 @@ mod tests { assert_eq!(block_iter.next(), Some(B_C)); assert_eq!(block_iter.len(), 0); assert_eq!(block_iter.next(), None); - assert_eq!(block.more, true); + assert!(block.more); } } diff --git a/lib/opte/src/engine/ip6.rs b/lib/opte/src/engine/ip6.rs index e987261f..2c0d4ad1 100644 --- a/lib/opte/src/engine/ip6.rs +++ b/lib/opte/src/engine/ip6.rs @@ -889,7 +889,7 @@ pub(crate) mod test { 0xc8, 0x34, 0xdd, 0x6b, 0xfa, 0x21, ]; - let mut pkt = Packet::copy(&buf); + let mut pkt = Packet::copy(buf); let mut reader = pkt.get_rdr_mut(); assert!(matches!( Ipv6Hdr::parse(&mut reader), diff --git a/lib/oxide-vpc/tests/fuzz_regression.rs b/lib/oxide-vpc/tests/fuzz_regression.rs index 4cbff79b..0e159429 100644 --- a/lib/oxide-vpc/tests/fuzz_regression.rs +++ b/lib/oxide-vpc/tests/fuzz_regression.rs @@ -40,7 +40,7 @@ fn run_tests( // Find all test descriptions in tests/resources/$root_dir. let mut tests: HashMap = HashMap::new(); let my_test_dir = base_resource_path.join(root_dir); - for entry in std::fs::read_dir(&my_test_dir) + for entry in std::fs::read_dir(my_test_dir) .unwrap_or_else(|e| panic!("failed to find directory {root_dir}: {e}")) { let entry = entry.unwrap_or_else(|e| { From 099aad8501ed57e74999ab05bca8bccbb24ad656 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 28 Mar 2024 18:13:56 +0000 Subject: [PATCH 09/16] Prevent DError proc_macro being pulled into omicron. --- lib/opte/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/opte/Cargo.toml b/lib/opte/Cargo.toml index 903572a3..0eb965b3 100644 --- a/lib/opte/Cargo.toml +++ b/lib/opte/Cargo.toml @@ -9,7 +9,7 @@ repository.workspace = true [features] default = ["api", "std"] api = [] -engine = ["api", "dep:crc32fast", "dep:heapless", "dep:itertools", "dep:zerocopy"] +engine = ["api", "dep:crc32fast", "dep:derror-macro", "dep:heapless", "dep:itertools", "dep:zerocopy"] kernel = ["illumos-sys-hdrs/kernel"] # This feature indicates that OPTE is being built with std. This is # mostly useful to consumers of the API, providing convenient methods @@ -22,7 +22,7 @@ test-help = [] usdt = ["std", "dep:usdt"] [dependencies] -derror-macro.workspace = true +derror-macro = { workspace = true, optional = true } illumos-sys-hdrs.workspace = true kstat-macro.workspace = true opte-api.workspace = true From 0eb0feffb821c03e265dda8dfacd5bc890014fc3 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 25 Apr 2024 13:55:11 +0100 Subject: [PATCH 10/16] Refresh nightly toolchain, self-review. --- .github/buildomat/jobs/opte-api.sh | 4 ++-- .github/buildomat/jobs/opte-ioctl.sh | 4 ++-- .github/buildomat/jobs/opte.sh | 8 ++++---- .github/buildomat/jobs/opteadm.sh | 4 ++-- .github/buildomat/jobs/oxide-vpc.sh | 8 ++++---- .github/buildomat/jobs/p5p.sh | 2 +- .github/buildomat/jobs/xde.sh | 6 +++--- bench/Cargo.toml | 2 +- lib/opte/src/d_error.rs | 5 +++-- xde/rust-toolchain.toml | 2 +- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/buildomat/jobs/opte-api.sh b/.github/buildomat/jobs/opte-api.sh index a4ededaf..69b3a2e6 100755 --- a/.github/buildomat/jobs/opte-api.sh +++ b/.github/buildomat/jobs/opte-api.sh @@ -3,7 +3,7 @@ #: name = "opte-api" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [] #: @@ -24,7 +24,7 @@ header "check API_VERSION" ./check-api-version.sh header "check style" -ptime -m cargo +nightly-2024-03-26 fmt -- --check +ptime -m cargo +nightly-2024-04-25 fmt -- --check header "analyze std" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte-ioctl.sh b/.github/buildomat/jobs/opte-ioctl.sh index c287515c..ee43732e 100755 --- a/.github/buildomat/jobs/opte-ioctl.sh +++ b/.github/buildomat/jobs/opte-ioctl.sh @@ -3,7 +3,7 @@ #: name = "opte-ioctl" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/opte-ioctl header "check style" -ptime -m cargo +nightly-2024-03-26 fmt -- --check +ptime -m cargo +nightly-2024-04-25 fmt -- --check header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte.sh b/.github/buildomat/jobs/opte.sh index c25ad71e..651c6b4c 100755 --- a/.github/buildomat/jobs/opte.sh +++ b/.github/buildomat/jobs/opte.sh @@ -3,7 +3,7 @@ #: name = "opte" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/opte header "check style" -ptime -m cargo +nightly-2024-03-26 fmt -- --check +ptime -m cargo +nightly-2024-04-25 fmt -- --check header "check docs" # @@ -30,13 +30,13 @@ header "check docs" # # Use nightly which is needed for the `kernel` feature. RUSTDOCFLAGS="-D warnings" ptime -m \ - cargo +nightly-2024-03-26 doc --no-default-features --features=api,std,engine,kernel + cargo +nightly-2024-04-25 doc --no-default-features --features=api,std,engine,kernel header "analyze std + api" ptime -m cargo clippy --all-targets header "analyze no_std + engine + kernel" -ptime -m cargo +nightly-2024-03-26 clippy --no-default-features --features engine,kernel +ptime -m cargo +nightly-2024-04-25 clippy --no-default-features --features engine,kernel header "test" ptime -m cargo test diff --git a/.github/buildomat/jobs/opteadm.sh b/.github/buildomat/jobs/opteadm.sh index c434572c..c20b4694 100755 --- a/.github/buildomat/jobs/opteadm.sh +++ b/.github/buildomat/jobs/opteadm.sh @@ -3,7 +3,7 @@ #: name = "opteadm" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [ #: "=/work/debug/opteadm", #: "=/work/debug/opteadm.debug.sha256", @@ -26,7 +26,7 @@ rustc --version pushd bin/opteadm header "check style" -ptime -m cargo +nightly-2024-03-26 fmt -- --check +ptime -m cargo +nightly-2024-04-25 fmt -- --check header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/oxide-vpc.sh b/.github/buildomat/jobs/oxide-vpc.sh index 1b5715d5..7c591377 100755 --- a/.github/buildomat/jobs/oxide-vpc.sh +++ b/.github/buildomat/jobs/oxide-vpc.sh @@ -3,7 +3,7 @@ #: name = "oxide-vpc" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/oxide-vpc header "check style" -ptime -m cargo +nightly-2024-03-26 fmt -- --check +ptime -m cargo +nightly-2024-04-25 fmt -- --check header "check docs" # @@ -30,13 +30,13 @@ header "check docs" # # Use nightly which is needed for the `kernel` feature. RUSTDOCFLAGS="-D warnings" ptime -m \ - cargo +nightly-2024-03-26 doc --no-default-features --features=api,std,engine,kernel + cargo +nightly-2024-04-25 doc --no-default-features --features=api,std,engine,kernel header "analyze std + api + usdt" ptime -m cargo clippy --features usdt --all-targets header "analyze no_std + engine + kernel" -ptime -m cargo +nightly-2024-03-26 clippy --no-default-features --features engine,kernel +ptime -m cargo +nightly-2024-04-25 clippy --no-default-features --features engine,kernel header "test" ptime -m cargo test diff --git a/.github/buildomat/jobs/p5p.sh b/.github/buildomat/jobs/p5p.sh index 2b377ab1..2a0aa196 100755 --- a/.github/buildomat/jobs/p5p.sh +++ b/.github/buildomat/jobs/p5p.sh @@ -3,7 +3,7 @@ #: name = "opte-p5p" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [ #: "=/out/opte.p5p", #: "=/out/opte.p5p.sha256", diff --git a/.github/buildomat/jobs/xde.sh b/.github/buildomat/jobs/xde.sh index 04307968..df96c912 100755 --- a/.github/buildomat/jobs/xde.sh +++ b/.github/buildomat/jobs/xde.sh @@ -3,7 +3,7 @@ #: name = "opte-xde" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-03-26" +#: rust_toolchain = "nightly-2024-04-25" #: output_rules = [ #: "=/work/debug/xde.dbg", #: "=/work/debug/xde.dbg.sha256", @@ -75,7 +75,7 @@ pushd xde cp xde.conf /work/xde.conf header "check style" -ptime -m cargo +nightly-2024-03-26 fmt -p xde -p xde-link -- --check +ptime -m cargo +nightly-2024-04-25 fmt -p xde -p xde-link -- --check header "analyze" ptime -m cargo clippy -- \ @@ -123,7 +123,7 @@ sha256sum $REL_TGT/xde_link.so > $REL_TGT/xde_link.so.sha256 header "build xde integration tests" pushd xde-tests -cargo +nightly-2024-03-26 fmt -- --check +cargo +nightly-2024-04-25 fmt -- --check cargo clippy --all-targets cargo build --test loopback loopback_test=$( diff --git a/bench/Cargo.toml b/bench/Cargo.toml index 87a01dfa..2124141e 100644 --- a/bench/Cargo.toml +++ b/bench/Cargo.toml @@ -21,7 +21,7 @@ rand.workspace = true opte.workspace = true opte-test-utils.workspace = true oxide-vpc.workspace = true -serde = { default_features = true, workspace = true } +serde = { default-features = true, workspace = true } serde_json.workspace = true [dev-dependencies] diff --git a/lib/opte/src/d_error.rs b/lib/opte/src/d_error.rs index 597427a2..6583c922 100644 --- a/lib/opte/src/d_error.rs +++ b/lib/opte/src/d_error.rs @@ -10,8 +10,9 @@ use core::ffi::CStr; pub use derror_macro::DError; -/// Compile-time const cstring from a byte slice, including declaration. -/// Callers must include a `b'\0'`. +/// Convenience macro for a compile-time static CStr declaration. +/// Callers must pass in a `c"..."` or other valid const CStr +/// initialiser. macro_rules! static_cstr { ($i:ident, $e:expr) => { static $i: &CStr = $e; diff --git a/xde/rust-toolchain.toml b/xde/rust-toolchain.toml index ba0c1e06..5bcb1544 100644 --- a/xde/rust-toolchain.toml +++ b/xde/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2024-03-26" +channel = "nightly-2024-04-25" target = "x86_64-unknown-illumos" components = [ "clippy", "rustfmt", "rust-src" ] profile = "minimal" From afe37d67e2e87f6dc6ab199aaf98ab45e0a4a86a Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Fri, 26 Apr 2024 11:16:13 +0100 Subject: [PATCH 11/16] Review feedback: do away with static_cstr macro --- lib/opte/src/d_error.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/opte/src/d_error.rs b/lib/opte/src/d_error.rs index 6583c922..b61d5877 100644 --- a/lib/opte/src/d_error.rs +++ b/lib/opte/src/d_error.rs @@ -10,15 +10,6 @@ use core::ffi::CStr; pub use derror_macro::DError; -/// Convenience macro for a compile-time static CStr declaration. -/// Callers must pass in a `c"..."` or other valid const CStr -/// initialiser. -macro_rules! static_cstr { - ($i:ident, $e:expr) => { - static $i: &CStr = $e; - }; -} - // XXX: I think we want some way of doing the whole thing in one big chunk // to prevent e.g. 4 dyn dispatches in a row. @@ -35,7 +26,7 @@ pub trait DError { fn leaf_data(&self, _data: &mut [u64]) {} } -static_cstr!(EMPTY_STRING, c""); +static EMPTY_STRING: &CStr = c""; /// An error trace designed to be passed to a Dtrace handler, which contains /// the names of all `enum` discriminators encountered when resolving an error @@ -210,10 +201,10 @@ impl<'a, const L: usize> ExactSizeIterator for ErrorBlockIter<'a, L> { mod tests { use super::*; - static_cstr!(A_C, c"A"); - static_cstr!(B_C, c"B"); - static_cstr!(ND_C, c"NoData"); - static_cstr!(D_C, c"Data"); + static A_C: &CStr = c"A"; + static B_C: &CStr = c"B"; + static ND_C: &CStr = c"NoData"; + static D_C: &CStr = c"Data"; #[derive(DError)] enum TestEnum { From 2712f34845476589d9bcab6bfc870ebfaf7264c6 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Fri, 26 Apr 2024 11:22:08 +0100 Subject: [PATCH 12/16] Re-bump API version. --- crates/opte-api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/opte-api/src/lib.rs b/crates/opte-api/src/lib.rs index 60b1c1d7..45cc4c80 100644 --- a/crates/opte-api/src/lib.rs +++ b/crates/opte-api/src/lib.rs @@ -47,7 +47,7 @@ pub use ulp::*; /// /// We rely on CI and the check-api-version.sh script to verify that /// this number is incremented anytime the oxide-api code changes. -pub const API_VERSION: u64 = 29; +pub const API_VERSION: u64 = 30; /// Major version of the OPTE package. pub const MAJOR_VERSION: u64 = 0; From c57487ea0ad44dc461b25868d62a2e36dbe4be71 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Mon, 13 May 2024 12:29:08 +0100 Subject: [PATCH 13/16] Refresh nightly toolchain. This has also caught a bad feature flag in one spot (debug_assert vs. debug_assertions). --- .github/buildomat/jobs/opte-api.sh | 4 ++-- .github/buildomat/jobs/opte-ioctl.sh | 4 ++-- .github/buildomat/jobs/opte.sh | 8 ++++---- .github/buildomat/jobs/opteadm.sh | 4 ++-- .github/buildomat/jobs/oxide-vpc.sh | 8 ++++---- .github/buildomat/jobs/p5p.sh | 2 +- .github/buildomat/jobs/xde.sh | 6 +++--- lib/opte/src/engine/rule.rs | 4 ++-- xde/rust-toolchain.toml | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/buildomat/jobs/opte-api.sh b/.github/buildomat/jobs/opte-api.sh index 69b3a2e6..eb4d0a7b 100755 --- a/.github/buildomat/jobs/opte-api.sh +++ b/.github/buildomat/jobs/opte-api.sh @@ -3,7 +3,7 @@ #: name = "opte-api" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [] #: @@ -24,7 +24,7 @@ header "check API_VERSION" ./check-api-version.sh header "check style" -ptime -m cargo +nightly-2024-04-25 fmt -- --check +ptime -m cargo +nightly-2024-05-12 fmt -- --check header "analyze std" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte-ioctl.sh b/.github/buildomat/jobs/opte-ioctl.sh index ee43732e..fdc61df0 100755 --- a/.github/buildomat/jobs/opte-ioctl.sh +++ b/.github/buildomat/jobs/opte-ioctl.sh @@ -3,7 +3,7 @@ #: name = "opte-ioctl" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/opte-ioctl header "check style" -ptime -m cargo +nightly-2024-04-25 fmt -- --check +ptime -m cargo +nightly-2024-05-12 fmt -- --check header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/opte.sh b/.github/buildomat/jobs/opte.sh index 651c6b4c..a04d14a5 100755 --- a/.github/buildomat/jobs/opte.sh +++ b/.github/buildomat/jobs/opte.sh @@ -3,7 +3,7 @@ #: name = "opte" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/opte header "check style" -ptime -m cargo +nightly-2024-04-25 fmt -- --check +ptime -m cargo +nightly-2024-05-12 fmt -- --check header "check docs" # @@ -30,13 +30,13 @@ header "check docs" # # Use nightly which is needed for the `kernel` feature. RUSTDOCFLAGS="-D warnings" ptime -m \ - cargo +nightly-2024-04-25 doc --no-default-features --features=api,std,engine,kernel + cargo +nightly-2024-05-12 doc --no-default-features --features=api,std,engine,kernel header "analyze std + api" ptime -m cargo clippy --all-targets header "analyze no_std + engine + kernel" -ptime -m cargo +nightly-2024-04-25 clippy --no-default-features --features engine,kernel +ptime -m cargo +nightly-2024-05-12 clippy --no-default-features --features engine,kernel header "test" ptime -m cargo test diff --git a/.github/buildomat/jobs/opteadm.sh b/.github/buildomat/jobs/opteadm.sh index c20b4694..56133dde 100755 --- a/.github/buildomat/jobs/opteadm.sh +++ b/.github/buildomat/jobs/opteadm.sh @@ -3,7 +3,7 @@ #: name = "opteadm" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [ #: "=/work/debug/opteadm", #: "=/work/debug/opteadm.debug.sha256", @@ -26,7 +26,7 @@ rustc --version pushd bin/opteadm header "check style" -ptime -m cargo +nightly-2024-04-25 fmt -- --check +ptime -m cargo +nightly-2024-05-12 fmt -- --check header "analyze" ptime -m cargo clippy --all-targets diff --git a/.github/buildomat/jobs/oxide-vpc.sh b/.github/buildomat/jobs/oxide-vpc.sh index 7c591377..65e97ab9 100755 --- a/.github/buildomat/jobs/oxide-vpc.sh +++ b/.github/buildomat/jobs/oxide-vpc.sh @@ -3,7 +3,7 @@ #: name = "oxide-vpc" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [] #: @@ -21,7 +21,7 @@ rustc --version cd lib/oxide-vpc header "check style" -ptime -m cargo +nightly-2024-04-25 fmt -- --check +ptime -m cargo +nightly-2024-05-12 fmt -- --check header "check docs" # @@ -30,13 +30,13 @@ header "check docs" # # Use nightly which is needed for the `kernel` feature. RUSTDOCFLAGS="-D warnings" ptime -m \ - cargo +nightly-2024-04-25 doc --no-default-features --features=api,std,engine,kernel + cargo +nightly-2024-05-12 doc --no-default-features --features=api,std,engine,kernel header "analyze std + api + usdt" ptime -m cargo clippy --features usdt --all-targets header "analyze no_std + engine + kernel" -ptime -m cargo +nightly-2024-04-25 clippy --no-default-features --features engine,kernel +ptime -m cargo +nightly-2024-05-12 clippy --no-default-features --features engine,kernel header "test" ptime -m cargo test diff --git a/.github/buildomat/jobs/p5p.sh b/.github/buildomat/jobs/p5p.sh index 2a0aa196..1d51caff 100755 --- a/.github/buildomat/jobs/p5p.sh +++ b/.github/buildomat/jobs/p5p.sh @@ -3,7 +3,7 @@ #: name = "opte-p5p" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [ #: "=/out/opte.p5p", #: "=/out/opte.p5p.sha256", diff --git a/.github/buildomat/jobs/xde.sh b/.github/buildomat/jobs/xde.sh index df96c912..af1aa68b 100755 --- a/.github/buildomat/jobs/xde.sh +++ b/.github/buildomat/jobs/xde.sh @@ -3,7 +3,7 @@ #: name = "opte-xde" #: variety = "basic" #: target = "helios-2.0" -#: rust_toolchain = "nightly-2024-04-25" +#: rust_toolchain = "nightly-2024-05-12" #: output_rules = [ #: "=/work/debug/xde.dbg", #: "=/work/debug/xde.dbg.sha256", @@ -75,7 +75,7 @@ pushd xde cp xde.conf /work/xde.conf header "check style" -ptime -m cargo +nightly-2024-04-25 fmt -p xde -p xde-link -- --check +ptime -m cargo +nightly-2024-05-12 fmt -p xde -p xde-link -- --check header "analyze" ptime -m cargo clippy -- \ @@ -123,7 +123,7 @@ sha256sum $REL_TGT/xde_link.so > $REL_TGT/xde_link.so.sha256 header "build xde integration tests" pushd xde-tests -cargo +nightly-2024-04-25 fmt -- --check +cargo +nightly-2024-05-12 fmt -- --check cargo clippy --all-targets cargo build --test loopback loopback_test=$( diff --git a/lib/opte/src/engine/rule.rs b/lib/opte/src/engine/rule.rs index 0b2fe198..4c9fee9a 100644 --- a/lib/opte/src/engine/rule.rs +++ b/lib/opte/src/engine/rule.rs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// Copyright 2023 Oxide Computer Company +// Copyright 2024 Oxide Computer Company //! Rules and actions. @@ -831,7 +831,7 @@ impl<'a> Rule { where R: PacketRead<'a>, { - #[cfg(debug_assert)] + #[cfg(debug_assertions)] { if let Some(preds) = &self.state.preds { if preds.hdr_preds.len() == 0 && preds.data_preds.len() == 0 { diff --git a/xde/rust-toolchain.toml b/xde/rust-toolchain.toml index 5bcb1544..fe1a3bfa 100644 --- a/xde/rust-toolchain.toml +++ b/xde/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2024-04-25" +channel = "nightly-2024-05-12" target = "x86_64-unknown-illumos" components = [ "clippy", "rustfmt", "rust-src" ] profile = "minimal" From d0959ef46d03d7c975951832c6b8386f1da8e7e9 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Mon, 13 May 2024 12:32:30 +0100 Subject: [PATCH 14/16] Minor merge error on doc link. --- lib/opte/src/d_error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/opte/src/d_error.rs b/lib/opte/src/d_error.rs index 2390a0de..a558fe97 100644 --- a/lib/opte/src/d_error.rs +++ b/lib/opte/src/d_error.rs @@ -46,7 +46,7 @@ pub struct LabelBlock { entries: [*const i8; L], } -/// Signals that an [`ErrorBlock`] could not contain a new string entry. +/// Signals that a [`LabelBlock`] could not contain a new string entry. #[derive(Clone, Copy, Debug)] pub struct LabelBlockFull; From 5cab368c2c6cab5e1da0f4aa3ca52a378826bd33 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Mon, 13 May 2024 12:33:45 +0100 Subject: [PATCH 15/16] Bump API again. --- crates/opte-api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/opte-api/src/lib.rs b/crates/opte-api/src/lib.rs index 45cc4c80..fd220e77 100644 --- a/crates/opte-api/src/lib.rs +++ b/crates/opte-api/src/lib.rs @@ -47,7 +47,7 @@ pub use ulp::*; /// /// We rely on CI and the check-api-version.sh script to verify that /// this number is incremented anytime the oxide-api code changes. -pub const API_VERSION: u64 = 30; +pub const API_VERSION: u64 = 31; /// Major version of the OPTE package. pub const MAJOR_VERSION: u64 = 0; From 3cf54eeda9a864c1aeb3fc721e2484a06c16e3b3 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Mon, 13 May 2024 12:46:59 +0100 Subject: [PATCH 16/16] Inform cargo about custom rustc-flags --- lib/opte/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/opte/build.rs b/lib/opte/build.rs index 946b5822..8771fa07 100644 --- a/lib/opte/build.rs +++ b/lib/opte/build.rs @@ -1,5 +1,7 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rustc-check-cfg=cfg(usdt_stable_asm)"); + println!("cargo::rustc-check-cfg=cfg(usdt_stable_asm_sym)"); if version_check::is_min_version("1.59").unwrap_or(false) { println!("cargo:rustc-cfg=usdt_stable_asm");