From: weiming Subject: Re: Is it possible to make hypercall from user application directly? Date: Tue, 11 Mar 2008 21:42:23 -0500 Message-ID: References: <1205265056.6230.6.camel@thinkpad.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1160213691==" Return-path: In-Reply-To: <1205265056.6230.6.camel@thinkpad.localdomain> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Daniel Stodden Cc: xen-devel List-Id: xen-devel@lists.xenproject.org --===============1160213691== Content-Type: multipart/alternative; boundary="----=_Part_4492_15753704.1205289743798" ------=_Part_4492_15753704.1205289743798 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline After some study, I got the following understanding. Please correct me if I'm wrong; otherwise, you can just say "correct". 1. In x86_64 mode, xen sets the LSTAR (the EIP of syscall target), and this value keeps constant. This value is code of "syscall_enter" defined in xen/arch/x86/x86_64/entry.S 2. In ENTRY(syscall_enter) ... ... testb $TF_kernel_mode, VCPU_thread_flag(%rbx) jz switch_to_kernel /*hypercall*/ ... so whenever a syscall is issued, "syscall_enter" checks the context. If it decides that the context is "kernel mode", it will treat the syscall as a plain "system call" from user applications. So it goes to "jz switch_to_kernel". Otherwise, it will think it's a hypercall issued from guest domains. 3. So an application can't make "hypercalls" directly because it's context is "kernel mode", so it will always be treated as a system call to the gues= t OS. Am I right? Thanks, Weiming On Tue, Mar 11, 2008 at 2:50 PM, Daniel Stodden wrote: > On Tue, 2008-03-11 at 12:13 -0500, weiming wrote: > > Hi, > > > > I implemented my own Hypercall in xen. > > > > Now I wish my application under dom0 could talk to Xen via my > > hypercall. > > Currently, I make a stub in dom0's kernel, which works as a proxy to > > forward the request. So, my application first makes a system call to > > dom0, which then makes hypercall to xen. > > > > Is this design necessary? May I call hypercalls from user application > > under dom0 directly? > > No, not directly (didn't we have that syscall conversation recently? ;). > > But for dom0-only privileged operations there's /proc/xen/privcmd to > rule them all. See e.g. do_xen_hypercall() in tools/libxc/. > > regards, > Daniel > > -- > Daniel Stodden > LRR - Lehrstuhl f=FCr Rechnertechnik und Rechnerorganisation > Institut f=FCr Informatik der TU M=FCnchen D-85748 Garching > http://www.lrr.in.tum.de/~stodden > mailto:stodden@cs.tum.edu > PGP Fingerprint: F5A4 1575 4C56 E26A 0B33 3D80 457E 82AE B0D8 735B > > > ------=_Part_4492_15753704.1205289743798 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline After some study, I got the following understanding. Please correct me if I= 'm wrong; otherwise, you can just say "correct".

1. In= x86_64 mode, xen sets the LSTAR (the EIP of syscall target), and this valu= e keeps constant. This value is code of "syscall_enter" defined i= n xen/arch/x86/x86_64/entry.S

2.
In ENTRY(syscall_enter)
...
...
testb $TF_kernel_mode, VCPU_thread_flag(%rbx)
jz switch_to_kernel

/*hypercall*/
...

so whenever a syscall is issued, "syscall_= enter" checks the context. If it decides that the context is "ker= nel mode", it will treat the syscall as a  plain "system cal= l" from user applications. So it goes to "jz switch_to_kernel&quo= t;. Otherwise, it will think it's a hypercall issued from guest domains= .

3. So an application can't make "hypercalls" directly bec= ause it's context is "kernel mode", so it will always be trea= ted as a system call to the guest OS.

Am I right?

Thanks,
Weiming

On Tue, Mar 11, 2008 at 2:50 PM, = Daniel Stodden <stodden@cs.tum.edu= > wrote:
On Tue, 2008-03-11 at 12:13 -0500, we= iming wrote:
> Hi,
>
> I implemented my own Hypercall in xen.
>
> Now I wish my application under dom0 could talk to Xen via my
> hypercall.
> Currently, I make a stub in dom0's kernel, which works as a proxy = to
> forward the request. So, my application first makes a system call to > dom0, which then makes hypercall to xen.
>
> Is this design necessary? May I call hypercalls from user application<= br> > under dom0 directly?

No, not directly (didn't we have that syscall conversation = recently? ;).

But for dom0-only privileged operations there's /proc/xen/privcmd to rule them all. See e.g. do_xen_hypercall() in tools/libxc/.

regards,
Daniel

--
Daniel Stodden
LRR     -      Lehrstuhl f=FCr Rechnertechnik und = Rechnerorganisation
Institut f=FCr Informatik der TU M=FCnchen         &nbs= p;   D-85748 Garching
http://ww= w.lrr.in.tum.de/~stodden         mailto:stodden@cs.tum.edu
PGP Fingerprint: F5A4 1575 4C56 E26A 0B33  3D80 457E 82AE B0D8 735B


------=_Part_4492_15753704.1205289743798-- --===============1160213691== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1160213691==--