From patchwork Wed Feb 22 15:32:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 398EEC677F1 for ; Wed, 22 Feb 2023 15:34:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499539.770724 (Exim 4.92) (envelope-from ) id 1pUr85-0001dt-Oi; Wed, 22 Feb 2023 15:34:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499539.770724; Wed, 22 Feb 2023 15:34:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr85-0001cu-Ha; Wed, 22 Feb 2023 15:34:01 +0000 Received: by outflank-mailman (input) for mailman id 499539; Wed, 22 Feb 2023 15:33:59 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr83-0001MH-Kj for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:33:59 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 50f65889-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:33:55 +0100 (CET) Received: by mail-lf1-x12a.google.com with SMTP id w27so10582964lfu.4 for ; Wed, 22 Feb 2023 07:33:56 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:33:55 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 50f65889-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ibm5vTCF8Joq270sdlVxryR5ZCLMLLfQMKzjgKlN6DY=; b=wRVF7YizhkRn9nUAGgaCmHQuX6WNYy5/1oDuW4uuCegBbsJWedRwekbKr8MU8MJVQe n88ECzGOtoGhPcN5JvYmrhutBupt1zYH8q5SLPwYgYIKwhOmiJcOHcJGIs2AmJ1OAmYV Hti1rWLWr9ZI5LjIiGJsrnzHJN2UPZMaYp/Zotly4RKnKkuU87G/4dSORQqbwwoJjmjf NlJQEJT7VMZ/gYh/IUtZzVb3UBr7I3hsFPu/NwL1C9GjqhTGWzQG3quRGMAN7EMp8Osu t4GO3ZAy/9USiu8KlCwJPPZ3B3DvBqDhlhqPi/L8+O5+3rW1bSDW9bL+JAFtsGwwdF6P QFbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ibm5vTCF8Joq270sdlVxryR5ZCLMLLfQMKzjgKlN6DY=; b=H3V2r189R/kXKUOcmohB2tr3VLBKKoSXDNoGTzdINLiqYKWBKaQrPmWFP95R5OUKgE bzYeIE/WL4Z+q8p/2MAPKjJeKk3kgKiAjKSjclrlIeFwp0QNI+1wOlVlai/dgqCx4K6n 0284F0Q8yY440T5V5OGVaJ4e+m3kjt5z+VtWteJITPyTVFBkKw4ChIrp+D7HnXJUDa/F j6L2tkKzr68nsgFsyvLu15eWcb2XRNPuWPvFwrQ7FjfZ5+48UEluZ5nLqzJYXjVv3Njg qmEE524DjVHVSpuvZ5SvanAPr+IojPMJBsrBs6tLLLga5mtWZ7F/zx77pOR9Yhq+/fVa 6HQw== X-Gm-Message-State: AO0yUKUheNUnG6Bdx7UlMks+IaR7i038AVeLPUPl9tdpz12OhZgpsuoT ZajLYyAJUWqXOvylAD3RhJLAkepH7pzc8d/NjU8= X-Google-Smtp-Source: AK7set8IyNbdN1JqtHC+inBoApaGbt/v+7RKn27kEmbic8++PN1Is1ZsWBBoYL2JWOwXB4wrfMdC6A== X-Received: by 2002:ac2:5308:0:b0:4dc:8366:2ea0 with SMTP id c8-20020ac25308000000b004dc83662ea0mr3013987lfh.5.1677080035438; Wed, 22 Feb 2023 07:33:55 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Luca Fancellu Subject: [XEN PATCH v7 01/20] xen/arm: smccc: add support for SMCCCv1.2 extended input/output registers Date: Wed, 22 Feb 2023 16:32:58 +0100 Message-Id: <13719ab3736160259ad9245d5d5b5071b8933194.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 SMCCC v1.2 [1] AArch64 allows x0-x17 to be used as both parameter registers and result registers for the SMC and HVC instructions. Arm Firmware Framework for Armv8-A specification makes use of x0-x7 as parameter and result registers. Let us add new interface to support this extended set of input/output registers. This is based on 3fdc0cb59d97 ("arm64: smccc: Add support for SMCCCv1.2 extended input/output registers") by Sudeep Holla from the Linux kernel The SMCCC version reported to the VM is bumped to 1.2 in order to support handling FF-A messages. [1] https://developer.arm.com/documentation/den0028/c/?lang=en Reviewed-by: Luca Fancellu Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis Acked-by: Julien Grall --- xen/arch/arm/arm64/asm-offsets.c | 9 +++++++ xen/arch/arm/arm64/smc.S | 42 ++++++++++++++++++++++++++++++++ xen/arch/arm/include/asm/smccc.h | 40 ++++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 2 +- 4 files changed, 92 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/arm64/asm-offsets.c b/xen/arch/arm/arm64/asm-offsets.c index 7226cd9b2eb0..7adb67a1b81a 100644 --- a/xen/arch/arm/arm64/asm-offsets.c +++ b/xen/arch/arm/arm64/asm-offsets.c @@ -57,6 +57,15 @@ void __dummy__(void) BLANK(); OFFSET(SMCCC_RES_a0, struct arm_smccc_res, a0); OFFSET(SMCCC_RES_a2, struct arm_smccc_res, a2); + OFFSET(ARM_SMCCC_1_2_REGS_X0_OFFS, struct arm_smccc_1_2_regs, a0); + OFFSET(ARM_SMCCC_1_2_REGS_X2_OFFS, struct arm_smccc_1_2_regs, a2); + OFFSET(ARM_SMCCC_1_2_REGS_X4_OFFS, struct arm_smccc_1_2_regs, a4); + OFFSET(ARM_SMCCC_1_2_REGS_X6_OFFS, struct arm_smccc_1_2_regs, a6); + OFFSET(ARM_SMCCC_1_2_REGS_X8_OFFS, struct arm_smccc_1_2_regs, a8); + OFFSET(ARM_SMCCC_1_2_REGS_X10_OFFS, struct arm_smccc_1_2_regs, a10); + OFFSET(ARM_SMCCC_1_2_REGS_X12_OFFS, struct arm_smccc_1_2_regs, a12); + OFFSET(ARM_SMCCC_1_2_REGS_X14_OFFS, struct arm_smccc_1_2_regs, a14); + OFFSET(ARM_SMCCC_1_2_REGS_X16_OFFS, struct arm_smccc_1_2_regs, a16); } /* diff --git a/xen/arch/arm/arm64/smc.S b/xen/arch/arm/arm64/smc.S index 91bae62dd4d2..fc6b676e2ee3 100644 --- a/xen/arch/arm/arm64/smc.S +++ b/xen/arch/arm/arm64/smc.S @@ -27,3 +27,45 @@ ENTRY(__arm_smccc_1_0_smc) stp x2, x3, [x4, #SMCCC_RES_a2] 1: ret + +/* + * void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args, + * struct arm_smccc_1_2_regs *res) + */ +ENTRY(arm_smccc_1_2_smc) + /* Save `res` and free a GPR that won't be clobbered by SMC call */ + stp x1, x19, [sp, #-16]! + + /* Ensure `args` won't be clobbered while loading regs in next step */ + mov x19, x0 + + /* Load the registers x0 - x17 from the struct arm_smccc_1_2_regs */ + ldp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS] + ldp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS] + ldp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS] + ldp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS] + ldp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS] + ldp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS] + ldp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS] + ldp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS] + ldp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS] + + smc #0 + + /* Load the `res` from the stack */ + ldr x19, [sp] + + /* Store the registers x0 - x17 into the result structure */ + stp x0, x1, [x19, #ARM_SMCCC_1_2_REGS_X0_OFFS] + stp x2, x3, [x19, #ARM_SMCCC_1_2_REGS_X2_OFFS] + stp x4, x5, [x19, #ARM_SMCCC_1_2_REGS_X4_OFFS] + stp x6, x7, [x19, #ARM_SMCCC_1_2_REGS_X6_OFFS] + stp x8, x9, [x19, #ARM_SMCCC_1_2_REGS_X8_OFFS] + stp x10, x11, [x19, #ARM_SMCCC_1_2_REGS_X10_OFFS] + stp x12, x13, [x19, #ARM_SMCCC_1_2_REGS_X12_OFFS] + stp x14, x15, [x19, #ARM_SMCCC_1_2_REGS_X14_OFFS] + stp x16, x17, [x19, #ARM_SMCCC_1_2_REGS_X16_OFFS] + + /* Restore original x19 */ + ldp xzr, x19, [sp], #16 + ret diff --git a/xen/arch/arm/include/asm/smccc.h b/xen/arch/arm/include/asm/smccc.h index b3dbeecc90ad..1adcd37443c7 100644 --- a/xen/arch/arm/include/asm/smccc.h +++ b/xen/arch/arm/include/asm/smccc.h @@ -33,6 +33,7 @@ #define ARM_SMCCC_VERSION_1_0 SMCCC_VERSION(1, 0) #define ARM_SMCCC_VERSION_1_1 SMCCC_VERSION(1, 1) +#define ARM_SMCCC_VERSION_1_2 SMCCC_VERSION(1, 2) /* * This file provides common defines for ARM SMC Calling Convention as @@ -265,6 +266,45 @@ void __arm_smccc_1_0_smc(register_t a0, register_t a1, register_t a2, else \ arm_smccc_1_0_smc(__VA_ARGS__); \ } while ( 0 ) + +/* + * struct arm_smccc_1_2_regs - Arguments for or Results from SMC call + * @a0-a17 argument values from registers 0 to 17 + */ +struct arm_smccc_1_2_regs { + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; + unsigned long a4; + unsigned long a5; + unsigned long a6; + unsigned long a7; + unsigned long a8; + unsigned long a9; + unsigned long a10; + unsigned long a11; + unsigned long a12; + unsigned long a13; + unsigned long a14; + unsigned long a15; + unsigned long a16; + unsigned long a17; +}; + +/* + * arm_smccc_1_2_smc() - make SMC calls + * @args: arguments passed via struct arm_smccc_1_2_regs + * @res: result values via struct arm_smccc_1_2_regs + * + * This function is used to make SMC calls following SMC Calling Convention + * v1.2 or above. The content of the supplied param are copied from the + * structure to registers prior to the SMC instruction. The return values + * are updated with the content from registers on return from the SMC + * instruction. + */ +void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args, + struct arm_smccc_1_2_regs *res); #endif /* CONFIG_ARM_64 */ #endif /* __ASSEMBLY__ */ diff --git a/xen/arch/arm/vsmc.c b/xen/arch/arm/vsmc.c index 7335276f3fa1..cd68fa80e98a 100644 --- a/xen/arch/arm/vsmc.c +++ b/xen/arch/arm/vsmc.c @@ -85,7 +85,7 @@ static bool handle_arch(struct cpu_user_regs *regs) switch ( fid ) { case ARM_SMCCC_VERSION_FID: - set_user_reg(regs, 0, ARM_SMCCC_VERSION_1_1); + set_user_reg(regs, 0, ARM_SMCCC_VERSION_1_2); return true; case ARM_SMCCC_ARCH_FEATURES_FID: From patchwork Wed Feb 22 15:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E10F3C636D6 for ; Wed, 22 Feb 2023 15:34:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499540.770727 (Exim 4.92) (envelope-from ) id 1pUr85-0001jD-VE; Wed, 22 Feb 2023 15:34:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499540.770727; Wed, 22 Feb 2023 15:34:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr85-0001fk-Qv; Wed, 22 Feb 2023 15:34:01 +0000 Received: by outflank-mailman (input) for mailman id 499540; Wed, 22 Feb 2023 15:34:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr83-0001MH-V8 for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:00 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 518898e9-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:33:56 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id w27so10583020lfu.4 for ; Wed, 22 Feb 2023 07:33:56 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:33:55 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 518898e9-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6ZsjNSv3BszwMRlZ3430f1yrOpOpDXzM9fMCdGNbTzc=; b=BIq73+5buxXluU82WKlUW/WkRfEhf2NGWpvWB7eFKDakZ9a0NK1xttUZuQLUbSy53x 3qMp5eYpS+922Ioc4H6ovetIJtTwjO6Sr90NMjW+JeT1vVA6GatO0bcSfb1iB1y5Wuli G9vG2m3RDsnYE5M7xKjyVjXFT2joNgz00pLx8EUxkQnQi3+ecoKqUgje5JlyJq7ynOFY 6aetXU/Yjzh7wYAyCt+yS78E+kPdySk+5mQOqA4Q/nVoo0cxpo7jU7gHHcjGlVsADlOx UAcZNVja1R6KetSU/oneOtbvZaXC0kguKoMoBP7ZufnaG8TDIGqj2eGAF+TO7Rz2wn1T AV4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ZsjNSv3BszwMRlZ3430f1yrOpOpDXzM9fMCdGNbTzc=; b=8MaZlQ/+FaKpTo+M+y9jhWlW8BsJfHgHuZmCMCZ4A496wIe9zTwsJXM127PpjOJsuY aCu3MyNAQx08OfwG+/I39Ic+ZrWW68tq07qUHJ1BlH5BcuFvXHI5eIapl5v0ADdkzGDk pEEduWSHAh6LrOOpv596+uSq+zmIYTHNELH0mGRBoF7ry27wzsZ84hKMRc0F30KWc7kF bBhMZnJiGF+mA9bEjZmbteu4TWmTN+Pk6j1CHSWKqO7GshkyYt5ZGsvbSMUQIcrmZOiU 0kMiClIzaQucogZTs4xa+BNqOyoW6sPiDxpAUSfaG+0t34zNGS+IC/9aVlWauKkQlnOl DBww== X-Gm-Message-State: AO0yUKWr217Gm+tcBEptisg/2OCiRU7sylJ0HcwNMstgck48iiHxpFEu 9/zSmi/XPTa+1Lvwk4nW4cJj+Nc2xwsWm8gvJMs= X-Google-Smtp-Source: AK7set9riMwQZMLprPrPH8sv4ujWvOXUCd5+6lnZiau7TuboZfgOu1DHlL74ZRYowGtdO7JjwnwicQ== X-Received: by 2002:a19:550e:0:b0:4db:456a:9a1 with SMTP id n14-20020a19550e000000b004db456a09a1mr2892389lfe.66.1677080036259; Wed, 22 Feb 2023 07:33:56 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN PATCH v7 02/20] xen/arm: tee: add a primitive FF-A mediator Date: Wed, 22 Feb 2023 16:32:59 +0100 Message-Id: <5f0a74b3e4f6cda56e780a739859537246d4892f.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds a FF-A version 1.1 [1] mediator to communicate with a Secure Partition in secure world. This commit brings in only the parts needed to negotiate FF-A version number with guest and SPMC. [1] https://developer.arm.com/documentation/den0077/e Signed-off-by: Jens Wiklander --- xen/arch/arm/include/asm/domain.h | 2 +- xen/arch/arm/include/asm/psci.h | 4 + xen/arch/arm/include/asm/tee/ffa.h | 35 +++++ xen/arch/arm/tee/Kconfig | 11 ++ xen/arch/arm/tee/Makefile | 1 + xen/arch/arm/tee/ffa.c | 217 +++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 17 ++- xen/include/public/arch-arm.h | 1 + 8 files changed, 284 insertions(+), 4 deletions(-) create mode 100644 xen/arch/arm/include/asm/tee/ffa.h create mode 100644 xen/arch/arm/tee/ffa.c diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index 0e310601e846..754daa8efa04 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -110,7 +110,7 @@ struct arch_domain struct vpl011 vpl011; #endif -#ifdef CONFIG_TEE +#if defined(CONFIG_TEE) || defined(CONFIG_FFA) void *tee; #endif diff --git a/xen/arch/arm/include/asm/psci.h b/xen/arch/arm/include/asm/psci.h index 832f77afff3a..4780972621bb 100644 --- a/xen/arch/arm/include/asm/psci.h +++ b/xen/arch/arm/include/asm/psci.h @@ -24,6 +24,10 @@ void call_psci_cpu_off(void); void call_psci_system_off(void); void call_psci_system_reset(void); +/* Range of allocated PSCI function numbers */ +#define PSCI_FNUM_MIN_VALUE _AC(0,U) +#define PSCI_FNUM_MAX_VALUE _AC(0x1f,U) + /* PSCI v0.2 interface */ #define PSCI_0_2_FN32(nr) ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ ARM_SMCCC_CONV_32, \ diff --git a/xen/arch/arm/include/asm/tee/ffa.h b/xen/arch/arm/include/asm/tee/ffa.h new file mode 100644 index 000000000000..94960100718e --- /dev/null +++ b/xen/arch/arm/include/asm/tee/ffa.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: MIT */ +/* + * xen/arch/arm/include/asm/tee/ffa.h + * + * Arm Firmware Framework for ARMv8-A(FFA) mediator + * + * Copyright (C) 2023 Linaro Limited + */ + +#ifndef __ASM_ARM_TEE_FFA_H__ +#define __ASM_ARM_TEE_FFA_H__ + +#include +#include + +#include +#include + +#define FFA_FNUM_MIN_VALUE _AC(0x60,U) +#define FFA_FNUM_MAX_VALUE _AC(0x86,U) + +static inline bool is_ffa_fid(uint32_t fid) +{ + uint32_t fn = fid & ARM_SMCCC_FUNC_MASK; + + return fn >= FFA_FNUM_MIN_VALUE && fn <= FFA_FNUM_MAX_VALUE; +} + +#ifdef CONFIG_FFA +#define FFA_NR_FUNCS (9 + (IS_ENABLED(CONFIG_ARM_64) ? 3 : 0) ) +#else +#define FFA_NR_FUNCS 0 +#endif + +#endif /*__ASM_ARM_TEE_FFA_H__*/ diff --git a/xen/arch/arm/tee/Kconfig b/xen/arch/arm/tee/Kconfig index 392169b2559d..923f08ba8cb7 100644 --- a/xen/arch/arm/tee/Kconfig +++ b/xen/arch/arm/tee/Kconfig @@ -8,3 +8,14 @@ config OPTEE virtualization-enabled OP-TEE present. You can learn more about virtualization for OP-TEE at https://optee.readthedocs.io/architecture/virtualization.html + +config FFA + bool "Enable FF-A mediator support (UNSUPPORTED)" if UNSUPPORTED + default n + depends on ARM_64 + help + This option enables a minimal FF-A mediator. The mediator is + generic as it follows the FF-A specification [1], but it only + implements a small subset of the specification. + + [1] https://developer.arm.com/documentation/den0077/latest diff --git a/xen/arch/arm/tee/Makefile b/xen/arch/arm/tee/Makefile index 982c87968447..58a1015e40e0 100644 --- a/xen/arch/arm/tee/Makefile +++ b/xen/arch/arm/tee/Makefile @@ -1,2 +1,3 @@ +obj-$(CONFIG_FFA) += ffa.o obj-y += tee.o obj-$(CONFIG_OPTEE) += optee.o diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c new file mode 100644 index 000000000000..824153c9303a --- /dev/null +++ b/xen/arch/arm/tee/ffa.c @@ -0,0 +1,217 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * xen/arch/arm/tee/ffa.c + * + * Arm Firmware Framework for ARMv8-A (FF-A) mediator + * + * Copyright (C) 2023 Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* Error codes */ +#define FFA_RET_OK 0 +#define FFA_RET_NOT_SUPPORTED -1 +#define FFA_RET_INVALID_PARAMETERS -2 +#define FFA_RET_NO_MEMORY -3 +#define FFA_RET_BUSY -4 +#define FFA_RET_INTERRUPTED -5 +#define FFA_RET_DENIED -6 +#define FFA_RET_RETRY -7 +#define FFA_RET_ABORTED -8 + +/* FFA_VERSION helpers */ +#define FFA_VERSION_MAJOR_SHIFT 16U +#define FFA_VERSION_MAJOR_MASK 0x7FFFU +#define FFA_VERSION_MINOR_SHIFT 0U +#define FFA_VERSION_MINOR_MASK 0xFFFFU +#define MAKE_FFA_VERSION(major, minor) \ + ((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \ + ((minor) & FFA_VERSION_MINOR_MASK)) + +#define FFA_MIN_VERSION MAKE_FFA_VERSION(1, 0) +#define FFA_VERSION_1_0 MAKE_FFA_VERSION(1, 0) +#define FFA_VERSION_1_1 MAKE_FFA_VERSION(1, 1) + +/* + * This is the version we want to use in communication with guests and SPs. + * During negotiation with a guest or a SP we may need to lower it for + * that particular guest or SP. + */ +#define FFA_MY_VERSION_MAJOR 1U +#define FFA_MY_VERSION_MINOR 1U +#define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ + FFA_MY_VERSION_MINOR) + +/* Function IDs */ +#define FFA_ERROR 0x84000060U +#define FFA_SUCCESS_32 0x84000061U +#define FFA_VERSION 0x84000063U + +struct ffa_ctx { + uint32_t guest_vers; +}; + +/* Negotiated FF-A version to use with the SPMC */ +static uint32_t ffa_version __ro_after_init; + +static bool ffa_get_version(uint32_t *vers) +{ + const struct arm_smccc_1_2_regs arg = { + .a0 = FFA_VERSION, + .a1 = FFA_MY_VERSION, + }; + struct arm_smccc_1_2_regs resp; + + arm_smccc_1_2_smc(&arg, &resp); + if ( resp.a0 == FFA_RET_NOT_SUPPORTED ) + { + gprintk(XENLOG_ERR, "ffa: FFA_VERSION returned not supported\n"); + return false; + } + + *vers = resp.a0; + + return true; +} + +static void set_regs(struct cpu_user_regs *regs, register_t v0, register_t v1, + register_t v2, register_t v3, register_t v4, register_t v5, + register_t v6, register_t v7) +{ + set_user_reg(regs, 0, v0); + set_user_reg(regs, 1, v1); + set_user_reg(regs, 2, v2); + set_user_reg(regs, 3, v3); + set_user_reg(regs, 4, v4); + set_user_reg(regs, 5, v5); + set_user_reg(regs, 6, v6); + set_user_reg(regs, 7, v7); +} + +static void handle_version(struct cpu_user_regs *regs) +{ + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + uint32_t vers = get_user_reg(regs, 1); + + if ( vers < FFA_VERSION_1_1 ) + vers = FFA_VERSION_1_0; + else + vers = FFA_VERSION_1_1; + + ctx->guest_vers = vers; + set_regs(regs, vers, 0, 0, 0, 0, 0, 0, 0); +} + +static bool ffa_handle_call(struct cpu_user_regs *regs) +{ + uint32_t fid = get_user_reg(regs, 0); + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + + if ( !ctx ) + return false; + + switch ( fid ) + { + case FFA_VERSION: + handle_version(regs); + return true; + + default: + gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); + return false; + } +} + +static int ffa_domain_init(struct domain *d) +{ + struct ffa_ctx *ctx; + + if ( !ffa_version ) + return -ENODEV; + + ctx = xzalloc(struct ffa_ctx); + if ( !ctx ) + return -ENOMEM; + + d->arch.tee = ctx; + + return 0; +} + +/* This function is supposed to undo what ffa_domain_init() has done */ +static int ffa_relinquish_resources(struct domain *d) +{ + struct ffa_ctx *ctx = d->arch.tee; + + if ( !ctx ) + return 0; + + XFREE(d->arch.tee); + + return 0; +} + +static bool ffa_probe(void) +{ + uint32_t vers; + unsigned int major_vers; + unsigned int minor_vers; + + /* + * psci_init_smccc() updates this value with what's reported by EL-3 + * or secure world. + */ + if ( smccc_ver < ARM_SMCCC_VERSION_1_2 ) + { + printk(XENLOG_ERR + "ffa: unsupported SMCCC version %#x (need at least %#x)\n", + smccc_ver, ARM_SMCCC_VERSION_1_2); + return false; + } + + if ( !ffa_get_version(&vers) ) + return false; + + if ( vers < FFA_MIN_VERSION || vers > FFA_MY_VERSION ) + { + printk(XENLOG_ERR "ffa: Incompatible version %#x found\n", vers); + return false; + } + + major_vers = (vers >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSION_MAJOR_MASK; + minor_vers = vers & FFA_VERSION_MINOR_MASK; + printk(XENLOG_INFO "ARM FF-A Mediator version %u.%u\n", + FFA_MY_VERSION_MAJOR, FFA_MY_VERSION_MINOR); + printk(XENLOG_INFO "ARM FF-A Firmware version %u.%u\n", + major_vers, minor_vers); + + ffa_version = vers; + + return true; +} + +static const struct tee_mediator_ops ffa_ops = +{ + .probe = ffa_probe, + .domain_init = ffa_domain_init, + .relinquish_resources = ffa_relinquish_resources, + .handle_call = ffa_handle_call, +}; + +REGISTER_TEE_MEDIATOR(ffa, "FF-A", XEN_DOMCTL_CONFIG_TEE_FFA, &ffa_ops); diff --git a/xen/arch/arm/vsmc.c b/xen/arch/arm/vsmc.c index cd68fa80e98a..7f2f5eb9ce3d 100644 --- a/xen/arch/arm/vsmc.c +++ b/xen/arch/arm/vsmc.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -24,7 +25,7 @@ #define XEN_SMCCC_FUNCTION_COUNT 3 /* Number of functions currently supported by Standard Service Service Calls. */ -#define SSSC_SMCCC_FUNCTION_COUNT (3 + VPSCI_NR_FUNCS) +#define SSSC_SMCCC_FUNCTION_COUNT (3 + VPSCI_NR_FUNCS + FFA_NR_FUNCS) static bool fill_uid(struct cpu_user_regs *regs, xen_uuid_t uuid) { @@ -188,13 +189,23 @@ static bool handle_existing_apis(struct cpu_user_regs *regs) return do_vpsci_0_1_call(regs, fid); } +static bool is_psci_fid(uint32_t fid) +{ + uint32_t fn = fid & ARM_SMCCC_FUNC_MASK; + + return fn >= PSCI_FNUM_MIN_VALUE && fn <= PSCI_FNUM_MAX_VALUE; +} + /* PSCI 0.2 interface and other Standard Secure Calls */ static bool handle_sssc(struct cpu_user_regs *regs) { uint32_t fid = (uint32_t)get_user_reg(regs, 0); - if ( do_vpsci_0_2_call(regs, fid) ) - return true; + if ( is_psci_fid(fid) ) + return do_vpsci_0_2_call(regs, fid); + + if ( is_ffa_fid(fid) ) + return tee_handle_call(regs); switch ( fid ) { diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 1528ced5097a..92aff923056a 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -296,6 +296,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); #define XEN_DOMCTL_CONFIG_TEE_NONE 0 #define XEN_DOMCTL_CONFIG_TEE_OPTEE 1 +#define XEN_DOMCTL_CONFIG_TEE_FFA 2 struct xen_arch_domainconfig { /* IN/OUT */ From patchwork Wed Feb 22 15:33:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77F3CC678D5 for ; Wed, 22 Feb 2023 15:34:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499542.770746 (Exim 4.92) (envelope-from ) id 1pUr87-00026T-G1; Wed, 22 Feb 2023 15:34:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499542.770746; Wed, 22 Feb 2023 15:34:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr87-00024z-94; Wed, 22 Feb 2023 15:34:03 +0000 Received: by outflank-mailman (input) for mailman id 499542; Wed, 22 Feb 2023 15:34:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr84-0001MH-La for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:00 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 51ed4ceb-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:33:56 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id m6so10601495lfq.5 for ; Wed, 22 Feb 2023 07:33:57 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:33:56 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 51ed4ceb-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hFm2TzWcNGWz8FKUUitzejc0u2aQwxYFeFHIlHq40P4=; b=GzxgN7BXbxo0+/tv1J0713rHL72vukYSwgLPf/P+YI0EbO88BD0N2mt9tsEc6yuqgF qEj0fifpnuzJYhfMWU8RXfcPezwCsDHddm6k4RBNibMtxs9op6/jrECuaKfTT7I4J02a DWqthWpQA1u4SpXUGpD/ARFbHmTN/j7AK58oQckLu9w9Ycnj6T2O4VkVaafp+p2SScMc WsXJRsp6sEDpaAINKRX1NDCnBCGIm01gBQ1xVJyq3qgmK32pgr9T/8p8m/YW18HlF/OH 68FoBzYyObu5o0DLZts2/ZKRP5tuaHzZvf5kFlBwS152PpNiWb3HNvan9mwU/WNnDxnS FZ3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hFm2TzWcNGWz8FKUUitzejc0u2aQwxYFeFHIlHq40P4=; b=eUx/Ra97c0jPV2kkEw1qZmM3RnlZaV4EWP4Gr28DwTkKa7JPO6zWmRve/Q5AOOQqQl NF1BCIAZXSniSjON4iKFDNL6KaBBMVmN1ZmlIg7B5AZ8tItC56dqQbhHQb9UhD2Uoo5k Q1XjbhschQeXLgRxedIFGloxW6XmPlviWlU33OM9PPlw7aVw/uO2lshcYspVRI71Dg/S y5pUC0A9SIKq1OeySIto12knQymECsRdJtnfVhlGqSEw/hUxUPJDbcjpDluU5UWsjjRh uIs3zT3UcEB92ZZX5PbikiIgLXstdAb/y0/0h7h1V+BgG7KrWi+pp/RghOrsK01tQbjc CnCw== X-Gm-Message-State: AO0yUKXSpG5Y7XalpaeBGnSKu/xu13H+UhR2dzaCt4wK2mPb0n6jfFpQ gcM+MlJwRZRLu6KC7XpT8vU9W99vOTtcKxpSPdw= X-Google-Smtp-Source: AK7set83a9EuQm3FIhZUxGYQNpN+Xliw3SPos9E5nhOpkX42RfqIIRGvaj5zAtDXQpR0Z7Rfgn5MBA== X-Received: by 2002:ac2:4ad9:0:b0:4db:268a:4ec5 with SMTP id m25-20020ac24ad9000000b004db268a4ec5mr2962768lfp.52.1677080037078; Wed, 22 Feb 2023 07:33:57 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN PATCH v7 03/20] tools: add Arm FF-A mediator Date: Wed, 22 Feb 2023 16:33:00 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds a new "ffa" value to the Enumeration "tee_type" to indicate if a guest is trusted to use FF-A. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- tools/libs/light/libxl_arm.c | 3 +++ tools/libs/light/libxl_types.idl | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index ddc7b2a15975..601890dda1ce 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -205,6 +205,9 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, case LIBXL_TEE_TYPE_OPTEE: config->arch.tee_type = XEN_DOMCTL_CONFIG_TEE_OPTEE; break; + case LIBXL_TEE_TYPE_FFA: + config->arch.tee_type = XEN_DOMCTL_CONFIG_TEE_FFA; + break; default: LOG(ERROR, "Unknown TEE type %d", d_config->b_info.tee); diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index 0cfad8508dbd..64fb570bc19a 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -494,7 +494,8 @@ libxl_gic_version = Enumeration("gic_version", [ libxl_tee_type = Enumeration("tee_type", [ (0, "none"), - (1, "optee") + (1, "optee"), + (2, "ffa") ], init_val = "LIBXL_TEE_TYPE_NONE") libxl_rdm_reserve = Struct("rdm_reserve", [ From patchwork Wed Feb 22 15:33:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E2E0C64EC7 for ; Wed, 22 Feb 2023 15:34:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499538.770719 (Exim 4.92) (envelope-from ) id 1pUr85-0001bl-F8; Wed, 22 Feb 2023 15:34:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499538.770719; Wed, 22 Feb 2023 15:34:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr85-0001be-8c; Wed, 22 Feb 2023 15:34:01 +0000 Received: by outflank-mailman (input) for mailman id 499538; Wed, 22 Feb 2023 15:33:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr83-0001MC-68 for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:33:59 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5311e990-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:33:58 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id m6so10601552lfq.5 for ; Wed, 22 Feb 2023 07:33:58 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:33:57 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5311e990-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zqvukz9Wc9inONzmuv1uqsHsrEr+5BrdoP3LyiYlJNc=; b=A5wwFKfLIQXuxIScvZsdkXI7TfET/8Br388Cj7wQG+b6a6GmqgTNLaCaxklh0lPUDS nAtT2c9RPmuCRUo9tHO/DoToQ6fM2JSEDsNaDEkka0r2rrTlb8NZTB3yVjfyUE55xwsJ MbWoyYJXmJ78Hfk8KBYdC/1UWDc3CPohkl3MjiC8fbTBmTWDN86nHVwYZOAXt395BHrB 0r1M5lmxpHiviohxpFyo+3w+stRsTSLsQmN+a+WbHu5sZp81OGz1bXzZoeJ8PW82Z2WL qZHrVGIulMCIaK8N750h+PWtKziYA7TTPJGkgAjWklIj8QJSCMfg81WhXynCr5u9e/5R RjLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zqvukz9Wc9inONzmuv1uqsHsrEr+5BrdoP3LyiYlJNc=; b=iMTFeCRCtHmehAD/djPzKFMSCd5OOE06jXql96iy/cty55qYHOkhRomRBX+9qrCGqm Pg4lp26jwBfOY2zsg6xhlQOgYs3664jE5qunbxt3rUJY+sNSOl+Ws1QHAf8sNwZO0tP1 0ARMLhssKwYx2fAyEWvEh86YVRVOymsrzsQJtkm7Klt1NTH5WkEEFxB81W+w2RGKzocZ dU6LX7v9GIKEVajpnGcdo4FBnHMioYCVonKjCQcOEN4Ebu9SSbmgKikaXdu6w/Gk0kx5 gQR+bvhnSIN1oWhxMNPZDkQ46VncnpLtGtnv8IJeAwK+qjFCQs4FSTG80o4r6fnAEKn7 G7uA== X-Gm-Message-State: AO0yUKWE5ozFZ/Il3/8JCAn1AyaHJqb/CKZBbC/w7KaLSo4himpLmzhm DBfNLJqdontwEP7G5zgHAhIy/UwIopDLKx4mLBM= X-Google-Smtp-Source: AK7set+DcuvGaDQ5vp9ctw+TkJQtIbCDGMtu3l/ttC+FbPE+boIAHse0unqWaTs9of2BqAGtALrbeg== X-Received: by 2002:ac2:5234:0:b0:4cb:4374:cc78 with SMTP id i20-20020ac25234000000b004cb4374cc78mr3352349lfl.26.1677080037933; Wed, 22 Feb 2023 07:33:57 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [XEN PATCH v7 04/20] docs: add Arm FF-A mediator Date: Wed, 22 Feb 2023 16:33:01 +0100 Message-Id: <5c588d92cdf23a7355a79bf4b91c7214e5ced197.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Describes a FF-A version 1.1 [1] mediator to communicate with a Secure Partition in secure world. [1] https://developer.arm.com/documentation/den0077/latest Signed-off-by: Jens Wiklander --- SUPPORT.md | 7 +++++++ docs/man/xl.cfg.5.pod.in | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index aa1940e55f09..5e0595419684 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -818,6 +818,13 @@ that covers the DMA of the device to be passed through. No support for QEMU backends in a 16K or 64K domain. +### ARM: Firmware Framework for Arm A-profile (FF-A) Mediator + + Status, Arm64: Tech Preview + +There are still some code paths where a vCPU may hog a pCPU longer than +necessary. The FF-A mediator is not yet implemented for Arm32. + ### ARM: Guest Device Tree support Status: Supported diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 024bceeb61b2..ca4fc3e67b0c 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1645,6 +1645,21 @@ in OP-TEE. This feature is a B. +=item B + +B Allow a guest to communicate via FF-A with Secure Partitions +(SP), default false. + +Currently is only a small subset of the FF-A specification supported. Just +enough to communicate with OP-TEE. In general only direct messaging and +sharing memory with one SP. More advanced use cases where memory might be +shared or donated to multple SPs is not supported. + +See L for more +informantion about FF-A. + +This feature is a B. + =back =back From patchwork Wed Feb 22 15:33:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 179AAC64EC4 for ; Wed, 22 Feb 2023 15:34:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499541.770737 (Exim 4.92) (envelope-from ) id 1pUr86-0001qB-Nc; Wed, 22 Feb 2023 15:34:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499541.770737; Wed, 22 Feb 2023 15:34:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr86-0001nu-9s; Wed, 22 Feb 2023 15:34:02 +0000 Received: by outflank-mailman (input) for mailman id 499541; Wed, 22 Feb 2023 15:34:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr84-0001MC-6N for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:00 +0000 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [2a00:1450:4864:20::12b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5368d821-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:33:59 +0100 (CET) Received: by mail-lf1-x12b.google.com with SMTP id k14so9541428lfj.7 for ; Wed, 22 Feb 2023 07:33:59 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:33:58 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5368d821-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KI1veJQCzcrc4867Mx0BfEZYRjuokQrrKibNDvguIjM=; b=b9ez+PWmP+J9IWGA/jmj+YSV97dCG8tsXUG6IOwBaO5H6cJ/qSpfYTAeagM9q8rBcx ybA9pfqW/XGjTmxj3MckoVjI4diyDvI0KJpi/udWoV8OMCLPWC17UwAt6hQfHqTqB7hA yXcaEBquUsyPSJ4F59x8YSDyAkcFXqkYRgFNjAjnL/HRkGMlsUO3TIumNXkb+tXhkjTO OlLvZo/sQWK9dj20yMPPvv/n8eQnpIAKYZnsWNjyh5UWrp6OatcUxVErrot0NtzETC1Q /dg0qdr4mQHAoVk6/x3GtLkhK0RiciNZyKLF2YmUgarE6dpWqdP3CxJBjwmhQriEEWE2 DgEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KI1veJQCzcrc4867Mx0BfEZYRjuokQrrKibNDvguIjM=; b=3PDda9sz6rIx3l+JGIqryRwoFHtCqW07hs3LiJz/DgA6R3IL6gGftWOx4/rZt4BLuH Jje/gWFZDk1a5w4US0Ch3S+V+FAu8SqZabJZoxO/IlsNAUSrK2vR1iH4c7cdOuj5Uhzc 4Z4TLJk6X7Wrgmu3eMc+iFmPB1O4UrPHrl3y2tkagobYWxkQ3fM7Qvlthk0W3bYb/HVv KRo4A/LLuu023Zgtd8VDDdhx+cfwKZMyn2pz19TVuae3ZcVcyZY+oT/fD+VMxhRTTtDi lF80eOCEbeizTTFfmiYL8ZwrAkXkVgEUdYr+ShXp6Q3dGDpzpsW+eBmZyWOgaL56yUZo YVEA== X-Gm-Message-State: AO0yUKUaBALXt1B7z9civ0g0OnGmCeWacf9hWUeP4/mR+mJXgYYf5s8P j6Dzd5OgFW0tpixfJETOBf2jMJSfjmA1RL2PmHM= X-Google-Smtp-Source: AK7set8mGAbfiuOZUZFXo+60NODykwSWgKjBA3+5AeEojv6aoHvq/0M/OGv8C5ap23Is/KGNmJDyEg== X-Received: by 2002:a19:ac4d:0:b0:4dc:8409:b214 with SMTP id r13-20020a19ac4d000000b004dc8409b214mr3389448lfc.21.1677080038697; Wed, 22 Feb 2023 07:33:58 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 05/20] xen/arm: ffa: add remaining SMC function IDs Date: Wed, 22 Feb 2023 16:33:02 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds the remaining SMC function IDs from FF-A 1.1 specification. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 824153c9303a..aa6cdbe0a4f9 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -59,7 +59,41 @@ /* Function IDs */ #define FFA_ERROR 0x84000060U #define FFA_SUCCESS_32 0x84000061U +#define FFA_SUCCESS_64 0xC4000061U +#define FFA_INTERRUPT 0x84000062U #define FFA_VERSION 0x84000063U +#define FFA_FEATURES 0x84000064U +#define FFA_RX_ACQUIRE 0x84000084U +#define FFA_RX_RELEASE 0x84000065U +#define FFA_RXTX_MAP_32 0x84000066U +#define FFA_RXTX_MAP_64 0xC4000066U +#define FFA_RXTX_UNMAP 0x84000067U +#define FFA_PARTITION_INFO_GET 0x84000068U +#define FFA_ID_GET 0x84000069U +#define FFA_SPM_ID_GET 0x84000085U +#define FFA_MSG_WAIT 0x8400006BU +#define FFA_MSG_YIELD 0x8400006CU +#define FFA_MSG_RUN 0x8400006DU +#define FFA_MSG_SEND2 0x84000086U +#define FFA_MSG_SEND_DIRECT_REQ_32 0x8400006FU +#define FFA_MSG_SEND_DIRECT_REQ_64 0xC400006FU +#define FFA_MSG_SEND_DIRECT_RESP_32 0x84000070U +#define FFA_MSG_SEND_DIRECT_RESP_64 0xC4000070U +#define FFA_MEM_DONATE_32 0x84000071U +#define FFA_MEM_DONATE_64 0xC4000071U +#define FFA_MEM_LEND_32 0x84000072U +#define FFA_MEM_LEND_64 0xC4000072U +#define FFA_MEM_SHARE_32 0x84000073U +#define FFA_MEM_SHARE_64 0xC4000073U +#define FFA_MEM_RETRIEVE_REQ_32 0x84000074U +#define FFA_MEM_RETRIEVE_REQ_64 0xC4000074U +#define FFA_MEM_RETRIEVE_RESP 0x84000075U +#define FFA_MEM_RELINQUISH 0x84000076U +#define FFA_MEM_RECLAIM 0x84000077U +#define FFA_MEM_FRAG_RX 0x8400007AU +#define FFA_MEM_FRAG_TX 0x8400007BU +#define FFA_MSG_SEND 0x8400006EU +#define FFA_MSG_POLL 0x8400006AU struct ffa_ctx { uint32_t guest_vers; From patchwork Wed Feb 22 15:33:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0868DC6FD1A for ; Wed, 22 Feb 2023 15:34:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499544.770767 (Exim 4.92) (envelope-from ) id 1pUr89-0002Uz-IM; Wed, 22 Feb 2023 15:34:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499544.770767; Wed, 22 Feb 2023 15:34:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr88-0002QV-Ox; Wed, 22 Feb 2023 15:34:04 +0000 Received: by outflank-mailman (input) for mailman id 499544; Wed, 22 Feb 2023 15:34:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr85-0001MH-Ns for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:01 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 536c2c77-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:33:59 +0100 (CET) Received: by mail-lf1-x135.google.com with SMTP id f18so10543953lfa.3 for ; Wed, 22 Feb 2023 07:34:00 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:33:59 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 536c2c77-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oaAb7ukOE/W1jF7n380+WVov1wWGPwFJcHBGgA4I42A=; b=PsIcsB1eAGAv31fKhzszD8BPuis7RyhebinM1YoSHMcMlhsPv+l5LRETNGSJgaWiOE vfoFQQNo+Z592qPRDlV+kqKb+5E8EmzMz3+Txwwqg0txE7h9x6COb81lmSwWOTM0USuI pHUguVHJU/s/rLl+H9m4QFmRWR9TEydGMFyNVTxCBHM4EGex5yO6/bSbIrHATk9ZSLjA qFav1IYaJG30zWOgLqi6BNAjnWGFgjnakHyII6qasFKHHEkH0GU6jqXA1JLxjKAiu4Y/ Kazw2LNaosSD0z8bJimwxf96wgDm1Iuo/ckhKILeffwCrxz6bWlTmpNZIeIax34OB5i6 mwgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oaAb7ukOE/W1jF7n380+WVov1wWGPwFJcHBGgA4I42A=; b=kqWLteWdKuPfHwK2AWvsT3rrjkxT0Tx0y1Hk1KQQ6gJmoxeMcpXJeWvX1i1WLPdk/P Mh9gkYhUSWN1JkpnFiHlbCJL/o1v+1kTEYyW913NasSuhMKtmzNoBl1ciqzOkaUo1WTr m33rM08EmdALegp3K7MPgNTHcYHPrDNs+Am/i19xiO8l21u/6pl1y0uAERMOv8kYsBHo 1fc3mi4NstKd2XTc5RMhaEPcxOKQW+3pzqwSZOB9uQIIgW4kdZyk2n1t297Xos4jTHKP te8hgNT3UbEkiAEbsYx+kE6Ngk9cM4NTss7CmlVXycSLBwyGs+K165ouKdNi7Hc4BuoQ /gGA== X-Gm-Message-State: AO0yUKWxFtO/tdT1c0Qhqwp0LDdZWI566P0bNoXGY8BfZ5CaVSlr/+yd PYKUfrZnbpxbHIMutPUSxKgJkvsZVYzTBTGK4oo= X-Google-Smtp-Source: AK7set/BrU6GpxdvnsexBpdAumv70/Z+G4UeQ/FoCu2NxcHU8B/LeNDcv7Ablb5ZYe6LLtZazjYCTQ== X-Received: by 2002:ac2:5ece:0:b0:4dd:9aec:e468 with SMTP id d14-20020ac25ece000000b004dd9aece468mr1184919lfq.58.1677080039581; Wed, 22 Feb 2023 07:33:59 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 06/20] xen/arm: ffa: add flags for FFA_PARTITION_INFO_GET Date: Wed, 22 Feb 2023 16:33:03 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Defines flags used for the function FFA_PARTITION_INFO_GET. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index aa6cdbe0a4f9..f4562ed2defc 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -56,6 +56,32 @@ #define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ FFA_MY_VERSION_MINOR) +/* + * Flags used for the FFA_PARTITION_INFO_GET return message: + * BIT(0): Supports receipt of direct requests + * BIT(1): Can send direct requests + * BIT(2): Can send and receive indirect messages + * BIT(3): Supports receipt of notifications + * BIT(4-5): Partition ID is a PE endpoint ID + */ +#define FFA_PART_PROP_DIRECT_REQ_RECV BIT(0, U) +#define FFA_PART_PROP_DIRECT_REQ_SEND BIT(1, U) +#define FFA_PART_PROP_INDIRECT_MSGS BIT(2, U) +#define FFA_PART_PROP_RECV_NOTIF BIT(3, U) +#define FFA_PART_PROP_IS_PE_ID (0U << 4) +#define FFA_PART_PROP_IS_SEPID_INDEP (1U << 4) +#define FFA_PART_PROP_IS_SEPID_DEP (2U << 4) +#define FFA_PART_PROP_IS_AUX_ID (3U << 4) +#define FFA_PART_PROP_NOTIF_CREATED BIT(6, U) +#define FFA_PART_PROP_NOTIF_DESTROYED BIT(7, U) +#define FFA_PART_PROP_AARCH64_STATE BIT(8, U) + +/* + * Flag used as parameter to FFA_PARTITION_INFO_GET to return partition + * count only. + */ +#define FFA_PARTITION_INFO_GET_COUNT_FLAG BIT(0, U) + /* Function IDs */ #define FFA_ERROR 0x84000060U #define FFA_SUCCESS_32 0x84000061U From patchwork Wed Feb 22 15:33:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA71BC6FA99 for ; Wed, 22 Feb 2023 15:34:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499543.770755 (Exim 4.92) (envelope-from ) id 1pUr88-0002HA-9l; Wed, 22 Feb 2023 15:34:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499543.770755; Wed, 22 Feb 2023 15:34:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr87-0002En-Qi; Wed, 22 Feb 2023 15:34:03 +0000 Received: by outflank-mailman (input) for mailman id 499543; Wed, 22 Feb 2023 15:34:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr85-0001MC-6h for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:01 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5466f783-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:34:00 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id m6so10601696lfq.5 for ; Wed, 22 Feb 2023 07:34:00 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:00 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5466f783-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=daCXmezi75zgDEVaU54najSvdry1ZvL/v784GcKBNIM=; b=r8/bfWS5zxacR3bGf35cbhZHARGEdjT5DmuvT3lTG7ZqVQpv8gjMCyEsMth1VaAQ9/ 2FikkF1y4tF41RUHKkqLyZt8DBE1K4FEABM6GXx07QoGTw5heKZwFgojECn2LHaZBxEy 5GlWAOOlphjbZ+r+mkbVaHlJCwLDWlzZiXaGkESTk2kuPgiYXRYShC6y/wXXO5ARQF2L 5Pkz6V/C4RmjPB+3zwEUpaimm0UBwUaJju7dtVvmNN0/epxtkF3gTdVYa5AuTFH6fKbM ZPOVDl4Vedq8I7CvapjlQprNWfY3x3WqQQIpAbuvgNQwlwUSrcfc5R6S8b6bSJNoafZr dXgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=daCXmezi75zgDEVaU54najSvdry1ZvL/v784GcKBNIM=; b=SmyspjUt14CUVenSviS4kfNFIASHc/KN8Rpb+/Cs2HiJn7ng+emJSuRAJO9lOLkIla 3eg2R/6mPTwOqatlZyWo0m2mtrar1OZlkb4Hf/DXrPceKGcNx4g9hNsxOtoHttuhbiba F/xJ+MZfBWxyr45sOQZBevu4VyUT1CB55XsC3wERJQ4QgdYjrwN3lSDmXVRlasXuj31K L6pJuGvRt6vPxMFTT+xBhH3dpRoAa/I5JUWcy5FxJvLBf55w14B5Nb0S9Os0E+lTIlGP A0iektnR7QKsQVnmjKg7NFz++qhhinX2ItT/13KMl0D6Hblma+DhYhjSnLFQYrelQrZX 0WuA== X-Gm-Message-State: AO0yUKVSfN5W3voHoo1G80p4BnU+jOCm9lbZo3lzf8mRQFOqWLAnVxj4 lD9J8Di7blqp1Q+GJn6HR9sVWRsGmGI8vJ1N+8o= X-Google-Smtp-Source: AK7set93muUJIEST07jzhhKMCkgsqD+Eb2DfvRNAehJS1K297RREfCeyvjA9vIOjRgr5rCQkNWg07g== X-Received: by 2002:ac2:5a05:0:b0:4b5:8f03:a2bc with SMTP id q5-20020ac25a05000000b004b58f03a2bcmr3022146lfn.9.1677080040361; Wed, 22 Feb 2023 07:34:00 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 07/20] xen/arm: ffa: add defines for framework direct request/response messages Date: Wed, 22 Feb 2023 16:33:04 +0100 Message-Id: <904055064f4b4e4514acf1e64751672eca045c05.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds defines for framework direct request/response messages. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index f4562ed2defc..d04bac9cc47f 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -56,6 +56,15 @@ #define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ FFA_MY_VERSION_MINOR) +/* Framework direct request/response */ +#define FFA_MSG_FLAG_FRAMEWORK BIT(31, U) +#define FFA_MSG_TYPE_MASK 0xFFU; +#define FFA_MSG_PSCI 0x0U +#define FFA_MSG_SEND_VM_CREATED 0x4U +#define FFA_MSG_RESP_VM_CREATED 0x5U +#define FFA_MSG_SEND_VM_DESTROYED 0x6U +#define FFA_MSG_RESP_VM_DESTROYED 0x7U + /* * Flags used for the FFA_PARTITION_INFO_GET return message: * BIT(0): Supports receipt of direct requests From patchwork Wed Feb 22 15:33:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37015C6FD1B for ; Wed, 22 Feb 2023 15:34:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499545.770773 (Exim 4.92) (envelope-from ) id 1pUr8A-0002er-8B; Wed, 22 Feb 2023 15:34:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499545.770773; Wed, 22 Feb 2023 15:34:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr89-0002c4-Gi; Wed, 22 Feb 2023 15:34:05 +0000 Received: by outflank-mailman (input) for mailman id 499545; Wed, 22 Feb 2023 15:34:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr87-0001MH-B7 for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:03 +0000 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [2a00:1450:4864:20::12c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5461d2c2-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:00 +0100 (CET) Received: by mail-lf1-x12c.google.com with SMTP id bp25so10676489lfb.0 for ; Wed, 22 Feb 2023 07:34:01 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:00 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5461d2c2-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6KguU5fKyIYZ3B6fRSfTmGKEYTHZutvCnKPhrDpB1io=; b=YQ7QaUw2xSr0uhygfwAIAPTnrqAX0QSAeZ638gQy98K6yT9B0ioUdpuyfD/GEtFt34 E/q0d6XP2L3ipHWJwhkjyR7Sfq08lY5CYYj9oLtjj86uVPLOe6wmrFCCUiSmNwMc8d4w bLdQmsYNKgnSuQ1e2GmC2kCPGuLo9KM5IPf/rJ7iNEpy2L7nacLcUPXj4a32DtpSjmqx Ww4Slve+itnWYK3BK8k3cBJhIngJrnUd7FigQzG6zTc6HCeeMRsM8JI3VSUi4p6fVZNs XkNR0Fw0hv1Y4AXvWq+xFYJtG8ujcRIr8RDF9i1z2cgHl81oZColGEa8Nq8oA6Mvj7FI 3ItQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6KguU5fKyIYZ3B6fRSfTmGKEYTHZutvCnKPhrDpB1io=; b=GS+WVJftdXyfPCPi+XgF5RV0EKWljbVdcTnBM2G3QRRXPRDgsnHNxiso/YGmG9YQuy 0kcdC91wKKXCLXS51eK0fqOChWdinjZvNnAfqe++VPLbu+0aO9nvgCnGrIEenuA0wn6E qiyA3jDOiYJaIvTeuxjFo3lQ/EL7bvP8mg0FkER72xyeLMrWhCFDEhrOgcKt3Cd6ei18 O+v8kbwOtVF67SNXBUXn4dhWF+Rz+S7UsD5Ibuk07TcHAsEnR5X9gAPR53Eu1ItdyMfs QcQxtka34HrCCq/tRobBUSSE+auiNodU/5vF0GOPmG0mm2xlWjFXaU5CskU9LyDgpOgt Jyxw== X-Gm-Message-State: AO0yUKXG2DmIMr0I2QmmJx6AGsf1/RSUTjaJmqUQdYB1ojKSBcKvF30W Ytc1WoOO9wk07qG3KGFgwWFd2Wsaq0scD04Dvwk= X-Google-Smtp-Source: AK7set/xYReyFarccwfkMjZIxvACnhtNCeZqDqdQl+pSNBAcE7+gyQOEvXc3nFfTscS6Ntnj2sDjTw== X-Received: by 2002:ac2:43b3:0:b0:4dc:4b05:485c with SMTP id t19-20020ac243b3000000b004dc4b05485cmr2784611lfl.50.1677080041130; Wed, 22 Feb 2023 07:34:01 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 08/20] xen/arm: ffa: note dependency on 4k pages Date: Wed, 22 Feb 2023 16:33:05 +0100 Message-Id: <6c0ef5d2174bfa8c25aeb94395160ab9d863b63a.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds a BUILD_BUG_ON() to assert the dependency on 4k pages in the FF-A mediator. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index d04bac9cc47f..8b0b80ce1ff5 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -56,6 +56,16 @@ #define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ FFA_MY_VERSION_MINOR) +/* + * The FF-A specification explicitly works with 4K pages as a measure of + * memory size, for example, FFA_RXTX_MAP takes one parameter "RX/TX page + * count" which is the number of contiguous 4K pages allocated. Xen may use + * a different page size depending on the configuration to avoid confusion + * with PAGE_SIZE use a special define when it's a page size as in the FF-A + * specification. + */ +#define FFA_PAGE_SIZE SZ_4K + /* Framework direct request/response */ #define FFA_MSG_FLAG_FRAMEWORK BIT(31, U) #define FFA_MSG_TYPE_MASK 0xFFU; @@ -242,6 +252,17 @@ static bool ffa_probe(void) unsigned int major_vers; unsigned int minor_vers; + /* + * FF-A often works in units of 4K pages and currently it's assumed + * that we can map memory using that granularity. See also the comment + * above the FFA_PAGE_SIZE define. + * + * It is possible to support a PAGE_SIZE larger than 4K in Xen, but + * until that is fully handled in this code make sure that we only use + * 4K page sizes. + */ + BUILD_BUG_ON(PAGE_SIZE != FFA_PAGE_SIZE); + /* * psci_init_smccc() updates this value with what's reported by EL-3 * or secure world. From patchwork Wed Feb 22 15:33:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0DF6C64EC7 for ; Wed, 22 Feb 2023 15:34:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499546.770779 (Exim 4.92) (envelope-from ) id 1pUr8A-0002st-RA; Wed, 22 Feb 2023 15:34:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499546.770779; Wed, 22 Feb 2023 15:34:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8A-0002oX-Aa; Wed, 22 Feb 2023 15:34:06 +0000 Received: by outflank-mailman (input) for mailman id 499546; Wed, 22 Feb 2023 15:34:04 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr87-0001MH-TG for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:04 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 54c90f4c-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:01 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id m6so10601812lfq.5 for ; Wed, 22 Feb 2023 07:34:02 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:01 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 54c90f4c-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qlRarVPuGGMxZJ7O9DysTL7l0g/2Vw4D9Z/5pFVB9eY=; b=v6eOR64rfNhuETorAOP32Qsll4kvQB9Dgr24SH4+6NC8LyDPcWLA9Txni/P313Yu84 ijBsLthYJCWX8rLhn0AZ8WgHJiggxz0OGHcnjWi2ELDHpC2tyY5sjFg4SaKglJPE2y1c OobXeDx38ZOfnjIXy+5uSycUzKX7aEJpk3gHYsyDn4ocAJLGOMijC1kkxh69COT7r5Gv lH/yW2Ce/ylH/JdyjppsFcQtZ2pQyVQQXOWN8LdFvaqOMxYOXXRMBcpk3qDA3PhXE5oG Br/N22skns/Tggkr1hYsnjSxVvbB9YQGoa15L0qL5UuQ4A3ZVsDot0SudVgBewchl/1E FeMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qlRarVPuGGMxZJ7O9DysTL7l0g/2Vw4D9Z/5pFVB9eY=; b=VVLb35Nd3O61M+MnaZxMV+/QwVY+l9eLgyzQNlZ/dIXXC0M52l/uB5QuLDx4+oNOQ7 3/lsmpmmkGsXZEVCCVtKMin+jAr2S+0KCJR+CR8AKjEvcTViYDdH8+oS3Wwfv1ubuBA4 AnLjA/+09bRvtLbcd3v7PpNNlCzhlapqgrLutiNPYbxi83phfw9ZilmoXRhEy5m+N5KZ 5KUi4BhTBxalYNWUk4JfVoGLO2q2xsP3BJ4WWytuRwiqSSZ0w4ZLTIGV6Znv3pk1Wxh6 ji9SM40NrZI8KeugFGMozAzWzDus1KDkqpgVtnlO3LcDpCcH6VFoLjrf1NS4Zp3UUeQu dvJQ== X-Gm-Message-State: AO0yUKVVqPs6MV5+NJfJGrqsnY4wl57gC359P/mF4AOs9faFPcFr3Irm nHwAHwKEXJ6+7l+TNNlTPKMX9QOSpETNd6RxMmQ= X-Google-Smtp-Source: AK7set/IEh/V1KX9mwsFk0gNb3edbAK94pykYyZvOLSlTnGOfCA8Xl0pLjrnvD6r9JW5sb3plOEDfA== X-Received: by 2002:ac2:4893:0:b0:4db:44e1:d8a1 with SMTP id x19-20020ac24893000000b004db44e1d8a1mr3484319lfc.0.1677080041867; Wed, 22 Feb 2023 07:34:01 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 09/20] xen/arm: ffa: add support for FFA_ID_GET Date: Wed, 22 Feb 2023 16:33:06 +0100 Message-Id: <82e4e0c3ac1614822fddd90336c22e6fad5b485e.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support for the FF-A function FFA_ID_GET to return the ID of the calling client. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 8b0b80ce1ff5..463fd7730573 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -167,6 +167,12 @@ static bool ffa_get_version(uint32_t *vers) return true; } +static uint16_t get_vm_id(const struct domain *d) +{ + /* +1 since 0 is reserved for the hypervisor in FF-A */ + return d->domain_id + 1; +} + static void set_regs(struct cpu_user_regs *regs, register_t v0, register_t v1, register_t v2, register_t v3, register_t v4, register_t v5, register_t v6, register_t v7) @@ -181,6 +187,12 @@ static void set_regs(struct cpu_user_regs *regs, register_t v0, register_t v1, set_user_reg(regs, 7, v7); } +static void set_regs_success(struct cpu_user_regs *regs, uint32_t w2, + uint32_t w3) +{ + set_regs(regs, FFA_SUCCESS_32, 0, w2, w3, 0, 0, 0, 0); +} + static void handle_version(struct cpu_user_regs *regs) { struct domain *d = current->domain; @@ -210,6 +222,9 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) case FFA_VERSION: handle_version(regs); return true; + case FFA_ID_GET: + set_regs_success(regs, get_vm_id(d), 0); + return true; default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -221,7 +236,11 @@ static int ffa_domain_init(struct domain *d) { struct ffa_ctx *ctx; - if ( !ffa_version ) + /* + * We can't use that last possible domain ID or get_vm_id() would cause + * an overflow. + */ + if ( !ffa_version || d->domain_id == UINT16_MAX) return -ENODEV; ctx = xzalloc(struct ffa_ctx); From patchwork Wed Feb 22 15:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2173C6FD18 for ; Wed, 22 Feb 2023 15:34:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499547.770791 (Exim 4.92) (envelope-from ) id 1pUr8B-000357-RG; Wed, 22 Feb 2023 15:34:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499547.770791; Wed, 22 Feb 2023 15:34:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8B-00031j-8Q; Wed, 22 Feb 2023 15:34:07 +0000 Received: by outflank-mailman (input) for mailman id 499547; Wed, 22 Feb 2023 15:34:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr88-0001MH-O3 for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:04 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5540a006-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:02 +0100 (CET) Received: by mail-lf1-x135.google.com with SMTP id f18so10544187lfa.3 for ; Wed, 22 Feb 2023 07:34:03 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:02 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5540a006-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kkuvt9UXNHNkVAS/s0VFcET0eufVzl6U4CDVsy+uJVk=; b=x4CHeQVoB/gXPv4A4zyctWjL31vbD1kfqcBY3qLXtFmefh7ew6OVmaP4Vk1eZk0XFB 1unpgsf/zq2oM05no+wr34qzXZ2K1mg7qjMck3c7E4LDAl8Xwg1LUzFOBViI7NfrI71t IPeool/FV+xSeJwrGWZHuAVYkyXwEHxDHadmasEdQ0964YvVGytqlGcX6z4QxcJnGsXs veZO5cy85ofIpYmkIjTECfbvVy605ADh4PzL9mEgtYZMdUhV46H4tZwHvwvgu3IY/u0d FqBft1E3btju1jSF+8tnYg52S7LngoeG+JPe6U0bCh2UESkx8lmzlVswBHXIbdXzaKEj SBGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kkuvt9UXNHNkVAS/s0VFcET0eufVzl6U4CDVsy+uJVk=; b=XbKwlvUo9aBGbMa3hKdZI+HtxxLt9ESTbXUo1+HFDoCcpFbV3GgNjfZZYdWJhzckIf QaY4MVGvy5bIrfueJvpKL+9RDSM6eBxVHPKo9C1sK1Zf8UB/ZrIFQNhPTxorzC4aAAZU UOSEhjgh+NlGJorTNTcJd/LaUxnfUBaWDOgqukzW5RQMRrQM8iN6o7oi0nGf7wmP0SVI PC0tmWA/kvSEKYP5TFqxSZHQfw/dEWzcss9kk4oYOBRldrAkJG2HzigseTBVQmK+i1SB WzFo7MNhWfVLWiynJnHwQpWhWzwEgQBeg6fahlUsHXw/akZNWrG2jiKCp3njs8zQYUfM cGUA== X-Gm-Message-State: AO0yUKU8HNpotzhWLvEnfpcu7QnOIrAt4uUg0BrgeiNdB9CiccQKl9Ty gOUvZ3laCanyyfYjzH4MWAOak4GeA3TjfnQMTTA= X-Google-Smtp-Source: AK7set9MBF+cgaDazaqsWQaTxBA/fD7CzrvHmWOKRiZpG84l7B6lwQ56kwpuzjVn65GmxYxseRPcgA== X-Received: by 2002:a19:5517:0:b0:4db:26d3:e2f8 with SMTP id n23-20020a195517000000b004db26d3e2f8mr2748068lfe.22.1677080042624; Wed, 22 Feb 2023 07:34:02 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 10/20] xen/arm: ffa: add direct request support Date: Wed, 22 Feb 2023 16:33:07 +0100 Message-Id: <3332563e64568b2ffd236b1f428c27aa4cdf9790.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support for sending a FF-A direct request. Checks that the SP also supports handling a 32-bit direct request. 64-bit direct requests are not used by the mediator itself so there is not need to check for that. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 119 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 463fd7730573..a5d8a12635b6 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -142,6 +142,7 @@ struct ffa_ctx { uint32_t guest_vers; + bool interrupted; }; /* Negotiated FF-A version to use with the SPMC */ @@ -167,6 +168,55 @@ static bool ffa_get_version(uint32_t *vers) return true; } +static int32_t get_ffa_ret_code(const struct arm_smccc_1_2_regs *resp) +{ + switch ( resp->a0 ) + { + case FFA_ERROR: + if ( resp->a2 ) + return resp->a2; + else + return FFA_RET_NOT_SUPPORTED; + case FFA_SUCCESS_32: + case FFA_SUCCESS_64: + return FFA_RET_OK; + default: + return FFA_RET_NOT_SUPPORTED; + } +} + +static int32_t ffa_simple_call(uint32_t fid, register_t a1, register_t a2, + register_t a3, register_t a4) +{ + const struct arm_smccc_1_2_regs arg = { + .a0 = fid, + .a1 = a1, + .a2 = a2, + .a3 = a3, + .a4 = a4, + }; + struct arm_smccc_1_2_regs resp; + + arm_smccc_1_2_smc(&arg, &resp); + + return get_ffa_ret_code(&resp); +} + +static int32_t ffa_features(uint32_t id) +{ + return ffa_simple_call(FFA_FEATURES, id, 0, 0, 0); +} + +static bool check_mandatory_feature(uint32_t id) +{ + uint32_t ret = ffa_features(id); + + if (ret) + printk(XENLOG_ERR "ffa: mandatory feature id %#x missing\n", id); + + return !ret; +} + static uint16_t get_vm_id(const struct domain *d) { /* +1 since 0 is reserved for the hypervisor in FF-A */ @@ -208,6 +258,66 @@ static void handle_version(struct cpu_user_regs *regs) set_regs(regs, vers, 0, 0, 0, 0, 0, 0, 0); } +static void handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_t fid) +{ + struct arm_smccc_1_2_regs arg = { .a0 = fid, }; + struct arm_smccc_1_2_regs resp = { }; + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + uint32_t src_dst; + uint64_t mask; + + if ( smccc_is_conv_64(fid) ) + mask = GENMASK_ULL(63, 0); + else + mask = GENMASK_ULL(31, 0); + + src_dst = get_user_reg(regs, 1); + if ( (src_dst >> 16) != get_vm_id(d) ) + { + resp.a0 = FFA_ERROR; + resp.a2 = FFA_RET_INVALID_PARAMETERS; + goto out; + } + + arg.a1 = src_dst; + arg.a2 = get_user_reg(regs, 2) & mask; + arg.a3 = get_user_reg(regs, 3) & mask; + arg.a4 = get_user_reg(regs, 4) & mask; + arg.a5 = get_user_reg(regs, 5) & mask; + arg.a6 = get_user_reg(regs, 6) & mask; + arg.a7 = get_user_reg(regs, 7) & mask; + + while ( true ) + { + arm_smccc_1_2_smc(&arg, &resp); + + switch ( resp.a0 ) + { + case FFA_INTERRUPT: + ctx->interrupted = true; + goto out; + case FFA_ERROR: + case FFA_SUCCESS_32: + case FFA_SUCCESS_64: + case FFA_MSG_SEND_DIRECT_RESP_32: + case FFA_MSG_SEND_DIRECT_RESP_64: + goto out; + default: + /* Bad fid, report back. */ + memset(&arg, 0, sizeof(arg)); + arg.a0 = FFA_ERROR; + arg.a1 = src_dst; + arg.a2 = FFA_RET_NOT_SUPPORTED; + continue; + } + } + +out: + set_regs(regs, resp.a0, resp.a1 & mask, resp.a2 & mask, resp.a3 & mask, + resp.a4 & mask, resp.a5 & mask, resp.a6 & mask, resp.a7 & mask); +} + static bool ffa_handle_call(struct cpu_user_regs *regs) { uint32_t fid = get_user_reg(regs, 0); @@ -225,6 +335,12 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) case FFA_ID_GET: set_regs_success(regs, get_vm_id(d), 0); return true; + case FFA_MSG_SEND_DIRECT_REQ_32: +#ifdef CONFIG_ARM_64 + case FFA_MSG_SEND_DIRECT_REQ_64: +#endif + handle_msg_send_direct_req(regs, fid); + return true; default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -310,6 +426,9 @@ static bool ffa_probe(void) printk(XENLOG_INFO "ARM FF-A Firmware version %u.%u\n", major_vers, minor_vers); + if ( !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) + return false; + ffa_version = vers; return true; From patchwork Wed Feb 22 15:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 171F4C677F1 for ; Wed, 22 Feb 2023 15:34:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499549.770814 (Exim 4.92) (envelope-from ) id 1pUr8E-0003gG-J0; Wed, 22 Feb 2023 15:34:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499549.770814; Wed, 22 Feb 2023 15:34:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8D-0003Xc-7g; Wed, 22 Feb 2023 15:34:09 +0000 Received: by outflank-mailman (input) for mailman id 499549; Wed, 22 Feb 2023 15:34:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr89-0001MH-MV for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:05 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 55cba0ed-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:03 +0100 (CET) Received: by mail-lf1-x131.google.com with SMTP id n2so7258380lfb.12 for ; Wed, 22 Feb 2023 07:34:04 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:03 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 55cba0ed-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r2jocSbtwo5F8M83i1Ug9henF/cqlpwGkk7d8f2nrvc=; b=o5OthBNe4k7qeC6QV8RqK6drlj4jAq/lTI23snrg+DvDPxM+xJK65Q1P8runQ9137I ReT0cfDRYfkgXfuJjNr9N8Z6wCwNiJyum2M8HWqpj/FDtp4Y+xT/1oD4uVWTjtUVTYkv CtflFM/RddhzC0zM47ANJf60jfNG8GyOiw3vcvrLSGrR4d1+2oKk4bEusteknyRlnBLK T7//T4PE6O9Cas86oK9ib+TYAeUlQ9/zxM1FH0FFyZmsgoFD4WVxbGvqcNkDv+BieOzt pDZhB+SFslJtKcXM5/sH3HxC8KgojFhYxTc9zQvH9XamCPNDqYHQTzdU68lTfbWTgC58 NIkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r2jocSbtwo5F8M83i1Ug9henF/cqlpwGkk7d8f2nrvc=; b=yy5nrO89KuzlbXRzx/OBKwNKhOn+ROU12H/+BP5pyZiCPPfZpOtjTV9GndZq5Ce++Y heytb61npoRVK60EV8u6L+6l813H/EF6uetyDO9Ouhv0mX1FR2xxY2X+DpcBYorxEZB6 yk3uvR7FgrEKTHRrUSIZigQrXiFdl2P4DwUXuz4ogWojboDV2n6WFRKtkBmjaslVytJv OEvhZ+I8nlb6DgnafEXfE3H7aEvRYZhsY7k1wIul/1lUgscSMpmwA+vEOdkdz7r/TItz /RMTwqnrzZ+AFRcJm8Bidwllux1iU6HTdjvpVWVtVWN28eIEOPvZC2ZGMVZqerjlhZ4e PAJw== X-Gm-Message-State: AO0yUKW3cT339U7bQE4JJTk3bv3ZlVEMoa2JVGRUJCEuCISZDy1zf/M+ 1PVW+WIKxuYqRqcpxcXTaY59yr41hKQ3L68AnDY= X-Google-Smtp-Source: AK7set8Mt0ftqqKEa4+wKLn4rNec2sPsBqbyC9zFbjak0+oSQqFYa7nlPlOPUNPvcX9LYg6RQn498Q== X-Received: by 2002:ac2:5615:0:b0:4a4:68b8:f4bd with SMTP id v21-20020ac25615000000b004a468b8f4bdmr2975009lfd.3.1677080043409; Wed, 22 Feb 2023 07:34:03 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 11/20] xen/arm: ffa: map SPMC rx/tx buffers Date: Wed, 22 Feb 2023 16:33:08 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 When initializing the FF-A mediator map the RX and TX buffers shared with the SPMC. These buffer are later used to to transmit data that cannot be passed in registers only. Adds a check that the SP supports the needed FF-A features FFA_RXTX_MAP_64 / FFA_RXTX_MAP_32 and FFA_RXTX_UNMAP. In 64-bit mode we must use FFA_RXTX_MAP_64 since registers are used to transmit the physical addresses of the RX/TX buffers. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 57 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index a5d8a12635b6..07dd5c36d54b 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -148,6 +148,15 @@ struct ffa_ctx { /* Negotiated FF-A version to use with the SPMC */ static uint32_t ffa_version __ro_after_init; +/* + * Our rx/tx buffers shared with the SPMC. + * + * ffa_page_count is the number of pages used in each of these buffers. + */ +static void *ffa_rx __read_mostly; +static void *ffa_tx __read_mostly; +static unsigned int ffa_page_count __read_mostly; + static bool ffa_get_version(uint32_t *vers) { const struct arm_smccc_1_2_regs arg = { @@ -217,6 +226,17 @@ static bool check_mandatory_feature(uint32_t id) return !ret; } +static int32_t ffa_rxtx_map(register_t tx_addr, register_t rx_addr, + uint32_t page_count) +{ + uint32_t fid = FFA_RXTX_MAP_32; + + if ( IS_ENABLED(CONFIG_ARM_64) ) + fid = FFA_RXTX_MAP_64; + + return ffa_simple_call(fid, tx_addr, rx_addr, page_count, 0); +} + static uint16_t get_vm_id(const struct domain *d) { /* +1 since 0 is reserved for the hypervisor in FF-A */ @@ -384,6 +404,7 @@ static int ffa_relinquish_resources(struct domain *d) static bool ffa_probe(void) { uint32_t vers; + int e; unsigned int major_vers; unsigned int minor_vers; @@ -426,12 +447,46 @@ static bool ffa_probe(void) printk(XENLOG_INFO "ARM FF-A Firmware version %u.%u\n", major_vers, minor_vers); - if ( !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) + if ( +#ifdef CONFIG_ARM_64 + !check_mandatory_feature(FFA_RXTX_MAP_64) || +#endif +#ifdef CONFIG_ARM_32 + !check_mandatory_feature(FFA_RXTX_MAP_32) || +#endif + !check_mandatory_feature(FFA_RXTX_UNMAP) || + !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) return false; + ffa_rx = alloc_xenheap_pages(0, 0); + if ( !ffa_rx ) + return false; + + ffa_tx = alloc_xenheap_pages(0, 0); + if ( !ffa_tx ) + goto err_free_ffa_rx; + + e = ffa_rxtx_map(__pa(ffa_tx), __pa(ffa_rx), 1); + if ( e ) + { + printk(XENLOG_ERR "ffa: Failed to map rxtx: error %d\n", e); + goto err_free_ffa_tx; + } + ffa_page_count = 1; ffa_version = vers; return true; + +err_free_ffa_tx: + free_xenheap_pages(ffa_tx, 0); + ffa_tx = NULL; +err_free_ffa_rx: + free_xenheap_pages(ffa_rx, 0); + ffa_rx = NULL; + ffa_page_count = 0; + ffa_version = 0; + + return false; } static const struct tee_mediator_ops ffa_ops = From patchwork Wed Feb 22 15:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149304 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB1CFC6FD1C for ; Wed, 22 Feb 2023 15:34:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499548.770800 (Exim 4.92) (envelope-from ) id 1pUr8C-0003Kg-Qa; Wed, 22 Feb 2023 15:34:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499548.770800; Wed, 22 Feb 2023 15:34:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8C-0003Ft-6g; Wed, 22 Feb 2023 15:34:08 +0000 Received: by outflank-mailman (input) for mailman id 499548; Wed, 22 Feb 2023 15:34:06 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr89-0001MC-9m for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:05 +0000 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [2a00:1450:4864:20::12b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 56b60095-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:34:04 +0100 (CET) Received: by mail-lf1-x12b.google.com with SMTP id k14so9541792lfj.7 for ; Wed, 22 Feb 2023 07:34:04 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:03 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 56b60095-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NJzaZctbLN0X37KKF3Aj2PkBCjDMgRDd+78/Gv1GG98=; b=xW0vwRbqy+Pj5n+CkSZhIHnFgo7jW37etlbDh+MBLwGfNouZ1wHYvefyhsCl6XIezR MkpBOzKjOMVGpR4Knf3TTFFWoezZiLyAVTvBAyFPEQoKcrTpYgP1i4e5TqK/5kdIvw3a XhYK8HUYcodRDDVwQhcaoDbndxLV518PCJk/aNl7Uq/sV3yXmsfpo++GSRoaYX6GvEL5 huJYZgDf+uqbD1Z/2lO3YTnoE3JeGiwl6kqZRM151xjUK6LCxRgfDMnMCt1tbbIMSkeW BuiM/4rd6hSwWaSUQzQAmszU5TiVa8MpXTEpZKQQ1oQ7otVPClvPYLs+DyVYB0li21t4 1YEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NJzaZctbLN0X37KKF3Aj2PkBCjDMgRDd+78/Gv1GG98=; b=tlaqueQ9jYQFKqkMrFHW+82TDXoRDZTjuee63R58Awcfeu7Zqx9YhfW6QMQfd9cfMD uvgZFYXIZhkSnodsWmVVwzoAeizJ0NFHkiCK98/cOPHjnbXtFrENRAop/FS9w+/TOUa3 5ck6ZuqTO6pJVDyy/6wnsSxEgN+D5/HJHj2SUUlXyYvAE8NITLCHD/r4jPjQikt6qSjV YWVWjW/nkwlyToZP/Wh9uzFMCIDJZuS3z6XGQSieIaYfGNKXHxhNTOlOEZZetBF71laE U929eJB41jrrimG4WfsdDnwSno2EhBIwI5/9jhrxhXv1BePm93eBEAhzsA8xRRdG/42t YO1g== X-Gm-Message-State: AO0yUKViLc6z+2E19yEiLWAsjcU2WgzeK5c7i1Hd5tHlqk2ctK98y9DQ kLDeTy2zLXftZZcBkcUF1iT/rinDKQecPXgwyYw= X-Google-Smtp-Source: AK7set+kbgkO0xYcIfALEaMQ3URs/Gg48aA5WIJtUSrrOKjk1+heIZ1I7EoUZOCEb4HMmQ0fJRPLFQ== X-Received: by 2002:ac2:5229:0:b0:4da:b5d4:efd5 with SMTP id i9-20020ac25229000000b004dab5d4efd5mr2902410lfl.60.1677080044182; Wed, 22 Feb 2023 07:34:04 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 12/20] xen/arm: ffa: send guest events to Secure Partitions Date: Wed, 22 Feb 2023 16:33:09 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The FF-A specification defines framework messages sent as direct requests when certain events occurs. For instance when a VM (guest) is created or destroyed. Only SPs which have subscribed to these events will receive them. An SP can subscribe to these messages in its partition properties. Adds a check that the SP supports the needed FF-A features FFA_PARTITION_INFO_GET and FFA_RX_RELEASE. The partition properties of each SP is retrieved with FFA_PARTITION_INFO_GET which returns the information in our RX buffer. Using FFA_PARTITION_INFO_GET changes the owner of the RX buffer to the caller (us), so once we're done with the buffer it must be released using FFA_RX_RELEASE before another call can be made. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 191 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 07dd5c36d54b..f1b014b6c7f4 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -140,6 +140,14 @@ #define FFA_MSG_SEND 0x8400006EU #define FFA_MSG_POLL 0x8400006AU +/* Partition information descriptor */ +struct ffa_partition_info_1_1 { + uint16_t id; + uint16_t execution_context; + uint32_t partition_properties; + uint8_t uuid[16]; +}; + struct ffa_ctx { uint32_t guest_vers; bool interrupted; @@ -148,6 +156,12 @@ struct ffa_ctx { /* Negotiated FF-A version to use with the SPMC */ static uint32_t ffa_version __ro_after_init; +/* SPs subscribing to VM_CREATE and VM_DESTROYED events */ +static uint16_t *subscr_vm_created __read_mostly; +static unsigned int subscr_vm_created_count __read_mostly; +static uint16_t *subscr_vm_destroyed __read_mostly; +static unsigned int subscr_vm_destroyed_count __read_mostly; + /* * Our rx/tx buffers shared with the SPMC. * @@ -237,6 +251,72 @@ static int32_t ffa_rxtx_map(register_t tx_addr, register_t rx_addr, return ffa_simple_call(fid, tx_addr, rx_addr, page_count, 0); } +static int32_t ffa_partition_info_get(uint32_t w1, uint32_t w2, uint32_t w3, + uint32_t w4, uint32_t w5, + uint32_t *count) +{ + const struct arm_smccc_1_2_regs arg = { + .a0 = FFA_PARTITION_INFO_GET, + .a1 = w1, + .a2 = w2, + .a3 = w3, + .a4 = w4, + .a5 = w5, + }; + struct arm_smccc_1_2_regs resp; + uint32_t ret; + + arm_smccc_1_2_smc(&arg, &resp); + + ret = get_ffa_ret_code(&resp); + if ( !ret ) + *count = resp.a2; + + return ret; +} + +static int32_t ffa_rx_release(void) +{ + return ffa_simple_call(FFA_RX_RELEASE, 0, 0, 0, 0); +} + +static int32_t ffa_direct_req_send_vm(uint16_t sp_id, uint16_t vm_id, + uint8_t msg) +{ + uint32_t exp_resp = FFA_MSG_FLAG_FRAMEWORK; + int32_t res; + + if ( msg == FFA_MSG_SEND_VM_CREATED ) + exp_resp |= FFA_MSG_RESP_VM_CREATED; + else if ( msg == FFA_MSG_SEND_VM_DESTROYED ) + exp_resp |= FFA_MSG_RESP_VM_DESTROYED; + else + return FFA_RET_INVALID_PARAMETERS; + + do { + const struct arm_smccc_1_2_regs arg = { + .a0 = FFA_MSG_SEND_DIRECT_REQ_32, + .a1 = sp_id, + .a2 = FFA_MSG_FLAG_FRAMEWORK | msg, + .a5 = vm_id, + }; + struct arm_smccc_1_2_regs resp; + + arm_smccc_1_2_smc(&arg, &resp); + if ( resp.a0 != FFA_MSG_SEND_DIRECT_RESP_32 || resp.a2 != exp_resp ) + { + /* + * This is an invalid response, likely due to some error in the + * implementation of the ABI. + */ + return FFA_RET_INVALID_PARAMETERS; + } + res = resp.a3; + } while ( res == FFA_RET_INTERRUPTED || res == FFA_RET_RETRY ); + + return res; +} + static uint16_t get_vm_id(const struct domain *d) { /* +1 since 0 is reserved for the hypervisor in FF-A */ @@ -371,6 +451,10 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) static int ffa_domain_init(struct domain *d) { struct ffa_ctx *ctx; + unsigned int n; + unsigned int m; + unsigned int c_pos; + int32_t res; /* * We can't use that last possible domain ID or get_vm_id() would cause @@ -383,24 +467,121 @@ static int ffa_domain_init(struct domain *d) if ( !ctx ) return -ENOMEM; + for ( n = 0; n < subscr_vm_created_count; n++ ) + { + res = ffa_direct_req_send_vm(subscr_vm_created[n], get_vm_id(d), + FFA_MSG_SEND_VM_CREATED); + if ( res ) + { + printk(XENLOG_ERR "ffa: Failed to report creation of vm_id %u to %u: res %d\n", + get_vm_id(d), subscr_vm_created[n], res); + c_pos = n; + goto err; + } + } + d->arch.tee = ctx; return 0; + +err: + /* Undo any already sent vm created messaged */ + for ( n = 0; n < c_pos; n++ ) + for ( m = 0; m < subscr_vm_destroyed_count; m++ ) + if ( subscr_vm_destroyed[m] == subscr_vm_created[n] ) + ffa_direct_req_send_vm(subscr_vm_destroyed[n], get_vm_id(d), + FFA_MSG_SEND_VM_DESTROYED); + + return -ENOMEM; } /* This function is supposed to undo what ffa_domain_init() has done */ static int ffa_relinquish_resources(struct domain *d) { struct ffa_ctx *ctx = d->arch.tee; + unsigned int n; + int32_t res; if ( !ctx ) return 0; + for ( n = 0; n < subscr_vm_destroyed_count; n++ ) + { + res = ffa_direct_req_send_vm(subscr_vm_destroyed[n], get_vm_id(d), + FFA_MSG_SEND_VM_DESTROYED); + + if ( res ) + printk(XENLOG_ERR "ffa: Failed to report destruction of vm_id %u to %u: res %d\n", + get_vm_id(d), subscr_vm_destroyed[n], res); + } + XFREE(d->arch.tee); return 0; } +static bool init_subscribers(void) +{ + struct ffa_partition_info_1_1 *fpi; + bool ret = false; + uint32_t count; + int e; + uint32_t n; + uint32_t c_pos; + uint32_t d_pos; + + if ( ffa_version < FFA_VERSION_1_1 ) + return true; + + e = ffa_partition_info_get(0, 0, 0, 0, 0, &count); + if ( e ) + { + printk(XENLOG_ERR "ffa: Failed to get list of SPs: %d\n", e); + goto out; + } + + fpi = ffa_rx; + subscr_vm_created_count = 0; + subscr_vm_destroyed_count = 0; + for ( n = 0; n < count; n++ ) + { + if (fpi[n].partition_properties & FFA_PART_PROP_NOTIF_CREATED) + subscr_vm_created_count++; + if (fpi[n].partition_properties & FFA_PART_PROP_NOTIF_DESTROYED) + subscr_vm_destroyed_count++; + } + + if ( subscr_vm_created_count ) + subscr_vm_created = xzalloc_array(uint16_t, subscr_vm_created_count); + if ( subscr_vm_destroyed_count ) + subscr_vm_destroyed = xzalloc_array(uint16_t, + subscr_vm_destroyed_count); + if ( (subscr_vm_created_count && !subscr_vm_created) || + (subscr_vm_destroyed_count && !subscr_vm_destroyed) ) + { + printk(XENLOG_ERR "ffa: Failed to allocate subscription lists\n"); + subscr_vm_created_count = 0; + subscr_vm_destroyed_count = 0; + XFREE(subscr_vm_created); + XFREE(subscr_vm_destroyed); + goto out; + } + + for ( c_pos = 0, d_pos = 0, n = 0; n < count; n++ ) + { + if ( fpi[n].partition_properties & FFA_PART_PROP_NOTIF_CREATED ) + subscr_vm_created[c_pos++] = fpi[n].id; + if ( fpi[n].partition_properties & FFA_PART_PROP_NOTIF_DESTROYED ) + subscr_vm_destroyed[d_pos++] = fpi[n].id; + } + + ret = true; +out: + ffa_rx_release(); + + return ret; +} + static bool ffa_probe(void) { uint32_t vers; @@ -447,7 +628,8 @@ static bool ffa_probe(void) printk(XENLOG_INFO "ARM FF-A Firmware version %u.%u\n", major_vers, minor_vers); - if ( + if ( !check_mandatory_feature(FFA_PARTITION_INFO_GET) || + !check_mandatory_feature(FFA_RX_RELEASE) || #ifdef CONFIG_ARM_64 !check_mandatory_feature(FFA_RXTX_MAP_64) || #endif @@ -475,6 +657,9 @@ static bool ffa_probe(void) ffa_page_count = 1; ffa_version = vers; + if ( !init_subscribers() ) + goto err_free_ffa_tx; + return true; err_free_ffa_tx: @@ -485,6 +670,10 @@ err_free_ffa_rx: ffa_rx = NULL; ffa_page_count = 0; ffa_version = 0; + XFREE(subscr_vm_created); + subscr_vm_created_count = 0; + XFREE(subscr_vm_destroyed); + subscr_vm_destroyed_count = 0; return false; } From patchwork Wed Feb 22 15:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FFDDC6FA9D for ; Wed, 22 Feb 2023 15:34:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499550.770825 (Exim 4.92) (envelope-from ) id 1pUr8G-00042x-Gt; Wed, 22 Feb 2023 15:34:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499550.770825; Wed, 22 Feb 2023 15:34:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8F-0003yw-79; Wed, 22 Feb 2023 15:34:11 +0000 Received: by outflank-mailman (input) for mailman id 499550; Wed, 22 Feb 2023 15:34:06 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8A-0001MC-9x for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:06 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 57258fdd-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:34:05 +0100 (CET) Received: by mail-lf1-x132.google.com with SMTP id w27so10583569lfu.4 for ; Wed, 22 Feb 2023 07:34:05 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:04 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 57258fdd-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cS+8KCwx/w81eQ/g9wS82HyI0n3UdnJ7LzOtx2RTVL8=; b=bQvRcXo07xFoAPdUYDd6yJX5vesisEukCPpmrxVmhT5GYEb4VzZiKujwBo2PHqc2uV JX449HIVFh15Qxxwp+FWhevN8Upr/P2WSy2pdrNHk24uxHZYopBxI98GvEzKj2gt7fX7 5BkfawNB8ZFuZ2/GZqDM0EN4YN+A7f4ghRgl8aEGpT2PMe+ZoAq2XwfkcezRQwK8BR4N eeIE+0Akk5LL0/uQsS2xyJUdkVjJsgHgT4uoiCwYk9S8ysOHDtZ1CRZWN04FytCGTIv3 /p1SyNNGxi+PxgjySWCokiR7CPvOVXUdsY9We+QB2fwohK/qEEj8I34bgTRmk44Aqeo0 YCnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cS+8KCwx/w81eQ/g9wS82HyI0n3UdnJ7LzOtx2RTVL8=; b=fQcWCiOB5c3dhgxqOWo8W9XUkVSYxJyiSftCdwJCLMUkRNg75Q9eEI2Ck8aXURv9xx TZsSBj2HPrZ85bazRMQXrXM9e4QhsrjUxJWwHcOkKafR4UrTT4lXE2FBr9bAyj7wH2kc Knv+X9czY3hMSNP/3ABiV/Of2Pr98qog1OtcBShkre1nX4REuFldrbKeURCq+0Hn65Bv 5m2IU0gSANicwQefp7YdFfMZENd7/nMC3sSkJhFjQdSfMbuT1F1SQuJseYvTPzbiAjNh /Dl+vN4/BacWdkOkOy9t9zfnlonOyAgALgg/NJOhrP4O97bihNW8hW58MrkJcpt60+c3 xbvw== X-Gm-Message-State: AO0yUKUoU75Jypkf01egxfLM/M2oNanqRiHbIpXeFuIB1819t4WfU5Ey 8UD3tlyOBbrov1yyMdQ8jbLF+ZbIx5X+pnsXrGk= X-Google-Smtp-Source: AK7set+s2js1Y9IyBYq/3+57C2Q5sWOQATXUGDSMOT3Gxj/f5u8Icwuc5V/KVEXvPSOj1xaGwIG+iQ== X-Received: by 2002:ac2:5615:0:b0:4d8:6540:a731 with SMTP id v21-20020ac25615000000b004d86540a731mr2937063lfd.47.1677080044956; Wed, 22 Feb 2023 07:34:04 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 13/20] xen/arm: ffa: support mapping guest RX/TX buffers Date: Wed, 22 Feb 2023 16:33:10 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support in the mediator to map and unmap the RX and TX buffers provided by the guest using the two FF-A functions FFA_RXTX_MAP and FFA_RXTX_UNMAP. These buffer are later used to to transmit data that cannot be passed in registers only. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 127 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index f1b014b6c7f4..953b6dfd5eca 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -149,10 +149,17 @@ struct ffa_partition_info_1_1 { }; struct ffa_ctx { + void *rx; + const void *tx; + struct page_info *rx_pg; + struct page_info *tx_pg; + unsigned int page_count; uint32_t guest_vers; + bool tx_is_mine; bool interrupted; }; + /* Negotiated FF-A version to use with the SPMC */ static uint32_t ffa_version __ro_after_init; @@ -337,6 +344,11 @@ static void set_regs(struct cpu_user_regs *regs, register_t v0, register_t v1, set_user_reg(regs, 7, v7); } +static void set_regs_error(struct cpu_user_regs *regs, uint32_t error_code) +{ + set_regs(regs, FFA_ERROR, 0, error_code, 0, 0, 0, 0, 0); +} + static void set_regs_success(struct cpu_user_regs *regs, uint32_t w2, uint32_t w3) { @@ -358,6 +370,99 @@ static void handle_version(struct cpu_user_regs *regs) set_regs(regs, vers, 0, 0, 0, 0, 0, 0, 0); } +static uint32_t handle_rxtx_map(uint32_t fid, register_t tx_addr, + register_t rx_addr, uint32_t page_count) +{ + uint32_t ret = FFA_RET_INVALID_PARAMETERS; + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + struct page_info *tx_pg; + struct page_info *rx_pg; + p2m_type_t t; + void *rx; + void *tx; + + if ( !smccc_is_conv_64(fid) ) + { + tx_addr &= UINT32_MAX; + rx_addr &= UINT32_MAX; + } + + /* For now to keep things simple, only deal with a single page */ + if ( page_count != 1 ) + return FFA_RET_NOT_SUPPORTED; + + /* Already mapped */ + if ( ctx->rx ) + return FFA_RET_DENIED; + + tx_pg = get_page_from_gfn(d, gfn_x(gaddr_to_gfn(tx_addr)), &t, P2M_ALLOC); + if ( !tx_pg ) + return FFA_RET_INVALID_PARAMETERS; + /* Only normal RAM for now */ + if ( !p2m_is_ram(t) ) + goto err_put_tx_pg; + + rx_pg = get_page_from_gfn(d, gfn_x(gaddr_to_gfn(rx_addr)), &t, P2M_ALLOC); + if ( !tx_pg ) + goto err_put_tx_pg; + /* Only normal RAM for now */ + if ( !p2m_is_ram(t) ) + goto err_put_rx_pg; + + tx = __map_domain_page_global(tx_pg); + if ( !tx ) + goto err_put_rx_pg; + + rx = __map_domain_page_global(rx_pg); + if ( !rx ) + goto err_unmap_tx; + + ctx->rx = rx; + ctx->tx = tx; + ctx->rx_pg = rx_pg; + ctx->tx_pg = tx_pg; + ctx->page_count = 1; + ctx->tx_is_mine = true; + return FFA_RET_OK; + +err_unmap_tx: + unmap_domain_page_global(tx); +err_put_rx_pg: + put_page(rx_pg); +err_put_tx_pg: + put_page(tx_pg); + + return ret; +} + +static void rxtx_unmap(struct ffa_ctx *ctx) +{ + unmap_domain_page_global(ctx->rx); + unmap_domain_page_global(ctx->tx); + put_page(ctx->rx_pg); + put_page(ctx->tx_pg); + ctx->rx = NULL; + ctx->tx = NULL; + ctx->rx_pg = NULL; + ctx->tx_pg = NULL; + ctx->page_count = 0; + ctx->tx_is_mine = false; +} + +static uint32_t handle_rxtx_unmap(void) +{ + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + + if ( !ctx->rx ) + return FFA_RET_INVALID_PARAMETERS; + + rxtx_unmap(ctx); + + return FFA_RET_OK; +} + static void handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_t fid) { struct arm_smccc_1_2_regs arg = { .a0 = fid, }; @@ -423,6 +528,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) uint32_t fid = get_user_reg(regs, 0); struct domain *d = current->domain; struct ffa_ctx *ctx = d->arch.tee; + int e; if ( !ctx ) return false; @@ -435,6 +541,24 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) case FFA_ID_GET: set_regs_success(regs, get_vm_id(d), 0); return true; + case FFA_RXTX_MAP_32: +#ifdef CONFIG_ARM_64 + case FFA_RXTX_MAP_64: +#endif + e = handle_rxtx_map(fid, get_user_reg(regs, 1), get_user_reg(regs, 2), + get_user_reg(regs, 3)); + if ( e ) + set_regs_error(regs, e); + else + set_regs_success(regs, 0, 0); + return true; + case FFA_RXTX_UNMAP: + e = handle_rxtx_unmap(); + if ( e ) + set_regs_error(regs, e); + else + set_regs_success(regs, 0, 0); + return true; case FFA_MSG_SEND_DIRECT_REQ_32: #ifdef CONFIG_ARM_64 case FFA_MSG_SEND_DIRECT_REQ_64: @@ -515,6 +639,9 @@ static int ffa_relinquish_resources(struct domain *d) get_vm_id(d), subscr_vm_destroyed[n], res); } + if ( ctx->rx ) + rxtx_unmap(ctx); + XFREE(d->arch.tee); return 0; From patchwork Wed Feb 22 15:33:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06623C6FD19 for ; Wed, 22 Feb 2023 15:34:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499551.770832 (Exim 4.92) (envelope-from ) id 1pUr8H-0004HR-7C; Wed, 22 Feb 2023 15:34:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499551.770832; Wed, 22 Feb 2023 15:34:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8G-0004CY-9y; Wed, 22 Feb 2023 15:34:12 +0000 Received: by outflank-mailman (input) for mailman id 499551; Wed, 22 Feb 2023 15:34:07 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8B-0001MC-A9 for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:07 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 579dbb43-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:34:06 +0100 (CET) Received: by mail-lf1-x132.google.com with SMTP id f41so10501931lfv.13 for ; Wed, 22 Feb 2023 07:34:06 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:05 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 579dbb43-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PKen3qJPmkTvDeSAkak1h6D6WS5xyInpmZTn/4tNUg8=; b=a6V1ggfXAR5GzGDCNUPBm18CgChnXa1ayRPDFApfPH9Pgwg5cmjbYd2l0wkfBDDDkW N0v4szwyfOBMZJ7ONe1XLyjf8zh5XScn2DuE19tmjBOFW8t3Gzmsi+NFpdAcz5WuTAIX mNrYRanN3NLBG19vo6ES/EHVmuCx0NOnew2aCSEXARn23Ny4zfi2B8ywQEDWcK8JjMEj DPurICq7hEUbkgEZLLX2xR/SJEnf7IRbwvKpHxkkgck1lwxsx6xpwzfM2Z2jS5WegLry 4laj1Y+Hl8DaZY0pjSOtBsJ93HeyivCzJSpPaGu9vOm73X9HlVOTYmZv69tw00izK01+ QREQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PKen3qJPmkTvDeSAkak1h6D6WS5xyInpmZTn/4tNUg8=; b=yn/7naHkl1qJglGUTKepVITi1uAnSD7J76rv9fSLUNVQllLFI+9dQUR6nptKMM1n2U G2mt0MJxzEZpOe4M/+iarJxYMKUDMIQAkfCWyRHoqEkLgyV4itgZ+PwV761EfN+YWofF dzDCUA+phPv1zI+RZgFotc+lC1AWPjkkVMm/JfG3gSdlOpmaKjdIasZz15TyQ0JGfIhs ANLvQXyHwpgdFsuFMOZ3bGUQRB4flNuX+r+9+7P9qdlyXGTmL0bNRT1sMcFaIYtoPbnE alj++2PkASQw6BKgSvTBy9blmi5305D+RYI6/ucYTGiR4+Q/imde4kJVt9oYIctPHktu dnWA== X-Gm-Message-State: AO0yUKUhTCAN9D6GQEwHjouJVEdwhbbSD02UGq4S6dwkLW+MM0NFmnZF kfDrsTQ6bMTN1FQTj20C4WTU+6CM83/UjVPqEOw= X-Google-Smtp-Source: AK7set+0o0Ptn4JK86nuCdJ1Z4yrG0grXUD+actcFpHCgn3J/tEoAMIddbOZsMfrFPicXzS30zyXwA== X-Received: by 2002:ac2:4479:0:b0:4da:ffb1:9872 with SMTP id y25-20020ac24479000000b004daffb19872mr3228121lfl.4.1677080045700; Wed, 22 Feb 2023 07:34:05 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 14/20] xen/arm: ffa: support guest FFA_PARTITION_INFO_GET Date: Wed, 22 Feb 2023 16:33:11 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support in the mediator to handle FFA_PARTITION_INFO_GET requests from a guest. The requests are forwarded to the SPMC and the response is translated according to the FF-A version in use by the guest. Using FFA_PARTITION_INFO_GET changes the owner of the RX buffer to the caller (the guest in this case), so once it is done with the buffer it must be released using FFA_RX_RELEASE before another call can be made. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 126 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 953b6dfd5eca..3571817c0bcd 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -141,6 +141,12 @@ #define FFA_MSG_POLL 0x8400006AU /* Partition information descriptor */ +struct ffa_partition_info_1_0 { + uint16_t id; + uint16_t execution_context; + uint32_t partition_properties; +}; + struct ffa_partition_info_1_1 { uint16_t id; uint16_t execution_context; @@ -157,9 +163,8 @@ struct ffa_ctx { uint32_t guest_vers; bool tx_is_mine; bool interrupted; + spinlock_t lock; }; - - /* Negotiated FF-A version to use with the SPMC */ static uint32_t ffa_version __ro_after_init; @@ -173,10 +178,16 @@ static unsigned int subscr_vm_destroyed_count __read_mostly; * Our rx/tx buffers shared with the SPMC. * * ffa_page_count is the number of pages used in each of these buffers. + * + * The RX buffer is protected from concurrent usage with ffa_rx_buffer_lock. + * Note that the SPMC is also tracking the ownership of our RX buffer so + * for calls which uses our RX buffer to deliver a result we must call + * ffa_rx_release() to let the SPMC know that we're done with the buffer. */ static void *ffa_rx __read_mostly; static void *ffa_tx __read_mostly; static unsigned int ffa_page_count __read_mostly; +static DEFINE_SPINLOCK(ffa_rx_buffer_lock); static bool ffa_get_version(uint32_t *vers) { @@ -463,6 +474,98 @@ static uint32_t handle_rxtx_unmap(void) return FFA_RET_OK; } +static uint32_t handle_partition_info_get(uint32_t w1, uint32_t w2, uint32_t w3, + uint32_t w4, uint32_t w5, + uint32_t *count) +{ + bool query_count_only = w5 & FFA_PARTITION_INFO_GET_COUNT_FLAG; + uint32_t w5_mask = 0; + uint32_t ret = FFA_RET_DENIED; + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + + /* + * FF-A v1.0 has w5 MBZ while v1.1 allows + * FFA_PARTITION_INFO_GET_COUNT_FLAG to be non-zero. + */ + if ( ctx->guest_vers == FFA_VERSION_1_1 ) + w5_mask = FFA_PARTITION_INFO_GET_COUNT_FLAG; + if ( w5 & ~w5_mask ) + return FFA_RET_INVALID_PARAMETERS; + + if ( query_count_only ) + return ffa_partition_info_get(w1, w2, w3, w4, w5, count); + + if ( !ffa_page_count ) + return FFA_RET_DENIED; + + spin_lock(&ctx->lock); + spin_lock(&ffa_rx_buffer_lock); + if ( !ctx->page_count || !ctx->tx_is_mine ) + goto out; + ret = ffa_partition_info_get(w1, w2, w3, w4, w5, count); + if ( ret ) + goto out; + + if ( ctx->guest_vers == FFA_VERSION_1_0 ) + { + size_t n; + struct ffa_partition_info_1_1 *src = ffa_rx; + struct ffa_partition_info_1_0 *dst = ctx->rx; + + if ( ctx->page_count * FFA_PAGE_SIZE < *count * sizeof(*dst) ) + { + ret = FFA_RET_NO_MEMORY; + goto out_rx_release; + } + + for ( n = 0; n < *count; n++ ) + { + dst[n].id = src[n].id; + dst[n].execution_context = src[n].execution_context; + dst[n].partition_properties = src[n].partition_properties; + } + } + else + { + size_t sz = *count * sizeof(struct ffa_partition_info_1_1); + + if ( ctx->page_count * FFA_PAGE_SIZE < sz ) + { + ret = FFA_RET_NO_MEMORY; + goto out_rx_release; + } + + + memcpy(ctx->rx, ffa_rx, sz); + } + ctx->tx_is_mine = false; +out_rx_release: + ffa_rx_release(); +out: + spin_unlock(&ffa_rx_buffer_lock); + spin_unlock(&ctx->lock); + + return ret; +} + +static uint32_t handle_rx_release(void) +{ + uint32_t ret = FFA_RET_DENIED; + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + + spin_lock(&ctx->lock); + if ( !ctx->page_count || ctx->tx_is_mine ) + goto out; + ret = FFA_RET_OK; + ctx->tx_is_mine = true; +out: + spin_unlock(&ctx->lock); + + return ret; +} + static void handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_t fid) { struct arm_smccc_1_2_regs arg = { .a0 = fid, }; @@ -528,6 +631,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) uint32_t fid = get_user_reg(regs, 0); struct domain *d = current->domain; struct ffa_ctx *ctx = d->arch.tee; + uint32_t count; int e; if ( !ctx ) @@ -559,6 +663,24 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) else set_regs_success(regs, 0, 0); return true; + case FFA_PARTITION_INFO_GET: + e = handle_partition_info_get(get_user_reg(regs, 1), + get_user_reg(regs, 2), + get_user_reg(regs, 3), + get_user_reg(regs, 4), + get_user_reg(regs, 5), &count); + if ( e ) + set_regs_error(regs, e); + else + set_regs_success(regs, count, 0); + return true; + case FFA_RX_RELEASE: + e = handle_rx_release(); + if ( e ) + set_regs_error(regs, e); + else + set_regs_success(regs, 0, 0); + return true; case FFA_MSG_SEND_DIRECT_REQ_32: #ifdef CONFIG_ARM_64 case FFA_MSG_SEND_DIRECT_REQ_64: From patchwork Wed Feb 22 15:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D53D7C677F1 for ; Wed, 22 Feb 2023 15:34:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499552.770837 (Exim 4.92) (envelope-from ) id 1pUr8J-0004aR-2D; Wed, 22 Feb 2023 15:34:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499552.770837; Wed, 22 Feb 2023 15:34:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8H-0004Uq-Mz; Wed, 22 Feb 2023 15:34:13 +0000 Received: by outflank-mailman (input) for mailman id 499552; Wed, 22 Feb 2023 15:34:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8C-0001MH-FF for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:08 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 578f1631-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:06 +0100 (CET) Received: by mail-lf1-x135.google.com with SMTP id f18so10544559lfa.3 for ; Wed, 22 Feb 2023 07:34:06 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:06 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 578f1631-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G/X5KC3KPrylB3VOA87nQRK8zMTV0Yo7K5jzAEfaZqM=; b=BiBI0jbPKBI4welALwUtVN89qYfR1BkiTBwDkT+C+bFarA7eY6ZdgmyUhfcVoS/s7i fXFHx6g832m6SZgh/t7IJsN88hltOFTld2HhEPu4QaYwfl3vANaBPgWrmO5Lp0mGWbDL x+lQPW4lbO9T59cm5Mrgx5T+W/elLyPsnXGTnziFG5UCPI/qdFZvAdwiLSnmOzPRpvW4 drWtFTcmGlkd8EjrT65Gen771+9AQVo9CcDQg1mEtNZMo18qgmcHWJ+ZXVt6m+V0j+oA dbg6qQyOv0n78sT+K9SsZ3VLR7DOx/lFAYF3GIdAg4eVQnd2OptSu0GKMyHTuos75W10 79AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G/X5KC3KPrylB3VOA87nQRK8zMTV0Yo7K5jzAEfaZqM=; b=EbEamxhxbhQsoinuNhFVaSOMWnm+4Ir9PC1Riy3rrRlyewUGof9BGy2y1MToGEnj4t 27Oav7m24cv8xJAtzxofvikeViWexoe7KbfBeXr6D6oAFuKPdAclAmlr0KxtRdC/LwM3 fKZZkZVG3JcNgK88MU8mopICJI94KA1xbgu/VJji1wcFwq98PgsqvXunT4WF7tiWGc1x ga3tiGe8rUkU/pP2koNmXohJM0kfVcF+eYvkVOc/YB1swgDpTuht2Lu2aAI3/huUQCbi bh2MlqxvbeuG50MDCFl+K7WsFGqOmLcmpX7xEK9mYEHJzyDiDSNga3CU50hGMzBTFSg3 sGOw== X-Gm-Message-State: AO0yUKUoPtIcvm/S6FF2vZ4JXarcsFvSBMJswuDCRHkIf3vIERqfsyuU YE26ngsevYlIJhYShkBAo4q3WISZ68/5x4XIxKM= X-Google-Smtp-Source: AK7set+y8n4M2F+vnq1AqE4NZOLtp1Zn6O1TO09h1u14zQ6vavsu3iXYmjkK47rB0n7oRpzNE3zN7w== X-Received: by 2002:a05:6512:31cd:b0:4db:5120:367 with SMTP id j13-20020a05651231cd00b004db51200367mr3754959lfe.31.1677080046518; Wed, 22 Feb 2023 07:34:06 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Michal Orzel Subject: [XEN PATCH v7 15/20] xen/arm: move regpair_to_uint64() and uint64_to_regpair() to regs.h Date: Wed, 22 Feb 2023 16:33:12 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Moves the two helper functions regpair_to_uint64() and uint64_to_regpair() from xen/arch/arm/tee/optee.c to the common arm specific regs.h. This enables reuse of these functions in the FF-A mediator in a subsequent patch. Reviewed-by: Michal Orzel Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/include/asm/regs.h | 12 ++++++++++++ xen/arch/arm/tee/optee.c | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/include/asm/regs.h b/xen/arch/arm/include/asm/regs.h index 0693a681315f..aa39e83ee5f4 100644 --- a/xen/arch/arm/include/asm/regs.h +++ b/xen/arch/arm/include/asm/regs.h @@ -60,6 +60,18 @@ static inline bool guest_mode(const struct cpu_user_regs *r) register_t get_user_reg(struct cpu_user_regs *regs, int reg); void set_user_reg(struct cpu_user_regs *regs, int reg, register_t val); +static inline uint64_t regpair_to_uint64(register_t reg0, register_t reg1) +{ + return ((uint64_t)reg0 << 32) | (uint32_t)reg1; +} + +static inline void uint64_to_regpair(register_t *reg0, register_t *reg1, + uint64_t val) +{ + *reg0 = val >> 32; + *reg1 = (uint32_t)val; +} + #endif #endif /* __ARM_REGS_H__ */ diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c index 9cb9f16d43cb..47027ecef47c 100644 --- a/xen/arch/arm/tee/optee.c +++ b/xen/arch/arm/tee/optee.c @@ -268,17 +268,6 @@ static int optee_domain_init(struct domain *d) return 0; } -static uint64_t regpair_to_uint64(register_t reg0, register_t reg1) -{ - return ((uint64_t)reg0 << 32) | (uint32_t)reg1; -} - -static void uint64_to_regpair(register_t *reg0, register_t *reg1, uint64_t val) -{ - *reg0 = val >> 32; - *reg1 = (uint32_t)val; -} - static struct page_info *get_domain_ram_page(gfn_t gfn) { struct page_info *page; From patchwork Wed Feb 22 15:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7CB13C6FA9E for ; Wed, 22 Feb 2023 15:34:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499553.770849 (Exim 4.92) (envelope-from ) id 1pUr8K-0004ro-Ai; Wed, 22 Feb 2023 15:34:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499553.770849; Wed, 22 Feb 2023 15:34:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8J-0004iT-6u; Wed, 22 Feb 2023 15:34:15 +0000 Received: by outflank-mailman (input) for mailman id 499553; Wed, 22 Feb 2023 15:34:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8C-0001MC-Bc for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:08 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 589ce21f-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:34:07 +0100 (CET) Received: by mail-lf1-x136.google.com with SMTP id g8so6807600lfj.2 for ; Wed, 22 Feb 2023 07:34:07 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:07 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 589ce21f-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qhAiY5OLLPHeZBZaC/MjkG52+6CXwzhSsS3y4KPhi9A=; b=cky4pHS//IDFn8KcURyNgEQyvp6E4MB4IMdKlCgh47mvVsRQlq9BRRMlVq8DdZL8jb eMuzQbcLf4sF/lfyHIHRni4sEPnlikqeVLYcW5Ku+sGPopazRytm7RDXOhc739bzWQsI JySIaXdFwJjbsHB2ePyF4iiiWuClN+EUfie3s/rkur03emkjT57nxcpg/0abTSwpQ89S mZD/CJtVpeZnvrccbmeva3AsuRZWB4l68xCDfjIYKKVaEPOwVvryAn6PUzOm4ZjnFutJ WpHEmbRuXwSd/QQbYwtmz/5SiySYHrNKK4JNk6eSrm97uIVFnlBPofTOjRry2XxdVyLf zhQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qhAiY5OLLPHeZBZaC/MjkG52+6CXwzhSsS3y4KPhi9A=; b=i/OCr7sKGqRbCgT3VHvEK1Q30aBJJa2FQjlPWbPQGZWrp2VIXydpOmMPVxQXTULY0j EuVJkPaQlHIC2ZpnFPmmi0ubjSPjG+etcFGGgHe/KOPToOsQSICt+aSZgQOe6z/0gjA9 TFi6vLNcGgGgsN3D9mypiyEbXGqziKJZ2KwzVO6L2X4aFeYY201qlunPEbXwPK0B375A mT/FR2HRiqqDNTiiZIm1feKSMAC9l4jBXlXimC/a93M7oXE7WrxPwOx/CzkjCLsCO33H ZD5vZC9JxTxrqEVsQcrXINl6SwleOFaYBTnkpMkU7PJq8jmitiuW7uTdY/0ddu0NVMw0 RPMQ== X-Gm-Message-State: AO0yUKXzjSJH3yloYpRtBwlRBqCzBjQFyQEWvxoIstqpJqAyVhust2W5 IKikGaRX5E7SHvyk8XsoEQMySJUmOmgRb0HZ3D4= X-Google-Smtp-Source: AK7set/kmBjenoML7LDyTljAhBrKRq++3DX/KZvrrW+9a4EJ0hpd35LEVJfNiOGCpNNLk1MoOSkTyg== X-Received: by 2002:ac2:54b0:0:b0:4d2:72bf:7382 with SMTP id w16-20020ac254b0000000b004d272bf7382mr2950346lfk.37.1677080047369; Wed, 22 Feb 2023 07:34:07 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 16/20] xen/arm: ffa: add defines for sharing memory Date: Wed, 22 Feb 2023 16:33:13 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds defines needed for sharing using the function FFA_MEM_SHARE and friends. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 3571817c0bcd..bfd378f7fcd7 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -22,6 +22,14 @@ #include #include +/* + * References: + * FF-A-1.0-REL: FF-A specification version 1.0 available at + * https://developer.arm.com/documentation/den0077/a + * FF-A-1.1-REL0: FF-A specification version 1.1 available at + * https://developer.arm.com/documentation/den0077/e + */ + /* Error codes */ #define FFA_RET_OK 0 #define FFA_RET_NOT_SUPPORTED -1 @@ -66,6 +74,55 @@ */ #define FFA_PAGE_SIZE SZ_4K +/* + * Limit for shared buffer size. Please note that this define limits + * number of pages. But user buffer can be not aligned to a page + * boundary. So it is possible that user would not be able to share + * exactly FFA_MAX_SHM_BUFFER_PG * FFA_PAGE_SIZE bytes. + * + * FF-A doesn't have any direct requirments on GlobalPlatform or vice + * versa, but an implementation can very well use FF-A in order to provide + * a GlobalPlatform interface on top. + * + * Global Platform specification for TEE requires that any TEE + * implementation should allow to share buffers with size of at least + * 512KB. Due to align issue mentioned above, we need to increase this + * value with one. + */ +#define FFA_MAX_SHM_PAGE_COUNT (SZ_512K / FFA_PAGE_SIZE + 1) + +/* + * Limits the number of shared buffers that guest can have at once. This + * is to prevent case, when guests tricks XEN into exhausting its own + * memory by allocating many small buffers. This value has been chosen + * arbitrary. + */ +#define FFA_MAX_SHM_COUNT 32 + +/* FF-A-1.1-REL0 section 10.9.2 Memory region handle, page 167 */ +#define FFA_HANDLE_HYP_FLAG BIT(63, ULL) +#define FFA_HANDLE_INVALID 0xffffffffffffffffULL + +/* + * The bits for FFA_NORMAL_MEM_REG_ATTR FFA_MEM_ACC_RW below are + * defined in FF-A-1.1-REL0 Table 10.18 at page 175. + */ + /* Memory attributes: Normal memory, Write-Back cacheable, Inner shareable */ +#define FFA_NORMAL_MEM_REG_ATTR 0x2fU +/* Memory access permissions: Read-write */ +#define FFA_MEM_ACC_RW 0x2U + +/* FF-A-1.1-REL0 section 10.11.4 Flags usage, page 184-187 */ +/* Clear memory before mapping in receiver */ +#define FFA_MEMORY_REGION_FLAG_CLEAR BIT(0, U) +/* Relayer may time slice this operation */ +#define FFA_MEMORY_REGION_FLAG_TIME_SLICE BIT(1, U) +/* Clear memory after receiver relinquishes it */ +#define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH BIT(2, U) +/* Share memory transaction */ +#define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE (1U << 3) + + /* Framework direct request/response */ #define FFA_MSG_FLAG_FRAMEWORK BIT(31, U) #define FFA_MSG_TYPE_MASK 0xFFU; From patchwork Wed Feb 22 15:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B5C0C61DA4 for ; Wed, 22 Feb 2023 15:34:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499554.770862 (Exim 4.92) (envelope-from ) id 1pUr8N-0005Pj-5s; Wed, 22 Feb 2023 15:34:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499554.770862; Wed, 22 Feb 2023 15:34:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8L-0005HY-VU; Wed, 22 Feb 2023 15:34:17 +0000 Received: by outflank-mailman (input) for mailman id 499554; Wed, 22 Feb 2023 15:34:11 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8E-0001MH-Nb for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:10 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 58c7bb9a-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:08 +0100 (CET) Received: by mail-lf1-x12d.google.com with SMTP id i9so10367529lfc.6 for ; Wed, 22 Feb 2023 07:34:09 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:07 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 58c7bb9a-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8mpbdpWvkQP3NZC61nZP/NPeTV2c8jtDhk5/FkNx/Xw=; b=hmD0HnFwUA9POGeBbCmOz3zaonZ39Kq5HvhDBcqw4q4BOOQV/dU0BVezOkVQShkaoM ZsXwZKJYYOFCM7MY0jtygaykHy/TqeFJHl/nToc3gyFVK3WEy4QdS3tZJSvsk/2L5Pxd 24i+LVCwqjOJtB2JPUiQCQajkohPAKRb9SQJayOwH9ayLS/WwM+yem+vjYAGtOxkWbzi k1jtSfjVv0jFUXJ+jGK/bDU1WkhAtdbH+0rb3+R1RgnhnDOFxGm4rhsFdzoswJWFXDP2 wa0lZaL/nZJhSTSKBRaLFZws+puREJRWuRnGrHVsriSZmpv8g9N6+WAd91ybtpI8nwgI 0xiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8mpbdpWvkQP3NZC61nZP/NPeTV2c8jtDhk5/FkNx/Xw=; b=EyJe4d9v6CWMr9+CXlOFvGi+YefvsIA8juXmwqL+z8oo5pQws4lBTVCyqmUrqmkdLv GV/0Z/A19Mgjm/NoNiTHcvrLMBUcZv+FftLKkrAI9Mal2kfWnEz319edpyqtlSUHeJ98 Apv1hXupx8JM53Lsgnq+zjjZ3vhLZEJEUAFcc5hGClaSsUNET2fu2Ck6t6b6MSvCSttz oolYJEzCRIH66WI9EIo12U4WUnpubwudfVStrdDcDI2gTauK22Fp232Ji2XHJzPHkhct G1YCDaQDORmHW0fRYHc7PXgd0Pp0WhcNevCLxZwiCU5DHg89jE79S8+1LDCwpZ4PrYTD WRXg== X-Gm-Message-State: AO0yUKW0scNVQk/EARNBIKtLvgWOkcIqwfLhN5ClHsqfQJu6ZuN6Hk/X DOYG1K1HJNm1SQQY5MjDKNZ34f+gCRm6zREQ1KE= X-Google-Smtp-Source: AK7set+0TRegHa85MMH11cxIFnQQ6a0Xj9077dunvyV3UVJYeFbfsDVnZWDz2A/+evM6CP8tk9cPHQ== X-Received: by 2002:ac2:4c0f:0:b0:4cb:2c19:ec21 with SMTP id t15-20020ac24c0f000000b004cb2c19ec21mr2816894lfq.0.1677080048376; Wed, 22 Feb 2023 07:34:08 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 17/20] xen/arm: ffa: add ABI structs for sharing memory Date: Wed, 22 Feb 2023 16:33:14 +0100 Message-Id: <50da283fe4a91820a818d13db4ce50fd8414580a.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds the ABI structs used by function FFA_MEM_SHARE and friends for sharing memory. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa.c | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index bfd378f7fcd7..94c90b252454 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -197,6 +197,11 @@ #define FFA_MSG_SEND 0x8400006EU #define FFA_MSG_POLL 0x8400006AU +/* + * Structs below ending with _1_0 are defined in FF-A-1.0-REL and + * struct ending with _1_1 are defined in FF-A-1.1-REL0. + */ + /* Partition information descriptor */ struct ffa_partition_info_1_0 { uint16_t id; @@ -211,6 +216,75 @@ struct ffa_partition_info_1_1 { uint8_t uuid[16]; }; +/* Constituent memory region descriptor */ +struct ffa_address_range { + uint64_t address; + uint32_t page_count; + uint32_t reserved; +}; + +/* Composite memory region descriptor */ +struct ffa_mem_region { + uint32_t total_page_count; + uint32_t address_range_count; + uint64_t reserved; + struct ffa_address_range address_range_array[]; +}; + +/* Memory access permissions descriptor */ +struct ffa_mem_access_perm { + uint16_t endpoint_id; + uint8_t perm; + uint8_t flags; +}; + +/* Endpoint memory access descriptor */ +struct ffa_mem_access { + struct ffa_mem_access_perm access_perm; + uint32_t region_offs; + uint64_t reserved; +}; + +/* Lend, donate or share memory transaction descriptor */ +struct ffa_mem_transaction_1_0 { + uint16_t sender_id; + uint8_t mem_reg_attr; + uint8_t reserved0; + uint32_t flags; + uint64_t global_handle; + uint64_t tag; + uint32_t reserved1; + uint32_t mem_access_count; + struct ffa_mem_access mem_access_array[]; +}; + +struct ffa_mem_transaction_1_1 { + uint16_t sender_id; + uint16_t mem_reg_attr; + uint32_t flags; + uint64_t global_handle; + uint64_t tag; + uint32_t mem_access_size; + uint32_t mem_access_count; + uint32_t mem_access_offs; + uint8_t reserved[12]; +}; + +/* Endpoint RX/TX descriptor */ +struct ffa_endpoint_rxtx_descriptor_1_0 { + uint16_t sender_id; + uint16_t reserved; + uint32_t rx_range_count; + uint32_t tx_range_count; +}; + +struct ffa_endpoint_rxtx_descriptor_1_1 { + uint16_t sender_id; + uint16_t reserved; + uint32_t rx_region_offs; + uint32_t tx_region_offs; +}; + struct ffa_ctx { void *rx; const void *tx; From patchwork Wed Feb 22 15:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9034BC677F1 for ; Wed, 22 Feb 2023 15:34:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499555.770874 (Exim 4.92) (envelope-from ) id 1pUr8O-00061J-Uy; Wed, 22 Feb 2023 15:34:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499555.770874; Wed, 22 Feb 2023 15:34:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8N-0005sA-TL; Wed, 22 Feb 2023 15:34:19 +0000 Received: by outflank-mailman (input) for mailman id 499555; Wed, 22 Feb 2023 15:34:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8E-0001MC-Vd for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:11 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 59ccab43-b2c6-11ed-a089-e9535cc0f9c3; Wed, 22 Feb 2023 16:34:09 +0100 (CET) Received: by mail-lj1-x233.google.com with SMTP id e9so8175052ljn.9 for ; Wed, 22 Feb 2023 07:34:09 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:08 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 59ccab43-b2c6-11ed-a089-e9535cc0f9c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WdZRzPZwwG/fX18/7IY+cXVLO7gdKBMeAYMh6i/Po7k=; b=G/wGOj70DT2gTYZ1rb27kBnjEeoBKT2iz7tYG0j3W8jVJqtY+8oUPhsEv2SHPNVMdM BZ7L8XSESD4d6uKRp3XufeK6qAPjKSAPle4QJbHE9Wc0OH8x6Gu/CP8rm36LMzxuqeKz MzVBNqsok20kbWrVXbHZLwMEt3MjA4LqCFLku5X77ksLaOVPwOQDRTzZJ59UTFi51apn Mdt6vwMkgzZoKNvIXq39DOAkfew4HNGZbMYvT0+mUS39FvCFFU+hE2m1p8H0il2clKq/ sF11GGJpTYRlF3ZIdSB4eeX2G0a3B50iulvyxP+XVbH/tZVO4IHw0rBB/IvrwKKMbYLM GAZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WdZRzPZwwG/fX18/7IY+cXVLO7gdKBMeAYMh6i/Po7k=; b=7WjDskTi0RMlWeO4nbk8hNz2r7sKAzwFhRT2ZNhvZ28KLFxZyJNw85TZgHxytPRsQp UYzdyeq9P0DXXGpojOl2kIiTLdWzrazJTLmmu5SxYdWh3gDyBVaXVtIExZqbPdBV1vOi tadeeewLM/z626V5ppmOUGvn6k73Q2kqHPK6HEDCjVDfhPe3rmZ/V7WzWxPFvzYnm35m Ra+El5S29+77oqtIu3A8lgR9IFSIo0a6ltkJZxE2xg5PvnpAxHcVYLW0yFYAfj4SMIC2 AXPRCuYXYL8wscB8EhJ8juxuH3XCIfiR8JRnEuCJQABiTRjqKd2zZi6AVPJjdxPB58BL +Fgw== X-Gm-Message-State: AO0yUKUwad4CKsh8Geg9w4JUttSPGpNtl1qH5uRi6PjVEZX0r7SeuMp2 dh7D4cLsmW7iPk1DS89dEM5azqrtUGj1r5bmC9k= X-Google-Smtp-Source: AK7set84sywa4fkmKPbl5uTdh5VQbx094u7I4/4RMrHRGuNExAM2+/Lr/2FvTbA0oqXQmG7/mz4gFw== X-Received: by 2002:a2e:964f:0:b0:294:712a:5190 with SMTP id z15-20020a2e964f000000b00294712a5190mr3263154ljh.28.1677080049263; Wed, 22 Feb 2023 07:34:09 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 18/20] xen/arm: ffa: support sharing memory Date: Wed, 22 Feb 2023 16:33:15 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support for a guest to share memory with an SP using FFA_MEM_SHARE and FFA_MEM_RECLAIM. Only small memory regions can be shared using a single call to FFA_MEM_SHARE are supported. A memory region that doesn't need to be shared any longer can be reclaimed with FFA_MEM_RECLAIM once the SP doesn't use it any longer. This is checked by the SPMC and not in control of the mediator. With this commit we have a FF-A version 1.1 [1] mediator able to communicate with a Secure Partition in secure world using shared memory. The secure world must use FF-A version 1.1, but the guest is free to use version 1.0 or version 1.1. Adds a check that the SP supports the needed FF-A features FFA_MEM_SHARE_64 or FFA_MEM_SHARE_32. [1] https://developer.arm.com/documentation/den0077/latest Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 491 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 491 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 94c90b252454..cdc286caf62c 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -270,6 +270,38 @@ struct ffa_mem_transaction_1_1 { uint8_t reserved[12]; }; +/* Calculate offset of struct ffa_mem_access from start of buffer */ +#define MEM_ACCESS_OFFSET(access_idx) \ + ( sizeof(struct ffa_mem_transaction_1_1) + \ + ( access_idx ) * sizeof(struct ffa_mem_access) ) + +/* Calculate offset of struct ffa_mem_region from start of buffer */ +#define REGION_OFFSET(access_count, region_idx) \ + ( MEM_ACCESS_OFFSET(access_count) + \ + ( region_idx ) * sizeof(struct ffa_mem_region) ) + +/* Calculate offset of struct ffa_address_range from start of buffer */ +#define ADDR_RANGE_OFFSET(access_count, region_count, range_idx) \ + ( REGION_OFFSET(access_count, region_count) + \ + ( range_idx ) * sizeof(struct ffa_address_range) ) + +/* + * The parts needed from struct ffa_mem_transaction_1_0 or struct + * ffa_mem_transaction_1_1, used to provide an abstraction of difference in + * data structures between version 1.0 and 1.1. This is just an internal + * interface and can be changed without changing any ABI. + */ +struct ffa_mem_transaction_x { + uint16_t sender_id; + uint8_t mem_reg_attr; + uint8_t flags; + uint8_t mem_access_size; + uint8_t mem_access_count; + uint16_t mem_access_offs; + uint64_t global_handle; + uint64_t tag; +}; + /* Endpoint RX/TX descriptor */ struct ffa_endpoint_rxtx_descriptor_1_0 { uint16_t sender_id; @@ -294,8 +326,20 @@ struct ffa_ctx { uint32_t guest_vers; bool tx_is_mine; bool interrupted; + struct list_head shm_list; + unsigned int shm_count; spinlock_t lock; }; + +struct ffa_shm_mem { + struct list_head list; + uint16_t sender_id; + uint16_t ep_id; /* endpoint, the one lending */ + uint64_t handle; /* FFA_HANDLE_INVALID if not set yet */ + unsigned int page_count; + struct page_info *pages[]; +}; + /* Negotiated FF-A version to use with the SPMC */ static uint32_t ffa_version __ro_after_init; @@ -310,6 +354,8 @@ static unsigned int subscr_vm_destroyed_count __read_mostly; * * ffa_page_count is the number of pages used in each of these buffers. * + * The TX buffer is protected from concurrent usage with ffa_tx_buffer_lock. + * * The RX buffer is protected from concurrent usage with ffa_rx_buffer_lock. * Note that the SPMC is also tracking the ownership of our RX buffer so * for calls which uses our RX buffer to deliver a result we must call @@ -319,6 +365,7 @@ static void *ffa_rx __read_mostly; static void *ffa_tx __read_mostly; static unsigned int ffa_page_count __read_mostly; static DEFINE_SPINLOCK(ffa_rx_buffer_lock); +static DEFINE_SPINLOCK(ffa_tx_buffer_lock); static bool ffa_get_version(uint32_t *vers) { @@ -429,6 +476,42 @@ static int32_t ffa_rx_release(void) return ffa_simple_call(FFA_RX_RELEASE, 0, 0, 0, 0); } +static int32_t ffa_mem_share(uint32_t tot_len, uint32_t frag_len, + register_t addr, uint32_t pg_count, + uint64_t *handle) +{ + struct arm_smccc_1_2_regs arg = { + .a0 = FFA_MEM_SHARE_32, + .a1 = tot_len, + .a2 = frag_len, + .a3 = addr, + .a4 = pg_count, + }; + struct arm_smccc_1_2_regs resp; + + if ( IS_ENABLED(CONFIG_ARM_64) ) + arg.a0 = FFA_MEM_SHARE_64; + + arm_smccc_1_2_smc(&arg, &resp); + + switch ( resp.a0 ) + { + case FFA_ERROR: + if ( resp.a2 ) + return resp.a2; + else + return FFA_RET_NOT_SUPPORTED; + case FFA_SUCCESS_32: + *handle = regpair_to_uint64(resp.a3, resp.a2); + return FFA_RET_OK; + case FFA_MEM_FRAG_RX: + *handle = regpair_to_uint64(resp.a2, resp.a1); + return resp.a3; + default: + return FFA_RET_NOT_SUPPORTED; + } +} + static int32_t ffa_direct_req_send_vm(uint16_t sp_id, uint16_t vm_id, uint8_t msg) { @@ -757,6 +840,404 @@ out: resp.a4 & mask, resp.a5 & mask, resp.a6 & mask, resp.a7 & mask); } +/* + * Gets all page and assigns them to the supplied shared memory object. If + * this function fails then the caller is still expected to call + * put_shm_pages() as a cleanup. + */ +static int get_shm_pages(struct domain *d, struct ffa_shm_mem *shm, + const struct ffa_address_range *range, + uint32_t range_count, unsigned int start_page_idx, + unsigned int *last_page_idx) +{ + unsigned int pg_idx = start_page_idx; + gfn_t gfn; + unsigned int n; + unsigned int m; + p2m_type_t t; + uint64_t addr; + + for ( n = 0; n < range_count; n++ ) + { + for ( m = 0; m < range[n].page_count; m++ ) + { + if ( pg_idx >= shm->page_count ) + return FFA_RET_INVALID_PARAMETERS; + + addr = read_atomic(&range[n].address); + gfn = gaddr_to_gfn(addr + m * FFA_PAGE_SIZE); + shm->pages[pg_idx] = get_page_from_gfn(d, gfn_x(gfn), &t, + P2M_ALLOC); + if ( !shm->pages[pg_idx] ) + return FFA_RET_DENIED; + pg_idx++; + /* Only normal RAM for now */ + if ( !p2m_is_ram(t) ) + return FFA_RET_DENIED; + } + } + + *last_page_idx = pg_idx; + + return FFA_RET_OK; +} + +static void put_shm_pages(struct ffa_shm_mem *shm) +{ + unsigned int n; + + for ( n = 0; n < shm->page_count && shm->pages[n]; n++ ) + { + put_page(shm->pages[n]); + shm->pages[n] = NULL; + } +} + +static struct ffa_shm_mem *alloc_ffa_shm_mem(struct ffa_ctx *ctx, + unsigned int page_count) +{ + struct ffa_shm_mem *shm; + + if ( page_count >= FFA_MAX_SHM_PAGE_COUNT || + ctx->shm_count >= FFA_MAX_SHM_COUNT ) + return NULL; + + shm = xzalloc_flex_struct(struct ffa_shm_mem, pages, page_count); + if ( shm ) + { + ctx->shm_count++; + shm->page_count = page_count; + } + + return shm; +} + +static void free_ffa_shm_mem(struct ffa_ctx *ctx, struct ffa_shm_mem *shm) +{ + if ( shm ) { + ASSERT(ctx->shm_count > 0); + ctx->shm_count--; + put_shm_pages(shm); + xfree(shm); + } +} + +static void init_range(struct ffa_address_range *addr_range, + paddr_t pa) +{ + memset(addr_range, 0, sizeof(*addr_range)); + addr_range->address = pa; + addr_range->page_count = 1; +} + +/* + * This function uses the ffa_tx buffer to transmit the memory transaction + * descriptor. The function depends ffa_tx_buffer_lock to be used to guard + * the buffer from concurrent use. + */ +static int share_shm(struct ffa_shm_mem *shm) +{ + const uint32_t max_frag_len = ffa_page_count * FFA_PAGE_SIZE; + struct ffa_mem_access *mem_access_array; + struct ffa_mem_transaction_1_1 *descr; + struct ffa_address_range *addr_range; + struct ffa_mem_region *region_descr; + const unsigned int region_count = 1; + void *buf = ffa_tx; + uint32_t frag_len; + uint32_t tot_len; + paddr_t last_pa; + unsigned int n; + paddr_t pa; + + ASSERT(spin_is_locked(&ffa_tx_buffer_lock)); + if ( !shm->page_count ) + { + ASSERT_UNREACHABLE(); + return FFA_RET_INVALID_PARAMETERS; + } + + descr = buf; + memset(descr, 0, sizeof(*descr)); + descr->sender_id = shm->sender_id; + descr->global_handle = shm->handle; + descr->mem_reg_attr = FFA_NORMAL_MEM_REG_ATTR; + descr->mem_access_count = 1; + descr->mem_access_size = sizeof(*mem_access_array); + descr->mem_access_offs = MEM_ACCESS_OFFSET(0); + + mem_access_array = buf + descr->mem_access_offs; + memset(mem_access_array, 0, sizeof(*mem_access_array)); + mem_access_array[0].access_perm.endpoint_id = shm->ep_id; + mem_access_array[0].access_perm.perm = FFA_MEM_ACC_RW; + mem_access_array[0].region_offs = REGION_OFFSET(descr->mem_access_count, 0); + + region_descr = buf + mem_access_array[0].region_offs; + memset(region_descr, 0, sizeof(*region_descr)); + region_descr->total_page_count = shm->page_count; + + region_descr->address_range_count = 1; + last_pa = page_to_maddr(shm->pages[0]); + for ( n = 1; n < shm->page_count; last_pa = pa, n++ ) + { + pa = page_to_maddr(shm->pages[n]); + if ( last_pa + FFA_PAGE_SIZE == pa ) + continue; + region_descr->address_range_count++; + } + + tot_len = ADDR_RANGE_OFFSET(descr->mem_access_count, region_count, + region_descr->address_range_count); + if ( tot_len > max_frag_len ) + return FFA_RET_NOT_SUPPORTED; + + addr_range = region_descr->address_range_array; + frag_len = ADDR_RANGE_OFFSET(descr->mem_access_count, region_count, 1); + last_pa = page_to_maddr(shm->pages[0]); + init_range(addr_range, last_pa); + for ( n = 1; n < shm->page_count; last_pa = pa, n++ ) + { + pa = page_to_maddr(shm->pages[n]); + if ( last_pa + FFA_PAGE_SIZE == pa ) + { + addr_range->page_count++; + continue; + } + + frag_len += sizeof(*addr_range); + addr_range++; + init_range(addr_range, pa); + } + + return ffa_mem_share(tot_len, frag_len, 0, 0, &shm->handle); +} + +static int read_mem_transaction(uint32_t ffa_vers, const void *buf, size_t blen, + struct ffa_mem_transaction_x *trans) +{ + uint16_t mem_reg_attr; + uint32_t flags; + uint32_t count; + uint32_t offs; + uint32_t size; + + if ( ffa_vers >= FFA_VERSION_1_1 ) + { + const struct ffa_mem_transaction_1_1 *descr; + + if ( blen < sizeof(*descr) ) + return FFA_RET_INVALID_PARAMETERS; + + descr = buf; + trans->sender_id = descr->sender_id; + mem_reg_attr = descr->mem_reg_attr; + flags = descr->flags; + trans->global_handle = descr->global_handle; + trans->tag = descr->tag; + + count = descr->mem_access_count; + size = descr->mem_access_size; + offs = descr->mem_access_offs; + } + else + { + const struct ffa_mem_transaction_1_0 *descr; + + if ( blen < sizeof(*descr) ) + return FFA_RET_INVALID_PARAMETERS; + + descr = buf; + trans->sender_id = descr->sender_id; + mem_reg_attr = descr->mem_reg_attr; + flags = descr->flags; + trans->global_handle = descr->global_handle; + trans->tag = descr->tag; + + count = descr->mem_access_count; + size = sizeof(struct ffa_mem_access); + offs = offsetof(struct ffa_mem_transaction_1_0, mem_access_array); + } + /* + * Make sure that "descr" which is shared with the guest isn't accessed + * again after this point. + */ + barrier(); + + /* + * We're doing a rough check to see that no information is lost when + * tranfering the values into a struct ffa_mem_transaction_x below. The + * fields in struct ffa_mem_transaction_x are wide enough to hold any + * valid value so being out of range means that something is wrong. + */ + if ( mem_reg_attr > UINT8_MAX || flags > UINT8_MAX || size > UINT8_MAX || + count > UINT8_MAX || offs > UINT16_MAX ) + return FFA_RET_INVALID_PARAMETERS; + + /* Check that the endpoint memory access descriptor array fits */ + if ( size * count + offs > blen ) + return FFA_RET_INVALID_PARAMETERS; + + trans->mem_reg_attr = mem_reg_attr; + trans->flags = flags; + trans->mem_access_size = size; + trans->mem_access_count = count; + trans->mem_access_offs = offs; + + return 0; +} + +static void handle_mem_share(struct cpu_user_regs *regs) +{ + uint32_t tot_len = get_user_reg(regs, 1); + uint32_t frag_len = get_user_reg(regs, 2); + uint64_t addr = get_user_reg(regs, 3); + uint32_t page_count = get_user_reg(regs, 4); + const struct ffa_mem_region *region_descr; + const struct ffa_mem_access *mem_access; + struct ffa_mem_transaction_x trans; + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + struct ffa_shm_mem *shm = NULL; + unsigned int last_page_idx = 0; + register_t handle_hi = 0; + register_t handle_lo = 0; + int ret = FFA_RET_DENIED; + uint32_t range_count; + uint32_t region_offs; + + /* + * We're only accepting memory transaction descriptors via the rx/tx + * buffer. + */ + if ( addr ) + { + ret = FFA_RET_NOT_SUPPORTED; + goto out_set_ret; + } + + /* Check that fragment length doesn't exceed total length */ + if ( frag_len > tot_len ) + { + ret = FFA_RET_INVALID_PARAMETERS; + goto out_set_ret; + } + + /* We currently only support a single fragment */ + if ( frag_len != tot_len ) + { + ret = FFA_RET_NOT_SUPPORTED; + goto out_set_ret; + } + + spin_lock(&ctx->lock); + + if ( frag_len > ctx->page_count * FFA_PAGE_SIZE ) + goto out_unlock; + + if ( !ffa_page_count ) + { + ret = FFA_RET_NO_MEMORY; + goto out_unlock; + } + + ret = read_mem_transaction(ctx->guest_vers, ctx->tx, frag_len, &trans); + if ( ret ) + goto out_unlock; + + if ( trans.mem_reg_attr != FFA_NORMAL_MEM_REG_ATTR ) + { + ret = FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + /* Only supports sharing it with one SP for now */ + if ( trans.mem_access_count != 1 ) + { + ret = FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + if ( trans.sender_id != get_vm_id(d) ) + { + ret = FFA_RET_INVALID_PARAMETERS; + goto out_unlock; + } + + /* Check that it fits in the supplied data */ + if ( trans.mem_access_offs + trans.mem_access_size > frag_len ) + goto out_unlock; + + mem_access = ctx->tx + trans.mem_access_offs; + if ( read_atomic(&mem_access->access_perm.perm) != FFA_MEM_ACC_RW ) + { + ret = FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + region_offs = read_atomic(&mem_access->region_offs); + if ( sizeof(*region_descr) + region_offs > frag_len ) + { + ret = FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + region_descr = ctx->tx + region_offs; + range_count = read_atomic(®ion_descr->address_range_count); + page_count = read_atomic(®ion_descr->total_page_count); + + shm = alloc_ffa_shm_mem(ctx, page_count); + if ( !shm ) + { + ret = FFA_RET_NO_MEMORY; + goto out_unlock; + } + shm->sender_id = trans.sender_id; + shm->ep_id = read_atomic(&mem_access->access_perm.endpoint_id); + + /* + * Check that the Composite memory region descriptor fits. + */ + if ( sizeof(*region_descr) + region_offs + + range_count * sizeof(struct ffa_address_range) > frag_len ) + { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + + ret = get_shm_pages(d, shm, region_descr->address_range_array, range_count, + 0, &last_page_idx); + if ( ret ) + goto out; + if ( last_page_idx != shm->page_count ) + { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + + /* Note that share_shm() uses our tx buffer */ + spin_lock(&ffa_tx_buffer_lock); + ret = share_shm(shm); + spin_unlock(&ffa_tx_buffer_lock); + if ( ret ) + goto out; + + list_add_tail(&shm->list, &ctx->shm_list); + + uint64_to_regpair(&handle_hi, &handle_lo, shm->handle); + +out: + if ( ret ) + free_ffa_shm_mem(ctx, shm); +out_unlock: + spin_unlock(&ctx->lock); + +out_set_ret: + if ( ret == 0) + set_regs_success(regs, handle_lo, handle_hi); + else + set_regs_error(regs, ret); +} + static bool ffa_handle_call(struct cpu_user_regs *regs) { uint32_t fid = get_user_reg(regs, 0); @@ -818,6 +1299,12 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) #endif handle_msg_send_direct_req(regs, fid); return true; + case FFA_MEM_SHARE_32: +#ifdef CONFIG_ARM_64 + case FFA_MEM_SHARE_64: +#endif + handle_mem_share(regs); + return true; default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -857,6 +1344,8 @@ static int ffa_domain_init(struct domain *d) } } + INIT_LIST_HEAD(&ctx->shm_list); + d->arch.tee = ctx; return 0; @@ -1012,11 +1501,13 @@ static bool ffa_probe(void) !check_mandatory_feature(FFA_RX_RELEASE) || #ifdef CONFIG_ARM_64 !check_mandatory_feature(FFA_RXTX_MAP_64) || + !check_mandatory_feature(FFA_MEM_SHARE_64) || #endif #ifdef CONFIG_ARM_32 !check_mandatory_feature(FFA_RXTX_MAP_32) || #endif !check_mandatory_feature(FFA_RXTX_UNMAP) || + !check_mandatory_feature(FFA_MEM_SHARE_32) || !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) return false; From patchwork Wed Feb 22 15:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D75EDC61DA4 for ; Wed, 22 Feb 2023 15:39:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499642.770924 (Exim 4.92) (envelope-from ) id 1pUrD3-00048r-3n; Wed, 22 Feb 2023 15:39:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499642.770924; Wed, 22 Feb 2023 15:39:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUrD2-00047w-SR; Wed, 22 Feb 2023 15:39:08 +0000 Received: by outflank-mailman (input) for mailman id 499642; Wed, 22 Feb 2023 15:39:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8G-0001MH-3p for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:12 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 59bb165a-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:09 +0100 (CET) Received: by mail-lf1-x12a.google.com with SMTP id w27so10583974lfu.4 for ; Wed, 22 Feb 2023 07:34:10 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:09 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 59bb165a-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L7KfqryCuiLTxh6V7wTFhyCR1D3Skcqadhm2jdw7Dpg=; b=buPVoqX4k+wFegkL/jsOQNHnwtRYALuPdIV2R1Q43tL4QfQQDMkPAsD6JccvuqSX/x p8yeHRPleXPwIEgmmkNjoYPQYfwv0nd3SmPWQqZQL6MZDj3jC3Zy8ybOHQnwnMGVtImk pTF2ASVOte+CYmGMoJ2+4jCYS3Yix9eRfelaR4gJo8+AuC/KMtryLZ8YRFnqlQnMOWXx UF67Hd7yckN/L+EX0n16HaMXJpxmjKEgp6UZfYRzuBEb5tyAacSGKJrlfjmdB2wFk3Hb itts9MsS5hRC/qzHI3bNFXVp4D9gGWk9eDi/HHcaFGYLHhK4BzEcCugkOg5NXAWSNSXh HPrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L7KfqryCuiLTxh6V7wTFhyCR1D3Skcqadhm2jdw7Dpg=; b=VgpvMnuG3aNOp/IN2KwFOXIrSWH200eBEvlWkkTju1hb3c63ocBAKYap2hDUGksLKT cDHCXgIjVAilZmaavz3rUEOJlXr6MpCwIVmXpZDh2VvEoJqOxBEnmSew3XeHKHZuc9JE QBUwDPxf5AYKPubhtuViv43w+hOsGylmOLz1JSnf+lrAlLlOrbMtY7ceK1WeKpfGQ99A R1Izsij28Pd70oiHku1ZhG9xjpAo+vZZHlAfr9K6e1snAuXWiUN+OEOVFTdhjKdFEsMb As5P18C05YO0us0o8pc2K1W4PT6E3dxMzcHO4PZajQ9nDyT7XaWWfJOKQQB7Es+O+AsD R6SQ== X-Gm-Message-State: AO0yUKVf4JAu+gw/TBbMaA2/OxbsH62krgg9/XDebKIdLZHWqZW4tvVy WNKXFZ0TvV9k0xxjaSBFIsFii0i1daWN508PURY= X-Google-Smtp-Source: AK7set9AQLUVCBjm0EJ6SEfxAjBSS8LFZYBlQPJteDZtuDeT2rcECFkrQMoVQbHhHPG+EBuP2WABgg== X-Received: by 2002:ac2:554f:0:b0:4db:664d:7bb0 with SMTP id l15-20020ac2554f000000b004db664d7bb0mr3094883lfk.47.1677080050152; Wed, 22 Feb 2023 07:34:10 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 19/20] xen/arm: ffa: add support to reclaim shared memory Date: Wed, 22 Feb 2023 16:33:16 +0100 Message-Id: <6dda7c17462221fac26f45a8663370952e37040d.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support to reclaim memory previously shared with FFA_MEM_SHARE. Adds a check that the SP supports the needed FF-A feature FFA_MEM_RECLAIM. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index cdc286caf62c..3557edc455d0 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -512,6 +512,12 @@ static int32_t ffa_mem_share(uint32_t tot_len, uint32_t frag_len, } } +static int32_t ffa_mem_reclaim(uint32_t handle_lo, uint32_t handle_hi, + uint32_t flags) +{ + return ffa_simple_call(FFA_MEM_RECLAIM, handle_lo, handle_hi, flags, 0); +} + static int32_t ffa_direct_req_send_vm(uint16_t sp_id, uint16_t vm_id, uint8_t msg) { @@ -1238,6 +1244,43 @@ out_set_ret: set_regs_error(regs, ret); } +static int handle_mem_reclaim(uint64_t handle, uint32_t flags) +{ + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + struct ffa_shm_mem *shm; + register_t handle_hi; + register_t handle_lo; + int ret; + + spin_lock(&ctx->lock); + list_for_each_entry(shm, &ctx->shm_list, list) + { + if ( shm->handle == handle ) + goto found_it; + } + shm = NULL; + ret = FFA_RET_INVALID_PARAMETERS; + goto out; +found_it: + + uint64_to_regpair(&handle_hi, &handle_lo, handle); + ret = ffa_mem_reclaim(handle_lo, handle_hi, flags); + if ( ret ) + { + shm = NULL; + goto out; + } + + list_del(&shm->list); + +out: + free_ffa_shm_mem(ctx, shm); + spin_unlock(&ctx->lock); + + return ret; +} + static bool ffa_handle_call(struct cpu_user_regs *regs) { uint32_t fid = get_user_reg(regs, 0); @@ -1305,6 +1348,15 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) #endif handle_mem_share(regs); return true; + case FFA_MEM_RECLAIM: + e = handle_mem_reclaim(regpair_to_uint64(get_user_reg(regs, 2), + get_user_reg(regs, 1)), + get_user_reg(regs, 3)); + if ( e ) + set_regs_error(regs, e); + else + set_regs_success(regs, 0, 0); + return true; default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -1508,6 +1560,7 @@ static bool ffa_probe(void) #endif !check_mandatory_feature(FFA_RXTX_UNMAP) || !check_mandatory_feature(FFA_MEM_SHARE_32) || + !check_mandatory_feature(FFA_MEM_RECLAIM) || !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) return false; From patchwork Wed Feb 22 15:33:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13149316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D117C636D6 for ; Wed, 22 Feb 2023 15:39:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.499640.770916 (Exim 4.92) (envelope-from ) id 1pUrD2-00045V-N0; Wed, 22 Feb 2023 15:39:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 499640.770916; Wed, 22 Feb 2023 15:39:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUrD2-00045O-JY; Wed, 22 Feb 2023 15:39:08 +0000 Received: by outflank-mailman (input) for mailman id 499640; Wed, 22 Feb 2023 15:39:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pUr8H-0001MH-G9 for xen-devel@lists.xenproject.org; Wed, 22 Feb 2023 15:34:13 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5a36b5af-b2c6-11ed-93b6-47a8fe42b414; Wed, 22 Feb 2023 16:34:10 +0100 (CET) Received: by mail-lf1-x12d.google.com with SMTP id i9so10367712lfc.6 for ; Wed, 22 Feb 2023 07:34:11 -0800 (PST) Received: from localhost.localdomain (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q9-20020ac25289000000b004db0d26adb4sm927746lfm.182.2023.02.22.07.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 07:34:10 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5a36b5af-b2c6-11ed-93b6-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9EBnqstd93+kMQVfeEulFqyhSQhNIu3e1sgUFJ4bxhc=; b=uOGa2/AjT1YEsddJLsepEfyIkRMybDZu5DbW5UIHDySSh4Ux2xCVd2QVsS45rgb43i kEQAu66NdQ/NaZOiVA0Y8Bn/inG1lws/N5EXhh2Dm5tt6Udcmj+lX2GMbBV8JRiQnh3j a2x+n5KsZZWXmiiLM9p2+z+ru18dE6WU5c+uZUhVUfk96YSPrWdPBvELsYgUFBMBMBfj RwWJ7uCUsYP72TsaH2SoT5EefN/SJhCd1IzzFOXWVayGUUr1hz8igMVppLJQ1HUaHzCW SB4w6xNg4aJ/l8VVjCxXA5d4D6ALfgxPeLL9V9r0wuK8007KHRibwZdGzcoMxQkzLWJ2 38zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9EBnqstd93+kMQVfeEulFqyhSQhNIu3e1sgUFJ4bxhc=; b=gdQb3vZR+v8Kkz9l882fjDhabGHVOGukRRpUS8By95OB8S/hg/kkIfoOqsfn5eBHx+ l698Ownkx25+ZjZ1FN4CNi6KQZ1gJQ/vtIFLlefSdXF9h25mRslvx/FlXCJN/+kUxG5i nB2dg0QyVeYMcuSVl7Ngmlh5MbnvMgXMML5uxrFCWoVci4dW30exsVNHnxXYfeyaJSXC OmMu8bn8D3MCNc4tU8F0DG0aHQbb0Q0lxHzXDZ6bUmrs21+hgyznosG1xATnLYabxWUY fxZ8bkjtwEgsdbPww1GroieIRZROYfsRxMIoxJDTCFyn0wqSntQQVCQyfqXOpL7gIpl6 lwiA== X-Gm-Message-State: AO0yUKVspX0PMuuFkDlCHkpo+5puoR5gOdWXV8p08O7kLhnpgye3lHCg VPJcwlnGZ8foG3ji2E0fPdKpNlzCq6DthyiLO3E= X-Google-Smtp-Source: AK7set/siyuKsdBS5hCv12Um9J1mP06l9QLSNfMmqFSvZxRjhoRsprVfaZLYg2Ob61HD0WF3EQs0kA== X-Received: by 2002:ac2:4a88:0:b0:4d8:65c5:8684 with SMTP id l8-20020ac24a88000000b004d865c58684mr3719214lfp.58.1677080050928; Wed, 22 Feb 2023 07:34:10 -0800 (PST) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v7 20/20] xen/arm: ffa: support sharing large memory ranges Date: Wed, 22 Feb 2023 16:33:17 +0100 Message-Id: <5a48b7c7a56b83138932850eb7f94f90604168e4.1677079672.git.jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Adds support for sharing large memory ranges transmitted in fragments using FFA_MEM_FRAG_TX. The implementation is the bare minimum to be able to communicate with OP-TEE running as an SPMC at S-EL1. Adds a check that the SP supports the needed FF-A feature FFA_MEM_FRAG_TX. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 254 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 240 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 3557edc455d0..72c0249d8cad 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -326,6 +326,7 @@ struct ffa_ctx { uint32_t guest_vers; bool tx_is_mine; bool interrupted; + struct list_head frag_list; struct list_head shm_list; unsigned int shm_count; spinlock_t lock; @@ -340,6 +341,18 @@ struct ffa_shm_mem { struct page_info *pages[]; }; +struct mem_frag_state { + struct list_head list; + struct ffa_shm_mem *shm; + uint32_t range_count; + unsigned int current_page_idx; + unsigned int frag_offset; + unsigned int range_offset; + const uint8_t *buf; + unsigned int buf_size; + struct ffa_address_range range; +}; + /* Negotiated FF-A version to use with the SPMC */ static uint32_t ffa_version __ro_after_init; @@ -512,6 +525,36 @@ static int32_t ffa_mem_share(uint32_t tot_len, uint32_t frag_len, } } +static int32_t ffa_mem_frag_tx(uint64_t handle, uint32_t frag_len, + uint16_t sender_id) +{ + struct arm_smccc_1_2_regs arg = { + .a0 = FFA_MEM_FRAG_TX, + .a1 = handle & UINT32_MAX, + .a2 = handle >> 32, + .a3 = frag_len, + .a4 = (uint32_t)sender_id << 16, + }; + struct arm_smccc_1_2_regs resp; + + arm_smccc_1_2_smc(&arg, &resp); + + switch ( resp.a0 ) + { + case FFA_ERROR: + if ( resp.a2 ) + return resp.a2; + else + return FFA_RET_NOT_SUPPORTED; + case FFA_SUCCESS_32: + return FFA_RET_OK; + case FFA_MEM_FRAG_RX: + return resp.a3; + default: + return FFA_RET_NOT_SUPPORTED; + } +} + static int32_t ffa_mem_reclaim(uint32_t handle_lo, uint32_t handle_hi, uint32_t flags) { @@ -586,6 +629,14 @@ static void set_regs_success(struct cpu_user_regs *regs, uint32_t w2, set_regs(regs, FFA_SUCCESS_32, 0, w2, w3, 0, 0, 0, 0); } +static void set_regs_frag_rx(struct cpu_user_regs *regs, uint32_t handle_lo, + uint32_t handle_hi, uint32_t frag_offset, + uint16_t sender_id) +{ + set_regs(regs, FFA_MEM_FRAG_RX, handle_lo, handle_hi, frag_offset, + (uint32_t)sender_id << 16, 0, 0, 0); +} + static void handle_version(struct cpu_user_regs *regs) { struct domain *d = current->domain; @@ -955,6 +1006,8 @@ static int share_shm(struct ffa_shm_mem *shm) paddr_t last_pa; unsigned int n; paddr_t pa; + bool first; + int ret; ASSERT(spin_is_locked(&ffa_tx_buffer_lock)); if ( !shm->page_count ) @@ -994,13 +1047,23 @@ static int share_shm(struct ffa_shm_mem *shm) tot_len = ADDR_RANGE_OFFSET(descr->mem_access_count, region_count, region_descr->address_range_count); - if ( tot_len > max_frag_len ) - return FFA_RET_NOT_SUPPORTED; + /* + * Sharing memory with secure world may have to be done with multiple + * calls depending on how many address ranges will be needed. If we're + * sharing physically contiguous memory we will only need one range but + * we will also need to deal with the worst case where all physical + * pages are non-contiguous. For the first batch of address ranges we + * call ffa_mem_share() and for all that follows ffa_mem_frag_tx(). + * + * We use frag_len to keep track of how far into the transmit buffer we + * have gone. + */ addr_range = region_descr->address_range_array; frag_len = ADDR_RANGE_OFFSET(descr->mem_access_count, region_count, 1); last_pa = page_to_maddr(shm->pages[0]); init_range(addr_range, last_pa); + first = true; for ( n = 1; n < shm->page_count; last_pa = pa, n++ ) { pa = page_to_maddr(shm->pages[n]); @@ -1010,12 +1073,34 @@ static int share_shm(struct ffa_shm_mem *shm) continue; } - frag_len += sizeof(*addr_range); - addr_range++; + if ( frag_len == max_frag_len ) + { + if ( first ) + { + ret = ffa_mem_share(tot_len, frag_len, 0, 0, &shm->handle); + first = false; + } + else + { + ret = ffa_mem_frag_tx(shm->handle, frag_len, shm->sender_id); + } + if ( ret <= 0 ) + return ret; + frag_len = sizeof(*addr_range); + addr_range = buf; + } + else + { + frag_len += sizeof(*addr_range); + addr_range++; + } init_range(addr_range, pa); } - return ffa_mem_share(tot_len, frag_len, 0, 0, &shm->handle); + if ( first ) + return ffa_mem_share(tot_len, frag_len, 0, 0, &shm->handle); + else + return ffa_mem_frag_tx(shm->handle, frag_len, shm->sender_id); } static int read_mem_transaction(uint32_t ffa_vers, const void *buf, size_t blen, @@ -1092,8 +1177,53 @@ static int read_mem_transaction(uint32_t ffa_vers, const void *buf, size_t blen, return 0; } +static int add_mem_share_frag(struct mem_frag_state *s, unsigned int offs, + unsigned int frag_len) +{ + struct domain *d = current->domain; + unsigned int o = offs; + unsigned int l; + int ret; + + if ( frag_len < o ) + return FFA_RET_INVALID_PARAMETERS; + + /* Fill up the first struct ffa_address_range */ + l = min_t(unsigned int, frag_len - o, sizeof(s->range) - s->range_offset); + memcpy((uint8_t *)&s->range + s->range_offset, s->buf + o, l); + s->range_offset += l; + o += l; + if ( s->range_offset != sizeof(s->range) ) + goto out; + s->range_offset = 0; + + while ( true ) + { + ret = get_shm_pages(d, s->shm, &s->range, 1, s->current_page_idx, + &s->current_page_idx); + if ( ret ) + return ret; + if ( s->range_count == 1 ) + return 0; + s->range_count--; + if ( frag_len - o < sizeof(s->range) ) + break; + memcpy(&s->range, s->buf + o, sizeof(s->range)); + o += sizeof(s->range); + } + + /* Collect any remaining bytes for the next struct ffa_address_range */ + s->range_offset = frag_len - o; + memcpy(&s->range, s->buf + o, frag_len - o); +out: + s->frag_offset += frag_len; + + return s->frag_offset; +} + static void handle_mem_share(struct cpu_user_regs *regs) { + static uint64_t next_handle = FFA_HANDLE_HYP_FLAG; uint32_t tot_len = get_user_reg(regs, 1); uint32_t frag_len = get_user_reg(regs, 2); uint64_t addr = get_user_reg(regs, 3); @@ -1128,13 +1258,6 @@ static void handle_mem_share(struct cpu_user_regs *regs) goto out_set_ret; } - /* We currently only support a single fragment */ - if ( frag_len != tot_len ) - { - ret = FFA_RET_NOT_SUPPORTED; - goto out_set_ret; - } - spin_lock(&ctx->lock); if ( frag_len > ctx->page_count * FFA_PAGE_SIZE ) @@ -1195,11 +1318,41 @@ static void handle_mem_share(struct cpu_user_regs *regs) if ( !shm ) { ret = FFA_RET_NO_MEMORY; - goto out_unlock; + goto out; } shm->sender_id = trans.sender_id; shm->ep_id = read_atomic(&mem_access->access_perm.endpoint_id); + if ( frag_len != tot_len ) + { + struct mem_frag_state *s = xzalloc(struct mem_frag_state); + + if ( !s ) + { + ret = FFA_RET_NO_MEMORY; + goto out; + } + s->shm = shm; + s->range_count = range_count; + s->buf = ctx->tx; + s->buf_size = ffa_page_count * FFA_PAGE_SIZE; + ret = add_mem_share_frag(s, sizeof(*region_descr) + region_offs, + frag_len); + if ( ret <= 0 ) + { + xfree(s); + if ( ret < 0 ) + goto out; + } + else + { + shm->handle = next_handle++; + uint64_to_regpair(&handle_hi, &handle_lo, shm->handle); + list_add_tail(&s->list, &ctx->frag_list); + } + goto out_unlock; + } + /* * Check that the Composite memory region descriptor fits. */ @@ -1238,7 +1391,75 @@ out_unlock: spin_unlock(&ctx->lock); out_set_ret: - if ( ret == 0) + if ( ret > 0 ) + set_regs_frag_rx(regs, handle_lo, handle_hi, ret, trans.sender_id); + else if ( ret == 0) + set_regs_success(regs, handle_lo, handle_hi); + else + set_regs_error(regs, ret); +} + +static struct mem_frag_state *find_frag_state(struct ffa_ctx *ctx, + uint64_t handle) +{ + struct mem_frag_state *s; + + list_for_each_entry(s, &ctx->frag_list, list) + if ( s->shm->handle == handle ) + return s; + + return NULL; +} + +static void handle_mem_frag_tx(struct cpu_user_regs *regs) +{ + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; + uint32_t frag_len = get_user_reg(regs, 3); + uint32_t handle_lo = get_user_reg(regs, 1); + uint32_t handle_hi = get_user_reg(regs, 2); + uint64_t handle = regpair_to_uint64(handle_hi, handle_lo); + struct mem_frag_state *s; + uint16_t sender_id = 0; + int ret; + + spin_lock(&ctx->lock); + s = find_frag_state(ctx, handle); + if ( !s ) + { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + sender_id = s->shm->sender_id; + + if ( frag_len > s->buf_size ) + { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + + ret = add_mem_share_frag(s, 0, frag_len); + if ( ret == 0 ) + { + /* Note that share_shm() uses our tx buffer */ + spin_lock(&ffa_tx_buffer_lock); + ret = share_shm(s->shm); + spin_unlock(&ffa_tx_buffer_lock); + if ( ret == 0 ) + list_add_tail(&s->shm->list, &ctx->shm_list); + else + free_ffa_shm_mem(ctx, s->shm); + } + else if ( ret < 0 ) + free_ffa_shm_mem(ctx, s->shm); + list_del(&s->list); + xfree(s); +out: + spin_unlock(&ctx->lock); + + if ( ret > 0 ) + set_regs_frag_rx(regs, handle_lo, handle_hi, ret, sender_id); + else if ( ret == 0) set_regs_success(regs, handle_lo, handle_hi); else set_regs_error(regs, ret); @@ -1357,6 +1578,9 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) else set_regs_success(regs, 0, 0); return true; + case FFA_MEM_FRAG_TX: + handle_mem_frag_tx(regs); + return true; default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -1396,6 +1620,7 @@ static int ffa_domain_init(struct domain *d) } } + INIT_LIST_HEAD(&ctx->frag_list); INIT_LIST_HEAD(&ctx->shm_list); d->arch.tee = ctx; @@ -1560,6 +1785,7 @@ static bool ffa_probe(void) #endif !check_mandatory_feature(FFA_RXTX_UNMAP) || !check_mandatory_feature(FFA_MEM_SHARE_32) || + !check_mandatory_feature(FFA_MEM_FRAG_TX) || !check_mandatory_feature(FFA_MEM_RECLAIM) || !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) return false;