mm: clear MMU mapping for secure os memory [1/1]
authortao zeng <tao.zeng@amlogic.com>
Fri, 2 Nov 2018 11:10:16 +0000 (19:10 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 5 Nov 2018 12:38:07 +0000 (05:38 -0700)
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 <tao.zeng@amlogic.com>
arch/arm64/boot/dts/amlogic/g12b_a311d_skt.dts
arch/arm64/boot/dts/amlogic/g12b_a311d_w400.dts
arch/arm64/boot/dts/amlogic/g12b_a311d_w400_buildroot.dts
arch/arm64/boot/dts/amlogic/mesong12b.dtsi
drivers/amlogic/secmon/secmon.c

index e39d1b7..4786033 100644 (file)
@@ -68,6 +68,7 @@
                        size = <0x0 0x400000>;
                        alignment = <0x0 0x400000>;
                        alloc-ranges = <0x0 0x05000000 0x0 0x400000>;
+                       clear-map;
                };
 
                secos_reserved:linux,secos {
index 9da3d75..089b9bb 100644 (file)
@@ -68,6 +68,7 @@
                        size = <0x0 0x400000>;
                        alignment = <0x0 0x400000>;
                        alloc-ranges = <0x0 0x05000000 0x0 0x400000>;
+                       clear-map;
                };
 
                secos_reserved:linux,secos {
index 826673e..e135257 100644 (file)
@@ -67,6 +67,7 @@
                        size = <0x0 0x400000>;
                        alignment = <0x0 0x400000>;
                        alloc-ranges = <0x0 0x05000000 0x0 0x400000>;
+                       clear-map;
                };
 
                secos_reserved:linux,secos {
index a5be3ea..4d3d3f7 100644 (file)
                in_base_func = <0x82000020>;
                out_base_func = <0x82000021>;
                reserve_mem_size = <0x00300000>;
+               clear_range = <0x05100000 0x200000>;
        };
 
        securitykey {
index 1eb31cb..624c8e3 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/platform_device.h>
 #include <linux/dma-contiguous.h>
 #include <asm/compiler.h>
+#include <linux/cma.h>
 #include <linux/arm-smccc.h>
 #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);