From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?GB2312?B?09q80bj7?= Subject: Re: How to switch VGA passthrough live Date: Tue, 8 Jun 2010 11:18:56 +0800 Message-ID: References: <20100605084314.GB16920@angi.xci-test.com> <20100607091313.GA31058@angi.xci-test.com> Mime-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20100607091313.GA31058@angi.xci-test.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jean Guyader , yuri.schaeffer@os3.nl, allen.m.kay@intel.com Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Thanks for your reminding. This method will pass sci interrupt and straightly invoke power_off_php_devfn function. It solves two problems: 1. Detach VGA passthrough device from HVM-1 2. Assign VGA passthrough device to a new HVM-2 during its creating process The limit of this method is that we cannot assign VGA dev back to HVM-1. I did some research and tried to find the reason. When unregistering a real device at power_off_php_devfn function, all the mmio/pio maps and irqs related to the dev are destroyed. The output of Xen is as below: Xm pci-detach 00:00:02.0 (XEN) domctl.c:1001:d0 memory_map:remove: gfn=3Df1000 mfn=3Dfe800 nr_mfns= =3D400 (XEN) domctl.c:1001:d0 memory_map:remove: gfn=3De0000 mfn=3Dd0000 nr_mfns= =3D10000 (XEN) domctl.c:1071:d0 ioport_map:remove f_gport=3Dc2d0 f_mport=3Dec90 np= =3D8 (XEN) domctl.c:1071:d0 ioport_map:remove f_gport=3D3b0 f_mport=3D3b0 np=3Dc (XEN) domctl.c:1071:d0 ioport_map:remove f_gport=3D3c0 f_mport=3D3c0 np=3D2= 0 (XEN) domctl.c:1001:d0 memory_map:remove: gfn=3Da0 mfn=3Da0 nr_mfns=3D20 On the contrary, if we register a new VGA device using power_on_php_devfn function, the output of Xen is: Xm pci-attach 00:00:02.0 (XEN) domctl.c:1047:d0 ioport_map:add f_gport=3D3b0 f_mport=3D3b0 np=3Dc (XEN) domctl.c:1047:d0 ioport_map:add f_gport=3D3c0 f_mport=3D3c0 np=3D20 (XEN) domctl.c:991:d0 memory_map:add: gfn=3Da0 mfn=3Da0 nr_mfns=3D20 In conclusion, part of VGA initial work has done during video BIOS staring. Only invoking power_on_php_devfn function cannot rebuild full context of VGA dev. I also trace power_off_php_devfn function, and find that the screen will be shutdown as long as invoking pci_hide_device. Could anybody know why? Maybe we can implement pci_unhide_device function to switch passthrough dev between HVM domains. Thanks & Regards Yujiageng 2010/6/7 Jean Guyader > > Here is a patch for xen-4 (ioemu). > > Jean > > P.S.: Please don't forget to CC the mailing list when you reply. > Your messages could be useful for other people. Thanks. > > --- > > diff --git a/xen-vl-extra.c b/xen-vl-extra.c > index 206ac65..bafc5a4 100644 > --- a/xen-vl-extra.c > +++ b/xen-vl-extra.c > @@ -111,13 +111,18 @@ void do_pci_del(char *devname) > > devfn =3D bdf_to_devfn(devname); > > - if (devfn < 0) > + if (devfn < 0 && devfn =3D=3D 0x10) > fprintf(logfile, "Device \"%s\" is not used by a hotplug device.\= n", > devname_cpy); > else > acpi_php_del(devfn); > > free(devname_cpy); > + if (devfn =3D=3D 0x10) > + { > + power_off_php_devfn(devfn); > + xenstore_record_dm_state("pci-removed"); > + } > } > > void do_pci_add(char *devname) > > On Mon, Jun 07, 2010 at 02:54:00AM +0100, =D3=DA=BC=D1=B8=FB wrote: > > > > It seems a complex work. Could you give the old patch, and I try to por= t it on Xen4.0. > > > > 2010/6/5 Jean Guyader > > > > > Hi, > > > > I tried that in the past and is was working fine but you have to put th= e > > guest into S3 (acpi suspend to RAM) first, then we don't have to wait f= or > > any ACPI hotplug ack (you could remove some code in qemu for that). > > > > Jean > > > > On Fri, Jun 04, 2010 at 10:29:43AM +0100, =D3=DA=BC=D1=B8=FB wrote: > > > Hi, > > > > > > I want to switch video card live between two HVMs. My simplest idea i= s that when the HVM has the permission to access passthrough video card, an= d another HVM will be paused. If switch from A to B, execute commands : > > > > > > xm pause A ; > > > xm pci-detach A 00:00:02.0 ; > > > xm pci-attach B 00:00:02.0 ; > > > xm unpause B. > > > > > > I have a try, but failed. The pseudo-code is as below. Can you give m= e some ideas? Any suggestions will be thankful. > > > > > > Execute "xm pci-detach Domain 00:00:02.0": > > > > > > 1. Raise sci interrupt to unplug the device. If OSPM doesn't ha= ndle the unplug process, and then invoke acpi_php_writeb to power off the d= evice. > > > > > > 2. Modify power_off_php_devfn function: > > > int power_off_php_devfn(int php_devfn) > > > { > > > If(php_devfn =3D=3D 0x10) // Intel integrated gr= aphics > > > { > > > p =3D & dpci_infos.php_devs[php_devfn]; > > > > > > // save the two-tuples : (php_dev, domid) > > > save_php_device_by_domid(p,domid); > > > > > > // hide the device from bus and dpci_infos > > > pci_hide_device(& p->pt_dev->dev); > > > memset(p,0x00,sizeof(struct php_dev)); > > > > > > return 0; > > > } > > > > > > return unregister_real_device(php_devfn); > > > > > > } > > > > > > Execute "xm pci-attach Domain 00:00:02.0": > > > > > > 1. Modify power_on_php_devfn function: > > > > > > int power_off_php_devfn(int devfn) > > > > > > { > > > > > > .... > > > > > > while(devfn =3D=3D 0x10) // Intel integrated graphics > > > > > > { > > > > > > if( ! get_php_device_by_domid(p,domid) ) // get s= aved php_dev struct > > > > > > break; = // cannot get , create new one > > > > > > > > > > > > //restore the php device to bus and dpci_infos > > > > > > restore_php_device(p,devfn); // restore d= pci_infos.php_devs[devfn] > > > > > > dpci_infos->e_bus->devices[devfn] =3D p-> pt_dev-= >dev; > > > > > > > > > > > > return 0; > > > > > > } > > > > > > > > > > > > if (!dpci_infos.pci_access) > > > > > > {...} > > > > > > pt_dev =3D register_real_device(..); > > > > > > return 0; > > > > > > } > > > > > > This plan hides the VGA device from HVM and never destroys it. Both m= mio and pio maps are reserved. When finishing "xm unpause B", it seems work= ing well observed by Dom0 serial port login. But the screen is black and ca= nnot receive any signal. I am confusing. Video BIOS should be reloaded? Or = need raise some interrupt to flush screen? > > > > > > > > > Thanks & Regards, > > > Yujiageng > > > > > _______________________________________________ > > > Xen-devel mailing list > > > Xen-devel@lists.xensource.com > > > http://lists.xensource.com/xen-devel > > > >