From patchwork Thu May 27 08:14:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 448840 Delivered-To: patches@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp285439jac; Thu, 27 May 2021 01:14:21 -0700 (PDT) X-Received: by 2002:a2e:9bc1:: with SMTP id w1mr1616266ljj.290.1622103261596; Thu, 27 May 2021 01:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622103261; cv=none; d=google.com; s=arc-20160816; b=CNU2yfrIj/5vgPjRefPDryLepkOpuc3wu1FkayRmdM7+7W32CskvckhpIE66OmZ5yV vi5x/efPOGpVEh9Sbm6ydMyrFndLO4d1ojKsyikKBPyzTbZemrBBNMPvTa4ZSD/m30eS VjWpMdCQiCRMgY1ubn0Q9LQ3L5sS8ABDMiZEkSZFRoVykNlk+abusRy2nskR6gv6a3ef KIvYt4Zk8kfYiKH+sXiIJdjpKlpStPG/eUOqVLwZUuD69ML2oxnChgX7SWdm6WRYcmmI auMBhViXYkBirDym8ExZShgsiDWsFzTWPifzQLrHDbP8FWZoTlXFtvcYSksZNCQWO1tK T67Q== 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=YSMhRaAh0/rjMIx1myzNsTqUJ67O67HuU1P0C4BZ2/I=; b=JbrFJR1TzCWM6diSL7lvSyjFO6BuEAGn/nGKc2p2in/0DwBq0lYaggSokHPmFYvbP5 pp+9pGEoljMPyS1RuQypvQd9yWbOPgYQVASiQ+y9awvB6HJEsj7EMc2J8yUf0Q5Uf4Av YAZlNhI08VMCS4o1iRc4RLQYvEwvwGMOSqOsTc6UhZ1cY27r6YDkev+fnlxoVAEyKT5k 3/SSqy8l1ajjJtezvJKtshaANzpTxgBwqr/QF4p8FM6cMCHp665k5aRfGgvgPPuhZIl5 aIxfc0zlnnFldD53DO/UPVEfzlOa29TYxc4sEn2aUqOncBCvW+yjDcf8A/i5sgTDkjtR 9HAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wzK1Hi4v; 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 g16sor720741ljl.5.2021.05.27.01.14.21 for (Google Transport Security); Thu, 27 May 2021 01:14:21 -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=wzK1Hi4v; 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=YSMhRaAh0/rjMIx1myzNsTqUJ67O67HuU1P0C4BZ2/I=; b=wzK1Hi4vYmsLpZCDIXCjm0zp9CnM9C1xYsygrV0BGofYNtX4CrQtd9VNaXcukxUdMG RCAb7y9UPzhvEH0zNDrKMlmHj6IbuPzU9YTs5UiXTxrQCDsu1tjTH1DRkwVKcBWK8X9Q zzSLTR2yUXKpHRuk3EfHy5uuSTs2Um9rjtZFk2DSzq6KHyyPd+iQwOubzUWO0atTjSrJ 9hd1u2Ssd99gvpyw5iIK4pnhZ9/jAFGN0YMqT8FI+Z0Oa7DPJyRYKLcKvCiip9lI8g3S IfwpRNlmNrvcPMGAVoM1dYEIq4dVXwFgE0pxYAliPLPhFHAkWQjRtfF/lPbdmVSHXNDV wyUg== 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=YSMhRaAh0/rjMIx1myzNsTqUJ67O67HuU1P0C4BZ2/I=; b=MXv29ve5KhMuDDrtBiPG4yZUG+4QeZzao4rQ58YC1An5KX8ye8nsRmNreGnDpBIOb0 ohhFcTo3vHz2kg0rN4AjRDuKyuqNoWh+JEuWMUS0uGp0KzpVSoOqmiMsYj/RoKDLevak GjW4lJ88+psdibvoeStLQK8ABD/DcpZPDX0HZjrLim5gWExrOgQZsXloRqX2VAEVhBFY slQraa2p9bCkXxwnPe4nExekOlqlAgojxPZOolVAtdVhxM5nHv1sjO26CsLsByJQ/wpH 7YaEE/UrA4WPbJh9M4MrU7I1EhtJ0qtklv+bpLiCYtG4Vgccqm5buGVfhsLlFCcEXdub UrKA== X-Gm-Message-State: AOAM533270Dv8PuV2sJcl5vdWqfj/BLECCY28Q+NOtU4MkZA8pY5Vfl9 ewZOOU/ogmal9jT+eXHEkqMjP0Fj X-Google-Smtp-Source: ABdhPJzhgB4bIzeYPaVnRvMpVrs3HXWrIxydein8yQ5xgTc+Hm/aKHhTImpzExRk5//tbYDefTDBQA== X-Received: by 2002:a2e:99cd:: with SMTP id l13mr1671425ljj.89.1622103261222; Thu, 27 May 2021 01:14:21 -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 z10sm133186lfe.228.2021.05.27.01.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 01:14:20 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, op-tee@lists.trustedfirmware.org Cc: Sudeep Holla , Marc Bonnici , Jerome Forissier , Jens Wiklander Subject: [PATCH v2 4/5] optee: add a FF-A memory pool Date: Thu, 27 May 2021 10:14:03 +0200 Message-Id: <20210527081404.1433177-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527081404.1433177-1-jens.wiklander@linaro.org> References: <20210527081404.1433177-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Adds a memory pool to be used when the driver uses FF-A [1] as transport layer. [1] https://developer.arm.com/documentation/den0077/latest Signed-off-by: Jens Wiklander --- drivers/tee/optee/shm_pool.c | 65 +++++++++++++++++++++++++++++++++--- drivers/tee/optee/shm_pool.h | 1 + 2 files changed, 61 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c index d767eebf30bd..d2116cb39c8b 100644 --- a/drivers/tee/optee/shm_pool.c +++ b/drivers/tee/optee/shm_pool.c @@ -12,8 +12,14 @@ #include "optee_smc.h" #include "shm_pool.h" -static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, - struct tee_shm *shm, size_t size) +static int +pool_op_alloc_helper(struct tee_shm_pool_mgr *poolm, + struct tee_shm *shm, size_t size, + int (*shm_register)(struct tee_context *ctx, + struct tee_shm *shm, + struct page **pages, + size_t num_pages, + unsigned long start)) { unsigned int order = get_order(size); struct page *page; @@ -27,7 +33,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, shm->paddr = page_to_phys(page); shm->size = PAGE_SIZE << order; - if (shm->flags & TEE_SHM_DMA_BUF) { + if (shm_register) { unsigned int nr_pages = 1 << order, i; struct page **pages; @@ -41,14 +47,23 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, } shm->flags |= TEE_SHM_REGISTER; - rc = optee_shm_register(shm->ctx, shm, pages, nr_pages, - (unsigned long)shm->kaddr); + rc = shm_register(shm->ctx, shm, pages, nr_pages, + (unsigned long)shm->kaddr); kfree(pages); } return rc; } +static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, + struct tee_shm *shm, size_t size) +{ + if (!(shm->flags & TEE_SHM_DMA_BUF)) + return pool_op_alloc_helper(poolm, shm, size, NULL); + + return pool_op_alloc_helper(poolm, shm, size, optee_shm_register); +} + static void pool_op_free(struct tee_shm_pool_mgr *poolm, struct tee_shm *shm) { @@ -87,3 +102,43 @@ struct tee_shm_pool_mgr *optee_shm_pool_alloc_pages(void) return mgr; } + +#ifdef CONFIG_ARM_FFA_TRANSPORT +static int pool_ffa_op_alloc(struct tee_shm_pool_mgr *poolm, + struct tee_shm *shm, size_t size) +{ + return pool_op_alloc_helper(poolm, shm, size, optee_ffa_shm_register); +} + +static void pool_ffa_op_free(struct tee_shm_pool_mgr *poolm, + struct tee_shm *shm) +{ + optee_ffa_shm_unregister(shm->ctx, shm); + free_pages((unsigned long)shm->kaddr, get_order(shm->size)); + shm->kaddr = NULL; +} + +static const struct tee_shm_pool_mgr_ops pool_ffa_ops = { + .alloc = pool_ffa_op_alloc, + .free = pool_ffa_op_free, + .destroy_poolmgr = pool_op_destroy_poolmgr, +}; + +/** + * optee_ffa_shm_pool_alloc_pages() - create page-based allocator pool + * + * This pool is used with OP-TEE over FF-A. In this case command buffers + * and such are allocated from kernel's own memory. + */ +struct tee_shm_pool_mgr *optee_ffa_shm_pool_alloc_pages(void) +{ + struct tee_shm_pool_mgr *mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); + + if (!mgr) + return ERR_PTR(-ENOMEM); + + mgr->ops = &pool_ffa_ops; + + return mgr; +} +#endif /*CONFIG_ARM_FFA_TRANSPORT*/ diff --git a/drivers/tee/optee/shm_pool.h b/drivers/tee/optee/shm_pool.h index 28109d991c4b..34c5fd74a3ff 100644 --- a/drivers/tee/optee/shm_pool.h +++ b/drivers/tee/optee/shm_pool.h @@ -10,5 +10,6 @@ #include struct tee_shm_pool_mgr *optee_shm_pool_alloc_pages(void); +struct tee_shm_pool_mgr *optee_ffa_shm_pool_alloc_pages(void); #endif