From owner-freebsd-virtualization@FreeBSD.ORG Wed Jun 19 13:16:02 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id CBE65516; Wed, 19 Jun 2013 13:16:02 +0000 (UTC) (envelope-from larrymelia@gmail.com) Received: from mail-pb0-x230.google.com (mail-pb0-x230.google.com [IPv6:2607:f8b0:400e:c01::230]) by mx1.freebsd.org (Postfix) with ESMTP id 9D24810DA; Wed, 19 Jun 2013 13:16:02 +0000 (UTC) Received: by mail-pb0-f48.google.com with SMTP id ma3so5024089pbc.7 for ; Wed, 19 Jun 2013 06:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=JWx8hqZ7WM0Tfz+FUYIygdjXlZkJd3KpRJP9AAnST6Y=; b=RgXpbiAD5k7TyGQWyRrqX8RJMupcqRnfz88TYI0bgcEr0znIzQHa3/XTYvve+j6Tu+ ox+HPjOQ2PPxztn9OOOG4mENKG++0s57EK94ujD6W3HhOch03ly5xEmoBO8/CguoWsll KCKnNiujVH4vRyDUXZLkUo3byFjSiLJPs6Ty44D3WWEav5tjjeK6CnMyIbsnPM0YDzXp A1UGP/I0pSXALsTjH7JEfeFcBM5yp4Pm+oq7BhW3wxn7uGIJPZpApvjv7aAfNwzdCNxT x5LoTBaLEHY2kgnsXAtIu/f6+BYva83f+Ore5sFwBzfl+iNB5rZjfcLB2SOHXBZYLIF+ hgPA== X-Received: by 10.66.240.41 with SMTP id vx9mr6672164pac.93.1371647762423; Wed, 19 Jun 2013 06:16:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.70.85.196 with HTTP; Wed, 19 Jun 2013 06:15:22 -0700 (PDT) In-Reply-To: <201304291345.50635.jhb@freebsd.org> References: <201304291345.50635.jhb@freebsd.org> From: Larry Melia Date: Wed, 19 Jun 2013 06:15:22 -0700 Message-ID: Subject: Re: Proposal for better support of hypervisors and their synthetic drivers at boot-time To: John Baldwin Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: Alexander Motin , KY Srinivasan , "Abhishek Gupta \(LIS\)" , freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jun 2013 13:16:02 -0000 John, Sorry for not responding earlier to your comments, but we=92re at a point where we=92re trying to get our VM drivers included with the current build. Your solution for dynamic loading sounds wonderful! Is this a simple change? And how can we help? Here=92s an example of the modern, preferred way (Linux has been doing this for 5+ years) to detect the presence of a hypervisor on x86/AMD chips, both 32/64 bit modes (this is pulled from our FreeBSD driver, but the formatting is off because Google's Gmail really wants to make it look "pretty"): *#define HV_X64_MSR_GUEST_OS_ID 0x40000000* *#define HV_X64_CPUID_MIN 0x40000005* *#define HV_X64_CPUID_MAX 0x4000ffff* *static* *int* *hv_check_for_hyper_v*(*void*) { u_int regs[4]; *int* hyper_v_detected *=3D* 0; do_cpuid(1, regs); *if* (regs[2] *&* 0x80000000) { */* if(a hypervisor is detected) */* */* make sure this really is Hyper-V */* */* we look at the CPUID info */* do_cpuid(HV_X64_MSR_GUEST_OS_ID, regs); hyper_v_detected *=3D* regs[0] *>=3D* HV_X64_CPUID_MIN *&&* regs[0] *<=3D* HV_X64_CPUID_MAX *&&* *!*memcmp("Microsoft Hv", *&*regs[1], 12); } *return* (hyper_v_detected); } Of course, a general purpose routine will simply copy the name-tag somewhere and make it available. We are also having some issues with some of the disk utilities. They need to behave differently when operating under a hypervisor. I=92ll try to provide a list of all the things that should be upgraded or enhanced, then we can figure out the best way to get them done. On Mon, Apr 29, 2013 at 10:45 AM, John Baldwin wrote: > I know Alexander replied about the ATA bits already, but I wanted to repl= y > to > two of your other points below: > > On Tuesday, April 23, 2013 10:07:03 am Larry Melia wrote: > > (1) Move the call to init_param1() (in sys/kern/subr_parm.c), which is > used > > for hypervisor detection, to an earlier point in the boot process. > > Presently, it appears to be called after the ATA driver is selected, > which > > is too late in the boot process. (This was discovered after some testin= g > > with the ATA driver.) Therefore, before the bus drivers and native > > controllers are detected and selected, discovery of a host hypervisor > > should be done first. > > > > (3) Upgrade the init_param1() function (in sys/kern/subr_parm.c) to use > the > > more recent approach to hypervisor detection. This approach uses the > > CPU-identify functions to retrieve a unique signature consisting of a > fixed > > string of ASCII characters. This was done on Linux about five years. Fo= r > > backward compatibility, however, the existing logic would be retained, > but > > augmented with this new approach. It would also be conditionally added > only > > for x86/AMD64 builds. > > I definitely agree with these proposals. In addition, our current > hypervisor > detection code is completely x86-specific and does not belong in MI code. > The > only bits that should be MI are the vm_guest variable and the VM_GUEST > constants. I would argue that most of the VM_GUEST constants (for specif= ic > VMs which we do not have currently) should be MD as well. > > Each platform that supports hypervisors would install its own SYSINIT to > set > vm_guest instead of doing it directly from init_param1(). > > Making the VM_GUEST_FOO constants be MD macros means you can use #ifdef t= o > test for them. Thus: > > #ifdef VM_GUEST_HYPERV > /* Include a hyper-V specific driver. */ > #endif > > The current enum approach doesn't allow for that. > > -- > John Baldwin >