Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp995154lqm; Thu, 2 May 2024 01:57:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWq12y0Pzd3qrd9rKzKfOiITSx3E0NgqkNeNMzqujrar/78MqGn/6VF5f8GJkp8qVu1Q2kF20kxCcQ1f7WyqCOHkO0GeM7xEwJ3i9cLdg== X-Google-Smtp-Source: AGHT+IGA4qImg+smEvt7SvncwvfZY6EH6gph14W81h3Kc9BPdAa28sFKgEyIiV/uZUG12Da9fBvX X-Received: by 2002:a05:622a:409:b0:43a:cbe7:3640 with SMTP id n9-20020a05622a040900b0043acbe73640mr6105714qtx.17.1714640234560; Thu, 02 May 2024 01:57:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714640234; cv=pass; d=google.com; s=arc-20160816; b=LAgXqE+d8F7XnNgLE8xC7Hq3t42qh81MvuQNRERt96scT5m1Grl3g1cuoMTszNUcln bqDd3jhOusD2bpCdOFET8vMy6Rz/3oW/UZDaL60SbEZw26CZ8qlbEcAhEtTqXc5Fo1iE DWjCJGNBck08R1gZD+Ai9a1fSTma8SQcuSSsokI1qSpjUIC34tEm5AumPmhWD5J6navA Q6JftRatSOuBmAuF5EDtujU21l7QDi5+v1dvUFAbG9XUxPKS3KFHTpSHCOa6IorlDfRq wfl4Fjup5xpLJesufd/FEg/L8kQT+yleVHaymCXllv6huOI/il3YLdXVx+LBsIfChsFQ h0Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=Wa9ZFYyQyLg9Zk5bCCWMW/hFYEEEDVpBvBp/sui5nAM=; fh=7sj7zX0xQGmE6p+1qp3ByfRvs1xQ6ZbFgogcVms3r4I=; b=MFWke1K+hL6f9KBXxa3jX2OYdg9YHMHDwOBH9Djwiqrq0eoCgPhvOLdO+KvWZW2iqA FrsXpWOMU7JkLLDAEL2Yhg821cDHX92SdcyLEPW2uH06oIHA20dDNpJNVWO0BO8H+VLk jO7gpfSRBJhK7dW93uEL460fOOwmayVy+7otxClbtgvAbADZQkoBF0WroQ1pgDrr5vcX C1ncSWgdrIkiYqs2TE4sloW5rD6qW4dTsv90IsSre7GPpzdlEHNJL/iIcx8a0lfixeUU a1K4+r5aDQxB9FHx16TSyjdQGybwvZBEfRT8616uG263bF9pMhRy9TqvF+lKQKYGs1Mr D7gQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=u+FsOxmF; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-166162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166162-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m7-20020a05622a054700b00439d0c8ecb9si529514qtx.429.2024.05.02.01.57.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 01:57:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=u+FsOxmF; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-166162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166162-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0AB881C20F84 for ; Thu, 2 May 2024 08:56:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C16BC50A88; Thu, 2 May 2024 08:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="u+FsOxmF" Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F3A147A7A for ; Thu, 2 May 2024 08:56:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714640213; cv=none; b=Kk6Ca+yBEr/RefzUnwhOD0BnNQ9MqjmBgQOs5Mt0o3tyJbPoPnDLoIgfQdeLMHFvHx3AHxV3ovKlcqfooZdBmj86XbZ08D9VkYXPD/fZUzwauFTxEmIQBZjoctrdJ26+zwCgnQiS4yTwEqtUqbQAgfLcoSUoj157bqrDVF5UhYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714640213; c=relaxed/simple; bh=KYv593Y9tvOEPRgIJcKYCbyN/TKFJCLBDoXJppF5+3c=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=YFAE4Z3LYm2FMbVVkIdRs56/k5kjp+K3KFo3Cyv+b2W8otWc/1ZY+zzMLtEv5Kyj3mHIHctTjJj/Zu5Rpak4spz1aZhWCSpfsi6DfRqBatJIPk0/Uab+G1npdbZVj8pCID5n7Csgx8EJ7uI1ocQ3MaVzIM+YMnfofDrMOx+e//w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=u+FsOxmF; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: e3675d7a086111efb92737409a0e9459-20240502 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=Wa9ZFYyQyLg9Zk5bCCWMW/hFYEEEDVpBvBp/sui5nAM=; b=u+FsOxmFXXBL1NszHOPoyAYR0eCxncqHkwH+xgA9cN1rSHJtSoMtrrBAcQiAy5R6El3OcWZrgbM/doPMcV+Hrfi8aB/Z72D33iX/BrwXQpT22zq+I1B9+YLuh2tymn4cEb5hxjXDHx7t7y2ljCyGchrJE/Bd1MDrQAQ7lhktvgU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:472237c0-32d4-4cc4-a17c-777b9dbf11c3,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:82c5f88,CLOUDID:09255d83-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: e3675d7a086111efb92737409a0e9459-20240502 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1666401368; Thu, 02 May 2024 16:56:39 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by MTKMBS09N1.mediatek.inc (172.21.101.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 2 May 2024 16:56:37 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 2 May 2024 16:56:37 +0800 From: gavin.liu To: Jens Wiklander , Sumit Garg , Matthias Brugger CC: , , , , Gavin Liu Subject: [PATCH v2] optee: add timeout value to optee_notif_wait() to support timeout Date: Thu, 2 May 2024 16:56:36 +0800 Message-ID: <20240502085636.4049-1-gavin.liu@mediatek.com> X-Mailer: git-send-email 2.18.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N From: Gavin Liu Add timeout value to support self waking when timeout to avoid waiting indefinitely. Signed-off-by: Gavin Liu --- Change in v2: Change commit message. Add description for value[0].c in optee_rpc_cmd.h. --- --- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 2 +- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/tee/optee/notif.c b/drivers/tee/optee/notif.c index 05212842b0a5..d5e5c0645609 100644 --- a/drivers/tee/optee/notif.c +++ b/drivers/tee/optee/notif.c @@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_int key) return false; } -int optee_notif_wait(struct optee *optee, u_int key) +int optee_notif_wait(struct optee *optee, u_int key, u32 timeout) { unsigned long flags; struct notif_entry *entry; @@ -70,7 +70,12 @@ int optee_notif_wait(struct optee *optee, u_int key) * Unlock temporarily and wait for completion. */ spin_unlock_irqrestore(&optee->notif.lock, flags); - wait_for_completion(&entry->c); + if (timeout != 0) { + if (!wait_for_completion_timeout(&entry->c, timeout)) + rc = -ETIMEDOUT; + } else { + wait_for_completion(&entry->c); + } spin_lock_irqsave(&optee->notif.lock, flags); list_del(&entry->link); diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index 7a5243c78b55..da990c4016ec 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -252,7 +252,7 @@ struct optee_call_ctx { int optee_notif_init(struct optee *optee, u_int max_key); void optee_notif_uninit(struct optee *optee); -int optee_notif_wait(struct optee *optee, u_int key); +int optee_notif_wait(struct optee *optee, u_int key, u32 timeout); int optee_notif_send(struct optee *optee, u_int key); u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, diff --git a/drivers/tee/optee/optee_rpc_cmd.h b/drivers/tee/optee/optee_rpc_cmd.h index f3f06e0994a7..99342aa66263 100644 --- a/drivers/tee/optee/optee_rpc_cmd.h +++ b/drivers/tee/optee/optee_rpc_cmd.h @@ -41,6 +41,7 @@ * Waiting on notification * [in] value[0].a OPTEE_RPC_NOTIFICATION_WAIT * [in] value[0].b notification value + * [in] value[0].c timeout in millisecond or 0 if no timeout * * Sending a synchronous notification * [in] value[0].a OPTEE_RPC_NOTIFICATION_SEND diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c index e69bc6380683..14e6246aaf05 100644 --- a/drivers/tee/optee/rpc.c +++ b/drivers/tee/optee/rpc.c @@ -130,6 +130,8 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, static void handle_rpc_func_cmd_wq(struct optee *optee, struct optee_msg_arg *arg) { + int rc = 0; + if (arg->num_params != 1) goto bad; @@ -139,7 +141,8 @@ static void handle_rpc_func_cmd_wq(struct optee *optee, switch (arg->params[0].u.value.a) { case OPTEE_RPC_NOTIFICATION_WAIT: - if (optee_notif_wait(optee, arg->params[0].u.value.b)) + rc = optee_notif_wait(optee, arg->params[0].u.value.b, arg->params[0].u.value.c); + if (rc) goto bad; break; case OPTEE_RPC_NOTIFICATION_SEND: @@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(struct optee *optee, arg->ret = TEEC_SUCCESS; return; bad: - arg->ret = TEEC_ERROR_BAD_PARAMETERS; + if (rc == -ETIMEDOUT) + arg->ret = TEEC_ERROR_BUSY; + else + arg->ret = TEEC_ERROR_BAD_PARAMETERS; } static void handle_rpc_func_cmd_wait(struct optee_msg_arg *arg) -- 2.18.0