Skip to content

Commit

Permalink
Merge pull request #48 from keystone-enclave/dev
Browse files Browse the repository at this point in the history
Merging Dev
  • Loading branch information
dkohlbre authored Feb 7, 2019
2 parents 744a4c1 + 959f77d commit a3e54c5
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion linux-keystone-driver
76 changes: 76 additions & 0 deletions patches/linux-cma.patch
Original file line number Diff line number Diff line change
@@ -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 <linux/gfp.h>
#include <linux/mm.h>
#include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
#include <linux/scatterlist.h>
#include <linux/swiotlb.h>

@@ -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 <linux/memblock.h>
#include <linux/swap.h>
#include <linux/sizes.h>
+#include <linux/dma-contiguous.h>

#include <asm/tlbflush.h>
#include <asm/sections.h>
@@ -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)
9 changes: 8 additions & 1 deletion scripts/apply-patch.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#!/usr/bin/env bash
cd riscv-qemu
patch -p0 --forward hw/riscv/boot.c < ../patches/qemu-kernel-reloc.patch || true
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 ..

2 changes: 1 addition & 1 deletion scripts/travis.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion sdk
1 change: 0 additions & 1 deletion tests/test-qemu.expected.log
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a3e54c5

Please sign in to comment.