From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 7 03:03:43 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6EAF010656F2; Tue, 7 Apr 2009 03:03:43 +0000 (UTC) (envelope-from babkin@verizon.net) Received: from vms173009pub.verizon.net (vms173009pub.verizon.net [206.46.173.9]) by mx1.freebsd.org (Postfix) with ESMTP id 499318FC0A; Tue, 7 Apr 2009 03:03:43 +0000 (UTC) (envelope-from babkin@verizon.net) MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_WiFBaHW3z0cbU6RwDfiehA)" Received: from verizon.net ([96.234.43.209]) by vms173009.mailsrvcs.net (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTPA id <0KHP0056BN5L84EC@vms173009.mailsrvcs.net>; Mon, 06 Apr 2009 22:03:21 -0500 (CDT) Sender: root Message-id: <49DAC4A1.589A5FE@verizon.net> Date: Mon, 06 Apr 2009 23:12:33 -0400 From: Sergey Babkin X-Mailer: Mozilla 4.7 [en] (X11; U; FreeBSD 4.7-RELEASE i386) X-Accept-Language: en, ru To: John Baldwin References: <1366225354.253456.1238948619308.JavaMail.root@vms124.mailsrvcs.net> <200904061154.19601.jhb@freebsd.org> <9bbcef730904061007y66a8440al3c43a6a6b6cd6ed6@mail.gmail.com> <200904061342.22000.jhb@freebsd.org> X-Mailman-Approved-At: Tue, 07 Apr 2009 04:49:07 +0000 Cc: freebsd-hackers@freebsd.org, Ivan Voras Subject: Re: Patch for MS Hyper V (virtualization) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2009 03:03:43 -0000 This is a multi-part message in MIME format. --Boundary_(ID_WiFBaHW3z0cbU6RwDfiehA) Content-type: text/plain; charset=koi8-r Content-transfer-encoding: 8BIT John Baldwin wrote: > > On Monday 06 April 2009 1:07:38 pm Ivan Voras wrote: > > 2009/4/6 John Baldwin : > > > On Sunday 05 April 2009 12:23:39 pm Sergey Babkin wrote: > > > > > Hmm, the problem is we need to be able to write to BARs to size them. Â Any > OS > > > needs to be able to do this to know what address space regions are being > > > decoded by devices. Â We can't avoid writing to BARs. > > > > I have only vague idea what BARs are and if it's the correct diagnosis > > in this case, but the fact is that other operating systems (Windows, > > Linux tested) work, so either there is a way around it or the original > > premise is wrong-ish. > > Every OS writes to BARs to size them during boot. It's the defined procedure > for sizing them. A BAR is a base address register, and it is how a PCI > device gets memory and I/O port resources. OS (or BIOS) writes a starting > address into the register to tell the PCI device where a given > resource "starts". The OS doesn't have to write to the BAR if BIOS has already done it. And the BIOS in the Hyper-V VM is obviously special, so it doesn't trip on iself. Anyway, as far as I can tell, it's only the base register of the simulated DEC21140 device that has this issue, so it's quite possible that the bug is in that device's simulator. I've attached a modified patch that checks conservatively for this precise situation, so it should not break compatibility with anything else. I've tested it on Hyper-V. -SB --Boundary_(ID_WiFBaHW3z0cbU6RwDfiehA) Content-type: text/plain; charset=koi8-r; name=hyperv.df Content-transfer-encoding: 7BIT Content-disposition: inline; filename=hyperv.df --- dev/pci/pci.c.0 2009-04-06 21:35:26.000000000 +0000 +++ dev/pci/pci.c 2009-04-06 22:43:08.000000000 +0000 @@ -3590,6 +3590,18 @@ struct pci_devinfo *dinfo = device_get_ivars(child); pcicfgregs *cfg = &dinfo->cfg; + /* A workaround for Hyper-V that hangs on VM stop + * if the base address register of the 21140 simulator is written; + * since on Hyper-V the value written is the same as the one + * already in the register, it can be simply skipped. + * 0x1011: DEC, 0x0009: 21140 */ + if (dinfo->cfg.vendor == 0x1011 && dinfo->cfg.device == 0x0009) { + if (reg == PCIR_BARS + && (val & ~3) == (PCIB_READ_CONFIG(device_get_parent(dev), + cfg->bus, cfg->slot, cfg->func, reg, width) & ~3) ) + return; + } + PCIB_WRITE_CONFIG(device_get_parent(dev), cfg->bus, cfg->slot, cfg->func, reg, val, width); } --Boundary_(ID_WiFBaHW3z0cbU6RwDfiehA)--