From patchwork Wed Jan 11 23:36:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9511625 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 5C15660710 for ; Wed, 11 Jan 2017 23:39:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4420C2851B for ; Wed, 11 Jan 2017 23:39:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 367F328655; Wed, 11 Jan 2017 23:39:10 +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 BC7ED2851B for ; Wed, 11 Jan 2017 23:39:09 +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 1cRSRn-0004Qh-PN; Wed, 11 Jan 2017 23:36:51 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRSRn-0004Qb-3U for xen-devel@lists.xenproject.org; Wed, 11 Jan 2017 23:36:51 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id FE/1E-02804-291C6785; Wed, 11 Jan 2017 23:36:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRWlGSWpSXmKPExsVybKJsh+7Eg2U RBq/Walh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBl7+7cwFnyXrmj7sJa5gXG9eBcjF4eQwFRG if7rs5m7GDmBnNlMEt0tFiA2i4C2xPtXK1hBbDYBQ4m/TzaxdTFycEgA2Us+c4CERQTkJJrev mMBmcMs0MQosfHxC0aQGmGBbIldF1NAangFvCS+HD4NNl5UQFfi0L8/bBBxQYmTM5+wgNjMAl oSy6dvA7MlBDIk5vXMYYWwvSQW3bgEZatJXD23iXkCI/8sJO2zkLQvYGRaxahRnFpUllqka2i gl1SUmZ5RkpuYmQPkGevlphYXJ6an5iQmFesl5+duYgQGWz0DA+MOxm1dzocYJTmYlER5s5eX RQjxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4O04AJQTLEpNT61Iy8wBhj1MWoKDR0mEVxUkzVtck JhbnJkOkTrFaMxx6sbpl0wcfc+uvGQSYsnLz0uVEuetACkVACnNKM2DGwSLx0uMslLCvIwMDA xCPAWpRbmZJajyrxjFORiVhHlLQabwZOaVwO17BXQKE9ApkXbFIKeUJCKkpBoYlZ1PvXHOOKZ 2PzQqQuGQy62pHycU7OcW21CkGvqgMjFqT/X1SvXo7z8WttpM8zsxzyfz99JT59P3/tvXsL37 bGG0Ew+X05redLm5U5qTDs++sLR47vbpjedWHaqUUoo3W3w0ssH96cKGKDOOI39Om3xYPS/z+ 7a23/qLJe3FD3lKTDGIN0o8oMRSnJFoqMVcVJwIAPx9skvCAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-15.tower-31.messagelabs.com!1484177808!76109767!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48017 invoked from network); 11 Jan 2017 23:36:49 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-15.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Jan 2017 23:36:49 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92C6E201FE; Wed, 11 Jan 2017 23:36:46 +0000 (UTC) Received: from [10.1.10.56] (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F699201C7; Wed, 11 Jan 2017 23:36:45 +0000 (UTC) Date: Wed, 11 Jan 2017 15:36:40 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: boris.ostrovsky@oracle.com Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP Cc: jgross@suse.com, karahmed@amazon.de, sstabellini@kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH] partially revert "xen: Remove event channel notification through Xen PCI platform device" 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 The following commit: commit 72a9b186292d98494f222226cfd24a1621796209 Author: KarimAllah Ahmed Date: Fri Aug 26 23:55:36 2016 +0200 xen: Remove event channel notification through Xen PCI platform device broke Linux when booting as Dom0 on Xen in a nested Xen environment (Xen installed inside a Xen VM). In this scenario, Linux is a PV guest, but at the same time it uses the platform-pci driver to receive notifications from L0 Xen. vector callbacks are not available because L1 Xen doesn't allow them. Partially revert the offending commit, by restoring IRQ based notifications for PV guests only. I restored only the code which is strictly needed and replaced the xen_have_vector_callback checks within it with xen_pv_domain() checks. Signed-off-by: Stefano Stabellini --- Alternatively, I could also restore the xen_have_vector_callback checks. In general, it's best to have feature flag checks than umbrella xen_pv/hvm_domain() checks. --- diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c index b59c9455..1477f1d 100644 --- a/drivers/xen/platform-pci.c +++ b/drivers/xen/platform-pci.c @@ -42,6 +42,7 @@ static unsigned long platform_mmio; static unsigned long platform_mmio_alloc; static unsigned long platform_mmiolen; +static uint64_t callback_via; static unsigned long alloc_xen_mmio(unsigned long len) { @@ -54,6 +55,51 @@ static unsigned long alloc_xen_mmio(unsigned long len) return addr; } +static uint64_t get_callback_via(struct pci_dev *pdev) +{ + u8 pin; + int irq; + + irq = pdev->irq; + if (irq < 16) + return irq; /* ISA IRQ */ + + pin = pdev->pin; + + /* We don't know the GSI. Specify the PCI INTx line instead. */ + return ((uint64_t)0x01 << 56) | /* PCI INTx identifier */ + ((uint64_t)pci_domain_nr(pdev->bus) << 32) | + ((uint64_t)pdev->bus->number << 16) | + ((uint64_t)(pdev->devfn & 0xff) << 8) | + ((uint64_t)(pin - 1) & 3); +} + +static irqreturn_t do_hvm_evtchn_intr(int irq, void *dev_id) +{ + xen_hvm_evtchn_do_upcall(); + return IRQ_HANDLED; +} + +static int xen_allocate_irq(struct pci_dev *pdev) +{ + return request_irq(pdev->irq, do_hvm_evtchn_intr, + IRQF_NOBALANCING | IRQF_TRIGGER_RISING, + "xen-platform-pci", pdev); +} + +static int platform_pci_resume(struct pci_dev *pdev) +{ + int err; + if (!xen_pv_domain()) + return 0; + err = xen_set_callback_via(callback_via); + if (err) { + dev_err(&pdev->dev, "platform_pci_resume failure!\n"); + return err; + } + return 0; +} + static int platform_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -92,6 +138,21 @@ static int platform_pci_probe(struct pci_dev *pdev, platform_mmio = mmio_addr; platform_mmiolen = mmio_len; + if (xen_pv_domain()) { + ret = xen_allocate_irq(pdev); + if (ret) { + dev_warn(&pdev->dev, "request_irq failed err=%d\n", ret); + goto out; + } + callback_via = get_callback_via(pdev); + ret = xen_set_callback_via(callback_via); + if (ret) { + dev_warn(&pdev->dev, "Unable to set the evtchn callback " + "err=%d\n", ret); + goto out; + } + } + max_nr_gframes = gnttab_max_grant_frames(); grant_frames = alloc_xen_mmio(PAGE_SIZE * max_nr_gframes); ret = gnttab_setup_auto_xlat_frames(grant_frames); @@ -123,6 +184,9 @@ static int platform_pci_probe(struct pci_dev *pdev, .name = DRV_NAME, .probe = platform_pci_probe, .id_table = platform_pci_tbl, +#ifdef CONFIG_PM + .resume_early = platform_pci_resume, +#endif }; static int __init platform_pci_init(void)