Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp252235lqh; Mon, 6 May 2024 19:16:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfjE+Op0qhGm1TnANrjxIrYCVgdbJo+u6KuoeZ+3VRszQiawaixxF8yZsiXkinKNwcbruiOmBEnHMIYuFNkOqtB6ntWkfvgYDxioVEHw== X-Google-Smtp-Source: AGHT+IGKPOwdBSbQz8Cy55d0REt1JSx8633C6S4QGw3/WhSHRIbyQ7Zx6Nh+5UlPIy64XCpzgrtB X-Received: by 2002:a05:6214:d88:b0:6a0:cd66:ffb0 with SMTP id e8-20020a0562140d8800b006a0cd66ffb0mr13659532qve.38.1715048176028; Mon, 06 May 2024 19:16:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715048176; cv=pass; d=google.com; s=arc-20160816; b=rDXCD5RvXc8CvC/gwEihmSgiwcTEMz6hNC5xNpRX6oT+LMN24f8kHQ20lwG0jyW6hq Q8f7AZc1C1MC9mPNSaqylLSDef+O1okIQ0Vspbsck1yM6LG1tclmyY2y1hc3xwgDUOHs L7fTuWUARxyav8/PfetDy91A2DC9V5mS26BwRwR+tcZWkwdo+mY5zC2Yvy2jd48+EPXK 5w18x40nTmnqqbD+TvjjlcQVoBJELGUwdlqse7kf7CDTCpWEPFkdGMpNZ3OXX1+iYa0m xNqneotCLaI14QxgoMA8yiuLmo6cuCriLhzIc8j8ehkuoquOU3R42wVptbdoJHz84gRr CrvA== 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=OkbheN73NOmkxbTzCeJVpVCAkNTb+uG4tFp2uucwYAQ=; fh=7sj7zX0xQGmE6p+1qp3ByfRvs1xQ6ZbFgogcVms3r4I=; b=Dci1o3EWv0Xn2xj7K7thleXeJT+WW0XC7XgQzev4x6jFRcH3cVB71pfXp1nc3Yy7pL sCXNW/goW32LC0lcWx7ejNN8pjygFla350b2f8CINXU1qfGRfeFUPOkfmMfo99Psr7um H/+maJBmq2F/CUXw2IC49yjz5WpytY5Y1SOrujf8b8g2s+w32PGIHmnhLgFd9kMWlbHM iLYL+G0orhrVxZ0gOHP6qa2+YQN888+wWpc0cNsIK6sfwpVewtNeeb4EmevpdnwePDkP oSCYV/9BIXUyhfCiC3iSqLZ6DNzfn/Ap6g9yRM3BOHv7+vzEILzpKwGo6jwz+D3AODvP KQ5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=TLpadRJk; 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-170578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170578-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 7-20020a0562140dc700b006a04d4c2eebsi10771585qvt.569.2024.05.06.19.16.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:16:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=TLpadRJk; 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-170578-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170578-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 9F9DD1C21874 for ; Tue, 7 May 2024 02:16:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 708104C8A; Tue, 7 May 2024 02:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="TLpadRJk" 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 161EB3FE4 for ; Tue, 7 May 2024 02:16:06 +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=1715048169; cv=none; b=UymuzATiNBlu+iAQxxnKxsVfCzgCPwEOC37mlAUGCMgHYx+TJF1NqRey39iZeo4G3crwW+MMZE4ePCOkdC8fq4JtiM8nbbfreyoo7hJtF+ju8zFopQscAARkqTpoLUHPkqxEWYgGR0OPIkxFNFZLi5LuKCYhYJBEoqdzhcmdEUY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715048169; c=relaxed/simple; bh=Tlg2msnuHEnP6RLCR6+Oxh1TTRZaMFlw6rLi2MhjLGw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fKv88eXN91VNwuoudMOUXiM3SfIantblg4yEi+x1+3eLbDF3aA4Lkh3RtU0JnVXwt+21WSzv/AVtnEkgQDO798eCRnGREDX6SDiO9wIBYUjmWpVaO9K9SvLxcbV+jtYGJH7NyQng/xeAYUVh12w8ui386DBNl00fQy/LYElmZ1U= 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=TLpadRJk; 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: 9dbad1140c1511efb92737409a0e9459-20240507 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=OkbheN73NOmkxbTzCeJVpVCAkNTb+uG4tFp2uucwYAQ=; b=TLpadRJk75RzdzbqokqlXSgJs19HzlTh/1pv4twmQlLAsF3P0XkjXrjM0lYUWU6y1wLZUV0Y9xufIPBPocSiqdm1qvfK/ggwCmNQoMYMNempU1uIlMgXrx7GsJHRiuAY+YHx3hRCHDxO8y4aJD3MX0SHbww+l2kVG4sAsdMZROk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:8f27c4fa-1286-4ede-8ff3-c894e0523740,IP:0,U RL:0,TC:0,Content:0,EDM:-32768,RT:0,SF:-32768,FILE:0,BULK:-32768,RULE:Rele ase_Ham,ACTION:release,TS:0 X-CID-META: VersionHash:82c5f88,CLOUDID:f20f6e92-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:nil,TC:nil,Content:0,EDM:nil,IP:nil, URL: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: 9dbad1140c1511efb92737409a0e9459-20240507 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1715883791; Tue, 07 May 2024 10:00:45 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 7 May 2024 10:00:43 +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; Tue, 7 May 2024 10:00:43 +0800 From: gavin.liu To: Jens Wiklander , Sumit Garg , Matthias Brugger CC: , , , , Gavin Liu Subject: [PATCH v3] optee: add timeout value to optee_notif_wait() to support timeout Date: Tue, 7 May 2024 10:00:37 +0800 Message-ID: <20240507020037.14009-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 v3: 1. change the comment in optee_rpc_cmd.h 2. add macro for "TEE_ERROR_TIMEOUT" 3. change from "TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT" --- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 5 ++++- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/tee/optee/notif.c b/drivers/tee/optee/notif.c index 0d7878e770cd..1970880c796f 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 429cc20be5cc..424898cdc4e9 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -26,6 +26,9 @@ #define TEEC_ERROR_BUSY 0xFFFF000D #define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010 +/* API Return Codes are from the GP TEE Internal Core API Specification */ +#define TEE_ERROR_TIMEOUT 0xFFFF3001 + #define TEEC_ORIGIN_COMMS 0x00000002 /* @@ -252,7 +255,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..4576751b490c 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 milliseconds 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 f086812f1179..5de4504665be 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 = TEE_ERROR_TIMEOUT; + else + arg->ret = TEEC_ERROR_BAD_PARAMETERS; } static void handle_rpc_func_cmd_wait(struct optee_msg_arg *arg) -- 2.18.0