Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60456261 authored by Isaac J. Manjarres's avatar Isaac J. Manjarres
Browse files

soc: qcom: mem-buf: Add support for inter-VM memory sharing



Add the initial support required to share memory buffers
between VMs. This driver exposes an interface to userspace
clients to request memory to be allocated from another VM,
and added to the current VM. The VMs communicate with each
other via the use of the hypervisor message queues, as well
as utilize various facilities offered by the Haven resource
manager to manage memory that is transferred from one VM
to another.

Change-Id: I3181a1b14e61db30ed6b86752750722e24fd62e0
Signed-off-by: default avatarIsaac J. Manjarres <isaacm@codeaurora.org>
parent 4883cd21
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -57,6 +57,16 @@ config OVERRIDE_MEMORY_LIMIT
	  hot-plugging.
	  If unsure, say N

config QCOM_MEM_BUF
	bool "Qualcomm Technologies, Inc. Memory Buffer Sharing Driver"
	depends on HH_MSGQ && HH_RM_DRV && ION_MSM_HEAPS && QCOM_SECURE_BUFFER
	help
	  Add support for lending memory from one virtual machine to another.
	  This driver communicates with the hypervisor, as well as other
	  virtual machines, to request and lend memory from and to VMs
	  respectively.
	  If unsure, say N

config QCOM_GENI_SE
	tristate "QCOM GENI Serial Engine Driver"
	depends on ARCH_QCOM || COMPILE_TEST
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ obj-$(CONFIG_QCOM_LLCC) += llcc-slice.o
obj-$(CONFIG_QCOM_LAHAINA_LLCC) += llcc-lahaina.o
obj-$(CONFIG_QCOM_MINIDUMP) += msm_minidump.o minidump_log.o
obj-$(CONFIG_QCOM_MEM_OFFLINE) += mem-offline.o
obj-$(CONFIG_QCOM_MEM_BUF) += mem-buf.o
obj-$(CONFIG_QCOM_MEMORY_DUMP_V2) += memory_dump_v2.o
obj-$(CONFIG_QCOM_DCC_V2) += dcc_v2.o
obj-$(CONFIG_MSM_JTAGV8) += jtagv8.o jtagv8-etm.o
+1637 −0

File added.

Preview size limit exceeded, changes collapsed.

+69 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 *  Copyright (c) 2020, The Linux Foundation. All rights reserved.
 */

#ifndef _MEM_BUF_H
#define _MEM_BUF_H

#include <uapi/linux/mem-buf.h>

/**
 * struct mem_buf_allocation_data - Data structure that contains information
 * about a memory buffer allocation request.
 * @size: The size (in bytes) of the memory to be requested from a remote VM
 * @nr_acl_entries: The number of ACL entries in @acl_list
 * @acl_list: A list of VMID and permission pairs that describe what VMIDs will
 * have access to the memory, and with what permissions
 * @src_mem_type: The type of memory that the remote VM should allocate
 * (e.g. ION memory)
 * @src_data: A pointer to memory type specific data that the remote VM may need
 * when performing an allocation (e.g. ION memory allocations require a heap ID)
 * @dst_mem_type: The type of memory that the native VM wants (e.g. ION memory)
 * @dst_data: A pointer to memory type specific data that the native VM may
 * need when adding the memory from the remote VM (e.g. ION memory requires a
 * heap ID to add the memory to).
 */
struct mem_buf_allocation_data {
	size_t size;
	unsigned int nr_acl_entries;
	struct acl_entry *acl_list;
	enum mem_buf_mem_type src_mem_type;
	void *src_data;
	enum mem_buf_mem_type dst_mem_type;
	void *dst_data;
};

#if IS_ENABLED(CONFIG_QCOM_MEM_BUF)

void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data);

int mem_buf_get_fd(void *membuf_desc);

void mem_buf_put(void *membuf_desc);

void *mem_buf_get(int fd);

#else

static inline void *mem_buf_alloc(struct mem_buf_allocation_data *alloc_data)
{
	return ERR_PTR(-ENODEV);
}

static inline int mem_buf_get_fd(void *membuf_desc)
{
	return -ENODEV;
}

static inline void mem_buf_put(void *membuf_desc)
{
}

static inline void *mem_buf_get(int fd)
{
	return ERR_PTR(-ENODEV);
}

#endif /* CONFIG_QCOM_MEM_BUF */
#endif /* _MEM_BUF_H */
+98 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
 */

#ifndef _UAPI_LINUX_MEM_BUF_H
#define _UAPI_LINUX_MEM_BUF_H

#include <linux/ioctl.h>
#include <linux/types.h>

#define MEM_BUF_IOC_MAGIC 'M'

/**
 * enum mem_buf_mem_type: Types of memory that can be allocated from and to
 * @MEM_BUF_ION_MEM_TYPE: The memory for the source or destination is ION memory
 */
enum mem_buf_mem_type {
	MEM_BUF_ION_MEM_TYPE,
	MEM_BUF_MAX_MEM_TYPE,
};

/* The mem-buf values that represent VMIDs for an ACL. */
#define MEM_BUF_VMID_HLOS 0
#define	MEM_BUF_VMID_TRUSTED_UI 1

#define MEM_BUF_PERM_FLAG_READ (1U << 0)
#define MEM_BUF_PERM_FLAG_WRITE (1U << 1)
#define MEM_BUF_PERM_FLAG_EXEC (1U << 2)
#define MEM_BUF_PERM_VALID_FLAGS\
	(MEM_BUF_PERM_FLAG_READ | MEM_BUF_PERM_FLAG_WRITE |\
	 MEM_BUF_PERM_FLAG_EXEC)

/**
 * struct acl_entry: Represents the access control permissions for a VMID.
 * @vmid: The mem-buf VMID specifier associated with the VMID that will access
 * the memory.
 * @perms: The access permissions for the VMID in @vmid. This flag is
 * interpreted as a bitmap, and thus, should be a combination of one or more
 * of the MEM_BUF_PERM_FLAG_* flags.
 */
struct acl_entry {
	__u32 vmid;
	__u32 perms;
};

/**
 * struct mem_buf_ion_data: Data that is unique to memory that is of type
 * MEM_BUF_ION_MEM_TYPE.
 * @heap_id: The heap ID of where memory should be allocated from or added to.
 */
struct mem_buf_ion_data {
	__u32 heap_id;
};

/**
 * struct mem_buf_alloc_ioctl_arg: An request to allocate memory from another
 * VM to other VMs.
 * @size: The size of the allocation.
 * @nr_acl_entries: The number of ACL entries in @acl_list.
 * @acl_list: An array of structures, where each structure specifies a VMID
 * and the access permissions that the VMID will have to the memory to be
 * allocated.
 * @src_mem_type: The type of memory that the source VM should allocate from.
 * This should be one of the mem_buf_mem_type enum values.
 * @src_data: A pointer to data that the source VM should interpret when
 * performing the allocation.
 * @dst_mem_type: The type of memory that the destination VM should treat the
 * incoming allocation from the source VM as. This should be one of the
 * mem_buf_mem_type enum values.
 * @dst_data: A pointer to data that the destination VM should interpret when
 * adding the memory to the current VM.
 * @mem_buf_fd: A file descriptor representing the memory that was allocated
 * from the source VM and added to the current VM. Calling close() on this file
 * descriptor will deallocate the memory from the current VM, and return it
 * to the source VM.
 *
 * All reserved fields must be zeroed out by the caller prior to invoking the
 * allocation IOCTL command with this argument.
 */
struct mem_buf_alloc_ioctl_arg {
	__u64 size;
	__u32 nr_acl_entries;
	__u64 acl_list;
	__u32 src_mem_type;
	__u64 src_data;
	__u32 dst_mem_type;
	__u64 dst_data;
	__u32 mem_buf_fd;
	__u64 reserved0;
	__u64 reserved1;
	__u64 reserved2;
};

#define MEM_BUF_IOC_ALLOC		_IOWR(MEM_BUF_IOC_MAGIC, 0,\
					      struct mem_buf_alloc_ioctl_arg)

#endif /* _UAPI_LINUX_MEM_BUF_H */