public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Cross vendor migration ideas
@ 2008-11-12 15:39 Alexander Graf
  2008-11-12 15:45 ` Anthony Liguori
  2008-11-12 16:52 ` Amit Shah
  0 siblings, 2 replies; 26+ messages in thread
From: Alexander Graf @ 2008-11-12 15:39 UTC (permalink / raw)
  To: kvm@vger.kernel.org list
  Cc: Amit Shah, Avi Kivity, Elsie Wahlig,
	Serebrin, Benjamin (Calendar), Anthony Liguori, Nakajima, Jun

Hi,

I was thinking a bit about cross vendor migration recently and since  
we're doing open source development, I figured it might be a good idea  
to talk to everyone about this.

So why are we having a problem?

In normal operation we don't. If we're running a 32-bit kernel, we can  
use SYSENTER to jump from kernel<->userspace. If we're on a 64-bit  
kernel with 64-bit userspace, every CPU supports SYSCALL. At least  
Linux is being smart on this and does use exactly these two  
capabilities in these two cases.
But if we're running in compat mode (64-bit kernel with 32-bit  
userspace), things differ. Intel supports only SYSENTER here, while  
AMD only supports SYSCALL. Both can still use int80.

Operating systems detect usage of SYSCALL or SYSENTER pretty early on  
(Linux does this on vdso). So when we boot up on an Intel machine,  
Linux assumes that using SYSENTER in compat mode is fine. Migrating  
that machine to an AMD machine breaks this assumption though, since  
SYSENTER can't be used in compat mode.
On LInux, this detection is based on the CPU vendor string. If Linux  
finds a "GenuineIntel", SYSENTER is used in compat mode, if it's  
"AuthenticAMD", SYSCALL is used and if none of these two is found,  
int80 is used.

I tried modifying the vendor string, removed the "overwrite the vendor  
string with the native string" hack and things look like they work  
just fine with Linux.

Unfortunately right now I don't have a 64-bit Windows installation  
around to check if that approach works there too, but if it does and  
no known OS breaks due to the invalid vendor string, we can just  
create our own virtual CPU string, no?

I'd love to hear comments and suggestions on this and hope we'll end  
up in a fruitful discussion on how to improve the current situation.

Alex

^ permalink raw reply	[flat|nested] 26+ messages in thread
* RE: Cross vendor migration ideas
@ 2008-11-16  0:23 Skywing
  0 siblings, 0 replies; 26+ messages in thread
From: Skywing @ 2008-11-16  0:23 UTC (permalink / raw)
  To: Andi Kleen, Serebrin, Benjamin (Calendar)
  Cc: Alexander Graf, Anthony Liguori, kvm@vger.kernel.org, Amit Shah,
	Avi Kivity, Wahlig, Elsie, Nakajima, Jun

Comments inline.

-----Original Message-----
From: Andi Kleen <andi@firstfloor.org>
Sent: Saturday, November 15, 2008 07:03
To: Serebrin, Benjamin (Calendar) <Benjamin.Serebrin@exchange.amd.com>
Cc: Skywing <Skywing@valhallalegends.com>; Alexander Graf <agraf@suse.de>; Anthony Liguori <anthony@codemonkey.ws>; kvm@vger.kernel.org <kvm@vger.kernel.org>; Amit Shah <amit.shah@redhat.com>; Avi Kivity <avi@redhat.com>; Wahlig, Elsie <elsie.wahlig@amd.com>; Nakajima, Jun <jun.nakajima@intel.com>
Subject: Re: Cross vendor migration ideas

> Also it might break user space, unless you key the fake vendor CPUID
> intercept on ring 0 vs ring 3 (but even if that might not be enough
> because some kernel modules can call CPUID on their own)
> 
> I think just emulating SYSCALL/SYSENTER would be safer. It shouldn't
> be that much slower than int 0x80 hopefully.
> 
> -Andi

If I understand that idea correctly, I think that trying to present a differing view of the CPU vendor and/or feature set is likely to be fraught with peril and highly fragile.

There are many systems where the kernel gets processor feature data in CPL=0 and makes it available to user mode.  This creates an inconsistency when user mode uses cpuid directly and comes up with differing results.

As a real world example, in Windows, the kernel is responsible for examining the current processors installed on the box, mapping processor feature codes to a standard encoding, and making this available to all user mode processes via a shared memory region (read only to user mode) at a well known location (SharedUserData->ProcessorFeatures).

However, user mode programs are free to make their own determinations via cpuid calls if they so wish.  Many programs use the standard abstracted processor feature determination mechanism (figured by the kernel), while others, for varying reasons (some good and some foolish) just call cpuid directly at CPL=3.  There can even be a mix within different code modules loaded into a process.

In the specific case of Windows and system services, IIRC the old-style int 2e system service interface is always initialized on 32-bit x86 kernels, even if sysenter or syscall will be preferred.  As far as I know, this is just for backcompat with programs issuing system services directly as opposed to using the correct C-level abstraction layer.

For Windows, it is CPL=0 inspection of processor attributes via cpuid (assuming the "disable fast system service interface" registry value is not set) that determines which is used.  This occurs once, at system boot, as one would expect.

That being said, I still think that it will break things in difficult to debug ways should you introduce an inconsistent view of cpuid features into the system.

- S

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

end of thread, other threads:[~2008-11-17 11:59 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 15:39 Cross vendor migration ideas Alexander Graf
2008-11-12 15:45 ` Anthony Liguori
2008-11-12 15:50   ` Alexander Graf
2008-11-12 15:59     ` Anthony Liguori
2008-11-13  0:02     ` Skywing
2008-11-13  1:48       ` Serebrin, Benjamin (Calendar)
2008-11-15 13:03         ` Andi Kleen
2008-11-15 16:39           ` Alexander Graf
2008-11-15 17:37             ` Andi Kleen
2008-11-16 15:36               ` Avi Kivity
2008-11-17 11:09                 ` Andi Kleen
2008-11-17 11:59                   ` Avi Kivity
2008-11-15 17:38             ` Glauber Costa
2008-11-16 14:58               ` Avi Kivity
2008-11-13 10:16     ` Avi Kivity
2008-11-12 20:06   ` Andi Kleen
2008-11-12 20:52     ` Alexander Graf
2008-11-13 10:20   ` Avi Kivity
2008-11-12 16:52 ` Amit Shah
2008-11-12 17:19   ` Alexander Graf
2008-11-13  4:35     ` Amit Shah
2008-11-13 13:38       ` Alexander Graf
2008-11-14 13:07         ` Amit Shah
2008-11-14 23:43           ` Nitin A Kamble
2008-11-17 10:07             ` Amit Shah
  -- strict thread matches above, loose matches on Subject: below --
2008-11-16  0:23 Skywing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox