UTM size

196 views
Skip to first unread message

Mriganka Chakravarty

unread,
Dec 20, 2020, 9:58:42 AM12/20/20
to Keystone Enclave Forum
Hello,
I am trying to increase the size of the untrusted memory(around a GB). Could you please help me.
I tried increasing it here, but I end up getting a segment fault.

Thank you.

Paul Heath

unread,
Dec 20, 2020, 4:31:34 PM12/20/20
to Mriganka Chakravarty, Keystone Enclave Forum
Just had this discussion last week with Dayeol.
There is about a two meg limit on that space due to the allocation method used. I had to break stuff into chunks to get all I needed into the enclave.

--
You received this message because you are subscribed to the Google Groups "Keystone Enclave Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keystone-enclave-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keystone-enclave-forum/770e7869-37fd-4052-800d-b50a31b74a7cn%40googlegroups.com.

Dayeol Lee

unread,
Dec 20, 2020, 5:51:45 PM12/20/20
to Paul Heath, Mriganka Chakravarty, Keystone Enclave Forum
Thanks Paul!

Yes, UTM allocation is relying on the buddy allocator, so 2MB is possibly the largest you can expect.
We may need some better error handling on the library side such that the kernel does not print out error messages when it fails to allocate.

Thanks!

Mriganka Chakravarty

unread,
Dec 21, 2020, 2:17:20 AM12/21/20
to Keystone Enclave Forum
Is there any workaround to this limitation? I want to get around ocalls for a faster transfer :(

Dayeol Lee

unread,
Dec 21, 2020, 3:33:24 PM12/21/20
to Mriganka Chakravarty, Keystone Enclave Forum
To hack this around, you can modify the driver to use CMA for the UTM as well. 
Use `dma_alloc_coherent` (as in keystone-page.c:52) instead of `__get_free_pages` (as in keystone-page.c:101)
Note that even with that, your total allocation cannot exceed the total CMA reservation (see Linux config. probably it's about 1GB in our default config).

Hope that helps!

Dayeol

Dayeol Lee

unread,
Dec 21, 2020, 3:39:59 PM12/21/20
to Mriganka Chakravarty, Keystone Enclave Forum
Sorry, I missed how UTM is handled in the security monitor.
The method I described won't work because the UTM should be always be naturally aligned to the power of two.
This is because we are handling UTM by using only the last PMP register (NAPOT encoding).
Because of that, I think having a larger UTM is not as trivial as I described.

How critical is it to have a large UTM for your transfer performance?
I think context switch is pretty cheap so switching every 2MB sounds not much of a problem to me.

Mriganka Chakravarty

unread,
Dec 22, 2020, 3:40:39 AM12/22/20
to Keystone Enclave Forum
I tried CMA. With CMA i am getting around 64 MB, after which the seg fault comes in. Its not mission critical, I am a student and kinda on an exploratory path. :)

Dayeol Lee

unread,
Dec 23, 2020, 2:24:27 AM12/23/20
to Keystone Enclave Forum
I'd just stick to 2MB buffer, if it's not critical.
Anything larger than 2MB allocated by CMA could be unaligned, which may cause an undefined behavior (or probably fail).

rajesh sarvapalli

unread,
Dec 24, 2020, 6:04:38 AM12/24/20
to Keystone Enclave Forum
Hey, I am facing the same situation.  dma_alloc_coherent returns me allocated memory, but  i am getting segmentation fault here: https://github.com/keystone-enclave/keystone-sdk/blob/5e4592cb1e50c731d6937ef5aba632c672ec2a6f/lib/host/src/keystone.cpp#L91

It looks like the page table runs out of pages, i guess.


Error Log: https://pastebin.com/6R9eWjH5 (I dont understand why am i getting segF at 0x0..0147)
Any help would be highly appreciated.
Thanks

rajesh sarvapalli

unread,
Jan 2, 2021, 4:28:52 AM1/2/21
to Keystone Enclave Forum
Hello friends. I am sorry to bug, but I really need to increase the UTM size for a research work that I am doing. Please help me if possible. I am very close to getting positive results, and am stuck at this for like a month.
Thank you.

Dayeol Lee

unread,
Jan 2, 2021, 5:57:00 PM1/2/21
to rajesh sarvapalli, Keystone Enclave Forum
This seems to be really old SDK, so could you please try the latest version?
Also, what did you change? it's hard to tell by just looking at your error log.

rajesh sarvapalli

unread,
Jan 3, 2021, 10:15:52 AM1/3/21
to Keystone Enclave Forum
Hi.

The exact problem is a seg-fault at this faulting line:
Control reaches the above line via  Keystone::init()----->loadUntrusted()----> allocPage()--->faulting line.
The fault occurs as __ept_walk_create() returns wrong pte_t* which basically contains the bad-address.

It occurs to me that it could be solved by increasing the space allocated to epm_free_list, but I might be very wrong.
If the solution to the problem comes at the cost of performance, then also its fine.



Changes I did are :-

In linux-keystone-driver/keystone-page.c

Instead of:
utm->ptr = (void*) __get_free_pages(GFP_HIGHUSER, order);

I used:
if (order <= MAX_ORDER)
    utm->ptr = (void*) __get_free_pages(GFP_HIGHUSER, order);
if (!utm->ptr) {
    printk(KERN_INFO "[driver] Buddy Allocator for UTM failed\n");
    #ifdef CONFIG_CMA
        utm->ptr = (void *) dma_alloc_coherent(keystone_dev.this_device,
                                                                    count << PAGE_SHIFT,
                                                                    &device_phys_addr,
                                                                    GFP_KERNEL | __GFP_DMA32);
        if(!device_phys_addr)
            return -ENOMEM;
    #endif
    if(!utm->ptr)
        return -ENOMEM;
}
printk(KERN_INFO "[driver] UTM INIT successful\n");      //I get this print, so I have memory


In test-runner.cpp
I have used:
params.setUntrustedSize(32*1024*(4096));


Please suggest possible solutions.
Thank you.

rajesh sarvapalli

unread,
Jan 3, 2021, 10:22:42 AM1/3/21
to Keystone Enclave Forum
Also, I did the same with the recent sdk, but got the same seg-fault again.

PS:  In the previous post, device_phys_addr is a local var, phys_addr_t device_phys_addr;

Paul Heath

unread,
Jan 6, 2021, 11:58:18 AM1/6/21
to Keystone Enclave Forum
I have tried to overcome the UTM size limit by breaking items up into chunks and sending them over one at a time, rebuilding 
things on the enclave side when the transfer process is completed. If this would be useful, I could repackage it a bit and 
share the code to anyone who could use it. My current code only needs matrices of doubles, but I will need to make changes 
to allow generic blobs of bytes. Let me know if this would be useful to anyone . 

Paul 

Reply all
Reply to author
Forward
0 new messages