All of lore.kernel.org
 help / color / mirror / Atom feed
* [ARM] Native application design and discussion (I hope)
@ 2017-04-06 20:21 Volodymyr Babchuk
  2017-04-06 21:31 ` Stefano Stabellini
  0 siblings, 1 reply; 78+ messages in thread
From: Volodymyr Babchuk @ 2017-04-06 20:21 UTC (permalink / raw)
  To: Xen Devel, Artem Mygaiev, Julien Grall, Stefano Stabellini

Hello all,

I want to discuss EL0 (native) applications for XEN. This will be relatively
long e-mail with requirements, proposed design and my PoC results.

So, why we want XEN native applications in the first place? I see the following
reasons:

1. Isolation. I see XEN as a sort of micro-kernel, so there are no place for
device drivers, emulators, specific SMC handlers, hypervisor extension, etc..

2. Modularity. Just look at Linux kernel. Obviously, for different devices we
can load different drivers.

3. Performance. Native application should be faster than stub domain, or there
will be no sense in it.

4. Ease of use. I want to make call to EL0 app as easy as possible.
Ideally - as a function call.

Actually, no one wants extra code in hypervisor, so reasons (1) and (2) are most
important. I know that there was tries to do such thing in x86 but with
different approach. I want describe my idea for arm64.

Native application is an another domain type. It has own vCPU (only one at this
moment) Native app is loaded as any other kernel, using ELF loader.
It looks like another stub-domain such as MiniOS, but there are two big
differences:

1. MiniOS has event loop that serves requests from hypervisor. Native
application does not has such loop. It has one entry point where you jump every
time when you need something from it.

2. Native application runs in EL0 mode, so it does not have access to MMU,
it can't handle vIQRs, exceptions and so on. XEN does all this for it.

You can find example native application at [1]. I used exactly this one to
benchmark my implementation. Mostly it is inspired by approach used in TEE.
Actually, I took some code directly from OP-TEE Trusted Application library.
In app_entry.c you can find entry point - __app_entry(). It takes function
number and some parameters that will be passed to a function. I probably going
to change ABI a bit, but basic idea will be the same.

Function number will be something like APP_INIT, APP_HANDLE_SMC
or APP_HANDLE_MMIO... I think you got the idea. I also implemented two syscalls
(via old plain SVC instruction). app_log() writes to XEN log, app_return() exits
from application back to hypervisor. We will need other syscalls like
app_call_smc(), app_map_guest_page(), app_map_io(), etc.

Now, back to XEN. Classic way to handle something with stubdomain is to
write request to a ring buffer, fire an event through event channel, that will
trigger vIRQ in stubdomain and stubdomain's vCPU will be scheduled to handle
a request. Problem it that you can't control scheduler, so you don't know
when your request will be really handled, which in not fine in some
embedded use cases.

There is how I see handling requests with native application:

0. Hypervisor pauses requester vCPU
1. Hypervisor either passes parameters via registers or writes request to a
shared page/ring buffer.
2. Then in sets PC of native app vCPU to entry point and initializes r0-r7
with function code and other parameters.
3. Hypervisor switches context to native app vCPU
4. When native app finishes request handling it calls special syscall app_exit()
5. Hypervisor analyses return code, updates requester vCPU state (if needed),
switches back to that vCPU, unpauses it.

Most of that was done at [2]. Most interesting part is in arch/arm/domain.c
There are functions call_el0_app() and return_from_el0_app() that do most
of the work. Also I have added syscalls handlers (in the same way,
as hypercalls are handled). You can find them at xen/arch/arm/syscall.c

At this moment entry point is hardcoded and you need to update it every time
you rebuild native application. Also there are no actual parameters passed.
Also, whole code is a piece of gosa, because it was first time I hacked XEN.

I don't want to repeat benchmark results, because they already was posted in ML.
You can find them at [3].

I understand that I have missed many things:

1. How to ship and load native app, because some of them will be needed even
before dom0 is created.

2. How to distinguish multiple native apps

3. Concurrency in native apps

4. How to restart misbehaved apps.

But at this moment I want to discuss basic approach. If there are will be no
objections against basic concept, then we can develop details.

[1] https://github.com/lorc/xen_app_stub - native app
[2] https://github.com/lorc/xen/tree/el0_app - my branch with PoC
[3] http://marc.info/?l=xen-devel&m=149088856116797&w=2 - benchmark results


-- 
WBR Volodymyr Babchuk aka lorc [+380976646013]
mailto: vlad.babchuk@gmail.com

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2017-05-15 17:32 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-06 20:21 [ARM] Native application design and discussion (I hope) Volodymyr Babchuk
2017-04-06 21:31 ` Stefano Stabellini
2017-04-07 11:03   ` Volodymyr Babchuk
2017-04-07 23:36     ` Stefano Stabellini
2017-04-11 20:32       ` Stefano Stabellini
2017-04-12 18:13         ` Dario Faggioli
2017-04-12 19:17           ` Stefano Stabellini
2017-04-20 20:20             ` Volodymyr Babchuk
2017-04-21 14:42               ` Andrii Anisov
2017-04-21 15:49                 ` Julien Grall
2017-04-21 16:08                   ` Volodymyr Babchuk
2017-04-21 16:20                   ` Andrii Anisov
2017-04-21 20:58                 ` Stefano Stabellini
2017-04-21 21:17                   ` Stefano Stabellini
2017-04-24 16:56                   ` Andrii Anisov
2017-04-24 18:08                     ` Stefano Stabellini
2017-04-25 10:15                       ` Andrii Anisov
2017-05-05 10:51                       ` Andrii Anisov
2017-05-05 19:28                         ` Stefano Stabellini
2017-05-08 10:46                           ` George Dunlap
2017-05-08 18:31                             ` Stefano Stabellini
2017-05-08 18:33                               ` Julien Grall
2017-05-09  8:53                               ` George Dunlap
2017-05-10 16:38                                 ` Andrii Anisov
2017-05-09 10:13                           ` Dario Faggioli
2017-05-09 10:32                             ` Julien Grall
2017-05-09 11:08                               ` Dario Faggioli
2017-05-09 11:19                                 ` Julien Grall
2017-05-09 18:29                                 ` Stefano Stabellini
2017-05-10  9:56                                   ` George Dunlap
2017-05-10 10:00                                     ` Julien Grall
2017-05-10 10:03                                       ` George Dunlap
2017-05-10 10:48                                         ` Julien Grall
2017-05-10 17:37                                           ` Volodymyr Babchuk
2017-05-10 18:05                                             ` Stefano Stabellini
2017-05-10 19:04                                             ` Julien Grall
2017-05-11 10:07                                               ` Julien Grall
2017-05-11 11:28                                                 ` Volodymyr Babchuk
2017-05-10 18:08                                     ` Andrii Anisov
2017-05-10 18:24                                       ` Stefano Stabellini
2017-05-11 15:19                                         ` Volodymyr Babchuk
2017-05-11 15:35                                           ` Modules support in Xen (WAS: Re: [ARM] Native application design and discussion (I hope)) Julien Grall
2017-05-11 16:35                                             ` George Dunlap
2017-05-11 17:14                                               ` Volodymyr Babchuk
2017-05-11 17:20                                                 ` George Dunlap
2017-05-11 17:53                                                   ` Lars Kurth
2017-05-11 17:14                                             ` George Dunlap
2017-05-11 17:16                                               ` George Dunlap
2017-05-11 18:13                                               ` Volodymyr Babchuk
2017-05-12 11:48                                                 ` George Dunlap
2017-05-12 18:43                                                   ` Stefano Stabellini
2017-05-12 19:04                                                     ` Volodymyr Babchuk
2017-05-15 11:21                                                       ` George Dunlap
2017-05-15 17:32                                                         ` Stefano Stabellini
2017-05-11 18:04                                             ` Stefano Stabellini
2017-05-11 18:39                                               ` Volodymyr Babchuk
2017-05-05 11:09                       ` [ARM] Native application design and discussion (I hope) Andrii Anisov
2017-04-24 19:11                     ` Julien Grall
2017-04-24 21:41                       ` Volodymyr Babchuk
2017-04-25 11:43                         ` Julien Grall
2017-04-26 21:44                           ` Volodymyr Babchuk
2017-04-27 17:26                             ` Volodymyr Babchuk
2017-05-02 12:52                               ` Julien Grall
2017-05-02 12:42                             ` Julien Grall
2017-04-25  8:52                       ` Andrii Anisov
2017-04-21 15:57               ` Julien Grall
2017-04-21 16:16                 ` Volodymyr Babchuk
2017-04-21 16:47                   ` Julien Grall
2017-04-21 17:04                     ` Volodymyr Babchuk
2017-04-21 17:38                       ` Julien Grall
2017-04-21 18:35                         ` Volodymyr Babchuk
2017-04-24 11:00                           ` Julien Grall
2017-04-24 21:29                             ` Volodymyr Babchuk
2017-04-21 21:24                         ` Stefano Stabellini
2017-04-24 16:14                           ` Andrii Anisov
2017-04-24 16:46                           ` Andrii Anisov
2017-04-27 15:25                           ` George Dunlap
2017-05-02 12:45                             ` Julien Grall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.