From nobody Thu Nov 6 08:38:18 2025 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=1716967583; cv=none; d=zohomail.com; s=zohoarc; b=k+iLV4LCiT6wQ2EB28EXwq0QXcC1HaONrb/qi32wG/aRmgZ4hV2GDEr/9mg1CpsttI1N/bpoMHVSYjz+KK3V9OP97+KNLlidVE53dv7zY1zF1qQmoMYann8xpbmV5a4YzQe4hJdivMqDdwA5QSot1D6zpTBAd4QG6NrNZzRs3zU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967583; 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=KUuwb+dXIeh2QgN/PmkZdKeEjuXgW0sq+m5mCYAxP2f4W2xakrj7kCFmRyUk9F30qDvNqeJ+S6flj0/luk5g2TD5tny75BHUkrHO3tWJIPjF3G6RHXQOSWqHUNO8kCKwUEk6Ruedbj2kyHId4onPrwUbqTl50Lev2OBote/Absc= 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 1716967583670369.8979476835849; Wed, 29 May 2024 00:26:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731496.1137027 (Exim 4.92) (envelope-from ) id 1sCDhI-0003ft-Fx; Wed, 29 May 2024 07:26:08 +0000 Received: by outflank-mailman (output) from mailman id 731496.1137027; Wed, 29 May 2024 07:26:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhI-0003fk-Bv; Wed, 29 May 2024 07:26:08 +0000 Received: by outflank-mailman (input) for mailman id 731496; Wed, 29 May 2024 07:26:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhH-0002xp-Oo for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:07 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b49b26a9-1d8c-11ef-b4bb-af5377834399; Wed, 29 May 2024 09:26:03 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5295eb47b48so2163324e87.1 for ; Wed, 29 May 2024 00:26:04 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:02 -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: b49b26a9-1d8c-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967564; x=1717572364; 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=UF1xwjfU11jMAoruWrPSOaPXIXLOW9FovPzSabYrt0ugV5KA0mOb4BQqD3O1DNojl1 cDYNMvxOUtOjjSYFRDmo6LuyLV0F9lg1/EB7G49yQ86Qu2AdAGoteK32HKlkfuGkHOUc bPottUM5iY/qJdBEayPr4KwtF9tJOssTNii/Bvp2j3OFty1YF7ipoXHX3H3MnpXSFwiz 4cr3kBjMsIGd5wpFlGvxaJ9zk5fxq0JZAM2XuT/Zt9HdajCW0YyKlMRaGZ01vxywhi2a rrehQkzlxwT0jTdBfqnuubZTd8TpOCj8fwpWY3W8PlfEe+BHmA+AIdyXpVrYPWUXdQuD zALg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967564; x=1717572364; 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=o6wV/5svJxALnVMTh/ziVE1oM/M3JzCFb7pnS4SAgEiDZEZqTLM/SpVc9aSq2HylKq T0Qk7jh8oInSAGcY2gdvQXCxD2tXK782Bx3Mj2USxhquq7yjfQFPYjCYUA1ypCUCvKSJ ygKMdfwfOQjXolMh2I0KyqcvhE1U97venPWNTgSFaxDzrIXlN1r5XErv6Bwa5fGSGEsK YYo1H9FCwTSsu0wh4ImAFv9kwYQMicBSP7dWKM4fDYT50YXZpGXy4BY/wiJWt6uXsXbx iIdK127xilcmISUTTYcDdInI7qUmlahhSmHQ9PLO3RTtm4c55PpjdL6SRbejI1W/tBr/ 9REg== X-Gm-Message-State: AOJu0YxS9DpYipRdb6/YNMyU1eZY98us/2d+x6+igh+VIfjllph+AFBr 7uWXdlxKUHzxiBpYzh+0sCJ/U8CUgkwZCUukQhTcUOeZd264mX1Hl4Svdp9G5ByYgq1M18H6OXL D0wM= X-Google-Smtp-Source: AGHT+IHUammB1br6gC/kNEl2MIJXLC3DblISLU4GACqDN+CQ2EGDJncNtdswHtQjYuXcwxxcJqhvRg== X-Received: by 2002:a19:6a17:0:b0:529:c0c6:faad with SMTP id 2adb3069b0e04-529c0c6fbcamr1133747e87.28.1716967563718; Wed, 29 May 2024 00:26:03 -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 v5 1/7] xen/arm: ffa: refactor ffa_handle_call() Date: Wed, 29 May 2024 09:25:53 +0200 Message-Id: <20240529072559.2486986-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967584560100001 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 Thu Nov 6 08:38:18 2025 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=1716967584; cv=none; d=zohomail.com; s=zohoarc; b=giTOkestlm6BW/RSen2tonZiSf2j+6udYauaEoee19hHyMQnT93QPZMgzJP/ukh89kuL7gJ6GM7xbT+JMxEFt1JZduwxfy8E6MJEABJt3BPghBQFnoHoUIaTCUHT7l1Z3yKPYI+g1/Fw4gMcmqnlq3B+z4l+VhSwN2EqMqNpcBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967584; 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=YamENGN5XNJJaZV0DS7XLKmC+prr6u8zRsuwOwa0/rk22cYqs1H7Vb5t/PLHkpWDJ5i5BW5eqjud0zO1OYDSP1U7KxnOC845SLtD91R/XH3YmGoGkBIp8aHm0J7nBTXmMNiJFZVVCFwBKxhqPDN7rwMbYOjsaLJV9pFYqJB4/8g= 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 1716967584163547.0418804408159; Wed, 29 May 2024 00:26:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731497.1137037 (Exim 4.92) (envelope-from ) id 1sCDhJ-0003vP-Mn; Wed, 29 May 2024 07:26:09 +0000 Received: by outflank-mailman (output) from mailman id 731497.1137037; Wed, 29 May 2024 07:26:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhJ-0003v9-IL; Wed, 29 May 2024 07:26:09 +0000 Received: by outflank-mailman (input) for mailman id 731497; Wed, 29 May 2024 07:26:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhI-0002xp-Or for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:08 +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 b5c3aa7e-1d8c-11ef-b4bb-af5377834399; Wed, 29 May 2024 09:26:05 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-52b6ccfdf28so6718e87.2 for ; Wed, 29 May 2024 00:26:06 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:04 -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: b5c3aa7e-1d8c-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967565; x=1717572365; 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=qsR57bksHdfVIS5ZgWF3GPCxGYE8lK0+trTmrCkCSVGiejL6rCS/NttsludEcpQjEF PyWJEMKtHvA21IMjCII4vr5eAaIvHbLr8oQ9OaCrt+FSDNSj4dRdA7Fd9LwWACCxnFe9 l8wAsNRPJcavjHJPBS7lNDZGlo97oTdct0z9kVNeTbdpUqyfXnEhtPr1vUnlNYYs5HuS hf0LHzQv0QbDSaiJeahyAa0e+cW4d/lSEtJi2rXyDAoz0lav6CcfUQnVFs5X+xTlihQG h0mCsH9xmgYQVi4KTtE6likulUB6bHywx8Hii8WYhhTDWzqJUvur1gJ81MyBhPpFVOEx 5Gtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967565; x=1717572365; 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=aQxL1JTBCjJ6HymiCQ3XVGRi6XjlE4TFCVS46CxGDg5RTPo4ajx1fDEliR6rF3pxLh rAb1HtnpD32TC+7y6fJSdAFLV9UQn4Ut8x+9O6aIODhMlyyh7ntW4tJ3ObECTqYN2K1q 3WRTmCjpTn0NkbD4+emkmkTZX/qt4nAesgBQR/rqHd78zbUFKEFuiARFxjkNmXmMKuCr cYUi9ufur1rPPIDUrLOnY06FHShoTpZ/cYoUooaEacMHrYpxzOmzpcZzl2+Vnr+m6kjS GYJcy8qfc+U3kOX80tq0OZ5Jhac22UEJKwy/67EOVKZBp1aW+TRgx3d+JhcNXAasF2L9 eO8A== X-Gm-Message-State: AOJu0Ywngn9R1gWxOrbF2s98067GZn+kXTenfmzgnlW3N/pLANSAacX5 Xqp8KXjzx37FZzjCO6bun3NVqHEY8DZJZUAxfYUIsilDI9f4Jh+bCgMXiQ/dpIXjRWKu9VYvcX1 18BQ= X-Google-Smtp-Source: AGHT+IG4us99S6HJMmw1BnNMPCNiTcik3IIzYpyfmcLKgmcqg3Zk8NHoh84cKeLXUs6K75aOamqMZw== X-Received: by 2002:a05:6512:4cc:b0:51e:f2bb:158a with SMTP id 2adb3069b0e04-52966ca8c0fmr8792474e87.64.1716967565550; Wed, 29 May 2024 00:26:05 -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 v5 2/7] xen/arm: ffa: use ACCESS_ONCE() Date: Wed, 29 May 2024 09:25:54 +0200 Message-Id: <20240529072559.2486986-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967584563100002 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 Thu Nov 6 08:38:18 2025 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=1716967588; cv=none; d=zohomail.com; s=zohoarc; b=dWQ4Q5QTIflCzVLx1r3rwv8F4rWviFiXtJYiLmGPX5S5oMZ0seKiVaj74jC4dXRj5DbcOnhdIxUKtuyGjuZZOxE1LkWAmIlRoMVht3652mVBaVW5SWacBBR3F4/DFp0vXwu8XpjHBKIr7HROdEk2VKcxvHQNmxJlq/nMBqU0dTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967588; 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=n6RENXOQfwUxO0lbIDfSC7Ub+yUzjfWUN2Bk/XIFafaoBFFalLAtxz7fUi5mK8/ayxI69pZlQ+aXQ/n+FKiUZtuLG0jQrr/5nrTQQyj1ciX/hGUs8X5gFOgmJgNoxHZjGRzh9VE6vXy3UHBEgjgZNxRxZLNf+d8NgzQKswrGh+w= 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 1716967588224677.4220546104283; Wed, 29 May 2024 00:26:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731498.1137047 (Exim 4.92) (envelope-from ) id 1sCDhL-0004Cu-3h; Wed, 29 May 2024 07:26:11 +0000 Received: by outflank-mailman (output) from mailman id 731498.1137047; Wed, 29 May 2024 07:26:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhK-0004Ch-WE; Wed, 29 May 2024 07:26:11 +0000 Received: by outflank-mailman (input) for mailman id 731498; Wed, 29 May 2024 07:26:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhJ-0003Qb-2E for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:09 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b79f8de9-1d8c-11ef-90a1-e314d9c70b13; Wed, 29 May 2024 09:26:08 +0200 (CEST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2e95a1eff78so22859931fa.0 for ; Wed, 29 May 2024 00:26:08 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:06 -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: b79f8de9-1d8c-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967567; x=1717572367; 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=apGCZuFr314QW5S7oM+Ji2IjCiTkVcm76gRDB0ig0ePZFb2lUj/2Ao+JG3aMpkpTP/ I4LYBMQbLfNLcFmSKcwrsvkZ5+2KOc6FKbyOL/yhsb1F5F9WiDcPixHSR2LQbvBkii1W CY9gw55nFQki/HVz6Te0iZ6z1AngEmxGU85EefXN8sbgsKNq3MWUGnUC4cQKr2malIAp 1+1krxV6tANNUgllzaj1Oh5qsM9bs+4MRkHTEH2q83X7t/BOIZ+mO0Zn5uR5xDG5Ymfh Q7lsSJFxFAFV0HnJqW81P+HlSC2FhjFCKnYn+RVy1XtvnkDNOk2PL53KmkSEAdeMxtny yqHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967567; x=1717572367; 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=tDbM54x4c9pvDm+z7rt4N6DFrvzLZUvPvAaHQfVYfTdUmHyN1i0A3M6mBTMFm10jj4 7mAN8FMFL1rYNd37MLrFqAy5FRjKDy6rrOwZT6+Dg1n7XYKPm4sDzlB2VlbaNEfS/56n WbJkaDqtpgx5O5bEVUa/9bxbrg9pcw2IplvlvHT7SFtA2UONg7dn4uN9VvNzBjAbqgem BKtkieScplpqBLd8ukfYeKZ5vBRFx9oWKLDjjHR94cQFGvKbKnoFyD24UwyEgPpn8tn3 6IRzEenoXWJ2ylt1kzGkWW2eCENBeLt+aLb7/vv5vfQ9zYVz9QqK69vl+T6outHmBy87 80vQ== X-Gm-Message-State: AOJu0YwFqRgYzF6pmdSq+9JodT9KBfJANxMiSvdI1SEo/wCAwHjWEJcn L+6wkelQ/BtN0OklDmWncYXcvHeXgDfFvbU/La/8oQ74AOca6XmYGKmKvRVdmSJ9NXkAlPGFchV QWhM= X-Google-Smtp-Source: AGHT+IFIoBrKT/kDs3uPPD+xIx8y8di16Jqchsw2ABXeJEk1y0F6sSFegq5DQBoH4LL32mpv6TxtmQ== X-Received: by 2002:a19:ad4a:0:b0:529:4864:9c17 with SMTP id 2adb3069b0e04-52967463e64mr12099898e87.57.1716967567404; Wed, 29 May 2024 00:26:07 -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 v5 3/7] xen/arm: ffa: simplify ffa_handle_mem_share() Date: Wed, 29 May 2024 09:25:55 +0200 Message-Id: <20240529072559.2486986-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967588553100001 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 Thu Nov 6 08:38:18 2025 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=1716967591; cv=none; d=zohomail.com; s=zohoarc; b=jYM3mTXanJ/YYKTEJ7X3Z0ZIHwQUdC8iWVyrPLMxTxf7aWKKRfe7Y2wuCvADCWEsCd0N518dTPu6Lh+lsEjiXOUA4OQ5wU0dzUyanMCqrtFq9pKo8fe/BzMW3H4YgfJ0PCOZy526NjSm8U9/judeBn3zbKCGFFLNdSHeuWKyC7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967591; 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=SILgfa72VI0ajqqfGUDbvcNqJ8ZZiLfW7kFdd1Zm0SE=; b=hIn880xJ0mZzqsEAXuftHf0EPbH9SDvrsrrOcUKLD92NSUUYFgQRdEUfMazXvZiqyqDVL+tP2EMoyel7npLTPfiy86hg4Zb1z/qkS0xcdSlI8Zf9ks+rA1FBP9xnk8mvJXtZMGhECT5a4gRbMKs1loSeK0oyHTxVD3i2id0J6v4= 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 1716967591707748.0053284055231; Wed, 29 May 2024 00:26:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731499.1137057 (Exim 4.92) (envelope-from ) id 1sCDhN-0004VO-Bi; Wed, 29 May 2024 07:26:13 +0000 Received: by outflank-mailman (output) from mailman id 731499.1137057; Wed, 29 May 2024 07:26:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhN-0004VF-8C; Wed, 29 May 2024 07:26:13 +0000 Received: by outflank-mailman (input) for mailman id 731499; Wed, 29 May 2024 07:26:11 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhL-0002xp-UK for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:11 +0000 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [2a00:1450:4864:20::141]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7b4ac3f-1d8c-11ef-b4bb-af5377834399; Wed, 29 May 2024 09:26:08 +0200 (CEST) Received: by mail-lf1-x141.google.com with SMTP id 2adb3069b0e04-52b59f77670so93660e87.2 for ; Wed, 29 May 2024 00:26:10 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:07 -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: b7b4ac3f-1d8c-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967569; x=1717572369; 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=SILgfa72VI0ajqqfGUDbvcNqJ8ZZiLfW7kFdd1Zm0SE=; b=AuB4qbJ2xqimzqlEorSKI44W2m0Wekva43pyAvzluEBYQO/uksqZgbPHXejPJW+A7A A0MWYEnCBvwmnO7KNwEeUjMY0MStM2BfoCy+l7SWT+Gvi11A35jaLtlzzDzllpwcWxRq Mo4/WJUN7/fBOL7571xA6onMrSR84WT+JI4+OJGaKLwq2HH8Aj6H0LKdvj6/dHV4STbR TyxEk56Qtue/hNwxFOHEmCe2y67j5WpsNbQe9Q5R13J2TVCWvy5fb4VfeHRCOUlxQigb vtgZVxsxdNTFd29s6T+GkWNxQqFXk4jtePAlTNrmGIZz86iGsenRlGSeL86Ct4BairIX ai1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967569; x=1717572369; 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=SILgfa72VI0ajqqfGUDbvcNqJ8ZZiLfW7kFdd1Zm0SE=; b=Y78kyyTdgmyCjkUxf0blcYMLeUQqQ7vEMfCNnQcfDwlnwXK+TZTbxF9GRfVrL1mlyr /RZktFe1vkCbUNXcf2VTN8rmWEPm8WMLZM2SgvEYrUGlzP4tLPA0sloaj0r2FwIRW6hS P3FVal98/pp2pbmmc0Mr4aiNTlydZhZdYIfv6+OiWsf6Qf9PEB1nAb/Tv2QIEgM0VOsL pfQ1n8pOtLaDbtmeHc9MLjiBFnZN04cHdqFTZ0n37Ot0D1xjAS6KwCXEW0tVnbmwdWlI VULYjptIitvzDMW41RLqt6V7rXPkD2G/IZ+U1cXP+QaSHcUP80N/3AKwMJ0E30jks9Om xy2g== X-Gm-Message-State: AOJu0YzBMnXzEG6TZJB2U0jRsGC+o78anRXPJWEvX3Oa/XTWVJVHJltw +oZhd1ihYkqUtWPaCxDlMNJQZgSLH9w+3GJtR91DbJfr6UkhN63dD+5x5UR/GV/kL4Po8kSDNFR RERFstg== X-Google-Smtp-Source: AGHT+IGBGpu4uivcFEM720OCgQ74X83zEPu/U5/K/JeSfte5w6XVAwJSrJjdaWEyuMCcyTnyu21+EA== X-Received: by 2002:a05:6512:344d:b0:51c:c7ad:329b with SMTP id 2adb3069b0e04-52965c30f7fmr11942347e87.30.1716967569170; Wed, 29 May 2024 00:26:09 -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 v5 4/7] xen/arm: allow dynamically assigned SGI handlers Date: Wed, 29 May 2024 09:25:56 +0200 Message-Id: <20240529072559.2486986-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967592536100005 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. From the Arm Base System Architecture v1.0C [1]: "The system shall implement at least eight Non-secure SGIs, assigned to interrupt IDs 0-7." 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. [1] https://developer.arm.com/documentation/den0094/ Signed-off-by: Jens Wiklander Acked-by: Julien Grall Reviewed-by: Bertrand Marquis --- v3->v4 - Use IRQ_TYPE_EDGE_RISING instead of DT_IRQ_TYPE_EDGE_RISING v2->v3 - Rename GIC_SGI_MAX to GIC_SGI_STATIC_MAX and rename do_sgi() to do_static_sgi() - Update comment in setup_irq() to mention that SGI irq_desc is banked - Add ASSERT() in do_IRQ() that the irq isn't an SGI before injecting calling vgic_inject_irq() - Initialize local_irqs_type[] range for SGIs as IRQ_TYPE_EDGE_RISING - Adding link to the Arm Base System Architecture v1.0C v1->v2 - Update patch description as requested --- xen/arch/arm/gic.c | 12 +++++++----- xen/arch/arm/include/asm/gic.h | 2 +- xen/arch/arm/irq.c | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index b3467a76ae75..3eaf670fd731 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -38,7 +38,7 @@ const struct gic_hw_operations *gic_hw_ops; static void __init __maybe_unused build_assertions(void) { /* Check our enum gic_sgi only covers SGIs */ - BUILD_BUG_ON(GIC_SGI_MAX > NR_GIC_SGI); + BUILD_BUG_ON(GIC_SGI_STATIC_MAX > NR_GIC_SGI); } =20 void register_gic_ops(const struct gic_hw_operations *ops) @@ -117,7 +117,9 @@ 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); + /* SGIs are always edge-triggered, so there is need to set it */ + if ( desc->irq >=3D NR_GIC_SGI) + gic_set_irq_type(desc, desc->arch.type); gic_set_irq_priority(desc, priority); } =20 @@ -322,7 +324,7 @@ void gic_disable_cpu(void) gic_hw_ops->disable_interface(); } =20 -static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi) +static void do_static_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi) { struct irq_desc *desc =3D irq_to_desc(sgi); =20 @@ -367,7 +369,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_STATIC_MAX && irq < 1020) ) { isb(); do_IRQ(regs, irq, is_fiq); @@ -379,7 +381,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_f= iq) } else if ( unlikely(irq < 16) ) { - do_sgi(regs, irq); + do_static_sgi(regs, irq); } else { diff --git a/xen/arch/arm/include/asm/gic.h b/xen/arch/arm/include/asm/gic.h index 03f209529b13..541f0eeb808a 100644 --- a/xen/arch/arm/include/asm/gic.h +++ b/xen/arch/arm/include/asm/gic.h @@ -285,7 +285,7 @@ enum gic_sgi { GIC_SGI_EVENT_CHECK, GIC_SGI_DUMP_STATE, GIC_SGI_CALL_FUNCTION, - GIC_SGI_MAX, + GIC_SGI_STATIC_MAX, }; =20 /* SGI irq mode types */ diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index bcce80a4d624..5224898265a5 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -152,7 +152,13 @@ void __init init_IRQ(void) =20 spin_lock(&local_irqs_type_lock); for ( irq =3D 0; irq < NR_LOCAL_IRQS; irq++ ) - local_irqs_type[irq] =3D IRQ_TYPE_INVALID; + { + /* SGIs are always edge-triggered */ + if ( irq < NR_GIC_SGI ) + local_irqs_type[irq] =3D IRQ_TYPE_EDGE_RISING; + else + local_irqs_type[irq] =3D IRQ_TYPE_INVALID; + } spin_unlock(&local_irqs_type_lock); =20 BUG_ON(init_local_irq_data(smp_processor_id()) < 0); @@ -224,9 +230,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_STATIC_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); @@ -260,6 +269,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int ir= q, int is_fiq) * The irq cannot be a PPI, we only support delivery of SPIs to * guests. */ + ASSERT(irq >=3D NR_GIC_SGI); vgic_inject_irq(info->d, NULL, info->virq, true); goto out_no_end; } @@ -396,7 +406,7 @@ int setup_irq(unsigned int irq, unsigned int irqflags, = struct irqaction *new) { gic_route_irq_to_xen(desc, GIC_PRI_IRQ); /* It's fine to use smp_processor_id() because: - * For PPI: irq_desc is banked + * For SGI and PPI: irq_desc is banked * For SPI: we don't care for now which CPU will receive the * interrupt * TODO: Handle case where SPI is setup on different CPU than --=20 2.34.1 From nobody Thu Nov 6 08:38:18 2025 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=1716967593; cv=none; d=zohomail.com; s=zohoarc; b=ZvrJPEp9o2V/K/OAQQBieEWDFzEUXzuDaSU/yaaoc9/gdR/FYd1ZpHOCGbNz8F3a99+fD1Ni4KqPD4wkhkwPFMrwLnpeKzk/rVZOamdmOVlXJPAivGn7j5hZUBIr7wEkUh6f4pFcFjTBUL1Oy+xc958C3dCABofRuqWxefxRB/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967593; 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=yqcaM/22lmEA4Im1sZdSJGF9/Zga7zG5i6aY5+pENkc=; b=WDlh2nvgCBEiiI4L1ieoLpUnwMzmNCQ23qf/Da97ZCgxHlbYvEB2Stt2ovYoGBiR+e/eneqCIjfcn3FO22MhgNAS+GbGXzl2A6xdsYvr9ig0NQtgnrDtsbSFLtoNEQ8dgbZ2oLDi7lEVlPfxPKaeMIARyiIo2tSTEnqjuBEiCXg= 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 1716967593451892.7833145688843; Wed, 29 May 2024 00:26:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731500.1137062 (Exim 4.92) (envelope-from ) id 1sCDhN-0004YU-NF; Wed, 29 May 2024 07:26:13 +0000 Received: by outflank-mailman (output) from mailman id 731500.1137062; Wed, 29 May 2024 07:26:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhN-0004Xs-Gp; Wed, 29 May 2024 07:26:13 +0000 Received: by outflank-mailman (input) for mailman id 731500; Wed, 29 May 2024 07:26:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhM-0003Qb-Ar for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:12 +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 b97cdd2f-1d8c-11ef-90a1-e314d9c70b13; Wed, 29 May 2024 09:26:11 +0200 (CEST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-52ae14e78e5so352601e87.3 for ; Wed, 29 May 2024 00:26:11 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:09 -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: b97cdd2f-1d8c-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967571; x=1717572371; 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=yqcaM/22lmEA4Im1sZdSJGF9/Zga7zG5i6aY5+pENkc=; b=JoqR5twlnKnlx641Z91rxxU7T2zsze1jbWPyq7jV7bIcw8vMuN6wJR7Q3SoSsE4Y1Q xdzm6RUEM/vpArvjzXs7plobqRFoJ26zqQQ6Kbcn+e1NARTno2gd6YPczuNFYxvsWCpJ 2fvYGpX0AoOlqatB4YnI+w54CeDVmCCJ1LZo8oiMuuj+GklOb/nJhbD5aWdEjNXKAJ/N ioHdR53nLpu0+kjZh+pCe8o5HnJk3vPj59hGIgM8cG43lU/3mUWNH/pyIIzhGHrV3PsY X7pUgi/komKUFXjbQR8Iwpt2IQxeUp+RoSkLnya1PpFEke9SXqXfwVk7l+FfRtWt4DMV Rx7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967571; x=1717572371; 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=yqcaM/22lmEA4Im1sZdSJGF9/Zga7zG5i6aY5+pENkc=; b=v2A/XgjRNFAKdaaFu6kZlF40djo64q5chEUGkphmnxh+hD31caEXmCIbEYrLMu1hIa PltF7hUaIBJCWkXC9vQTXaX6te3JtSkYfpf2lVD5vEKScjN7P6qEVmYOS8Ki/3Enyom5 J675lGnu6pSkA/lVkTw8DjIfnB6awx4GAoD0Uz1/mZ3mnwGP2IVwlO6rnU8O2GzGaPU9 de3PrtDZ/yGXScTFHsVzltu/M73J9JrtiB50VNA8+GzrDbcr2N8Zb5cUX9U2qFGnAoat RUvIiPxBa/0LaTqMDXFMYWL3AZ74BybhC0q0mNGEXxw93+ASDI4W+FY6hHncC0JB3v8K z+GQ== X-Gm-Message-State: AOJu0YxdRXJ9dwOFy18PpGS3BGs8K4Agd+W2v8luHbtLe9UfK58fuNsi NZwtfkg9WoVKDzKRKN36v08y5PgR6a0FeWfBJiQMaB8wib0at0ifkk0Wlny9pbu1Ij9DdW9fRO7 IRfo= X-Google-Smtp-Source: AGHT+IHk4ObidGwCD812vZGe+Z1dmGa50LEp02UVipqGGD3NRtyQPamoN4Tga8ZC5srPW8Wo0VdLlA== X-Received: by 2002:a05:6512:eaa:b0:51c:d6c9:e9a3 with SMTP id 2adb3069b0e04-52964aba890mr10135809e87.17.1716967570797; Wed, 29 May 2024 00:26:10 -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 v5 5/7] xen/arm: add and call init_tee_interrupt() Date: Wed, 29 May 2024 09:25:57 +0200 Message-Id: <20240529072559.2486986-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967594546100007 Content-Type: text/plain; charset="utf-8" Add init_tee_interrupt() to the TEE mediator framework and call it from start_secondary() late enough that per-cpu interrupts can be configured on CPUs as they are initialized. This is needed in later patches. Signed-off-by: Jens Wiklander --- xen/arch/arm/include/asm/tee/tee.h | 8 ++++++++ xen/arch/arm/smpboot.c | 2 ++ xen/arch/arm/tee/tee.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/xen/arch/arm/include/asm/tee/tee.h b/xen/arch/arm/include/asm/= tee/tee.h index da324467e130..eda8a8aa38f2 100644 --- a/xen/arch/arm/include/asm/tee/tee.h +++ b/xen/arch/arm/include/asm/tee/tee.h @@ -28,6 +28,9 @@ struct tee_mediator_ops { */ bool (*probe)(void); =20 + /* Initialize eventual interrupt handlers on the secondary CPUs */ + void (*init_interrupt)(void); + /* * Called during domain construction if toolstack requests to enable * TEE support so mediator can inform TEE about new @@ -66,6 +69,7 @@ int tee_domain_init(struct domain *d, uint16_t tee_type); int tee_domain_teardown(struct domain *d); int tee_relinquish_resources(struct domain *d); uint16_t tee_get_type(void); +void init_tee_interrupt(void); =20 #define REGISTER_TEE_MEDIATOR(_name, _namestr, _type, _ops) \ static const struct tee_mediator_desc __tee_desc_##_name __used \ @@ -105,6 +109,10 @@ static inline uint16_t tee_get_type(void) return XEN_DOMCTL_CONFIG_TEE_NONE; } =20 +static inline void init_tee_interrupt(void) +{ +} + #endif /* CONFIG_TEE */ =20 #endif /* __ARCH_ARM_TEE_TEE_H__ */ diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 93a10d7721b4..e1c1e20efd98 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -29,6 +29,7 @@ #include #include #include +#include =20 /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn @@ -401,6 +402,7 @@ void asmlinkage start_secondary(void) */ init_maintenance_interrupt(); init_timer_interrupt(); + init_tee_interrupt(); =20 local_abort_enable(); =20 diff --git a/xen/arch/arm/tee/tee.c b/xen/arch/arm/tee/tee.c index ddd17506a9ff..8117fd55123e 100644 --- a/xen/arch/arm/tee/tee.c +++ b/xen/arch/arm/tee/tee.c @@ -96,6 +96,12 @@ static int __init tee_init(void) =20 __initcall(tee_init); =20 +void __init init_tee_interrupt(void) +{ + if ( cur_mediator && cur_mediator->ops->init_interrupt) + cur_mediator->ops->init_interrupt(); +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Thu Nov 6 08:38:18 2025 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=1716967590; cv=none; d=zohomail.com; s=zohoarc; b=oKe2c9PispPTd7PxuDk0lh7Pg+zydCe5Xa3jWHU79+EGlk8mBfyAcGBnnIHJvhQsrh+UgZnr8MJACzWD3SlLF9wvVzDDnQMfc4mwcPC12sdGV2ByrciUjLNZpXPY2nCA7FSYGzC1Ubd4P8ozVbZrjXjew9H7JWXAesAsV3PADyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967590; 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=Px3daIYvC5d3ihWRjkhDysb/DJOq/aAiZUJCtozW1Ns=; b=DxpYrDiPAxeo+kfG4H53QW2rtsK4UBcKFpmVhjqlaiX7xJfr64Q3rIoxEVTR3Y6Gb6eF1qN7T8SqwSFib0hSVzZQW56Pdev7+IX3SBICAbRB6OxyUUdOccMQnerMtKPndEHTUUM3dRKNS1FHY/aHysexzjsHU/hqf2iQFO3Vbt8= 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 1716967590041814.1458978313611; Wed, 29 May 2024 00:26:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731501.1137076 (Exim 4.92) (envelope-from ) id 1sCDhQ-000570-S4; Wed, 29 May 2024 07:26:16 +0000 Received: by outflank-mailman (output) from mailman id 731501.1137076; Wed, 29 May 2024 07:26:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhQ-00056q-On; Wed, 29 May 2024 07:26:16 +0000 Received: by outflank-mailman (input) for mailman id 731501; Wed, 29 May 2024 07:26:15 +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 1sCDhP-0002xp-7I for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:15 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b99d04ef-1d8c-11ef-b4bb-af5377834399; Wed, 29 May 2024 09:26:11 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-529682e013dso2045289e87.3 for ; Wed, 29 May 2024 00:26:13 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:11 -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: b99d04ef-1d8c-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967572; x=1717572372; 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=Px3daIYvC5d3ihWRjkhDysb/DJOq/aAiZUJCtozW1Ns=; b=LA4eHj7skT1HsI4uWzgRhfNAZo7SnBYMQNsx5agvJ7gwsb2J/Vqw42wt77K1J+G4Bu fgONsnWw+w7ftjUdfSChH4wqXHGy6q8CPGPkbPi0ii0QtZytxVMWQjHzHnvvkwT1nj2+ reBb9PO4UmgZIkwW2o4psRdg2RbrrtdAVfeA+AkNyhygb8Kp2y3+31xb3pXAAuFeKpgO IQB8/V4DdYcmXNC5SvTGTYbWWj92TPPhjJraWf0FdyPWBZE/gnZuYpiN4UY6MxdzvuwW tPH0wt8WmvT5f+Vyv5HzGOebGqARxyT53TU9oXaO/r3yL6SZVdHWNkRNsJwwJ40fqOzl pQ7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967572; x=1717572372; 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=Px3daIYvC5d3ihWRjkhDysb/DJOq/aAiZUJCtozW1Ns=; b=uImUovKYjA4c/TLcB5obFRmLO9XJ0nqEpPD9VkoSCzJ3P5XA8P5w3xZSq3HTy2WqsG KywJnvLrho4EEpP/tyHBCOIxjJnNDl4KsWAvZaNs8JvpcYZAIo8QLpGJWg+OLI9Lk9qB M65OPS2PjkpG5G3elhYipK7RbBkf1ilmwUn2LT1wITmLCT61XxHhOnvXfK/akkgzZKFz Yq7Gk/pXBNUkOtUUwdH9cd85cRbJSak0CDJSWoCFiiPfy5D/XRGspY9jNJlL9q63A763 XNuktXSCKwF/jSI3XxHzkPRls4UyuEydkShzqSWzN0wfHxpbCwFy4UR18Ywwof6cbwLA ADOg== X-Gm-Message-State: AOJu0Yy3LtSophNl45IhMU0Iz941RBumdL3G1DijDCpWFwjG/QEeGEmg oOrqh/bd9q1o+6tAFqSH2/MDlY1+4IJAarIEVRriWRiWJQZFi6Z4SCnHHqkrr/fl+nKS5WPeReF 1ICA= X-Google-Smtp-Source: AGHT+IHZbnpYtnOOu1mZzARWcnHwDkNNpf8A2L3wrm68sMOOMmvSDs1EjYrgF4UQT+PbkcE6gf4Tyg== X-Received: by 2002:ac2:5dd3:0:b0:521:a96:bf15 with SMTP id 2adb3069b0e04-52965198d34mr8322912e87.38.1716967572307; Wed, 29 May 2024 00:26:12 -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 v5 6/7] xen/arm: add and call tee_free_domain_ctx() Date: Wed, 29 May 2024 09:25:58 +0200 Message-Id: <20240529072559.2486986-7-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967590515100003 Content-Type: text/plain; charset="utf-8" Add tee_free_domain_ctx() to the TEE mediator framework. tee_free_domain_ctx() is called from arch_domain_destroy() to allow late freeing of the d->arch.tee context. This will simplify access to d->arch.tee for domains retrieved with rcu_lock_domain_by_id(). Signed-off-by: Jens Wiklander Reviewed-by: Bertrand Marquis --- xen/arch/arm/domain.c | 1 + xen/arch/arm/include/asm/tee/tee.h | 6 ++++++ xen/arch/arm/tee/tee.c | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 34cbfe699a68..61e46a157ccc 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -837,6 +837,7 @@ int arch_domain_teardown(struct domain *d) =20 void arch_domain_destroy(struct domain *d) { + tee_free_domain_ctx(d); /* IOMMU page table is shared with P2M, always call * iommu_domain_destroy() before p2m_final_teardown(). */ diff --git a/xen/arch/arm/include/asm/tee/tee.h b/xen/arch/arm/include/asm/= tee/tee.h index eda8a8aa38f2..2e99a38184be 100644 --- a/xen/arch/arm/include/asm/tee/tee.h +++ b/xen/arch/arm/include/asm/tee/tee.h @@ -38,6 +38,7 @@ struct tee_mediator_ops { */ int (*domain_init)(struct domain *d); int (*domain_teardown)(struct domain *d); + void (*free_domain_ctx)(struct domain *d); =20 /* * Called during domain destruction to relinquish resources used @@ -70,6 +71,7 @@ int tee_domain_teardown(struct domain *d); int tee_relinquish_resources(struct domain *d); uint16_t tee_get_type(void); void init_tee_interrupt(void); +void tee_free_domain_ctx(struct domain *d); =20 #define REGISTER_TEE_MEDIATOR(_name, _namestr, _type, _ops) \ static const struct tee_mediator_desc __tee_desc_##_name __used \ @@ -113,6 +115,10 @@ static inline void init_tee_interrupt(void) { } =20 +static inline void tee_free_domain_ctx(struct domain *d) +{ +} + #endif /* CONFIG_TEE */ =20 #endif /* __ARCH_ARM_TEE_TEE_H__ */ diff --git a/xen/arch/arm/tee/tee.c b/xen/arch/arm/tee/tee.c index 8117fd55123e..cb65f187f51f 100644 --- a/xen/arch/arm/tee/tee.c +++ b/xen/arch/arm/tee/tee.c @@ -102,6 +102,12 @@ void __init init_tee_interrupt(void) cur_mediator->ops->init_interrupt(); } =20 +void tee_free_domain_ctx(struct domain *d) +{ + if ( cur_mediator && cur_mediator->ops->free_domain_ctx) + cur_mediator->ops->free_domain_ctx(d); +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Thu Nov 6 08:38:18 2025 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=1716967603; cv=none; d=zohomail.com; s=zohoarc; b=EFJO7LJ0PcJFb6KkxzSmFZ0XvcU1OBp8WwDOZQmvHx1WCnRJ6j/cu8tqX6tkXK01rrRSzAP764yivYPQ6krthnaGyq6LSsF8GeoI96QfWQBrLUaq30USxoDbmIyJPObBiCQXBVRA8HxAClnr32dOh3i/ghoW+IXqahkgaaZwX1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716967603; 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=KaYVHgDBDb/dcSaigpLjukQO1YXkyiCDeKoH2jDdqdU=; b=iha3LBIcdu+n+5MTP/rKfJ3KRV31D9+ZT5rtka8IzAlKxa9c6SpHWQEToIE0SqDzRZD2L5Y6wOuN0pVv7S637igPpNI7i6Jb9nbKbSeNULlYsTJKcN/9iyw9KM4zLohdcVlqmtP/yI5MD2z6x6gbDQdcqgDGnJ5EaupiWcZu5po= 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 1716967603914766.8297497094292; Wed, 29 May 2024 00:26:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731504.1137087 (Exim 4.92) (envelope-from ) id 1sCDhT-0005YD-9A; Wed, 29 May 2024 07:26:19 +0000 Received: by outflank-mailman (output) from mailman id 731504.1137087; Wed, 29 May 2024 07:26:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCDhT-0005XA-34; Wed, 29 May 2024 07:26:19 +0000 Received: by outflank-mailman (input) for mailman id 731504; Wed, 29 May 2024 07:26:17 +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 1sCDhR-0002xp-K8 for xen-devel@lists.xenproject.org; Wed, 29 May 2024 07:26:17 +0000 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [2a00:1450:4864:20::142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id baaca1c1-1d8c-11ef-b4bb-af5377834399; Wed, 29 May 2024 09:26:13 +0200 (CEST) Received: by mail-lf1-x142.google.com with SMTP id 2adb3069b0e04-5241b49c0daso2037241e87.0 for ; Wed, 29 May 2024 00:26:15 -0700 (PDT) Received: from localhost.localdomain ([2001:2043:5e37:9d00:b09:3200:dd72:cfc8]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296ee4a58fsm1182353e87.67.2024.05.29.00.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 00:26:12 -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: baaca1c1-1d8c-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716967574; x=1717572374; 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=KaYVHgDBDb/dcSaigpLjukQO1YXkyiCDeKoH2jDdqdU=; b=fPuYR+aCZFeZEX7cxx8imf3UL3TP4JXnZNru7p6LpcAXefpSvHz01nPKdE0dTsYvBn v6aOiy8Nc3TjV+eTmWx8xQsrZAeu1uptC5ay8QnzVqkPlZr/oxCjzyyhUgV+IHAImhYS ZDbA3o6qaLnCJz0QrDyLv98fNzCGBLTBPIoE3VRrKEXkifidEHsYiF5qXm0J9eYZzARH hAIzNq7LB1BLgQXCc4o/gdWCQ+3NjdDZYo6+Z6dFOkowTcmAC3yyBcdAyOaI2mzVyWfY nDphTS1WmBA6yQ2mKgWmU/HQDCubsriEPESgnv0V0wDeP0+zqf7yhkq6syJM8/AGqVci YyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716967574; x=1717572374; 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=KaYVHgDBDb/dcSaigpLjukQO1YXkyiCDeKoH2jDdqdU=; b=K4gqPMGLsIgZHqDTSk8CtYoku+PVhq213QQN5jfX+eOIzLi7THs1l09qlavyEQzq0b cuTxkstsl4rS7JzvDg4UFcQ5REUOQV3RJQW3KohBSM96nG2QRyQGyPp/5tKR3DmmKUnm i/WdQ736wvDq8P272uKZXBxYbGEG01X5H4fZhKiU1GgeqrNR9/A8jNQ5MiFVeEju5xIm yH4vchZs2l72AYbtacGyThml1fDnypotzD7Boxmj1c+/Ae0kZ0ZlBC1rL4xcE9APeE5D l9FOKxyqJczSltz+xGGE90PsljUumEDtQG8p7fv8u5NUox2lAgc/28nAYXCUxRDdlTnh FWZQ== X-Gm-Message-State: AOJu0YyD4CarN72AWWgE2OjHZs3lKkk5ogMTrQFvuDgKdej5FmXrZBAv GqMPhYdEz3P2Skxi+MXC+WZwHafJUzc64nQalwaV+bXETuRiiEgXzSUuFDGjtQ6GCdPoj0Dj47G bSu4PQA== X-Google-Smtp-Source: AGHT+IGDjJw1+iUK1GJvCm2xiDFsxGaereF2OKqYlw8CutyGSEtt28lcpc5JDhpdakdMJJ06xROlVQ== X-Received: by 2002:ac2:4f8a:0:b0:519:6953:2ffc with SMTP id 2adb3069b0e04-52966ca64bbmr8145309e87.42.1716967573859; Wed, 29 May 2024 00:26:13 -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 v5 7/7] xen/arm: ffa: support notification Date: Wed, 29 May 2024 09:25:59 +0200 Message-Id: <20240529072559.2486986-8-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529072559.2486986-1-jens.wiklander@linaro.org> References: <20240529072559.2486986-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1716967604720100001 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 triggers a tasklet to retrieve 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 --- v4->v5: - Move the freeing of d->arch.tee to the new TEE mediator free_domain_ctx callback to make the context accessible during rcu_lock_domain_by_id() from a tasklet - Initialize interrupt handlers for secondary CPUs from the new TEE mediator init_interrupt() callback - Restore the ffa_probe() from v3, that is, remove the presmp_initcall(ffa_init) approach and use ffa_probe() as usual now that = we have the init_interrupt callback. - A tasklet is added to handle the Schedule Receiver interrupt. The tasklet finds each relevant domain with rcu_lock_domain_by_id() which now is enou= gh to guarantee that the FF-A context can be accessed. - The notification interrupt handler only schedules the notification tasklet mentioned above v3->v4: - Add another note on FF-A limitations - Clear secure_pending in ffa_handle_notification_get() if both SP and SPM bitmaps are retrieved - ASSERT that ffa_rcu_lock_domain_by_vm_id() isn't passed the vm_id FF-A uses for Xen itself - Replace the get_domain_by_id() call done via ffa_get_domain_by_vm_id() in notif_irq_handler() with a call to rcu_lock_live_remote_domain_by_id() via ffa_rcu_lock_domain_by_vm_id() - Remove spinlock in struct ffa_ctx_notif and use atomic functions as needed to access and update the secure_pending field - In notif_irq_handler(), look for the first online CPU instead of assuming that the first CPU is online - Initialize FF-A via presmp_initcall() before the other CPUs are online, use register_cpu_notifier() to install the interrupt handler notif_irq_handler() - Update commit message to reflect recent updates v2->v3: - Add a GUEST_ prefix and move FFA_NOTIF_PEND_INTR_ID and FFA_SCHEDULE_RECV_INTR_ID to public/arch-arm.h - Register the Xen SRI handler on each CPU using on_selected_cpus() and setup_irq() - Check that the SGI ID retrieved with FFA_FEATURE_SCHEDULE_RECV_INTR doesn't conflict with static SGI handlers 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 | 72 +++++- xen/arch/arm/tee/ffa_notif.c | 409 ++++++++++++++++++++++++++++++++ xen/arch/arm/tee/ffa_partinfo.c | 9 +- xen/arch/arm/tee/ffa_private.h | 56 ++++- xen/arch/arm/tee/tee.c | 2 +- xen/include/public/arch-arm.h | 14 ++ 7 files changed, 548 insertions(+), 15 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..d644ee97cd5b 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -39,6 +39,12 @@ * - 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 + * - doesn't support signalling the secondary scheduler of pending + * notification for secure partitions + * - doesn't support notifications for Xen itself * * 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 +200,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 +248,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, GUEST_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, GUEST_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 +337,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 +370,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 +394,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) @@ -376,13 +426,6 @@ static void ffa_domain_teardown_continue(struct ffa_ct= x *ctx, bool first_time) } else { - /* - * domain_destroy() might have been called (via put_domain() in - * ffa_reclaim_shms()), so we can't touch the domain structure - * anymore. - */ - xfree(ctx); - /* Only check if there has been a change to the teardown queue */ if ( !first_time ) { @@ -423,12 +466,18 @@ 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 return 0; } =20 +static void ffa_free_domain_ctx(struct domain *d) +{ + XFREE(d->arch.tee); +} + static int ffa_relinquish_resources(struct domain *d) { return 0; @@ -502,6 +551,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 @@ -517,8 +567,10 @@ err_rxtx_destroy: static const struct tee_mediator_ops ffa_ops =3D { .probe =3D ffa_probe, + .init_interrupt =3D ffa_notif_init_interrupt, .domain_init =3D ffa_domain_init, .domain_teardown =3D ffa_domain_teardown, + .free_domain_ctx =3D ffa_free_domain_ctx, .relinquish_resources =3D ffa_relinquish_resources, .handle_call =3D ffa_handle_call, }; diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c new file mode 100644 index 000000000000..e8e8b62590b3 --- /dev/null +++ b/xen/arch/arm/tee/ffa_notif.c @@ -0,0 +1,409 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ffa_private.h" + +static bool __ro_after_init notif_enabled; +static unsigned int __ro_after_init notif_sri_irq; + +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; + + if ( !notif_enabled ) + { + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + return; + } + + if ( test_and_clear_bool(ctx->notif.secure_pending) ) + { + /* 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; + + /* + * Clear secure pending if both FFA_NOTIF_FLAG_BITMAP_SP and + * FFA_NOTIF_FLAG_BITMAP_SPM are set since secure world can't have + * any more pending notifications. + */ + if ( ( flags & FFA_NOTIF_FLAG_BITMAP_SP ) && + ( flags & FFA_NOTIF_FLAG_BITMAP_SPM ) ) + { + struct ffa_ctx *ctx =3D d->arch.tee; + + ACCESS_ONCE(ctx->notif.secure_pending) =3D false; + } + + 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_vm_pend_intr(uint16_t vm_id) +{ + struct ffa_ctx *ctx; + struct domain *d; + struct vcpu *v; + + /* + * vm_id =3D=3D 0 means a notifications pending for Xen itself, but + * we don't support that yet. + */ + if ( !vm_id ) + return; + + d =3D ffa_rcu_lock_domain_by_vm_id(vm_id); + if ( !d ) + return; + + ctx =3D d->arch.tee; + if ( !ctx ) + goto out_unlock; + + /* + * arch.tee is freed from complete_domain_destroy() so the RCU lock + * guarantees that the data structure isn't freed while we're accessing + * it. + */ + ACCESS_ONCE(ctx->notif.secure_pending) =3D true; + + /* + * Since we're only delivering global notification, always + * deliver to the first online vCPU. It doesn't matter + * which we chose, as long as it's available. + */ + for_each_vcpu(d, v) + { + if ( is_vcpu_online(v) ) + { + vgic_inject_irq(d, v, GUEST_FFA_NOTIF_PEND_INTR_ID, + true); + break; + } + } + if ( !v ) + printk(XENLOG_ERR "ffa: can't inject NPI, all vCPUs offline\n"); + +out_unlock: + rcu_unlock_domain(d); +} + +static void notif_sri_action(void *unused) +{ + 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; + uint16_t vm_id =3D get_id_from_resp(&resp, id_pos); + + notif_vm_pend_intr(vm_id); + + id_pos +=3D count; + } + + } while (resp.a2 & FFA_NOTIF_INFO_GET_MORE_FLAG); +} + +static DECLARE_TASKLET(notif_sri_tasklet, notif_sri_action, NULL); + +static void notif_irq_handler(int irq, void *data) +{ + tasklet_schedule(¬if_sri_tasklet); +} + +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_interrupt(void) +{ + int ret; + + if ( notif_enabled && notif_sri_irq < NR_GIC_SGI ) + { + /* + * An error here is unlikely since the primary CPU has already + * succeeded in installing the interrupt handler. If this fails it + * may lead to a problem with notifictaions. + * + * The CPUs without an notification handler installed will fail to + * trigger on the SGI indicating that there are notifications + * pending, while the SPMC in the secure world will not notice that + * the interrupt was lost. + */ + ret =3D request_irq(notif_sri_irq, 0, notif_irq_handler, "FF-A not= if", + NULL); + if ( ret ) + printk(XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n", + notif_sri_irq, ret); + } +} + +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; + notif_sri_irq =3D irq; + 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); + return; + } + + notif_enabled =3D true; +} + +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..7c6b06f686fc 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 @@ -175,6 +176,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 +229,24 @@ #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; + + /* + * 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 +262,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 +292,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 +306,31 @@ 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); +void ffa_notif_init_interrupt(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_rcu_lock_domain_by_vm_id(uint16_t vm_id) +{ + ASSERT(vm_id); + + /* -1 to match ffa_get_vm_id() */ + return rcu_lock_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, diff --git a/xen/arch/arm/tee/tee.c b/xen/arch/arm/tee/tee.c index cb65f187f51f..1e890ecc2932 100644 --- a/xen/arch/arm/tee/tee.c +++ b/xen/arch/arm/tee/tee.c @@ -94,7 +94,7 @@ static int __init tee_init(void) return 0; } =20 -__initcall(tee_init); +presmp_initcall(tee_init); =20 void __init init_tee_interrupt(void) { diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 289af81bd69d..e2412a17474e 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -505,6 +505,7 @@ typedef uint64_t xen_callback_t; #define GUEST_MAX_VCPUS 128 =20 /* Interrupts */ + #define GUEST_TIMER_VIRT_PPI 27 #define GUEST_TIMER_PHYS_S_PPI 29 #define GUEST_TIMER_PHYS_NS_PPI 30 @@ -515,6 +516,19 @@ typedef uint64_t xen_callback_t; #define GUEST_VIRTIO_MMIO_SPI_FIRST 33 #define GUEST_VIRTIO_MMIO_SPI_LAST 43 =20 +/* + * SGI is the preferred delivery mechanism of FF-A pending notifications or + * schedule recveive interrupt. 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. + * + * For partitioning of SGIs see also Arm Base System Architecture v1.0C, + * https://developer.arm.com/documentation/den0094/ + */ +#define GUEST_FFA_NOTIF_PEND_INTR_ID 8 +#define GUEST_FFA_SCHEDULE_RECV_INTR_ID 9 + /* PSCI functions */ #define PSCI_cpu_suspend 0 #define PSCI_cpu_off 1 --=20 2.34.1