From patchwork Fri Jun 30 15:01:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9819835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04D13602B1 for ; Fri, 30 Jun 2017 15:04:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAE5D28338 for ; Fri, 30 Jun 2017 15:04:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE8232853A; Fri, 30 Jun 2017 15:04:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4EBAD28338 for ; Fri, 30 Jun 2017 15:04:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQxQV-00038t-4J; Fri, 30 Jun 2017 15:01:43 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dQxQU-00035Z-0Q for xen-devel@lists.xenproject.org; Fri, 30 Jun 2017 15:01:42 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 25/D4-02962-5D766595; Fri, 30 Jun 2017 15:01:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMIsWRWlGSWpSXmKPExsXitHSDve7V9LB Ig66vvBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b8Q3/ZCqZpV0ze08rawPhKsYuRg0NCwF/i /ESxLkZODjYBHYmLc3eygYRFBFQkbu816GLk4mAWOMEo0fpiHRtIjbBAqMSz5yuZQGwWAVWJD 9+XsIDYvAKWEj3zZ4HVSAjoSbyd+IIRZA6ngJXEiUkyIGEhoJKFfy4zQZQLSpyc+QSslVlAU6 J1+292CFteonnrbGaIekWJ/nkP2CYw8s1C0jILScssJC0LGJlXMWoUpxaVpRbpGlrqJRVlpme U5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEBhoDEOxg/LEs4BCjJAeTkijvymuhkUJ8Sfkp lRmJxRnxRaU5qcWHGDU4OAQ2r119gVGKJS8/L1VJgrc1LSxSSLAoNT21Ii0zBxgLMKUSHDxKI ryyQUBp3uKCxNzizHSI1ClGXY5jM35+YxICmyElznsWZIYASFFGaR7cCFhcXmKUlRLmZQQ6UI inILUoN7MEVf4VozgHo5Iw72mQKTyZeSVwm14BHcEEdITwjBCQI0oSEVJSDYxSrysUoxdaXSq K2cR11pPRdnveh/dhbYY5tlWu3l73NpxxUw+okVt4rXyS+AzVnUv2vCiQF3XiMpuukWNc7Cpy Msr3ROdC70lb5hU/jdz7ddqp0HfLs2Vvbb15tVqibel/Xom5J6K+tUz4uaxk4vT20LXCPL0m0 RMXHZN+/Fxz34sSp9s2m6KVWIozEg21mIuKEwHHZYJDxgIAAA== X-Env-Sender: prvs=3475c4a2e=roger.pau@citrix.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1498834898!57200718!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26790 invoked from network); 30 Jun 2017 15:01:40 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-2.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 30 Jun 2017 15:01:40 -0000 X-IronPort-AV: E=Sophos;i="5.40,287,1496102400"; d="scan'208";a="438474112" From: Roger Pau Monne To: Date: Fri, 30 Jun 2017 16:01:11 +0100 Message-ID: <20170630150117.88489-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170630150117.88489-1-roger.pau@citrix.com> References: <20170630150117.88489-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , julien.grall@arm.com, Jan Beulich , boris.ostrovsky@oracle.com, Roger Pau Monne Subject: [Xen-devel] [PATCH v4 3/9] x86/physdev: enable PHYSDEVOP_pci_mmcfg_reserved for PVH Dom0 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP So that hotplug (or MMCFG regions not present in the MCFG ACPI table) can be added at run time by the hardware domain. When a new MMCFG area is added to a PVH Dom0, Xen will scan it and add the devices to the hardware domain. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- changes since v3: - New in this version. --- tools/tests/vpci/emul.h | 2 -- xen/arch/x86/hvm/hypercall.c | 4 ++++ xen/arch/x86/physdev.c | 19 +++++++++++++++++++ xen/drivers/passthrough/pci.c | 37 ++++++++++++++++++++++++++++++++++--- xen/drivers/vpci/vpci.c | 4 ++-- xen/include/xen/pci.h | 1 + 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/tools/tests/vpci/emul.h b/tools/tests/vpci/emul.h index 1b0217e7e3..047079de4c 100644 --- a/tools/tests/vpci/emul.h +++ b/tools/tests/vpci/emul.h @@ -58,8 +58,6 @@ extern struct pci_dev test_pdev; #include "vpci.h" -#define __hwdom_init - #define has_vpci(d) true /* Define our own locks. */ diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index e7238ce293..89625d514c 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -89,6 +89,10 @@ static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( !has_pirq(curr->domain) ) return -ENOSYS; break; + case PHYSDEVOP_pci_mmcfg_reserved: + if ( !is_hardware_domain(curr->domain) ) + return -ENOSYS; + break; } if ( !curr->hcall_compat ) diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 0eb409758f..6b1c92fa0b 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -559,6 +559,25 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) ret = pci_mmcfg_reserved(info.address, info.segment, info.start_bus, info.end_bus, info.flags); + if ( ret || !is_hvm_domain(currd) ) + break; + + /* + * For HVM (PVH) domains try to add the newly found MMCFG to the + * domain. + */ + ret = register_vpci_mmcfg_handler(currd, info.address, info.start_bus, + info.end_bus, info.segment); + if ( ret == -EEXIST ) + { + ret = 0; + break; + } + if ( ret ) + break; + + ret = pci_scan_and_setup_segment(info.segment); + break; } diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 3208cd5d71..2d38a5a297 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -924,7 +924,7 @@ out: return ret; } -bool_t __init pci_device_detect(u16 seg, u8 bus, u8 dev, u8 func) +bool pci_device_detect(u16 seg, u8 bus, u8 dev, u8 func) { u32 vendor; @@ -971,7 +971,7 @@ void pci_check_disable_device(u16 seg, u8 bus, u8 devfn) * scan pci devices to add all existed PCI devices to alldevs_list, * and setup pci hierarchy in array bus2bridge. */ -static int __init _scan_pci_devices(struct pci_seg *pseg, void *arg) +static int _scan_pci_devices(struct pci_seg *pseg, void *arg) { struct pci_dev *pdev; int bus, dev, func; @@ -1050,7 +1050,7 @@ static void setup_one_hwdom_device(const struct setup_hwdom *ctxt, ctxt->d->domain_id, err); } -static int __hwdom_init _setup_hwdom_pci_devices(struct pci_seg *pseg, void *arg) +static int _setup_hwdom_pci_devices(struct pci_seg *pseg, void *arg) { struct setup_hwdom *ctxt = arg; int bus, devfn; @@ -1110,6 +1110,37 @@ void __hwdom_init setup_hwdom_pci_devices( pcidevs_unlock(); } +static int add_device(uint8_t devfn, struct pci_dev *pdev) +{ + return iommu_add_device(pdev); +} + +int pci_scan_and_setup_segment(uint16_t segment) +{ + struct pci_seg *pseg = get_pseg(segment); + struct setup_hwdom ctxt = { + .d = current->domain, + .handler = add_device, + }; + int ret; + + if ( !pseg ) + return -EINVAL; + + pcidevs_lock(); + ret = _scan_pci_devices(pseg, NULL); + if ( ret ) + goto out; + + ret = _setup_hwdom_pci_devices(pseg, &ctxt); + if ( ret ) + goto out; + + out: + pcidevs_unlock(); + return ret; +} + #ifdef CONFIG_ACPI #include #include diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index c54de83b82..7d4ecd5fb5 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -33,12 +33,12 @@ struct vpci_register { struct list_head node; }; -int __hwdom_init vpci_add_handlers(struct pci_dev *pdev) +int vpci_add_handlers(struct pci_dev *pdev) { unsigned int i; int rc = 0; - if ( !has_vpci(pdev->domain) ) + if ( !has_vpci(pdev->domain) || pdev->vpci ) return 0; pdev->vpci = xzalloc(struct vpci); diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index a9b80e330b..e550effcc9 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -131,6 +131,7 @@ struct pci_dev *pci_get_real_pdev(int seg, int bus, int devfn); struct pci_dev *pci_get_pdev_by_domain( struct domain *, int seg, int bus, int devfn); void pci_check_disable_device(u16 seg, u8 bus, u8 devfn); +int pci_scan_and_setup_segment(uint16_t segment); uint8_t pci_conf_read8( unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,