gpu(gv11b): ACR WPR blob parity (LSB/BL sizes, wpr_region_id, variable netlist) and Gv11bLevel policy (#591)

* gv11b_acr: split LSB vs BL-desc sizes, accept variable-length netlist regions

Audit of the feat/arm64-xavier-gv11b silicon commits (40ed53fa, e308dae4,
2bf9846c) against nvgpu L4T R36.5 as summarized in
nouveau-gv11b/analysis/01-acr-secboot-falcon.md [A]:

- lsb_header_v1 tail: lsf_gen_wpr_requirements overrides the non-PMU
  app_code_size = ucode_size - bl_code_size and app_data_size = data_size,
  i.e. 256-B aligned for FECS as well. Upstream wrote raw FECS sizes here
  (2bf9846c was right on this point).
- flcn_bl_dmem_desc_v2: non_sec_code_size / data_size come from
  app_resident_{code,data}_size, which is raw for FECS and 256-B aligned for
  GPCCS. 2bf9846c rounded FECS to 4 B, which nvgpu does not do; keep the
  upstream resident() semantics and apply them only to the BL descriptor.
- flcn_acr_desc_v1.wpr_region_id: nvgpu GV11B writes only blob start/size,
  no_regions = 1 and wpr_offset = 0. e308dae4 forced 1 (dGPU gm200 style),
  2bf9846c forced 0; neither matches, so the field stays untouched (the L4T
  images ship a zeroed descriptor). Documented and asserted.
- Netlist inst/data regions are not word multiples on real images (40ed53fa
  relaxed inst only); accept any non-empty u32-sized inst and data.
- New validate_nonwpr_blob(): non-WPR sysmem blob must be non-empty, in the
  40-bit DMA window, no larger than WPR1 and disjoint from the
  firmware-locked WPR1.

Host unit tests only; nothing here has run on GV11B silicon.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* gv11b_bringup: plan Stage 3-6 levels and the fuse-selected ACR path

Adds pure planning helpers for the secure half of Tegra194 bring-up:

- Gv11bLevel 0..=6 (cumulative), extending the branch's 0-5 ladder with
  level 6 = FECS/GPCCS cpuctl_alias start + ctxsw handshake
  (gv11b_gr::start_fecs_gpccs_and_handshake). Out-of-range levels are
  rejected, not clamped.
- plan_acr_path(): priv_sec_en == 0 selects the non-secure path; with
  priv_sec_en fused, WPR1 from 0x100cd4 must be programmed
  (MissingWpr1 otherwise, as nvgpu fails with -EINVAL) and pass the
  128 KiB / 40-bit sysmem WPR checks.
- level_action(): skips only the PMU HS ACR level on the non-secure path.

Host unit tests only; no hardware touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BlivionIaG
2026-12-05 16:21:27 +01:00
committed by GitHub
parent f6274a00f6
commit 49fcc6db10
3 changed files with 306 additions and 15 deletions

View File

@ -422,6 +422,12 @@ pub fn patch_hs_signature(file: &mut [u8], img: &HsAcrImage, image: AcrImage) ->
/// Patches the non-WPR blob location into the image's `flcn_acr_desc_v1`
/// (`acr_sw_gv11b.c:58-105`): one region, `wpr_offset = 0`, zeroed
/// `region_props` (the ACR reads WPR1 from hardware).
///
/// `wpr_region_id` (`0x210`) and `mmu_memory_range` (`0x218`) are left as
/// shipped: nvgpu writes only `nonwpr_ucode_blob_{start,size}`,
/// `regions.no_regions` and `wpr_offset` on `GV11B`. The dGPU-style
/// `wpr_region_id = 1` / `no_regions = 2` of `gm200_acr_load_setup` does not
/// apply, and the L4T images ship a zeroed descriptor, so no value is forced.
pub fn patch_acr_desc_v1(
file: &mut [u8],
img: &HsAcrImage,
@ -496,7 +502,10 @@ fn len32(bytes: &[u8]) -> Result<u32, Error> {
u32::try_from(bytes.len()).map_err(|_| Error::InvalidBounds)
}
/// FECS keeps raw resident sizes; GPCCS rounds them to 256 B (`acr_blob_construct.c`).
/// `ls_falcon_ucode_desc.app_resident_{code,data}_size`: FECS keeps the raw
/// netlist sizes, GPCCS rounds them to 256 B (`nvgpu_acr_lsf_{fecs,gpccs}_ucode_details`).
/// These feed only `flcn_bl_dmem_desc_v2`; the `lsb_header_v1` tail always
/// carries the 256-B-aligned sizes (`lsf_gen_wpr_requirements`).
fn resident(id: LsFalcon, size: u32) -> Result<u32, Error> {
match id {
LsFalcon::Fecs => Ok(size),
@ -527,10 +536,12 @@ fn place(fw: &LsFalconFw<'_>, at: u32) -> Result<(LsbPlacement, u32), Error> {
bl_imem_off: fw.desc.imem_offset,
bl_data_off,
bl_data_size,
// `lsf_gen_wpr_requirements` (non-PMU falcons): app_code_size =
// ucode_size - bl_code_size, app_data_size = data_size.
app_code_off: bl_code_size,
app_code_size: resident(fw.id, len32(fw.inst)?)?,
app_code_size: code,
app_data_off: ucode_size,
app_data_size: resident(fw.id, len32(fw.data)?)?,
app_data_size: data,
flags: match fw.id {
LsFalcon::Fecs => 0,
LsFalcon::Gpccs => FLAG_FORCE_PRIV_LOAD,
@ -539,8 +550,10 @@ fn place(fw: &LsFalconFw<'_>, at: u32) -> Result<(LsbPlacement, u32), Error> {
Ok((p, add(bl_data_off, bl_data_size)?))
}
fn is_words_len(bytes: &[u8]) -> bool {
u32::try_from(bytes.len()).is_ok_and(is_words)
/// Netlist FECS/GPCCS inst/data regions are variable-length (not word
/// multiples); nvgpu copies `code.size`/`data.size` bytes verbatim.
fn is_region_len(bytes: &[u8]) -> bool {
!bytes.is_empty() && u32::try_from(bytes.len()).is_ok()
}
fn check_falcons(falcons: &[LsFalconFw<'_>]) -> Result<(), Error> {
@ -553,8 +566,8 @@ fn check_falcons(falcons: &[LsFalconFw<'_>]) -> Result<(), Error> {
for fw in falcons {
if fw.sig.len() != TEGRA_LS_SIG_BYTES
|| fw.bootloader.len() != fw.desc.size as usize
|| !is_words_len(fw.inst)
|| !is_words_len(fw.data)
|| !is_region_len(fw.inst)
|| !is_region_len(fw.data)
{
return Err(Error::InvalidFalcons);
}
@ -607,17 +620,26 @@ fn write_image(out: &mut [u8], fw: &LsFalconFw<'_>, p: &LsbPlacement) {
copy_at(out, p.ucode_off + p.app_data_off, fw.data);
}
fn write_bl_desc(out: &mut [u8], p: &LsbPlacement, wpr: &Wpr1) {
/// `lsfm_populate_flcn_bl_dmem_desc`: `code_dma_base = wpr_base + ucode_off +
/// app_start_offset`, `data_dma_base = code + app_resident_data_offset`,
/// `non_sec_code_size`/`data_size` = `app_resident_{code,data}_size`.
fn write_bl_desc(
out: &mut [u8],
fw: &LsFalconFw<'_>,
p: &LsbPlacement,
wpr: &Wpr1,
) -> Result<(), Error> {
let code = wpr.start + p.ucode_off as u64 + p.app_code_off as u64;
let data = code + (p.app_data_off - p.app_code_off) as u64;
let off = p.bl_data_off as usize;
put_u32(out, off + 0x20, 0);
put_u64(out, off + 0x24, code);
put_u32(out, off + 0x2c, 0);
put_u32(out, off + 0x30, p.app_code_size);
put_u32(out, off + 0x30, resident(fw.id, len32(fw.inst)?)?);
put_u32(out, off + 0x3c, 0);
put_u64(out, off + 0x40, data);
put_u32(out, off + 0x48, p.app_data_size);
put_u32(out, off + 0x48, resident(fw.id, len32(fw.data)?)?);
Ok(())
}
/// Lays out the non-WPR LS blob into `out` and returns its size. nvgpu orders
@ -656,7 +678,7 @@ pub fn compose_wpr_blob(
write_wpr_header(out, slot, fw, &p);
write_lsb(out, fw, &p);
write_image(out, fw, &p);
write_bl_desc(out, &p, wpr);
write_bl_desc(out, fw, &p, wpr)?;
}
put_u32(
out,
@ -666,6 +688,26 @@ pub fn compose_wpr_blob(
Ok(blob)
}
/// Checks the sysmem non-WPR blob the HS ACR copies into WPR1 before
/// `patch_acr_desc_v1`: non-empty, inside the 40-bit DMA window, no larger than
/// WPR1 and disjoint from it (WPR1 is firmware-locked against CPU/DMA writes,
/// so the blob must live in ordinary sysmem).
pub fn validate_nonwpr_blob(blob_start: u64, blob_size: u32, wpr: &Wpr1) -> Result<(), Error> {
wpr.validate()?;
if blob_start == 0 || blob_size == 0 {
return Err(Error::InvalidBounds);
}
let size = blob_size as u64;
check_dma(blob_start, size)?;
if size > wpr.size() {
return Err(Error::InvalidWpr);
}
if blob_start < wpr.end && wpr.start < blob_start + size {
return Err(Error::InvalidWpr);
}
Ok(())
}
/// Sysmem aperture of the PMU instance block; `GV11B` has no VRAM.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SysAperture {

View File

@ -301,7 +301,11 @@ fn gv11b_patch_acr_desc_v1_fields() {
}
patch_acr_desc_v1(&mut f, &img, 0xf_1234_5000, 0x4600).unwrap();
let desc = &f[d..d + ACR_DESC_V1_BYTES];
assert_eq!(get(desc, 0x210), 0xaaaa_aaaa, "wpr_region_id untouched");
assert_eq!(
get(desc, 0x210),
0xaaaa_aaaa,
"wpr_region_id untouched (nvgpu GV11B never writes it)"
);
assert_eq!(get(desc, 0x214), 0);
assert_eq!(get(desc, 0x218), 0xaaaa_aaaa, "mmu_memory_range untouched");
assert_eq!(get(desc, 0x21c), 1);
@ -416,7 +420,9 @@ fn gv11b_compose_wpr_blob_layout() {
(fe.lsb_offset, fe.ucode_off, fe.bl_data_off, fe.flags),
(0x2600, 0x3000, 0x4500, 0)
);
assert_eq!((fe.app_code_size, fe.app_data_size), (0x1004, 0x204));
// lsb_header_v1 app sizes are 256-B aligned for FECS too
// (`lsf_gen_wpr_requirements`); only the BL descriptor keeps raw sizes.
assert_eq!((fe.app_code_size, fe.app_data_size), (0x1100, 0x300));
// lsb_header_v1: 108-B sig, falcon_id overwritten, zero pad to 192, tail.
let lsb = &out[0x2600..0x2600 + LSB_HEADER_V1_BYTES];
@ -429,7 +435,7 @@ fn gv11b_compose_wpr_blob_layout() {
let tail: Vec<u32> = (0..12).map(|i| get(lsb, 192 + i * 4)).collect();
assert_eq!(
tail,
[0x3000, 0x1200, 0x300, 0x100, 0x7e00, 0x4500, 0x100, 0x100, 0x1004, 0x1200, 0x204, 0]
[0x3000, 0x1200, 0x300, 0x100, 0x7e00, 0x4500, 0x100, 0x100, 0x1100, 0x1200, 0x300, 0]
);
assert_eq!(get(&out, 0x100 + 0x48), 3);
assert_eq!(get(&out, 0x100 + 192 + 44), 8);
@ -492,7 +498,15 @@ fn gv11b_compose_wpr_blob_rejects_bad_inputs() {
);
let mut bad = fw_bytes(2);
bad.inst.pop();
bad.inst.clear();
let f = [ls(LsFalcon::Fecs, 0, &bad)];
assert_eq!(
compose_wpr_blob(&mut out, &f, &WPR),
Err(Error::InvalidFalcons)
);
let mut bad = fw_bytes(2);
bad.data.clear();
let f = [ls(LsFalcon::Fecs, 0, &bad)];
assert_eq!(
compose_wpr_blob(&mut out, &f, &WPR),
@ -537,6 +551,93 @@ fn gv11b_compose_wpr_blob_rejects_bad_inputs() {
);
}
/// Netlist FECS/GPCCS regions are not word multiples on real L4T images: the
/// LSB tail rounds to 256 B, the BL descriptor keeps `app_resident_*` (raw for
/// FECS, 256-B aligned for GPCCS) and the image pads with zeros.
#[test]
fn gv11b_compose_wpr_blob_variable_length_regions() {
let mut out = vec![0xeeu8; 0x5000];
let mut e = fw_bytes(2);
e.inst.resize(0x1002, 0xc2);
e.data.resize(0x201, 0xd2);
let f = [ls(LsFalcon::Fecs, 0x7e00, &e)];
let blob = compose_wpr_blob(&mut out, &f, &WPR).unwrap();
assert_eq!(blob.size, 0x2600);
let p = blob.lsb[0].unwrap();
assert_eq!((p.ucode_size, p.data_size), (0x1200, 0x300));
assert_eq!((p.app_code_size, p.app_data_size), (0x1100, 0x300));
let bl = p.bl_data_off as usize;
assert_eq!(get64(&out, bl + 0x24), WPR.start + 0x1100);
assert_eq!(get(&out, bl + 0x30), 0x1002);
assert_eq!(get64(&out, bl + 0x40), WPR.start + 0x2200);
assert_eq!(get(&out, bl + 0x48), 0x201);
assert!(out[0x1100..0x2102].iter().all(|b| *b == 0xc2));
assert!(out[0x2102..0x2200].iter().all(|b| *b == 0));
assert!(out[0x2200..0x2401].iter().all(|b| *b == 0xd2));
assert!(out[0x2401..0x2500].iter().all(|b| *b == 0));
let mut g = fw_bytes(3);
g.inst.resize(0x1002, 0xc3);
g.data.resize(0x201, 0xd3);
let f = [ls(LsFalcon::Gpccs, 0x3400, &g)];
let p = compose_wpr_blob(&mut out, &f, &WPR).unwrap().lsb[0].unwrap();
assert_eq!((p.app_code_size, p.app_data_size), (0x1100, 0x300));
let bl = p.bl_data_off as usize;
assert_eq!(get(&out, bl + 0x30), 0x1100);
assert_eq!(get(&out, bl + 0x48), 0x300);
}
#[test]
fn gv11b_validate_nonwpr_blob() {
let below = WPR.start - 0x10_0000;
assert_eq!(validate_nonwpr_blob(below, 0x4600, &WPR), Ok(()));
assert_eq!(validate_nonwpr_blob(WPR.end, 0x4600, &WPR), Ok(()));
assert_eq!(
validate_nonwpr_blob(WPR.start - 0x4600, 0x4600, &WPR),
Ok(())
);
assert_eq!(
validate_nonwpr_blob(WPR.start - 0x4000, 0x4600, &WPR),
Err(Error::InvalidWpr),
"blob tail inside WPR1"
);
assert_eq!(
validate_nonwpr_blob(WPR.start + 0x1000, 0x4600, &WPR),
Err(Error::InvalidWpr),
"blob inside WPR1"
);
assert_eq!(
validate_nonwpr_blob(WPR.end - 0x1000, 0x4600, &WPR),
Err(Error::InvalidWpr),
"blob head inside WPR1"
);
assert_eq!(
validate_nonwpr_blob(0x1000, (WPR.size() + 1) as u32, &WPR),
Err(Error::InvalidWpr),
"blob larger than WPR1"
);
assert_eq!(
validate_nonwpr_blob(below, 0, &WPR),
Err(Error::InvalidBounds)
);
assert_eq!(
validate_nonwpr_blob(0, 0x4600, &WPR),
Err(Error::InvalidBounds)
);
assert_eq!(
validate_nonwpr_blob((1 << 40) - 0x1000, 0x4600, &WPR),
Err(Error::DmaOutOfRange)
);
let unaligned = Wpr1 {
start: WPR.start + 0x1000,
end: WPR.end,
};
assert_eq!(
validate_nonwpr_blob(below, 0x4600, &unaligned),
Err(Error::InvalidWpr)
);
}
const NCOH_INST: PmuInstBlock = PmuInstBlock {
phys: 0x1_2345_6000,
aperture: SysAperture::SystemNoncoherent,

View File

@ -31,6 +31,8 @@ pub enum SkipReason {
NoVbiosProm,
NoNvlinkOrRebar,
NoSec2Engine,
/// `fuse_opt_priv_sec_en == 0`: no HS ACR, FECS/GPCCS load non-secure.
NoPrivSecurity,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -46,6 +48,9 @@ pub enum BringupError {
DmaOutOfRange,
UnalignedWpr,
EmptyWpr,
/// `priv_sec_en` is fused but firmware left WPR1 unprogrammed (`0x100cd4`
/// idx 2/3 read zero or inverted); nvgpu fails with `-EINVAL` here.
MissingWpr1,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -95,6 +100,88 @@ pub const fn stage_action(stage: Gv11bStage) -> StageAction {
}
}
/// Cumulative Tegra194 platform bring-up levels. Levels 3-6 cover the secure
/// half: FB/MMU + ACR probe, PMU HS ACR, GR deltas, then FECS/GPCCS start.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Gv11bLevel {
/// Platform probe, RM API node and hwmon only.
Probe = 0,
/// Firmware load, BAR2 instance block and IRQs.
Firmware = 1,
/// BAR2 bind into the sysmem instance block.
Bar2Bind = 2,
/// FB/privring/MMU init, fuse security state and firmware-carved WPR1 read.
FbMmuAcrProbe = 3,
/// Non-WPR sysmem blob composition and the PMU-hosted HS ACR run.
PmuHsAcr = 4,
/// GR register deltas and ECC scrub.
GrDeltasEcc = 5,
/// FECS/GPCCS `cpuctl_alias` start and the ctxsw-ready handshake.
CtxswStart = 6,
}
impl Gv11bLevel {
pub const MAX: Self = Self::CtxswStart;
/// Decodes a level number; values above `MAX` are rejected, not clamped.
pub const fn from_u32(level: u32) -> Option<Self> {
Some(match level {
0 => Self::Probe,
1 => Self::Firmware,
2 => Self::Bar2Bind,
3 => Self::FbMmuAcrProbe,
4 => Self::PmuHsAcr,
5 => Self::GrDeltasEcc,
6 => Self::CtxswStart,
_ => return None,
})
}
/// Whether `self` (the requested level) runs `stage`.
pub const fn includes(self, stage: Self) -> bool {
self as u8 >= stage as u8
}
}
/// How FECS/GPCCS reach a running state, chosen at level 3 from the fuses.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AcrPath {
/// `priv_sec_en == 0`: no HS ACR run (`gp10b_fuse_check_priv_security`).
NonSecure,
/// `priv_sec_en == 1`: the HS ACR copies the non-WPR sysmem blob into the
/// firmware-carved WPR1 `[wpr_start, wpr_end)` and boots FECS/GPCCS from it.
HsAcrWpr1 { wpr_start: u64, wpr_end: u64 },
}
/// Picks the ACR path from `priv_sec_en` and the WPR1 bounds read from
/// `0x100cd4` (end already includes the 128 KiB hi adjustment). WPR1 is only
/// required, and only validated, when the ACR runs.
pub const fn plan_acr_path(
priv_sec_en: bool,
wpr_start: u64,
wpr_end: u64,
) -> Result<AcrPath, BringupError> {
if !priv_sec_en {
return Ok(AcrPath::NonSecure);
}
if wpr_start == 0 || wpr_end <= wpr_start {
return Err(BringupError::MissingWpr1);
}
if let Err(err) = validate_sysmem_wpr(wpr_start, wpr_end - wpr_start) {
return Err(err);
}
Ok(AcrPath::HsAcrWpr1 { wpr_start, wpr_end })
}
/// Whether bring-up `level` runs on the chosen ACR path. Only the PMU HS ACR
/// level depends on it; FECS/GPCCS start runs on both paths.
pub const fn level_action(level: Gv11bLevel, path: AcrPath) -> StageAction {
match (level, path) {
(Gv11bLevel::PmuHsAcr, AcrPath::NonSecure) => StageAction::Skip(SkipReason::NoPrivSecurity),
_ => StageAction::Run,
}
}
/// Validates 128 KiB alignment and 40-bit DMA bounds for a sysmem ACR WPR carver.
pub const fn validate_sysmem_wpr(phys: u64, size: u64) -> Result<(), BringupError> {
if size == 0 {
@ -211,6 +298,67 @@ mod tests {
assert_eq!(build_plan(&bad), Err(BringupError::DmaOutOfRange));
}
#[test]
fn levels_decode_and_are_cumulative() {
for n in 0..=6 {
assert_eq!(Gv11bLevel::from_u32(n).unwrap() as u32, n);
}
assert_eq!(Gv11bLevel::from_u32(7), None);
assert_eq!(Gv11bLevel::from_u32(u32::MAX), None);
assert_eq!(Gv11bLevel::MAX, Gv11bLevel::CtxswStart);
let lvl = Gv11bLevel::PmuHsAcr;
assert!(lvl.includes(Gv11bLevel::FbMmuAcrProbe));
assert!(lvl.includes(Gv11bLevel::PmuHsAcr));
assert!(!lvl.includes(Gv11bLevel::GrDeltasEcc));
assert!(!lvl.includes(Gv11bLevel::CtxswStart));
}
#[test]
fn acr_path_follows_fuse_and_wpr1() {
let (lo, hi) = (0x2_0000_0000, 0x2_0040_0000);
assert_eq!(plan_acr_path(false, 0, 0), Ok(AcrPath::NonSecure));
assert_eq!(plan_acr_path(false, 1, 0), Ok(AcrPath::NonSecure));
assert_eq!(
plan_acr_path(true, lo, hi),
Ok(AcrPath::HsAcrWpr1 {
wpr_start: lo,
wpr_end: hi
})
);
assert_eq!(plan_acr_path(true, 0, 0), Err(BringupError::MissingWpr1));
assert_eq!(plan_acr_path(true, 0, hi), Err(BringupError::MissingWpr1));
assert_eq!(plan_acr_path(true, hi, lo), Err(BringupError::MissingWpr1));
assert_eq!(plan_acr_path(true, lo, lo), Err(BringupError::MissingWpr1));
assert_eq!(
plan_acr_path(true, lo + 0x1000, hi),
Err(BringupError::UnalignedWpr)
);
assert_eq!(
plan_acr_path(
true,
(1 << GV11B_DMA_BITS) - GV11B_WPR_ALIGN_BYTES,
(1 << GV11B_DMA_BITS) + GV11B_WPR_ALIGN_BYTES
),
Err(BringupError::DmaOutOfRange)
);
let secure = plan_acr_path(true, lo, hi).unwrap();
let actions = [3, 4, 5, 6].map(|n| Gv11bLevel::from_u32(n).unwrap());
assert_eq!(
actions.map(|l| level_action(l, AcrPath::NonSecure)),
[
StageAction::Run,
StageAction::Skip(SkipReason::NoPrivSecurity),
StageAction::Run,
StageAction::Run,
]
);
assert_eq!(
actions.map(|l| level_action(l, secure)),
[StageAction::Run; 4]
);
}
#[test]
fn ordered_stages_follow_gv11b_policy() {
let actions: [StageAction; 9] = ORDERED_STAGES.map(stage_action);