From: "Jan Beulich" Subject: [PATCH v5 1/7] x86/PCI: add config space abstract write intercept logic Date: Mon, 20 Jul 2015 15:18:31 +0100 Message-ID: <55AD1F570200007800093270@mail.emea.novell.com> References: <55AD1E830200007800093243@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartB4804127.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZHBts-000468-Se for xen-devel@lists.xenproject.org; Mon, 20 Jul 2015 14:18:37 +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. --=__PartB4804127.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This is to be used by MSI code, and later to also be hooked up to MMCFG accesses by Dom0. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -1108,6 +1108,12 @@ void pci_cleanup_msi(struct pci_dev *pde msi_free_irqs(pdev); } =20 +int pci_msi_conf_write_intercept(struct pci_dev *pdev, unsigned int reg, + unsigned int size, uint32_t *data) +{ + return 0; +} + int pci_restore_msi_state(struct pci_dev *pdev) { unsigned long flags; --- a/xen/arch/x86/pci.c +++ b/xen/arch/x86/pci.c @@ -67,3 +67,28 @@ void pci_conf_write(uint32_t cf8, uint8_ =20 spin_unlock_irqrestore(&pci_config_lock, flags); } + +int pci_conf_write_intercept(unsigned int seg, unsigned int bdf, + unsigned int reg, unsigned int size, + uint32_t *data) +{ + struct pci_dev *pdev; + int rc =3D 0; + + /* + * Avoid expensive operations when no hook is going to do anything + * for the access anyway. + */ + if ( reg < 64 || reg >=3D 256 ) + return 0; + + spin_lock(&pcidevs_lock); + + pdev =3D pci_get_pdev(seg, PCI_BUS(bdf), PCI_DEVFN2(bdf)); + if ( pdev ) + rc =3D pci_msi_conf_write_intercept(pdev, reg, size, data); + + spin_unlock(&pcidevs_lock); + + return rc; +} --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1777,8 +1777,8 @@ static bool_t admin_io_okay(unsigned int return ioports_access_permitted(d, port, port + bytes - 1); } =20 -static bool_t pci_cfg_ok(struct domain *currd, bool_t write, - unsigned int start, unsigned int size) +static bool_t pci_cfg_ok(struct domain *currd, unsigned int start, + unsigned int size, uint32_t *write) { uint32_t machine_bdf; =20 @@ -1810,8 +1810,12 @@ static bool_t pci_cfg_ok(struct domain * start |=3D CF8_ADDR_HI(currd->arch.pci_cf8); } =20 - return !xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf, - start, start + size - 1, write); + if ( xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf, + start, start + size - 1, !!write) !=3D = 0 ) + return 0; + + return !write || + pci_conf_write_intercept(0, machine_bdf, start, size, write) = >=3D 0; } =20 uint32_t guest_io_read(unsigned int port, unsigned int bytes, @@ -1863,7 +1867,7 @@ uint32_t guest_io_read(unsigned int port size =3D min(bytes, 4 - (port & 3)); if ( size =3D=3D 3 ) size =3D 2; - if ( pci_cfg_ok(currd, 0, port & 3, size) ) + if ( pci_cfg_ok(currd, port & 3, size, NULL) ) sub_data =3D pci_conf_read(currd->arch.pci_cf8, port & 3, = size); } =20 @@ -1934,7 +1938,7 @@ void guest_io_write(unsigned int port, u size =3D min(bytes, 4 - (port & 3)); if ( size =3D=3D 3 ) size =3D 2; - if ( pci_cfg_ok(currd, 1, port & 3, size) ) + if ( pci_cfg_ok(currd, port & 3, size, &data) ) pci_conf_write(currd->arch.pci_cf8, port & 3, size, = data); } =20 --- a/xen/include/asm-x86/pci.h +++ b/xen/include/asm-x86/pci.h @@ -15,4 +15,10 @@ struct arch_pci_dev { vmask_t used_vectors; }; =20 +int pci_conf_write_intercept(unsigned int seg, unsigned int bdf, + unsigned int reg, unsigned int size, + uint32_t *data); +int pci_msi_conf_write_intercept(struct pci_dev *, unsigned int reg, + unsigned int size, uint32_t *data); + #endif /* __X86_PCI_H__ */ --=__PartB4804127.1__= Content-Type: text/plain; name="x86-PCI-CFG-write-intercept.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-PCI-CFG-write-intercept.patch" x86/PCI: add config space abstract write intercept logic=0A=0AThis is to = be used by MSI code, and later to also be hooked up to=0AMMCFG accesses by = Dom0.=0A=0ASigned-off-by: Jan Beulich =0AReviewed-by: = Andrew Cooper =0A=0A--- a/xen/arch/x86/msi.c=0A+= ++ b/xen/arch/x86/msi.c=0A@@ -1108,6 +1108,12 @@ void pci_cleanup_msi(struc= t pci_dev *pde=0A msi_free_irqs(pdev);=0A }=0A =0A+int pci_msi_conf_wri= te_intercept(struct pci_dev *pdev, unsigned int reg,=0A+ = unsigned int size, uint32_t *data)=0A+{=0A+ return = 0;=0A+}=0A+=0A int pci_restore_msi_state(struct pci_dev *pdev)=0A {=0A = unsigned long flags;=0A--- a/xen/arch/x86/pci.c=0A+++ b/xen/arch/x86/pci.c= =0A@@ -67,3 +67,28 @@ void pci_conf_write(uint32_t cf8, uint8_=0A =0A = spin_unlock_irqrestore(&pci_config_lock, flags);=0A }=0A+=0A+int pci_conf_w= rite_intercept(unsigned int seg, unsigned int bdf,=0A+ = unsigned int reg, unsigned int size,=0A+ = uint32_t *data)=0A+{=0A+ struct pci_dev *pdev;=0A+ int rc =3D = 0;=0A+=0A+ /*=0A+ * Avoid expensive operations when no hook is = going to do anything=0A+ * for the access anyway.=0A+ */=0A+ if = ( reg < 64 || reg >=3D 256 )=0A+ return 0;=0A+=0A+ spin_lock(&pci= devs_lock);=0A+=0A+ pdev =3D pci_get_pdev(seg, PCI_BUS(bdf), PCI_DEVFN2(= bdf));=0A+ if ( pdev )=0A+ rc =3D pci_msi_conf_write_intercept(pd= ev, reg, size, data);=0A+=0A+ spin_unlock(&pcidevs_lock);=0A+=0A+ = return rc;=0A+}=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/traps.c= =0A@@ -1777,8 +1777,8 @@ static bool_t admin_io_okay(unsigned int=0A = return ioports_access_permitted(d, port, port + bytes - 1);=0A }=0A = =0A-static bool_t pci_cfg_ok(struct domain *currd, bool_t write,=0A- = unsigned int start, unsigned int size)=0A+static bool_t = pci_cfg_ok(struct domain *currd, unsigned int start,=0A+ = unsigned int size, uint32_t *write)=0A {=0A uint32_t machine_bdf;= =0A =0A@@ -1810,8 +1810,12 @@ static bool_t pci_cfg_ok(struct domain *=0A = start |=3D CF8_ADDR_HI(currd->arch.pci_cf8);=0A }=0A =0A- = return !xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf,=0A- = start, start + size - 1, write);=0A+ if = ( xsm_pci_config_permission(XSM_HOOK, currd, machine_bdf,=0A+ = start, start + size - 1, !!write) !=3D 0 )=0A+ = return 0;=0A+=0A+ return !write ||=0A+ pci_conf_write_interce= pt(0, machine_bdf, start, size, write) >=3D 0;=0A }=0A =0A uint32_t = guest_io_read(unsigned int port, unsigned int bytes,=0A@@ -1863,7 +1867,7 = @@ uint32_t guest_io_read(unsigned int port=0A size =3D = min(bytes, 4 - (port & 3));=0A if ( size =3D=3D 3 )=0A = size =3D 2;=0A- if ( pci_cfg_ok(currd, 0, port & 3, = size) )=0A+ if ( pci_cfg_ok(currd, port & 3, size, NULL) )=0A = sub_data =3D pci_conf_read(currd->arch.pci_cf8, port & 3, = size);=0A }=0A =0A@@ -1934,7 +1938,7 @@ void guest_io_write(unsigne= d int port, u=0A size =3D min(bytes, 4 - (port & 3));=0A = if ( size =3D=3D 3 )=0A size =3D 2;=0A- = if ( pci_cfg_ok(currd, 1, port & 3, size) )=0A+ if ( pci_cfg_ok(= currd, port & 3, size, &data) )=0A pci_conf_write(currd->ar= ch.pci_cf8, port & 3, size, data);=0A }=0A =0A--- a/xen/include/asm= -x86/pci.h=0A+++ b/xen/include/asm-x86/pci.h=0A@@ -15,4 +15,10 @@ struct = arch_pci_dev {=0A vmask_t used_vectors;=0A };=0A =0A+int pci_conf_write= _intercept(unsigned int seg, unsigned int bdf,=0A+ = unsigned int reg, unsigned int size,=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+=0A #endif /* __X86_PCI_H__ */=0A --=__PartB4804127.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 --=__PartB4804127.1__=--