From owner-freebsd-virtualization@FreeBSD.ORG Sun Dec 22 01:06:51 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 67AE3993 for ; Sun, 22 Dec 2013 01:06:51 +0000 (UTC) Received: from mail-pa0-x232.google.com (mail-pa0-x232.google.com [IPv6:2607:f8b0:400e:c03::232]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 35041112F for ; Sun, 22 Dec 2013 01:06:51 +0000 (UTC) Received: by mail-pa0-f50.google.com with SMTP id kp14so2226984pab.9 for ; Sat, 21 Dec 2013 17:06:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OtVy3vtd4p+cNYTBo4b81gbYS+6ySQwi/p05mtezUNU=; b=Oj3rNBsYolVecANGDg/ahG7APq83IAoc0XpJdBC5s67lykP0OooMHuoFTTBTkg81ed /ymPpHjswZoNrxhOSNTAk7qNDSi7SSh6nojT1MyBPPhTuZO3R8oWojo+cdQlTzwOypTs GSab8jDJc4VilvCeyF1Yqamz8yi0TOT0UTmpyaSIEyyaSie97iiX1eyR/pY3SckPg2QJ l1M45M40IAz0+K/3KGXarH/YcwU6rX5uF3WVV5pbA9GhHEPBNjUbbmroMsbeAiSU3cJy e0cjP055H1OjCq28EupDQ9aHc71RbYOFXSAvenCPGGMgHulOU7+kuKaOC5/vqJBckChM 1aKA== MIME-Version: 1.0 X-Received: by 10.66.146.199 with SMTP id te7mr17615069pab.106.1387674410790; Sat, 21 Dec 2013 17:06:50 -0800 (PST) Received: by 10.68.185.130 with HTTP; Sat, 21 Dec 2013 17:06:50 -0800 (PST) In-Reply-To: References: Date: Sat, 21 Dec 2013 20:06:50 -0500 Message-ID: Subject: Re: Means to control a bhyve VM instance From: Aryeh Friedman To: =?UTF-8?Q?Micha=C5=82_Dubiel?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.17 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Sun, 22 Dec 2013 01:06:51 -0000 An other option is a frontend like PetiteCloud (we will be releasing 0.2 in the next few days that gives 100% web based control [as well command line control]) over bhyve instances On Fri, Dec 20, 2013 at 4:54 AM, Micha=C5=82 Dubiel wrote= : > Hi, > > May I ask you about the means to control a VM instance. I mean by that > something providing similar features as QEMU's monitor interface along > with QEMU > Machine Protocol (QMP) do. Has it already been decided/designed how bhyve > is going to handle features like a soft start/stop of a VM instance, > hot-plugging of additional blk/net devices, etc? > > Regards, > Michal. > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to " > freebsd-virtualization-unsubscribe@freebsd.org" > From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 11:06:57 2013 Return-Path: Delivered-To: freebsd-virtualization@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5DA41687 for ; Mon, 23 Dec 2013 11:06:57 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4921411DF for ; Mon, 23 Dec 2013 11:06:57 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id rBNB6vNi030191 for ; Mon, 23 Dec 2013 11:06:57 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id rBNB6uEp030189 for freebsd-virtualization@FreeBSD.org; Mon, 23 Dec 2013 11:06:56 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 23 Dec 2013 11:06:56 GMT Message-Id: <201312231106.rBNB6uEp030189@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-virtualization@FreeBSD.org Subject: Current problem reports assigned to freebsd-virtualization@FreeBSD.org X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 11:06:57 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o kern/165252 virtualization[vimage] [pf] [panic] kernel panics with VIMAGE and PF o kern/161094 virtualization[vimage] [pf] [panic] kernel panic with pf + VIMAGE wh o kern/160541 virtualization[vimage][pf][patch] panic: userret: Returning on td 0x o kern/160496 virtualization[vimage] [pf] [patch] kernel panic with pf + VIMAGE o kern/148155 virtualization[vimage] [pf] Kernel panic with PF + VIMAGE kernel opt a kern/147950 virtualization[vimage] [carp] VIMAGE + CARP = kernel crash s kern/143808 virtualization[pf] pf does not work inside jail 7 problems total. From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 16:18:40 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0975277B for ; Mon, 23 Dec 2013 16:18:40 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D488518BB for ; Mon, 23 Dec 2013 16:18:39 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id C3F37B941; Mon, 23 Dec 2013 11:18:38 -0500 (EST) From: John Baldwin To: Neel Natu Subject: Re: Panic starting a bhyve guest after resume Date: Fri, 20 Dec 2013 17:23:46 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <201312121511.38608.jhb@freebsd.org> <201312131709.20264.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201312201723.46978.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 23 Dec 2013 11:18:38 -0500 (EST) Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 16:18:40 -0000 On Friday, December 13, 2013 9:28:29 pm Neel Natu wrote: > Hi John, > > On Fri, Dec 13, 2013 at 2:09 PM, John Baldwin wrote: > > On Thursday, December 12, 2013 4:00:08 pm Neel Natu wrote: > >> Hi John, > >> > >> On Thu, Dec 12, 2013 at 12:11 PM, John Baldwin wrote: > >> > If I suspend and resume my laptop and then try to start a guest after the > >> > resume, I get an odd panic. It generates a privileged instruction fault (in > >> > kernel mode) for 'vmclear'. I've checked CR4 and it claims that VMXE is set. > >> > I dont have any other ideas off the top of my head on what I should be poking > >> > at? It looks like we read a bunch of MSRs in vmx_init(), but we don't write > >> > to them, and all vmx_enable() does on each CPU is set VMXE in CR4 from what I > >> > can tell. > >> > > >> > >> It also does a "vmxon" on each logical cpu which may also need to be > >> done after a resume. > > > > Ah, yes it does. That was sufficient both for starting a new guest after > > resume and even doing a suspend/resume while a guest was active (and the > > guest continued to run fine). I have a hacky patch for this. One, it > > includes both a suspend and resume hook for VMM, though for my testing I only > > needed a resume hook to invoke vmxon. Second, the name of vmx_resume2() > > is a total hack (because vmx_resume() was already taken. I think for now > > if I were to commit this, I'd just add the resme hook and maybe call the > > Intel method vmx_reset() or vmx_restore()? > > > > http://people.freebsd.org/~jhb/patches/bhyve_resume.patch > > > > There seems to be a race after the APs are restarted and before > 'vmm_resume_p()' where it would be problematic to execute a VMX > instruction. > > Perhaps we should enable VMX on each cpu before they return to the > interrupted code? I've updated the patch at the URL above to do just that. This also works in my testing. -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 19:15:28 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5A2D5840; Mon, 23 Dec 2013 19:15:28 +0000 (UTC) Received: from mail-qc0-x229.google.com (mail-qc0-x229.google.com [IPv6:2607:f8b0:400d:c01::229]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 07DA616C1; Mon, 23 Dec 2013 19:15:27 +0000 (UTC) Received: by mail-qc0-f169.google.com with SMTP id r5so5295395qcx.14 for ; Mon, 23 Dec 2013 11:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HPCSO1hEN/pnEozwB5X0Us+BmdESuRWr05PcimvxB3Q=; b=k4SezGXsykf2t6LQmi/Z41JT05LtD0Yb4VMOV2Xvxi8v9GG8LCpqE5AhTmdXFj+rEA h0J0igH4H+t5bYbWbTN6TfQ2HrwyM2s9jKUMjXrAMrIARaICAAx3M4MAAB6Sgn4BxWj+ WYldTf4Pdz/VINEpleg9dA9fTbGn3SsNfSgGd+W+FO9uD3uI5wOV5539fuJhLybggnyu uvENABq8KU7Ra6RirmfpDoNGKdJAdVCvsj++p+yiEK3bowxiWhwP4mmX71UoVBlLprJo rZx7Vjzr08UHMTKpjWenEQ4B4jtP3masKzdwANA0fcuqUZRrV5O8XdgQos58Ui8tWciW CQ+Q== MIME-Version: 1.0 X-Received: by 10.229.194.1 with SMTP id dw1mr45015151qcb.20.1387826127198; Mon, 23 Dec 2013 11:15:27 -0800 (PST) Received: by 10.140.34.17 with HTTP; Mon, 23 Dec 2013 11:15:27 -0800 (PST) In-Reply-To: <201312201723.46978.jhb@freebsd.org> References: <201312121511.38608.jhb@freebsd.org> <201312131709.20264.jhb@freebsd.org> <201312201723.46978.jhb@freebsd.org> Date: Mon, 23 Dec 2013 11:15:27 -0800 Message-ID: Subject: Re: Panic starting a bhyve guest after resume From: Neel Natu To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 19:15:28 -0000 Hi John, On Fri, Dec 20, 2013 at 2:23 PM, John Baldwin wrote: > On Friday, December 13, 2013 9:28:29 pm Neel Natu wrote: >> Hi John, >> >> On Fri, Dec 13, 2013 at 2:09 PM, John Baldwin wrote: >> > On Thursday, December 12, 2013 4:00:08 pm Neel Natu wrote: >> >> Hi John, >> >> >> >> On Thu, Dec 12, 2013 at 12:11 PM, John Baldwin wrote: >> >> > If I suspend and resume my laptop and then try to start a guest after the >> >> > resume, I get an odd panic. It generates a privileged instruction fault (in >> >> > kernel mode) for 'vmclear'. I've checked CR4 and it claims that VMXE is set. >> >> > I dont have any other ideas off the top of my head on what I should be poking >> >> > at? It looks like we read a bunch of MSRs in vmx_init(), but we don't write >> >> > to them, and all vmx_enable() does on each CPU is set VMXE in CR4 from what I >> >> > can tell. >> >> > >> >> >> >> It also does a "vmxon" on each logical cpu which may also need to be >> >> done after a resume. >> > >> > Ah, yes it does. That was sufficient both for starting a new guest after >> > resume and even doing a suspend/resume while a guest was active (and the >> > guest continued to run fine). I have a hacky patch for this. One, it >> > includes both a suspend and resume hook for VMM, though for my testing I only >> > needed a resume hook to invoke vmxon. Second, the name of vmx_resume2() >> > is a total hack (because vmx_resume() was already taken. I think for now >> > if I were to commit this, I'd just add the resme hook and maybe call the >> > Intel method vmx_reset() or vmx_restore()? >> > >> > http://people.freebsd.org/~jhb/patches/bhyve_resume.patch >> > >> >> There seems to be a race after the APs are restarted and before >> 'vmm_resume_p()' where it would be problematic to execute a VMX >> instruction. >> >> Perhaps we should enable VMX on each cpu before they return to the >> interrupted code? > > I've updated the patch at the URL above to do just that. This also works > in my testing. > Looks great! best Neel > -- > John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 19:19:34 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E57E6B34; Mon, 23 Dec 2013 19:19:34 +0000 (UTC) Received: from mail-qc0-x233.google.com (mail-qc0-x233.google.com [IPv6:2607:f8b0:400d:c01::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 805F016FF; Mon, 23 Dec 2013 19:19:34 +0000 (UTC) Received: by mail-qc0-f179.google.com with SMTP id i8so5208973qcq.24 for ; Mon, 23 Dec 2013 11:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=7x5si4GAem2E6mrGQwavRA7OpXg1/Kk+4+jbm1Td5Vs=; b=r0/nGmKV4oqVcvKlZr0ZwP4p5kExT4APPemI5OGB2c8t0W+QDIUVfDMFZBXqx0IRfh V3CiQdZHSLdMiRorwBhnjmpqSAaQp5VZTK+6kSpTvt2rDR94C1qWvpVYa2WCnLER5ceF ajBb9+z0nbhgIUHbZSWQOcgIclXb++y6K7SlextFPntNX7WXEaGENMtgj1fSIYApOq3l 7hiwNKl6p2EwpT7Nn/C8HSobdMdKr68ECv4dxWH36h+y9Lz8I+T3PPerQENIF3XqfSGU CYTll/9bMxxkaavx6H+txScyYswdeXBxCTrID+24XYzgYXOJdg8QkZfRCmYPwmHZySsP u3aw== MIME-Version: 1.0 X-Received: by 10.49.28.101 with SMTP id a5mr45628484qeh.70.1387826373710; Mon, 23 Dec 2013 11:19:33 -0800 (PST) Received: by 10.140.34.17 with HTTP; Mon, 23 Dec 2013 11:19:33 -0800 (PST) In-Reply-To: References: <201312131304.57455.jhb@freebsd.org> Date: Mon, 23 Dec 2013 11:19:33 -0800 Message-ID: Subject: Re: 11.0-CURRENT panic while running a bhyve instance From: Neel Natu To: Markiyan Kushnir Content-Type: text/plain; charset=ISO-8859-1 Cc: FreeBSD current , "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 19:19:35 -0000 Hi Markiyan, Fixed in r259737: http://svnweb.freebsd.org/changeset/base/259737 best Neel On Fri, Dec 13, 2013 at 2:35 PM, Markiyan Kushnir wrote: > 2013/12/13 John Baldwin : >> On Friday, December 13, 2013 5:46:20 am Markiyan Kushnir wrote: >>> Forgot to fill the Subject: header, re-posting it fixed. >> >> The mailing lists strips attachments, can you post it at a URL? >> > > Shared here: > > https://drive.google.com/file/d/0B9Q-zpUXxqCnem5iYTVqLUxrcWo4cmlhdkM1c2lJa2dKak5R/edit?usp=sharing > > -- > Markiyan. > >>> -- >>> Markiyan >>> >>> >>> ---------- Forwarded message ---------- >>> From: Markiyan Kushnir >>> Date: 2013/12/13 >>> Subject: >>> To: freebsd-current@freebsd.org, freebsd-virtualization@freebsd.org >>> >>> >>> I started some ports to compile inside a bhyve instance: >>> >>> root@vm:~ # uname -a >>> FreeBSD vm.mkushnir.mooo.com 11.0-CURRENT FreeBSD 11.0-CURRENT #0 >>> r259250: Thu Dec 12 14:17:32 EET 2013 >>> root@vm.mkushnir.zapto.org:/ >>> usr/obj/usr/src.svnup/sys/MAREK amd64 >>> >>> and left it running unattended. Approx. 2 hours later the host went to >>> panic. The bhyve instance survived after the panic and I could be able >>> to complete my ports compilation. >>> >>> core.txt attached (gzipped) >>> _______________________________________________ >>> freebsd-current@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/freebsd-current >>> To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >>> >> >> -- >> John Baldwin > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 19:44:29 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3E6AFB8A for ; Mon, 23 Dec 2013 19:44:29 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EEB20194C for ; Mon, 23 Dec 2013 19:44:28 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id CE8F1B9CC for ; Mon, 23 Dec 2013 14:44:27 -0500 (EST) From: John Baldwin To: virtualization@freebsd.org Subject: [PATCH] Support for S5 (soft power off) in bhyve Date: Mon, 23 Dec 2013 14:43:39 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201312231443.39282.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 23 Dec 2013 14:44:28 -0500 (EST) X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 19:44:29 -0000 One minor nit I've found annoying is that there is no easy way to break out of the loop in vmrun.sh. Breaking into the loader prompt and typing 'reboot' does work, but it requires you to be on the console at the time. What I really want is for 'shutdown -p' or 'poweroff' inside a guest to cleanly shut down and exit the loop in vmrun.sh. To that end, I've implemented support for a few more registers (such of which are non-optional in ACPI) including the Reset Control register (0xcf9), ACPI Power Management 1 Event registers (PM1_EVT) and the ACPI Power Management 1 Control register (PM1_CNT). I added a valid _S5 package and catch writes of the value _S5 specifies to ask bhyve to exit gracefully but with an exit code of 1 (so the loop in vmrun terminates). Most of the PM1 support is very simple (it doesn't support signalling anything for external events as most of them don't make sense). It does perform a reset for writes to the 0xcf9 register however, and also advertises 0xcf9 as the ACPI reset register. (Tested by commenting out the current 0x64 hack.) One thing I had to do was make it possible for an I/O port to request a reset or poweroff, so I added some #define's for additional return codes from in/out handlers. I haven't gone through and changed any existing handlers to use the new constants, but the new handlers make use of INOT_RESET and INOUT_POWEROFF. Note that this also means that the current 0x64 hack could be reimplemented as an in-out handler rather than a special case. I did not explicitly catch VMEXIT_POWEROFF and use a custom exit value in the main loop in bhyverun.c. Instead, I let it fall through to the default and do an exit(1). The patch is all in bhyve itself: --- //depot/vendor/freebsd/src/usr.sbin/bhyve/Makefile +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/Makefile @@ -10,7 +10,7 @@ SRCS= acpi.c atpic.c bhyverun.c block_if.c consport.c dbgport.c elcr.c SRCS+= inout.c legacy_irq.c mem.c mevent.c mptbl.c pci_ahci.c SRCS+= pci_emul.c pci_hostbridge.c pci_lpc.c pci_passthru.c pci_virtio_block.c -SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pmtmr.c post.c rtc.c +SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pm.c pmtmr.c post.c rtc.c SRCS+= uart_emul.c virtio.c xmsr.c spinup_ap.c .PATH: ${.CURDIR}/../../sys/amd64/vmm --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.c @@ -85,6 +85,8 @@ #define BHYVE_ASL_SUFFIX ".aml" #define BHYVE_ASL_COMPILER "/usr/sbin/iasl" +#define BHYVE_PM1A_EVT_ADDR 0x400 +#define BHYVE_PM1A_CNT_ADDR 0x404 #define BHYVE_PM_TIMER_ADDR 0x408 static int basl_keep_temps; @@ -332,9 +344,11 @@ EFPRINTF(fp, "[0001]\t\tACPI Disable Value : 00\n"); EFPRINTF(fp, "[0001]\t\tS4BIOS Command : 00\n"); EFPRINTF(fp, "[0001]\t\tP-State Control : 00\n"); - EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : 00000000\n"); + EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : %08X\n", + BHYVE_PM1A_EVT_ADDR); EFPRINTF(fp, "[0004]\t\tPM1B Event Block Address : 00000000\n"); - EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : 00000000\n"); + EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : %08X\n", + BHYVE_PM1A_CNT_ADDR); EFPRINTF(fp, "[0004]\t\tPM1B Control Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM2 Control Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM Timer Block Address : %08X\n", @@ -397,10 +411,10 @@ EFPRINTF(fp, "[0001]\t\tBit Width : 08\n"); EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 01 [Byte Access:8]\n"); - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); + EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000CF9\n"); EFPRINTF(fp, "\n"); - EFPRINTF(fp, "[0001]\t\tValue to cause reset : 00\n"); + EFPRINTF(fp, "[0001]\t\tValue to cause reset : 06\n"); EFPRINTF(fp, "[0003]\t\tReserved : 000000\n"); EFPRINTF(fp, "[0008]\t\tFACS Address : 00000000%08X\n", basl_acpi_base + FACS_OFFSET); @@ -412,7 +426,8 @@ EFPRINTF(fp, "[0001]\t\tBit Width : 20\n"); EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); + EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", + BHYVE_PM1A_EVT_ADDR); EFPRINTF(fp, "\n"); EFPRINTF(fp, @@ -431,7 +446,8 @@ EFPRINTF(fp, "[0001]\t\tBit Width : 10\n"); EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); + EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", + BHYVE_PM1A_CNT_ADDR); EFPRINTF(fp, "\n"); EFPRINTF(fp, @@ -603,6 +619,11 @@ EFPRINTF(fp, "DefinitionBlock (\"bhyve_dsdt.aml\", \"DSDT\", 2," "\"BHYVE \", \"BVDSDT \", 0x00000001)\n"); EFPRINTF(fp, "{\n"); + EFPRINTF(fp, " Name (_S5, Package (0x02)\n"); + EFPRINTF(fp, " {\n"); + EFPRINTF(fp, " 0x05,\n"); + EFPRINTF(fp, " Zero,\n"); + EFPRINTF(fp, " })\n"); EFPRINTF(fp, " Scope (_SB)\n"); EFPRINTF(fp, " {\n"); EFPRINTF(fp, " Device (PCI0)\n"); --- //depot/vendor/freebsd/src/usr.sbin/bhyve/bhyverun.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/bhyverun.c @@ -72,6 +72,7 @@ #define VMEXIT_RESTART 2 /* restart current instruction */ #define VMEXIT_ABORT 3 /* abort the vm run loop */ #define VMEXIT_RESET 4 /* guest machine has reset */ +#define VMEXIT_POWEROFF 5 /* guest machine has powered off */ #define MB (1024UL * 1024) #define GB (1024UL * MB) @@ -296,12 +297,17 @@ return (vmexit_handle_notify(ctx, vme, pvcpu, eax)); error = emulate_inout(ctx, vcpu, in, port, bytes, &eax, strictio); - if (error == 0 && in) + if (error == INOUT_OK && in) error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, eax); - if (error == 0) + switch (error) { + case INOUT_OK: return (VMEXIT_CONTINUE); - else { + case INOUT_RESET: + return (VMEXIT_RESET); + case INOUT_POWEROFF: + return (VMEXIT_POWEROFF); + default: fprintf(stderr, "Unhandled %s%c 0x%04x\n", in ? "in" : "out", bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port); --- //depot/vendor/freebsd/src/usr.sbin/bhyve/inout.h +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/inout.h @@ -33,6 +33,12 @@ struct vmctx; +/* Handler return values. */ +#define INOUT_ERROR -1 +#define INOUT_OK 0 +#define INOUT_RESET 1 +#define INOUT_POWEROFF 2 + typedef int (*inout_func_t)(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg); --- /dev/null +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pm.c @@ -0,0 +1,139 @@ +/*- + * Copyright (c) 2013 Advanced Computing Technologies LLC + * Written by: John H. Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD"); + +#include + +#include "inout.h" + +#define PM1A_EVT_ADDR 0x400 +#define PM1A_CNT_ADDR 0x404 + +/* + * Reset Control register at I/O port 0xcf9. Bit 2 forces a system + * reset when it transitions from 0 to 1. Bit 1 selects the type of + * reset to attempt: 0 selects a "soft" reset, and 1 selects a "hard" + * reset. + */ +static int +reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, void *arg) +{ + static uint8_t reset_control; + + if (bytes != 1) + return (-1); + if (in) + *eax = reset_control; + else { + reset_control = *eax; + + /* Treat hard and soft resets the same. */ + if (reset_control & 0x4) + return (INOUT_RESET); + } + return (0); +} +INOUT_PORT(reset_reg, 0xCF9, IOPORT_F_INOUT, reset_handler); + +/* + * Power Management 1 Event Registers + * + * bhyve doesn't support any power management events currently, so the + * status register always returns zero. The enable register preserves + * its value but has no effect. + */ +static int +pm1_status_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, void *arg) +{ + + if (bytes != 2) + return (-1); + if (in) + *eax = 0; + return (0); +} + +static int +pm1_enable_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, void *arg) +{ + static uint16_t pm1_enable; + + if (bytes != 2) + return (-1); + if (in) + *eax = pm1_enable; + else + pm1_enable = *eax; + return (0); +} +INOUT_PORT(pm1_status, PM1A_EVT_ADDR, IOPORT_F_INOUT, pm1_status_handler); +INOUT_PORT(pm1_enable, PM1A_EVT_ADDR + 2, IOPORT_F_INOUT, pm1_enable_handler); + +/* + * Power Management 1 Control Register + * + * This is mostly unimplemented except that we wish to handle writes that + * set SPL_EN to handle S5 (soft power off). + */ +#define PM1_SLP_TYP 0x1c00 +#define PM1_SLP_EN 0x2000 +#define PM1_ALWAYS_ZERO 0xc003 + +static int +pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, void *arg) +{ + static uint16_t pm1_control; + + if (bytes != 2) + return (-1); + if (in) + *eax = pm1_control; + else { + /* + * Various bits are write-only or reserved, so force them + * to zero in pm1_control. + */ + pm1_control = *eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO); + + /* + * If SLP_EN is set, check for S5. Bhyve's _S5_ method + * says that '5' should be stored in SLP_TYP for S5. + */ + if (*eax & PM1_SLP_EN) { + if ((pm1_control & PM1_SLP_TYP) >> 10 == 5) + return (INOUT_POWEROFF); + } + } + return (0); +} +INOUT_PORT(pm1_control, PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); + -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 22:01:46 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8ACF9E18; Mon, 23 Dec 2013 22:01:46 +0000 (UTC) Received: from mail-qe0-x22e.google.com (mail-qe0-x22e.google.com [IPv6:2607:f8b0:400d:c02::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 39A99134B; Mon, 23 Dec 2013 22:01:46 +0000 (UTC) Received: by mail-qe0-f46.google.com with SMTP id a11so5640928qen.19 for ; Mon, 23 Dec 2013 14:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=oydzBh5XiXoLkOPYJ1OcCXckG+JXjQymc5DeSB0rQxo=; b=B7AYsunPqmoDIjTMyBKVouR/2f5EPhWYfD/jq97HoCFpEsIWGTmQlE2/fzfVzYSAGc sH4j6jFUVDHA+OwayddihVQPAUvoB7HD2zSq+uZgtv2s+O4bjq0cMYYAQB8oAmOwb/Bi +A2hOmXbI/UVCYQTtUpKPdc9gf5mfkqthCKADHa27pEQjBkG9hs5PCP/MFhplzZydEOx g0dNM5WHIM+D1CWoStHqeILP7g3ZA5Be9yRg1D77qSNOfkFMxlT0H8HFXQhINEH9ZmnR TiLqiIyKuESqCjU5QR5DtvxMYURYQ/+sfmfsIXh3fswPFJ4aOk6y9aieRNq4FQ9BEdDE X0HA== MIME-Version: 1.0 X-Received: by 10.224.124.134 with SMTP id u6mr46023045qar.79.1387836105378; Mon, 23 Dec 2013 14:01:45 -0800 (PST) Received: by 10.140.34.17 with HTTP; Mon, 23 Dec 2013 14:01:45 -0800 (PST) In-Reply-To: <201312231443.39282.jhb@freebsd.org> References: <201312231443.39282.jhb@freebsd.org> Date: Mon, 23 Dec 2013 14:01:45 -0800 Message-ID: Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve From: Neel Natu To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 22:01:46 -0000 Hi John, This looks good - thanks for adding this support! I noticed that the RESET_REGISTER is not being advertised in the FACP flags field. So, perhaps the access to 0xCF9 that you saw during testing was triggered by cpu_reset_real() as opposed to AcpiReset()? best Neel On Mon, Dec 23, 2013 at 11:43 AM, John Baldwin wrote: > One minor nit I've found annoying is that there is no easy way to break out of > the loop in vmrun.sh. Breaking into the loader prompt and typing 'reboot' > does work, but it requires you to be on the console at the time. What I > really want is for 'shutdown -p' or 'poweroff' inside a guest to cleanly shut > down and exit the loop in vmrun.sh. To that end, I've implemented support for > a few more registers (such of which are non-optional in ACPI) including the > Reset Control register (0xcf9), ACPI Power Management 1 Event registers > (PM1_EVT) and the ACPI Power Management 1 Control register (PM1_CNT). I added > a valid _S5 package and catch writes of the value _S5 specifies to ask bhyve > to exit gracefully but with an exit code of 1 (so the loop in vmrun > terminates). Most of the PM1 support is very simple (it doesn't support > signalling anything for external events as most of them don't make sense). It > does perform a reset for writes to the 0xcf9 register however, and also > advertises 0xcf9 as the ACPI reset register. (Tested by commenting out the > current 0x64 hack.) > > One thing I had to do was make it possible for an I/O port to request a reset > or poweroff, so I added some #define's for additional return codes from > in/out handlers. I haven't gone through and changed any existing handlers to > use the new constants, but the new handlers make use of INOT_RESET and > INOUT_POWEROFF. Note that this also means that the current 0x64 hack could be > reimplemented as an in-out handler rather than a special case. I did not > explicitly catch VMEXIT_POWEROFF and use a custom exit value in the main loop > in bhyverun.c. Instead, I let it fall through to the default and do an > exit(1). The patch is all in bhyve itself: > > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/Makefile > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/Makefile > @@ -10,7 +10,7 @@ > SRCS= acpi.c atpic.c bhyverun.c block_if.c consport.c dbgport.c elcr.c > SRCS+= inout.c legacy_irq.c mem.c mevent.c mptbl.c pci_ahci.c > SRCS+= pci_emul.c pci_hostbridge.c pci_lpc.c pci_passthru.c pci_virtio_block.c > -SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pmtmr.c post.c rtc.c > +SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pm.c pmtmr.c post.c rtc.c > SRCS+= uart_emul.c virtio.c xmsr.c spinup_ap.c > > .PATH: ${.CURDIR}/../../sys/amd64/vmm > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.c > @@ -85,6 +85,8 @@ > #define BHYVE_ASL_SUFFIX ".aml" > #define BHYVE_ASL_COMPILER "/usr/sbin/iasl" > > +#define BHYVE_PM1A_EVT_ADDR 0x400 > +#define BHYVE_PM1A_CNT_ADDR 0x404 > #define BHYVE_PM_TIMER_ADDR 0x408 > > static int basl_keep_temps; > @@ -332,9 +344,11 @@ > EFPRINTF(fp, "[0001]\t\tACPI Disable Value : 00\n"); > EFPRINTF(fp, "[0001]\t\tS4BIOS Command : 00\n"); > EFPRINTF(fp, "[0001]\t\tP-State Control : 00\n"); > - EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : 00000000\n"); > + EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : %08X\n", > + BHYVE_PM1A_EVT_ADDR); > EFPRINTF(fp, "[0004]\t\tPM1B Event Block Address : 00000000\n"); > - EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : 00000000\n"); > + EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : %08X\n", > + BHYVE_PM1A_CNT_ADDR); > EFPRINTF(fp, "[0004]\t\tPM1B Control Block Address : 00000000\n"); > EFPRINTF(fp, "[0004]\t\tPM2 Control Block Address : 00000000\n"); > EFPRINTF(fp, "[0004]\t\tPM Timer Block Address : %08X\n", > @@ -397,10 +411,10 @@ > EFPRINTF(fp, "[0001]\t\tBit Width : 08\n"); > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 01 [Byte Access:8]\n"); > - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); > + EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000CF9\n"); > EFPRINTF(fp, "\n"); > > - EFPRINTF(fp, "[0001]\t\tValue to cause reset : 00\n"); > + EFPRINTF(fp, "[0001]\t\tValue to cause reset : 06\n"); > EFPRINTF(fp, "[0003]\t\tReserved : 000000\n"); > EFPRINTF(fp, "[0008]\t\tFACS Address : 00000000%08X\n", > basl_acpi_base + FACS_OFFSET); > @@ -412,7 +426,8 @@ > EFPRINTF(fp, "[0001]\t\tBit Width : 20\n"); > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); > - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); > + EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > + BHYVE_PM1A_EVT_ADDR); > EFPRINTF(fp, "\n"); > > EFPRINTF(fp, > @@ -431,7 +446,8 @@ > EFPRINTF(fp, "[0001]\t\tBit Width : 10\n"); > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); > - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); > + EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > + BHYVE_PM1A_CNT_ADDR); > EFPRINTF(fp, "\n"); > > EFPRINTF(fp, > @@ -603,6 +619,11 @@ > EFPRINTF(fp, "DefinitionBlock (\"bhyve_dsdt.aml\", \"DSDT\", 2," > "\"BHYVE \", \"BVDSDT \", 0x00000001)\n"); > EFPRINTF(fp, "{\n"); > + EFPRINTF(fp, " Name (_S5, Package (0x02)\n"); > + EFPRINTF(fp, " {\n"); > + EFPRINTF(fp, " 0x05,\n"); > + EFPRINTF(fp, " Zero,\n"); > + EFPRINTF(fp, " })\n"); > EFPRINTF(fp, " Scope (_SB)\n"); > EFPRINTF(fp, " {\n"); > EFPRINTF(fp, " Device (PCI0)\n"); > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/bhyverun.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/bhyverun.c > @@ -72,6 +72,7 @@ > #define VMEXIT_RESTART 2 /* restart current instruction */ > #define VMEXIT_ABORT 3 /* abort the vm run loop */ > #define VMEXIT_RESET 4 /* guest machine has reset */ > +#define VMEXIT_POWEROFF 5 /* guest machine has powered off */ > > #define MB (1024UL * 1024) > #define GB (1024UL * MB) > @@ -296,12 +297,17 @@ > return (vmexit_handle_notify(ctx, vme, pvcpu, eax)); > > error = emulate_inout(ctx, vcpu, in, port, bytes, &eax, strictio); > - if (error == 0 && in) > + if (error == INOUT_OK && in) > error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, eax); > > - if (error == 0) > + switch (error) { > + case INOUT_OK: > return (VMEXIT_CONTINUE); > - else { > + case INOUT_RESET: > + return (VMEXIT_RESET); > + case INOUT_POWEROFF: > + return (VMEXIT_POWEROFF); > + default: > fprintf(stderr, "Unhandled %s%c 0x%04x\n", > in ? "in" : "out", > bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port); > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/inout.h > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/inout.h > @@ -33,6 +33,12 @@ > > struct vmctx; > > +/* Handler return values. */ > +#define INOUT_ERROR -1 > +#define INOUT_OK 0 > +#define INOUT_RESET 1 > +#define INOUT_POWEROFF 2 > + > typedef int (*inout_func_t)(struct vmctx *ctx, int vcpu, int in, int port, > int bytes, uint32_t *eax, void *arg); > > --- /dev/null > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pm.c > @@ -0,0 +1,139 @@ > +/*- > + * Copyright (c) 2013 Advanced Computing Technologies LLC > + * Written by: John H. Baldwin > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > + * SUCH DAMAGE. > + */ > + > +#include > +__FBSDID("$FreeBSD"); > + > +#include > + > +#include "inout.h" > + > +#define PM1A_EVT_ADDR 0x400 > +#define PM1A_CNT_ADDR 0x404 > + > +/* > + * Reset Control register at I/O port 0xcf9. Bit 2 forces a system > + * reset when it transitions from 0 to 1. Bit 1 selects the type of > + * reset to attempt: 0 selects a "soft" reset, and 1 selects a "hard" > + * reset. > + */ > +static int > +reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > + uint32_t *eax, void *arg) > +{ > + static uint8_t reset_control; > + > + if (bytes != 1) > + return (-1); > + if (in) > + *eax = reset_control; > + else { > + reset_control = *eax; > + > + /* Treat hard and soft resets the same. */ > + if (reset_control & 0x4) > + return (INOUT_RESET); > + } > + return (0); > +} > +INOUT_PORT(reset_reg, 0xCF9, IOPORT_F_INOUT, reset_handler); > + > +/* > + * Power Management 1 Event Registers > + * > + * bhyve doesn't support any power management events currently, so the > + * status register always returns zero. The enable register preserves > + * its value but has no effect. > + */ > +static int > +pm1_status_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > + uint32_t *eax, void *arg) > +{ > + > + if (bytes != 2) > + return (-1); > + if (in) > + *eax = 0; > + return (0); > +} > + > +static int > +pm1_enable_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > + uint32_t *eax, void *arg) > +{ > + static uint16_t pm1_enable; > + > + if (bytes != 2) > + return (-1); > + if (in) > + *eax = pm1_enable; > + else > + pm1_enable = *eax; > + return (0); > +} > +INOUT_PORT(pm1_status, PM1A_EVT_ADDR, IOPORT_F_INOUT, pm1_status_handler); > +INOUT_PORT(pm1_enable, PM1A_EVT_ADDR + 2, IOPORT_F_INOUT, pm1_enable_handler); > + > +/* > + * Power Management 1 Control Register > + * > + * This is mostly unimplemented except that we wish to handle writes that > + * set SPL_EN to handle S5 (soft power off). > + */ > +#define PM1_SLP_TYP 0x1c00 > +#define PM1_SLP_EN 0x2000 > +#define PM1_ALWAYS_ZERO 0xc003 > + > +static int > +pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > + uint32_t *eax, void *arg) > +{ > + static uint16_t pm1_control; > + > + if (bytes != 2) > + return (-1); > + if (in) > + *eax = pm1_control; > + else { > + /* > + * Various bits are write-only or reserved, so force them > + * to zero in pm1_control. > + */ > + pm1_control = *eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO); > + > + /* > + * If SLP_EN is set, check for S5. Bhyve's _S5_ method > + * says that '5' should be stored in SLP_TYP for S5. > + */ > + if (*eax & PM1_SLP_EN) { > + if ((pm1_control & PM1_SLP_TYP) >> 10 == 5) > + return (INOUT_POWEROFF); > + } > + } > + return (0); > +} > +INOUT_PORT(pm1_control, PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); > + > > > -- > John Baldwin > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org" From owner-freebsd-virtualization@FreeBSD.ORG Mon Dec 23 22:08:56 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4D7B8FA2 for ; Mon, 23 Dec 2013 22:08:56 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E68D51380 for ; Mon, 23 Dec 2013 22:08:55 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id F3CD1B917; Mon, 23 Dec 2013 17:08:54 -0500 (EST) From: John Baldwin To: Neel Natu Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve Date: Mon, 23 Dec 2013 17:08:45 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <201312231443.39282.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201312231708.45431.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 23 Dec 2013 17:08:55 -0500 (EST) Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Mon, 23 Dec 2013 22:08:56 -0000 On Monday, December 23, 2013 5:01:45 pm Neel Natu wrote: > Hi John, > > This looks good - thanks for adding this support! > > I noticed that the RESET_REGISTER is not being advertised in the FACP > flags field. So, perhaps the access to 0xCF9 that you saw during > testing was triggered by cpu_reset_real() as opposed to AcpiReset()? Yeah, that might explain why I had to comment out the 0x64 check in bhyverun.c directly as AcpiReset() should take precedence before cpu_reset_real() is invoked. I'll retest that tomorrow to make sure I have the FACP correct. > best > Neel > > On Mon, Dec 23, 2013 at 11:43 AM, John Baldwin wrote: > > One minor nit I've found annoying is that there is no easy way to break out of > > the loop in vmrun.sh. Breaking into the loader prompt and typing 'reboot' > > does work, but it requires you to be on the console at the time. What I > > really want is for 'shutdown -p' or 'poweroff' inside a guest to cleanly shut > > down and exit the loop in vmrun.sh. To that end, I've implemented support for > > a few more registers (such of which are non-optional in ACPI) including the > > Reset Control register (0xcf9), ACPI Power Management 1 Event registers > > (PM1_EVT) and the ACPI Power Management 1 Control register (PM1_CNT). I added > > a valid _S5 package and catch writes of the value _S5 specifies to ask bhyve > > to exit gracefully but with an exit code of 1 (so the loop in vmrun > > terminates). Most of the PM1 support is very simple (it doesn't support > > signalling anything for external events as most of them don't make sense). It > > does perform a reset for writes to the 0xcf9 register however, and also > > advertises 0xcf9 as the ACPI reset register. (Tested by commenting out the > > current 0x64 hack.) > > > > One thing I had to do was make it possible for an I/O port to request a reset > > or poweroff, so I added some #define's for additional return codes from > > in/out handlers. I haven't gone through and changed any existing handlers to > > use the new constants, but the new handlers make use of INOT_RESET and > > INOUT_POWEROFF. Note that this also means that the current 0x64 hack could be > > reimplemented as an in-out handler rather than a special case. I did not > > explicitly catch VMEXIT_POWEROFF and use a custom exit value in the main loop > > in bhyverun.c. Instead, I let it fall through to the default and do an > > exit(1). The patch is all in bhyve itself: > > > > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/Makefile > > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/Makefile > > @@ -10,7 +10,7 @@ > > SRCS= acpi.c atpic.c bhyverun.c block_if.c consport.c dbgport.c elcr.c > > SRCS+= inout.c legacy_irq.c mem.c mevent.c mptbl.c pci_ahci.c > > SRCS+= pci_emul.c pci_hostbridge.c pci_lpc.c pci_passthru.c pci_virtio_block.c > > -SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pmtmr.c post.c rtc.c > > +SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pm.c pmtmr.c post.c rtc.c > > SRCS+= uart_emul.c virtio.c xmsr.c spinup_ap.c > > > > .PATH: ${.CURDIR}/../../sys/amd64/vmm > > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.c > > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.c > > @@ -85,6 +85,8 @@ > > #define BHYVE_ASL_SUFFIX ".aml" > > #define BHYVE_ASL_COMPILER "/usr/sbin/iasl" > > > > +#define BHYVE_PM1A_EVT_ADDR 0x400 > > +#define BHYVE_PM1A_CNT_ADDR 0x404 > > #define BHYVE_PM_TIMER_ADDR 0x408 > > > > static int basl_keep_temps; > > @@ -332,9 +344,11 @@ > > EFPRINTF(fp, "[0001]\t\tACPI Disable Value : 00\n"); > > EFPRINTF(fp, "[0001]\t\tS4BIOS Command : 00\n"); > > EFPRINTF(fp, "[0001]\t\tP-State Control : 00\n"); > > - EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : 00000000\n"); > > + EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : %08X\n", > > + BHYVE_PM1A_EVT_ADDR); > > EFPRINTF(fp, "[0004]\t\tPM1B Event Block Address : 00000000\n"); > > - EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : 00000000\n"); > > + EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : %08X\n", > > + BHYVE_PM1A_CNT_ADDR); > > EFPRINTF(fp, "[0004]\t\tPM1B Control Block Address : 00000000\n"); > > EFPRINTF(fp, "[0004]\t\tPM2 Control Block Address : 00000000\n"); > > EFPRINTF(fp, "[0004]\t\tPM Timer Block Address : %08X\n", > > @@ -397,10 +411,10 @@ > > EFPRINTF(fp, "[0001]\t\tBit Width : 08\n"); > > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 01 [Byte Access:8]\n"); > > - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); > > + EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000CF9\n"); > > EFPRINTF(fp, "\n"); > > > > - EFPRINTF(fp, "[0001]\t\tValue to cause reset : 00\n"); > > + EFPRINTF(fp, "[0001]\t\tValue to cause reset : 06\n"); > > EFPRINTF(fp, "[0003]\t\tReserved : 000000\n"); > > EFPRINTF(fp, "[0008]\t\tFACS Address : 00000000%08X\n", > > basl_acpi_base + FACS_OFFSET); > > @@ -412,7 +426,8 @@ > > EFPRINTF(fp, "[0001]\t\tBit Width : 20\n"); > > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); > > - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); > > + EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > > + BHYVE_PM1A_EVT_ADDR); > > EFPRINTF(fp, "\n"); > > > > EFPRINTF(fp, > > @@ -431,7 +446,8 @@ > > EFPRINTF(fp, "[0001]\t\tBit Width : 10\n"); > > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); > > - EFPRINTF(fp, "[0008]\t\tAddress : 0000000000000001\n"); > > + EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > > + BHYVE_PM1A_CNT_ADDR); > > EFPRINTF(fp, "\n"); > > > > EFPRINTF(fp, > > @@ -603,6 +619,11 @@ > > EFPRINTF(fp, "DefinitionBlock (\"bhyve_dsdt.aml\", \"DSDT\", 2," > > "\"BHYVE \", \"BVDSDT \", 0x00000001)\n"); > > EFPRINTF(fp, "{\n"); > > + EFPRINTF(fp, " Name (_S5, Package (0x02)\n"); > > + EFPRINTF(fp, " {\n"); > > + EFPRINTF(fp, " 0x05,\n"); > > + EFPRINTF(fp, " Zero,\n"); > > + EFPRINTF(fp, " })\n"); > > EFPRINTF(fp, " Scope (_SB)\n"); > > EFPRINTF(fp, " {\n"); > > EFPRINTF(fp, " Device (PCI0)\n"); > > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/bhyverun.c > > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/bhyverun.c > > @@ -72,6 +72,7 @@ > > #define VMEXIT_RESTART 2 /* restart current instruction */ > > #define VMEXIT_ABORT 3 /* abort the vm run loop */ > > #define VMEXIT_RESET 4 /* guest machine has reset */ > > +#define VMEXIT_POWEROFF 5 /* guest machine has powered off */ > > > > #define MB (1024UL * 1024) > > #define GB (1024UL * MB) > > @@ -296,12 +297,17 @@ > > return (vmexit_handle_notify(ctx, vme, pvcpu, eax)); > > > > error = emulate_inout(ctx, vcpu, in, port, bytes, &eax, strictio); > > - if (error == 0 && in) > > + if (error == INOUT_OK && in) > > error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, eax); > > > > - if (error == 0) > > + switch (error) { > > + case INOUT_OK: > > return (VMEXIT_CONTINUE); > > - else { > > + case INOUT_RESET: > > + return (VMEXIT_RESET); > > + case INOUT_POWEROFF: > > + return (VMEXIT_POWEROFF); > > + default: > > fprintf(stderr, "Unhandled %s%c 0x%04x\n", > > in ? "in" : "out", > > bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port); > > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/inout.h > > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/inout.h > > @@ -33,6 +33,12 @@ > > > > struct vmctx; > > > > +/* Handler return values. */ > > +#define INOUT_ERROR -1 > > +#define INOUT_OK 0 > > +#define INOUT_RESET 1 > > +#define INOUT_POWEROFF 2 > > + > > typedef int (*inout_func_t)(struct vmctx *ctx, int vcpu, int in, int port, > > int bytes, uint32_t *eax, void *arg); > > > > --- /dev/null > > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pm.c > > @@ -0,0 +1,139 @@ > > +/*- > > + * Copyright (c) 2013 Advanced Computing Technologies LLC > > + * Written by: John H. Baldwin > > + * All rights reserved. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + * notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + * notice, this list of conditions and the following disclaimer in the > > + * documentation and/or other materials provided with the distribution. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > > + * SUCH DAMAGE. > > + */ > > + > > +#include > > +__FBSDID("$FreeBSD"); > > + > > +#include > > + > > +#include "inout.h" > > + > > +#define PM1A_EVT_ADDR 0x400 > > +#define PM1A_CNT_ADDR 0x404 > > + > > +/* > > + * Reset Control register at I/O port 0xcf9. Bit 2 forces a system > > + * reset when it transitions from 0 to 1. Bit 1 selects the type of > > + * reset to attempt: 0 selects a "soft" reset, and 1 selects a "hard" > > + * reset. > > + */ > > +static int > > +reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > > + uint32_t *eax, void *arg) > > +{ > > + static uint8_t reset_control; > > + > > + if (bytes != 1) > > + return (-1); > > + if (in) > > + *eax = reset_control; > > + else { > > + reset_control = *eax; > > + > > + /* Treat hard and soft resets the same. */ > > + if (reset_control & 0x4) > > + return (INOUT_RESET); > > + } > > + return (0); > > +} > > +INOUT_PORT(reset_reg, 0xCF9, IOPORT_F_INOUT, reset_handler); > > + > > +/* > > + * Power Management 1 Event Registers > > + * > > + * bhyve doesn't support any power management events currently, so the > > + * status register always returns zero. The enable register preserves > > + * its value but has no effect. > > + */ > > +static int > > +pm1_status_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > > + uint32_t *eax, void *arg) > > +{ > > + > > + if (bytes != 2) > > + return (-1); > > + if (in) > > + *eax = 0; > > + return (0); > > +} > > + > > +static int > > +pm1_enable_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > > + uint32_t *eax, void *arg) > > +{ > > + static uint16_t pm1_enable; > > + > > + if (bytes != 2) > > + return (-1); > > + if (in) > > + *eax = pm1_enable; > > + else > > + pm1_enable = *eax; > > + return (0); > > +} > > +INOUT_PORT(pm1_status, PM1A_EVT_ADDR, IOPORT_F_INOUT, pm1_status_handler); > > +INOUT_PORT(pm1_enable, PM1A_EVT_ADDR + 2, IOPORT_F_INOUT, pm1_enable_handler); > > + > > +/* > > + * Power Management 1 Control Register > > + * > > + * This is mostly unimplemented except that we wish to handle writes that > > + * set SPL_EN to handle S5 (soft power off). > > + */ > > +#define PM1_SLP_TYP 0x1c00 > > +#define PM1_SLP_EN 0x2000 > > +#define PM1_ALWAYS_ZERO 0xc003 > > + > > +static int > > +pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > > + uint32_t *eax, void *arg) > > +{ > > + static uint16_t pm1_control; > > + > > + if (bytes != 2) > > + return (-1); > > + if (in) > > + *eax = pm1_control; > > + else { > > + /* > > + * Various bits are write-only or reserved, so force them > > + * to zero in pm1_control. > > + */ > > + pm1_control = *eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO); > > + > > + /* > > + * If SLP_EN is set, check for S5. Bhyve's _S5_ method > > + * says that '5' should be stored in SLP_TYP for S5. > > + */ > > + if (*eax & PM1_SLP_EN) { > > + if ((pm1_control & PM1_SLP_TYP) >> 10 == 5) > > + return (INOUT_POWEROFF); > > + } > > + } > > + return (0); > > +} > > +INOUT_PORT(pm1_control, PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); > > + > > > > > > -- > > John Baldwin > > _______________________________________________ > > freebsd-virtualization@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > > To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org" > -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 00:24:46 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A0D33D00; Tue, 24 Dec 2013 00:24:46 +0000 (UTC) Received: from mail-we0-x233.google.com (mail-we0-x233.google.com [IPv6:2a00:1450:400c:c03::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E18F71CD2; Tue, 24 Dec 2013 00:24:45 +0000 (UTC) Received: by mail-we0-f179.google.com with SMTP id q59so5528054wes.10 for ; Mon, 23 Dec 2013 16:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3lU3asYcaSZxTDw39+OcgCWA+YsB/it7/arFQ9KCzg4=; b=X0uln1xdWyS6x+JZG1CXBn/tvfEzmGv8ifHO2HuHUAwxUmX/buYB9Unu0xSmN2zyE7 ph0tyNRVa5Pr6mtJ60IKfk8WWXKDVAheszo5JaHiqoW7TXhI1NLlwu31aEUliIFYCOCc G/g/kfUQIU+LKtZgbfQSucyswNPIkApvu8KOeXv6QafYyiry/Kcu9tfbEaeUb1r/o1sI 2KWBZfVAggos9HTDObvVDCTu/DtoRDQ7KjOw6S/3qW/44nph6WLGBsVmeuYA0FPnEne9 nGU0h3VQVdZLygshVxP6jAbbGfsElCh2nzqfYqkh+h5oR0YbUYNd71f4wpA2/pbs9/6J D7Hg== MIME-Version: 1.0 X-Received: by 10.180.12.3 with SMTP id u3mr7597340wib.27.1387844684044; Mon, 23 Dec 2013 16:24:44 -0800 (PST) Received: by 10.227.226.12 with HTTP; Mon, 23 Dec 2013 16:24:43 -0800 (PST) In-Reply-To: References: <201312131304.57455.jhb@freebsd.org> Date: Tue, 24 Dec 2013 02:24:43 +0200 Message-ID: Subject: Re: 11.0-CURRENT panic while running a bhyve instance From: Markiyan Kushnir To: Neel Natu Content-Type: text/plain; charset=ISO-8859-1 Cc: FreeBSD current , "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 00:24:46 -0000 Works for me (I'm at r259742), no panic. Thanks! -- Markiyan. 2013/12/23 Neel Natu : > Hi Markiyan, > > Fixed in r259737: > http://svnweb.freebsd.org/changeset/base/259737 > > best > Neel > > On Fri, Dec 13, 2013 at 2:35 PM, Markiyan Kushnir > wrote: >> 2013/12/13 John Baldwin : >>> On Friday, December 13, 2013 5:46:20 am Markiyan Kushnir wrote: >>>> Forgot to fill the Subject: header, re-posting it fixed. >>> >>> The mailing lists strips attachments, can you post it at a URL? >>> >> >> Shared here: >> >> https://drive.google.com/file/d/0B9Q-zpUXxqCnem5iYTVqLUxrcWo4cmlhdkM1c2lJa2dKak5R/edit?usp=sharing >> >> -- >> Markiyan. >> >>>> -- >>>> Markiyan >>>> >>>> >>>> ---------- Forwarded message ---------- >>>> From: Markiyan Kushnir >>>> Date: 2013/12/13 >>>> Subject: >>>> To: freebsd-current@freebsd.org, freebsd-virtualization@freebsd.org >>>> >>>> >>>> I started some ports to compile inside a bhyve instance: >>>> >>>> root@vm:~ # uname -a >>>> FreeBSD vm.mkushnir.mooo.com 11.0-CURRENT FreeBSD 11.0-CURRENT #0 >>>> r259250: Thu Dec 12 14:17:32 EET 2013 >>>> root@vm.mkushnir.zapto.org:/ >>>> usr/obj/usr/src.svnup/sys/MAREK amd64 >>>> >>>> and left it running unattended. Approx. 2 hours later the host went to >>>> panic. The bhyve instance survived after the panic and I could be able >>>> to complete my ports compilation. >>>> >>>> core.txt attached (gzipped) >>>> _______________________________________________ >>>> freebsd-current@freebsd.org mailing list >>>> http://lists.freebsd.org/mailman/listinfo/freebsd-current >>>> To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >>>> >>> >>> -- >>> John Baldwin >> _______________________________________________ >> freebsd-current@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-current >> To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 06:03:50 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2A4B062D for ; Tue, 24 Dec 2013 06:03:50 +0000 (UTC) Received: from mail-la0-x234.google.com (mail-la0-x234.google.com [IPv6:2a00:1450:4010:c03::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A805D11C6 for ; Tue, 24 Dec 2013 06:03:49 +0000 (UTC) Received: by mail-la0-f52.google.com with SMTP id y1so2707749lam.11 for ; Mon, 23 Dec 2013 22:03:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=6JgEz1sjc6fvASCZVW0VoijljP8PWMhQPnInB1W+krw=; b=1FF/NriQZ9KBGwYYiohFWTLuuFnf7Duc6yy/STtEPgxRGQ+EoXlQPn4vOqhQlWRYS/ N6LB+xB7fhCJwrFdTwdVaKgYKLl0iwKveHhjYTQsN/OhcxRQ50TXAaJUvhYnmM82lOfC PVAmRZ1AqTkWoZjDnLSyvsaASJ6197DJ33gpvWhVHrOsLDgfA6j2dSkLRXKPSDWlC7/A 8qzwKPoYRT278bFwjCb7Ubwf+Vxb+5SO5VqAJdIBFBMQnuQTm7jk2DcnWKSK0O8tSGRN Vv0/jrbV4267WSC8lrJov4B0eBnj0nHy4veGydUt3Wyq9e1Gdb3XJxU3zc99wxDnHojX EZ6g== MIME-Version: 1.0 X-Received: by 10.112.168.199 with SMTP id zy7mr4620lbb.68.1387865027463; Mon, 23 Dec 2013 22:03:47 -0800 (PST) Sender: crodr001@gmail.com Received: by 10.114.181.101 with HTTP; Mon, 23 Dec 2013 22:03:47 -0800 (PST) Date: Mon, 23 Dec 2013 22:03:47 -0800 X-Google-Sender-Auth: VVP9iHkjyEhr90I9DBi9PpNtBpA Message-ID: Subject: Booting a disk image with GRUB in BHyve? From: Craig Rodrigues To: "freebsd-virtualization@freebsd.org" Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 06:03:50 -0000 Hi, I tried the following: (1) Downloaded SmartOS USB image from: http://wiki.smartos.org/display/DOC/Download+SmartOS (2) Uncompressed the bz2 file. (3) Ran "file" on the binary: # file smartos-latest-USB.img smartos-latest-USB.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0xc, starthead 1, startsector 63, 3903732 sectors, extended partition table (last)\011, code offset 0x48 (4) Tried vmrun.sh: sh /usr/share/examples/bhyve/vmrun.sh -d ./smartos-latest-USB.img -m 4G smartos_vm1 I got this error: ================================================= Launching virtual machine "smartos_vm1" ... Consoles: userboot FreeBSD/amd64 User boot, Revision 1.1 (rodrigc@pcbsd-4708, Mon Oct 14 14:36:53 PDT 2013) \ can't load 'kernel' Type '?' for a list of commands, 'help' for more detailed help. OK ==================================================== How can I boot something which uses GRUB bootloader in BHyve? Thanks. -- From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 06:18:23 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6D2C87EB; Tue, 24 Dec 2013 06:18:23 +0000 (UTC) Received: from alto.onthenet.com.au (alto.OntheNet.com.au [203.13.68.12]) by mx1.freebsd.org (Postfix) with ESMTP id 2C390125E; Tue, 24 Dec 2013 06:18:22 +0000 (UTC) Received: from dommail.onthenet.com.au (dommail.OntheNet.com.au [203.13.70.57]) by alto.onthenet.com.au (Postfix) with ESMTPS id 6D93B122F6; Tue, 24 Dec 2013 16:18:13 +1000 (EST) Received: from Peters-MacBook-Pro.local (c-71-196-188-222.hsd1.co.comcast.net [71.196.188.222]) by dommail.onthenet.com.au (MOS 4.2.4-GA) with ESMTP id BQW62635 (AUTH peterg@ptree32.com.au); Tue, 24 Dec 2013 16:18:12 +1000 Message-ID: <52B9271A.503@freebsd.org> Date: Mon, 23 Dec 2013 23:18:02 -0700 From: Peter Grehan User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Craig Rodrigues Subject: Re: Booting a disk image with GRUB in BHyve? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 06:18:23 -0000 Hi Craig, > (4) Tried vmrun.sh: vmrun.sh is FreeBSD-only. > How can I boot something which uses GRUB bootloader in BHyve? There is a user-space port of grub2 that allows a number of Linux distros to boot (sysutils/grub2-bhyve). However, for Linux distros such as rhel/centos 6.* that use grub-1, it's somewhat of a manual process. Illumos/SmartOS is a different kettle of fish. It's grub-1, but the the o/s itself presents a number of issues that are still being worked through (BIOS calls, timer modes/calibration etc). later, Peter. From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 09:59:47 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4DEE7E43 for ; Tue, 24 Dec 2013 09:59:47 +0000 (UTC) Received: from mail-pd0-f172.google.com (mail-pd0-f172.google.com [209.85.192.172]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1E6C81FA5 for ; Tue, 24 Dec 2013 09:59:46 +0000 (UTC) Received: by mail-pd0-f172.google.com with SMTP id g10so6153192pdj.31 for ; Tue, 24 Dec 2013 01:59:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=qWB2xiLM/7008F7itr1aA8JwK81pGYoW+u5Er0eYSE8=; b=VsLkut1jVpaeLpaNcEGbrm4RRFAaQhPNP7V5981m8URBPjc6hXpSpTM2GRooxw6tqV fQ2orqDjiI1wZTJpLupscpikQjjxcbx2NTvKuANBGPcizqMyOB3Ripkz+X8+raainWPT 3V6tSup6Ml0Y652aUYdUIVGF9iKMFI0DQ4Nr4On1cnQcWS8eL6cK0pS50AThBLZHyxLd zUJ2loSrKUk7BJ0fNyOIyJaU3A7TmKugfN+zZtvwaPBrjYQqwu6V9TRXr7Ue5w+AWcm0 03eoW15gCjqqCGo6iC2XzBsU2jcfbE19ZamY50anqVLvUCGmFP9agJNm9XydfWRvW3w5 W2fg== X-Gm-Message-State: ALoCoQm4WeuPUkvLVPpTOCwTrc8CmNFR4laMHbb078B2dRtGDlMAw+bl7XR1Aw9eQiNsBQVpogN2 X-Received: by 10.68.204.136 with SMTP id ky8mr31769897pbc.33.1387879180512; Tue, 24 Dec 2013 01:59:40 -0800 (PST) Received: from Michaels-MacBook-Pro.local (ip70-185-178-226.sb.sd.cox.net. [70.185.178.226]) by mx.google.com with ESMTPSA id dq3sm40394085pbc.35.2013.12.24.01.59.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Dec 2013 01:59:39 -0800 (PST) Message-ID: <52B95B14.7000603@callfortesting.org> Date: Tue, 24 Dec 2013 01:59:48 -0800 From: Michael Dexter User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Peter Grehan , Craig Rodrigues Subject: Re: Booting a disk image with GRUB in BHyve? References: <52B9271A.503@freebsd.org> In-Reply-To: <52B9271A.503@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 09:59:47 -0000 On 12/23/13 10:18 PM, Peter Grehan wrote: >> How can I boot something which uses GRUB bootloader in BHyve? > > There is a user-space port of grub2 that allows a number of Linux > distros to boot (sysutils/grub2-bhyve). However, for Linux distros such > as rhel/centos 6.* that use grub-1, it's somewhat of a manual process. I have made some significant improvements to my "bhyve-script" at: http://bhyve.org/bhyve-script.tar It now automatically retrieves and installs Ubuntu and Debian plus FreeNAS with one manual step and pfSense with a few manual steps. It also supports nmdm, lpc and tmux consoles/multiplexing. Michael From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 15:55:46 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8B6572D7 for ; Tue, 24 Dec 2013 15:55:46 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 635BD1CAB for ; Tue, 24 Dec 2013 15:55:46 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 667C7B968; Tue, 24 Dec 2013 10:55:45 -0500 (EST) From: John Baldwin To: Neel Natu Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve Date: Tue, 24 Dec 2013 10:55:40 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <201312231443.39282.jhb@freebsd.org> <201312231708.45431.jhb@freebsd.org> In-Reply-To: <201312231708.45431.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201312241055.40217.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 24 Dec 2013 10:55:45 -0500 (EST) Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 15:55:46 -0000 On Monday, December 23, 2013 5:08:45 pm John Baldwin wrote: > On Monday, December 23, 2013 5:01:45 pm Neel Natu wrote: > > Hi John, > > > > This looks good - thanks for adding this support! > > > > I noticed that the RESET_REGISTER is not being advertised in the FACP > > flags field. So, perhaps the access to 0xCF9 that you saw during > > testing was triggered by cpu_reset_real() as opposed to AcpiReset()? > > Yeah, that might explain why I had to comment out the 0x64 check in > bhyverun.c directly as AcpiReset() should take precedence before > cpu_reset_real() is invoked. I'll retest that tomorrow to make sure I have > the FACP correct. With that fixed, ACPI now resets via 0xcf9 before trying 0x64. -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 19:15:03 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 14F59945 for ; Tue, 24 Dec 2013 19:15:03 +0000 (UTC) Received: from mail-pd0-f173.google.com (mail-pd0-f173.google.com [209.85.192.173]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id DBEDF18F2 for ; Tue, 24 Dec 2013 19:15:02 +0000 (UTC) Received: by mail-pd0-f173.google.com with SMTP id p10so6583394pdj.32 for ; Tue, 24 Dec 2013 11:14:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=sMWeaf/zyLzt0lP6wCcFrRzY9UUu3vtWYCL1mIIGObk=; b=hlll2Tu3pDMfUPXG4aZfqeiDSgtBAJoroiLvPBaPB2m8ZZLBL/8ZVbLrXDZiZVw8VL /lfWbCTW4K0J6CVksUs5iIBjpkVtgSul2jpufRFaKM9FoODT54g0IK7Z/kkY9fXQwv8+ NBbd8YVdBgIBwOIFWHsloQJ7dy71uGhe70jF36qHpRUQI6Ppzy9XoQe0fVC+8O2ro6/F pw0Y0hYTZrN/Ego0SC/qipfvs92zYVFL1wXiPUFG5ORelE9oHUZDkDaZU2z2mX6KpbtQ BiTO8pWzaGuMNGQiY9DEpATawwHNflyLbRrYtIiOfXrLZ/1EUv2wVY4g6RxP3repvirS hrrA== X-Gm-Message-State: ALoCoQm7OEudqcITTVzayR7ipSb2lze+iACXhkCiHsFA/fx7EPYEmpocTH5tThtCG3x7btPK7v71 MIME-Version: 1.0 X-Received: by 10.68.238.226 with SMTP id vn2mr34364758pbc.50.1387912495745; Tue, 24 Dec 2013 11:14:55 -0800 (PST) Received: by 10.70.36.232 with HTTP; Tue, 24 Dec 2013 11:14:55 -0800 (PST) Date: Tue, 24 Dec 2013 14:14:55 -0500 Message-ID: Subject: 30-day Public Review for Virtual I/O Device (VIRTIO) Version 1.0 From: Paul Knight To: members@lists.oasis-open.org, virtio@lists.oasis-open.org, tc-announce@lists.oasis-open.org, virtualization@lists.linux-foundation.org, freebsd-virtualization@freebsd.org, qemu-devel@nongnu.org, xen-devel@lists.xenproject.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 19:15:03 -0000 Season's greetings all: The OASIS Virtual I/O Device (VIRTIO) TC [1] members have recently approved a Committee Specification Draft (CSD) and submitted this specification for 30-day(*) public review: Virtual I/O Device (VIRTIO) Version 1.0 Committee Specification Draft 01 / Public Review Draft 01 03 December 2013 Specification Overview: This document describes the specifications of the "virtio" family of devices. These devices are found in virtual environments, yet by design they are not all that different from physical devices, and this document treats them as such. This allows the guest to use standard drivers and discovery mechanisms. The purpose of virtio and this specification is that virtual environments and guests should have a straightforward, efficient, standard and extensible mechanism for virtual devices, rather than boutique per-environment or per-OS mechanisms. This is the first public review draft, after months of hard work by the VIRTIO Technical Committee. TC Description: The goal of the OASIS Virtual I/O Device (VIRTIO) TC is to simplify virtual devices, making them more extensible and more recognizable. The purpose of VIRTIO is to ensure that virtual environments and guests have a straightforward, efficient, standard, and extensible mechanism for virtual devices, rather than boutique per-environment or per-OS mechanisms. Public Review Period: (*) The TC has requested an extended Public Review period due to the holiday season. The public review starts 00:00 GMT 25 December 2013 and ends 23:59 GMT 31 January 2014. This is an open invitation to comment. OASIS solicits feedback from potential users, developers and others, whether OASIS members or not, for the sake of improving the interoperability and quality of its technical work. URIs: The prose specification document and related files are available here: PDF (Authoritative): http://docs.oasis-open.org/virtio/virtio/v1.0/csprd01/virtio-v1.0-csprd01.pdf HTML: http://docs.oasis-open.org/virtio/virtio/v1.0/csprd01/virtio-v1.0-csprd01.html Editable TeX Source: http://docs.oasis-open.org/virtio/virtio/v1.0/csprd01/tex/ For your convenience, OASIS provides a complete package of the prose specification and related files in a ZIP distribution file. You can download the ZIP file here: http://docs.oasis-open.org/virtio/virtio/v1.0/csprd01/virtio-v1.0-csprd01.zip Additional information about the specification and the OASIS Virtual I/O Device (VIRTIO) TC can be found at the TC's public home page: https://www.oasis-open.org/committees/virtio/ Comments may be submitted to the TC by any person through the use of the OASIS TC Comment Facility which can be located via the button labeled "Send A Comment" at the top of the TC public home, or directly at: https://www.oasis-open.org/committees/comments/index.php?wg_abbrev=virtio Comments submitted by TC non-members for this work and for other work of this TC are publicly archived and can be viewed at: https://lists.oasis-open.org/archives/virtio-comment/ All comments submitted to OASIS are subject to the OASIS Feedback License, which ensures that the feedback you provide carries the same obligations at least as the obligations of the TC members. In connection with this public review of "Virtual I/O Device (VIRTIO) Version 1.0", we call your attention to the OASIS IPR Policy [2] applicable especially [3] to the work of this technical committee. All members of the TC should be familiar with this document, which may create obligations regarding the disclosure and availability of a member's patent, copyright, trademark and license rights that read on an approved OASIS specification. OASIS invites any persons who know of any such claims to disclose these if they may be essential to the implementation of the above specification, so that notice of them may be posted to the notice page for this TC's work. ========== Additional references: [1] OASIS Virtual I/O Device (VIRTIO) TC https://www.oasis-open.org/committees/virtio/ [2] http://www.oasis-open.org/who/intellectualproperty.php [3] http://www.oasis-open.org/committees/virtio/ipr.php https://www.oasis-open.org/policies-guidelines/ipr#s10.3 Non-Assertion IPR Mode Best regards, Paul -- Paul Knight - Tel: +1 781-861-1013 OASIS - Advancing open standards for the information society Document Process Analyst From owner-freebsd-virtualization@FreeBSD.ORG Tue Dec 24 23:13:59 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 058D7E22 for ; Tue, 24 Dec 2013 23:13:59 +0000 (UTC) Received: from btw.pki2.com (btw.pki2.com [IPv6:2001:470:a:6fd::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A157C1868 for ; Tue, 24 Dec 2013 23:13:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by btw.pki2.com (8.14.7/8.14.5) with ESMTP id rBONDktW000125 for ; Tue, 24 Dec 2013 15:13:46 -0800 (PST) (envelope-from freebsd@pki2.com) Subject: nmdm doesn't create entries in /dev (10.0-RC2+) From: Dennis Glatting To: freebsd-virtualization@freebsd.org Content-Type: text/plain; charset="ISO-8859-1" Date: Tue, 24 Dec 2013 15:13:46 -0800 Message-ID: <1387926826.71651.129.camel@btw.pki2.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-yoursite-MailScanner-Information: Dennis Glatting X-yoursite-MailScanner-ID: rBONDktW000125 X-yoursite-MailScanner: Found to be clean X-MailScanner-From: freebsd@pki2.com X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 24 Dec 2013 23:13:59 -0000 Bhyve newbie trying to get it to start. I am getting the FreeBSD loader but it then exits when the loader goes to boot. I've also found "kldload nmdm" does not create any entries in /dev. Isn't it suppose to? I'm not sure what I am doing wrong. System: Elmer# uname -a FreeBSD Elmer 10.0-PRERELEASE FreeBSD 10.0-PRERELEASE #0 r259838: Tue Dec 24 15:21:17 MST 2013 root@Elmer:/disk-2/obj/usr/src/sys/PENFORD-FreeBSD10-amd64 amd64 I am executing the following instructions: kldload nmdm kldload vmm kldload if_tap ifconfig tap0 create ./vmrun.sh -c 4 -d /disk-2/VMs/nms.img -i -I /disk-3/tmp/FreeBSD-10.0-RC2-amd64-disc1.iso -m 2G -t /dev/tap0 nms Some data: Elmer# ls -lh /disk-2/VMs/nms.img -rw-r--r-- 1 root wheel 24G Dec 24 13:16 /disk-2/VMs/nms.img Elmer# file /disk-2/VMs/nms.img /disk-2/VMs/nms.img: data Elmer# ls -lh /disk-3/tmp/FreeBSD-10.0-RC2-amd64-disc1.iso -rw-r--r-- 1 root wheel 622M Dec 15 01:59 /disk-3/tmp/FreeBSD-10.0-RC2-amd64-disc1.iso Elmer# dmesg|more Copyright (c) 1992-2013 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD is a registered trademark of The FreeBSD Foundation. FreeBSD 10.0-PRERELEASE #0 r259838: Tue Dec 24 15:21:17 MST 2013 root@Elmer:/disk-2/obj/usr/src/sys/PENFORD-FreeBSD10-amd64 amd64 FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610 CPU: Intel(R) Xeon(R) CPU E5540 @ 2.53GHz (2533.47-MHz K8-class CPU) Origin = "GenuineIntel" Id = 0x106a5 Family = 0x6 Model = 0x1a Stepping = 5 Features=0xbfebfbff Features2=0x9ce3bd AMD Features=0x28100800 AMD Features2=0x1 TSC: P-state invariant, performance statistics real memory = 42949672960 (40960 MB) avail memory = 41654677504 (39724 MB) Event timer "LAPIC" quality 400 ACPI APIC Table: FreeBSD/SMP: Multiprocessor System Detected: 16 CPUs FreeBSD/SMP: 2 package(s) x 4 core(s) x 2 SMT threads ... From owner-freebsd-virtualization@FreeBSD.ORG Wed Dec 25 00:28:20 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7BCBEE89 for ; Wed, 25 Dec 2013 00:28:20 +0000 (UTC) Received: from alto.onthenet.com.au (alto.OntheNet.com.au [203.13.68.12]) by mx1.freebsd.org (Postfix) with ESMTP id 3CE041DE9 for ; Wed, 25 Dec 2013 00:28:20 +0000 (UTC) Received: from dommail.onthenet.com.au (dommail.OntheNet.com.au [203.13.70.57]) by alto.onthenet.com.au (Postfix) with ESMTPS id 07B5512373; Wed, 25 Dec 2013 10:28:18 +1000 (EST) Received: from Peters-MacBook-Pro.local (c-71-196-188-222.hsd1.co.comcast.net [71.196.188.222]) by dommail.onthenet.com.au (MOS 4.2.4-GA) with ESMTP id BQW76567 (AUTH peterg@ptree32.com.au); Wed, 25 Dec 2013 10:28:16 +1000 Message-ID: <52BA26A1.10204@freebsd.org> Date: Tue, 24 Dec 2013 17:28:17 -0700 From: Peter Grehan User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Dennis Glatting Subject: Re: nmdm doesn't create entries in /dev (10.0-RC2+) References: <1387926826.71651.129.camel@btw.pki2.com> In-Reply-To: <1387926826.71651.129.camel@btw.pki2.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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, 25 Dec 2013 00:28:20 -0000 Hi Dennis, > Bhyve newbie trying to get it to start. No problems. > I am getting the FreeBSD loader but it then exits when the loader goes > to boot. I've also found "kldload nmdm" does not create any entries > in /dev. Isn't it suppose to? I'm not sure what I am doing wrong. nmdm(4) is a cloneable device so device nodes won't show up until they're opened. Also, vmrun.sh is hard-coded to use stdio for output. You'll have to modify the script to get bhyveload (the -c option) and bhyve (the "-l com1," option) to use an nmdm device. > System: > > Elmer# uname -a > FreeBSD Elmer 10.0-PRERELEASE FreeBSD 10.0-PRERELEASE #0 r259838: Tue > Dec 24 15:21:17 MST 2013 > root@Elmer:/disk-2/obj/usr/src/sys/PENFORD-FreeBSD10-amd64 amd64 > > > I am executing the following instructions: > > kldload nmdm > kldload vmm > kldload if_tap > ifconfig tap0 create > ./vmrun.sh -c 4 -d /disk-2/VMs/nms.img -i > -I /disk-3/tmp/FreeBSD-10.0-RC2-amd64-disc1.iso -m 2G -t /dev/tap0 nms > > > FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610 > CPU: Intel(R) Xeon(R) CPU E5540 @ 2.53GHz (2533.47-MHz > K8-class CPU) This is a Nehalem Xeon - it doesn't have the VT-x feature known as "unrestricted guest" aka 16/32-bit emulation which arrived in Westmere. This won't allow FreeBSD to spin up APs (16-bit emulation required) or to run Linux via grub-bhyve (32-bit paging-disabled emulation). You'll be restricted to single CPU FreeBSD guests on this model :( later, Peter. From owner-freebsd-virtualization@FreeBSD.ORG Wed Dec 25 15:43:29 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D883AF6 for ; Wed, 25 Dec 2013 15:43:29 +0000 (UTC) Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AA1F31EEF for ; Wed, 25 Dec 2013 15:43:29 +0000 (UTC) Received: by mail-pa0-f45.google.com with SMTP id fb1so7483764pad.18 for ; Wed, 25 Dec 2013 07:43:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=bOX+j1CQhSWBH32mW92CB5as5q1X5zNbJ0952NmkJFs=; b=AUe9Um77FobNKdrnegpGYaLNY3qymKQ+2nBiBM7T+gx88g8T8ZQmB9ZAqwPo41FwTN YDSsc2S6TMaXvNucu6RUhHj5sAYr1C3ld+jjcyq/z5CMMP/6bMCvqN+Zwrjp0ozdAnOc W6dEnNqtBxTg1rcXUPGLKlVQKnRvseNfAFLiMTARUX0Bs4GYsqV2hiZM5y/59f3iKgXV m65/6UlDvclGB3vigcAfl6d78M98VPi50LGlu7H3dof1fLjA/oi+WJRKQE+K70e0nUvI QxZMQLnxWvQQgohF6qLck26qNbEtuQNIGyq9Vm+hrig55XneRajKY3QFeVhwYGA7rl6X YREQ== X-Gm-Message-State: ALoCoQkoVR4LmqOmXHYNudm89avS9Fnq+S9Wtj3CEzZF6CFKe3DNduQbQ1GxS7yB4erIG7ExOfqF X-Received: by 10.66.139.130 with SMTP id qy2mr38955252pab.73.1387986208423; Wed, 25 Dec 2013 07:43:28 -0800 (PST) Received: from Michaels-MacBook-Pro.local (ip70-185-178-226.sb.sd.cox.net. [70.185.178.226]) by mx.google.com with ESMTPSA id gv10sm49166597pbd.0.2013.12.25.07.43.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Dec 2013 07:43:27 -0800 (PST) Message-ID: <52BAFD1F.3060404@callfortesting.org> Date: Wed, 25 Dec 2013 07:43:27 -0800 From: Michael Dexter User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: freebsd-virtualization@freebsd.org Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve References: <201312231443.39282.jhb@freebsd.org> In-Reply-To: <201312231443.39282.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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, 25 Dec 2013 15:43:29 -0000 John, This is awesome. Can this be triggered from the host to shut down an unresponsive VM? If so, syntax? Michael On 12/23/13 11:43 AM, John Baldwin wrote: > To that end, I've implemented support for > a few more registers (such of which are non-optional in ACPI) including the > Reset Control register (0xcf9), ACPI Power Management 1 Event registers > (PM1_EVT) and the ACPI Power Management 1 Control register (PM1_CNT). I added > a valid _S5 package and catch writes of the value _S5 specifies to ask bhyve > to exit gracefully but with an exit code of 1 (so the loop in vmrun > terminates). From owner-freebsd-virtualization@FreeBSD.ORG Thu Dec 26 16:38:16 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3CF1B3DB for ; Thu, 26 Dec 2013 16:38:16 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 104F01EFE for ; Thu, 26 Dec 2013 16:38:16 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id D6C41B941; Thu, 26 Dec 2013 11:38:14 -0500 (EST) From: John Baldwin To: freebsd-virtualization@freebsd.org Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve Date: Thu, 26 Dec 2013 11:37:47 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <201312231443.39282.jhb@freebsd.org> <52BAFD1F.3060404@callfortesting.org> In-Reply-To: <52BAFD1F.3060404@callfortesting.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201312261137.47329.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 26 Dec 2013 11:38:14 -0500 (EST) X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Thu, 26 Dec 2013 16:38:16 -0000 On Wednesday, December 25, 2013 10:43:27 am Michael Dexter wrote: > > John, > > This is awesome. > > Can this be triggered from the host to shut down an unresponsive VM? > > If so, syntax? It cannot. However, we could add a virtual power button that acts like an external ACPI power button. We could then add a flag to bhyvectl to trigger it. I will look into that. -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Thu Dec 26 21:17:46 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D0832B96 for ; Thu, 26 Dec 2013 21:17:46 +0000 (UTC) Received: from mail-pb0-x235.google.com (mail-pb0-x235.google.com [IPv6:2607:f8b0:400e:c01::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A99001285 for ; Thu, 26 Dec 2013 21:17:46 +0000 (UTC) Received: by mail-pb0-f53.google.com with SMTP id ma3so8548201pbc.12 for ; Thu, 26 Dec 2013 13:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=cReaKywfbfaRsZoksuuu5+SsMjkLlaQ2qMoKZ3Mtb5I=; b=iqHrqSw+OrbZtTImlBmGhh/4IOb4y1zrQNd6lgK3jETdcTunzfxCcQIt+bihm9w93F uls70nFnnIAoRvFTjxHh2mDYJ9AfabNZQaIYu/KfmvC4QByCaUkJgj5jbZ9nTs3MENX8 KWEkAZ53lDWnOARuhwMznlaWiSc/3XK1ozXnJGwd/5LddRxzOscRhncAOc/9mHKvpmhP 4E0I9dkdIm3cTMwIrBUStFNk3DSM0Jia3dyMZ5f2I4cjDuEfXpayHvp5IliO8mMtVkgD +sFKAvND408akpOUKcefFeBtbkHHTWD88KsUkKAZMIFvAhkHHao0JvyEVLn8nP8U+GN3 ODvw== MIME-Version: 1.0 X-Received: by 10.66.141.231 with SMTP id rr7mr45701301pab.41.1388092666224; Thu, 26 Dec 2013 13:17:46 -0800 (PST) Received: by 10.68.185.130 with HTTP; Thu, 26 Dec 2013 13:17:46 -0800 (PST) Date: Thu, 26 Dec 2013 16:17:46 -0500 Message-ID: Subject: new suspend/resume functionality on bhyve From: Aryeh Friedman To: "freebsd-virtualization@freebsd.org" Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Thu, 26 Dec 2013 21:17:46 -0000 Will this make it into 10.0? or is it a -CURRENT thing only? From owner-freebsd-virtualization@FreeBSD.ORG Fri Dec 27 17:10:34 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BC761997 for ; Fri, 27 Dec 2013 17:10:34 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7903D1F22 for ; Fri, 27 Dec 2013 17:10:34 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 70C31B941 for ; Fri, 27 Dec 2013 12:10:33 -0500 (EST) From: John Baldwin To: freebsd-virtualization@freebsd.org Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve Date: Fri, 27 Dec 2013 11:46:34 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <201312231443.39282.jhb@freebsd.org> <52BAFD1F.3060404@callfortesting.org> <201312261137.47329.jhb@freebsd.org> In-Reply-To: <201312261137.47329.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201312271146.34364.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 27 Dec 2013 12:10:33 -0500 (EST) X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Fri, 27 Dec 2013 17:10:34 -0000 On Thursday, December 26, 2013 11:37:47 am John Baldwin wrote: > On Wednesday, December 25, 2013 10:43:27 am Michael Dexter wrote: > > > > John, > > > > This is awesome. > > > > Can this be triggered from the host to shut down an unresponsive VM? > > > > If so, syntax? > > It cannot. However, we could add a virtual power button that acts like an > external ACPI power button. We could then add a flag to bhyvectl to > trigger it. I will look into that. I've implemented this. Rather than doing it via bhyvectl, I turned SIGTERM sent to bhyve itself into the virtual power button. Thus, if you 'killall bhyve' or 'pkill bhyve' from the host, the guest will gracefully shutdown using S5. You can still use kill -9 to kill a hung guest (similar to the 4 second power button override on real metal). To do this I fleshed out the ACPI power management support a bit more adding more of the implementation of PM1_EVT and PM1_CNT. I also added an SMI_CMD register with commands to enable and disable ACPI (for now all that does is enable/disable the virtual power button as well as toggle SCI_EN in PM1_CNT). I also added support for raising ACPI's SCI based on settings in PM1_EVT. I extended mevent to handle EVFILT_SIGNAL events and use a mevent handler for SIGTERM to simulate pressing the power button. This just implements the simple fixed-feature power button support via PM1_EVT rather than having a control method button (which would require implementing GPE support). While here, I made sure the SCI interrupt was active-lo / level-triggered, and I changed PCI interrupts in the MP Table to explicitly use active-lo since they were already explicitly using level-trigger. I also fixed the pmtmr code to use pthread_once instead of a racy static int. That should probably be a separate commit though. --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.c @@ -85,10 +87,6 @@ #define BHYVE_ASL_SUFFIX ".aml" #define BHYVE_ASL_COMPILER "/usr/sbin/iasl" -#define BHYVE_PM1A_EVT_ADDR 0x400 -#define BHYVE_PM1A_CNT_ADDR 0x404 -#define BHYVE_PM_TIMER_ADDR 0x408 - static int basl_keep_temps; static int basl_verbose_iasl; static int basl_ncpu; @@ -285,11 +290,11 @@ EFPRINTF(fp, "[0001]\t\tSubtable Type : 02\n"); EFPRINTF(fp, "[0001]\t\tLength : 0A\n"); EFPRINTF(fp, "[0001]\t\tBus : 00\n"); - EFPRINTF(fp, "[0001]\t\tSource : 09\n"); - EFPRINTF(fp, "[0004]\t\tInterrupt : 00000009\n"); + EFPRINTF(fp, "[0001]\t\tSource : %02X\n", SCI_INT); + EFPRINTF(fp, "[0004]\t\tInterrupt : %08X\n", SCI_INT); EFPRINTF(fp, "[0002]\t\tFlags (decoded below) : 0000\n"); - EFPRINTF(fp, "\t\t\tPolarity : 0\n"); - EFPRINTF(fp, "\t\t\tTrigger Mode : 0\n"); + EFPRINTF(fp, "\t\t\tPolarity : 3\n"); + EFPRINTF(fp, "\t\t\tTrigger Mode : 3\n"); EFPRINTF(fp, "\n"); /* Local APIC NMI is connected to LINT 1 on all CPUs */ @@ -336,23 +341,27 @@ basl_acpi_base + FACS_OFFSET); EFPRINTF(fp, "[0004]\t\tDSDT Address : %08X\n", basl_acpi_base + DSDT_OFFSET); - EFPRINTF(fp, "[0001]\t\tModel : 00\n"); + EFPRINTF(fp, "[0001]\t\tModel : 01\n"); EFPRINTF(fp, "[0001]\t\tPM Profile : 00 [Unspecified]\n"); - EFPRINTF(fp, "[0002]\t\tSCI Interrupt : 0009\n"); - EFPRINTF(fp, "[0004]\t\tSMI Command Port : 00000000\n"); - EFPRINTF(fp, "[0001]\t\tACPI Enable Value : 00\n"); - EFPRINTF(fp, "[0001]\t\tACPI Disable Value : 00\n"); + EFPRINTF(fp, "[0002]\t\tSCI Interrupt : %04X\n", + SCI_INT); + EFPRINTF(fp, "[0004]\t\tSMI Command Port : %08X\n", + SMI_CMD); + EFPRINTF(fp, "[0001]\t\tACPI Enable Value : %02X\n", + BHYVE_ACPI_ENABLE); + EFPRINTF(fp, "[0001]\t\tACPI Disable Value : %02X\n", + BHYVE_ACPI_DISABLE); EFPRINTF(fp, "[0001]\t\tS4BIOS Command : 00\n"); EFPRINTF(fp, "[0001]\t\tP-State Control : 00\n"); EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : %08X\n", - BHYVE_PM1A_EVT_ADDR); + PM1A_EVT_ADDR); EFPRINTF(fp, "[0004]\t\tPM1B Event Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : %08X\n", - BHYVE_PM1A_CNT_ADDR); + PM1A_CNT_ADDR); EFPRINTF(fp, "[0004]\t\tPM1B Control Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM2 Control Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM Timer Block Address : %08X\n", - BHYVE_PM_TIMER_ADDR); + IO_PMTMR); EFPRINTF(fp, "[0004]\t\tGPE0 Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tGPE1 Block Address : 00000000\n"); EFPRINTF(fp, "[0001]\t\tPM1 Event Block Length : 04\n"); @@ -385,7 +394,7 @@ EFPRINTF(fp, "\t\t\tWBINVD flushes all caches (V1) : 0\n"); EFPRINTF(fp, "\t\t\tAll CPUs support C1 (V1) : 1\n"); EFPRINTF(fp, "\t\t\tC2 works on MP system (V1) : 0\n"); - EFPRINTF(fp, "\t\t\tControl Method Power Button (V1) : 1\n"); + EFPRINTF(fp, "\t\t\tControl Method Power Button (V1) : 0\n"); EFPRINTF(fp, "\t\t\tControl Method Sleep Button (V1) : 1\n"); EFPRINTF(fp, "\t\t\tRTC wake not in fixed reg space (V1) : 0\n"); EFPRINTF(fp, "\t\t\tRTC can wake system from S4 (V1) : 0\n"); @@ -427,7 +436,7 @@ EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", - BHYVE_PM1A_EVT_ADDR); + PM1A_EVT_ADDR); EFPRINTF(fp, "\n"); EFPRINTF(fp, @@ -447,7 +456,7 @@ EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", - BHYVE_PM1A_CNT_ADDR); + PM1A_CNT_ADDR); EFPRINTF(fp, "\n"); EFPRINTF(fp, @@ -479,7 +488,7 @@ EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 03 [DWord Access:32]\n"); EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", - BHYVE_PM_TIMER_ADDR); + IO_PMTMR); EFPRINTF(fp, "\n"); EFPRINTF(fp, "[0012]\t\tGPE0 Block : [Generic Address Structure]\n"); --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.h +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.h @@ -29,6 +29,19 @@ #ifndef _ACPI_H_ #define _ACPI_H_ +#define SCI_INT 9 + +#define SMI_CMD 0xb2 +#define BHYVE_ACPI_ENABLE 0xa0 +#define BHYVE_ACPI_DISABLE 0xa1 + +#define PM1A_EVT_ADDR 0x400 +#define PM1A_CNT_ADDR 0x404 + +#define IO_PMTMR 0x408 /* 4-byte i/o port for the timer */ + +struct vmctx; + int acpi_build(struct vmctx *ctx, int ncpu); #endif /* _ACPI_H_ */ --- //depot/vendor/freebsd/src/usr.sbin/bhyve/mevent.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/mevent.c @@ -135,6 +135,9 @@ if (mevp->me_type == EVF_TIMER) retval = EVFILT_TIMER; + if (mevp->me_type == EVF_SIGNAL) + retval = EVFILT_SIGNAL; + return (retval); } @@ -437,7 +440,7 @@ * Block awaiting events */ ret = kevent(mfd, NULL, 0, eventlist, MEVENT_MAX, NULL); - if (ret == -1) { + if (ret == -1 && errno != EINTR) { perror("Error return from kevent monitor"); } --- //depot/vendor/freebsd/src/usr.sbin/bhyve/mevent.h +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/mevent.h @@ -32,7 +32,8 @@ enum ev_type { EVF_READ, EVF_WRITE, - EVF_TIMER + EVF_TIMER, + EVF_SIGNAL }; struct mevent; --- //depot/vendor/freebsd/src/usr.sbin/bhyve/mptbl.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/mptbl.c @@ -36,6 +36,7 @@ #include #include +#include "acpi.h" #include "bhyverun.h" #include "mptbl.h" @@ -227,13 +228,21 @@ mpie->int_type = INTENTRY_TYPE_INT; mpie->src_bus_irq = 0; break; + case SCI_INT: + /* ACPI SCI is level triggered and active-lo. */ + mpie->int_flags = INTENTRY_FLAGS_POLARITY_ACTIVELO | + INTENTRY_FLAGS_TRIGGER_LEVEL; + mpie->int_type = INTENTRY_TYPE_INT; + mpie->src_bus_irq = SCI_INT; + break; case 5: case 10: case 11: /* - * PCI Irqs set to level triggered. + * PCI Irqs set to level triggered and active-lo. */ - mpie->int_flags = INTENTRY_FLAGS_TRIGGER_LEVEL; + mpie->int_flags = INTENTRY_FLAGS_POLARITY_ACTIVELO | + INTENTRY_FLAGS_TRIGGER_LEVEL; mpie->src_bus_id = 0; /* fall through.. */ default: --- //depot/vendor/freebsd/src/usr.sbin/bhyve/pm.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pm.c @@ -29,11 +29,20 @@ __FBSDID("$FreeBSD: head/usr.sbin/bhyve/pm.c 259826 2013-12-24 16:14:19Z jhb $"); #include +#include + +#include +#include +#include +#include +#include "acpi.h" #include "inout.h" +#include "mevent.h" -#define PM1A_EVT_ADDR 0x400 -#define PM1A_CNT_ADDR 0x404 +static pthread_mutex_t pm_lock = PTHREAD_MUTEX_INITIALIZER; +static struct mevent *power_button; +static sig_t old_power_handler; /* * Reset Control register at I/O port 0xcf9. Bit 2 forces a system @@ -63,12 +73,75 @@ INOUT_PORT(reset_reg, 0xCF9, IOPORT_F_INOUT, reset_handler); /* + * ACPI's SCI is a level-triggered interrupt. + */ +static int sci_active; + +static void +sci_assert(struct vmctx *ctx) +{ + + if (sci_active) + return; + vm_ioapic_assert_irq(ctx, SCI_INT); + sci_active = 1; +} + +static void +sci_deassert(struct vmctx *ctx) +{ + + if (!sci_active) + return; + vm_ioapic_deassert_irq(ctx, SCI_INT); + sci_active = 0; +} + +/* * Power Management 1 Event Registers * - * bhyve doesn't support any power management events currently, so the - * status register always returns zero. The enable register preserves - * its value but has no effect. + * The only power management event supported is a power button upon + * receiving SIGTERM. */ +static uint16_t pm1_enable, pm1_status; + +#define PM1_TMR_STS 0x0001 +#define PM1_BM_STS 0x0010 +#define PM1_GBL_STS 0x0020 +#define PM1_PWRBTN_STS 0x0100 +#define PM1_SLPBTN_STS 0x0200 +#define PM1_RTC_STS 0x0400 +#define PM1_WAK_STS 0x8000 + +#define PM1_TMR_EN 0x0001 +#define PM1_GBL_EN 0x0020 +#define PM1_PWRBTN_EN 0x0100 +#define PM1_SLPBTN_EN 0x0200 +#define PM1_RTC_EN 0x0400 + +static void +sci_update(struct vmctx *ctx) +{ + int need_sci; + + /* See if the SCI should be active or not. */ + need_sci = 0; + if ((pm1_enable & PM1_TMR_EN) && (pm1_status & PM1_TMR_STS)) + need_sci = 1; + if ((pm1_enable & PM1_GBL_EN) && (pm1_status & PM1_GBL_STS)) + need_sci = 1; + if ((pm1_enable & PM1_PWRBTN_EN) && (pm1_status & PM1_PWRBTN_STS)) + need_sci = 1; + if ((pm1_enable & PM1_SLPBTN_EN) && (pm1_status & PM1_SLPBTN_STS)) + need_sci = 1; + if ((pm1_enable & PM1_RTC_EN) && (pm1_status & PM1_RTC_STS)) + need_sci = 1; + if (need_sci) + sci_assert(ctx); + else + sci_deassert(ctx); +} + static int pm1_status_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) @@ -76,8 +150,20 @@ if (bytes != 2) return (-1); + + pthread_mutex_lock(&pm_lock); if (in) - *eax = 0; + *eax = pm1_status; + else { + /* + * Writes are only permitted to clear certain bits by + * writing 1 to those flags. + */ + pm1_status &= ~(*eax & (PM1_WAK_STS | PM1_RTC_STS | + PM1_SLPBTN_STS | PM1_PWRBTN_STS | PM1_BM_STS)); + sci_update(ctx); + } + pthread_mutex_unlock(&pm_lock); return (0); } @@ -85,25 +171,51 @@ pm1_enable_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - static uint16_t pm1_enable; if (bytes != 2) return (-1); + + pthread_mutex_lock(&pm_lock); if (in) *eax = pm1_enable; - else - pm1_enable = *eax; + else { + /* + * Only permit certain bits to be set. We never use + * the global lock, but ACPI-CA whines profusely if it + * can't set GBL_EN. + */ + pm1_enable = *eax & (PM1_PWRBTN_EN | PM1_GBL_EN); + sci_update(ctx); + } + pthread_mutex_unlock(&pm_lock); return (0); } INOUT_PORT(pm1_status, PM1A_EVT_ADDR, IOPORT_F_INOUT, pm1_status_handler); INOUT_PORT(pm1_enable, PM1A_EVT_ADDR + 2, IOPORT_F_INOUT, pm1_enable_handler); +static void +power_button_handler(int signal, enum ev_type type, void *arg) +{ + struct vmctx *ctx; + + ctx = arg; + pthread_mutex_lock(&pm_lock); + if (!(pm1_status & PM1_PWRBTN_STS)) { + pm1_status |= PM1_PWRBTN_STS; + sci_update(ctx); + } + pthread_mutex_unlock(&pm_lock); +} + /* * Power Management 1 Control Register * * This is mostly unimplemented except that we wish to handle writes that * set SPL_EN to handle S5 (soft power off). */ +static uint16_t pm1_control; + +#define PM1_SCI_EN 0x0001 #define PM1_SLP_TYP 0x1c00 #define PM1_SLP_EN 0x2000 #define PM1_ALWAYS_ZERO 0xc003 @@ -112,7 +224,6 @@ pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - static uint16_t pm1_control; if (bytes != 2) return (-1); @@ -121,9 +232,11 @@ else { /* * Various bits are write-only or reserved, so force them - * to zero in pm1_control. + * to zero in pm1_control. Always preserve SCI_EN as OSPM + * can never change it. */ - pm1_control = *eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO); + pm1_control = (pm1_control & PM1_SCI_EN) | + (*eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO)); /* * If SLP_EN is set, check for S5. Bhyve's _S5_ method @@ -137,3 +250,41 @@ return (0); } INOUT_PORT(pm1_control, PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); + +/* + * ACPI SMI Command Register + * + * This write-only register is used to enable and disable ACPI. + */ +static int +smi_cmd_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, void *arg) +{ + + assert(!in); + if (bytes != 1) + return (-1); + + pthread_mutex_lock(&pm_lock); + switch (*eax) { + case BHYVE_ACPI_ENABLE: + pm1_control |= PM1_SCI_EN; + if (power_button == NULL) { + power_button = mevent_add(SIGTERM, EVF_SIGNAL, + power_button_handler, ctx); + old_power_handler = signal(SIGTERM, SIG_IGN); + } + break; + case BHYVE_ACPI_DISABLE: + pm1_control &= ~PM1_SCI_EN; + if (power_button != NULL) { + mevent_delete(power_button); + power_button = NULL; + signal(SIGTERM, old_power_handler); + } + break; + } + pthread_mutex_unlock(&pm_lock); + return (0); +} +INOUT_PORT(smi_cmd, SMI_CMD, IOPORT_F_OUT, smi_cmd_handler); --- //depot/vendor/freebsd/src/usr.sbin/bhyve/pmtmr.c +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pmtmr.c @@ -40,6 +40,7 @@ #include #include +#include "acpi.h" #include "inout.h" /* @@ -49,11 +50,10 @@ * This implementation will be 32-bits */ -#define IO_PMTMR 0x408 /* 4-byte i/o port for the timer */ - #define PMTMR_FREQ 3579545 /* 3.579545MHz */ static pthread_mutex_t pmtmr_mtx; +static pthread_once_t pmtmr_once = PTHREAD_ONCE_INIT; static uint64_t pmtmr_old; @@ -123,6 +123,7 @@ pmtmr_uptime_old = tsnew; pmtmr_old = timespec_to_pmtmr(&tsnew, &tsold); } + pthread_mutex_init(&pmtmr_mtx, NULL); } static uint32_t @@ -133,13 +134,7 @@ uint64_t pmtmr_new; int error; - static int inited = 0; - - if (!inited) { - pthread_mutex_init(&pmtmr_mtx, NULL); - pmtmr_init(); - inited = 1; - } + pthread_once(&pmtmr_once, pmtmr_init); pthread_mutex_lock(&pmtmr_mtx); > > -- > John Baldwin > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org" > -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Fri Dec 27 17:10:35 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4B846A5C for ; Fri, 27 Dec 2013 17:10:35 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1F22F1F24 for ; Fri, 27 Dec 2013 17:10:35 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 1055CB946 for ; Fri, 27 Dec 2013 12:10:34 -0500 (EST) From: John Baldwin To: virtualization@freebsd.org Subject: [PATCH] Rework DSDT generation in bhyve Date: Fri, 27 Dec 2013 12:05:54 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201312271205.54102.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 27 Dec 2013 12:10:34 -0500 (EST) X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Fri, 27 Dec 2013 17:10:35 -0000 While hacking on the power button support, I also started rototilling the DSDT generation code a bit. My initial goal was to enumerate the LPC serial ports (COM1 and COM2) properly via ACPI. I ended up doing the following: - Moved the info for the top-level PCI bus into the PCI emulation code and added ResourceProducer entries for the memory ranges decoded by the bus for memory BARs. - I added a framework to allow each PCI emulation driver to optionally write an entry into the DSDT under the \_SB_.PCI0 namespace. The LPC driver uses this to write a node for the LPC bus (\_SB_.PCI0.ISA). - I added a linker set to allow any LPC devices to write entries into the DSDT below the LPC node. I moved the existing block for the RTC out of acpi.c and into the RTC driver. I added DSDT nodes for the AT PIC, the 8254 ISA timer, and the LPC UART devices. - I also added a "SuperIO" device under the LPC node to claim "system resources" (as is done in real hardware). I added a linker set to allow various drivers to add IO or memory ranges that should be claimed by SuperIO and then added the extended RTC IO range and the registers used for ACPI power management as system resources. The end result is that for the stock VM created by vmrun.sh, the attimer0, uart0, and uart1 devices move from isa0 to acpi0. There is also a PIC device that would be claimed by 'device atpic' (but the stock amd64 kernel doesn't include that). The DSDT is also a bit more fleshed out, and also looks "nice" as devices are mostly laid out in the normal tree rather than using separate Scope() sections for each device. Note that I did add some helper routines for writing out DSDT lines and resource entries to try to simplify the code in the various DSDT handlers and make the code that generates DSDT lines a bit more readable (e.g. the implicit newlines make things more readable IMO). The patch is relative to the previous power button patch and is at http://www.FreeBSD.org/~jhb/patches/bhyve_dsdt.patch Assuming these are ok, the next thing I might work on is cleaning up the PCI INTx interrupts. They should really all be rounted to the I/O APIC intpins above 15 (and we should leave ISA IRQs 5, 10, and 11 alone in APIC mode and only fall back to that if we are using the 8259As and a real ELCR). The MP Table output would need some minor tweaking for that, and for ACPI we should generate a _PRT table under _SB_.PCI0 in pci_emul.c. -- John Baldwin From owner-freebsd-virtualization@FreeBSD.ORG Fri Dec 27 21:01:58 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 73F042DF for ; Fri, 27 Dec 2013 21:01:58 +0000 (UTC) Received: from mail-pb0-f49.google.com (mail-pb0-f49.google.com [209.85.160.49]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3F3C21FE0 for ; Fri, 27 Dec 2013 21:01:58 +0000 (UTC) Received: by mail-pb0-f49.google.com with SMTP id jt11so9554669pbb.36 for ; Fri, 27 Dec 2013 13:01:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=meqgPHzlJ8GMgsOLvKG+cOPqBx780TlzlCd6X2vRsUM=; b=m+Z8auEwwrOtNAOirOJ707qy6brWTSJ+0aVvyOulkGOtQnNN7BcpQMai+BDM9fK/P1 d7JTTMnyG9ujIbCWW7bOrNQCHlzzJ5hM/t5rUoTfbzSzZFksxKWq/sK1SX3OXp/HeVX+ cfCMjed/jKFoXAykIGGeMk6yp3AVsys42hJUrRM22zGoq9KIW4y6cy0eWxYKQpHwfTPW kANGLXqbx+1+e8pquXITvfpZh3CXCDvxbv5XQ9Q2jtzfzWvh7qYAqjMd1yr0LW/+gPt/ fyGkJU8Fqqzf/NCeoC6x+WjgsrRfDLBN9gaVYio70dNBISNmkpT9sS/Hqz1ccnB/3mpC lh2Q== X-Gm-Message-State: ALoCoQkhV+RGOY/nYI6L/ZZPQLPj1qpdyzqszOEQl0dqRAbMdZ8x3Uk1wWtIt0viHAy8LQBkJT9Z X-Received: by 10.67.24.7 with SMTP id ie7mr52567098pad.112.1388174758935; Fri, 27 Dec 2013 12:05:58 -0800 (PST) Received: from Michaels-MacBook-Pro.local (ip70-185-178-226.sb.sd.cox.net. [70.185.178.226]) by mx.google.com with ESMTPSA id ko10sm51910657pbd.38.2013.12.27.12.05.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Dec 2013 12:05:58 -0800 (PST) Message-ID: <52BDDDAD.6010503@callfortesting.org> Date: Fri, 27 Dec 2013 12:06:05 -0800 From: Michael Dexter User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: John Baldwin , freebsd-virtualization@freebsd.org Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve References: <201312231443.39282.jhb@freebsd.org> <52BAFD1F.3060404@callfortesting.org> <201312261137.47329.jhb@freebsd.org> <201312271146.34364.jhb@freebsd.org> In-Reply-To: <201312271146.34364.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Fri, 27 Dec 2013 21:01:58 -0000 On 12/27/13 8:46 AM, John Baldwin wrote: >>> Can this be triggered from the host to shut down an unresponsive VM? >> > >> > It cannot. >> > >> > I will look into that. >> > > I've implemented this. You rock. Michael From owner-freebsd-virtualization@FreeBSD.ORG Sat Dec 28 01:45:33 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B8FBBCA2; Sat, 28 Dec 2013 01:45:33 +0000 (UTC) Received: from mail-qc0-x235.google.com (mail-qc0-x235.google.com [IPv6:2607:f8b0:400d:c01::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 66B85129B; Sat, 28 Dec 2013 01:45:33 +0000 (UTC) Received: by mail-qc0-f181.google.com with SMTP id e9so9080117qcy.26 for ; Fri, 27 Dec 2013 17:45:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=GZz8PAKBuOveGS8yEsL+fhpZbHwl9FQcSE60caJD/bY=; b=kj7FTG5YtkoBoDbBBPuG7w/d+aA4NSBmuQNpkQg092dtD6PYvWOI7yr5naI2LxFZtX xMZ7bEspPP4W787Xhw6B2DuW7zgzuJiN2M6Kkgs+iFY4IIWIU6P6HaMOlb4UQzd8jG/F MAzOtEffxxl/DiiONaAR2JW44OzsWSCZAxi/cc6n7/dne3I8H+WjASz+xp22EDNu8/2U sjbJUpDDJ0S3WwnRg1tJCfJrEVy+pABHMJqp5TffwfseD5cY1SmgTKg/ufkMK5AHExAg 0DFHshCvF/I7kfOIeZha5G6iRALtd1BIr8BzprkebK+HfA634r4vHs9khtHiRAEjKUlG USdQ== MIME-Version: 1.0 X-Received: by 10.49.28.101 with SMTP id a5mr86822086qeh.70.1388195132476; Fri, 27 Dec 2013 17:45:32 -0800 (PST) Received: by 10.140.34.17 with HTTP; Fri, 27 Dec 2013 17:45:32 -0800 (PST) In-Reply-To: <201312271146.34364.jhb@freebsd.org> References: <201312231443.39282.jhb@freebsd.org> <52BAFD1F.3060404@callfortesting.org> <201312261137.47329.jhb@freebsd.org> <201312271146.34364.jhb@freebsd.org> Date: Fri, 27 Dec 2013 17:45:32 -0800 Message-ID: Subject: Re: [PATCH] Support for S5 (soft power off) in bhyve From: Neel Natu To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Sat, 28 Dec 2013 01:45:33 -0000 Hi John, On Fri, Dec 27, 2013 at 8:46 AM, John Baldwin wrote: > On Thursday, December 26, 2013 11:37:47 am John Baldwin wrote: >> On Wednesday, December 25, 2013 10:43:27 am Michael Dexter wrote: >> > >> > John, >> > >> > This is awesome. >> > >> > Can this be triggered from the host to shut down an unresponsive VM? >> > >> > If so, syntax? >> >> It cannot. However, we could add a virtual power button that acts like an >> external ACPI power button. We could then add a flag to bhyvectl to >> trigger it. I will look into that. > > I've implemented this. Rather than doing it via bhyvectl, I turned SIGTERM > sent to bhyve itself into the virtual power button. Thus, if you > 'killall bhyve' or 'pkill bhyve' from the host, the guest will gracefully > shutdown using S5. You can still use kill -9 to kill a hung guest (similar > to the 4 second power button override on real metal). > > To do this I fleshed out the ACPI power management support a bit more adding > more of the implementation of PM1_EVT and PM1_CNT. I also added an SMI_CMD > register with commands to enable and disable ACPI (for now all that does is > enable/disable the virtual power button as well as toggle SCI_EN in PM1_CNT). > I also added support for raising ACPI's SCI based on settings in PM1_EVT. > > I extended mevent to handle EVFILT_SIGNAL events and use a mevent handler for > SIGTERM to simulate pressing the power button. This just implements the > simple fixed-feature power button support via PM1_EVT rather than having a > control method button (which would require implementing GPE support). > > While here, I made sure the SCI interrupt was active-lo / level-triggered, > and I changed PCI interrupts in the MP Table to explicitly use active-lo > since they were already explicitly using level-trigger. > > I also fixed the pmtmr code to use pthread_once instead of a racy static > int. That should probably be a separate commit though. > This looks great! Thanks for adding this functionality. best Neel > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.c > @@ -85,10 +87,6 @@ > #define BHYVE_ASL_SUFFIX ".aml" > #define BHYVE_ASL_COMPILER "/usr/sbin/iasl" > > -#define BHYVE_PM1A_EVT_ADDR 0x400 > -#define BHYVE_PM1A_CNT_ADDR 0x404 > -#define BHYVE_PM_TIMER_ADDR 0x408 > - > static int basl_keep_temps; > static int basl_verbose_iasl; > static int basl_ncpu; > @@ -285,11 +290,11 @@ > EFPRINTF(fp, "[0001]\t\tSubtable Type : 02\n"); > EFPRINTF(fp, "[0001]\t\tLength : 0A\n"); > EFPRINTF(fp, "[0001]\t\tBus : 00\n"); > - EFPRINTF(fp, "[0001]\t\tSource : 09\n"); > - EFPRINTF(fp, "[0004]\t\tInterrupt : 00000009\n"); > + EFPRINTF(fp, "[0001]\t\tSource : %02X\n", SCI_INT); > + EFPRINTF(fp, "[0004]\t\tInterrupt : %08X\n", SCI_INT); > EFPRINTF(fp, "[0002]\t\tFlags (decoded below) : 0000\n"); > - EFPRINTF(fp, "\t\t\tPolarity : 0\n"); > - EFPRINTF(fp, "\t\t\tTrigger Mode : 0\n"); > + EFPRINTF(fp, "\t\t\tPolarity : 3\n"); > + EFPRINTF(fp, "\t\t\tTrigger Mode : 3\n"); > EFPRINTF(fp, "\n"); > > /* Local APIC NMI is connected to LINT 1 on all CPUs */ > @@ -336,23 +341,27 @@ > basl_acpi_base + FACS_OFFSET); > EFPRINTF(fp, "[0004]\t\tDSDT Address : %08X\n", > basl_acpi_base + DSDT_OFFSET); > - EFPRINTF(fp, "[0001]\t\tModel : 00\n"); > + EFPRINTF(fp, "[0001]\t\tModel : 01\n"); > EFPRINTF(fp, "[0001]\t\tPM Profile : 00 [Unspecified]\n"); > - EFPRINTF(fp, "[0002]\t\tSCI Interrupt : 0009\n"); > - EFPRINTF(fp, "[0004]\t\tSMI Command Port : 00000000\n"); > - EFPRINTF(fp, "[0001]\t\tACPI Enable Value : 00\n"); > - EFPRINTF(fp, "[0001]\t\tACPI Disable Value : 00\n"); > + EFPRINTF(fp, "[0002]\t\tSCI Interrupt : %04X\n", > + SCI_INT); > + EFPRINTF(fp, "[0004]\t\tSMI Command Port : %08X\n", > + SMI_CMD); > + EFPRINTF(fp, "[0001]\t\tACPI Enable Value : %02X\n", > + BHYVE_ACPI_ENABLE); > + EFPRINTF(fp, "[0001]\t\tACPI Disable Value : %02X\n", > + BHYVE_ACPI_DISABLE); > EFPRINTF(fp, "[0001]\t\tS4BIOS Command : 00\n"); > EFPRINTF(fp, "[0001]\t\tP-State Control : 00\n"); > EFPRINTF(fp, "[0004]\t\tPM1A Event Block Address : %08X\n", > - BHYVE_PM1A_EVT_ADDR); > + PM1A_EVT_ADDR); > EFPRINTF(fp, "[0004]\t\tPM1B Event Block Address : 00000000\n"); > EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : %08X\n", > - BHYVE_PM1A_CNT_ADDR); > + PM1A_CNT_ADDR); > EFPRINTF(fp, "[0004]\t\tPM1B Control Block Address : 00000000\n"); > EFPRINTF(fp, "[0004]\t\tPM2 Control Block Address : 00000000\n"); > EFPRINTF(fp, "[0004]\t\tPM Timer Block Address : %08X\n", > - BHYVE_PM_TIMER_ADDR); > + IO_PMTMR); > EFPRINTF(fp, "[0004]\t\tGPE0 Block Address : 00000000\n"); > EFPRINTF(fp, "[0004]\t\tGPE1 Block Address : 00000000\n"); > EFPRINTF(fp, "[0001]\t\tPM1 Event Block Length : 04\n"); > @@ -385,7 +394,7 @@ > EFPRINTF(fp, "\t\t\tWBINVD flushes all caches (V1) : 0\n"); > EFPRINTF(fp, "\t\t\tAll CPUs support C1 (V1) : 1\n"); > EFPRINTF(fp, "\t\t\tC2 works on MP system (V1) : 0\n"); > - EFPRINTF(fp, "\t\t\tControl Method Power Button (V1) : 1\n"); > + EFPRINTF(fp, "\t\t\tControl Method Power Button (V1) : 0\n"); > EFPRINTF(fp, "\t\t\tControl Method Sleep Button (V1) : 1\n"); > EFPRINTF(fp, "\t\t\tRTC wake not in fixed reg space (V1) : 0\n"); > EFPRINTF(fp, "\t\t\tRTC can wake system from S4 (V1) : 0\n"); > @@ -427,7 +436,7 @@ > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); > EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > - BHYVE_PM1A_EVT_ADDR); > + PM1A_EVT_ADDR); > EFPRINTF(fp, "\n"); > > EFPRINTF(fp, > @@ -447,7 +456,7 @@ > EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); > EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); > EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > - BHYVE_PM1A_CNT_ADDR); > + PM1A_CNT_ADDR); > EFPRINTF(fp, "\n"); > > EFPRINTF(fp, > @@ -479,7 +488,7 @@ > EFPRINTF(fp, > "[0001]\t\tEncoded Access Width : 03 [DWord Access:32]\n"); > EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", > - BHYVE_PM_TIMER_ADDR); > + IO_PMTMR); > EFPRINTF(fp, "\n"); > > EFPRINTF(fp, "[0012]\t\tGPE0 Block : [Generic Address Structure]\n"); > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/acpi.h > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/acpi.h > @@ -29,6 +29,19 @@ > #ifndef _ACPI_H_ > #define _ACPI_H_ > > +#define SCI_INT 9 > + > +#define SMI_CMD 0xb2 > +#define BHYVE_ACPI_ENABLE 0xa0 > +#define BHYVE_ACPI_DISABLE 0xa1 > + > +#define PM1A_EVT_ADDR 0x400 > +#define PM1A_CNT_ADDR 0x404 > + > +#define IO_PMTMR 0x408 /* 4-byte i/o port for the timer */ > + > +struct vmctx; > + > int acpi_build(struct vmctx *ctx, int ncpu); > > #endif /* _ACPI_H_ */ > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/mevent.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/mevent.c > @@ -135,6 +135,9 @@ > if (mevp->me_type == EVF_TIMER) > retval = EVFILT_TIMER; > > + if (mevp->me_type == EVF_SIGNAL) > + retval = EVFILT_SIGNAL; > + > return (retval); > } > > @@ -437,7 +440,7 @@ > * Block awaiting events > */ > ret = kevent(mfd, NULL, 0, eventlist, MEVENT_MAX, NULL); > - if (ret == -1) { > + if (ret == -1 && errno != EINTR) { > perror("Error return from kevent monitor"); > } > > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/mevent.h > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/mevent.h > @@ -32,7 +32,8 @@ > enum ev_type { > EVF_READ, > EVF_WRITE, > - EVF_TIMER > + EVF_TIMER, > + EVF_SIGNAL > }; > > struct mevent; > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/mptbl.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/mptbl.c > @@ -36,6 +36,7 @@ > #include > #include > > +#include "acpi.h" > #include "bhyverun.h" > #include "mptbl.h" > > @@ -227,13 +228,21 @@ > mpie->int_type = INTENTRY_TYPE_INT; > mpie->src_bus_irq = 0; > break; > + case SCI_INT: > + /* ACPI SCI is level triggered and active-lo. */ > + mpie->int_flags = INTENTRY_FLAGS_POLARITY_ACTIVELO | > + INTENTRY_FLAGS_TRIGGER_LEVEL; > + mpie->int_type = INTENTRY_TYPE_INT; > + mpie->src_bus_irq = SCI_INT; > + break; > case 5: > case 10: > case 11: > /* > - * PCI Irqs set to level triggered. > + * PCI Irqs set to level triggered and active-lo. > */ > - mpie->int_flags = INTENTRY_FLAGS_TRIGGER_LEVEL; > + mpie->int_flags = INTENTRY_FLAGS_POLARITY_ACTIVELO | > + INTENTRY_FLAGS_TRIGGER_LEVEL; > mpie->src_bus_id = 0; > /* fall through.. */ > default: > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/pm.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pm.c > @@ -29,11 +29,20 @@ > __FBSDID("$FreeBSD: head/usr.sbin/bhyve/pm.c 259826 2013-12-24 16:14:19Z jhb $"); > > #include > +#include > + > +#include > +#include > +#include > +#include > > +#include "acpi.h" > #include "inout.h" > +#include "mevent.h" > > -#define PM1A_EVT_ADDR 0x400 > -#define PM1A_CNT_ADDR 0x404 > +static pthread_mutex_t pm_lock = PTHREAD_MUTEX_INITIALIZER; > +static struct mevent *power_button; > +static sig_t old_power_handler; > > /* > * Reset Control register at I/O port 0xcf9. Bit 2 forces a system > @@ -63,12 +73,75 @@ > INOUT_PORT(reset_reg, 0xCF9, IOPORT_F_INOUT, reset_handler); > > /* > + * ACPI's SCI is a level-triggered interrupt. > + */ > +static int sci_active; > + > +static void > +sci_assert(struct vmctx *ctx) > +{ > + > + if (sci_active) > + return; > + vm_ioapic_assert_irq(ctx, SCI_INT); > + sci_active = 1; > +} > + > +static void > +sci_deassert(struct vmctx *ctx) > +{ > + > + if (!sci_active) > + return; > + vm_ioapic_deassert_irq(ctx, SCI_INT); > + sci_active = 0; > +} > + > +/* > * Power Management 1 Event Registers > * > - * bhyve doesn't support any power management events currently, so the > - * status register always returns zero. The enable register preserves > - * its value but has no effect. > + * The only power management event supported is a power button upon > + * receiving SIGTERM. > */ > +static uint16_t pm1_enable, pm1_status; > + > +#define PM1_TMR_STS 0x0001 > +#define PM1_BM_STS 0x0010 > +#define PM1_GBL_STS 0x0020 > +#define PM1_PWRBTN_STS 0x0100 > +#define PM1_SLPBTN_STS 0x0200 > +#define PM1_RTC_STS 0x0400 > +#define PM1_WAK_STS 0x8000 > + > +#define PM1_TMR_EN 0x0001 > +#define PM1_GBL_EN 0x0020 > +#define PM1_PWRBTN_EN 0x0100 > +#define PM1_SLPBTN_EN 0x0200 > +#define PM1_RTC_EN 0x0400 > + > +static void > +sci_update(struct vmctx *ctx) > +{ > + int need_sci; > + > + /* See if the SCI should be active or not. */ > + need_sci = 0; > + if ((pm1_enable & PM1_TMR_EN) && (pm1_status & PM1_TMR_STS)) > + need_sci = 1; > + if ((pm1_enable & PM1_GBL_EN) && (pm1_status & PM1_GBL_STS)) > + need_sci = 1; > + if ((pm1_enable & PM1_PWRBTN_EN) && (pm1_status & PM1_PWRBTN_STS)) > + need_sci = 1; > + if ((pm1_enable & PM1_SLPBTN_EN) && (pm1_status & PM1_SLPBTN_STS)) > + need_sci = 1; > + if ((pm1_enable & PM1_RTC_EN) && (pm1_status & PM1_RTC_STS)) > + need_sci = 1; > + if (need_sci) > + sci_assert(ctx); > + else > + sci_deassert(ctx); > +} > + > static int > pm1_status_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > uint32_t *eax, void *arg) > @@ -76,8 +150,20 @@ > > if (bytes != 2) > return (-1); > + > + pthread_mutex_lock(&pm_lock); > if (in) > - *eax = 0; > + *eax = pm1_status; > + else { > + /* > + * Writes are only permitted to clear certain bits by > + * writing 1 to those flags. > + */ > + pm1_status &= ~(*eax & (PM1_WAK_STS | PM1_RTC_STS | > + PM1_SLPBTN_STS | PM1_PWRBTN_STS | PM1_BM_STS)); > + sci_update(ctx); > + } > + pthread_mutex_unlock(&pm_lock); > return (0); > } > > @@ -85,25 +171,51 @@ > pm1_enable_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > uint32_t *eax, void *arg) > { > - static uint16_t pm1_enable; > > if (bytes != 2) > return (-1); > + > + pthread_mutex_lock(&pm_lock); > if (in) > *eax = pm1_enable; > - else > - pm1_enable = *eax; > + else { > + /* > + * Only permit certain bits to be set. We never use > + * the global lock, but ACPI-CA whines profusely if it > + * can't set GBL_EN. > + */ > + pm1_enable = *eax & (PM1_PWRBTN_EN | PM1_GBL_EN); > + sci_update(ctx); > + } > + pthread_mutex_unlock(&pm_lock); > return (0); > } > INOUT_PORT(pm1_status, PM1A_EVT_ADDR, IOPORT_F_INOUT, pm1_status_handler); > INOUT_PORT(pm1_enable, PM1A_EVT_ADDR + 2, IOPORT_F_INOUT, pm1_enable_handler); > > +static void > +power_button_handler(int signal, enum ev_type type, void *arg) > +{ > + struct vmctx *ctx; > + > + ctx = arg; > + pthread_mutex_lock(&pm_lock); > + if (!(pm1_status & PM1_PWRBTN_STS)) { > + pm1_status |= PM1_PWRBTN_STS; > + sci_update(ctx); > + } > + pthread_mutex_unlock(&pm_lock); > +} > + > /* > * Power Management 1 Control Register > * > * This is mostly unimplemented except that we wish to handle writes that > * set SPL_EN to handle S5 (soft power off). > */ > +static uint16_t pm1_control; > + > +#define PM1_SCI_EN 0x0001 > #define PM1_SLP_TYP 0x1c00 > #define PM1_SLP_EN 0x2000 > #define PM1_ALWAYS_ZERO 0xc003 > @@ -112,7 +224,6 @@ > pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > uint32_t *eax, void *arg) > { > - static uint16_t pm1_control; > > if (bytes != 2) > return (-1); > @@ -121,9 +232,11 @@ > else { > /* > * Various bits are write-only or reserved, so force them > - * to zero in pm1_control. > + * to zero in pm1_control. Always preserve SCI_EN as OSPM > + * can never change it. > */ > - pm1_control = *eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO); > + pm1_control = (pm1_control & PM1_SCI_EN) | > + (*eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO)); > > /* > * If SLP_EN is set, check for S5. Bhyve's _S5_ method > @@ -137,3 +250,41 @@ > return (0); > } > INOUT_PORT(pm1_control, PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); > + > +/* > + * ACPI SMI Command Register > + * > + * This write-only register is used to enable and disable ACPI. > + */ > +static int > +smi_cmd_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, > + uint32_t *eax, void *arg) > +{ > + > + assert(!in); > + if (bytes != 1) > + return (-1); > + > + pthread_mutex_lock(&pm_lock); > + switch (*eax) { > + case BHYVE_ACPI_ENABLE: > + pm1_control |= PM1_SCI_EN; > + if (power_button == NULL) { > + power_button = mevent_add(SIGTERM, EVF_SIGNAL, > + power_button_handler, ctx); > + old_power_handler = signal(SIGTERM, SIG_IGN); > + } > + break; > + case BHYVE_ACPI_DISABLE: > + pm1_control &= ~PM1_SCI_EN; > + if (power_button != NULL) { > + mevent_delete(power_button); > + power_button = NULL; > + signal(SIGTERM, old_power_handler); > + } > + break; > + } > + pthread_mutex_unlock(&pm_lock); > + return (0); > +} > +INOUT_PORT(smi_cmd, SMI_CMD, IOPORT_F_OUT, smi_cmd_handler); > --- //depot/vendor/freebsd/src/usr.sbin/bhyve/pmtmr.c > +++ //depot/user/jhb/bhyve/usr.sbin/bhyve/pmtmr.c > @@ -40,6 +40,7 @@ > #include > #include > > +#include "acpi.h" > #include "inout.h" > > /* > @@ -49,11 +50,10 @@ > * This implementation will be 32-bits > */ > > -#define IO_PMTMR 0x408 /* 4-byte i/o port for the timer */ > - > #define PMTMR_FREQ 3579545 /* 3.579545MHz */ > > static pthread_mutex_t pmtmr_mtx; > +static pthread_once_t pmtmr_once = PTHREAD_ONCE_INIT; > > static uint64_t pmtmr_old; > > @@ -123,6 +123,7 @@ > pmtmr_uptime_old = tsnew; > pmtmr_old = timespec_to_pmtmr(&tsnew, &tsold); > } > + pthread_mutex_init(&pmtmr_mtx, NULL); > } > > static uint32_t > @@ -133,13 +134,7 @@ > uint64_t pmtmr_new; > int error; > > - static int inited = 0; > - > - if (!inited) { > - pthread_mutex_init(&pmtmr_mtx, NULL); > - pmtmr_init(); > - inited = 1; > - } > + pthread_once(&pmtmr_once, pmtmr_init); > > pthread_mutex_lock(&pmtmr_mtx); > > >> >> -- >> John Baldwin >> _______________________________________________ >> freebsd-virtualization@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization >> To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org" >> > > -- > John Baldwin > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org" From owner-freebsd-virtualization@FreeBSD.ORG Sat Dec 28 01:49:17 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6D3C9F8A; Sat, 28 Dec 2013 01:49:17 +0000 (UTC) Received: from mail-qe0-x235.google.com (mail-qe0-x235.google.com [IPv6:2607:f8b0:400d:c02::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1D37312B1; Sat, 28 Dec 2013 01:49:17 +0000 (UTC) Received: by mail-qe0-f53.google.com with SMTP id nc12so9509206qeb.40 for ; Fri, 27 Dec 2013 17:49:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=p88W7+vYGhB33M5C2aG5CVgaCIhm7kZSG7dtE23wmA0=; b=HDS99jUTcpJcTGz247D3SJdNz1JR+QqK8Asq+PfToUWq30G0viiaMF3NYiHUB2iwef QXKBZ66KiJOhuoexCBlknJZWQK9vZEHAa+rZDpMsKrlfZTPFAk9ExmxValYIecSzcdYy pwC1YgBg/2DAU54+8POcx84DYcYmt7YeLOJ3ASYeh7l2NEGxFWMogNT+mIC7pgMraV2F Xn6MEMQtNfgMtmOBZuZNce6YXQZwzvc2VSE7UvggJrvz0Xv79FyYPGwjhl4lr+VzAuKm QjzMB+6jpsToswk6wGixACjeRIcwQXH1pe9JyN6h8BM7P6CeiAn3t5HjiPeOMYGlDZ0q ncJQ== MIME-Version: 1.0 X-Received: by 10.224.97.65 with SMTP id k1mr63563911qan.67.1388195356338; Fri, 27 Dec 2013 17:49:16 -0800 (PST) Received: by 10.140.34.17 with HTTP; Fri, 27 Dec 2013 17:49:16 -0800 (PST) In-Reply-To: <201312271205.54102.jhb@freebsd.org> References: <201312271205.54102.jhb@freebsd.org> Date: Fri, 27 Dec 2013 17:49:16 -0800 Message-ID: Subject: Re: [PATCH] Rework DSDT generation in bhyve From: Neel Natu To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Sat, 28 Dec 2013 01:49:17 -0000 Hi John, On Fri, Dec 27, 2013 at 9:05 AM, John Baldwin wrote: > While hacking on the power button support, I also started rototilling the DSDT > generation code a bit. My initial goal was to enumerate the LPC serial ports > (COM1 and COM2) properly via ACPI. I ended up doing the following: > > - Moved the info for the top-level PCI bus into the PCI emulation code and > added ResourceProducer entries for the memory ranges decoded by the bus > for memory BARs. > - I added a framework to allow each PCI emulation driver to optionally write > an entry into the DSDT under the \_SB_.PCI0 namespace. The LPC driver uses > this to write a node for the LPC bus (\_SB_.PCI0.ISA). > - I added a linker set to allow any LPC devices to write entries into the > DSDT below the LPC node. I moved the existing block for the RTC out of > acpi.c and into the RTC driver. I added DSDT nodes for the AT PIC, > the 8254 ISA timer, and the LPC UART devices. > - I also added a "SuperIO" device under the LPC node to claim "system > resources" (as is done in real hardware). I added a linker set to allow > various drivers to add IO or memory ranges that should be claimed by > SuperIO and then added the extended RTC IO range and the registers used > for ACPI power management as system resources. > > The end result is that for the stock VM created by vmrun.sh, the attimer0, > uart0, and uart1 devices move from isa0 to acpi0. There is also a PIC > device that would be claimed by 'device atpic' (but the stock amd64 kernel > doesn't include that). The DSDT is also a bit more fleshed out, and also > looks "nice" as devices are mostly laid out in the normal tree rather than > using separate Scope() sections for each device. > > Note that I did add some helper routines for writing out DSDT lines and > resource entries to try to simplify the code in the various DSDT handlers > and make the code that generates DSDT lines a bit more readable (e.g. the > implicit newlines make things more readable IMO). > > The patch is relative to the previous power button patch and is at > http://www.FreeBSD.org/~jhb/patches/bhyve_dsdt.patch I am getting a "404 Not Found" at this URL. best Neel > > Assuming these are ok, the next thing I might work on is cleaning up > the PCI INTx interrupts. They should really all be rounted to the I/O APIC > intpins above 15 (and we should leave ISA IRQs 5, 10, and 11 alone in APIC > mode and only fall back to that if we are using the 8259As and a real ELCR). > The MP Table output would need some minor tweaking for that, and for ACPI we > should generate a _PRT table under _SB_.PCI0 in pci_emul.c. > > -- > John Baldwin > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org" From owner-freebsd-virtualization@FreeBSD.ORG Sat Dec 28 03:03:45 2013 Return-Path: Delivered-To: virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8601EAAA for ; Sat, 28 Dec 2013 03:03:45 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5B6721859 for ; Sat, 28 Dec 2013 03:03:45 +0000 (UTC) Received: from new-host-6.home (pool-173-70-85-31.nwrknj.fios.verizon.net [173.70.85.31]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id EDDCAB943; Fri, 27 Dec 2013 22:03:42 -0500 (EST) Message-ID: <52BE3FB0.7060809@FreeBSD.org> Date: Fri, 27 Dec 2013 22:04:16 -0500 From: John Baldwin User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Neel Natu Subject: Re: [PATCH] Rework DSDT generation in bhyve References: <201312271205.54102.jhb@freebsd.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 27 Dec 2013 22:03:43 -0500 (EST) Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 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: Sat, 28 Dec 2013 03:03:45 -0000 On 12/27/13 8:49 PM, Neel Natu wrote: > Hi John, > > On Fri, Dec 27, 2013 at 9:05 AM, John Baldwin wrote: >> While hacking on the power button support, I also started rototilling the DSDT >> generation code a bit. My initial goal was to enumerate the LPC serial ports >> (COM1 and COM2) properly via ACPI. I ended up doing the following: >> >> - Moved the info for the top-level PCI bus into the PCI emulation code and >> added ResourceProducer entries for the memory ranges decoded by the bus >> for memory BARs. >> - I added a framework to allow each PCI emulation driver to optionally write >> an entry into the DSDT under the \_SB_.PCI0 namespace. The LPC driver uses >> this to write a node for the LPC bus (\_SB_.PCI0.ISA). >> - I added a linker set to allow any LPC devices to write entries into the >> DSDT below the LPC node. I moved the existing block for the RTC out of >> acpi.c and into the RTC driver. I added DSDT nodes for the AT PIC, >> the 8254 ISA timer, and the LPC UART devices. >> - I also added a "SuperIO" device under the LPC node to claim "system >> resources" (as is done in real hardware). I added a linker set to allow >> various drivers to add IO or memory ranges that should be claimed by >> SuperIO and then added the extended RTC IO range and the registers used >> for ACPI power management as system resources. >> >> The end result is that for the stock VM created by vmrun.sh, the attimer0, >> uart0, and uart1 devices move from isa0 to acpi0. There is also a PIC >> device that would be claimed by 'device atpic' (but the stock amd64 kernel >> doesn't include that). The DSDT is also a bit more fleshed out, and also >> looks "nice" as devices are mostly laid out in the normal tree rather than >> using separate Scope() sections for each device. >> >> Note that I did add some helper routines for writing out DSDT lines and >> resource entries to try to simplify the code in the various DSDT handlers >> and make the code that generates DSDT lines a bit more readable (e.g. the >> implicit newlines make things more readable IMO). >> >> The patch is relative to the previous power button patch and is at >> http://www.FreeBSD.org/~jhb/patches/bhyve_dsdt.patch > > I am getting a "404 Not Found" at this URL. Oops, I forgot to upload it to freefall. It should be there now. -- John Baldwin