Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4636792pxb; Tue, 25 Jan 2022 15:08:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyG0/Wf4YNdaWqAtEIXE8o3Y6ammPMFeGLyoSQo/Qxtm9yblij68mW5sGnmvBEQYKeLEEIK X-Received: by 2002:a05:6402:235a:: with SMTP id r26mr13463931eda.406.1643152108922; Tue, 25 Jan 2022 15:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643152108; cv=none; d=google.com; s=arc-20160816; b=gDg/w4AwRBlV/Ai3np6mUYzoLazDLPOILlulE9QkGjo+BwS233JcZ4/5F6dHXZV61a cwZE5wSj6lZbk+uTfBxUeuJzzk3JYbH0DnfodWII3nd5HGu8JcLMUog+R24TyBFW0Kk2 5YRE7380onkk8zguu1wqsF9wrM0dj8srSbLLaGe4pkAr0Paa7R8Ji4ctKip2Ptgg/aUb LuwDJzD/yagtnqITzfl6YqbpuQVnCUzBvnSuhXy7xVjrBWpuq0iamZ7bhBcWNWsa0Zxz QtxKYhIwSIsSNf88l7nNq0X8FfnT/LPiQECEzDyioc1d7ucwp677CSmggi5FqasiYj+a kRrQ== 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=ZLkFwdHW7tpL1lpDBNXdPL4T4si80CJ3ca8C0Rhph3U=; b=fSQomrijRKAUztf4a+ZWFJeYPmgWQOMOHX9ENp0uPFgHySJ06ltk3siZ36boUpJ1Kr jWRzhA2eXYlpEFnh0fj7VcdfzCeXDHKSARcpTR4N2iYDFKdSyzyIZSvxeGiYAwRzyB75 SVBAA0wgUvfJarOGYdsNpdWF4u08ZIyeYC+oTaGphJ6+h6OIqN2uLmib5j8/PJEMS6hT 1ubCzk6Y2TpQl1wMThJkozeCk3h6iXBLSK518yE/GY3bm+EbFZk4sXLfe02TaMvN2VQ0 pWyuxhIiXDZg6LkbOsKlHhaAeVSiGVlBsdn2LPFNfr68uLDobYyGBJse4MGKx2X+K6Mh 1hzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oRgAlIHm; 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 d8si10997447ejo.244.2022.01.25.15.08.04; Tue, 25 Jan 2022 15:08:28 -0800 (PST) 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=oRgAlIHm; 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 S1583756AbiAYQdp (ORCPT + 99 others); Tue, 25 Jan 2022 11:33:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380219AbiAYQ3u (ORCPT ); Tue, 25 Jan 2022 11:29:50 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A4AFC06173B for ; Tue, 25 Jan 2022 08:29:50 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id bu18so57823376lfb.5 for ; Tue, 25 Jan 2022 08:29:50 -0800 (PST) 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=ZLkFwdHW7tpL1lpDBNXdPL4T4si80CJ3ca8C0Rhph3U=; b=oRgAlIHm6wWyN2asjrWvedJdamiN7DJRaW2stasAGmr7toukW9AkjcwSqned/kk5/z c5YF6RrmHglNSxAP7jvWkfUV3iEeNpE3FiJ8my2VCmPcpVsW3yJ3IiAnYONRmUZM6qRp Lanc8yOL1WZdpqQU1OnpnsLwdsBr19IS7cIxpcTPlEO/8Mp7XJIRwHXif9cR4hHVDQdO aHin8GuDKIeDbQqZBVwmnE5lNEhSkhyEwgmVMJhKf+2vNX5YPRhqrDiYvRcXWaLftLYp VJgPOr2rROiaLLtyxGByft74FWkxGhl6ZvIq82vqeb6ZWpI5op8/+WuIaQljBymKS2zv 0+kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZLkFwdHW7tpL1lpDBNXdPL4T4si80CJ3ca8C0Rhph3U=; b=69THxqUB+B18N7I7b2idl00//SiuZj9ZLlidil7YaeGecUAX0Bzt+nCyejQv9Jxi7g ew1A+51sluNCDZRAhTdXJG7f27l47k3Ha7o5J/Mcn/DmHaz2plVzKz5YZbw/GeEuWNH/ 7lfrUP8U9QfF9tjjix2b2SuK5IZqM9OagA03vFfKhEVccDGdmjZKsGGLkwDD0eAiHE0b 0KWptPwIZldQFAHdrlYlFIAE03Mo2cagvfE4yyWSkihcz1KNS00eCyNu7uePhiBgUNiM DySKzV/8PqMqFu9WRnq6mm2G+SVIboqIcGqE+gTOFhWiSuPgamwt7wBEugsKrjFVgQg2 /1bw== X-Gm-Message-State: AOAM532WZ/oQfVnjwhbaX6lcSnzl2l2CjEuGByP+KGOzOjwrw/udewAA U7MHjG+H3iYSW12D7u1nhuedpv5vxTwISQ== X-Received: by 2002:a05:6512:1086:: with SMTP id j6mr17394682lfg.375.1643128188139; Tue, 25 Jan 2022 08:29:48 -0800 (PST) Received: from jade.urgonet (h-94-254-48-165.A175.priv.bahnhof.se. [94.254.48.165]) by smtp.gmail.com with ESMTPSA id d13sm536240lfq.75.2022.01.25.08.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 08:29:47 -0800 (PST) From: Jens Wiklander To: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org Cc: Sumit Garg , Herbert Xu , Devaraj Rangasamy , Rijo Thomas , David Howells , Tyler Hicks , Jens Wiklander Subject: [PATCH v3 03/12] tee: add tee_shm_alloc_user_buf() Date: Tue, 25 Jan 2022 17:29:29 +0100 Message-Id: <20220125162938.838382-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220125162938.838382-1-jens.wiklander@linaro.org> References: <20220125162938.838382-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_user_buf() or user mode allocations, replacing passing the flags TEE_SHM_MAPPED | TEE_SHM_DMA_BUF to tee_shm_alloc(). Signed-off-by: Jens Wiklander --- drivers/tee/tee_core.c | 2 +- drivers/tee/tee_private.h | 2 ++ drivers/tee/tee_shm.c | 17 +++++++++++++++++ drivers/tee/tee_shm_pool.c | 2 +- include/linux/tee_drv.h | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 3fc426dad2df..a15812baaeb1 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -297,7 +297,7 @@ static int tee_ioctl_shm_alloc(struct tee_context *ctx, if (data.flags) return -EINVAL; - shm = tee_shm_alloc(ctx, data.size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); + shm = tee_shm_alloc_user_buf(ctx, data.size); if (IS_ERR(shm)) return PTR_ERR(shm); diff --git a/drivers/tee/tee_private.h b/drivers/tee/tee_private.h index e55204df31ce..e09c8aa5d967 100644 --- a/drivers/tee/tee_private.h +++ b/drivers/tee/tee_private.h @@ -68,4 +68,6 @@ void tee_device_put(struct tee_device *teedev); void teedev_ctx_get(struct tee_context *ctx); void teedev_ctx_put(struct tee_context *ctx); +struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size); + #endif /*TEE_PRIVATE_H*/ diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 499fccba3d74..7e7e762fc1de 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -127,6 +127,23 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags) } EXPORT_SYMBOL_GPL(tee_shm_alloc); +/** + * tee_shm_alloc_user_buf() - Allocate shared memory for user space + * @ctx: Context that allocates the shared memory + * @size: Requested size of shared memory + * + * Memory allocated as user space shared memory is automatically freed when + * the TEE file pointer is closed. The primary usage of this function is + * when the TEE driver doesn't support registering ordinary user space + * memory. + * + * @returns a pointer to 'struct tee_shm' + */ +struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size) +{ + return tee_shm_alloc(ctx, size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); +} + /** * tee_shm_alloc_kernel_buf() - Allocate shared memory for kernel buffer * @ctx: Context that allocates the shared memory diff --git a/drivers/tee/tee_shm_pool.c b/drivers/tee/tee_shm_pool.c index a9f9d50fd181..0e460347138a 100644 --- a/drivers/tee/tee_shm_pool.c +++ b/drivers/tee/tee_shm_pool.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2015, Linaro Limited + * Copyright (c) 2015, 2017, 2022 Linaro Limited */ #include #include diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index 6b0f0d01ebdf..975500b2553e 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2015-2016, Linaro Limited + * Copyright (c) 2015-2022 Linaro Limited */ #ifndef __TEE_DRV_H -- 2.31.1