From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549765; cv=none; d=zohomail.com; s=zohoarc; b=knP7KfL29GchIftLGnGNDhYiCG/14bZVipxIMzlc/Sb6BBfwru02tE3DIPkUwV+bCvdh6nUwh4QaPqf9HHAvwSAquMAVm6kMqG83fFYgqzcBaiWQ/L6N+r8YtCWKA4OxtJAYQojfLjqfE25rbFg+Rfb4xV8J0Denj06rWO0Asss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=am4ipN3ru3xzSJvgYsCfVXNDufmrJ7j+gUVMYasa6R8=; b=jyqI3MPr9chZ4nM14uxxux07/08rnwl9rh8qEvVfaQtyS18GltDj0kP7I6Z0FiFZPK6Ni0e5mO5tM1pM+qZA/bOF3M+2nU0bcRBfd33rNuwbN7TJsRUeKPPXGxcsbJ39WchHWEThz2EWDqO9XlH8PP2+GJTyRF9PmQBAjPIM20Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549765841289.1855469023661; Wed, 5 Jul 2023 02:36:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558881.873361 (Exim 4.92) (envelope-from ) id 1qGyuu-0005fS-Ko; Wed, 05 Jul 2023 09:35:20 +0000 Received: by outflank-mailman (output) from mailman id 558881.873361; Wed, 05 Jul 2023 09:35: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 1qGyuu-0005ed-Fg; Wed, 05 Jul 2023 09:35:20 +0000 Received: by outflank-mailman (input) for mailman id 558881; Wed, 05 Jul 2023 09:35:19 +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 1qGyut-0005bC-MD for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:19 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 406545c0-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:17 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4fbb281eec6so4765599e87.1 for ; Wed, 05 Jul 2023 02:35:17 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:16 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 406545c0-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549716; x=1691141716; 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=am4ipN3ru3xzSJvgYsCfVXNDufmrJ7j+gUVMYasa6R8=; b=YRRVF3KTUR2CfX8sPtJGO/1Jng4XNRK/IuXWR5mRgQEIlhCd8cqSgFMhzC/Yndbaqi jQQ1qOWBoOL9CdNIwvvesIQ/g4Gzn9BW3GiAQGINWc0nmYau2qH51TRxkRJOP9hDFk95 JDQAX3XZ7mR81dRnlEXo0nPFWc+N8ASyz3MvXJNIc0t3A0v/77JFbmaHRuH8+zG90zV8 TNdCkmpNNycLL422jOxbgFTGQLdlD4sq7aLzPrCEJay0ScS0BC8V1hPoDfxkQxFlM+rm 6/O2BXb1U3lyXm+ZOd1HicIqgEel/nX5OkPQcTeXcUQodA2mZ7X/sxVdz4Yz3xz1a12m opeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549716; x=1691141716; 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=am4ipN3ru3xzSJvgYsCfVXNDufmrJ7j+gUVMYasa6R8=; b=kWXTHK3YkqqON6c4nHlEwpyC3FTVQlzxmqz1uLeSib1YisPKvzRnFc1o+jO9v9MRjZ n1Kgzd2taZd2Zw72xiVOyZp36boCnFALSMPfE9ibSIIIV4z+e+j3xPJ1tiw5rnZqmO4Q +dDn5gqZ6Wj+fBZ/8L8kGTKQNqNSTuZM3oDyYpiAqoxo+7pOeO3ckh3KaWeMp1Tzp9Jm gzxG0HZdtVAOQ909qIAPtkj2P4S9n3rFApX5hvdJJk5JXXguiF177Vm8fLp+rK40yQ/o sO8wnTOoOfeNsejm+IHp9CQjuez84mC6pjtCai8TxxqdzQ7Sc1ci7G741ygTzmjD8hem /eYQ== X-Gm-Message-State: ABy/qLYd/DjYMpvXZU+dvHl82fMrj9eZ7Cwfzjm0PvFxNFZZryAWG6C+ 42yDLyvFJcfd2Wo/P7NwWeFTzTI+iBGDmkaO7cg= X-Google-Smtp-Source: APBJJlFmHssN6U2jD6Aj2M55oV1Ks3I50SPjEcyFBfIaeIPGLY9rjYKrdzZePpVHlgKBka1r4/s5Ww== X-Received: by 2002:a2e:8182:0:b0:2b6:cfec:69f7 with SMTP id e2-20020a2e8182000000b002b6cfec69f7mr10183434ljg.1.1688549716784; Wed, 05 Jul 2023 02:35:16 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Andrew Cooper , George Dunlap , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jan Beulich , Bertrand Marquis , Jens Wiklander Subject: [XEN PATCH v9 01/24] xen: Introduce arch_domain_teardown() Date: Wed, 5 Jul 2023 11:34:10 +0200 Message-Id: <20230705093433.2514898-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549766433100011 From: Andrew Cooper Plumb it into domain_teardown(). Provide arch_val in the teardown continuation information for use by arch_domain_teardown(). No practical change. Signed-off-by: Andrew Cooper Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Jens Wiklander --- xen/arch/arm/domain.c | 5 +++++ xen/arch/x86/domain.c | 5 +++++ xen/common/domain.c | 6 ++++++ xen/include/xen/domain.h | 1 + xen/include/xen/sched.h | 1 + 5 files changed, 18 insertions(+) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 8c18e9207907..15d9709a97d2 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -793,6 +793,11 @@ fail: return rc; } =20 +int arch_domain_teardown(struct domain *d) +{ + return 0; +} + void arch_domain_destroy(struct domain *d) { /* IOMMU page table is shared with P2M, always call diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 39c215316546..5f66c2ae33d7 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -888,6 +888,11 @@ int arch_domain_create(struct domain *d, return rc; } =20 +int arch_domain_teardown(struct domain *d) +{ + return 0; +} + void arch_domain_destroy(struct domain *d) { if ( is_hvm_domain(d) ) diff --git a/xen/common/domain.c b/xen/common/domain.c index caaa40263792..304aa04fa6cb 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -439,6 +439,7 @@ static int domain_teardown(struct domain *d) PROG_none, PROG_gnttab_mappings, PROG_vcpu_teardown, + PROG_arch_teardown, PROG_done, }; =20 @@ -459,6 +460,11 @@ static int domain_teardown(struct domain *d) return rc; } =20 + PROGRESS(arch_teardown): + rc =3D arch_domain_teardown(d); + if ( rc ) + return rc; + PROGRESS(done): break; =20 diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 1df8f933d076..d35af348410c 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -81,6 +81,7 @@ int arch_domain_create(struct domain *d, struct xen_domctl_createdomain *config, unsigned int flags); =20 +int arch_domain_teardown(struct domain *d); void arch_domain_destroy(struct domain *d); =20 void arch_domain_shutdown(struct domain *d); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 85242a73d374..854f3e32c00e 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -589,6 +589,7 @@ struct domain */ struct { unsigned int val; + unsigned int arch_val; struct vcpu *vcpu; } teardown; =20 --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549753; cv=none; d=zohomail.com; s=zohoarc; b=gwwC+iZT/TNC09ZDe99upEFGUclkvrYLGPJHc9y5cuMP/FKteV9uh30e2sC4XojcFfJEabilPHPOGp2w0h85jx/68Cn5FhoOPq1mlnm/fzLiBx9yByNoZjM3FCA8ssGMtMPG7G48/Oy2gzmJRV3dV/4CZXYBxQQhnVU7Djyp2G8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549753; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ope1qDQvv3JfY3UstaYChJhi8PznZe74QQXVc0GdGf0=; b=Zlk/lhU7CbI7gjtWROfJPNMj08kYMgTFHOlr3GH+YRF0ST7+4u3/zmOoPMojIs603FFdbESVFxp5lMtlx3KVY038sLWcojg0JS9thpuSNGlOJRUekOj+2qxx8FJK96vJLPdJiNOFzeTOGhudzPqy7EdRsHxhYnsY+D7f/zy0ULQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549753192194.48963590111487; Wed, 5 Jul 2023 02:35:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558882.873374 (Exim 4.92) (envelope-from ) id 1qGyuv-00065P-Uq; Wed, 05 Jul 2023 09:35:21 +0000 Received: by outflank-mailman (output) from mailman id 558882.873374; Wed, 05 Jul 2023 09:35:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyuv-00065G-S0; Wed, 05 Jul 2023 09:35:21 +0000 Received: by outflank-mailman (input) for mailman id 558882; Wed, 05 Jul 2023 09:35:20 +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 1qGyuu-0005bC-MI for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:20 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4121ccd7-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:18 +0200 (CEST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b701e1ca63so1938751fa.1 for ; Wed, 05 Jul 2023 02:35:18 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:17 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4121ccd7-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549718; x=1691141718; 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=ope1qDQvv3JfY3UstaYChJhi8PznZe74QQXVc0GdGf0=; b=yQRvRdMBEFY/hypIbPRrBs1HNR6BgT+uFRC3j4vCbpwZKfhBFNukSX/z4O8CuiX79M cKPEGVUUkcn2T1j+EbmgUH19JAJm7b0mMnka6IJnxQrsdzpnzfKMVj1X2qULH7bNni+t P3LALB7miE0ci6w4elxbWD4ycyvuYlbA1LvOeiCy3yPRy7m9/aZOVdB0KaMgKf2j6Stv CE15TA6SHQPsNCzMNEr6ziFf4+QWPr2tLTss/bdTnF7QuKo8viJS+IE4KKvBYQzDPZWy qegMdHx3ZbAF+Aarkdn1rd/99jl79WaZosFsx/ZFOcqUnPgOuocWdyXoRlcGSNKGLyzd K4Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549718; x=1691141718; 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=ope1qDQvv3JfY3UstaYChJhi8PznZe74QQXVc0GdGf0=; b=Nj2OjRadSMQ+H1dsAzgvB0oY19Hcx2zkjksr62e6J0vpJ6BfZvGoKlqeYJN+OL3nCU WXkzDCHtFGlehnoF72AdsgHS++2ZhOWLEj08hynb0DD6P3x/rVQ6jThljfitZb6++r5M tP3bMYpnVUz3EfEZVBUYeX1pnxJ9Mli2fWulOrDlp8Y9Jx3LPjQXBUo4A9r6MS2ln6MX KqX36sL/QDtdUiyzXh7yzKmb1EHs444qvEAF6NRyhOPu+ztsLKnn9vHW3NYCGF54Thk0 qO1Y17xtpgoZ0vVl3iBXPC3Th2B2UZHwGDOY7YHzY3ltoC560sPHvv8CCRScOmxDg19D MVNQ== X-Gm-Message-State: ABy/qLZwctYKcwnFkieH6JnU2213WVd/qeeJgC2xcnbnI/98IgmlHZeg Q1aFR9cV/82d8zKRYPEORWZiFZt3aarQ++h3Dg8= X-Google-Smtp-Source: APBJJlFUO0g/R6+68G1F19Zc1rsGwbxz5DkB4z9w6ruFa/qeFCAUCb3VSNCVeNO3kT8pSD6WhwSixg== X-Received: by 2002:a2e:a17a:0:b0:2b6:dc84:b93e with SMTP id u26-20020a2ea17a000000b002b6dc84b93emr8292683ljl.21.1688549718034; Wed, 05 Jul 2023 02:35:18 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Bertrand Marquis , Andrew Cooper Subject: [XEN PATCH v9 02/24] xen/arm: add TEE teardown to arch_domain_teardown() Date: Wed, 5 Jul 2023 11:34:11 +0200 Message-Id: <20230705093433.2514898-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549754291100003 Content-Type: text/plain; charset="utf-8" Adds a progress state for tee_domain_teardown() to be called from arch_domain_teardown(). tee_domain_teardown() calls the new callback domain_teardown() in struct tee_mediator_ops. An empty domain_teardown() callback is added to the OP-TEE mediator. Signed-off-by: Andrew Cooper Co-developed-by: Andrew Cooper Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Jens Wiklander --- xen/arch/arm/domain.c | 36 ++++++++++++++++++++++++++++++ xen/arch/arm/include/asm/tee/tee.h | 7 ++++++ xen/arch/arm/tee/optee.c | 6 +++++ xen/arch/arm/tee/tee.c | 8 +++++++ 4 files changed, 57 insertions(+) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 15d9709a97d2..18171decdc66 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -795,6 +795,42 @@ fail: =20 int arch_domain_teardown(struct domain *d) { + int ret =3D 0; + + BUG_ON(!d->is_dying); + + /* See domain_teardown() for an explanation of all of this magic. */ + switch ( d->teardown.arch_val ) + { +#define PROGRESS(x) \ + d->teardown.arch_val =3D PROG_ ## x; \ + fallthrough; \ + case PROG_ ## x + + enum { + PROG_none, + PROG_tee, + PROG_done, + }; + + case PROG_none: + BUILD_BUG_ON(PROG_none !=3D 0); + + PROGRESS(tee): + ret =3D tee_domain_teardown(d); + if ( ret ) + return ret; + break; + + PROGRESS(done): + break; + +#undef PROGRESS + + default: + BUG(); + } + return 0; } =20 diff --git a/xen/arch/arm/include/asm/tee/tee.h b/xen/arch/arm/include/asm/= tee/tee.h index f483986385c8..da324467e130 100644 --- a/xen/arch/arm/include/asm/tee/tee.h +++ b/xen/arch/arm/include/asm/tee/tee.h @@ -34,6 +34,7 @@ struct tee_mediator_ops { * guest and create own structures for the new domain. */ int (*domain_init)(struct domain *d); + int (*domain_teardown)(struct domain *d); =20 /* * Called during domain destruction to relinquish resources used @@ -62,6 +63,7 @@ struct tee_mediator_desc { =20 bool tee_handle_call(struct cpu_user_regs *regs); int tee_domain_init(struct domain *d, uint16_t tee_type); +int tee_domain_teardown(struct domain *d); int tee_relinquish_resources(struct domain *d); uint16_t tee_get_type(void); =20 @@ -93,6 +95,11 @@ static inline int tee_relinquish_resources(struct domain= *d) return 0; } =20 +static inline int tee_domain_teardown(struct domain *d) +{ + return 0; +} + static inline uint16_t tee_get_type(void) { return XEN_DOMCTL_CONFIG_TEE_NONE; diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c index 301d205a36c5..c91bd7d5ac25 100644 --- a/xen/arch/arm/tee/optee.c +++ b/xen/arch/arm/tee/optee.c @@ -268,6 +268,11 @@ static int optee_domain_init(struct domain *d) return 0; } =20 +static int optee_domain_teardown(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; @@ -1732,6 +1737,7 @@ static const struct tee_mediator_ops optee_ops =3D { .probe =3D optee_probe, .domain_init =3D optee_domain_init, + .domain_teardown =3D optee_domain_teardown, .relinquish_resources =3D optee_relinquish_resources, .handle_call =3D optee_handle_call, }; diff --git a/xen/arch/arm/tee/tee.c b/xen/arch/arm/tee/tee.c index 3964a8a5cddf..ddd17506a9ff 100644 --- a/xen/arch/arm/tee/tee.c +++ b/xen/arch/arm/tee/tee.c @@ -52,6 +52,14 @@ int tee_domain_init(struct domain *d, uint16_t tee_type) return cur_mediator->ops->domain_init(d); } =20 +int tee_domain_teardown(struct domain *d) +{ + if ( !cur_mediator ) + return 0; + + return cur_mediator->ops->domain_teardown(d); +} + int tee_relinquish_resources(struct domain *d) { if ( !cur_mediator ) --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549759; cv=none; d=zohomail.com; s=zohoarc; b=nXyUFessj3XXS3GfZld6FnzhcYWwdXqNjUbQIazlSmTH7nz6XHA2XXQJt6GSJ7K5G2ELX1IekNJqj1k4ROfcnnyOw1TCcN3b7OQBn5O6lfuTQnf9o036MV1s6p9W+F7CRnhrJS7Yevx2PN/EdX8M3lg4/NuOb2xHlf0sJlo8ZVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549759; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sPB2Dc6t3Zgd1EEjPsex1QWFM8C9VFNKedpjWqBxO5k=; b=UwOUhBQX44OmrIcXK1StgRaPuJS5l942Ts483qOyQDS2lzzLAe6KbKtu2OZa+I6YbEmhfGjJg8Mh401fcdto1j/l1/dd3I1sHQ2U+Niz1YGcngGUPoYp3s81emv/tGliEz+xO2covlV0Pm75fI7P8uai2/siVEsg/nOFKu8YFpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168854975943289.04435688057845; Wed, 5 Jul 2023 02:35:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558883.873385 (Exim 4.92) (envelope-from ) id 1qGyux-0006Ky-6V; Wed, 05 Jul 2023 09:35:23 +0000 Received: by outflank-mailman (output) from mailman id 558883.873385; Wed, 05 Jul 2023 09:35:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyux-0006Kq-3S; Wed, 05 Jul 2023 09:35:23 +0000 Received: by outflank-mailman (input) for mailman id 558883; Wed, 05 Jul 2023 09:35:21 +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 1qGyuv-0005bC-NG for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:21 +0000 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [2a00:1450:4864:20::231]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 41e81fc1-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:20 +0200 (CEST) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2b6ff1a637bso6931261fa.3 for ; Wed, 05 Jul 2023 02:35:19 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:18 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 41e81fc1-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549719; x=1691141719; 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=sPB2Dc6t3Zgd1EEjPsex1QWFM8C9VFNKedpjWqBxO5k=; b=KzmaQV2K2xH/7mILxkUyQHMyBQr51bl76tMoOkpR5LmbxOQfz2xmwZBtC098B47iRY Rr0Yisz6v5tz+R77+f565Y5X9/t2IHXMg/NVgP116iy/fLK1RhGmhvCbTcG5z9qfXUGK EKb4jKN+wZO0/qbli2qAs/bNUm3JbW9ZfrBbyKgYVlCbQWzQPNj9v3SK0lu0xWtFF3KC qmsQHMm3+Vr4X5HC+yNSZFPM7a6lEFS+AFosXOtEjQb8R3pGT1/bVLL5dhjRp+26KqpQ zw/PTEdIWaDjg1GWXwQ9xIBMkp+Z+01H3gyBm5JidRoCQ9TqLggDBct21iX3JUWJOPRL 1Qtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549719; x=1691141719; 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=sPB2Dc6t3Zgd1EEjPsex1QWFM8C9VFNKedpjWqBxO5k=; b=ApwQFEnzOBfFqmqz2ubAkFyV2I8WLapvHPlq17mQWAjjFbsA4pSA+w93iC+pNtlY7h Xsq0xqKSJoeFIqHUPrfL+kdWefP91DoPRtoR4eh/xAbnNjztatOsDktt7pgxnCcqIwGi LbvLrWfUf6ALeNmIx4YiSYiko5zfCxfouV70EZd5R8hDc2XjILFf7A7fC1SJTjf0Vo/L L51ablVKowl3VlGVgwnFkc49suXKuM0PW+sqhorbXXMnuBzunGnRKWX6b6ms+pJEzKta ++KHGc3BobQ4twbHBdGTizcW3UDaTvknLAQtR9OeKAbc2O/KXHq9VSLVAvojaBARmBXw X5eA== X-Gm-Message-State: ABy/qLYz5zS6CeanCDg2JH92O2swTRBQqy8sNYzb9bjtI7i3SNOmyfKU 2RYdVBQKeHCBwZ2dTDYIE1njd49SF3AAeRR/HFw= X-Google-Smtp-Source: APBJJlG2atj/pftIqyUxkI68m2T9ZWgQ4liE5nTUqR4RHRlqXrJJbO8QtoL2Mc+TBw3H4UBwqyxZxw== X-Received: by 2002:a2e:b0d2:0:b0:2b6:d9dd:f65f with SMTP id g18-20020a2eb0d2000000b002b6d9ddf65fmr8142657ljl.17.1688549719284; Wed, 05 Jul 2023 02:35:19 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Bertrand Marquis , Luca Fancellu , Julien Grall Subject: [XEN PATCH v9 03/24] xen/arm: smccc: add support for SMCCCv1.2 extended input/output registers Date: Wed, 5 Jul 2023 11:34:12 +0200 Message-Id: <20230705093433.2514898-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549760855100001 Content-Type: text/plain; charset="utf-8" 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=3Den Signed-off-by: Jens Wiklander Reviewed-by: Luca Fancellu 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-offs= ets.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); } =20 /* 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/sm= ccc.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 @@ =20 #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) =20 /* * 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 */ =20 #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; =20 case ARM_SMCCC_ARCH_FEATURES_FID: --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549761; cv=none; d=zohomail.com; s=zohoarc; b=gzkncUMCAT0iJMHwWNaDcjra0YxH6iYMv9VOxFz3VxuAEEUYkDHDRTIhR3QJV9QYhkzYSQpe6iX+oG/6z5YFdNHaoiSrCZJQ1cGsdJgjbAJxKIBWuy0H0VnSUoRaW+dZp09onW6tnP6seWsZv7s/alp8lL3HYeNvnyYvmSljUjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549761; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eWdsZxNkENko/UmOoCJsCn44L2mriNbtUyUkPA5KWjw=; b=D5V9xgUXD2SsitimIDcN44c3D3ksnXe8QZrcE9pdnyj/sDW5qk74ZIb4gaYNQ3qCzZIWAF99l3WJkT45QXm8xcCbKeQKmRRTje5jDGRlMCN9upT5K0VZlne9eks21ewXjQo0OAC+PJ9aD8LhNAvuO1MTOb3wQWoTtAoYAj2l4rg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549761911950.392481216418; Wed, 5 Jul 2023 02:36:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558884.873395 (Exim 4.92) (envelope-from ) id 1qGyuz-0006cy-DY; Wed, 05 Jul 2023 09:35:25 +0000 Received: by outflank-mailman (output) from mailman id 558884.873395; Wed, 05 Jul 2023 09:35:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyuz-0006cr-AS; Wed, 05 Jul 2023 09:35:25 +0000 Received: by outflank-mailman (input) for mailman id 558884; Wed, 05 Jul 2023 09:35:23 +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 1qGyux-0005bC-4Y for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:23 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 429717a4-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:21 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b701dee4bfso2127031fa.0 for ; Wed, 05 Jul 2023 02:35:21 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:19 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 429717a4-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549720; x=1691141720; 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=eWdsZxNkENko/UmOoCJsCn44L2mriNbtUyUkPA5KWjw=; b=PtMM2azYPNLYCU674l2UTHpGLNb6m4A2S+CicJxM1IEK4riNu16LMY5HFAB2UphJOs 71W6C9Rg2aas2x/eJbJ2jSMUKFaNrxKEWkpD5fD5y1JJo8O0qJ1njmlSiKMN13x2qJMT 9YNd+ld01xj5mwO55Vvqkux7i4PEpsSb+CPi2YWZ8BDakEX49VGIe3YZFtL/tVbMOXO2 JXRlFh0cS0GYPj54VYehMs5DmUFdhbu6nDi4XU84yZw1sV2NNql92p+caPtJ+fWmKoVc eS26NRoFxb6M6Y378RhlvUS5MTm4o83s3diS8B8lLFwGQcC5CDCdc6MFWDrkqGYtcHpv ilDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549720; x=1691141720; 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=eWdsZxNkENko/UmOoCJsCn44L2mriNbtUyUkPA5KWjw=; b=IrlX7c2VU7+xypqAOmNJMMwNDHgpFgHmhY004MNGNU7jNl5SYFr/CgUH0B99Ty90FP 6fDLyGrbOZnQ9lr0ZA5YZ2LGti0qTj3jXR6Ikjmfa3hbn+WmzoLW6/A5Kfr1N5WBF27J /vqUSR1TodCid42GyRLbDnEZH8omy1l4fI5UGSRCR7PsEd0T5H2RrvL5ktet8Jn7umZh tX6cqNJnLJPlFD2uzY7nX5lMppGcWp9CRz/IsmhnqybaewukgInOYy7sSBmj0mgI+4uc yNd1pkEujLTfekDR100cs2TpulzPFOsGrr0n+EM5gxAEDl251WsGp9bJAMEfTUFLBt/F AAFw== X-Gm-Message-State: ABy/qLa2WcNa4AQRTpOpxBc5ensVEM0KPYMk1jAp6efqq+EMelsoZOlv LJ/Kj4K7jr5d781NdAsImtRgSLbZ6HJxnct53yE= X-Google-Smtp-Source: APBJJlHOMd8tM9yW7zXDCnRwJVvIW1lEoGwpNE1piNVj9RQP3clxYLJzbcgbg2rTHVlcdwytIdvudQ== X-Received: by 2002:a2e:3009:0:b0:2b6:cca1:9760 with SMTP id w9-20020a2e3009000000b002b6cca19760mr11654855ljw.27.1688549720403; Wed, 05 Jul 2023 02:35:20 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Bertrand Marquis , Andrew Cooper Subject: [XEN PATCH v9 04/24] xen/arm: tee: add a primitive FF-A mediator Date: Wed, 5 Jul 2023 11:34:13 +0200 Message-Id: <20230705093433.2514898-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549762711100003 Content-Type: text/plain; charset="utf-8" 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/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 | 225 +++++++++++++++++++++++++++++ xen/arch/arm/vsmc.c | 17 ++- xen/include/public/arch-arm.h | 1 + 7 files changed, 291 insertions(+), 3 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/psci.h b/xen/arch/arm/include/asm/psc= i.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); =20 +/* 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..44361a4e78e4 --- /dev/null +++ b/xen/arch/arm/include/asm/tee/ffa.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * 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 =3D fid & ARM_SMCCC_FUNC_MASK; + + return fn >=3D FFA_FNUM_MIN_VALUE && fn <=3D FFA_FNUM_MAX_VALUE; +} + +#ifdef CONFIG_FFA +#define FFA_NR_FUNCS 12 +#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) +=3D ffa.o obj-y +=3D tee.o obj-$(CONFIG_OPTEE) +=3D optee.o diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c new file mode 100644 index 000000000000..927c4d33a380 --- /dev/null +++ b/xen/arch/arm/tee/ffa.c @@ -0,0 +1,225 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * 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_VERSION_1_0 MAKE_FFA_VERSION(1, 0) +#define FFA_VERSION_1_1 MAKE_FFA_VERSION(1, 1) +/* The minimal FF-A version of the SPMC that can be supported */ +#define FFA_MIN_SPMC_VERSION 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 { + /* FF-A version used by the guest */ + uint32_t guest_vers; +}; + +/* Negotiated FF-A version to use with the SPMC */ +static uint32_t __ro_after_init ffa_version; + +static bool ffa_get_version(uint32_t *vers) +{ + const struct arm_smccc_1_2_regs arg =3D { + .a0 =3D FFA_VERSION, + .a1 =3D FFA_MY_VERSION, + }; + struct arm_smccc_1_2_regs resp; + + arm_smccc_1_2_smc(&arg, &resp); + if ( resp.a0 =3D=3D FFA_RET_NOT_SUPPORTED ) + { + gprintk(XENLOG_ERR, "ffa: FFA_VERSION returned not supported\n"); + return false; + } + + *vers =3D 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 =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; + uint32_t vers =3D get_user_reg(regs, 1); + + if ( vers < FFA_VERSION_1_1 ) + vers =3D FFA_VERSION_1_0; + else + vers =3D FFA_VERSION_1_1; + + ctx->guest_vers =3D 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 =3D get_user_reg(regs, 0); + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D 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 =3D xzalloc(struct ffa_ctx); + if ( !ctx ) + return -ENOMEM; + + d->arch.tee =3D ctx; + + return 0; +} + +/* This function is supposed to undo what ffa_domain_init() has done */ +static int ffa_domain_teardown(struct domain *d) +{ + struct ffa_ctx *ctx =3D d->arch.tee; + + if ( !ctx ) + return 0; + + XFREE(d->arch.tee); + + return 0; +} + +static int ffa_relinquish_resources(struct domain *d) +{ + 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_SPMC_VERSION || vers > FFA_MY_VERSION ) + { + printk(XENLOG_ERR "ffa: Incompatible version %#x found\n", vers); + return false; + } + + major_vers =3D (vers >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSION_MAJOR_M= ASK; + minor_vers =3D 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 =3D vers; + + return true; +} + +static const struct tee_mediator_ops ffa_ops =3D +{ + .probe =3D ffa_probe, + .domain_init =3D ffa_domain_init, + .domain_teardown =3D ffa_domain_teardown, + .relinquish_resources =3D ffa_relinquish_resources, + .handle_call =3D 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 =20 /* Number of functions currently supported by Standard Service Service Cal= ls. */ -#define SSSC_SMCCC_FUNCTION_COUNT (3 + VPSCI_NR_FUNCS) +#define SSSC_SMCCC_FUNCTION_COUNT (3 + VPSCI_NR_FUNCS + FFA_NR_FUNCS) =20 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); } =20 +static bool is_psci_fid(uint32_t fid) +{ + uint32_t fn =3D fid & ARM_SMCCC_FUNC_MASK; + + return fn >=3D PSCI_FNUM_MIN_VALUE && fn <=3D 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 =3D (uint32_t)get_user_reg(regs, 0); =20 - 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); =20 switch ( fid ) { diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 38311f559581..c6449893e493 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); =20 #define XEN_DOMCTL_CONFIG_TEE_NONE 0 #define XEN_DOMCTL_CONFIG_TEE_OPTEE 1 +#define XEN_DOMCTL_CONFIG_TEE_FFA 2 =20 struct xen_arch_domainconfig { /* IN/OUT */ --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549747; cv=none; d=zohomail.com; s=zohoarc; b=l60IVf3wBFzFmKAbo5X0zywgVlFIsiBEZuo0uGPCYV+0bSKLLK/CWFkMM2WXXHwgCz2LCWc1/sukdrZtQ28BFos2dqYzPm7J6amec5wPtjL7D27w21att9hLpK+jRcak6hDkZtcCNhhKXM9tBkN5cjF9q5xNDpuoMmOa/StsWic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549747; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dqoldXxWy8H0mye06Jm+vbzYDtmZMz3z5RdS7rzJXrI=; b=NNw/Ie5foxkd+WhaJ+qcEcvpI74xQK/x+IWIpVrH4KLoeIQJSBO5lB7PhAS3usucqYrEVFrnFB1Ri7CHWlI+Mp9G457VXpGtbXCP6DsC3zc0Jj00T/ZucWYPPHV1S3ytAV9nHKeEH+p3Iw5AVEOYpQ1MXCiFxQboFbeWaj1noZg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549747702137.29513275420652; Wed, 5 Jul 2023 02:35:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558885.873401 (Exim 4.92) (envelope-from ) id 1qGyuz-0006ga-SA; Wed, 05 Jul 2023 09:35:25 +0000 Received: by outflank-mailman (output) from mailman id 558885.873401; Wed, 05 Jul 2023 09:35:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyuz-0006ez-Jp; Wed, 05 Jul 2023 09:35:25 +0000 Received: by outflank-mailman (input) for mailman id 558885; Wed, 05 Jul 2023 09:35:23 +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 1qGyux-0005bC-Ps for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:23 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 43416c5a-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:22 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b6ff1ad155so5535491fa.0 for ; Wed, 05 Jul 2023 02:35:22 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:21 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 43416c5a-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549721; x=1691141721; 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=dqoldXxWy8H0mye06Jm+vbzYDtmZMz3z5RdS7rzJXrI=; b=yuMft45L04JztcnXQTMuUwXg3C+yuWG+iQk+uWUOKI7ixbPrY4+Q0OtD2WIC3VcOHm hzAen+5zXi4+pOrHM32vexT8/Yo6/9Td83Xw38T7vHQUvMJXFUGam/6QZp4dX/TtEzG6 pl4QEO9mT6UawuiXag/RAULeGICoAF6GigS2113JMmLWmdlhO/B53XiOKlt0Ry1uOJrL Nr8D/q88n18lAg2YaDHjh2P5aNwoBsPyvgjCIkz5HJPzgj/whtdIOC4CwRL2lMoqaas6 DNsvuP3izvZxL6BVQGgew9OTCYu9a6EArjs7ttEKqx/adWk7r7Zrxta0TaQTvX7j4k1T 5BDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549721; x=1691141721; 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=dqoldXxWy8H0mye06Jm+vbzYDtmZMz3z5RdS7rzJXrI=; b=evXomomsPq5z2RohGEpEbp4qT9uSDY7LdQBhZJMLWXm0eU6ri+009/6gJ6yzXa9bge 5dyslFbjdrHDEQqepQRSzhTegbyOkS+maxplddUerupFkVV+b0LiZMy0hIILE55W8wjp +oOzWJzF+z1PPAbJMmLu4T9RdkNoEXE9gnHKOGaGMR29EX6D9CbWCRwlwyK1dilhz+Yr Qr+fL6teW1u/+4I25uuNqwYGW1wBGFOVadj4vf3VkdOXqt3Rwj3RPGGnBBXXxvlsWdpD hlTYUbcklLHZsO+V0BXxWy0UijIVBajkYkZTJRUJQjJ716PMp7RRS4YW7XmmFlSG0fXj IdbQ== X-Gm-Message-State: ABy/qLZdcaIsvsE+KC16hx/pYxmFp3jBqhHOFnBXzH7keaJSd/HV5zzd PTF8jXIGTwqWFmT/Yd6ayWbrO33fBS8mGMYPnG0= X-Google-Smtp-Source: APBJJlHXrPKLZ1T6BqR2/M0Cyskz25seyh+y7ryNtyh9dtB3tHMVIFKLFAy9H0tdDCA4prZi9cIcGw== X-Received: by 2002:a05:651c:10ab:b0:2b6:9e1d:cd0f with SMTP id k11-20020a05651c10ab00b002b69e1dcd0fmr717756ljn.12.1688549721596; Wed, 05 Jul 2023 02:35:21 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 05/24] xen/arm: ffa: add remaining SMC function IDs Date: Wed, 5 Jul 2023 11:34:14 +0200 Message-Id: <20230705093433.2514898-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549749213100001 Content-Type: text/plain; charset="utf-8" Adds the remaining SMC function IDs from FF-A 1.1 specification, DEN0077A version 1.1 REL0. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis Reviewed-by: Henry Wang --- 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 927c4d33a380..2296e3115beb 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -60,7 +60,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_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 =20 struct ffa_ctx { /* FF-A version used by the guest */ --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549751; cv=none; d=zohomail.com; s=zohoarc; b=HQyioAygV0Kgb3sL1Z6ProOQhu4rohjOXPY43NZHyM/zZjuj1gWckDJfVNYUN87L2zKwJbeReDWnJ4Bx28JeER6Z9k7KKUTsM2OjRsoW27xpkeBpteazHK3JraHRmJyClzJs/j5muij00ztH9GTjPi0rdIQdGM8LrHfLZx99+o8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549751; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4wSiWqYej8EPgULt6otzEwmKVlaIAponcAwfHuOJ0rA=; b=aoZa/kLaWjppkA2c7ZQPkNCKbPhYJCzaUpa2XyZFaIN9yCAJwsbFZlSA8J2Bx/XQ70f/naV6kOYMchDa111ncA34ZLR2bA04LQFiknPevt1Pc4ZrSqiN0bjT3gSy7E9n2vQKWk16Du+aY5J7pSdphv8sNaUDCTEo1JxllXsBP8U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549751049974.6860873688629; Wed, 5 Jul 2023 02:35:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558887.873407 (Exim 4.92) (envelope-from ) id 1qGyv0-0006sH-Fg; Wed, 05 Jul 2023 09:35:26 +0000 Received: by outflank-mailman (output) from mailman id 558887.873407; Wed, 05 Jul 2023 09:35:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv0-0006qn-7L; Wed, 05 Jul 2023 09:35:26 +0000 Received: by outflank-mailman (input) for mailman id 558887; Wed, 05 Jul 2023 09:35:25 +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 1qGyuy-0006bq-VN for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:24 +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 43dcee0b-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:23 +0200 (CEST) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4f9fdb0ef35so10482796e87.0 for ; Wed, 05 Jul 2023 02:35:23 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 43dcee0b-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549722; x=1691141722; 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=4wSiWqYej8EPgULt6otzEwmKVlaIAponcAwfHuOJ0rA=; b=r35PHpmueX5C+pIp9nZqViEJktUKqKWBtarwFHhL2i/AgPHEvBdFC8KyHwyTlDrcou AssVt2fcoTsmlb4xWImJkUl55hUSUufnAX4NLjvrWqBrY+IZDWwOXKdv+DGCWZPEDjaz hsMz/TzFYAvkPLFRRk7yhOC708tUCZXG11u6GQLX2IXRyM7rZ1dyphwMJkFRlUW21yIQ xSp6pVbY9HYqwrGd/6pwordftglJ8zOMB2PJPGxW5kX7Eq6/i1DfLUip4OpsOZ33XLC5 ii2IyefzvcBuiOkjGEsdiKXBbjgZVapiVwSll0CPkiYY21moDwhwF+5zd8IrY3lEmJq8 HB/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549722; x=1691141722; 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=4wSiWqYej8EPgULt6otzEwmKVlaIAponcAwfHuOJ0rA=; b=fq//tjTb/zbxQU8oFBeXsq0cr1A1/nUrWJU1YYZkjBi6xfSU9UabOU7An6habjIhTi OAyjnwMd07z/wh779DiU8fAPSlitqlSmqgYaVi+1Z57XcUWFHlcz7zlyE48tSxJgOhhO VyypjYbzqzMyV+h8OKcBzDgm3rW3EInY8OL9e8XvmxCbjk/5+mqEtK8yRdyuJMXJAOq7 SrmVYjBZ0ZwnAI/1/2gq1fBwmzOMHa0hLBvqw6tu5+sUBMOy3G6DLY0PZZJHZ83oO90n Dgttg5z5ZdS33fSRezPV3491wkbzxOrXxqC9iiUtt9zxVVoc02kxumO/Xn24TBbzS7Xt SR7Q== X-Gm-Message-State: ABy/qLbhNa2eu/XaTiK8Mu0N9hGATf4H8QR4Vk2boOANpTqnwlYl57t+ CQbm18qJssWeOPI2xZ9VyU30t8BQmIc6MmisjCI= X-Google-Smtp-Source: APBJJlGqOGGKofqtcuqgQggNsgp6inqP9Q8bZx6Tf0C0P7PTqa8fNrFX6V4UqNchZuYg84fwbvJ70w== X-Received: by 2002:a2e:860e:0:b0:2b6:e2e4:7d9a with SMTP id a14-20020a2e860e000000b002b6e2e47d9amr7134910lji.38.1688549722702; Wed, 05 Jul 2023 02:35:22 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 06/24] xen/arm: ffa: add flags for FFA_PARTITION_INFO_GET Date: Wed, 5 Jul 2023 11:34:15 +0200 Message-Id: <20230705093433.2514898-7-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549753107100001 Content-Type: text/plain; charset="utf-8" According to DEN0077A version 1.1 REL0, section 13.8, defines flags used for the function FFA_PARTITION_INFO_GET. Signed-off-by: Jens Wiklander Reviewed-by: Henry Wang --- 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 2296e3115beb..c1dead73d1f2 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -57,6 +57,40 @@ #define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ FFA_MY_VERSION_MINOR) =20 +/* + * Flags to determine partition properties in 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 + * BIT(6): Partition must be informed about each VM that is created by + * the Hypervisor + * BIT(7): Partition must be informed about each VM that is destroyed by + * the Hypervisor + * BIT(8): Partition runs in the AArch64 execution state else AArch32 + * execution state + */ +#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_TYPE_MASK (3U << 4) +#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 --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549766; cv=none; d=zohomail.com; s=zohoarc; b=C5VvLvb2Fb5McmKdxD30XrW2VyZBjvTyisF4769xfT+ac13K9UFZQzzX3MsTzmCPpC5RXqr+GP3oXeMtP3S0c2zSYQfnojw2oSirG1xYtM+mza0qCSlXdmXN5etAIbb7o7za5Yc7t/QRzRjRWGs72i0Iq1VOyejJiM2U+X+36Jc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549766; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aYcDkH+NYTJEg4WTYuKdvOgpJpdPrLrE00Jo/az+PMc=; b=bl9VLAZZ2z/3nr7DoicSbrvwf5wslxg7WrkOaz2J/UjnpFyjWT+8fjsu3cEBLeAOag1iD1i26vUjNQxpf7q6zKAf2CDSb0WFvWWt3rp5qeQHdB0ueHoWg5APL0nFbBcF8FS86loH9Di71s6Md96NAvsLmgnxlFBcsbqXzSobrmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549766295718.1346372234079; Wed, 5 Jul 2023 02:36:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558888.873415 (Exim 4.92) (envelope-from ) id 1qGyv1-00072F-1Q; Wed, 05 Jul 2023 09:35:27 +0000 Received: by outflank-mailman (output) from mailman id 558888.873415; Wed, 05 Jul 2023 09:35:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv0-00070r-Ob; Wed, 05 Jul 2023 09:35:26 +0000 Received: by outflank-mailman (input) for mailman id 558888; Wed, 05 Jul 2023 09:35:26 +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 1qGyuz-0005bC-UC for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:25 +0000 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [2a00:1450:4864:20::22f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 448c732a-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:24 +0200 (CEST) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b701e1ca63so1940111fa.1 for ; Wed, 05 Jul 2023 02:35:24 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:23 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 448c732a-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549723; x=1691141723; 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=aYcDkH+NYTJEg4WTYuKdvOgpJpdPrLrE00Jo/az+PMc=; b=qdNF81NI4N83t2hYr2K2/bAjBK98JgWSuVIgkhQ6MKSDlmTk/7HEmdS8MIGirJKx8c RXrrV93GMmrpNQc55W4LUOULiPsp2SYRrH60pjdBJmYJkHBZz+klwRRUvA4XVsQsfsbQ IIzgsVG8LrjKp+R/Ke50nUVEMNr8OqykmbhMMZMPBoB6uIHZ93JBgi8jmkwcOu7t3bsL UQKhwKk886ChWnazba94QK1l3J8+GAjB5dk/8RMolLFRER/OFCpywr8XBSpmSV95gmBF JsvSjfFBJVKVfANMSTWGNuaR8gVZbd+Q6do1RcXAV1mqLwcnMHteq2fuZPNk70W4uePy wtjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549723; x=1691141723; 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=aYcDkH+NYTJEg4WTYuKdvOgpJpdPrLrE00Jo/az+PMc=; b=K6AjGh84POW/LDmoxnBJ+Qd6RGrdQQhm/4NyGW8ZdKYEPYbVvc0VjDSiML7YiCKhRO G/OUqea25QI38gGFuRtYqx2qsbL4e6oaJ67xxbHyhkMjo7c5FngsBFfqjESAKqe3FVus yGNfkmH8Dm25hql3zUvFizybSNN2ld7qMVgCZ33dLS8PLPqksf1Q4xOH7wBQrSx1smdR PwgTlCygQ7CU0vfeJSg2q92YHrNkWUg51ZNNr/N26rFAUTIpjnH21Ut6G+eGf2uf72kP HhLS7LT+FpiL1pcnr5arIEViweOxCNw9IUUrT/TDNblJ8P6o3YHqBob0JuqYml+JAGhL 571A== X-Gm-Message-State: ABy/qLY7Jj6MsS7oJ1yv3/dcC2w1BVPCtT4JmLeC9Lrv6gHWk9ngjYfQ A4vmi7BrKOsi9Q2iG0vSZdQ9/MedjG3NErtVKds= X-Google-Smtp-Source: APBJJlGNmiJkwe/ZlBCen5VK7sAfo8dxwOkxD55c0uqBvg2uz6iWiUfGl7wn+2u6butwESe1L0ktwg== X-Received: by 2002:a2e:9bd6:0:b0:2b5:95a8:4126 with SMTP id w22-20020a2e9bd6000000b002b595a84126mr10320701ljj.52.1688549723757; Wed, 05 Jul 2023 02:35:23 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 07/24] xen/arm: ffa: add defines for framework direct request/response messages Date: Wed, 5 Jul 2023 11:34:16 +0200 Message-Id: <20230705093433.2514898-8-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549768497100015 Content-Type: text/plain; charset="utf-8" According to DEN0077A version 1.1 REL0, section 18.3, Table 18.{21, 25, 26, 27, 28}, add defines for framework direct request/response messages. Signed-off-by: Jens Wiklander Reviewed-by: Henry Wang --- xen/arch/arm/tee/ffa.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index c1dead73d1f2..56a0a10c1e99 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -57,6 +57,19 @@ #define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ FFA_MY_VERSION_MINOR) =20 +/* + * Flags and field values used for the MSG_SEND_DIRECT_REQ/RESP: + * BIT(31): Framework or partition message + * BIT(7-0): Message type for frameworks messages + */ +#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 to determine partition properties in FFA_PARTITION_INFO_GET return * message: --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549762; cv=none; d=zohomail.com; s=zohoarc; b=hAHMoRrF0j7EPl0C1Vu5Rp5WEUeRBrKR+oLov5i8dr0UrD/gBcvpYRo5HJSPoSpImIy4eKvG+NqJiwbRljBpYyxC+IyGGODXJ3QdArrNLwjx3e7XnGEtaEEOXILgQb+nBHtBZ0CfxEEtpBEjbm3HchvFZ+zYQC5sll6xA6IYfc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549762; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tuV8RapENruJ9yIpnO0p4qSE4ssdvVfnP6i34l3RXw0=; b=bUaargVDe5+rWkKu97447WEFmYiQ28DqsDt3MriGjM29jfPhmB2qro2ebPqkGy/bvzwwyGYgFG4S6swuz8nzPm6pqa6rejN1D+WYRJzgpqOyS5+QYiPcDf3JZWJMoPsHCyo1TavbB6k5/m25xzGSSoQYgEllWaeWf3U6wbaj4As= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549762886126.15153328940028; Wed, 5 Jul 2023 02:36:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558889.873422 (Exim 4.92) (envelope-from ) id 1qGyv1-0007Bc-EE; Wed, 05 Jul 2023 09:35:27 +0000 Received: by outflank-mailman (output) from mailman id 558889.873422; Wed, 05 Jul 2023 09:35:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv1-00079y-6e; Wed, 05 Jul 2023 09:35:27 +0000 Received: by outflank-mailman (input) for mailman id 558889; Wed, 05 Jul 2023 09:35:26 +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 1qGyv0-0006bq-1E for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:26 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4544a2c6-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:25 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b6ef64342aso37113401fa.3 for ; Wed, 05 Jul 2023 02:35:25 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:24 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4544a2c6-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549725; x=1691141725; 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=tuV8RapENruJ9yIpnO0p4qSE4ssdvVfnP6i34l3RXw0=; b=Rnpt5EUPE7G9VmG1WJ9myyfK62kUeDWU2Vb0eOVWtZy7XRGFsPUzyLZMWY4UlT1TNG +FfboeWU7NqJXuboGxrfAWeS/LqhH9ElxSA6t8GE/gYBjL8u6+WGK+hpBPzq/d1/++4y /jx5IPwq+ABREzb4uqJ3F1bihd+xaEtiOMq7l/NI7OnMghcFPH/NbpQhiUVmH+tBm2dL kT2oHqnMiWs2IVlpWpbMTQSGRE1L+sL10UMYlQa09n7YGzo9zNOb0ePHgUF/OOAgMUeJ jgcoD7vkSkuyVJPn8ndAGnOrf2sU0wrXXhHZnDB9l9BjczuTAG5evWnpjZlncKiIV6M+ AJfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549725; x=1691141725; 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=tuV8RapENruJ9yIpnO0p4qSE4ssdvVfnP6i34l3RXw0=; b=MnRJbcbsxofbyFxhgtkTi2keBTPzJlyrOrdginXqV35cwazqUJBWRiQA7P00lG/DkI uzspx8yLWpR3E8LO+Siux81BuqjEJyQIQlRlsxCwvLJJT5xJQJQpuBaxfyyRB+/p8ybz gXW3RmPAyitXapLxxoQRaEMF1m9QB7fpNLKaPuHuC+Noe+NQ9gdYwIWIZJPAE8ZNk9p4 GIiJmbEzOn0si6gGBxSiFMNfFS9pRbwtiwlZpcvDLEVzkhZdoI1y1pQr2ushGHroDL+D TuFRkhxKIpiBqOuyZAavtxvanQL/TCKsQhKIXr4yyiCRuYMe3cOGSBT455JetOmLQKox /vKQ== X-Gm-Message-State: ABy/qLZix9BAUpda8GGURMSBhEwa/YfAcX3OhbPZDxJ0wft/kFHTex8J DENCyjv+AucHR+uRFQXPgvxLIEACgYHzwe8vGXk= X-Google-Smtp-Source: APBJJlEyQ1nAz45G88ONDZMf7naLt9F5A+CYbW+n20mlO7bNWFVpw/GB4ieBlNRKLv4M4/XRSSXylg== X-Received: by 2002:a2e:9657:0:b0:2b6:faaa:fb53 with SMTP id z23-20020a2e9657000000b002b6faaafb53mr2604114ljh.26.1688549724911; Wed, 05 Jul 2023 02:35:24 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 08/24] xen/arm: ffa: enforce dependency on 4k pages Date: Wed, 5 Jul 2023 11:34:17 +0200 Message-Id: <20230705093433.2514898-9-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549764761100005 Content-Type: text/plain; charset="utf-8" Adds a BUILD_BUG_ON() to assert the dependency on 4k pages in the FF-A mediator since the current implementation only works if Xen page size is the same as the FFA page size. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis Reviewed-by: Henry Wang --- 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 56a0a10c1e99..f0a2715d4bbf 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -57,6 +57,16 @@ #define FFA_MY_VERSION MAKE_FFA_VERSION(FFA_MY_VERSION_MAJOR, \ FFA_MY_VERSION_MINOR) =20 +/* + * 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 + /* * Flags and field values used for the MSG_SEND_DIRECT_REQ/RESP: * BIT(31): Framework or partition message @@ -261,6 +271,17 @@ static bool ffa_probe(void) unsigned int major_vers; unsigned int minor_vers; =20 + /* + * 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 !=3D FFA_PAGE_SIZE); + /* * psci_init_smccc() updates this value with what's reported by EL-3 * or secure world. --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549755; cv=none; d=zohomail.com; s=zohoarc; b=VDGN7zvJAjafFatjqe6OfSALG7Jh+TRR90Fsf2qiGrFfXsQgWv6U5e8W5Lc4qOdeAxRBosXgjguWP9k8hRnzL+lWi/fhrVQZWSVtbfqtmrSm7chrgWCOTK4jYf/Z1YweWIM4dQIfhz7LKn28mq/Bvr4ZqrRr/64BlMd7d/Gxc7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549755; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=x0GAChav/BgZruQ3EPU8Qo2tQ1sDnkEZR3Mc3i3hmhg=; b=MzoeJusHvhEM6WEZMc6/4CQ9dNamPT47R6Eax2OfDXlcaTNeUeKTO92w69a6zZQQGHt0MAqE4dv9HsSZ3VXqfWcoXNiH2PrsMpgUzNnbYwbP/nm8r4s0O5+moViGdoItIUJ38qihr7z22y2ueN272/6mACw2CpchhaIj90WiYPI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549755113367.6194152564211; Wed, 5 Jul 2023 02:35:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558890.873445 (Exim 4.92) (envelope-from ) id 1qGyv4-00082U-Px; Wed, 05 Jul 2023 09:35:30 +0000 Received: by outflank-mailman (output) from mailman id 558890.873445; Wed, 05 Jul 2023 09:35:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv4-000825-KI; Wed, 05 Jul 2023 09:35:30 +0000 Received: by outflank-mailman (input) for mailman id 558890; Wed, 05 Jul 2023 09:35:28 +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 1qGyv2-0005bC-DQ for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:28 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4603b5a3-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:26 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b69f958ef3so104571781fa.1 for ; Wed, 05 Jul 2023 02:35:26 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:25 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4603b5a3-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549726; x=1691141726; 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=x0GAChav/BgZruQ3EPU8Qo2tQ1sDnkEZR3Mc3i3hmhg=; b=B7NNbw/vy6w4tKLRiLZWwvU8hljfohWfyEwbBn5sSoQWTjZr8y/jX5iaAZwpmb9h5w EdzzZOicphG2Ac7ttvHMErFT6+3Skp4xynxoPAzxEww1cbhisDNKRyYH5Yr/kDGXR+K8 J5miq7s0+zDgptmEUVCh7RWtNuWjt7Hw2wiSEuVsZMEr57JqCyzP/mQRJi2wYirrMUlt HO+JSjZ2eRsv5DHGS6H7wj6aTuJr6C2TmlogkK5Uy22KXuETaGqk+4JocCNpK433FEyD 68egJnjz72Plv/q6Mlp71/VRdGo93gv4n9LDK9hJcBavwyJxhFw0U7OF+m11QT7LC+0N JXNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549726; x=1691141726; 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=x0GAChav/BgZruQ3EPU8Qo2tQ1sDnkEZR3Mc3i3hmhg=; b=XEwhhYedMFU+x9rQwYCUO4xgEs3oDuvvMWBG4L7WKcBNauZPafmA15LuwbPuGX+0db 9p2PeTK3qBjeKIHXNbS7M6Z0yM6zo1BSi53rgdRYmkBx0yL/vmpXeZE0xWOa8nzFzQ2Q 7wuaAnAQlgDL39jH26mqMwBCfXE0zeB+TBRtvEiSraPfcZcK7fH0E+ZpfIK5FN5YZavq gcaK7K4XFlttWYKtRb1hSARBWI7mXoET62ay0F2jhJVZleMoosITFRfh+Y9EWJKRyi1X tx9GIHT7dih1RhGW1abzN85ah076XB7eRLcODRhWnvjx0OwzTtLpERD/4MlpIATdEbOq TSjg== X-Gm-Message-State: ABy/qLaWyETbXtLe1NSHxCUHksSt5OXB8QJbK9y952huPug8FVNqq+RA XHAj+mQ0t32WE+fcj5GlMG/QSfg7lJkpAx201uc= X-Google-Smtp-Source: APBJJlFOVK027Xr13cYrFNIVHsgMnH0tYA85EQAiduYKdHJhh8oelr0qTEPlmLcdJtkcm7XZnqt20w== X-Received: by 2002:a2e:93d6:0:b0:2b6:fe54:2a4b with SMTP id p22-20020a2e93d6000000b002b6fe542a4bmr1072946ljh.37.1688549726106; Wed, 05 Jul 2023 02:35:26 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 09/24] xen/arm: ffa: add support for FFA_ID_GET Date: Wed, 5 Jul 2023 11:34:18 +0200 Message-Id: <20230705093433.2514898-10-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549755544100005 Content-Type: text/plain; charset="utf-8" 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, 21 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index f0a2715d4bbf..e157ed20ad8b 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -181,6 +181,12 @@ static bool ffa_get_version(uint32_t *vers) return true; } =20 +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) @@ -195,6 +201,12 @@ static void set_regs(struct cpu_user_regs *regs, regis= ter_t v0, register_t v1, set_user_reg(regs, 7, v7); } =20 +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 =3D current->domain; @@ -224,6 +236,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; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -237,6 +252,12 @@ static int ffa_domain_init(struct domain *d) =20 if ( !ffa_version ) return -ENODEV; + /* + * We can't use that last possible domain ID or get_vm_id() would cau= se + * an overflow. + */ + if ( d->domain_id >=3D UINT16_MAX) + return -ERANGE; =20 ctx =3D xzalloc(struct ffa_ctx); if ( !ctx ) --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549766; cv=none; d=zohomail.com; s=zohoarc; b=CHRua9KuqNgb/1X4l9FfaW2Tr4iaAo1oP/RCshYMTFiuz2LcLqWJHiUdjJwLqWYON0YAjCPZtNDjKy61BSJTCcDpc3DAtsBrFPELY+9HnlSe+H7qwHQlksbQbJY7jTrKDgfjX01oxJ/ZtosOfCii0Dp4gqSxzRF5TFkceTE7f4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549766; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C+n5gOj+w1Jr5cwaD9TQj7fEu8jpwI0+pO30/yvaxYY=; b=FEZeaxasTLo4j6Z6AFHAncxZgv9tnKnOe2Es5hIdFmTU/3Sf36oLEMN0FCI08cKhRHvBHzWj3CSjIpKRJw8+vEkgO2fv72zBpFoIOJp5uih/AIOMw5kUcrbtCnkBunchTWjUHrStD0CQDtfxH4KX7OFMM/Rm0ML/55FSM5O/Sw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549766115246.94287367874801; Wed, 5 Jul 2023 02:36:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558892.873450 (Exim 4.92) (envelope-from ) id 1qGyv5-0008BJ-Jw; Wed, 05 Jul 2023 09:35:31 +0000 Received: by outflank-mailman (output) from mailman id 558892.873450; Wed, 05 Jul 2023 09:35:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv5-00089X-9M; Wed, 05 Jul 2023 09:35:31 +0000 Received: by outflank-mailman (input) for mailman id 558892; Wed, 05 Jul 2023 09:35:29 +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 1qGyv3-0005bC-Nl for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:29 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 46c7d82d-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:28 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b701e1ca63so1941201fa.1 for ; Wed, 05 Jul 2023 02:35:28 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:26 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 46c7d82d-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549727; x=1691141727; 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=C+n5gOj+w1Jr5cwaD9TQj7fEu8jpwI0+pO30/yvaxYY=; b=EM0sBwQY9tSqUTMbLrIvqFIY5GpkuUgHl9KHji4cYp+SotFHgcMNLEfioBijVsltOY IGiopmKU57bTIfiigojSxbnt/U+GL0ocSxVKiVuWhULCAFBXV8YLQELG89mUp+cHEBze e37D/aI1rBPFTXszZ/jMiVfWDxg8jbrfYaBgwm4Cfx1N6wyu9fG82RI/sFZoCPg+uvOd EIhb7rG8PVSUmbiFptKJu7eNhe2EEUweCdkTI5wSVE8emMn/MTCgDogKLeiSVb7J5MqK 07W0Cac+7E+WWZW22zDHNUcsUttSCfOYAesUNiiRfOA4yOghP94yb2N316iXEpVdLb1f bJgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549727; x=1691141727; 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=C+n5gOj+w1Jr5cwaD9TQj7fEu8jpwI0+pO30/yvaxYY=; b=Dq0q4JyPLg3ovXRHmLKbqY8AWnrsXE30YHnxQj3r3QEOJV46HDqavQehMl4QLhXbtJ cr9R3vUBrB/M9Knc6te88b0UAIPv+YaVdp8dVNDZ9LDN9eMyeb1QbkPeEWYdG2g5vMxt Pp5KK6AGglJ4mSeKGI9kMLmSA0RiO9p8KA0lNbPyfsj5/m9gEGmE4q+UPJq3nQeuSRxS 4S1KtIRFDQhQw6WNIgGJV3Ln+ewGQYRYa/tmC3+M2fNWE1jmYiC0M/Sn2Vle2Kb5jzCk 0ZSpycK3OdR5Q46a18waCKDUpKrR+vb+RByyT5ZOqrk0uwqaeAFhyGy0N6zIdjloAUoD 0shA== X-Gm-Message-State: ABy/qLbkKQ/KKj3PuLsDktQ+1Q30V+mdoG7QxhNUafI7I/Qmds1jJTn6 Ml8dHqDu54buY89gMowk5xXTrwsKfq81ik6pOEg= X-Google-Smtp-Source: APBJJlHTzND0+TurDFFDgmVPf6e+8XxKHVpcScnbrup7W0dblLipHGopPxvW6YyLx4SRCQZn9GEHmQ== X-Received: by 2002:a2e:8095:0:b0:2b6:a344:29cf with SMTP id i21-20020a2e8095000000b002b6a34429cfmr10214394ljg.17.1688549727373; Wed, 05 Jul 2023 02:35:27 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 10/24] xen/arm: ffa: add direct request support Date: Wed, 5 Jul 2023 11:34:19 +0200 Message-Id: <20230705093433.2514898-11-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549767431100013 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Henry Wang --- xen/arch/arm/tee/ffa.c | 113 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index e157ed20ad8b..e05d58cf7755 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -181,6 +181,56 @@ static bool ffa_get_version(uint32_t *vers) return true; } =20 +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 =3D { + .a0 =3D fid, + .a1 =3D a1, + .a2 =3D a2, + .a3 =3D a3, + .a4 =3D 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) +{ + int32_t ret =3D ffa_features(id); + + if ( ret ) + printk(XENLOG_ERR "ffa: mandatory feature id %#x missing: error %d= \n", + id, ret); + + return !ret; +} + static uint16_t get_vm_id(const struct domain *d) { /* +1 since 0 is reserved for the hypervisor in FF-A */ @@ -222,6 +272,57 @@ static void handle_version(struct cpu_user_regs *regs) set_regs(regs, vers, 0, 0, 0, 0, 0, 0, 0); } =20 +static void handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_= t fid) +{ + struct arm_smccc_1_2_regs arg =3D { .a0 =3D fid, }; + struct arm_smccc_1_2_regs resp =3D { }; + struct domain *d =3D current->domain; + uint32_t src_dst; + uint64_t mask; + + if ( smccc_is_conv_64(fid) ) + mask =3D GENMASK_ULL(63, 0); + else + mask =3D GENMASK_ULL(31, 0); + + src_dst =3D get_user_reg(regs, 1); + if ( (src_dst >> 16) !=3D get_vm_id(d) ) + { + resp.a0 =3D FFA_ERROR; + resp.a2 =3D FFA_RET_INVALID_PARAMETERS; + goto out; + } + + arg.a1 =3D src_dst; + arg.a2 =3D get_user_reg(regs, 2) & mask; + arg.a3 =3D get_user_reg(regs, 3) & mask; + arg.a4 =3D get_user_reg(regs, 4) & mask; + arg.a5 =3D get_user_reg(regs, 5) & mask; + arg.a6 =3D get_user_reg(regs, 6) & mask; + arg.a7 =3D get_user_reg(regs, 7) & mask; + + arm_smccc_1_2_smc(&arg, &resp); + switch ( resp.a0 ) + { + 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: + break; + default: + /* Bad fid, report back. */ + memset(&arg, 0, sizeof(arg)); + arg.a0 =3D FFA_ERROR; + arg.a1 =3D src_dst; + arg.a2 =3D FFA_RET_ABORTED; + } + +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 & mas= k); +} + static bool ffa_handle_call(struct cpu_user_regs *regs) { uint32_t fid =3D get_user_reg(regs, 0); @@ -239,6 +340,10 @@ 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: + case FFA_MSG_SEND_DIRECT_REQ_64: + handle_msg_send_direct_req(regs, fid); + return true; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -331,6 +436,14 @@ static bool ffa_probe(void) printk(XENLOG_INFO "ARM FF-A Firmware version %u.%u\n", major_vers, minor_vers); =20 + /* + * At the moment domains must support the same features used by Xen. + * TODO: Rework the code to allow domain to use a subset of the + * features supported. + */ + if ( !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) + return false; + ffa_version =3D vers; =20 return true; --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549767; cv=none; d=zohomail.com; s=zohoarc; b=PZWxy6o5IzBOswuDJvEOHle4GOQnZU//tnwj4GJKGZLLNNYD6OKpqdpOGlSnLxQ9qDsQrUKqfMZdxckTsvBAil4rvifdSVKnA05eVnhsst8CFmtWuaHPubrqolKDFb84OJ6e/jlAg+ISzGVQCmQpWqKJvbQZkg5EggnwwQw4w54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549767; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I6PcGNOj2uFVtSWdI80VqpOM3Tw157fUaqVtYpkv27I=; b=n5m9neopgEEoLIblLq1PS8R3fZkysJhsWLRa/Pp8/Rxvy0p6g9eaZb63DILRoqbkxSDDl3DGaK0CvElZ9jgCgy5rwXKmuIVfUActIettjtMfl5OdN22TjpG/sZBd6ZBPLRYNV/Je9MuvtgEvjUmpi4RkSlkEmQKFhn+AyWLPR/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549767094956.3517069290275; Wed, 5 Jul 2023 02:36:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558893.873462 (Exim 4.92) (envelope-from ) id 1qGyv6-0008Vo-Vx; Wed, 05 Jul 2023 09:35:32 +0000 Received: by outflank-mailman (output) from mailman id 558893.873462; Wed, 05 Jul 2023 09:35:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv6-0008VA-Mh; Wed, 05 Jul 2023 09:35:32 +0000 Received: by outflank-mailman (input) for mailman id 558893; Wed, 05 Jul 2023 09:35:30 +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 1qGyv4-0005bC-P7 for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:30 +0000 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [2a00:1450:4864:20::22d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 476e6fdc-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:29 +0200 (CEST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2b6a16254a4so97375261fa.0 for ; Wed, 05 Jul 2023 02:35:29 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:28 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 476e6fdc-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549728; x=1691141728; 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=I6PcGNOj2uFVtSWdI80VqpOM3Tw157fUaqVtYpkv27I=; b=DEvL+q710F8tk41SRkTdh0e+4CAz6gsiuAYF2/Qh1nvPJxeVsuvtBY46qIR5CL0W9D DjS/xDuPmq1FnFAVKMREGGaifsozQsDRxgtqUCdvqzNMF2M/9RgQXgf8cRuZgLHQFa51 MwGM8Lr6IekmzgYvu0doaUHDACAA5NRfmPLW/Ek4CMFhPErsIVFs7iqFaYJ4ktDpnU95 VJDPIMVpw6mOE5WrZomfynZzMwzSPw7xeahQekjrwEphGyFTV6twzsnI5qoco0fL2riG nWajvs6prZVdlRGuydjorhG7Q/GIM/W/DufKThXPZObMIWTJf8Jzl+KfIfrfYA31VFvb YT8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549728; x=1691141728; 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=I6PcGNOj2uFVtSWdI80VqpOM3Tw157fUaqVtYpkv27I=; b=ayyvKsoxRGxlBaxi/ezWKv6I2Gdg67b8x6z/ENbPvwt9hvrUP10e80kLtz37JSV1b5 RErH7oUtV6MbH/et2zkPHMjFGIQshnObyffy/oL3IAL6g+nsR5yalfLKGtDSoxoFJzq1 +HzoSgWGmvb8zJRKDrA2WmDhQ9KMi2bF09lFjpFatT37N1xKFnUzxPIDfS1zGcbeVrAM w/MEFV78MX7xA+dHZzGzObycu4ZUB3ShlEAw68qT3B/nby+aeLyx4CYZM5/Q9t/Ha+KH 1Ld6xpBLgyZtyN37eSJCRrzW4cV9QjnjdIgXqxQlYYkXWB7Kr4gjb73uB7UebUmWfxZo D+NA== X-Gm-Message-State: ABy/qLYs3NEoyhtVvc29T9RGMIIhYTYRA/cb5aWqmXvQucxaCJjSZFZ9 qVbTc9NQ7zmWS/j5mwuLxWa1zlVFUUQOPzR4uEI= X-Google-Smtp-Source: APBJJlF1WoV8nmFc2oR5r4szd6sSBwz7KYe0xDqmvDJ4irnPV5Er1nvwLqLtUFmLapP0IzGV+pkxkQ== X-Received: by 2002:a2e:a41a:0:b0:2b1:a89a:5f2b with SMTP id p26-20020a2ea41a000000b002b1a89a5f2bmr10849559ljn.2.1688549728532; Wed, 05 Jul 2023 02:35:28 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 11/24] xen/arm: ffa: map SPMC rx/tx buffers Date: Wed, 5 Jul 2023 11:34:20 +0200 Message-Id: <20230705093433.2514898-12-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549768505100016 Content-Type: text/plain; charset="utf-8" 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 and FFA_RXTX_UNMAP. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index e05d58cf7755..f8ccaabc568d 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,12 @@ */ #define FFA_PAGE_SIZE SZ_4K =20 +/* + * The number of pages used for each of the RX and TX buffers shared with + * the SPMC. + */ +#define FFA_RXTX_PAGE_COUNT 1 + /* * Flags and field values used for the MSG_SEND_DIRECT_REQ/RESP: * BIT(31): Framework or partition message @@ -161,6 +168,13 @@ struct ffa_ctx { /* Negotiated FF-A version to use with the SPMC */ static uint32_t __ro_after_init ffa_version; =20 +/* + * Our rx/tx buffers shared with the SPMC. FFA_RXTX_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 bool ffa_get_version(uint32_t *vers) { const struct arm_smccc_1_2_regs arg =3D { @@ -231,6 +245,12 @@ static bool check_mandatory_feature(uint32_t id) return !ret; } =20 +static int32_t ffa_rxtx_map(paddr_t tx_addr, paddr_t rx_addr, + uint32_t page_count) +{ + return ffa_simple_call(FFA_RXTX_MAP_64, 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 */ @@ -394,6 +414,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; =20 @@ -441,12 +462,39 @@ static bool ffa_probe(void) * TODO: Rework the code to allow domain to use a subset of the * features supported. */ - if ( !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) + if ( + !check_mandatory_feature(FFA_RXTX_MAP_64) || + !check_mandatory_feature(FFA_RXTX_UNMAP) || + !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) + return false; + + ffa_rx =3D alloc_xenheap_pages(get_order_from_pages(FFA_RXTX_PAGE_COUN= T), 0); + if ( !ffa_rx ) return false; =20 + ffa_tx =3D alloc_xenheap_pages(get_order_from_pages(FFA_RXTX_PAGE_COUN= T), 0); + if ( !ffa_tx ) + goto err_free_ffa_rx; + + e =3D ffa_rxtx_map(__pa(ffa_tx), __pa(ffa_rx), FFA_RXTX_PAGE_COUNT); + if ( e ) + { + printk(XENLOG_ERR "ffa: Failed to map rxtx: error %d\n", e); + goto err_free_ffa_tx; + } ffa_version =3D vers; =20 return true; + +err_free_ffa_tx: + free_xenheap_pages(ffa_tx, 0); + ffa_tx =3D NULL; +err_free_ffa_rx: + free_xenheap_pages(ffa_rx, 0); + ffa_rx =3D NULL; + ffa_version =3D 0; + + return false; } =20 static const struct tee_mediator_ops ffa_ops =3D --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688550001; cv=none; d=zohomail.com; s=zohoarc; b=HuPD70P3hRhMsG7zLgNtAjOBz27vtZR2F6C0kBZguF50ovrUdhLOBWF9INK6HYpArXjXDEsqKfkmNSdRr12ngMTmqp+V0Mvj8u23JkfGA+WoUrMvAIs7520zLI5JJarFfp+trMBkAQLkHEjr6s/H8Utcc2YvfMLIb0nYWRpENfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688550001; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xKMZdOi/Dn1qjCZASYiDWBzyjEGqNklqsbHI8w4JIKE=; b=B1EG2F7FE1Xg1OK4vonZM9um6HxatMZWiw11hJlNlpIwDowq5kIJaguvcFWnQ7RBSgIl13xDxUNcoD9JJpFGhN/1KO6bDgZNApWeUiweGLU59r4m9QH4bUz8fZ0oYoz2xwlqnxy/G0NRw5is1VrSzE0yYV2IrYL/Q8G18xzoW0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168855000098432.97093359122198; Wed, 5 Jul 2023 02:40:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558964.873590 (Exim 4.92) (envelope-from ) id 1qGyz6-0000gp-3L; Wed, 05 Jul 2023 09:39:40 +0000 Received: by outflank-mailman (output) from mailman id 558964.873590; Wed, 05 Jul 2023 09:39:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyz5-0000fv-QZ; Wed, 05 Jul 2023 09:39:39 +0000 Received: by outflank-mailman (input) for mailman id 558964; Wed, 05 Jul 2023 09:39:38 +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 1qGyv6-0005bC-8e for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:32 +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 48196d2b-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:30 +0200 (CEST) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4fb761efa7aso10061091e87.0 for ; Wed, 05 Jul 2023 02:35:30 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:29 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 48196d2b-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549729; x=1691141729; 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=xKMZdOi/Dn1qjCZASYiDWBzyjEGqNklqsbHI8w4JIKE=; b=Yo5l1JORxuZq/AUfzucBeFEkCWltsrQvif6qfvakkf/kwf/4KYHoc0MC98lzbMGREb EfNs/oicp1xaYXvNIWJKg8PyoQLn7y+F2uFlNRg+FF43I0Ba87D2VEyyW90oGX4h76Vs rJsenLywtkD+ftIKurzhDSxTwiZdiyAOYEZn+Am7Gm4pRiHjkgYU0poeYdbVt2z7l/XU 7vuU1FTgN33kJA10NP3o2UBTItvsz3humY+lJLwqs5X7NRQFmr3PwAeSDNgG0BuINNI+ kufYDlA+lYx7Wp14s7zjTNwMll2Zx2b/HF0lzxsJfkF7+l29zqBtMpgl0AfNDyyWf5/l 5e8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549729; x=1691141729; 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=xKMZdOi/Dn1qjCZASYiDWBzyjEGqNklqsbHI8w4JIKE=; b=CAPFmpfpP3j0vTFCaLqY7/S+/e30p7Lss1LFzA4L9j6peO3pafYHYcjM0z4u8URQjT NpfSuOCziDEE1q5xh7zFPYTfyrxWN94EG8f1GDYSkunmIFnHWL7fmc/UZHACwENBAySv wbLNcOnJTSi7qOGhqUXYFdIOYi8vmljDKspCoQ+0Un09+JD+dToxQEJhL/mCVRp4uf9e yf8twPqtsp49Bi6M/y+DQzfEHuhudI8P4trWeISzSPqAtRrSDjBOUxodhy443WZtcAw6 /duJHMkk6YFkJGxcWpHqy99c/OIPnQ2XgyfzS2PSnA+4z+RCTVGUGzTdrgY39p/sbOCi CEMQ== X-Gm-Message-State: ABy/qLYkcq7gaOjUBFZ1Jvm3w6Mo7fau+wQBJO6GiVNO5irb7K84PY1U TEexO3HFPcqlKp7lG3UEsu0itKjs7B2srBOxf20= X-Google-Smtp-Source: APBJJlG1vx41HWZkhZrzm5Al4+cHWA0wwjhNJ5mLa89tKq4ICxneInL0vwVIY3DuVhJznqjeNzdDrA== X-Received: by 2002:a2e:9599:0:b0:2b6:c818:a9bc with SMTP id w25-20020a2e9599000000b002b6c818a9bcmr11146517ljh.23.1688549729693; Wed, 05 Jul 2023 02:35:29 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper Subject: [XEN PATCH v9 12/24] xen/arm: ffa: send guest events to Secure Partitions Date: Wed, 5 Jul 2023 11:34:21 +0200 Message-Id: <20230705093433.2514898-13-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688550001572100010 Content-Type: text/plain; charset="utf-8" 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 | 233 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index f8ccaabc568d..d755363de686 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -160,14 +160,33 @@ #define FFA_MSG_SEND 0x8400006EU #define FFA_MSG_POLL 0x8400006AU =20 +/* 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 { /* FF-A version used by the guest */ uint32_t guest_vers; + /* + * Number of SPs that we have sent a VM created signal to, used in + * ffa_domain_teardown() to know which SPs need to be signalled. + */ + uint16_t create_signal_count; }; =20 /* Negotiated FF-A version to use with the SPMC */ static uint32_t __ro_after_init ffa_version; =20 +/* SPs subscribing to VM_CREATE and VM_DESTROYED events */ +static uint16_t *subscr_vm_created __read_mostly; +static uint16_t subscr_vm_created_count __read_mostly; +static uint16_t *subscr_vm_destroyed __read_mostly; +static uint16_t subscr_vm_destroyed_count __read_mostly; + /* * Our rx/tx buffers shared with the SPMC. FFA_RXTX_PAGE_COUNT is the * number of pages used in each of these buffers. @@ -251,6 +270,87 @@ static int32_t ffa_rxtx_map(paddr_t tx_addr, paddr_t r= x_addr, return ffa_simple_call(FFA_RXTX_MAP_64, tx_addr, rx_addr, page_count, = 0); } =20 +static int32_t ffa_partition_info_get(uint32_t w1, uint32_t w2, uint32_t w= 3, + uint32_t w4, uint32_t w5, + uint32_t *count) +{ + const struct arm_smccc_1_2_regs arg =3D { + .a0 =3D FFA_PARTITION_INFO_GET, + .a1 =3D w1, + .a2 =3D w2, + .a3 =3D w3, + .a4 =3D w4, + .a5 =3D w5, + }; + struct arm_smccc_1_2_regs resp; + uint32_t ret; + + arm_smccc_1_2_smc(&arg, &resp); + + ret =3D get_ffa_ret_code(&resp); + if ( !ret ) + *count =3D 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 =3D FFA_MSG_FLAG_FRAMEWORK; + unsigned int retry_count =3D 0; + int32_t res; + + if ( msg =3D=3D FFA_MSG_SEND_VM_CREATED ) + exp_resp |=3D FFA_MSG_RESP_VM_CREATED; + else if ( msg =3D=3D FFA_MSG_SEND_VM_DESTROYED ) + exp_resp |=3D FFA_MSG_RESP_VM_DESTROYED; + else + return FFA_RET_INVALID_PARAMETERS; + + do { + const struct arm_smccc_1_2_regs arg =3D { + .a0 =3D FFA_MSG_SEND_DIRECT_REQ_32, + .a1 =3D sp_id, + .a2 =3D FFA_MSG_FLAG_FRAMEWORK | msg, + .a5 =3D vm_id, + }; + struct arm_smccc_1_2_regs resp; + + arm_smccc_1_2_smc(&arg, &resp); + if ( resp.a0 !=3D FFA_MSG_SEND_DIRECT_RESP_32 || resp.a2 !=3D exp_= resp ) + { + /* + * This is an invalid response, likely due to some error in the + * implementation of the ABI. + */ + return FFA_RET_INVALID_PARAMETERS; + } + res =3D resp.a3; + if ( ++retry_count > 10 ) + { + /* + * TODO + * FFA_RET_INTERRUPTED means that the SPMC has a pending + * non-secure interrupt, we need a way of delivering that + * non-secure interrupt. + * FFA_RET_RETRY is the SP telling us that it's temporarily + * blocked from handling the direct request, we need a generic + * way to deal with this. + * For now in both cases, give up after a few retries. + */ + return res; + } + } while ( res =3D=3D FFA_RET_INTERRUPTED || res =3D=3D 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 */ @@ -374,6 +474,8 @@ 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; + int32_t res; =20 if ( !ffa_version ) return -ENODEV; @@ -387,20 +489,68 @@ static int ffa_domain_init(struct domain *d) ctx =3D xzalloc(struct ffa_ctx); if ( !ctx ) return -ENOMEM; - d->arch.tee =3D ctx; =20 + for ( n =3D 0; n < subscr_vm_created_count; n++ ) + { + res =3D 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); + ctx->create_signal_count =3D n; + return -EIO; + } + } + ctx->create_signal_count =3D n; + return 0; } =20 +static bool is_in_subscr_list(const uint16_t *subscr, uint16_t start, + uint16_t end, uint16_t vm_id) +{ + unsigned int n; + + for (n =3D start; n < end; n++) + { + if (subscr[n] =3D=3D vm_id) + return true; + } + + return false; +} + /* This function is supposed to undo what ffa_domain_init() has done */ static int ffa_domain_teardown(struct domain *d) { struct ffa_ctx *ctx =3D d->arch.tee; + unsigned int n; + int32_t res; =20 if ( !ctx ) return 0; =20 + for ( n =3D 0; n < subscr_vm_destroyed_count; n++ ) + { + /* + * Skip SPs subscribed to the VM created event that never was + * notified of the VM creation due to an error during + * ffa_domain_init(). + */ + if ( is_in_subscr_list(subscr_vm_created, ctx->create_signal_count, + subscr_vm_created_count, get_vm_id(d)) ) + continue; + + res =3D 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); =20 return 0; @@ -411,6 +561,81 @@ static int ffa_relinquish_resources(struct domain *d) return 0; } =20 +static void uninit_subscribers(void) +{ + subscr_vm_created_count =3D 0; + subscr_vm_destroyed_count =3D 0; + XFREE(subscr_vm_created); + XFREE(subscr_vm_destroyed); +} + +static bool init_subscribers(struct ffa_partition_info_1_1 *fpi, uint16_t = count) +{ + uint16_t n; + uint16_t c_pos; + uint16_t d_pos; + + subscr_vm_created_count =3D 0; + subscr_vm_destroyed_count =3D 0; + for ( n =3D 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 =3D xzalloc_array(uint16_t, subscr_vm_created_co= unt); + if ( subscr_vm_destroyed_count ) + subscr_vm_destroyed =3D 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"); + uninit_subscribers(); + return false; + } + + for ( c_pos =3D 0, d_pos =3D 0, n =3D 0; n < count; n++ ) + { + if ( fpi[n].partition_properties & FFA_PART_PROP_NOTIF_CREATED ) + subscr_vm_created[c_pos++] =3D fpi[n].id; + if ( fpi[n].partition_properties & FFA_PART_PROP_NOTIF_DESTROYED ) + subscr_vm_destroyed[d_pos++] =3D fpi[n].id; + } + + return true; +} + +static bool init_sps(void) +{ + bool ret =3D false; + uint32_t count; + int e; + + e =3D 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; + } + + if ( count >=3D UINT16_MAX ) + { + printk(XENLOG_ERR "ffa: Impossible number of SPs: %u\n", count); + goto out; + } + + ret =3D init_subscribers(ffa_rx, count); + +out: + ffa_rx_release(); + + return ret; +} + static bool ffa_probe(void) { uint32_t vers; @@ -462,7 +687,8 @@ static bool ffa_probe(void) * TODO: Rework the code to allow domain to use a subset of the * features supported. */ - if ( + if ( !check_mandatory_feature(FFA_PARTITION_INFO_GET) || + !check_mandatory_feature(FFA_RX_RELEASE) || !check_mandatory_feature(FFA_RXTX_MAP_64) || !check_mandatory_feature(FFA_RXTX_UNMAP) || !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) @@ -484,6 +710,9 @@ static bool ffa_probe(void) } ffa_version =3D vers; =20 + if ( !init_sps() ) + goto err_free_ffa_tx; + return true; =20 err_free_ffa_tx: --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549764; cv=none; d=zohomail.com; s=zohoarc; b=AIj3hMqle0rl93IbnWjOSvfo8Kk5K5voU9BA9KOteGqJbyAqOPUyXshm/CIfufKXD5gbt7PyHaC7uoDsL+YP95J49TXIGbOViLxwy+0zS4xKmwGPn3WZJGnicJkXzYKXXRVv/1k+DW7GIkJ+dBeDicxz2Y5+W8aQL4c/JyVz5PI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549764; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DSBg2xryTcGQSIhkiAk5XZ42VUodB1h52U56N4DUxBw=; b=ULzJt7mvxKUGGBnMbxMw2+jyIFWITjSI7+awTcT/eVA7R6O+jgQaszxVJZHgpAlwJ7K+6iCO/w6UpMd5Y7hnhLrzQhhrmq7OkrjpWopNBXU3cV0e7gl8Mlx2943iKMROcBaOyo+yNgM4S4H/kGWdOQhju2BWqKeq+u7DIfssgfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549764407743.2278589941952; Wed, 5 Jul 2023 02:36:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558894.873465 (Exim 4.92) (envelope-from ) id 1qGyv7-0000AJ-JV; Wed, 05 Jul 2023 09:35:33 +0000 Received: by outflank-mailman (output) from mailman id 558894.873465; Wed, 05 Jul 2023 09:35:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyv7-00009P-81; Wed, 05 Jul 2023 09:35:33 +0000 Received: by outflank-mailman (input) for mailman id 558894; Wed, 05 Jul 2023 09:35:32 +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 1qGyv6-0006bq-59 for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:32 +0000 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [2a00:1450:4864:20::22c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 48d8192e-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:31 +0200 (CEST) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2b69dcf45faso105696701fa.0 for ; Wed, 05 Jul 2023 02:35:31 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:30 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 48d8192e-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549731; x=1691141731; 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=DSBg2xryTcGQSIhkiAk5XZ42VUodB1h52U56N4DUxBw=; b=haix9goqTFpeMCgdTNcgcuJZeX+0YMjDXLAQnkf1/sLdppJVDOj+/tcCGGpSE4G8EH vQPmx4Yyj5Bsq5d7NH26qdkt0k1KVHYKA+/Q/hxhwNJN3XTSoJPzvhtR0pCSQblTvC+f 1Ef6o05MuYwmQWRhYVLbF9tIgQx6VW0Fq73Z14/bO+VN6XjhGqoUGGXlZ6KaPAAr3cpQ k8WrX1aPPmAX21Abp6bAZEhIbyGgH7I2Hxpc4jYlaITLXWSqvYRqT47RWAAfvSF6S9MX kC7r1DeLDmttUjKlKn7GAoGJhJp2uAtbqYay9Et9hYwQ8u2GQ+qmjJQR1w5Hn/WgMkkb 9PMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549731; x=1691141731; 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=DSBg2xryTcGQSIhkiAk5XZ42VUodB1h52U56N4DUxBw=; b=dtw2enCkMov8bn/UlslcnBZKzXN3/H6sZZF/U9+YUNTSgnZ25Mbfq1OBjDATyX3937 FInXpN3Ob9Sz4V3LjhPaVCrCzAPqyhFrkD3GHdi/sfbt9QtFWAF1iu5Drhoh4wzFSbBe ICGfRkjZq5lUrgSZmdvNixWojp3Wjlw3L6wgun+US8PUKzEbWH6L73RI0UtY1UJEdwuL SVibVdg6XVaibXGcmtYrF+pgnoJRt/L/LN1KX28ElK6yKpGWUvEl4X6U+ZJB67sY07zr z7rgNn102x3STTGM78ZbRIJ9UZsuEjpmCDneuvhdAxh1NKRlyOwYc86RuTAZTh9zlGPx GYqA== X-Gm-Message-State: ABy/qLbKIGS6FK/+BuFMvkEVTsMD0i9C1rUd+OdNuPd5Uz93Uo+hBlkF qNNStUxWZGICdPSNA/qsYaNwo4esrSMXeXy7qFU= X-Google-Smtp-Source: APBJJlGVz+GGr1BGYhTewNovKl6bOEcgQCxFMYm0WJ6fzZSavWHZSOqfa3zc0++sJavG17h6yVNjHw== X-Received: by 2002:a2e:b0d2:0:b0:2b6:d9dd:f65f with SMTP id g18-20020a2eb0d2000000b002b6d9ddf65fmr8142941ljl.17.1688549730903; Wed, 05 Jul 2023 02:35:30 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper Subject: [XEN PATCH v9 13/24] xen/arm: ffa: support mapping guest RX/TX buffers Date: Wed, 5 Jul 2023 11:34:22 +0200 Message-Id: <20230705093433.2514898-14-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549766287100007 Content-Type: text/plain; charset="utf-8" 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 transmit data that cannot be passed in registers only. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 138 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index d755363de686..ffabb5ed0a80 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -74,6 +74,12 @@ */ #define FFA_RXTX_PAGE_COUNT 1 =20 +/* + * Limits the number of pages RX/TX buffers guests can map. + * TODO support a larger number. + */ +#define FFA_MAX_RXTX_PAGE_COUNT 1 + /* * Flags and field values used for the MSG_SEND_DIRECT_REQ/RESP: * BIT(31): Framework or partition message @@ -169,6 +175,12 @@ struct ffa_partition_info_1_1 { }; =20 struct ffa_ctx { + void *rx; + const void *tx; + struct page_info *rx_pg; + struct page_info *tx_pg; + /* Number of 4kB pages in each of rx/rx_pg and tx/tx_pg */ + unsigned int page_count; /* FF-A version used by the guest */ uint32_t guest_vers; /* @@ -176,6 +188,7 @@ struct ffa_ctx { * ffa_domain_teardown() to know which SPs need to be signalled. */ uint16_t create_signal_count; + bool rx_is_free; }; =20 /* Negotiated FF-A version to use with the SPMC */ @@ -371,6 +384,11 @@ static void set_regs(struct cpu_user_regs *regs, regis= ter_t v0, register_t v1, set_user_reg(regs, 7, v7); } =20 +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) { @@ -392,6 +410,106 @@ static void handle_version(struct cpu_user_regs *regs) set_regs(regs, vers, 0, 0, 0, 0, 0, 0, 0); } =20 +static uint32_t handle_rxtx_map(uint32_t fid, register_t tx_addr, + register_t rx_addr, uint32_t page_count) +{ + uint32_t ret =3D FFA_RET_INVALID_PARAMETERS; + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D 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) ) + { + /* + * Calls using the 32-bit calling convention must ignore the upper + * 32 bits in the argument registers. + */ + tx_addr &=3D UINT32_MAX; + rx_addr &=3D UINT32_MAX; + } + + if ( page_count > FFA_MAX_RXTX_PAGE_COUNT ) + { + printk(XENLOG_ERR "ffa: RXTX_MAP: error: %u pages requested (limit= %u)\n", + page_count, FFA_MAX_RXTX_PAGE_COUNT); + return FFA_RET_NOT_SUPPORTED; + } + + /* Already mapped */ + if ( ctx->rx ) + return FFA_RET_DENIED; + + tx_pg =3D get_page_from_gfn(d, gfn_x(gaddr_to_gfn(tx_addr)), &t, P2M_A= LLOC); + if ( !tx_pg ) + return FFA_RET_INVALID_PARAMETERS; + /* Only normal RW RAM for now */ + if ( t !=3D p2m_ram_rw ) + goto err_put_tx_pg; + + rx_pg =3D get_page_from_gfn(d, gfn_x(gaddr_to_gfn(rx_addr)), &t, P2M_A= LLOC); + if ( !tx_pg ) + goto err_put_tx_pg; + /* Only normal RW RAM for now */ + if ( t !=3D p2m_ram_rw ) + goto err_put_rx_pg; + + tx =3D __map_domain_page_global(tx_pg); + if ( !tx ) + goto err_put_rx_pg; + + rx =3D __map_domain_page_global(rx_pg); + if ( !rx ) + goto err_unmap_tx; + + ctx->rx =3D rx; + ctx->tx =3D tx; + ctx->rx_pg =3D rx_pg; + ctx->tx_pg =3D tx_pg; + ctx->page_count =3D page_count; + ctx->rx_is_free =3D 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 =3D NULL; + ctx->tx =3D NULL; + ctx->rx_pg =3D NULL; + ctx->tx_pg =3D NULL; + ctx->page_count =3D 0; + ctx->rx_is_free =3D false; +} + +static uint32_t handle_rxtx_unmap(void) +{ + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D 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 =3D { .a0 =3D fid, }; @@ -448,6 +566,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) uint32_t fid =3D get_user_reg(regs, 0); struct domain *d =3D current->domain; struct ffa_ctx *ctx =3D d->arch.tee; + int e; =20 if ( !ctx ) return false; @@ -460,6 +579,22 @@ 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: + case FFA_RXTX_MAP_64: + e =3D handle_rxtx_map(fid, get_user_reg(regs, 1), get_user_reg(reg= s, 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 =3D 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: case FFA_MSG_SEND_DIRECT_REQ_64: handle_msg_send_direct_req(regs, fid); @@ -551,6 +686,9 @@ static int ffa_domain_teardown(struct domain *d) get_vm_id(d), subscr_vm_destroyed[n], res); } =20 + if ( ctx->rx ) + rxtx_unmap(ctx); + XFREE(d->arch.tee); =20 return 0; --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549998; cv=none; d=zohomail.com; s=zohoarc; b=KK6NOy9HxTikryUw4wvqdqkoOdEFdDLcGTqUcxm5hAZcAHpJP7j2BJceRjb7PRojyJvP5TD45W43KbqRfUFKsMas4qOqxsYzZQrx28deZEcaeRoD4DYoCHI/u7pib+1BVcH3mG/r6o5TkYigS4YTZ6ARXGOl665jN7kioHquPRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549998; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yGDYqeByXV8bSEztmWgee0JK3pFxnI7HN01UFyB4olQ=; b=QutXrzhUaSYGcLBbGRrvwt8LYiMHNVjMVS87ObpdNH70rlNleOj9nUqaDk2Qwt3uRB1IJgjx8y+3YJSSbFGl25UHZspL0YYNkp3zaV0vQyy+ClA792A1jGc1E2j6ew8FdF2HnZges4rzGr8PpFL/AB1PPSUa/7KKwLELIWGJtEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549998431808.477004144325; Wed, 5 Jul 2023 02:39:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558940.873555 (Exim 4.92) (envelope-from ) id 1qGyyu-0007rz-GZ; Wed, 05 Jul 2023 09:39:28 +0000 Received: by outflank-mailman (output) from mailman id 558940.873555; Wed, 05 Jul 2023 09:39:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyyu-0007qk-Bh; Wed, 05 Jul 2023 09:39:28 +0000 Received: by outflank-mailman (input) for mailman id 558940; Wed, 05 Jul 2023 09:39:27 +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 1qGyv8-0005bC-H8 for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:34 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 499a72cb-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:32 +0200 (CEST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b69923a715so99586011fa.0 for ; Wed, 05 Jul 2023 02:35:32 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:31 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 499a72cb-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549732; x=1691141732; 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=yGDYqeByXV8bSEztmWgee0JK3pFxnI7HN01UFyB4olQ=; b=tOrp+EQBc+CiGVQR1hP1s4epr7j8Wmx1XrqFzK7KK9t4o58/DNwO2O0N+fhOyZJte1 tbsJhNLi7cFuTcw7+qecjuUMnFsEfBA5te2SO34oypF8mW6TLefIdzs25Vrl60J3ccpn tZs74jU0i0y/06ofqvOiDEz3H/hXDltZR3gJevNUneA0VA9+oyYaW+vR1OLYoGCdku8B fukcOu7I9CT2HdNMyrTIJKeC4mUQyiQ2GRyES6Xuv8apE7+q2f3V3awtnCjvZHuja3Gu PYFxSoRhgsznb6SH0CVCEfl7AwmMOm0ODT+mNWUPRJQ0IJ7B19sJ/HFJkDOE1/3puuvs F6SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549732; x=1691141732; 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=yGDYqeByXV8bSEztmWgee0JK3pFxnI7HN01UFyB4olQ=; b=beZKmUsqqAoFIJiva8mbaPJMbp96Ek2v/RxHxEIE6xQboJKTcvWe5mnUn9KS728OC/ 2T1xRgH4BTcMQ17wzjLsBLvhnh5/UqkO1v7fVwyJM4xxSO6BVrgfOJrMfMB1BRhddDor YrqHmFsyyW150OCEFX2GTM1J4sLGbXKZ3aWNxDImy+VJpG47Jsco/g85jDOZKs8dC/wr wiCRx1BnO8HeXSX5RqeNTBfv/gNgx+8U0dlXDMQY0M/bs2XYdVmbxWYi8KcFb/mBnMab 5zqZ2SebyT8v98K0Fyen7vRWOJbWL1XK8QiVPRxjWDPVa1fF9ktEFVOLYt0g1zc9jXsk c5pA== X-Gm-Message-State: ABy/qLbyEnYV1hoXmh6SHkUuc977RPEPz209Hv7l/PrMx/5PzLwqpN7G HuzB5RuVs3BaPU9SD7+dk81NVkzEZqzQ+9nNu7U= X-Google-Smtp-Source: APBJJlFd7t5u9T3m922SVShBOkmmhCN2fZdYiMjgI6t5YOpmbnssRvBS/zlV0BbVl93rNHuGlAuXSw== X-Received: by 2002:a2e:9d18:0:b0:2b6:dac0:affe with SMTP id t24-20020a2e9d18000000b002b6dac0affemr9952361lji.31.1688549732190; Wed, 05 Jul 2023 02:35:32 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 14/24] xen/arm: ffa: support guest FFA_PARTITION_INFO_GET Date: Wed, 5 Jul 2023 11:34:23 +0200 Message-Id: <20230705093433.2514898-15-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688550000169100007 Content-Type: text/plain; charset="utf-8" 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 | 131 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index ffabb5ed0a80..d5748b9ce88c 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -166,7 +166,18 @@ #define FFA_MSG_SEND 0x8400006EU #define FFA_MSG_POLL 0x8400006AU =20 +/* + * 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; + uint16_t execution_context; + uint32_t partition_properties; +}; + struct ffa_partition_info_1_1 { uint16_t id; uint16_t execution_context; @@ -189,6 +200,7 @@ struct ffa_ctx { */ uint16_t create_signal_count; bool rx_is_free; + spinlock_t lock; }; =20 /* Negotiated FF-A version to use with the SPMC */ @@ -203,9 +215,15 @@ static uint16_t subscr_vm_destroyed_count __read_mostl= y; /* * Our rx/tx buffers shared with the SPMC. FFA_RXTX_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_loc= k. + * 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 DEFINE_SPINLOCK(ffa_rx_buffer_lock); =20 static bool ffa_get_version(uint32_t *vers) { @@ -510,6 +528,100 @@ static uint32_t handle_rxtx_unmap(void) return FFA_RET_OK; } =20 +static int32_t handle_partition_info_get(uint32_t w1, uint32_t w2, uint32_= t w3, + uint32_t w4, uint32_t w5, + uint32_t *count) +{ + int32_t ret =3D FFA_RET_DENIED; + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D 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 ( w5 =3D=3D FFA_PARTITION_INFO_GET_COUNT_FLAG && + ctx->guest_vers =3D=3D FFA_VERSION_1_1 ) + return ffa_partition_info_get(w1, w2, w3, w4, w5, count); + if ( w5 ) + return FFA_RET_INVALID_PARAMETERS; + + if ( !ffa_rx ) + return FFA_RET_DENIED; + + spin_lock(&ctx->lock); + if ( !ctx->page_count || !ctx->rx_is_free ) + goto out; + spin_lock(&ffa_rx_buffer_lock); + ret =3D ffa_partition_info_get(w1, w2, w3, w4, w5, count); + if ( ret ) + goto out_rx_buf_unlock; + /* + * ffa_partition_info_get() succeeded so we now own the RX buffer we + * share with the SPMC. We must give it back using ffa_rx_release() + * once we've copied the content. + */ + + if ( ctx->guest_vers =3D=3D FFA_VERSION_1_0 ) + { + size_t n; + struct ffa_partition_info_1_1 *src =3D ffa_rx; + struct ffa_partition_info_1_0 *dst =3D ctx->rx; + + if ( ctx->page_count * FFA_PAGE_SIZE < *count * sizeof(*dst) ) + { + ret =3D FFA_RET_NO_MEMORY; + goto out_rx_release; + } + + for ( n =3D 0; n < *count; n++ ) + { + dst[n].id =3D src[n].id; + dst[n].execution_context =3D src[n].execution_context; + dst[n].partition_properties =3D src[n].partition_properties; + } + } + else + { + size_t sz =3D *count * sizeof(struct ffa_partition_info_1_1); + + if ( ctx->page_count * FFA_PAGE_SIZE < sz ) + { + ret =3D FFA_RET_NO_MEMORY; + goto out_rx_release; + } + + + memcpy(ctx->rx, ffa_rx, sz); + } + ctx->rx_is_free =3D false; +out_rx_release: + ffa_rx_release(); +out_rx_buf_unlock: + spin_unlock(&ffa_rx_buffer_lock); +out: + spin_unlock(&ctx->lock); + + return ret; +} + +static int32_t handle_rx_release(void) +{ + int32_t ret =3D FFA_RET_DENIED; + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; + + spin_lock(&ctx->lock); + if ( !ctx->page_count || ctx->rx_is_free ) + goto out; + ret =3D FFA_RET_OK; + ctx->rx_is_free =3D 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 =3D { .a0 =3D fid, }; @@ -566,6 +678,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) uint32_t fid =3D get_user_reg(regs, 0); struct domain *d =3D current->domain; struct ffa_ctx *ctx =3D d->arch.tee; + uint32_t count; int e; =20 if ( !ctx ) @@ -595,6 +708,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 =3D 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 =3D 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: case FFA_MSG_SEND_DIRECT_REQ_64: handle_msg_send_direct_req(regs, fid); --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549997; cv=none; d=zohomail.com; s=zohoarc; b=VrFilessKDhTKbEak6YWhH8U23jOAr+5O8BcbWiNFcmgt1g/0XW7CdQl1oRaD09skgdLAmNzsyp4CR1ZIXQYhno9msH4wNuzcGQO8oCfWo67JYV0SN/lbZlP6y0PTeM1HcmjD8w0cotigO3NFJ/A5BG0mwT5E3DBntTRPL6B/VI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549997; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YcMbvZQAuDfLbcHqMVEHcqz7Bisfyi8R+YRN0ovSOHM=; b=PPCtZkxldQ2V7yr/LIm4wbijutmm2bRka+u4cQcTBL2bT5pykTIX1PkL2q2B6Q9maZRvdAxiz3swV+aDZgB0Txw4V3dDaFToaUxq+CMvssQ6pmzY03MZM0cpiVrmvaQ9kbcy9VljtmyLkJVC6JevRwNJeYEEyIGdFchsjKsnMwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549997783291.16330475776886; Wed, 5 Jul 2023 02:39:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558932.873539 (Exim 4.92) (envelope-from ) id 1qGyyt-0007QY-6D; Wed, 05 Jul 2023 09:39:27 +0000 Received: by outflank-mailman (output) from mailman id 558932.873539; Wed, 05 Jul 2023 09:39:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyyt-0007Og-2F; Wed, 05 Jul 2023 09:39:27 +0000 Received: by outflank-mailman (input) for mailman id 558932; Wed, 05 Jul 2023 09:39:25 +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 1qGyvA-0005bC-HF for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:36 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4a477626-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:34 +0200 (CEST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b6fdaf6eefso9840481fa.0 for ; Wed, 05 Jul 2023 02:35:34 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:32 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4a477626-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549733; x=1691141733; 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=YcMbvZQAuDfLbcHqMVEHcqz7Bisfyi8R+YRN0ovSOHM=; b=pp3m2feVOW0WTQUVdSOeb6fmKUFShrOpu81W4NVgjIS8b5Ty8XCeqWmEjiaq53i0sA AY0mAbR41D74t9Rd/4OnXm7ATqCUoOSDaEWRTbdq7ccaK3U7b6af9RK1dK9zV8VX33Dx +t7fihSUtPcUreGuXAaupJsZN7uIPnAnDonGWuv878TxHvyzG7wzagtxIpy8CZiu8JMA MiuarmJSNxm3wxsgM24VMoBYd5vMT+9GKQzle2tHx3bNWilRu6HVOo6MtJ58V+i+Bufa ++SerX5pwn5aPN3lYev8HKp8u6OToA6AFU/+xA2cOjklelZgWiwMfTSWi6vBcn03LiBd ShFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549733; x=1691141733; 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=YcMbvZQAuDfLbcHqMVEHcqz7Bisfyi8R+YRN0ovSOHM=; b=SkHWtVrfo6ejfm+VkEMNxovF+hUVX9sO5sOflftcKcJYexO6rX/GF2mx2e40eG8bO6 A6d/TWcLn8uO4uUBE88kCeau0RV7ZvL+XYJBUDTBq77BnvKHN2bZOTZfi0UwzY5GKjgd 45h/p1ngFyh6RXDolS7bJRkCEBN0vdrCsGgVbnchR8oO0Ns7DernqEwW+uzTwbgwQeRj I96AReEAdyM90IIf1iIPmcXz3qEZlQI5pfMMz+U77TfnjA1uKL0KrtjHXMYXGwwbCdIc RiGfU0BGTqTfxrXptIKbULYC+kLasdzBwPB0v8tSye6rKPeBtBtLk3fiCivJZeWzdt6T xd6Q== X-Gm-Message-State: ABy/qLZDGkx68ZrQjPdfv6ghRSy+TTLYb5ePp4jquZhDAjo6U90Y1hvf 5YQfV8YlE/CwyGESHhdmTbIhq2Enpf5Y5prSD1Y= X-Google-Smtp-Source: APBJJlE0gVfOljS8MpbdcMy7JQIw9Ok0b7WsJC3Oc+ZkT6BTFzwoZPfyp/XWTUXKtDzygRVPkRvuiw== X-Received: by 2002:a2e:3815:0:b0:2b6:a804:4cc with SMTP id f21-20020a2e3815000000b002b6a80404ccmr10458145lja.53.1688549733391; Wed, 05 Jul 2023 02:35:33 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Bertrand Marquis , Michal Orzel , Henry Wang Subject: [XEN PATCH v9 15/24] xen/arm: move regpair_to_uint64() and uint64_to_regpair() to regs.h Date: Wed, 5 Jul 2023 11:34:24 +0200 Message-Id: <20230705093433.2514898-16-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549998285100003 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Jens Wiklander Reviewed-by: Michal Orzel Reviewed-by: Bertrand Marquis Reviewed-by: Henry Wang --- 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/reg= s.h index ef34b38aa171..8a0db9541507 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 value); =20 +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 =3D val >> 32; + *reg1 =3D (uint32_t)val; +} + #endif =20 #endif /* __ARM_REGS_H__ */ diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c index c91bd7d5ac25..5151bd90ed02 100644 --- a/xen/arch/arm/tee/optee.c +++ b/xen/arch/arm/tee/optee.c @@ -273,17 +273,6 @@ static int optee_domain_teardown(struct domain *d) return 0; } =20 -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 =3D val >> 32; - *reg1 =3D (uint32_t)val; -} - static struct page_info *get_domain_ram_page(gfn_t gfn) { struct page_info *page; --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688550010; cv=none; d=zohomail.com; s=zohoarc; b=UkYuTpRd2LeY0ZAjcKsIZ0kQP/wU6Bn9e47CbqSNGZ4qPHpy2cFJ/QyfWaxwe4+VrCyI+FlB6r8hjjQ7GPlIwYBs+0b7e1EoAg5BC9qQ+w9wHe3xfQv/+JUxcLsdqSiWzOL7Ivcr9TuKki4t8fioy2pNmekEweBkBeG3yGhVW3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688550010; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jd1PqoKu3zNmxIHhUbgtRR0UeglIV+SwdMxJBYTSy/E=; b=WoKhxqUlr8eMl5YNUsCvd0A2CeukATxjtSUbZwt0ZcUFUZgkuNfGE9taJMmG5ZGW9KzDB7aDRWdxZ7nSmkWWMwVckdCZiTzCOeMeab/fzWrzEOSWm0znraHv1SFAjrSUHCgFjzkfcZyvpjo7TOkOPvuxV4TPRpRi2aA583AztLA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688550010320286.02977250213553; Wed, 5 Jul 2023 02:40:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558960.873585 (Exim 4.92) (envelope-from ) id 1qGyz5-0000eM-Mn; Wed, 05 Jul 2023 09:39:39 +0000 Received: by outflank-mailman (output) from mailman id 558960.873585; Wed, 05 Jul 2023 09:39:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyz5-0000eE-Go; Wed, 05 Jul 2023 09:39:39 +0000 Received: by outflank-mailman (input) for mailman id 558960; Wed, 05 Jul 2023 09:39:38 +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 1qGyvC-0005bC-Hh for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:38 +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 4b053be9-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:35 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f954d7309fso661802e87.1 for ; Wed, 05 Jul 2023 02:35:35 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:34 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4b053be9-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549734; x=1691141734; 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=jd1PqoKu3zNmxIHhUbgtRR0UeglIV+SwdMxJBYTSy/E=; b=FyL+sojBuZm/elrnCYhlczxOzQWpPWmPl8isP57HPXDdhoMHYoKUusoO22frV6d+QD XZixMu173FNWtayEXgoA9jb5K1OiB1ATZLF0bC9OIw2mLHZUADpIJpVBHsqREO24PUCq eyKs3uOiTYjEBLe+l3rXkDEIYYM0NbG5owAbwkmCGGuBgyZeLsw1IFIObSSRRzozVizf sZN3c17+6GiGyOTcfmPcHurn0nirO8Pd7tOyw4hjtbTCTjptiMxnSfORdOwSzty/OJ6N xuQLAx2MoA+Tq1TE401VXlZo/3ZX//w2Ln+xp9HWROBF+wR3Q7fMe80WAm6vqYJMi5dQ zttg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549734; x=1691141734; 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=jd1PqoKu3zNmxIHhUbgtRR0UeglIV+SwdMxJBYTSy/E=; b=LqWGZajekorbQXW1+QI4RWPtRENhEn+YTxtF38OVwTGMie15qdBwRsncTMR87Zqn4k 9QyKMi2VAglapMJg8ECBx6kSkQTeBYYtEcPHGQECu1a4hSiV0QfEJIBLYbShDQN3gi4S q0yWMsM4+g3cUeeolm4MtuH8ipvhtfm/nmRWX9Z8tInlKavpyJCNyhFrokFt7dEEPI/2 qCm6HU3L/WyqQxTejOjGgFh5JkbQgj392Tqfc+8dvzF9n3vY9HMB1raYDqs4pIjKNg28 872uzd7bjEbn5m/QQtcuext2eljNGMvVLyEZw07YNMc1gADYpNucU/vu0XKp64Ys05QC K+dA== X-Gm-Message-State: ABy/qLYVi4XtVXmQ6QzexDG0VoeKxJojr8gZtqpfV+bJumUOyoZi0GFN +sCdfHxk/YUWKwzF/DCAySuUlaDzmsSJ5BxLRbM= X-Google-Smtp-Source: APBJJlHPM8fpcFFS2935sU4w8P/nYq1uPlNDlVSDk7rIgrQVGG3GkRebkD2L+5ufvFxZ0cpNyjKWVQ== X-Received: by 2002:a05:6512:1588:b0:4fb:7758:4ec0 with SMTP id bp8-20020a056512158800b004fb77584ec0mr681199lfb.24.1688549734512; Wed, 05 Jul 2023 02:35:34 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 16/24] xen/arm: ffa: add defines for sharing memory Date: Wed, 5 Jul 2023 11:34:25 +0200 Message-Id: <20230705093433.2514898-17-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688550011582100001 Content-Type: text/plain; charset="utf-8" According to DEN0077A version 1.1 REL0 - Section 10.9.2 Memory region handle, page 167 - Table 10.18 at page 175 - Table 10.15 at page 168 - Section 10.11.4 Flags usage, page 184-187 add defines needed for sharing using the function FFA_MEM_SHARE and friends. Also add limits for how many shared buffers that a guest can have at once and how large a shared buffer can be at most. Signed-off-by: Jens Wiklander Reviewed-by: Henry Wang --- xen/arch/arm/tee/ffa.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index d5748b9ce88c..e895e355e620 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -5,6 +5,14 @@ * Arm Firmware Framework for ARMv8-A (FF-A) mediator * * Copyright (C) 2023 Linaro Limited + * + * 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 + * TEEC-1.0C: TEE Client API Specification version 1.0c available at + * https://globalplatform.org/specs-library/tee-client-api-spec= ification/ */ =20 #include @@ -80,6 +88,56 @@ */ #define FFA_MAX_RXTX_PAGE_COUNT 1 =20 +/* + * Limit for shared buffer size. Please note that this define limits + * number of pages. + * + * FF-A doesn't have any direct requirements 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, defined in TEEC-1.0C page 24, Table 4-1, + * TEEC_CONFIG_SHAREDMEM_MAX_SIZE. + * Due to overhead which can be hard to predict exactly, double this number + * to give a safe margin. + */ +#define FFA_MAX_SHM_PAGE_COUNT (2 * SZ_512K / FFA_PAGE_SIZE) + +/* + * Limits the number of shared buffers that guest can have at once. This + * is to prevent case, when guests trick XEN into exhausting its own + * memory by allocating many small buffers. This value has been chosen + * arbitrarily. + */ +#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 + +/* + * Memory attributes: Normal memory, Write-Back cacheable, Inner shareable + * Defined in FF-A-1.1-REL0 Table 10.18 at page 175. + */ +#define FFA_NORMAL_MEM_REG_ATTR 0x2fU +/* + * Memory access permissions: Read-write + * Defined in FF-A-1.1-REL0 Table 10.15 at page 168. + */ +#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) + /* * Flags and field values used for the MSG_SEND_DIRECT_REQ/RESP: * BIT(31): Framework or partition message --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549996; cv=none; d=zohomail.com; s=zohoarc; b=TfXxVOyEJ9DDopYogG7+kbqOUkcsf4D2NkS2Gx7GYS2GCEC9qW+7ckQg1vJT4iAEXdyzf6e4MSU6ytgNTaTEw7TvaFDip++tlxMeXPcTQslJZwvP+G9G3NsaaWrqA7mqUQxI4CZPCLhd0I39FE3Xfv+sZjGY2sCG1/efVYwbFQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549996; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KZBEdfHgu5rAc17OpHgYSz2Q4Zpnm6hWeKYd8pGy/wA=; b=hGU/b1Z3LJ5YV8PFuZi4Xiqcf5DHAFUDiex+w70MRqPV89EG2pNMyJ9E9drbrKRBaWCo53z7njuFPiFch0kpALbI64kbOR4J02Rd24UfiT5a6g2YXTQJCWC2WROnu/Xo+yyHne/C27rT/vBFk5cN4N+RtUcmeTjO/7wEvpkNxXQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549996564130.8545696575028; Wed, 5 Jul 2023 02:39:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558948.873576 (Exim 4.92) (envelope-from ) id 1qGyz3-0000BZ-E0; Wed, 05 Jul 2023 09:39:37 +0000 Received: by outflank-mailman (output) from mailman id 558948.873576; Wed, 05 Jul 2023 09:39:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyz3-0000BK-5s; Wed, 05 Jul 2023 09:39:37 +0000 Received: by outflank-mailman (input) for mailman id 558948; Wed, 05 Jul 2023 09:39:35 +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 1qGyvD-0005bC-Hj for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:39 +0000 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [2a00:1450:4864:20::234]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4baac23b-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:36 +0200 (CEST) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b702319893so1064051fa.3 for ; Wed, 05 Jul 2023 02:35:36 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:35 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4baac23b-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549735; x=1691141735; 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=KZBEdfHgu5rAc17OpHgYSz2Q4Zpnm6hWeKYd8pGy/wA=; b=VapJGscb5IgJCmRF1M/FkdFBn4lJV/Wkqp0/zl1VATS+qXvDKpKe30k0t7lc2LCYbB vyFczcjHjWJWxQOkgtUw6VL+aqtFtkygooYvfGWMcciHT97xzvrojDcgGbYgK1u/f1Lm 2OFG4f7Yc7XgPvN5KhaHenm0q4407tPjWNlRVFQ8A/DLSdIDE8tyPfZ2AZah7a9ppOi3 pr/lK0si+7k2dPCmnLbeieYe0+cew2BJZ3van1ygtmomihprUSVwNni4TUdmnjG9bimr Bh0bISK4kuNhTRNj1ib1yazLnqh4lcrnfJk58CL8bGQDOyp6zDqzpwKub577GUJTqUY6 2utg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549735; x=1691141735; 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=KZBEdfHgu5rAc17OpHgYSz2Q4Zpnm6hWeKYd8pGy/wA=; b=lqAd7ldkCC2MepOu484Z+FUeb/leJWNllN4C0dp1MPGUbjR3KQsMxORQ40ErkN2Vka cTypNJ2izMn8+d/LcvQn/4hfgeXJZY3V5JZN23aZL07Ojx3LLasBcCmuKHEA032rhGws l3XjheIJEEC/C94YbR5msPUd1/IvY75ycIWmqLVZa6wkTiZOI6ns5FCzwJ1FnyapCyQS HZd8SyDX/5htX+Gx5qYo1ccfSFHby1GGBDLT1sHWeclxKMqDPhc/zCQ41ahgi8ulTNo/ wCwbsGLU0SBu9SuWh5/+dW2QNdRSzAI7ak2N+vvkDORbKtCwmatLKC+cjLrsvhiyQLWm 0TOw== X-Gm-Message-State: ABy/qLZWPZm+VwTZMWorFqBDu5dDkF3ccIPMGYLSsIcXKZI2JFRhkWem /KHUOsjSQEY638M88p2RS99XTQ/509uB39fq4yc= X-Google-Smtp-Source: APBJJlGIZZycqhIAKudqt909+uOsbXnjdgh2GxNsB3tbsqwEgJydSgpmRp2nyDDlRcxBsKlRVOFsNw== X-Received: by 2002:a2e:8847:0:b0:2b1:e807:f0f with SMTP id z7-20020a2e8847000000b002b1e8070f0fmr11326365ljj.28.1688549735702; Wed, 05 Jul 2023 02:35:35 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 17/24] xen/arm: ffa: add ABI structs for sharing memory Date: Wed, 5 Jul 2023 11:34:26 +0200 Message-Id: <20230705093433.2514898-18-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549998301100004 Content-Type: text/plain; charset="utf-8" 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 | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index e895e355e620..03699473cfc5 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -243,6 +243,75 @@ struct ffa_partition_info_1_1 { uint8_t uuid[16]; }; =20 +/* 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 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 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; --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549771; cv=none; d=zohomail.com; s=zohoarc; b=WHU9U9JnCVvFQdfYCoCOpuBb7tQVTC5mZtUv177VkgPGZUlfZZqawAOuMocTod0jewemt3bgdBokX5JjW6s2r6FRvhz6Zwm6flr6ZyfWZHK6KWRqeRsGrDNyYaAuaB5V5yC1sLdhLTNyGEHSKpj+UkIG2jwJMc7oXkp4qD8dBVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549771; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EfUxs6oNXk54MzNkpT+pqgSAZUf1sqgLTIg8nTp7P0A=; b=Fj3WW5LcN5hx5gdEron76/0ACLjDAWKXGRFCd4z8b9ZVnlOlYiPoAqBzsFsPTA9fs7ganr46bky/pUiJikk9nXKnxoxQ5WJIE989Ii5F2rSZ8OzmwiBxaQ1sj2Gt/Wi/CT8fDyjRD4kbuS9ZPW6PRf0f52xe0k9JFu6OPJ5YB/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549771718919.9300297929284; Wed, 5 Jul 2023 02:36:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558896.873485 (Exim 4.92) (envelope-from ) id 1qGyvE-0001YW-1o; Wed, 05 Jul 2023 09:35:40 +0000 Received: by outflank-mailman (output) from mailman id 558896.873485; Wed, 05 Jul 2023 09:35:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyvD-0001Y6-RT; Wed, 05 Jul 2023 09:35:39 +0000 Received: by outflank-mailman (input) for mailman id 558896; Wed, 05 Jul 2023 09:35:38 +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 1qGyvC-0006bq-IY for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:38 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4c712355-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:37 +0200 (CEST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b701dee4bfso2132311fa.0 for ; Wed, 05 Jul 2023 02:35:37 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:36 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4c712355-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549737; x=1691141737; 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=EfUxs6oNXk54MzNkpT+pqgSAZUf1sqgLTIg8nTp7P0A=; b=pA6fk+FIoBbWLGluJvHuyyIl3Vv/fJZcabIJwPpBB45JJ6rzomnEVHHm98GRRqVh/L g4qSsRiBLMwo0p4m6D8IEZFRjmXhKnQeaRhQZRjPYxC26Ek+rnaOc7gsBQHmkYcYFEYQ 4ygiXpu1RR8/jr0TwSpu6FVSawzY1AsEtDujhD7uwfcAvGTtMfHup+7ZLDoy7jBAy+Jx MnCZ0uJufgyyAgjtrMJlmOZXpcM5BTwRvDEFLWhErCnxbQSmc3RF3WOefmKH761Ug0oC vUKHVXOV4vAOcAAZ3Yx4c+DYlP22KehrUIdPkSlPaIe32Giczvbd6b8hXrq3a2KTzqAP +mWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549737; x=1691141737; 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=EfUxs6oNXk54MzNkpT+pqgSAZUf1sqgLTIg8nTp7P0A=; b=e8zfruMlqGyS2Sa1jt7jCriyyyqXoG8+BLxmd7YB2V5icTDAzyvR5riRc4lffAwlgF nf/xfHry8ULQXUaLLZnP1pX/CbsoYHrBriMS7QAVUC0M4Np3QLXh5CikkOpU0A8KndWI 9gJAXZWaHtCdHyu9MFwXY0lzQOWTPjNdTdokarw2cz9t2WRCXXj8Ik1aKr1jUCkDinVX svEmNigY5Y9HUPavzzInC2E3d3gVnmWIj1uTeOFSS0k+D10Tw4fEey8ve4tC1gAbzS3g Su0APoMj6ytAjQoNsaC1aq/EiJaZW9mAya7v9okJxC75SKHzxo+KYU2yr3N21z53kh+I gR/g== X-Gm-Message-State: ABy/qLaSTxdCt8n7V/HLJyB8FI03xbzV4O3qC45jneyeQYMh/0+HHOOE HuUq4aJfyOQda8wEbJqPFidnX7+HwWms1B78m2Y= X-Google-Smtp-Source: APBJJlErcrEdNv5Br/S5iZ7lSjiqlWippZXRMWVGTzt9ZxkvuOLqCe3vBZx8UfiC6Yczm+ZTM/ajCA== X-Received: by 2002:a2e:b703:0:b0:2b6:df15:f6c3 with SMTP id j3-20020a2eb703000000b002b6df15f6c3mr8492698ljo.39.1688549736891; Wed, 05 Jul 2023 02:35:36 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 18/24] xen/arm: ffa: support sharing memory Date: Wed, 5 Jul 2023 11:34:27 +0200 Message-Id: <20230705093433.2514898-19-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549773486100001 Content-Type: text/plain; charset="utf-8" Adds support for a guest to share memory with an SP using FFA_MEM_SHARE. Only memory regions small enough to be shared with a single call to FFA_MEM_SHARE are supported. 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 | 486 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 486 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 03699473cfc5..f3eb84a8e9b7 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -297,6 +297,38 @@ struct ffa_mem_transaction_1_1 { uint8_t reserved[12]; }; =20 +/* 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_int { + 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 handle; + uint64_t tag; +}; + /* Endpoint RX/TX descriptor */ struct ffa_endpoint_rxtx_descriptor_1_0 { uint16_t sender_id; @@ -327,9 +359,22 @@ struct ffa_ctx { */ uint16_t create_signal_count; bool rx_is_free; + /* Used shared memory objects, struct ffa_shm_mem */ + struct list_head shm_list; + /* Number of allocated shared memory object */ + unsigned int shm_count; spinlock_t lock; }; =20 +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 __ro_after_init ffa_version; =20 @@ -351,6 +396,7 @@ static uint16_t subscr_vm_destroyed_count __read_mostly; static void *ffa_rx __read_mostly; static void *ffa_tx __read_mostly; static DEFINE_SPINLOCK(ffa_rx_buffer_lock); +static DEFINE_SPINLOCK(ffa_tx_buffer_lock); =20 static bool ffa_get_version(uint32_t *vers) { @@ -457,6 +503,41 @@ static int32_t ffa_rx_release(void) return ffa_simple_call(FFA_RX_RELEASE, 0, 0, 0, 0); } =20 +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 =3D { + .a0 =3D FFA_MEM_SHARE_64, + .a1 =3D tot_len, + .a2 =3D frag_len, + .a3 =3D addr, + .a4 =3D pg_count, + }; + 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: + *handle =3D regpair_to_uint64(resp.a3, resp.a2); + return FFA_RET_OK; + case FFA_MEM_FRAG_RX: + *handle =3D regpair_to_uint64(resp.a2, resp.a1); + if ( resp.a3 > INT32_MAX ) /* Impossible value */ + return FFA_RET_ABORTED; + return resp.a3 & INT32_MAX; + 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) { @@ -800,6 +881,403 @@ out: resp.a4 & mask, resp.a5 & mask, resp.a6 & mask, resp.a7 & mas= k); } =20 +/* + * 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 =3D start_page_idx; + gfn_t gfn; + unsigned int n; + unsigned int m; + p2m_type_t t; + uint64_t addr; + uint64_t page_count; + + for ( n =3D 0; n < range_count; n++ ) + { + page_count =3D read_atomic(&range[n].page_count); + addr =3D read_atomic(&range[n].address); + for ( m =3D 0; m < page_count; m++ ) + { + if ( pg_idx >=3D shm->page_count ) + return FFA_RET_INVALID_PARAMETERS; + + gfn =3D gaddr_to_gfn(addr + m * FFA_PAGE_SIZE); + shm->pages[pg_idx] =3D get_page_from_gfn(d, gfn_x(gfn), &t, + P2M_ALLOC); + if ( !shm->pages[pg_idx] ) + return FFA_RET_DENIED; + /* Only normal RW RAM for now */ + if ( t !=3D p2m_ram_rw ) + return FFA_RET_DENIED; + pg_idx++; + } + } + + *last_page_idx =3D pg_idx; + + return FFA_RET_OK; +} + +static void put_shm_pages(struct ffa_shm_mem *shm) +{ + unsigned int n; + + for ( n =3D 0; n < shm->page_count && shm->pages[n]; n++ ) + { + put_page(shm->pages[n]); + shm->pages[n] =3D 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 >=3D FFA_MAX_SHM_PAGE_COUNT || + ctx->shm_count >=3D FFA_MAX_SHM_COUNT ) + return NULL; + + shm =3D xzalloc_flex_struct(struct ffa_shm_mem, pages, page_count); + if ( shm ) + { + ctx->shm_count++; + shm->page_count =3D page_count; + } + + return shm; +} + +static void free_ffa_shm_mem(struct ffa_ctx *ctx, struct ffa_shm_mem *shm) +{ + if ( !shm ) + return; + + 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 =3D pa; + addr_range->page_count =3D 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 =3D FFA_RXTX_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 =3D 1; + void *buf =3D 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)); + ASSERT(shm->page_count); + + descr =3D buf; + memset(descr, 0, sizeof(*descr)); + descr->sender_id =3D shm->sender_id; + descr->handle =3D shm->handle; + descr->mem_reg_attr =3D FFA_NORMAL_MEM_REG_ATTR; + descr->mem_access_count =3D 1; + descr->mem_access_size =3D sizeof(*mem_access_array); + descr->mem_access_offs =3D MEM_ACCESS_OFFSET(0); + + mem_access_array =3D buf + descr->mem_access_offs; + memset(mem_access_array, 0, sizeof(*mem_access_array)); + mem_access_array[0].access_perm.endpoint_id =3D shm->ep_id; + mem_access_array[0].access_perm.perm =3D FFA_MEM_ACC_RW; + mem_access_array[0].region_offs =3D REGION_OFFSET(descr->mem_access_co= unt, 0); + + region_descr =3D buf + mem_access_array[0].region_offs; + memset(region_descr, 0, sizeof(*region_descr)); + region_descr->total_page_count =3D shm->page_count; + + region_descr->address_range_count =3D 1; + last_pa =3D page_to_maddr(shm->pages[0]); + for ( n =3D 1; n < shm->page_count; last_pa =3D pa, n++ ) + { + pa =3D page_to_maddr(shm->pages[n]); + if ( last_pa + FFA_PAGE_SIZE =3D=3D pa ) + continue; + region_descr->address_range_count++; + } + + tot_len =3D 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 =3D region_descr->address_range_array; + frag_len =3D ADDR_RANGE_OFFSET(descr->mem_access_count, region_count, = 1); + last_pa =3D page_to_maddr(shm->pages[0]); + init_range(addr_range, last_pa); + for ( n =3D 1; n < shm->page_count; last_pa =3D pa, n++ ) + { + pa =3D page_to_maddr(shm->pages[n]); + if ( last_pa + FFA_PAGE_SIZE =3D=3D pa ) + { + addr_range->page_count++; + continue; + } + + frag_len +=3D 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_int *trans) +{ + uint16_t mem_reg_attr; + uint32_t flags; + uint32_t count; + uint32_t offs; + uint32_t size; + + if ( ffa_vers >=3D FFA_VERSION_1_1 ) + { + const struct ffa_mem_transaction_1_1 *descr; + + if ( blen < sizeof(*descr) ) + return FFA_RET_INVALID_PARAMETERS; + + descr =3D buf; + trans->sender_id =3D descr->sender_id; + mem_reg_attr =3D descr->mem_reg_attr; + flags =3D descr->flags; + trans->handle =3D descr->handle; + trans->tag =3D descr->tag; + + count =3D descr->mem_access_count; + size =3D descr->mem_access_size; + offs =3D descr->mem_access_offs; + } + else + { + const struct ffa_mem_transaction_1_0 *descr; + + if ( blen < sizeof(*descr) ) + return FFA_RET_INVALID_PARAMETERS; + + descr =3D buf; + trans->sender_id =3D descr->sender_id; + mem_reg_attr =3D descr->mem_reg_attr; + flags =3D descr->flags; + trans->handle =3D descr->handle; + trans->tag =3D descr->tag; + + count =3D descr->mem_access_count; + size =3D sizeof(struct ffa_mem_access); + offs =3D 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_int below. + * The fields in struct ffa_mem_transaction_int 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 =3D mem_reg_attr; + trans->flags =3D flags; + trans->mem_access_size =3D size; + trans->mem_access_count =3D count; + trans->mem_access_offs =3D offs; + + return 0; +} + +static void handle_mem_share(struct cpu_user_regs *regs) +{ + uint32_t tot_len =3D get_user_reg(regs, 1); + uint32_t frag_len =3D get_user_reg(regs, 2); + uint64_t addr =3D get_user_reg(regs, 3); + uint32_t page_count =3D get_user_reg(regs, 4); + const struct ffa_mem_region *region_descr; + const struct ffa_mem_access *mem_access; + struct ffa_mem_transaction_int trans; + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; + struct ffa_shm_mem *shm =3D NULL; + unsigned int last_page_idx =3D 0; + register_t handle_hi =3D 0; + register_t handle_lo =3D 0; + int ret =3D 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 =3D FFA_RET_NOT_SUPPORTED; + goto out_set_ret; + } + + /* Check that fragment length doesn't exceed total length */ + if ( frag_len > tot_len ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_set_ret; + } + + /* We currently only support a single fragment */ + if ( frag_len !=3D tot_len ) + { + ret =3D FFA_RET_NOT_SUPPORTED; + goto out_set_ret; + } + + spin_lock(&ctx->lock); + + if ( frag_len > ctx->page_count * FFA_PAGE_SIZE ) + goto out_unlock; + + ret =3D read_mem_transaction(ctx->guest_vers, ctx->tx, frag_len, &tran= s); + if ( ret ) + goto out_unlock; + + if ( trans.mem_reg_attr !=3D FFA_NORMAL_MEM_REG_ATTR ) + { + ret =3D FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + /* Only supports sharing it with one SP for now */ + if ( trans.mem_access_count !=3D 1 ) + { + ret =3D FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + if ( trans.sender_id !=3D get_vm_id(d) ) + { + ret =3D 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 =3D ctx->tx + trans.mem_access_offs; + if ( read_atomic(&mem_access->access_perm.perm) !=3D FFA_MEM_ACC_RW ) + { + ret =3D FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + region_offs =3D read_atomic(&mem_access->region_offs); + if ( sizeof(*region_descr) + region_offs > frag_len ) + { + ret =3D FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + + region_descr =3D ctx->tx + region_offs; + range_count =3D read_atomic(®ion_descr->address_range_count); + page_count =3D read_atomic(®ion_descr->total_page_count); + + if ( !page_count ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_unlock; + } + + shm =3D alloc_ffa_shm_mem(ctx, page_count); + if ( !shm ) + { + ret =3D FFA_RET_NO_MEMORY; + goto out_unlock; + } + shm->sender_id =3D trans.sender_id; + shm->ep_id =3D 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 =3D FFA_RET_INVALID_PARAMETERS; + goto out; + } + + ret =3D get_shm_pages(d, shm, region_descr->address_range_array, range= _count, + 0, &last_page_idx); + if ( ret ) + goto out; + if ( last_page_idx !=3D shm->page_count ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out; + } + + /* Note that share_shm() uses our tx buffer */ + spin_lock(&ffa_tx_buffer_lock); + ret =3D 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 =3D=3D 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 =3D get_user_reg(regs, 0); @@ -857,6 +1335,10 @@ static bool ffa_handle_call(struct cpu_user_regs *reg= s) case FFA_MSG_SEND_DIRECT_REQ_64: handle_msg_send_direct_req(regs, fid); return true; + case FFA_MEM_SHARE_32: + case FFA_MEM_SHARE_64: + handle_mem_share(regs); + return true; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -898,6 +1380,8 @@ static int ffa_domain_init(struct domain *d) } ctx->create_signal_count =3D n; =20 + INIT_LIST_HEAD(&ctx->shm_list); + return 0; } =20 @@ -1086,7 +1570,9 @@ static bool ffa_probe(void) if ( !check_mandatory_feature(FFA_PARTITION_INFO_GET) || !check_mandatory_feature(FFA_RX_RELEASE) || !check_mandatory_feature(FFA_RXTX_MAP_64) || + !check_mandatory_feature(FFA_MEM_SHARE_64) || !check_mandatory_feature(FFA_RXTX_UNMAP) || + !check_mandatory_feature(FFA_MEM_SHARE_32) || !check_mandatory_feature(FFA_MSG_SEND_DIRECT_REQ_32) ) return false; =20 --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549772; cv=none; d=zohomail.com; s=zohoarc; b=kV9WaeCO8ci21Q3gYnLVqA+5r0nljOQEFMr1v8UhmAWxaC6C1t6d9kE5onV+WuGAjdWgnmKPYhp8DCebApcwt1f1Ze0AHSlOJyV8RjtM/2isY89mq2AJKfgmlnh8Lj/wj3pF8LtlQnEaHrhU3uDiKA8GRUYNAfK4M2oxeMf9Y8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549772; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sWua/aGnhgeAUqYKtQ1Lf4Q/vc2pnAQzQP1lQqZFLOs=; b=WAFjeqJfH3VPmA6tlNK10ylMZYVW+LXKImG4HwhgemtjYl7+GB+gIUd5W1UIte1Did2YE/x0obS5Q7LKrMmWGxK3vsNmSJHGPVPnTkGe/SsOh5Xk+I6WmYb88dK0NE5LFPq+6SueCuz1j5AU/wKL22ArV+1VhfyKXZjwKGoevhE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549772619620.612469639165; Wed, 5 Jul 2023 02:36:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558897.873490 (Exim 4.92) (envelope-from ) id 1qGyvE-0001hk-QR; Wed, 05 Jul 2023 09:35:40 +0000 Received: by outflank-mailman (output) from mailman id 558897.873490; Wed, 05 Jul 2023 09:35:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyvE-0001fe-CA; Wed, 05 Jul 2023 09:35:40 +0000 Received: by outflank-mailman (input) for mailman id 558897; Wed, 05 Jul 2023 09:35:39 +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 1qGyvD-0006bq-IQ for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:39 +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 4d117840-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:38 +0200 (CEST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b63e5f94f1so6622001fa.1 for ; Wed, 05 Jul 2023 02:35:38 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:37 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4d117840-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549738; x=1691141738; 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=sWua/aGnhgeAUqYKtQ1Lf4Q/vc2pnAQzQP1lQqZFLOs=; b=t2lANbONfVCUPmioMdbT5ugJNIAtFeNHJLUO0BudbmZENdOHcp6cnWKOZNcWSPSe44 FyH6gNeEgGbD5gYkrf282Wg5SQ5hNOMS7IkqvNPTKzitGaF1FnFzBik7MwpbCDVMWTkm mt04bNyxh3zxd6HrUNl1iLEAsu71tPIseuxgrVU+6rDKUjgZNiRAP+HO25O1IMGiCmrC PsRFLeqQrfOc+4DGK1AuRDHqPLhHSaN+gT8z77/HTSEJAH8ZGIWkcIhKDGYz+MNzw+My Sj5Ms0hiSkVmlG3wdoToYh/vGgHh/0xZe22M9yMH1r1Mzz2APH2IfI+v0ctxQUcW0ym5 Sigg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549738; x=1691141738; 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=sWua/aGnhgeAUqYKtQ1Lf4Q/vc2pnAQzQP1lQqZFLOs=; b=hlO8TwgEOjX7giNOouqHY1KEq6rJlAuy+ZKAC2a6jCUN9mlADzFD0WQRfu8uZIzlp1 08Fk85+BN3vRcvyGi+t7oWmJiUK6tmyTZVDhY7wr2FZDgDg3eJyILwvqFaO/BRRdBrC2 7N52+qP3+7YsQgCLfhfjbOU13waoHKj/q0NaOGkY7Aq5MFWdQ7GxaBfYxNbDpi4eN3mL s+MZdz+0NW1EwJK9Rji3qcLUd91P5r5VjZeh2e1XiB+1lyNIkgmA2/XYu+JT3qynhyuF IpIDFNqaX+mLhI1QcGzKghLiwPCeehmvXEiPP7UIIFRn5/Wub6RKfzSL/bxE8IGjK0DY auXw== X-Gm-Message-State: ABy/qLb+8S6ntcrih1XzZ/S6kfWGLmDcx66eeCmFSd47OwbDtlSflKdh CBdf8TY9FaYmEMn+K5CzlxeaxlYigR9U7/IJTZ8= X-Google-Smtp-Source: APBJJlGIsl0hv181Iy7TeYWQi9ltmrfQxnPlGaqu1gvAxtnhqtpqsv2Zkq7ZEC1I47eH29T1HbLyXA== X-Received: by 2002:a2e:3c04:0:b0:2b6:b849:c893 with SMTP id j4-20020a2e3c04000000b002b6b849c893mr578326lja.26.1688549738005; Wed, 05 Jul 2023 02:35:38 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 19/24] xen/arm: ffa: add support to reclaim shared memory Date: Wed, 5 Jul 2023 11:34:28 +0200 Message-Id: <20230705093433.2514898-20-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549774719100003 Content-Type: text/plain; charset="utf-8" Adds support to reclaim memory previously shared with FFA_MEM_SHARE. 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. 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 f3eb84a8e9b7..c623c51168b9 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -538,6 +538,12 @@ static int32_t ffa_mem_share(uint32_t tot_len, uint32_= t frag_len, } } =20 +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) { @@ -1278,6 +1284,43 @@ out_set_ret: set_regs_error(regs, ret); } =20 +static int handle_mem_reclaim(uint64_t handle, uint32_t flags) +{ + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D 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 =3D=3D handle ) + goto found_it; + } + shm =3D NULL; + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out; +found_it: + + uint64_to_regpair(&handle_hi, &handle_lo, handle); + ret =3D ffa_mem_reclaim(handle_lo, handle_hi, flags); + if ( ret ) + { + shm =3D 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 =3D get_user_reg(regs, 0); @@ -1339,6 +1382,15 @@ static bool ffa_handle_call(struct cpu_user_regs *re= gs) case FFA_MEM_SHARE_64: handle_mem_share(regs); return true; + case FFA_MEM_RECLAIM: + e =3D 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; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -1573,6 +1625,7 @@ static bool ffa_probe(void) !check_mandatory_feature(FFA_MEM_SHARE_64) || !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; =20 --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549765; cv=none; d=zohomail.com; s=zohoarc; b=Z9koXR8+4g7XmShwHoNQsiwwv19Q/CHXOehvwBonzLnNDG9vCfDHtY/fq4SBAUdCN22uwfJFF8tPKIwRFjcV8shvYhlQQsBTWYEOB0HoP6nr1b2JJ/SperDz8GldVFEM/32l4JhJBkRaB6d2cvnWJWmIh6M9sZLBnlGXVgwHrT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549765; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aYbk+SQ1clAFmK5go+uqkAk7DJv+x5ZhyiBn1d+JtnA=; b=oKCGiwZEyiyp9dd9O0KsQTwVf9yHXh7LsWvHC8VUFCxCk23M/Am7yujjOkeImFpt2IYWiJRgVMEIOSRMEgqNBdOTdojAjqxeH6JjZ1EANHMFdzuU88S/Q9yrNS0DaqMg4ye/O6qvFqaqj4+Qd4/Wu8mJ9cCn9+ck+RVJ+JPNIkU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549765041785.4499377709495; Wed, 5 Jul 2023 02:36:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558898.873500 (Exim 4.92) (envelope-from ) id 1qGyvG-0002J0-Pv; Wed, 05 Jul 2023 09:35:42 +0000 Received: by outflank-mailman (output) from mailman id 558898.873500; Wed, 05 Jul 2023 09:35:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyvG-0002GF-Cc; Wed, 05 Jul 2023 09:35:42 +0000 Received: by outflank-mailman (input) for mailman id 558898; Wed, 05 Jul 2023 09:35:41 +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 1qGyvE-0006bq-KV for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:40 +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 4dc097f4-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:39 +0200 (CEST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fb73ba3b5dso10463065e87.1 for ; Wed, 05 Jul 2023 02:35:39 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:38 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4dc097f4-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549739; x=1691141739; 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=aYbk+SQ1clAFmK5go+uqkAk7DJv+x5ZhyiBn1d+JtnA=; b=RYuKrG+nyp98x2XlR4g1pqGU6cthc/eD2x5DpsJORp1UZ4nEIW8PHICrRlP2vFM4nX t6tVw4TQseuueu2mcA/Ngy0bkB6nPJY1sHXrAKxNGrX6w5A3y3Adigd1rWlESmb1OTGr DhBa8eBoSJKIW7Q0WVBCrHFLrqXUVZG/bt8t3X1rxdGn9jswUa+B9O7LcAPQAo0VO797 6C1nb+sMFIzkHTyzv78LqyNkRhzUB7ap8UHSBwchTLQUKyZCUx2i7jN7zInJlHUk8TaP 6o0Jian0GRFem6itEKUG9cRtW2JYMVSV/GLBbFfPdlplxdERyZq6w7Tmb/dXdZmtHlOA B3PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549739; x=1691141739; 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=aYbk+SQ1clAFmK5go+uqkAk7DJv+x5ZhyiBn1d+JtnA=; b=crE1OOkPxeuUHUOoxoIFJ3C68/NRLzQFN7RVwi34cRZ/utc3RC2s2aJAzJe5Ek/age VhsvlKo4PuDCPViUMKmEhLBR8dlWm2AOsQdHCu/9n32aDPn5eTQyfCGhpxDAS15bETbG PKa+nodOXRi1qGat12hl6mrCj0JuTrosp1NvI1jZiA1juRiMcAd9aULil2PmWTdEMAVr U0r03IurlNUHDQuYkJEd+w6c9Ebbtf6OBnTKwedBGBhpKAGVZESz+EcrkR2pUTTOpzNf ICSi+msYSaV8q5FyrRllXH25Bwc+5J9OcCnYSalrf4gUc/Wvyk6y40fmxNDhj5S/bzk3 fFFg== X-Gm-Message-State: ABy/qLbrkr2gLNJHnllNJo9TiHAmUOr9nztiRU+UYlJCKHgnXPKTdvZE nlZK/MPchiRvoDtASYccnrI9JCY9paC2f6nzeNA= X-Google-Smtp-Source: APBJJlFEsmI9XieucKFevLoCAa5Lqvq6pcooF4RgPlcFUBGQuDcdyXtmjQu7OcvFUzrfWZsUidy+BQ== X-Received: by 2002:a2e:3611:0:b0:2b6:fa8d:ff91 with SMTP id d17-20020a2e3611000000b002b6fa8dff91mr2738414lja.3.1688549739097; Wed, 05 Jul 2023 02:35:39 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 20/24] xen/arm: ffa: support sharing large memory ranges Date: Wed, 5 Jul 2023 11:34:29 +0200 Message-Id: <20230705093433.2514898-21-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549766319100008 Content-Type: text/plain; charset="utf-8" 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 | 253 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 240 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index c623c51168b9..ac23b9edc74c 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -359,6 +359,8 @@ struct ffa_ctx { */ uint16_t create_signal_count; bool rx_is_free; + /* Currently used fragment states, struct mem_frag_state */ + struct list_head frag_list; /* Used shared memory objects, struct ffa_shm_mem */ struct list_head shm_list; /* Number of allocated shared memory object */ @@ -375,6 +377,18 @@ struct ffa_shm_mem { struct page_info *pages[]; }; =20 +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 __ro_after_init ffa_version; =20 @@ -538,6 +552,36 @@ static int32_t ffa_mem_share(uint32_t tot_len, uint32_= t frag_len, } } =20 +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 =3D { + .a0 =3D FFA_MEM_FRAG_TX, + .a1 =3D handle & UINT32_MAX, + .a2 =3D handle >> 32, + .a3 =3D frag_len, + .a4 =3D (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) { @@ -627,6 +671,14 @@ static void set_regs_success(struct cpu_user_regs *reg= s, uint32_t w2, set_regs(regs, FFA_SUCCESS_32, 0, w2, w3, 0, 0, 0, 0); } =20 +static void set_regs_frag_rx(struct cpu_user_regs *regs, uint32_t handle_l= o, + 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 =3D current->domain; @@ -999,6 +1051,8 @@ static int share_shm(struct ffa_shm_mem *shm) paddr_t last_pa; unsigned int n; paddr_t pa; + bool first; + int ret; =20 ASSERT(spin_is_locked(&ffa_tx_buffer_lock)); ASSERT(shm->page_count); @@ -1034,13 +1088,23 @@ static int share_shm(struct ffa_shm_mem *shm) =20 tot_len =3D 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; =20 + /* + * 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 =3D region_descr->address_range_array; frag_len =3D ADDR_RANGE_OFFSET(descr->mem_access_count, region_count, = 1); last_pa =3D page_to_maddr(shm->pages[0]); init_range(addr_range, last_pa); + first =3D true; for ( n =3D 1; n < shm->page_count; last_pa =3D pa, n++ ) { pa =3D page_to_maddr(shm->pages[n]); @@ -1050,12 +1114,34 @@ static int share_shm(struct ffa_shm_mem *shm) continue; } =20 - frag_len +=3D sizeof(*addr_range); - addr_range++; + if ( frag_len =3D=3D max_frag_len ) + { + if ( first ) + { + ret =3D ffa_mem_share(tot_len, frag_len, 0, 0, &shm->handl= e); + first =3D false; + } + else + { + ret =3D ffa_mem_frag_tx(shm->handle, frag_len, shm->sender= _id); + } + if ( ret <=3D 0 ) + return ret; + frag_len =3D sizeof(*addr_range); + addr_range =3D buf; + } + else + { + frag_len +=3D sizeof(*addr_range); + addr_range++; + } init_range(addr_range, pa); } =20 - 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); } =20 static int read_mem_transaction(uint32_t ffa_vers, const void *buf, size_t= blen, @@ -1132,8 +1218,53 @@ static int read_mem_transaction(uint32_t ffa_vers, c= onst void *buf, size_t blen, return 0; } =20 +static int add_mem_share_frag(struct mem_frag_state *s, unsigned int offs, + unsigned int frag_len) +{ + struct domain *d =3D current->domain; + unsigned int o =3D offs; + unsigned int l; + int ret; + + if ( frag_len < o ) + return FFA_RET_INVALID_PARAMETERS; + + /* Fill up the first struct ffa_address_range */ + l =3D min_t(unsigned int, frag_len - o, sizeof(s->range) - s->range_of= fset); + memcpy((uint8_t *)&s->range + s->range_offset, s->buf + o, l); + s->range_offset +=3D l; + o +=3D l; + if ( s->range_offset !=3D sizeof(s->range) ) + goto out; + s->range_offset =3D 0; + + while ( true ) + { + ret =3D 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 =3D=3D 1 ) + return 0; + s->range_count--; + if ( frag_len - o < sizeof(s->range) ) + break; + memcpy(&s->range, s->buf + o, sizeof(s->range)); + o +=3D sizeof(s->range); + } + + /* Collect any remaining bytes for the next struct ffa_address_range */ + s->range_offset =3D frag_len - o; + memcpy(&s->range, s->buf + o, frag_len - o); +out: + s->frag_offset +=3D frag_len; + + return s->frag_offset; +} + static void handle_mem_share(struct cpu_user_regs *regs) { + static uint64_t next_handle =3D FFA_HANDLE_HYP_FLAG; uint32_t tot_len =3D get_user_reg(regs, 1); uint32_t frag_len =3D get_user_reg(regs, 2); uint64_t addr =3D get_user_reg(regs, 3); @@ -1168,13 +1299,6 @@ static void handle_mem_share(struct cpu_user_regs *r= egs) goto out_set_ret; } =20 - /* We currently only support a single fragment */ - if ( frag_len !=3D tot_len ) - { - ret =3D FFA_RET_NOT_SUPPORTED; - goto out_set_ret; - } - spin_lock(&ctx->lock); =20 if ( frag_len > ctx->page_count * FFA_PAGE_SIZE ) @@ -1240,6 +1364,36 @@ static void handle_mem_share(struct cpu_user_regs *r= egs) shm->sender_id =3D trans.sender_id; shm->ep_id =3D read_atomic(&mem_access->access_perm.endpoint_id); =20 + if ( frag_len !=3D tot_len ) + { + struct mem_frag_state *s =3D xzalloc(struct mem_frag_state); + + if ( !s ) + { + ret =3D FFA_RET_NO_MEMORY; + goto out; + } + s->shm =3D shm; + s->range_count =3D range_count; + s->buf =3D ctx->tx; + s->buf_size =3D FFA_RXTX_PAGE_COUNT * FFA_PAGE_SIZE; + ret =3D add_mem_share_frag(s, sizeof(*region_descr) + region_offs, + frag_len); + if ( ret <=3D 0 ) + { + xfree(s); + if ( ret < 0 ) + goto out; + } + else + { + shm->handle =3D 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. */ @@ -1278,7 +1432,75 @@ out_unlock: spin_unlock(&ctx->lock); =20 out_set_ret: - if ( ret =3D=3D 0) + if ( ret > 0 ) + set_regs_frag_rx(regs, handle_lo, handle_hi, ret, trans.sender= _id); + else if ( ret =3D=3D 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 =3D=3D handle ) + return s; + + return NULL; +} + +static void handle_mem_frag_tx(struct cpu_user_regs *regs) +{ + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; + uint32_t frag_len =3D get_user_reg(regs, 3); + uint32_t handle_lo =3D get_user_reg(regs, 1); + uint32_t handle_hi =3D get_user_reg(regs, 2); + uint64_t handle =3D regpair_to_uint64(handle_hi, handle_lo); + struct mem_frag_state *s; + uint16_t sender_id =3D 0; + int ret; + + spin_lock(&ctx->lock); + s =3D find_frag_state(ctx, handle); + if ( !s ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out; + } + sender_id =3D s->shm->sender_id; + + if ( frag_len > s->buf_size ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_free_s; + } + + ret =3D add_mem_share_frag(s, 0, frag_len); + if ( ret < 0 ) + goto out_free_s; + + /* Note that share_shm() uses our tx buffer */ + spin_lock(&ffa_tx_buffer_lock); + ret =3D share_shm(s->shm); + spin_unlock(&ffa_tx_buffer_lock); + if ( ret < 0 ) + goto out_free_s; + list_add_tail(&s->shm->list, &ctx->shm_list); +out_free_s: + 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 =3D=3D 0) set_regs_success(regs, handle_lo, handle_hi); else set_regs_error(regs, ret); @@ -1391,6 +1613,9 @@ static bool ffa_handle_call(struct cpu_user_regs *reg= s) else set_regs_success(regs, 0, 0); return true; + case FFA_MEM_FRAG_TX: + handle_mem_frag_tx(regs); + return true; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -1432,6 +1657,7 @@ static int ffa_domain_init(struct domain *d) } ctx->create_signal_count =3D n; =20 + INIT_LIST_HEAD(&ctx->frag_list); INIT_LIST_HEAD(&ctx->shm_list); =20 return 0; @@ -1625,6 +1851,7 @@ static bool ffa_probe(void) !check_mandatory_feature(FFA_MEM_SHARE_64) || !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; --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549779; cv=none; d=zohomail.com; s=zohoarc; b=B/Q8Gh8qoAez67E8gJdGG3DySYVpwkgQfeRmJfYke7ESFfvMxNYOj7rrcNuDQWu5np7qlCHP4IJ+QBE90DjwYT7wSeC1s/ucal0AxFWUExI4Rv23fie+MmcDnjE8JZVXgz+KR5n7aqTyjeXBF87W4kGMnrytab4kdKMtunIExzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549779; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZoIi1uajGrKh0qyhlJNpu9qRdkH7y35FjQEkn4RminE=; b=mdV5lGiK+JcuA/XlKvWPLZIny1NHt2Q9B84goikmrUAL8osaTK7CHvNdD5eCiKUnq5EzpKm40+G0FhDycAt3XZR3Bkk2nCP/MH2adq81raVvciHF2bJM3aH2VTMoy7hgbXK4Jn7tPg/9DIc6D+xUKcsa7URGwrZ016RxkwPI260= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549779911934.5422973307809; Wed, 5 Jul 2023 02:36:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558899.873506 (Exim 4.92) (envelope-from ) id 1qGyvH-0002TW-SW; Wed, 05 Jul 2023 09:35:43 +0000 Received: by outflank-mailman (output) from mailman id 558899.873506; Wed, 05 Jul 2023 09:35:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyvH-0002Qc-3c; Wed, 05 Jul 2023 09:35:43 +0000 Received: by outflank-mailman (input) for mailman id 558899; Wed, 05 Jul 2023 09:35:41 +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 1qGyvF-0006bq-J3 for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:41 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4e5c5d9d-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:40 +0200 (CEST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b6994a8ce3so96190141fa.1 for ; Wed, 05 Jul 2023 02:35:40 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:39 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4e5c5d9d-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549740; x=1691141740; 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=ZoIi1uajGrKh0qyhlJNpu9qRdkH7y35FjQEkn4RminE=; b=uk1lwxt6nIGp645jtDaH3HmxmOBSm6likMtc1qTznUd3+eCEWs2IiLXL8AaANOMH1q sQDspJWiZkwKf5xXk0+oaVksGgF6SVkEKO5pLByJYBXV/IAACw9xwqs9ZE8zEknUYjeO gEedd+1pxj41Nx3AkKffU7xE9TCp9zypoqZmqlINOWUCSyLDPh0cFG3UxNTOQugFzweW ikBv3QL0XGjgU76FNiBHaN9v4RJyohlmQgQ0LlfXeGir8Wqir2zNHE9kuJJPumM9TC9c u2Cqpq7O4kr3xSGPDHSE/LagDto8+EmLcT1No2OiyNZyG+cWQE02fMxblBVQYDvOoS1M Z8zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549740; x=1691141740; 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=ZoIi1uajGrKh0qyhlJNpu9qRdkH7y35FjQEkn4RminE=; b=C+yJIWjTWkLuoy68AppDP945uRDrMYWYsd7RCbMTW2U+GeJ52PnKQzME9CowA+xLQa vdO7Qir2VRdBzJ79XSy0v9FZTF2Ci3mQGrqSeslr8CJO1wPlLZvDb5ABJTeOScdJJzCq kUlgKsNnyCLCinE2fU114FPg4x6qmuevMZ6zyCUyOuRDrIyMZRSbg518ZJ0KGCBW50M0 APXO884EeMlnULfZ2Pxj87iY4T1AgQ6+jU8QQdUBzkcKpob46TegJgw/TPGu343sO0v+ TK3hrA2loNhDnYD2/qubY0INMvEgOjx2BT9qnJPjW4qDT/524xPSNZ+bnSHOA0odCQy2 AVsg== X-Gm-Message-State: ABy/qLb5ByFebXdp7kfsoxEwXdeLLCFwj5JA4XpqjDX/ACZm8n5yt1ht w3JLNZYsM2bIKauN7pAY49brYpBF2LhCzhqtZDo= X-Google-Smtp-Source: APBJJlFV3xIQWTSoKCG2Vg3YpY+nX20MmYIbkU/GnXObWSaerREItuD3NzagU7HoZXkbPi6yhntIQw== X-Received: by 2002:a2e:9b92:0:b0:2b1:d588:a1a5 with SMTP id z18-20020a2e9b92000000b002b1d588a1a5mr10752483lji.52.1688549740175; Wed, 05 Jul 2023 02:35:40 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH v9 21/24] xen/arm: ffa: improve lock granularity Date: Wed, 5 Jul 2023 11:34:30 +0200 Message-Id: <20230705093433.2514898-22-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549780535100001 Content-Type: text/plain; charset="utf-8" The single lock in struct ffa_ctx is complemented with rx_lock and tx_lock. The old lock is used for small critical sections, like increasing shm_count or adding another shm to shm_list. rx_lock and tx_lock are only acquired using spin_trylock() which for well-behaving guests should always succeed. Guests using the RX and TX buffers are expected to serialize accesses before doing the FF-A request. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/ffa.c | 121 ++++++++++++++++++++++++++++++----------- 1 file changed, 89 insertions(+), 32 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index ac23b9edc74c..59832f73c2be 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -365,6 +365,13 @@ struct ffa_ctx { struct list_head shm_list; /* Number of allocated shared memory object */ unsigned int shm_count; + /* + * tx_lock is used to serialize access to tx + * rx_lock is used to serialize access to rx + * lock is used for the rest in this struct + */ + spinlock_t tx_lock; + spinlock_t rx_lock; spinlock_t lock; }; =20 @@ -815,7 +822,9 @@ static int32_t handle_partition_info_get(uint32_t w1, u= int32_t w2, uint32_t w3, if ( !ffa_rx ) return FFA_RET_DENIED; =20 - spin_lock(&ctx->lock); + if ( !spin_trylock(&ctx->rx_lock) ) + return FFA_RET_BUSY; + if ( !ctx->page_count || !ctx->rx_is_free ) goto out; spin_lock(&ffa_rx_buffer_lock); @@ -866,7 +875,7 @@ out_rx_release: out_rx_buf_unlock: spin_unlock(&ffa_rx_buffer_lock); out: - spin_unlock(&ctx->lock); + spin_unlock(&ctx->rx_lock); =20 return ret; } @@ -877,13 +886,15 @@ static int32_t handle_rx_release(void) struct domain *d =3D current->domain; struct ffa_ctx *ctx =3D d->arch.tee; =20 - spin_lock(&ctx->lock); + if ( !spin_trylock(&ctx->rx_lock) ) + return FFA_RET_BUSY; + if ( !ctx->page_count || ctx->rx_is_free ) goto out; ret =3D FFA_RET_OK; ctx->rx_is_free =3D true; out: - spin_unlock(&ctx->lock); + spin_unlock(&ctx->rx_lock); =20 return ret; } @@ -994,21 +1005,43 @@ static void put_shm_pages(struct ffa_shm_mem *shm) } } =20 +static bool inc_ctx_shm_count(struct ffa_ctx *ctx) +{ + bool ret =3D true; + + spin_lock(&ctx->lock); + if (ctx->shm_count >=3D FFA_MAX_SHM_COUNT) + ret =3D false; + else + ctx->shm_count++; + spin_unlock(&ctx->lock); + + return ret; +} + +static void dec_ctx_shm_count(struct ffa_ctx *ctx) +{ + spin_lock(&ctx->lock); + ASSERT(ctx->shm_count > 0); + ctx->shm_count--; + spin_unlock(&ctx->lock); +} + static struct ffa_shm_mem *alloc_ffa_shm_mem(struct ffa_ctx *ctx, unsigned int page_count) { struct ffa_shm_mem *shm; =20 - if ( page_count >=3D FFA_MAX_SHM_PAGE_COUNT || - ctx->shm_count >=3D FFA_MAX_SHM_COUNT ) + if ( page_count >=3D FFA_MAX_SHM_PAGE_COUNT ) + return NULL; + if ( !inc_ctx_shm_count(ctx) ) return NULL; =20 shm =3D xzalloc_flex_struct(struct ffa_shm_mem, pages, page_count); if ( shm ) - { - ctx->shm_count++; shm->page_count =3D page_count; - } + else + dec_ctx_shm_count(ctx); =20 return shm; } @@ -1018,8 +1051,7 @@ static void free_ffa_shm_mem(struct ffa_ctx *ctx, str= uct ffa_shm_mem *shm) if ( !shm ) return; =20 - ASSERT(ctx->shm_count > 0); - ctx->shm_count--; + dec_ctx_shm_count(ctx); put_shm_pages(shm); xfree(shm); } @@ -1299,7 +1331,11 @@ static void handle_mem_share(struct cpu_user_regs *r= egs) goto out_set_ret; } =20 - spin_lock(&ctx->lock); + if ( !spin_trylock(&ctx->tx_lock) ) + { + ret =3D FFA_RET_BUSY; + goto out_set_ret; + } =20 if ( frag_len > ctx->page_count * FFA_PAGE_SIZE ) goto out_unlock; @@ -1421,7 +1457,9 @@ static void handle_mem_share(struct cpu_user_regs *re= gs) if ( ret ) goto out; =20 + spin_lock(&ctx->lock); list_add_tail(&shm->list, &ctx->shm_list); + spin_unlock(&ctx->lock); =20 uint64_to_regpair(&handle_hi, &handle_lo, shm->handle); =20 @@ -1429,7 +1467,7 @@ out: if ( ret ) free_ffa_shm_mem(ctx, shm); out_unlock: - spin_unlock(&ctx->lock); + spin_unlock(&ctx->tx_lock); =20 out_set_ret: if ( ret > 0 ) @@ -1464,7 +1502,12 @@ static void handle_mem_frag_tx(struct cpu_user_regs = *regs) uint16_t sender_id =3D 0; int ret; =20 - spin_lock(&ctx->lock); + if ( !spin_trylock(&ctx->tx_lock) ) + { + ret =3D FFA_RET_BUSY; + goto out_set_ret; + } + s =3D find_frag_state(ctx, handle); if ( !s ) { @@ -1489,15 +1532,20 @@ static void handle_mem_frag_tx(struct cpu_user_regs= *regs) spin_unlock(&ffa_tx_buffer_lock); if ( ret < 0 ) goto out_free_s; + + spin_lock(&ctx->lock); list_add_tail(&s->shm->list, &ctx->shm_list); + spin_unlock(&ctx->lock); + out_free_s: if ( ret < 0 ) free_ffa_shm_mem(ctx, s->shm); list_del(&s->list); xfree(s); out: - spin_unlock(&ctx->lock); + spin_unlock(&ctx->tx_lock); =20 +out_set_ret: if ( ret > 0 ) set_regs_frag_rx(regs, handle_lo, handle_hi, ret, sender_id); else if ( ret =3D=3D 0) @@ -1506,6 +1554,18 @@ out: set_regs_error(regs, ret); } =20 +/* Must only be called with ctx->lock held */ +static struct ffa_shm_mem *find_shm_mem(struct ffa_ctx *ctx, uint64_t hand= le) +{ + struct ffa_shm_mem *shm; + + list_for_each_entry(shm, &ctx->shm_list, list) + if ( shm->handle =3D=3D handle ) + return shm; + + return NULL; +} + static int handle_mem_reclaim(uint64_t handle, uint32_t flags) { struct domain *d =3D current->domain; @@ -1516,29 +1576,26 @@ static int handle_mem_reclaim(uint64_t handle, uint= 32_t flags) int ret; =20 spin_lock(&ctx->lock); - list_for_each_entry(shm, &ctx->shm_list, list) - { - if ( shm->handle =3D=3D handle ) - goto found_it; - } - shm =3D NULL; - ret =3D FFA_RET_INVALID_PARAMETERS; - goto out; -found_it: + shm =3D find_shm_mem(ctx, handle); + if ( shm ) + list_del(&shm->list); + spin_unlock(&ctx->lock); + if ( !shm ) + return FFA_RET_INVALID_PARAMETERS; =20 uint64_to_regpair(&handle_hi, &handle_lo, handle); ret =3D ffa_mem_reclaim(handle_lo, handle_hi, flags); + if ( ret ) { - shm =3D NULL; - goto out; + spin_lock(&ctx->lock); + list_add_tail(&shm->list, &ctx->shm_list); + spin_unlock(&ctx->lock); + } + else + { + free_ffa_shm_mem(ctx, shm); } - - list_del(&shm->list); - -out: - free_ffa_shm_mem(ctx, shm); - spin_unlock(&ctx->lock); =20 return ret; } --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549995; cv=none; d=zohomail.com; s=zohoarc; b=HFE6vAzd1a82nZgMtUq+QCdbuCSe1qGZWKG90I46NTubaPLFA5egvgfP2DpE/bvPLn5vbEe5g5vt2tusROCmZW4Yw+JoVO/kA1SC61/48uliDRzOKy9C+EO1cl1v08pYy8rW5yHQrt86f1cJ9rX0nAlPGWsa4BpDLREQJorokSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549995; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l0XHslbV1muN4VtuaM4zruuvudWXBg6/E8tWHxT1G2w=; b=DA2FAIin7ZO8hfN6K/pRlIZgg17Pt/felB1p0Uxk0MloRgQamVTs1fCLw+gal842mJnGIpeJ91AMFGXf5HDHFiZ5/hgVlcW/LyU+rdkGDvk2L9X3VRSGxpfsvWCj/+UizVjQ0+3yrdRpFyxyNc9CGLC2Zy09fG7miPxgWDeKOgE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549995518959.0889471139604; Wed, 5 Jul 2023 02:39:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558926.873535 (Exim 4.92) (envelope-from ) id 1qGyys-0007Ni-VL; Wed, 05 Jul 2023 09:39:26 +0000 Received: by outflank-mailman (output) from mailman id 558926.873535; Wed, 05 Jul 2023 09:39:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyys-0007Nb-Qh; Wed, 05 Jul 2023 09:39:26 +0000 Received: by outflank-mailman (input) for mailman id 558926; Wed, 05 Jul 2023 09:39:25 +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 1qGyvI-0005bC-I6 for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:44 +0000 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [2a00:1450:4864:20::236]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4f0d355d-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:42 +0200 (CEST) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b69dcf45faso105699081fa.0 for ; Wed, 05 Jul 2023 02:35:42 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:40 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4f0d355d-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549741; x=1691141741; 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=l0XHslbV1muN4VtuaM4zruuvudWXBg6/E8tWHxT1G2w=; b=f899ZIKOky2C3a7sro1D/PW5bsGIsjNat/XajNAkKNjim/maYyRXaufJNUm8Khzrer H90b+A+uxSsw4GWLkTMWL/FxYHSseZQVqgxYjBaxFpPFXnY3F0TNmwbMB6EyA9lQrtc/ QbftdMNWM4Tg8EOyZNgKnTvMDZq5p3ssHk7W7aOTqwyGr0TNrwrEYg01Jc8vkPNWBGQ/ spsbGgAg1NkBG1epHMEeBvR1/GEsW1eW6cb1pt5jql9/B5lZYYYwOQf/oZ9Dfl16udxR fQ7lL8cAbPXMWM5bsgtMMu5VmhCpbMtP6igz9C45WOxw6kuy9HoQt20YawlDmZfW9tyJ 77TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549741; x=1691141741; 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=l0XHslbV1muN4VtuaM4zruuvudWXBg6/E8tWHxT1G2w=; b=JVkwM4o1DAs6YWzYHGLunDyqZ6uavsMbq/jSK1Wc2Cbcngmxjg7PeEjcA7IqL4Jy00 qmmOLEA4TmsgMwDo0FMIGVqdxWozUHch5GHxpo47PgpSjMXwIaBLGkUJ2C4KEBrdzncM whJ6tRWaHtUq5RJiBjsykyEBQDvVTuI1pDFkjbfjd/Gkk3ZfOrggSF1dHL5C1aHoAscR W1BwMJiViyxkKecVEgRuVMrc0u8H5jtOw4FqaomHLwU2pOUl2y8mJCsxCL1n9IqdLf16 dx3l/F6G0X9OnCNHJJZ+jB5cntfv0uBTv3uCDvonVMM+fsA5Xg9WHS/II+Mi5bPOL+Kq VeBA== X-Gm-Message-State: ABy/qLYBJMsieuda4tS0qek+MpQlBd5CMye1Y5NynXAr2yzcA5ssTt1k belSFwQ9mgEebs6NZcoNRnkeffra3bBZVuGuJFg= X-Google-Smtp-Source: APBJJlFz3GD2LUh6Zwr7QSCWB/3NRAG6M/UVX+8FWJ/vvSRXnWpckZNZca5gXfWOTtmlF8Ihw5rOuA== X-Received: by 2002:a2e:800b:0:b0:2b6:cd40:21ad with SMTP id j11-20020a2e800b000000b002b6cd4021admr10535462ljg.37.1688549741363; Wed, 05 Jul 2023 02:35:41 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 22/24] xen/arm: ffa: list current limitations Date: Wed, 5 Jul 2023 11:34:31 +0200 Message-Id: <20230705093433.2514898-23-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549996799100001 Content-Type: text/plain; charset="utf-8" Adds comments with a list of unsupported FF-A interfaces and limitations in the implemented FF-A interfaces. Signed-off-by: Jens Wiklander Reviewed-by: Henry Wang --- xen/arch/arm/tee/ffa.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 59832f73c2be..0fbaf7e1bb8f 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -13,6 +13,37 @@ * https://developer.arm.com/documentation/den0077/e * TEEC-1.0C: TEE Client API Specification version 1.0c available at * https://globalplatform.org/specs-library/tee-client-api-spec= ification/ + * + * Notes on the the current implementation. + * + * Unsupported FF-A interfaces: + * o FFA_MSG_POLL and FFA_MSG_SEND - deprecated in FF-A-1.1-REL0 + * o FFA_MEM_RETRIEVE_* - Used when sharing memory from an SP to a VM + * o FFA_MEM_DONATE_* and FFA_MEM_LEND_* - Used when tranferring ownership + * or access of a memory region + * o FFA_MSG_SEND2 and FFA_MSG_WAIT - Used for indirect messaging + * o FFA_MSG_YIELD + * o FFA_INTERRUPT - Used to report preemption + * o FFA_RUN + * + * Limitations in the implemented FF-A interfaces: + * o FFA_RXTX_MAP_*: + * - Maps only one 4k page as RX and TX buffers + * - Doesn't support forwarding this call on behalf of an endpoint + * o FFA_MEM_SHARE_*: only supports sharing + * - from a VM to an SP + * - with one borrower + * - with the memory transaction descriptor in the RX/TX buffer + * - normal memory + * - at most 512 kB large memory regions + * - at most 32 shared memory regions per guest + * o FFA_MSG_SEND_DIRECT_REQ: + * - only supported from a VM to an SP + * + * There are some large locked sections with ffa_tx_buffer_lock and + * ffa_rx_buffer_lock. Especially the ffa_tx_buffer_lock spinlock used + * around share_shm() is a very large locked section which can let one VM + * affect another VM. */ =20 #include --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688549767; cv=none; d=zohomail.com; s=zohoarc; b=KCiWs1XMxDTHrXmCOZPSSq/77hFz06RK+cL0ARRz7eTHd37yhXhw73be6EG6/2lo0+I+Tv8Cu1bkd6Vu331lENGB5oVOCUAUEvKXlPxDDSdGdbeyY16+iq8/SWc9MW7ZGmYn12//sn69Bf6wcb/RiIqgcDNKKT5aysuCCncKtrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688549767; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7qJzaSd0HvmBntjUGVzcYap0wvkw2yCzYdORcW1H2Eg=; b=kGb1uGjYJsaenuBh1QzxX9Us5YJ7gzDDpPvkrNnvg9KAFR8punRxA41AK/N2ljlKSNiGXDOc2XB2IAnirAMWQNi20BZ1Ppc+E07RronvpHe7/SIbapGi9x6K107m5Zq4TE9ZWQNELe69ZtaA9DjNJs++UE2/VzatoMH+M+L5HFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688549767977479.0505350279392; Wed, 5 Jul 2023 02:36:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558901.873518 (Exim 4.92) (envelope-from ) id 1qGyvK-0003Pb-G3; Wed, 05 Jul 2023 09:35:46 +0000 Received: by outflank-mailman (output) from mailman id 558901.873518; Wed, 05 Jul 2023 09:35:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyvK-0003Nu-5R; Wed, 05 Jul 2023 09:35:46 +0000 Received: by outflank-mailman (input) for mailman id 558901; Wed, 05 Jul 2023 09:35:43 +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 1qGyvH-0006bq-Jy for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:43 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4fbbcc8e-1b17-11ee-b237-6b7b168915f2; Wed, 05 Jul 2023 11:35:43 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b6afc1ceffso106242191fa.0 for ; Wed, 05 Jul 2023 02:35:43 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:41 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4fbbcc8e-1b17-11ee-b237-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549742; x=1691141742; 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=7qJzaSd0HvmBntjUGVzcYap0wvkw2yCzYdORcW1H2Eg=; b=ipq/A2Hi2yQUmOcd+UZDrLei6lggYX4sIgnIVHJKc77vrX5poi1Yzzassr7SKrPsnm OyhOSngsjtiuR81fAvKtsl1tVmmxfFVuGBBRFSbys7HttK9RFwmoncVPBCK8JHR1vZmU SojLhvTT7T2PVQ4kUGa8QlVqc4guEqO3hIjyMVKKnLftmS0f1zn931MCTMzcCepRBDHA mwr9GCscYEZA1iumyDG2vffm1NeyA4SMcOZ6QiSLwwC+w2acvCt7D1m0V5mQsqMqyQjf Y/4h5UQ8Am8erHTFAt2LXWK2+VFTyoC5a9OjipK3wd/EMG3p5YtCc3zkitATsYMuhJei Mr9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549742; x=1691141742; 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=7qJzaSd0HvmBntjUGVzcYap0wvkw2yCzYdORcW1H2Eg=; b=aOEmrC6xX6kFEP9iO21Yv8iDGLrRG0DAgpcfdb/e8U07LdAKjP+zk0XB/dA2XZio3K G+VibI0jQvUFCvpoULLObfAUFKKQh7ZN2gFeG8bP1FSmU+UerqIop7WqzHqOuPmeVG8e V1sHwGUwKmXaXO+UctXFrGyOsrYv5MVJ7k/V6VuUvpGYX1crwvGPBzuhkQH9tN+OiCet iIDKrcn0f3RrKWfbBvmxM96Ha91d9R5jtUuphiH+e3qNBWedpNP0ARJwb6WywJYFohnr 8hKQmAQ9O/Ls+x+dZQY670EqmkRm23Crcga8NSIdoNAKmAeM9GefE3MCE1GuM2bXcR9o jejQ== X-Gm-Message-State: ABy/qLaz5n0d9Kt/CEaVSs6SKBWUlR5cEGf80NDPuGbwIfmgL6sDrBOV zh/oUtfDmwjSi6I8W/zxzZcJ49mz+g0Ey3KtL1E= X-Google-Smtp-Source: APBJJlHUJBWSzdcUQruJ6Mrl2LWhLifbL4Yl9LecwWQlfhdSBsxllBSZTar7jy7JAcWGb/JRz/hnQA== X-Received: by 2002:a2e:3515:0:b0:2b6:d89e:74e2 with SMTP id z21-20020a2e3515000000b002b6d89e74e2mr8243482ljz.7.1688549742487; Wed, 05 Jul 2023 02:35:42 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v9 23/24] tools: add Arm FF-A mediator Date: Wed, 5 Jul 2023 11:34:32 +0200 Message-Id: <20230705093433.2514898-24-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688549768715100019 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Henry Wang --- tools/include/libxl.h | 5 +++++ tools/libs/light/libxl_arm.c | 3 +++ tools/libs/light/libxl_types.idl | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index cac641a7eba2..bf1a49e5d687 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -283,6 +283,11 @@ */ #define LIBXL_HAVE_BUILDINFO_ARCH_ARM_TEE 1 =20 +/* + * arch_arm.tee field in libxl_domain_build_info has ffa value. + */ +#define LIBXL_HAVE_BUILDINFO_ARCH_ARM_TEE_FFA 1 + /* * libxl_domain_build_info has the arch_arm.sve_vl field. */ diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index 35f76dfc21e4..e155c68989aa 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -207,6 +207,9 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, case LIBXL_TEE_TYPE_OPTEE: config->arch.tee_type =3D XEN_DOMCTL_CONFIG_TEE_OPTEE; break; + case LIBXL_TEE_TYPE_FFA: + config->arch.tee_type =3D 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_type= s.idl index 9e48bb772646..65600e17429e 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -520,7 +520,8 @@ libxl_gic_version =3D Enumeration("gic_version", [ =20 libxl_tee_type =3D Enumeration("tee_type", [ (0, "none"), - (1, "optee") + (1, "optee"), + (2, "ffa"), ], init_val =3D "LIBXL_TEE_TYPE_NONE") =20 libxl_sve_type =3D Enumeration("sve_type", [ --=20 2.34.1 From nobody Fri May 10 05:33:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1688550001; cv=none; d=zohomail.com; s=zohoarc; b=TIEXH9PCIHDoGUt29OMwCdK4ZkHNsXY0iyM1Zsq616nH0XwctlC7zLPT0I2ILFc1R3/X3x9G+DwFCMhIxW40skgnaYhJ7CMUlDWVul5xNj5ACRuN/OKM7ABVU6Vx8yOudoIHCeAtqXJtKYCbf2/dKa4ZYLu8lyuJc1QhfSKt76E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688550001; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6R/D9gUszluJweN/TK1ixSj9VXkkPD7CMOFZ9iBZSkU=; b=B7FJPei+vt9jCwiFUKQZUy6b2CdQ+ts/bEB/CP9su1n4VknTXJ0kB63rCBoQFc+UWVlPM02gfXVBhpaB2r824EYyItY5p3AYSsF95oMR1vHywO2W6bpesyZ/ohnnNK8HH5edDfXXq51es7DBuEQ1IXBzz1Czfqm+bs602C2dxTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168855000099649.07719103779846; Wed, 5 Jul 2023 02:40:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.558941.873560 (Exim 4.92) (envelope-from ) id 1qGyyu-0007vN-Qc; Wed, 05 Jul 2023 09:39:28 +0000 Received: by outflank-mailman (output) from mailman id 558941.873560; Wed, 05 Jul 2023 09:39:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qGyyu-0007um-KJ; Wed, 05 Jul 2023 09:39:28 +0000 Received: by outflank-mailman (input) for mailman id 558941; Wed, 05 Jul 2023 09:39:27 +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 1qGyvK-0005bC-Il for xen-devel@lists.xenproject.org; Wed, 05 Jul 2023 09:35:46 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 50754205-1b17-11ee-8611-37d641c3527e; Wed, 05 Jul 2023 11:35:44 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b69923a715so99588901fa.0 for ; Wed, 05 Jul 2023 02:35:44 -0700 (PDT) Received: from rayden.urgonet (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id q22-20020a2e84d6000000b002b6d8cfb6d2sm2910625ljh.140.2023.07.05.02.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 02:35:43 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 50754205-1b17-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688549743; x=1691141743; 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=6R/D9gUszluJweN/TK1ixSj9VXkkPD7CMOFZ9iBZSkU=; b=LobW9+25cTLWzcRstSuR690/dlXuCVYMwbPjIEHTenZ/2nRyXeKwA/h4JAzHRUzD3s FmhvlBe2Q1EO5fMOb9VnD+mG9ZME87aqU7YDwVJjHbbHjeiROCCDnsooeVOOfxpDtZ5j 9ioX15OCbqKNZaAm3a6tIgDXGvCY8M7lUzMzv24y8iQgoIWQh+utR6FxUgrajknE4/6L nt47aOLygXEI1KDw0FvuIviN0CZ9nZcBRDTnCAw4YdW3FSaQbWsLsjsgc0Id+7afCimr t5Hbe/fTj8Eq0eBBQOqjXDyhwxnqSUUpH/18drtvjaNhf1gf+SeH6o9m6mgpxDoz800U Mb+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688549743; x=1691141743; 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=6R/D9gUszluJweN/TK1ixSj9VXkkPD7CMOFZ9iBZSkU=; b=kBvK1h/qtMtdpc5bvxLS/YZPinocxhmd7WOWccix/AYZvko+u2BeeIKOzgeJt5OwpS gl//dTUc8VSyXWzyrVn9whDzMGJ95krEkdSeBkECQvIGjy9cjG2QAKLJRCZfHJq6KMDw KHR7M/vCyBdj3l5OGwBobItpk8eLNcDGiKeZ/We3T/Ym6sJ+tBEQjew6e0G/v41RMpK4 CQMOP5MMruBCnThurt1G/yPL/UINcJbtA8GKSPZP4rzw5WsJXbypZk5hsC+Fla40vQwg UVm5L6Xn2NgRTyHFfNPZGrkBbEWNidjhWzBICmJlNxz6q2NnBz1sxcXZOpjgoF65SwYz BYWw== X-Gm-Message-State: ABy/qLZ7bJflmzWfdxTH0l0ZJ8SLyiOKJR02yH0V6g5/f6IWPAxlg6pX TsP0/47L68kPluvboSGcNbu9vzlvZ/8uPdU4LXY= X-Google-Smtp-Source: APBJJlG/ZBCtB2DwyEpGctwoEHXQfYDNb0BZg67xTGH4UHtUtorEKgA7D8goMZYyEGY7vBlTlkf+Gg== X-Received: by 2002:a2e:888e:0:b0:2b6:bb21:8d74 with SMTP id k14-20020a2e888e000000b002b6bb218d74mr13048468lji.1.1688549743794; Wed, 05 Jul 2023 02:35:43 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand.Marquis@arm.com, Anthony PERARD , Juergen Gross , Wei Liu , Marc Bonnici , Achin Gupta , Jens Wiklander , Andrew Cooper , George Dunlap , Jan Beulich , Henry Wang Subject: [XEN PATCH v9 24/24] docs: add Arm FF-A mediator Date: Wed, 5 Jul 2023 11:34:33 +0200 Message-Id: <20230705093433.2514898-25-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230705093433.2514898-1-jens.wiklander@linaro.org> References: <20230705093433.2514898-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1688550001523100009 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Henry Wang --- SUPPORT.md | 9 +++++++++ docs/man/xl.cfg.5.pod.in | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index 35a6249e03b2..fe512762cee7 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -840,6 +840,15 @@ that covers the DMA of the device to be passed through. =20 No support for QEMU backends in a 16K or 64K domain. =20 +### 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. Part of the +FF-A specification is not supported, see the top comment in +xen/arch/arm/tee/ffa.c for limitations. + ### ARM: Guest Device Tree support =20 Status: Supported diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 3979be2a590a..911c3619ce32 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1648,6 +1648,21 @@ in OP-TEE. =20 This feature is a B. =20 +=3Ditem B + +B Allow a guest to communicate via FF-A with Secure Partitions +(SP), default false. + +Currently only a small subset of the FF-A specification is 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 multiple SPs are not supported. + +See L for more +information about FF-A. + +This feature is a B. + =3Dback =20 =3Dback --=20 2.34.1