Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5152361pxj; Wed, 9 Jun 2021 10:17:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx53r2HUwAZzivnAWI0CniE8xGjZan/365xsz5+OwfZA/OGrInhYcVai82+fWgln0wzOX/W X-Received: by 2002:a17:906:6899:: with SMTP id n25mr897347ejr.462.1623259062012; Wed, 09 Jun 2021 10:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623259062; cv=none; d=google.com; s=arc-20160816; b=LFbI0ek70ZkR0tiJJ3s0eioDWoHg8te28uWKjmlP/HAPtsXZrL1C+eu5iGn+eeFuas KyypX7dNWoKlWCr0O7Wk1o+8diXdbd2yfE3cUZj89ZVC8ccl+zeY9mDjRHjjYXv+TnTl wY7O2jT+ndAxa5xxMm1HSiFPUE8JqCy8JfCcDcBAxX1f7QBRQRO5UDg5ex0+994vXxNr LkvdQXIAbjnjXo3CeGt0BuSqykKDSGIUeVTWh1klRDVtUJC8JOYyy99p2B0WerWkNnRF 8f8d6Y24kXYzuY/GI6X6c03s7KruUG9yul+m2q9meYVo8mgcJkd4W35yGPcuB/T5hmnj AeFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7RcDq8BcfTAWvH1WjeQwKK7cYkn1EkqelTe3jQATvG4=; b=bG4uhvjbr68Ie1IxNYCrji53CcXhrSU3zAcy1f98Qt2WbMsmv9+gnuE78kUIf4s5QD WuEy3Vk32F6+PH5zQfcj1o988/sRdK5gNLd4fHCgKu1ss86UapBrF344XEwwGgY3w45N Nz1/vz3JQTxF2KRqzBHTxofuiPi7fSDv/VMazi9vmh7yIaM8blsImGv14rxeS6Q0Qktl WtPjqBwl2b3E0E8A/i8hrJ+e36RloWYGLHWe2lggWCgatPw8XpIJtCc6ZyW6ztBXvT4I FEGRpWloIQW5H5YWCeqEwrGIP0hSW5Fs4zeLFzHI7UsZ4S8bhvCFkGB4GR1DO/KzcVei 9mkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ozpM35nW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id os28si255810ejb.695.2021.06.09.10.17.17; Wed, 09 Jun 2021 10:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ozpM35nW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238811AbhFIK06 (ORCPT + 99 others); Wed, 9 Jun 2021 06:26:58 -0400 Received: from mail-lj1-f170.google.com ([209.85.208.170]:38489 "EHLO mail-lj1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238805AbhFIK0w (ORCPT ); Wed, 9 Jun 2021 06:26:52 -0400 Received: by mail-lj1-f170.google.com with SMTP id s22so10545872ljg.5 for ; Wed, 09 Jun 2021 03:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7RcDq8BcfTAWvH1WjeQwKK7cYkn1EkqelTe3jQATvG4=; b=ozpM35nWXWBjw5iUr59+oW0hcacsvLGFrjStft3HGELn8/8ScTMkxs4XPjEmtlo/BN ZUyvZD+GH0yxF8V9U8dQnKU8fPdl+wun5GkDI0U2GJt0Xv92w9xAo9PWaAi0VHA8PXW+ I6A6fYa98bjoZ563pMDdIzgn/Ta76RMVZQ7T4kINmT1u2SAYW/SkhEF09H1UI6SF+QTY w0P85B/IPraoS/NZEmjn8As+YnIg7xiqoOyRilivQ3E7U9qsItvotMr6vqzUXe2p72Dx ZuZLGwsyOTZMi+GOI0cDJeYJHZLoTWlt7/ldmiprb7nEoIfghaB/w77zPbo9PDbEpG69 aRwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7RcDq8BcfTAWvH1WjeQwKK7cYkn1EkqelTe3jQATvG4=; b=kQZY/OG215YPWFcrrEbG7w1DVYeTh6SbPa7KfOQvdulf5o2Hhu9c2seViOV0OaLfYQ yVwDD6o2Z9XUGPOKtjLWB1v6ycGtNH/fBy+jZhY91898Q4waqigq4ZhfKUU5/2BbPSNq erYiHpFXd6G3N0rIQoWYcc/fUZSx4MwQp7/w4XoQuRX3IenhvIqNYi+PNdSVhmCdCgRz zLRM8TSZ+E3NZLmzQ21eeUiLox/4IAl4dCIy2bEo0EZK740cHUerjLBoKhNQm7XxSh2q jeN3kzJ8TSRkbtnI28kcJ99o5lZW459XWhDI5YIVn6jjdEoDe+iaIA+CYW0cpj4W+/Eb OJQg== X-Gm-Message-State: AOAM533+CGCaplIABaE+1lVDSdwczuxXlLe8WBHekQf234b+ruL16LvO ol0gY0blzaY+K5EaC8vPs/dJl9QLArZ/YZlq X-Received: by 2002:a2e:9c08:: with SMTP id s8mr22318777lji.64.1623234220060; Wed, 09 Jun 2021 03:23:40 -0700 (PDT) Received: from jade.urgonet (h-79-136-85-3.A175.priv.bahnhof.se. [79.136.85.3]) by smtp.gmail.com with ESMTPSA id m4sm302966ljp.9.2021.06.09.03.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:23:39 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, op-tee@lists.trustedfirmware.org Cc: Sumit Garg , Herbert Xu , Sakkinen , Sasha Levin , Thirupathaiah Annapureddy , Vikas Gupta , "David S . Miller" , Tyler Hicks , Jens Wiklander Subject: [PATCH 3/7] tee: add tee_shm_alloc_kernel_buf() Date: Wed, 9 Jun 2021 12:23:20 +0200 Message-Id: <20210609102324.2222332-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210609102324.2222332-1-jens.wiklander@linaro.org> References: <20210609102324.2222332-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adds a new function tee_shm_alloc_kernel_buf() to allocate shared memory from a kernel driver. This function can later be made more lightweight by unnecessary dma-buf export. Signed-off-by: Jens Wiklander --- drivers/tee/tee_shm.c | 18 ++++++++++++++++++ include/linux/tee_drv.h | 1 + 2 files changed, 19 insertions(+) diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index b9dbf4bce149..63fce8d39d8b 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -192,6 +192,24 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags) } EXPORT_SYMBOL_GPL(tee_shm_alloc); +/** + * tee_shm_alloc_kernel_buf() - Allocate shared memory for kernel buffer + * @ctx: Context that allocates the shared memory + * @size: Requested size of shared memory + * + * The returned memory registered in secure world and is suitable to be + * passed as a memory buffer in parameter argument to + * tee_client_invoke_func(). The memory allocated is later freed with a + * call to tee_shm_free(). + * + * @returns a pointer to 'struct tee_shm' + */ +struct tee_shm *tee_shm_alloc_kernel_buf(struct tee_context *ctx, size_t size) +{ + return tee_shm_alloc(ctx, size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); +} +EXPORT_SYMBOL_GPL(tee_shm_alloc_kernel_buf); + struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, size_t length, u32 flags) { diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index 62b7c7a55743..58b319766f8e 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -282,6 +282,7 @@ void *tee_get_drvdata(struct tee_device *teedev); * @returns a pointer to 'struct tee_shm' */ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags); +struct tee_shm *tee_shm_alloc_kernel_buf(struct tee_context *ctx, size_t size); /** * tee_shm_register() - Register shared memory buffer -- 2.31.1