From patchwork Wed Jun 9 10:23:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 456816 Delivered-To: patches@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp5115922jae; Wed, 9 Jun 2021 03:23:40 -0700 (PDT) X-Received: by 2002:a2e:5c82:: with SMTP id q124mr21948230ljb.332.1623234220428; Wed, 09 Jun 2021 03:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623234220; cv=none; d=google.com; s=arc-20160816; b=ubQzO0BZH6gE/TptIVhpFmGi9g9bf+FnBpzxHl3tenDEVmCttHNmTc13qCqO4hBfcp CCTr+V8Ti0zlde2yRDsI91l4OS0VpF4GltYya5bBF0OAK86jA7IbzTdOy4pTq49OBa/t nj4cbMyfIUlrFbnmF6SgRRHQrGGD6GPmnvRdbu+PStLcK6Hxnz/azMvKCvRpl4VIo2aQ 4fLUeci7P30KaGQBStSVqneLSAXLGSWDCY3GwybokFuTzZrd4pF5coU5ycrAzDqTPIYs AybphYcnfhw2QOqlu9DP+TrDcv9H9K0Feh2BvfIHt7vi5nYAndjXfQObNQ+gSWVLeUPq Md+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=7RcDq8BcfTAWvH1WjeQwKK7cYkn1EkqelTe3jQATvG4=; b=roKpYIu40HqwbYiNmplLV6OWNdcmIxX0mIL/9a+vO5JqPwnckBzBYjkBRaAmW5NA9G Y5UGhdtb7EoZS/xiYKgyJ2o8ATGd1m8zTh2nrqBMI5FeB5JCQtXjYugNwPm1CJchh7LU miaXUuHzZe7jr5C1tN/lxOwz5pP4czB+APDJAKzlJKc0PPOiZx4LOFISozPW9T1cX2kt YWNX7S3CEXxQdAlm5z024xfqoc/+aX+umJP1jFjw8QAfxFZ3HHIXQAwL8f/+CzrjHDBP mORguiZKYnBIIQqOftqvOT9NJo7EFd2tkKK8z0b2s5oC1MVSH6ki+jQGR/pMdsNFbH9F eg4g== 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 jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id q20sor338525ljg.20.2021.06.09.03.23.40 for (Google Transport Security); Wed, 09 Jun 2021 03:23:40 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ozpM35nW; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=J3i8YSnCHG2Pa2O9hMxdxsISFce8DykRpnEPzdgQ3O7UCFIppIZ5ZYf2620/Sbx/Ic TLapWuSdcMcSxZ7sp3RS7uj68xWU9zC9kzQCyA3GerksIFMezCz34A4+EnCtLcjrw8H7 a4kQ+kOisKSgCdSDr+L7oabsoOYPVlMn8vMbPE9j7YMVJbm3W//xKw1936Tr5z05K6bx PKJG+cL9GVhMXpADdcB4YiTZKyegS6mWiEtlFWFrxZLEj23gQWuFU2sEkQbS4xmy/9vL tsUOYWXwBCBcKJutiA6Q3xpH8u+ZPTGrIzFaSY2SDBkz4uXAlD5/3OfKVMTg0W8ciqxs V0Mw== X-Gm-Message-State: AOAM5301t5dNfM2iD8IKTiczV4Ncih3L536xYF/AXwHjDIbtCch/89qt 4ZdCnDn99up//yBKMWWjXzkYuY3+ X-Google-Smtp-Source: ABdhPJzF0zg4WbIXADx/FTVUlCvDWQq7mIP7AFvOez86MvdSJywFf7MGKKUVQv0m6jWAIfrQN8y1wA== X-Received: by 2002:a2e:9c08:: with SMTP id s8mr22318777lji.64.1623234220060; Wed, 09 Jun 2021 03:23:40 -0700 (PDT) Return-Path: 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 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(+) -- 2.31.1 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