From nobody Mon May 13 19:10:41 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=1690805767; cv=none; d=zohomail.com; s=zohoarc; b=J526/F3Bancv6TZ94vq0DeiSrVlUa/TU+mLbFqFKvP8bGMGHO5vFH6kuJIFkizpNz7RKnSzViKvQQnfMteTs9eGjOaEyeIYQobmdTFSSHzb2R/w1KzCYCC5SuRvG/7Azb21cD/8qHyEVvnABgXC9xR/1Tmr2ExqkdJOiYx3BsXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805767; 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=pJQzvJ0OqzEXs06pXN7HU741HPJ2/SrxAbSMgLekP8w=; b=Q8uh5HNr3+3fi871n1spLEH0GJhhChJ838ryk9B1l+q+ygZbNLAW6FBECT/cq9gNX7QPGIrKSV/4Jc/yQZRtWh7opV24pf9uRsNUNOZFtz5zhXraodI9SECWz14cQc5R7gAkP+dvnMYZJ1R7A7X7OjmI7lvN7eyOWCcUXXdXbqs= 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 1690805767553901.7905097861662; Mon, 31 Jul 2023 05:16:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572961.897133 (Exim 4.92) (envelope-from ) id 1qQRoQ-0003tZ-37; Mon, 31 Jul 2023 12:15:46 +0000 Received: by outflank-mailman (output) from mailman id 572961.897133; Mon, 31 Jul 2023 12:15: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 1qQRoP-0003sx-VL; Mon, 31 Jul 2023 12:15:45 +0000 Received: by outflank-mailman (input) for mailman id 572961; Mon, 31 Jul 2023 12:15:44 +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 1qQRoO-0003r6-J2 for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:44 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f839bb05-2f9b-11ee-8613-37d641c3527e; Mon, 31 Jul 2023 14:15:42 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4fe28e4671dso2692760e87.0 for ; Mon, 31 Jul 2023 05:15: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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15: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: f839bb05-2f9b-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805742; x=1691410542; 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=pJQzvJ0OqzEXs06pXN7HU741HPJ2/SrxAbSMgLekP8w=; b=GCHLTJtQ8oGnt0c+OFuGjHgpp6yn/bwRxTpv540FME/hbSXJx+s/z4UA1mqWSEBgHK YYXvaMM4ZjePOwnC1AwJkj8uHX2HoM9oAob3YNmwBgTr7ZdYOJ/F8rUYwC6WMAF1TRRe vhO3P9UC9eua38l6BciYJ8fP1dCVhrRsm+39868+quIWG6AByGt+kd2RnXlNOkWTnlE+ rdzm6VR9t54RoC2plCAhkjJO6uO372Zmp5louEoZ5p7YoZqCelYpQQ1iPTdOCDz29vB6 eBXgUEMDgbZI1uHVUaR2JWKzzWZIOjBhnQUDEJx+zghTsCSnuJvfvnbdb5plR1quoge7 yTig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805742; x=1691410542; 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=pJQzvJ0OqzEXs06pXN7HU741HPJ2/SrxAbSMgLekP8w=; b=Rc5yLAdY2zqHtj26ubo0ws6MXaBArqnZL1roUX+zdfKd91NDcg3fd/ZN21Rz9zastx FjYRQnxbVThYJgMIr0IvKFAGIlT44Nz0lh6ciYIqlSqcFGhYbYQXCLjo6zagld6G0u0p CWfEkzG0nFdo8L3BrAZm3+7a+VaMt/bo4VoV7nvMzXU4w39sDk3OHw8HtceFAOGlHkI/ wrvxRgVZPzCBQWZShJtWLn1UE11hjOmzkMqgdY/21z7mIfIKQTcnBeUtObVNDSpRliDV CbikFh8QF/TFD23VStfQAmWmNofos8TAdki1UmVqYtEvb3+tSPHfNudkq5UvfZ+3b6js NbFA== X-Gm-Message-State: ABy/qLaOmbGnGmdQcynWJppSqWfY2XkA7uSPafhYfu358HA3rUH0nppr WRj1daH92IHZuXw0nbRqQEM+Aj9HQKq/toc26aM= X-Google-Smtp-Source: APBJJlFSC/mFSDFmW8bgNee1xzB0UFNA1ks6ln4nHrhOatVk1GOT3ytH+NRVitDpX7lMJcd0nQCnyQ== X-Received: by 2002:a05:6512:1591:b0:4fb:97e8:bc1c with SMTP id bp17-20020a056512159100b004fb97e8bc1cmr7158804lfb.54.1690805741921; Mon, 31 Jul 2023 05:15:41 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v11 01/14] xen/arm: ffa: add direct request support Date: Mon, 31 Jul 2023 14:15:23 +0200 Message-Id: <20230731121536.934239-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805768820100001 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 Reviewed-by: Bertrand Marquis --- v10->v11 - In handle_msg_send_direct_req(), replaced the "arg" with "resp" at the default: label in the switch statement. --- 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..961a8c052f59 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 to the caller. */ + memset(&resp, 0, sizeof(resp)); + resp.a0 =3D FFA_ERROR; + resp.a1 =3D src_dst; + resp.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 Mon May 13 19:10:41 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=1690805765; cv=none; d=zohomail.com; s=zohoarc; b=ZxKyd+sTVxV0Ks4KE4nUhq1Yxhwv/cwmyKAgAdePmYRXqqUPCkQxdptjRmPodcgvbshwz0MI9iv0niw0eDtYoVFBnX3BLdnvCjhsnXx24Vy7ZxD28ty9IEQnn84h09+N87ZN9vkd4psXvY9E03ZSq8tK62x/+K5sBEI5zVXrK18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805765; 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=IuPpDETKsd9EJlCiQj7fwJqFCPyxOJBlZOFnIaGXlq0=; b=UrzD4RrmECgGyGh7S+rHdIjPAApEVs3d9p+cqHM7ncj/4Jln7dxQ5wGvwqjZFCoPxoL//H8iuXpQn+I6b4KeGj1gAxh7hglj2FaWUP5Q/jACtAMKwkkbNJ9wjgOfZSaX9JsOADxIsQHNquz/F4Tt2OS1bddXRnuBXmS8krZR/FU= 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 1690805765584501.6016156009629; Mon, 31 Jul 2023 05:16:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572962.897139 (Exim 4.92) (envelope-from ) id 1qQRoQ-00042t-GD; Mon, 31 Jul 2023 12:15:46 +0000 Received: by outflank-mailman (output) from mailman id 572962.897139; Mon, 31 Jul 2023 12:15: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 1qQRoQ-00041L-BS; Mon, 31 Jul 2023 12:15:46 +0000 Received: by outflank-mailman (input) for mailman id 572962; Mon, 31 Jul 2023 12:15:45 +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 1qQRoP-0003r6-Mc for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:45 +0000 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [2a00:1450:4864:20::134]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f90d4d6c-2f9b-11ee-8613-37d641c3527e; Mon, 31 Jul 2023 14:15:44 +0200 (CEST) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4fe0eb0ca75so7035137e87.2 for ; Mon, 31 Jul 2023 05:15: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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:42 -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: f90d4d6c-2f9b-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805743; x=1691410543; 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=IuPpDETKsd9EJlCiQj7fwJqFCPyxOJBlZOFnIaGXlq0=; b=iOTLKtvQETxTMalLcdecJT/sHdrrm5WB3/2sAZHm1rFIfG3n9EU4BTAhUbvsxZDs0t gPmZBjx/gwuRdAQIcIYmsgsgHt17Va1D2yzo2ILTG2UgC+iuyh/pvVkv6WJdDvYMyO8J P5FzTDyuSrRe5GLTEdfrwVcgdA1Y+mQV8bhRnuX/BWm5Z1F5xhxbQ3sngy6qx2/zZ5PM tCXbVOxC7N49qal9hJIXT4I1UoietrdrU6AzGjw0WbRJbMFQ09ZVM++yFiYWtxizQxMQ /cwIjb6CEY+87tKasTbAvDrsz4JO/TesBEIHUXppSepUxW5PZrg2dCyK4LRFMGujQdxl 7FYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805743; x=1691410543; 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=IuPpDETKsd9EJlCiQj7fwJqFCPyxOJBlZOFnIaGXlq0=; b=Eluw1HOH88/eHc+/L93iR3NCQpMfTsCkyGVKtEJEYcHEU/9psUxG+o3z/Gd1d3hGyV PHlJh08uTyAazOHwOq41Z57NEUIK5W5KhMkjJ53xknDBiPF1JVN3NERyX/TMDK8exXmI 6fCDB8QSx8tmcl2D+BywgmzAGTxm/Dv1iJx5y/NOwZFPkiTK135vBbnwNFXinsaUmuRH 1BepTKgM5WsFYj6kBRpwFXBC5Y8YDjCvUK/PGLft+M9IhmM0LuFABJoDU+DoXrvryrP9 CpnLtJGU8NkIon/6YzZUf3YKNGIR8r/8Q4bkIgajatup8QZIE0tGm2Qmuu9FjnEmtx88 0Mqw== X-Gm-Message-State: ABy/qLayML9A2IhnkveqcYxR+wmxZfwCcJZC6VDapf6LKMRFT0yPBf7b 2vurS/FwFa8fKi/eWfEz6Ev7fJQCgN9SyBYKzu8= X-Google-Smtp-Source: APBJJlFGXJpsvWNFf2xF1DleAbjD+fJafx2vX2SmChqHWEBQGXJ9Ducp6skAwEtEmdTsL2U78f490Q== X-Received: by 2002:a19:ca44:0:b0:4fe:193c:de74 with SMTP id h4-20020a19ca44000000b004fe193cde74mr4900973lfj.18.1690805743019; Mon, 31 Jul 2023 05:15:43 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 02/14] xen/arm: ffa: map SPMC rx/tx buffers Date: Mon, 31 Jul 2023 14:15:24 +0200 Message-Id: <20230731121536.934239-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805766185100003 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 Reviewed-by: Bertrand Marquis --- v10->v11 - Adding Reviewed-by: Bertrand Marquis --- 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 961a8c052f59..072198a1326d 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 Mon May 13 19:10:41 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=1690805772; cv=none; d=zohomail.com; s=zohoarc; b=PL2W+viaZz48onMjfkLtCUbj5Wk32Y1MpffO0tfUOLR/DGkmRUlwMhibsj8Tbu6USzKj1ejgLGFP7vBSJAUGGGV6mxxzkPBVu3v4gsaVNNqM0I1gQjgQrRzmh38hLGMyUD5Atos8GSRZo90YID2ByuXdy1+hO+IbArhnp0rB3K8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805772; 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=rFiw8jg7BUWz3gVWuBmPXLW/ZlH0wqkGB//S/ukxL+E=; b=FWq845/2zk5BzDOtQlb4w2xsP7Fd6RT4anW7XmTQekczlBvPm63Bdpuq0xaVecahAZPthu9dIDKhPZ8JYdTE8yP5QJ6lCHzMij39RbL9nUBTNjt/EvUPPQjraKn98BS/EQtvre1jmV5pAgEpH00MMdkOA3jTadRMJWhwaZ80G9c= 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 1690805772015915.0329596321334; Mon, 31 Jul 2023 05:16:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572963.897158 (Exim 4.92) (envelope-from ) id 1qQRoR-0004aN-OU; Mon, 31 Jul 2023 12:15:47 +0000 Received: by outflank-mailman (output) from mailman id 572963.897158; Mon, 31 Jul 2023 12:15:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoR-0004Zo-LK; Mon, 31 Jul 2023 12:15:47 +0000 Received: by outflank-mailman (input) for mailman id 572963; Mon, 31 Jul 2023 12:15:46 +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 1qQRoQ-0003r0-3A for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:46 +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 f9d27e97-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:45 +0200 (CEST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fe3c7f16bbso618996e87.0 for ; Mon, 31 Jul 2023 05:15:45 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15: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: f9d27e97-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805744; x=1691410544; 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=rFiw8jg7BUWz3gVWuBmPXLW/ZlH0wqkGB//S/ukxL+E=; b=Qmwm9M97izBmwm1GD6NJ6Bhvhd+288hCfhcwIHcm55wS3ig67kJAaYkRGeB7KYqGIF pvlN9gR1TpKDjSpNwApHqe6KaNTRVI0UVb/UigDUqVs9zvYECJxtQRxEax9Bm6RHqkTE oTfuY28Fjm8w4NcVNyxrurfa5493FahG+kGJEUeoPlmrmlv1El4LPD2+80zHxvKMpJJu OgojCGL6dsIqAG+Oh1cNqaTSAWChsOesplW5X4cQmZKe4qqnc5ZhJQGC3NlsbouX1zbc FTBe5XrhQytGeT43SNt2F5zn/P0z2t9nOda0IqRBmXPSfaazINWLs5BWTFbj/HvFOQFM Uq1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805744; x=1691410544; 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=rFiw8jg7BUWz3gVWuBmPXLW/ZlH0wqkGB//S/ukxL+E=; b=b90xTgULTXE7pHqXHbYnwvyEFr6xGvI3mVEgh1y0CP3XEzcJPH/X8Olckp19xpooWk HjRTA6C1rqfuSBgSNYhFGmFJ+ySF8om0qdee7hOY1EpS0UH2F84c3WHGSbN99cT4tpt0 wLpeaz0kaTY9zWzhfGM2ddHHViF2l4EA0psgf46QLNL/TZwaYqcfGupjX1a6D2VpNPRx sPkVYmJtdQDDdk6frZpYuv/03nMCSgkL19UN/ZNw1iMgC97PkBL7nAK1+EvAAUr/ZGLz vbCDdm+OFRfYTZk2ktB3lkRUZL1Dmux0lOdFwEmwLlQ2pYKPgoTHTlzwrIpi1kJxTAKJ jd5A== X-Gm-Message-State: ABy/qLbMFfYyBg9q6l4eZzYq5yOKMyCfiVD2hUOaBCn7xMuHTw25dSPe uWLed3DTK82feIqaE8xDxNxrTUfaNymF2QRXJnk= X-Google-Smtp-Source: APBJJlEzvi+DSzU4DDcyxiL5ilCoLcuqx0IiNp6RDvbEy4U+ssR82e1McUCSHJzxgnYrqgDPH6Pp+Q== X-Received: by 2002:a05:6512:39c5:b0:4fb:89f2:278e with SMTP id k5-20020a05651239c500b004fb89f2278emr6049815lfu.68.1690805744438; Mon, 31 Jul 2023 05:15:44 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 03/14] xen/arm: ffa: send guest events to Secure Partitions Date: Mon, 31 Jul 2023 14:15:25 +0200 Message-Id: <20230731121536.934239-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805772630100001 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 Reviewed-by: Bertrand Marquis --- v10->v11: - Addressing comments and fixing a few style issues - Fixing how is_in_subscr_list() is used, it's supposed to take an sp_id, not a vm_id. --- xen/arch/arm/tee/ffa.c | 234 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 072198a1326d..5af3e5eedc88 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; @@ -390,17 +492,68 @@ static int ffa_domain_init(struct domain *d) =20 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 subscr_vm_created_count; + return 0; } =20 +static bool is_in_subscr_list(const uint16_t *subscr, uint16_t start, + uint16_t end, uint16_t sp_id) +{ + unsigned int n; + + for ( n =3D start; n < end; n++ ) + { + if ( subscr[n] =3D=3D sp_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, + subscr_vm_destroyed[n]) ) + 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 +564,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 +690,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 +713,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 Mon May 13 19:10:41 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=1690805770; cv=none; d=zohomail.com; s=zohoarc; b=YccmrxkbkG/VjFI0j/TZqE6IUtKo3J4xkplktA2zvuMm+9ILtf2fW6FfxhpvK50oPMyp67heFC9fwY82nrBYiWHZukAFjYKKz8eYBSsbQUSSUel/U4NxKUP8Mk8AMpRuh+haDvORGGsUVZjBbACWWhlBlMD653kLumVR2+3O+j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805770; 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=wLAbTbD8REc4gEPXiOhZft6RS/Ams+Y0BUWbmBkKJ7M=; b=L6/Z4fkzzruWIwVmezM3OCQEtf53ny1SrTHc5AMJm+rNBtAjAtYhlsB9YtroYKMA3jQGZX3KE2OxZ5PRzT+/4xYZFdv0NYFQLNoaOhMjJXrlh5Izme8rVCWVGrt5CKqV2KJGh7arMZbrMH/SR4+x8XeLW/f4oRom6ss4XQPhGxQ= 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 1690805770325970.0583438925398; Mon, 31 Jul 2023 05:16:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572964.897165 (Exim 4.92) (envelope-from ) id 1qQRoS-0004lZ-EG; Mon, 31 Jul 2023 12:15:48 +0000 Received: by outflank-mailman (output) from mailman id 572964.897165; Mon, 31 Jul 2023 12:15:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoS-0004kt-9S; Mon, 31 Jul 2023 12:15:48 +0000 Received: by outflank-mailman (input) for mailman id 572964; Mon, 31 Jul 2023 12:15:47 +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 1qQRoR-0003r0-Jb for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:47 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fac2235b-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:46 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4f4b2bc1565so6929750e87.2 for ; Mon, 31 Jul 2023 05:15:46 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:45 -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: fac2235b-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805746; x=1691410546; 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=wLAbTbD8REc4gEPXiOhZft6RS/Ams+Y0BUWbmBkKJ7M=; b=fnS8900MhsUzDHFIdPTo0VDqH6gyfxILEzrnfE7raqj0J8sxPLOgnXdm9Ly4f5oJG6 kRbVDiJmxnETDJEWVdZCzy6Qrp3NpW4fw5hb76V75gpnityqLfWvf+K0+W5YU9qPg5eo 7cI9r2WnWMsFsIH5ZMS9m5ddwMpNKIR7S/ksdkhKBWmsB9FiRxMZH0oj0o+SlaGUKLv3 oNlyvaxCnvqZ4kztqaYpCX3T5NzjXjWGBlYBGD4HWjiYMvDzOG/fsMLF4ZH3HlkRzNe+ XddORfZrJeHBGl1KhYH5kYImRWMWW6ElH7FoMzyA7FvgKtjekU3DU3e2B+QuHkrAJN3P CB7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805746; x=1691410546; 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=wLAbTbD8REc4gEPXiOhZft6RS/Ams+Y0BUWbmBkKJ7M=; b=aiDZUDE5BVNh+DRXfIGuJ2Kuo6MZ9Q64gkAfjDg58+YaVzs4773XPxd+wXVlikiaOZ UY261cnMphEyLsunIY6MmHm2JdSCpfy9ZLKiHRO14eMhu4HzCRohqL9X6dqu4C89ehty zzHB5RUkrxnNxfYxG6ltqJNmba2FxB0kYoys4wcRgNJbyKVUyxnLFgF3lPuAapV3lPzO FMkm7VVzVw/9kWla87/Q57HHYHewbNGLjJuHbe2hDNalT3/3zPU6E4PfVvPF2wQhtnS0 WzDr5YAAsnwFEiVn0bYvA7pdApD3mFI6PVbKkMp6dzxDBt9tJ7PjxbKvEyK4V+sQ9ypV EnZA== X-Gm-Message-State: ABy/qLZGuXcENqFketbT5sfOjWmerIvN9kzvdnd9Y3rhJhs+ZxHZy1Wf JnOSdLzZP9f4w6CQdlema4dXNEgV6hiXG6CDDzk= X-Google-Smtp-Source: APBJJlGsytHD8uI0JreHbyjyk9r34ALyu+st1rnZRjElyXSmYAMHntSDhxHYpVPlROJC/u4uvNkmpw== X-Received: by 2002:a05:6512:1c3:b0:4f4:d071:be48 with SMTP id f3-20020a05651201c300b004f4d071be48mr5424879lfp.14.1690805745979; Mon, 31 Jul 2023 05:15:45 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 04/14] xen/arm: ffa: support mapping guest RX/TX buffers Date: Mon, 31 Jul 2023 14:15:26 +0200 Message-Id: <20230731121536.934239-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805772737100002 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 Reviewed-by: Bertrand Marquis --- v10->v11 - Fixing a typo in a comment and adding a couple of newlines as requested --- xen/arch/arm/tee/ffa.c | 140 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 5af3e5eedc88..6c76c9885774 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 +/* + * Limit 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,108 @@ 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 +568,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 +581,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); @@ -554,6 +691,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 Mon May 13 19:10:41 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=1690805772; cv=none; d=zohomail.com; s=zohoarc; b=QpwBM9ErmFN3Gd2fdgyBD1rTDv+GzI0JIyHZWNApksuha4r6haHHOSI+MiGEgtDlAI4Ef4+h/E8wksyNoX8LGzcIVodab+UQsZhvrjOnBb3h+uh7w+q0A4/RsanS5dzEv0/UV1FCCpmVg2J6+UD+d/BezdcWvjttYQH9nqaMeIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805772; 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=4AB6A9Fj9vf3tU/KMptcs+JouX3pEtTOo9oFrsEL35s=; b=MLzydgG+CziQp2eJ1/ebeJllLHzgbWsNzjzgNtuQLw8N2YFSZmLxfrlgLfWuFOvpj3TeZZ7qTiSCNw9fMNe1NTwsrwvWZdIyyleX39CftpUSqAs6jxftp763BIansfLoJvp/6xz2xTHNDbtZhQfnyo9Js/1s5uTLhqLDfBifsk8= 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 1690805772938396.06735557508136; Mon, 31 Jul 2023 05:16:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572965.897178 (Exim 4.92) (envelope-from ) id 1qQRoT-00058Z-RM; Mon, 31 Jul 2023 12:15:49 +0000 Received: by outflank-mailman (output) from mailman id 572965.897178; Mon, 31 Jul 2023 12:15:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoT-00058H-M1; Mon, 31 Jul 2023 12:15:49 +0000 Received: by outflank-mailman (input) for mailman id 572965; Mon, 31 Jul 2023 12:15:48 +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 1qQRoS-0003r0-Ks for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:48 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fb6e64f8-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:48 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fe21e7f3d1so4304543e87.3 for ; Mon, 31 Jul 2023 05:15:48 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:46 -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: fb6e64f8-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805747; x=1691410547; 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=4AB6A9Fj9vf3tU/KMptcs+JouX3pEtTOo9oFrsEL35s=; b=fX1IMNzMLXqAynWPqbnUkV1Rt3C0luOm0RJJStG+L08FeEH7bcQ7VOdpdPjO/M8gkX HUF4119LckHAnbQYfjrACz6Qjgc8cWA6q8T9iA0Lb0SOnyybqdUbAl2bkl1WL8CWQCxX FBzbQ2BWG+Q2QYjCyfzkjLSjLG4lMcBbyaRQmi+ylNNtod6tZ8P+MhWZ51ysuB3ZfMyv QIRJIgvgn5jGRK95vvWs75DfBFCaWS3ps1pCthDQt/QPQ/p49+urIx4bmHOPugnjqjg5 UZWhJF3cFnmK779Hs5Ju8m1qVSSVymY2/TLrNeGmufkrJZ5q+0LcdFj5HFeGqFC0FCTL HJJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805747; x=1691410547; 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=4AB6A9Fj9vf3tU/KMptcs+JouX3pEtTOo9oFrsEL35s=; b=h2vyGbeDMI1wua4TH4p4heNz9h6JW6cOpB4X7dT/qb9Pq8kHuVqMJ7jFyVzi8D/nlV uYn27HHBKPjF/0XXudPd6MPhUumoXmkoHzp6zLbntUQn2yfDgvYq5OgdEf8gwRklOXZi vbt7AoiYXaF/HqAT2+rdiPg8OMMRpWCL4kUdibLNJGKSNeoIKd+p3fVtc0dE+YsiEzKS yPjyKXPXEGM48ktGEQvpKMiVzupJMOYj/VUODzhy6ZEqB4hbPzFxWpaS6gWEc35Z7f84 DvDqyk94k6keT/Lbi77PP4NYV4uHSU0d+NROD87Sy6gm5xWvAl+XPibGGo1kYJSqjirm 9e4w== X-Gm-Message-State: ABy/qLb+rS41GPf46ipIta6KOy9gyDS2GcGtC72a69q6I26OJangPtka gjDq0EaK1Glb7eiPRmQEcl3gdxcdu4LaILRP3gk= X-Google-Smtp-Source: APBJJlHxge4QcUxtlZBi8niviTT+SjTx4A6GMi/eZePSKE3dub2Em06W0e4BqLkfd925t/I0dhh7Yw== X-Received: by 2002:a19:4f52:0:b0:4fd:d9dd:7a22 with SMTP id a18-20020a194f52000000b004fdd9dd7a22mr5256715lfk.26.1690805747264; Mon, 31 Jul 2023 05:15:47 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 05/14] xen/arm: ffa: support guest FFA_PARTITION_INFO_GET Date: Mon, 31 Jul 2023 14:15:27 +0200 Message-Id: <20230731121536.934239-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805775393100003 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 Reviewed-by: Bertrand Marquis --- v10->v11 - Fixing a typo in a comment and adding another comment as requested --- xen/arch/arm/tee/ffa.c | 134 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 6c76c9885774..6c889bf97002 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 + * structs 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) { @@ -512,6 +530,103 @@ 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. + * + * FFA_PARTITION_INFO_GET_COUNT is only using registers and not the + * rxtx buffer so do the partition_info_get directly. + */ + 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, }; @@ -568,6 +683,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 ) @@ -597,6 +713,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 Mon May 13 19:10:41 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=1690805773; cv=none; d=zohomail.com; s=zohoarc; b=SXPEDVdgOipshGS8lcMOZ7+fEemgEJE4umjGqJCswdaxQME/7LbnVwO1LQVdUS+mWJ3Z2r7qnz5MUvtMGjvj8dchJTHjSxr9UF9woddRJPwj6qPdcYya7VWjgH/7wAUccmW5z88mGH+apxZJ7ysl8+l9GibtRX1HfyIRu3rWaxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805773; 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=/VXgpYeEzG0m5+ymIEw5RAHkfT6uMITIdBZHbBu8of4=; b=i08qH6w33E15Rpfahnmu92cBUeXWr8gqLG0ILooYCybMqBn8r9LINp8eZGL/jzNK6Ru3N2qSprgoYC/I0Ch8qbt+xugPqD1wCl2XP1/FANakgpSEr+52uaVZZFL+zMk4hHPTMcWftZ7D1XLqdwhOXG7X5RQjthSvii/XxprOxVo= 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 1690805773109897.4579767091286; Mon, 31 Jul 2023 05:16:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572966.897188 (Exim 4.92) (envelope-from ) id 1qQRoV-0005RQ-6m; Mon, 31 Jul 2023 12:15:51 +0000 Received: by outflank-mailman (output) from mailman id 572966.897188; Mon, 31 Jul 2023 12:15:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoV-0005Qc-1C; Mon, 31 Jul 2023 12:15:51 +0000 Received: by outflank-mailman (input) for mailman id 572966; Mon, 31 Jul 2023 12:15:49 +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 1qQRoT-0003r0-JJ for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:49 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fc10b9dd-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:49 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4fe21e7f3d1so4304579e87.3 for ; Mon, 31 Jul 2023 05:15:49 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:47 -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: fc10b9dd-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805748; x=1691410548; 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=/VXgpYeEzG0m5+ymIEw5RAHkfT6uMITIdBZHbBu8of4=; b=ylKMKE+tWA3sQFzkBLH9O/Gvaxr6PeIWBWD5xkoUS5sVPn2oqRMwmZbVjaoBgpm3Mf aWk1g3xQVkh5vhQi7WD4zLYhnD17heG1mfAEZlLMv46YNO1x61gV/dU0fNwQ8+GVhKd/ 86G7CKl/GGfUSBGIWAa7TGUE3c2FTedoEdiiVPA7F6lXdKDVU2T/yWHs5+nS1ofWeRwE vVU0HG5HzVp5vtQHT1aqfCx4YfiIH9YHnxGtqQJXm6Xzt2bQ0ZULCVja/2Z9j69Wv210 RksnXvGmHaoNZq3fZXlGsBfmeXX1LgOdjwbTz4nnbR2rVio3Z4b5I3k2BkfMyAxpY6gs q41w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805748; x=1691410548; 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=/VXgpYeEzG0m5+ymIEw5RAHkfT6uMITIdBZHbBu8of4=; b=L7cvuoVpNPHqk+WaONjUMG6HRQEKJdXVvqQ6nPO7B4sARXAejH8l/cC0L9UcPw7WTB +IZ2JaIHQ3Xris5dsOKrOtRaj1qro+RNBgUx58mJxmSDXsOi5KMBBmztCpsOS8eXH/W/ LLPkY7cjEy6dIG9tdafejHmcoLla3NQP+zBd/7zbvg83TRgOAQVJ2qYsIvPNa03z1XUw mAWTaWNMgFK2hDsuNcgXJSC1rv3OocALGYCiiTsrO1qJRp7wGlI5L7xjVDM1GVfidrEi 38qX9OSyZLa4i37SL9MBC2zRqA+3v0H9PYeT4U8ZGqqZ9371LsIJm5YHrMFZrmoEl0gi NDoA== X-Gm-Message-State: ABy/qLY2Bhz+ORlz3hcYbJ3YDOf2sV0uCSEC58IvMqmkyPJ7B8t5dxAD fIpB8nD6rWSXxQlbNQesKYBtwj85/SEppmISc3A= X-Google-Smtp-Source: APBJJlHKfP93ROT2ikVBjmRWxK5rgzAl/WYL5PB49C+k4cV0Wxy88iM+jAhYzdMKjMdGYA/zrFaoWg== X-Received: by 2002:a05:6512:3290:b0:4fb:8939:d95c with SMTP id p16-20020a056512329000b004fb8939d95cmr5346679lfe.30.1690805748405; Mon, 31 Jul 2023 05:15:48 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Michal Orzel , Henry Wang Subject: [XEN PATCH v11 06/14] xen/arm: move regpair_to_uint64() and uint64_to_regpair() to regs.h Date: Mon, 31 Jul 2023 14:15:28 +0200 Message-Id: <20230731121536.934239-7-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805775018100001 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 --- v10->v11 - No changes --- 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 Mon May 13 19:10:41 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=1690805776; cv=none; d=zohomail.com; s=zohoarc; b=EX/3ky0cw85YKFS4JHT8MGuxIXHdWYvP+wi4NhKR1Kzf+BSIiQpcYdVizaAfGyqf7rvNCa86He0E+bJ9AbbCwUX1f0O9NrMytoYc/3tjoRxE2L7dP6j6tZRXePqG/epJ7I1Zs8FPK2nrXgTvemXp1Gflc7sWYRwGJUr3/6ZcbnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805776; 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=91TK2fSJgBDrNg5Gf6mzXvMddHme3pib23sjpSHTPK4=; b=E538fY14nynT8mN9deEzxHbAZmuJUjuGRCvOvSWfhahj2GQEnU2Yr3nFvACEC5zjFEI5HxcpMpYJm7aXf28bglwlZVaNMEfNkh0QJZ/JqMBgJAnD/21K/9jYU+0/qbdFokjJwRYs8nzUCtd0Jxk6kXy0U74J7AURSz8qyKDL57U= 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 1690805776326928.7160199585943; Mon, 31 Jul 2023 05:16:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572967.897199 (Exim 4.92) (envelope-from ) id 1qQRoW-0005jr-IX; Mon, 31 Jul 2023 12:15:52 +0000 Received: by outflank-mailman (output) from mailman id 572967.897199; Mon, 31 Jul 2023 12:15:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoW-0005jB-CK; Mon, 31 Jul 2023 12:15:52 +0000 Received: by outflank-mailman (input) for mailman id 572967; Mon, 31 Jul 2023 12:15:50 +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 1qQRoU-0003r0-Ky for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:50 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fcb18808-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:50 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4fe0e23a4b1so6932085e87.3 for ; Mon, 31 Jul 2023 05:15:50 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:48 -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: fcb18808-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805749; x=1691410549; 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=91TK2fSJgBDrNg5Gf6mzXvMddHme3pib23sjpSHTPK4=; b=V0wqe86VBSiXbh/GxV5ECzB54GWICIbLdhcdwtWNfjxZUXNhQAjKv/BYMd1hC5ge88 Y0IKkcze6XObSz/dtCHZub2KelLY7HPE5TG18ghaKmcvbaqEVGcDU5jQSj6lhpz4q9NI tkSklqRtW5i1fh14CtdMGpcTCVXHDlwfM4FPy3CloQ+DPAWJpgyRoiL1g+7zmA9oFzC0 s3iZP3//GiqlNicxqqjbicdxtF7Ob2eX8gTm1Km5Vf6bReQIqLP+6hDFMbeAjMdzw9Vw c/IocJ11mO4+IiAme2ZsyBZaEnIbR/Uxop5x9eRmN/LaJBOL3TA569JAylXAPtQUoUMj iyrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805749; x=1691410549; 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=91TK2fSJgBDrNg5Gf6mzXvMddHme3pib23sjpSHTPK4=; b=jRoSlp2jlwIGRGNty940REE80Z19tJjomSkHmgG4wEVE6y2uWGgo5e0h9WvLSGCrJj bxE7EdCk/mC9WapU1U0LduuJ210bQY5GSL8BzSnCjB3QcavM1d3e1xmkYHyFkCkvNFtI 74a7pQLHTM7/PztTDtUBVFG39NFh65bQmypt3SMKo80B/8z77hfjvVZ1CvqERyON6GDf SrNHQZUa85LKOZO48rYEtwbeuIe9wIpi/N4BsgHx5vyVLHpCg5sbBbx+oXzNpMsS2oxA lcpWrsSzos6b+cCEKTeVNYJUJh3BapnV5v+JiQR/bG9Oy1RzYix7q6QrFF/shvRC14bx w3Uw== X-Gm-Message-State: ABy/qLaAs0aE9hI74AUCuTPruTxIIyqzPuxCcIFZQoyiaAgdYEyOANq7 CmytWVNnKep4iJbkKkr4O2Ytpo3Nr39XxJyJc5I= X-Google-Smtp-Source: APBJJlGhQLfstVSoA8t0Yv+/XhY3VvcHDySUWZUqNz0i+YUUzC8MSTmVNfhlJqYKZQ8wLlurghV9Iw== X-Received: by 2002:a05:6512:718:b0:4f6:1779:b1c1 with SMTP id b24-20020a056512071800b004f61779b1c1mr5142914lfs.48.1690805749482; Mon, 31 Jul 2023 05:15:49 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v11 07/14] xen/arm: ffa: add defines for sharing memory Date: Mon, 31 Jul 2023 14:15:29 +0200 Message-Id: <20230731121536.934239-8-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805776556100005 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 Reviewed-by: Bertrand Marquis --- v10->v11 - Adding Reviewed-by: Bertrand Marquis --- 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 6c889bf97002..e0d1746f3bfd 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 Mon May 13 19:10:41 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=1690805776; cv=none; d=zohomail.com; s=zohoarc; b=MdBuyHK5tNELaqjnIgm+6P4zQ7oHthOqPjZyzA3FfjHlNW6oPQk6xngvzfhlxCWDfnWnfIdqsUmwtIOD/D8Doae6IeyxiDiKB2jVYbBRcYOzvUn4IdtGXO7Alsp9+B/QNuJjt+HDEYO2FGEpRNGCBa2yPdHBZwTe9dchZi97jrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805776; 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=Ra6bzn7NO+Bj2QIqg1KOF4qCATzBH3WWnRdNuT2ZsJk=; b=hcT3fV028Qri+cWdN0BQlNjT5QbllEzDbFSe5M29dsxaqQEN07y620Jb9U6fBArGSeFOc8crbXKeyMA0lUQMJbwC8bWkVlrNapnds4oGnf38WeGOSE5/98XJ1g9xXSQyfPeHzMMqTqYY7T8NdRY4fDDd1mpox+kOeT2jK9YnsFM= 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 1690805776334532.9833609468661; Mon, 31 Jul 2023 05:16:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572968.897203 (Exim 4.92) (envelope-from ) id 1qQRoX-0005sv-4e; Mon, 31 Jul 2023 12:15:53 +0000 Received: by outflank-mailman (output) from mailman id 572968.897203; Mon, 31 Jul 2023 12:15:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoX-0005rU-0a; Mon, 31 Jul 2023 12:15:53 +0000 Received: by outflank-mailman (input) for mailman id 572968; Mon, 31 Jul 2023 12:15:51 +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 1qQRoV-0003r0-PJ for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:51 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fd64c346-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:51 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4fe07f0636bso7121423e87.1 for ; Mon, 31 Jul 2023 05:15:51 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:50 -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: fd64c346-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805750; x=1691410550; 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=Ra6bzn7NO+Bj2QIqg1KOF4qCATzBH3WWnRdNuT2ZsJk=; b=jsPWksmQaVnXCdmZ0VKCJytk2yXrXjtkIS1Jqd9Ht5F4lFa8BVhrdSeLd1XqrLdUnF WX2RFQ5f+uaAvQDO09ANKhhIHoibC7td8iPebZC3Z+5pvxeGPyI0gd1fgBWLXGR/vv9Z 5RrkMuQunnMjxgRQc7AqDywMxl5pwwlSLselyQHWuA1PCEVuPr/ZhDvNDZMuAMCLgGil 0v3rE1fSY+rx3rzz79QNUJsklmNXZREgpjFxAX5/THhr9Sp7bVGDyYmi10n5DDBJpkDw 3ltUpR6NcEl6iloXWhbHf0j3u1pPDFlfaJC0cMUk1mqZODNPd/sFHJjgAkB5spaGVlFR ZBnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805750; x=1691410550; 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=Ra6bzn7NO+Bj2QIqg1KOF4qCATzBH3WWnRdNuT2ZsJk=; b=Lwys28J2PwQjOlfWO1cUjlU8NB7X2o4A2+Ws8KqBcPD7nVAmuOierja4cvFnGOJ6AZ ix1o6/1JQzZmpYom0XPzWQ1l8UwuXB9frIA+AOYcsCT17I04CgD+fo+D9AEVJaMhidzl rpHp8IES9+n301tPdiSvMcpvvohejoIheOKjA2PPaz4K9SVE4Apfnm6Kldj/JADvmVvR G56R9mrs51gPWUaIFnULf29HPT/PBx59KCWPOzBV6tBUgipAgZK6mnsc7NnAfmbklPNm dFYYgDe7DONZ1g3nHfhNQnYY6Z2rcpJtwrzS2Va+2K9beIuPDQFdwma5KkQ+vzSOzirN csHQ== X-Gm-Message-State: ABy/qLbCimhsYE1yIrTjNWSddfePcISFHTy4mMKvpbE2DEh47pfErF0W sdQuT5u/EVcOmMDFHQvpVD7DgDlNJfG3lRgg12Q= X-Google-Smtp-Source: APBJJlG56YNcj8dVMPrIORRIRMloOKThCd3L3exybXwsNk8fmMggAuHfiku9rUraKur4MeQpSuK1lA== X-Received: by 2002:a19:7401:0:b0:4f9:69af:9857 with SMTP id v1-20020a197401000000b004f969af9857mr4090577lfe.51.1690805750658; Mon, 31 Jul 2023 05:15:50 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 08/14] xen/arm: ffa: add ABI structs for sharing memory Date: Mon, 31 Jul 2023 14:15:30 +0200 Message-Id: <20230731121536.934239-9-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805776980100007 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 --- v10->v11 - No changes --- 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 e0d1746f3bfd..9927fdf78af5 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 Mon May 13 19:10:41 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=1690805780; cv=none; d=zohomail.com; s=zohoarc; b=mvaZ/efay+NddSofn/RJGIQ8iDYhhqKdyCEfJI6UpDnSUqz9PdBr45msPmafrNz9bYSZpd5Q0JrpowLt+PDQD+Lp8Jm8K/YT5HIABrnoPCjzmhikTtRE6YYlCo41y5muTXsmw8CI6OuB47saPfzk99c8tXP1M6vozJiYcxMzZSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805780; 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=sOD/fTW4qR3MvnkEx+WBHt8FnCjpvsBZaFI+mewckws=; b=cK8zH9Pqqadqddp1RAhSc555g9BO6NcmzAHMzspqysn1dZ6VHh2lkXtI42Mq1RVanm7EiIjHAAF5l5YzTbsgzyfuSNjRqX2P54wuRVwEClhe9+WDt44LK0rPlLx3RtYASoTGw7BBjLE3g4XZ8Ede0rNM1QiBAQeYSs1L8XIgn1U= 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 1690805780054765.825813038164; Mon, 31 Jul 2023 05:16:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572969.897218 (Exim 4.92) (envelope-from ) id 1qQRoZ-0006Pq-LI; Mon, 31 Jul 2023 12:15:55 +0000 Received: by outflank-mailman (output) from mailman id 572969.897218; Mon, 31 Jul 2023 12:15:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoZ-0006PJ-GF; Mon, 31 Jul 2023 12:15:55 +0000 Received: by outflank-mailman (input) for mailman id 572969; Mon, 31 Jul 2023 12:15:53 +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 1qQRoX-0003r0-IM for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:53 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fe2a3de0-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:52 +0200 (CEST) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4fe3b86cec1so796177e87.2 for ; Mon, 31 Jul 2023 05:15:52 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:51 -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: fe2a3de0-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805752; x=1691410552; 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=sOD/fTW4qR3MvnkEx+WBHt8FnCjpvsBZaFI+mewckws=; b=r9L0kw2Uh45MiFpmt6ntDguYPitlL6+6FglkdTG0yVMv8wmGb2I5zbV5K2ZOtg+Dst JlWyjo8v9XyBkBBVt5j8cIxLBpZuex/SSxUAs0sIQH2NVbc7jUQm2EHa1YVPyY4ZB1Fg UX45A3DRVTC+c7JncuiFLeoQld8/glpX9AcMfT7DJgs3b4RJ2Xw8DuzpzCwULQ7QrI7Q NP2VitBXKqfIsDvZVGyeHFoZc8kOvsaKd658/20yGnHhBFQEfMmhBOYg8X7cMqcG9yaz v6/wJMZommqs86F1pkGtN2job5cMYdvOGKsA7fo04IMG3FRphHLnmO/HgXc6aacq4kuy dx0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805752; x=1691410552; 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=sOD/fTW4qR3MvnkEx+WBHt8FnCjpvsBZaFI+mewckws=; b=axOrKJmjuKZ1nKS+uMBqXirSnUXoFrrRAXV3dei3v/77RBgoIzacrREqgLFWkm1cNw OoNLldZpapzfPGirBRE43FLQUr5gjabSnDH+FyEjUfJ9Ya1SP7ePmm5cYgfDreyI8FQU Q7O40JElSZkyVQ6bt0jVLl4L/bg/+F6DlBOgzA43NW4UCOlrP4dSJsniMCQA6PTChkJh clr8vTOGtr1uyPost5uS+j2p2yZRmBija7VuKco32j+UpV+yGachj8afQZRu3h8q2pv8 8NzWmWy2osTp1G4lVQJSZ9PKElAz4b8RsFkDR3XWydEnSlZezUTnHV5nV/3Jij15B5o8 WmXA== X-Gm-Message-State: ABy/qLYYBGr5D+Itvu0tCo9kppLhXyYNHlk9lh9EDE4aXJR7HYXHqlXl CWJ3U6mfs61YzOkTw+aN8j1N/W4j2GvDO6kkQU8= X-Google-Smtp-Source: APBJJlGBfdFlJGG6imObY22ExZ5FWXAcbu98zQ2+8T/z82liu1HGaOD6Dodya2U3hAm9S+mIOgdzUQ== X-Received: by 2002:a05:6512:3b13:b0:4fe:c53:1824 with SMTP id f19-20020a0565123b1300b004fe0c531824mr7430714lfv.40.1690805751906; Mon, 31 Jul 2023 05:15:51 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 09/14] xen/arm: ffa: support sharing memory Date: Mon, 31 Jul 2023 14:15:31 +0200 Message-Id: <20230731121536.934239-10-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805781070100011 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 Reviewed-by: Bertrand Marquis --- v10->v11 - Adding Reviewed-by: Bertrand Marquis --- 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 9927fdf78af5..74e3ef50091e 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) { @@ -805,6 +886,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); @@ -862,6 +1340,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); @@ -904,6 +1386,8 @@ static int ffa_domain_init(struct domain *d) } ctx->create_signal_count =3D subscr_vm_created_count; =20 + INIT_LIST_HEAD(&ctx->shm_list); + return 0; } =20 @@ -1094,7 +1578,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 Mon May 13 19:10:41 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=1690805778; cv=none; d=zohomail.com; s=zohoarc; b=H67m4dQ74ZgpwUTiNB7Op7aivR6R8O+GYaxi5uW9tVWigwh1HSvRZ5Xf9WNYlI7ZK6laiXvdUVX4M2fGAG62SOaZF23re6R1K5xioQmggfiM0/zmiGfuEQCM9WxbWpq6Q38mG+Yf7QKWCdu/C7gqLg6ME75SHU+1MNqIg4u64S4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805778; 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=g4vSjtYXla7KgcWjbel3A+vRKKWcV7JLHovFCdSLbtg=; b=lGRkwv093m4lcwoJGa0ysUe1Rd3S/lSfOShp5G0Xb0XtCZvct8b6Vu4nxK+Y//C6SmOxpxv32+AS8+KMnum+KBEwv2vYasYaAlE5JNZlWLm+H1Yfz/3tObmPQdPo3wVmbCj4PoaERoSQ6JsyP1Kerf91mji6FtvpNNnHePuMs6w= 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 169080577856653.47440939027797; Mon, 31 Jul 2023 05:16:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572970.897222 (Exim 4.92) (envelope-from ) id 1qQRoa-0006T7-62; Mon, 31 Jul 2023 12:15:56 +0000 Received: by outflank-mailman (output) from mailman id 572970.897222; Mon, 31 Jul 2023 12:15:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoZ-0006Rz-TX; Mon, 31 Jul 2023 12:15:55 +0000 Received: by outflank-mailman (input) for mailman id 572970; Mon, 31 Jul 2023 12:15:54 +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 1qQRoY-0003r0-AW for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:54 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fee65c95-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:53 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f954d7309fso5499468e87.1 for ; Mon, 31 Jul 2023 05:15:53 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:52 -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: fee65c95-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805753; x=1691410553; 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=g4vSjtYXla7KgcWjbel3A+vRKKWcV7JLHovFCdSLbtg=; b=Z8pYQvEZVC1Z3Epa1PSdfPQ4kTcwio3hoQ/rKCmzlfp7teuipYKhOMcq6E95EaOZ9A JsHKlMfjqzThJb4Rg+J/LISRj2R2QLaCC5AvznHwr4svMOSdgF8DiUlVbcHeA9qH4tj9 GjSIsTN5yTygaafkhb9AMeqwjeWJgsXK6V8nB9Nq9Om5riuFkPDSBBgxzUMcF5wWnp/O bpKba0kJm6D7v0dJ2r1eoPHJ3sSTkJQ3i/wDKtN/O60yZVeWKLMlG8cTrFXddW9bt4DA ho3gCeUBzL5Kl4R8TrIATVLQXIg0DHeWzBVACgGknXRXL5K30aYwo537mW3LlzEMOt/v YGnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805753; x=1691410553; 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=g4vSjtYXla7KgcWjbel3A+vRKKWcV7JLHovFCdSLbtg=; b=hUQXmD30s1MJSnc08B1+d0RSFoTe4JAj4Ly3nxZnwN2P+W5d/EupWaTrT5PiitNA4h NelKZ3v5Il/RfVnocPxL9ygkovK3vUr+XDhSVz+IRXa8m3nGbklWPYLumgBNyS9nr+KE r4MUNoDXUJkIfGjW6SuvLhMfll3vRVhAF1xkmw7X9loPbvjOT+vP/7a2AlssR/k4q7Z1 cSsJNvADOqSRn5sCdwA7HY1HdoRzypcJCjmqyc8CDkiEkr1PmV4vjKB5DuD24oaRPI70 385mxgGnlofqiP992l1wXeTEnONfU1c+DfwVX9MQrKy5gFulR9ihv+Iptf1twm9uhZ96 +FOg== X-Gm-Message-State: ABy/qLZbJGvemw07vEGyT99y8nfINM3zmmt2wDC9J1XEP1UpoPjMS1K4 lK60BG3lvuyLSXLphpS0jm36MZgnWjlIw/spgyo= X-Google-Smtp-Source: APBJJlGcyr+7aeiaGR8us8V2/Q5tdSMajkMdzYPMDVuV4rkMvRbZjxFRnnARAAPA2I0ZLR5B7Mr3/g== X-Received: by 2002:ac2:58e8:0:b0:4fb:fb4e:7580 with SMTP id v8-20020ac258e8000000b004fbfb4e7580mr2872942lfo.8.1690805753285; Mon, 31 Jul 2023 05:15:53 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 10/14] xen/arm: ffa: add support to reclaim shared memory Date: Mon, 31 Jul 2023 14:15:32 +0200 Message-Id: <20230731121536.934239-11-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805779011100009 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 --- v10->v11 - No changes --- 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 74e3ef50091e..75700938c444 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) { @@ -1283,6 +1289,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); @@ -1344,6 +1387,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); @@ -1581,6 +1633,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 Mon May 13 19:10:41 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=1690805781; cv=none; d=zohomail.com; s=zohoarc; b=kkPIgLjJm4BiZ0Mb9pJN9gWmbVVilq5tIP8L4rUXSkK9frol/k+wRSCAq4BRHRadXyAjqYTWCA7UU3eGrOUTBxKUF2bnL+MuH2yzXx0IVuXNzXnyrckZlaTh6u5Nhyl8y0fXlfJl5ZCVKbt+Mzm28xM/AOkDKIDJWdJL56a8rmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805781; 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=O7Tv43Fw+2yJGd68qd39ntIRSoYO8/W65g1z0p43Q1c=; b=bqAsxZyYVmDB+OBXsbuiANVjx5+S9ymPq/5n/Ru4Cbq3vfhMVgIfBclRmj2p6zNuEx8RAiwzb3YpElDADTw5MzIjubCbsXSflKS3oJh6g/XytAjNfXDhYOL/ReT2NYlO3076AaWJsHFxj5n/C4A69Q1DPBWu/vvIzefJnG77drs= 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 1690805781129824.7808445610034; Mon, 31 Jul 2023 05:16:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572971.897233 (Exim 4.92) (envelope-from ) id 1qQRoc-0006v8-8K; Mon, 31 Jul 2023 12:15:58 +0000 Received: by outflank-mailman (output) from mailman id 572971.897233; Mon, 31 Jul 2023 12:15:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRob-0006tS-Ri; Mon, 31 Jul 2023 12:15:57 +0000 Received: by outflank-mailman (input) for mailman id 572971; Mon, 31 Jul 2023 12:15:55 +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 1qQRoZ-0003r0-IZ for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:55 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ff9b8268-2f9b-11ee-b255-6b7b168915f2; Mon, 31 Jul 2023 14:15:55 +0200 (CEST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4fe2de785e7so2218098e87.1 for ; Mon, 31 Jul 2023 05:15:55 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:53 -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: ff9b8268-2f9b-11ee-b255-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805754; x=1691410554; 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=O7Tv43Fw+2yJGd68qd39ntIRSoYO8/W65g1z0p43Q1c=; b=HNicUyZ/f8BHG2++n3STRpiLZeJeB53CC2UwqdczD1LpkV0s2EiCtcoDBgtmPGMkvW uH04JN45w/JPf7V3Hawlvkc2eUFKpqQt7VzsiZ33l/81iFiGYwGpm/5xiSmuajeIUenx sfVTO5tdePuKXLGN10UCv6e4Y8nj2WWm6YxirRWeUguy1UAHwgm6nsgWYcXAVLbRPZAC AHCkAafAIaV0baK9XDSWLqISFh75kdRxdbuwtfffT076r2DY9Q/PmgEMru5TOh/0FqDp 9F3GXcWyqspv9N3FeJuOuxMhH8NWN7xzM0LoggswRWdaXf+mqHjIz44SExIUiW0aujqi EH+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805754; x=1691410554; 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=O7Tv43Fw+2yJGd68qd39ntIRSoYO8/W65g1z0p43Q1c=; b=S4Uwp12kH7KPhLx1EiXVIXiJREpzaf8WCQ4knZlf4T1/anTwoDp3h5RpxAk8UAu+ZS vZmyThqV26/totY2TMqQW8YTZvagIkp/Ut24gLEi1Y+BDr/iIkqLJmV1ZfesRxzc5GEh kyd2r2mDpRrVTJgUCgPDqAA02fcVfx0D6XDy5rANmX3aJ8SFHL70j+uJx5Aw1Q+nRbwg cw0Hc0FTY67V5td8OB3JXTxj1pU/V4yBI9vV19ZH/mM2Ds7u32dZU8vRc02jiIeWItnb v7Ie+Dl3FqGe5MpOvWP9M8eQHLJykLs4lfNMd1Xehzle7DdBmehmIir8PzR2rH+tazuY MFbQ== X-Gm-Message-State: ABy/qLaT2Stk63+tsverqTrWCDU75opiaPbuhSUVV0Ott+UVxem+OD4b rOTELJVPZtby/J6c3DZ5Ql0YPioo0z24UsS1EGc= X-Google-Smtp-Source: APBJJlHt6A4biBbVLpbbAllO8aE4h4H2Kr0DxMGPdsBcldHgd9k70UTdq+YFs/UC2fXBZOo735pfog== X-Received: by 2002:a05:6512:2106:b0:4f5:a181:97b8 with SMTP id q6-20020a056512210600b004f5a18197b8mr4652307lfr.25.1690805754348; Mon, 31 Jul 2023 05:15:54 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis Subject: [XEN PATCH v11 11/14] xen/arm: ffa: improve lock granularity Date: Mon, 31 Jul 2023 14:15:33 +0200 Message-Id: <20230731121536.934239-12-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805782759100013 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 Reviewed-by: Bertrand Marquis --- v10->v11 - No changes except resolving conflicts since "xen/arm: ffa: support sharing large memory ranges" was dropped. --- xen/arch/arm/tee/ffa.c | 107 +++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 75700938c444..eb4a58fec470 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -363,6 +363,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 @@ -768,7 +775,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); @@ -819,7 +828,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; } @@ -830,13 +839,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; } @@ -947,21 +958,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; } @@ -971,8 +1004,7 @@ static void free_ffa_shm_mem(struct ffa_ctx *ctx, stru= ct 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); } @@ -1180,7 +1212,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; @@ -1272,7 +1308,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 @@ -1280,7 +1318,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 =3D=3D 0) @@ -1289,6 +1327,18 @@ out_set_ret: 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; @@ -1299,29 +1349,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 Mon May 13 19:10:41 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=1690805782; cv=none; d=zohomail.com; s=zohoarc; b=Yq2M+wKZCorl99FmdB0DLIkNdOCgHnFzviWk4XG0rs5ZjsByojC0nxzvpv3reD2ooCkDDdHp/OQ/m/daBmaNjAZgIxx9avcwdCT13BWCeCriViAr62sc7hXI+xxKZZczuhhMT4+huwJcF1sxv3ajni7EwsvkMdNUOVNV7hlgSWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805782; 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=UKqs7nnqnAqZUU+7Ywvxf/RqUSRtJt12JR8UMGzNweA=; b=lQP20Nf7i5APSCSe9alVoHUwUzE7kvxu6cFudXjJamnzz8qqSSTx9nZN56hVcQ9QmVkBrK2anDwj6va4NTFw2vWMRVIbzooQ5qQVgACbYTZw+P+QMgOMzp/JkyHzC9eW7VXkLr9ExVBOFPaOIPAw78NG3wpQw8tOODPlzjWvWHU= 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 1690805782629752.5974508790514; Mon, 31 Jul 2023 05:16:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572972.897244 (Exim 4.92) (envelope-from ) id 1qQRod-0007Id-V6; Mon, 31 Jul 2023 12:15:59 +0000 Received: by outflank-mailman (output) from mailman id 572972.897244; Mon, 31 Jul 2023 12:15:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRod-0007Gp-CA; Mon, 31 Jul 2023 12:15:59 +0000 Received: by outflank-mailman (input) for mailman id 572972; Mon, 31 Jul 2023 12:15:58 +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 1qQRob-0003r6-TN for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:57 +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 00673a30-2f9c-11ee-8613-37d641c3527e; Mon, 31 Jul 2023 14:15:56 +0200 (CEST) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4fe3c7f16bbso619289e87.0 for ; Mon, 31 Jul 2023 05:15:56 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:54 -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: 00673a30-2f9c-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805755; x=1691410555; 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=UKqs7nnqnAqZUU+7Ywvxf/RqUSRtJt12JR8UMGzNweA=; b=ols1N8y4SdzG4xgNYq24Bjwkmi274DQHDrIhNrjG1U+kWelPknIJwF/LRU++vdHMQc Mf3jRxWxi8+zWEyak04fmZSAKClZkrHLj+F+cqR4FZX7U3+wXw/+zOX4GAL+A56uElFD T0i44b11AsVDGIVZz4UrtaZeAxZdi3ppfHAKpD3QTCw7rlQsv/unOTUo2hB3SwE9xLvK 3NtyOa+zzvyzkpjIrw74flofN2Io+gRAEpHQ520WAXXU7PCrrpAAWQoKluD325Gt92iD KzxVmzVFoPHY9MCU150TrN5CBsCyxbM5sVBjKUAwKL3cwTiofCm2JVd7s1vGswqEj2uv vXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805755; x=1691410555; 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=UKqs7nnqnAqZUU+7Ywvxf/RqUSRtJt12JR8UMGzNweA=; b=K71iDFUvGeOWgEt5FVAQZY+6fYr+O7lH28rYyLVzPDQaesRF7YCYLpuNb/fXW5nqNW V+qq2ErzokynwDPGigZucP/a0puJxnnu17X8V4lKUmRv3CXgbotpa3OWmMgf4nyT8E3N VRIMkSMjsLRqU3sixgM/ZL5tihsYrACCBjiT8wAqmo/Kdmqx2PMhwInfdHf2lcrdqTcY umUQHu3FKW5v/pxflfzr7RIenvZrAswc0l1B5ucIK0EdKv4aH5r3P6jBePWrI+dv48/t tm3MwxfDlR6pEL5KdK18rG30BRibBSIdWpLmXJbRfRKEn/NvJ/y0Da7jo1aiZfL2VKZi DaMw== X-Gm-Message-State: ABy/qLZiOk6qFnVLhWTt3Vu6hrSH+oLRzuooc8pXHxRiDe3g4bjuKNDN ZvOKgut7OEo5gg6cVee8lJevR9wwbVIr477s3yQ= X-Google-Smtp-Source: APBJJlFQ8wjatPqFLCOvaNWX8BW9Midq9eZVdN6JmRM/NJRvRDq/8s8JyDoMNFvfobeeWdiIjm7BGw== X-Received: by 2002:a05:6512:3da0:b0:4f4:c6ab:f119 with SMTP id k32-20020a0565123da000b004f4c6abf119mr6902072lfv.64.1690805755586; Mon, 31 Jul 2023 05:15:55 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v11 12/14] xen/arm: ffa: list current limitations Date: Mon, 31 Jul 2023 14:15:34 +0200 Message-Id: <20230731121536.934239-13-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805784761100015 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 Reviewed-by: Bertrand Marquis --- v10->v11 - No changes --- 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 eb4a58fec470..cfbabec81dd2 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 Mon May 13 19:10:41 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=1690805783; cv=none; d=zohomail.com; s=zohoarc; b=hGJlDqMXwhaZcr7/yFheO2Cc32LCx6InuzrTppleTqVPOF+gCD8z/XzqO6//YuLEV/YZOhqaTMOO4nsXb/p+skFGuxZuovQ3k8c+WEosSORY0fZY6i6qTPncfA6z2Y4l2PuWsy6L49rIVZBtlqgnHMEbpBBg6DZa/KiqdNmlWFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805783; 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=F6DPe1jvY7rersaps1H4x8200JLUC6kxOQle79BMJ3w=; b=MqnMgefHkbkxpDEefdvK/jVJ30BxROD1hfyBJFnSN0DeQCtO3Pia0raMLcGSsv9EZa84a8wkqjYbTt0eKoBvkLUO/UGCfTELdNzxRu+k65pSte8tm61BRPUOhkA2DZCuYsKaiD6TAS5Cg36w1YXJo7MEi+/CX0SrX+vzT+rsRpc= 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 169080578357269.39627600973085; Mon, 31 Jul 2023 05:16:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572973.897254 (Exim 4.92) (envelope-from ) id 1qQRog-0007zt-3U; Mon, 31 Jul 2023 12:16:02 +0000 Received: by outflank-mailman (output) from mailman id 572973.897254; Mon, 31 Jul 2023 12:16:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRof-0007yg-R5; Mon, 31 Jul 2023 12:16:01 +0000 Received: by outflank-mailman (input) for mailman id 572973; Mon, 31 Jul 2023 12:15:59 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRod-0003r6-IG for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:15:59 +0000 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [2a00:1450:4864:20::12e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0151d164-2f9c-11ee-8613-37d641c3527e; Mon, 31 Jul 2023 14:15:58 +0200 (CEST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4fe1c285690so5939120e87.3 for ; Mon, 31 Jul 2023 05:15:57 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:56 -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: 0151d164-2f9c-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805757; x=1691410557; 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=F6DPe1jvY7rersaps1H4x8200JLUC6kxOQle79BMJ3w=; b=YbLBt51bWU+HuvJn0TGGLBvRUUFEFj5hJsHmr2IEOTqZQgX7SG0kfH8Iw81tSDTIEz r00BSXSJYyrW4ADR6kcRlxZjKRvqQvK0JXKt+8YfBu0RaByt/FVzj4SrTPNZWXlhoVmc JlGd8kzNh/W4NRAZI1vhfDoDfq4k4RnZEJUt4aMDeGaDKqdCRdMBx652qXuYCy83wMrO Lyk/vmkgbInZnr4MKRN+8aPFBIxRAJv9+3edSuRAWyqBWpwR7ZMg7ZfFmwrpPMCJByLx WALNsJ555CFMF6Zr/teDX3t+Sy3r0wqt6xgy69+of5NUhQ3rqZ0IV23cZc7YVSZBS3ya mS8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805757; x=1691410557; 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=F6DPe1jvY7rersaps1H4x8200JLUC6kxOQle79BMJ3w=; b=dItDanE+P6xbdcC6YqFIOF0rNKV2fSpUach6GjR8fGq0eYCDsF0PwQfPVp/CV6NxXP xPqUdJKwOUzy1vAKY+dnYC1whYzzYT7QqP+A/QO/d81By/j9MW/kYhJP/d1R/gj3w+se kdKQaub2sEuJVTJOajLwljBSbcfn7uJbjQAyvZmeuLAbX42Ah2yXRlbsSq3Eg2XFptOy Zxh83YSBtS3BfFwHDr7rQGawmCTLG0OOHPCsNb4yjkl5Yi+/uy7GrHLgPUcuHOb/5/9N 9Bukmd4iThjh6jDGfIUBCyH/sihuP8ASmw9cXYmgTdlqwnpw76yEkkQDE2NaafSIYK0f 5ucA== X-Gm-Message-State: ABy/qLbDAU4WMtmjwwFeWlL+afEwbYNMTNFIg2KSG5daVPQCSgZSw4AL q/ijnTJi2vhR751n2jV9+chXIwCTaxhcW6+xCso= X-Google-Smtp-Source: APBJJlFKmXITZt0r4z+c/dlQvrr59iXjr59ZLc8lpfQIsDNZB7RFSH42uxv9CLuKatYEqcpZcBvRFA== X-Received: by 2002:a05:6512:3e7:b0:4fe:79c:7269 with SMTP id n7-20020a05651203e700b004fe079c7269mr5159360lfq.67.1690805756910; Mon, 31 Jul 2023 05:15:56 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Wei Liu , Anthony PERARD , Juergen Gross , Bertrand Marquis , Henry Wang Subject: [XEN PATCH v11 13/14] tools: add Arm FF-A mediator Date: Mon, 31 Jul 2023 14:15:35 +0200 Message-Id: <20230731121536.934239-14-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805785167100017 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 Acked-by: Anthony PERARD --- v10->v11 - No changes --- 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 f3975ecc021f..bcf290de2446 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 f98e1affa294..15391917748c 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 b524d1578bd1..3bd66291afd4 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 Mon May 13 19:10:41 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=1690805785; cv=none; d=zohomail.com; s=zohoarc; b=WGtBH8co0Y9rjgM0/CKfh3n1KvBLDRGOHkpkoRO2ksygCx4u0qjcY2u72zVih0v9tRkF45uy2tQw1IbXsj/xDTz+YU7598Z5HuLNmyzQojmCrK3YmhQPRTJ6/sq7+HKgp6Rn30+NSqY4jk1B/4flXlLu1QhTDGqdPwUdAPbzNmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690805785; 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=gBs/FDkfYRgoPZr2GGaB11R97tPaKWbGqww2/VGZEhE=; b=Tj0FtLoM+mm+Hb1/YaHT7M/Llbh+q/NrcXhijxSDm43joqrKaFmNWEr9mU/nGAxrGTWwTIB0TADaSMTc2RG8ol8zu7OMmhs6zJxPHAWKkvrUqG/7uPVL8h1G+0lmxOfkwYonPtnd08DvsuVVpQ1XcmWE1F8r53SqP8K67zWCEAI= 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 1690805785763670.9583566369948; Mon, 31 Jul 2023 05:16:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.572974.897259 (Exim 4.92) (envelope-from ) id 1qQRog-00087y-V4; Mon, 31 Jul 2023 12:16:02 +0000 Received: by outflank-mailman (output) from mailman id 572974.897259; Mon, 31 Jul 2023 12:16:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRog-00086U-Hr; Mon, 31 Jul 2023 12:16:02 +0000 Received: by outflank-mailman (input) for mailman id 572974; Mon, 31 Jul 2023 12:16:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQRoe-0003r6-JW for xen-devel@lists.xenproject.org; Mon, 31 Jul 2023 12:16:00 +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 01f72e92-2f9c-11ee-8613-37d641c3527e; Mon, 31 Jul 2023 14:15:59 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4fe10f0f4d1so7287058e87.0 for ; Mon, 31 Jul 2023 05:15:59 -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 l10-20020ac2430a000000b004fbb1bc1ae0sm2028077lfh.163.2023.07.31.05.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:15:57 -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: 01f72e92-2f9c-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690805758; x=1691410558; 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=gBs/FDkfYRgoPZr2GGaB11R97tPaKWbGqww2/VGZEhE=; b=mv6YspaDGeTi1WqN/SF31Z9c0+2y2PjHwqOv8iuM7N/eeNiBiSCC32vrqtXwnz7KUe z789FZY9VMV9eG/mcjtCNNHdeOp68HifeHRV5FRxCjuf/sV7Ly01q0OhT4qQC5Yjd2m+ 61wDbDACiqCaj8henceKNoRzaUV/7pGEBqTycamtITwEQuoLh4tupRelkonSXxhYb/3g NHlCBN+1RZg9Hx1+B7hOgUUIPYR3xy7n1wjbFiRVkpReyOTsIt0JdK0/dqFeywps6pV4 hX0muTBmlrXCl4lpm4dO4wyhjqX4axiB5LB5w5VKH08wDRlupW5Rt2tan5tIdWaTCZDl hdSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690805758; x=1691410558; 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=gBs/FDkfYRgoPZr2GGaB11R97tPaKWbGqww2/VGZEhE=; b=PDDBG9nY2P+UiXDbsV7Ec2jGkw4qKX/mVNoppthWroX0sNCOiIrszQcfErx9N3CXuy 76Cw7zgsIu2ije9bl1Es0Cpz99K4Y3G7Km9RVp++5l5ZAfPu0rD+hH06vRshNxL9ZjKX hBM2OehhIOV66WW1B9e1m/Gwe6ZL+IISJk29wPuFjbqdL9T36c3K+hGzOvcqBNIHOB9G kfuKS15v+rPMmhjwrGAscqyAR4rl8tla4JJ0Xv2oxcbGRrTSh2zJHcNOhYvI+G4W9v0g XXt/H8cZTiGZo+Eyz4iLJQ4WXZyKTTyXGmAGy71ygFGKP4mg0syWZPL6oOUvKkLivdhd kN1w== X-Gm-Message-State: ABy/qLYpHpXGXgx3+Q+VJx5cbQ8RuECrWqXk7C0kbGpSfcy/ngO6b1h7 W+7i3+ryVw/twsN/dRzN1OJ7UPOuulLsvfGEFIM= X-Google-Smtp-Source: APBJJlFHWP4N4SZZJsNudSOwkqOQW2CE9qoDGOLMrNEzkNM/i1gHC1PN5lQuy06JIsqlbb9MmrCm9w== X-Received: by 2002:a05:6512:3086:b0:4fe:629:9265 with SMTP id z6-20020a056512308600b004fe06299265mr7181260lfd.20.1690805758289; Mon, 31 Jul 2023 05:15:58 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: Bertrand.Marquis@arm.com, Marc Bonnici , Achin Gupta , Jens Wiklander , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [XEN PATCH v11 14/14] docs: add Arm FF-A mediator Date: Mon, 31 Jul 2023 14:15:36 +0200 Message-Id: <20230731121536.934239-15-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731121536.934239-1-jens.wiklander@linaro.org> References: <20230731121536.934239-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1690805786880100019 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 Reviewed-by: Anthony PERARD Reviewed-by: Bertrand Marquis --- v10->v11 - Add a CHANGELOG.md entry as requested --- CHANGELOG.md | 3 ++- SUPPORT.md | 9 +++++++++ docs/man/xl.cfg.5.pod.in | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7e0590f8c6..f24c8c4b8011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,8 @@ The format is based on [Keep a Changelog](https://keepach= angelog.com/en/1.0.0/) - xl/libxl can customize SMBIOS strings for HVM guests. - Add support for AVX512-FP16 on x86. - On Arm, Xen supports guests running SVE/SVE2 instructions. (Tech Previe= w) - + - On Arm, add suport for Firmware Framework for Arm A-profile (FF-A) Medi= ator + (Tech Preview) =20 ## [4.17.0](https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dshortlog;h=3DR= ELEASE-4.17.0) - 2022-12-12 =20 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 a2bccd5b48a1..ec4864958e0e 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1656,6 +1656,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