[커널 18차] 62주차

2022.07.30 23:13

kkr 조회 수:26

kernel driver에서의 memory 할당 종류 별 실습 및 asan 실습

 

git : https://github.com/iamroot18/5.10/commit/906572520f74381d93c75631ae3611b2d25b3f5f

 

diff --git a/iamroot18/alloc_pages/hello.c b/iamroot18/alloc_pages/hello.c
new file mode 100644
index 000000000000..b9bc2da11fdc
--- /dev/null
+++ b/iamroot18/alloc_pages/hello.c
@@ -0,0 +1,51 @@
+#include <linux/init.h>
+#include <linux/module.h>
+
+#define CNT    10000
+static struct page *arr[CNT];
+
+/*
+ * IAMROOT, 2022.07.30:
+ * - buddy system에서 할당해온다. /proc/pagetypeinfo 를 통해
+ *   할당 전후 상황을 확인한다.
+ */
+static int hello_init(void) {
+    uint32_t i;
+#define ALLOC_BYTES    (4 * 1024)
+    int order = get_order(ALLOC_BYTES);
+
+    printk(KERN_INFO "alloc : %u byte. order %d. cnt %u\n",
+            ALLOC_BYTES, -1, CNT);
+    for (i = 0; i < CNT; i++) {
+        if (arr[i])
+            continue;
+        arr[i] = alloc_pages(GFP_KERNEL, order);
+        if (arr[i] == NULL)
+        {
+            printk(KERN_INFO "%d alloc fail.\n", i);
+        }
+    }
+#if 0
+    uint8_t *data = page_address(arr[0]);
+    memset(data, 0, ALLOCn);
+#endif
+    return 0;
+}
+
+static void hello_exit(void) {
+    uint32_t i;
+    int order = get_order(ALLOC_BYTES);
+
+    for (i = 0; i < CNT; i++) {
+        if (arr[i] == NULL)
+            continue;
+        __free_pages(arr[i], order);
+        arr[i] = NULL;
+    }
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
diff --git a/iamroot18/asan/build.sh b/iamroot18/asan/build.sh
new file mode 100755
index 000000000000..27c90272de0b
--- /dev/null
+++ b/iamroot18/asan/build.sh
@@ -0,0 +1,2 @@
+gcc -O0 -g -fsanitize=address -o test test.c
+#gcc -o test test.c
diff --git a/iamroot18/asan/test.c b/iamroot18/asan/test.c
new file mode 100644
index 000000000000..e6d4139ac64d
--- /dev/null
+++ b/iamroot18/asan/test.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+//double_free
+void double_free(void)
+{
+    char *p = malloc(100);
+    free(p);
+    free(p);
+}
+
+//stack_corrupt
+void __stack_corrupt(char **p)
+{
+    char __p[1];
+    *p = __p;
+}
+
+void stack_corrupt(void)
+{
+    char *p;
+    __stack_corrupt(&p);
+    printf("%p\n", p);
+    memset(p, 'a', 10);
+    printf("%c\n", *p);
+}
+
+void overwrite(void)
+{
+    char *p = malloc(100);
+    memset(p, 0xff, 101);
+    free(p);
+}
+
+
+int main(void)
+{
+    //double_free();
+    //stack_corrupt();
+    overwrite();
+    return 0;
+}
diff --git a/iamroot18/cma/hello.c b/iamroot18/cma/hello.c
new file mode 100644
index 000000000000..15b1cab06963
--- /dev/null
+++ b/iamroot18/cma/hello.c
@@ -0,0 +1,85 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/dma-mapping.h>
+#include <linux/of.h>
+#include <linux/of_reserved_mem.h>
+
+static dma_addr_t g_dma_addr;
+static void *g_dma;
+#define ALLOC_SIZE    1024
+
+/*
+ * IAMROOT, 2022.07.30:
+ * ------ default_cma.dts
+ * - menuconfig에서 libraries에서 dma-api debug on후 /sys/kerenel/debug/dma-api/dump에서 확인
+ * - dump 내용
+ *  |  dev_name | driver name  | map type    | hash index | phys addr   | pfn    | dev_addr   | size  | 
+ *     iamroot    IAMROOT_NAME      coherent   idx 4736      P=42500000  N=42500   D=42500000   L=400  
+ *
+ *  | dir              | map error check string             |
+ *   DMA_BIDIRECTIONAL   dma map error check not applicable
+ *
+ *
+ * ------ cma2.dts
+ *  - default cma와 다른 reserved가 있는상태.
+ *  - default cma는 즉시 cma로 잡히고 다른 한개는 reserved로만 예약된다.
+ *  - log
+ *  [    0.000000] Memory: 3817648K/4194304K available (14912K kernel code, 3068K rwdata,
+ *  8252K rodata, 6208K init, 880K bss, 245584K reserved, 131072K cma-reserved)
+
+ */
+static int iamroot_probe(struct platform_device *pdev)
+{
+    int err;
+
+    err = of_reserved_mem_device_init_by_idx(&pdev->dev, pdev->dev.of_node, 0);
+
+    if (err < 0) {
+        dev_err(&pdev->dev, "failed to get nominal EMC table: %d\n", err);
+        return err;
+    }
+
+    printk(KERN_INFO "%s %d %px\n", __func__, __LINE__, pdev->dev.dma_mem);
+    g_dma = dma_alloc_coherent(&pdev->dev, ALLOC_SIZE, &g_dma_addr, GFP_KERNEL);
+    printk(KERN_INFO "%s %d %px %llx\n", __func__, __LINE__, g_dma, g_dma_addr);
+    return 0;
+}
+
+static int iamroot_remove(struct platform_device *pdev)
+{
+    printk(KERN_INFO "%s %d\n", __func__, __LINE__);
+    dma_free_coherent(&pdev->dev, ALLOC_SIZE, g_dma, g_dma_addr);
+    return 0;
+}
+
+static const struct of_device_id iamroot_ids[] = {
+    {.compatible = "iamroot_comp"},
+    {},
+};
+
+static struct platform_driver iamroot_driver = {
+    .driver        = {
+        .name    = "IAMROOT_NAME",
+        .of_match_table = iamroot_ids,
+    },
+    .probe        = iamroot_probe,
+    .remove         = iamroot_remove
+};
+
+static int hello_init(void) {
+    printk(KERN_INFO "%s %d\n", __func__, __LINE__);
+    return platform_driver_register(&iamroot_driver);
+}
+
+static void hello_exit(void) {
+    printk(KERN_INFO "%s %d\n", __func__, __LINE__);
+    platform_driver_unregister(&iamroot_driver);
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
diff --git a/iamroot18/example/abc.dts b/iamroot18/example/abc.dts
new file mode 100644
index 000000000000..14c1c064b389
--- /dev/null
+++ b/iamroot18/example/abc.dts
@@ -0,0 +1,407 @@
+/dts-v1/;
+
+/ {
+    interrupt-parent = <0x8001>;
+    #size-cells = <0x02>;
+    #address-cells = <0x02>;
+    compatible = "linux,dummy-virt";
+
+    psci {
+        migrate = <0xc4000005>;
+        cpu_on = <0xc4000003>;
+        cpu_off = <0x84000002>;
+        cpu_suspend = <0xc4000001>;
+        method = "hvc";
+        compatible = "arm,psci-0.2\0arm,psci";
+    };
+
+    memory@40000000 {
+        reg = <0x00 0x40000000 0x00 0x80000000>;
+        device_type = "memory";
+    };
+
+    platform@c000000 {
+        interrupt-parent = <0x8001>;
+        ranges = <0x00 0x00 0xc000000 0x2000000>;
+        #address-cells = <0x01>;
+        #size-cells = <0x01>;
+        compatible = "qemu,platform\0simple-bus";
+    };
+
+    fw-cfg@9020000 {
+        dma-coherent;
+        reg = <0x00 0x9020000 0x00 0x18>;
+        compatible = "qemu,fw-cfg-mmio";
+    };
+
+    virtio_mmio@a000000 {
+        dma-coherent;
+        interrupts = <0x00 0x10 0x01>;
+        reg = <0x00 0xa000000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000200 {
+        dma-coherent;
+        interrupts = <0x00 0x11 0x01>;
+        reg = <0x00 0xa000200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000400 {
+        dma-coherent;
+        interrupts = <0x00 0x12 0x01>;
+        reg = <0x00 0xa000400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000600 {
+        dma-coherent;
+        interrupts = <0x00 0x13 0x01>;
+        reg = <0x00 0xa000600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000800 {
+        dma-coherent;
+        interrupts = <0x00 0x14 0x01>;
+        reg = <0x00 0xa000800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000a00 {
+        dma-coherent;
+        interrupts = <0x00 0x15 0x01>;
+        reg = <0x00 0xa000a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000c00 {
+        dma-coherent;
+        interrupts = <0x00 0x16 0x01>;
+        reg = <0x00 0xa000c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000e00 {
+        dma-coherent;
+        interrupts = <0x00 0x17 0x01>;
+        reg = <0x00 0xa000e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001000 {
+        dma-coherent;
+        interrupts = <0x00 0x18 0x01>;
+        reg = <0x00 0xa001000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001200 {
+        dma-coherent;
+        interrupts = <0x00 0x19 0x01>;
+        reg = <0x00 0xa001200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001400 {
+        dma-coherent;
+        interrupts = <0x00 0x1a 0x01>;
+        reg = <0x00 0xa001400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001600 {
+        dma-coherent;
+        interrupts = <0x00 0x1b 0x01>;
+        reg = <0x00 0xa001600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001800 {
+        dma-coherent;
+        interrupts = <0x00 0x1c 0x01>;
+        reg = <0x00 0xa001800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001a00 {
+        dma-coherent;
+        interrupts = <0x00 0x1d 0x01>;
+        reg = <0x00 0xa001a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001c00 {
+        dma-coherent;
+        interrupts = <0x00 0x1e 0x01>;
+        reg = <0x00 0xa001c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001e00 {
+        dma-coherent;
+        interrupts = <0x00 0x1f 0x01>;
+        reg = <0x00 0xa001e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002000 {
+        dma-coherent;
+        interrupts = <0x00 0x20 0x01>;
+        reg = <0x00 0xa002000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002200 {
+        dma-coherent;
+        interrupts = <0x00 0x21 0x01>;
+        reg = <0x00 0xa002200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002400 {
+        dma-coherent;
+        interrupts = <0x00 0x22 0x01>;
+        reg = <0x00 0xa002400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002600 {
+        dma-coherent;
+        interrupts = <0x00 0x23 0x01>;
+        reg = <0x00 0xa002600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002800 {
+        dma-coherent;
+        interrupts = <0x00 0x24 0x01>;
+        reg = <0x00 0xa002800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002a00 {
+        dma-coherent;
+        interrupts = <0x00 0x25 0x01>;
+        reg = <0x00 0xa002a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002c00 {
+        dma-coherent;
+        interrupts = <0x00 0x26 0x01>;
+        reg = <0x00 0xa002c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002e00 {
+        dma-coherent;
+        interrupts = <0x00 0x27 0x01>;
+        reg = <0x00 0xa002e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003000 {
+        dma-coherent;
+        interrupts = <0x00 0x28 0x01>;
+        reg = <0x00 0xa003000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003200 {
+        dma-coherent;
+        interrupts = <0x00 0x29 0x01>;
+        reg = <0x00 0xa003200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003400 {
+        dma-coherent;
+        interrupts = <0x00 0x2a 0x01>;
+        reg = <0x00 0xa003400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003600 {
+        dma-coherent;
+        interrupts = <0x00 0x2b 0x01>;
+        reg = <0x00 0xa003600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003800 {
+        dma-coherent;
+        interrupts = <0x00 0x2c 0x01>;
+        reg = <0x00 0xa003800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003a00 {
+        dma-coherent;
+        interrupts = <0x00 0x2d 0x01>;
+        reg = <0x00 0xa003a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003c00 {
+        dma-coherent;
+        interrupts = <0x00 0x2e 0x01>;
+        reg = <0x00 0xa003c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003e00 {
+        dma-coherent;
+        interrupts = <0x00 0x2f 0x01>;
+        reg = <0x00 0xa003e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    gpio-keys {
+        #address-cells = <0x01>;
+        #size-cells = <0x00>;
+        compatible = "gpio-keys";
+
+        poweroff {
+            gpios = <0x8003 0x03 0x00>;
+            linux,code = <0x74>;
+            label = "GPIO Key Poweroff";
+        };
+    };
+
+    pl061@9030000 {
+        phandle = <0x8003>;
+        clock-names = "apb_pclk";
+        clocks = <0x8000>;
+        interrupts = <0x00 0x07 0x04>;
+        gpio-controller;
+        #gpio-cells = <0x02>;
+        compatible = "arm,pl061\0arm,primecell";
+        reg = <0x00 0x9030000 0x00 0x1000>;
+    };
+
+    pcie@10000000 {
+        interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
+        interrupt-map = <0x00 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x03 0x04 0x00 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x04 0x04 0x800 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x05 0x04 0x800 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x05 0x04 0x1000 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x06 0x04 0x1000 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x06 0x04 0x1800 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x03 0x04 0x1800 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x05 0x04>;
+        #interrupt-cells = <0x01>;
+        ranges = <0x1000000 0x00 0x00 0x00 0x3eff0000 0x00 0x10000 0x2000000 0x00 0x10000000 0x00 0x10000000 0x00 0x2eff0000 0x3000000 0x80 0x00 0x80 0x00 0x80 0x00>;
+        reg = <0x40 0x10000000 0x00 0x10000000>;
+        msi-parent = <0x8002>;
+        dma-coherent;
+        bus-range = <0x00 0xff>;
+        linux,pci-domain = <0x00>;
+        #size-cells = <0x02>;
+        #address-cells = <0x03>;
+        device_type = "pci";
+        compatible = "pci-host-ecam-generic";
+    };
+
+    pl031@9010000 {
+        clock-names = "apb_pclk";
+        clocks = <0x8000>;
+        interrupts = <0x00 0x02 0x04>;
+        reg = <0x00 0x9010000 0x00 0x1000>;
+        compatible = "arm,pl031\0arm,primecell";
+    };
+
+    pl011@9000000 {
+        clock-names = "uartclk\0apb_pclk";
+        clocks = <0x8000 0x8000>;
+        interrupts = <0x00 0x01 0x04>;
+        reg = <0x00 0x9000000 0x00 0x1000>;
+        compatible = "arm,pl011\0arm,primecell";
+    };
+
+    pmu {
+        interrupts = <0x01 0x07 0x704>;
+        compatible = "arm,armv8-pmuv3";
+    };
+
+    intc@8000000 {
+        phandle = <0x8001>;
+        reg = <0x00 0x8000000 0x00 0x10000 0x00 0x8010000 0x00 0x10000>;
+        compatible = "arm,cortex-a15-gic";
+        ranges;
+        #size-cells = <0x02>;
+        #address-cells = <0x02>;
+        interrupt-controller;
+        #interrupt-cells = <0x03>;
+
+        v2m@8020000 {
+            phandle = <0x8002>;
+            reg = <0x00 0x8020000 0x00 0x1000>;
+            msi-controller;
+            compatible = "arm,gic-v2m-frame";
+        };
+    };
+
+    flash@0 {
+        bank-width = <0x04>;
+        reg = <0x00 0x00 0x00 0x4000000 0x00 0x4000000 0x00 0x4000000>;
+        compatible = "cfi-flash";
+    };
+
+    cpus {
+        #size-cells = <0x00>;
+        #address-cells = <0x01>;
+
+        cpu@0 {
+            reg = <0x00>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+
+        cpu@1 {
+            reg = <0x01>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+
+        cpu@2 {
+            reg = <0x02>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+    };
+
+    timer {
+        interrupts = <0x01 0x0d 0x704 0x01 0x0e 0x704 0x01 0x0b 0x704 0x01 0x0a 0x704>;
+        always-on;
+        compatible = "arm,armv8-timer\0arm,armv7-timer";
+    };
+
+    apb-pclk {
+        phandle = <0x8000>;
+        clock-output-names = "clk24mhz";
+        clock-frequency = <0x16e3600>;
+        #clock-cells = <0x00>;
+        compatible = "fixed-clock";
+    };
+
+    chosen {
+        bootargs = "rootwait root=/dev/vda rw console=ttyAMA0";
+        stdout-path = "/pl011@9000000";
+    };
+
+  iamroot {
+    compatible = "iamroot_comp";
+    memory-region = <&iamroot_buffer>;
+  };
+
+  reserved-memory {
+      #address-cells = <2>;
+      #size-cells = <2>;
+      ranges;
+
+      iamroot_buffer: iamroot_buffer@0 {
+          compatible = "shared-dma-pool";
+          size = <0x00000000 0x08000000>;
+          linux,cma-default;
+      reusable;
+      };
+  };
+};
diff --git a/iamroot18/example/br.sh b/iamroot18/example/br.sh
new file mode 100755
index 000000000000..639b069b239e
--- /dev/null
+++ b/iamroot18/example/br.sh
@@ -0,0 +1,27 @@
+WHOAMI=$(whoami)
+DEV=enp0s3
+DEV_TAP=tap0
+IP_TAP=$(ip addr show ${DEV_TAP} | awk '/inet / {print $2}' | cut -d/ -f1)
+
+if [ "$IP_TAP" == "20.0.2.4" ]; then
+echo tap0 interface is already installed.
+exit
+fi
+
+sudo iptables -P INPUT ACCEPT
+sudo iptables -P FORWARD ACCEPT
+sudo iptables -P OUTPUT ACCEPT
+sudo iptables -t nat -F
+#sudo iptables -t mangle -F
+sudo iptables -F
+sudo iptables -X
+
+
+echo setup NAT network: tap0 to ethernet:${DEV}
+sudo tunctl -d ${DEV_TAP}
+sudo tunctl -u ${WHOAMI}
+sudo ifconfig ${DEV_TAP} 20.0.2.4/24 up
+sudo modprobe ip_tables
+sudo modprobe iptable_filter
+sudo sysctl -w net.ipv4.ip_forward=1
+sudo iptables -t nat -A POSTROUTING -o ${DEV} -j MASQUERADE
diff --git a/iamroot18/example/cma2.dts b/iamroot18/example/cma2.dts
new file mode 100644
index 000000000000..cbe2f85935fb
--- /dev/null
+++ b/iamroot18/example/cma2.dts
@@ -0,0 +1,412 @@
+/dts-v1/;
+
+/ {
+    interrupt-parent = <0x8001>;
+    #size-cells = <0x02>;
+    #address-cells = <0x02>;
+    compatible = "linux,dummy-virt";
+
+    psci {
+        migrate = <0xc4000005>;
+        cpu_on = <0xc4000003>;
+        cpu_off = <0x84000002>;
+        cpu_suspend = <0xc4000001>;
+        method = "hvc";
+        compatible = "arm,psci-0.2\0arm,psci";
+    };
+
+    memory@40000000 {
+        reg = <0x00 0x40000000 0x00 0x80000000>;
+        device_type = "memory";
+    };
+
+    platform@c000000 {
+        interrupt-parent = <0x8001>;
+        ranges = <0x00 0x00 0xc000000 0x2000000>;
+        #address-cells = <0x01>;
+        #size-cells = <0x01>;
+        compatible = "qemu,platform\0simple-bus";
+    };
+
+    fw-cfg@9020000 {
+        dma-coherent;
+        reg = <0x00 0x9020000 0x00 0x18>;
+        compatible = "qemu,fw-cfg-mmio";
+    };
+
+    virtio_mmio@a000000 {
+        dma-coherent;
+        interrupts = <0x00 0x10 0x01>;
+        reg = <0x00 0xa000000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000200 {
+        dma-coherent;
+        interrupts = <0x00 0x11 0x01>;
+        reg = <0x00 0xa000200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000400 {
+        dma-coherent;
+        interrupts = <0x00 0x12 0x01>;
+        reg = <0x00 0xa000400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000600 {
+        dma-coherent;
+        interrupts = <0x00 0x13 0x01>;
+        reg = <0x00 0xa000600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000800 {
+        dma-coherent;
+        interrupts = <0x00 0x14 0x01>;
+        reg = <0x00 0xa000800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000a00 {
+        dma-coherent;
+        interrupts = <0x00 0x15 0x01>;
+        reg = <0x00 0xa000a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000c00 {
+        dma-coherent;
+        interrupts = <0x00 0x16 0x01>;
+        reg = <0x00 0xa000c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000e00 {
+        dma-coherent;
+        interrupts = <0x00 0x17 0x01>;
+        reg = <0x00 0xa000e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001000 {
+        dma-coherent;
+        interrupts = <0x00 0x18 0x01>;
+        reg = <0x00 0xa001000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001200 {
+        dma-coherent;
+        interrupts = <0x00 0x19 0x01>;
+        reg = <0x00 0xa001200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001400 {
+        dma-coherent;
+        interrupts = <0x00 0x1a 0x01>;
+        reg = <0x00 0xa001400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001600 {
+        dma-coherent;
+        interrupts = <0x00 0x1b 0x01>;
+        reg = <0x00 0xa001600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001800 {
+        dma-coherent;
+        interrupts = <0x00 0x1c 0x01>;
+        reg = <0x00 0xa001800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001a00 {
+        dma-coherent;
+        interrupts = <0x00 0x1d 0x01>;
+        reg = <0x00 0xa001a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001c00 {
+        dma-coherent;
+        interrupts = <0x00 0x1e 0x01>;
+        reg = <0x00 0xa001c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001e00 {
+        dma-coherent;
+        interrupts = <0x00 0x1f 0x01>;
+        reg = <0x00 0xa001e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002000 {
+        dma-coherent;
+        interrupts = <0x00 0x20 0x01>;
+        reg = <0x00 0xa002000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002200 {
+        dma-coherent;
+        interrupts = <0x00 0x21 0x01>;
+        reg = <0x00 0xa002200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002400 {
+        dma-coherent;
+        interrupts = <0x00 0x22 0x01>;
+        reg = <0x00 0xa002400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002600 {
+        dma-coherent;
+        interrupts = <0x00 0x23 0x01>;
+        reg = <0x00 0xa002600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002800 {
+        dma-coherent;
+        interrupts = <0x00 0x24 0x01>;
+        reg = <0x00 0xa002800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002a00 {
+        dma-coherent;
+        interrupts = <0x00 0x25 0x01>;
+        reg = <0x00 0xa002a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002c00 {
+        dma-coherent;
+        interrupts = <0x00 0x26 0x01>;
+        reg = <0x00 0xa002c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002e00 {
+        dma-coherent;
+        interrupts = <0x00 0x27 0x01>;
+        reg = <0x00 0xa002e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003000 {
+        dma-coherent;
+        interrupts = <0x00 0x28 0x01>;
+        reg = <0x00 0xa003000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003200 {
+        dma-coherent;
+        interrupts = <0x00 0x29 0x01>;
+        reg = <0x00 0xa003200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003400 {
+        dma-coherent;
+        interrupts = <0x00 0x2a 0x01>;
+        reg = <0x00 0xa003400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003600 {
+        dma-coherent;
+        interrupts = <0x00 0x2b 0x01>;
+        reg = <0x00 0xa003600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003800 {
+        dma-coherent;
+        interrupts = <0x00 0x2c 0x01>;
+        reg = <0x00 0xa003800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003a00 {
+        dma-coherent;
+        interrupts = <0x00 0x2d 0x01>;
+        reg = <0x00 0xa003a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003c00 {
+        dma-coherent;
+        interrupts = <0x00 0x2e 0x01>;
+        reg = <0x00 0xa003c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003e00 {
+        dma-coherent;
+        interrupts = <0x00 0x2f 0x01>;
+        reg = <0x00 0xa003e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    gpio-keys {
+        #address-cells = <0x01>;
+        #size-cells = <0x00>;
+        compatible = "gpio-keys";
+
+        poweroff {
+            gpios = <0x8003 0x03 0x00>;
+            linux,code = <0x74>;
+            label = "GPIO Key Poweroff";
+        };
+    };
+
+    pl061@9030000 {
+        phandle = <0x8003>;
+        clock-names = "apb_pclk";
+        clocks = <0x8000>;
+        interrupts = <0x00 0x07 0x04>;
+        gpio-controller;
+        #gpio-cells = <0x02>;
+        compatible = "arm,pl061\0arm,primecell";
+        reg = <0x00 0x9030000 0x00 0x1000>;
+    };
+
+    pcie@10000000 {
+        interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
+        interrupt-map = <0x00 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x03 0x04 0x00 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x04 0x04 0x800 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x05 0x04 0x800 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x05 0x04 0x1000 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x06 0x04 0x1000 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x06 0x04 0x1800 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x03 0x04 0x1800 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x05 0x04>;
+        #interrupt-cells = <0x01>;
+        ranges = <0x1000000 0x00 0x00 0x00 0x3eff0000 0x00 0x10000 0x2000000 0x00 0x10000000 0x00 0x10000000 0x00 0x2eff0000 0x3000000 0x80 0x00 0x80 0x00 0x80 0x00>;
+        reg = <0x40 0x10000000 0x00 0x10000000>;
+        msi-parent = <0x8002>;
+        dma-coherent;
+        bus-range = <0x00 0xff>;
+        linux,pci-domain = <0x00>;
+        #size-cells = <0x02>;
+        #address-cells = <0x03>;
+        device_type = "pci";
+        compatible = "pci-host-ecam-generic";
+    };
+
+    pl031@9010000 {
+        clock-names = "apb_pclk";
+        clocks = <0x8000>;
+        interrupts = <0x00 0x02 0x04>;
+        reg = <0x00 0x9010000 0x00 0x1000>;
+        compatible = "arm,pl031\0arm,primecell";
+    };
+
+    pl011@9000000 {
+        clock-names = "uartclk\0apb_pclk";
+        clocks = <0x8000 0x8000>;
+        interrupts = <0x00 0x01 0x04>;
+        reg = <0x00 0x9000000 0x00 0x1000>;
+        compatible = "arm,pl011\0arm,primecell";
+    };
+
+    pmu {
+        interrupts = <0x01 0x07 0x704>;
+        compatible = "arm,armv8-pmuv3";
+    };
+
+    intc@8000000 {
+        phandle = <0x8001>;
+        reg = <0x00 0x8000000 0x00 0x10000 0x00 0x8010000 0x00 0x10000>;
+        compatible = "arm,cortex-a15-gic";
+        ranges;
+        #size-cells = <0x02>;
+        #address-cells = <0x02>;
+        interrupt-controller;
+        #interrupt-cells = <0x03>;
+
+        v2m@8020000 {
+            phandle = <0x8002>;
+            reg = <0x00 0x8020000 0x00 0x1000>;
+            msi-controller;
+            compatible = "arm,gic-v2m-frame";
+        };
+    };
+
+    flash@0 {
+        bank-width = <0x04>;
+        reg = <0x00 0x00 0x00 0x4000000 0x00 0x4000000 0x00 0x4000000>;
+        compatible = "cfi-flash";
+    };
+
+    cpus {
+        #size-cells = <0x00>;
+        #address-cells = <0x01>;
+
+        cpu@0 {
+            reg = <0x00>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+
+        cpu@1 {
+            reg = <0x01>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+
+        cpu@2 {
+            reg = <0x02>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+    };
+
+    timer {
+        interrupts = <0x01 0x0d 0x704 0x01 0x0e 0x704 0x01 0x0b 0x704 0x01 0x0a 0x704>;
+        always-on;
+        compatible = "arm,armv8-timer\0arm,armv7-timer";
+    };
+
+    apb-pclk {
+        phandle = <0x8000>;
+        clock-output-names = "clk24mhz";
+        clock-frequency = <0x16e3600>;
+        #clock-cells = <0x00>;
+        compatible = "fixed-clock";
+    };
+
+    chosen {
+        bootargs = "rootwait root=/dev/vda rw console=ttyAMA0";
+        stdout-path = "/pl011@9000000";
+    };
+
+  iamroot {
+    compatible = "iamroot_comp";
+    memory-region = <&iamroot_buffer2>;
+  };
+
+  reserved-memory {
+      #address-cells = <2>;
+      #size-cells = <2>;
+      ranges;
+
+      iamroot_buffer: iamroot_buffer@0 {
+          compatible = "shared-dma-pool";
+          size = <0x00000000 0x08000000>;
+          linux,cma-default;
+      reusable;
+      };
+
+      iamroot_buffer2: iamroot_buffer@2 {
+          compatible = "shared-dma-pool";
+          size = <0x00000000 0x04000000>;
+      };
+  };
+};
diff --git a/iamroot18/example/convert_dtb.sh b/iamroot18/example/convert_dtb.sh
new file mode 100755
index 000000000000..f484021fc09f
--- /dev/null
+++ b/iamroot18/example/convert_dtb.sh
@@ -0,0 +1,2 @@
+#dtc -I dtb -O dts abc.dtb -o abc.dts
+dtc -I dts -O dtb abc.dts -o abc.dtb
diff --git a/iamroot18/example/default_cma.dts b/iamroot18/example/default_cma.dts
new file mode 100644
index 000000000000..14c1c064b389
--- /dev/null
+++ b/iamroot18/example/default_cma.dts
@@ -0,0 +1,407 @@
+/dts-v1/;
+
+/ {
+    interrupt-parent = <0x8001>;
+    #size-cells = <0x02>;
+    #address-cells = <0x02>;
+    compatible = "linux,dummy-virt";
+
+    psci {
+        migrate = <0xc4000005>;
+        cpu_on = <0xc4000003>;
+        cpu_off = <0x84000002>;
+        cpu_suspend = <0xc4000001>;
+        method = "hvc";
+        compatible = "arm,psci-0.2\0arm,psci";
+    };
+
+    memory@40000000 {
+        reg = <0x00 0x40000000 0x00 0x80000000>;
+        device_type = "memory";
+    };
+
+    platform@c000000 {
+        interrupt-parent = <0x8001>;
+        ranges = <0x00 0x00 0xc000000 0x2000000>;
+        #address-cells = <0x01>;
+        #size-cells = <0x01>;
+        compatible = "qemu,platform\0simple-bus";
+    };
+
+    fw-cfg@9020000 {
+        dma-coherent;
+        reg = <0x00 0x9020000 0x00 0x18>;
+        compatible = "qemu,fw-cfg-mmio";
+    };
+
+    virtio_mmio@a000000 {
+        dma-coherent;
+        interrupts = <0x00 0x10 0x01>;
+        reg = <0x00 0xa000000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000200 {
+        dma-coherent;
+        interrupts = <0x00 0x11 0x01>;
+        reg = <0x00 0xa000200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000400 {
+        dma-coherent;
+        interrupts = <0x00 0x12 0x01>;
+        reg = <0x00 0xa000400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000600 {
+        dma-coherent;
+        interrupts = <0x00 0x13 0x01>;
+        reg = <0x00 0xa000600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000800 {
+        dma-coherent;
+        interrupts = <0x00 0x14 0x01>;
+        reg = <0x00 0xa000800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000a00 {
+        dma-coherent;
+        interrupts = <0x00 0x15 0x01>;
+        reg = <0x00 0xa000a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000c00 {
+        dma-coherent;
+        interrupts = <0x00 0x16 0x01>;
+        reg = <0x00 0xa000c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a000e00 {
+        dma-coherent;
+        interrupts = <0x00 0x17 0x01>;
+        reg = <0x00 0xa000e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001000 {
+        dma-coherent;
+        interrupts = <0x00 0x18 0x01>;
+        reg = <0x00 0xa001000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001200 {
+        dma-coherent;
+        interrupts = <0x00 0x19 0x01>;
+        reg = <0x00 0xa001200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001400 {
+        dma-coherent;
+        interrupts = <0x00 0x1a 0x01>;
+        reg = <0x00 0xa001400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001600 {
+        dma-coherent;
+        interrupts = <0x00 0x1b 0x01>;
+        reg = <0x00 0xa001600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001800 {
+        dma-coherent;
+        interrupts = <0x00 0x1c 0x01>;
+        reg = <0x00 0xa001800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001a00 {
+        dma-coherent;
+        interrupts = <0x00 0x1d 0x01>;
+        reg = <0x00 0xa001a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001c00 {
+        dma-coherent;
+        interrupts = <0x00 0x1e 0x01>;
+        reg = <0x00 0xa001c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a001e00 {
+        dma-coherent;
+        interrupts = <0x00 0x1f 0x01>;
+        reg = <0x00 0xa001e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002000 {
+        dma-coherent;
+        interrupts = <0x00 0x20 0x01>;
+        reg = <0x00 0xa002000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002200 {
+        dma-coherent;
+        interrupts = <0x00 0x21 0x01>;
+        reg = <0x00 0xa002200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002400 {
+        dma-coherent;
+        interrupts = <0x00 0x22 0x01>;
+        reg = <0x00 0xa002400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002600 {
+        dma-coherent;
+        interrupts = <0x00 0x23 0x01>;
+        reg = <0x00 0xa002600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002800 {
+        dma-coherent;
+        interrupts = <0x00 0x24 0x01>;
+        reg = <0x00 0xa002800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002a00 {
+        dma-coherent;
+        interrupts = <0x00 0x25 0x01>;
+        reg = <0x00 0xa002a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002c00 {
+        dma-coherent;
+        interrupts = <0x00 0x26 0x01>;
+        reg = <0x00 0xa002c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a002e00 {
+        dma-coherent;
+        interrupts = <0x00 0x27 0x01>;
+        reg = <0x00 0xa002e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003000 {
+        dma-coherent;
+        interrupts = <0x00 0x28 0x01>;
+        reg = <0x00 0xa003000 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003200 {
+        dma-coherent;
+        interrupts = <0x00 0x29 0x01>;
+        reg = <0x00 0xa003200 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003400 {
+        dma-coherent;
+        interrupts = <0x00 0x2a 0x01>;
+        reg = <0x00 0xa003400 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003600 {
+        dma-coherent;
+        interrupts = <0x00 0x2b 0x01>;
+        reg = <0x00 0xa003600 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003800 {
+        dma-coherent;
+        interrupts = <0x00 0x2c 0x01>;
+        reg = <0x00 0xa003800 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003a00 {
+        dma-coherent;
+        interrupts = <0x00 0x2d 0x01>;
+        reg = <0x00 0xa003a00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003c00 {
+        dma-coherent;
+        interrupts = <0x00 0x2e 0x01>;
+        reg = <0x00 0xa003c00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    virtio_mmio@a003e00 {
+        dma-coherent;
+        interrupts = <0x00 0x2f 0x01>;
+        reg = <0x00 0xa003e00 0x00 0x200>;
+        compatible = "virtio,mmio";
+    };
+
+    gpio-keys {
+        #address-cells = <0x01>;
+        #size-cells = <0x00>;
+        compatible = "gpio-keys";
+
+        poweroff {
+            gpios = <0x8003 0x03 0x00>;
+            linux,code = <0x74>;
+            label = "GPIO Key Poweroff";
+        };
+    };
+
+    pl061@9030000 {
+        phandle = <0x8003>;
+        clock-names = "apb_pclk";
+        clocks = <0x8000>;
+        interrupts = <0x00 0x07 0x04>;
+        gpio-controller;
+        #gpio-cells = <0x02>;
+        compatible = "arm,pl061\0arm,primecell";
+        reg = <0x00 0x9030000 0x00 0x1000>;
+    };
+
+    pcie@10000000 {
+        interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
+        interrupt-map = <0x00 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x03 0x04 0x00 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x04 0x04 0x800 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x05 0x04 0x800 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x05 0x04 0x1000 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x06 0x04 0x1000 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x01 0x8001 0x00 0x00 0x00 0x06 0x04 0x1800 0x00 0x00 0x02 0x8001 0x00 0x00 0x00 0x03 0x04 0x1800 0x00 0x00 0x03 0x8001 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x04 0x8001 0x00 0x00 0x00 0x05 0x04>;
+        #interrupt-cells = <0x01>;
+        ranges = <0x1000000 0x00 0x00 0x00 0x3eff0000 0x00 0x10000 0x2000000 0x00 0x10000000 0x00 0x10000000 0x00 0x2eff0000 0x3000000 0x80 0x00 0x80 0x00 0x80 0x00>;
+        reg = <0x40 0x10000000 0x00 0x10000000>;
+        msi-parent = <0x8002>;
+        dma-coherent;
+        bus-range = <0x00 0xff>;
+        linux,pci-domain = <0x00>;
+        #size-cells = <0x02>;
+        #address-cells = <0x03>;
+        device_type = "pci";
+        compatible = "pci-host-ecam-generic";
+    };
+
+    pl031@9010000 {
+        clock-names = "apb_pclk";
+        clocks = <0x8000>;
+        interrupts = <0x00 0x02 0x04>;
+        reg = <0x00 0x9010000 0x00 0x1000>;
+        compatible = "arm,pl031\0arm,primecell";
+    };
+
+    pl011@9000000 {
+        clock-names = "uartclk\0apb_pclk";
+        clocks = <0x8000 0x8000>;
+        interrupts = <0x00 0x01 0x04>;
+        reg = <0x00 0x9000000 0x00 0x1000>;
+        compatible = "arm,pl011\0arm,primecell";
+    };
+
+    pmu {
+        interrupts = <0x01 0x07 0x704>;
+        compatible = "arm,armv8-pmuv3";
+    };
+
+    intc@8000000 {
+        phandle = <0x8001>;
+        reg = <0x00 0x8000000 0x00 0x10000 0x00 0x8010000 0x00 0x10000>;
+        compatible = "arm,cortex-a15-gic";
+        ranges;
+        #size-cells = <0x02>;
+        #address-cells = <0x02>;
+        interrupt-controller;
+        #interrupt-cells = <0x03>;
+
+        v2m@8020000 {
+            phandle = <0x8002>;
+            reg = <0x00 0x8020000 0x00 0x1000>;
+            msi-controller;
+            compatible = "arm,gic-v2m-frame";
+        };
+    };
+
+    flash@0 {
+        bank-width = <0x04>;
+        reg = <0x00 0x00 0x00 0x4000000 0x00 0x4000000 0x00 0x4000000>;
+        compatible = "cfi-flash";
+    };
+
+    cpus {
+        #size-cells = <0x00>;
+        #address-cells = <0x01>;
+
+        cpu@0 {
+            reg = <0x00>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+
+        cpu@1 {
+            reg = <0x01>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+
+        cpu@2 {
+            reg = <0x02>;
+            enable-method = "psci";
+            compatible = "arm,cortex-a72";
+            device_type = "cpu";
+        };
+    };
+
+    timer {
+        interrupts = <0x01 0x0d 0x704 0x01 0x0e 0x704 0x01 0x0b 0x704 0x01 0x0a 0x704>;
+        always-on;
+        compatible = "arm,armv8-timer\0arm,armv7-timer";
+    };
+
+    apb-pclk {
+        phandle = <0x8000>;
+        clock-output-names = "clk24mhz";
+        clock-frequency = <0x16e3600>;
+        #clock-cells = <0x00>;
+        compatible = "fixed-clock";
+    };
+
+    chosen {
+        bootargs = "rootwait root=/dev/vda rw console=ttyAMA0";
+        stdout-path = "/pl011@9000000";
+    };
+
+  iamroot {
+    compatible = "iamroot_comp";
+    memory-region = <&iamroot_buffer>;
+  };
+
+  reserved-memory {
+      #address-cells = <2>;
+      #size-cells = <2>;
+      ranges;
+
+      iamroot_buffer: iamroot_buffer@0 {
+          compatible = "shared-dma-pool";
+          size = <0x00000000 0x08000000>;
+          linux,cma-default;
+      reusable;
+      };
+  };
+};
diff --git a/iamroot18/example/module_Makefile_example b/iamroot18/example/module_Makefile_example
new file mode 100644
index 000000000000..a844d473c5c0
--- /dev/null
+++ b/iamroot18/example/module_Makefile_example
@@ -0,0 +1,8 @@
+obj-m += hello.o
+KERNEL := /home/kkr/main/iamroot/5.15/
+CROSS := aarch64-linux-gnu-
+
+all:
+    $(MAKE) ARCH=arm64 CROSS_COMPILE=$(CROSS) -C $(KERNEL) M=$(shell pwd)  modules
+clean:
+    $(MAKE) -C $(KERNEL) M=$(shell pwd) clean
diff --git a/iamroot18/example/run3.sh b/iamroot18/example/run3.sh
new file mode 100755
index 000000000000..aeeaf5debc66
--- /dev/null
+++ b/iamroot18/example/run3.sh
@@ -0,0 +1,22 @@
+sudo qemu-system-aarch64                 \
+    -M virt                         \
+    -dtb ./abc.dtb                \
+    -cpu cortex-a72                          \
+    -nographic                         \
+    -smp 3                             \
+    -m 4096                            \
+    -kernel //home/kkr/main/iamroot/qemu/img/dma_Image     \
+    -append "rootwait root=/dev/vda rw console=ttyAMA0"     \
+    -device virtio-net-device,netdev=mynet1 \
+    -netdev tap,id=mynet1,ifname=tap0,script=no,downscript=no \
+    -device virtio-blk-device,drive=disk \
+    -drive if=none,id=disk,file=/dev/sdd,format=raw
+
+#-M virt,dumpdtb=abc.dtb                         \
+#if=none,format=raw,id=disk                 \
+#-device virtio-net-device,netdev=eth0              \
+#-device virtio-blk-device,drive=disk
+#-drive file=/home/kkr/main/iamroot/qemu/rfs/buildroot/output/images/rootfs.ext4,
+#if=none,format=raw,id=hd0                 
+#-device virtio-blk-device,drive=hd0
+#-enable-kvm                     
diff --git a/iamroot18/hello/hello.c b/iamroot18/hello/hello.c
new file mode 100644
index 000000000000..5a57f6eabef4
--- /dev/null
+++ b/iamroot18/hello/hello.c
@@ -0,0 +1,17 @@
+#include <linux/init.h>
+#include <linux/module.h>
+
+static int hello_init(void) {
+    printk(KERN_INFO "Hello world.\n");
+    return 0;
+}
+
+static void hello_exit(void) {
+    printk(KERN_INFO "Goodbye world.\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
diff --git a/iamroot18/kmalloc/hello.c b/iamroot18/kmalloc/hello.c
new file mode 100644
index 000000000000..2ecd73662368
--- /dev/null
+++ b/iamroot18/kmalloc/hello.c
@@ -0,0 +1,61 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+/*
+ * IAMROOT, 2022.07.30:
+ * - slab cache에서 할당해온다. slabtop -sa 명령어 등으로 할당을
+ *   확인할 수 있다.
+ */
+#define CNT    10000
+//static struct page *arr[CNT];
+static void *arr[CNT];
+
+static int hello_init(void) {
+    uint32_t i;
+#define ALLOC_BYTES    (4 * 1024)
+    //int order = get_order(ALLOC_BYTES);
+
+    printk(KERN_INFO "alloc : %u byte. order %d. cnt %u\n",
+            ALLOC_BYTES, -1, CNT);
+    for (i = 0; i < CNT; i++) {
+        if (arr[i])
+            continue;
+#if 0
+        arr[i] = alloc_pages(GFP_KERNEL, order);
+#else
+        arr[i] = kmalloc(ALLOC_BYTES, GFP_KERNEL);
+#endif
+        if (arr[i] == NULL)
+        {
+            printk(KERN_INFO "%d alloc fail.\n", i);
+        }
+    }
+#if 0
+    uint8_t *data = page_address(arr[0]);
+    memset(data, 0, ALLOCn);
+#endif
+    return 0;
+}
+
+static void hello_exit(void) {
+    uint32_t i;
+    //int order = get_order(ALLOC_BYTES);
+
+    for (i = 0; i < CNT; i++) {
+        if (arr[i] == NULL)
+            continue;
+#if 0
+        __free_pages(arr[i], order);
+#else
+        kfree(arr[i]);
+#endif
+        arr[i] = NULL;
+    }
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
diff --git a/iamroot18/kmemcache/hello.c b/iamroot18/kmemcache/hello.c
new file mode 100644
index 000000000000..33a36ed9f15a
--- /dev/null
+++ b/iamroot18/kmemcache/hello.c
@@ -0,0 +1,100 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+
+static struct kmem_cache * g_cache;
+static struct kmem_cache * g_cache2;
+
+#define CNT    100
+#define CNT2    50
+#define ALLOC_BYTES    (832)
+#define ALLOC_BYTES2    (798)
+
+static void *arr[CNT];
+static void *arr2[CNT];
+
+/*
+ * IAMROOT, 2022.07.30:
+ * - 직접 slab cache를 생성한다.
+ * - unmerged가 아니면(보통의 경우이면) :xxxx.. 로 unique id를 가진
+ *   slab cache가 생기고 거기에 link되는 식으로 만들어진다.
+ * - /sys/kernel/slab/iamroot_cache 에 생성된다.
+ */
+static int hello_init(void) {
+    uint32_t i;
+
+    if (g_cache == NULL)
+    {
+/*
+ * IAMROOT, 2022.07.30:
+ * - align은 방식은 보통3가지 방식을 쓴다.
+ *   1. 0. 최소 size(long size)로 align
+ *   2. size랑 똑같게한다.
+ *   3. 0을 쓰고 flag로 SLAB_HWCACHE_ALIGN. cache align.
+ */
+        g_cache = kmem_cache_create("iamroot_cache", ALLOC_BYTES, 0,
+                SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
+        g_cache2 = kmem_cache_create("iamroot_cache2", ALLOC_BYTES2, 0,
+                SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
+    }
+
+    printk(KERN_INFO "alloc : %u byte. cnt %u\n", ALLOC_BYTES, CNT);
+    for (i = 0; i < CNT; i++) {
+        if (arr[i])
+            continue;
+        arr[i] = kmem_cache_alloc(g_cache, GFP_KERNEL);
+        if (arr[i] == NULL)
+        {
+            printk(KERN_INFO "%d alloc fail.\n", i);
+        }
+    }
+
+    for (i = 0; i < CNT2; i++) {
+        if (arr2[i])
+            continue;
+        arr2[i] = kmem_cache_alloc(g_cache2, GFP_KERNEL);
+        if (arr2[i] == NULL)
+        {
+            printk(KERN_INFO "%d alloc fail.\n", i);
+        }
+    }
+#if 0
+    uint8_t *data = page_address(arr[0]);
+    memset(data, 0, ALLOCn);
+#endif
+    return 0;
+}
+
+static void hello_exit(void) {
+    uint32_t i;
+    //int order = get_order(ALLOC_BYTES);
+
+    for (i = 0; i < CNT; i++) {
+        if (arr[i] == NULL)
+            continue;
+        kmem_cache_free(g_cache, arr[i]);
+        arr[i] = NULL;
+    }
+
+    for (i = 0; i < CNT2; i++) {
+        if (arr2[i] == NULL)
+            continue;
+        kmem_cache_free(g_cache2, arr2[i]);
+        arr2[i] = NULL;
+    }
+
+    if(g_cache)
+    {
+        kmem_cache_destroy(g_cache);
+        kmem_cache_destroy(g_cache2);
+        g_cache = NULL;
+        g_cache2 = NULL;
+    }
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
diff --git a/iamroot18/kmemcache_debug/hello.c b/iamroot18/kmemcache_debug/hello.c
new file mode 100644
index 000000000000..da02878b9708
--- /dev/null
+++ b/iamroot18/kmemcache_debug/hello.c
@@ -0,0 +1,64 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+
+static struct kmem_cache * g_cache;
+
+#define ALLOC_BYTES    (10)
+//#define DOUBLE_FREE
+//#define OVERWRITE_LEFT
+//#define OVERWRITE_RIGHT
+//#define OVERWRITE_RIGHT2
+#define POISON_TEST
+
+
+static uint8_t *arr;
+
+static int hello_init(void) {
+    if (g_cache == NULL)
+    {
+        g_cache = kmem_cache_create("iamroot_cache", ALLOC_BYTES, 0,
+                SLAB_HWCACHE_ALIGN, NULL);
+    }
+
+    arr = kmem_cache_alloc(g_cache, GFP_KERNEL);
+#ifdef OVERWRITE_LEFT
+    memset(arr - 1, 0x1, 1);
+#endif
+
+#ifdef OVERWRITE_RIGHT
+    memset(&arr[ALLOC_BYTES], 0x1, 1);
+#endif
+
+#ifdef OVERWRITE_RIGHT2
+    memset(&arr[ALLOC_BYTES+7], 0x1, 1);
+#endif
+
+#ifdef POISON_TEST
+    kmem_cache_free(g_cache, arr);
+    memset(arr, 1, 1);
+    arr = kmem_cache_alloc(g_cache, GFP_KERNEL);
+#endif
+    return 0;
+}
+
+static void hello_exit(void) {
+
+    kmem_cache_free(g_cache, arr);
+#ifdef DOUBLE_FREE
+    kmem_cache_free(g_cache, arr);
+#endif
+
+    if(g_cache)
+    {
+        kmem_cache_destroy(g_cache);
+        g_cache = NULL;
+    }
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
diff --git a/iamroot18/vmalloc/hello.c b/iamroot18/vmalloc/hello.c
new file mode 100644
index 000000000000..fb9cbf9eda8a
--- /dev/null
+++ b/iamroot18/vmalloc/hello.c
@@ -0,0 +1,56 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+
+#define CNT    100
+static void *arr[CNT];
+
+static int hello_init(void) {
+    uint32_t i;
+#define ALLOC_BYTES    (4 * 1024 * 1024)
+    //int order = get_order(ALLOC_BYTES);
+
+    printk(KERN_INFO "alloc : %u byte. order %d. cnt %u\n",
+            ALLOC_BYTES, -1, CNT);
+    for (i = 0; i < CNT; i++) {
+        if (arr[i])
+            continue;
+#if 0
+        arr[i] = alloc_pages(GFP_KERNEL, order);
+#else
+        arr[i] = vmalloc(ALLOC_BYTES);
+#endif
+        if (arr[i] == NULL)
+        {
+            printk(KERN_INFO "%d alloc fail.\n", i);
+        }
+    }
+#if 0
+    uint8_t *data = page_address(arr[0]);
+    memset(data, 0, ALLOCn);
+#endif
+    return 0;
+}
+
+static void hello_exit(void) {
+    uint32_t i;
+    //int order = get_order(ALLOC_BYTES);
+
+    for (i = 0; i < CNT; i++) {
+        if (arr[i] == NULL)
+            continue;
+#if 0
+        __free_pages(arr[i], order);
+#else
+        vfree(arr[i]);
+#endif
+        arr[i] = NULL;
+    }
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("kkr");
+
 

번호 제목 글쓴이 날짜 조회 수
공지 [공지] 스터디 정리 노트 공간입니다. woos 2016.05.14 626
148 [커널 17차] 103주차 ㅇㅇㅇ 2022.08.28 35
147 [커널 18차] 66주차 kkr 2022.08.27 76
146 [커널 17차] 101~102주차 ㅇㅇㅇ 2022.08.21 47
145 [커널 18차] 65주차 kkr 2022.08.20 28
144 [커널 18차] 64주차 kkr 2022.08.13 75
143 [커널 17차] 100주차 [1] ㅇㅇㅇ 2022.08.06 100
142 [커널 18차] 63주차 kkr 2022.08.06 102
141 [커널 17차] 99주차 ㅇㅇㅇ 2022.07.31 35
» [커널 18차] 62주차 kkr 2022.07.30 26
139 [커널 17차] 97~98주차 ㅇㅇㅇ 2022.07.24 52
138 [커널 18차] 61주차 kkr 2022.07.23 113
137 [커널 18차] 60주차 kkr 2022.07.16 129
136 [커널 17차] 95~96주차 ㅇㅇㅇ 2022.07.10 105
135 [커널 18차] 59주차 kkr 2022.07.09 126
134 [커널 19차] 8주차 kanlee 2022.07.02 160
133 [커널 19차] 7주차 kanlee 2022.07.02 95
132 [커널 19차] 6주차 kanlee 2022.07.02 42
131 [커널 19차] 5주차 kanlee 2022.07.02 38
130 [커널 19차] 4주차 kanlee 2022.07.02 106
129 [커널 18차] 57주차 kkr 2022.06.25 129
XE Login