From: "Jan Beulich" Subject: Re: GPU passthrough performance regression in >4GB vms due to XSA-60 changes Date: Fri, 16 May 2014 15:36:43 +0100 Message-ID: <53763E9B0200007800013260@mail.emea.novell.com> References: <537484A9.9000001@gmail.com> <5374CFF80200007800012A53@mail.emea.novell.com> <5374AEBD.7090403@gmail.com> <5374DBFD0200007800012AEE@mail.emea.novell.com> <5374C389.507@gmail.com> <5374D08F.2050202@gmail.com> <5374D5B0.2080808@gmail.com> <537502710200007800012C7E@mail.emea.novell.com> <5374DFCA.10207@gmail.com> <5375CD4F0200007800012E27@mail.emea.novell.com> <5375F410.2060406@gmail.com> <537614F30200007800013139@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part04362C6B.2__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WlJFe-0004ey-Ou for xen-devel@lists.xenproject.org; Fri, 16 May 2014 14:36:47 +0000 In-Reply-To: <537614F30200007800013139@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Tomasz Wroblewski Cc: Jinsong Liu , xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part04362C6B.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 16.05.14 at 13:38, wrote: >>>> On 16.05.14 at 13:18, wrote: >>> If I coded up a patch to deal with this on -unstable, would you be >>> able to test that? >> Willing to give it a go (xen major version updates are often problematic= =20 >> to do though so can't promise success). What would your patch be = doing?=20 >> Adding entries to MTRR for the relocated regions? >=20 > This and properly declare the region in ACPI's _CRS. For starters I'll > probably try keeping the WB default overlaid with UC variable ranges, > as that's going to be the less intrusive change. Okay here are two patches - the first to deal with the above mentioned items, and the second to further increase correctness and at once shrink the number of MTRR regions needed. Afaict they apply equally well to stable-4.3, master, and staging. But to be honest I don't expect any performance improvement, all I'd expect is that BARs relocated above 4Gb would now get treated equally to such below 4Gb - UC in all cases. Jan --=__Part04362C6B.2__= Content-Type: text/plain; name="hvmloader-PCI-above-4G.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="hvmloader-PCI-above-4G.patch" --- a/tools/firmware/hvmloader/acpi/build.c=0A+++ b/tools/firmware/hvmloade= r/acpi/build.c=0A@@ -53,6 +53,7 @@ struct acpi_info {=0A uint32_t = madt_csum_addr; /* 12 - Address of MADT checksum */=0A uint32_t = madt_lapic0_addr; /* 16 - Address of first MADT LAPIC struct */=0A = uint32_t vm_gid_addr; /* 20 - Address of VM generation id buffer = */=0A+ uint64_t pci_hi_min, pci_hi_len; /* 24, 32 - PCI I/O hole = boundaries */=0A };=0A =0A /* Number of processor objects in the chosen = DSDT. */=0A@@ -541,6 +542,11 @@ void acpi_build_tables(struct acpi_confi=0A= acpi_info->hpet_present =3D hpet_exists(ACPI_HPET_ADDRESS);=0A = acpi_info->pci_min =3D pci_mem_start;=0A acpi_info->pci_len =3D = pci_mem_end - pci_mem_start;=0A+ if ( pci_hi_mem_end > pci_hi_mem_start = )=0A+ {=0A+ acpi_info->pci_hi_min =3D pci_hi_mem_start;=0A+ = acpi_info->pci_hi_len =3D pci_hi_mem_end - pci_hi_mem_start;=0A+ }=0A = =0A return;=0A =0A--- a/tools/firmware/hvmloader/acpi/dsdt.asl=0A+++ = b/tools/firmware/hvmloader/acpi/dsdt.asl=0A@@ -45,7 +45,7 @@ DefinitionBloc= k ("DSDT.aml", "DSDT", 2, =0A Scope (\_SB)=0A {=0A /* = ACPI_INFO_PHYSICAL_ADDRESS =3D=3D 0xFC000000 */=0A- OperationRegion(B= IOS, SystemMemory, 0xFC000000, 24)=0A+ OperationRegion(BIOS, = SystemMemory, 0xFC000000, 40)=0A Field(BIOS, ByteAcc, NoLock, = Preserve) {=0A UAR1, 1,=0A UAR2, 1,=0A@@ -56,7 +56,9 = @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, =0A PLEN, 32,=0A = MSUA, 32, /* MADT checksum address */=0A MAPA, 32, /* = MADT LAPIC0 address */=0A- VGIA, 32 /* VM generation id address = */=0A+ VGIA, 32, /* VM generation id address */=0A+ = HMIN, 64,=0A+ HLEN, 64=0A }=0A =0A /* Fix HCT = test for 0x400 pci memory:=0A@@ -136,7 +138,7 @@ DefinitionBlock ("DSDT.aml= ", "DSDT", 2, =0A /* reserve memory for pci devices = */=0A DWordMemory(=0A = ResourceProducer, PosDecode, MinFixed, MaxFixed,=0A- = Cacheable, ReadWrite,=0A+ WriteCombining, = ReadWrite,=0A 0x00000000,=0A = 0x000A0000,=0A 0x000BFFFF,=0A@@ -145,13 +147,24 = @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, =0A =0A = DWordMemory(=0A ResourceProducer, PosDecode, = MinFixed, MaxFixed,=0A- Cacheable, ReadWrite,=0A+ = NonCacheable, ReadWrite,=0A = 0x00000000,=0A 0xF0000000,=0A = 0xF4FFFFFF,=0A 0x00000000,=0A = 0x05000000,=0A ,, _Y01)=0A+=0A+ = QWordMemory (=0A+ ResourceProducer, PosDecode,= MinFixed, MaxFixed,=0A+ NonCacheable, ReadWrite,=0A= + 0x0000000000000000,=0A+ = 0x0000000000000000,=0A+ 0x0000000000000000,=0A+ = 0x0000000000000000,=0A+ = 0x0000000000000000,=0A+ ,, _Y02)=0A+=0A = })=0A =0A CreateDWordField(PRT0, \_SB.PCI0._CRS._Y01._M= IN, MMIN)=0A@@ -163,6 +176,15 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, = =0A Add(MMIN, MLEN, MMAX)=0A Subtract(MMAX,= One, MMAX)=0A =0A+ CreateQWordField(PRT0, \_SB.PCI0._CRS._Y= 02._MIN, HMIN)=0A+ CreateQWordField(PRT0, \_SB.PCI0._CRS._Y0= 2._MAX, HMAX)=0A+ CreateQWordField(PRT0, \_SB.PCI0._CRS._Y02= ._LEN, HLEN)=0A+=0A+ Store(\_SB.HMIN, HMIN)=0A+ = Store(\_SB.HLEN, HLEN)=0A+ Add(HMIN, HLEN, HMAX)=0A+ = Subtract(HMAX, One, HMAX)=0A+=0A Return = (PRT0)=0A }=0A =0A--- a/tools/firmware/hvmloader/cacheattr.c=0A= +++ b/tools/firmware/hvmloader/cacheattr.c=0A@@ -97,8 +97,7 @@ void = cacheattr_init(void)=0A nr_var_ranges =3D (uint8_t)mtrr_cap;=0A if = ( nr_var_ranges !=3D 0 )=0A {=0A- unsigned long base =3D = pci_mem_start, size;=0A- int i;=0A+ uint64_t base =3D = pci_mem_start, size;=0A =0A for ( i =3D 0; (base !=3D pci_mem_end) = && (i < nr_var_ranges); i++ )=0A {=0A@@ -109,8 +108,22 @@ void = cacheattr_init(void)=0A size >>=3D 1;=0A =0A = wrmsr(MSR_MTRRphysBase(i), base);=0A- wrmsr(MSR_MTRRphysMask(i),= =0A- (~(uint64_t)(size-1) & addr_mask) | (1u << 11));=0A+ = wrmsr(MSR_MTRRphysMask(i), (~(size - 1) & addr_mask) | (1u << = 11));=0A+=0A+ base +=3D size;=0A+ }=0A+=0A+ for ( = base =3D pci_hi_mem_start;=0A+ (base !=3D pci_hi_mem_end) && = (i < nr_var_ranges); i++ )=0A+ {=0A+ size =3D PAGE_SIZE;= =0A+ while ( !(base & size) )=0A+ size <<=3D = 1;=0A+ while ( (base + size < base) || (base + size > pci_hi_mem= _end) )=0A+ size >>=3D 1;=0A+=0A+ wrmsr(MSR_MTRRp= hysBase(i), base);=0A+ wrmsr(MSR_MTRRphysMask(i), (~(size - 1) = & addr_mask) | (1u << 11));=0A =0A base +=3D size;=0A = }=0A--- a/tools/firmware/hvmloader/config.h=0A+++ b/tools/firmware/hvmloade= r/config.h=0A@@ -57,7 +57,7 @@ extern struct bios_config ovmf_config;=0A = #define PCI_MEM_END 0xfc000000=0A =0A extern unsigned long = pci_mem_start, pci_mem_end;=0A-=0A+extern uint64_t pci_hi_mem_start, = pci_hi_mem_end;=0A =0A /* Memory map. */=0A #define SCRATCH_PHYSICAL_ADDRES= S 0x00010000=0A--- a/tools/firmware/hvmloader/pci.c=0A+++ b/tools/firm= ware/hvmloader/pci.c=0A@@ -32,6 +32,7 @@=0A =0A unsigned long pci_mem_start= =3D PCI_MEM_START;=0A unsigned long pci_mem_end =3D PCI_MEM_END;=0A+uint64= _t pci_hi_mem_start =3D 0, pci_hi_mem_end =3D 0;=0A =0A enum virtual_vga = virtual_vga =3D VGA_none;=0A unsigned long igd_opregion_pgbase =3D 0;=0A@@ = -345,9 +346,8 @@ void pci_setup(void)=0A if ( high_mem_reso= urce.base & (bar_sz - 1) )=0A high_mem_resource.base = =3D high_mem_resource.base - =0A (high_mem_resource= .base & (bar_sz - 1)) + bar_sz;=0A- else=0A- = high_mem_resource.base =3D high_mem_resource.base - =0A- = (high_mem_resource.base & (bar_sz - 1));=0A+ if ( = !pci_hi_mem_start )=0A+ pci_hi_mem_start =3D high_mem_re= source.base;=0A resource =3D &high_mem_resource;=0A = bar_data &=3D ~PCI_BASE_ADDRESS_MEM_MASK;=0A } =0A@@ = -398,6 +398,16 @@ void pci_setup(void)=0A pci_writew(devfn, = PCI_COMMAND, cmd);=0A }=0A =0A+ if ( pci_hi_mem_start )=0A+ = {=0A+ /*=0A+ * Make end address alignment match the start = address one's so that=0A+ * fewer variable range MTRRs are needed = to cover the range.=0A+ */=0A+ pci_hi_mem_end =3D ((high_mem= _resource.base - 1) |=0A+ ((pci_hi_mem_start & = -pci_hi_mem_start) - 1)) + 1;=0A+ }=0A+=0A if ( vga_devfn !=3D 256 = )=0A {=0A /*=0A --=__Part04362C6B.2__= Content-Type: text/plain; name="hvmloader-UC-up-to-4G.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="hvmloader-UC-up-to-4G.patch" --- a/tools/firmware/hvmloader/cacheattr.c=0A+++ b/tools/firmware/hvmloader= /cacheattr.c=0A@@ -99,12 +99,12 @@ void cacheattr_init(void)=0A {=0A = uint64_t base =3D pci_mem_start, size;=0A =0A- for ( i =3D 0; = (base !=3D pci_mem_end) && (i < nr_var_ranges); i++ )=0A+ for ( i = =3D 0; !(base >> 32) && (i < nr_var_ranges); i++ )=0A {=0A = size =3D PAGE_SIZE;=0A while ( !(base & size) )=0A = size <<=3D 1;=0A- while ( ((base + size) < base) || = ((base + size) > pci_mem_end) )=0A+ while ( ((base + size) < = base) || ((base + size - 1) >> 32) )=0A size >>=3D 1;=0A = =0A wrmsr(MSR_MTRRphysBase(i), base);=0A --=__Part04362C6B.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part04362C6B.2__=--