From: "Jan Beulich" Subject: [PATCH] x86: allow Dom0 read-only access to IO-APICs Date: Thu, 02 May 2013 07:31:22 +0100 Message-ID: <5182245A02000078000D26B0@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part99A9472A.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser , Konrad Rzeszutek Wilk 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. --=__Part99A9472A.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline There are BIOSes that want to map the IO-APIC MMIO region from some ACPI method(s), and there is at least one BIOS flavor that wants to use this mapping to clear an RTE's mask bit. While we can't allow the latter, we can permit reads and simply drop write attempts, leveraging the already existing infrastructure introduced for dealing with AMD IOMMUs' representation as PCI devices. This fixes an interrupt setup problem on a system where _CRS evaluation involved the above described BIOS/ACPI behavior, and is expected to also deal with a boot time crash of pv-ops Linux upon encountering the same kind of system. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -1114,7 +1114,7 @@ int __init construct_dom0( for ( i =3D 0; i < nr_ioapics; i++ ) { mfn =3D paddr_to_pfn(mp_ioapics[i].mpc_apicaddr); - if ( smp_found_config ) + if ( !rangeset_contains_singleton(mmio_ro_ranges, mfn) ) rc |=3D iomem_deny_access(dom0, mfn, mfn); } =20 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -2468,6 +2468,9 @@ void __init init_ioapic_mappings(void) unsigned int i, idx =3D FIX_IO_APIC_BASE_0; union IO_APIC_reg_01 reg_01; =20 + mmio_ro_ranges =3D rangeset_new(NULL, "r/o mmio ranges", + RANGESETF_prettyprint_hex); + if ( smp_found_config ) nr_irqs_gsi =3D 0; for ( i =3D 0; i < nr_ioapics; i++ ) @@ -2507,6 +2510,11 @@ void __init init_ioapic_mappings(void) reg_01.raw =3D io_apic_read(i, 1); nr_ioapic_entries[i] =3D reg_01.bits.entries + 1; nr_irqs_gsi +=3D nr_ioapic_entries[i]; + + if ( rangeset_add_singleton(mmio_ro_ranges, + ioapic_phys >> PAGE_SHIFT) ) + printk(KERN_ERR "Failed to mark IO-APIC page %lx = read-only\n", + ioapic_phys); } } =20 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -105,8 +105,6 @@ void __init pt_pci_init(void) radix_tree_init(&pci_segments); if ( !alloc_pseg(0) ) panic("Could not initialize PCI segment 0\n"); - mmio_ro_ranges =3D rangeset_new(NULL, "r/o mmio ranges", - RANGESETF_prettyprint_hex); } =20 int __init pci_add_segment(u16 seg) --=__Part99A9472A.1__= Content-Type: text/plain; name="x86-ioapic-dom0-allow-ro.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-ioapic-dom0-allow-ro.patch" x86: allow Dom0 read-only access to IO-APICs=0A=0AThere are BIOSes that = want to map the IO-APIC MMIO region from some=0AACPI method(s), and there = is at least one BIOS flavor that wants to=0Ause this mapping to clear an = RTE's mask bit. While we can't allow the=0Alatter, we can permit reads and = simply drop write attempts, leveraging=0Athe already existing infrastructur= e introduced for dealing with AMD=0AIOMMUs' representation as PCI = devices.=0A=0AThis fixes an interrupt setup problem on a system where _CRS = evaluation=0Ainvolved the above described BIOS/ACPI behavior, and is = expected to=0Aalso deal with a boot time crash of pv-ops Linux upon = encountering the=0Asame kind of system.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/domain_build.c=0A+++ b/xen/arch= /x86/domain_build.c=0A@@ -1114,7 +1114,7 @@ int __init construct_dom0(=0A = for ( i =3D 0; i < nr_ioapics; i++ )=0A {=0A mfn =3D = paddr_to_pfn(mp_ioapics[i].mpc_apicaddr);=0A- if ( smp_found_config = )=0A+ if ( !rangeset_contains_singleton(mmio_ro_ranges, mfn) )=0A = rc |=3D iomem_deny_access(dom0, mfn, mfn);=0A }=0A =0A--- = a/xen/arch/x86/io_apic.c=0A+++ b/xen/arch/x86/io_apic.c=0A@@ -2468,6 = +2468,9 @@ void __init init_ioapic_mappings(void)=0A unsigned int i, = idx =3D FIX_IO_APIC_BASE_0;=0A union IO_APIC_reg_01 reg_01;=0A =0A+ = mmio_ro_ranges =3D rangeset_new(NULL, "r/o mmio ranges",=0A+ = RANGESETF_prettyprint_hex);=0A+=0A if ( smp_found_co= nfig )=0A nr_irqs_gsi =3D 0;=0A for ( i =3D 0; i < nr_ioapics; = i++ )=0A@@ -2507,6 +2510,11 @@ void __init init_ioapic_mappings(void)=0A = reg_01.raw =3D io_apic_read(i, 1);=0A nr_ioapic_entri= es[i] =3D reg_01.bits.entries + 1;=0A nr_irqs_gsi +=3D = nr_ioapic_entries[i];=0A+=0A+ if ( rangeset_add_singleton(mmio_r= o_ranges,=0A+ ioapic_phys >> = PAGE_SHIFT) )=0A+ printk(KERN_ERR "Failed to mark IO-APIC = page %lx read-only\n",=0A+ ioapic_phys);=0A = }=0A }=0A =0A--- a/xen/drivers/passthrough/pci.c=0A+++ b/xen/drivers/pa= ssthrough/pci.c=0A@@ -105,8 +105,6 @@ void __init pt_pci_init(void)=0A = radix_tree_init(&pci_segments);=0A if ( !alloc_pseg(0) )=0A = panic("Could not initialize PCI segment 0\n");=0A- mmio_ro_ranges =3D = rangeset_new(NULL, "r/o mmio ranges",=0A- = RANGESETF_prettyprint_hex);=0A }=0A =0A int __init pci_add_segment(u16 = seg)=0A --=__Part99A9472A.1__= 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 --=__Part99A9472A.1__=--