From 5ca27fa0d547c659093c5a84aefefdb6e05331b7 Mon Sep 17 00:00:00 2001 From: Dayeol Lee Date: Tue, 29 Jan 2019 19:16:37 +0000 Subject: [PATCH 1/8] Enable CMA in the kernel and the driver Keystone driver will try to allocate from contiguous CMA memory instead of buddy allocation system. This will allow the driver to successfully allocate a larger enclave memory which could be several gigabytes. --- linux-keystone-driver | 2 +- patches/linux-cma.patch | 76 +++++++++++++++++++++++++++++++++++++++++ scripts/apply-patch.sh | 8 ++++- 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 patches/linux-cma.patch diff --git a/linux-keystone-driver b/linux-keystone-driver index 4f8e0ea15..56de11a76 160000 --- a/linux-keystone-driver +++ b/linux-keystone-driver @@ -1 +1 @@ -Subproject commit 4f8e0ea159b8e76a33c53b72b2921d592bb93076 +Subproject commit 56de11a7675c71b3437287f9dab89e1661785120 diff --git a/patches/linux-cma.patch b/patches/linux-cma.patch new file mode 100644 index 000000000..7c8a5328f --- /dev/null +++ b/patches/linux-cma.patch @@ -0,0 +1,76 @@ +diff --git arch/riscv/mm/dma.c arch/riscv/mm/dma.c +index 0689bb2..9fa9f11 100644 +--- arch/riscv/mm/dma.c ++++ arch/riscv/mm/dma.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -35,14 +36,41 @@ static void *dma_riscv_alloc(struct device *dev, size_t size, + gfp |= __GFP_DMA32; + } + +- return swiotlb_alloc_coherent(dev, size, dma_handle, gfp); ++ if (dev_get_cma_area(dev) && gfpflags_allow_blocking(gfp)) { ++ void* addr; ++ struct page *page; ++ page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, ++ get_order(size), gfp); ++ if (!page) ++ { ++ pr_err("Unabled to allocated from contiguous memory\n"); ++ return NULL; ++ } ++ ++ *dma_handle = phys_to_dma(dev, page_to_phys(page)); ++ addr = page_address(page); ++ memset(addr, 0, size); ++ return addr; ++ } else { ++ return swiotlb_alloc_coherent(dev, size, dma_handle, gfp); ++ } + } + + static void dma_riscv_free(struct device *dev, size_t size, + void *cpu_addr, dma_addr_t dma_addr, + unsigned long attrs) + { +- return swiotlb_free_coherent(dev, size, cpu_addr, dma_addr); ++ bool freed; ++ phys_addr_t paddr = dma_to_phys(dev, dma_addr); ++ ++ freed = dma_release_from_contiguous(dev, ++ phys_to_page(paddr), ++ size >> PAGE_SHIFT); ++ if(!freed) { ++ swiotlb_free_coherent(dev, size, cpu_addr, dma_addr); ++ } ++ ++ return; + } + + static int dma_riscv_supported(struct device *dev, u64 mask) +diff --git arch/riscv/mm/init.c arch/riscv/mm/init.c +index c77df81..312c84d 100644 +--- arch/riscv/mm/init.c ++++ arch/riscv/mm/init.c +@@ -18,6 +18,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -44,6 +45,7 @@ void __init paging_init(void) + setup_zero_page(); + local_flush_tlb_all(); + zone_sizes_init(); ++ dma_contiguous_reserve(memblock_end_of_DRAM()); + } + + void __init mem_init(void) diff --git a/scripts/apply-patch.sh b/scripts/apply-patch.sh index 68e0323a4..a515e05fe 100755 --- a/scripts/apply-patch.sh +++ b/scripts/apply-patch.sh @@ -1,3 +1,9 @@ #!/usr/bin/env bash cd riscv-qemu -patch hw/riscv/boot.c < ../patches/qemu-kernel-reloc.patch +patch --forward hw/riscv/boot.c < ../patches/qemu-kernel-reloc.patch || true +cd .. + +# linux patch +cd riscv-linux +patch -p0 --forward < ../patches/linux-cma.patch || true +cd .. From 7235583002be47d7fa2ca2ef2e38c6109ce50bad Mon Sep 17 00:00:00 2001 From: David Kohlbrenner Date: Fri, 1 Feb 2019 13:23:09 -0800 Subject: [PATCH 2/8] Bumping driver and sdk for new tiny-malloc handling and improved elf loading for applications. Now includes bss type section loading --- linux-keystone-driver | 2 +- sdk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-keystone-driver b/linux-keystone-driver index 4f8e0ea15..d461ad08d 160000 --- a/linux-keystone-driver +++ b/linux-keystone-driver @@ -1 +1 @@ -Subproject commit 4f8e0ea159b8e76a33c53b72b2921d592bb93076 +Subproject commit d461ad08d25fde855d7cb655bf505d5c5604cd6f diff --git a/sdk b/sdk index c7a0a6e7c..9eea52b3f 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit c7a0a6e7c1fb9f24c725acd1766244f80ee87487 +Subproject commit 9eea52b3fbcb4fc2a8325103714a95ae370b327e From 1b92092e0e6074883b1dc1a566baa0b3d48612fc Mon Sep 17 00:00:00 2001 From: David Kohlbrenner Date: Fri, 1 Feb 2019 16:42:44 -0800 Subject: [PATCH 3/8] added additional travis debugging information --- .travis.yml | 3 +++ scripts/travis.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 36ef6ac7d..58686b89c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,3 +65,6 @@ jobs: - source ./source.sh - travis_wait 120 make - travis_wait 10 ./scripts/travis.sh + after_failure: + - cat screenlog.0 + - cat output.log \ No newline at end of file diff --git a/scripts/travis.sh b/scripts/travis.sh index 07aee8480..5175a4650 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -1,7 +1,7 @@ #!/bin/bash # Launch QEMU test -screen -dmS qemu ./scripts/run-qemu.sh +screen -L -dmS qemu ./scripts/run-qemu.sh sleep 10 ./scripts/test-qemu.sh From 5e5c40342478e1d862ca7faef33a95715e96ac77 Mon Sep 17 00:00:00 2001 From: David Kohlbrenner Date: Fri, 1 Feb 2019 17:18:45 -0800 Subject: [PATCH 4/8] Removed attestation report printing in sdk tests and updated travis to no longer expect it --- sdk | 2 +- tests/test-qemu.expected.log | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk b/sdk index 9eea52b3f..bc11cab37 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 9eea52b3fbcb4fc2a8325103714a95ae370b327e +Subproject commit bc11cab37f25d17124d2dcc0a27ead7636e56dd7 diff --git a/tests/test-qemu.expected.log b/tests/test-qemu.expected.log index db11dd75e..151618c8f 100644 --- a/tests/test-qemu.expected.log +++ b/tests/test-qemu.expected.log @@ -20,7 +20,6 @@ Enclave said: 2nd hello world! Enclave said value: 13 Enclave said value: 20 testing attestation -{"device_pubkey": "0faad4ff01178583baa588966f7c1ff32564dd17d7dc2b46cb50a84a69270b4c", "enclave": {"data": "6e6f6e6365", "datalen": 5, "hash": "d57055329653d90d51d1cccb27aebdddbb7fb57ec233bb0e6fa252442c890578dc870b470ff2ef8b566bb2d8e426686635c5e887962e90b07e5ecfd1ce544a96", "signature": "715eb432d5a135ff99db5ebf36c879a2256ac30c748da53f4686582be8bc7350734ecfd0d546052e954b6982033412bcc5ad1ac31c6b0880072c2cb34725bd0f"}, "security_monitor": {"hash": "eae0226b42eaf3614ecf3fb1e6d3ce8854788457cacd018d9ef04de7c8d0d62504c040dc6a86b02380e459936e0ea96a4c721a0bec60351977b697ca46e7b05e", "pubkey": "40efc082defde02e3559d79b4536b602c3def2bf20515c59f189551a5c3481be", "signature": "f2acf168316d121005fc8dd3278b9740a17426a39ce6a95272ec9797a8710aa14f2cf700443b7aeddfd17f441f74f20a2d33827a4b4a04f3b6fde9ad6aa38c05"}} Attestation report SIGNATURE is valid root@ucbvax:~# poweroff root@ucbvax:~# Connection to localhost closed by remote host. From 75203c4482a4450b630ab266fd6e463032504a26 Mon Sep 17 00:00:00 2001 From: Dayeol Lee Date: Sun, 3 Feb 2019 22:57:35 +0000 Subject: [PATCH 5/8] Modify driver to have a fallback --- linux-keystone-driver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-keystone-driver b/linux-keystone-driver index 56de11a76..2f0ada172 160000 --- a/linux-keystone-driver +++ b/linux-keystone-driver @@ -1 +1 @@ -Subproject commit 56de11a7675c71b3437287f9dab89e1661785120 +Subproject commit 2f0ada172f1885ee245c52d9466dc6deee983df9 From ede1ae1312dfb2f70724bac0e86d6bce422617b5 Mon Sep 17 00:00:00 2001 From: Dayeol Lee Date: Sun, 3 Feb 2019 23:07:42 +0000 Subject: [PATCH 6/8] Bump linux driver and sdk for resolving #44 This resolves #44 --- linux-keystone-driver | 2 +- sdk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-keystone-driver b/linux-keystone-driver index d461ad08d..9c6b89010 160000 --- a/linux-keystone-driver +++ b/linux-keystone-driver @@ -1 +1 @@ -Subproject commit d461ad08d25fde855d7cb655bf505d5c5604cd6f +Subproject commit 9c6b89010f4a6e60d097d0f606f55fce816c44d8 diff --git a/sdk b/sdk index bc11cab37..29d1d040a 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit bc11cab37f25d17124d2dcc0a27ead7636e56dd7 +Subproject commit 29d1d040a174949489ef8c51248e9472a5d86b65 From 9b19707a68e4baca2e5d341617cb248d946b50b1 Mon Sep 17 00:00:00 2001 From: Dayeol Lee Date: Sun, 3 Feb 2019 23:45:46 +0000 Subject: [PATCH 7/8] Bump SDK to remove interrupt error messages --- sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk b/sdk index bc11cab37..2dbcb942d 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit bc11cab37f25d17124d2dcc0a27ead7636e56dd7 +Subproject commit 2dbcb942df8e41f916025c84ba586898c986aedd From 959f77d73098cf39ef67fb54777cd48743780f1d Mon Sep 17 00:00:00 2001 From: Dayeol Lee Date: Mon, 4 Feb 2019 05:19:43 +0000 Subject: [PATCH 8/8] Fixing unpublished submodule --- sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk b/sdk index 2dbcb942d..f73d3772c 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 2dbcb942df8e41f916025c84ba586898c986aedd +Subproject commit f73d3772cd2bbb48fa44434bbfc26ed4e9fe63cb