mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-07 14:32:23 +00:00
d88e0493a0
Replaces the shared memory pool based on two pools with a single pool. The alloc() function pointer in struct tee_shm_pool_ops gets another parameter, align. This makes it possible to make less than page aligned allocations from the optional reserved shared memory pool while still making user space allocations page aligned. With in practice unchanged behaviour using only a single pool for bookkeeping. The allocation algorithm in the static OP-TEE shared memory pool is changed from best-fit to first-fit since only the latter supports an alignment parameter. The best-fit algorithm was previously the default choice and not a conscious one. The optee and amdtee drivers are updated as needed to work with this changed pool handling. This also removes OPTEE_SHM_NUM_PRIV_PAGES which becomes obsolete with this change as the private pages can be mixed with the payload pages. The OP-TEE driver changes minimum alignment for argument struct from 8 bytes to 512 bytes. A typical OP-TEE private shm allocation is 224 bytes (argument struct with 6 parameters, needed for open session). So with an alignment of 512 well waste a bit more than 50%. Before this we had a single page reserved for this so worst case usage compared to that would be 3 pages instead of 1 page. However, this worst case only occurs if there is a high pressure from multiple threads on secure world. All in all this should scale up and down better than fixed boundaries. Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
63 lines
1.6 KiB
C
63 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (c) 2015-2016, Linaro Limited
|
|
*/
|
|
#ifndef TEE_PRIVATE_H
|
|
#define TEE_PRIVATE_H
|
|
|
|
#include <linux/cdev.h>
|
|
#include <linux/completion.h>
|
|
#include <linux/device.h>
|
|
#include <linux/kref.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/types.h>
|
|
|
|
#define TEE_DEVICE_FLAG_REGISTERED 0x1
|
|
#define TEE_MAX_DEV_NAME_LEN 32
|
|
|
|
/**
|
|
* struct tee_device - TEE Device representation
|
|
* @name: name of device
|
|
* @desc: description of device
|
|
* @id: unique id of device
|
|
* @flags: represented by TEE_DEVICE_FLAG_REGISTERED above
|
|
* @dev: embedded basic device structure
|
|
* @cdev: embedded cdev
|
|
* @num_users: number of active users of this device
|
|
* @c_no_user: completion used when unregistering the device
|
|
* @mutex: mutex protecting @num_users and @idr
|
|
* @idr: register of user space shared memory objects allocated or
|
|
* registered on this device
|
|
* @pool: shared memory pool
|
|
*/
|
|
struct tee_device {
|
|
char name[TEE_MAX_DEV_NAME_LEN];
|
|
const struct tee_desc *desc;
|
|
int id;
|
|
unsigned int flags;
|
|
|
|
struct device dev;
|
|
struct cdev cdev;
|
|
|
|
size_t num_users;
|
|
struct completion c_no_users;
|
|
struct mutex mutex; /* protects num_users and idr */
|
|
|
|
struct idr idr;
|
|
struct tee_shm_pool *pool;
|
|
};
|
|
|
|
int tee_shm_init(void);
|
|
|
|
int tee_shm_get_fd(struct tee_shm *shm);
|
|
|
|
bool tee_device_get(struct tee_device *teedev);
|
|
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*/
|