From patchwork Tue Apr 9 15:36:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13622897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02C09CD128A for ; Tue, 9 Apr 2024 15:36:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.702501.1097578 (Exim 4.92) (envelope-from ) id 1ruDWa-0005X9-Pg; Tue, 09 Apr 2024 15:36:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 702501.1097578; Tue, 09 Apr 2024 15:36: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 1ruDWa-0005X2-MJ; Tue, 09 Apr 2024 15:36:40 +0000 Received: by outflank-mailman (input) for mailman id 702501; Tue, 09 Apr 2024 15:36:39 +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 1ruDWZ-0005IN-41 for xen-devel@lists.xenproject.org; Tue, 09 Apr 2024 15:36:39 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f3be7998-f686-11ee-94a3-07e782e9044d; Tue, 09 Apr 2024 17:36:37 +0200 (CEST) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a44665605f3so658896566b.2 for ; Tue, 09 Apr 2024 08:36:37 -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 gs44-20020a1709072d2c00b00a46a3ad035esm5849000ejc.179.2024.04.09.08.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:36:35 -0700 (PDT) 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: f3be7998-f686-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712676996; x=1713281796; 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=tq93WPQosnJ9mNzaU1t6RTCuYLzdJLsCMqw2tR2kTUc=; b=dn0myULHZ1TQtYEf4eDWraP2MQK56OXDIPpGPR7qc2i8HV1OeYHFRIoM5Cv5L9f6Le HRRtMYSh8rr1bEydGfsxCaHqEJ21+X/Ul7y8TTv3Ryp+nSh1a9XCU8pYyOzYHbYb9ld5 IKVjFo71hXXxaR823NoQffiKwUmlUiT7NnZUKaUMwN3TMH3OciwVkJeMAN13E7I47eRJ 30xTUa8hBqdNjsoBUzmsbIf8Xm1AB3njIGfZHuBP02M5ynTgHoWbFP7w45+fbJ/YhuLD FO8rdq52UGKy/12FmN8nTshuHhlykBY/JTqSL2tMMoAZpUM9WCBoZ7Biugljhi2Ox8i6 0/5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712676996; x=1713281796; 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=tq93WPQosnJ9mNzaU1t6RTCuYLzdJLsCMqw2tR2kTUc=; b=pRVd9UaIBQsDnTSGNHfxNhXeJkdOZ2JkWtQS51XsvyEacp16uf+pvBCfWv317vSnGp Z8QxJkkV72B/8cp6ww1bRzae6WmtH4fsYWLs1z9OAs/liLmUFnuaaydyqkxbSEOkpwsX HLlOnnB3xL7tOM4WrY5HH8x4EQi+ipBt9UCgBit3+NmJjm5SfphF1SK3MX+pfDHWB8C3 rU3g73DgRZUHaE66pxXvYk8PKdtj9CKNQWCTKwVCRjdBHZe2WC8onxUml9hH5FekoqOZ ig/xeHIMBwvmP6tDz6XqrS9Sn8r7qW5D8Rquj44NAmNJua95h4jQ9NhSRXVBu2+0HbWF ciRg== X-Gm-Message-State: AOJu0YyV7bXLwJQzP20bJq5jg3R0ADd2/TblVhNxRSxw9fsyq87jJXoQ YUkM5z8U2du7vsK4aQgmB60/BqvqjFNs1V+ST9wY0nqYTrGyU80VWmRxv+aC9kH87yOpVoe2ieh Z X-Google-Smtp-Source: AGHT+IHzQ4aNK0bOM68T+jvL5+0yoYRMd3y8CZAcEIbSCHRQw5E/IvmNyJidSpMF2jN5u6WxxPPjtQ== X-Received: by 2002:a17:906:fb8d:b0:a51:986c:79dd with SMTP id lr13-20020a170906fb8d00b00a51986c79ddmr7613505ejb.27.1712676996347; Tue, 09 Apr 2024 08:36:36 -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 v1 1/5] xen/arm: ffa: refactor ffa_handle_call() Date: Tue, 9 Apr 2024 17:36:26 +0200 Message-Id: <20240409153630.2026584-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409153630.2026584-1-jens.wiklander@linaro.org> References: <20240409153630.2026584-1-jens.wiklander@linaro.org> MIME-Version: 1.0 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 *regs) case FFA_RXTX_MAP_64: e = 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 = 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 = 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 = 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 *regs) e = 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; 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; } static int ffa_domain_init(struct domain *d) From patchwork Tue Apr 9 15:36:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13622899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98C6FCD129A for ; Tue, 9 Apr 2024 15:36:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.702502.1097583 (Exim 4.92) (envelope-from ) id 1ruDWb-0005aT-3d; Tue, 09 Apr 2024 15:36:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 702502.1097583; Tue, 09 Apr 2024 15:36:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ruDWa-0005Zp-Th; Tue, 09 Apr 2024 15:36:40 +0000 Received: by outflank-mailman (input) for mailman id 702502; Tue, 09 Apr 2024 15:36:39 +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 1ruDWZ-0005IN-Oz for xen-devel@lists.xenproject.org; Tue, 09 Apr 2024 15:36:39 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f4456e89-f686-11ee-94a3-07e782e9044d; Tue, 09 Apr 2024 17:36:38 +0200 (CEST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a5200202c1bso73898366b.0 for ; Tue, 09 Apr 2024 08:36:38 -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 gs44-20020a1709072d2c00b00a46a3ad035esm5849000ejc.179.2024.04.09.08.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:36:37 -0700 (PDT) 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: f4456e89-f686-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712676997; x=1713281797; 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=2oUmASxTp+9g/nhjEeQPRm9Cad1umKqLTvyNY/+uRUE=; b=E+guPPP4NS6AjQTZ5xJbP015XBPfd+EXo9xJGDnzZWWTxfJgskyeX17wV4cGYdf7NC dB9gvH9Ij/6OUGF/9VUNe1EA1gSVLzqzd9oAbrFh2t9/CtOUt/PZp0mLWQ19p/uuZzZo f99ZMPea97mEQU574Z+4S3NYFoH2C1QkwGQC42WkOQpm9/He0+kkWjvcsJ6WGHuiQC15 cVSEwP5IvBKXviPuAm++ZdqLyiLoOaQ2X463f1M0B2TAaOj0gCGH8qjMYCFbXisTvy2K fZi4dsWjp7f79T/ms7UF7ItWNJRo9UhgzBPeKMD6Hei5ltfn+qg4buV2/wwbTBernPoM 1Ceg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712676997; x=1713281797; 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=2oUmASxTp+9g/nhjEeQPRm9Cad1umKqLTvyNY/+uRUE=; b=tqOwrThUUTDekfCQ+29BaxCtO87fxfkLMIqlH0nmPlHY+6F16oDw/DLi6LYCxK4M4+ L9g5o2jblm0gG06goKYhjPpdiKWPGp9F1QmjyYAaOnONKLxsBfXlVfQ9n9UkUd8S7Kcr 2uvgvwsulXCfgFrVxobRuDV59KRygArRVSNx52DxJfBz4h7J1v8dCQslis0+73swINSH ywX4G+2u3g4xwVzXTkjdRZE5kCmdBf38Te3c82I8Fqd621TSwQKdIkuXb9+DzrxQvyJL 4Lwd4gM6V2Ax6Mm+8CmfXffgjzlJ65R9ipUv1w6NgeOLLgs52fg3QFkr8QhLvsvrekfK QBzA== X-Gm-Message-State: AOJu0Yy0/Lb4RzaCew8a2RdJB3NWihxNn8MsTLGC5CBz9eNWyR3EIUt3 M7Cd2CIrW1S7nqGe9arrlEK36TCyuu5f5Wiwrec0xC1fnLFkk2ugr+iiV7rXMHBoqMVlp5j+OCK s X-Google-Smtp-Source: AGHT+IGbto1wNOCGSVxLb+C98WA2o9ISJr0k/9kSL+BzB/yrxIQfwl4kANp2eL8ONh7P0r3LzcNXAQ== X-Received: by 2002:a17:907:72c4:b0:a46:dd30:7cb5 with SMTP id du4-20020a17090772c400b00a46dd307cb5mr11754671ejc.76.1712676997351; Tue, 09 Apr 2024 08:36:37 -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 v1 2/5] xen/arm: ffa: use ACCESS_ONCE() Date: Tue, 9 Apr 2024 17:36:27 +0200 Message-Id: <20240409153630.2026584-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409153630.2026584-1-jens.wiklander@linaro.org> References: <20240409153630.2026584-1-jens.wiklander@linaro.org> MIME-Version: 1.0 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 @@ -171,8 +172,8 @@ static int get_shm_pages(struct domain *d, struct ffa_shm_mem *shm, for ( n = 0; n < range_count; n++ ) { - page_count = read_atomic(&range[n].page_count); - addr = read_atomic(&range[n].address); + page_count = ACCESS_ONCE(range[n].page_count); + addr = ACCESS_ONCE(range[n].address); for ( m = 0; m < page_count; m++ ) { if ( pg_idx >= shm->page_count ) @@ -527,13 +528,13 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out_unlock; mem_access = ctx->tx + trans.mem_access_offs; - if ( read_atomic(&mem_access->access_perm.perm) != FFA_MEM_ACC_RW ) + if ( ACCESS_ONCE(mem_access->access_perm.perm) != FFA_MEM_ACC_RW ) { ret = FFA_RET_NOT_SUPPORTED; goto out_unlock; } - region_offs = read_atomic(&mem_access->region_offs); + region_offs = ACCESS_ONCE(mem_access->region_offs); if ( sizeof(*region_descr) + region_offs > frag_len ) { ret = FFA_RET_NOT_SUPPORTED; @@ -541,8 +542,8 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) } region_descr = ctx->tx + region_offs; - range_count = read_atomic(®ion_descr->address_range_count); - page_count = read_atomic(®ion_descr->total_page_count); + range_count = ACCESS_ONCE(region_descr->address_range_count); + page_count = ACCESS_ONCE(region_descr->total_page_count); if ( !page_count ) { @@ -557,7 +558,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out_unlock; } shm->sender_id = trans.sender_id; - shm->ep_id = read_atomic(&mem_access->access_perm.endpoint_id); + shm->ep_id = ACCESS_ONCE(mem_access->access_perm.endpoint_id); /* * Check that the Composite memory region descriptor fits. From patchwork Tue Apr 9 15:36:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13622898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08AD5CD129C for ; Tue, 9 Apr 2024 15:36:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.702504.1097593 (Exim 4.92) (envelope-from ) id 1ruDWb-0005oK-ML; Tue, 09 Apr 2024 15:36:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 702504.1097593; Tue, 09 Apr 2024 15:36:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ruDWb-0005kU-HA; Tue, 09 Apr 2024 15:36:41 +0000 Received: by outflank-mailman (input) for mailman id 702504; Tue, 09 Apr 2024 15:36:40 +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 1ruDWa-0005IN-P5 for xen-devel@lists.xenproject.org; Tue, 09 Apr 2024 15:36:40 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f4da0e13-f686-11ee-94a3-07e782e9044d; Tue, 09 Apr 2024 17:36:39 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a519eae91d1so553105666b.3 for ; Tue, 09 Apr 2024 08:36:39 -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 gs44-20020a1709072d2c00b00a46a3ad035esm5849000ejc.179.2024.04.09.08.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:36:38 -0700 (PDT) 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: f4da0e13-f686-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712676998; x=1713281798; 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=C8OCgwxfFNBl0g/LFD7KGefGi5I0NjNvh/BY8PRWmBI=; b=G/QzDv2s9Qtf0wUCYr8OL9nTWgFvBwYh2sA/xKsd2kqNDE4L/YKGfPsUpEvtuQdCuy xYeVtNpCuUY8i893qQ02Qb3/l+JsXObnOrYiHOr8Eeg7Bbi6rlilIjv2OQMBXxnJ49oh fXtDoszs3FAyWFM719yq+gAknab3N7ibbJIuvIEmz33BuzCluVOU1alHa6Dmpwa+8M2g l0kvHFxRN4YZ+LJcDVUgC+gdtR2nzOpW0Y0WnUj80EtRgT+SedjI7stYLx8DyV5tX0ft wD2/4W/yUU28qOYmQy8la8jM/XNFvwgkc5leCiedcOvrusFMa7lua0bTCZBLVjQfIoOw lRSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712676998; x=1713281798; 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=C8OCgwxfFNBl0g/LFD7KGefGi5I0NjNvh/BY8PRWmBI=; b=VY7tMpb/yKFIrTOvRFTKWJlEGeRnm8fuXRqwoSxBOl6MCiYYlzDSLJMKNWzx/tI7VP D/K1vc351Rn5xIkpgbIQeVVWRThZp8tbaVMWScChCXXj9BNZjbiVN3Wpx/3YSLKqRjjo JztgGcjdWY4oFS7yanLBigzNDZPHswiyhkJDcI8zlVj2RpxHAfeulZhks3WZhnQa0Qm9 DJjZkY37xZFBIUfbFaFPbNImMV29QNWZ1dJ8Yi8GER3nbNhdv4kc75kWxpte1TYjxdmb OyvBfdeRTVhGZuyq0NV+6ohER+q9F79VmXqVL3saD8fO8uoiq6JW7Vg2FfYRgonjYEp7 6qyg== X-Gm-Message-State: AOJu0YzAQ5Rq23V9hQV04r6ShhH5Fe97l84i+1PPGHRqhUi1rLkBH5cT VeDy02HDJwqn1T1sxU+HN5SOGs/hq0Xh6yXuusDc9Y30KdXOUD3/ofGDmQhHtNveK0MG7+gjMxv a X-Google-Smtp-Source: AGHT+IEV6VmAkaioQ3AY4tx0PhOMRDHEhLjTgJ4V/HabB0Lb33pB1LlO5vHf9bOM8u8CsFT7cXzTQw== X-Received: by 2002:a17:907:7b88:b0:a51:a488:8fb8 with SMTP id ne8-20020a1709077b8800b00a51a4888fb8mr8848674ejc.70.1712676998350; Tue, 09 Apr 2024 08:36:38 -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 v1 3/5] xen/arm: ffa: simplify ffa_handle_mem_share() Date: Tue, 9 Apr 2024 17:36:28 +0200 Message-Id: <20240409153630.2026584-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409153630.2026584-1-jens.wiklander@linaro.org> References: <20240409153630.2026584-1-jens.wiklander@linaro.org> MIME-Version: 1.0 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, uint32_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 = start_page_idx; + unsigned int pg_idx = 0; gfn_t gfn; unsigned int n; unsigned int m; @@ -191,7 +190,9 @@ static int get_shm_pages(struct domain *d, struct ffa_shm_mem *shm, } } - *last_page_idx = pg_idx; + /* The ranges must add up */ + if ( pg_idx < shm->page_count ) + return FFA_RET_INVALID_PARAMETERS; return FFA_RET_OK; } @@ -460,7 +461,6 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) struct domain *d = current->domain; struct ffa_ctx *ctx = d->arch.tee; struct ffa_shm_mem *shm = NULL; - unsigned int last_page_idx = 0; register_t handle_hi = 0; register_t handle_lo = 0; int ret = FFA_RET_DENIED; @@ -570,15 +570,9 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out; } - ret = get_shm_pages(d, shm, region_descr->address_range_array, range_count, - 0, &last_page_idx); + ret = get_shm_pages(d, shm, region_descr->address_range_array, range_count); if ( ret ) goto out; - if ( last_page_idx != shm->page_count ) - { - ret = FFA_RET_INVALID_PARAMETERS; - goto out; - } /* Note that share_shm() uses our tx buffer */ spin_lock(&ffa_tx_buffer_lock); From patchwork Tue Apr 9 15:36:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13622901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F002CD129D for ; Tue, 9 Apr 2024 15:36:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.702503.1097590 (Exim 4.92) (envelope-from ) id 1ruDWb-0005gI-FZ; Tue, 09 Apr 2024 15:36:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 702503.1097590; Tue, 09 Apr 2024 15:36:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ruDWb-0005eU-80; Tue, 09 Apr 2024 15:36:41 +0000 Received: by outflank-mailman (input) for mailman id 702503; Tue, 09 Apr 2024 15:36:40 +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 1ruDWa-0005IE-E1 for xen-devel@lists.xenproject.org; Tue, 09 Apr 2024 15:36:40 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f565771a-f686-11ee-b907-491648fe20b8; Tue, 09 Apr 2024 17:36:39 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a51a7d4466bso518056466b.2 for ; Tue, 09 Apr 2024 08:36:39 -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 gs44-20020a1709072d2c00b00a46a3ad035esm5849000ejc.179.2024.04.09.08.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:36:38 -0700 (PDT) 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: f565771a-f686-11ee-b907-491648fe20b8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712676999; x=1713281799; 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=+uEJrO4wREA7Y495lkxFCQXI3O8u6pydWDQAtd/HK8M=; b=oGNEd/lLI5v+J19dOV/2sePbBZGcjY1E8ymJ8bXIq8owBLcv/EUegKtFZ5w9pBo/3x CLwwe4sjbBW3FlkGQrrmRhmSSWqU8Br8TEiYQENrzatP6zUJ37zM9zlOBz+Kaoi9WBAx CAgctetevhuoUXk88cx93QNOtJtD1i7Vm0UUYqaTmPMMO4WGLjmBc7oB6dkNOxl8Le8K 4e2+tNjoGcZJLU1LCzdAoCAc+I35lmX9bm8a5MppVMFbx7AKSYRioS9RNikzwpceM9fJ z/vLWSpX7FIKEX/SWGa4dJojzpB7PrZDS00Ep8MriqnGONjEBJjI0fgao1UNGlRgd4M4 YBFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712676999; x=1713281799; 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=+uEJrO4wREA7Y495lkxFCQXI3O8u6pydWDQAtd/HK8M=; b=E7xaA2DjadlkOrgwcEDJ+BLsET4qc2Y1aOVI7L/t3eyhcpxRjiFsEFyTR+MtMlusbS uzgf+DmL/bDOvVl4mguAs69VLSdDrN2eM8KxP9d5LV0bAHqTqeFWbLPdfStC2f7uFKA+ KT2jmBxYclZMS+qaUGfQJAusy8NF7022y5YIV3GXBnoQpMnnw2d9g8OUNh5PwTR4zDEo UHbhMktv8MLVh37zWyn6d7DY9qqwBjHsmzuUIIC2GL8QFky7mrJkBxFOVn2ASPFfXvch NjcvJMuH8cCWid4C84fD3Og7e0v0Ge+8Rpif0ckIxTORhMG1pn2Kv8MwPHOCrpG+nwMh rNRg== X-Gm-Message-State: AOJu0YyRQE5ZZDvWuTH6ypAv6zubejQ0x+05/jJNnVxGL6a1B+fqO93s d/ensJyXBGrfqip35I/EipSdZwbIXHFoEyOaiY7LWy0NI/nIKjdiUFXfd5od30KJtxzf0fnP9FR s X-Google-Smtp-Source: AGHT+IG0Viseu+hUAYAPjjQpOZn2uDv0CplDB0QrTJy7b31K6uj6uQbi8ba76tBgsTmmrU8GNqnLVQ== X-Received: by 2002:a17:907:3fa3:b0:a51:d2d4:1302 with SMTP id hr35-20020a1709073fa300b00a51d2d41302mr5631524ejc.40.1712676999287; Tue, 09 Apr 2024 08:36:39 -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 v1 4/5] xen/arm: allow dynamically assigned SGI handlers Date: Tue, 9 Apr 2024 17:36:29 +0200 Message-Id: <20240409153630.2026584-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409153630.2026584-1-jens.wiklander@linaro.org> References: <20240409153630.2026584-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Updates so request_irq() can be used with a dynamically assigned SGI irq as input. gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they have their type assigned earlier during boot 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 Acked-by: Michal Orzel --- 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, unsigned int priority) desc->handler = gic_hw_ops->gic_host_irq_type; - gic_set_irq_type(desc, desc->arch.type); + if ( desc->irq >= NR_GIC_SGI) + gic_set_irq_type(desc, desc->arch.type); gic_set_irq_priority(desc, priority); } @@ -375,7 +376,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq) /* Reading IRQ will ACK it */ irq = gic_hw_ops->read_irq(); - if ( likely(irq >= 16 && irq < 1020) ) + if ( likely(irq >= 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 irq, int is_fiq) perfc_incr(irqs); - ASSERT(irq >= 16); /* SGIs do not come down this path */ + /* Statically assigned SGIs do not come down this path */ + ASSERT(irq >= GIC_SGI_MAX); - 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); From patchwork Tue Apr 9 15:36:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 13622900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB48FCD1296 for ; Tue, 9 Apr 2024 15:36:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.702505.1097618 (Exim 4.92) (envelope-from ) id 1ruDWe-0006YC-SM; Tue, 09 Apr 2024 15:36:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 702505.1097618; Tue, 09 Apr 2024 15:36:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ruDWe-0006Y0-OE; Tue, 09 Apr 2024 15:36:44 +0000 Received: by outflank-mailman (input) for mailman id 702505; Tue, 09 Apr 2024 15:36:43 +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 1ruDWd-0005IN-AN for xen-devel@lists.xenproject.org; Tue, 09 Apr 2024 15:36:43 +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 f633d0cd-f686-11ee-94a3-07e782e9044d; Tue, 09 Apr 2024 17:36:41 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-516d47ce662so7418911e87.1 for ; Tue, 09 Apr 2024 08:36: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 gs44-20020a1709072d2c00b00a46a3ad035esm5849000ejc.179.2024.04.09.08.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:36:39 -0700 (PDT) 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: f633d0cd-f686-11ee-94a3-07e782e9044d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712677000; x=1713281800; 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=pkiNITyS2Gv4ORmeiWESmXZBMWeFqhOQWcTG7lLPN6s=; b=EPAM68IqZCexAA0Tgfi6dlwTN3cMb5kOWQCZmRBmF1GLPVnUB2AtcwHcpVxNUVJZPZ 5yR7z73HIrce3Y6puagjun/KXSLCQnrUd6vwDfWEsTPK1J+quByNt+wo6EHx1cWALow3 SzR2O9w5oWzvVRvH0M6HNE727vuOYb/snOZHhySb7ZQ88QFZckt3Fxa6dDDgjYjMfF1i m6jXdoezTaH/stU4xUyxfXJBrUlGJYPPN14Uksc0RovEhRVzGlSkQ63qU78PobIpplMK aDBUcmVBA6+QcJSewSSiK8UD0a6PmNABIt2pvngXWW5ixERy0e38C0jEhyzbn3U+b1f2 zfRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712677000; x=1713281800; 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=pkiNITyS2Gv4ORmeiWESmXZBMWeFqhOQWcTG7lLPN6s=; b=Aa8xqo08AyLA3TnfAtexvIRJm0az80R0DbbZhqAxpFHyX5497vjN31AfTCDiq93baK lFWUQAewphY6mvF2/iAnXFQHGcpWQfKPwAVVZInyXAqZtvcSCPxPKI+e9X2M+Dntk5e0 GRRskccYDbmc/DJpTZFGuUrnfOty42eTq+Glnu6W56PgA1KAM+ysgem3gGbfxy5eo2tW fcLHK3OLWSUp/3DLfwzIL4WB9ukSFzPfy3fR7zIB45G1z210OcA/cl/ZjDRU+/ZG1pRQ OyliJ5dJDT6g/akeHtRK5K20gv2IDIK5lV4cZptbALKq/2lSef1ZaYWnzmjwu+pzgV+K Z1CA== X-Gm-Message-State: AOJu0YyP2ysP1pwXVOV7oyZ2oY4yBXXj6N0z4xjdGszV22/JE04Z9CiF V1YNZQFyK4c84kIE8dHVp093ShmuwtCB0vhV9ggO7mwAwc6ZPt1dZFzN15Iw+F3THajBfWhoClI Z X-Google-Smtp-Source: AGHT+IEAky4+JDj2TctdrcJCyOVFPoPiRfvC26YHi7IvJM1efJOuaoiQa50MH8ZQ4INEeypAIdf0KA== X-Received: by 2002:a05:6512:475:b0:515:bfaa:fa12 with SMTP id x21-20020a056512047500b00515bfaafa12mr11383475lfd.22.1712677000297; Tue, 09 Apr 2024 08:36:40 -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 v1 5/5] xen/arm: ffa: support notification Date: Tue, 9 Apr 2024 17:36:30 +0200 Message-Id: <20240409153630.2026584-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409153630.2026584-1-jens.wiklander@linaro.org> References: <20240409153630.2026584-1-jens.wiklander@linaro.org> MIME-Version: 1.0 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. Signed-off-by: Jens Wiklander --- xen/arch/arm/tee/Makefile | 1 + xen/arch/arm/tee/ffa.c | 58 ++++++ xen/arch/arm/tee/ffa_notif.c | 319 +++++++++++++++++++++++++++++++++ xen/arch/arm/tee/ffa_private.h | 71 ++++++++ 4 files changed, 449 insertions(+) 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) += ffa.o obj-$(CONFIG_FFA) += ffa_shm.o obj-$(CONFIG_FFA) += ffa_partinfo.o obj-$(CONFIG_FFA) += ffa_rxtx.o +obj-$(CONFIG_FFA) += ffa_notif.o obj-y += tee.o obj-$(CONFIG_OPTEE) += optee.o diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 5209612963e1..ce9757bfeed1 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: static void handle_features(struct cpu_user_regs *regs) { + struct domain *d = current->domain; + struct ffa_ctx *ctx = d->arch.tee; uint32_t a1 = get_user_reg(regs, 1); unsigned int n; @@ -240,6 +245,30 @@ static void handle_features(struct cpu_user_regs *regs) BUILD_BUG_ON(PAGE_SIZE != 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_NOTIF_PEND_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,30 @@ 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 = ffa_handle_notification_bind(get_user_reg(regs, 1), + get_user_reg(regs, 2), + get_user_reg(regs, 3), + get_user_reg(regs, 4)); + break; + case FFA_NOTIFICATION_UNBIND: + e = ffa_handle_notification_unbind(get_user_reg(regs, 1), + get_user_reg(regs, 3), + get_user_reg(regs, 4)); + 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 = ffa_handle_notification_set(get_user_reg(regs, 1), + get_user_reg(regs, 2), + get_user_reg(regs, 3), + get_user_reg(regs, 4)); + break; default: gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid); @@ -348,6 +401,9 @@ static int ffa_domain_init(struct domain *d) if ( !ffa_partinfo_domain_init(d) ) return -EIO; + if ( !ffa_notif_domain_init(d) ) + return -ENOMEM; + return 0; } @@ -423,6 +479,7 @@ static int ffa_domain_teardown(struct domain *d) return 0; ffa_rxtx_domain_destroy(d); + ffa_notif_domain_destroy(d); ffa_domain_teardown_continue(ctx, true /* first_time */); @@ -502,6 +559,7 @@ static bool ffa_probe(void) if ( !ffa_partinfo_init() ) goto err_rxtx_destroy; + ffa_notif_init(); INIT_LIST_HEAD(&ffa_teardown_head); init_timer(&ffa_teardown_timer, ffa_teardown_timer_callback, NULL, 0); diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c new file mode 100644 index 000000000000..0173ee515362 --- /dev/null +++ b/xen/arch/arm/tee/ffa_notif.c @@ -0,0 +1,319 @@ +/* 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(uint32_t src_dst, uint32_t flags, + uint32_t bitmap_lo, uint32_t bitmap_hi) +{ + struct domain *d = current->domain; + + if ( !notif_enabled ) + return FFA_RET_NOT_SUPPORTED; + + if ( (src_dst & 0xffff) != 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_hi, + bitmap_lo); +} + +int ffa_handle_notification_unbind(uint32_t src_dst, uint32_t bitmap_lo, + uint32_t bitmap_hi) +{ + struct domain *d = current->domain; + + if ( !notif_enabled ) + return FFA_RET_NOT_SUPPORTED; + + if ( (src_dst & 0xffff) != 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 = current->domain; + struct ffa_ctx *ctx = 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 = ctx->notif.secure_pending; + ctx->notif.secure_pending = 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_id(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 = current->domain; + uint32_t recv = get_user_reg(regs, 1); + uint32_t flags = get_user_reg(regs, 2); + uint32_t w2 = 0; + uint32_t w3 = 0; + uint32_t w4 = 0; + uint32_t w5 = 0; + uint32_t w6 = 0; + uint32_t w7 = 0; + + if ( !notif_enabled ) + { + ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); + return; + } + + if ( (recv & 0xffff) != 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 = { + .a0 = FFA_NOTIFICATION_GET, + .a1 = recv, + .a2 = 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 = ffa_get_ret_code(&resp); + if ( e ) + { + ffa_set_regs_error(regs, e); + return; + } + + if ( flags & FFA_NOTIF_FLAG_BITMAP_SP ) + { + w2 = resp.a2; + w3 = resp.a3; + } + + if ( flags & FFA_NOTIF_FLAG_BITMAP_SPM ) + w6 = resp.a6; + } + + ffa_set_regs(regs, FFA_SUCCESS_32, 0, w2, w3, w4, w5, w6, w7); +} + +int ffa_handle_notification_set(uint32_t src_dst, uint32_t flags, + uint32_t bitmap_lo, uint32_t bitmap_hi) +{ + struct domain *d = current->domain; + + if ( !notif_enabled ) + return FFA_RET_NOT_SUPPORTED; + + if ( (src_dst >> 16) != ffa_get_vm_id(d) ) + return FFA_RET_INVALID_PARAMETERS; + + /* + * 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_SET, src_dst, flags, bitmap_lo, + bitmap_hi); +} + +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 = 4; + else + ids_per_reg = 2; + + reg_idx = n / ids_per_reg + 3; + reg_shift = ( 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 = { + .a0 = 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 = ffa_get_ret_code(&resp); + if ( res ) + { + if ( res != FFA_RET_NO_DATA ) + printk(XENLOG_ERR "ffa: notification info get failed: error %d\n", + res); + return; + } + + ids_count = resp.a2 >> FFA_NOTIF_INFO_GET_ID_LIST_SHIFT; + list_count = ( resp.a2 >> FFA_NOTIF_INFO_GET_ID_COUNT_SHIFT ) & + FFA_NOTIF_INFO_GET_ID_COUNT_MASK; + + id_pos = 0; + for ( n = 0; n < list_count; n++ ) + { + unsigned int count = ((ids_count >> 2 * n) & 0x3) + 1; + struct domain *d; + + d = ffa_get_domain_by_vm_id(get_id_from_resp(&resp, id_pos)); + + if ( d ) + { + struct ffa_ctx *ctx = d->arch.tee; + + spin_lock(&ctx->notif.lock); + ctx->notif.secure_pending = 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, true); + + put_domain(d); + } + + id_pos += 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_count, + 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 = { + .a0 = FFA_FEATURES, + .a1 = 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 != FFA_SUCCESS_32 ) + return; + + irq = resp.a2; + if ( irq >= NR_GIC_SGI ) + irq_set_type(irq, IRQ_TYPE_EDGE_RISING); + ret = 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 = !ret; +} + +bool ffa_notif_domain_init(struct domain *d) +{ + struct ffa_ctx *ctx = d->arch.tee; + int32_t res; + + if ( !notif_enabled ) + return true; + + res = ffa_notification_bitmap_create(ffa_get_vm_id(d), d->max_vcpus); + if ( res ) + return false; + + ctx->notif.enabled = true; + + return true; +} + +void ffa_notif_domain_destroy(struct domain *d) +{ + struct ffa_ctx *ctx = d->arch.tee; + + if ( ctx->notif.enabled ) + { + ffa_notification_bitmap_destroy(ffa_get_vm_id(d)); + ctx->notif.enabled = false; + } +} diff --git a/xen/arch/arm/tee/ffa_private.h b/xen/arch/arm/tee/ffa_private.h index 98236cbf14a3..26c2af164d38 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 /* FFA_VERSION helpers */ #define FFA_VERSION_MAJOR_SHIFT 16U @@ -60,6 +61,8 @@ */ #define FFA_PAGE_SIZE SZ_4K +#define FFA_NOTIF_BITMAP_SIZE 64 + /* * The number of pages used for each of the RX and TX buffers shared with * the SPMC. @@ -97,6 +100,18 @@ */ #define FFA_MAX_SHM_COUNT 32 +/* + * 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 +190,21 @@ */ #define FFA_PARTITION_INFO_GET_COUNT_FLAG BIT(0, U) +/* 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 +243,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; +}; struct ffa_ctx { void *rx; @@ -228,6 +279,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 @@ -271,12 +323,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); +void ffa_notif_init(void); +bool ffa_notif_domain_init(struct domain *d); +void ffa_notif_domain_destroy(struct domain *d); + +int ffa_handle_notification_bind(uint32_t src_dst, uint32_t flags, + uint32_t bitmap_lo, uint32_t bitmap_hi); +int ffa_handle_notification_unbind(uint32_t src_dst, uint32_t bitmap_lo, + uint32_t bitmap_hi); +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(uint32_t src_dst, uint32_t flags, + uint32_t bitmap_lo, uint32_t bitmap_hi); + 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; } +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 v3, register_t v4, register_t v5, register_t v6,