From patchwork Mon Mar 12 18:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey G X-Patchwork-Id: 10277007 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 2A87C602C2 for ; Mon, 12 Mar 2018 18:39:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A80628DD8 for ; Mon, 12 Mar 2018 18:39:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DF8628DF2; Mon, 12 Mar 2018 18:39:54 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E86B28DD8 for ; Mon, 12 Mar 2018 18:39:53 +0000 (UTC) Received: from localhost ([::1]:33886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evSMS-0006JU-MY for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Mar 2018 14:39:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evSIc-0008KY-DC for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:35:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evSIZ-0005SS-8j for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:35:54 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:37678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evSIZ-0005SB-2X for qemu-devel@nongnu.org; Mon, 12 Mar 2018 14:35:51 -0400 Received: by mail-pl0-x243.google.com with SMTP id w12-v6so9830422plp.4 for ; Mon, 12 Mar 2018 11:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=yPASatqb1fmhAi6rC1ukYmZJdpe1srjOs0kHyLTI/wc=; b=VFv3lWMqcfXWNIYf9Nns6+L+EPFURsBt0nSCBsq7mPSO+dOhWNgKMMBIz+ZOBSZl/K uimkRJ7vPwk9+FVeEAHbo09gEnxyoqlE+77ba2/6HJWASGQJXwyOHT3eahX7evC//2qt B7K9N+Nc00zNuBfMe86pAMNE9owutJAXF9v5ZCwPX6Qlm4sF+3apCEVGINY7WUVk3dMm byEPsiy5PYAYpRA9G82ZND8Da3J8NnBdRmJWOwAEOu5jK/mnvzZj1bWxCElxHn2PWZOY wmZOp+UA+RcbcUp54UsbHJiBYeW1F3S9au0miJHhb8BTxlbQpKy/SQVHgew7z6gwoZpj EwgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=yPASatqb1fmhAi6rC1ukYmZJdpe1srjOs0kHyLTI/wc=; b=pcO5dUUQ1Y+RoF8MjmFtKGF8HwoocuOQ4SRl4hUgirlwXkq5tsAlopswA3cjtU2I85 SXbV8Z4rDr+P4FallXQ82/yk5rGdrJx2Z01inEyr8Yovo79EvlP0uX71J9q+7lRjqk8X 0wiCSDIYidwdIQJzsmwrir/ZVM3VmSBX/S7xTbsqGPAckPlHhn9TVYfrfVQVBmaWCKHA yjDKWE+RxVw6a4dTge2Zc1j3wpTSBkwbKyLR2T2jORJ4jORQtVN/vZFiF0BW8A4oSKvw at3iXLMkalEL8WOqZJlymG6DjS5q9n7PAdj7IFM9k/pz5LqQYGQ7Q8Qo1yIx4tDDNn+o AYIg== X-Gm-Message-State: AElRT7G+YTYsOgRI+perqOHiMuaBhDzsXHbdHXV/jwBWmPllbWGKKpjW UtvcZzIVwVwIF4CBFCeYD2c= X-Google-Smtp-Source: AG47ELt3YFBAa88k10HHpYzT/H7oO/PgyMhszOZTHy5i4J1WCgQSM3yX6fjb+6MREAG2kBre+XmDqw== X-Received: by 2002:a17:902:8501:: with SMTP id bj1-v6mr9163871plb.110.1520879750211; Mon, 12 Mar 2018 11:35:50 -0700 (PDT) Received: from localhost.localdomain ([217.150.73.25]) by smtp.gmail.com with ESMTPSA id w10sm14468666pgr.57.2018.03.12.11.35.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 11:35:49 -0700 (PDT) From: Alexey Gerasimenko To: xen-devel@lists.xenproject.org Date: Tue, 13 Mar 2018 04:34:05 +1000 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::243 Subject: [Qemu-devel] [RFC PATCH 20/30] xen/pt: determine the legacy/PCIe mode for a passed through device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Stefano Stabellini , Alexey Gerasimenko , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Even if we have some real PCIe device being passed through to a guest, there are situations when we cannot use its PCIe features, primarily allowing to access extended (>256) config space. Basically, we can allow reading PCIe extended config space only if both the device and emulated system are PCIe-capable. So it's a combination of checks: - PCI Express capability presence - pci_is_express(device) - pci_bus_is_express(device bus) The AND-product of these checks is stored to pcie_enabled_dev flag in XenPCIPassthroughState for later use in functions like xen_pt_pci_config_access_check. This way we get consistent behavior when the same PCIe device being passed through to either i440 domain or Q35 one. Signed-off-by: Alexey Gerasimenko --- hw/xen/xen_pt.c | 28 ++++++++++++++++++++++++++-- hw/xen/xen_pt.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 9b7a960de1..a902a9b685 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -687,6 +687,21 @@ static const MemoryListener xen_pt_io_listener = { .priority = 10, }; +static inline bool xen_pt_dev_is_pcie_mode(PCIDevice *d) +{ + XenPCIPassthroughState *s = XEN_PT_DEVICE(d); + PCIBus *bus = pci_get_bus(d); + + if (bus != NULL) { + if (pci_is_express(d) && pci_bus_is_express(bus) && + xen_host_pci_find_next_cap(&s->real_device, 0, PCI_CAP_ID_EXP)) { + return true; + } + } + + return false; +} + static void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s, XenHostPCIDevice *dev) @@ -794,8 +809,17 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) s->real_device.dev, s->real_device.func); } - /* Initialize virtualized PCI configuration (Extended 256 Bytes) */ - memset(d->config, 0, PCI_CONFIG_SPACE_SIZE); + s->pcie_enabled_dev = xen_pt_dev_is_pcie_mode(d); + if (s->pcie_enabled_dev) { + XEN_PT_LOG(d, "Host device %04x:%02x:%02x.%d passed thru " + "in PCIe mode\n", s->real_device.domain, + s->real_device.bus, s->real_device.dev, + s->real_device.func); + } + + /* Initialize virtualized PCI configuration space (256/4K bytes) */ + memset(d->config, 0, pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE + : PCI_CONFIG_SPACE_SIZE); s->memory_listener = xen_pt_memory_listener; s->io_listener = xen_pt_io_listener; diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h index aa39a9aa5f..1204acbdce 100644 --- a/hw/xen/xen_pt.h +++ b/hw/xen/xen_pt.h @@ -212,6 +212,7 @@ struct XenPCIPassthroughState { PCIHostDeviceAddress hostaddr; bool is_virtfn; + bool pcie_enabled_dev; bool permissive; bool permissive_warned; XenHostPCIDevice real_device;