Skip to content

core: ffa: add direct request v2 support#7840

Merged
jenswikl merged 1 commit into
OP-TEE:masterfrom
sah01Kaushal:directreq2-upstream
Jun 17, 2026
Merged

core: ffa: add direct request v2 support#7840
jenswikl merged 1 commit into
OP-TEE:masterfrom
sah01Kaushal:directreq2-upstream

Conversation

@sah01Kaushal

Copy link
Copy Markdown

Add support for FF-A direct request/response v2 messages for secure partitions.

Direct request v2 carries the target service UUID in x2/x3 and uses x4-x17 for the payload, so preserve the full AArch64 FF-A register set when entering and returning from secure partitions.

Advertise DirectReq2/Resp2 to normal-world and secure partition callers, and expose the corresponding partition properties for AArch64 secure partitions that support direct messaging. Validate DirectReq2 messages by checking sender and receiver capabilities and matching non-nil UUIDs against the destination partition UUID.

Logical secure partitions do not support DirectReq2 yet, so reject Req2 messages targeting LSPs.

Comment thread core/arch/arm/kernel/secure_partition.c Outdated
}

if (ffa_version != FFA_VERSION_1_0 && ffa_version != FFA_VERSION_1_1) {
if (ffa_version != FFA_VERSION_1_0 &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if (ffa_version < FFA_VERSION_1_0 || ffa_version > FFA_VERSION_1_2)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change.

Comment thread core/arch/arm/kernel/secure_partition.c Outdated

#ifdef ARM64
memcpy(ctx->sp_regs.x, args->a, sizeof(args->a));
#else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working for ARM32, so we should replace the assignment with the memcpy instead.

Same further down in this function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old ARM32 path in this patch still used x[] even though ARM32 thread_ctx_regs does not have that field. I replaced it with a struct copy, and made the same change at the second copy site.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove the ARM32 part entirely if you want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the ARM32 part entirely.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed entirely. Thanks!

Comment thread core/arch/arm/kernel/spmc_sp_handler.c Outdated
static void direct_req2_uuid_from_args(struct thread_smc_1_2_regs *args,
uint32_t uuid_words[4])
{
uuid_words[0] = (uint32_t)args->a2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use high32_from_64() and low32_from_64() to extract the words.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change.

Comment thread core/arch/arm/kernel/spmc_sp_handler.c Outdated
!uuid_words[2] && !uuid_words[3]);
}

#ifdef ARM64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is only compiled for ARM64, so the ifdef isn't needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the ifdefs for ARM64

Comment thread core/arch/arm/kernel/spmc_sp_handler.c Outdated
struct sp_session *dst = NULL;
struct spmc_lsp_desc *lsp = NULL;
TEE_Result res = FFA_OK;
bool is_req2 = args->a0 == FFA_MSG_SEND_DIRECT_REQ2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it simple, I'd prefer:

uint32_t caller_props = 0;
uint32_t dst_prots = 0

if (args->a0 == FFA_MSG_SEND_DIRECT_REQ2) {
        caller_props = FFA_PART_PROP_DIRECT_REQ2_SEND;
        dst_props = FFA_PART_PROP_DIRECT_REQ2_RECV;
} else {
        caller_props = FFA_PART_PROP_DIRECT_REQ_SEND;
        dst_props = FFA_PART_PROP_DIRECT_REQ_RECV;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this form.

Comment thread core/arch/arm/kernel/spmc_sp_handler.c Outdated
}

if (args->a2 & FFA_MSG_FLAG_FRAMEWORK) {
if (is_resp2) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (args->a0 == FFA_MSG_SEND_DIRECT_RESP2) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread core/arch/arm/kernel/thread.c Outdated
static void init_regs_spmc(struct thread_ctx *thread,
const struct thread_smc_1_2_regs *args, void *pc)
{
#ifdef ARM64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With CFG_SECURE_PARTITION y, we can depend on ARM64 to be defined.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the #ifdef ARM64

Comment thread core/arch/arm/kernel/thread.c Outdated
#ifdef ARM64
size_t n = 0;

thread->regs.pc = (uint64_t)pc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer casting to vaddr_t when converting a pointer into an integer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to vaddr_t

Comment thread core/arch/arm/kernel/thread.c Outdated
for (; n < ARRAY_SIZE(thread->regs.x); n++)
thread->regs.x[n] = 0;

thread->regs.x[29] = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be cleared in the loop above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment thread core/arch/arm/kernel/thread_spmc.c Outdated
FFA_PART_PROP_DIRECT_REQ_SEND |
FFA_PART_PROP_INDIRECT_MSGS;
/* In FF-A 1.1 only bits [8:0] are defined, let's mask others */
else if (ffa_vers < FFA_VERSION_1_2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit broken. How about something like this instead?

/* mask out bits introduced with FF-A version 1.1 */
if (ffa_vers < FFA_VERSION_1_1)
...

/* mask out bits introduced with FF-A version 1.2 */
if (ffa_vers < FFA_VERSION_1_2)
...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the switch to this form

Comment thread core/arch/arm/kernel/secure_partition.c Outdated

if (ffa_version != FFA_VERSION_1_0 && ffa_version != FFA_VERSION_1_1) {
if (ffa_version < FFA_VERSION_1_0 ||
ffa_version > FFA_VERSION_1_2) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fold up, it fits on one line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread core/arch/arm/kernel/secure_partition.c Outdated

#ifdef ARM64
memcpy(ctx->sp_regs.x, args->a, sizeof(args->a));
#else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the ARM32 part entirely.

Comment thread core/arch/arm/kernel/spmc_sp_handler.c Outdated
switch (resp_fid) {
case FFA_MSG_SEND_DIRECT_RESP_32:
return req_fid == FFA_MSG_SEND_DIRECT_REQ_32;
#ifdef ARM64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ifdef/endif isn't needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the ifdef/endif

@jenswikl

jenswikl commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Looks good, please squash in the fixups and apply:
Reviewed-by: Jens Wiklander <jenswi@kernel.org>

Add support for FF-A direct request/response v2 messages for secure
partitions.

Direct request v2 carries the target service UUID in x2/x3 and uses
x4-x17 for the payload, so preserve the full AArch64 FF-A register set
when entering and returning from secure partitions.

Advertise DirectReq2/Resp2 to normal-world and secure partition callers,
and expose the corresponding partition properties for AArch64 secure
partitions that support direct messaging. Validate DirectReq2 messages
by checking sender and receiver capabilities and matching non-nil UUIDs
against the destination partition UUID.

Logical secure partitions do not support DirectReq2 yet, so reject Req2
messages targeting LSPs.

Signed-off-by: Arteom Katkov <arteom.katkov@arm.com>
Signed-off-by: Sahil Kaushal <Sahil.Kaushal@arm.com>
Reviewed-by: Jens Wiklander <jenswi@kernel.org>
@sah01Kaushal sah01Kaushal force-pushed the directreq2-upstream branch from 0d70e5b to 73947a6 Compare June 16, 2026 14:12
@sah01Kaushal

Copy link
Copy Markdown
Author

Looks good, please squash in the fixups and apply: Reviewed-by: Jens Wiklander <jenswi@kernel.org>

Thank you very much for the review, Jens! I have squashed the fixups in and pushed again.

@jenswikl

Copy link
Copy Markdown
Contributor

I'll merge this when the CI checks have passed.

@jenswikl jenswikl merged commit 1428386 into OP-TEE:master Jun 17, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants