Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Apr 2009 23:12:33 -0400
From:      Sergey Babkin <babkin@verizon.net>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, Ivan Voras <ivoras@freebsd.org>
Subject:   Re: Patch for MS Hyper V (virtualization)
Message-ID:  <49DAC4A1.589A5FE@verizon.net>
References:  <1366225354.253456.1238948619308.JavaMail.root@vms124.mailsrvcs.net> <200904061154.19601.jhb@freebsd.org> <9bbcef730904061007y66a8440al3c43a6a6b6cd6ed6@mail.gmail.com> <200904061342.22000.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <jhb@freebsd.org>:
> > > 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)--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49DAC4A1.589A5FE>