linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Brian Gerst <brgerst@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	the arch/x86 maintainers <x86@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Kees Cook <keescook@chromium.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH] x86/kconfig/32: Mark CONFIG_VM86 as BROKEN
Date: Thu, 9 Jul 2015 07:52:25 +0200	[thread overview]
Message-ID: <20150709055225.GA29556@gmail.com> (raw)
In-Reply-To: <CALCETrUDD8yuOzSYeZARYc5qpbNC1LVdKzaNDH0bCM6q-DDHnQ@mail.gmail.com>


* Andy Lutomirski <luto@amacapital.net> wrote:

> >> I look forward to it.
> >>
> >> However: I imagine that, if you do this, you may need to be quite careful 
> >> about an x86_32-ism.  Currently, if you have a pt_regs pointer for the 
> >> current entry and user_mode(regs) returns true, then regs == 
> >> current_pt_regs().  If you let user mode run with EFLAGS.VM set with the 
> >> normal tss.sp0, then this will no longer be true, as the extra-long 
> >> entry-from-v8086 frame will shift pt_regs by a few bytes. I don't know 
> >> whether this matters, but I can imagine it causing do_signal to explode.  
> >> *shudder*
> >
> > I am aware that pt_regs is in a fixed location on the stack.  What I plan to 
> > do is increase the padding at the top of the stack if VM86 is configured, to 
> > reserve space for the extra segment registers.  Then it will move tss.sp0 up 
> > 16 bytes when entering vm86 mode so that the longer IRET frame is in the right 
> > place.
> >
> 
> Hmm, should work.
> 
> I wonder if the right way to do this is to set a TIF_VM86 flag and do the fixups 
> in enter_from_user_mode and prepare_return_to_usermode. See the patches I just 
> sent (and tip/x88/asm, which they apply to).
> 
> Without something like that, we'll be in the awkward position of having some of 
> the selectors (DS, ES, FS, and GS) in both the normal pt_regs slot and in the 
> extended hardware frame during execution of normal vm86-unaware kernel code.  
> If, on the other hand, we copied the selectors across in enter_from_user_mode 
> and prepare_return_from_usermode, then pt_regs would work normally even for 
> tasks that are running in v8086 mode.
> 
> regs->flags & X86_EFLAGS_VM will be true regardless, so all of the asm that 
> decides to invoke those helpers should work fine.

Btw., has anyone considered an entirely different approach: using KVM's 
instruction emulator to emulate vm86 16-bit code execution? Basically the vm86 
system call would be kept compatible, but fully emulated, the CPU never enters 
true 16-bit mode, just iterates pt_regs as if it had.

This approach has four main advantages:

 - we could remove the fragile vm86 code from the entry code

 - it might even be faster for certain workloads than faulting in and out all the
   time and using ancient, fragile hardware mode of the CPU. (For example it could
   detect the VGA screen write patterns and accelerate them.)

 - it could be made to work on 64-bit as well, FWIIW

 - it would provide another angle of testing for the KVM emulator

Hm?

Thanks,

	Ingo

  reply	other threads:[~2015-07-09  5:52 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08  1:25 [PATCH] x86/kconfig/32: Mark CONFIG_VM86 as BROKEN Andy Lutomirski
2015-07-08  2:33 ` Arjan van de Ven
2015-07-08 14:00   ` Thomas Gleixner
2015-07-08 14:04     ` Ingo Molnar
2015-07-09  9:03     ` Pavel Machek
2015-07-09 17:57       ` Andy Lutomirski
2015-07-09 18:03         ` Kees Cook
2015-07-09 18:30         ` Linus Torvalds
2015-07-08 16:59   ` Linus Torvalds
2015-07-08 17:30     ` Andy Lutomirski
2015-07-08 17:49       ` Andy Lutomirski
2015-07-08 17:55         ` Linus Torvalds
2015-07-08 18:47           ` Andy Lutomirski
2015-07-08 18:53             ` Kees Cook
2015-07-08 18:48           ` Kees Cook
2015-07-08 19:04             ` Andy Lutomirski
2015-07-08 18:54           ` Austin S Hemmelgarn
2015-07-08 19:05       ` Brian Gerst
2015-07-08 19:14         ` Andy Lutomirski
2015-07-08 19:39           ` Brian Gerst
2015-07-08 19:59             ` Andy Lutomirski
2015-07-09  5:52               ` Ingo Molnar [this message]
2015-07-09  5:59                 ` Ingo Molnar
2015-07-09 18:33                   ` Andy Lutomirski
2015-07-10 11:16                     ` Paolo Bonzini
2015-07-10 14:13                       ` Ingo Molnar
2015-07-10 14:24                         ` Paolo Bonzini
2015-07-10 14:39                       ` Andy Lutomirski
2015-07-10 14:12       ` Eric W. Biederman
2015-07-10 14:37         ` Andy Lutomirski
2015-07-10 16:35           ` Linus Torvalds
2015-07-10 16:44             ` Andy Lutomirski
2015-07-10 17:04               ` Linus Torvalds
2015-07-10 17:13                 ` Andy Lutomirski
2015-07-10 17:39                   ` Linus Torvalds
2015-07-10 17:58                     ` Andy Lutomirski
2015-07-10 18:00                     ` Al Viro
2015-07-11  9:18                     ` Ingo Molnar
2015-07-08 19:13     ` Ingo Molnar
2015-07-08  9:45 ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2015-07-08 15:32 ` [PATCH] " Brian Gerst

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=20150709055225.GA29556@gmail.com \
    --to=mingo@kernel.org \
    --cc=arjan@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).