public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Denys Vlasenko <dvlasenk@redhat.com>
Cc: lguest@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lguest: simplify lguest_iret
Date: Wed, 25 Mar 2015 14:08:56 +1030	[thread overview]
Message-ID: <871tkdiw4v.fsf@rustcorp.com.au> (raw)
In-Reply-To: <55117432.7060604@redhat.com>

Denys Vlasenko <dvlasenk@redhat.com> writes:
> On 03/23/2015 04:30 AM, Rusty Russell wrote:
>> +		 * They may be about to iret, where they asked us never to
>> +		 * deliver interrupts.  In this case, we can emulate that iret
>> +		 * then immediately deliver the interrupt.  This is bascially
>> +		 * a noop: the iret would pop the interrupt frame and restore
>> +		 * eflags, and then we'd set it up again.  So just restore the
>> +		 * eflags word and jump straight to the handler in this case.
>>  		 */
>> +		if (cpu->regs->eip >= cpu->lg->noirq_start &&
>> +		    (cpu->regs->eip < cpu->lg->noirq_end)) {
>> +			restore_eflags(cpu);
>
> In truth, this is not _exactly_ true for irets to CPL3.
>
> If a new interrupt comes right after iret, then
> a new transition to CPL0 will happen.
>
> This means ss:esp will be loaded from tss.ss0:tss.sp0.
>
> Meaning, that the new iret frame may be in a different place
> than the one which was used by iret.

True.  We could check the to-be-restored-CPL and reset the sp.  Instead,
I've added this comment:

		/*
		 * They may be about to iret, where they asked us never to
		 * deliver interrupts.  In this case, we can emulate that iret
		 * then immediately deliver the interrupt.  This is basically
		 * a noop: the iret would pop the interrupt frame and restore
		 * eflags, and then we'd set it up again.  So just restore the
		 * eflags word and jump straight to the handler in this case.
		 *
		 * Denys Vlasenko points out that this isn't quite right: if
		 * the iret was returning to userspace, then that interrupt
		 * would reset the stack pointer (which the Guest told us
		 * about via LHCALL_SET_STACK).  But unless the Guest is being
		 * *really* weird, that will be the same as the current stack
		 * anyway.
		 */

> There is no good reason for CPL0 code to move iret frame around,
> but who knows. As an example, look what 32-bit Linux kernel does
> with NMI iret frames... it's mind bending.

Fortunately, lguest is allergic to NMIs :)

Thanks!
Rusty.



      reply	other threads:[~2015-03-25  4:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-21 21:42 [PATCH] lguest: simplify lguest_iret Denys Vlasenko
2015-03-23  3:30 ` Rusty Russell
2015-03-24 14:26   ` Denys Vlasenko
2015-03-25  3:38     ` Rusty Russell [this message]

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=871tkdiw4v.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=dvlasenk@redhat.com \
    --cc=lguest@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox