[PATCH v4 0/3] Add Altera SoCFPGA Crypto Service (FCS) driver

From: hang . suan . wang

Date: Fri Sep 04 2026 - 14:52:17 EST


From: Hang Suan Wang <hang.suan.wang@xxxxxxxxxx>

This series adds Linux support for one of the Altera SoCFPGA Crypto Service
(FCS): Secure Data Object Service (SDOS). FCS is a runtime cryptographic
interface provided by the Secure Device Manager (SDM).

The SDM is the hardware security controller in Altera SoCFPGA devices. Host
software reaches it through the existing stratix10-svc mailbox, which uses
Arm Trusted Firmware SIP SMC calls. In this series does not expose the rest
of FCS (RNG, AES, SHA, key management, and so on).

SDOS protects data at rest. The SDM encrypts and decrypts using a key
derived from a device-unique SDOS root key that never leaves the secure
boundary. The host supplies plaintext (or an authenticated object) and
never handles raw key material. A primary use case is black-key
provisioning.

SDOS requests use the stratix10-svc asynchronous SIP SMC path. Source and
destination buffers are allocated from the service-layer memory pool, and
their physical addresses are passed to the SDM. Each request opens an SDM
crypto session, runs under a lock (one in-flight transaction), and closes
the session afterwards.

The series is organized as follows:
- Patch 1 (prerequisite) enlarges the stratix10-svc SMC argument array so
the asynchronous FCS SDOS command can pass its full set of parameters.

- Patch 2 (prerequisite) extends the stratix10-svc service layer with the
FCS command codes and matching SIP SMC function IDs, adds the Agilex 5
(intel,agilex5-svc) match, and registers a "stratix10-fcs" platform
device that an FCS client driver binds to.

- Patch 3 adds the FCS driver implementing SDOS encrypt/decrypt. It is
exposed as a misc device (/dev/socfpga-fcs) via ioctl FCS_IOC_SDOS. The
crypto session is opened and closed in the kernel and is not part of the
user ABI.

Testing:
- Built for arm64 (defconfig + CONFIG_ALTERA_SOCFPGA_FCS=m).
- Tested on an Agilex 5 SoC FPGA board (SDOS root key provisioned).
SDOS encrypt/decrypt round-trip; the decrypted output matches the
original 32-byte plaintext:

root@agilex5e:~# hexdump -v -e '/1 "%02x "' secret.bin
38 61 39 36 38 38 65 31 64 65 35 37 38 33 62 34
39 37 32 65 33 31 64 37 63 65 30 37 30 63 31 35

root@agilex5e:~# ./fcs_client -E -i secret.bin -o enc.bin -d 0x1234 -r
0xabcd
root@agilex5e:~# ./fcs_client -D -i enc.bin -o sdos_decrypt.bin

root@agilex5e:~# hexdump -v -e '/1 "%02x "' sdos_decrypt.bin
38 61 39 36 38 38 65 31 64 65 35 37 38 33 62 34
39 37 32 65 33 31 64 37 63 65 30 37 30 63 31 35

---
Changes since v3:
- Rebase onto current linux-upstream; register stratix10-fcs beside the
existing socfpga-hwmon child device.
- Drop context_id from the ioctl UAPI; the kernel owns session and context.
- Make FCS state per-device and kref-counted so an open fd can outlive
driver remove (-ENODEV after unbind).
- Copy user buffers in the front-end; the core uses kernel pointers only.
- Use kzalloc_obj() and shorten comments.

Changes since v2:
socfpga-fcs (front-end):
- Replace the sysfs store interface with an ioctl character device
(/dev/socfpga_fcs) using a fixed-width UAPI struct and
compat_ptr_ioctl(), fixing the KASAN out-of-bounds read and the
32-bit incompatibility of casting the sysfs buffer as a pointer.
- Add include/uapi/misc/socfpga-fcs-crypto.h and register the ioctl
magic in Documentation/userspace-api/ioctl/ioctl-number.rst.
- Add a .release handler so a session is torn down if the owning fd
is closed (including on crash).
socfpga-fcs (core):
- Manage the crypto session internally: SDOS opens and closes its own
session; reject a concurrent open with -EBUSY. Removes the
user-visible open/close-session interface and session UUID, fixing
the session-exhaustion/DoS concern.
- Harden the async poll loop: keep polling until the deadline and
always call stratix10_svc_async_done(), fixing the teardown
use-after-free from the previous -EINPROGRESS early-return and the
needless full-timeout block.
- Clear receive_cb only on the synchronous send-error path so a late
firmware response cannot deref a NULL callback.
- Set priv = NULL on all fcs_init() error paths so a later probe is
not permanently rejected with -EBUSY.
- Read the SDOS owner ID with get_unaligned_le64() for correct
little-endian handling on big-endian hosts.
stratix10-svc:
- Enlarge the SMC arguments array so the async SDOS command can
pass its full parameter set (through a11).
- In remove(), unregister the child devices before
stratix10_svc_async_exit() so async_poll() cannot race a freed
handle.

---
Changes since v1:
stratix10-svc:
- Forward result registers (kaddr1) for OPEN_SESSION and SDOS_DATA_EXT
so session ID / output length reach the client.
socfpga-fcs (front-end):
- Publish sysfs via driver.dev_groups on the platform device instead of
a raw kobject under /sys/kernel; callbacks now get a struct device.
socfpga-fcs (core):
- Convert completion timeouts with msecs_to_jiffies(); drop TIMEOUT.
- On SDM-busy timeout (-EAGAIN), abort without async_done() (no id
reuse) and return -EINPROGRESS.
- SDOS: on in-flight abort, leak s_buf/d_buf instead of freeing to
avoid corruption from late firmware DMA.
- Validate the caller UUID early in fcs_sdos_crypt().
- Enforce single instance: -EBUSY in fcs_init() and priv NULL-guard in
fcs_acquire_cmd_ctx().
- Drop the always-zero platform attribute and fcs_get_platform().
- Set/clear receive_cb only around the synchronous send.
- Use device-lifetime priv->completion for the async path (was on-stack).
- Use the local ctx snapshot consistently in fcs_sdos_crypt() and
fcs_session_close().
- Point sdos.dst_size at priv->sdos_output_size, not a stack variable.
socfpga-fcs.h:
- Drop platform/AGILEX5_PLAT; add sdos_output_size.
---

Hang Suan Wang (3):
firmware: stratix10-svc: increase args array
firmware: stratix10-svc: add FCS crypto-service commands for Agilex 5
firmware: socfpga-fcs: add Altera SoCFPGA FCS driver with SDOS

.../userspace-api/ioctl/ioctl-number.rst | 1 +
MAINTAINERS | 9 +
drivers/firmware/Kconfig | 17 +
drivers/firmware/Makefile | 2 +
drivers/firmware/socfpga-fcs-core.c | 684 ++++++++++++++++++
drivers/firmware/socfpga-fcs.c | 294 ++++++++
drivers/firmware/stratix10-svc.c | 65 +-
include/linux/firmware/intel/socfpga-fcs.h | 130 ++++
include/linux/firmware/intel/stratix10-smc.h | 64 ++
.../firmware/intel/stratix10-svc-client.h | 18 +-
include/uapi/misc/socfpga-fcs-crypto.h | 28 +
11 files changed, 1304 insertions(+), 8 deletions(-)
create mode 100644 drivers/firmware/socfpga-fcs-core.c
create mode 100644 drivers/firmware/socfpga-fcs.c
create mode 100644 include/linux/firmware/intel/socfpga-fcs.h
create mode 100644 include/uapi/misc/socfpga-fcs-crypto.h

--
2.43.7