From nobody Sun May 19 06:23:14 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=1713771471; cv=none; d=zohomail.com; s=zohoarc; b=GmfJISIl97SkmKr/ty2v/IscGCP7tuhhTbxJh5MGF9hTlsJtuBpE4t/iWDi6YJwMAeR1tduVg0OXQlrRTk+OoJWbNMJbspQPLQS/p0VWbFOaHRH0Q6+3KQfCOpI2zaH7Mgvr/ATICk9Rh39zf9yiuD8+WVuFy0fYEEsCfurJ+0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713771471; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2VzeWK8x82YxZO3FACx+2RlqRVfXhRtSExk4PP34ai4=; b=l4Y4x6uIusvUUmuetFygWWJ+8oAARpmbl7SZtgYwPoyoqeaBfXxYU1kO15P7LMiBPD7dNKn1TnVu9JdZATx5umxag861zQPjgtWY3bOqJSeF4S2C2vy7QtPQOuM72Ni5WlHptibg/pcqrZK+7JrSRYmBDuHitdX6/LO6OmOoks8= 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 1713771470658964.0179767104948; Mon, 22 Apr 2024 00:37:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.709714.1108695 (Exim 4.92) (envelope-from ) id 1ryoEy-0006ho-Lb; Mon, 22 Apr 2024 07:37:28 +0000 Received: by outflank-mailman (output) from mailman id 709714.1108695; Mon, 22 Apr 2024 07:37:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ryoEy-0006hf-Iy; Mon, 22 Apr 2024 07:37:28 +0000 Received: by outflank-mailman (input) for mailman id 709714; Mon, 22 Apr 2024 07:37:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ryoEx-0006Sb-Dc for xen-devel@lists.xenproject.org; Mon, 22 Apr 2024 07:37:27 +0000 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [2607:f8b0:4864:20::432]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 29856638-007b-11ef-8b06-e9908f64f69c; Mon, 22 Apr 2024 09:37:25 +0200 (CEST) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6eced6fd98aso3860280b3a.0 for ; Mon, 22 Apr 2024 00:37:25 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id x37-20020a056a000be500b006edcceffcb0sm7221726pfu.161.2024.04.22.00.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:37:23 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 29856638-007b-11ef-8b06-e9908f64f69c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713771444; x=1714376244; darn=lists.xenproject.org; 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=2VzeWK8x82YxZO3FACx+2RlqRVfXhRtSExk4PP34ai4=; b=BRr1HZgeHXiJ1xOcD0StlhMj3Uk9dgUU1qFGyQPIgRQFKCxTvjNEc6dpiWjrjnvAVw 8dPyU/hjaUkj97IQrH+0xkRZKKZlnvR6ND/2IWV4mn7KH2rJQ75zfOpIj/uGTAFLwUYb uQrzF9d6Dh+S8N/YhQFzHNxdBKF6NSeYIEHtKGZEvZT9DWVEPEWotAFimWtmYWimWaYH glw51+rXIZYl//y9p/Myr7o2woo+0v7bfzQYvQAy3A+x5HYInWoaXBbnLhRSXvy71GqU kL146qmi499geBvrlmIoegq5OK1EgBzKcx/HnQarxoMLtYBDNO8bo6z3Wowg/kGhv++P 6HRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771444; x=1714376244; 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=2VzeWK8x82YxZO3FACx+2RlqRVfXhRtSExk4PP34ai4=; b=d0dglx+FKwCRu9PeMtJ9h7eGW0+7Si8U9Fp4fnxUkqIDN6y+KdDteHco9mxo32+dnv oxZlJPi9NXl1UVEb4OuD+7VkjVhOZhS37aRP57LAlhgt81ue7g0QSNooSbNRB37z4jK+ TKYpZCj3nSpkG0eCG569pa4v6Zl+CCWwmKaVAdffK5Yji9G1USjsG0aDPTrbsuji/2jH Z+leX5jS/dX2J7Jn0oaNu/fHADi9UDBrIeHb5J3PezD4NwH69exY0AUdMp1aWODvxRO5 ntbRQN7A5xIbvP+wTZNayYdrBZDl9y36TbcFueUZvUFd1XVfm/P6jeJtZQmYVhBj4z2X yqIw== X-Gm-Message-State: AOJu0Yzjfpxznv1UCVCnhJKjplVcGNrEkV7lmzI5buEfgDDUdbCMZV4A iUdusbq7hMZaA4C/ySxCAjNK2URZIHZRaTRlyhOTEJhRT9BOB6VEYb22idn4+Fu3k9DIs8FvGgw t X-Google-Smtp-Source: AGHT+IHvzUzQnmPOJwLqCNPYatbb81JlKVMMSj7eh2f/KL7gdQ+7f2dkOyd1cR6AGmf3KGwkBYHq8Q== X-Received: by 2002:a05:6a20:43a7:b0:1ad:a8d:dc6d with SMTP id i39-20020a056a2043a700b001ad0a8ddc6dmr6800017pzl.8.1713771443904; Mon, 22 Apr 2024 00:37:23 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel Subject: [XEN PATCH v2 1/5] xen/arm: ffa: refactor ffa_handle_call() Date: Mon, 22 Apr 2024 09:37:04 +0200 Message-Id: <20240422073708.3663529-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240422073708.3663529-1-jens.wiklander@linaro.org> References: <20240422073708.3663529-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713771471884100003 Content-Type: text/plain; charset="utf-8" Refactors the large switch block in ffa_handle_call() to use common code for the simple case where it's either an error code or success with no further parameters. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 8665201e34a9..5209612963e1 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -273,18 +273,10 @@ static bool ffa_handle_call(struct cpu_user_regs *reg= s) case FFA_RXTX_MAP_64: e =3D ffa_handle_rxtx_map(fid, get_user_reg(regs, 1), get_user_reg(regs, 2), get_user_reg(regs, 3)); - if ( e ) - ffa_set_regs_error(regs, e); - else - ffa_set_regs_success(regs, 0, 0); - return true; + break; case FFA_RXTX_UNMAP: e =3D ffa_handle_rxtx_unmap(); - if ( e ) - ffa_set_regs_error(regs, e); - else - ffa_set_regs_success(regs, 0, 0); - return true; + break; case FFA_PARTITION_INFO_GET: e =3D ffa_handle_partition_info_get(get_user_reg(regs, 1), get_user_reg(regs, 2), @@ -299,11 +291,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) return true; case FFA_RX_RELEASE: e =3D ffa_handle_rx_release(); - if ( e ) - ffa_set_regs_error(regs, e); - else - ffa_set_regs_success(regs, 0, 0); - return true; + break; case FFA_MSG_SEND_DIRECT_REQ_32: case FFA_MSG_SEND_DIRECT_REQ_64: handle_msg_send_direct_req(regs, fid); @@ -316,17 +304,19 @@ static bool ffa_handle_call(struct cpu_user_regs *reg= s) e =3D ffa_handle_mem_reclaim(regpair_to_uint64(get_user_reg(regs, = 2), get_user_reg(regs, 1)= ), get_user_reg(regs, 3)); - if ( e ) - ffa_set_regs_error(regs, e); - else - ffa_set_regs_success(regs, 0, 0); - return true; + break; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); return true; } + + if ( e ) + ffa_set_regs_error(regs, e); + else + ffa_set_regs_success(regs, 0, 0); + return true; } =20 static int ffa_domain_init(struct domain *d) --=20 2.34.1 From nobody Sun May 19 06:23:14 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=1713771468; cv=none; d=zohomail.com; s=zohoarc; b=DriYSJtZIlbS1cCXP4FYMxh3xrW088p0yee3SJk/e+2DQ6s6CAPEdOzxaZu+q/uyh/EMUWNYbcm8Wjy/jgsrGiPPSkKm1lUAGzcEc65k/STwIs0g7ggpKE7Y3FNJYC2NM28MLWKJuSwJeQLRPEwF9ThLOxnnefLy2Dmt3OmKR7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713771468; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Injz1eHKMU34CsdRACoEV/3/mGn5muvQCz5MmACq6o4=; b=JpEj5Y0VlbLBCz2HpHvWlrXJ2UpGc0bHeRIjr6KgnoljnqVlAgipooILWfwVIU4BeL8RtmVd8Lihy+eOzJtt1d73jEFGgm1ecpqbyqz+ZvB48lgVriny0HvScP3LxNiVsaz2VV5QbXrBnlYI9IxvG/3YDzwsOBtmtW2HZDcskDo= 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 1713771468374708.6553712747277; Mon, 22 Apr 2024 00:37:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.709715.1108706 (Exim 4.92) (envelope-from ) id 1ryoF4-00070E-2B; Mon, 22 Apr 2024 07:37:34 +0000 Received: by outflank-mailman (output) from mailman id 709715.1108706; Mon, 22 Apr 2024 07:37:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ryoF3-000704-VU; Mon, 22 Apr 2024 07:37:33 +0000 Received: by outflank-mailman (input) for mailman id 709715; Mon, 22 Apr 2024 07:37:32 +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 1ryoF2-0006Sb-Hv for xen-devel@lists.xenproject.org; Mon, 22 Apr 2024 07:37:32 +0000 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [2607:f8b0:4864:20::22e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2ca9e7a7-007b-11ef-8b06-e9908f64f69c; Mon, 22 Apr 2024 09:37:30 +0200 (CEST) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3c7510d1bacso978487b6e.1 for ; Mon, 22 Apr 2024 00:37:30 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id x37-20020a056a000be500b006edcceffcb0sm7221726pfu.161.2024.04.22.00.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:37:28 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2ca9e7a7-007b-11ef-8b06-e9908f64f69c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713771449; x=1714376249; darn=lists.xenproject.org; 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=Injz1eHKMU34CsdRACoEV/3/mGn5muvQCz5MmACq6o4=; b=EScPsunjKNdnDcAmcoaxTaN4DSWv8HaeAmTfbx6WonRnRB91JLa6+/7Qx/X0e9j6bO +D1B2/5bwqXgiWR3qNtLiMZfSgNsAprz2GeCss9/BC8zPYq16ZrogW5bQ+jMnF5wLnb4 kPg4PmCwEsLsoQ/d77/9B1hzBzCsQGNFug0eyXc9JcMmfsXUuotlkgD13CoGgzU/Tr/u /FcoTPYk16+1warChZog1ikoCUi7CkzGnkFEqv6RCivyIEmma1wQCVcfiJ5WVAbIJyet cXSf8/qOqQ1HuSGvaPAmnm78hog9SZRAjTbItisWStYxgFJNB8CkjdD0E9Ahm2qd+SYp 50qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771449; x=1714376249; 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=Injz1eHKMU34CsdRACoEV/3/mGn5muvQCz5MmACq6o4=; b=kn3kjAzOu+I9v82NklGcc5POnzTPYy879sexjmfNag4CBTrLzT/ngo7ZiKVjZC4VyX AchaglcSLm4p8Gt1D9ll+fayIi22lXZaZRh/ijH4Jvu1bplIzPI0P2RzOZIP396aAmIt DJRFWLCDdmZPOOroIlfLiXGhdqLeFpQtUfOQx8SV+6ccubQFXZwOVK8lmDvJ2/UN7Dcy nCw41n9b2Zp5Hxg/3yq24JAv2W3W5UBxLrDPXCVb1Q8l39+ONzwa+52feut+r3z4eUof NT3VIDCwf9oE3brCXeUS5cx0WBGtdnj9/bbjZJ3x0HQODVv840vkAkkOPJXv5Xe3Hxqy 0Jkg== X-Gm-Message-State: AOJu0Yxl230nivfqwO1XFHCAi8AY50h65QxwVW1pIudIbkoPEa+DlkpU hjAlwIVzvbQ1jUF6kwBqsrsy4NuvYKeqVPR7H6W2ku8prYT65br49cif+yOsYuTPO2dOXEC669O N X-Google-Smtp-Source: AGHT+IF8/Yq3GWuUme2jfU/Tj71Y6yTYZXpvsfQH19JqEaP37CxWt4rB7tdPh7TwB//e/GI2cqHXjw== X-Received: by 2002:a05:6808:b16:b0:3c5:e2dc:8a6a with SMTP id s22-20020a0568080b1600b003c5e2dc8a6amr10635627oij.24.1713771449345; Mon, 22 Apr 2024 00:37:29 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel Subject: [XEN PATCH v2 2/5] xen/arm: ffa: use ACCESS_ONCE() Date: Mon, 22 Apr 2024 09:37:05 +0200 Message-Id: <20240422073708.3663529-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240422073708.3663529-1-jens.wiklander@linaro.org> References: <20240422073708.3663529-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713771469915100001 Content-Type: text/plain; charset="utf-8" Replace read_atomic() with ACCESS_ONCE() to match the intended use, that is, to prevent the compiler from (via optimization) reading shared memory more than once. Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa_shm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/tee/ffa_shm.c b/xen/arch/arm/tee/ffa_shm.c index eed9ad2d2986..75a5b66aeb4c 100644 --- a/xen/arch/arm/tee/ffa_shm.c +++ b/xen/arch/arm/tee/ffa_shm.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include =20 @@ -171,8 +172,8 @@ static int get_shm_pages(struct domain *d, struct ffa_s= hm_mem *shm, =20 for ( n =3D 0; n < range_count; n++ ) { - page_count =3D read_atomic(&range[n].page_count); - addr =3D read_atomic(&range[n].address); + page_count =3D ACCESS_ONCE(range[n].page_count); + addr =3D ACCESS_ONCE(range[n].address); for ( m =3D 0; m < page_count; m++ ) { if ( pg_idx >=3D shm->page_count ) @@ -527,13 +528,13 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out_unlock; =20 mem_access =3D ctx->tx + trans.mem_access_offs; - if ( read_atomic(&mem_access->access_perm.perm) !=3D FFA_MEM_ACC_RW ) + if ( ACCESS_ONCE(mem_access->access_perm.perm) !=3D FFA_MEM_ACC_RW ) { ret =3D FFA_RET_NOT_SUPPORTED; goto out_unlock; } =20 - region_offs =3D read_atomic(&mem_access->region_offs); + region_offs =3D ACCESS_ONCE(mem_access->region_offs); if ( sizeof(*region_descr) + region_offs > frag_len ) { ret =3D FFA_RET_NOT_SUPPORTED; @@ -541,8 +542,8 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) } =20 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); + range_count =3D ACCESS_ONCE(region_descr->address_range_count); + page_count =3D ACCESS_ONCE(region_descr->total_page_count); =20 if ( !page_count ) { @@ -557,7 +558,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out_unlock; } shm->sender_id =3D trans.sender_id; - shm->ep_id =3D read_atomic(&mem_access->access_perm.endpoint_id); + shm->ep_id =3D ACCESS_ONCE(mem_access->access_perm.endpoint_id); =20 /* * Check that the Composite memory region descriptor fits. --=20 2.34.1 From nobody Sun May 19 06:23:14 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=1713771478; cv=none; d=zohomail.com; s=zohoarc; b=AXO6Kx0Hy0B7+wP48hbs8dB/q6F/2yttbZ+NnBTIMMAQqyJuZi44pAAlfj+rQXaHYY4IkfmMcCPwRNZHje26pY+BA0D6zhGM/VAGw5SToo0wTe9AdJ+XQgLZVlVb7QmyTNviyujPvU6OO8hm3vMT8z2eYYJlZ1bF7hNxct6Fr6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713771478; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XH0hx5FhOx9XD5Quim9d/dWx8ptFKhc8V8iHDPJ7zTg=; b=i9gGTjgghQrwdtuU6HHeEjvF6xYd5kz/n5a5RHQMu1DDchW1zzeEmzsji8hNFb6ZgU3IEN9bj41UCHU4DiAARWnkJwRddsD9SWtNWZ3BsZBRUHrGxB1akFDMgXRUnK2u8NrXSrX785Tl1pDkqdcnw/XJMSUvjwk1XPDdWTXQ+Us= 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 1713771478101841.5150066523522; Mon, 22 Apr 2024 00:37:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.709716.1108715 (Exim 4.92) (envelope-from ) id 1ryoFA-0007Ms-8y; Mon, 22 Apr 2024 07:37:40 +0000 Received: by outflank-mailman (output) from mailman id 709716.1108715; Mon, 22 Apr 2024 07:37:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ryoFA-0007Ml-67; Mon, 22 Apr 2024 07:37:40 +0000 Received: by outflank-mailman (input) for mailman id 709716; Mon, 22 Apr 2024 07:37:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ryoF8-0006Sb-7T for xen-devel@lists.xenproject.org; Mon, 22 Apr 2024 07:37:38 +0000 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [2607:f8b0:4864:20::434]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2ff3fed5-007b-11ef-8b06-e9908f64f69c; Mon, 22 Apr 2024 09:37:36 +0200 (CEST) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ed20fb620fso3360073b3a.2 for ; Mon, 22 Apr 2024 00:37:36 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id x37-20020a056a000be500b006edcceffcb0sm7221726pfu.161.2024.04.22.00.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:37:34 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2ff3fed5-007b-11ef-8b06-e9908f64f69c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713771455; x=1714376255; darn=lists.xenproject.org; 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=XH0hx5FhOx9XD5Quim9d/dWx8ptFKhc8V8iHDPJ7zTg=; b=tidflhVmpDXLNQbwn/3bs3/zrUwhmiIQI6CfTEw8wIG0G0EVZ8TMRD+ArxuoHns53J cwcmNjgZ0hNr6PJCFS9mjGfzjApUWz4zz5kpkGrsnMHCGkKWFW0ku/IyT/EGZqMROMmq U7tvEBvefLwmOm89zhI6zKixAinqkvYnS0ypnK4yqixwrFl1sMEiTN0bQk4NvBi7rEC+ fX3JWYjZsvtOfzcKfP2M3VQHTvXv0zy96J6WfM20EsMhbmABpU/lbVBW49KAVK61EbEV 6L4OyN1SJScxNXcMd0svy6ZUlqyPO62WRiGtkO5b3JtTkgPr7H2i/IBfQJudMFuVe3tK H9jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771455; x=1714376255; 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=XH0hx5FhOx9XD5Quim9d/dWx8ptFKhc8V8iHDPJ7zTg=; b=CFC4WOrxxblFUcyU16nWmUYEbXE3qKyWdF8o/f/2l19JOeoTpdsqvbsS+Ta1IiTNGr Zs+nJ1BS1XgzqQTzkb3ir7HW7W8lI3suZtFdK+Gga6Hx2meQs1guE4bbyNEVHGdHMiFG FkzAm5/Vu/HtMosNsvHGx9sywRhBooytiNAgfGkA1+IfKN0L5UCUB19aTHlEgR/p7rMX Mh1Sq9a+7HjtkNPqeqInCsRkxOcqFo8kw98Ks4PrrPV7xjCLEvPUjS7Af7A/+LaNRWy5 iXXBdnVOwtLUOlIo5Jl63QEjc6zs0pPk+cuU7k9JsulDW56g7GD46C2D5BKzvskJRuVu H7XA== X-Gm-Message-State: AOJu0YxDww9T3iP8MzWaFmvpHgg8PuZ+5pp0MGm3IJwaioZJhdIOhaBV sn/S0+oieyDc2xW2QOegRj51IgI4oiRLDmjejevk4lb5F33hqv1NwXKSKV39+AF0BJMEN35CN67 Q X-Google-Smtp-Source: AGHT+IGka8NQ9dDC8A6vYPkgAjXKykEfW2GOONxsXMsWFGAv2DdLMChwEDD2uno7UHsIXu15nuUq3A== X-Received: by 2002:a05:6a00:1906:b0:6ea:aaf5:9e00 with SMTP id y6-20020a056a00190600b006eaaaf59e00mr10590326pfi.33.1713771454705; Mon, 22 Apr 2024 00:37:34 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel Subject: [XEN PATCH v2 3/5] xen/arm: ffa: simplify ffa_handle_mem_share() Date: Mon, 22 Apr 2024 09:37:06 +0200 Message-Id: <20240422073708.3663529-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240422073708.3663529-1-jens.wiklander@linaro.org> References: <20240422073708.3663529-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713771479978100001 Content-Type: text/plain; charset="utf-8" Simplify ffa_handle_mem_share() by removing the start_page_idx and last_page_idx parameters from get_shm_pages() and check that the number of pages matches expectations at the end of get_shm_pages(). Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/tee/ffa_shm.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/tee/ffa_shm.c b/xen/arch/arm/tee/ffa_shm.c index 75a5b66aeb4c..370d83ec5cf8 100644 --- a/xen/arch/arm/tee/ffa_shm.c +++ b/xen/arch/arm/tee/ffa_shm.c @@ -159,10 +159,9 @@ static int32_t ffa_mem_reclaim(uint32_t handle_lo, uin= t32_t handle_hi, */ 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) + uint32_t range_count) { - unsigned int pg_idx =3D start_page_idx; + unsigned int pg_idx =3D 0; gfn_t gfn; unsigned int n; unsigned int m; @@ -191,7 +190,9 @@ static int get_shm_pages(struct domain *d, struct ffa_s= hm_mem *shm, } } =20 - *last_page_idx =3D pg_idx; + /* The ranges must add up */ + if ( pg_idx < shm->page_count ) + return FFA_RET_INVALID_PARAMETERS; =20 return FFA_RET_OK; } @@ -460,7 +461,6 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) 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; @@ -570,15 +570,9 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out; } =20 - ret =3D get_shm_pages(d, shm, region_descr->address_range_array, range= _count, - 0, &last_page_idx); + ret =3D get_shm_pages(d, shm, region_descr->address_range_array, range= _count); if ( ret ) goto out; - if ( last_page_idx !=3D shm->page_count ) - { - ret =3D FFA_RET_INVALID_PARAMETERS; - goto out; - } =20 /* Note that share_shm() uses our tx buffer */ spin_lock(&ffa_tx_buffer_lock); --=20 2.34.1 From nobody Sun May 19 06:23:14 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=1713771479; cv=none; d=zohomail.com; s=zohoarc; b=mQ19M64WhKsxdm91R0Tlq/Dw7OPngE/sWwbjmiumsTr4TDSCO0RWnrLHbMRTz8k9It8FLm+wxDLQfc2yGLwAOZbbCAPq5j2VVMLb3q+13htFEGcxVddBiYKMeh/bhyih2KzBXhZfVswUSCyMzQGcV9XnZGFyRdWvNw2SlPE2PNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713771479; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fqIqZwJgUcekPQuPI1VH6Nw18oRab5zr4LvkDvC5BW8=; b=CG5Es6zN/3cw+L20Sb3Klpks9OvqnVh1Le/xnQ5eDlxrp+OVruGDGfZMj/9GBQmqEdFf7YF6IKjqIp7jGsqeK4AI4cfvJvytgypBhtjMHgmaHMRenDsfimd8UCOOCa6fNtx2iwT54hT0EvEqAPRXf40fK9VFXpRa0iamDNpKcRE= 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 1713771479052968.1109691958181; Mon, 22 Apr 2024 00:37:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.709719.1108725 (Exim 4.92) (envelope-from ) id 1ryoFD-0007jG-H2; Mon, 22 Apr 2024 07:37:43 +0000 Received: by outflank-mailman (output) from mailman id 709719.1108725; Mon, 22 Apr 2024 07:37:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ryoFD-0007j2-E9; Mon, 22 Apr 2024 07:37:43 +0000 Received: by outflank-mailman (input) for mailman id 709719; Mon, 22 Apr 2024 07:37:42 +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 1ryoFC-0007cz-Hy for xen-devel@lists.xenproject.org; Mon, 22 Apr 2024 07:37:42 +0000 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [2607:f8b0:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 33228ea9-007b-11ef-9e3a-7da7ca7a9ce9; Mon, 22 Apr 2024 09:37:42 +0200 (CEST) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5c229dabbb6so2188890a12.0 for ; Mon, 22 Apr 2024 00:37:41 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id x37-20020a056a000be500b006edcceffcb0sm7221726pfu.161.2024.04.22.00.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:37:39 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 33228ea9-007b-11ef-9e3a-7da7ca7a9ce9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713771460; x=1714376260; darn=lists.xenproject.org; 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=fqIqZwJgUcekPQuPI1VH6Nw18oRab5zr4LvkDvC5BW8=; b=hgMAzr9/v3VV2ZdPFngyZFvDjtm0yzZ+ChNw/gDYVOnM7giroacv2sqWyMfBdDQl0F UkFF9LnaYkk8M7zyeJYUf+q26CrWhV0Bt3lO57ev03q8ROP1m4vdGQuw2bYPxAxxipos 8pJHZMpv3dtX0OV8+tE8/RZoFFOMUL9Q9O+q8gPmsDcc+UVDznuvXaQKSfSeDbmGO12L oxGuG8OGxAnyYqclPyJBQzbqcF8f4VJDXELoGaMR1HkT8zYa9VH5TB489fHpSqV8NJws Mc+Fi4MxmQju2nqN/2xuJLhkDtQCFAlFRrxoQgl+GNYSHRE+rSVQIuptDKc1Fnk5DoeH 7P3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771460; x=1714376260; 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=fqIqZwJgUcekPQuPI1VH6Nw18oRab5zr4LvkDvC5BW8=; b=PMGk6NFczZS2xo7RDwgpNHatz3ngnmg4H8A8kWupmpf/ZmHzyPTLhP5yC6N2UVZukT 24UDHYmtbWFTzxwEaAmcA70Qy07pcXx8pq7TWcIs0l6AnZyI1IcnLoBEN+gbfJC8Usfo YQZQd+HkhK/V7cZlRwNvN2X6lowNuI2L2WAvLE2eECC+p1Va6SkBr4WDQWTtisMLldcw 08lhpRAx7BOomnvJ9oc7jyRb9JlAT+rZsrERKzce/UNUNLv6EEB3i6jpbyImo+Tv0AyH 2fNr8NnTsgmiVY+vSk5d+a9JeCkBbGDsGZFEAxkVPZxOcjoE3aDNmNFzUCKnionF/m1T 5yHQ== X-Gm-Message-State: AOJu0YysgCJ5mFXm0+lmYd6oTg6yLxPtXecOFTCnrG568pdLEIi+iT+T vATIEzh88c8APosRsaYnhpjMPD45+NU/zGQOnD42QvU+wUyWFq1L8t+ftlIquncOFyMviwnxD0Q v X-Google-Smtp-Source: AGHT+IFomXvyJRBoJZ6esF5z/ya0gd+1lmpeMxibc4K5rG4EGXwP1H+lFCeoqG4tVAoaic3N+WUdGg== X-Received: by 2002:a05:6a20:8417:b0:1aa:41e4:f1b4 with SMTP id c23-20020a056a20841700b001aa41e4f1b4mr9140138pzd.44.1713771460059; Mon, 22 Apr 2024 00:37:40 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, Jens Wiklander , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers Date: Mon, 22 Apr 2024 09:37:07 +0200 Message-Id: <20240422073708.3663529-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240422073708.3663529-1-jens.wiklander@linaro.org> References: <20240422073708.3663529-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713771479988100002 Content-Type: text/plain; charset="utf-8" Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world. gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered. gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION. Signed-off-by: Jens Wiklander --- v1->v2 - Update patch description as requested --- xen/arch/arm/gic.c | 5 +++-- xen/arch/arm/irq.c | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 44c40e86defe..e9aeb7138455 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsign= ed int priority) =20 desc->handler =3D gic_hw_ops->gic_host_irq_type; =20 - gic_set_irq_type(desc, desc->arch.type); + if ( desc->irq >=3D NR_GIC_SGI) + gic_set_irq_type(desc, desc->arch.type); gic_set_irq_priority(desc, priority); } =20 @@ -375,7 +376,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_f= iq) /* Reading IRQ will ACK it */ irq =3D gic_hw_ops->read_irq(); =20 - if ( likely(irq >=3D 16 && irq < 1020) ) + if ( likely(irq >=3D GIC_SGI_MAX && irq < 1020) ) { isb(); do_IRQ(regs, irq, is_fiq); diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index bcce80a4d624..fdb214560978 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int i= rq, int is_fiq) =20 perfc_incr(irqs); =20 - ASSERT(irq >=3D 16); /* SGIs do not come down this path */ + /* Statically assigned SGIs do not come down this path */ + ASSERT(irq >=3D GIC_SGI_MAX); =20 - if ( irq < 32 ) + if ( irq < NR_GIC_SGI ) + perfc_incr(ipis); + else if ( irq < NR_GIC_LOCAL_IRQS ) perfc_incr(ppis); else perfc_incr(spis); --=20 2.34.1 From nobody Sun May 19 06:23:14 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=1713771489; cv=none; d=zohomail.com; s=zohoarc; b=TNddMUxUGMLzcCnA/U86FkqHJBWyF+xo5lBsdZfniJuiP0rg1L1tVi/400Z0SQ2hAq0GSADGKKP1Mw3JmTebu0fzryAaOrbXiGwdjxNo1YKuKcyooxytO+t55a1xhwo05l4k/rmydKCm5UOEvWCi410ucRQ0coBMvXhxuj1uFZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713771489; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d/7fKiW+izi3jT4eDFQ5vnoXCxte+tN47jnjPcuTARI=; b=KDB8/Q/yFwnttXSr9HkNXWDiZb5TjDQ43I5D084SUcwdU+/QK5/Eysza3epAhH49Ukk2dpB+4rL4tr3u8kPc+2T/HJh19Oh87a0bRjzw+zEubRU5JW5MJk6iOQVF000lznfzQ+PZvlgeO/ucCqvllKtjYBBJo9erODsRkG6ZXFc= 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 1713771488902655.3096144091013; Mon, 22 Apr 2024 00:38:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.709721.1108736 (Exim 4.92) (envelope-from ) id 1ryoFJ-0008JX-Qi; Mon, 22 Apr 2024 07:37:49 +0000 Received: by outflank-mailman (output) from mailman id 709721.1108736; Mon, 22 Apr 2024 07:37: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 1ryoFJ-0008JO-O2; Mon, 22 Apr 2024 07:37:49 +0000 Received: by outflank-mailman (input) for mailman id 709721; Mon, 22 Apr 2024 07:37: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 1ryoFI-0007cz-PA for xen-devel@lists.xenproject.org; Mon, 22 Apr 2024 07:37:48 +0000 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [2607:f8b0:4864:20::430]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 367b4462-007b-11ef-9e3a-7da7ca7a9ce9; Mon, 22 Apr 2024 09:37:47 +0200 (CEST) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6eff9dc1821so4008360b3a.3 for ; Mon, 22 Apr 2024 00:37:47 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id x37-20020a056a000be500b006edcceffcb0sm7221726pfu.161.2024.04.22.00.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 00:37: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: 367b4462-007b-11ef-9e3a-7da7ca7a9ce9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713771465; x=1714376265; darn=lists.xenproject.org; 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=d/7fKiW+izi3jT4eDFQ5vnoXCxte+tN47jnjPcuTARI=; b=j/qu7hMOtcA9jO2WRtzFaqKEOahS74IjaE5uBc/JpC8GQd9WL97g92t5Ofn/q5C45S bGfJonix+Vl7p2WjB/JU7lqxT9/08RbHRIQxD6QHNqgwSkrMvZC09fgIbgCG/5lW7g2H BXH/hdPA8FZc2I34o/ok7Kk+H8U1OUW3+Qd1HbEeh2LvhWGEn5OZYWh71Zbswb7Ne7ot 9eqnuD/3XHhvOFa/DB20Nt4JZqlgY4xr8Ttlwat7U19FADPiiztgPtfehZNyXbYt78eL K9OrM/+zqLUAZRam5Lvx+6cQNGVHLYlwy7u+LV3mi7vBGetFiI3O/bgZiswqzImRHQiL OWYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713771465; x=1714376265; 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=d/7fKiW+izi3jT4eDFQ5vnoXCxte+tN47jnjPcuTARI=; b=RsahBaCbEARq3Jp9YHCJ3Mi6ScAiEYzMR7O22dU8pCppp6cOccDfjB0ESTghC+oTXi RsnkJveSkh6r2VC3XJu8mC5ycXmCNzn8hIaX8BFc/upha/cpSFwm/dsB5pynmjz8bwVa y90skqsCzVlprnGxblx8nl6khaELkyMgBPemIBwKCB47F54Q5L9LJTnm256iG6jISfMS 4lA8vQdm29gwhHTCF+EURWk6RAUO2QCbD5Qr+nczd3UgrO9z82qjo+AQ3xzYqaUmr8i1 ACq3NWZcRcGYCRjqIxsonJ7OdLjGtvNQdPNJSQEYN3Drmcyq2ALUFnV7T3r1e4Z34UJU ClSg== X-Gm-Message-State: AOJu0YxKGcFk/iDjFfUXaaISuvDX3AYCo9UK4i0fDj1AKhDi98yYVEio a6yBk3mUNtI5wc7NCN4N455Bo74diiI9RM/uGE0oUHFDr5uvlqR2/ES6ZBZc7a19aLZB9fXwY5u + X-Google-Smtp-Source: AGHT+IHVCgH6OCpekvx+B+E26CYf1edbMbYsxeS44PDAikThebyPmCVOoPJm05/ZvHgj6wK1DCjUTA== X-Received: by 2002:a05:6a21:3e05:b0:1a7:7306:3677 with SMTP id bk5-20020a056a213e0500b001a773063677mr7903593pzc.25.1713771465522; Mon, 22 Apr 2024 00:37:45 -0700 (PDT) From: Jens Wiklander To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, Jens Wiklander , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel Subject: [XEN PATCH v2 5/5] xen/arm: ffa: support notification Date: Mon, 22 Apr 2024 09:37:08 +0200 Message-Id: <20240422073708.3663529-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240422073708.3663529-1-jens.wiklander@linaro.org> References: <20240422073708.3663529-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1713771490060100001 Content-Type: text/plain; charset="utf-8" Add support for FF-A notifications, currently limited to an SP (Secure Partition) sending an asynchronous notification to a guest. Guests and Xen itself are made aware of pending notifications with an interrupt. The interrupt handler retrieves the notifications using the FF-A ABI and deliver them to their destinations. Update ffa_partinfo_domain_init() to return error code like ffa_notif_domain_init(). Signed-off-by: Jens Wiklander --- v1->v2: - Addressing review comments - Change ffa_handle_notification_{bind,unbind,set}() to take struct cpu_user_regs *regs as argument. - Update ffa_partinfo_domain_init() and ffa_notif_domain_init() to return an error code. - Fixing a bug in handle_features() for FFA_FEATURE_SCHEDULE_RECV_INTR. --- xen/arch/arm/tee/Makefile | 1 + xen/arch/arm/tee/ffa.c | 55 +++++- xen/arch/arm/tee/ffa_notif.c | 331 ++++++++++++++++++++++++++++++++ xen/arch/arm/tee/ffa_partinfo.c | 9 +- xen/arch/arm/tee/ffa_private.h | 68 ++++++- 5 files changed, 457 insertions(+), 7 deletions(-) create mode 100644 xen/arch/arm/tee/ffa_notif.c diff --git a/xen/arch/arm/tee/Makefile b/xen/arch/arm/tee/Makefile index f0112a2f922d..7c0f46f7f446 100644 --- a/xen/arch/arm/tee/Makefile +++ b/xen/arch/arm/tee/Makefile @@ -2,5 +2,6 @@ obj-$(CONFIG_FFA) +=3D ffa.o obj-$(CONFIG_FFA) +=3D ffa_shm.o obj-$(CONFIG_FFA) +=3D ffa_partinfo.o obj-$(CONFIG_FFA) +=3D ffa_rxtx.o +obj-$(CONFIG_FFA) +=3D ffa_notif.o obj-y +=3D tee.o obj-$(CONFIG_OPTEE) +=3D optee.o diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 5209612963e1..aa171c0b61f0 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -39,6 +39,9 @@ * - at most 32 shared memory regions per guest * o FFA_MSG_SEND_DIRECT_REQ: * - only supported from a VM to an SP + * o FFA_NOTIFICATION_*: + * - only supports global notifications, that is, per vCPU notifications + * are not supported * * There are some large locked sections with ffa_tx_buffer_lock and * ffa_rx_buffer_lock. Especially the ffa_tx_buffer_lock spinlock used @@ -194,6 +197,8 @@ out: =20 static void handle_features(struct cpu_user_regs *regs) { + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; uint32_t a1 =3D get_user_reg(regs, 1); unsigned int n; =20 @@ -240,6 +245,30 @@ static void handle_features(struct cpu_user_regs *regs) BUILD_BUG_ON(PAGE_SIZE !=3D FFA_PAGE_SIZE); ffa_set_regs_success(regs, 0, 0); break; + case FFA_FEATURE_NOTIF_PEND_INTR: + if ( ctx->notif.enabled ) + ffa_set_regs_success(regs, FFA_NOTIF_PEND_INTR_ID, 0); + else + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + break; + case FFA_FEATURE_SCHEDULE_RECV_INTR: + if ( ctx->notif.enabled ) + ffa_set_regs_success(regs, FFA_SCHEDULE_RECV_INTR_ID, 0); + else + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + break; + + case FFA_NOTIFICATION_BIND: + case FFA_NOTIFICATION_UNBIND: + case FFA_NOTIFICATION_GET: + case FFA_NOTIFICATION_SET: + case FFA_NOTIFICATION_INFO_GET_32: + case FFA_NOTIFICATION_INFO_GET_64: + if ( ctx->notif.enabled ) + ffa_set_regs_success(regs, 0, 0); + else + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + break; default: ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); break; @@ -305,6 +334,22 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) get_user_reg(regs, 1)= ), get_user_reg(regs, 3)); break; + case FFA_NOTIFICATION_BIND: + e =3D ffa_handle_notification_bind(regs); + break; + case FFA_NOTIFICATION_UNBIND: + e =3D ffa_handle_notification_unbind(regs); + break; + case FFA_NOTIFICATION_INFO_GET_32: + case FFA_NOTIFICATION_INFO_GET_64: + ffa_handle_notification_info_get(regs); + return true; + case FFA_NOTIFICATION_GET: + ffa_handle_notification_get(regs); + return true; + case FFA_NOTIFICATION_SET: + e =3D ffa_handle_notification_set(regs); + break; =20 default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -322,6 +367,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs) static int ffa_domain_init(struct domain *d) { struct ffa_ctx *ctx; + int ret; =20 if ( !ffa_version ) return -ENODEV; @@ -345,10 +391,11 @@ static int ffa_domain_init(struct domain *d) * error, so no need for cleanup in this function. */ =20 - if ( !ffa_partinfo_domain_init(d) ) - return -EIO; + ret =3D ffa_partinfo_domain_init(d); + if ( ret ) + return ret; =20 - return 0; + return ffa_notif_domain_init(d); } =20 static void ffa_domain_teardown_continue(struct ffa_ctx *ctx, bool first_t= ime) @@ -423,6 +470,7 @@ static int ffa_domain_teardown(struct domain *d) return 0; =20 ffa_rxtx_domain_destroy(d); + ffa_notif_domain_destroy(d); =20 ffa_domain_teardown_continue(ctx, true /* first_time */); =20 @@ -502,6 +550,7 @@ static bool ffa_probe(void) if ( !ffa_partinfo_init() ) goto err_rxtx_destroy; =20 + ffa_notif_init(); INIT_LIST_HEAD(&ffa_teardown_head); init_timer(&ffa_teardown_timer, ffa_teardown_timer_callback, NULL, 0); =20 diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c new file mode 100644 index 000000000000..949587cf4b80 --- /dev/null +++ b/xen/arch/arm/tee/ffa_notif.c @@ -0,0 +1,331 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Linaro Limited + */ + +#include +#include +#include +#include + +#include +#include + +#include "ffa_private.h" + +static bool __ro_after_init notif_enabled; + +int ffa_handle_notification_bind(struct cpu_user_regs *regs) +{ + struct domain *d =3D current->domain; + uint32_t src_dst =3D get_user_reg(regs, 1); + uint32_t flags =3D get_user_reg(regs, 2); + uint32_t bitmap_lo =3D get_user_reg(regs, 3); + uint32_t bitmap_hi =3D get_user_reg(regs, 4); + + if ( !notif_enabled ) + return FFA_RET_NOT_SUPPORTED; + + if ( (src_dst & 0xFFFFU) !=3D ffa_get_vm_id(d) ) + return FFA_RET_INVALID_PARAMETERS; + + if ( flags ) /* Only global notifications are supported */ + return FFA_RET_DENIED; + + /* + * We only support notifications from SP so no need to check the sender + * endpoint ID, the SPMC will take care of that for us. + */ + return ffa_simple_call(FFA_NOTIFICATION_BIND, src_dst, flags, bitmap_h= i, + bitmap_lo); +} + +int ffa_handle_notification_unbind(struct cpu_user_regs *regs) +{ + struct domain *d =3D current->domain; + uint32_t src_dst =3D get_user_reg(regs, 1); + uint32_t bitmap_lo =3D get_user_reg(regs, 3); + uint32_t bitmap_hi =3D get_user_reg(regs, 4); + + if ( !notif_enabled ) + return FFA_RET_NOT_SUPPORTED; + + if ( (src_dst & 0xFFFFU) !=3D ffa_get_vm_id(d) ) + return FFA_RET_INVALID_PARAMETERS; + + /* + * We only support notifications from SP so no need to check the + * destination endpoint ID, the SPMC will take care of that for us. + */ + return ffa_simple_call(FFA_NOTIFICATION_UNBIND, src_dst, 0, bitmap_hi, + bitmap_lo); +} + +void ffa_handle_notification_info_get(struct cpu_user_regs *regs) +{ + struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; + bool pending_global; + + if ( !notif_enabled ) + { + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + return; + } + + spin_lock(&ctx->notif.lock); + pending_global =3D ctx->notif.secure_pending; + ctx->notif.secure_pending =3D false; + spin_unlock(&ctx->notif.lock); + + if ( pending_global ) + { + /* A pending global notification for the guest */ + ffa_set_regs(regs, FFA_SUCCESS_64, 0, + 1U << FFA_NOTIF_INFO_GET_ID_COUNT_SHIFT, ffa_get_vm_i= d(d), + 0, 0, 0, 0); + } + else + { + /* Report an error if there where no pending global notification */ + ffa_set_regs_error(regs, FFA_RET_NO_DATA); + } +} + +void ffa_handle_notification_get(struct cpu_user_regs *regs) +{ + struct domain *d =3D current->domain; + uint32_t recv =3D get_user_reg(regs, 1); + uint32_t flags =3D get_user_reg(regs, 2); + uint32_t w2 =3D 0; + uint32_t w3 =3D 0; + uint32_t w4 =3D 0; + uint32_t w5 =3D 0; + uint32_t w6 =3D 0; + uint32_t w7 =3D 0; + + if ( !notif_enabled ) + { + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + return; + } + + if ( (recv & 0xFFFFU) !=3D ffa_get_vm_id(d) ) + { + ffa_set_regs_error(regs, FFA_RET_INVALID_PARAMETERS); + return; + } + + if ( flags & ( FFA_NOTIF_FLAG_BITMAP_SP | FFA_NOTIF_FLAG_BITMAP_SPM ) ) + { + struct arm_smccc_1_2_regs arg =3D { + .a0 =3D FFA_NOTIFICATION_GET, + .a1 =3D recv, + .a2 =3D flags & ( FFA_NOTIF_FLAG_BITMAP_SP | + FFA_NOTIF_FLAG_BITMAP_SPM ), + }; + struct arm_smccc_1_2_regs resp; + int32_t e; + + arm_smccc_1_2_smc(&arg, &resp); + e =3D ffa_get_ret_code(&resp); + if ( e ) + { + ffa_set_regs_error(regs, e); + return; + } + + if ( flags & FFA_NOTIF_FLAG_BITMAP_SP ) + { + w2 =3D resp.a2; + w3 =3D resp.a3; + } + + if ( flags & FFA_NOTIF_FLAG_BITMAP_SPM ) + w6 =3D resp.a6; + } + + ffa_set_regs(regs, FFA_SUCCESS_32, 0, w2, w3, w4, w5, w6, w7); +} + +int ffa_handle_notification_set(struct cpu_user_regs *regs) +{ + struct domain *d =3D current->domain; + uint32_t src_dst =3D get_user_reg(regs, 1); + uint32_t flags =3D get_user_reg(regs, 2); + uint32_t bitmap_lo =3D get_user_reg(regs, 3); + uint32_t bitmap_hi =3D get_user_reg(regs, 4); + + if ( !notif_enabled ) + return FFA_RET_NOT_SUPPORTED; + + if ( (src_dst >> 16) !=3D ffa_get_vm_id(d) ) + return FFA_RET_INVALID_PARAMETERS; + + /* Let the SPMC check the destination of the notification */ + return ffa_simple_call(FFA_NOTIFICATION_SET, src_dst, flags, bitmap_lo, + bitmap_hi); +} + +/* + * Extract a 16-bit ID (index n) from the successful return value from + * FFA_NOTIFICATION_INFO_GET_64 or FFA_NOTIFICATION_INFO_GET_32. IDs are + * returned in registers 3 to 7 with four IDs per register for 64-bit + * calling convention and two IDs per register for 32-bit calling + * convention. + */ +static uint16_t get_id_from_resp(struct arm_smccc_1_2_regs *resp, + unsigned int n) +{ + unsigned int ids_per_reg; + unsigned int reg_idx; + unsigned int reg_shift; + + if ( smccc_is_conv_64(resp->a0) ) + ids_per_reg =3D 4; + else + ids_per_reg =3D 2; + + reg_idx =3D n / ids_per_reg + 3; + reg_shift =3D ( n % ids_per_reg ) * 16; + + switch ( reg_idx ) + { + case 3: + return resp->a3 >> reg_shift; + case 4: + return resp->a4 >> reg_shift; + case 5: + return resp->a5 >> reg_shift; + case 6: + return resp->a6 >> reg_shift; + case 7: + return resp->a7 >> reg_shift; + default: + ASSERT(0); /* "Can't happen" */ + return 0; + } +} + +static void notif_irq_handler(int irq, void *data) +{ + const struct arm_smccc_1_2_regs arg =3D { + .a0 =3D FFA_NOTIFICATION_INFO_GET_64, + }; + struct arm_smccc_1_2_regs resp; + unsigned int id_pos; + unsigned int list_count; + uint64_t ids_count; + unsigned int n; + int32_t res; + + do { + arm_smccc_1_2_smc(&arg, &resp); + res =3D ffa_get_ret_code(&resp); + if ( res ) + { + if ( res !=3D FFA_RET_NO_DATA ) + printk(XENLOG_ERR "ffa: notification info get failed: erro= r %d\n", + res); + return; + } + + ids_count =3D resp.a2 >> FFA_NOTIF_INFO_GET_ID_LIST_SHIFT; + list_count =3D ( resp.a2 >> FFA_NOTIF_INFO_GET_ID_COUNT_SHIFT ) & + FFA_NOTIF_INFO_GET_ID_COUNT_MASK; + + id_pos =3D 0; + for ( n =3D 0; n < list_count; n++ ) + { + unsigned int count =3D ((ids_count >> 2 * n) & 0x3) + 1; + struct domain *d; + + d =3D ffa_get_domain_by_vm_id(get_id_from_resp(&resp, id_pos)); + + if ( d ) + { + struct ffa_ctx *ctx =3D d->arch.tee; + + spin_lock(&ctx->notif.lock); + ctx->notif.secure_pending =3D true; + spin_unlock(&ctx->notif.lock); + + /* + * Since we're only delivering global notification, always + * deliver to the first vCPU. It doesn't matter which we + * chose, as long as it's available. + */ + vgic_inject_irq(d, d->vcpu[0], FFA_NOTIF_PEND_INTR_ID, tru= e); + + put_domain(d); + } + + id_pos +=3D count; + } + + } while (resp.a2 & FFA_NOTIF_INFO_GET_MORE_FLAG); +} + +static int32_t ffa_notification_bitmap_create(uint16_t vm_id, + uint32_t vcpu_count) +{ + return ffa_simple_call(FFA_NOTIFICATION_BITMAP_CREATE, vm_id, vcpu_cou= nt, + 0, 0); +} + +static int32_t ffa_notification_bitmap_destroy(uint16_t vm_id) +{ + return ffa_simple_call(FFA_NOTIFICATION_BITMAP_DESTROY, vm_id, 0, 0, 0= ); +} + +void ffa_notif_init(void) +{ + const struct arm_smccc_1_2_regs arg =3D { + .a0 =3D FFA_FEATURES, + .a1 =3D FFA_FEATURE_SCHEDULE_RECV_INTR, + }; + struct arm_smccc_1_2_regs resp; + unsigned int irq; + int ret; + + arm_smccc_1_2_smc(&arg, &resp); + if ( resp.a0 !=3D FFA_SUCCESS_32 ) + return; + + irq =3D resp.a2; + if ( irq >=3D NR_GIC_SGI ) + irq_set_type(irq, IRQ_TYPE_EDGE_RISING); + ret =3D request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL); + if ( ret ) + printk(XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n", + irq, ret); + notif_enabled =3D !ret; +} + +int ffa_notif_domain_init(struct domain *d) +{ + struct ffa_ctx *ctx =3D d->arch.tee; + int32_t res; + + if ( !notif_enabled ) + return 0; + + res =3D ffa_notification_bitmap_create(ffa_get_vm_id(d), d->max_vcpus); + if ( res ) + return -ENOMEM; + + ctx->notif.enabled =3D true; + + return 0; +} + +void ffa_notif_domain_destroy(struct domain *d) +{ + struct ffa_ctx *ctx =3D d->arch.tee; + + if ( ctx->notif.enabled ) + { + ffa_notification_bitmap_destroy(ffa_get_vm_id(d)); + ctx->notif.enabled =3D false; + } +} diff --git a/xen/arch/arm/tee/ffa_partinfo.c b/xen/arch/arm/tee/ffa_partinf= o.c index dc1059584828..93a03c6bc672 100644 --- a/xen/arch/arm/tee/ffa_partinfo.c +++ b/xen/arch/arm/tee/ffa_partinfo.c @@ -306,7 +306,7 @@ static void vm_destroy_bitmap_init(struct ffa_ctx *ctx, } } =20 -bool ffa_partinfo_domain_init(struct domain *d) +int ffa_partinfo_domain_init(struct domain *d) { unsigned int count =3D BITS_TO_LONGS(subscr_vm_destroyed_count); struct ffa_ctx *ctx =3D d->arch.tee; @@ -315,7 +315,7 @@ bool ffa_partinfo_domain_init(struct domain *d) =20 ctx->vm_destroy_bitmap =3D xzalloc_array(unsigned long, count); if ( !ctx->vm_destroy_bitmap ) - return false; + return -ENOMEM; =20 for ( n =3D 0; n < subscr_vm_created_count; n++ ) { @@ -330,7 +330,10 @@ bool ffa_partinfo_domain_init(struct domain *d) } vm_destroy_bitmap_init(ctx, n); =20 - return n =3D=3D subscr_vm_created_count; + if ( n !=3D subscr_vm_created_count ) + return -EIO; + + return 0; } =20 bool ffa_partinfo_domain_destroy(struct domain *d) diff --git a/xen/arch/arm/tee/ffa_private.h b/xen/arch/arm/tee/ffa_private.h index 98236cbf14a3..ef8ffd4526bd 100644 --- a/xen/arch/arm/tee/ffa_private.h +++ b/xen/arch/arm/tee/ffa_private.h @@ -25,6 +25,7 @@ #define FFA_RET_DENIED -6 #define FFA_RET_RETRY -7 #define FFA_RET_ABORTED -8 +#define FFA_RET_NO_DATA -9 =20 /* FFA_VERSION helpers */ #define FFA_VERSION_MAJOR_SHIFT 16U @@ -97,6 +98,18 @@ */ #define FFA_MAX_SHM_COUNT 32 =20 +/* + * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely + * unused, but that may change. + * + * SGI is the preferred delivery mechanism. SGIs 8-15 are normally not used + * by a guest as they in a non-virtualized system typically are assigned to + * the secure world. Here we're free to use SGI 8-15 since they are virtual + * and have nothing to do with the secure world. + */ +#define FFA_NOTIF_PEND_INTR_ID 8 +#define FFA_SCHEDULE_RECV_INTR_ID 9 + /* * The time we wait until trying to tear down a domain again if it was * blocked initially. @@ -175,6 +188,21 @@ */ #define FFA_PARTITION_INFO_GET_COUNT_FLAG BIT(0, U) =20 +/* Flags used in calls to FFA_NOTIFICATION_GET interface */ +#define FFA_NOTIF_FLAG_BITMAP_SP BIT(0, U) +#define FFA_NOTIF_FLAG_BITMAP_VM BIT(1, U) +#define FFA_NOTIF_FLAG_BITMAP_SPM BIT(2, U) +#define FFA_NOTIF_FLAG_BITMAP_HYP BIT(3, U) + +#define FFA_NOTIF_INFO_GET_MORE_FLAG BIT(0, U) +#define FFA_NOTIF_INFO_GET_ID_LIST_SHIFT 12 +#define FFA_NOTIF_INFO_GET_ID_COUNT_SHIFT 7 +#define FFA_NOTIF_INFO_GET_ID_COUNT_MASK 0x1F + +/* Feature IDs used with FFA_FEATURES */ +#define FFA_FEATURE_NOTIF_PEND_INTR 0x1U +#define FFA_FEATURE_SCHEDULE_RECV_INTR 0x2U + /* Function IDs */ #define FFA_ERROR 0x84000060U #define FFA_SUCCESS_32 0x84000061U @@ -213,6 +241,27 @@ #define FFA_MEM_FRAG_TX 0x8400007BU #define FFA_MSG_SEND 0x8400006EU #define FFA_MSG_POLL 0x8400006AU +#define FFA_NOTIFICATION_BITMAP_CREATE 0x8400007DU +#define FFA_NOTIFICATION_BITMAP_DESTROY 0x8400007EU +#define FFA_NOTIFICATION_BIND 0x8400007FU +#define FFA_NOTIFICATION_UNBIND 0x84000080U +#define FFA_NOTIFICATION_SET 0x84000081U +#define FFA_NOTIFICATION_GET 0x84000082U +#define FFA_NOTIFICATION_INFO_GET_32 0x84000083U +#define FFA_NOTIFICATION_INFO_GET_64 0xC4000083U + +struct ffa_ctx_notif { + bool enabled; + + /* Used to serialize access to the rest of this struct */ + spinlock_t lock; + + /* + * True if domain is reported by FFA_NOTIFICATION_INFO_GET to have + * pending global notifications. + */ + bool secure_pending; +}; =20 struct ffa_ctx { void *rx; @@ -228,6 +277,7 @@ struct ffa_ctx { struct list_head shm_list; /* Number of allocated shared memory object */ unsigned int shm_count; + struct ffa_ctx_notif notif; /* * tx_lock is used to serialize access to tx * rx_lock is used to serialize access to rx @@ -257,7 +307,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs); int ffa_handle_mem_reclaim(uint64_t handle, uint32_t flags); =20 bool ffa_partinfo_init(void); -bool ffa_partinfo_domain_init(struct domain *d); +int ffa_partinfo_domain_init(struct domain *d); bool ffa_partinfo_domain_destroy(struct domain *d); int32_t ffa_handle_partition_info_get(uint32_t w1, uint32_t w2, uint32_t w= 3, uint32_t w4, uint32_t w5, uint32_t *= count, @@ -271,12 +321,28 @@ uint32_t ffa_handle_rxtx_map(uint32_t fid, register_t= tx_addr, uint32_t ffa_handle_rxtx_unmap(void); int32_t ffa_handle_rx_release(void); =20 +void ffa_notif_init(void); +int ffa_notif_domain_init(struct domain *d); +void ffa_notif_domain_destroy(struct domain *d); + +int ffa_handle_notification_bind(struct cpu_user_regs *regs); +int ffa_handle_notification_unbind(struct cpu_user_regs *regs); +void ffa_handle_notification_info_get(struct cpu_user_regs *regs); +void ffa_handle_notification_get(struct cpu_user_regs *regs); +int ffa_handle_notification_set(struct cpu_user_regs *regs); + static inline uint16_t ffa_get_vm_id(const struct domain *d) { /* +1 since 0 is reserved for the hypervisor in FF-A */ return d->domain_id + 1; } =20 +static inline struct domain *ffa_get_domain_by_vm_id(uint16_t vm_id) +{ + /* -1 to match ffa_get_vm_id() */ + return get_domain_by_id(vm_id - 1); +} + static inline void ffa_set_regs(struct cpu_user_regs *regs, register_t v0, register_t v1, register_t v2, register_t v= 3, register_t v4, register_t v5, register_t v= 6, --=20 2.34.1