All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xu Zhang <xzhang54@uic.edu>
To: Samuel Thibault <samuel.thibault@ens-lyon.org>,
	Xu Zhang <xzhang@cs.uic.edu>,
	xen-devel@lists.xen.org, stefano.stabellini@eu.citrix.com,
	jeremy@goop.org, gm281@cam.ac.uk
Subject: Re: [PATCH 6/6] mini-os/x86-64 entry: check against nested events and try to fix up
Date: Tue, 12 Mar 2013 21:42:13 -0500	[thread overview]
Message-ID: <513FE785.3010207@uic.edu> (raw)
In-Reply-To: <20130309211932.GG6036@type.youpi.perso.aquilenet.fr>

On 03/09/2013 03:19 PM, Samuel Thibault wrote:
>> +		andb $KERNEL_CS_MASK,CS(%rsp)      # CS on stack might have changed
> I don't see why this.
>

Thank you for all your comments and acks. :-)

     ...
     /* Direct iret to kernel space. Correct CS and SS. */
     orb   $3,1*8(%rsp)
     orb   $3,4*8(%rsp)
1:  iretq
     ...

HYPERVISOR_IRET is part of the critical section. It could be the case 
that a nested event comes immediately after we set the lowest byte of 
on-stack CS from 0 to 3 (orb   $3,1*8(%rsp)). After invoking the fixup 
routine, we want the stack frame to be exactly the same of the original one.

One scenario this could be useful is that if mini-os had an userspace. 
If the on-stack CS had changed before nested event came and we didn't 
reset it, we could end up doing an iret with a hypercall iret, assuming 
we return to kernel with direct iret if on-stack CS is 0 (yet have to 
change it to 3 before doing so because guest kernel is in ring 3) and 
userspace with hypercall iret if 3 in x86 64bit. The scenario looks 
something like this:

  ...
  - enable events; in critical section: returning to kernel via direct 
iret (on-stack CS is 0);
  ...
  - orb   $3,1*8(%rsp): set on-stack CS to 3
  - nested event came: fixing up the stack frame;
  - go back to handle events; perform iret again; if we didn't reset 
on-stack CS to be 0 in fixup routine, we would return with a hypercall 
iret instead of a direct iret (assume if on-stack CS is 3, we return to 
userspace with hypercall iret)

In x86 64-bit mini-os, the critical section only gets executed iff 
events need to be enabled and we are returning to kernel. So does fixup 
routine. Thus it is safe to reset the lowest byte of CS to 0 in fixup 
routine.

It doesn't hurt not doing this. But I think conceptually the stack frame 
should be the same after fixing up. ;-)

Thanks,

-- 
xu

:q!

  reply	other threads:[~2013-03-13  2:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-08 21:30 [PATCH 0/6] mini-os: check and fix up against nested events in x86-64 kernel entry Xu Zhang
2013-03-08 21:30 ` [PATCH 1/6] mini-os/x86-64 entry: code clean-ups Xu Zhang
2013-03-09 20:57   ` Samuel Thibault
2013-03-08 21:30 ` [PATCH 2/6] mini-os/x86-64 entry: define macros for registers partial save and restore Xu Zhang
2013-03-09 20:55   ` Samuel Thibault
2013-03-08 21:30 ` [PATCH 3/6] mini-os/x86-64 entry: code refactoring; no functional changes Xu Zhang
2013-03-09 21:03   ` Samuel Thibault
2013-04-11  4:40     ` Xu Zhang
2013-03-08 21:30 ` [PATCH 4/6] mini-os/x86-64 entry: remove unnecessary event blocking Xu Zhang
2013-03-09 21:07   ` Samuel Thibault
2013-03-15 20:16   ` Konrad Rzeszutek Wilk
2013-04-11  4:40     ` Xu Zhang
2013-03-08 21:30 ` [PATCH 5/6] mini-os/x86-64 entry: defer RESTORE_REST until return Xu Zhang
2013-03-09 21:15   ` Samuel Thibault
2013-03-08 21:30 ` [PATCH 6/6] mini-os/x86-64 entry: check against nested events and try to fix up Xu Zhang
2013-03-09 21:19   ` Samuel Thibault
2013-03-13  2:42     ` Xu Zhang [this message]
2013-03-09 22:44   ` Jeremy Fitzhardinge
2013-03-13  2:42     ` Xu Zhang
2013-03-13  5:53       ` Xu Zhang
2013-03-14  1:09       ` Jeremy Fitzhardinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=513FE785.3010207@uic.edu \
    --to=xzhang54@uic.edu \
    --cc=gm281@cam.ac.uk \
    --cc=jeremy@goop.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    --cc=xzhang@cs.uic.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.