gv100/hbm: survey only the FBPAs the FBIO floorsweep fuse leaves enabled (#399) (#583)

* gv100/hbm: survey only the FBPAs the FBIO floorsweep fuse leaves enabled

survey_gv100_hbm() demanded all 16 FBPA PLLs readable, locked and equal.
A CMP 100-210 (10de:1df4, 12 GB, three HBM2 stacks) has FBPA 0..=3 fused
off: their PLL cfg/coeff registers answer 0xbadf2010 (PRI bus error)
while FBPA 4..=15 read cfg 0x29, coeff 0x14102 (877.5 MHz). The survey
refused the card (CfgUnreadable at FBPA 0), so the HBM2 session never got
a baseline and v100_hbm_ndiv was a no-op. program_coeff() made the same
assumption twice more: its post-write probe read FBPA 0, and its lock
wait polled all 16.

1. Survey mask. 580.178.04 does not probe for bus errors; it computes the
   enabled-FBPA mask from the fuse. _nv030402rm (GV100 GPU HAL slot
   +0x3a0) [D]:
     n    = RD32(0x2243c)                      NV_PTOP_SCAL_NUM_FBPAS
     fuse = OBJFUSE+0x118(0xff000033)          _nv029006rm
            -> OBJFUSE+0x110 _nv028950rm: fuse word 0xc14, shift 0,
               mask 0xffff, i.e. BAR0 0x21c14
     mask = zext64(~fuse); if n <= 64: mask &= ~0 >> (64 - n); n == 0: 0
   A stock mmiotrace of a Tesla V100 shows that pair once, 0x2243c = 0x10
   then 0x21c14 = 0 [O] (reports/original-mmiotrace-b3-first/b3-bar0.txt),
   which gives 0xffff. On the #399 card the reporter read 0x2243c = 0x10
   and 0x21c14 = 0xf [O], which gives 0xfff0 and matches the partitions
   that answer.
2. Post-write probe on the first enabled FBPA instead of FBPA 0.
3. Lock wait polls only the enabled FBPAs.
   Stock never retunes the HBM2 PLL, so 2 and 3 have no stock evidence;
   they follow from 1. On silicon [O]: the reporter ran 23db150 with the
   equivalent change (presence taken from the bus-error word rather than
   the fuse) on the #399 card and got a verified 877.5 -> 1107 MHz unlock
   (NDIV 65 -> 82) on FBPA 4..=15, D2D 618 -> 781 GB/s, then adaptive
   backoff on real ECC DBE/SBE and a clean return to NDIV 65
   (https://github.com/QuixiAI/nvdriver/issues/399#issuecomment-7386631509).
   This exact commit has not run on silicon.

fbio_enabled_mask() is the stock arithmetic and gv100_enabled_fbpa_mask()
the two reads, in stock order. An enabled partition must still be
readable, locked and in agreement (the reference coefficient is the first
enabled partition's), so a card whose fuse says 16 but whose FBPA 0 does
not answer is refused as before. The mask is resolved before the
multicast write; if 0x2243c is unreadable, 0 or above 16, or the fuse is
unreadable or enables nothing, the survey reports the new fault kinds
FbpaCountUnusable (6) / FbioFuseUnusable (7) and nothing is written. A
mask lost between the survey and the write is a refusal before the target
write, like the PMC_BOOT_0 canary: logged as SurveyFailed, not RolledBack.
gpu_owner.c logs kinds 6 and 7, and the CoeffMismatch text now says "the
first enabled FBPA" instead of "FBPA 0". A 16-partition card does two
more BAR0 reads per survey and per program_coeff and otherwise behaves as
before. The ECC poll and the backoff logic are unchanged.

Tests: fbio_enabled_mask_matches_nv030402rm_arithmetic,
gv100_hbm_survey_and_unlock_skip_fused_off_fbpas (mock with FBPA 0..=3
reading 0xbadf2010, fuse 0xf: survey, unlock 65 -> 82, backoff step,
restore; refusals with zero writes for unusable mask inputs), and
gv100_hbm_mask_lost_before_the_target_write_is_not_a_rollback. Without
the change the first survey assertion fails; reverting only the probe or
only the lock wait makes the unlock fail.

Refs #399

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

* gv100/hbm: fall back to cached floorsweep mask on rollback/restore and log teardown failure

Addresses CodeRabbit review finding on PR #583:
- Cache the static silicon enabled-FBPA mask resolved during baseline survey
  (HbmSession::enabled_fbpa_mask and inside unlock/set rollback paths).
- If re-reading PTOP_SCAL_NUM_FBPAS (0x2243c) or FUSE_OPT_FBIO (0x21c14)
  glitches during a rollback or teardown restore, fall back to the cached
  mask so the baseline HBM2 coefficient write is not blocked while PMC_BOOT_0
  canary remains strictly enforced.
- Log failed HBM2 teardown restores in pmu_bringup.rs via log_hbm_outcome
  instead of discarding the result.
- Add unit test covering fuse-glitch teardown restore and canary refusal.

* gv100/hbm: use cached floorsweep mask for downward safety steps (ECC backoff / baseline return)

Addresses follow-up CodeRabbit finding on PR #583:
- In HbmSession::step_to, downward safety steps (target <= current clock:
  live ECC backoff via on_instability and sysfs return to baseline) fall
  back to the cached static silicon enabled-FBPA mask on a transient read
  failure of 0x2243c/0x21c14 so an elevated clock is never stranded while
  the GPU remains in service.
- Upward overclock steps continue to require a fresh fuse read and refuse
  before writing when unreadable.
- Extend unit test to cover on_instability and on_user_write(0) under a
  fuse-read glitch.

* gv100/hbm: skip rollback write on pre-write mask refusal

Addresses CodeRabbit trivial finding on PR #583:
- When program_coeff refuses before the target write due to an unreadable
  FBPA count (FbpaCountUnusable) or FBIO fuse (FbioFuseUnusable), skip the
  unnecessary rollback multicast write so the PLL stays completely untouched
  (writes == 0) and a clean refusal can never degrade into FailedUnverified.
- Preserve existing pre-write canary refusal behavior unchanged.

---------

Co-authored-by: Scottcjn <121303252+Scottcjn@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
This commit is contained in:
morebrackets
2026-12-05 00:18:44 -08:00
committed by GitHub
parent 19a84a4392
commit f3838d692d
3 changed files with 532 additions and 42 deletions

View File

@ -264,9 +264,16 @@ void nv_rs_hbm_clock_outcome_log(u32 outcome, u32 requested_ndiv, u32 current_kh
fault_fbpa, fault_value);
break;
case 5:
scnprintf(fault, sizeof(fault), "FBPA %u PLL coefficient 0x%08x differs from FBPA 0",
scnprintf(fault, sizeof(fault), "FBPA %u PLL coefficient 0x%08x differs from the first enabled FBPA",
fault_fbpa, fault_value);
break;
case 6:
scnprintf(fault, sizeof(fault), "FBPA count 0x2243c unusable (0x%08x)", fault_value);
break;
case 7:
scnprintf(fault, sizeof(fault), "FBIO floorsweep fuse 0x21c14 unusable (0x%08x)",
fault_value);
break;
default:
scnprintf(fault, sizeof(fault), "unknown fault %u", fault_kind);
break;

View File

@ -3263,9 +3263,17 @@ impl gr_bringup::WhileLoaded for Start<'_, '_> {
c6,
);
}
let _ = hbm_session.restore(io.registers, |us| unsafe {
nv_rs_os_busy_us(us)
});
if let Some(base) = hbm_session.baseline {
if !hbm_session.restore(io.registers, |us| unsafe {
nv_rs_os_busy_us(us)
}) {
log_hbm_outcome(
&hbm_session,
nv_rs_core::gpu::hbm_clock::HbmOutcome::ClockUnknown,
base.ndiv(),
);
}
}
if let Some(saved_p0) = p0_restore {
nv_rs_core::gpu::gv100_p0_boost::restore_gv100_p0(
io.registers,

View File

@ -3,8 +3,9 @@
//! Raises GV100 HBM2 memory clock from NVIDIA's driver-locked 877.5 MHz (`NDIV = 65`)
//! to 1053.0 MHz (`NDIV = 78`, +20% bandwidth, default) or 1080.0 MHz (`NDIV = 80`, +23%)
//! via a single write to the write-only multicast HBM PLL coefficient register `0x98BC98`,
//! with full `PMC_BOOT_0` canary, PRI-ring read-guard, 16-partition lock polling, readback
//! verification, and automatic rollback on failure.
//! with full `PMC_BOOT_0` canary, PRI-ring read-guard, lock polling on every FBPA partition
//! the FBIO floorsweep fuse leaves enabled (16 on a Tesla V100, 12 on a three-stack
//! CMP 100-210), readback verification, and automatic rollback on failure.
//!
//! Hardware register map & safety invariants derived from `FBR-RAM-Downloader` (`v100-unlock`, MIT).
use crate::gpu::registers::RegisterIo;
@ -22,6 +23,18 @@ pub const NO_READ_END: u32 = 0x0098_c000;
/// 16 FBPA memory partitions across 4 HBM2 stacks on GV100.
pub const FBPA_COUNT: usize = 16;
/// `NV_PTOP_SCAL_NUM_FBPAS` (`0x2243c`): FBPA partition count of the chip. The first read of
/// 580.178.04 `_nv030402rm` \[D\]; reads `0x10` on a Tesla V100 under the stock driver \[O\]
/// and on the #399 CMP 100-210 (reporter's read) \[O\].
pub const PTOP_SCAL_NUM_FBPAS: u32 = 0x0002_243c;
/// FBIO floorsweep fuse word: bit `i` set = FBPA partition `i` is fused off. 580.178.04 reads
/// it as OBJFUSE query `0xff000033` (`_nv029006rm`), which GV100 OBJFUSE+0x110 `_nv028950rm`
/// resolves to fuse word `0xc14`, shift 0, mask `0xffff` \[D\]; the fuse block is at `0x21000`.
/// Reads `0` on a Tesla V100 under the stock driver and `0xf` on the #399 CMP 100-210 \[O\].
pub const FUSE_OPT_FBIO: u32 = 0x0002_1c14;
/// Field mask `_nv028950rm` returns for the FBIO fuse word.
pub const FUSE_OPT_FBIO_MASK: u32 = 0xffff;
pub const FBPA_CFG_BASE: u32 = 0x0090_3c90;
pub const FBPA_COEFF_BASE: u32 = 0x0090_3c98;
pub const FBPA_STRIDE: u32 = 0x4000;
@ -126,7 +139,7 @@ pub enum HbmUnlockStatus {
Skipped,
/// Card is already at or above `target_ndiv` (e.g. V100S at 1107 MHz).
AlreadyAtOrAbove { current: HbmCoeff },
/// Successfully raised HBM2 clock and verified lock + readback on all 16 partitions.
/// Successfully raised HBM2 clock and verified lock + readback on every enabled partition.
Unlocked {
from: HbmCoeff,
to: HbmCoeff,
@ -153,8 +166,14 @@ pub enum HbmSurveyFaultKind {
CoeffUnreadable = 3,
/// An FBPA PLL config register reads back without `PLL_LOCK`.
PllUnlocked = 4,
/// An FBPA PLL coefficient differs from the first partition's.
/// An FBPA PLL coefficient differs from the first enabled partition's.
CoeffMismatch = 5,
/// `NV_PTOP_SCAL_NUM_FBPAS` was unreadable, `0`, or above the [`FBPA_COUNT`] partitions
/// this module has registers for; `value` is the raw word.
FbpaCountUnusable = 6,
/// The FBIO floorsweep fuse word was unreadable or leaves no partition enabled; `value`
/// is the raw word.
FbioFuseUnusable = 7,
}
/// First check that made [`survey_gv100_hbm_checked`] refuse the card, with the partition
@ -162,7 +181,8 @@ pub enum HbmSurveyFaultKind {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HbmSurveyFault {
pub kind: HbmSurveyFaultKind,
/// FBPA partition index `0..FBPA_COUNT`; [`HbmSurveyFault::NO_FBPA`] for the canary.
/// FBPA partition index `0..FBPA_COUNT`; [`HbmSurveyFault::NO_FBPA`] for the canary and
/// the enabled-partition mask.
pub fbpa: u8,
/// Raw word read from the register; `u32::MAX` when the read itself failed.
pub value: u32,
@ -205,8 +225,61 @@ fn canary_fault(io: &mut impl RegisterIo) -> Result<(), HbmSurveyFault> {
})
}
/// Surveys all 16 GV100 FBPA partitions; returns `Some(coeff)` iff all 16 are locked,
/// agree on the same coefficient, and pass `PMC_BOOT_0` canary before and after.
/// Enabled-FBPA mask arithmetic of 580.178.04 `_nv030402rm` (GV100 GPU HAL slot +0x3a0) \[D\]:
/// the 32-bit complement of the FBIO fuse field, zero-extended to 64 bits, cut to the low
/// `num_fbpas` bits when `num_fbpas <= 64`, and `0` when the chip reports no FBPA.
pub const fn fbio_enabled_mask(num_fbpas: u32, fbio_fuse: u32) -> u64 {
if num_fbpas == 0 {
return 0;
}
let enabled = !(fbio_fuse & FUSE_OPT_FBIO_MASK) as u64;
if num_fbpas <= 64 {
enabled & (u64::MAX >> (64 - num_fbpas))
} else {
enabled
}
}
/// Reads the mask of FBPA partitions the FBIO floorsweep fuse leaves enabled, the way
/// `_nv030402rm` does: `NV_PTOP_SCAL_NUM_FBPAS`, then the FBIO fuse word (#399).
///
/// `None` when either read fails, when no partition is enabled, or when the chip reports
/// more partitions than the [`FBPA_COUNT`] this module has registers for.
pub fn gv100_enabled_fbpa_mask(io: &mut impl RegisterIo) -> Option<u16> {
gv100_enabled_fbpa_mask_checked(io).ok()
}
/// [`gv100_enabled_fbpa_mask`] with the reason for a refusal, as an [`HbmSurveyFault`].
fn gv100_enabled_fbpa_mask_checked(io: &mut impl RegisterIo) -> Result<u16, HbmSurveyFault> {
let fault = |kind, value| HbmSurveyFault {
kind,
fbpa: HbmSurveyFault::NO_FBPA,
value,
};
// Both words are read, in stock order, before either is judged.
let num_fbpas = read_or_raw(io, PTOP_SCAL_NUM_FBPAS);
let fbio_fuse = read_or_raw(io, FUSE_OPT_FBIO);
let num_fbpas = match num_fbpas {
Ok(n) if n != 0 && n as usize <= FBPA_COUNT => n,
Ok(raw) | Err(raw) => return Err(fault(HbmSurveyFaultKind::FbpaCountUnusable, raw)),
};
let fbio_fuse = fbio_fuse.map_err(|raw| fault(HbmSurveyFaultKind::FbioFuseUnusable, raw))?;
match fbio_enabled_mask(num_fbpas, fbio_fuse) {
0 => Err(fault(HbmSurveyFaultKind::FbioFuseUnusable, fbio_fuse)),
// num_fbpas <= FBPA_COUNT, so the mask fits in FBPA_COUNT bits.
mask => Ok(mask as u16),
}
}
#[inline]
const fn fbpa_enabled(mask: u16, i: usize) -> bool {
(mask >> i) & 1 != 0
}
/// Surveys the GV100 FBPA partitions the FBIO floorsweep fuse leaves enabled; returns
/// `Some(coeff)` iff every one of them is locked, they agree on the same coefficient, and
/// `PMC_BOOT_0` passes the canary before and after. Fused-off partitions answer with a PRI
/// bus error and are not read.
pub fn survey_gv100_hbm(io: &mut impl RegisterIo) -> Option<HbmCoeff> {
survey_gv100_hbm_checked(io).ok()
}
@ -214,9 +287,31 @@ pub fn survey_gv100_hbm(io: &mut impl RegisterIo) -> Option<HbmCoeff> {
/// [`survey_gv100_hbm`] with the reason for a refusal: the same reads in the same order,
/// reporting the first check that failed instead of collapsing every failure to `None`.
pub fn survey_gv100_hbm_checked(io: &mut impl RegisterIo) -> Result<HbmCoeff, HbmSurveyFault> {
survey_gv100_hbm_checked_with_mask(io).map(|(coeff, _)| coeff)
}
fn survey_gv100_hbm_checked_with_mask(
io: &mut impl RegisterIo,
) -> Result<(HbmCoeff, u16), HbmSurveyFault> {
canary_fault(io)?;
let enabled = gv100_enabled_fbpa_mask_checked(io)?;
let coeff = survey_gv100_hbm_for_mask(io, enabled)?;
Ok((coeff, enabled))
}
/// Surveys the FBPA partitions named by a non-zero `enabled` mask after `canary_fault` has
/// already passed, finishing with the post-survey `PMC_BOOT_0` canary check.
fn survey_gv100_hbm_for_mask(
io: &mut impl RegisterIo,
enabled: u16,
) -> Result<HbmCoeff, HbmSurveyFault> {
// The mask is non-zero; its lowest enabled partition is the reference coefficient.
let reference = enabled.trailing_zeros() as usize;
let mut first = 0u32;
for i in 0..FBPA_COUNT {
if !fbpa_enabled(enabled, i) {
continue;
}
let fault = |kind, value| HbmSurveyFault {
kind,
fbpa: i as u8,
@ -229,7 +324,7 @@ pub fn survey_gv100_hbm_checked(io: &mut impl RegisterIo) -> Result<HbmCoeff, Hb
if (cfg & CFG_PLL_LOCK) == 0 {
return Err(fault(HbmSurveyFaultKind::PllUnlocked, cfg));
}
if i == 0 {
if i == reference {
first = coeff;
} else if coeff != first {
return Err(fault(HbmSurveyFaultKind::CoeffMismatch, coeff));
@ -239,17 +334,64 @@ pub fn survey_gv100_hbm_checked(io: &mut impl RegisterIo) -> Result<HbmCoeff, Hb
Ok(HbmCoeff(first))
}
/// Writes `coeff` and waits for every partition to lock and read it back. `Err(Some(fault))`
/// means the `PMC_BOOT_0` canary refused the card before the write, so `coeff` was never
/// written; `Err(None)` means it failed at or after the write.
fn survey_gv100_hbm_with_fallback(
io: &mut impl RegisterIo,
fallback_mask: Option<u16>,
) -> Result<HbmCoeff, HbmSurveyFault> {
survey_gv100_hbm_checked_with_mask_fallback(io, fallback_mask).map(|(coeff, _)| coeff)
}
fn survey_gv100_hbm_checked_with_mask_fallback(
io: &mut impl RegisterIo,
fallback_mask: Option<u16>,
) -> Result<(HbmCoeff, u16), HbmSurveyFault> {
canary_fault(io)?;
let enabled = match gv100_enabled_fbpa_mask_checked(io) {
Ok(mask) => mask,
Err(fault) => match fallback_mask.filter(|&m| m != 0) {
Some(cached) => cached,
None => return Err(fault),
},
};
let coeff = survey_gv100_hbm_for_mask(io, enabled)?;
Ok((coeff, enabled))
}
/// Writes `coeff` and waits for every enabled partition to lock and read it back.
/// `Err(Some(fault))` means the `PMC_BOOT_0` canary or the enabled-partition mask refused the
/// card before the write, so `coeff` was never written; `Err(None)` means it failed at or
/// after the write.
fn program_coeff(
io: &mut impl RegisterIo,
coeff: HbmCoeff,
delay_us: impl FnMut(u32),
) -> Result<u32, Option<HbmSurveyFault>> {
program_coeff_with_fallback(io, coeff, None, delay_us)
}
/// Like [`program_coeff`], but when `fallback_mask` is `Some(non_zero)` (rollback / teardown
/// restore of a previously surveyed card), a transient read failure on the static floorsweep
/// fuses falls back to the cached silicon mask rather than blocking the baseline restore.
/// The `PMC_BOOT_0` canary is still strictly enforced before any write.
fn program_coeff_with_fallback(
io: &mut impl RegisterIo,
coeff: HbmCoeff,
fallback_mask: Option<u16>,
mut delay_us: impl FnMut(u32),
) -> Result<u32, Option<HbmSurveyFault>> {
canary_fault(io).map_err(Some)?;
// Resolved before the write: a card whose enabled partitions cannot be told is not written,
// unless a rollback/restore already holds the silicon's verified floorsweep mask.
let enabled = match gv100_enabled_fbpa_mask_checked(io) {
Ok(mask) => mask,
Err(fault) => match fallback_mask.filter(|&m| m != 0) {
Some(cached) => cached,
None => return Err(Some(fault)),
},
};
io.write32(HBMPLL_COEFF_MC, coeff.0).map_err(|_| None)?;
safe_read(io, fbpa_coeff(0)).ok_or(None)?;
// Post-write PRI probe on the first enabled partition; partition 0 may be fused off (#399).
safe_read(io, fbpa_coeff(enabled.trailing_zeros() as usize)).ok_or(None)?;
if !check_canary(io) {
return Err(None);
}
@ -257,6 +399,9 @@ fn program_coeff(
for _ in 0..LOCK_TIMEOUT_POLLS {
let mut all_locked = true;
for i in 0..FBPA_COUNT {
if !fbpa_enabled(enabled, i) {
continue;
}
match safe_read(io, fbpa_cfg(i)) {
Some(cfg) if (cfg & CFG_PLL_LOCK) != 0 => {}
_ => {
@ -266,8 +411,8 @@ fn program_coeff(
}
}
if all_locked {
return match survey_gv100_hbm(io) {
Some(confirmed) if confirmed == coeff => Ok(elapsed_us),
return match survey_gv100_hbm_with_fallback(io, fallback_mask) {
Ok(confirmed) if confirmed == coeff => Ok(elapsed_us),
_ => Err(None),
};
}
@ -309,8 +454,8 @@ fn unlock_gv100_hbm_noted(
return (HbmUnlockStatus::Skipped, Some(fault));
}
let target = target_ndiv.min(MAX_SAFE_NDIV);
let from = match survey_gv100_hbm_checked(io) {
Ok(from) => from,
let (from, enabled) = match survey_gv100_hbm_checked_with_mask(io) {
Ok(surveyed) => surveyed,
Err(fault) => return (HbmUnlockStatus::FailedRolledBack, Some(fault)),
};
if from.mdiv() != STOCK_MDIV
@ -326,9 +471,19 @@ fn unlock_gv100_hbm_noted(
let to = from.with_ndiv(target);
match program_coeff(io, to, &mut delay_us) {
Ok(lock_us) => (HbmUnlockStatus::Unlocked { from, to, lock_us }, None),
// The rollback runs either way; a canary refusal before the target write is kept so
// Fresh-mask refusal before the target write: nothing was written to HBMPLL_COEFF_MC,
// so skip rollback instead of issuing an unnecessary write that could fail.
Err(Some(refused))
if matches!(
refused.kind,
HbmSurveyFaultKind::FbpaCountUnusable | HbmSurveyFaultKind::FbioFuseUnusable
) =>
{
(HbmUnlockStatus::FailedRolledBack, Some(refused))
}
// The rollback runs otherwise; a canary refusal before the target write is kept so
// a verified rollback of a target that was never written is not logged as one.
Err(refused) => match program_coeff(io, from, &mut delay_us) {
Err(refused) => match program_coeff_with_fallback(io, from, Some(enabled), &mut delay_us) {
Ok(_) => (HbmUnlockStatus::FailedRolledBack, refused),
Err(_) => (HbmUnlockStatus::FailedUnverified { from }, refused),
},
@ -360,14 +515,27 @@ pub fn set_gv100_hbm_ndiv(
fn set_gv100_hbm_ndiv_noted(
io: &mut impl RegisterIo,
target_ndiv: u8,
delay_us: impl FnMut(u32),
) -> (HbmUnlockStatus, Option<HbmSurveyFault>) {
set_gv100_hbm_ndiv_noted_with_fallback(io, target_ndiv, None, delay_us)
}
/// Like [`set_gv100_hbm_ndiv_noted`], but when `fallback_mask` is `Some(non_zero)` (used for
/// downward safety steps — live ECC backoff or sysfs return to baseline — on an already
/// surveyed card), a transient read failure on the static floorsweep fuses falls back to the
/// cached silicon mask so the card is never stranded at an elevated clock.
fn set_gv100_hbm_ndiv_noted_with_fallback(
io: &mut impl RegisterIo,
target_ndiv: u8,
fallback_mask: Option<u16>,
mut delay_us: impl FnMut(u32),
) -> (HbmUnlockStatus, Option<HbmSurveyFault>) {
if target_ndiv == 0 {
return (HbmUnlockStatus::Skipped, None);
}
let target = target_ndiv.clamp(MIN_STOCK_NDIV, MAX_SAFE_NDIV);
let from = match survey_gv100_hbm_checked(io) {
Ok(from) => from,
let (from, enabled) = match survey_gv100_hbm_checked_with_mask_fallback(io, fallback_mask) {
Ok(surveyed) => surveyed,
Err(fault) => return (HbmUnlockStatus::FailedRolledBack, Some(fault)),
};
if from.mdiv() != STOCK_MDIV
@ -381,11 +549,22 @@ fn set_gv100_hbm_ndiv_noted(
return (HbmUnlockStatus::AlreadyAtOrAbove { current: from }, None);
}
let to = from.with_ndiv(target);
match program_coeff(io, to, &mut delay_us) {
let write_fallback = fallback_mask.map(|_| enabled);
match program_coeff_with_fallback(io, to, write_fallback, &mut delay_us) {
Ok(lock_us) => (HbmUnlockStatus::Unlocked { from, to, lock_us }, None),
// The rollback runs either way; a canary refusal before the target write is kept so
// Fresh-mask refusal before the target write: nothing was written to HBMPLL_COEFF_MC,
// so skip rollback instead of issuing an unnecessary write that could fail.
Err(Some(refused))
if matches!(
refused.kind,
HbmSurveyFaultKind::FbpaCountUnusable | HbmSurveyFaultKind::FbioFuseUnusable
) =>
{
(HbmUnlockStatus::FailedRolledBack, Some(refused))
}
// The rollback runs otherwise; a canary refusal before the target write is kept so
// a verified rollback of a target that was never written is not logged as one.
Err(refused) => match program_coeff(io, from, &mut delay_us) {
Err(refused) => match program_coeff_with_fallback(io, from, Some(enabled), &mut delay_us) {
Ok(_) => (HbmUnlockStatus::FailedRolledBack, refused),
Err(_) => (HbmUnlockStatus::FailedUnverified { from }, refused),
},
@ -630,6 +809,9 @@ pub struct HbmSession {
/// or the effective target of a step (for `v100_hbm_ndiv = 0` with a baseline, the
/// baseline NDIV being restored). Zero only when no target was requested.
pub target_ndiv: u8,
/// Enabled FBPA partition mask cached from the baseline survey so a transient fuse-read
/// glitch at teardown cannot block restoring the card to `baseline`.
pub enabled_fbpa_mask: Option<u16>,
}
/// What an [`HbmSession`] step did to the HBM2 clock, for the kernel log (#399).
@ -676,8 +858,8 @@ impl HbmSession {
target_ndiv: u8,
mut delay_us: impl FnMut(u32),
) -> (Self, HbmUnlockStatus) {
let base = match survey_gv100_hbm_checked(io) {
Ok(base) => base,
let (base, enabled_mask) = match survey_gv100_hbm_checked_with_mask(io) {
Ok(surveyed) => surveyed,
Err(fault) => {
let mut backoff = HbmAutoBackoff::new(STOCK_V100_NDIV);
backoff.user_ndiv = target_ndiv;
@ -689,6 +871,7 @@ impl HbmSession {
backoff,
survey_fault: Some(fault),
target_ndiv,
enabled_fbpa_mask: None,
},
HbmUnlockStatus::FailedRolledBack,
);
@ -708,6 +891,7 @@ impl HbmSession {
backoff,
survey_fault: None,
target_ndiv,
enabled_fbpa_mask: Some(enabled_mask),
},
st,
)
@ -722,6 +906,7 @@ impl HbmSession {
backoff,
survey_fault: None,
target_ndiv,
enabled_fbpa_mask: Some(enabled_mask),
},
st,
)
@ -734,6 +919,7 @@ impl HbmSession {
backoff,
survey_fault: fault,
target_ndiv,
enabled_fbpa_mask: Some(enabled_mask),
},
st,
),
@ -757,6 +943,7 @@ impl HbmSession {
backoff,
survey_fault,
target_ndiv,
enabled_fbpa_mask: Some(enabled_mask),
},
st,
)
@ -769,6 +956,7 @@ impl HbmSession {
backoff,
survey_fault: fault,
target_ndiv,
enabled_fbpa_mask: Some(enabled_mask),
},
st,
),
@ -822,7 +1010,24 @@ impl HbmSession {
return HbmUnlockStatus::Skipped;
}
self.target_ndiv = target_ndiv;
let (st, fault) = set_gv100_hbm_ndiv_noted(io, target_ndiv, &mut delay_us);
// Downward safety steps (live ECC backoff or sysfs return to baseline) fall back to
// the cached static silicon floorsweep mask on a transient fuse-read glitch so an
// elevated clock can always be lowered while the GPU stays in service. Upward steps
// still require a fresh fuse read.
let downward_fallback = self.baseline.and_then(|base| {
let clamped = target_ndiv.clamp(MIN_STOCK_NDIV, MAX_SAFE_NDIV);
if target_ndiv != 0 && base.with_ndiv(clamped).khz() <= self.current_khz {
self.enabled_fbpa_mask
} else {
None
}
});
let (st, fault) = set_gv100_hbm_ndiv_noted_with_fallback(
io,
target_ndiv,
downward_fallback,
&mut delay_us,
);
self.survey_fault = fault;
match st {
HbmUnlockStatus::Unlocked { to, .. } => {
@ -834,7 +1039,7 @@ impl HbmSession {
self.current_khz = current.khz();
}
HbmUnlockStatus::FailedRolledBack => {
let after = survey_gv100_hbm_checked(io);
let after = survey_gv100_hbm_with_fallback(io, downward_fallback);
// Refused before the target write: a survey failure, not a rollback.
self.state = match (fault, &after) {
(Some(_), _) => HbmSessionState::SurveyFailed,
@ -933,20 +1138,31 @@ impl HbmSession {
let Some(base) = self.baseline else {
return false;
};
if !restore_gv100_hbm(io, base, &mut delay_us) {
if let Err(fault) =
program_coeff_with_fallback(io, base, self.enabled_fbpa_mask, &mut delay_us)
{
self.state = HbmSessionState::ClockUnknown;
self.current_khz = 0;
self.survey_fault = fault;
return false;
}
match survey_gv100_hbm(io) {
Some(cur) if cur.ndiv() == base.ndiv() => {
match survey_gv100_hbm_with_fallback(io, self.enabled_fbpa_mask) {
Ok(cur) if cur.ndiv() == base.ndiv() => {
self.current_khz = cur.khz();
self.backoff.active_ndiv = cur.ndiv();
self.survey_fault = None;
true
}
_ => {
Ok(_) => {
self.state = HbmSessionState::ClockUnknown;
self.current_khz = 0;
self.survey_fault = None;
false
}
Err(fault) => {
self.state = HbmSessionState::ClockUnknown;
self.current_khz = 0;
self.survey_fault = Some(fault);
false
}
}
@ -1849,6 +2065,8 @@ mod tests {
boot0: u32,
coeff: [u32; FBPA_COUNT],
cfg: [u32; FBPA_COUNT],
num_fbpas: u32,
fbio_fuse: u32,
writes: usize,
read_forbidden: bool,
}
@ -1860,6 +2078,9 @@ mod tests {
boot0: BOOT0_GV100,
coeff: [c; FBPA_COUNT],
cfg: [CFG_PLL_LOCK; FBPA_COUNT],
// Tesla V100 under the stock driver: 0x2243c = 0x10, 0x21c14 = 0.
num_fbpas: 0x10,
fbio_fuse: 0,
writes: 0,
read_forbidden: false,
}
@ -1875,6 +2096,12 @@ mod tests {
if offset == PMC_BOOT_0 {
return Ok(self.boot0);
}
if offset == PTOP_SCAL_NUM_FBPAS {
return Ok(self.num_fbpas);
}
if offset == FUSE_OPT_FBIO {
return Ok(self.fbio_fuse);
}
for i in 0..FBPA_COUNT {
if offset == fbpa_cfg(i) {
return Ok(self.cfg[i]);
@ -1889,7 +2116,11 @@ mod tests {
fn write32(&mut self, offset: u32, value: u32) -> Result<(), NvStatus> {
self.writes += 1;
if offset == HBMPLL_COEFF_MC {
self.coeff = [value; FBPA_COUNT];
// The multicast write reaches the partitions that exist; a fused-off one
// keeps answering with its bus-error word.
for c in self.coeff.iter_mut().filter(|c| !is_bus_error(**c)) {
*c = value;
}
}
Ok(())
}
@ -2026,23 +2257,240 @@ mod tests {
}
}
/// Issue #399: the BAR0 words a CMP 100-210 (10de:1df4, 12 GB) reports for its 16 FBPA
/// PLLs. Partitions 0..=3 answer with a PRI bus error, 4..=15 are locked at NDIV 65.
/// Issue #399: the BAR0 words a CMP 100-210 (10de:1df4, 12 GB, three HBM2 stacks) reports.
/// `0x2243c = 0x10`, FBIO fuse `0x21c14 = 0xf`; partitions 0..=3 answer with a PRI bus
/// error, 4..=15 are locked (cfg `0x29`) at NDIV 65 (coeff `0x14102`).
fn cmp_100_210_three_stack() -> MockGv100 {
let mut gpu = MockGv100::new(65);
assert_eq!(gpu.coeff[4], 0x0001_4102);
gpu.fbio_fuse = 0xf;
gpu.cfg = [0x0000_0029; FBPA_COUNT];
gpu.cfg[..4].fill(0xbadf_2010);
gpu.coeff[..4].fill(0xbadf_2010);
gpu
}
#[test]
fn fbio_enabled_mask_matches_nv030402rm_arithmetic() {
// Tesla V100 under the stock driver [O]: 0x2243c = 0x10, 0x21c14 = 0.
assert_eq!(fbio_enabled_mask(0x10, 0), 0xffff);
// Issue #399 CMP 100-210 [O]: 0x2243c = 0x10, 0x21c14 = 0xf.
assert_eq!(fbio_enabled_mask(0x10, 0xf), 0xfff0);
// Only the 16-bit field _nv028950rm returns takes part.
assert_eq!(fbio_enabled_mask(0x10, 0xffff_000f), 0xfff0);
assert_eq!(fbio_enabled_mask(0x10, 0xffff), 0);
// No FBPA reported: stock caches 0 whatever the fuse says.
assert_eq!(fbio_enabled_mask(0, 0), 0);
assert_eq!(fbio_enabled_mask(4, 0x1), 0xe);
// The complement is taken in 32 bits and zero-extended, so counts above 32 keep
// bits 16..=31 set and never reach bit 32; above 64 nothing is cut.
assert_eq!(fbio_enabled_mask(32, 0), 0xffff_ffff);
assert_eq!(fbio_enabled_mask(64, 0), 0xffff_ffff);
assert_eq!(fbio_enabled_mask(65, 0xf), 0xffff_fff0);
assert_eq!((PTOP_SCAL_NUM_FBPAS, FUSE_OPT_FBIO), (0x2243c, 0x21c14));
}
#[test]
fn gv100_hbm_survey_and_unlock_skip_fused_off_fbpas() {
// Issue #399: three-stack CMP 100-210. The survey used to demand all 16 partitions.
let mut gpu = cmp_100_210_three_stack();
assert_eq!(
survey_gv100_hbm_checked(&mut gpu),
Ok(HbmCoeff(0x0001_4102))
);
assert_eq!(gv100_enabled_fbpa_mask(&mut gpu), Some(0xfff0));
// Unlock, live step and restore run on the 12 enabled partitions: the post-write
// probe reads FBPA 4, not fused-off FBPA 0, and the lock wait skips FBPA 0..=3.
let (mut sess, st) = HbmSession::begin(&mut gpu, 82, |_| {});
assert_eq!(
st,
HbmUnlockStatus::Unlocked {
from: HbmCoeff(0x0001_4102),
to: HbmCoeff(0x0001_5202),
lock_us: 0,
}
);
assert_eq!(sess.outcome(st), HbmOutcome::Unlocked);
assert_eq!(sess.current_khz, 1_107_000);
assert_eq!(gpu.coeff[4..], [0x0001_5202; 12]);
assert!(matches!(
sess.on_instability(&mut gpu, |_| {}),
Some(HbmUnlockStatus::Unlocked { to, .. }) if to.ndiv() == 78
));
assert!(sess.restore(&mut gpu, |_| {}));
assert_eq!(sess.current_khz, 877_500);
assert_eq!(gpu.coeff[..4], [0xbadf_2010; 4]);
assert_eq!(gpu.coeff[4..], [0x0001_4102; 12]);
assert!(!gpu.read_forbidden);
// An enabled partition must still be readable, locked and in agreement; the
// reference coefficient is the first enabled partition's.
let mut unlocked = cmp_100_210_three_stack();
unlocked.cfg[4] = 0x0000_0009;
assert_eq!(
survey_gv100_hbm_checked(&mut unlocked),
Err(HbmSurveyFault {
kind: HbmSurveyFaultKind::PllUnlocked,
fbpa: 4,
value: 0x0000_0009,
})
);
let mut split = cmp_100_210_three_stack();
split.coeff[15] = 0x0001_5202;
assert_eq!(
survey_gv100_hbm_checked(&mut split),
Err(HbmSurveyFault {
kind: HbmSurveyFaultKind::CoeffMismatch,
fbpa: 15,
value: 0x0001_5202,
})
);
let mut dead = cmp_100_210_three_stack();
dead.cfg[9] = 0xbadf_1100;
assert_eq!(survey_gv100_hbm(&mut dead), None);
// Unreadable or out-of-range floorsweep inputs refuse the card before any write.
for (num_fbpas, fbio_fuse, kind, value) in [
(0u32, 0u32, HbmSurveyFaultKind::FbpaCountUnusable, 0),
(17, 0, HbmSurveyFaultKind::FbpaCountUnusable, 17),
(u32::MAX, 0, HbmSurveyFaultKind::FbpaCountUnusable, u32::MAX),
(
0xbadf_1100,
0,
HbmSurveyFaultKind::FbpaCountUnusable,
0xbadf_1100,
),
(
0x10,
0xbadf_1100,
HbmSurveyFaultKind::FbioFuseUnusable,
0xbadf_1100,
),
(0x10, 0xffff, HbmSurveyFaultKind::FbioFuseUnusable, 0xffff),
] {
let mut gpu = MockGv100::new(65);
gpu.num_fbpas = num_fbpas;
gpu.fbio_fuse = fbio_fuse;
let fault = HbmSurveyFault {
kind,
fbpa: HbmSurveyFault::NO_FBPA,
value,
};
assert_eq!(gv100_enabled_fbpa_mask(&mut gpu), None);
assert_eq!(survey_gv100_hbm_checked(&mut gpu), Err(fault));
let (sess, st) = HbmSession::begin(&mut gpu, 82, |_| {});
assert_eq!(sess.outcome(st), HbmOutcome::SurveyFailed);
assert_eq!(sess.survey_fault, Some(fault));
assert!(!restore_gv100_hbm(&mut gpu, HbmCoeff(0x0001_4102), |_| {}));
assert_eq!(gpu.writes, 0);
}
// A chip reporting fewer partitions is surveyed on those only.
let mut eight = MockGv100::new(65);
eight.num_fbpas = 8;
eight.cfg[8..].fill(0xbadf_2010);
eight.coeff[8..].fill(0xbadf_2010);
assert_eq!(gv100_enabled_fbpa_mask(&mut eight), Some(0x00ff));
assert_eq!(survey_gv100_hbm(&mut eight), Some(HbmCoeff(0x0001_4102)));
}
#[test]
fn gv100_hbm_mask_lost_before_the_target_write_is_not_a_rollback() {
// FBIO fuse reads: 1 start survey, 2 unlock survey, 3 program_coeff before the target
// write (fails here: nothing is written and no rollback write is issued), 4 the survey
// after.
let mut gpu = MockGlitchGv100::new(FUSE_OPT_FBIO, 3, 4, 0xbadf_1100);
gpu.gpu.gpu.fbio_fuse = 0xf;
gpu.gpu.gpu.cfg = [0x0000_0029; FBPA_COUNT];
gpu.gpu.gpu.cfg[..4].fill(0xbadf_2010);
gpu.gpu.gpu.coeff[..4].fill(0xbadf_2010);
let (sess, st) = HbmSession::begin(&mut gpu, 82, |_| {});
assert_eq!(st, HbmUnlockStatus::FailedRolledBack);
assert_eq!(sess.outcome(st), HbmOutcome::SurveyFailed);
assert_eq!(
sess.survey_fault,
Some(HbmSurveyFault {
kind: HbmSurveyFaultKind::FbioFuseUnusable,
fbpa: HbmSurveyFault::NO_FBPA,
value: 0xbadf_1100,
})
);
// Neither target nor rollback wrote: the PLL stays completely untouched.
assert_eq!(gpu.gpu.gpu.writes, 0);
assert_eq!(gpu.gpu.gpu.coeff[4..], [0x0001_4102; 12]);
assert_eq!(sess.current_khz, 877_500);
}
#[test]
fn gv100_hbm_restore_uses_cached_mask_when_fuse_read_glitches_but_honors_canary() {
let mut gpu = cmp_100_210_three_stack();
let (mut sess, st) = HbmSession::begin(&mut gpu, 82, |_| {});
assert!(matches!(st, HbmUnlockStatus::Unlocked { .. }));
assert_eq!(sess.enabled_fbpa_mask, Some(0xfff0));
assert_eq!(gpu.coeff[4..], [0x0001_5202; 12]);
// Even if FUSE_OPT_FBIO or PTOP_SCAL_NUM_FBPAS reads back a PRI error while tuned,
// live ECC backoff (on_instability) and sysfs return to baseline (on_user_write(0))
// fall back to the cached floorsweep mask instead of stranding the elevated clock.
gpu.fbio_fuse = 0xbadf_1100;
gpu.num_fbpas = 0xbadf_2010;
let stepped = sess.on_instability(&mut gpu, |_| {});
assert!(matches!(
stepped,
Some(HbmUnlockStatus::Unlocked { to, .. }) if to.ndiv() == 78
));
assert_eq!(sess.state, HbmSessionState::Ready);
assert_eq!(sess.current_khz, 1_053_000);
assert_eq!(gpu.coeff[4..], [0x0001_4e02; 12]);
let returned = sess.on_user_write(&mut gpu, 0, |_| {});
assert!(matches!(
returned,
Some(HbmUnlockStatus::Unlocked { to, .. }) if to.ndiv() == 65
));
assert_eq!(sess.state, HbmSessionState::Ready);
assert_eq!(sess.current_khz, 877_500);
assert_eq!(gpu.coeff[4..], [0x0001_4102; 12]);
// Re-raise with healthy fuses, then verify teardown restore() under a fuse glitch.
gpu.fbio_fuse = 0xf;
gpu.num_fbpas = FBPA_COUNT as u32;
assert!(matches!(
sess.on_user_write(&mut gpu, 82, |_| {}),
Some(HbmUnlockStatus::Unlocked { to, .. }) if to.ndiv() == 82
));
gpu.fbio_fuse = 0xbadf_1100;
gpu.num_fbpas = 0xbadf_2010;
assert!(sess.restore(&mut gpu, |_| {}));
assert_eq!(gpu.coeff[4..], [0x0001_4102; 12]);
assert_eq!(sess.current_khz, 877_500);
assert_eq!(sess.survey_fault, None);
// If PMC_BOOT_0 fails the canary, restore() still refuses without writing.
gpu.boot0 = 0xffff_ffff;
let writes_before = gpu.writes;
assert!(!sess.restore(&mut gpu, |_| {}));
assert_eq!(gpu.writes, writes_before);
assert_eq!(sess.state, HbmSessionState::ClockUnknown);
assert_eq!(
sess.survey_fault,
Some(HbmSurveyFault {
kind: HbmSurveyFaultKind::CanaryMismatch,
fbpa: HbmSurveyFault::NO_FBPA,
value: 0xffff_ffff,
})
);
}
#[test]
fn hbm_survey_reports_the_first_failed_check() {
let mut ok = MockGv100::new(65);
assert_eq!(survey_gv100_hbm_checked(&mut ok), Ok(HbmCoeff(0x0001_4102)));
// FBPA 0..=3 do not answer but the fuse leaves them enabled: refused at FBPA 0.
let mut swept = cmp_100_210_three_stack();
swept.fbio_fuse = 0;
assert_eq!(
survey_gv100_hbm_checked(&mut swept),
Err(HbmSurveyFault {
@ -2096,7 +2544,30 @@ mod tests {
value: 0x1620_00a1,
})
);
for gpu in [&ok, &swept, &coeff_bad, &unlocked, &split, &other] {
let mut no_count = MockGv100::new(65);
no_count.num_fbpas = 0;
assert_eq!(
survey_gv100_hbm_checked(&mut no_count),
Err(HbmSurveyFault {
kind: HbmSurveyFaultKind::FbpaCountUnusable,
fbpa: HbmSurveyFault::NO_FBPA,
value: 0,
})
);
let mut all_fused = MockGv100::new(65);
all_fused.fbio_fuse = 0xffff;
assert_eq!(
survey_gv100_hbm_checked(&mut all_fused),
Err(HbmSurveyFault {
kind: HbmSurveyFaultKind::FbioFuseUnusable,
fbpa: HbmSurveyFault::NO_FBPA,
value: 0xffff,
})
);
for gpu in [
&ok, &swept, &coeff_bad, &unlocked, &split, &other, &no_count, &all_fused,
] {
assert_eq!(gpu.writes, 0);
assert!(!gpu.read_forbidden);
}
@ -2118,12 +2589,16 @@ mod tests {
assert_eq!(HbmSurveyFaultKind::CoeffUnreadable as u32, 3);
assert_eq!(HbmSurveyFaultKind::PllUnlocked as u32, 4);
assert_eq!(HbmSurveyFaultKind::CoeffMismatch as u32, 5);
assert_eq!(HbmSurveyFaultKind::FbpaCountUnusable as u32, 6);
assert_eq!(HbmSurveyFaultKind::FbioFuseUnusable as u32, 7);
// Issue #399: with FBPA 0..=3 unreadable the start fails in the survey, for a requested
// target and for the default 0 alike, and the session carries the reason. Before, this
// start and a PLL that would not lock were the same silent `FailedRolledBack`.
// Issue #399: with FBPA 0..=3 unreadable while the fuse leaves them enabled, the start
// fails in the survey, for a requested target and for the default 0 alike, and the
// session carries the reason. Before, this start and a PLL that would not lock were
// the same silent `FailedRolledBack`.
for target in [82u8, 0u8] {
let mut swept = cmp_100_210_three_stack();
swept.fbio_fuse = 0;
let (sess, st) = HbmSession::begin(&mut swept, target, |_| {});
assert_eq!(st, HbmUnlockStatus::FailedRolledBack);
assert_eq!(sess.outcome(st), HbmOutcome::SurveyFailed);