From patchwork Thu Mar 25 15:44:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 408834 Delivered-To: patches@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp647970jai; Thu, 25 Mar 2021 08:44:41 -0700 (PDT) X-Received: by 2002:a19:860b:: with SMTP id i11mr5401578lfd.330.1616687080968; Thu, 25 Mar 2021 08:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616687080; cv=none; d=google.com; s=arc-20160816; b=PDa0QeA7kuZ0qUvEmFt5K84qo1SLFAmaidaDRbw7MHqDnC3J66wcYO0Cr1EqZrbJyM +GwsqqT4hlgQag/jiU0gnrX5IWma4q0h1LuTpYxMbMUZBI6I1TqJe5psAQZ4Mkp0mdSy 2+CodNuCeQ5xGzGzkXYcKA5Jek1WVku1r8JJM1LEhofi905FdwlCggvNZ3SWKuGCH3u4 jGQxnrLi009/pJ2jKu/PygRHIO+Wr3OUsqh1cuEk4SdzylieVpJjiUqy2ccDPIMTiQkA pMkf8f9Ev2pPJ3RKrkdQgGnxjjV/k9/WYMZJUiHyl5k8pOgbPDDXauzMSUgEUuGlSSTb VVKw== 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=MraRBFbI6YetFMFdwduSb7yUJLlx4khE9vQL7IIg1jMX4B5UZnCSQsyrG/qxqI3vox 8n8d5vaEbQmxdU6j64x45/M5GyubNrqnEKVGVATjcFUukjDoaDmQaVxXRrt+oGJiHwpr bAUtnTFfB1GJGFbTYfsGhc2eh8NTROFADct68ov6+ba/vZJ4xdqu5kK3UeKGj89OEM5m UXAc9HA+4EWgJc/TbTZ60dXNKUb6LP0FuY+27xcjS3T6Kd1GuALk6ICovYybjNZCCafO HGf4hkFcCWymYHdlJz2Etd1wAI1LXcc/TY9fQXou8YJVmNfC/mpzKljdlIFLNI6FePGi GTUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EFKuh+lJ; 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 o23sor1468596lfg.170.2021.03.25.08.44.40 for (Google Transport Security); Thu, 25 Mar 2021 08:44: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=EFKuh+lJ; 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=EFKuh+lJ9rIFnC8y5rU4o8VuR5CXMEyL4syonu1xoPso3+1efItVAIODBBtxJu6HOz 9OdKJHOf7uFynDibDEPArpPqHRN/Vj9KpsRf0Qq+8Z+p2WjVOq0QX2PbV+T+iR92YLHe MxfbOrq+MlOQlFSfeEBQkoG+smcd3ySJOH4AmdlwNNeFqcFlmHIv9RPBrTnPKX/PyBi7 3vfSFkIwwGqd3owY9p85ozgMxUgh9VJo8gEOAQN9DC3R/Dq14jF483sTFXieQtDnXroH KzrggQme1gsorGdxr+MuqnsSrmkuB5S3wzBkeq4xz2UuVUtvIKGXTkY45uVnKohlaRCF ELFg== 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=XdQzS8bYwBtwCjSk4t1Gm9mjX5BBhS5yFS4BfCjOUAGVYcCSjmE/ePTrDrw2nzu6jq j723TViVMdNd4VlNK7oZVtIZHBg54jKGe5VR62dZwlU4KM1H26dNaXXAFfXsJKWFykfQ Cip4O2P2rvbY87P4I3FC+kUC1/vzcHRFz7+7X+N4YNO8WVREAq+ih2A6VcqWvt44bJQR Jtgqq8gElIwoUOUdF46B+wzWclCKBR4GtyBj8y4OTZwrMOd9ZjBJ70tij268tWe+sXWN DeWxG7ax4mG9EsSTUn8iV/6sKs+4oh67JKvE+qlJyf4j+GII9YwAQWpZuVhZDQrTkDbU M47Q== X-Gm-Message-State: AOAM532DSfrYJd2cMN+PniOc/T1jNJ199DUOWC7rSjEfqlmkKre6YNRJ LvKh4qzk2+747a9G2Jph69ud+txo X-Google-Smtp-Source: ABdhPJwb5w57NuuGD741guscv+zO4NeeLTibb/qQCJDVLFcWKCp06a7alF830Xu+/+cw57Os0NaFLw== X-Received: by 2002:a19:b03:: with SMTP id 3mr5493439lfl.236.1616687080578; Thu, 25 Mar 2021 08:44:40 -0700 (PDT) Return-Path: Received: from jade.urgonet (h-249-223.A175.priv.bahnhof.se. [98.128.249.223]) by smtp.gmail.com with ESMTPSA id m27sm770916ljc.109.2021.03.25.08.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 08:44:40 -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 5/6] optee: add a FF-A memory pool Date: Thu, 25 Mar 2021 16:44:25 +0100 Message-Id: <20210325154426.3520148-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210325154426.3520148-1-jens.wiklander@linaro.org> References: <20210325154426.3520148-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