From: tao zeng Date: Fri, 2 Nov 2018 11:10:16 +0000 (+0800) Subject: mm: clear MMU mapping for secure os memory [1/1] X-Git-Tag: khadas-vims-v0.9.6-release~1174 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93c6afa6bdc93a7fdcbf7e2509c7b3fc97e0a72b;p=platform%2Fkernel%2Flinux-amlogic.git mm: clear MMU mapping for secure os memory [1/1] PD#SWPL-1631 Problem: If Cortex A73 accessed memory near secure memory range, an SError may occur due to prefetch of A73 core. Solution: Remove mmu maping of secure memory range. Note: must add clear-map and set clear range property in DTS Verify: W400 Change-Id: I718919c1b4873584eb87e00332622a1626672808 Signed-off-by: tao zeng --- diff --git a/arch/arm64/boot/dts/amlogic/g12b_a311d_skt.dts b/arch/arm64/boot/dts/amlogic/g12b_a311d_skt.dts index e39d1b7..4786033 100644 --- a/arch/arm64/boot/dts/amlogic/g12b_a311d_skt.dts +++ b/arch/arm64/boot/dts/amlogic/g12b_a311d_skt.dts @@ -68,6 +68,7 @@ size = <0x0 0x400000>; alignment = <0x0 0x400000>; alloc-ranges = <0x0 0x05000000 0x0 0x400000>; + clear-map; }; secos_reserved:linux,secos { diff --git a/arch/arm64/boot/dts/amlogic/g12b_a311d_w400.dts b/arch/arm64/boot/dts/amlogic/g12b_a311d_w400.dts index 9da3d75..089b9bb 100644 --- a/arch/arm64/boot/dts/amlogic/g12b_a311d_w400.dts +++ b/arch/arm64/boot/dts/amlogic/g12b_a311d_w400.dts @@ -68,6 +68,7 @@ size = <0x0 0x400000>; alignment = <0x0 0x400000>; alloc-ranges = <0x0 0x05000000 0x0 0x400000>; + clear-map; }; secos_reserved:linux,secos { diff --git a/arch/arm64/boot/dts/amlogic/g12b_a311d_w400_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12b_a311d_w400_buildroot.dts index 826673e9..e135257 100644 --- a/arch/arm64/boot/dts/amlogic/g12b_a311d_w400_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12b_a311d_w400_buildroot.dts @@ -67,6 +67,7 @@ size = <0x0 0x400000>; alignment = <0x0 0x400000>; alloc-ranges = <0x0 0x05000000 0x0 0x400000>; + clear-map; }; secos_reserved:linux,secos { diff --git a/arch/arm64/boot/dts/amlogic/mesong12b.dtsi b/arch/arm64/boot/dts/amlogic/mesong12b.dtsi index a5be3ea..4d3d3f7 100644 --- a/arch/arm64/boot/dts/amlogic/mesong12b.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesong12b.dtsi @@ -249,6 +249,7 @@ in_base_func = <0x82000020>; out_base_func = <0x82000021>; reserve_mem_size = <0x00300000>; + clear_range = <0x05100000 0x200000>; }; securitykey { diff --git a/drivers/amlogic/secmon/secmon.c b/drivers/amlogic/secmon/secmon.c index 1eb31cb..624c8e3 100644 --- a/drivers/amlogic/secmon/secmon.c +++ b/drivers/amlogic/secmon/secmon.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #undef pr_fmt #define pr_fmt(fmt) "secmon: " fmt @@ -61,6 +62,7 @@ static int secmon_probe(struct platform_device *pdev) int ret; int mem_size; struct page *page; + unsigned int clear[2] = {}; if (!of_property_read_u32(np, "in_base_func", &id)) phy_in_base = get_sharemem_info(id); @@ -80,6 +82,11 @@ static int secmon_probe(struct platform_device *pdev) return ret; } + if (of_property_read_u32_array(np, "clear_range", clear, 2)) + pr_info("can't fine clear_range\n"); + else + pr_info("clear_range:%x %x\n", clear[0], clear[1]); + page = dma_alloc_from_contiguous(&pdev->dev, mem_size >> PAGE_SHIFT, 0); if (!page) { pr_err("alloc page failed, ret:%p\n", page); @@ -97,6 +104,13 @@ static int secmon_probe(struct platform_device *pdev) return -ENOMEM; } + if (clear[0]) { + struct page *page = phys_to_page(clear[0]); + int cnt = clear[1] / PAGE_SIZE; + + cma_mmu_op(page, cnt, 0); + } + if (pfn_valid(__phys_to_pfn(phy_out_base))) sharemem_out_base = (void __iomem *) __phys_to_virt(phy_out_base);