Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Documentation/ABI/testing/sysfs-driver-apple-sep
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,35 @@ Description:
lowercase hex digits once pnon reads "read", and
"unavailable" before then.

What: /sys/bus/platform/devices/<unit>.sep/diag/xars
Date: November 2026
KernelVersion: 7.3
Contact: Ryan Murray <ryan@aurorasilicon.org>
Description:
(RO) The enclave's xART control service (endpoint xars).
The driver sends nothing on xars at boot, idle or system
sleep, and registers its out-of-line buffers lazily. On an
orderly reboot, halt or power-off, a blocking reboot notifier
sends the storage-volume unmount notification followed by a
non-forced cached-state flush while xarm continues servicing
enclave-initiated writes, then closes the host xART store.

======== =============================================
pending Bring-up has not ended yet.
ready The endpoint is offered with its known layout
and the xART store is writable; the shutdown
barrier is armed.
readonly The endpoint is offered, but the xART store
is read-only (for example, during initrd
keystore_only attach); the barrier will not
run until writes are enabled.
absent The endpoint was not offered or advertised an
unknown layout; left alone.
flushed The shutdown barrier completed cleanly.
failed The shutdown barrier failed or ended
indeterminate; the kernel log says why.
======== =============================================

What: /sys/bus/platform/devices/<unit>.sep/diag/sse
What: /sys/bus/platform/devices/<unit>.sep/diag/hibe
What: /sys/bus/platform/devices/<unit>.sep/diag/skdl
Expand Down
22 changes: 22 additions & 0 deletions drivers/soc/apple/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern "C" {
fn sep_diag_set_hwrng(registered: bool);
fn sep_diag_set_stac(state: c_int);
fn sep_diag_set_pnon(state: c_int, digest: *const u8, len: usize);
fn sep_diag_set_xars(state: c_int);
fn sep_diag_set_offer(endpoint: u8, state: c_int);
fn sep_diag_sse_event() -> c_uint;
fn sep_diag_xarm_failed() -> c_uint;
Expand Down Expand Up @@ -423,6 +424,27 @@ pub(crate) fn pnon(state: Pnon, digest: Option<&[u8; crate::pnon::DIGEST_LEN]>)
unsafe { sep_diag_set_pnon(state as c_int, ptr, len) };
}

/// The xART control endpoint (`xars`), as `SEP_DIAG_XARS_*` in `shim.h` spells it.
#[derive(Clone, Copy)]
pub(crate) enum Xars {
/// Endpoint offered with known layout and xART writable; shutdown barrier armed.
Ready = 1,
/// Endpoint offered with known layout, but xART is read-only.
ReadOnly = 2,
/// Endpoint absent or advertises an unknown layout.
Absent = 3,
/// Shutdown unmount and non-forced flush barrier completed.
Flushed = 4,
/// Shutdown barrier failed or ended indeterminate.
Failed = 5,
}

/// Reports the `xars` endpoint / shutdown-barrier state.
pub(crate) fn xars(state: Xars) {
// SAFETY: no preconditions; updates one word.
unsafe { sep_diag_set_xars(state as c_int) };
}

/// An endpoint the driver checks at bring-up and sends nothing to, as
/// `SEP_DIAG_OFFER_*` in `shim.h` spells the reported states.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
36 changes: 36 additions & 0 deletions drivers/soc/apple/diag_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static struct {
atomic_t stac;
atomic_t stac_onlines;
atomic_t pnon;
atomic_t xars;
atomic_t sse;
atomic_t sse_events;
atomic_t hibe;
Expand Down Expand Up @@ -670,6 +671,35 @@ static ssize_t local_policy_digest_show(struct device *dev,
}
static DEVICE_ATTR_ADMIN_RO(local_policy_digest);

static ssize_t xars_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
const char *state;

switch (atomic_read(&sep_diag.xars)) {
case SEP_DIAG_XARS_READY:
state = "ready";
break;
case SEP_DIAG_XARS_READONLY:
state = "readonly";
break;
case SEP_DIAG_XARS_ABSENT:
state = "absent";
break;
case SEP_DIAG_XARS_FLUSHED:
state = "flushed";
break;
case SEP_DIAG_XARS_FAILED:
state = "failed";
break;
default:
state = "pending";
break;
}
return sysfs_emit(buf, "%s\n", state);
}
static DEVICE_ATTR_RO(xars);

static ssize_t sep_diag_offer_emit(char *buf, atomic_t *state)
{
switch (atomic_read(state)) {
Expand Down Expand Up @@ -803,6 +833,7 @@ static struct attribute *sep_diag_attrs[] = {
&dev_attr_stac_onlines.attr,
&dev_attr_pnon.attr,
&dev_attr_local_policy_digest.attr,
&dev_attr_xars.attr,
&dev_attr_sse.attr,
&dev_attr_sse_events.attr,
&dev_attr_hibe.attr,
Expand Down Expand Up @@ -916,6 +947,11 @@ void sep_diag_set_pnon(int state, const u8 *digest, size_t len)
atomic_set(&sep_diag.pnon, state);
}

void sep_diag_set_xars(int state)
{
atomic_set(&sep_diag.xars, state);
}

unsigned int sep_diag_xarm_failed(void)
{
return (unsigned int)atomic_inc_return(&sep_diag.xarm_failures);
Expand Down
13 changes: 10 additions & 3 deletions drivers/soc/apple/pm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern "C" {
sleep: unsafe extern "C" fn() -> c_int,
wake: unsafe extern "C" fn(),
told: unsafe extern "C" fn() -> bool,
shutdown: unsafe extern "C" fn(),
) -> c_int;
fn sep_pm_unregister();
fn sep_pm_keep_domains(dev: *mut c_void) -> c_int;
Expand Down Expand Up @@ -278,6 +279,12 @@ unsafe extern "C" fn pm_told() -> bool {
with_sep(false, |sep| sep.sleep_gate() == SleepGate::Told)
}

/// # Safety
/// Called by `pm_shim.c` from the blocking reboot notifier chain, in process context.
unsafe extern "C" fn pm_shutdown() {
with_sep((), |sep| sep.xars_shutdown_barrier());
}

pub(crate) fn register(sep: Arc<SepData>) -> Result<()> {
let dev: *mut c_void = sep.dev.as_raw().cast();
let ptr = sep.into_foreign();
Expand All @@ -296,9 +303,9 @@ pub(crate) fn register(sep: Arc<SepData>) -> Result<()> {
return Err(EBUSY);
}

// SAFETY: the shim stores the callback and registers a notifier block
// that lives for the module's lifetime.
let rc = unsafe { sep_pm_register(dev, pm_event, pm_sleep, pm_wake, pm_told) };
// SAFETY: the shim stores the callbacks and registers notifier blocks
// that live for the module's lifetime.
let rc = unsafe { sep_pm_register(dev, pm_event, pm_sleep, pm_wake, pm_told, pm_shutdown) };
if rc != 0 {
let raw = SEP.swap(core::ptr::null_mut(), Ordering::AcqRel);
if !raw.is_null() {
Expand Down
50 changes: 44 additions & 6 deletions drivers/soc/apple/pm_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/pm.h>
#include <linux/panic.h>
#include <linux/pm_domain.h>
#include <linux/reboot.h>
#include <linux/regmap.h>
#include <linux/soc/apple/dart.h>
#include <linux/soc/apple/mailbox.h>
Expand Down Expand Up @@ -58,6 +59,7 @@ static void (*sep_pm_event)(bool entering);
static int (*sep_pm_sleep)(void);
static void (*sep_pm_wake)(void);
static bool (*sep_pm_told)(void);
static void (*sep_pm_shutdown)(void);
/* In the device's .suspend, the only caller that can leave the request to the sleep. */
static bool sep_pm_suspending;

Expand Down Expand Up @@ -91,6 +93,29 @@ static struct notifier_block sep_pm_nb = {
.notifier_call = sep_pm_notify,
};

static int sep_reboot_notify(struct notifier_block *nb, unsigned long action,
void *data)
{
void (*shutdown)(void) = READ_ONCE(sep_pm_shutdown);

if (!shutdown)
return NOTIFY_DONE;

switch (action) {
case SYS_RESTART:
case SYS_HALT:
case SYS_POWER_OFF:
shutdown();
return NOTIFY_OK;
default:
return NOTIFY_DONE;
}
}

static struct notifier_block sep_reboot_nb = {
.notifier_call = sep_reboot_notify,
};

/* The enclave's own domain is the first one its node lists. */
static int sep_pm_domain(struct device *dev, struct regmap **regmap, u32 *offset)
{
Expand Down Expand Up @@ -520,34 +545,47 @@ const struct dev_pm_ops sep_pm_ops = {
};

int sep_pm_register(void *ptr, void (*event)(bool entering), int (*sleep)(void),
void (*wake)(void), bool (*told)(void))
void (*wake)(void), bool (*told)(void),
void (*shutdown)(void))
{
int ret;

WRITE_ONCE(sep_pm_event, event);
WRITE_ONCE(sep_pm_sleep, sleep);
WRITE_ONCE(sep_pm_wake, wake);
WRITE_ONCE(sep_pm_told, told);
WRITE_ONCE(sep_pm_shutdown, shutdown);
ret = register_pm_notifier(&sep_pm_nb);
if (ret)
goto err_clear;

ret = register_reboot_notifier(&sep_reboot_nb);
if (ret) {
WRITE_ONCE(sep_pm_event, NULL);
WRITE_ONCE(sep_pm_sleep, NULL);
WRITE_ONCE(sep_pm_wake, NULL);
WRITE_ONCE(sep_pm_told, NULL);
return ret;
unregister_pm_notifier(&sep_pm_nb);
goto err_clear;
}

return 0;

err_clear:
WRITE_ONCE(sep_pm_event, NULL);
WRITE_ONCE(sep_pm_sleep, NULL);
WRITE_ONCE(sep_pm_wake, NULL);
WRITE_ONCE(sep_pm_told, NULL);
WRITE_ONCE(sep_pm_shutdown, NULL);
return ret;
}

/* Returns only once no notifier call is still running. */
void sep_pm_unregister(void)
{
unregister_reboot_notifier(&sep_reboot_nb);
unregister_pm_notifier(&sep_pm_nb);
WRITE_ONCE(sep_pm_event, NULL);
WRITE_ONCE(sep_pm_sleep, NULL);
WRITE_ONCE(sep_pm_wake, NULL);
WRITE_ONCE(sep_pm_told, NULL);
WRITE_ONCE(sep_pm_shutdown, NULL);
}

static void sep_pm_release_domains(void *data)
Expand Down
Loading
Loading