Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1551221rdb; Wed, 24 Jan 2024 21:28:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCM636zXvXCj0Lj+YQhHvhrZf3JSrA/rtXZ7rz81Nj627pX9CGcziBso5W90zZrMG39aGS X-Received: by 2002:a05:6402:35cb:b0:55d:2b7:8ce9 with SMTP id z11-20020a05640235cb00b0055d02b78ce9mr94977edc.8.1706160494312; Wed, 24 Jan 2024 21:28:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706160494; cv=pass; d=google.com; s=arc-20160816; b=r0CK1i1d6NOPH0Om+bHU0CE/1bNUISEPDkKFTuQFoDq1FNLRowVeJH1dBp4TrUJOxf hluDfLH4D7dPaxz6HgoiwpJo33Lcn+BJACqpMg8aNrpxhh5c6BCohmO7vUIh1IxmXqGv UB+Le1UydJ0Fyzkxe0Sqn5zs/50n+5Kl+jeth2xDTGFw+dAel0Qn3kgAeylukawX0GKH PHbprliEbg8puaHbzZfWJGP3Lz4qw7pwQKMAlZ3oQcu/8GJY9WIKH7tt3TlpruF+tmK/ 13YUuzCl0qwjvuJQICZyUNaV+LVyWEJOPbZu6PTOveOInCfS5GuRWPJyTHpNN5lv/WIb UCsQ== 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=CI/NWBRSwikIHFcrWI6AUp0255MAfCWVxlivVpcLloM=; fh=eF5Kqrd0XRxiTbOEM6DLoETH2TWi0nwuuxvptPHHhTA=; b=NcrUOC88EakxJfsoiLprh6mS9t+MxU2yzLrkHoKKVk9QG4/IDHqC9+MdIwFa58oQuo z4uz7kkYnqAzQx9hXQYtGxlSKK3S4JPCyj9tlhILB+li6aQLWC4b3CqD2aMJqtouScwR xU55hOl0rZGK6n+zm0Y+xuD23tv/5uLzsrQoMuOgII5EoGh3ZJJwmK5QqkrbdpB/7sdV gCAtzqh4x36+s6+9gmtPVN27bG4kHK5pY3x1e4PgUekrDDf3nzlN1zpVCU1SKNvzxQz5 /cN3gAKXt5ydt9eSLJ1W6U1+XLlCHJykGYluRr00ZXaquIL/DLRd3HmRewGwR2lmgyZy DKvg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=h0D3WLPb; 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-37977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z34-20020a509e25000000b0055bfdd68cfesi5200401ede.604.2024.01.24.21.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 21:28:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=h0D3WLPb; 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-37977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37977-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DB33B1F2447B for ; Thu, 25 Jan 2024 05:28:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A37ADD2E8; Thu, 25 Jan 2024 05:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="h0D3WLPb" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 B832779C3 for ; Thu, 25 Jan 2024 05:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706160484; cv=none; b=J6qBIXfyLGh4xeGxebUw2wW3NQ9kvgYvqjRgZD1MirlR8O3erzv3pUW5jV6rGmRZxfBkmzOqXEYKBbh8LcIY1ge0mzKyooD36uLzAjL+nWXDXwY1ZPe2qgY0o1gpxy+BdoaFdUNgTeQ5yuEJkG+48zwEPx/FFUjIh2zbHdCRWNw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706160484; c=relaxed/simple; bh=X48wOc0KCkgUpX81+UrrYap7VWgVfnyOqeOP9apPXFM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Ta1j2iJoOSbHcgSrRwHNcELKf7jZ5SKp9QQT6WgLcxLtFj1wXw33rinheRFWpbGIPk5fS+Q0N2/Jsu8R4w7g4r4QBvBqHIKUdvhnZllV9WIGwV1DRBeTBpa1gnWx6xPtU0ghIKuBBxRCoz1yEWUUE3ZYXqaTvfJj/ZCAzeKDvQo= 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=h0D3WLPb; arc=none smtp.client-ip=210.61.82.184 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: 7d9c2848bb4211eea2298b7352fd921d-20240125 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=CI/NWBRSwikIHFcrWI6AUp0255MAfCWVxlivVpcLloM=; b=h0D3WLPbNPxeXzoCWk0+CRNrt5vaMmPR0UcJ8/C8s30bCRVoNxH8eriSE62llmfWOizYRJeydmbluHzvEmk+WyXMi2srdwE2n4VQqPj6pJRPQ1I+cBCnWadcZ+jH9Nfj1kOi+n4gxskS7qqjXpkIl+fTTl6pPH+l+Tm1/EqLzGk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.36,REQID:8c31b1a6-83ce-4017-a375-a59dc409e092,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:6e16cf4,CLOUDID:4a153c83-8d4f-477b-89d2-1e3bdbef96d1,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: 7d9c2848bb4211eea2298b7352fd921d-20240125 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 465339585; Thu, 25 Jan 2024 13:27:54 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 25 Jan 2024 13:27:52 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 25 Jan 2024 13:27:52 +0800 From: gavin.liu To: Jens Wiklander , Sumit Garg , Matthias Brugger CC: AngeloGioacchino Del Regno , , , , , , Subject: [PATCH] optee: support wq_sleep_timeout Date: Thu, 25 Jan 2024 13:27:44 +0800 Message-ID: <20240125052744.18866-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-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--7.493700-8.000000 X-TMASE-MatchedRID: qg9A2eKC0s6GeTbGWdRz1kKcYi5Qw/RVqQ9UezeTkTj7efdnqtsaE3B4 4IkzjfYyThbvLLI8RvPmRq+NdpkLXHW0oJLOugKB8rLt6/XzAZZA8JZETQujwhS11FlOYRohQyY np0aZIjLD9dt+AOidH43/d0NuPcI1j2hRzH1UwuAURSScn+QSXt0H8LFZNFG73Yq8RVaZivVGBu cRG9mMVEGysrMIjvt71lbKRwZ0frWo+cmBJ4qixNAUj8eogZsv X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--7.493700-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 90681AE6CC77A603801ECED92FA187A83A4070873E71D2606BD318CCA0010D692000:8 X-MTK: N From: Gavin Liu Add wq_sleep_timeout to support self waking when timeout for secure driver usage. Signed-off-by: Gavin Liu --- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 2 +- drivers/tee/optee/rpc.c | 10 ++++++++-- 3 files changed, 16 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/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