Unverified Commit 3152ab40 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!13243 virtcca: fix the double map of cvm secure memory

Merge Pull Request from: @restricted-band-tree 
 
 
 
Link:https://gitee.com/openeuler/kernel/pulls/13243

 

Reviewed-by: default avatarWeilong Chen <chenweilong@huawei.com>
Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
Reviewed-by: default avatarZhang Peng <zhangpeng362@huawei.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents da7cab1a 77313e84
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ extern void __init swiotlb_cvm_update_mem_attributes(void);

extern void virtcca_cvm_tsi_init(void);

extern void swiotlb_unmap_notify(unsigned long paddr, unsigned long size);

#else

static inline int set_cvm_memory_encrypted(unsigned long addr, int numpages)
@@ -39,5 +41,6 @@ static inline void __init swiotlb_cvm_update_mem_attributes(void) {}

static inline void virtcca_cvm_tsi_init(void) {}

static inline void swiotlb_unmap_notify(unsigned long paddr, unsigned long size) {}
#endif /* CONFIG_HISI_VIRTCCA_GUEST */
#endif /* __VIRTCCA_CVM_GUEST_H */
+7 −0
Original line number Diff line number Diff line
@@ -68,6 +68,13 @@
 */
#define SMC_TSI_DEVICE_CERT                 SMC_TSI_FID(0x19A)

/*
 * arg0: Paddr of rd
 * arg1: Paddr of memory to unmap
 * arg2: Size of memory to unmap
 */
 #define SMC_TSI_SEC_MEM_UNMAP              SMC_TSI_FID(0x19C)

static inline unsigned long tsi_get_version(void)
{
	struct arm_smccc_res res;
+35 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/vmalloc.h>
#include <linux/swiotlb.h>

#include <asm/cacheflush.h>
#include <asm/set_memory.h>
@@ -69,6 +70,7 @@ bool is_virtcca_cvm_world(void)
{
	return cvm_guest_enable && static_branch_likely(&cvm_tsi_present);
}
EXPORT_SYMBOL_GPL(is_virtcca_cvm_world);

static int change_page_range_cvm(pte_t *ptep, unsigned long addr, void *data)
{
@@ -119,3 +121,36 @@ int set_cvm_memory_decrypted(unsigned long addr, int numpages)
{
	return __set_memory_encrypted(addr, numpages, false);
}

/*
 * struct io_tlb_no_swiotlb_mem - whether use the
 * bounce buffer mechanism or not
 * @for_alloc: %true if the pool is used for memory allocation.
 *	Here it is set to %false, to force devices to use direct dma operations.
 *
 * @force_bounce: %true if swiotlb bouncing is forced.
 *	Here it is set to %false, to force devices to use direct dma operations.
 */
static struct io_tlb_mem io_tlb_no_swiotlb_mem = {
	.for_alloc = false,
	.force_bounce = false,
};

void enable_swiotlb_for_cvm_dev(struct device *dev, bool enable)
{
	if (!is_virtcca_cvm_world())
		return;

	if (enable)
		swiotlb_dev_init(dev);
	else
		dev->dma_io_tlb_mem = &io_tlb_no_swiotlb_mem;
}
EXPORT_SYMBOL_GPL(enable_swiotlb_for_cvm_dev);

void swiotlb_unmap_notify(unsigned long paddr, unsigned long size)
{
	struct arm_smccc_res res;

	arm_smccc_1_1_smc(SMC_TSI_SEC_MEM_UNMAP, paddr, size, &res);
}
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <linux/swiotlb.h>
#include <linux/sysfs.h>
#include <linux/dma-map-ops.h> /* for dma_default_coherent */
#include <linux/virtcca_cvm_domain.h>

#include "base.h"
#include "physical_location.h"
@@ -3134,6 +3135,7 @@ void device_initialize(struct device *dev)
	dev->dma_coherent = dma_default_coherent;
#endif
	swiotlb_dev_init(dev);
	enable_swiotlb_for_cvm_dev(dev, false);
}
EXPORT_SYMBOL_GPL(device_initialize);

+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#ifdef CONFIG_HISI_VIRTCCA_GUEST
#include <linux/swiotlb.h>
#include <asm/virtcca_cvm_guest.h>
#include <linux/virtcca_cvm_domain.h>
#endif

#include <linux/irqchip.h>
@@ -6191,6 +6192,7 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
#ifdef CONFIG_HISI_VIRTCCA_GUEST
	if (is_virtcca_cvm_world()) {
		device_initialize(&cvm_alloc_device);
		enable_swiotlb_for_cvm_dev(&cvm_alloc_device, true);
		raw_spin_lock_init(&cvm_its_lock);
	}
#endif
Loading