Skip to content

Commit 8eb00bb

Browse files
committed
soc: apple: sep: abort suspend when capture workers fail to drain
The six-second drain budget does not bound all sequential sensor and SBIO transactions. Continuing after it expires lets live workers access providers that the suspend core is about to power down. Return EBUSY through the Rust callback and the PM notifier instead. Successful preparation now requires the capture count to reach zero. Clear the suspend hold and wake waiting starts directly on failure: the PM notifier rollback does not call the notifier that rejected the prepare event. Keep the same bounded drain rather than extending the timeout or pretending cancellation proves hardware quiescence. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
1 parent 2cf2b0a commit 8eb00bb

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

‎drivers/soc/apple/pm.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,31 @@ use crate::SepData;
2121
static SEP: AtomicPtr<c_void> = AtomicPtr::new(core::ptr::null_mut());
2222

2323
extern "C" {
24-
fn sep_pm_register(event: unsafe extern "C" fn(bool)) -> c_int;
24+
fn sep_pm_register(event: unsafe extern "C" fn(bool) -> c_int) -> c_int;
2525
fn sep_pm_unregister();
2626
}
2727

2828
/// # Safety
2929
/// Called by `pm_shim.c` from the PM notifier chain, in process context.
30-
unsafe extern "C" fn pm_event(entering: bool) {
30+
unsafe extern "C" fn pm_event(entering: bool) -> c_int {
3131
let ptr = SEP.load(Ordering::Acquire);
3232
if ptr.is_null() {
33-
return;
33+
return 0;
3434
}
3535
// SAFETY: produced by `into_foreign` in `register`, and reclaimed by
3636
// `unregister` only after `sep_pm_unregister` has waited out any running
3737
// notifier call, so it is live for this borrow.
3838
let sep = unsafe { <Arc<SepData> as ForeignOwnable>::borrow(ptr) };
3939
if entering {
40-
sep.sleep_prepare();
40+
if let Err(error) = sep.sleep_prepare() {
41+
// A failing notifier is not included in the PM chain's rollback.
42+
sep.sleep_finished();
43+
return error.to_errno();
44+
}
4145
} else {
4246
sep.sleep_finished();
4347
}
48+
0
4449
}
4550

4651
pub(crate) fn register(sep: Arc<SepData>) -> Result<()> {

‎drivers/soc/apple/pm_shim.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
#include "shim.h"
1212

13-
static void (*sep_pm_event)(bool entering);
13+
static int (*sep_pm_event)(bool entering);
1414

1515
static int sep_pm_notify(struct notifier_block *nb, unsigned long action,
1616
void *data)
1717
{
18-
void (*event)(bool entering) = READ_ONCE(sep_pm_event);
18+
int (*event)(bool entering) = READ_ONCE(sep_pm_event);
1919

2020
if (!event)
2121
return NOTIFY_DONE;
@@ -24,8 +24,7 @@ static int sep_pm_notify(struct notifier_block *nb, unsigned long action,
2424
case PM_SUSPEND_PREPARE:
2525
case PM_HIBERNATION_PREPARE:
2626
case PM_RESTORE_PREPARE:
27-
event(true);
28-
return NOTIFY_OK;
27+
return notifier_from_errno(event(true));
2928
case PM_POST_SUSPEND:
3029
case PM_POST_HIBERNATION:
3130
case PM_POST_RESTORE:
@@ -40,7 +39,7 @@ static struct notifier_block sep_pm_nb = {
4039
.notifier_call = sep_pm_notify,
4140
};
4241

43-
int sep_pm_register(void (*event)(bool entering))
42+
int sep_pm_register(int (*event)(bool entering))
4443
{
4544
int ret;
4645

‎drivers/soc/apple/sbio.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ impl SepData {
26272627
/// The system is about to suspend. End any capture in progress, hold new
26282628
/// ones, and wait for the enrol or verify work to stop touching the sensor
26292629
/// before devices go down.
2630-
pub(crate) fn sleep_prepare(&self) {
2630+
pub(crate) fn sleep_prepare(&self) -> Result<()> {
26312631
let woke = {
26322632
let mut session = self.bio_session.lock();
26332633
self.suspending.store(true, Relaxed);
@@ -2646,14 +2646,15 @@ impl SepData {
26462646
if waited >= SLEEP_DRAIN_MS {
26472647
dev_warn!(
26482648
self.dev,
2649-
"Touch ID: a capture was still running {} ms after the system started to sleep; continuing\n",
2649+
"Touch ID: capture did not drain within {} ms; aborting suspend\n",
26502650
SLEEP_DRAIN_MS
26512651
);
2652-
return;
2652+
return Err(EBUSY);
26532653
}
26542654
kernel::time::delay::fsleep(kernel::time::Delta::from_millis(10));
26552655
waited += 10;
26562656
}
2657+
Ok(())
26572658
}
26582659

26592660
/// The system has resumed, or the suspend was aborted.

‎drivers/soc/apple/shim.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void sep_cancel_delayed_work_sync(void *work);
2525

2626
/* -- pm_shim.c ---------------------------------------------------------- */
2727

28-
int sep_pm_register(void (*event)(bool entering));
28+
int sep_pm_register(int (*event)(bool entering));
2929
void sep_pm_unregister(void);
3030

3131
/* -- hwrng_shim.c ------------------------------------------------------- */

0 commit comments

Comments
 (0)