From: "Jan Beulich" Subject: [PATCH v5 7/7] x86/PCI: intercept all PV Dom0 MMCFG writes Date: Mon, 20 Jul 2015 15:23:36 +0100 Message-ID: <55AD208802000078000932C1@mail.emea.novell.com> References: <55AD1E830200007800093243@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartECD81978.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZHH7s-0000X4-AR for xen-devel@lists.xenproject.org; Mon, 20 Jul 2015 19:53:24 +0000 In-Reply-To: <55AD1E830200007800093243@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: xen-devel Cc: Andrew Cooper , Keir Fraser , Roger Pau Monne 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. --=__PartECD81978.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... to hook up pci_conf_write_intercept() even for Dom0 not using method 1 accesses for the base part of PCI device config space. Signed-off-by: Jan Beulich --- Not entirely sure whether the complicated logging logic in x86/mm.c is actually worth it. --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -734,6 +734,46 @@ static int update_xen_mappings(unsigned=20 return err; } =20 +#ifndef NDEBUG +struct mmio_emul_range_ctxt { + const struct domain *d; + unsigned long mfn; +}; + +static int print_mmio_emul_range(unsigned long s, unsigned long e, void = *arg) +{ + const struct mmio_emul_range_ctxt *ctxt =3D arg; + + if ( ctxt->mfn > e ) + return 0; + + if ( ctxt->mfn >=3D s ) + { + static DEFINE_SPINLOCK(last_lock); + static const struct domain *last_d; + static unsigned long last_s =3D ~0UL, last_e; + bool_t print =3D 0; + + spin_lock(&last_lock); + if ( last_d !=3D ctxt->d || last_s !=3D s || last_e !=3D e ) + { + last_d =3D ctxt->d; + last_s =3D s; + last_e =3D e; + print =3D 1; + } + spin_unlock(&last_lock); + + if ( print ) + printk(XENLOG_G_INFO + "d%d: Forcing write emulation on MFNs %lx-%lx\n", + ctxt->d->domain_id, s, e); + } + + return 1; +} +#endif + int get_page_from_l1e( l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner) @@ -757,6 +797,11 @@ get_page_from_l1e( if ( !mfn_valid(mfn) || (real_pg_owner =3D page_get_owner_and_reference(page)) =3D=3D = dom_io ) { +#ifndef NDEBUG + const unsigned long *ro_map; + unsigned int seg, bdf; +#endif + /* Only needed the reference to confirm dom_io ownership. */ if ( mfn_valid(mfn) ) put_page(page); @@ -792,9 +837,20 @@ get_page_from_l1e( if ( !(l1f & _PAGE_RW) || !rangeset_contains_singleton(mmio_ro_ranges, mfn) ) return 0; - dprintk(XENLOG_G_WARNING, - "d%d: Forcing read-only access to MFN %lx\n", - l1e_owner->domain_id, mfn); +#ifndef NDEBUG + if ( !pci_mmcfg_decode(mfn, &seg, &bdf) || + ((ro_map =3D pci_get_ro_map(seg)) !=3D NULL && + test_bit(bdf, ro_map)) ) + printk(XENLOG_G_WARNING + "d%d: Forcing read-only access to MFN %lx\n", + l1e_owner->domain_id, mfn); + else + rangeset_report_ranges(mmio_ro_ranges, 0, ~0UL, + print_mmio_emul_range, + &(struct mmio_emul_range_ctxt){ + .d =3D l1e_owner, + .mfn =3D mfn }); +#endif return 1; } =20 @@ -5145,6 +5201,7 @@ int ptwr_do_page_fault(struct vcpu *v, u =20 /* We are looking only for read-only mappings of p.t. pages. */ if ( ((l1e_get_flags(pte) & (_PAGE_PRESENT|_PAGE_RW)) !=3D _PAGE_PRESE= NT) || + rangeset_contains_singleton(mmio_ro_ranges, l1e_get_pfn(pte)) || !get_page_from_pagenr(l1e_get_pfn(pte), d) ) goto bail; =20 @@ -5192,6 +5249,7 @@ int ptwr_do_page_fault(struct vcpu *v, u struct mmio_ro_emulate_ctxt { struct x86_emulate_ctxt ctxt; unsigned long cr2; + unsigned int seg, bdf; }; =20 static int mmio_ro_emulated_read( @@ -5231,6 +5289,44 @@ static const struct x86_emulate_ops mmio .write =3D mmio_ro_emulated_write, }; =20 +static int mmio_intercept_write( + enum x86_segment seg, + unsigned long offset, + void *p_data, + unsigned int bytes, + struct x86_emulate_ctxt *ctxt) +{ + struct mmio_ro_emulate_ctxt *mmio_ctxt =3D + container_of(ctxt, struct mmio_ro_emulate_ctxt, ctxt); + + /* + * Only allow naturally-aligned stores no wider than 4 bytes to the + * original %cr2 address. + */ + if ( ((bytes | offset) & (bytes - 1)) || bytes > 4 || + offset !=3D mmio_ctxt->cr2 ) + { + MEM_LOG("mmio_intercept: bad write (cr2=3D%lx, addr=3D%lx, = bytes=3D%u)", + mmio_ctxt->cr2, offset, bytes); + return X86EMUL_UNHANDLEABLE; + } + + offset &=3D 0xfff; + pci_conf_write_intercept(mmio_ctxt->seg, mmio_ctxt->bdf, offset, = bytes, + p_data); + pci_mmcfg_write(mmio_ctxt->seg, PCI_BUS(mmio_ctxt->bdf), + PCI_DEVFN2(mmio_ctxt->bdf), offset, bytes, + *(uint32_t *)p_data); + + return X86EMUL_OKAY; +} + +static const struct x86_emulate_ops mmio_intercept_ops =3D { + .read =3D mmio_ro_emulated_read, + .insn_fetch =3D ptwr_emulated_read, + .write =3D mmio_intercept_write, +}; + /* Check if guest is trying to modify a r/o MMIO page. */ int mmio_ro_do_page_fault(struct vcpu *v, unsigned long addr, struct cpu_user_regs *regs) @@ -5245,6 +5341,7 @@ int mmio_ro_do_page_fault(struct vcpu *v .ctxt.swint_emulate =3D x86_swint_emulate_none, .cr2 =3D addr }; + const unsigned long *ro_map; int rc; =20 /* Attempt to read the PTE that maps the VA being accessed. */ @@ -5269,7 +5366,12 @@ int mmio_ro_do_page_fault(struct vcpu *v if ( !rangeset_contains_singleton(mmio_ro_ranges, mfn) ) return 0; =20 - rc =3D x86_emulate(&mmio_ro_ctxt.ctxt, &mmio_ro_emulate_ops); + if ( pci_mmcfg_decode(mfn, &mmio_ro_ctxt.seg, &mmio_ro_ctxt.bdf) && + ((ro_map =3D pci_get_ro_map(mmio_ro_ctxt.seg)) =3D=3D NULL || + !test_bit(mmio_ro_ctxt.bdf, ro_map)) ) + rc =3D x86_emulate(&mmio_ro_ctxt.ctxt, &mmio_intercept_ops); + else + rc =3D x86_emulate(&mmio_ro_ctxt.ctxt, &mmio_ro_emulate_ops); =20 return rc !=3D X86EMUL_UNHANDLEABLE ? EXCRET_fault_fixed : 0; } --- a/xen/arch/x86/x86_64/mmconfig_64.c +++ b/xen/arch/x86/x86_64/mmconfig_64.c @@ -134,30 +134,10 @@ static void __iomem *mcfg_ioremap(const=20 return (void __iomem *) virt; } =20 -void arch_pci_ro_device(int seg, int bdf) -{ - unsigned int idx, bus =3D PCI_BUS(bdf); - - for (idx =3D 0; idx < pci_mmcfg_config_num; ++idx) { - const struct acpi_mcfg_allocation *cfg =3D pci_mmcfg_virt[idx].cfg= ; - unsigned long mfn =3D (cfg->address >> PAGE_SHIFT) + bdf; - - if (!pci_mmcfg_virt[idx].virt || cfg->pci_segment !=3D seg || - cfg->start_bus_number > bus || cfg->end_bus_number < bus) - continue; - - if (rangeset_add_singleton(mmio_ro_ranges, mfn)) - printk(XENLOG_ERR - "%04x:%02x:%02x.%u: could not mark MCFG (mfn %#lx) = read-only\n", - cfg->pci_segment, bus, PCI_SLOT(bdf), PCI_FUNC(bdf), - mfn); - } -} - int pci_mmcfg_arch_enable(unsigned int idx) { const typeof(pci_mmcfg_config[0]) *cfg =3D pci_mmcfg_virt[idx].cfg; - const unsigned long *ro_map =3D pci_get_ro_map(cfg->pci_segment); + unsigned long start_mfn, end_mfn; =20 if (pci_mmcfg_virt[idx].virt) return 0; @@ -169,16 +149,15 @@ int pci_mmcfg_arch_enable(unsigned int i } printk(KERN_INFO "PCI: Using MCFG for segment %04x bus %02x-%02x\n", cfg->pci_segment, cfg->start_bus_number, cfg->end_bus_number); - if (ro_map) { - unsigned int bdf =3D PCI_BDF(cfg->start_bus_number, 0, 0); - unsigned int end =3D PCI_BDF(cfg->end_bus_number, -1, -1); - - while ((bdf =3D find_next_bit(ro_map, end + 1, bdf)) <=3D end) { - arch_pci_ro_device(cfg->pci_segment, bdf); - if (bdf++ =3D=3D end) - break; - } - } + + start_mfn =3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->start_bus_number, = 0, 0); + end_mfn =3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->end_bus_number, ~0, = ~0); + if ( rangeset_add_range(mmio_ro_ranges, start_mfn, end_mfn) ) + printk(XENLOG_ERR + "%04x:%02x-%02x: could not mark MCFG (mfns %lx-%lx) = read-only\n", + cfg->pci_segment, cfg->start_bus_number, cfg->end_bus_numbe= r, + start_mfn, end_mfn); + return 0; } =20 @@ -197,6 +176,28 @@ void pci_mmcfg_arch_disable(unsigned int cfg->pci_segment, cfg->start_bus_number, cfg->end_bus_number); } =20 +bool_t pci_mmcfg_decode(unsigned long mfn, unsigned int *seg, + unsigned int *bdf) +{ + unsigned int idx; + + for (idx =3D 0; idx < pci_mmcfg_config_num; ++idx) { + const struct acpi_mcfg_allocation *cfg =3D pci_mmcfg_virt[idx].cfg= ; + + if (pci_mmcfg_virt[idx].virt && + mfn >=3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->start_bus_numbe= r, + 0, 0) && + mfn <=3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->end_bus_number,= + ~0, ~0)) { + *seg =3D cfg->pci_segment; + *bdf =3D mfn - PFN_DOWN(cfg->address); + return 1; + } + } + + return 0; +} + int __init pci_mmcfg_arch_init(void) { int i; --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -447,7 +447,6 @@ int __init pci_ro_device(int seg, int bu } =20 __set_bit(PCI_BDF2(bus, devfn), pseg->ro_map); - arch_pci_ro_device(seg, PCI_BDF2(bus, devfn)); _pci_hide_device(pdev); =20 return 0; --- a/xen/include/asm-x86/pci.h +++ b/xen/include/asm-x86/pci.h @@ -20,5 +20,7 @@ int pci_conf_write_intercept(unsigned in uint32_t *data); int pci_msi_conf_write_intercept(struct pci_dev *, unsigned int reg, unsigned int size, uint32_t *data); +bool_t pci_mmcfg_decode(unsigned long mfn, unsigned int *seg, + unsigned int *bdf); =20 #endif /* __X86_PCI_H__ */ --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -110,7 +110,6 @@ int pci_add_device(u16 seg, u8 bus, u8 d const struct pci_dev_info *, nodeid_t node); int pci_remove_device(u16 seg, u8 bus, u8 devfn); int pci_ro_device(int seg, int bus, int devfn); -void arch_pci_ro_device(int seg, int bdf); int pci_hide_device(int bus, int devfn); struct pci_dev *pci_get_pdev(int seg, int bus, int devfn); struct pci_dev *pci_get_real_pdev(int seg, int bus, int devfn); --=__PartECD81978.1__= Content-Type: text/plain; name="x86-PCI-MMCFG-intercept.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-PCI-MMCFG-intercept.patch" x86/PCI: intercept all PV Dom0 MMCFG writes=0A=0A... to hook up pci_conf_wr= ite_intercept() even for Dom0 not using=0Amethod 1 accesses for the base = part of PCI device config space.=0A=0ASigned-off-by: Jan Beulich =0A---=0ANot entirely sure whether the complicated logging logic = in x86/mm.c is=0Aactually worth it.=0A=0A--- a/xen/arch/x86/mm.c=0A+++ = b/xen/arch/x86/mm.c=0A@@ -734,6 +734,46 @@ static int update_xen_mappings(u= nsigned =0A return err;=0A }=0A =0A+#ifndef NDEBUG=0A+struct mmio_emul_= range_ctxt {=0A+ const struct domain *d;=0A+ unsigned long mfn;=0A+};= =0A+=0A+static int print_mmio_emul_range(unsigned long s, unsigned long e, = void *arg)=0A+{=0A+ const struct mmio_emul_range_ctxt *ctxt =3D = arg;=0A+=0A+ if ( ctxt->mfn > e )=0A+ return 0;=0A+=0A+ if ( = ctxt->mfn >=3D s )=0A+ {=0A+ static DEFINE_SPINLOCK(last_lock);= =0A+ static const struct domain *last_d;=0A+ static unsigned = long last_s =3D ~0UL, last_e;=0A+ bool_t print =3D 0;=0A+=0A+ = spin_lock(&last_lock);=0A+ if ( last_d !=3D ctxt->d || last_s !=3D = s || last_e !=3D e )=0A+ {=0A+ last_d =3D ctxt->d;=0A+ = last_s =3D s;=0A+ last_e =3D e;=0A+ print = =3D 1;=0A+ }=0A+ spin_unlock(&last_lock);=0A+=0A+ if = ( print )=0A+ printk(XENLOG_G_INFO=0A+ "d%d: = Forcing write emulation on MFNs %lx-%lx\n",=0A+ = ctxt->d->domain_id, s, e);=0A+ }=0A+=0A+ return 1;=0A+}=0A+#endif=0A+= =0A int=0A get_page_from_l1e(=0A l1_pgentry_t l1e, struct domain = *l1e_owner, struct domain *pg_owner)=0A@@ -757,6 +797,11 @@ get_page_from_l= 1e(=0A if ( !mfn_valid(mfn) ||=0A (real_pg_owner =3D = page_get_owner_and_reference(page)) =3D=3D dom_io )=0A {=0A+#ifndef = NDEBUG=0A+ const unsigned long *ro_map;=0A+ unsigned int = seg, bdf;=0A+#endif=0A+=0A /* Only needed the reference to confirm = dom_io ownership. */=0A if ( mfn_valid(mfn) )=0A = put_page(page);=0A@@ -792,9 +837,20 @@ get_page_from_l1e(=0A if ( = !(l1f & _PAGE_RW) ||=0A !rangeset_contains_singleton(mmio_ro_r= anges, mfn) )=0A return 0;=0A- dprintk(XENLOG_G_WARNING,= =0A- "d%d: Forcing read-only access to MFN %lx\n",=0A- = l1e_owner->domain_id, mfn);=0A+#ifndef NDEBUG=0A+ if ( = !pci_mmcfg_decode(mfn, &seg, &bdf) ||=0A+ ((ro_map =3D = pci_get_ro_map(seg)) !=3D NULL &&=0A+ test_bit(bdf, ro_map)) = )=0A+ printk(XENLOG_G_WARNING=0A+ "d%d: = Forcing read-only access to MFN %lx\n",=0A+ l1e_owner->do= main_id, mfn);=0A+ else=0A+ rangeset_report_ranges(mmio_r= o_ranges, 0, ~0UL,=0A+ print_mmio_emul_ra= nge,=0A+ &(struct mmio_emul_range_ctxt){= =0A+ .d =3D l1e_owner,=0A+ = .mfn =3D mfn });=0A+#endif=0A return = 1;=0A }=0A =0A@@ -5145,6 +5201,7 @@ int ptwr_do_page_fault(struct vcpu = *v, u=0A =0A /* We are looking only for read-only mappings of p.t. = pages. */=0A if ( ((l1e_get_flags(pte) & (_PAGE_PRESENT|_PAGE_RW)) = !=3D _PAGE_PRESENT) ||=0A+ rangeset_contains_singleton(mmio_ro_rang= es, l1e_get_pfn(pte)) ||=0A !get_page_from_pagenr(l1e_get_pfn(pte)= , d) )=0A goto bail;=0A =0A@@ -5192,6 +5249,7 @@ int ptwr_do_page_f= ault(struct vcpu *v, u=0A struct mmio_ro_emulate_ctxt {=0A struct = x86_emulate_ctxt ctxt;=0A unsigned long cr2;=0A+ unsigned int seg, = bdf;=0A };=0A =0A static int mmio_ro_emulated_read(=0A@@ -5231,6 +5289,44 = @@ static const struct x86_emulate_ops mmio=0A .write =3D = mmio_ro_emulated_write,=0A };=0A =0A+static int mmio_intercept_write(=0A+ = enum x86_segment seg,=0A+ unsigned long offset,=0A+ void = *p_data,=0A+ unsigned int bytes,=0A+ struct x86_emulate_ctxt = *ctxt)=0A+{=0A+ struct mmio_ro_emulate_ctxt *mmio_ctxt =3D=0A+ = container_of(ctxt, struct mmio_ro_emulate_ctxt, ctxt);=0A+=0A+ /*=0A+ = * Only allow naturally-aligned stores no wider than 4 bytes to the=0A+ = * original %cr2 address.=0A+ */=0A+ if ( ((bytes | offset) & = (bytes - 1)) || bytes > 4 ||=0A+ offset !=3D mmio_ctxt->cr2 )=0A+ = {=0A+ MEM_LOG("mmio_intercept: bad write (cr2=3D%lx, addr=3D%lx, = bytes=3D%u)",=0A+ mmio_ctxt->cr2, offset, bytes);=0A+ = return X86EMUL_UNHANDLEABLE;=0A+ }=0A+=0A+ offset &=3D 0xfff;=0A+ = pci_conf_write_intercept(mmio_ctxt->seg, mmio_ctxt->bdf, offset, = bytes,=0A+ p_data);=0A+ pci_mmcfg_write(mmio= _ctxt->seg, PCI_BUS(mmio_ctxt->bdf),=0A+ PCI_DEVFN2(mmio= _ctxt->bdf), offset, bytes,=0A+ *(uint32_t *)p_data);=0A= +=0A+ return X86EMUL_OKAY;=0A+}=0A+=0A+static const struct x86_emulate_o= ps mmio_intercept_ops =3D {=0A+ .read =3D mmio_ro_emulated_read,= =0A+ .insn_fetch =3D ptwr_emulated_read,=0A+ .write =3D = mmio_intercept_write,=0A+};=0A+=0A /* Check if guest is trying to modify a = r/o MMIO page. */=0A int mmio_ro_do_page_fault(struct vcpu *v, unsigned = long addr,=0A struct cpu_user_regs *regs)=0A@@ = -5245,6 +5341,7 @@ int mmio_ro_do_page_fault(struct vcpu *v=0A = .ctxt.swint_emulate =3D x86_swint_emulate_none,=0A .cr2 =3D = addr=0A };=0A+ const unsigned long *ro_map;=0A int rc;=0A =0A = /* Attempt to read the PTE that maps the VA being accessed. */=0A@@ = -5269,7 +5366,12 @@ int mmio_ro_do_page_fault(struct vcpu *v=0A if ( = !rangeset_contains_singleton(mmio_ro_ranges, mfn) )=0A return = 0;=0A =0A- rc =3D x86_emulate(&mmio_ro_ctxt.ctxt, &mmio_ro_emulate_ops);= =0A+ if ( pci_mmcfg_decode(mfn, &mmio_ro_ctxt.seg, &mmio_ro_ctxt.bdf) = &&=0A+ ((ro_map =3D pci_get_ro_map(mmio_ro_ctxt.seg)) =3D=3D NULL = ||=0A+ !test_bit(mmio_ro_ctxt.bdf, ro_map)) )=0A+ rc =3D = x86_emulate(&mmio_ro_ctxt.ctxt, &mmio_intercept_ops);=0A+ else=0A+ = rc =3D x86_emulate(&mmio_ro_ctxt.ctxt, &mmio_ro_emulate_ops);=0A =0A = return rc !=3D X86EMUL_UNHANDLEABLE ? EXCRET_fault_fixed : 0;=0A }=0A--- = a/xen/arch/x86/x86_64/mmconfig_64.c=0A+++ b/xen/arch/x86/x86_64/mmconfig_64= .c=0A@@ -134,30 +134,10 @@ static void __iomem *mcfg_ioremap(const =0A = return (void __iomem *) virt;=0A }=0A =0A-void arch_pci_ro_device(int seg, = int bdf)=0A-{=0A- unsigned int idx, bus =3D PCI_BUS(bdf);=0A-=0A- = for (idx =3D 0; idx < pci_mmcfg_config_num; ++idx) {=0A- const = struct acpi_mcfg_allocation *cfg =3D pci_mmcfg_virt[idx].cfg;=0A- = unsigned long mfn =3D (cfg->address >> PAGE_SHIFT) + bdf;=0A-=0A- = if (!pci_mmcfg_virt[idx].virt || cfg->pci_segment !=3D seg ||=0A- = cfg->start_bus_number > bus || cfg->end_bus_number < bus)=0A- = continue;=0A-=0A- if (rangeset_add_singleton(mmio_ro_ranges, = mfn))=0A- printk(XENLOG_ERR=0A- "%04x:%02x:%02= x.%u: could not mark MCFG (mfn %#lx) read-only\n",=0A- = cfg->pci_segment, bus, PCI_SLOT(bdf), PCI_FUNC(bdf),=0A- = mfn);=0A- }=0A-}=0A-=0A int pci_mmcfg_arch_enable(unsigned int idx)=0A = {=0A const typeof(pci_mmcfg_config[0]) *cfg =3D pci_mmcfg_virt[idx].cfg= ;=0A- const unsigned long *ro_map =3D pci_get_ro_map(cfg->pci_segment);= =0A+ unsigned long start_mfn, end_mfn;=0A =0A if (pci_mmcfg_virt[idx= ].virt)=0A return 0;=0A@@ -169,16 +149,15 @@ int pci_mmcfg_arch_ena= ble(unsigned int i=0A }=0A printk(KERN_INFO "PCI: Using MCFG for = segment %04x bus %02x-%02x\n",=0A cfg->pci_segment, cfg->start_b= us_number, cfg->end_bus_number);=0A- if (ro_map) {=0A- unsigned = int bdf =3D PCI_BDF(cfg->start_bus_number, 0, 0);=0A- unsigned int = end =3D PCI_BDF(cfg->end_bus_number, -1, -1);=0A-=0A- while ((bdf = =3D find_next_bit(ro_map, end + 1, bdf)) <=3D end) {=0A- = arch_pci_ro_device(cfg->pci_segment, bdf);=0A- if (bdf++ =3D=3D = end)=0A- break;=0A- }=0A- }=0A+=0A+ start_mfn = =3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->start_bus_number, 0, 0);=0A+ = end_mfn =3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->end_bus_number, ~0, = ~0);=0A+ if ( rangeset_add_range(mmio_ro_ranges, start_mfn, end_mfn) = )=0A+ printk(XENLOG_ERR=0A+ "%04x:%02x-%02x: could = not mark MCFG (mfns %lx-%lx) read-only\n",=0A+ cfg->pci_segme= nt, cfg->start_bus_number, cfg->end_bus_number,=0A+ = start_mfn, end_mfn);=0A+=0A return 0;=0A }=0A =0A@@ -197,6 +176,28 @@ = void pci_mmcfg_arch_disable(unsigned int=0A cfg->pci_segment, = cfg->start_bus_number, cfg->end_bus_number);=0A }=0A =0A+bool_t pci_mmcfg_d= ecode(unsigned long mfn, unsigned int *seg,=0A+ = unsigned int *bdf)=0A+{=0A+ unsigned int idx;=0A+=0A+ for (idx =3D = 0; idx < pci_mmcfg_config_num; ++idx) {=0A+ const struct acpi_mcfg_a= llocation *cfg =3D pci_mmcfg_virt[idx].cfg;=0A+=0A+ if (pci_mmcfg_vi= rt[idx].virt &&=0A+ mfn >=3D PFN_DOWN(cfg->address) + PCI_BDF(cf= g->start_bus_number,=0A+ = 0, 0) &&=0A+ mfn <=3D PFN_DOWN(cfg->address) + PCI_BDF(cfg->end= _bus_number,=0A+ ~0, = ~0)) {=0A+ *seg =3D cfg->pci_segment;=0A+ *bdf =3D = mfn - PFN_DOWN(cfg->address);=0A+ return 1;=0A+ }=0A+ = }=0A+=0A+ return 0;=0A+}=0A+=0A int __init pci_mmcfg_arch_init(void)=0A = {=0A int i;=0A--- a/xen/drivers/passthrough/pci.c=0A+++ b/xen/drivers/p= assthrough/pci.c=0A@@ -447,7 +447,6 @@ int __init pci_ro_device(int seg, = int bu=0A }=0A =0A __set_bit(PCI_BDF2(bus, devfn), pseg->ro_map);= =0A- arch_pci_ro_device(seg, PCI_BDF2(bus, devfn));=0A _pci_hide_dev= ice(pdev);=0A =0A return 0;=0A--- a/xen/include/asm-x86/pci.h=0A+++ = b/xen/include/asm-x86/pci.h=0A@@ -20,5 +20,7 @@ int pci_conf_write_intercep= t(unsigned in=0A uint32_t *data);=0A int = pci_msi_conf_write_intercept(struct pci_dev *, unsigned int reg,=0A = unsigned int size, uint32_t *data);=0A+bool_t = pci_mmcfg_decode(unsigned long mfn, unsigned int *seg,=0A+ = unsigned int *bdf);=0A =0A #endif /* __X86_PCI_H__ */=0A--- = a/xen/include/xen/pci.h=0A+++ b/xen/include/xen/pci.h=0A@@ -110,7 +110,6 = @@ int pci_add_device(u16 seg, u8 bus, u8 d=0A const = struct pci_dev_info *, nodeid_t node);=0A int pci_remove_device(u16 seg, = u8 bus, u8 devfn);=0A int pci_ro_device(int seg, int bus, int devfn);=0A-vo= id arch_pci_ro_device(int seg, int bdf);=0A int pci_hide_device(int bus, = int devfn);=0A struct pci_dev *pci_get_pdev(int seg, int bus, int = devfn);=0A struct pci_dev *pci_get_real_pdev(int seg, int bus, int = devfn);=0A --=__PartECD81978.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 --=__PartECD81978.1__=--